1 | /* $Id: DisplayImpl.h 26173 2010-02-02 21:11:09Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ____H_DISPLAYIMPL
|
---|
23 | #define ____H_DISPLAYIMPL
|
---|
24 |
|
---|
25 | #include "VirtualBoxBase.h"
|
---|
26 | #include "SchemaDefs.h"
|
---|
27 |
|
---|
28 | #include <iprt/semaphore.h>
|
---|
29 | #include <VBox/pdmdrv.h>
|
---|
30 | #include <VBox/VMMDev.h>
|
---|
31 | #include <VBox/VBoxVideo.h>
|
---|
32 |
|
---|
33 | class Console;
|
---|
34 |
|
---|
35 | enum {
|
---|
36 | ResizeStatus_Void,
|
---|
37 | ResizeStatus_InProgress,
|
---|
38 | ResizeStatus_UpdateDisplayData
|
---|
39 | };
|
---|
40 |
|
---|
41 | typedef struct _DISPLAYFBINFO
|
---|
42 | {
|
---|
43 | uint32_t u32Offset;
|
---|
44 | uint32_t u32MaxFramebufferSize;
|
---|
45 | uint32_t u32InformationSize;
|
---|
46 |
|
---|
47 | ComPtr<IFramebuffer> pFramebuffer;
|
---|
48 |
|
---|
49 | LONG xOrigin;
|
---|
50 | LONG yOrigin;
|
---|
51 |
|
---|
52 | ULONG w;
|
---|
53 | ULONG h;
|
---|
54 |
|
---|
55 | VBOXVIDEOINFOHOSTEVENTS *pHostEvents;
|
---|
56 |
|
---|
57 | volatile uint32_t u32ResizeStatus;
|
---|
58 |
|
---|
59 | /* The Framebuffer has default format and must be updates immediately. */
|
---|
60 | bool fDefaultFormat;
|
---|
61 |
|
---|
62 | struct {
|
---|
63 | /* The rectangle that includes all dirty rectangles. */
|
---|
64 | int32_t xLeft;
|
---|
65 | int32_t xRight;
|
---|
66 | int32_t yTop;
|
---|
67 | int32_t yBottom;
|
---|
68 | } dirtyRect;
|
---|
69 |
|
---|
70 | struct {
|
---|
71 | bool fPending;
|
---|
72 | ULONG pixelFormat;
|
---|
73 | void *pvVRAM;
|
---|
74 | uint32_t bpp;
|
---|
75 | uint32_t cbLine;
|
---|
76 | int w;
|
---|
77 | int h;
|
---|
78 | } pendingResize;
|
---|
79 |
|
---|
80 | #ifdef VBOX_WITH_HGSMI
|
---|
81 | bool fVBVAEnabled;
|
---|
82 | uint32_t cVBVASkipUpdate;
|
---|
83 | struct {
|
---|
84 | int32_t xLeft;
|
---|
85 | int32_t yTop;
|
---|
86 | int32_t xRight;
|
---|
87 | int32_t yBottom;
|
---|
88 | } vbvaSkippedRect;
|
---|
89 | PVBVAHOSTFLAGS pVBVAHostFlags;
|
---|
90 | #endif /* VBOX_WITH_HGSMI */
|
---|
91 | } DISPLAYFBINFO;
|
---|
92 |
|
---|
93 | class ATL_NO_VTABLE Display :
|
---|
94 | public VirtualBoxBase,
|
---|
95 | VBOX_SCRIPTABLE_IMPL(IConsoleCallback),
|
---|
96 | public VirtualBoxSupportErrorInfoImpl<Display, IDisplay>,
|
---|
97 | public VirtualBoxSupportTranslation<Display>,
|
---|
98 | VBOX_SCRIPTABLE_IMPL(IDisplay)
|
---|
99 | {
|
---|
100 |
|
---|
101 | public:
|
---|
102 |
|
---|
103 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Display)
|
---|
104 |
|
---|
105 | DECLARE_NOT_AGGREGATABLE(Display)
|
---|
106 |
|
---|
107 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
108 |
|
---|
109 | BEGIN_COM_MAP(Display)
|
---|
110 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
111 | COM_INTERFACE_ENTRY(IDisplay)
|
---|
112 | COM_INTERFACE_ENTRY2(IDispatch,IDisplay)
|
---|
113 | END_COM_MAP()
|
---|
114 |
|
---|
115 | DECLARE_EMPTY_CTOR_DTOR (Display)
|
---|
116 |
|
---|
117 | HRESULT FinalConstruct();
|
---|
118 | void FinalRelease();
|
---|
119 |
|
---|
120 | // public initializer/uninitializer for internal purposes only
|
---|
121 | HRESULT init (Console *aParent);
|
---|
122 | void uninit();
|
---|
123 | int registerSSM(PVM pVM);
|
---|
124 |
|
---|
125 | // public methods only for internal purposes
|
---|
126 | int handleDisplayResize (unsigned uScreenId, uint32_t bpp, void *pvVRAM, uint32_t cbLine, int w, int h);
|
---|
127 | void handleDisplayUpdate (int x, int y, int cx, int cy);
|
---|
128 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
129 | void handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
|
---|
130 | #endif
|
---|
131 | IFramebuffer *getFramebuffer()
|
---|
132 | {
|
---|
133 | return maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
|
---|
134 | }
|
---|
135 |
|
---|
136 | int VideoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
|
---|
137 | void VideoAccelFlush (void);
|
---|
138 |
|
---|
139 | bool VideoAccelAllowed (void);
|
---|
140 |
|
---|
141 | #ifdef VBOX_WITH_VRDP
|
---|
142 | void VideoAccelVRDP (bool fEnable);
|
---|
143 | #endif /* VBOX_WITH_VRDP */
|
---|
144 |
|
---|
145 | // IConsoleCallback methods
|
---|
146 | STDMETHOD(OnMousePointerShapeChange)(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
|
---|
147 | ULONG width, ULONG height, BYTE *shape)
|
---|
148 | {
|
---|
149 | return S_OK;
|
---|
150 | }
|
---|
151 |
|
---|
152 | STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL needsHostCursor)
|
---|
153 | {
|
---|
154 | return S_OK;
|
---|
155 | }
|
---|
156 |
|
---|
157 | STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
|
---|
158 | {
|
---|
159 | return S_OK;
|
---|
160 | }
|
---|
161 |
|
---|
162 | STDMETHOD(OnStateChange)(MachineState_T machineState);
|
---|
163 |
|
---|
164 | STDMETHOD(OnAdditionsStateChange)()
|
---|
165 | {
|
---|
166 | return S_OK;
|
---|
167 | }
|
---|
168 |
|
---|
169 | STDMETHOD(OnNetworkAdapterChange) (INetworkAdapter *aNetworkAdapter)
|
---|
170 | {
|
---|
171 | return S_OK;
|
---|
172 | }
|
---|
173 |
|
---|
174 | STDMETHOD(OnSerialPortChange) (ISerialPort *aSerialPort)
|
---|
175 | {
|
---|
176 | return S_OK;
|
---|
177 | }
|
---|
178 |
|
---|
179 | STDMETHOD(OnParallelPortChange) (IParallelPort *aParallelPort)
|
---|
180 | {
|
---|
181 | return S_OK;
|
---|
182 | }
|
---|
183 |
|
---|
184 | STDMETHOD(OnStorageControllerChange) ()
|
---|
185 | {
|
---|
186 | return S_OK;
|
---|
187 | }
|
---|
188 |
|
---|
189 | STDMETHOD(OnMediumChange)(IMediumAttachment *aMediumAttachment)
|
---|
190 | {
|
---|
191 | return S_OK;
|
---|
192 | }
|
---|
193 |
|
---|
194 | STDMETHOD(OnCPUChange)(ULONG aCPU, BOOL aRemove)
|
---|
195 | {
|
---|
196 | return S_OK;
|
---|
197 | }
|
---|
198 |
|
---|
199 | STDMETHOD(OnVRDPServerChange)()
|
---|
200 | {
|
---|
201 | return S_OK;
|
---|
202 | }
|
---|
203 |
|
---|
204 | STDMETHOD(OnRemoteDisplayInfoChange)()
|
---|
205 | {
|
---|
206 | return S_OK;
|
---|
207 | }
|
---|
208 |
|
---|
209 | STDMETHOD(OnUSBControllerChange)()
|
---|
210 | {
|
---|
211 | return S_OK;
|
---|
212 | }
|
---|
213 |
|
---|
214 | STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *device, BOOL attached,
|
---|
215 | IVirtualBoxErrorInfo *message)
|
---|
216 | {
|
---|
217 | return S_OK;
|
---|
218 | }
|
---|
219 |
|
---|
220 | STDMETHOD(OnSharedFolderChange) (Scope_T aScope)
|
---|
221 | {
|
---|
222 | return S_OK;
|
---|
223 | }
|
---|
224 |
|
---|
225 | STDMETHOD(OnRuntimeError)(BOOL fatal, IN_BSTR id, IN_BSTR message)
|
---|
226 | {
|
---|
227 | return S_OK;
|
---|
228 | }
|
---|
229 |
|
---|
230 | STDMETHOD(OnCanShowWindow)(BOOL *canShow)
|
---|
231 | {
|
---|
232 | if (canShow)
|
---|
233 | *canShow = TRUE;
|
---|
234 | return S_OK;
|
---|
235 | }
|
---|
236 |
|
---|
237 | STDMETHOD(OnShowWindow)(ULONG64 *winId)
|
---|
238 | {
|
---|
239 | if (winId)
|
---|
240 | *winId = 0;
|
---|
241 | return S_OK;
|
---|
242 | }
|
---|
243 |
|
---|
244 | // IDisplay properties
|
---|
245 | STDMETHOD(COMGETTER(Width)) (ULONG *width);
|
---|
246 | STDMETHOD(COMGETTER(Height)) (ULONG *height);
|
---|
247 | STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *bitsPerPixel);
|
---|
248 |
|
---|
249 | // IDisplay methods
|
---|
250 | STDMETHOD(SetFramebuffer)(ULONG aScreenId, IFramebuffer *aFramebuffer);
|
---|
251 | STDMETHOD(GetFramebuffer)(ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin);
|
---|
252 | STDMETHOD(SetVideoModeHint)(ULONG width, ULONG height, ULONG bitsPerPixel, ULONG display);
|
---|
253 | STDMETHOD(TakeScreenShot)(BYTE *address, ULONG width, ULONG height);
|
---|
254 | STDMETHOD(TakeScreenShotSlow)(ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
|
---|
255 | STDMETHOD(DrawToScreen)(BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
|
---|
256 | STDMETHOD(InvalidateAndUpdate)();
|
---|
257 | STDMETHOD(ResizeCompleted)(ULONG aScreenId);
|
---|
258 | STDMETHOD(UpdateCompleted)();
|
---|
259 | STDMETHOD(SetSeamlessMode)(BOOL enabled);
|
---|
260 |
|
---|
261 | STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
|
---|
262 |
|
---|
263 | // for VirtualBoxSupportErrorInfoImpl
|
---|
264 | static const wchar_t *getComponentName() { return L"Display"; }
|
---|
265 |
|
---|
266 | static const PDMDRVREG DrvReg;
|
---|
267 |
|
---|
268 | private:
|
---|
269 |
|
---|
270 | void updateDisplayData (bool aCheckParams = false);
|
---|
271 |
|
---|
272 | static DECLCALLBACK(int) changeFramebuffer(Display *that, IFramebuffer *aFB, unsigned uScreenId);
|
---|
273 |
|
---|
274 | static DECLCALLBACK(void*) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
|
---|
275 | static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
|
---|
276 | static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
|
---|
277 | static DECLCALLBACK(int) displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy);
|
---|
278 | static DECLCALLBACK(void) displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
|
---|
279 | uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
|
---|
280 | static DECLCALLBACK(void) displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface);
|
---|
281 | static DECLCALLBACK(void) displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface);
|
---|
282 | static DECLCALLBACK(void) displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
|
---|
283 | static DECLCALLBACK(void) displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
|
---|
284 | static DECLCALLBACK(void) displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
|
---|
285 |
|
---|
286 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
287 | static DECLCALLBACK(void) displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
|
---|
288 | #endif
|
---|
289 |
|
---|
290 | #ifdef VBOX_WITH_HGSMI
|
---|
291 | static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
|
---|
292 | static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
|
---|
293 | static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
|
---|
294 | static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
|
---|
295 | static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
|
---|
296 | static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
|
---|
297 | static DECLCALLBACK(int) displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvShape);
|
---|
298 | #endif
|
---|
299 |
|
---|
300 |
|
---|
301 | static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
|
---|
302 | static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
|
---|
303 | static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
|
---|
304 | static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
|
---|
305 |
|
---|
306 | const ComObjPtr<Console, ComWeakRef> mParent;
|
---|
307 | /** Pointer to the associated display driver. */
|
---|
308 | struct DRVMAINDISPLAY *mpDrv;
|
---|
309 | /** Pointer to the device instance for the VMM Device. */
|
---|
310 | PPDMDEVINS mpVMMDev;
|
---|
311 | /** Set after the first attempt to find the VMM Device. */
|
---|
312 | bool mfVMMDevInited;
|
---|
313 |
|
---|
314 | unsigned mcMonitors;
|
---|
315 | DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
|
---|
316 |
|
---|
317 | bool mFramebufferOpened;
|
---|
318 |
|
---|
319 | /* arguments of the last handleDisplayResize() call */
|
---|
320 | void *mLastAddress;
|
---|
321 | uint32_t mLastBytesPerLine;
|
---|
322 | uint32_t mLastBitsPerPixel;
|
---|
323 | int mLastWidth;
|
---|
324 | int mLastHeight;
|
---|
325 |
|
---|
326 | VBVAMEMORY *mpVbvaMemory;
|
---|
327 | bool mfVideoAccelEnabled;
|
---|
328 | bool mfVideoAccelVRDP;
|
---|
329 | uint32_t mfu32SupportedOrders;
|
---|
330 |
|
---|
331 | int32_t volatile mcVideoAccelVRDPRefs;
|
---|
332 |
|
---|
333 | VBVAMEMORY *mpPendingVbvaMemory;
|
---|
334 | bool mfPendingVideoAccelEnable;
|
---|
335 | bool mfMachineRunning;
|
---|
336 |
|
---|
337 | uint8_t *mpu8VbvaPartial;
|
---|
338 | uint32_t mcbVbvaPartial;
|
---|
339 |
|
---|
340 | bool vbvaFetchCmd (VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
|
---|
341 | void vbvaReleaseCmd (VBVACMDHDR *pHdr, int32_t cbCmd);
|
---|
342 |
|
---|
343 | void handleResizeCompletedEMT (void);
|
---|
344 |
|
---|
345 | #ifdef VBOX_WITH_OLD_VBVA_LOCK
|
---|
346 | RTCRITSECT mVBVALock;
|
---|
347 | volatile uint32_t mfu32PendingVideoAccelDisable;
|
---|
348 |
|
---|
349 | int vbvaLock(void);
|
---|
350 | void vbvaUnlock(void);
|
---|
351 |
|
---|
352 | public:
|
---|
353 | static int displayTakeScreenshotEMT(Display *pDisplay, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
|
---|
354 |
|
---|
355 | private:
|
---|
356 | static void InvalidateAndUpdateEMT(Display *pDisplay);
|
---|
357 | static int DrawToScreenEMT(Display *pDisplay, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
|
---|
358 |
|
---|
359 | int videoAccelRefreshProcess(void);
|
---|
360 |
|
---|
361 | /* Functions run under VBVA lock. */
|
---|
362 | int videoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
|
---|
363 | void videoAccelFlush (void);
|
---|
364 | #endif /* VBOX_WITH_OLD_VBVA_LOCK */
|
---|
365 |
|
---|
366 | #ifdef VBOX_WITH_HGSMI
|
---|
367 | volatile uint32_t mu32UpdateVBVAFlags;
|
---|
368 | #endif
|
---|
369 | };
|
---|
370 |
|
---|
371 | void gdImageCopyResampled (uint8_t *dst, uint8_t *src,
|
---|
372 | int dstX, int dstY,
|
---|
373 | int srcX, int srcY,
|
---|
374 | int dstW, int dstH, int srcW, int srcH);
|
---|
375 |
|
---|
376 |
|
---|
377 | #endif // ____H_DISPLAYIMPL
|
---|
378 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|