1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox Remote Desktop Framebuffer
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include "Framebuffer.h"
|
---|
19 |
|
---|
20 | #include <iprt/alloc.h>
|
---|
21 |
|
---|
22 | #define LOG_GROUP LOG_GROUP_GUI
|
---|
23 | #include <VBox/log.h>
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * VRDP server frame buffer
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifdef VBOX_WITH_XPCOM
|
---|
30 | #include <nsMemory.h>
|
---|
31 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VRDPFramebuffer, IFramebuffer)
|
---|
32 | NS_DECL_CLASSINFO(VRDPFramebuffer)
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | VRDPFramebuffer::VRDPFramebuffer()
|
---|
36 | {
|
---|
37 | #if defined (RT_OS_WINDOWS)
|
---|
38 | refcnt = 0;
|
---|
39 | #endif /* RT_OS_WINDOWS */
|
---|
40 |
|
---|
41 | mBuffer = NULL;
|
---|
42 |
|
---|
43 | RTCritSectInit (&m_CritSect);
|
---|
44 |
|
---|
45 | // start with a standard size
|
---|
46 | RequestResize(0, FramebufferPixelFormat_Opaque,
|
---|
47 | NULL, 0, 0, 640, 480, NULL);
|
---|
48 | }
|
---|
49 |
|
---|
50 | VRDPFramebuffer::~VRDPFramebuffer()
|
---|
51 | {
|
---|
52 | if (mBuffer)
|
---|
53 | {
|
---|
54 | RTMemFree (mBuffer);
|
---|
55 | }
|
---|
56 |
|
---|
57 | RTCritSectDelete (&m_CritSect);
|
---|
58 | }
|
---|
59 |
|
---|
60 | STDMETHODIMP VRDPFramebuffer::COMGETTER(Width)(ULONG *width)
|
---|
61 | {
|
---|
62 | if (!width)
|
---|
63 | return E_INVALIDARG;
|
---|
64 | *width = mWidth;
|
---|
65 | return S_OK;
|
---|
66 | }
|
---|
67 |
|
---|
68 | STDMETHODIMP VRDPFramebuffer::COMGETTER(Height)(ULONG *height)
|
---|
69 | {
|
---|
70 | if (!height)
|
---|
71 | return E_INVALIDARG;
|
---|
72 | *height = mHeight;
|
---|
73 | return S_OK;
|
---|
74 | }
|
---|
75 |
|
---|
76 | STDMETHODIMP VRDPFramebuffer::Lock()
|
---|
77 | {
|
---|
78 | RTCritSectEnter (&m_CritSect);
|
---|
79 | return S_OK;
|
---|
80 | }
|
---|
81 |
|
---|
82 | STDMETHODIMP VRDPFramebuffer::Unlock()
|
---|
83 | {
|
---|
84 | RTCritSectLeave (&m_CritSect);
|
---|
85 | return S_OK;
|
---|
86 | }
|
---|
87 |
|
---|
88 | STDMETHODIMP VRDPFramebuffer::COMGETTER(Address)(BYTE **address)
|
---|
89 | {
|
---|
90 | if (!address)
|
---|
91 | return E_INVALIDARG;
|
---|
92 | *address = mScreen;
|
---|
93 | return S_OK;
|
---|
94 | }
|
---|
95 |
|
---|
96 | STDMETHODIMP VRDPFramebuffer::COMGETTER(BitsPerPixel)(ULONG *bitsPerPixel)
|
---|
97 | {
|
---|
98 | if (!bitsPerPixel)
|
---|
99 | return E_INVALIDARG;
|
---|
100 | *bitsPerPixel = mBitsPerPixel;
|
---|
101 | return S_OK;
|
---|
102 | }
|
---|
103 |
|
---|
104 | STDMETHODIMP VRDPFramebuffer::COMGETTER(BytesPerLine)(ULONG *bytesPerLine)
|
---|
105 | {
|
---|
106 | if (!bytesPerLine)
|
---|
107 | return E_INVALIDARG;
|
---|
108 | *bytesPerLine = mBytesPerLine;
|
---|
109 | return S_OK;
|
---|
110 | }
|
---|
111 |
|
---|
112 | STDMETHODIMP VRDPFramebuffer::COMGETTER(PixelFormat) (ULONG *pixelFormat)
|
---|
113 | {
|
---|
114 | if (!pixelFormat)
|
---|
115 | return E_POINTER;
|
---|
116 | *pixelFormat = mPixelFormat;
|
---|
117 | return S_OK;
|
---|
118 | }
|
---|
119 |
|
---|
120 | STDMETHODIMP VRDPFramebuffer::COMGETTER(UsesGuestVRAM) (BOOL *usesGuestVRAM)
|
---|
121 | {
|
---|
122 | if (!usesGuestVRAM)
|
---|
123 | return E_POINTER;
|
---|
124 | *usesGuestVRAM = mUsesGuestVRAM;
|
---|
125 | return S_OK;
|
---|
126 | }
|
---|
127 |
|
---|
128 | STDMETHODIMP VRDPFramebuffer::COMGETTER(HeightReduction) (ULONG *heightReduction)
|
---|
129 | {
|
---|
130 | if (!heightReduction)
|
---|
131 | return E_POINTER;
|
---|
132 | /* no reduction at all */
|
---|
133 | *heightReduction = 0;
|
---|
134 | return S_OK;
|
---|
135 | }
|
---|
136 |
|
---|
137 | STDMETHODIMP VRDPFramebuffer::COMGETTER(Overlay) (IFramebufferOverlay **aOverlay)
|
---|
138 | {
|
---|
139 | if (!aOverlay)
|
---|
140 | return E_POINTER;
|
---|
141 | /* overlays are not yet supported */
|
---|
142 | *aOverlay = 0;
|
---|
143 | return S_OK;
|
---|
144 | }
|
---|
145 |
|
---|
146 | STDMETHODIMP VRDPFramebuffer::COMGETTER(WinId) (LONG64 *winId)
|
---|
147 | {
|
---|
148 | if (!winId)
|
---|
149 | return E_POINTER;
|
---|
150 | *winId = 0;
|
---|
151 | return S_OK;
|
---|
152 | }
|
---|
153 |
|
---|
154 | STDMETHODIMP VRDPFramebuffer::NotifyUpdate(ULONG x, ULONG y,
|
---|
155 | ULONG w, ULONG h)
|
---|
156 | {
|
---|
157 | return S_OK;
|
---|
158 | }
|
---|
159 |
|
---|
160 | STDMETHODIMP VRDPFramebuffer::RequestResize(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
|
---|
161 | ULONG bitsPerPixel, ULONG bytesPerLine,
|
---|
162 | ULONG w, ULONG h,
|
---|
163 | BOOL *finished)
|
---|
164 | {
|
---|
165 | /* Agree to requested format for LFB modes and use guest VRAM directly, thus avoiding
|
---|
166 | * unnecessary memcpy in VGA device.
|
---|
167 | */
|
---|
168 |
|
---|
169 | Log(("pixelFormat = %08X, vram = %p, bpp = %d, bpl = 0x%08X, %dx%d\n",
|
---|
170 | pixelFormat, vram, bitsPerPixel, bytesPerLine, w, h));
|
---|
171 |
|
---|
172 | /* Free internal buffer. */
|
---|
173 | if (mBuffer)
|
---|
174 | {
|
---|
175 | RTMemFree (mBuffer);
|
---|
176 | mBuffer = NULL;
|
---|
177 | }
|
---|
178 |
|
---|
179 | mUsesGuestVRAM = FALSE;
|
---|
180 |
|
---|
181 | mWidth = w;
|
---|
182 | mHeight = h;
|
---|
183 |
|
---|
184 | if (pixelFormat == FramebufferPixelFormat_FOURCC_RGB)
|
---|
185 | {
|
---|
186 | switch (bitsPerPixel)
|
---|
187 | {
|
---|
188 | case 32:
|
---|
189 | case 24:
|
---|
190 | case 16:
|
---|
191 | mUsesGuestVRAM = TRUE;
|
---|
192 | break;
|
---|
193 |
|
---|
194 | default:
|
---|
195 | break;
|
---|
196 | }
|
---|
197 | }
|
---|
198 |
|
---|
199 | if (mUsesGuestVRAM)
|
---|
200 | {
|
---|
201 | mScreen = vram;
|
---|
202 | mBitsPerPixel = bitsPerPixel;
|
---|
203 | mBytesPerLine = bytesPerLine;
|
---|
204 | mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
|
---|
205 |
|
---|
206 | Log (("Using guest VRAM directly, %d BPP\n", mBitsPerPixel));
|
---|
207 | }
|
---|
208 | else
|
---|
209 | {
|
---|
210 | mBitsPerPixel = 32;
|
---|
211 | mBytesPerLine = w * 4; /* Here we have 32 BPP */
|
---|
212 |
|
---|
213 | if (mBytesPerLine > 0 && h > 0) /* Check for nul dimensions. */
|
---|
214 | {
|
---|
215 | mBuffer = RTMemAllocZ(mBytesPerLine * h);
|
---|
216 | }
|
---|
217 |
|
---|
218 | mScreen = (uint8_t *)mBuffer;
|
---|
219 |
|
---|
220 | Log(("Using internal buffer, %d BPP\n", mBitsPerPixel));
|
---|
221 | }
|
---|
222 |
|
---|
223 | if (!mScreen)
|
---|
224 | {
|
---|
225 | Log(("No screen. BPP = %d, w = %d, h = %d!!!\n", mBitsPerPixel, w, h));
|
---|
226 |
|
---|
227 | /* Just reset everything. */
|
---|
228 | mPixelFormat = FramebufferPixelFormat_Opaque;
|
---|
229 |
|
---|
230 | mWidth = 0;
|
---|
231 | mHeight = 0;
|
---|
232 | mBitsPerPixel = 0;
|
---|
233 | mBytesPerLine = 0;
|
---|
234 | mUsesGuestVRAM = FALSE;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /* Inform the caller that the operation was successful. */
|
---|
238 |
|
---|
239 | if (finished)
|
---|
240 | *finished = TRUE;
|
---|
241 |
|
---|
242 | return S_OK;
|
---|
243 | }
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Returns whether we like the given video mode.
|
---|
247 | *
|
---|
248 | * @returns COM status code
|
---|
249 | * @param width video mode width in pixels
|
---|
250 | * @param height video mode height in pixels
|
---|
251 | * @param bpp video mode bit depth in bits per pixel
|
---|
252 | * @param supported pointer to result variable
|
---|
253 | */
|
---|
254 | STDMETHODIMP VRDPFramebuffer::VideoModeSupported(ULONG width, ULONG height, ULONG bpp, BOOL *supported)
|
---|
255 | {
|
---|
256 | if (!supported)
|
---|
257 | return E_POINTER;
|
---|
258 | *supported = TRUE;
|
---|
259 | return S_OK;
|
---|
260 | }
|
---|
261 |
|
---|
262 | STDMETHODIMP VRDPFramebuffer::GetVisibleRegion(BYTE *aRectangles, ULONG aCount,
|
---|
263 | ULONG *aCountCopied)
|
---|
264 | {
|
---|
265 | PRTRECT rects = (PRTRECT)aRectangles;
|
---|
266 |
|
---|
267 | if (!rects)
|
---|
268 | return E_POINTER;
|
---|
269 |
|
---|
270 | /// @todo
|
---|
271 |
|
---|
272 | NOREF(aCount);
|
---|
273 | NOREF(aCountCopied);
|
---|
274 |
|
---|
275 | return S_OK;
|
---|
276 | }
|
---|
277 |
|
---|
278 | STDMETHODIMP VRDPFramebuffer::SetVisibleRegion(BYTE *aRectangles, ULONG aCount)
|
---|
279 | {
|
---|
280 | PRTRECT rects = (PRTRECT)aRectangles;
|
---|
281 |
|
---|
282 | if (!rects)
|
---|
283 | return E_POINTER;
|
---|
284 |
|
---|
285 | /// @todo
|
---|
286 |
|
---|
287 | NOREF(aCount);
|
---|
288 |
|
---|
289 | return S_OK;
|
---|
290 | }
|
---|
291 |
|
---|
292 | STDMETHODIMP VRDPFramebuffer::ProcessVHWACommand(BYTE *pCommand)
|
---|
293 | {
|
---|
294 | return E_NOTIMPL;
|
---|
295 | }
|
---|
296 |
|
---|
297 | STDMETHODIMP VRDPFramebuffer::Notify3DEvent(ULONG uType, BYTE *pReserved)
|
---|
298 | {
|
---|
299 | return E_NOTIMPL;
|
---|
300 | }
|
---|