VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxFrameBuffer.h@ 22247

Last change on this file since 22247 was 22247, checked in by vboxsync, 16 years ago

video hw accel: more saved state support impl, bugfixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.1 KB
Line 
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.215389.xyz. 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//#define VBOXQGL_PROF_BASE 1
26//#define VBOXQGL_DBG_SURF 1
27#include "COMDefs.h"
28#include <iprt/critsect.h>
29
30/* Qt includes */
31#include <QImage>
32#include <QPixmap>
33#include <QMutex>
34#include <QPaintEvent>
35#include <QMoveEvent>
36#if defined (VBOX_GUI_USE_QGL)
37#include <QGLWidget>
38#endif
39
40#if defined (VBOX_GUI_USE_SDL)
41#include <SDL.h>
42#include <signal.h>
43#endif
44
45#if defined (Q_WS_WIN) && defined (VBOX_GUI_USE_DDRAW)
46// VBox/cdefs.h defines these:
47#undef LOWORD
48#undef HIWORD
49#undef LOBYTE
50#undef HIBYTE
51#include <ddraw.h>
52#endif
53
54class VBoxConsoleView;
55
56/////////////////////////////////////////////////////////////////////////////
57
58/**
59 * Frame buffer resize event.
60 */
61class VBoxResizeEvent : public QEvent
62{
63public:
64
65 VBoxResizeEvent (ulong aPixelFormat, uchar *aVRAM,
66 ulong aBitsPerPixel, ulong aBytesPerLine,
67 ulong aWidth, ulong aHeight) :
68 QEvent ((QEvent::Type) VBoxDefs::ResizeEventType),
69 mPixelFormat (aPixelFormat), mVRAM (aVRAM), mBitsPerPixel (aBitsPerPixel),
70 mBytesPerLine (aBytesPerLine), mWidth (aWidth), mHeight (aHeight) {}
71 ulong pixelFormat() { return mPixelFormat; }
72 uchar *VRAM() { return mVRAM; }
73 ulong bitsPerPixel() { return mBitsPerPixel; }
74 ulong bytesPerLine() { return mBytesPerLine; }
75 ulong width() { return mWidth; }
76 ulong height() { return mHeight; }
77
78private:
79
80 ulong mPixelFormat;
81 uchar *mVRAM;
82 ulong mBitsPerPixel;
83 ulong mBytesPerLine;
84 ulong mWidth;
85 ulong mHeight;
86};
87
88/**
89 * Frame buffer repaint event.
90 */
91class VBoxRepaintEvent : public QEvent
92{
93public:
94 VBoxRepaintEvent (int x, int y, int w, int h) :
95 QEvent ((QEvent::Type) VBoxDefs::RepaintEventType),
96 ex (x), ey (y), ew (w), eh (h)
97 {}
98 int x() { return ex; }
99 int y() { return ey; }
100 int width() { return ew; }
101 int height() { return eh; }
102private:
103 int ex, ey, ew, eh;
104};
105
106/**
107 * Frame buffer set region event.
108 */
109class VBoxSetRegionEvent : public QEvent
110{
111public:
112 VBoxSetRegionEvent (const QRegion &aReg)
113 : QEvent ((QEvent::Type) VBoxDefs::SetRegionEventType)
114 , mReg (aReg) {}
115 QRegion region() { return mReg; }
116private:
117 QRegion mReg;
118};
119
120#ifdef VBOX_GUI_USE_QGL
121typedef enum
122{
123 VBOXVHWA_PIPECMD_PAINT = 1,
124 VBOXVHWA_PIPECMD_VHWA,
125 VBOXVHWA_PIPECMD_OP,
126}VBOXVHWA_PIPECMD_TYPE;
127
128typedef DECLCALLBACK(void) FNVBOXVHWACALLBACK(void * pContext);
129typedef FNVBOXVHWACALLBACK *PFNVBOXVHWACALLBACK;
130
131typedef struct VBOXVHWACALLBACKINFO
132{
133 PFNVBOXVHWACALLBACK pfnCallback;
134 void * pContext;
135}VBOXVHWACALLBACKINFO;
136class VBoxVHWACommandElement
137{
138public:
139 void setVHWACmd(struct _VBOXVHWACMD * pCmd)
140 {
141 mType = VBOXVHWA_PIPECMD_VHWA;
142 u.mpCmd = pCmd;
143 }
144
145 void setPaintCmd(const QRect & aRect)
146 {
147 mType = VBOXVHWA_PIPECMD_PAINT;
148 mRect = aRect;
149 }
150
151 void setOp(const VBOXVHWACALLBACKINFO & aOp)
152 {
153 mType = VBOXVHWA_PIPECMD_OP;
154 u.mCallback = aOp;
155 }
156
157 void setData(VBOXVHWA_PIPECMD_TYPE aType, void * pvData)
158 {
159 switch(aType)
160 {
161 case VBOXVHWA_PIPECMD_PAINT:
162 setPaintCmd(*((QRect*)pvData));
163 break;
164 case VBOXVHWA_PIPECMD_VHWA:
165 setVHWACmd((struct _VBOXVHWACMD *)pvData);
166 break;
167 case VBOXVHWA_PIPECMD_OP:
168 setOp(*((VBOXVHWACALLBACKINFO *)pvData));
169 break;
170 default:
171 Assert(0);
172 break;
173 }
174 }
175
176 VBOXVHWA_PIPECMD_TYPE type() const {return mType;}
177 const QRect & rect() const {return mRect;}
178 struct _VBOXVHWACMD * vhwaCmd() const {return u.mpCmd;}
179
180private:
181 VBoxVHWACommandElement * mpNext;
182 VBOXVHWA_PIPECMD_TYPE mType;
183 union
184 {
185 struct _VBOXVHWACMD * mpCmd;
186 VBOXVHWACALLBACKINFO mCallback;
187 }u;
188 QRect mRect;
189
190 friend class VBoxVHWACommandElementPipe;
191 friend class VBoxVHWACommandElementStack;
192 friend class VBoxGLWidget;
193};
194
195class VBoxVHWACommandElementPipe
196{
197public:
198 VBoxVHWACommandElementPipe() :
199 mpFirst(NULL),
200 mpLast(NULL)
201 {}
202
203 void put(VBoxVHWACommandElement *pCmd)
204 {
205 if(mpLast)
206 {
207 Assert(mpFirst);
208 mpLast->mpNext = pCmd;
209 mpLast = pCmd;
210 }
211 else
212 {
213 Assert(!mpFirst);
214 mpFirst = pCmd;
215 mpLast = pCmd;
216 }
217 pCmd->mpNext= NULL;
218
219 }
220
221 VBoxVHWACommandElement * detachList()
222 {
223 if(mpLast)
224 {
225 VBoxVHWACommandElement * pHead = mpFirst;
226 mpFirst = NULL;
227 mpLast = NULL;
228 return pHead;
229 }
230 return NULL;
231 }
232private:
233 VBoxVHWACommandElement *mpFirst;
234 VBoxVHWACommandElement *mpLast;
235};
236
237class VBoxVHWACommandElementStack
238{
239public:
240 VBoxVHWACommandElementStack() :
241 mpFirst(NULL) {}
242
243 void push(VBoxVHWACommandElement *pCmd)
244 {
245 pCmd->mpNext = mpFirst;
246 mpFirst = pCmd;
247 }
248
249 void pusha(VBoxVHWACommandElement *pFirst, VBoxVHWACommandElement *pLast)
250 {
251 pLast->mpNext = mpFirst;
252 mpFirst = pFirst;
253 }
254
255 VBoxVHWACommandElement * pop()
256 {
257 if(mpFirst)
258 {
259 VBoxVHWACommandElement * ret = mpFirst;
260 mpFirst = ret->mpNext;
261 return ret;
262 }
263 return NULL;
264 }
265private:
266 VBoxVHWACommandElement *mpFirst;
267};
268
269class VBoxVHWACommandProcessEvent : public QEvent
270{
271public:
272 VBoxVHWACommandProcessEvent (VBoxVHWACommandElement *pEl)
273 : QEvent ((QEvent::Type) VBoxDefs::VHWACommandProcessType)
274 {
275 mCmdPipe.put(pEl);
276 }
277 VBoxVHWACommandElementPipe & pipe() { return mCmdPipe; }
278private:
279 VBoxVHWACommandElementPipe mCmdPipe;
280 VBoxVHWACommandProcessEvent *mpNext;
281
282 friend class VBoxGLWidget;
283};
284
285#endif
286
287/////////////////////////////////////////////////////////////////////////////
288
289/**
290 * Common IFramebuffer implementation for all methods used by GUI to maintain
291 * the VM display video memory.
292 *
293 * Note that although this class can be called from multiple threads
294 * (in particular, the GUI thread and EMT) it doesn't protect access to every
295 * data field using its mutex lock. This is because all synchronization between
296 * the GUI and the EMT thread is supposed to be done using the
297 * IFramebuffer::NotifyUpdate() and IFramebuffer::RequestResize() methods
298 * (in particular, the \a aFinished parameter of these methods is responsible
299 * for the synchronization). These methods are always called on EMT and
300 * therefore always follow one another but never in parallel.
301 *
302 * Using this object's mutex lock (exposed also in IFramebuffer::Lock() and
303 * IFramebuffer::Unlock() implementations) usually makes sense only if some
304 * third-party thread (i.e. other than GUI or EMT) needs to make sure that
305 * *no* VM display update or resize event can occur while it is accessing
306 * IFramebuffer properties or the underlying display memory storage area.
307 *
308 * See IFramebuffer documentation for more info.
309 */
310
311class VBoxFrameBuffer : VBOX_SCRIPTABLE_IMPL(IFramebuffer)
312{
313public:
314
315 VBoxFrameBuffer (VBoxConsoleView *aView);
316 virtual ~VBoxFrameBuffer();
317
318 NS_DECL_ISUPPORTS
319
320#if defined (Q_OS_WIN32)
321
322 STDMETHOD_(ULONG, AddRef)()
323 {
324 return ::InterlockedIncrement (&refcnt);
325 }
326
327 STDMETHOD_(ULONG, Release)()
328 {
329 long cnt = ::InterlockedDecrement (&refcnt);
330 if (cnt == 0)
331 delete this;
332 return cnt;
333 }
334#endif
335 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
336
337 // IFramebuffer COM methods
338 STDMETHOD(COMGETTER(Address)) (BYTE **aAddress);
339 STDMETHOD(COMGETTER(Width)) (ULONG *aWidth);
340 STDMETHOD(COMGETTER(Height)) (ULONG *aHeight);
341 STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *aBitsPerPixel);
342 STDMETHOD(COMGETTER(BytesPerLine)) (ULONG *aBytesPerLine);
343 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *aPixelFormat);
344 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *aUsesGuestVRAM);
345 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *aHeightReduction);
346 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
347 STDMETHOD(COMGETTER(WinId)) (ULONG64 *winId);
348
349 STDMETHOD(Lock)();
350 STDMETHOD(Unlock)();
351
352 STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
353 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
354 ULONG aWidth, ULONG aHeight,
355 BOOL *aFinished);
356
357 STDMETHOD(VideoModeSupported) (ULONG aWidth, ULONG aHeight, ULONG aBPP,
358 BOOL *aSupported);
359
360 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
361 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
362
363 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
364
365 ulong width() { return mWdt; }
366 ulong height() { return mHgt; }
367
368 virtual ulong pixelFormat()
369 {
370 return FramebufferPixelFormat_FOURCC_RGB;
371 }
372
373 virtual bool usesGuestVRAM()
374 {
375 return false;
376 }
377
378 void lock() { RTCritSectEnter(&mCritSect); }
379 void unlock() { RTCritSectLeave(&mCritSect); }
380
381 virtual uchar *address() = 0;
382 virtual ulong bitsPerPixel() = 0;
383 virtual ulong bytesPerLine() = 0;
384
385 /**
386 * Called on the GUI thread (from VBoxConsoleView) when some part of the
387 * VM display viewport needs to be repainted on the host screen.
388 */
389 virtual void paintEvent (QPaintEvent *pe) = 0;
390
391 /**
392 * Called on the GUI thread (from VBoxConsoleView) after it gets a
393 * VBoxResizeEvent posted from the RequestResize() method implementation.
394 */
395 virtual void resizeEvent (VBoxResizeEvent *re)
396 {
397 mWdt = re->width();
398 mHgt = re->height();
399 }
400
401 /**
402 * Called on the GUI thread (from VBoxConsoleView) when the VM console
403 * window is moved.
404 */
405 virtual void moveEvent (QMoveEvent * /*me*/ ) {}
406
407#ifdef VBOX_GUI_USE_QGL
408 /* this method is called from the GUI thread
409 * to perform the actual Video HW Acceleration command processing */
410 virtual void doProcessVHWACommand(VBoxVHWACommandProcessEvent * pEvent);
411#endif
412
413protected:
414
415 VBoxConsoleView *mView;
416 RTCRITSECT mCritSect;
417 int mWdt;
418 int mHgt;
419 uint64_t mWinId;
420
421#if defined (Q_OS_WIN32)
422private:
423 long refcnt;
424#endif
425};
426
427/////////////////////////////////////////////////////////////////////////////
428
429#if defined (VBOX_GUI_USE_QIMAGE)
430
431class VBoxQImageFrameBuffer : public VBoxFrameBuffer
432{
433public:
434
435 VBoxQImageFrameBuffer (VBoxConsoleView *aView);
436
437 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
438 ULONG aW, ULONG aH);
439
440 ulong pixelFormat() { return mPixelFormat; }
441 bool usesGuestVRAM() { return mUsesGuestVRAM; }
442
443 uchar *address() { return mImg.bits(); }
444 ulong bitsPerPixel() { return mImg.depth(); }
445 ulong bytesPerLine() { return mImg.bytesPerLine(); }
446
447 void paintEvent (QPaintEvent *pe);
448 void resizeEvent (VBoxResizeEvent *re);
449
450private:
451
452 QPixmap mPM;
453 QImage mImg;
454 ulong mPixelFormat;
455 bool mUsesGuestVRAM;
456};
457
458#endif
459
460/////////////////////////////////////////////////////////////////////////////
461
462#if defined (VBOX_GUI_USE_QGL)
463
464#ifdef DEBUG
465#include "iprt/stream.h"
466#define VBOXQGLLOG(_m) RTPrintf _m
467#else
468#define VBOXQGLLOG(_m)
469#endif
470#define VBOXQGLLOG_ENTER(_m)
471//do{VBOXQGLLOG(("==>[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
472#define VBOXQGLLOG_EXIT(_m)
473//do{VBOXQGLLOG(("<==[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
474#ifdef DEBUG
475#define VBOXQGL_ASSERTNOERR() \
476 do { GLenum err = glGetError(); \
477 if(err != GL_NO_ERROR) VBOXQGLLOG(("gl error ocured (0x%x)\n", err)); \
478 Assert(err == GL_NO_ERROR); \
479 }while(0)
480
481#define VBOXQGL_CHECKERR(_op) \
482 do { \
483 glGetError(); \
484 _op \
485 VBOXQGL_ASSERTNOERR(); \
486 }while(0)
487#else
488#define VBOXQGL_ASSERTNOERR() \
489 do {}while(0)
490
491#define VBOXQGL_CHECKERR(_op) \
492 do { \
493 _op \
494 }while(0)
495#endif
496
497#ifdef DEBUG
498#include <iprt/time.h>
499
500#define VBOXGETTIME() RTTimeNanoTS()
501
502#define VBOXPRINTDIF(_nano, _m) do{\
503 uint64_t cur = VBOXGETTIME(); \
504 VBOXQGLLOG(_m); \
505 VBOXQGLLOG(("(%Lu)\n", cur - (_nano))); \
506 }while(0)
507
508class VBoxVHWADbgTimeCounter
509{
510public:
511 VBoxVHWADbgTimeCounter(const char* msg) {mTime = VBOXGETTIME(); mMsg=msg;}
512 ~VBoxVHWADbgTimeCounter() {VBOXPRINTDIF(mTime, (mMsg));}
513private:
514 uint64_t mTime;
515 const char* mMsg;
516};
517
518#define VBOXQGLLOG_METHODTIME(_m) VBoxVHWADbgTimeCounter _dbgTimeCounter(_m)
519#else
520#define VBOXQGLLOG_METHODTIME(_m)
521#endif
522
523#define VBOXQGLLOG_QRECT(_p, _pr, _s) do{\
524 VBOXQGLLOG((_p " x(%d), y(%d), w(%d), h(%d)" _s, (_pr)->x(), (_pr)->y(), (_pr)->width(), (_pr)->height()));\
525 }while(0)
526
527#define VBOXQGLLOG_CKEY(_p, _pck, _s) do{\
528 VBOXQGLLOG((_p " l(0x%x), u(0x%x)" _s, (_pck)->lower(), (_pck)->upper()));\
529 }while(0)
530
531class VBoxVHWADirtyRect
532{
533public:
534 VBoxVHWADirtyRect() :
535 mIsClear(true)
536 {}
537
538 VBoxVHWADirtyRect(const QRect & aRect)
539 {
540 if(aRect.isEmpty())
541 {
542 mIsClear = false;
543 mRect = aRect;
544 }
545 else
546 {
547 mIsClear = true;
548 }
549 }
550
551 bool isClear() const { return mIsClear; }
552
553 void add(const QRect & aRect)
554 {
555 if(aRect.isEmpty())
556 return;
557
558 mRect = mIsClear ? aRect : mRect.united(aRect);
559 mIsClear = false;
560 }
561
562 void add(const VBoxVHWADirtyRect & aRect)
563 {
564 if(aRect.isClear())
565 return;
566 add(aRect.rect());
567 }
568
569 void set(const QRect & aRect)
570 {
571 if(aRect.isEmpty())
572 {
573 mIsClear = true;
574 }
575 else
576 {
577 mRect = aRect;
578 mIsClear = false;
579 }
580 }
581
582 void clear() { mIsClear = true; }
583
584 const QRect & rect() const {return mRect;}
585
586 bool intersects(const QRect & aRect) const {return mIsClear ? false : mRect.intersects(aRect);}
587
588 bool intersects(const VBoxVHWADirtyRect & aRect) const {return mIsClear ? false : aRect.intersects(mRect);}
589
590 QRect united(const QRect & aRect) const {return mIsClear ? aRect : aRect.united(mRect);}
591
592 bool contains(const QRect & aRect) const {return mIsClear ? false : aRect.contains(mRect);}
593
594 void subst(const VBoxVHWADirtyRect & aRect) { if(!mIsClear && aRect.contains(mRect)) clear(); }
595
596private:
597 QRect mRect;
598 bool mIsClear;
599};
600
601class VBoxVHWAColorKey
602{
603public:
604 VBoxVHWAColorKey() :
605 mUpper(0),
606 mLower(0)
607 {}
608
609 VBoxVHWAColorKey(uint32_t aUpper, uint32_t aLower) :
610 mUpper(aUpper),
611 mLower(aLower)
612 {}
613
614 uint32_t upper() const {return mUpper; }
615 uint32_t lower() const {return mLower; }
616
617 bool operator==(const VBoxVHWAColorKey & other) const { return mUpper == other.mUpper && mLower == other.mLower; }
618private:
619 uint32_t mUpper;
620 uint32_t mLower;
621};
622
623class VBoxVHWAColorComponent
624{
625public:
626 VBoxVHWAColorComponent() :
627 mMask(0),
628 mRange(0),
629 mOffset(32),
630 mcBits(0)
631 {}
632
633 VBoxVHWAColorComponent(uint32_t aMask);
634
635 uint32_t mask() const { return mMask; }
636 uint32_t range() const { return mRange; }
637 uint32_t offset() const { return mOffset; }
638 uint32_t cBits() const { return mcBits; }
639 uint32_t colorVal(uint32_t col) const { return (col & mMask) >> mOffset; }
640 float colorValNorm(uint32_t col) const { return ((float)colorVal(col))/mRange; }
641private:
642 uint32_t mMask;
643 uint32_t mRange;
644 uint32_t mOffset;
645 uint32_t mcBits;
646};
647
648class VBoxVHWAColorFormat
649{
650public:
651
652// VBoxVHWAColorFormat(GLint aInternalFormat, GLenum aFormat, GLenum aType, uint32_t aDataFormat);
653 VBoxVHWAColorFormat(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
654 VBoxVHWAColorFormat(uint32_t fourcc);
655 VBoxVHWAColorFormat(){}
656 GLint internalFormat() const {return mInternalFormat; }
657 GLenum format() const {return mFormat; }
658 GLenum type() const {return mType; }
659 bool isValid() const {return mBitsPerPixel != 0; }
660 uint32_t fourcc() const {return mDataFormat;}
661 uint32_t bitsPerPixel() const { return mBitsPerPixel; }
662 uint32_t bitsPerPixelTex() const { return mBitsPerPixelTex; }
663// uint32_t bitsPerPixelDd() const { return mBitsPerPixelDd; }
664 void pixel2Normalized(uint32_t pix, float *r, float *g, float *b) const;
665 uint32_t widthCompression() const {return mWidthCompression;}
666 uint32_t heightCompression() const {return mHeightCompression;}
667 const VBoxVHWAColorComponent& r() const {return mR;}
668 const VBoxVHWAColorComponent& g() const {return mG;}
669 const VBoxVHWAColorComponent& b() const {return mB;}
670 const VBoxVHWAColorComponent& a() const {return mA;}
671
672private:
673 void VBoxVHWAColorFormat::init(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
674 void VBoxVHWAColorFormat::init(uint32_t fourcc);
675
676 GLint mInternalFormat;
677 GLenum mFormat;
678 GLenum mType;
679 uint32_t mDataFormat;
680
681 uint32_t mBitsPerPixel;
682 uint32_t mBitsPerPixelTex;
683// uint32_t mBitsPerPixelDd;
684 uint32_t mWidthCompression;
685 uint32_t mHeightCompression;
686 VBoxVHWAColorComponent mR;
687 VBoxVHWAColorComponent mG;
688 VBoxVHWAColorComponent mB;
689 VBoxVHWAColorComponent mA;
690};
691
692class VBoxVHWATexture
693{
694public:
695 VBoxVHWATexture() {}
696 VBoxVHWATexture(const QRect * pRect, const VBoxVHWAColorFormat *pFormat);
697 virtual ~VBoxVHWATexture();
698 virtual void init(uchar *pvMem);
699 void setAddress(uchar *pvMem) {mAddress = pvMem;}
700 void update(const QRect * pRect) { doUpdate(mAddress, pRect);}
701 void bind() {glBindTexture(texTarget(), mTexture);}
702
703 virtual void texCoord(int x, int y);
704 virtual void multiTexCoord(GLenum texUnit, int x, int y);
705
706// GLuint texture() {return mTexture;}
707 const QRect & texRect() {return mTexRect;}
708 const QRect & rect() {return mRect;}
709 uchar * address(){ return mAddress; }
710 uint32_t rectSizeTex(const QRect * pRect) {return pRect->width() * pRect->height() * mBytesPerPixelTex;}
711 uchar * pointAddress(int x, int y)
712 {
713 x = toXTex(x);
714 y = toYTex(y);
715 return pointAddressTex(x, y);
716 }
717 uint32_t pointOffsetTex(int x, int y) { return y*mBytesPerLine + x*mBytesPerPixelTex; }
718 uchar * pointAddressTex(int x, int y) { return mAddress + pointOffsetTex(x, y); }
719 int toXTex(int x) {return x/mColorFormat.widthCompression();}
720 int toYTex(int y) {return y/mColorFormat.heightCompression();}
721 ulong memSize(){ return mBytesPerLine * mRect.height(); }
722 uint32_t bytesPerLine() {return mBytesPerLine; }
723
724protected:
725 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
726 virtual void initParams();
727 virtual void load();
728 virtual GLenum texTarget() {return GL_TEXTURE_2D; }
729
730
731 QRect mTexRect; /* texture size */
732 QRect mRect; /* img size */
733 uchar * mAddress;
734 GLuint mTexture;
735 uint32_t mBytesPerPixel;
736 uint32_t mBytesPerPixelTex;
737 uint32_t mBytesPerLine;
738 VBoxVHWAColorFormat mColorFormat;
739private:
740 void uninit();
741};
742
743class VBoxVHWATextureNP2 : public VBoxVHWATexture
744{
745public:
746 VBoxVHWATextureNP2() : VBoxVHWATexture() {}
747 VBoxVHWATextureNP2(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
748 VBoxVHWATexture(pRect, pFormat){
749 mTexRect = QRect(0, 0, pRect->width()/pFormat->widthCompression(), pRect->height()/pFormat->heightCompression());
750 }
751};
752
753class VBoxVHWATextureNP2Rect : public VBoxVHWATextureNP2
754{
755public:
756 VBoxVHWATextureNP2Rect() : VBoxVHWATextureNP2() {}
757 VBoxVHWATextureNP2Rect(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
758 VBoxVHWATextureNP2(pRect, pFormat){}
759
760 virtual void texCoord(int x, int y);
761 virtual void multiTexCoord(GLenum texUnit, int x, int y);
762protected:
763 virtual GLenum texTarget();
764};
765
766class VBoxVHWATextureNP2RectPBO : public VBoxVHWATextureNP2Rect
767{
768public:
769 VBoxVHWATextureNP2RectPBO() : VBoxVHWATextureNP2Rect() {}
770 VBoxVHWATextureNP2RectPBO(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
771 VBoxVHWATextureNP2Rect(pRect, pFormat){}
772 virtual ~VBoxVHWATextureNP2RectPBO();
773
774 virtual void init(uchar *pvMem);
775protected:
776 virtual void load();
777 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
778private:
779 void updateBuffer(uchar * pBuf, const QRect * pRect);
780 GLuint mPBO;
781};
782
783class VBoxVHWAHandleTable
784{
785public:
786 VBoxVHWAHandleTable(uint32_t initialSize);
787 ~VBoxVHWAHandleTable();
788 uint32_t put(void * data);
789 bool mapPut(uint32_t h, void * data);
790 void* get(uint32_t h);
791 void* remove(uint32_t h);
792private:
793 void doPut(uint32_t h, void * data);
794 void doRemove(uint32_t h);
795 void** mTable;
796 uint32_t mcSize;
797 uint32_t mcUsage;
798 uint32_t mCursor;
799};
800
801/* data flow:
802 * I. NON-Yinverted surface:
803 * 1.direct memory update (paint, lock/unlock):
804 * mem->tex->fb
805 * 2.blt
806 * srcTex->invFB->tex->fb
807 * |->mem
808 *
809 * II. Yinverted surface:
810 * 1.direct memory update (paint, lock/unlock):
811 * mem->tex->fb
812 * 2.blt
813 * srcTex->fb->tex
814 * |->mem
815 *
816 * III. flip support:
817 * 1. Yinverted<->NON-YInverted conversion :
818 * mem->tex-(rotate model view, force LAZY complete fb update)->invFB->tex
819 * fb-->| |->mem
820 * */
821class VBoxVHWASurfaceBase
822{
823public:
824 VBoxVHWASurfaceBase(
825 class VBoxGLWidget *mWidget,
826#if 0
827 class VBoxVHWAGlContextState *aState,
828 bool aIsYInverted,
829#endif
830 const QSize * aSize, const QSize * aTargetSize,
831 VBoxVHWAColorFormat & aColorFormat,
832 VBoxVHWAColorKey * pSrcBltCKey, VBoxVHWAColorKey * pDstBltCKey,
833 VBoxVHWAColorKey * pSrcOverlayCKey, VBoxVHWAColorKey * pDstOverlayCKey,
834 bool bVGA);
835
836 virtual ~VBoxVHWASurfaceBase();
837
838 void init(VBoxVHWASurfaceBase * pPrimary, uchar *pvMem);
839 void setupMatricies(VBoxVHWASurfaceBase *pPrimary);
840
841 void uninit();
842
843 static void globalInit();
844
845// int blt(const QRect * aDstRect, VBoxVHWASurfaceBase * aSrtSurface, const QRect * aSrcRect, const VBoxVHWAColorKey * pDstCKeyOverride, const VBoxVHWAColorKey * pSrcCKeyOverride);
846// int overlay(VBoxVHWASurfaceBase * aOverlaySurface);
847
848 int lock(const QRect * pRect, uint32_t flags);
849
850 int unlock();
851
852 void updatedMem(const QRect * aRect);
853
854 void performDisplay(VBoxVHWASurfaceBase *pPrimary);
855
856 void setRects(VBoxVHWASurfaceBase *pPrimary, const QRect * aTargRect, const QRect * aSrcRect);
857 void setTargetRectPosition(VBoxVHWASurfaceBase *pPrimary, const QPoint * aPoint);
858
859 static ulong calcBytesPerPixel(GLenum format, GLenum type);
860
861 static GLsizei makePowerOf2(GLsizei val);
862
863 bool addressAlocated() const { return mFreeAddress; }
864 uchar * address(){ return mAddress; }
865
866 ulong memSize();
867
868 ulong width() { return mRect.width(); }
869 ulong height() { return mRect.height(); }
870
871 GLenum format() {return mColorFormat.format(); }
872 GLint internalFormat() { return mColorFormat.internalFormat(); }
873 GLenum type() { return mColorFormat.type(); }
874 uint32_t fourcc() {return mColorFormat.fourcc(); }
875
876// ulong bytesPerPixel() { return mpTex[0]->bytesPerPixel(); }
877 ulong bitsPerPixel() { return mColorFormat.bitsPerPixel(); }
878// ulong bitsPerPixelDd() { return mColorFormat.bitsPerPixelDd(); }
879 ulong bytesPerLine() { return mpTex[0]->bytesPerLine(); }
880
881 const VBoxVHWAColorKey * dstBltCKey() const { return mpDstBltCKey; }
882 const VBoxVHWAColorKey * srcBltCKey() const { return mpSrcBltCKey; }
883 const VBoxVHWAColorKey * dstOverlayCKey() const { return mpDstOverlayCKey; }
884 const VBoxVHWAColorKey * defaultSrcOverlayCKey() const { return mpDefaultSrcOverlayCKey; }
885 const VBoxVHWAColorKey * defaultDstOverlayCKey() const { return mpDefaultDstOverlayCKey; }
886 const VBoxVHWAColorKey * srcOverlayCKey() const { return mpSrcOverlayCKey; }
887 void resetDefaultSrcOverlayCKey() { mpSrcOverlayCKey = mpDefaultSrcOverlayCKey; }
888 void resetDefaultDstOverlayCKey() { mpDstOverlayCKey = mpDefaultDstOverlayCKey; }
889
890 void setDstBltCKey(const VBoxVHWAColorKey * ckey)
891 {
892 if(ckey)
893 {
894 mDstBltCKey = *ckey;
895 mpDstBltCKey = &mDstBltCKey;
896 }
897 else
898 {
899 mpDstBltCKey = NULL;
900 }
901 }
902
903 void setSrcBltCKey(const VBoxVHWAColorKey * ckey)
904 {
905 if(ckey)
906 {
907 mSrcBltCKey = *ckey;
908 mpSrcBltCKey = &mSrcBltCKey;
909 }
910 else
911 {
912 mpSrcBltCKey = NULL;
913 }
914 }
915
916 void setDefaultDstOverlayCKey(const VBoxVHWAColorKey * ckey)
917 {
918 if(ckey)
919 {
920 mDefaultDstOverlayCKey = *ckey;
921 mpDefaultDstOverlayCKey = &mDefaultDstOverlayCKey;
922 }
923 else
924 {
925 mpDefaultDstOverlayCKey = NULL;
926 }
927 }
928
929 void setDefaultSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
930 {
931 if(ckey)
932 {
933 mDefaultSrcOverlayCKey = *ckey;
934 mpDefaultSrcOverlayCKey = &mDefaultSrcOverlayCKey;
935 }
936 else
937 {
938 mpDefaultSrcOverlayCKey = NULL;
939 }
940 }
941
942 void setOverriddenDstOverlayCKey(const VBoxVHWAColorKey * ckey)
943 {
944 if(ckey)
945 {
946 mOverriddenDstOverlayCKey = *ckey;
947 mpDstOverlayCKey = &mOverriddenDstOverlayCKey;
948 }
949 else
950 {
951 mpDstOverlayCKey = NULL;
952 }
953 }
954
955 void setOverriddenSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
956 {
957 if(ckey)
958 {
959 mOverriddenSrcOverlayCKey = *ckey;
960 mpSrcOverlayCKey = &mOverriddenSrcOverlayCKey;
961 }
962 else
963 {
964 mpSrcOverlayCKey = NULL;
965 }
966 }
967
968 const VBoxVHWAColorKey * getActiveSrcOverlayCKey()
969 {
970 return mpSrcOverlayCKey;
971 }
972
973 const VBoxVHWAColorKey * getActiveDstOverlayCKey(VBoxVHWASurfaceBase * pPrimary)
974 {
975 return mpDstOverlayCKey ? mpDefaultDstOverlayCKey : pPrimary->mpDstOverlayCKey;
976 }
977
978 const VBoxVHWAColorFormat & colorFormat() {return mColorFormat; }
979
980 void setAddress(uchar * addr);
981
982 const QRect& rect() {return mRect;}
983
984 class VBoxVHWASurfList * getComplexList() {return mComplexList; }
985
986 class VBoxVHWAGlProgramMngr * getGlProgramMngr();
987 static int setCKey(class VBoxVHWAGlProgramVHWA * pProgram, const VBoxVHWAColorFormat * pFormat, const VBoxVHWAColorKey * pCKey, bool bDst);
988
989 uint64_t handle() {return mHGHandle;}
990 void setHandle(uint64_t h) {mHGHandle = h;}
991private:
992 void setComplexList(VBoxVHWASurfList *aComplexList) { mComplexList = aComplexList; }
993 void initDisplay(VBoxVHWASurfaceBase *pPrimary);
994 void deleteDisplay();
995
996 GLuint createDisplay(VBoxVHWASurfaceBase *pPrimary);
997 void doDisplay(VBoxVHWASurfaceBase *pPrimary, VBoxVHWAGlProgramVHWA * pProgram, bool bBindDst);
998 void synchTexMem(const QRect * aRect);
999
1000 int performBlt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool blt);
1001
1002 void doTex2FB(const QRect * pDstRect, const QRect * pSrcRect);
1003 void doMultiTex2FB(const QRect * pDstRect, VBoxVHWATexture * pDstTex, const QRect * pSrcRect, int cSrcTex);
1004 void doMultiTex2FB(const QRect * pDstRect, const QRect * pSrcRect, int cSrcTex);
1005
1006 void doSetupMatrix(const QSize * pSize , bool bInverted);
1007
1008 QRect mRect; /* == Inv FB size */
1009
1010 QRect mSrcRect;
1011 QRect mTargRect; /* == Vis FB size */
1012 QRect mTargSize;
1013
1014 GLuint mVisibleDisplay;
1015
1016 bool mVisibleDisplayInitialized;
1017
1018 uchar * mAddress;
1019 VBoxVHWATexture *mpTex[3];
1020
1021 VBoxVHWAColorFormat mColorFormat;
1022
1023 VBoxVHWAColorKey *mpSrcBltCKey;
1024 VBoxVHWAColorKey *mpDstBltCKey;
1025 VBoxVHWAColorKey *mpSrcOverlayCKey;
1026 VBoxVHWAColorKey *mpDstOverlayCKey;
1027
1028 VBoxVHWAColorKey *mpDefaultDstOverlayCKey;
1029 VBoxVHWAColorKey *mpDefaultSrcOverlayCKey;
1030
1031 VBoxVHWAColorKey mSrcBltCKey;
1032 VBoxVHWAColorKey mDstBltCKey;
1033 VBoxVHWAColorKey mOverriddenSrcOverlayCKey;
1034 VBoxVHWAColorKey mOverriddenDstOverlayCKey;
1035 VBoxVHWAColorKey mDefaultDstOverlayCKey;
1036 VBoxVHWAColorKey mDefaultSrcOverlayCKey;
1037
1038 int mLockCount;
1039 /* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
1040 VBoxVHWADirtyRect mUpdateMem2TexRect;
1041
1042 bool mFreeAddress;
1043
1044 class VBoxVHWASurfList *mComplexList;
1045
1046 class VBoxGLWidget *mWidget;
1047
1048 uint64_t mHGHandle;
1049protected:
1050
1051 friend class VBoxVHWASurfList;
1052#ifdef DEBUG
1053public:
1054 uint64_t cFlipsCurr;
1055 uint64_t cFlipsTarg;
1056#endif
1057};
1058
1059typedef std::list <VBoxVHWASurfaceBase*> SurfList;
1060typedef std::list <VBoxVHWASurfList*> OverlayList;
1061
1062class VBoxVHWASurfList
1063{
1064public:
1065
1066 VBoxVHWASurfList() : mCurrent(NULL) {}
1067 void add(VBoxVHWASurfaceBase *pSurf)
1068 {
1069 VBoxVHWASurfList * pOld = pSurf->getComplexList();
1070 if(pOld)
1071 {
1072 pOld->remove(pSurf);
1073 }
1074 mSurfaces.push_back(pSurf);
1075 pSurf->setComplexList(this);
1076 }
1077
1078 void clear()
1079 {
1080 for (SurfList::iterator it = mSurfaces.begin();
1081 it != mSurfaces.end(); ++ it)
1082 {
1083 (*it)->setComplexList(NULL);
1084 }
1085 mSurfaces.clear();
1086 mCurrent = NULL;
1087 }
1088
1089 void remove(VBoxVHWASurfaceBase *pSurf)
1090 {
1091 mSurfaces.remove(pSurf);
1092 pSurf->setComplexList(NULL);
1093 if(mCurrent == pSurf)
1094 mCurrent = NULL;
1095 }
1096
1097 bool empty() { return mSurfaces.empty(); }
1098
1099 void setCurrentVisible(VBoxVHWASurfaceBase *pSurf)
1100 {
1101 mCurrent = pSurf;
1102 }
1103
1104 VBoxVHWASurfaceBase * current() { return mCurrent; }
1105 const SurfList & surfaces() const {return mSurfaces;}
1106
1107private:
1108
1109 SurfList mSurfaces;
1110 VBoxVHWASurfaceBase* mCurrent;
1111};
1112
1113class VBoxVHWADisplay
1114{
1115public:
1116 VBoxVHWADisplay() :
1117 mSurfVGA(NULL)
1118// ,
1119// mSurfPrimary(NULL)
1120 {}
1121
1122 VBoxVHWASurfaceBase * setVGA(VBoxVHWASurfaceBase * pVga)
1123 {
1124 VBoxVHWASurfaceBase * old = mSurfVGA;
1125 mSurfVGA = pVga;
1126 mPrimary.clear();
1127 if(pVga)
1128 {
1129 mPrimary.add(pVga);
1130 mPrimary.setCurrentVisible(pVga);
1131 }
1132// mSurfPrimary = pVga;
1133 mOverlays.clear();
1134 return old;
1135 }
1136
1137 VBoxVHWASurfaceBase * getVGA()
1138 {
1139 return mSurfVGA;
1140 }
1141
1142 VBoxVHWASurfaceBase * getPrimary()
1143 {
1144 return mPrimary.current();
1145 }
1146//
1147// void setPrimary(VBoxVHWASurfList * pSurf)
1148// {
1149// mSurfPrimary = pSurf;
1150// }
1151
1152 void addOverlay(VBoxVHWASurfList * pSurf)
1153 {
1154 mOverlays.push_back(pSurf);
1155 }
1156
1157 void checkAddOverlay(VBoxVHWASurfList * pSurf)
1158 {
1159 if(!hasOverlay(pSurf))
1160 addOverlay(pSurf);
1161 }
1162
1163 bool hasOverlay(VBoxVHWASurfList * pSurf)
1164 {
1165 for (OverlayList::iterator it = mOverlays.begin();
1166 it != mOverlays.end(); ++ it)
1167 {
1168 if((*it) == pSurf)
1169 {
1170 return true;
1171 }
1172 }
1173 return false;
1174 }
1175
1176 void removeOverlay(VBoxVHWASurfList * pSurf)
1177 {
1178 mOverlays.remove(pSurf);
1179 }
1180
1181 void performDisplay()
1182 {
1183 VBoxVHWASurfaceBase * pPrimary = mPrimary.current();
1184 pPrimary->performDisplay(NULL);
1185
1186 for (OverlayList::const_iterator it = mOverlays.begin();
1187 it != mOverlays.end(); ++ it)
1188 {
1189 VBoxVHWASurfaceBase * pOverlay = (*it)->current();
1190 if(pOverlay)
1191 {
1192 pOverlay->performDisplay(pPrimary);
1193 }
1194 }
1195 }
1196
1197 const OverlayList & overlays() const {return mOverlays;}
1198
1199private:
1200 VBoxVHWASurfaceBase *mSurfVGA;
1201 VBoxVHWASurfList mPrimary;
1202
1203 OverlayList mOverlays;
1204};
1205
1206typedef void (VBoxGLWidget::*PFNVBOXQGLOP)(void* );
1207
1208class VBoxGLWidget : public QGLWidget
1209{
1210public:
1211 VBoxGLWidget (VBoxConsoleView *aView, QWidget *aParent);
1212 ~VBoxGLWidget();
1213
1214 ulong vboxPixelFormat() { return mPixelFormat; }
1215 bool vboxUsesGuestVRAM() { return mUsesGuestVRAM; }
1216
1217 uchar *vboxAddress() { return mDisplay.getVGA() ? mDisplay.getVGA()->address() : NULL; }
1218
1219#ifdef VBOX_WITH_VIDEOHWACCEL
1220 uchar *vboxVRAMAddressFromOffset(uint64_t offset);
1221
1222 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1223 int vhwaLoadExec(struct SSMHANDLE * pSSM, uint32_t u32Version);
1224#endif
1225
1226 ulong vboxBitsPerPixel() { return mDisplay.getVGA()->bitsPerPixel(); }
1227 ulong vboxBytesPerLine() { return mDisplay.getVGA() ? mDisplay.getVGA()->bytesPerLine() : NULL; }
1228
1229 void vboxPaintEvent (QPaintEvent *pe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoPaint, pe);}
1230 void vboxResizeEvent (VBoxResizeEvent *re) {vboxPerformGLOp(&VBoxGLWidget::vboxDoResize, re);}
1231
1232 void vboxProcessVHWACommands(VBoxVHWACommandProcessEvent * pEvent) {vboxPerformGLOp(&VBoxGLWidget::vboxDoProcessVHWACommands, pEvent);}
1233#ifdef VBOX_WITH_VIDEOHWACCEL
1234 void vboxVHWACmd (struct _VBOXVHWACMD * pCmd) {vboxPerformGLOp(&VBoxGLWidget::vboxDoVHWACmd, pCmd);}
1235#endif
1236 class VBoxVHWAGlProgramMngr * vboxVHWAGetGlProgramMngr() { return mpMngr; }
1237
1238 VBoxVHWASurfaceBase * vboxGetVGASurface() { return mDisplay.getVGA(); }
1239
1240 void postCmd(VBOXVHWA_PIPECMD_TYPE aType, void * pvData);
1241protected:
1242
1243 void paintGL()
1244 {
1245 if(mpfnOp)
1246 {
1247 (this->*mpfnOp)(mOpContext);
1248 mpfnOp = NULL;
1249 }
1250 else
1251 {
1252 mDisplay.performDisplay();
1253 }
1254 }
1255
1256 void initializeGL();
1257private:
1258 void vboxDoResize(void *re);
1259 void vboxDoPaint(void *rec);
1260
1261 void vboxDoUpdateRect(const QRect * pRect);
1262#ifdef VBOXQGL_DBG_SURF
1263 void vboxDoTestSurfaces(void *context);
1264#endif
1265#ifdef VBOX_WITH_VIDEOHWACCEL
1266 void vboxDoVHWACmdExec(void *cmd);
1267 void vboxDoVHWACmd(void *cmd);
1268
1269 void vboxCheckUpdateAddress (VBoxVHWASurfaceBase * pSurface, uint64_t offset)
1270 {
1271#ifndef VBOXQGL_DBG_SURF
1272 if(offset == 0xffffffffffffffffL)
1273 {
1274 return;
1275 }
1276#endif
1277 if (pSurface->addressAlocated())
1278 {
1279 uchar * addr = vboxVRAMAddressFromOffset(offset);
1280 if(addr)
1281 {
1282 pSurface->setAddress(addr);
1283 }
1284 }
1285 }
1286 int vhwaSurfaceCanCreate(struct _VBOXVHWACMD_SURF_CANCREATE *pCmd);
1287 int vhwaSurfaceCreate(struct _VBOXVHWACMD_SURF_CREATE *pCmd);
1288 int vhwaSurfaceDestroy(struct _VBOXVHWACMD_SURF_DESTROY *pCmd);
1289 int vhwaSurfaceLock(struct _VBOXVHWACMD_SURF_LOCK *pCmd);
1290 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1291 int vhwaSurfaceBlt(struct _VBOXVHWACMD_SURF_BLT *pCmd);
1292 int vhwaSurfaceFlip(struct _VBOXVHWACMD_SURF_FLIP *pCmd);
1293 int vhwaSurfaceOverlayUpdate(struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmf);
1294 int vhwaSurfaceOverlaySetPosition(struct _VBOXVHWACMD_SURF_OVERLAY_SETPOSITION *pCmd);
1295 int vhwaSurfaceColorkeySet(struct _VBOXVHWACMD_SURF_COLORKEY_SET *pCmd);
1296 int vhwaQueryInfo1(struct _VBOXVHWACMD_QUERYINFO1 *pCmd);
1297 int vhwaQueryInfo2(struct _VBOXVHWACMD_QUERYINFO2 *pCmd);
1298 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1299
1300 int vhwaSaveSurface(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, uint32_t surfCaps);
1301 int vhwaLoadSurface(struct SSMHANDLE * pSSM, uint32_t u32Version);
1302 int vhwaSaveOverlayData(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf);
1303 int vhwaLoadOverlayData(struct SSMHANDLE * pSSM, uint32_t u32Version);
1304
1305 void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
1306#endif
1307 static const QGLFormat & vboxGLFormat();
1308
1309 VBoxVHWADisplay mDisplay;
1310
1311
1312 /* we do all opengl stuff in the paintGL context,
1313 * submit the operation to be performed
1314 * @todo: could be moved outside the updateGL */
1315 void vboxPerformGLOp(PFNVBOXQGLOP pfn, void* pContext) {mpfnOp = pfn; mOpContext = pContext; updateGL();}
1316
1317 /* posts op to UI thread */
1318 int vboxExecOpSynch(PFNVBOXQGLOP pfn, void* pContext);
1319
1320 void cmdPipeInit();
1321 void cmdPipeDelete();
1322 void vboxDoProcessVHWACommands(void *pContext);
1323
1324 VBoxVHWACommandElement * detachCmdList(VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
1325 VBoxVHWACommandElement * processCmdList(VBoxVHWACommandElement * pCmd);
1326
1327 VBoxVHWASurfaceBase* handle2Surface(uint32_t h) { return (VBoxVHWASurfaceBase*)mSurfHandleTable.get(h); }
1328
1329 VBoxVHWAHandleTable mSurfHandleTable;
1330
1331 PFNVBOXQGLOP mpfnOp;
1332 void *mOpContext;
1333
1334 ulong mPixelFormat;
1335 bool mUsesGuestVRAM;
1336 bool mVGASurfCreated;
1337
1338 RTCRITSECT mCritSect;
1339 VBoxVHWACommandProcessEvent *mpFirstEvent;
1340 VBoxVHWACommandProcessEvent *mpLastEvent;
1341 bool mbNewEvent;
1342 VBoxVHWACommandElementStack mFreeElements;
1343 VBoxVHWACommandElement mElementsBuffer[2048];
1344
1345 VBoxConsoleView *mView;
1346
1347 VBoxVHWASurfList *mConstructingList;
1348 int32_t mcRemaining2Contruct;
1349
1350 class VBoxVHWAGlProgramMngr *mpMngr;
1351};
1352
1353
1354class VBoxQGLFrameBuffer : public VBoxFrameBuffer
1355{
1356public:
1357
1358 VBoxQGLFrameBuffer (VBoxConsoleView *aView);
1359
1360 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1361 ULONG aW, ULONG aH);
1362#ifdef VBOXQGL_PROF_BASE
1363 STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
1364 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
1365 ULONG aWidth, ULONG aHeight,
1366 BOOL *aFinished);
1367#endif
1368
1369#ifdef VBOX_WITH_VIDEOHWACCEL
1370 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
1371
1372
1373 static bool isAcceleration2DVideoAvailable();
1374#endif
1375
1376 ulong pixelFormat() { return vboxWidget()->vboxPixelFormat(); }
1377 bool usesGuestVRAM() { return vboxWidget()->vboxUsesGuestVRAM(); }
1378
1379 uchar *address() { return vboxWidget()->vboxAddress(); }
1380 ulong bitsPerPixel() { return vboxWidget()->vboxBitsPerPixel(); }
1381 ulong bytesPerLine() { return vboxWidget()->vboxBytesPerLine(); }
1382
1383 void paintEvent (QPaintEvent *pe);
1384 void resizeEvent (VBoxResizeEvent *re);
1385 void doProcessVHWACommand(VBoxVHWACommandProcessEvent * pEvent);
1386
1387private:
1388// void vboxMakeCurrent();
1389 VBoxGLWidget * vboxWidget();
1390};
1391
1392
1393#endif
1394
1395/////////////////////////////////////////////////////////////////////////////
1396
1397#if defined (VBOX_GUI_USE_SDL)
1398
1399class VBoxSDLFrameBuffer : public VBoxFrameBuffer
1400{
1401public:
1402
1403 VBoxSDLFrameBuffer (VBoxConsoleView *aView);
1404 virtual ~VBoxSDLFrameBuffer();
1405
1406 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1407 ULONG aW, ULONG aH);
1408
1409 uchar *address()
1410 {
1411 SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
1412 return surf ? (uchar *) (uintptr_t) surf->pixels : 0;
1413 }
1414
1415 ulong bitsPerPixel()
1416 {
1417 SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
1418 return surf ? surf->format->BitsPerPixel : 0;
1419 }
1420
1421 ulong bytesPerLine()
1422 {
1423 SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
1424 return surf ? surf->pitch : 0;
1425 }
1426
1427 ulong pixelFormat()
1428 {
1429 return mPixelFormat;
1430 }
1431
1432 bool usesGuestVRAM()
1433 {
1434 return mSurfVRAM != NULL;
1435 }
1436
1437 void paintEvent (QPaintEvent *pe);
1438 void resizeEvent (VBoxResizeEvent *re);
1439
1440private:
1441
1442 SDL_Surface *mScreen;
1443 SDL_Surface *mSurfVRAM;
1444
1445 ulong mPixelFormat;
1446};
1447
1448#endif
1449
1450/////////////////////////////////////////////////////////////////////////////
1451
1452#if defined (VBOX_GUI_USE_DDRAW)
1453
1454class VBoxDDRAWFrameBuffer : public VBoxFrameBuffer
1455{
1456public:
1457
1458 VBoxDDRAWFrameBuffer (VBoxConsoleView *aView);
1459 virtual ~VBoxDDRAWFrameBuffer();
1460
1461 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1462 ULONG aW, ULONG aH);
1463
1464 uchar *address() { return (uchar *) mSurfaceDesc.lpSurface; }
1465 ulong bitsPerPixel() { return mSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; }
1466 ulong bytesPerLine() { return (ulong) mSurfaceDesc.lPitch; }
1467
1468 ulong pixelFormat() { return mPixelFormat; };
1469
1470 bool usesGuestVRAM() { return mUsesGuestVRAM; }
1471
1472 void paintEvent (QPaintEvent *pe);
1473 void resizeEvent (VBoxResizeEvent *re);
1474 void moveEvent (QMoveEvent *me);
1475
1476private:
1477
1478 void releaseObjects();
1479
1480 bool createSurface (ULONG aPixelFormat, uchar *pvVRAM,
1481 ULONG aBitsPerPixel, ULONG aBytesPerLine,
1482 ULONG aWidth, ULONG aHeight);
1483 void deleteSurface();
1484 void drawRect (ULONG x, ULONG y, ULONG w, ULONG h);
1485 void getWindowPosition (void);
1486
1487 LPDIRECTDRAW7 mDDRAW;
1488 LPDIRECTDRAWCLIPPER mClipper;
1489 LPDIRECTDRAWSURFACE7 mSurface;
1490 DDSURFACEDESC2 mSurfaceDesc;
1491 LPDIRECTDRAWSURFACE7 mPrimarySurface;
1492
1493 ulong mPixelFormat;
1494
1495 bool mUsesGuestVRAM;
1496
1497 int mWndX;
1498 int mWndY;
1499
1500 bool mSynchronousUpdates;
1501};
1502
1503#endif
1504
1505/////////////////////////////////////////////////////////////////////////////
1506
1507#if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
1508
1509#include <Carbon/Carbon.h>
1510
1511class VBoxQuartz2DFrameBuffer : public VBoxFrameBuffer
1512{
1513public:
1514
1515 VBoxQuartz2DFrameBuffer (VBoxConsoleView *aView);
1516 virtual ~VBoxQuartz2DFrameBuffer ();
1517
1518 STDMETHOD (NotifyUpdate) (ULONG aX, ULONG aY,
1519 ULONG aW, ULONG aH);
1520 STDMETHOD (SetVisibleRegion) (BYTE *aRectangles, ULONG aCount);
1521
1522 uchar *address() { return mDataAddress; }
1523 ulong bitsPerPixel() { return CGImageGetBitsPerPixel (mImage); }
1524 ulong bytesPerLine() { return CGImageGetBytesPerRow (mImage); }
1525 ulong pixelFormat() { return mPixelFormat; };
1526 bool usesGuestVRAM() { return mBitmapData == NULL; }
1527
1528 const CGImageRef imageRef() const { return mImage; }
1529
1530 void paintEvent (QPaintEvent *pe);
1531 void resizeEvent (VBoxResizeEvent *re);
1532
1533private:
1534
1535 void clean();
1536
1537 uchar *mDataAddress;
1538 void *mBitmapData;
1539 ulong mPixelFormat;
1540 CGImageRef mImage;
1541 typedef struct
1542 {
1543 /** The size of this structure expressed in rcts entries. */
1544 ULONG allocated;
1545 /** The number of entries in the rcts array. */
1546 ULONG used;
1547 /** Variable sized array of the rectangle that makes up the region. */
1548 CGRect rcts[1];
1549 } RegionRects;
1550 /** The current valid region, all access is by atomic cmpxchg or atomic xchg.
1551 *
1552 * The protocol for updating and using this has to take into account that
1553 * the producer (SetVisibleRegion) and consumer (paintEvent) are running
1554 * on different threads. Therefore the producer will create a new RegionRects
1555 * structure before atomically replace the existing one. While the consumer
1556 * will read the value by atomically replace it by NULL, and then when its
1557 * done try restore it by cmpxchg. If the producer has already put a new
1558 * region there, it will be discarded (see mRegionUnused).
1559 */
1560 RegionRects volatile *mRegion;
1561 /** For keeping the unused region and thus avoid some RTMemAlloc/RTMemFree calls.
1562 * This is operated with atomic cmpxchg and atomic xchg. */
1563 RegionRects volatile *mRegionUnused;
1564};
1565
1566#endif /* Q_WS_MAC && VBOX_GUI_USE_QUARTZ2D */
1567
1568#endif // !___VBoxFrameBuffer_h___
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