VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • 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 28800 2010-04-27 08:22:32Z 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 END_COM_MAP()
114
115 DECLARE_EMPTY_CTOR_DTOR (Display)
116
117 HRESULT FinalConstruct();
118 void FinalRelease();
119
120 // public initializer/uninitializer for internal purposes only
121 HRESULT init (Console *aParent);
122 void uninit();
123 int registerSSM(PVM pVM);
124
125 // public methods only for internal purposes
126 int handleDisplayResize (unsigned uScreenId, uint32_t bpp, void *pvVRAM, uint32_t cbLine, int w, int h);
127 void handleDisplayUpdate (int x, int y, int cx, int cy);
128#ifdef VBOX_WITH_VIDEOHWACCEL
129 void handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
130#endif
131 IFramebuffer *getFramebuffer()
132 {
133 return maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
134 }
135#ifdef MMSEAMLESS
136 int handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect);
137 int handleQueryVisibleRegion(uint32_t *pcRect, PRTRECT pRect);
138#endif
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 methods
249 STDMETHOD(GetScreenResolution)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel);
250 STDMETHOD(SetFramebuffer)(ULONG aScreenId, IFramebuffer *aFramebuffer);
251 STDMETHOD(GetFramebuffer)(ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin);
252 STDMETHOD(SetVideoModeHint)(ULONG width, ULONG height, ULONG bitsPerPixel, ULONG display);
253 STDMETHOD(TakeScreenShot)(ULONG aScreenId, BYTE *address, ULONG width, ULONG height);
254 STDMETHOD(TakeScreenShotToArray)(ULONG aScreenId, ULONG width, ULONG height, ComSafeArrayOut(BYTE, aScreenData));
255 STDMETHOD(DrawToScreen)(ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
256 STDMETHOD(InvalidateAndUpdate)();
257 STDMETHOD(ResizeCompleted)(ULONG aScreenId);
258 STDMETHOD(SetSeamlessMode)(BOOL enabled);
259
260 STDMETHOD(CompleteVHWACommand)(BYTE *pCommand);
261
262 // for VirtualBoxSupportErrorInfoImpl
263 static const wchar_t *getComponentName() { return L"Display"; }
264
265 static const PDMDRVREG DrvReg;
266
267private:
268
269 void updateDisplayData(void);
270
271 static DECLCALLBACK(int) changeFramebuffer(Display *that, IFramebuffer *aFB, unsigned uScreenId);
272
273 static DECLCALLBACK(void*) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
274 static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
275 static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
276 static DECLCALLBACK(int) displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface, uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy);
277 static DECLCALLBACK(void) displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
278 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
279 static DECLCALLBACK(void) displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface);
280 static DECLCALLBACK(void) displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface);
281 static DECLCALLBACK(void) displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
282 static DECLCALLBACK(void) displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
283 static DECLCALLBACK(void) displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
284
285#ifdef VBOX_WITH_VIDEOHWACCEL
286 static DECLCALLBACK(void) displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand);
287#endif
288
289#ifdef VBOX_WITH_HGSMI
290 static DECLCALLBACK(int) displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags);
291 static DECLCALLBACK(void) displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
292 static DECLCALLBACK(void) displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId);
293 static DECLCALLBACK(void) displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd);
294 static DECLCALLBACK(void) displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy);
295 static DECLCALLBACK(int) displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM);
296 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);
297#endif
298
299
300 static DECLCALLBACK(void) displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser);
301 static DECLCALLBACK(int) displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
302 static DECLCALLBACK(void) displaySSMSave(PSSMHANDLE pSSM, void *pvUser);
303 static DECLCALLBACK(int) displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
304
305 Console * const mParent;
306 /** Pointer to the associated display driver. */
307 struct DRVMAINDISPLAY *mpDrv;
308 /** Pointer to the device instance for the VMM Device. */
309 PPDMDEVINS mpVMMDev;
310 /** Set after the first attempt to find the VMM Device. */
311 bool mfVMMDevInited;
312
313 unsigned mcMonitors;
314 DISPLAYFBINFO maFramebuffers[SchemaDefs::MaxGuestMonitors];
315
316 bool mFramebufferOpened;
317
318 /* arguments of the last handleDisplayResize() call */
319 void *mLastAddress;
320 uint32_t mLastBytesPerLine;
321 uint32_t mLastBitsPerPixel;
322 int mLastWidth;
323 int mLastHeight;
324
325 VBVAMEMORY *mpVbvaMemory;
326 bool mfVideoAccelEnabled;
327 bool mfVideoAccelVRDP;
328 uint32_t mfu32SupportedOrders;
329
330 int32_t volatile mcVideoAccelVRDPRefs;
331
332 VBVAMEMORY *mpPendingVbvaMemory;
333 bool mfPendingVideoAccelEnable;
334 bool mfMachineRunning;
335
336 uint8_t *mpu8VbvaPartial;
337 uint32_t mcbVbvaPartial;
338
339 bool vbvaFetchCmd (VBVACMDHDR **ppHdr, uint32_t *pcbCmd);
340 void vbvaReleaseCmd (VBVACMDHDR *pHdr, int32_t cbCmd);
341
342 void handleResizeCompletedEMT (void);
343
344#ifdef VBOX_WITH_OLD_VBVA_LOCK
345 RTCRITSECT mVBVALock;
346 volatile uint32_t mfu32PendingVideoAccelDisable;
347
348 int vbvaLock(void);
349 void vbvaUnlock(void);
350
351public:
352 static int displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height);
353
354private:
355 static void InvalidateAndUpdateEMT(Display *pDisplay);
356 static int drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height);
357
358 int videoAccelRefreshProcess(void);
359
360 /* Functions run under VBVA lock. */
361 int videoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory);
362 void videoAccelFlush (void);
363#endif /* VBOX_WITH_OLD_VBVA_LOCK */
364
365#ifdef VBOX_WITH_HGSMI
366 volatile uint32_t mu32UpdateVBVAFlags;
367#endif
368};
369
370void gdImageCopyResampled (uint8_t *dst, uint8_t *src,
371 int dstX, int dstY,
372 int srcX, int srcY,
373 int dstW, int dstH, int srcW, int srcH);
374
375
376#endif // ____H_DISPLAYIMPL
377/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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