1 | /* $Id: FramebufferVNC.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxHeadless - VNC server implementation for VirtualBox.
|
---|
4 | *
|
---|
5 | * Uses LibVNCServer (http://sourceforge.net/projects/libvncserver/)
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Contributed by Ivo Smits <[email protected]>
|
---|
10 | *
|
---|
11 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
12 | *
|
---|
13 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
14 | * available from http://www.virtualbox.org. This file is free software;
|
---|
15 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
16 | * General Public License (GPL) as published by the Free Software
|
---|
17 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
18 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
19 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "FramebufferVNC.h"
|
---|
23 |
|
---|
24 | #include <iprt/assert.h>
|
---|
25 | #include <iprt/mem.h>
|
---|
26 | #include <VBox/log.h>
|
---|
27 | #include <iprt/param.h>
|
---|
28 | #include <iprt/stream.h>
|
---|
29 | #include <iprt/thread.h>
|
---|
30 |
|
---|
31 | #include <png.h>
|
---|
32 | #include <rfb/rfb.h>
|
---|
33 |
|
---|
34 | // constructor / destructor
|
---|
35 | /////////////////////////////////////////////////////////////////////////////
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Perform parts of initialisation which are guaranteed not to fail
|
---|
39 | * unless we run out of memory. In this case, we just set the guest
|
---|
40 | * buffer to 0 so that RequestResize() does not free it the first time
|
---|
41 | * it is called.
|
---|
42 | */
|
---|
43 | VNCFB::VNCFB(ComPtr <IConsole> console, int port, const char *password) :
|
---|
44 | mPixelFormat(FramebufferPixelFormat_Opaque),
|
---|
45 | mBitsPerPixel(0),
|
---|
46 | mBytesPerLine(0),
|
---|
47 | mRGBBuffer(0),
|
---|
48 | mScreenBuffer(0),
|
---|
49 | mVncPort(port),
|
---|
50 | mConsole(console),
|
---|
51 | mKeyboard(0),
|
---|
52 | mMouse(0),
|
---|
53 | mWidth(800), mHeight(600),
|
---|
54 | vncServer(0),
|
---|
55 | mVncPassword(password)
|
---|
56 | {
|
---|
57 | LogFlow(("Creating VNC object %p, width=%u, height=%u, port=%u\n",
|
---|
58 | this, mWidth, mHeight, mVncPort));
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | VNCFB::~VNCFB() {
|
---|
63 | LogFlow(("Destroying VNCFB object %p\n", this));
|
---|
64 | RTCritSectDelete(&mCritSect);
|
---|
65 | if (vncServer) {
|
---|
66 | if (vncServer->authPasswdData) {
|
---|
67 | char **papszPassword = (char **)vncServer->authPasswdData;
|
---|
68 | vncServer->authPasswdData = NULL;
|
---|
69 | RTMemFree(papszPassword[0]);
|
---|
70 | RTMemFree(papszPassword);
|
---|
71 | }
|
---|
72 | rfbScreenCleanup(vncServer);
|
---|
73 | }
|
---|
74 | RTMemFree(mRGBBuffer);
|
---|
75 | mRGBBuffer = NULL;
|
---|
76 | RTMemFree(mScreenBuffer);
|
---|
77 | mScreenBuffer = NULL;
|
---|
78 | }
|
---|
79 |
|
---|
80 | HRESULT VNCFB::init() {
|
---|
81 | LogFlow(("Initialising VNCFB object %p\n", this));
|
---|
82 | int rc = RTCritSectInit(&mCritSect);
|
---|
83 | AssertReturn(rc == VINF_SUCCESS, E_UNEXPECTED);
|
---|
84 |
|
---|
85 | vncServer = rfbGetScreen(0, NULL, mWidth, mHeight, 8, 3, 1);
|
---|
86 | vncServer->screenData = (void*)this;
|
---|
87 | if (mVncPort) vncServer->port = mVncPort;
|
---|
88 | vncServer->desktopName = "VirtualBox";
|
---|
89 |
|
---|
90 | if (mVncPassword) {
|
---|
91 | char **papszPasswords = (char **)RTMemAlloc(2 * sizeof(char **));
|
---|
92 | papszPasswords[0] = RTStrDup(mVncPassword);
|
---|
93 | papszPasswords[1] = NULL;
|
---|
94 | vncServer->authPasswdData = papszPasswords;
|
---|
95 | vncServer->passwordCheck = rfbCheckPasswordByList; //Password list based authentication function
|
---|
96 | } else {
|
---|
97 | vncServer->authPasswdData = NULL;
|
---|
98 | }
|
---|
99 |
|
---|
100 | rfbInitServer(vncServer);
|
---|
101 | vncServer->kbdAddEvent = vncKeyboardEvent;
|
---|
102 | vncServer->kbdReleaseAllKeys = vncReleaseKeysEvent;
|
---|
103 | vncServer->ptrAddEvent = vncMouseEvent;
|
---|
104 |
|
---|
105 | /* Set the initial framebuffer size */
|
---|
106 | BOOL finished;
|
---|
107 | RequestResize(0, FramebufferPixelFormat_Opaque, NULL, 0, 0, mWidth, mHeight, &finished);
|
---|
108 |
|
---|
109 | rc = RTThreadCreate(&mVncThread, vncThreadFn, vncServer,
|
---|
110 | 0 /*cbStack*/, RTTHREADTYPE_GUI, 0 /*fFlags*/, "VNC");
|
---|
111 | AssertRCReturn(rc, E_UNEXPECTED);
|
---|
112 |
|
---|
113 | return S_OK;
|
---|
114 | }
|
---|
115 |
|
---|
116 | DECLCALLBACK(int) VNCFB::vncThreadFn(RTTHREAD hThreadSelf, void *pvUser)
|
---|
117 | {
|
---|
118 | rfbRunEventLoop((rfbScreenInfoPtr)pvUser, -1, FALSE);
|
---|
119 | return VINF_SUCCESS;
|
---|
120 | }
|
---|
121 |
|
---|
122 | void VNCFB::vncMouseEvent(int buttonMask, int x, int y, rfbClientPtr cl) {
|
---|
123 | ((VNCFB*)(cl->screen->screenData))->handleVncMouseEvent(buttonMask, x, y);
|
---|
124 | rfbDefaultPtrAddEvent(buttonMask, x, y, cl);
|
---|
125 | }
|
---|
126 |
|
---|
127 | void VNCFB::handleVncMouseEvent(int buttonMask, int x, int y) {
|
---|
128 | //RTPrintf("VNC mouse: button=%d x=%d y=%d\n", buttonMask, x, y);
|
---|
129 | if (!mMouse) {
|
---|
130 | this->mConsole->COMGETTER(Mouse)(mMouse.asOutParam());
|
---|
131 | if (!mMouse) {
|
---|
132 | RTPrintf("Warning: could not get mouse object!\n");
|
---|
133 | return;
|
---|
134 | }
|
---|
135 | }
|
---|
136 | int dz = 0, buttons = 0;
|
---|
137 | if (buttonMask & 16) dz = 1; else if (buttonMask & 8) dz = -1;
|
---|
138 | if (buttonMask & 1) buttons |= 1;
|
---|
139 | if (buttonMask & 2) buttons |= 4;
|
---|
140 | if (buttonMask & 4) buttons |= 2;
|
---|
141 | mMouse->PutMouseEvent(x - mouseX, y - mouseY, dz, 0, buttons);
|
---|
142 | //mMouse->PutMouseEventAbsolute(x + 1, y + 1, dz, 0, buttonMask);
|
---|
143 | mouseX = x;
|
---|
144 | mouseY = y;
|
---|
145 | }
|
---|
146 |
|
---|
147 | void VNCFB::kbdPutCode(int code) {
|
---|
148 | mKeyboard->PutScancode(code);
|
---|
149 | }
|
---|
150 | void VNCFB::kbdSetShift(int state) {
|
---|
151 | if (state && !kbdShiftState) {
|
---|
152 | kbdPutCode(0x2a, 1);
|
---|
153 | kbdShiftState = 1;
|
---|
154 | } else if (!state && kbdShiftState) {
|
---|
155 | kbdPutCode(0x2a, 0);
|
---|
156 | kbdShiftState = 0;
|
---|
157 | }
|
---|
158 | }
|
---|
159 | void VNCFB::kbdPutCode(int code, int down) {
|
---|
160 | if (code & 0xff00) kbdPutCode((code >> 8) & 0xff);
|
---|
161 | kbdPutCode((code & 0xff) | (down ? 0 : 0x80));
|
---|
162 | }
|
---|
163 | void VNCFB::kbdPutCodeShift(int shift, int code, int down) {
|
---|
164 | if (shift != kbdShiftState) kbdPutCode(0x2a, shift);
|
---|
165 | kbdPutCode(code, down);
|
---|
166 | if (shift != kbdShiftState) kbdPutCode(0x2a, kbdShiftState);
|
---|
167 | }
|
---|
168 |
|
---|
169 | /* Handle VNC keyboard code (X11 compatible?) to AT scancode conversion.
|
---|
170 | * Have tried the code from the SDL frontend, but that didn't work.
|
---|
171 | * Now we're using one lookup table for the lower X11 key codes (ASCII characters)
|
---|
172 | * and a switch() block to handle some special keys. */
|
---|
173 | void VNCFB::handleVncKeyboardEvent(int down, int keycode) {
|
---|
174 | //RTPrintf("VNC keyboard: down=%d code=%d -> ", down, keycode);
|
---|
175 | if (mKeyboard == NULL) {
|
---|
176 | this->mConsole->COMGETTER(Keyboard)(mKeyboard.asOutParam());
|
---|
177 | if (!mKeyboard) {
|
---|
178 | RTPrintf("Warning: could not get keyboard object!\n");
|
---|
179 | return;
|
---|
180 | }
|
---|
181 | }
|
---|
182 | /* Conversion table for key code range 32-127 (which happen to equal the ASCII codes)
|
---|
183 | * The values in the table differ slightly from the actual scancode values that will be sent,
|
---|
184 | * values 0xe0?? indicate that a 0xe0 scancode will be sent first (extended keys), then code ?? is sent
|
---|
185 | * values 0x01?? indicate that the shift key must be 'down', then ?? is sent
|
---|
186 | * values 0x00?? or 0x?? indicate that the shift key must be 'up', then ?? is sent
|
---|
187 | * values 0x02?? indicate that the shift key can be ignored, and scancode ?? is sent
|
---|
188 | * This is necessary because the VNC protocol sends a shift key sequence, but also
|
---|
189 | * sends the 'shifted' version of the characters. */
|
---|
190 | static int codes_low[] = { //Conversion table for VNC key code range 32-127
|
---|
191 | 0x0239, 0x0102, 0x0128, 0x0104, 0x0105, 0x0106, 0x0108, 0x0028, 0x010a, 0x010b, 0x0109, 0x010d, 0x0029, 0x000c, 0x0034, 0x0035, //space, !"#$%&'()*+`-./
|
---|
192 | 0x0b, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, //0123456789
|
---|
193 | 0x0127, 0x0027, 0x0133, 0x000d, 0x0134, 0x0135, 0x0103, //:;<=>?@
|
---|
194 | 0x11e, 0x130, 0x12e, 0x120, 0x112, 0x121, 0x122, 0x123, 0x117, 0x124, 0x125, 0x126, 0x132, 0x131, 0x118, 0x119, 0x110, 0x113, 0x11f, 0x114, 0x116, 0x12f, 0x111, 0x12d, 0x115, 0x12c, //A-Z
|
---|
195 | 0x001a, 0x002b, 0x001b, 0x0107, 0x010c, 0x0029, //[\]^_`
|
---|
196 | 0x1e, 0x30, 0x2e, 0x20, 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1f, 0x14, 0x16, 0x2f, 0x11, 0x2d, 0x15, 0x2c, //a-z
|
---|
197 | 0x011a, 0x012b, 0x011b, 0x0129 //{|}~
|
---|
198 | };
|
---|
199 | int shift = -1, code = -1;
|
---|
200 | if (keycode < 32) { //ASCII control codes.. unused..
|
---|
201 | } else if (keycode < 127) { //DEL is in high area
|
---|
202 | code = codes_low[keycode - 32];
|
---|
203 | shift = (code >> 8) & 0x03; if (shift == 0x02 || code & 0xe000) shift = -1;
|
---|
204 | code = code & 0xe0ff;
|
---|
205 | } else if ((keycode & 0xFF00) != 0xFF00) {
|
---|
206 | } else {
|
---|
207 | switch(keycode) {
|
---|
208 | /*Numpad keys - these have to be implemented yet
|
---|
209 | Todo: numpad arrows, home, pageup, pagedown, end, insert, delete
|
---|
210 | 65421 Numpad return
|
---|
211 |
|
---|
212 | 65450 Numpad *
|
---|
213 | 65451 Numpad +
|
---|
214 | 65453 Numpad -
|
---|
215 | 65454 Numpad .
|
---|
216 | 65455 Numpad /
|
---|
217 | 65457 Numpad 1
|
---|
218 | 65458 Numpad 2
|
---|
219 | 65459 Numpad 3
|
---|
220 |
|
---|
221 | 65460 Numpad 4
|
---|
222 | 65461 Numpad 5
|
---|
223 | 65462 Numpad 6
|
---|
224 | 65463 Numpad 7
|
---|
225 | 65464 Numpad 8
|
---|
226 | 65465 Numpad 9
|
---|
227 | 65456 Numpad 0
|
---|
228 | */
|
---|
229 | case 65288: code = 0x0e; break; //Backspace
|
---|
230 | case 65289: code = 0x0f; break; //Tab
|
---|
231 |
|
---|
232 | case 65293: code = 0x1c; break; //Return
|
---|
233 | //case 65299: break; Pause/break
|
---|
234 | case 65307: code = 0x01; break; //Escape
|
---|
235 |
|
---|
236 | case 65360: code = 0xe047; break; //Home
|
---|
237 | case 65361: code = 0xe04b; break; //Left
|
---|
238 | case 65362: code = 0xe048; break; //Up
|
---|
239 | case 65363: code = 0xe04d; break; //Right
|
---|
240 | case 65364: code = 0xe050; break; //Down
|
---|
241 | case 65365: code = 0xe049; break; //Page up
|
---|
242 | case 65366: code = 0xe051; break; //Page down
|
---|
243 | case 65367: code = 0xe04f; break; //End
|
---|
244 |
|
---|
245 | //case 65377: break; //Print screen
|
---|
246 | case 65379: code = 0xe052; break; //Insert
|
---|
247 |
|
---|
248 | case 65383: code = 0xe05d; break; //Menu
|
---|
249 |
|
---|
250 | case 65470: code = 0x3b; break; //F1
|
---|
251 | case 65471: code = 0x3c; break; //F2
|
---|
252 | case 65472: code = 0x3d; break; //F3
|
---|
253 | case 65473: code = 0x3e; break; //F4
|
---|
254 | case 65474: code = 0x3f; break; //F5
|
---|
255 | case 65475: code = 0x40; break; //F6
|
---|
256 | case 65476: code = 0x41; break; //F7
|
---|
257 | case 65477: code = 0x42; break; //F8
|
---|
258 | case 65478: code = 0x43; break; //F9
|
---|
259 | case 65479: code = 0x44; break; //F10
|
---|
260 | case 65480: code = 0x57; break; //F11
|
---|
261 | case 65481: code = 0x58; break; //F12
|
---|
262 |
|
---|
263 | case 65505: shift = down; break; //Shift (left + right)
|
---|
264 | case 65507: code = 0x1d; break; //Left ctrl
|
---|
265 | case 65508: code = 0xe01d; break; //Right ctrl
|
---|
266 | case 65513: code = 0x38; break; //Left Alt
|
---|
267 | case 65514: code = 0xe038; break; //Right Alt
|
---|
268 | case 65515: code = 0xe05b; break; //Left windows key
|
---|
269 | case 65516: code = 0xe05c; break; //Right windows key
|
---|
270 | case 65535: code = 0xe053; break; //Delete
|
---|
271 | default: RTPrintf("VNC unhandled keyboard code: down=%d code=%d\n", down, keycode); break;
|
---|
272 | }
|
---|
273 | }
|
---|
274 | //RTPrintf("down=%d shift=%d code=%d\n", down, shift, code);
|
---|
275 | if (shift != -1 && code != -1) {
|
---|
276 | kbdPutCodeShift(shift, code, down);
|
---|
277 | } else if (shift != -1) {
|
---|
278 | kbdSetShift(shift);
|
---|
279 | } else if (code != -1) {
|
---|
280 | kbdPutCode(code, down);
|
---|
281 | }
|
---|
282 | }
|
---|
283 | void VNCFB::handleVncKeyboardReleaseEvent() {
|
---|
284 | kbdSetShift(0);
|
---|
285 | kbdPutCode(0x1d, 0); //Left ctrl
|
---|
286 | kbdPutCode(0xe01d, 0); //Right ctrl
|
---|
287 | kbdPutCode(0x38, 0); //Left alt
|
---|
288 | kbdPutCode(0xe038, 0); //Right alt
|
---|
289 | }
|
---|
290 |
|
---|
291 | void VNCFB::vncKeyboardEvent(rfbBool down, rfbKeySym keySym, rfbClientPtr cl) {
|
---|
292 | ((VNCFB*)(cl->screen->screenData))->handleVncKeyboardEvent(down, keySym);
|
---|
293 | }
|
---|
294 | void VNCFB::vncReleaseKeysEvent(rfbClientPtr cl) { //Release modifier keys
|
---|
295 | ((VNCFB*)(cl->screen->screenData))->handleVncKeyboardReleaseEvent();
|
---|
296 | }
|
---|
297 |
|
---|
298 | // IFramebuffer properties
|
---|
299 | /////////////////////////////////////////////////////////////////////////////
|
---|
300 | /**
|
---|
301 | * Requests a resize of our "screen".
|
---|
302 | *
|
---|
303 | * @returns COM status code
|
---|
304 | * @param pixelFormat Layout of the guest video RAM (i.e. 16, 24,
|
---|
305 | * 32 bpp)
|
---|
306 | * @param vram host context pointer to the guest video RAM,
|
---|
307 | * in case we can cope with the format
|
---|
308 | * @param bitsPerPixel color depth of the guest video RAM
|
---|
309 | * @param bytesPerLine length of a screen line in the guest video RAM
|
---|
310 | * @param w video mode width in pixels
|
---|
311 | * @param h video mode height in pixels
|
---|
312 | * @retval finished set to true if the method is synchronous and
|
---|
313 | * to false otherwise
|
---|
314 | *
|
---|
315 | * This method is called when the guest attempts to resize the virtual
|
---|
316 | * screen. The pointer to the guest's video RAM is supplied in case
|
---|
317 | * the framebuffer can handle the pixel format. If it can't, it should
|
---|
318 | * allocate a memory buffer itself, and the virtual VGA device will copy
|
---|
319 | * the guest VRAM to that in a format we can handle. The
|
---|
320 | * COMGETTER(UsesGuestVRAM) method is used to tell the VGA device which method
|
---|
321 | * we have chosen, and the other COMGETTER methods tell the device about
|
---|
322 | * the layout of our buffer. We currently handle all VRAM layouts except
|
---|
323 | * FramebufferPixelFormat_Opaque (which cannot be handled by
|
---|
324 | * definition).
|
---|
325 | */
|
---|
326 | STDMETHODIMP VNCFB::RequestResize(ULONG aScreenId, ULONG pixelFormat,
|
---|
327 | BYTE *vram, ULONG bitsPerPixel,
|
---|
328 | ULONG bytesPerLine,
|
---|
329 | ULONG w, ULONG h, BOOL *finished) {
|
---|
330 | NOREF(aScreenId);
|
---|
331 | if (!finished) return E_POINTER;
|
---|
332 |
|
---|
333 | /* For now, we are doing things synchronously */
|
---|
334 | *finished = true;
|
---|
335 |
|
---|
336 | if (mRGBBuffer) RTMemFree(mRGBBuffer);
|
---|
337 |
|
---|
338 | mWidth = w;
|
---|
339 | mHeight = h;
|
---|
340 |
|
---|
341 | if (pixelFormat == FramebufferPixelFormat_FOURCC_RGB && bitsPerPixel == 32) {
|
---|
342 | mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
|
---|
343 | mBufferAddress = reinterpret_cast<uint8_t *>(vram);
|
---|
344 | mBytesPerLine = bytesPerLine;
|
---|
345 | mBitsPerPixel = bitsPerPixel;
|
---|
346 | mRGBBuffer = NULL;
|
---|
347 | } else {
|
---|
348 | mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
|
---|
349 | mBytesPerLine = w * 4;
|
---|
350 | mBitsPerPixel = 32;
|
---|
351 | mRGBBuffer = reinterpret_cast<uint8_t *>(RTMemAlloc(mBytesPerLine * h));
|
---|
352 | AssertReturn(mRGBBuffer != 0, E_OUTOFMEMORY);
|
---|
353 | mBufferAddress = mRGBBuffer;
|
---|
354 | }
|
---|
355 |
|
---|
356 | uint8_t *oldBuffer = mScreenBuffer;
|
---|
357 | mScreenBuffer = reinterpret_cast<uint8_t *>(RTMemAlloc(mBytesPerLine * h));
|
---|
358 | AssertReturn(mScreenBuffer != 0, E_OUTOFMEMORY);
|
---|
359 |
|
---|
360 | for (ULONG i = 0; i < mBytesPerLine * h; i += 4) {
|
---|
361 | mScreenBuffer[i] = mBufferAddress[i+2];
|
---|
362 | mScreenBuffer[i+1] = mBufferAddress[i+1];
|
---|
363 | mScreenBuffer[i+2] = mBufferAddress[i];
|
---|
364 | }
|
---|
365 |
|
---|
366 | RTPrintf("Set framebuffer: buffer=%d w=%lu h=%lu bpp=%d\n", mBufferAddress, mWidth, mHeight, (int)mBitsPerPixel);
|
---|
367 | rfbNewFramebuffer(vncServer, (char*)mScreenBuffer, mWidth, mHeight, 8, 3, mBitsPerPixel / 8);
|
---|
368 | if (oldBuffer) RTMemFree(oldBuffer);
|
---|
369 | return S_OK;
|
---|
370 | }
|
---|
371 |
|
---|
372 | //Guest framebuffer update notification
|
---|
373 | STDMETHODIMP VNCFB::NotifyUpdate(ULONG x, ULONG y, ULONG w, ULONG h) {
|
---|
374 | if (!mBufferAddress || !mScreenBuffer) return S_OK;
|
---|
375 | ULONG joff = y * mBytesPerLine + x * 4;
|
---|
376 | for (ULONG j = joff; j < joff + h * mBytesPerLine; j += mBytesPerLine)
|
---|
377 | for (ULONG i = j; i < j + w * 4; i += 4) {
|
---|
378 | mScreenBuffer[i] = mBufferAddress[i+2];
|
---|
379 | mScreenBuffer[i+1] = mBufferAddress[i+1];
|
---|
380 | mScreenBuffer[i+2] = mBufferAddress[i];
|
---|
381 | }
|
---|
382 | rfbMarkRectAsModified(vncServer, x, y, x+w, y+h);
|
---|
383 | return S_OK;
|
---|
384 | }
|
---|
385 |
|
---|
386 |
|
---|
387 |
|
---|
388 |
|
---|
389 | /**
|
---|
390 | * Return the address of the frame buffer for the virtual VGA device to
|
---|
391 | * write to. If COMGETTER(UsesGuestVRAM) returns FLASE (or if this address
|
---|
392 | * is not the same as the guests VRAM buffer), the device will perform
|
---|
393 | * translation.
|
---|
394 | *
|
---|
395 | * @returns COM status code
|
---|
396 | * @retval address The address of the buffer
|
---|
397 | */
|
---|
398 | STDMETHODIMP VNCFB::COMGETTER(Address) (BYTE **address) {
|
---|
399 | if (!address) return E_POINTER;
|
---|
400 | LogFlow(("FFmpeg::COMGETTER(Address): returning address %p\n", mBufferAddress));
|
---|
401 | *address = mBufferAddress;
|
---|
402 | return S_OK;
|
---|
403 | }
|
---|
404 |
|
---|
405 | /**
|
---|
406 | * Return the width of our frame buffer.
|
---|
407 | *
|
---|
408 | * @returns COM status code
|
---|
409 | * @retval width The width of the frame buffer
|
---|
410 | */
|
---|
411 | STDMETHODIMP VNCFB::COMGETTER(Width) (ULONG *width) {
|
---|
412 | if (!width) return E_POINTER;
|
---|
413 | LogFlow(("FFmpeg::COMGETTER(Width): returning width %lu\n", (unsigned long) mWidth));
|
---|
414 | *width = mWidth;
|
---|
415 | return S_OK;
|
---|
416 | }
|
---|
417 |
|
---|
418 | /**
|
---|
419 | * Return the height of our frame buffer.
|
---|
420 | *
|
---|
421 | * @returns COM status code
|
---|
422 | * @retval height The height of the frame buffer
|
---|
423 | */
|
---|
424 | STDMETHODIMP VNCFB::COMGETTER(Height) (ULONG *height) {
|
---|
425 | if (!height) return E_POINTER;
|
---|
426 | LogFlow(("FFmpeg::COMGETTER(Height): returning height %lu\n", (unsigned long) mHeight));
|
---|
427 | *height = mHeight;
|
---|
428 | return S_OK;
|
---|
429 | }
|
---|
430 |
|
---|
431 | /**
|
---|
432 | * Return the colour depth of our frame buffer. Note that we actually
|
---|
433 | * store the pixel format, not the colour depth internally, since
|
---|
434 | * when display sets FramebufferPixelFormat_Opaque, it
|
---|
435 | * wants to retreive FramebufferPixelFormat_Opaque and
|
---|
436 | * nothing else.
|
---|
437 | *
|
---|
438 | * @returns COM status code
|
---|
439 | * @retval bitsPerPixel The colour depth of the frame buffer
|
---|
440 | */
|
---|
441 | STDMETHODIMP VNCFB::COMGETTER(BitsPerPixel) (ULONG *bitsPerPixel) {
|
---|
442 | if (!bitsPerPixel) return E_POINTER;
|
---|
443 | *bitsPerPixel = mBitsPerPixel;
|
---|
444 | LogFlow(("FFmpeg::COMGETTER(BitsPerPixel): returning depth %lu\n",
|
---|
445 | (unsigned long) *bitsPerPixel));
|
---|
446 | return S_OK;
|
---|
447 | }
|
---|
448 |
|
---|
449 | /**
|
---|
450 | * Return the number of bytes per line in our frame buffer.
|
---|
451 | *
|
---|
452 | * @returns COM status code
|
---|
453 | * @retval bytesPerLine The number of bytes per line
|
---|
454 | */
|
---|
455 | STDMETHODIMP VNCFB::COMGETTER(BytesPerLine) (ULONG *bytesPerLine) {
|
---|
456 | if (!bytesPerLine) return E_POINTER;
|
---|
457 | LogFlow(("FFmpeg::COMGETTER(BytesPerLine): returning line size %lu\n", (unsigned long) mBytesPerLine));
|
---|
458 | *bytesPerLine = mBytesPerLine;
|
---|
459 | return S_OK;
|
---|
460 | }
|
---|
461 |
|
---|
462 | /**
|
---|
463 | * Return the pixel layout of our frame buffer.
|
---|
464 | *
|
---|
465 | * @returns COM status code
|
---|
466 | * @retval pixelFormat The pixel layout
|
---|
467 | */
|
---|
468 | STDMETHODIMP VNCFB::COMGETTER(PixelFormat) (ULONG *pixelFormat) {
|
---|
469 | if (!pixelFormat) return E_POINTER;
|
---|
470 | LogFlow(("FFmpeg::COMGETTER(PixelFormat): returning pixel format: %lu\n", (unsigned long) mPixelFormat));
|
---|
471 | *pixelFormat = mPixelFormat;
|
---|
472 | return S_OK;
|
---|
473 | }
|
---|
474 |
|
---|
475 | /**
|
---|
476 | * Return whether we use the guest VRAM directly.
|
---|
477 | *
|
---|
478 | * @returns COM status code
|
---|
479 | * @retval pixelFormat The pixel layout
|
---|
480 | */
|
---|
481 | STDMETHODIMP VNCFB::COMGETTER(UsesGuestVRAM) (BOOL *usesGuestVRAM) {
|
---|
482 | if (!usesGuestVRAM) return E_POINTER;
|
---|
483 | LogFlow(("FFmpeg::COMGETTER(UsesGuestVRAM): uses guest VRAM? %d\n", mRGBBuffer == NULL));
|
---|
484 | *usesGuestVRAM = (mRGBBuffer == NULL);
|
---|
485 | return S_OK;
|
---|
486 | }
|
---|
487 |
|
---|
488 | /**
|
---|
489 | * Return the number of lines of our frame buffer which can not be used
|
---|
490 | * (e.g. for status lines etc?).
|
---|
491 | *
|
---|
492 | * @returns COM status code
|
---|
493 | * @retval heightReduction The number of unused lines
|
---|
494 | */
|
---|
495 | STDMETHODIMP VNCFB::COMGETTER(HeightReduction) (ULONG *heightReduction) {
|
---|
496 | if (!heightReduction) return E_POINTER;
|
---|
497 | /* no reduction */
|
---|
498 | *heightReduction = 0;
|
---|
499 | LogFlow(("FFmpeg::COMGETTER(HeightReduction): returning 0\n"));
|
---|
500 | return S_OK;
|
---|
501 | }
|
---|
502 |
|
---|
503 | /**
|
---|
504 | * Return a pointer to the alpha-blended overlay used to render status icons
|
---|
505 | * etc above the framebuffer.
|
---|
506 | *
|
---|
507 | * @returns COM status code
|
---|
508 | * @retval aOverlay The overlay framebuffer
|
---|
509 | */
|
---|
510 | STDMETHODIMP VNCFB::COMGETTER(Overlay) (IFramebufferOverlay **aOverlay) {
|
---|
511 | if (!aOverlay) return E_POINTER;
|
---|
512 | /* not yet implemented */
|
---|
513 | *aOverlay = 0;
|
---|
514 | LogFlow(("FFmpeg::COMGETTER(Overlay): returning 0\n"));
|
---|
515 | return S_OK;
|
---|
516 | }
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * Return id of associated window
|
---|
520 | *
|
---|
521 | * @returns COM status code
|
---|
522 | * @retval winId Associated window id
|
---|
523 | */
|
---|
524 | STDMETHODIMP VNCFB::COMGETTER(WinId) (ULONG64 *winId) {
|
---|
525 | if (!winId) return E_POINTER;
|
---|
526 | *winId = 0;
|
---|
527 | return S_OK;
|
---|
528 | }
|
---|
529 |
|
---|
530 | // IFramebuffer methods
|
---|
531 | /////////////////////////////////////////////////////////////////////////////
|
---|
532 |
|
---|
533 | STDMETHODIMP VNCFB::Lock() {
|
---|
534 | LogFlow(("VNCFB::Lock: called\n"));
|
---|
535 | int rc = RTCritSectEnter(&mCritSect);
|
---|
536 | AssertRC(rc);
|
---|
537 | if (rc == VINF_SUCCESS) return S_OK;
|
---|
538 | return E_UNEXPECTED;
|
---|
539 | }
|
---|
540 |
|
---|
541 | STDMETHODIMP VNCFB::Unlock() {
|
---|
542 | LogFlow(("VNCFB::Unlock: called\n"));
|
---|
543 | RTCritSectLeave(&mCritSect);
|
---|
544 | return S_OK;
|
---|
545 | }
|
---|
546 |
|
---|
547 |
|
---|
548 | /**
|
---|
549 | * Returns whether we like the given video mode.
|
---|
550 | *
|
---|
551 | * @returns COM status code
|
---|
552 | */
|
---|
553 | STDMETHODIMP VNCFB::VideoModeSupported(ULONG width, ULONG height, ULONG bpp, BOOL *supported) {
|
---|
554 | if (!supported) return E_POINTER;
|
---|
555 | *supported = true;
|
---|
556 | return S_OK;
|
---|
557 | }
|
---|
558 |
|
---|
559 | /** Stubbed */
|
---|
560 | STDMETHODIMP VNCFB::GetVisibleRegion(BYTE *rectangles, ULONG /* count */, ULONG * /* countCopied */) {
|
---|
561 | if (!rectangles) return E_POINTER;
|
---|
562 | *rectangles = 0;
|
---|
563 | return S_OK;
|
---|
564 | }
|
---|
565 |
|
---|
566 | /** Stubbed */
|
---|
567 | STDMETHODIMP VNCFB::SetVisibleRegion(BYTE *rectangles, ULONG /* count */) {
|
---|
568 | if (!rectangles) return E_POINTER;
|
---|
569 | return S_OK;
|
---|
570 | }
|
---|
571 |
|
---|
572 | STDMETHODIMP VNCFB::ProcessVHWACommand(BYTE *pCommand) {
|
---|
573 | return E_NOTIMPL;
|
---|
574 | }
|
---|
575 |
|
---|
576 | #ifdef VBOX_WITH_XPCOM
|
---|
577 | NS_DECL_CLASSINFO(VNCFB)
|
---|
578 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VNCFB, IFramebuffer)
|
---|
579 | #endif
|
---|
580 |
|
---|