void UIMachineViewScale::prepareFrameBuffer() { /* That method is partial copy-paste of UIMachineView::prepareFrameBuffer() * and its temporary here just because not all of our frame-buffers are currently supports scale-mode; * When all of our frame-buffers will be supporting scale-mode, method will be removed! * Here we are processing only these frame-buffer types, which knows scale-mode! */ /* Prepare frame-buffer depending on render-mode: */ switch (vboxGlobal().vmRenderMode()) { #ifdef VBOX_GUI_USE_QUARTZ2D case VBoxDefs::Quartz2DMode: /* Indicate that we are doing all drawing stuff ourself: */ viewport()->setAttribute(Qt::WA_PaintOnScreen); m_pFrameBuffer = new UIFrameBufferQuartz2D(this); break; #endif /* VBOX_GUI_USE_QUARTZ2D */ default: #ifdef VBOX_GUI_USE_QIMAGE case VBoxDefs::QImageMode: m_pFrameBuffer = new UIFrameBufferQImage(this); break; #endif /* VBOX_GUI_USE_QIMAGE */ AssertReleaseMsgFailed(("Scale-mode is currently NOT supporting that render-mode: %d\n", vboxGlobal().vmRenderMode())); LogRel(("Scale-mode is currently NOT supporting that render-mode: %d\n", vboxGlobal().vmRenderMode())); qApp->exit(1); break; } /* If frame-buffer was prepared: */ if (m_pFrameBuffer) { /* Prepare display: */ CDisplay display = session().GetConsole().GetDisplay(); Assert(!display.isNull()); m_pFrameBuffer->AddRef(); display.SetFramebuffer(m_uScreenId, CFramebuffer(m_pFrameBuffer)); } QSize size; #ifdef Q_WS_X11 /* Processing pseudo resize-event to synchronize frame-buffer with stored * framebuffer size. On X11 this will be additional done when the machine * state was 'saved'. */ if (session().GetMachine().GetState() == KMachineState_Saved) size = guestSizeHint(); #endif /* Q_WS_X11 */ /* If there is a preview image saved, we will resize the framebuffer to the * size of that image. */ ULONG buffer = 0, width = 0, height = 0; CMachine machine = session().GetMachine(); machine.QuerySavedScreenshotPNGSize(0, buffer, width, height); if (buffer > 0) { /* Init with the screenshot size */ size = QSize(width, height); /* Try to get the real guest dimensions from the save state */ ULONG guestWidth = 0, guestHeight = 0; machine.QuerySavedGuestSize(0, guestWidth, guestHeight); if ( guestWidth > 0 && guestHeight > 0) size = QSize(guestWidth, guestHeight); } /* If we have a valid size, resize the framebuffer. */ if ( size.width() > 0 && size.height() > 0) { UIResizeEvent event(FramebufferPixelFormat_Opaque, NULL, 0, 0, size.width(), size.height()); frameBuffer()->resizeEvent(&event); } }
void UIMachineView::prepareFrameBuffer() { /* Prepare frame-buffer depending on render-mode: */ switch (vboxGlobal().vmRenderMode()) { #ifdef VBOX_GUI_USE_QIMAGE case VBoxDefs::QImageMode: # ifdef VBOX_WITH_VIDEOHWACCEL if (m_fAccelerate2DVideo) { UIFrameBuffer* pFramebuffer = uisession()->frameBuffer(screenId()); if (pFramebuffer) pFramebuffer->setView(this); else { /* these two additional template args is a workaround to this [VBox|UI] duplication * @todo: they are to be removed once VBox stuff is gone */ pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQImage, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session(), (uint32_t)screenId()); uisession()->setFrameBuffer(screenId(), pFramebuffer); } m_pFrameBuffer = pFramebuffer; } else m_pFrameBuffer = new UIFrameBufferQImage(this); # else /* VBOX_WITH_VIDEOHWACCEL */ m_pFrameBuffer = new UIFrameBufferQImage(this); # endif /* !VBOX_WITH_VIDEOHWACCEL */ break; #endif /* VBOX_GUI_USE_QIMAGE */ #ifdef VBOX_GUI_USE_QGLFB case VBoxDefs::QGLMode: m_pFrameBuffer = new UIFrameBufferQGL(this); break; // case VBoxDefs::QGLOverlayMode: // m_pFrameBuffer = new UIQGLOverlayFrameBuffer(this); // break; #endif /* VBOX_GUI_USE_QGLFB */ #ifdef VBOX_GUI_USE_SDL case VBoxDefs::SDLMode: /* Indicate that we are doing all drawing stuff ourself: */ // TODO_NEW_CORE viewport()->setAttribute(Qt::WA_PaintOnScreen); # ifdef Q_WS_X11 /* This is somehow necessary to prevent strange X11 warnings on i386 and segfaults on x86_64: */ XFlush(QX11Info::display()); # endif /* Q_WS_X11 */ # if defined(VBOX_WITH_VIDEOHWACCEL) && defined(DEBUG_misha) /* not tested yet */ if (m_fAccelerate2DVideo) { class UIFrameBuffer* pFramebuffer = uisession()->frameBuffer(screenId()); if (pFramebuffer) pFramebuffer->setView(this); else { /* these two additional template args is a workaround to this [VBox|UI] duplication * @todo: they are to be removed once VBox stuff is gone */ pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferSDL, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session(), (uint32_t)screenId()); uisession()->setFrameBuffer(screenId(), pFramebuffer); } m_pFrameBuffer = pFramebuffer; } else m_pFrameBuffer = new UIFrameBufferSDL(this); # else m_pFrameBuffer = new UIFrameBufferSDL(this); # endif /* Disable scrollbars because we cannot correctly draw in a scrolled window using SDL: */ horizontalScrollBar()->setEnabled(false); verticalScrollBar()->setEnabled(false); break; #endif /* VBOX_GUI_USE_SDL */ #if 0 // TODO: Enable DDraw frame buffer! #ifdef VBOX_GUI_USE_DDRAW case VBoxDefs::DDRAWMode: m_pFrameBuffer = new UIDDRAWFrameBuffer(this); if (!m_pFrameBuffer || m_pFrameBuffer->address() == NULL) { if (m_pFrameBuffer) delete m_pFrameBuffer; m_mode = VBoxDefs::QImageMode; m_pFrameBuffer = new UIFrameBufferQImage(this); } break; #endif /* VBOX_GUI_USE_DDRAW */ #endif #ifdef VBOX_GUI_USE_QUARTZ2D case VBoxDefs::Quartz2DMode: /* Indicate that we are doing all drawing stuff ourself: */ viewport()->setAttribute(Qt::WA_PaintOnScreen); # ifdef VBOX_WITH_VIDEOHWACCEL if (m_fAccelerate2DVideo) { UIFrameBuffer* pFramebuffer = uisession()->frameBuffer(screenId()); if (pFramebuffer) pFramebuffer->setView(this); else { /* these two additional template args is a workaround to this [VBox|UI] duplication * @todo: they are to be removed once VBox stuff is gone */ pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQuartz2D, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session(), (uint32_t)screenId()); uisession()->setFrameBuffer(screenId(), pFramebuffer); } m_pFrameBuffer = pFramebuffer; } else m_pFrameBuffer = new UIFrameBufferQuartz2D(this); # else /* VBOX_WITH_VIDEOHWACCEL */ m_pFrameBuffer = new UIFrameBufferQuartz2D(this); # endif /* !VBOX_WITH_VIDEOHWACCEL */ break; #endif /* VBOX_GUI_USE_QUARTZ2D */ default: AssertReleaseMsgFailed(("Render mode must be valid: %d\n", vboxGlobal().vmRenderMode())); LogRel(("Invalid render mode: %d\n", vboxGlobal().vmRenderMode())); qApp->exit(1); break; } /* If frame-buffer was prepared: */ if (m_pFrameBuffer) { /* Prepare display: */ CDisplay display = session().GetConsole().GetDisplay(); Assert(!display.isNull()); #ifdef VBOX_WITH_VIDEOHWACCEL CFramebuffer fb(NULL); if (m_fAccelerate2DVideo) { LONG XOrigin, YOrigin; /* Check if the framebuffer is already assigned; * in this case we do not need to re-assign it neither do we need to AddRef. */ display.GetFramebuffer(m_uScreenId, fb, XOrigin, YOrigin); } if (fb.raw() != m_pFrameBuffer) /* <-this will evaluate to true iff m_fAccelerate2DVideo is disabled or iff no framebuffer is yet assigned */ #endif /* VBOX_WITH_VIDEOHWACCEL */ { m_pFrameBuffer->AddRef(); } /* Always perform SetFramebuffer to ensure 3D gets notified: */ display.SetFramebuffer(m_uScreenId, CFramebuffer(m_pFrameBuffer)); } QSize size; #ifdef Q_WS_X11 /* Processing pseudo resize-event to synchronize frame-buffer with stored * framebuffer size. On X11 this will be additional done when the machine * state was 'saved'. */ if (session().GetMachine().GetState() == KMachineState_Saved) size = guestSizeHint(); #endif /* Q_WS_X11 */ /* If there is a preview image saved, we will resize the framebuffer to the * size of that image. */ ULONG buffer = 0, width = 0, height = 0; CMachine machine = session().GetMachine(); machine.QuerySavedScreenshotPNGSize(0, buffer, width, height); if (buffer > 0) { /* Init with the screenshot size */ size = QSize(width, height); /* Try to get the real guest dimensions from the save state */ ULONG guestWidth = 0, guestHeight = 0; machine.QuerySavedGuestSize(0, guestWidth, guestHeight); if ( guestWidth > 0 && guestHeight > 0) size = QSize(guestWidth, guestHeight); } /* If we have a valid size, resize the framebuffer. */ if ( size.width() > 0 && size.height() > 0) { UIResizeEvent event(FramebufferPixelFormat_Opaque, NULL, 0, 0, size.width(), size.height()); frameBuffer()->resizeEvent(&event); } }