VirtualBox

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

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

video hw accel & HGSMI saved state fixes

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