VirtualBox

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

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

video hw accel: fixes for basic ddraw op hanlding

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette