1 | /* $Id: DisplayImpl.h 30627 2010-07-05 17:08:55Z 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 |
|
---|
29 | class Console;
|
---|
30 |
|
---|
31 | enum {
|
---|
32 | ResizeStatus_Void,
|
---|
33 | ResizeStatus_InProgress,
|
---|
34 | ResizeStatus_UpdateDisplayData
|
---|
35 | };
|
---|
36 |
|
---|
37 | typedef struct _DISPLAYFBINFO
|
---|
38 | {
|
---|
39 | uint32_t u32Offset;
|
---|
40 | uint32_t u32MaxFramebufferSize;
|
---|
41 | uint32_t u32InformationSize;
|
---|
42 |
|
---|
43 | ComPtr<IFramebuffer> pFramebuffer;
|
---|
44 |
|
---|
45 | LONG xOrigin;
|
---|
46 | LONG yOrigin;
|
---|
47 |
|
---|
48 | ULONG w;
|
---|
49 | ULONG h;
|
---|
50 |
|
---|
51 | uint16_t u16BitsPerPixel;
|
---|
52 | uint8_t *pu8FramebufferVRAM;
|
---|
53 | uint32_t u32LineSize;
|
---|
54 |
|
---|
55 | VBOXVIDEOINFOHOSTEVENTS *pHostEvents;
|
---|
56 |
|
---|
57 | volatile uint32_t u32ResizeStatus;
|
---|
58 |
|
---|
59 | /* The Framebuffer has default format and must be updates immediately. */
|
---|
60 | bool fDefaultFormat;
|
---|
61 |
|
---|
62 | struct {
|
---|
63 | /* The rectangle that includes all dirty rectangles. */
|
---|
64 | int32_t xLeft;
|
---|
65 | int32_t xRight;
|
---|
66 | int32_t yTop;
|
---|
67 | int32_t yBottom;
|
---|
68 | } dirtyRect;
|
---|
69 |
|
---|
70 | struct {
|
---|
71 | bool fPending;
|
---|
72 | ULONG pixelFormat;
|
---|
73 | void *pvVRAM;
|
---|
74 | uint32_t bpp;
|
---|
75 | uint32_t cbLine;
|
---|
76 | int w;
|
---|
77 | int h;
|
---|
78 | } pendingResize;
|
---|
79 |
|
---|
80 | #ifdef VBOX_WITH_HGSMI
|
---|
81 | bool fVBVAEnabled;
|
---|
82 | uint32_t cVBVASkipUpdate;
|
---|
83 | struct {
|
---|
84 | int32_t xLeft;
|
---|
85 | int32_t yTop;
|
---|
86 | int32_t xRight;
|
---|
87 | int32_t yBottom;
|
---|
88 | } vbvaSkippedRect;
|
---|
89 | PVBVAHOSTFLAGS pVBVAHostFlags;
|
---|
90 | #endif /* VBOX_WITH_HGSMI */
|
---|
91 | } DISPLAYFBINFO;
|
---|
92 |
|
---|
93 | class ATL_NO_VTABLE Display :
|
---|
94 | public VirtualBoxBase,
|
---|
95 | VBOX_SCRIPTABLE_IMPL(IEventListener),
|
---|
96 | public VirtualBoxSupportErrorInfoImpl<Display, IDisplay>,
|
---|
97 | public VirtualBoxSupportTranslation<Display>,
|
---|
98 | VBOX_SCRIPTABLE_IMPL(IDisplay)
|
---|
99 | {
|
---|
100 |
|
---|
101 | public:
|
---|
102 |
|
---|
103 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Display)
|
---|
104 |
|
---|
105 | DECLARE_NOT_AGGREGATABLE(Display)
|
---|
106 |
|
---|
107 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
108 |
|
---|
109 | BEGIN_COM_MAP(Display)
|
---|
110 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
111 | COM_INTERFACE_ENTRY(IDisplay)
|
---|
112 | COM_INTERFACE_ENTRY2(IDispatch,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);
|
---|
128 | void handleDisplayUpdate (int x, int y, int cx, int cy);
|
---|
129 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
130 | void handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
|
---|
131 | #endif
|
---|
132 | IFramebuffer *getFramebuffer()
|
---|
133 | {
|
---|
134 | return maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
|
---|
135 | }
|
---|
136 | #ifdef MMSEAMLESS
|
---|
137 | int handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect);
|
---|
138 | int handleQueryVisibleRegion(uint32_t *pcRect, PRTRECT pRect);
|
---|
139 | #endif
|
---|
140 |
|
---|
141 | int VideoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
|
---|
142 | void VideoAccelFlush (void);
|
---|
143 |
|
---|
144 | bool VideoAccelAllowed (void);
|
---|
145 |
|
---|
146 | #ifdef VBOX_WITH_VRDP
|
---|
147 | void VideoAccelVRDP (bool fEnable);
|
---|
148 | #endif /* VBOX_WITH_VRDP */
|
---|
149 |
|
---|
150 | // IEventListener methods
|
---|
151 | STDMETHOD(HandleEvent)(IEvent * aEvent);
|
---|
152 |
|
---|
153 | // IDisplay methods
|
---|
154 | STDMETHOD(GetScreenResolution)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel);
|
---|
155 | STDMETHOD(SetFramebuffer)(ULONG aScreenId, IFramebuffer *aFramebuffer);
|
---|
156 | STDMETHOD(GetFramebuffer)(ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin);
|
---|
157 | STDMETHOD(SetVideoModeHint)(ULONG width, ULONG height, ULONG bitsPerPixel, ULONG display);
|
---|
158 | STDMETHOD(TakeScreenShot)(ULONG aScreenId, BYTE *address, ULONG width, ULONG height);
|
---|
159 | STDMETHOD(TakeScreenShotToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
|
---|
160 | STDMETHOD(DrawToScreen)(ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
|
---|
161 | STDMETHOD(InvalidateAndUpdate)();
|
---|
162 | STDMETHOD(ResizeCompleted)(ULONG aScreenId);
|
---|
163 | STDMETHOD(SetSeamlessMode)(BOOL enabled);
|
---|
164 |
|
---|
165 | STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
|
---|
166 |
|
---|
167 | // for VirtualBoxSupportErrorInfoImpl
|
---|
168 | static const wchar_t *getComponentName() { return L"Display"; }
|
---|
169 |
|
---|
170 | static const PDMDRVREG DrvReg;
|
---|
171 |
|
---|
172 | private:
|
---|
173 |
|
---|
174 | void updateDisplayData(void);
|
---|
175 |
|
---|
176 | static DECLCALLBACK(int) changeFramebuffer(Display *that, IFramebuffer *aFB, unsigned uScreenId);
|
---|
177 |
|
---|
178 | static DECLCALLBACK(void*) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
|
---|
179 | static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
|
---|
180 | static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
|
---|
181 | static DECLCALLBACK(int) displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy);
|
---|
182 | static DECLCALLBACK(void) displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
|
---|
183 | uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
|
---|
184 | static DECLCALLBACK(void) displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface);
|
---|
185 | static DECLCALLBACK(void) displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface);
|
---|
186 | static DECLCALLBACK(void) displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
|
---|
187 | static DECLCALLBACK(void) displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
|
---|
188 | static DECLCALLBACK(void) displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
|
---|
189 |
|
---|
190 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
191 | static DECLCALLBACK(void) displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | #ifdef VBOX_WITH_HGSMI
|
---|
195 | static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
|
---|
196 | static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
|
---|
197 | static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
|
---|
198 | static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
|
---|
199 | static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
|
---|
200 | static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
|
---|
201 | 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);
|
---|
202 | #endif
|
---|
203 |
|
---|
204 |
|
---|
205 | static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
|
---|
206 | static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
|
---|
207 | static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
|
---|
208 | static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
|
---|
209 |
|
---|
210 | Console * const mParent;
|
---|
211 | /** Pointer to the associated display driver. */
|
---|
212 | struct DRVMAINDISPLAY *mpDrv;
|
---|
213 | /** Pointer to the device instance for the VMM Device. */
|
---|
214 | PPDMDEVINS mpVMMDev;
|
---|
215 | /** Set after the first attempt to find the VMM Device. */
|
---|
216 | bool mfVMMDevInited;
|
---|
217 |
|
---|
218 | unsigned mcMonitors;
|
---|
219 | DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
|
---|
220 |
|
---|
221 | bool mFramebufferOpened;
|
---|
222 |
|
---|
223 | /* arguments of the last handleDisplayResize() call */
|
---|
224 | void *mLastAddress;
|
---|
225 | uint32_t mLastBytesPerLine;
|
---|
226 | uint32_t mLastBitsPerPixel;
|
---|
227 | int mLastWidth;
|
---|
228 | int mLastHeight;
|
---|
229 |
|
---|
230 | VBVAMEMORY *mpVbvaMemory;
|
---|
231 | bool mfVideoAccelEnabled;
|
---|
232 | bool mfVideoAccelVRDP;
|
---|
233 | uint32_t mfu32SupportedOrders;
|
---|
234 |
|
---|
235 | int32_t volatile mcVideoAccelVRDPRefs;
|
---|
236 |
|
---|
237 | VBVAMEMORY *mpPendingVbvaMemory;
|
---|
238 | bool mfPendingVideoAccelEnable;
|
---|
239 | bool mfMachineRunning;
|
---|
240 |
|
---|
241 | uint8_t *mpu8VbvaPartial;
|
---|
242 | uint32_t mcbVbvaPartial;
|
---|
243 |
|
---|
244 | bool vbvaFetchCmd (VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
|
---|
245 | void vbvaReleaseCmd (VBVACMDHDR *pHdr, int32_t cbCmd);
|
---|
246 |
|
---|
247 | void handleResizeCompletedEMT (void);
|
---|
248 |
|
---|
249 | #ifdef VBOX_WITH_OLD_VBVA_LOCK
|
---|
250 | RTCRITSECT mVBVALock;
|
---|
251 | volatile uint32_t mfu32PendingVideoAccelDisable;
|
---|
252 |
|
---|
253 | int vbvaLock(void);
|
---|
254 | void vbvaUnlock(void);
|
---|
255 |
|
---|
256 | public:
|
---|
257 | static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
|
---|
258 |
|
---|
259 | private:
|
---|
260 | static void InvalidateAndUpdateEMT(Display *pDisplay);
|
---|
261 | static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
|
---|
262 |
|
---|
263 | int videoAccelRefreshProcess(void);
|
---|
264 |
|
---|
265 | /* Functions run under VBVA lock. */
|
---|
266 | int videoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
|
---|
267 | void videoAccelFlush (void);
|
---|
268 | #endif /* VBOX_WITH_OLD_VBVA_LOCK */
|
---|
269 |
|
---|
270 | #ifdef VBOX_WITH_HGSMI
|
---|
271 | volatile uint32_t mu32UpdateVBVAFlags;
|
---|
272 | #endif
|
---|
273 | };
|
---|
274 |
|
---|
275 | void gdImageCopyResampled (uint8_t *dst, uint8_t *src,
|
---|
276 | int dstX, int dstY,
|
---|
277 | int srcX, int srcY,
|
---|
278 | int dstW, int dstH, int srcW, int srcH);
|
---|
279 |
|
---|
280 |
|
---|
281 | #endif // ____H_DISPLAYIMPL
|
---|
282 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|