VirtualBox

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

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

crOpenGL: presentation infrastructure rework (still work in progress)

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