VirtualBox

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

Last change on this file since 51342 was 51141, checked in by vboxsync, 11 years ago

crOpenGL: crcmd enhancements & fixes; osx deadlock fix; temporary disabled crcmd for testing

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