VirtualBox

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

Last change on this file since 47158 was 46523, checked in by vboxsync, 12 years ago

Main/VBoxManage: allow to enable video recording at VM runtime

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.1 KB
Line 
1/* $Id: DisplayImpl.h 46523 2013-06-13 12:02:48Z 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 int w;
88 int 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} DISPLAYFBINFO;
105
106class ATL_NO_VTABLE Display :
107 public VirtualBoxBase,
108 VBOX_SCRIPTABLE_IMPL(IEventListener),
109 VBOX_SCRIPTABLE_IMPL(IDisplay)
110{
111public:
112
113 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Display, IDisplay)
114
115 DECLARE_NOT_AGGREGATABLE(Display)
116
117 DECLARE_PROTECT_FINAL_CONSTRUCT()
118
119 BEGIN_COM_MAP(Display)
120 VBOX_DEFAULT_INTERFACE_ENTRIES(IDisplay)
121 COM_INTERFACE_ENTRY(IEventListener)
122 END_COM_MAP()
123
124 DECLARE_EMPTY_CTOR_DTOR(Display)
125
126 HRESULT FinalConstruct();
127 void FinalRelease();
128
129 // public initializer/uninitializer for internal purposes only
130 HRESULT init(Console *aParent);
131 void uninit();
132 int registerSSM(PUVM pUVM);
133
134 // public methods only for internal purposes
135 int handleDisplayResize(unsigned uScreenId, uint32_t bpp, void *pvVRAM, uint32_t cbLine, int w, int h, uint16_t flags);
136 void handleDisplayUpdateLegacy(int x, int y, int cx, int cy);
137 void handleDisplayUpdate(unsigned uScreenId, int x, int y, int w, int h);
138#ifdef VBOX_WITH_VIDEOHWACCEL
139 void handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
140#endif
141#ifdef VBOX_WITH_CRHGSMI
142 void handleCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd);
143 void handleCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl);
144
145 void handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
146 void handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
147#endif
148 IFramebuffer *getFramebuffer()
149 {
150 return maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
151 }
152 void getFramebufferDimensions(int32_t *px1, int32_t *py1, int32_t *px2, int32_t *py2);
153
154 int handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect);
155 int handleQueryVisibleRegion(uint32_t *pcRect, PRTRECT pRect);
156
157 int VideoAccelEnable(bool fEnable, VBVAMEMORY *pVbvaMemory);
158 void VideoAccelFlush(void);
159 bool VideoAccelAllowed(void);
160 void VideoAccelVRDP(bool fEnable);
161
162 int VideoCaptureStart();
163 void VideoCaptureStop();
164 int VideoCaptureEnableScreens(ComSafeArrayIn(BOOL, aScreens));
165
166 // IEventListener methods
167 STDMETHOD(HandleEvent)(IEvent * aEvent);
168
169 // IDisplay methods
170 STDMETHOD(GetScreenResolution)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel);
171 STDMETHOD(SetFramebuffer)(ULONG aScreenId, IFramebuffer *aFramebuffer);
172 STDMETHOD(GetFramebuffer)(ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin);
173 STDMETHOD(SetVideoModeHint)(ULONG aDisplay, BOOL aEnabled, BOOL aChangeOrigin, LONG aOriginX, LONG aOriginY, ULONG aWidth, ULONG aHeight, ULONG aBitsPerPixel);
174 STDMETHOD(TakeScreenShot)(ULONG aScreenId, BYTE *address, ULONG width, ULONG height);
175 STDMETHOD(TakeScreenShotToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
176 STDMETHOD(TakeScreenShotPNGToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
177 STDMETHOD(DrawToScreen)(ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
178 STDMETHOD(InvalidateAndUpdate)();
179 STDMETHOD(ResizeCompleted)(ULONG aScreenId);
180 STDMETHOD(SetSeamlessMode)(BOOL enabled);
181
182 STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
183
184 STDMETHOD(ViewportChanged)(ULONG aScreenId, ULONG x, ULONG y, ULONG width, ULONG height);
185
186 static const PDMDRVREG DrvReg;
187
188private:
189
190 void updateDisplayData(void);
191
192#ifdef VBOX_WITH_CRHGSMI
193 void setupCrHgsmiData(void);
194 void destructCrHgsmiData(void);
195#endif
196
197 static DECLCALLBACK(int) changeFramebuffer(Display *that, IFramebuffer *aFB, unsigned uScreenId);
198
199 static DECLCALLBACK(void*) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
200 static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
201 static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
202 static DECLCALLBACK(int) displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy);
203 static DECLCALLBACK(void) displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
204 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
205 static DECLCALLBACK(void) displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface);
206 static DECLCALLBACK(void) displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface);
207 static DECLCALLBACK(void) displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
208 static DECLCALLBACK(void) displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
209 static DECLCALLBACK(void) displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
210
211#ifdef VBOX_WITH_VIDEOHWACCEL
212 static DECLCALLBACK(void) displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
213#endif
214
215#ifdef VBOX_WITH_CRHGSMI
216 static DECLCALLBACK(void) displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd);
217 static DECLCALLBACK(void) displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl);
218
219 static DECLCALLBACK(void) displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
220 static DECLCALLBACK(void) displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
221#endif
222
223#ifdef VBOX_WITH_HGSMI
224 static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
225 static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
226 static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
227 static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
228 static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
229 static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
230 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);
231#endif
232
233 static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
234 static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
235 static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
236 static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
237
238 Console * const mParent;
239 /** Pointer to the associated display driver. */
240 struct DRVMAINDISPLAY *mpDrv;
241 /** Pointer to the device instance for the VMM Device. */
242 PPDMDEVINS mpVMMDev;
243 /** Set after the first attempt to find the VMM Device. */
244 bool mfVMMDevInited;
245
246 unsigned mcMonitors;
247 DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
248
249 /* arguments of the last handleDisplayResize() call */
250 void *mLastAddress;
251 uint32_t mLastBytesPerLine;
252 uint32_t mLastBitsPerPixel;
253 int mLastWidth;
254 int mLastHeight;
255 uint16_t mLastFlags;
256
257 VBVAMEMORY *mpVbvaMemory;
258 bool mfVideoAccelEnabled;
259 bool mfVideoAccelVRDP;
260 uint32_t mfu32SupportedOrders;
261
262 int32_t volatile mcVideoAccelVRDPRefs;
263
264 VBVAMEMORY *mpPendingVbvaMemory;
265 bool mfPendingVideoAccelEnable;
266 bool mfMachineRunning;
267
268 uint8_t *mpu8VbvaPartial;
269 uint32_t mcbVbvaPartial;
270
271#ifdef VBOX_WITH_CRHGSMI
272 /* for fast host hgcm calls */
273 HGCMCVSHANDLE mhCrOglSvc;
274#endif
275
276 bool vbvaFetchCmd(VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
277 void vbvaReleaseCmd(VBVACMDHDR *pHdr, int32_t cbCmd);
278
279 void handleResizeCompletedEMT(void);
280
281 RTCRITSECT mVBVALock;
282 volatile uint32_t mfu32PendingVideoAccelDisable;
283
284 int vbvaLock(void);
285 void vbvaUnlock(void);
286
287 RTCRITSECT mSaveSeamlessRectLock;
288 int SaveSeamlessRectLock(void);
289 void SaveSeamlessRectUnLock(void);
290
291public:
292 static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
293
294private:
295 static void InvalidateAndUpdateEMT(Display *pDisplay, unsigned uId, bool fUpdateAll);
296 static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
297
298 int videoAccelRefreshProcess(void);
299
300 /* Functions run under VBVA lock. */
301 int videoAccelEnable(bool fEnable, VBVAMEMORY *pVbvaMemory);
302 void videoAccelFlush(void);
303
304#ifdef VBOX_WITH_HGSMI
305 volatile uint32_t mu32UpdateVBVAFlags;
306#endif
307
308#ifdef VBOX_WITH_VPX
309 VIDEORECCONTEXT *mpVideoRecCtx;
310 bool maVideoRecEnabled[SchemaDefs::MaxGuestMonitors];
311#endif
312};
313
314void gdImageCopyResampled(uint8_t *dst, uint8_t *src,
315 int dstX, int dstY, int srcX, int srcY,
316 int dstW, int dstH, int srcW, int srcH);
317
318void BitmapScale32(uint8_t *dst, int dstW, int dstH,
319 const uint8_t *src, int iDeltaLine, int srcW, int srcH);
320
321int DisplayMakePNG(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
322 uint8_t **ppu8PNG, uint32_t *pcbPNG, uint32_t *pcxPNG, uint32_t *pcyPNG,
323 uint8_t fLimitSize);
324
325#endif // ____H_DISPLAYIMPL
326/* 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