Changeset 26823 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Feb 26, 2010 10:35:32 AM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 4 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r26822 r26823 490 490 src/runtime/UIIndicatorsPool.cpp \ 491 491 src/runtime/UIFrameBuffer.cpp \ 492 src/runtime/UIFrameBufferDirectDraw.cpp \ 492 493 src/runtime/UIFrameBufferQGL.cpp \ 494 src/runtime/UIFrameBufferQImage.cpp \ 493 495 src/runtime/UIFrameBufferQuartz2D.cpp \ 494 496 src/runtime/UIFrameBufferSDL.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp
r26822 r26823 25 25 # include "precomp.h" 26 26 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 27 /* Global includes */ 28 #include <QPainter> 27 29 28 /* Local includes */ 30 #include "UIMachineView.h" 31 #include "UIFrameBuffer.h" 32 #include "VBoxProblemReporter.h" 33 #include "VBoxGlobal.h" 29 # include "UIMachineView.h" 30 # include "UIFrameBuffer.h" 31 # include "VBoxProblemReporter.h" 32 # include "VBoxGlobal.h" 33 34 34 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 35 35 … … 246 246 #endif 247 247 248 #ifdef VBOX_GUI_USE_QIMAGE249 /** @class UIFrameBufferQImage250 *251 * The UIFrameBufferQImage class is a class that implements the IFrameBuffer252 * interface and uses QImage as the direct storage for VM display data. QImage253 * is then converted to QPixmap and blitted to the console view widget.254 */255 UIFrameBufferQImage::UIFrameBufferQImage(UIMachineView *pMachineView)256 : UIFrameBuffer(pMachineView)257 {258 /* Initialize the framebuffer the first time */259 resizeEvent(new UIResizeEvent(FramebufferPixelFormat_Opaque, NULL, 0, 0, 640, 480));260 }261 262 /** @note This method is called on EMT from under this object's lock */263 STDMETHODIMP UIFrameBufferQImage::NotifyUpdate(ULONG uX, ULONG uY, ULONG uW, ULONG uH)264 {265 /* We're not on the GUI thread and update() isn't thread safe in266 * Qt 4.3.x on the Win, Qt 3.3.x on the Mac (4.2.x is),267 * on Linux (didn't check Qt 4.x there) and probably on other268 * non-DOS platforms, so post the event instead. */269 QApplication::postEvent(m_pMachineView, new UIRepaintEvent(uX, uY, uW, uH));270 271 return S_OK;272 }273 274 void UIFrameBufferQImage::paintEvent(QPaintEvent *pEvent)275 {276 const QRect &r = pEvent->rect().intersected(m_pMachineView->viewport()->rect());277 278 /* Some outdated rectangle during processing UIResizeEvent */279 if (r.isEmpty())280 return;281 282 #if 0283 LogFlowFunc (("%dx%d-%dx%d (img=%dx%d)\n", r.x(), r.y(), r.width(), r.height(), img.width(), img.height()));284 #endif285 286 QPainter painter(m_pMachineView->viewport());287 288 if (r.width() < m_width * 2 / 3)289 {290 /* This method is faster for narrow updates */291 m_PM = QPixmap::fromImage(m_img.copy(r.x() + m_pMachineView->contentsX(),292 r.y() + m_pMachineView->contentsY(),293 r.width(), r.height()));294 painter.drawPixmap(r.x(), r.y(), m_PM);295 }296 else297 {298 /* This method is faster for wide updates */299 m_PM = QPixmap::fromImage(QImage(m_img.scanLine (r.y() + m_pMachineView->contentsY()),300 m_img.width(), r.height(), m_img.bytesPerLine(),301 QImage::Format_RGB32));302 painter.drawPixmap(r.x(), r.y(), m_PM, r.x() + m_pMachineView->contentsX(), 0, 0, 0);303 }304 }305 306 void UIFrameBufferQImage::resizeEvent(UIResizeEvent *pEvent)307 {308 #if 0309 LogFlowFunc (("fmt=%d, vram=%p, bpp=%d, bpl=%d, width=%d, height=%d\n",310 pEvent->pixelFormat(), pEvent->VRAM(),311 pEvent->bitsPerPixel(), pEvent->bytesPerLine(),312 pEvent->width(), pEvent->height()));313 #endif314 315 m_width = pEvent->width();316 m_height = pEvent->height();317 318 bool bRemind = false;319 bool bFallback = false;320 ulong bitsPerLine = pEvent->bytesPerLine() * 8;321 322 /* check if we support the pixel format and can use the guest VRAM directly */323 if (pEvent->pixelFormat() == FramebufferPixelFormat_FOURCC_RGB)324 {325 QImage::Format format;326 switch (pEvent->bitsPerPixel())327 {328 /* 32-, 8- and 1-bpp are the only depths supported by QImage */329 case 32:330 format = QImage::Format_RGB32;331 break;332 case 8:333 format = QImage::Format_Indexed8;334 bRemind = true;335 break;336 case 1:337 format = QImage::Format_Mono;338 bRemind = true;339 break;340 default:341 format = QImage::Format_Invalid; /* set it to something so gcc keeps quiet. */342 bRemind = true;343 bFallback = true;344 break;345 }346 347 if (!bFallback)348 {349 /* QImage only supports 32-bit aligned scan lines... */350 Assert ((pEvent->bytesPerLine() & 3) == 0);351 bFallback = ((pEvent->bytesPerLine() & 3) != 0);352 }353 if (!bFallback)354 {355 /* ...and the scan lines ought to be a whole number of pixels. */356 Assert ((bitsPerLine & (pEvent->bitsPerPixel() - 1)) == 0);357 bFallback = ((bitsPerLine & (pEvent->bitsPerPixel() - 1)) != 0);358 }359 if (!bFallback)360 {361 ulong virtWdt = bitsPerLine / pEvent->bitsPerPixel();362 m_img = QImage ((uchar *) pEvent->VRAM(), virtWdt, m_height, format);363 m_uPixelFormat = FramebufferPixelFormat_FOURCC_RGB;364 m_bUsesGuestVRAM = true;365 }366 }367 else368 {369 bFallback = true;370 }371 372 if (bFallback)373 {374 /* we don't support either the pixel format or the color depth,375 * bFallback to a self-provided 32bpp RGB buffer */376 m_img = QImage (m_width, m_height, QImage::Format_RGB32);377 m_uPixelFormat = FramebufferPixelFormat_FOURCC_RGB;378 m_bUsesGuestVRAM = false;379 }380 381 if (bRemind)382 {383 class RemindEvent : public VBoxAsyncEvent384 {385 ulong mRealBPP;386 public:387 RemindEvent (ulong aRealBPP)388 : mRealBPP (aRealBPP) {}389 void handle()390 {391 vboxProblem().remindAboutWrongColorDepth (mRealBPP, 32);392 }393 };394 (new RemindEvent (pEvent->bitsPerPixel()))->post();395 }396 }397 #endif /* VBOX_GUI_USE_QIMAGE */398 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.h
r26822 r26823 25 25 26 26 /* Global includes */ 27 //#include <QImage> 28 #include <QPixmap> 29 //#include <QMutex> 27 #include <QRegion> 30 28 #include <QPaintEvent> 31 //#include <QMoveEvent>32 29 33 30 /* Local includes */ 34 31 #include "COMDefs.h" 35 32 #include <iprt/critsect.h> 36 37 //#if defined (VBOX_GUI_USE_SDL)38 //#include <SDL.h>39 //#include <signal.h>40 //#endif41 42 //#if defined (Q_WS_WIN) && defined (VBOX_GUI_USE_DDRAW)43 // VBox/cdefs.h defines these:44 //#undef LOWORD45 //#undef HIWORD46 //#undef LOBYTE47 //#undef HIBYTE48 //#include <ddraw.h>49 //#endif50 33 51 34 class UIMachineView; … … 261 244 }; 262 245 263 #if defined (VBOX_GUI_USE_QIMAGE)264 class UIFrameBufferQImage : public UIFrameBuffer265 {266 public:267 268 UIFrameBufferQImage(UIMachineView *pMachineView);269 270 STDMETHOD(NotifyUpdate) (ULONG uX, ULONG uY, ULONG uW, ULONG uH);271 272 ulong pixelFormat() { return m_uPixelFormat; }273 bool usesGuestVRAM() { return m_bUsesGuestVRAM; }274 275 uchar *address() { return m_img.bits(); }276 ulong bitsPerPixel() { return m_img.depth(); }277 ulong bytesPerLine() { return m_img.bytesPerLine(); }278 279 void paintEvent (QPaintEvent *pEvent);280 void resizeEvent (UIResizeEvent *pEvent);281 282 private:283 284 QPixmap m_PM;285 QImage m_img;286 ulong m_uPixelFormat;287 bool m_bUsesGuestVRAM;288 };289 #endif290 291 #if 0292 #if defined (VBOX_GUI_USE_DDRAW)293 class UIFrameBufferDDRAW : public UIFrameBuffer294 {295 public:296 297 UIFrameBufferDDRAW(UIMachineView *pMachineView);298 virtual ~UIFrameBufferDDRAW();299 300 STDMETHOD(NotifyUpdate) (ULONG uX, ULONG uY, ULONG uW, ULONG uH);301 302 uchar* address() { return (uchar*) m_surfaceDesc.lpSurface; }303 ulong bitsPerPixel() { return m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount; }304 ulong bytesPerLine() { return (ulong) m_surfaceDesc.lPitch; }305 306 ulong pixelFormat() { return m_uPixelFormat; };307 308 bool usesGuestVRAM() { return m_bUsesGuestVRAM; }309 310 void paintEvent(QPaintEvent *pEvent);311 void resizeEvent(UIResizeEvent *pEvent);312 void moveEvent(QMoveEvent *pEvent);313 314 private:315 316 void releaseObjects();317 318 bool createSurface(ULONG uPixelFormat, uchar *pvVRAM,319 ULONG uBitsPerPixel, ULONG uBytesPerLine,320 ULONG uWidth, ULONG uHeight);321 void deleteSurface();322 void drawRect(ULONG uX, ULONG uY, ULONG uW, ULONG uH);323 void getWindowPosition(void);324 325 LPDIRECTDRAW7 m_DDRAW;326 LPDIRECTDRAWCLIPPER m_clipper;327 LPDIRECTDRAWSURFACE7 m_surface;328 DDSURFACEDESC2 m_surfaceDesc;329 LPDIRECTDRAWSURFACE7 m_primarySurface;330 331 ulong m_uPixelFormat;332 333 bool m_bUsesGuestVRAM;334 335 int m_iWndX;336 int m_iWndY;337 338 bool m_bSynchronousUpdates;339 };340 #endif341 #endif342 343 246 #endif // !___UIFrameBuffer_h___ 344 247 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferDirectDraw.cpp
r26818 r26823 22 22 */ 23 23 24 #if defined (VBOX_GUI_USE_DDRAW)24 #ifdef VBOX_GUI_USE_DDRAW 25 25 26 26 #ifdef VBOX_WITH_PRECOMPILED_HEADERS 27 27 # include "precomp.h" 28 28 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 29 #include "VBoxFrameBuffer.h" 30 31 # include "VBoxConsoleView.h"32 33 #include <qapplication.h> 34 //Added by qt3to4: 35 # include <QMoveEvent>36 #include <QPaintEvent> 37 38 # include <iprt/param.h>39 #include <iprt/alloc.h> 29 30 /* Local includes */ 31 # include "UIFrameBufferDirectDraw.h" 32 # include "UIMachineView.h" 33 34 # include <iprt/param.h> 35 # include <iprt/alloc.h> 36 37 /* Global includes */ 38 # include <QApplication> 39 40 40 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 41 41 42 42 #define LOGDDRAW Log 43 43 44 // TODO_NEW_CORE 45 #if 0 44 46 /* @todo 45 47 * - when paused in Guest VRAM mode after pause the screen is dimmed. because VRAM is dimmed. … … 517 519 } 518 520 519 #endif /* defined (VBOX_GUI_USE_DDRAW) */ 520 521 #endif 522 523 #endif /* VBOX_GUI_USE_DDRAW */ 524 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferDirectDraw.h
r26822 r26823 2 2 * 3 3 * VBox frontends: Qt GUI ("VirtualBox"): 4 * UIFrameBuffer class and subclasses declarations4 * UIFrameBufferDirectDraw class declarations 5 5 */ 6 6 … … 21 21 */ 22 22 23 #ifndef ___UIFrameBuffer _h___24 #define ___UIFrameBuffer _h___23 #ifndef ___UIFrameBufferDirectDraw_h___ 24 #define ___UIFrameBufferDirectDraw_h___ 25 25 26 /* Global includes */ 27 //#include <QImage> 28 #include <QPixmap> 29 //#include <QMutex> 30 #include <QPaintEvent> 31 //#include <QMoveEvent> 26 #ifdef VBOX_GUI_USE_DDRAW 32 27 33 28 /* Local includes */ 34 #include "COMDefs.h" 35 #include <iprt/critsect.h> 29 #include "UIFrameBuffer.h" 36 30 37 //#if defined (VBOX_GUI_USE_SDL) 38 //#include <SDL.h> 39 //#include <signal.h> 40 //#endif 31 /* VBox/cdefs.h defines these: */ 32 #undef LOWORD 33 #undef HIWORD 34 #undef LOBYTE 35 #undef HIBYTE 36 #include <ddraw.h> 41 37 42 //#if defined (Q_WS_WIN) && defined (VBOX_GUI_USE_DDRAW) 43 // VBox/cdefs.h defines these: 44 //#undef LOWORD 45 //#undef HIWORD 46 //#undef LOBYTE 47 //#undef HIBYTE 48 //#include <ddraw.h> 49 //#endif 50 51 class UIMachineView; 52 53 /** 54 * Frame buffer resize event. 55 */ 56 class UIResizeEvent : public QEvent 57 { 58 public: 59 60 UIResizeEvent(ulong uPixelFormat, uchar *pVRAM, 61 ulong uBitsPerPixel, ulong uBytesPerLine, 62 ulong uWidth, ulong uHeight) 63 : QEvent((QEvent::Type)VBoxDefs::ResizeEventType) 64 , m_uPixelFormat(uPixelFormat), m_pVRAM(pVRAM), m_uBitsPerPixel(uBitsPerPixel) 65 , m_uBytesPerLine(uBytesPerLine), m_uWidth(uWidth), m_uHeight(uHeight) {} 66 ulong pixelFormat() { return m_uPixelFormat; } 67 uchar *VRAM() { return m_pVRAM; } 68 ulong bitsPerPixel() { return m_uBitsPerPixel; } 69 ulong bytesPerLine() { return m_uBytesPerLine; } 70 ulong width() { return m_uWidth; } 71 ulong height() { return m_uHeight; } 72 73 private: 74 75 ulong m_uPixelFormat; 76 uchar *m_pVRAM; 77 ulong m_uBitsPerPixel; 78 ulong m_uBytesPerLine; 79 ulong m_uWidth; 80 ulong m_uHeight; 81 }; 82 83 /** 84 * Frame buffer repaint event. 85 */ 86 class UIRepaintEvent : public QEvent 87 { 88 public: 89 90 UIRepaintEvent(int iX, int iY, int iW, int iH) 91 : QEvent((QEvent::Type)VBoxDefs::RepaintEventType) 92 , m_iX(iX), m_iY(iY), m_iW(iW), m_iH(iH) {} 93 int x() { return m_iX; } 94 int y() { return m_iY; } 95 int width() { return m_iW; } 96 int height() { return m_iH; } 97 98 private: 99 100 int m_iX, m_iY, m_iW, m_iH; 101 }; 102 103 /** 104 * Frame buffer set region event. 105 */ 106 class UISetRegionEvent : public QEvent 107 { 108 public: 109 110 UISetRegionEvent(const QRegion ®ion) 111 : QEvent((QEvent::Type)VBoxDefs::SetRegionEventType) 112 , m_region(region) {} 113 QRegion region() { return m_region; } 114 115 private: 116 117 QRegion m_region; 118 }; 119 120 /** 121 * Common IFramebuffer implementation for all methods used by GUI to maintain 122 * the VM display video memory. 123 * 124 * Note that although this class can be called from multiple threads 125 * (in particular, the GUI thread and EMT) it doesn't protect access to every 126 * data field using its mutex lock. This is because all synchronization between 127 * the GUI and the EMT thread is supposed to be done using the 128 * IFramebuffer::NotifyUpdate() and IFramebuffer::RequestResize() methods 129 * (in particular, the \a aFinished parameter of these methods is responsible 130 * for the synchronization). These methods are always called on EMT and 131 * therefore always follow one another but never in parallel. 132 * 133 * Using this object's mutex lock (exposed also in IFramebuffer::Lock() and 134 * IFramebuffer::Unlock() implementations) usually makes sense only if some 135 * third-party thread (i.e. other than GUI or EMT) needs to make sure that 136 * *no* VM display update or resize event can occur while it is accessing 137 * IFramebuffer properties or the underlying display memory storage area. 138 * 139 * See IFramebuffer documentation for more info. 140 */ 141 class UIFrameBuffer : VBOX_SCRIPTABLE_IMPL(IFramebuffer) 142 { 143 public: 144 145 UIFrameBuffer(UIMachineView *aView); 146 virtual ~UIFrameBuffer(); 147 148 NS_DECL_ISUPPORTS 149 150 #if defined (Q_OS_WIN32) 151 STDMETHOD_(ULONG, AddRef)() 152 { 153 return ::InterlockedIncrement(&m_iRefCnt); 154 } 155 156 STDMETHOD_(ULONG, Release)() 157 { 158 long cnt = ::InterlockedDecrement(&m_iRefCnt); 159 if (cnt == 0) 160 delete this; 161 return cnt; 162 } 163 #endif 164 165 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer) 166 167 /* IFramebuffer COM methods */ 168 STDMETHOD(COMGETTER(Address)) (BYTE **ppAddress); 169 STDMETHOD(COMGETTER(Width)) (ULONG *puWidth); 170 STDMETHOD(COMGETTER(Height)) (ULONG *puHeight); 171 STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *puBitsPerPixel); 172 STDMETHOD(COMGETTER(BytesPerLine)) (ULONG *puBytesPerLine); 173 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *puPixelFormat); 174 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *pbUsesGuestVRAM); 175 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *puHeightReduction); 176 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **ppOverlay); 177 STDMETHOD(COMGETTER(WinId)) (ULONG64 *pWinId); 178 179 STDMETHOD(Lock)(); 180 STDMETHOD(Unlock)(); 181 182 STDMETHOD(RequestResize) (ULONG uScreenId, ULONG uPixelFormat, 183 BYTE *pVRAM, ULONG uBitsPerPixel, ULONG uBytesPerLine, 184 ULONG uWidth, ULONG uHeight, 185 BOOL *pbFinished); 186 187 STDMETHOD(VideoModeSupported) (ULONG uWidth, ULONG uHeight, ULONG uBPP, 188 BOOL *pbSupported); 189 190 STDMETHOD(GetVisibleRegion)(BYTE *pRectangles, ULONG uCount, ULONG *puCountCopied); 191 STDMETHOD(SetVisibleRegion)(BYTE *pRectangles, ULONG uCount); 192 193 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand); 194 195 ulong width() { return m_width; } 196 ulong height() { return m_height; } 197 198 virtual ulong pixelFormat() 199 { 200 return FramebufferPixelFormat_FOURCC_RGB; 201 } 202 203 virtual bool usesGuestVRAM() 204 { 205 return false; 206 } 207 208 void lock() { RTCritSectEnter(&m_critSect); } 209 void unlock() { RTCritSectLeave(&m_critSect); } 210 211 virtual uchar *address() = 0; 212 virtual ulong bitsPerPixel() = 0; 213 virtual ulong bytesPerLine() = 0; 214 215 /** 216 * Called on the GUI thread (from VBoxConsoleView) when some part of the 217 * VM display viewport needs to be repainted on the host screen. 218 */ 219 virtual void paintEvent(QPaintEvent *pEvent) = 0; 220 221 /** 222 * Called on the GUI thread (from VBoxConsoleView) after it gets a 223 * UIResizeEvent posted from the RequestResize() method implementation. 224 */ 225 virtual void resizeEvent(UIResizeEvent *pEvent) 226 { 227 m_width = pEvent->width(); 228 m_height = pEvent->height(); 229 } 230 231 /** 232 * Called on the GUI thread (from VBoxConsoleView) when the VM console 233 * window is moved. 234 */ 235 virtual void moveEvent(QMoveEvent * /* pEvent */) {} 236 237 #ifdef VBOX_WITH_VIDEOHWACCEL 238 /* this method is called from the GUI thread 239 * to perform the actual Video HW Acceleration command processing 240 * the event is framebuffer implementation specific */ 241 virtual void doProcessVHWACommand(QEvent * pEvent); 242 243 virtual void viewportResized(QResizeEvent * /* pEvent */) {} 244 245 virtual void viewportScrolled(int /* iX */, int /* iY */) {} 246 #endif 247 248 protected: 249 250 UIMachineView *m_pMachineView; 251 RTCRITSECT m_critSect; 252 int m_width; 253 int m_height; 254 uint64_t m_uWinId; 255 256 #if defined (Q_OS_WIN32) 257 private: 258 259 long m_iRefCnt; 260 #endif 261 }; 262 263 #if defined (VBOX_GUI_USE_QIMAGE) 264 class UIFrameBufferQImage : public UIFrameBuffer 265 { 266 public: 267 268 UIFrameBufferQImage(UIMachineView *pMachineView); 269 270 STDMETHOD(NotifyUpdate) (ULONG uX, ULONG uY, ULONG uW, ULONG uH); 271 272 ulong pixelFormat() { return m_uPixelFormat; } 273 bool usesGuestVRAM() { return m_bUsesGuestVRAM; } 274 275 uchar *address() { return m_img.bits(); } 276 ulong bitsPerPixel() { return m_img.depth(); } 277 ulong bytesPerLine() { return m_img.bytesPerLine(); } 278 279 void paintEvent (QPaintEvent *pEvent); 280 void resizeEvent (UIResizeEvent *pEvent); 281 282 private: 283 284 QPixmap m_PM; 285 QImage m_img; 286 ulong m_uPixelFormat; 287 bool m_bUsesGuestVRAM; 288 }; 289 #endif 290 38 /* TODO_NEW_CORE */ 291 39 #if 0 292 #if defined (VBOX_GUI_USE_DDRAW)293 40 class UIFrameBufferDDRAW : public UIFrameBuffer 294 41 { … … 339 86 }; 340 87 #endif 341 #endif342 88 343 #endif / / !___UIFrameBuffer_h___89 #endif /* VBOX_GUI_USE_DDRAW */ 344 90 91 #endif /* !___UIFrameBufferDirectDraw_h___ */ 92 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.cpp
r26822 r26823 3 3 * 4 4 * VBox frontends: Qt GUI ("VirtualBox"): 5 * UIFrameBuffer class and subclasses implementation5 * UIFrameBufferQImage class implementation 6 6 */ 7 7 … … 22 22 */ 23 23 24 #ifdef VBOX_GUI_USE_QIMAGE 25 24 26 #ifdef VBOX_WITH_PRECOMPILED_HEADERS 25 27 # include "precomp.h" 26 28 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 29 30 /* Local includes */ 31 # include "UIFrameBufferQImage.h" 32 # include "UIMachineView.h" 33 # include "VBoxProblemReporter.h" 34 # include "VBoxGlobal.h" 35 27 36 /* Global includes */ 28 #include <QPainter> 29 /* Local includes */ 30 #include "UIMachineView.h" 31 #include "UIFrameBuffer.h" 32 #include "VBoxProblemReporter.h" 33 #include "VBoxGlobal.h" 37 # include <QPainter> 38 # include <QApplication> 39 34 40 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 35 41 36 #if defined (Q_OS_WIN32)37 static CComModule _Module;38 #else39 NS_DECL_CLASSINFO (UIFrameBuffer)40 NS_IMPL_THREADSAFE_ISUPPORTS1_CI (UIFrameBuffer, IFramebuffer)41 #endif42 43 UIFrameBuffer::UIFrameBuffer(UIMachineView *pMachineView)44 : m_pMachineView(pMachineView)45 , m_width(0), m_height(0)46 #if defined (Q_OS_WIN32)47 , m_iRefCnt(0)48 #endif49 {50 AssertMsg(m_pMachineView, ("UIMachineView must not be null\n"));51 m_uWinId = (m_pMachineView && m_pMachineView->viewport()) ? (ULONG64)m_pMachineView->viewport()->winId() : 0;52 int rc = RTCritSectInit(&m_critSect);53 AssertRC(rc);54 }55 56 UIFrameBuffer::~UIFrameBuffer()57 {58 RTCritSectDelete(&m_critSect);59 }60 61 STDMETHODIMP UIFrameBuffer::COMGETTER(Address) (BYTE **ppAddress)62 {63 if (!ppAddress)64 return E_POINTER;65 *ppAddress = address();66 return S_OK;67 }68 69 STDMETHODIMP UIFrameBuffer::COMGETTER(Width) (ULONG *puWidth)70 {71 if (!puWidth)72 return E_POINTER;73 *puWidth = (ULONG)width();74 return S_OK;75 }76 77 STDMETHODIMP UIFrameBuffer::COMGETTER(Height) (ULONG *puHeight)78 {79 if (!puHeight)80 return E_POINTER;81 *puHeight = (ULONG)height();82 return S_OK;83 }84 85 STDMETHODIMP UIFrameBuffer::COMGETTER(BitsPerPixel) (ULONG *puBitsPerPixel)86 {87 if (!puBitsPerPixel)88 return E_POINTER;89 *puBitsPerPixel = bitsPerPixel();90 return S_OK;91 }92 93 STDMETHODIMP UIFrameBuffer::COMGETTER(BytesPerLine) (ULONG *puBytesPerLine)94 {95 if (!puBytesPerLine)96 return E_POINTER;97 *puBytesPerLine = bytesPerLine();98 return S_OK;99 }100 101 STDMETHODIMP UIFrameBuffer::COMGETTER(PixelFormat) (ULONG *puPixelFormat)102 {103 if (!puPixelFormat)104 return E_POINTER;105 *puPixelFormat = pixelFormat();106 return S_OK;107 }108 109 STDMETHODIMP UIFrameBuffer::COMGETTER(UsesGuestVRAM) (BOOL *pbUsesGuestVRAM)110 {111 if (!pbUsesGuestVRAM)112 return E_POINTER;113 *pbUsesGuestVRAM = usesGuestVRAM();114 return S_OK;115 }116 117 STDMETHODIMP UIFrameBuffer::COMGETTER(HeightReduction) (ULONG *puHeightReduction)118 {119 if (!puHeightReduction)120 return E_POINTER;121 *puHeightReduction = 0;122 return S_OK;123 }124 125 STDMETHODIMP UIFrameBuffer::COMGETTER(Overlay) (IFramebufferOverlay **ppOverlay)126 {127 if (!ppOverlay)128 return E_POINTER;129 /* not yet implemented */130 *ppOverlay = 0;131 return S_OK;132 }133 134 STDMETHODIMP UIFrameBuffer::COMGETTER(WinId) (ULONG64 *puWinId)135 {136 if (!puWinId)137 return E_POINTER;138 *puWinId = m_uWinId;139 return S_OK;140 }141 142 STDMETHODIMP UIFrameBuffer::Lock()143 {144 this->lock();145 return S_OK;146 }147 148 STDMETHODIMP UIFrameBuffer::Unlock()149 {150 this->unlock();151 return S_OK;152 }153 154 /** @note This method is called on EMT from under this object's lock */155 STDMETHODIMP UIFrameBuffer::RequestResize(ULONG uScreenId, ULONG uPixelFormat,156 BYTE *pVRAM, ULONG uBitsPerPixel, ULONG uBytesPerLine,157 ULONG uWidth, ULONG uHeight,158 BOOL *pbFinished)159 {160 NOREF(uScreenId);161 QApplication::postEvent (m_pMachineView,162 new UIResizeEvent(uPixelFormat, pVRAM, uBitsPerPixel,163 uBytesPerLine, uWidth, uHeight));164 165 *pbFinished = FALSE;166 return S_OK;167 }168 169 /**170 * Returns whether we like the given video mode.171 *172 * @returns COM status code173 * @param width video mode width in pixels174 * @param height video mode height in pixels175 * @param bpp video mode bit depth in bits per pixel176 * @param supported pointer to result variable177 */178 STDMETHODIMP UIFrameBuffer::VideoModeSupported(ULONG uWidth, ULONG uHeight, ULONG uBPP, BOOL *pbSupported)179 {180 NOREF(uBPP);181 LogFlowThisFunc(("width=%lu, height=%lu, BPP=%lu\n",182 (unsigned long)uWidth, (unsigned long)uHeight, (unsigned long)uBPP));183 if (!pbSupported)184 return E_POINTER;185 *pbSupported = TRUE;186 QRect screen = m_pMachineView->desktopGeometry();187 if ((screen.width() != 0) && (uWidth > (ULONG)screen.width()))188 *pbSupported = FALSE;189 if ((screen.height() != 0) && (uHeight > (ULONG)screen.height()))190 *pbSupported = FALSE;191 LogFlowThisFunc(("screenW=%lu, screenH=%lu -> aSupported=%s\n",192 screen.width(), screen.height(), *pbSupported ? "TRUE" : "FALSE"));193 return S_OK;194 }195 196 STDMETHODIMP UIFrameBuffer::GetVisibleRegion(BYTE *pRectangles, ULONG uCount, ULONG *puCountCopied)197 {198 PRTRECT rects = (PRTRECT)pRectangles;199 200 if (!rects)201 return E_POINTER;202 203 NOREF(uCount);204 NOREF(puCountCopied);205 206 return S_OK;207 }208 209 STDMETHODIMP UIFrameBuffer::SetVisibleRegion(BYTE *pRectangles, ULONG uCount)210 {211 PRTRECT rects = (PRTRECT)pRectangles;212 213 if (!rects)214 return E_POINTER;215 216 QRegion reg;217 for (ULONG ind = 0; ind < uCount; ++ ind)218 {219 QRect rect;220 rect.setLeft(rects->xLeft);221 rect.setTop(rects->yTop);222 /* QRect are inclusive */223 rect.setRight(rects->xRight - 1);224 rect.setBottom(rects->yBottom - 1);225 reg += rect;226 ++ rects;227 }228 QApplication::postEvent(m_pMachineView, new UISetRegionEvent(reg));229 230 return S_OK;231 }232 233 STDMETHODIMP UIFrameBuffer::ProcessVHWACommand(BYTE *pCommand)234 {235 Q_UNUSED(pCommand);236 return E_NOTIMPL;237 }238 239 #ifdef VBOX_WITH_VIDEOHWACCEL240 void UIFrameBuffer::doProcessVHWACommand(QEvent *pEvent)241 {242 Q_UNUSED(pEvent);243 /* should never be here */244 AssertBreakpoint();245 }246 #endif247 248 #ifdef VBOX_GUI_USE_QIMAGE249 42 /** @class UIFrameBufferQImage 250 43 * … … 395 188 } 396 189 } 190 397 191 #endif /* VBOX_GUI_USE_QIMAGE */ 398 192 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.h
r26822 r26823 2 2 * 3 3 * VBox frontends: Qt GUI ("VirtualBox"): 4 * UIFrameBuffer class and subclasses declarations4 * UIFrameBufferQImage class declarations 5 5 */ 6 6 … … 21 21 */ 22 22 23 #ifndef ___UIFrameBuffer_h___ 24 #define ___UIFrameBuffer_h___ 23 #ifndef ___UIFrameBufferQImage_h___ 24 #define ___UIFrameBufferQImage_h___ 25 26 #ifdef VBOX_GUI_USE_QIMAGE 27 28 /* Local includes */ 29 #include "UIFrameBuffer.h" 25 30 26 31 /* Global includes */ 27 //#include <QImage>32 #include <QImage> 28 33 #include <QPixmap> 29 //#include <QMutex>30 #include <QPaintEvent>31 //#include <QMoveEvent>32 34 33 /* Local includes */34 #include "COMDefs.h"35 #include <iprt/critsect.h>36 37 //#if defined (VBOX_GUI_USE_SDL)38 //#include <SDL.h>39 //#include <signal.h>40 //#endif41 42 //#if defined (Q_WS_WIN) && defined (VBOX_GUI_USE_DDRAW)43 // VBox/cdefs.h defines these:44 //#undef LOWORD45 //#undef HIWORD46 //#undef LOBYTE47 //#undef HIBYTE48 //#include <ddraw.h>49 //#endif50 51 class UIMachineView;52 53 /**54 * Frame buffer resize event.55 */56 class UIResizeEvent : public QEvent57 {58 public:59 60 UIResizeEvent(ulong uPixelFormat, uchar *pVRAM,61 ulong uBitsPerPixel, ulong uBytesPerLine,62 ulong uWidth, ulong uHeight)63 : QEvent((QEvent::Type)VBoxDefs::ResizeEventType)64 , m_uPixelFormat(uPixelFormat), m_pVRAM(pVRAM), m_uBitsPerPixel(uBitsPerPixel)65 , m_uBytesPerLine(uBytesPerLine), m_uWidth(uWidth), m_uHeight(uHeight) {}66 ulong pixelFormat() { return m_uPixelFormat; }67 uchar *VRAM() { return m_pVRAM; }68 ulong bitsPerPixel() { return m_uBitsPerPixel; }69 ulong bytesPerLine() { return m_uBytesPerLine; }70 ulong width() { return m_uWidth; }71 ulong height() { return m_uHeight; }72 73 private:74 75 ulong m_uPixelFormat;76 uchar *m_pVRAM;77 ulong m_uBitsPerPixel;78 ulong m_uBytesPerLine;79 ulong m_uWidth;80 ulong m_uHeight;81 };82 83 /**84 * Frame buffer repaint event.85 */86 class UIRepaintEvent : public QEvent87 {88 public:89 90 UIRepaintEvent(int iX, int iY, int iW, int iH)91 : QEvent((QEvent::Type)VBoxDefs::RepaintEventType)92 , m_iX(iX), m_iY(iY), m_iW(iW), m_iH(iH) {}93 int x() { return m_iX; }94 int y() { return m_iY; }95 int width() { return m_iW; }96 int height() { return m_iH; }97 98 private:99 100 int m_iX, m_iY, m_iW, m_iH;101 };102 103 /**104 * Frame buffer set region event.105 */106 class UISetRegionEvent : public QEvent107 {108 public:109 110 UISetRegionEvent(const QRegion ®ion)111 : QEvent((QEvent::Type)VBoxDefs::SetRegionEventType)112 , m_region(region) {}113 QRegion region() { return m_region; }114 115 private:116 117 QRegion m_region;118 };119 120 /**121 * Common IFramebuffer implementation for all methods used by GUI to maintain122 * the VM display video memory.123 *124 * Note that although this class can be called from multiple threads125 * (in particular, the GUI thread and EMT) it doesn't protect access to every126 * data field using its mutex lock. This is because all synchronization between127 * the GUI and the EMT thread is supposed to be done using the128 * IFramebuffer::NotifyUpdate() and IFramebuffer::RequestResize() methods129 * (in particular, the \a aFinished parameter of these methods is responsible130 * for the synchronization). These methods are always called on EMT and131 * therefore always follow one another but never in parallel.132 *133 * Using this object's mutex lock (exposed also in IFramebuffer::Lock() and134 * IFramebuffer::Unlock() implementations) usually makes sense only if some135 * third-party thread (i.e. other than GUI or EMT) needs to make sure that136 * *no* VM display update or resize event can occur while it is accessing137 * IFramebuffer properties or the underlying display memory storage area.138 *139 * See IFramebuffer documentation for more info.140 */141 class UIFrameBuffer : VBOX_SCRIPTABLE_IMPL(IFramebuffer)142 {143 public:144 145 UIFrameBuffer(UIMachineView *aView);146 virtual ~UIFrameBuffer();147 148 NS_DECL_ISUPPORTS149 150 #if defined (Q_OS_WIN32)151 STDMETHOD_(ULONG, AddRef)()152 {153 return ::InterlockedIncrement(&m_iRefCnt);154 }155 156 STDMETHOD_(ULONG, Release)()157 {158 long cnt = ::InterlockedDecrement(&m_iRefCnt);159 if (cnt == 0)160 delete this;161 return cnt;162 }163 #endif164 165 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)166 167 /* IFramebuffer COM methods */168 STDMETHOD(COMGETTER(Address)) (BYTE **ppAddress);169 STDMETHOD(COMGETTER(Width)) (ULONG *puWidth);170 STDMETHOD(COMGETTER(Height)) (ULONG *puHeight);171 STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *puBitsPerPixel);172 STDMETHOD(COMGETTER(BytesPerLine)) (ULONG *puBytesPerLine);173 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *puPixelFormat);174 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *pbUsesGuestVRAM);175 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *puHeightReduction);176 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **ppOverlay);177 STDMETHOD(COMGETTER(WinId)) (ULONG64 *pWinId);178 179 STDMETHOD(Lock)();180 STDMETHOD(Unlock)();181 182 STDMETHOD(RequestResize) (ULONG uScreenId, ULONG uPixelFormat,183 BYTE *pVRAM, ULONG uBitsPerPixel, ULONG uBytesPerLine,184 ULONG uWidth, ULONG uHeight,185 BOOL *pbFinished);186 187 STDMETHOD(VideoModeSupported) (ULONG uWidth, ULONG uHeight, ULONG uBPP,188 BOOL *pbSupported);189 190 STDMETHOD(GetVisibleRegion)(BYTE *pRectangles, ULONG uCount, ULONG *puCountCopied);191 STDMETHOD(SetVisibleRegion)(BYTE *pRectangles, ULONG uCount);192 193 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);194 195 ulong width() { return m_width; }196 ulong height() { return m_height; }197 198 virtual ulong pixelFormat()199 {200 return FramebufferPixelFormat_FOURCC_RGB;201 }202 203 virtual bool usesGuestVRAM()204 {205 return false;206 }207 208 void lock() { RTCritSectEnter(&m_critSect); }209 void unlock() { RTCritSectLeave(&m_critSect); }210 211 virtual uchar *address() = 0;212 virtual ulong bitsPerPixel() = 0;213 virtual ulong bytesPerLine() = 0;214 215 /**216 * Called on the GUI thread (from VBoxConsoleView) when some part of the217 * VM display viewport needs to be repainted on the host screen.218 */219 virtual void paintEvent(QPaintEvent *pEvent) = 0;220 221 /**222 * Called on the GUI thread (from VBoxConsoleView) after it gets a223 * UIResizeEvent posted from the RequestResize() method implementation.224 */225 virtual void resizeEvent(UIResizeEvent *pEvent)226 {227 m_width = pEvent->width();228 m_height = pEvent->height();229 }230 231 /**232 * Called on the GUI thread (from VBoxConsoleView) when the VM console233 * window is moved.234 */235 virtual void moveEvent(QMoveEvent * /* pEvent */) {}236 237 #ifdef VBOX_WITH_VIDEOHWACCEL238 /* this method is called from the GUI thread239 * to perform the actual Video HW Acceleration command processing240 * the event is framebuffer implementation specific */241 virtual void doProcessVHWACommand(QEvent * pEvent);242 243 virtual void viewportResized(QResizeEvent * /* pEvent */) {}244 245 virtual void viewportScrolled(int /* iX */, int /* iY */) {}246 #endif247 248 protected:249 250 UIMachineView *m_pMachineView;251 RTCRITSECT m_critSect;252 int m_width;253 int m_height;254 uint64_t m_uWinId;255 256 #if defined (Q_OS_WIN32)257 private:258 259 long m_iRefCnt;260 #endif261 };262 263 #if defined (VBOX_GUI_USE_QIMAGE)264 35 class UIFrameBufferQImage : public UIFrameBuffer 265 36 { … … 277 48 ulong bytesPerLine() { return m_img.bytesPerLine(); } 278 49 279 void paintEvent 280 void resizeEvent 50 void paintEvent(QPaintEvent *pEvent); 51 void resizeEvent(UIResizeEvent *pEvent); 281 52 282 53 private: … … 287 58 bool m_bUsesGuestVRAM; 288 59 }; 289 #endif290 60 291 #if 0 292 #if defined (VBOX_GUI_USE_DDRAW) 293 class UIFrameBufferDDRAW : public UIFrameBuffer 294 { 295 public: 61 #endif /* VBOX_GUI_USE_QIMAGE */ 296 62 297 UIFrameBufferDDRAW(UIMachineView *pMachineView); 298 virtual ~UIFrameBufferDDRAW(); 63 #endif /* !___UIFrameBufferQImage_h___ */ 299 64 300 STDMETHOD(NotifyUpdate) (ULONG uX, ULONG uY, ULONG uW, ULONG uH);301 302 uchar* address() { return (uchar*) m_surfaceDesc.lpSurface; }303 ulong bitsPerPixel() { return m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount; }304 ulong bytesPerLine() { return (ulong) m_surfaceDesc.lPitch; }305 306 ulong pixelFormat() { return m_uPixelFormat; };307 308 bool usesGuestVRAM() { return m_bUsesGuestVRAM; }309 310 void paintEvent(QPaintEvent *pEvent);311 void resizeEvent(UIResizeEvent *pEvent);312 void moveEvent(QMoveEvent *pEvent);313 314 private:315 316 void releaseObjects();317 318 bool createSurface(ULONG uPixelFormat, uchar *pvVRAM,319 ULONG uBitsPerPixel, ULONG uBytesPerLine,320 ULONG uWidth, ULONG uHeight);321 void deleteSurface();322 void drawRect(ULONG uX, ULONG uY, ULONG uW, ULONG uH);323 void getWindowPosition(void);324 325 LPDIRECTDRAW7 m_DDRAW;326 LPDIRECTDRAWCLIPPER m_clipper;327 LPDIRECTDRAWSURFACE7 m_surface;328 DDSURFACEDESC2 m_surfaceDesc;329 LPDIRECTDRAWSURFACE7 m_primarySurface;330 331 ulong m_uPixelFormat;332 333 bool m_bUsesGuestVRAM;334 335 int m_iWndX;336 int m_iWndY;337 338 bool m_bSynchronousUpdates;339 };340 #endif341 #endif342 343 #endif // !___UIFrameBuffer_h___344 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
r26822 r26823 34 34 #include "UIFrameBuffer.h" 35 35 #include "UIFrameBufferQGL.h" 36 #include "UIFrameBufferQImage.h" 36 37 #include "UIFrameBufferQuartz2D.h" 37 38 #include "UIFrameBufferSDL.h"
Note:
See TracChangeset
for help on using the changeset viewer.