VirtualBox

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

Last change on this file since 43831 was 42878, checked in by vboxsync, 12 years ago

Main/VideoRec: a few fixes

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