VirtualBox

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

Last change on this file since 50736 was 50677, checked in by vboxsync, 11 years ago

wddm: misc bugfixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.5 KB
Line 
1/* $Id: DisplayImpl.h 50677 2014-03-04 13:21:14Z 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
177#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
178 void handleCrAsyncCmdCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
179 void handleCrVRecScreenshotPerform(uint32_t uScreen,
180 uint32_t x, uint32_t y, uint32_t uPixelFormat, uint32_t uBitsPerPixel,
181 uint32_t uBytesPerLine, uint32_t uGuestWidth, uint32_t uGuestHeight,
182 uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
183 bool handleCrVRecScreenshotBegin(uint32_t uScreen, uint64_t u64TimeStamp);
184 void handleCrVRecScreenshotEnd(uint32_t uScreen, uint64_t u64TimeStamp);
185 void handleVRecCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
186#endif
187
188 int notifyCroglResize(const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
189
190 IFramebuffer *getFramebuffer()
191 {
192 return maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
193 }
194 void getFramebufferDimensions(int32_t *px1, int32_t *py1, int32_t *px2, int32_t *py2);
195 int getScreenResolution(uint32_t cScreen, ULONG *pcx, ULONG *pcy,
196 ULONG *pcBPP, LONG *pXOrigin, LONG *pYOrigin)
197 {
198 return GetScreenResolution(cScreen, pcx, pcy, pcBPP, pXOrigin, pYOrigin);
199 }
200
201 int handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect);
202 int handleQueryVisibleRegion(uint32_t *pcRect, PRTRECT pRect);
203
204 int VideoAccelEnable(bool fEnable, VBVAMEMORY *pVbvaMemory);
205 void VideoAccelFlush(void);
206 bool VideoAccelAllowed(void);
207 void VideoAccelVRDP(bool fEnable);
208
209 int VideoCaptureStart();
210 void VideoCaptureStop();
211 int VideoCaptureEnableScreens(ComSafeArrayIn(BOOL, aScreens));
212
213 // IEventListener methods
214 STDMETHOD(HandleEvent)(IEvent * aEvent);
215
216 // IDisplay methods
217 STDMETHOD(GetScreenResolution)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel, LONG *aXOrigin, LONG *aYOrigin);
218 STDMETHOD(SetFramebuffer)(ULONG aScreenId, IFramebuffer *aFramebuffer);
219 STDMETHOD(GetFramebuffer)(ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin);
220 STDMETHOD(SetVideoModeHint)(ULONG aDisplay, BOOL aEnabled, BOOL aChangeOrigin, LONG aOriginX, LONG aOriginY, ULONG aWidth, ULONG aHeight, ULONG aBitsPerPixel);
221 STDMETHOD(TakeScreenShot)(ULONG aScreenId, BYTE *address, ULONG width, ULONG height);
222 STDMETHOD(TakeScreenShotToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
223 STDMETHOD(TakeScreenShotPNGToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
224 STDMETHOD(DrawToScreen)(ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
225 STDMETHOD(InvalidateAndUpdate)();
226 STDMETHOD(ResizeCompleted)(ULONG aScreenId);
227 STDMETHOD(SetSeamlessMode)(BOOL enabled);
228
229 STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
230
231 STDMETHOD(ViewportChanged)(ULONG aScreenId, ULONG x, ULONG y, ULONG width, ULONG height);
232
233 static const PDMDRVREG DrvReg;
234
235private:
236
237 int updateDisplayData(void);
238
239#ifdef VBOX_WITH_CRHGSMI
240 void setupCrHgsmiData(void);
241 void destructCrHgsmiData(void);
242#endif
243
244#ifdef VBOX_WITH_CROGL
245 void crViewportNotify(class VMMDev *pVMMDev, ULONG aScreenId, ULONG x, ULONG y, ULONG width, ULONG height);
246#endif
247
248 static DECLCALLBACK(int) changeFramebuffer(Display *that, IFramebuffer *aFB, unsigned uScreenId);
249
250 static DECLCALLBACK(void*) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
251 static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
252 static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
253 static DECLCALLBACK(int) displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy);
254 static DECLCALLBACK(void) displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
255 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
256 static DECLCALLBACK(void) displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface);
257 static DECLCALLBACK(void) displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface);
258 static DECLCALLBACK(void) displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
259 static DECLCALLBACK(void) displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
260 static DECLCALLBACK(void) displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
261
262#ifdef VBOX_WITH_VIDEOHWACCEL
263 static DECLCALLBACK(int) displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
264#endif
265
266#ifdef VBOX_WITH_CRHGSMI
267 static DECLCALLBACK(void) displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd);
268 static DECLCALLBACK(void) displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl);
269
270 static DECLCALLBACK(void) displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
271 static DECLCALLBACK(void) displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
272#endif
273
274#ifdef VBOX_WITH_HGSMI
275 static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
276 static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
277 static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
278 static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
279 static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
280 static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
281 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);
282#endif
283
284#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
285 static DECLCALLBACK(void) displayCrVRecScreenshotPerform(void *pvCtx, uint32_t uScreen,
286 uint32_t x, uint32_t y,
287 uint32_t uBitsPerPixel, uint32_t uBytesPerLine,
288 uint32_t uGuestWidth, uint32_t uGuestHeight,
289 uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
290 static DECLCALLBACK(bool) displayCrVRecScreenshotBegin(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
291 static DECLCALLBACK(void) displayCrVRecScreenshotEnd(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
292
293 static DECLCALLBACK(void) displayVRecCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
294 static DECLCALLBACK(void) displayCrAsyncCmdCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
295#endif
296
297 static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
298 static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
299 static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
300 static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
301
302 Console * const mParent;
303 /** Pointer to the associated display driver. */
304 struct DRVMAINDISPLAY *mpDrv;
305 /** Pointer to the device instance for the VMM Device. */
306 PPDMDEVINS mpVMMDev;
307 /** Set after the first attempt to find the VMM Device. */
308 bool mfVMMDevInited;
309
310 unsigned mcMonitors;
311 DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
312
313 /* arguments of the last handleDisplayResize() call */
314 void *mLastAddress;
315 uint32_t mLastBytesPerLine;
316 uint32_t mLastBitsPerPixel;
317 uint32_t mLastWidth;
318 uint32_t mLastHeight;
319 uint16_t mLastFlags;
320
321 VBVAMEMORY *mpVbvaMemory;
322 bool mfVideoAccelEnabled;
323 bool mfVideoAccelVRDP;
324 uint32_t mfu32SupportedOrders;
325
326 int32_t volatile mcVideoAccelVRDPRefs;
327
328 VBVAMEMORY *mpPendingVbvaMemory;
329 bool mfPendingVideoAccelEnable;
330 bool mfMachineRunning;
331#ifdef VBOX_WITH_CROGL
332 bool mfCrOglDataHidden;
333#endif
334
335 uint8_t *mpu8VbvaPartial;
336 uint32_t mcbVbvaPartial;
337
338#ifdef VBOX_WITH_CRHGSMI
339 /* for fast host hgcm calls */
340 HGCMCVSHANDLE mhCrOglSvc;
341#endif
342#ifdef VBOX_WITH_CROGL
343 CR_MAIN_INTERFACE mCrOglCallbacks;
344 volatile uint32_t mfCrOglVideoRecState;
345 CRVBOXHGCMTAKESCREENSHOT mCrOglScreenshotData;
346#endif
347
348 bool vbvaFetchCmd(VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
349 void vbvaReleaseCmd(VBVACMDHDR *pHdr, int32_t cbCmd);
350
351 void handleResizeCompletedEMT(void);
352
353 RTCRITSECT mVBVALock;
354 volatile uint32_t mfu32PendingVideoAccelDisable;
355
356 int vbvaLock(void);
357 void vbvaUnlock(void);
358
359 RTCRITSECT mSaveSeamlessRectLock;
360 int SaveSeamlessRectLock(void);
361 void SaveSeamlessRectUnLock(void);
362
363public:
364 static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
365
366#ifdef VBOX_WITH_CROGL
367 static BOOL displayCheckTakeScreenshotCrOgl(Display *pDisplay, ULONG aScreenId, uint8_t *pu8Data, uint32_t u32Width, uint32_t u32Height);
368#endif
369
370private:
371 static void InvalidateAndUpdateEMT(Display *pDisplay, unsigned uId, bool fUpdateAll);
372 static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
373
374 int videoAccelRefreshProcess(void);
375
376 /* Functions run under VBVA lock. */
377 int videoAccelEnable(bool fEnable, VBVAMEMORY *pVbvaMemory);
378 void videoAccelFlush(void);
379
380#ifdef VBOX_WITH_CROGL
381 int crOglWindowsShow(bool fShow);
382#endif
383
384#ifdef VBOX_WITH_HGSMI
385 volatile uint32_t mu32UpdateVBVAFlags;
386#endif
387
388#ifdef VBOX_WITH_VPX
389 VIDEORECCONTEXT *mpVideoRecCtx;
390 bool maVideoRecEnabled[SchemaDefs::MaxGuestMonitors];
391#endif
392};
393
394void gdImageCopyResampled(uint8_t *dst, uint8_t *src,
395 int dstX, int dstY, int srcX, int srcY,
396 int dstW, int dstH, int srcW, int srcH);
397
398void BitmapScale32(uint8_t *dst, int dstW, int dstH,
399 const uint8_t *src, int iDeltaLine, int srcW, int srcH);
400
401int DisplayMakePNG(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
402 uint8_t **ppu8PNG, uint32_t *pcbPNG, uint32_t *pcxPNG, uint32_t *pcyPNG,
403 uint8_t fLimitSize);
404
405#endif // ____H_DISPLAYIMPL
406/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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