VirtualBox

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

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

Main/MouseImpl: restored Mouse test case, not yet building though; fix a burn.

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