VirtualBox

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

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

Main: onMousePointerShapeChange reworked

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* $Id: DisplayImpl.h 29518 2010-05-17 10:06:22Z 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
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
93class ATL_NO_VTABLE Display :
94 public VirtualBoxBase,
95 VBOX_SCRIPTABLE_IMPL(IConsoleCallback),
96 public VirtualBoxSupportErrorInfoImpl<Display, IDisplay>,
97 public VirtualBoxSupportTranslation<Display>,
98 VBOX_SCRIPTABLE_IMPL(IDisplay)
99{
100
101public:
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(IConsoleCallback)
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 // IConsoleCallback methods
151 STDMETHOD(OnMousePointerShapeChange)(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
152 ULONG width, ULONG height, ComSafeArrayIn(BYTE,shape))
153 {
154 return S_OK;
155 }
156
157 STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL supportsRelative, BOOL needsHostCursor)
158 {
159 return S_OK;
160 }
161
162 STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
163 {
164 return S_OK;
165 }
166
167 STDMETHOD(OnStateChange)(MachineState_T machineState);
168
169 STDMETHOD(OnAdditionsStateChange)()
170 {
171 return S_OK;
172 }
173
174 STDMETHOD(OnNetworkAdapterChange) (INetworkAdapter *aNetworkAdapter)
175 {
176 return S_OK;
177 }
178
179 STDMETHOD(OnSerialPortChange) (ISerialPort *aSerialPort)
180 {
181 return S_OK;
182 }
183
184 STDMETHOD(OnParallelPortChange) (IParallelPort *aParallelPort)
185 {
186 return S_OK;
187 }
188
189 STDMETHOD(OnStorageControllerChange) ()
190 {
191 return S_OK;
192 }
193
194 STDMETHOD(OnMediumChange)(IMediumAttachment *aMediumAttachment)
195 {
196 return S_OK;
197 }
198
199 STDMETHOD(OnCPUChange)(ULONG aCPU, BOOL aRemove)
200 {
201 return S_OK;
202 }
203
204 STDMETHOD(OnVRDPServerChange)()
205 {
206 return S_OK;
207 }
208
209 STDMETHOD(OnRemoteDisplayInfoChange)()
210 {
211 return S_OK;
212 }
213
214 STDMETHOD(OnUSBControllerChange)()
215 {
216 return S_OK;
217 }
218
219 STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *device, BOOL attached,
220 IVirtualBoxErrorInfo *message)
221 {
222 return S_OK;
223 }
224
225 STDMETHOD(OnSharedFolderChange) (Scope_T aScope)
226 {
227 return S_OK;
228 }
229
230 STDMETHOD(OnRuntimeError)(BOOL fatal, IN_BSTR id, IN_BSTR message)
231 {
232 return S_OK;
233 }
234
235 STDMETHOD(OnCanShowWindow)(BOOL *canShow)
236 {
237 if (canShow)
238 *canShow = TRUE;
239 return S_OK;
240 }
241
242 STDMETHOD(OnShowWindow)(ULONG64 *winId)
243 {
244 if (winId)
245 *winId = 0;
246 return S_OK;
247 }
248
249 // IDisplay methods
250 STDMETHOD(GetScreenResolution)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel);
251 STDMETHOD(SetFramebuffer)(ULONG aScreenId, IFramebuffer *aFramebuffer);
252 STDMETHOD(GetFramebuffer)(ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin);
253 STDMETHOD(SetVideoModeHint)(ULONG width, ULONG height, ULONG bitsPerPixel, ULONG display);
254 STDMETHOD(TakeScreenShot)(ULONG aScreenId, BYTE *address, ULONG width, ULONG height);
255 STDMETHOD(TakeScreenShotToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
256 STDMETHOD(DrawToScreen)(ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
257 STDMETHOD(InvalidateAndUpdate)();
258 STDMETHOD(ResizeCompleted)(ULONG aScreenId);
259 STDMETHOD(SetSeamlessMode)(BOOL enabled);
260
261 STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
262
263 // for VirtualBoxSupportErrorInfoImpl
264 static const wchar_t *getComponentName() { return L"Display"; }
265
266 static const PDMDRVREG DrvReg;
267
268private:
269
270 void updateDisplayData(void);
271
272 static DECLCALLBACK(int) changeFramebuffer(Display *that, IFramebuffer *aFB, unsigned uScreenId);
273
274 static DECLCALLBACK(void*) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
275 static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
276 static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
277 static DECLCALLBACK(int) displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy);
278 static DECLCALLBACK(void) displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
279 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
280 static DECLCALLBACK(void) displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface);
281 static DECLCALLBACK(void) displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface);
282 static DECLCALLBACK(void) displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
283 static DECLCALLBACK(void) displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
284 static DECLCALLBACK(void) displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
285
286#ifdef VBOX_WITH_VIDEOHWACCEL
287 static DECLCALLBACK(void) displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
288#endif
289
290#ifdef VBOX_WITH_HGSMI
291 static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
292 static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
293 static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
294 static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
295 static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
296 static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
297 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);
298#endif
299
300
301 static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
302 static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
303 static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
304 static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
305
306 Console * const mParent;
307 /** Pointer to the associated display driver. */
308 struct DRVMAINDISPLAY *mpDrv;
309 /** Pointer to the device instance for the VMM Device. */
310 PPDMDEVINS mpVMMDev;
311 /** Set after the first attempt to find the VMM Device. */
312 bool mfVMMDevInited;
313
314 unsigned mcMonitors;
315 DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
316
317 bool mFramebufferOpened;
318
319 /* arguments of the last handleDisplayResize() call */
320 void *mLastAddress;
321 uint32_t mLastBytesPerLine;
322 uint32_t mLastBitsPerPixel;
323 int mLastWidth;
324 int mLastHeight;
325
326 VBVAMEMORY *mpVbvaMemory;
327 bool mfVideoAccelEnabled;
328 bool mfVideoAccelVRDP;
329 uint32_t mfu32SupportedOrders;
330
331 int32_t volatile mcVideoAccelVRDPRefs;
332
333 VBVAMEMORY *mpPendingVbvaMemory;
334 bool mfPendingVideoAccelEnable;
335 bool mfMachineRunning;
336
337 uint8_t *mpu8VbvaPartial;
338 uint32_t mcbVbvaPartial;
339
340 bool vbvaFetchCmd (VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
341 void vbvaReleaseCmd (VBVACMDHDR *pHdr, int32_t cbCmd);
342
343 void handleResizeCompletedEMT (void);
344
345#ifdef VBOX_WITH_OLD_VBVA_LOCK
346 RTCRITSECT mVBVALock;
347 volatile uint32_t mfu32PendingVideoAccelDisable;
348
349 int vbvaLock(void);
350 void vbvaUnlock(void);
351
352public:
353 static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
354
355private:
356 static void InvalidateAndUpdateEMT(Display *pDisplay);
357 static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
358
359 int videoAccelRefreshProcess(void);
360
361 /* Functions run under VBVA lock. */
362 int videoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
363 void videoAccelFlush (void);
364#endif /* VBOX_WITH_OLD_VBVA_LOCK */
365
366#ifdef VBOX_WITH_HGSMI
367 volatile uint32_t mu32UpdateVBVAFlags;
368#endif
369};
370
371void gdImageCopyResampled (uint8_t *dst, uint8_t *src,
372 int dstX, int dstY,
373 int srcX, int srcY,
374 int dstW, int dstH, int srcW, int srcH);
375
376
377#endif // ____H_DISPLAYIMPL
378/* 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