VirtualBox

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

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

Main/DisplayImpl: 6711: Fix for the race condition where in GA sends the new resize rectangle dimensions while framebuffer is still resizing. At this moment DisplayImpl doesn't have the updated framebuffer rectangles and as a result the intersection between the new rectangles passed by GA and current frambuffe is NULL. Thus DisplayImpl rejects the rectangles passed from GA and GUI receives NULL for drawing.
The fix for the issue is to let DisplayImpl save the rectangles passed from the GA till the point framebuffer is completely resized and then pass these rectangle to GUI after checking for intersection with the curent newly resized framebuffer.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1/* $Id: DisplayImpl.h 46065 2013-05-14 13:15:42Z 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(DrawToScreen)(ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
173 STDMETHOD(InvalidateAndUpdate)();
174 STDMETHOD(ResizeCompleted)(ULONG aScreenId);
175 STDMETHOD(SetSeamlessMode)(BOOL enabled);
176
177 STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
178
179 STDMETHOD(ViewportChanged)(ULONG aScreenId, ULONG x, ULONG y, ULONG width, ULONG height);
180
181 static const PDMDRVREG DrvReg;
182
183private:
184
185 void updateDisplayData(void);
186
187#ifdef VBOX_WITH_CRHGSMI
188 void setupCrHgsmiData(void);
189 void destructCrHgsmiData(void);
190#endif
191
192 static DECLCALLBACK(int) changeFramebuffer(Display *that, IFramebuffer *aFB, unsigned uScreenId);
193
194 static DECLCALLBACK(void*) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
195 static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
196 static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
197 static DECLCALLBACK(int) displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy);
198 static DECLCALLBACK(void) displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
199 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
200 static DECLCALLBACK(void) displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface);
201 static DECLCALLBACK(void) displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface);
202 static DECLCALLBACK(void) displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
203 static DECLCALLBACK(void) displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
204 static DECLCALLBACK(void) displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
205
206#ifdef VBOX_WITH_VIDEOHWACCEL
207 static DECLCALLBACK(void) displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
208#endif
209
210#ifdef VBOX_WITH_CRHGSMI
211 static DECLCALLBACK(void) displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd);
212 static DECLCALLBACK(void) displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl);
213
214 static DECLCALLBACK(void) displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
215 static DECLCALLBACK(void) displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
216#endif
217
218#ifdef VBOX_WITH_HGSMI
219 static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
220 static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
221 static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
222 static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
223 static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
224 static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
225 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);
226#endif
227
228
229 static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
230 static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
231 static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
232 static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
233
234 Console * const mParent;
235 /** Pointer to the associated display driver. */
236 struct DRVMAINDISPLAY *mpDrv;
237 /** Pointer to the device instance for the VMM Device. */
238 PPDMDEVINS mpVMMDev;
239 /** Set after the first attempt to find the VMM Device. */
240 bool mfVMMDevInited;
241
242 unsigned mcMonitors;
243 DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
244
245 /* arguments of the last handleDisplayResize() call */
246 void *mLastAddress;
247 uint32_t mLastBytesPerLine;
248 uint32_t mLastBitsPerPixel;
249 int mLastWidth;
250 int mLastHeight;
251 uint16_t mLastFlags;
252
253 VBVAMEMORY *mpVbvaMemory;
254 bool mfVideoAccelEnabled;
255 bool mfVideoAccelVRDP;
256 uint32_t mfu32SupportedOrders;
257
258 int32_t volatile mcVideoAccelVRDPRefs;
259
260 VBVAMEMORY *mpPendingVbvaMemory;
261 bool mfPendingVideoAccelEnable;
262 bool mfMachineRunning;
263
264 uint8_t *mpu8VbvaPartial;
265 uint32_t mcbVbvaPartial;
266
267#ifdef VBOX_WITH_CRHGSMI
268 /* for fast host hgcm calls */
269 HGCMCVSHANDLE mhCrOglSvc;
270#endif
271
272 bool vbvaFetchCmd(VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
273 void vbvaReleaseCmd(VBVACMDHDR *pHdr, int32_t cbCmd);
274
275 void handleResizeCompletedEMT(void);
276
277 RTCRITSECT mVBVALock;
278 volatile uint32_t mfu32PendingVideoAccelDisable;
279
280 int vbvaLock(void);
281 void vbvaUnlock(void);
282
283 RTCRITSECT mSaveSeamlessRectLock;
284 int SaveSeamlessRectLock(void);
285 void SaveSeamlessRectUnLock(void);
286
287public:
288 static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
289
290private:
291 static void InvalidateAndUpdateEMT(Display *pDisplay, unsigned uId, bool fUpdateAll);
292 static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
293
294 int videoAccelRefreshProcess(void);
295
296 /* Functions run under VBVA lock. */
297 int videoAccelEnable(bool fEnable, VBVAMEMORY *pVbvaMemory);
298 void videoAccelFlush(void);
299
300#ifdef VBOX_WITH_HGSMI
301 volatile uint32_t mu32UpdateVBVAFlags;
302#endif
303
304#ifdef VBOX_WITH_VPX
305 VIDEORECCONTEXT *mpVideoRecCtx;
306#endif
307};
308
309void gdImageCopyResampled(uint8_t *dst, uint8_t *src,
310 int dstX, int dstY,
311 int srcX, int srcY,
312 int dstW, int dstH, int srcW, int srcH);
313
314
315void BitmapScale32(uint8_t *dst,
316 int dstW, int dstH,
317 const uint8_t *src,
318 int iDeltaLine,
319 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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette