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