1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * UIFrameBuffer class and subclasses declarations
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2010-2011 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef ___UIFrameBuffer_h___
|
---|
20 | #define ___UIFrameBuffer_h___
|
---|
21 |
|
---|
22 | /* Global includes */
|
---|
23 | #include <QRegion>
|
---|
24 | #include <QPaintEvent>
|
---|
25 |
|
---|
26 | /* Local includes */
|
---|
27 | #include "COMDefs.h"
|
---|
28 | #include <iprt/critsect.h>
|
---|
29 |
|
---|
30 | class UIMachineView;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Frame buffer resize event.
|
---|
34 | */
|
---|
35 | class UIResizeEvent : public QEvent
|
---|
36 | {
|
---|
37 | public:
|
---|
38 |
|
---|
39 | UIResizeEvent(ulong uPixelFormat, uchar *pVRAM,
|
---|
40 | ulong uBitsPerPixel, ulong uBytesPerLine,
|
---|
41 | ulong uWidth, ulong uHeight)
|
---|
42 | : QEvent((QEvent::Type)VBoxDefs::ResizeEventType)
|
---|
43 | , m_uPixelFormat(uPixelFormat), m_pVRAM(pVRAM), m_uBitsPerPixel(uBitsPerPixel)
|
---|
44 | , m_uBytesPerLine(uBytesPerLine), m_uWidth(uWidth), m_uHeight(uHeight) {}
|
---|
45 | ulong pixelFormat() { return m_uPixelFormat; }
|
---|
46 | uchar *VRAM() { return m_pVRAM; }
|
---|
47 | ulong bitsPerPixel() { return m_uBitsPerPixel; }
|
---|
48 | ulong bytesPerLine() { return m_uBytesPerLine; }
|
---|
49 | ulong width() { return m_uWidth; }
|
---|
50 | ulong height() { return m_uHeight; }
|
---|
51 |
|
---|
52 | private:
|
---|
53 |
|
---|
54 | ulong m_uPixelFormat;
|
---|
55 | uchar *m_pVRAM;
|
---|
56 | ulong m_uBitsPerPixel;
|
---|
57 | ulong m_uBytesPerLine;
|
---|
58 | ulong m_uWidth;
|
---|
59 | ulong m_uHeight;
|
---|
60 | };
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Frame buffer repaint event.
|
---|
64 | */
|
---|
65 | class UIRepaintEvent : public QEvent
|
---|
66 | {
|
---|
67 | public:
|
---|
68 |
|
---|
69 | UIRepaintEvent(int iX, int iY, int iW, int iH)
|
---|
70 | : QEvent((QEvent::Type)VBoxDefs::RepaintEventType)
|
---|
71 | , m_iX(iX), m_iY(iY), m_iW(iW), m_iH(iH) {}
|
---|
72 | int x() { return m_iX; }
|
---|
73 | int y() { return m_iY; }
|
---|
74 | int width() { return m_iW; }
|
---|
75 | int height() { return m_iH; }
|
---|
76 |
|
---|
77 | private:
|
---|
78 |
|
---|
79 | int m_iX, m_iY, m_iW, m_iH;
|
---|
80 | };
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Frame buffer set region event.
|
---|
84 | */
|
---|
85 | class UISetRegionEvent : public QEvent
|
---|
86 | {
|
---|
87 | public:
|
---|
88 |
|
---|
89 | UISetRegionEvent(const QRegion ®ion)
|
---|
90 | : QEvent((QEvent::Type)VBoxDefs::SetRegionEventType)
|
---|
91 | , m_region(region) {}
|
---|
92 | QRegion region() { return m_region; }
|
---|
93 |
|
---|
94 | private:
|
---|
95 |
|
---|
96 | QRegion m_region;
|
---|
97 | };
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Common IFramebuffer implementation for all methods used by GUI to maintain
|
---|
101 | * the VM display video memory.
|
---|
102 | *
|
---|
103 | * Note that although this class can be called from multiple threads
|
---|
104 | * (in particular, the GUI thread and EMT) it doesn't protect access to every
|
---|
105 | * data field using its mutex lock. This is because all synchronization between
|
---|
106 | * the GUI and the EMT thread is supposed to be done using the
|
---|
107 | * IFramebuffer::NotifyUpdate() and IFramebuffer::RequestResize() methods
|
---|
108 | * (in particular, the \a aFinished parameter of these methods is responsible
|
---|
109 | * for the synchronization). These methods are always called on EMT and
|
---|
110 | * therefore always follow one another but never in parallel.
|
---|
111 | *
|
---|
112 | * Using this object's mutex lock (exposed also in IFramebuffer::Lock() and
|
---|
113 | * IFramebuffer::Unlock() implementations) usually makes sense only if some
|
---|
114 | * third-party thread (i.e. other than GUI or EMT) needs to make sure that
|
---|
115 | * *no* VM display update or resize event can occur while it is accessing
|
---|
116 | * IFramebuffer properties or the underlying display memory storage area.
|
---|
117 | *
|
---|
118 | * See IFramebuffer documentation for more info.
|
---|
119 | */
|
---|
120 | class UIFrameBuffer : VBOX_SCRIPTABLE_IMPL(IFramebuffer)
|
---|
121 | {
|
---|
122 | public:
|
---|
123 |
|
---|
124 | UIFrameBuffer(UIMachineView *aView);
|
---|
125 | virtual ~UIFrameBuffer();
|
---|
126 |
|
---|
127 | void setDeleted(bool fIsDeleted) { m_fIsDeleted = fIsDeleted; }
|
---|
128 |
|
---|
129 | NS_DECL_ISUPPORTS
|
---|
130 |
|
---|
131 | #if defined (Q_OS_WIN32)
|
---|
132 | STDMETHOD_(ULONG, AddRef)()
|
---|
133 | {
|
---|
134 | return ::InterlockedIncrement(&m_iRefCnt);
|
---|
135 | }
|
---|
136 |
|
---|
137 | STDMETHOD_(ULONG, Release)()
|
---|
138 | {
|
---|
139 | long cnt = ::InterlockedDecrement(&m_iRefCnt);
|
---|
140 | if (cnt == 0)
|
---|
141 | delete this;
|
---|
142 | return cnt;
|
---|
143 | }
|
---|
144 | #endif
|
---|
145 |
|
---|
146 | VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
|
---|
147 |
|
---|
148 | /* IFramebuffer COM methods */
|
---|
149 | STDMETHOD(COMGETTER(Address)) (BYTE **ppAddress);
|
---|
150 | STDMETHOD(COMGETTER(Width)) (ULONG *puWidth);
|
---|
151 | STDMETHOD(COMGETTER(Height)) (ULONG *puHeight);
|
---|
152 | STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *puBitsPerPixel);
|
---|
153 | STDMETHOD(COMGETTER(BytesPerLine)) (ULONG *puBytesPerLine);
|
---|
154 | STDMETHOD(COMGETTER(PixelFormat)) (ULONG *puPixelFormat);
|
---|
155 | STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *pbUsesGuestVRAM);
|
---|
156 | STDMETHOD(COMGETTER(HeightReduction)) (ULONG *puHeightReduction);
|
---|
157 | STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **ppOverlay);
|
---|
158 | STDMETHOD(COMGETTER(WinId)) (LONG64 *pWinId);
|
---|
159 |
|
---|
160 | STDMETHOD(Lock)();
|
---|
161 | STDMETHOD(Unlock)();
|
---|
162 |
|
---|
163 | STDMETHOD(RequestResize) (ULONG uScreenId, ULONG uPixelFormat,
|
---|
164 | BYTE *pVRAM, ULONG uBitsPerPixel, ULONG uBytesPerLine,
|
---|
165 | ULONG uWidth, ULONG uHeight,
|
---|
166 | BOOL *pbFinished);
|
---|
167 |
|
---|
168 | STDMETHOD(VideoModeSupported) (ULONG uWidth, ULONG uHeight, ULONG uBPP,
|
---|
169 | BOOL *pbSupported);
|
---|
170 |
|
---|
171 | STDMETHOD(GetVisibleRegion)(BYTE *pRectangles, ULONG uCount, ULONG *puCountCopied);
|
---|
172 | STDMETHOD(SetVisibleRegion)(BYTE *pRectangles, ULONG uCount);
|
---|
173 |
|
---|
174 | STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
|
---|
175 |
|
---|
176 | ulong width() { return m_width; }
|
---|
177 | ulong height() { return m_height; }
|
---|
178 |
|
---|
179 | virtual QSize scaledSize() const { return m_scaledSize; }
|
---|
180 | virtual void setScaledSize(const QSize &size = QSize()) { m_scaledSize = size; }
|
---|
181 |
|
---|
182 | virtual ulong pixelFormat()
|
---|
183 | {
|
---|
184 | return FramebufferPixelFormat_FOURCC_RGB;
|
---|
185 | }
|
---|
186 |
|
---|
187 | virtual bool usesGuestVRAM()
|
---|
188 | {
|
---|
189 | return false;
|
---|
190 | }
|
---|
191 |
|
---|
192 | void lock() { RTCritSectEnter(&m_critSect); }
|
---|
193 | void unlock() { RTCritSectLeave(&m_critSect); }
|
---|
194 |
|
---|
195 | virtual uchar *address() = 0;
|
---|
196 | virtual ulong bitsPerPixel() = 0;
|
---|
197 | virtual ulong bytesPerLine() = 0;
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Called on the GUI thread (from VBoxConsoleView) when some part of the
|
---|
201 | * VM display viewport needs to be repainted on the host screen.
|
---|
202 | */
|
---|
203 | virtual void paintEvent(QPaintEvent *pEvent) = 0;
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Called on the GUI thread (from VBoxConsoleView) after it gets a
|
---|
207 | * UIResizeEvent posted from the RequestResize() method implementation.
|
---|
208 | */
|
---|
209 | virtual void resizeEvent(UIResizeEvent *pEvent)
|
---|
210 | {
|
---|
211 | m_width = pEvent->width();
|
---|
212 | m_height = pEvent->height();
|
---|
213 | }
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * Called on the GUI thread (from VBoxConsoleView) when the VM console
|
---|
217 | * window is moved.
|
---|
218 | */
|
---|
219 | virtual void moveEvent(QMoveEvent * /* pEvent */) {}
|
---|
220 |
|
---|
221 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
222 | /* this method is called from the GUI thread
|
---|
223 | * to perform the actual Video HW Acceleration command processing
|
---|
224 | * the event is framebuffer implementation specific */
|
---|
225 | virtual void doProcessVHWACommand(QEvent * pEvent);
|
---|
226 |
|
---|
227 | virtual void viewportResized(QResizeEvent * /* pEvent */) {}
|
---|
228 |
|
---|
229 | virtual void viewportScrolled(int /* iX */, int /* iY */) {}
|
---|
230 |
|
---|
231 | virtual void setView(UIMachineView * pView);
|
---|
232 | #endif
|
---|
233 |
|
---|
234 | protected:
|
---|
235 |
|
---|
236 | UIMachineView *m_pMachineView;
|
---|
237 | RTCRITSECT m_critSect;
|
---|
238 | ulong m_width;
|
---|
239 | ulong m_height;
|
---|
240 | QSize m_scaledSize;
|
---|
241 | int64_t m_WinId;
|
---|
242 | bool m_fIsDeleted;
|
---|
243 |
|
---|
244 | #if defined (Q_OS_WIN32)
|
---|
245 | private:
|
---|
246 |
|
---|
247 | long m_iRefCnt;
|
---|
248 | #endif
|
---|
249 | };
|
---|
250 |
|
---|
251 | #endif // !___UIFrameBuffer_h___
|
---|