VirtualBox

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

Last change on this file since 51002 was 50940, checked in by vboxsync, 11 years ago

compilable w/o CROGL

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.5 KB
Line 
1/* $Id: DisplayImpl.h 50940 2014-04-01 11:22:34Z 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 uint32_t cVBVASkipUpdate;
101 struct
102 {
103 int32_t xLeft;
104 int32_t yTop;
105 int32_t xRight;
106 int32_t yBottom;
107 } vbvaSkippedRect;
108 PVBVAHOSTFLAGS pVBVAHostFlags;
109#endif /* VBOX_WITH_HGSMI */
110
111#ifdef VBOX_WITH_CROGL
112 struct
113 {
114 bool fPending;
115 ULONG x;
116 ULONG y;
117 ULONG width;
118 ULONG height;
119 } pendingViewportInfo;
120#endif /* VBOX_WITH_CROGL */
121} DISPLAYFBINFO;
122
123class DisplayMouseInterface
124{
125public:
126 virtual int getScreenResolution(uint32_t cScreen, ULONG *pcx,
127 ULONG *pcy, ULONG *pcBPP, LONG *pXOrigin, LONG *pYOrigin) = 0;
128 virtual void getFramebufferDimensions(int32_t *px1, int32_t *py1,
129 int32_t *px2, int32_t *py2) = 0;
130};
131
132class VMMDev;
133
134class ATL_NO_VTABLE Display :
135 public VirtualBoxBase,
136 VBOX_SCRIPTABLE_IMPL(IEventListener),
137 VBOX_SCRIPTABLE_IMPL(IDisplay),
138 public DisplayMouseInterface
139{
140public:
141
142 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Display, IDisplay)
143
144 DECLARE_NOT_AGGREGATABLE(Display)
145
146 DECLARE_PROTECT_FINAL_CONSTRUCT()
147
148 BEGIN_COM_MAP(Display)
149 VBOX_DEFAULT_INTERFACE_ENTRIES(IDisplay)
150 COM_INTERFACE_ENTRY(IEventListener)
151 END_COM_MAP()
152
153 DECLARE_EMPTY_CTOR_DTOR(Display)
154
155 HRESULT FinalConstruct();
156 void FinalRelease();
157
158 // public initializer/uninitializer for internal purposes only
159 HRESULT init(Console *aParent);
160 void uninit();
161 int registerSSM(PUVM pUVM);
162
163 // public methods only for internal purposes
164 int handleDisplayResize(unsigned uScreenId, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t w, uint32_t h, uint16_t flags);
165 void handleDisplayUpdateLegacy(int x, int y, int cx, int cy);
166 void handleDisplayUpdate(unsigned uScreenId, int x, int y, int w, int h);
167#ifdef VBOX_WITH_VIDEOHWACCEL
168 int handleVHWACommandProcess(PVBOXVHWACMD pCommand);
169#endif
170#ifdef VBOX_WITH_CRHGSMI
171 void handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
172 void handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
173 void handleCrHgsmiCommandProcess(PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd);
174 void handleCrHgsmiControlProcess(PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl);
175#endif
176#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
177 int handleCrHgcmCtlSubmit(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd,
178 PFNCRCTLCOMPLETION pfnCompletion,
179 void *pvCompletion);
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#if defined(VBOX_WITH_HGCM) && defined(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(void) displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd);
269 static DECLCALLBACK(void) displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl);
270
271 static DECLCALLBACK(void) displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
272 static DECLCALLBACK(void) displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
273#endif
274#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
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#endif
281#ifdef VBOX_WITH_HGSMI
282 static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
283 static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
284 static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
285 static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
286 static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
287 static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
288 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);
289#endif
290
291#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
292 static DECLCALLBACK(void) displayCrVRecScreenshotPerform(void *pvCtx, uint32_t uScreen,
293 uint32_t x, uint32_t y,
294 uint32_t uBitsPerPixel, uint32_t uBytesPerLine,
295 uint32_t uGuestWidth, uint32_t uGuestHeight,
296 uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
297 static DECLCALLBACK(bool) displayCrVRecScreenshotBegin(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
298 static DECLCALLBACK(void) displayCrVRecScreenshotEnd(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
299
300 static DECLCALLBACK(void) displayVRecCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
301#endif
302 static DECLCALLBACK(void) displayCrCmdFree(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd, int rc, void *pvCompletion);
303
304 static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
305 static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
306 static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
307 static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
308
309 Console * const mParent;
310 /** Pointer to the associated display driver. */
311 struct DRVMAINDISPLAY *mpDrv;
312 /** Pointer to the device instance for the VMM Device. */
313 PPDMDEVINS mpVMMDev;
314 /** Set after the first attempt to find the VMM Device. */
315 bool mfVMMDevInited;
316
317 unsigned mcMonitors;
318 DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
319
320 /* arguments of the last handleDisplayResize() call */
321 void *mLastAddress;
322 uint32_t mLastBytesPerLine;
323 uint32_t mLastBitsPerPixel;
324 uint32_t mLastWidth;
325 uint32_t mLastHeight;
326 uint16_t mLastFlags;
327
328 VBVAMEMORY *mpVbvaMemory;
329 bool mfVideoAccelEnabled;
330 bool mfVideoAccelVRDP;
331 uint32_t mfu32SupportedOrders;
332
333 int32_t volatile mcVideoAccelVRDPRefs;
334
335 VBVAMEMORY *mpPendingVbvaMemory;
336 bool mfPendingVideoAccelEnable;
337 bool mfMachineRunning;
338#ifdef VBOX_WITH_CROGL
339 bool mfCrOglDataHidden;
340#endif
341
342 uint8_t *mpu8VbvaPartial;
343 uint32_t mcbVbvaPartial;
344
345#ifdef VBOX_WITH_CRHGSMI
346 /* for fast host hgcm calls */
347 HGCMCVSHANDLE mhCrOglSvc;
348#endif
349#ifdef VBOX_WITH_CROGL
350 CR_MAIN_INTERFACE mCrOglCallbacks;
351 volatile uint32_t mfCrOglVideoRecState;
352 CRVBOXHGCMTAKESCREENSHOT mCrOglScreenshotData;
353 VBOXCRCMDCTL_HGCM mCrOglScreenshotCtl;
354#endif
355
356 bool vbvaFetchCmd(VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
357 void vbvaReleaseCmd(VBVACMDHDR *pHdr, int32_t cbCmd);
358
359 void handleResizeCompletedEMT(unsigned uScreenId);
360
361 RTCRITSECT mVBVALock;
362 volatile uint32_t mfu32PendingVideoAccelDisable;
363
364 int vbvaLock(void);
365 void vbvaUnlock(void);
366
367 RTCRITSECT mSaveSeamlessRectLock;
368 int SaveSeamlessRectLock(void);
369 void SaveSeamlessRectUnLock(void);
370
371public:
372 static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
373
374#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
375 static BOOL displayCheckTakeScreenshotCrOgl(Display *pDisplay, ULONG aScreenId, uint8_t *pu8Data, uint32_t u32Width, uint32_t u32Height);
376 int crCtlSubmit(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd, PFNCRCTLCOMPLETION pfnCompletion, void *pvCompletion);
377 int crCtlSubmitSync(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd);
378#endif
379
380private:
381 static void InvalidateAndUpdateEMT(Display *pDisplay, unsigned uId, bool fUpdateAll);
382 static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
383
384 int videoAccelRefreshProcess(void);
385
386 /* Functions run under VBVA lock. */
387 int videoAccelEnable(bool fEnable, VBVAMEMORY *pVbvaMemory);
388 void videoAccelFlush(void);
389
390#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
391 int crOglWindowsShow(bool fShow);
392#endif
393
394#ifdef VBOX_WITH_HGSMI
395 volatile uint32_t mu32UpdateVBVAFlags;
396#endif
397
398#ifdef VBOX_WITH_VPX
399 VIDEORECCONTEXT *mpVideoRecCtx;
400 bool maVideoRecEnabled[SchemaDefs::MaxGuestMonitors];
401#endif
402};
403
404void gdImageCopyResampled(uint8_t *dst, uint8_t *src,
405 int dstX, int dstY, int srcX, int srcY,
406 int dstW, int dstH, int srcW, int srcH);
407
408void BitmapScale32(uint8_t *dst, int dstW, int dstH,
409 const uint8_t *src, int iDeltaLine, int srcW, int srcH);
410
411int DisplayMakePNG(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
412 uint8_t **ppu8PNG, uint32_t *pcbPNG, uint32_t *pcxPNG, uint32_t *pcyPNG,
413 uint8_t fLimitSize);
414
415#endif // ____H_DISPLAYIMPL
416/* 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