1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxFrameBuffer class and subclasses declarations
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef ___VBoxFrameBuffer_h___
|
---|
24 | #define ___VBoxFrameBuffer_h___
|
---|
25 |
|
---|
26 | #include "COMDefs.h"
|
---|
27 | #include <iprt/critsect.h>
|
---|
28 |
|
---|
29 | /* Qt includes */
|
---|
30 | #include <QImage>
|
---|
31 | #include <QPixmap>
|
---|
32 | #include <QMutex>
|
---|
33 | #include <QPaintEvent>
|
---|
34 | #include <QMoveEvent>
|
---|
35 | #if defined (VBOX_GUI_USE_QGL)
|
---|
36 | #include <QGLWidget>
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #if defined (VBOX_GUI_USE_SDL)
|
---|
40 | #include <SDL.h>
|
---|
41 | #include <signal.h>
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | #if defined (Q_WS_WIN) && defined (VBOX_GUI_USE_DDRAW)
|
---|
45 | // VBox/cdefs.h defines these:
|
---|
46 | #undef LOWORD
|
---|
47 | #undef HIWORD
|
---|
48 | #undef LOBYTE
|
---|
49 | #undef HIBYTE
|
---|
50 | #include <ddraw.h>
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | class VBoxConsoleView;
|
---|
54 |
|
---|
55 | /////////////////////////////////////////////////////////////////////////////
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Frame buffer resize event.
|
---|
59 | */
|
---|
60 | class VBoxResizeEvent : public QEvent
|
---|
61 | {
|
---|
62 | public:
|
---|
63 |
|
---|
64 | VBoxResizeEvent (ulong aPixelFormat, uchar *aVRAM,
|
---|
65 | ulong aBitsPerPixel, ulong aBytesPerLine,
|
---|
66 | ulong aWidth, ulong aHeight) :
|
---|
67 | QEvent ((QEvent::Type) VBoxDefs::ResizeEventType),
|
---|
68 | mPixelFormat (aPixelFormat), mVRAM (aVRAM), mBitsPerPixel (aBitsPerPixel),
|
---|
69 | mBytesPerLine (aBytesPerLine), mWidth (aWidth), mHeight (aHeight) {}
|
---|
70 | ulong pixelFormat() { return mPixelFormat; }
|
---|
71 | uchar *VRAM() { return mVRAM; }
|
---|
72 | ulong bitsPerPixel() { return mBitsPerPixel; }
|
---|
73 | ulong bytesPerLine() { return mBytesPerLine; }
|
---|
74 | ulong width() { return mWidth; }
|
---|
75 | ulong height() { return mHeight; }
|
---|
76 |
|
---|
77 | private:
|
---|
78 |
|
---|
79 | ulong mPixelFormat;
|
---|
80 | uchar *mVRAM;
|
---|
81 | ulong mBitsPerPixel;
|
---|
82 | ulong mBytesPerLine;
|
---|
83 | ulong mWidth;
|
---|
84 | ulong mHeight;
|
---|
85 | };
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Frame buffer repaint event.
|
---|
89 | */
|
---|
90 | class VBoxRepaintEvent : public QEvent
|
---|
91 | {
|
---|
92 | public:
|
---|
93 | VBoxRepaintEvent (int x, int y, int w, int h) :
|
---|
94 | QEvent ((QEvent::Type) VBoxDefs::RepaintEventType),
|
---|
95 | ex (x), ey (y), ew (w), eh (h)
|
---|
96 | {}
|
---|
97 | int x() { return ex; }
|
---|
98 | int y() { return ey; }
|
---|
99 | int width() { return ew; }
|
---|
100 | int height() { return eh; }
|
---|
101 | private:
|
---|
102 | int ex, ey, ew, eh;
|
---|
103 | };
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Frame buffer set region event.
|
---|
107 | */
|
---|
108 | class VBoxSetRegionEvent : public QEvent
|
---|
109 | {
|
---|
110 | public:
|
---|
111 | VBoxSetRegionEvent (const QRegion &aReg)
|
---|
112 | : QEvent ((QEvent::Type) VBoxDefs::SetRegionEventType)
|
---|
113 | , mReg (aReg) {}
|
---|
114 | QRegion region() { return mReg; }
|
---|
115 | private:
|
---|
116 | QRegion mReg;
|
---|
117 | };
|
---|
118 |
|
---|
119 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
120 | class VBoxVHWACommandProcessEvent : public QEvent
|
---|
121 | {
|
---|
122 | public:
|
---|
123 | VBoxVHWACommandProcessEvent (struct _VBOXVHWACMD * pCmd)
|
---|
124 | : QEvent ((QEvent::Type) VBoxDefs::VHWACommandProcessType)
|
---|
125 | , mpCmd (pCmd) {}
|
---|
126 | struct _VBOXVHWACMD * command() { return mpCmd; }
|
---|
127 | private:
|
---|
128 | struct _VBOXVHWACMD * mpCmd;
|
---|
129 | };
|
---|
130 |
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | /////////////////////////////////////////////////////////////////////////////
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Common IFramebuffer implementation for all methods used by GUI to maintain
|
---|
137 | * the VM display video memory.
|
---|
138 | *
|
---|
139 | * Note that although this class can be called from multiple threads
|
---|
140 | * (in particular, the GUI thread and EMT) it doesn't protect access to every
|
---|
141 | * data field using its mutex lock. This is because all synchronization between
|
---|
142 | * the GUI and the EMT thread is supposed to be done using the
|
---|
143 | * IFramebuffer::NotifyUpdate() and IFramebuffer::RequestResize() methods
|
---|
144 | * (in particular, the \a aFinished parameter of these methods is responsible
|
---|
145 | * for the synchronization). These methods are always called on EMT and
|
---|
146 | * therefore always follow one another but never in parallel.
|
---|
147 | *
|
---|
148 | * Using this object's mutex lock (exposed also in IFramebuffer::Lock() and
|
---|
149 | * IFramebuffer::Unlock() implementations) usually makes sense only if some
|
---|
150 | * third-party thread (i.e. other than GUI or EMT) needs to make sure that
|
---|
151 | * *no* VM display update or resize event can occur while it is accessing
|
---|
152 | * IFramebuffer properties or the underlying display memory storage area.
|
---|
153 | *
|
---|
154 | * See IFramebuffer documentation for more info.
|
---|
155 | */
|
---|
156 |
|
---|
157 | class VBoxFrameBuffer : VBOX_SCRIPTABLE_IMPL(IFramebuffer)
|
---|
158 | {
|
---|
159 | public:
|
---|
160 |
|
---|
161 | VBoxFrameBuffer (VBoxConsoleView *aView);
|
---|
162 | virtual ~VBoxFrameBuffer();
|
---|
163 |
|
---|
164 | NS_DECL_ISUPPORTS
|
---|
165 |
|
---|
166 | #if defined (Q_OS_WIN32)
|
---|
167 |
|
---|
168 | STDMETHOD_(ULONG, AddRef)()
|
---|
169 | {
|
---|
170 | return ::InterlockedIncrement (&refcnt);
|
---|
171 | }
|
---|
172 |
|
---|
173 | STDMETHOD_(ULONG, Release)()
|
---|
174 | {
|
---|
175 | long cnt = ::InterlockedDecrement (&refcnt);
|
---|
176 | if (cnt == 0)
|
---|
177 | delete this;
|
---|
178 | return cnt;
|
---|
179 | }
|
---|
180 |
|
---|
181 | STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
|
---|
182 | {
|
---|
183 | if (riid == IID_IUnknown) {
|
---|
184 | *ppObj = this;
|
---|
185 | AddRef();
|
---|
186 | return S_OK;
|
---|
187 | }
|
---|
188 | if (riid == IID_IFramebuffer) {
|
---|
189 | *ppObj = this;
|
---|
190 | AddRef();
|
---|
191 | return S_OK;
|
---|
192 | }
|
---|
193 | *ppObj = NULL;
|
---|
194 | return E_NOINTERFACE;
|
---|
195 | }
|
---|
196 |
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | // IFramebuffer COM methods
|
---|
200 | STDMETHOD(COMGETTER(Address)) (BYTE **aAddress);
|
---|
201 | STDMETHOD(COMGETTER(Width)) (ULONG *aWidth);
|
---|
202 | STDMETHOD(COMGETTER(Height)) (ULONG *aHeight);
|
---|
203 | STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *aBitsPerPixel);
|
---|
204 | STDMETHOD(COMGETTER(BytesPerLine)) (ULONG *aBytesPerLine);
|
---|
205 | STDMETHOD(COMGETTER(PixelFormat)) (ULONG *aPixelFormat);
|
---|
206 | STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *aUsesGuestVRAM);
|
---|
207 | STDMETHOD(COMGETTER(HeightReduction)) (ULONG *aHeightReduction);
|
---|
208 | STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
|
---|
209 | STDMETHOD(COMGETTER(WinId)) (ULONG64 *winId);
|
---|
210 |
|
---|
211 | STDMETHOD(Lock)();
|
---|
212 | STDMETHOD(Unlock)();
|
---|
213 |
|
---|
214 | STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
|
---|
215 | BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
|
---|
216 | ULONG aWidth, ULONG aHeight,
|
---|
217 | BOOL *aFinished);
|
---|
218 |
|
---|
219 | STDMETHOD(VideoModeSupported) (ULONG aWidth, ULONG aHeight, ULONG aBPP,
|
---|
220 | BOOL *aSupported);
|
---|
221 |
|
---|
222 | STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
|
---|
223 | STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
|
---|
224 |
|
---|
225 | STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
|
---|
226 |
|
---|
227 | ulong width() { return mWdt; }
|
---|
228 | ulong height() { return mHgt; }
|
---|
229 |
|
---|
230 | virtual ulong pixelFormat()
|
---|
231 | {
|
---|
232 | return FramebufferPixelFormat_FOURCC_RGB;
|
---|
233 | }
|
---|
234 |
|
---|
235 | virtual bool usesGuestVRAM()
|
---|
236 | {
|
---|
237 | return false;
|
---|
238 | }
|
---|
239 |
|
---|
240 | void lock() { RTCritSectEnter(&mCritSect); }
|
---|
241 | void unlock() { RTCritSectLeave(&mCritSect); }
|
---|
242 |
|
---|
243 | virtual uchar *address() = 0;
|
---|
244 | virtual ulong bitsPerPixel() = 0;
|
---|
245 | virtual ulong bytesPerLine() = 0;
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * Called on the GUI thread (from VBoxConsoleView) when some part of the
|
---|
249 | * VM display viewport needs to be repainted on the host screen.
|
---|
250 | */
|
---|
251 | virtual void paintEvent (QPaintEvent *pe) = 0;
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Called on the GUI thread (from VBoxConsoleView) after it gets a
|
---|
255 | * VBoxResizeEvent posted from the RequestResize() method implementation.
|
---|
256 | */
|
---|
257 | virtual void resizeEvent (VBoxResizeEvent *re)
|
---|
258 | {
|
---|
259 | mWdt = re->width();
|
---|
260 | mHgt = re->height();
|
---|
261 | }
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * Called on the GUI thread (from VBoxConsoleView) when the VM console
|
---|
265 | * window is moved.
|
---|
266 | */
|
---|
267 | virtual void moveEvent (QMoveEvent * /*me*/ ) {}
|
---|
268 |
|
---|
269 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
270 | /* this method is called from the GUI thread
|
---|
271 | * to perform the actual Video HW Acceleration command processing */
|
---|
272 | virtual void doProcessVHWACommand(struct _VBOXVHWACMD * pCommand);
|
---|
273 | #endif
|
---|
274 |
|
---|
275 | protected:
|
---|
276 |
|
---|
277 | VBoxConsoleView *mView;
|
---|
278 | RTCRITSECT mCritSect;
|
---|
279 | int mWdt;
|
---|
280 | int mHgt;
|
---|
281 | uint64_t mWinId;
|
---|
282 |
|
---|
283 | #if defined (Q_OS_WIN32)
|
---|
284 | private:
|
---|
285 | long refcnt;
|
---|
286 | #endif
|
---|
287 | };
|
---|
288 |
|
---|
289 | /////////////////////////////////////////////////////////////////////////////
|
---|
290 |
|
---|
291 | #if defined (VBOX_GUI_USE_QIMAGE)
|
---|
292 |
|
---|
293 | class VBoxQImageFrameBuffer : public VBoxFrameBuffer
|
---|
294 | {
|
---|
295 | public:
|
---|
296 |
|
---|
297 | VBoxQImageFrameBuffer (VBoxConsoleView *aView);
|
---|
298 |
|
---|
299 | STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
|
---|
300 | ULONG aW, ULONG aH);
|
---|
301 |
|
---|
302 | ulong pixelFormat() { return mPixelFormat; }
|
---|
303 | bool usesGuestVRAM() { return mUsesGuestVRAM; }
|
---|
304 |
|
---|
305 | uchar *address() { return mImg.bits(); }
|
---|
306 | ulong bitsPerPixel() { return mImg.depth(); }
|
---|
307 | ulong bytesPerLine() { return mImg.bytesPerLine(); }
|
---|
308 |
|
---|
309 | void paintEvent (QPaintEvent *pe);
|
---|
310 | void resizeEvent (VBoxResizeEvent *re);
|
---|
311 |
|
---|
312 | private:
|
---|
313 |
|
---|
314 | QPixmap mPM;
|
---|
315 | QImage mImg;
|
---|
316 | ulong mPixelFormat;
|
---|
317 | bool mUsesGuestVRAM;
|
---|
318 | };
|
---|
319 |
|
---|
320 | #endif
|
---|
321 |
|
---|
322 | /////////////////////////////////////////////////////////////////////////////
|
---|
323 |
|
---|
324 | #if defined (VBOX_GUI_USE_QGL)
|
---|
325 | class VBoxVHWADirtyRect
|
---|
326 | {
|
---|
327 | public:
|
---|
328 | VBoxVHWADirtyRect() :
|
---|
329 | mIsClear(false)
|
---|
330 | {}
|
---|
331 |
|
---|
332 | VBoxVHWADirtyRect(const QRect & aRect)
|
---|
333 | {
|
---|
334 | if(aRect.isEmpty())
|
---|
335 | {
|
---|
336 | mIsClear = false;
|
---|
337 | mRect = aRect;
|
---|
338 | }
|
---|
339 | else
|
---|
340 | {
|
---|
341 | mIsClear = true;
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | bool isClear() { return mIsClear; }
|
---|
346 |
|
---|
347 | void add(const QRect & aRect)
|
---|
348 | {
|
---|
349 | if(aRect.isEmpty())
|
---|
350 | return;
|
---|
351 |
|
---|
352 | mRect = mIsClear ? aRect : mRect.united(aRect);
|
---|
353 | mIsClear = false;
|
---|
354 | }
|
---|
355 |
|
---|
356 | void set(const QRect & aRect)
|
---|
357 | {
|
---|
358 | if(aRect.isEmpty())
|
---|
359 | {
|
---|
360 | mIsClear = true;
|
---|
361 | }
|
---|
362 | else
|
---|
363 | {
|
---|
364 | mRect = aRect;
|
---|
365 | }
|
---|
366 | }
|
---|
367 |
|
---|
368 | void clear() { mIsClear = true; }
|
---|
369 |
|
---|
370 | const QRect & rect() {return mRect;}
|
---|
371 |
|
---|
372 | bool intersects(const QRect & aRect) {return mIsClear ? false : mRect.intersects(aRect);}
|
---|
373 |
|
---|
374 | private:
|
---|
375 | QRect mRect;
|
---|
376 | bool mIsClear;
|
---|
377 | };
|
---|
378 |
|
---|
379 | class VBoxVHWASurfaceBase
|
---|
380 | {
|
---|
381 | public:
|
---|
382 | VBoxVHWASurfaceBase(GLsizei aWidth, GLsizei aHeight,
|
---|
383 | GLint aInternalFormat, GLenum aFormat, GLenum aType);
|
---|
384 |
|
---|
385 | virtual ~VBoxVHWASurfaceBase();
|
---|
386 |
|
---|
387 | virtual void init(uchar *pvMem);
|
---|
388 |
|
---|
389 | virtual void uninit();
|
---|
390 |
|
---|
391 | static void globalInit();
|
---|
392 |
|
---|
393 | int blt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrtSurface, const QRect * pSrcRect);
|
---|
394 |
|
---|
395 | int lock(const QRect * pRect);
|
---|
396 |
|
---|
397 | int unlock();
|
---|
398 |
|
---|
399 | virtual void makeCurrent() = 0;
|
---|
400 |
|
---|
401 | void paint(const QRect * pRect);
|
---|
402 |
|
---|
403 | void performDisplay() { Assert(mDisplayInitialized); glCallList(mDisplay); }
|
---|
404 |
|
---|
405 | static ulong calcBytesPerPixel(GLenum format, GLenum type);
|
---|
406 |
|
---|
407 | static GLsizei makePowerOf2(GLsizei val);
|
---|
408 |
|
---|
409 | uchar * address(){ return mAddress; }
|
---|
410 | uchar * pointAddress(int x, int y) { return mAddress + y*mBytesPerLine + x*mBytesPerPixel; }
|
---|
411 | ulong memSize(){ return mBytesPerLine * mDisplayHeight; }
|
---|
412 |
|
---|
413 | ulong width() { return mDisplayWidth; }
|
---|
414 | ulong height() { return mDisplayHeight; }
|
---|
415 |
|
---|
416 | GLenum format() {return mFormat; }
|
---|
417 | GLint internalFormat() { return mInternalFormat; }
|
---|
418 | GLenum type() { return mType; }
|
---|
419 | ulong bytesPerPixel() { return mBytesPerPixel; }
|
---|
420 | ulong bytesPerLine() { return mBytesPerLine; }
|
---|
421 |
|
---|
422 | /* clients should treat the rerurned texture as read-only */
|
---|
423 | GLuint textureSynched(const QRect * aRect) { synchTexture(aRect); return mTexture; }
|
---|
424 |
|
---|
425 | private:
|
---|
426 | void initDisplay();
|
---|
427 | void deleteDisplay();
|
---|
428 | void updateTexture(const QRect * pRect);
|
---|
429 | void synchTexture(const QRect * pRect);
|
---|
430 | void synchMem(const QRect * pRect);
|
---|
431 |
|
---|
432 | GLuint mDisplay;
|
---|
433 | bool mDisplayInitialized;
|
---|
434 |
|
---|
435 | uchar * mAddress;
|
---|
436 | GLuint mTexture;
|
---|
437 |
|
---|
438 | GLenum mFormat;
|
---|
439 | GLint mInternalFormat;
|
---|
440 | GLenum mType;
|
---|
441 | ulong mDisplayWidth;
|
---|
442 | ulong mDisplayHeight;
|
---|
443 | ulong mBytesPerPixel;
|
---|
444 | ulong mBytesPerLine;
|
---|
445 |
|
---|
446 | VBoxVHWADirtyRect mLockedRect;
|
---|
447 | /*in case of blit we blit from another surface's texture, so our current texture gets durty */
|
---|
448 | VBoxVHWADirtyRect mUpdateFB2TexRect;
|
---|
449 | /*in case of blit the memory buffer does not get updated until we need it, e.g. for pain or lock operations */
|
---|
450 | VBoxVHWADirtyRect mUpdateFB2MemRect;
|
---|
451 |
|
---|
452 | bool mFreeAddress;
|
---|
453 | };
|
---|
454 |
|
---|
455 | class VBoxVHWASurfacePrimary : public VBoxVHWASurfaceBase
|
---|
456 | {
|
---|
457 | public:
|
---|
458 | VBoxVHWASurfacePrimary(GLsizei aWidth, GLsizei aHeight,
|
---|
459 | GLint aInternalFormat, GLenum aFormat, GLenum aType,
|
---|
460 | class VBoxGLWidget *pWidget) :
|
---|
461 | VBoxVHWASurfaceBase(aWidth, aHeight,
|
---|
462 | aInternalFormat, aFormat, aType),
|
---|
463 | mWidget(pWidget)
|
---|
464 | {}
|
---|
465 |
|
---|
466 | void makeCurrent();
|
---|
467 | private:
|
---|
468 | class VBoxGLWidget *mWidget;
|
---|
469 | };
|
---|
470 |
|
---|
471 | class VBoxGLWidget : public QGLWidget
|
---|
472 | {
|
---|
473 | public:
|
---|
474 | VBoxGLWidget (QWidget *aParent)
|
---|
475 | : QGLWidget (aParent),
|
---|
476 | pDisplay(NULL),
|
---|
477 | mRe(NULL),
|
---|
478 | mpIntersectionRect(NULL),
|
---|
479 | mBitsPerPixel(0),
|
---|
480 | mPixelFormat(0),
|
---|
481 | mUsesGuestVRAM(false)
|
---|
482 | {
|
---|
483 | // /* No need for background drawing */
|
---|
484 | // setAttribute (Qt::WA_OpaquePaintEvent);
|
---|
485 | }
|
---|
486 |
|
---|
487 | ulong vboxPixelFormat() { return mPixelFormat; }
|
---|
488 | bool vboxUsesGuestVRAM() { return mUsesGuestVRAM; }
|
---|
489 |
|
---|
490 | uchar *vboxAddress() { return pDisplay ? pDisplay->address() : NULL; }
|
---|
491 | ulong vboxBitsPerPixel() { return mBitsPerPixel; }
|
---|
492 | ulong vboxBytesPerLine() { return pDisplay ? pDisplay->bytesPerLine() : NULL; }
|
---|
493 |
|
---|
494 | void vboxPaintEvent (QPaintEvent *pe);
|
---|
495 | void vboxResizeEvent (VBoxResizeEvent *re);
|
---|
496 |
|
---|
497 | VBoxVHWASurfacePrimary * vboxGetSurface() { return pDisplay; }
|
---|
498 | protected:
|
---|
499 | // void resizeGL (int height, int width);
|
---|
500 |
|
---|
501 | void paintGL();
|
---|
502 |
|
---|
503 | void initializeGL();
|
---|
504 |
|
---|
505 | private:
|
---|
506 | // void vboxDoInitDisplay();
|
---|
507 | // void vboxDoDeleteDisplay();
|
---|
508 | // void vboxDoPerformDisplay() { Assert(mDisplayInitialized); glCallList(mDisplay); }
|
---|
509 |
|
---|
510 | void vboxDoResize(VBoxResizeEvent *re);
|
---|
511 | void vboxDoPaint(const QRect *rec);
|
---|
512 | VBoxVHWASurfacePrimary * pDisplay;
|
---|
513 |
|
---|
514 | VBoxResizeEvent *mRe;
|
---|
515 | const QRect *mpIntersectionRect;
|
---|
516 | ulong mBitsPerPixel;
|
---|
517 | ulong mPixelFormat;
|
---|
518 | bool mUsesGuestVRAM;
|
---|
519 | };
|
---|
520 |
|
---|
521 |
|
---|
522 | class VBoxQGLFrameBuffer : public VBoxFrameBuffer
|
---|
523 | {
|
---|
524 | public:
|
---|
525 |
|
---|
526 | VBoxQGLFrameBuffer (VBoxConsoleView *aView);
|
---|
527 |
|
---|
528 | STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
|
---|
529 | ULONG aW, ULONG aH);
|
---|
530 |
|
---|
531 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
532 | STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
|
---|
533 | #endif
|
---|
534 |
|
---|
535 | ulong pixelFormat() { return vboxWidget()->vboxPixelFormat(); }
|
---|
536 | bool usesGuestVRAM() { return vboxWidget()->vboxUsesGuestVRAM(); }
|
---|
537 |
|
---|
538 | uchar *address() { /*Assert(0); */return vboxWidget()->vboxAddress(); }
|
---|
539 | ulong bitsPerPixel() { return vboxWidget()->vboxBitsPerPixel(); }
|
---|
540 | ulong bytesPerLine() { return vboxWidget()->vboxBytesPerLine(); }
|
---|
541 |
|
---|
542 | void paintEvent (QPaintEvent *pe);
|
---|
543 | void resizeEvent (VBoxResizeEvent *re);
|
---|
544 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
545 | void doProcessVHWACommand(struct _VBOXVHWACMD * pCommand);
|
---|
546 | #endif
|
---|
547 |
|
---|
548 | private:
|
---|
549 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
550 | int vhwaSurfaceCanCreate(struct _VBOXVHWACMD_SURF_CANCREATE *pCmd);
|
---|
551 | int vhwaSurfaceCreate(struct _VBOXVHWACMD_SURF_CREATE *pCmd);
|
---|
552 | int vhwaSurfaceDestroy(struct _VBOXVHWACMD_SURF_DESTROY *pCmd);
|
---|
553 | int vhwaSurfaceLock(struct _VBOXVHWACMD_SURF_LOCK *pCmd);
|
---|
554 | int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
|
---|
555 | int vhwaSurfaceBlt(struct _VBOXVHWACMD_SURF_BLT *pCmd);
|
---|
556 | int vhwaQueryInfo1(struct _VBOXVHWACMD_QUERYINFO1 *pCmd);
|
---|
557 | int vhwaQueryInfo2(struct _VBOXVHWACMD_QUERYINFO2 *pCmd);
|
---|
558 | #endif
|
---|
559 | void vboxMakeCurrent();
|
---|
560 | VBoxGLWidget * vboxWidget();
|
---|
561 | };
|
---|
562 |
|
---|
563 |
|
---|
564 | #endif
|
---|
565 |
|
---|
566 | /////////////////////////////////////////////////////////////////////////////
|
---|
567 |
|
---|
568 | #if defined (VBOX_GUI_USE_SDL)
|
---|
569 |
|
---|
570 | class VBoxSDLFrameBuffer : public VBoxFrameBuffer
|
---|
571 | {
|
---|
572 | public:
|
---|
573 |
|
---|
574 | VBoxSDLFrameBuffer (VBoxConsoleView *aView);
|
---|
575 | virtual ~VBoxSDLFrameBuffer();
|
---|
576 |
|
---|
577 | STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
|
---|
578 | ULONG aW, ULONG aH);
|
---|
579 |
|
---|
580 | uchar *address()
|
---|
581 | {
|
---|
582 | SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
|
---|
583 | return surf ? (uchar *) (uintptr_t) surf->pixels : 0;
|
---|
584 | }
|
---|
585 |
|
---|
586 | ulong bitsPerPixel()
|
---|
587 | {
|
---|
588 | SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
|
---|
589 | return surf ? surf->format->BitsPerPixel : 0;
|
---|
590 | }
|
---|
591 |
|
---|
592 | ulong bytesPerLine()
|
---|
593 | {
|
---|
594 | SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
|
---|
595 | return surf ? surf->pitch : 0;
|
---|
596 | }
|
---|
597 |
|
---|
598 | ulong pixelFormat()
|
---|
599 | {
|
---|
600 | return mPixelFormat;
|
---|
601 | }
|
---|
602 |
|
---|
603 | bool usesGuestVRAM()
|
---|
604 | {
|
---|
605 | return mSurfVRAM != NULL;
|
---|
606 | }
|
---|
607 |
|
---|
608 | void paintEvent (QPaintEvent *pe);
|
---|
609 | void resizeEvent (VBoxResizeEvent *re);
|
---|
610 |
|
---|
611 | private:
|
---|
612 |
|
---|
613 | SDL_Surface *mScreen;
|
---|
614 | SDL_Surface *mSurfVRAM;
|
---|
615 |
|
---|
616 | ulong mPixelFormat;
|
---|
617 | };
|
---|
618 |
|
---|
619 | #endif
|
---|
620 |
|
---|
621 | /////////////////////////////////////////////////////////////////////////////
|
---|
622 |
|
---|
623 | #if defined (VBOX_GUI_USE_DDRAW)
|
---|
624 |
|
---|
625 | class VBoxDDRAWFrameBuffer : public VBoxFrameBuffer
|
---|
626 | {
|
---|
627 | public:
|
---|
628 |
|
---|
629 | VBoxDDRAWFrameBuffer (VBoxConsoleView *aView);
|
---|
630 | virtual ~VBoxDDRAWFrameBuffer();
|
---|
631 |
|
---|
632 | STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
|
---|
633 | ULONG aW, ULONG aH);
|
---|
634 |
|
---|
635 | uchar *address() { return (uchar *) mSurfaceDesc.lpSurface; }
|
---|
636 | ulong bitsPerPixel() { return mSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; }
|
---|
637 | ulong bytesPerLine() { return (ulong) mSurfaceDesc.lPitch; }
|
---|
638 |
|
---|
639 | ulong pixelFormat() { return mPixelFormat; };
|
---|
640 |
|
---|
641 | bool usesGuestVRAM() { return mUsesGuestVRAM; }
|
---|
642 |
|
---|
643 | void paintEvent (QPaintEvent *pe);
|
---|
644 | void resizeEvent (VBoxResizeEvent *re);
|
---|
645 | void moveEvent (QMoveEvent *me);
|
---|
646 |
|
---|
647 | private:
|
---|
648 |
|
---|
649 | void releaseObjects();
|
---|
650 |
|
---|
651 | bool createSurface (ULONG aPixelFormat, uchar *pvVRAM,
|
---|
652 | ULONG aBitsPerPixel, ULONG aBytesPerLine,
|
---|
653 | ULONG aWidth, ULONG aHeight);
|
---|
654 | void deleteSurface();
|
---|
655 | void drawRect (ULONG x, ULONG y, ULONG w, ULONG h);
|
---|
656 | void getWindowPosition (void);
|
---|
657 |
|
---|
658 | LPDIRECTDRAW7 mDDRAW;
|
---|
659 | LPDIRECTDRAWCLIPPER mClipper;
|
---|
660 | LPDIRECTDRAWSURFACE7 mSurface;
|
---|
661 | DDSURFACEDESC2 mSurfaceDesc;
|
---|
662 | LPDIRECTDRAWSURFACE7 mPrimarySurface;
|
---|
663 |
|
---|
664 | ulong mPixelFormat;
|
---|
665 |
|
---|
666 | bool mUsesGuestVRAM;
|
---|
667 |
|
---|
668 | int mWndX;
|
---|
669 | int mWndY;
|
---|
670 |
|
---|
671 | bool mSynchronousUpdates;
|
---|
672 | };
|
---|
673 |
|
---|
674 | #endif
|
---|
675 |
|
---|
676 | /////////////////////////////////////////////////////////////////////////////
|
---|
677 |
|
---|
678 | #if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
|
---|
679 |
|
---|
680 | #include <Carbon/Carbon.h>
|
---|
681 |
|
---|
682 | class VBoxQuartz2DFrameBuffer : public VBoxFrameBuffer
|
---|
683 | {
|
---|
684 | public:
|
---|
685 |
|
---|
686 | VBoxQuartz2DFrameBuffer (VBoxConsoleView *aView);
|
---|
687 | virtual ~VBoxQuartz2DFrameBuffer ();
|
---|
688 |
|
---|
689 | STDMETHOD (NotifyUpdate) (ULONG aX, ULONG aY,
|
---|
690 | ULONG aW, ULONG aH);
|
---|
691 | STDMETHOD (SetVisibleRegion) (BYTE *aRectangles, ULONG aCount);
|
---|
692 |
|
---|
693 | uchar *address() { return mDataAddress; }
|
---|
694 | ulong bitsPerPixel() { return CGImageGetBitsPerPixel (mImage); }
|
---|
695 | ulong bytesPerLine() { return CGImageGetBytesPerRow (mImage); }
|
---|
696 | ulong pixelFormat() { return mPixelFormat; };
|
---|
697 | bool usesGuestVRAM() { return mBitmapData == NULL; }
|
---|
698 |
|
---|
699 | const CGImageRef imageRef() const { return mImage; }
|
---|
700 |
|
---|
701 | void paintEvent (QPaintEvent *pe);
|
---|
702 | void resizeEvent (VBoxResizeEvent *re);
|
---|
703 |
|
---|
704 | private:
|
---|
705 |
|
---|
706 | void clean();
|
---|
707 |
|
---|
708 | uchar *mDataAddress;
|
---|
709 | void *mBitmapData;
|
---|
710 | ulong mPixelFormat;
|
---|
711 | CGImageRef mImage;
|
---|
712 | typedef struct
|
---|
713 | {
|
---|
714 | /** The size of this structure expressed in rcts entries. */
|
---|
715 | ULONG allocated;
|
---|
716 | /** The number of entries in the rcts array. */
|
---|
717 | ULONG used;
|
---|
718 | /** Variable sized array of the rectangle that makes up the region. */
|
---|
719 | CGRect rcts[1];
|
---|
720 | } RegionRects;
|
---|
721 | /** The current valid region, all access is by atomic cmpxchg or atomic xchg.
|
---|
722 | *
|
---|
723 | * The protocol for updating and using this has to take into account that
|
---|
724 | * the producer (SetVisibleRegion) and consumer (paintEvent) are running
|
---|
725 | * on different threads. Therefore the producer will create a new RegionRects
|
---|
726 | * structure before atomically replace the existing one. While the consumer
|
---|
727 | * will read the value by atomically replace it by NULL, and then when its
|
---|
728 | * done try restore it by cmpxchg. If the producer has already put a new
|
---|
729 | * region there, it will be discarded (see mRegionUnused).
|
---|
730 | */
|
---|
731 | RegionRects volatile *mRegion;
|
---|
732 | /** For keeping the unused region and thus avoid some RTMemAlloc/RTMemFree calls.
|
---|
733 | * This is operated with atomic cmpxchg and atomic xchg. */
|
---|
734 | RegionRects volatile *mRegionUnused;
|
---|
735 | };
|
---|
736 |
|
---|
737 | #endif /* Q_WS_MAC && VBOX_GUI_USE_QUARTZ2D */
|
---|
738 |
|
---|
739 | #endif // !___VBoxFrameBuffer_h___
|
---|