VirtualBox

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

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

Main: unsigned width/height

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