VirtualBox

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

Last change on this file since 35177 was 35177, checked in by vboxsync, 14 years ago

Main: OnGuestMonitorChanged event.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: DisplayImpl.h 35177 2010-12-16 12:41:35Z 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/pdmdrv.h>
26#include <VBox/VMMDev.h>
27#include <VBox/VBoxVideo.h>
28
29class Console;
30
31enum {
32 ResizeStatus_Void,
33 ResizeStatus_InProgress,
34 ResizeStatus_UpdateDisplayData
35};
36
37typedef struct _DISPLAYFBINFO
38{
39 uint32_t u32Offset;
40 uint32_t u32MaxFramebufferSize;
41 uint32_t u32InformationSize;
42
43 ComPtr<IFramebuffer> pFramebuffer;
44 bool fDisabled;
45
46 LONG xOrigin;
47 LONG yOrigin;
48
49 ULONG w;
50 ULONG h;
51
52 uint16_t u16BitsPerPixel;
53 uint8_t *pu8FramebufferVRAM;
54 uint32_t u32LineSize;
55
56 uint16_t flags;
57
58 VBOXVIDEOINFOHOSTEVENTS *pHostEvents;
59
60 volatile uint32_t u32ResizeStatus;
61
62 /* The Framebuffer has default format and must be updates immediately. */
63 bool fDefaultFormat;
64
65 struct {
66 /* The rectangle that includes all dirty rectangles. */
67 int32_t xLeft;
68 int32_t xRight;
69 int32_t yTop;
70 int32_t yBottom;
71 } dirtyRect;
72
73 struct {
74 bool fPending;
75 ULONG pixelFormat;
76 void *pvVRAM;
77 uint32_t bpp;
78 uint32_t cbLine;
79 int w;
80 int h;
81 uint16_t flags;
82 } pendingResize;
83
84#ifdef VBOX_WITH_HGSMI
85 bool fVBVAEnabled;
86 uint32_t cVBVASkipUpdate;
87 struct {
88 int32_t xLeft;
89 int32_t yTop;
90 int32_t xRight;
91 int32_t yBottom;
92 } vbvaSkippedRect;
93 PVBVAHOSTFLAGS pVBVAHostFlags;
94#endif /* VBOX_WITH_HGSMI */
95} DISPLAYFBINFO;
96
97class ATL_NO_VTABLE Display :
98 public VirtualBoxBase,
99 VBOX_SCRIPTABLE_IMPL(IEventListener),
100 VBOX_SCRIPTABLE_IMPL(IDisplay)
101{
102public:
103
104 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Display, IDisplay)
105
106 DECLARE_NOT_AGGREGATABLE(Display)
107
108 DECLARE_PROTECT_FINAL_CONSTRUCT()
109
110 BEGIN_COM_MAP(Display)
111 COM_INTERFACE_ENTRY(ISupportErrorInfo)
112 COM_INTERFACE_ENTRY(IDisplay)
113 COM_INTERFACE_ENTRY2(IDispatch,IDisplay)
114 COM_INTERFACE_ENTRY(IEventListener)
115 END_COM_MAP()
116
117 DECLARE_EMPTY_CTOR_DTOR (Display)
118
119 HRESULT FinalConstruct();
120 void FinalRelease();
121
122 // public initializer/uninitializer for internal purposes only
123 HRESULT init (Console *aParent);
124 void uninit();
125 int registerSSM(PVM pVM);
126
127 // public methods only for internal purposes
128 int handleDisplayResize (unsigned uScreenId, uint32_t bpp, void *pvVRAM, uint32_t cbLine, int w, int h, uint16_t flags);
129 void handleDisplayUpdateLegacy (int x, int y, int cx, int cy);
130 void handleDisplayUpdate (unsigned uScreenId, int x, int y, int w, int h);
131#ifdef VBOX_WITH_VIDEOHWACCEL
132 void handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
133#endif
134#ifdef VBOX_WITH_CRHGSMI
135 void handleCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd);
136 void handleCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl);
137
138 void handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
139 void handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
140#endif
141 IFramebuffer *getFramebuffer()
142 {
143 return maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
144 }
145 void getFramebufferDimensions(int32_t *px1, int32_t *py1, int32_t *px2,
146 int32_t *py2);
147#ifdef MMSEAMLESS
148 int handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect);
149 int handleQueryVisibleRegion(uint32_t *pcRect, PRTRECT pRect);
150#endif
151
152 int VideoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
153 void VideoAccelFlush (void);
154
155 bool VideoAccelAllowed (void);
156
157 void VideoAccelVRDP (bool fEnable);
158
159 // IEventListener methods
160 STDMETHOD(HandleEvent)(IEvent * aEvent);
161
162 // IDisplay methods
163 STDMETHOD(GetScreenResolution)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel);
164 STDMETHOD(SetFramebuffer)(ULONG aScreenId, IFramebuffer *aFramebuffer);
165 STDMETHOD(GetFramebuffer)(ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin);
166 STDMETHOD(SetVideoModeHint)(ULONG width, ULONG height, ULONG bitsPerPixel, ULONG display);
167 STDMETHOD(TakeScreenShot)(ULONG aScreenId, BYTE *address, ULONG width, ULONG height);
168 STDMETHOD(TakeScreenShotToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
169 STDMETHOD(TakeScreenShotPNGToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
170 STDMETHOD(DrawToScreen)(ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
171 STDMETHOD(InvalidateAndUpdate)();
172 STDMETHOD(ResizeCompleted)(ULONG aScreenId);
173 STDMETHOD(SetSeamlessMode)(BOOL enabled);
174
175 STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
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);
208 static DECLCALLBACK(void) displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl);
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#ifdef VBOX_WITH_OLD_VBVA_LOCK
276 RTCRITSECT mVBVALock;
277 volatile uint32_t mfu32PendingVideoAccelDisable;
278
279 int vbvaLock(void);
280 void vbvaUnlock(void);
281
282public:
283 static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
284
285private:
286 static void InvalidateAndUpdateEMT(Display *pDisplay);
287 static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
288
289 int videoAccelRefreshProcess(void);
290
291 /* Functions run under VBVA lock. */
292 int videoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
293 void videoAccelFlush (void);
294#endif /* VBOX_WITH_OLD_VBVA_LOCK */
295
296#ifdef VBOX_WITH_HGSMI
297 volatile uint32_t mu32UpdateVBVAFlags;
298#endif
299};
300
301void gdImageCopyResampled (uint8_t *dst, uint8_t *src,
302 int dstX, int dstY,
303 int srcX, int srcY,
304 int dstW, int dstH, int srcW, int srcH);
305
306
307void BitmapScale32 (uint8_t *dst,
308 int dstW, int dstH,
309 const uint8_t *src,
310 int iDeltaLine,
311 int srcW, int srcH);
312
313int DisplayMakePNG(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
314 uint8_t **ppu8PNG, uint32_t *pcbPNG, uint32_t *pcxPNG, uint32_t *pcyPNG,
315 uint8_t fLimitSize);
316
317#endif // ____H_DISPLAYIMPL
318/* 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