VirtualBox

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

Last change on this file since 46284 was 46123, checked in by vboxsync, 12 years ago

Main/VPX, VBoxManage: added IMachine::VideoCaptureScreens and IDisplay::{enableVideoCapture,disableVideoCapture}

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