Git commit 2eed0606c94eef37196c227c100b200182efd9e8 by Arjen Hiemstra. Committed on 31/08/2014 at 22:00. Pushed by ahiemstra into branch 'master'. graphics: Fix resizing of RenderWindow Stupid Qt bugs... M +32 -11 graphics/renderwindow.cpp M +1 -0 graphics/renderwindow.h http://commits.kde.org/gluon/2eed0606c94eef37196c227c100b200182efd9e8 diff --git a/graphics/renderwindow.cpp b/graphics/renderwindow.cpp index eb9c9b6..7178cd7 100644 --- a/graphics/renderwindow.cpp +++ b/graphics/renderwindow.cpp @@ -21,6 +21,7 @@ = #include #include +#include = #include "manager.h" #include "outputsurface.h" @@ -34,11 +35,17 @@ class RenderWindow::Private { public: OutputSurface* surface =3D nullptr; + QBackingStore* store =3D nullptr; }; = RenderWindow::RenderWindow( QWindow* parent ) : QWindow( parent ) { - setSurfaceType( QSurface::OpenGLSurface ); + setSurfaceType( QSurface::RasterSurface ); + + //This is used to indirectly call some platform methods to handle resi= zing. + d->store =3D new QBackingStore{ this }; + + resize( 640, 480 ); = if( !Manager::instance()->backend()->initialize( winId() ) ) qFatal( Manager::instance()->backend()->errorString().toUtf8() ); @@ -56,6 +63,28 @@ OutputSurface* RenderWindow::outputSurface() const = void RenderWindow::exposeEvent( QExposeEvent* event ) { + Q_UNUSED( event ) + render(); +} + +void RenderWindow::resizeEvent( QResizeEvent* event ) +{ + if( d->surface ) + d->surface->setSize( event->size().width(), event->size().height()= ); + + //QWindow fails to properly resize if certain platform methods are not= called. + //However, those methods are not publicly available thus we need to use + //QBackingStore to indirectly call them. Rather than having a backing = store that + //takes as much memory as the window size, we can use a 1x1 backing st= ore since + //it just needs a non-zero size. In addition, the small size prevent f= lickering + //as it means the window doesn't get completely redrawn twice. + d->store->resize( QSize{ 1, 1 } ); + d->store->flush( QRect{ 0, 0, 1, 1 } ); + render(); +} + +void RenderWindow::render() +{ if( !isExposed() ) return; = @@ -66,20 +95,12 @@ void RenderWindow::exposeEvent( QExposeEvent* event ) d->surface->setSize( width(), height() ); } = - requestActivate(); d->surface->renderContents(); } = -void RenderWindow::resizeEvent( QResizeEvent* event ) -{ - if( d->surface ) - d->surface->setSize( event->size().width(), event->size().height()= ); - - QWindow::resizeEvent( event ); -} - void RenderWindow::update() { QExposeEvent* ev =3D new QExposeEvent( geometry() ); - QCoreApplication::sendEvent( this, ev ); + QCoreApplication::postEvent( this, ev ); + } diff --git a/graphics/renderwindow.h b/graphics/renderwindow.h index 7223be7..b68f9fc 100644 --- a/graphics/renderwindow.h +++ b/graphics/renderwindow.h @@ -50,6 +50,7 @@ namespace GluonGraphics virtual void resizeEvent( QResizeEvent* event ) override; = public Q_SLOTS: + virtual void render(); virtual void update(); = GLUON_PRIVATE_POINTER;