1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/* $Id: FramebufferVNC.h 28800 2010-04-27 08:22:32Z vboxsync $ */
/** @file
* VBox Remote Desktop Protocol - VNC server interface.
*/
/*
* Contributed by Ivo Smits <Ivo@UFO-Net.nl>
*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <VBox/com/VirtualBox.h>
#include <iprt/uuid.h>
#include <VBox/com/com.h>
#include <VBox/com/string.h>
#include <iprt/initterm.h>
#include <iprt/critsect.h>
#include <rfb/rfb.h>
#include <pthread.h>
class VNCFB : VBOX_SCRIPTABLE_IMPL(IFramebuffer)
{
public:
VNCFB(ComPtr <IConsole> console, int port, char const *password);
virtual ~VNCFB();
#ifndef VBOX_WITH_XPCOM
STDMETHOD_(ULONG, AddRef)() {
return ::InterlockedIncrement (&refcnt);
}
STDMETHOD_(ULONG, Release)() {
long cnt = ::InterlockedDecrement (&refcnt);
if (cnt == 0) delete this;
return cnt;
}
#endif
VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
NS_DECL_ISUPPORTS
// public methods only for internal purposes
HRESULT init ();
STDMETHOD(COMGETTER(Width))(ULONG *width);
STDMETHOD(COMGETTER(Height))(ULONG *height);
STDMETHOD(Lock)();
STDMETHOD(Unlock)();
STDMETHOD(COMGETTER(Address))(BYTE **address);
STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
STDMETHOD(COMGETTER(WinId)) (ULONG64 *winId);
STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
ULONG bitsPerPixel, ULONG bytesPerLine,
ULONG w, ULONG h, BOOL *finished);
STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
STDMETHOD(GetVisibleRegion)(BYTE *rectangles, ULONG count, ULONG *countCopied);
STDMETHOD(SetVisibleRegion)(BYTE *rectangles, ULONG count);
STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
private:
/** Guest framebuffer pixel format */
ULONG mPixelFormat;
/** Guest framebuffer color depth */
ULONG mBitsPerPixel;
/** Guest framebuffer line length */
ULONG mBytesPerLine;
//Our own framebuffer, in case we can't use the VRAM
uint8_t *mRGBBuffer;
//The source framebuffer (either our own mRGBBuffer or the guest VRAM)
uint8_t *mBufferAddress;
//VNC display framebuffer (RGB -> BGR converted)
uint8_t *mScreenBuffer;
int mVncPort;
ComPtr<IConsole> mConsole;
ComPtr<IKeyboard> mKeyboard;
ComPtr<IMouse> mMouse;
int kbdShiftState;
void kbdSetShift(int state);
void kbdPutCode(int code);
void kbdPutCode(int code, int down);
void kbdPutCodeShift(int shift, int code, int down);
ULONG mWidth, mHeight;
RTCRITSECT mCritSect;
rfbScreenInfoPtr vncServer;
RTTHREAD mVncThread;
static DECLCALLBACK(int) vncThreadFn(RTTHREAD hThreadSelf, void *pvUser);
/** The password that was passed to the constructor. NULL if no
* authentication required. */
char const *mVncPassword;
static void vncKeyboardEvent(rfbBool down, rfbKeySym keySym, rfbClientPtr cl);
static void vncMouseEvent(int buttonMask, int x, int y, rfbClientPtr cl);
static void vncReleaseKeysEvent(rfbClientPtr cl);
void handleVncKeyboardEvent(int down, int keySym);
void handleVncMouseEvent(int buttonMask, int x, int y);
void handleVncKeyboardReleaseEvent();
int mouseX, mouseY;
#ifndef VBOX_WITH_XPCOM
long refcnt;
#endif
};
|