VirtualBox

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

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

video hw accel: propper report supported functionality, some code cleaning

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