VirtualBox

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

Last change on this file since 27751 was 27751, checked in by vboxsync, 15 years ago

Main/Display: VBVA should call Framebuffer::RequestResize only if framebuffer parameters change (xTracker 4655).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.9 KB
Line 
1/* $Id: DisplayImpl.h 27751 2010-03-26 15:28:43Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ____H_DISPLAYIMPL
23#define ____H_DISPLAYIMPL
24
25#include "VirtualBoxBase.h"
26#include "SchemaDefs.h"
27
28#include <iprt/semaphore.h>
29#include <VBox/pdmdrv.h>
30#include <VBox/VMMDev.h>
31#include <VBox/VBoxVideo.h>
32
33class Console;
34
35enum {
36 ResizeStatus_Void,
37 ResizeStatus_InProgress,
38 ResizeStatus_UpdateDisplayData
39};
40
41typedef struct _DISPLAYFBINFO
42{
43 uint32_t u32Offset;
44 uint32_t u32MaxFramebufferSize;
45 uint32_t u32InformationSize;
46
47 ComPtr<IFramebuffer> pFramebuffer;
48
49 LONG xOrigin;
50 LONG yOrigin;
51
52 ULONG w;
53 ULONG h;
54
55 uint16_t u16BitsPerPixel;
56 uint8_t *pu8FramebufferVRAM;
57 uint32_t u32LineSize;
58
59 VBOXVIDEOINFOHOSTEVENTS *pHostEvents;
60
61 volatile uint32_t u32ResizeStatus;
62
63 /* The Framebuffer has default format and must be updates immediately. */
64 bool fDefaultFormat;
65
66 struct {
67 /* The rectangle that includes all dirty rectangles. */
68 int32_t xLeft;
69 int32_t xRight;
70 int32_t yTop;
71 int32_t yBottom;
72 } dirtyRect;
73
74 struct {
75 bool fPending;
76 ULONG pixelFormat;
77 void *pvVRAM;
78 uint32_t bpp;
79 uint32_t cbLine;
80 int w;
81 int h;
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(IConsoleCallback),
100 public VirtualBoxSupportErrorInfoImpl<Display, IDisplay>,
101 public VirtualBoxSupportTranslation<Display>,
102 VBOX_SCRIPTABLE_IMPL(IDisplay)
103{
104
105public:
106
107 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Display)
108
109 DECLARE_NOT_AGGREGATABLE(Display)
110
111 DECLARE_PROTECT_FINAL_CONSTRUCT()
112
113 BEGIN_COM_MAP(Display)
114 COM_INTERFACE_ENTRY(ISupportErrorInfo)
115 COM_INTERFACE_ENTRY(IDisplay)
116 COM_INTERFACE_ENTRY2(IDispatch,IDisplay)
117 END_COM_MAP()
118
119 DECLARE_EMPTY_CTOR_DTOR (Display)
120
121 HRESULT FinalConstruct();
122 void FinalRelease();
123
124 // public initializer/uninitializer for internal purposes only
125 HRESULT init (Console *aParent);
126 void uninit();
127 int registerSSM(PVM pVM);
128
129 // public methods only for internal purposes
130 int handleDisplayResize (unsigned uScreenId, uint32_t bpp, void *pvVRAM, uint32_t cbLine, int w, int h);
131 void handleDisplayUpdate (int x, int y, int cx, int cy);
132#ifdef VBOX_WITH_VIDEOHWACCEL
133 void handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
134#endif
135 IFramebuffer *getFramebuffer()
136 {
137 return maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
138 }
139
140 int VideoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
141 void VideoAccelFlush (void);
142
143 bool VideoAccelAllowed (void);
144
145#ifdef VBOX_WITH_VRDP
146 void VideoAccelVRDP (bool fEnable);
147#endif /* VBOX_WITH_VRDP */
148
149 // IConsoleCallback methods
150 STDMETHOD(OnMousePointerShapeChange)(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
151 ULONG width, ULONG height, BYTE *shape)
152 {
153 return S_OK;
154 }
155
156 STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL supportsRelative, BOOL needsHostCursor)
157 {
158 return S_OK;
159 }
160
161 STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
162 {
163 return S_OK;
164 }
165
166 STDMETHOD(OnStateChange)(MachineState_T machineState);
167
168 STDMETHOD(OnAdditionsStateChange)()
169 {
170 return S_OK;
171 }
172
173 STDMETHOD(OnNetworkAdapterChange) (INetworkAdapter *aNetworkAdapter)
174 {
175 return S_OK;
176 }
177
178 STDMETHOD(OnSerialPortChange) (ISerialPort *aSerialPort)
179 {
180 return S_OK;
181 }
182
183 STDMETHOD(OnParallelPortChange) (IParallelPort *aParallelPort)
184 {
185 return S_OK;
186 }
187
188 STDMETHOD(OnStorageControllerChange) ()
189 {
190 return S_OK;
191 }
192
193 STDMETHOD(OnMediumChange)(IMediumAttachment *aMediumAttachment)
194 {
195 return S_OK;
196 }
197
198 STDMETHOD(OnCPUChange)(ULONG aCPU, BOOL aRemove)
199 {
200 return S_OK;
201 }
202
203 STDMETHOD(OnVRDPServerChange)()
204 {
205 return S_OK;
206 }
207
208 STDMETHOD(OnRemoteDisplayInfoChange)()
209 {
210 return S_OK;
211 }
212
213 STDMETHOD(OnUSBControllerChange)()
214 {
215 return S_OK;
216 }
217
218 STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *device, BOOL attached,
219 IVirtualBoxErrorInfo *message)
220 {
221 return S_OK;
222 }
223
224 STDMETHOD(OnSharedFolderChange) (Scope_T aScope)
225 {
226 return S_OK;
227 }
228
229 STDMETHOD(OnRuntimeError)(BOOL fatal, IN_BSTR id, IN_BSTR message)
230 {
231 return S_OK;
232 }
233
234 STDMETHOD(OnCanShowWindow)(BOOL *canShow)
235 {
236 if (canShow)
237 *canShow = TRUE;
238 return S_OK;
239 }
240
241 STDMETHOD(OnShowWindow)(ULONG64 *winId)
242 {
243 if (winId)
244 *winId = 0;
245 return S_OK;
246 }
247
248 // IDisplay properties
249 STDMETHOD(COMGETTER(Width)) (ULONG *width);
250 STDMETHOD(COMGETTER(Height)) (ULONG *height);
251 STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *bitsPerPixel);
252
253 // IDisplay methods
254 STDMETHOD(SetFramebuffer)(ULONG aScreenId, IFramebuffer *aFramebuffer);
255 STDMETHOD(GetFramebuffer)(ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin);
256 STDMETHOD(SetVideoModeHint)(ULONG width, ULONG height, ULONG bitsPerPixel, ULONG display);
257 STDMETHOD(TakeScreenShot)(BYTE *address, ULONG width, ULONG height);
258 STDMETHOD(TakeScreenShotSlow)(ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
259 STDMETHOD(DrawToScreen)(BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
260 STDMETHOD(InvalidateAndUpdate)();
261 STDMETHOD(ResizeCompleted)(ULONG aScreenId);
262 STDMETHOD(UpdateCompleted)();
263 STDMETHOD(SetSeamlessMode)(BOOL enabled);
264
265 STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
266
267 // for VirtualBoxSupportErrorInfoImpl
268 static const wchar_t *getComponentName() { return L"Display"; }
269
270 static const PDMDRVREG DrvReg;
271
272private:
273
274 void updateDisplayData (bool aCheckParams = false);
275
276 static DECLCALLBACK(int) changeFramebuffer(Display *that, IFramebuffer *aFB, unsigned uScreenId);
277
278 static DECLCALLBACK(void*) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
279 static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
280 static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
281 static DECLCALLBACK(int) displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy);
282 static DECLCALLBACK(void) displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
283 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
284 static DECLCALLBACK(void) displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface);
285 static DECLCALLBACK(void) displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface);
286 static DECLCALLBACK(void) displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
287 static DECLCALLBACK(void) displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
288 static DECLCALLBACK(void) displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
289
290#ifdef VBOX_WITH_VIDEOHWACCEL
291 static DECLCALLBACK(void) displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
292#endif
293
294#ifdef VBOX_WITH_HGSMI
295 static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
296 static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
297 static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
298 static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
299 static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
300 static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
301 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);
302#endif
303
304
305 static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
306 static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
307 static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
308 static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
309
310 Console * const mParent;
311 /** Pointer to the associated display driver. */
312 struct DRVMAINDISPLAY *mpDrv;
313 /** Pointer to the device instance for the VMM Device. */
314 PPDMDEVINS mpVMMDev;
315 /** Set after the first attempt to find the VMM Device. */
316 bool mfVMMDevInited;
317
318 unsigned mcMonitors;
319 DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
320
321 bool mFramebufferOpened;
322
323 /* arguments of the last handleDisplayResize() call */
324 void *mLastAddress;
325 uint32_t mLastBytesPerLine;
326 uint32_t mLastBitsPerPixel;
327 int mLastWidth;
328 int mLastHeight;
329
330 VBVAMEMORY *mpVbvaMemory;
331 bool mfVideoAccelEnabled;
332 bool mfVideoAccelVRDP;
333 uint32_t mfu32SupportedOrders;
334
335 int32_t volatile mcVideoAccelVRDPRefs;
336
337 VBVAMEMORY *mpPendingVbvaMemory;
338 bool mfPendingVideoAccelEnable;
339 bool mfMachineRunning;
340
341 uint8_t *mpu8VbvaPartial;
342 uint32_t mcbVbvaPartial;
343
344 bool vbvaFetchCmd (VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
345 void vbvaReleaseCmd (VBVACMDHDR *pHdr, int32_t cbCmd);
346
347 void handleResizeCompletedEMT (void);
348
349#ifdef VBOX_WITH_OLD_VBVA_LOCK
350 RTCRITSECT mVBVALock;
351 volatile uint32_t mfu32PendingVideoAccelDisable;
352
353 int vbvaLock(void);
354 void vbvaUnlock(void);
355
356public:
357 static int displayTakeScreenshotEMT(Display *pDisplay, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
358
359private:
360 static void InvalidateAndUpdateEMT(Display *pDisplay);
361 static int DrawToScreenEMT(Display *pDisplay, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
362
363 int videoAccelRefreshProcess(void);
364
365 /* Functions run under VBVA lock. */
366 int videoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
367 void videoAccelFlush (void);
368#endif /* VBOX_WITH_OLD_VBVA_LOCK */
369
370#ifdef VBOX_WITH_HGSMI
371 volatile uint32_t mu32UpdateVBVAFlags;
372#endif
373};
374
375void gdImageCopyResampled (uint8_t *dst, uint8_t *src,
376 int dstX, int dstY,
377 int srcX, int srcY,
378 int dstW, int dstH, int srcW, int srcH);
379
380
381#endif // ____H_DISPLAYIMPL
382/* 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