VirtualBox

source: vbox/trunk/src/VBox/Main/include/DisplayImpl.h@ 50403

Last change on this file since 50403 was 50394, checked in by vboxsync, 11 years ago

crOpenGL: greyed-out 3D image on VM pause

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.6 KB
Line 
1/* $Id: DisplayImpl.h 50394 2014-02-10 15:33:47Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2013 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#ifndef ____H_DISPLAYIMPL
19#define ____H_DISPLAYIMPL
20
21#include "VirtualBoxBase.h"
22#include "SchemaDefs.h"
23
24#include <iprt/semaphore.h>
25#include <VBox/vmm/pdmdrv.h>
26#include <VBox/VMMDev.h>
27#include <VBox/VBoxVideo.h>
28
29#ifdef VBOX_WITH_CROGL
30# include <VBox/HostServices/VBoxCrOpenGLSvc.h>
31#endif
32
33class Console;
34struct VIDEORECCONTEXT;
35
36enum
37{
38 ResizeStatus_Void,
39 ResizeStatus_InProgress,
40 ResizeStatus_UpdateDisplayData
41};
42
43typedef struct _DISPLAYFBINFO
44{
45 uint32_t u32Offset;
46 uint32_t u32MaxFramebufferSize;
47 uint32_t u32InformationSize;
48
49 ComPtr<IFramebuffer> pFramebuffer;
50 bool fDisabled;
51
52 LONG xOrigin;
53 LONG yOrigin;
54
55 ULONG w;
56 ULONG h;
57
58 uint16_t u16BitsPerPixel;
59 uint8_t *pu8FramebufferVRAM;
60 uint32_t u32LineSize;
61
62 uint16_t flags;
63
64 /* for saving the rectangles arrived during fb resize is in progress. */
65 PRTRECT mpSavedVisibleRegion;
66 uint32_t mcSavedVisibleRegion;
67
68 VBOXVIDEOINFOHOSTEVENTS *pHostEvents;
69
70 volatile uint32_t u32ResizeStatus;
71
72 /* The Framebuffer has default format and must be updates immediately. */
73 bool fDefaultFormat;
74
75 struct
76 {
77 /* The rectangle that includes all dirty rectangles. */
78 int32_t xLeft;
79 int32_t xRight;
80 int32_t yTop;
81 int32_t yBottom;
82 } dirtyRect;
83
84 struct
85 {
86 bool fPending;
87 ULONG pixelFormat;
88 void *pvVRAM;
89 uint32_t bpp;
90 uint32_t cbLine;
91 uint32_t w;
92 uint32_t h;
93 uint16_t flags;
94 } pendingResize;
95
96#ifdef VBOX_WITH_HGSMI
97 bool fVBVAEnabled;
98 bool fVBVAForceResize;
99 uint32_t cVBVASkipUpdate;
100 struct
101 {
102 int32_t xLeft;
103 int32_t yTop;
104 int32_t xRight;
105 int32_t yBottom;
106 } vbvaSkippedRect;
107 PVBVAHOSTFLAGS pVBVAHostFlags;
108#endif /* VBOX_WITH_HGSMI */
109
110#ifdef VBOX_WITH_CROGL
111 struct
112 {
113 bool fPending;
114 ULONG x;
115 ULONG y;
116 ULONG width;
117 ULONG height;
118 } pendingViewportInfo;
119#endif /* VBOX_WITH_CROGL */
120} DISPLAYFBINFO;
121
122class DisplayMouseInterface
123{
124public:
125 virtual int getScreenResolution(uint32_t cScreen, ULONG *pcx,
126 ULONG *pcy, ULONG *pcBPP, LONG *pXOrigin, LONG *pYOrigin) = 0;
127 virtual void getFramebufferDimensions(int32_t *px1, int32_t *py1,
128 int32_t *px2, int32_t *py2) = 0;
129};
130
131class VMMDev;
132
133class ATL_NO_VTABLE Display :
134 public VirtualBoxBase,
135 VBOX_SCRIPTABLE_IMPL(IEventListener),
136 VBOX_SCRIPTABLE_IMPL(IDisplay),
137 public DisplayMouseInterface
138{
139public:
140
141 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Display, IDisplay)
142
143 DECLARE_NOT_AGGREGATABLE(Display)
144
145 DECLARE_PROTECT_FINAL_CONSTRUCT()
146
147 BEGIN_COM_MAP(Display)
148 VBOX_DEFAULT_INTERFACE_ENTRIES(IDisplay)
149 COM_INTERFACE_ENTRY(IEventListener)
150 END_COM_MAP()
151
152 DECLARE_EMPTY_CTOR_DTOR(Display)
153
154 HRESULT FinalConstruct();
155 void FinalRelease();
156
157 // public initializer/uninitializer for internal purposes only
158 HRESULT init(Console *aParent);
159 void uninit();
160 int registerSSM(PUVM pUVM);
161
162 // public methods only for internal purposes
163 int handleDisplayResize(unsigned uScreenId, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t w, uint32_t h, uint16_t flags);
164 void handleDisplayUpdateLegacy(int x, int y, int cx, int cy);
165 void handleDisplayUpdate(unsigned uScreenId, int x, int y, int w, int h);
166#ifdef VBOX_WITH_VIDEOHWACCEL
167 int handleVHWACommandProcess(PVBOXVHWACMD pCommand);
168#endif
169#ifdef VBOX_WITH_CRHGSMI
170 int handleCrCmdNotifyCmds();
171 void handleCrHgsmiCommandProcess(PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd);
172 void handleCrHgsmiControlProcess(PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl);
173
174 void handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
175 void handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
176#endif
177
178#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
179 void handleCrAsyncCmdCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
180 void handleCrVRecScreenshotPerform(uint32_t uScreen,
181 uint32_t x, uint32_t y, uint32_t uPixelFormat, uint32_t uBitsPerPixel,
182 uint32_t uBytesPerLine, uint32_t uGuestWidth, uint32_t uGuestHeight,
183 uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
184 bool handleCrVRecScreenshotBegin(uint32_t uScreen, uint64_t u64TimeStamp);
185 void handleCrVRecScreenshotEnd(uint32_t uScreen, uint64_t u64TimeStamp);
186 void handleVRecCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
187#endif
188
189 int notifyCroglResize(const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
190
191 IFramebuffer *getFramebuffer()
192 {
193 return maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
194 }
195 void getFramebufferDimensions(int32_t *px1, int32_t *py1, int32_t *px2, int32_t *py2);
196 int getScreenResolution(uint32_t cScreen, ULONG *pcx, ULONG *pcy,
197 ULONG *pcBPP, LONG *pXOrigin, LONG *pYOrigin)
198 {
199 return GetScreenResolution(cScreen, pcx, pcy, pcBPP, pXOrigin, pYOrigin);
200 }
201
202 int handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect);
203 int handleQueryVisibleRegion(uint32_t *pcRect, PRTRECT pRect);
204
205 int VideoAccelEnable(bool fEnable, VBVAMEMORY *pVbvaMemory);
206 void VideoAccelFlush(void);
207 bool VideoAccelAllowed(void);
208 void VideoAccelVRDP(bool fEnable);
209
210 int VideoCaptureStart();
211 void VideoCaptureStop();
212 int VideoCaptureEnableScreens(ComSafeArrayIn(BOOL, aScreens));
213
214 // IEventListener methods
215 STDMETHOD(HandleEvent)(IEvent * aEvent);
216
217 // IDisplay methods
218 STDMETHOD(GetScreenResolution)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel, LONG *aXOrigin, LONG *aYOrigin);
219 STDMETHOD(SetFramebuffer)(ULONG aScreenId, IFramebuffer *aFramebuffer);
220 STDMETHOD(GetFramebuffer)(ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin);
221 STDMETHOD(SetVideoModeHint)(ULONG aDisplay, BOOL aEnabled, BOOL aChangeOrigin, LONG aOriginX, LONG aOriginY, ULONG aWidth, ULONG aHeight, ULONG aBitsPerPixel);
222 STDMETHOD(TakeScreenShot)(ULONG aScreenId, BYTE *address, ULONG width, ULONG height);
223 STDMETHOD(TakeScreenShotToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
224 STDMETHOD(TakeScreenShotPNGToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
225 STDMETHOD(DrawToScreen)(ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
226 STDMETHOD(InvalidateAndUpdate)();
227 STDMETHOD(ResizeCompleted)(ULONG aScreenId);
228 STDMETHOD(SetSeamlessMode)(BOOL enabled);
229
230 STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
231
232 STDMETHOD(ViewportChanged)(ULONG aScreenId, ULONG x, ULONG y, ULONG width, ULONG height);
233
234 static const PDMDRVREG DrvReg;
235
236private:
237
238 int updateDisplayData(void);
239
240#ifdef VBOX_WITH_CRHGSMI
241 void setupCrHgsmiData(void);
242 void destructCrHgsmiData(void);
243#endif
244
245#ifdef VBOX_WITH_CROGL
246 void crViewportNotify(class VMMDev *pVMMDev, ULONG aScreenId, ULONG x, ULONG y, ULONG width, ULONG height);
247#endif
248
249 static DECLCALLBACK(int) changeFramebuffer(Display *that, IFramebuffer *aFB, unsigned uScreenId);
250
251 static DECLCALLBACK(void*) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
252 static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
253 static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
254 static DECLCALLBACK(int) displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy);
255 static DECLCALLBACK(void) displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
256 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
257 static DECLCALLBACK(void) displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface);
258 static DECLCALLBACK(void) displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface);
259 static DECLCALLBACK(void) displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
260 static DECLCALLBACK(void) displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
261 static DECLCALLBACK(void) displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
262
263#ifdef VBOX_WITH_VIDEOHWACCEL
264 static DECLCALLBACK(int) displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
265#endif
266
267#ifdef VBOX_WITH_CRHGSMI
268 static DECLCALLBACK(int) displayCrCmdNotifyCmds(PPDMIDISPLAYCONNECTOR pInterface);
269 static DECLCALLBACK(void) displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd);
270 static DECLCALLBACK(void) displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl);
271
272 static DECLCALLBACK(void) displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
273 static DECLCALLBACK(void) displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
274#endif
275
276#ifdef VBOX_WITH_HGSMI
277 static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
278 static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
279 static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
280 static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
281 static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
282 static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
283 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);
284#endif
285
286#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
287 static DECLCALLBACK(void) displayCrVRecScreenshotPerform(void *pvCtx, uint32_t uScreen,
288 uint32_t x, uint32_t y,
289 uint32_t uBitsPerPixel, uint32_t uBytesPerLine,
290 uint32_t uGuestWidth, uint32_t uGuestHeight,
291 uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
292 static DECLCALLBACK(bool) displayCrVRecScreenshotBegin(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
293 static DECLCALLBACK(void) displayCrVRecScreenshotEnd(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
294
295 static DECLCALLBACK(void) displayVRecCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
296 static DECLCALLBACK(void) displayCrAsyncCmdCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
297#endif
298
299 static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
300 static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
301 static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
302 static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
303
304 Console * const mParent;
305 /** Pointer to the associated display driver. */
306 struct DRVMAINDISPLAY *mpDrv;
307 /** Pointer to the device instance for the VMM Device. */
308 PPDMDEVINS mpVMMDev;
309 /** Set after the first attempt to find the VMM Device. */
310 bool mfVMMDevInited;
311
312 unsigned mcMonitors;
313 DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
314
315 /* arguments of the last handleDisplayResize() call */
316 void *mLastAddress;
317 uint32_t mLastBytesPerLine;
318 uint32_t mLastBitsPerPixel;
319 uint32_t mLastWidth;
320 uint32_t mLastHeight;
321 uint16_t mLastFlags;
322
323 VBVAMEMORY *mpVbvaMemory;
324 bool mfVideoAccelEnabled;
325 bool mfVideoAccelVRDP;
326 uint32_t mfu32SupportedOrders;
327
328 int32_t volatile mcVideoAccelVRDPRefs;
329
330 VBVAMEMORY *mpPendingVbvaMemory;
331 bool mfPendingVideoAccelEnable;
332 bool mfMachineRunning;
333#ifdef VBOX_WITH_CROGL
334 bool mfCrOglDataHidden;
335#endif
336
337 uint8_t *mpu8VbvaPartial;
338 uint32_t mcbVbvaPartial;
339
340#ifdef VBOX_WITH_CRHGSMI
341 /* for fast host hgcm calls */
342 HGCMCVSHANDLE mhCrOglSvc;
343#endif
344#ifdef VBOX_WITH_CROGL
345 CR_MAIN_INTERFACE mCrOglCallbacks;
346 volatile uint32_t mfCrOglVideoRecState;
347 CRVBOXHGCMTAKESCREENSHOT mCrOglScreenshotData;
348#endif
349
350 bool vbvaFetchCmd(VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
351 void vbvaReleaseCmd(VBVACMDHDR *pHdr, int32_t cbCmd);
352
353 void handleResizeCompletedEMT(void);
354
355 RTCRITSECT mVBVALock;
356 volatile uint32_t mfu32PendingVideoAccelDisable;
357
358 int vbvaLock(void);
359 void vbvaUnlock(void);
360
361 RTCRITSECT mSaveSeamlessRectLock;
362 int SaveSeamlessRectLock(void);
363 void SaveSeamlessRectUnLock(void);
364
365public:
366 static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
367
368#ifdef VBOX_WITH_CROGL
369 static BOOL displayCheckTakeScreenshotCrOgl(Display *pDisplay, ULONG aScreenId, uint8_t *pu8Data, uint32_t u32Width, uint32_t u32Height);
370#endif
371
372private:
373 static void InvalidateAndUpdateEMT(Display *pDisplay, unsigned uId, bool fUpdateAll);
374 static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
375
376 int videoAccelRefreshProcess(void);
377
378 /* Functions run under VBVA lock. */
379 int videoAccelEnable(bool fEnable, VBVAMEMORY *pVbvaMemory);
380 void videoAccelFlush(void);
381
382#ifdef VBOX_WITH_CROGL
383 int crOglWindowsShow(bool fShow);
384#endif
385
386#ifdef VBOX_WITH_HGSMI
387 volatile uint32_t mu32UpdateVBVAFlags;
388#endif
389
390#ifdef VBOX_WITH_VPX
391 VIDEORECCONTEXT *mpVideoRecCtx;
392 bool maVideoRecEnabled[SchemaDefs::MaxGuestMonitors];
393#endif
394};
395
396void gdImageCopyResampled(uint8_t *dst, uint8_t *src,
397 int dstX, int dstY, int srcX, int srcY,
398 int dstW, int dstH, int srcW, int srcH);
399
400void BitmapScale32(uint8_t *dst, int dstW, int dstH,
401 const uint8_t *src, int iDeltaLine, int srcW, int srcH);
402
403int DisplayMakePNG(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
404 uint8_t **ppu8PNG, uint32_t *pcbPNG, uint32_t *pcxPNG, uint32_t *pcyPNG,
405 uint8_t fLimitSize);
406
407#endif // ____H_DISPLAYIMPL
408/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette