VirtualBox

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

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

video hw accel: bugfix

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