VirtualBox

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

Last change on this file since 50762 was 50754, checked in by vboxsync, 11 years ago

Dev/VGA/crOpenGL/wddm: command thread, more command processing

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.2 KB
Line 
1/* $Id: DisplayImpl.h 50754 2014-03-12 17:43:09Z 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 void handleCrHgsmiCommandProcess(PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd);
171 void handleCrHgsmiControlProcess(PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl);
172
173 void handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
174 void handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
175#endif
176 int handleCrHgcmCtlSubmit(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd,
177 PFNCRCTLCOMPLETION pfnCompletion,
178 void *pvCompletion);
179#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
180 void handleCrAsyncCmdCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
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#ifdef VBOX_WITH_CROGL
247 void crViewportNotify(class VMMDev *pVMMDev, 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 static DECLCALLBACK(int) displayCrHgcmCtlSubmit(PPDMIDISPLAYCONNECTOR pInterface,
276 struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd,
277 PFNCRCTLCOMPLETION pfnCompletion,
278 void *pvCompletion);
279 static DECLCALLBACK(void) displayCrHgcmCtlSubmitCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
280#ifdef VBOX_WITH_HGSMI
281 static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
282 static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
283 static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
284 static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
285 static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
286 static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
287 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);
288#endif
289
290#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
291 static DECLCALLBACK(void) displayCrVRecScreenshotPerform(void *pvCtx, uint32_t uScreen,
292 uint32_t x, uint32_t y,
293 uint32_t uBitsPerPixel, uint32_t uBytesPerLine,
294 uint32_t uGuestWidth, uint32_t uGuestHeight,
295 uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
296 static DECLCALLBACK(bool) displayCrVRecScreenshotBegin(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
297 static DECLCALLBACK(void) displayCrVRecScreenshotEnd(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
298
299 static DECLCALLBACK(void) displayVRecCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
300 static DECLCALLBACK(void) displayCrAsyncCmdCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
301#endif
302
303 static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
304 static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
305 static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
306 static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
307
308 Console * const mParent;
309 /** Pointer to the associated display driver. */
310 struct DRVMAINDISPLAY *mpDrv;
311 /** Pointer to the device instance for the VMM Device. */
312 PPDMDEVINS mpVMMDev;
313 /** Set after the first attempt to find the VMM Device. */
314 bool mfVMMDevInited;
315
316 unsigned mcMonitors;
317 DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
318
319 /* arguments of the last handleDisplayResize() call */
320 void *mLastAddress;
321 uint32_t mLastBytesPerLine;
322 uint32_t mLastBitsPerPixel;
323 uint32_t mLastWidth;
324 uint32_t mLastHeight;
325 uint16_t mLastFlags;
326
327 VBVAMEMORY *mpVbvaMemory;
328 bool mfVideoAccelEnabled;
329 bool mfVideoAccelVRDP;
330 uint32_t mfu32SupportedOrders;
331
332 int32_t volatile mcVideoAccelVRDPRefs;
333
334 VBVAMEMORY *mpPendingVbvaMemory;
335 bool mfPendingVideoAccelEnable;
336 bool mfMachineRunning;
337#ifdef VBOX_WITH_CROGL
338 bool mfCrOglDataHidden;
339#endif
340
341 uint8_t *mpu8VbvaPartial;
342 uint32_t mcbVbvaPartial;
343
344#ifdef VBOX_WITH_CRHGSMI
345 /* for fast host hgcm calls */
346 HGCMCVSHANDLE mhCrOglSvc;
347#endif
348#ifdef VBOX_WITH_CROGL
349 CR_MAIN_INTERFACE mCrOglCallbacks;
350 volatile uint32_t mfCrOglVideoRecState;
351 CRVBOXHGCMTAKESCREENSHOT mCrOglScreenshotData;
352#endif
353
354 bool vbvaFetchCmd(VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
355 void vbvaReleaseCmd(VBVACMDHDR *pHdr, int32_t cbCmd);
356
357 void handleResizeCompletedEMT(void);
358
359 RTCRITSECT mVBVALock;
360 volatile uint32_t mfu32PendingVideoAccelDisable;
361
362 int vbvaLock(void);
363 void vbvaUnlock(void);
364
365 RTCRITSECT mSaveSeamlessRectLock;
366 int SaveSeamlessRectLock(void);
367 void SaveSeamlessRectUnLock(void);
368
369public:
370 static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
371
372#ifdef VBOX_WITH_CROGL
373 static BOOL displayCheckTakeScreenshotCrOgl(Display *pDisplay, ULONG aScreenId, uint8_t *pu8Data, uint32_t u32Width, uint32_t u32Height);
374#endif
375
376private:
377 static void InvalidateAndUpdateEMT(Display *pDisplay, unsigned uId, bool fUpdateAll);
378 static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
379
380 int videoAccelRefreshProcess(void);
381
382 /* Functions run under VBVA lock. */
383 int videoAccelEnable(bool fEnable, VBVAMEMORY *pVbvaMemory);
384 void videoAccelFlush(void);
385
386#ifdef VBOX_WITH_CROGL
387 int crOglWindowsShow(bool fShow);
388#endif
389
390#ifdef VBOX_WITH_HGSMI
391 volatile uint32_t mu32UpdateVBVAFlags;
392#endif
393
394#ifdef VBOX_WITH_VPX
395 VIDEORECCONTEXT *mpVideoRecCtx;
396 bool maVideoRecEnabled[SchemaDefs::MaxGuestMonitors];
397#endif
398};
399
400void gdImageCopyResampled(uint8_t *dst, uint8_t *src,
401 int dstX, int dstY, int srcX, int srcY,
402 int dstW, int dstH, int srcW, int srcH);
403
404void BitmapScale32(uint8_t *dst, int dstW, int dstH,
405 const uint8_t *src, int iDeltaLine, int srcW, int srcH);
406
407int DisplayMakePNG(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
408 uint8_t **ppu8PNG, uint32_t *pcbPNG, uint32_t *pcxPNG, uint32_t *pcyPNG,
409 uint8_t fLimitSize);
410
411#endif // ____H_DISPLAYIMPL
412/* 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