vncinput.hh (10839:10cac0f0f419) vncinput.hh (11359:b0b976a1ceda)
1/*
2 * Copyright (c) 2010, 2015 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Ali Saidi
38 * William Wang
39 */
40
41/** @file
42 * Declaration of a VNC input
43 */
44
45#ifndef __BASE_VNC_VNC_INPUT_HH__
46#define __BASE_VNC_VNC_INPUT_HH__
47
48#include <iostream>
49#include <memory>
50
51#include "base/bitmap.hh"
52#include "params/VncInput.hh"
53#include "sim/sim_object.hh"
54
1/*
2 * Copyright (c) 2010, 2015 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Ali Saidi
38 * William Wang
39 */
40
41/** @file
42 * Declaration of a VNC input
43 */
44
45#ifndef __BASE_VNC_VNC_INPUT_HH__
46#define __BASE_VNC_VNC_INPUT_HH__
47
48#include <iostream>
49#include <memory>
50
51#include "base/bitmap.hh"
52#include "params/VncInput.hh"
53#include "sim/sim_object.hh"
54
55class OutputDirectory;
56
55/**
56 * A device that expects to receive input from the vnc server should derrive
57 * (through mulitple inheritence if necessary from VncKeyboard or VncMouse
58 * and call setKeyboard() or setMouse() respectively on the vnc server.
59 */
60class VncKeyboard
61{
62 public:
63 /**
64 * Called when the vnc server receives a key press event from the
65 * client.
66 * @param key the key passed is an x11 keysym
67 * @param down is the key now down or up?
68 */
69 virtual void keyPress(uint32_t key, bool down) = 0;
70};
71
72class VncMouse
73{
74 public:
75 /**
76 * called whenever the mouse moves or it's button state changes
77 * buttons is a simple mask with each button (0-8) corresponding to
78 * a bit position in the byte with 1 being down and 0 being up
79 * @param x the x position of the mouse
80 * @param y the y position of the mouse
81 * @param buttos the button state as described above
82 */
83 virtual void mouseAt(uint16_t x, uint16_t y, uint8_t buttons) = 0;
84};
85
86class VncInput : public SimObject
87{
88 public:
89
90 /** Client -> Server message IDs */
91 enum ClientMessages {
92 ClientSetPixelFormat = 0,
93 ClientSetEncodings = 2,
94 ClientFrameBufferUpdate = 3,
95 ClientKeyEvent = 4,
96 ClientPointerEvent = 5,
97 ClientCutText = 6
98 };
99
100 struct PixelFormat {
101 uint8_t bpp;
102 uint8_t depth;
103 uint8_t bigendian;
104 uint8_t truecolor;
105 uint16_t redmax;
106 uint16_t greenmax;
107 uint16_t bluemax;
108 uint8_t redshift;
109 uint8_t greenshift;
110 uint8_t blueshift;
111 uint8_t padding[3];
112 } M5_ATTR_PACKED;
113
114 struct PixelFormatMessage {
115 uint8_t type;
116 uint8_t padding[3];
117 PixelFormat px;
118 } M5_ATTR_PACKED;
119
120 struct PixelEncodingsMessage {
121 uint8_t type;
122 uint8_t padding;
123 uint16_t num_encodings;
124 } M5_ATTR_PACKED;
125
126 struct FrameBufferUpdateReq {
127 uint8_t type;
128 uint8_t incremental;
129 uint16_t x;
130 uint16_t y;
131 uint16_t width;
132 uint16_t height;
133 } M5_ATTR_PACKED;
134
135 struct KeyEventMessage {
136 uint8_t type;
137 uint8_t down_flag;
138 uint8_t padding[2];
139 uint32_t key;
140 } M5_ATTR_PACKED;
141
142 struct PointerEventMessage {
143 uint8_t type;
144 uint8_t button_mask;
145 uint16_t x;
146 uint16_t y;
147 } M5_ATTR_PACKED;
148
149 struct ClientCutTextMessage {
150 uint8_t type;
151 uint8_t padding[3];
152 uint32_t length;
153 } M5_ATTR_PACKED;
154
155 typedef VncInputParams Params;
156 VncInput(const Params *p);
157
158 /** Set the address of the frame buffer we are going to show.
159 * To avoid copying, just have the display controller
160 * tell us where the data is instead of constanly copying it around
161 * @param rfb frame buffer that we're going to use
162 */
163 virtual void setFrameBuffer(const FrameBuffer *rfb);
164
165 /** Set up the device that would like to receive notifications when keys are
166 * pressed in the vnc client keyboard
167 * @param _keyboard an object that derrives from VncKeyboard
168 */
169 void setKeyboard(VncKeyboard *_keyboard) { keyboard = _keyboard; }
170
171 /** Setup the device that would like to receive notifications when mouse
172 * movements or button presses are received from the vnc client.
173 * @param _mouse an object that derrives from VncMouse
174 */
175 void setMouse(VncMouse *_mouse) { mouse = _mouse; }
176
177 /** What is the width of the screen we're displaying.
178 * This is used for pointer/tablet devices that need to know to calculate
179 * the correct value to send to the device driver.
180 * @return the width of the simulated screen
181 */
182 uint16_t videoWidth() const { return _videoWidth; }
183
184 /** What is the height of the screen we're displaying.
185 * This is used for pointer/tablet devices that need to know to calculate
186 * the correct value to send to the device driver.
187 * @return the height of the simulated screen
188 */
189 uint16_t videoHeight() const { return _videoHeight; }
190
191 /** The frame buffer uses this call to notify the vnc server that
192 * the frame buffer has been updated and a new image needs to be sent to the
193 * client
194 */
195 virtual void setDirty();
196
197 protected:
198 virtual void frameBufferResized() {};
199
200 /** The device to notify when we get key events */
201 VncKeyboard *keyboard;
202
203 /** The device to notify when we get mouse events */
204 VncMouse *mouse;
205
206 /** pointer to the actual data that is stored in the frame buffer device */
207 const FrameBuffer *fb;
208
209 /** the width of the frame buffer we are sending to the client */
210 uint16_t _videoWidth;
211
212 /** the height of the frame buffer we are sending to the client */
213 uint16_t _videoHeight;
214
215 /** Flag indicating whether to capture snapshots of frame buffer or not */
216 bool captureEnabled;
217
218 /** Current frame number being captured to a file */
219 int captureCurrentFrame;
220
221 /** Directory to store captured frames to */
57/**
58 * A device that expects to receive input from the vnc server should derrive
59 * (through mulitple inheritence if necessary from VncKeyboard or VncMouse
60 * and call setKeyboard() or setMouse() respectively on the vnc server.
61 */
62class VncKeyboard
63{
64 public:
65 /**
66 * Called when the vnc server receives a key press event from the
67 * client.
68 * @param key the key passed is an x11 keysym
69 * @param down is the key now down or up?
70 */
71 virtual void keyPress(uint32_t key, bool down) = 0;
72};
73
74class VncMouse
75{
76 public:
77 /**
78 * called whenever the mouse moves or it's button state changes
79 * buttons is a simple mask with each button (0-8) corresponding to
80 * a bit position in the byte with 1 being down and 0 being up
81 * @param x the x position of the mouse
82 * @param y the y position of the mouse
83 * @param buttos the button state as described above
84 */
85 virtual void mouseAt(uint16_t x, uint16_t y, uint8_t buttons) = 0;
86};
87
88class VncInput : public SimObject
89{
90 public:
91
92 /** Client -> Server message IDs */
93 enum ClientMessages {
94 ClientSetPixelFormat = 0,
95 ClientSetEncodings = 2,
96 ClientFrameBufferUpdate = 3,
97 ClientKeyEvent = 4,
98 ClientPointerEvent = 5,
99 ClientCutText = 6
100 };
101
102 struct PixelFormat {
103 uint8_t bpp;
104 uint8_t depth;
105 uint8_t bigendian;
106 uint8_t truecolor;
107 uint16_t redmax;
108 uint16_t greenmax;
109 uint16_t bluemax;
110 uint8_t redshift;
111 uint8_t greenshift;
112 uint8_t blueshift;
113 uint8_t padding[3];
114 } M5_ATTR_PACKED;
115
116 struct PixelFormatMessage {
117 uint8_t type;
118 uint8_t padding[3];
119 PixelFormat px;
120 } M5_ATTR_PACKED;
121
122 struct PixelEncodingsMessage {
123 uint8_t type;
124 uint8_t padding;
125 uint16_t num_encodings;
126 } M5_ATTR_PACKED;
127
128 struct FrameBufferUpdateReq {
129 uint8_t type;
130 uint8_t incremental;
131 uint16_t x;
132 uint16_t y;
133 uint16_t width;
134 uint16_t height;
135 } M5_ATTR_PACKED;
136
137 struct KeyEventMessage {
138 uint8_t type;
139 uint8_t down_flag;
140 uint8_t padding[2];
141 uint32_t key;
142 } M5_ATTR_PACKED;
143
144 struct PointerEventMessage {
145 uint8_t type;
146 uint8_t button_mask;
147 uint16_t x;
148 uint16_t y;
149 } M5_ATTR_PACKED;
150
151 struct ClientCutTextMessage {
152 uint8_t type;
153 uint8_t padding[3];
154 uint32_t length;
155 } M5_ATTR_PACKED;
156
157 typedef VncInputParams Params;
158 VncInput(const Params *p);
159
160 /** Set the address of the frame buffer we are going to show.
161 * To avoid copying, just have the display controller
162 * tell us where the data is instead of constanly copying it around
163 * @param rfb frame buffer that we're going to use
164 */
165 virtual void setFrameBuffer(const FrameBuffer *rfb);
166
167 /** Set up the device that would like to receive notifications when keys are
168 * pressed in the vnc client keyboard
169 * @param _keyboard an object that derrives from VncKeyboard
170 */
171 void setKeyboard(VncKeyboard *_keyboard) { keyboard = _keyboard; }
172
173 /** Setup the device that would like to receive notifications when mouse
174 * movements or button presses are received from the vnc client.
175 * @param _mouse an object that derrives from VncMouse
176 */
177 void setMouse(VncMouse *_mouse) { mouse = _mouse; }
178
179 /** What is the width of the screen we're displaying.
180 * This is used for pointer/tablet devices that need to know to calculate
181 * the correct value to send to the device driver.
182 * @return the width of the simulated screen
183 */
184 uint16_t videoWidth() const { return _videoWidth; }
185
186 /** What is the height of the screen we're displaying.
187 * This is used for pointer/tablet devices that need to know to calculate
188 * the correct value to send to the device driver.
189 * @return the height of the simulated screen
190 */
191 uint16_t videoHeight() const { return _videoHeight; }
192
193 /** The frame buffer uses this call to notify the vnc server that
194 * the frame buffer has been updated and a new image needs to be sent to the
195 * client
196 */
197 virtual void setDirty();
198
199 protected:
200 virtual void frameBufferResized() {};
201
202 /** The device to notify when we get key events */
203 VncKeyboard *keyboard;
204
205 /** The device to notify when we get mouse events */
206 VncMouse *mouse;
207
208 /** pointer to the actual data that is stored in the frame buffer device */
209 const FrameBuffer *fb;
210
211 /** the width of the frame buffer we are sending to the client */
212 uint16_t _videoWidth;
213
214 /** the height of the frame buffer we are sending to the client */
215 uint16_t _videoHeight;
216
217 /** Flag indicating whether to capture snapshots of frame buffer or not */
218 bool captureEnabled;
219
220 /** Current frame number being captured to a file */
221 int captureCurrentFrame;
222
223 /** Directory to store captured frames to */
222 std::string captureOutputDirectory;
224 OutputDirectory *captureOutputDirectory;
223
224 /** Computed hash of the last captured frame */
225 uint64_t captureLastHash;
226
227 /** Cached bitmap object for writing out frame buffers to file */
228 std::unique_ptr<Bitmap> captureBitmap;
229
230 /** Captures the current frame buffer to a file */
231 void captureFrameBuffer();
232};
233#endif
225
226 /** Computed hash of the last captured frame */
227 uint64_t captureLastHash;
228
229 /** Cached bitmap object for writing out frame buffers to file */
230 std::unique_ptr<Bitmap> captureBitmap;
231
232 /** Captures the current frame buffer to a file */
233 void captureFrameBuffer();
234};
235#endif