[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [gluon] graphics: graphics: Fix resizing of RenderWindow
From: Arjen Hiemstra <ahiemstra () heimr ! nl>
Date: 2014-08-31 22:01:21
Message-ID: E1XODBZ-0003xU-K1 () scm ! kde ! org
[Download RAW message or body]
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 <QtCore/QCoreApplication>
#include <QtGui/QResizeEvent>
+#include <QtGui/QBackingStore>
#include "manager.h"
#include "outputsurface.h"
@@ -34,11 +35,17 @@ class RenderWindow::Private
{
public:
OutputSurface* surface = nullptr;
+ QBackingStore* store = nullptr;
};
RenderWindow::RenderWindow( QWindow* parent ) : QWindow( parent )
{
- setSurfaceType( QSurface::OpenGLSurface );
+ setSurfaceType( QSurface::RasterSurface );
+
+ //This is used to indirectly call some platform methods to handle resizing.
+ d->store = 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 store since
+ //it just needs a non-zero size. In addition, the small size prevent flickering
+ //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 = 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;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic