From f1675d601f9a85df48bb3a2d2d295ad5b887dff5 Mon Sep 17 00:00:00 2001
From: Alessandro Pignotti <a.pignotti@sssup.it>
Date: Tue, 12 Jun 2012 20:21:47 +0200
Subject: [PATCH] [graphics] Fix handling of resizing
---
src/backends/rendering.cpp | 16 ++++++++++++++--
src/backends/rendering.h | 8 ++++----
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/backends/rendering.cpp b/src/backends/rendering.cpp
index 9f5a5e9..a702675 100644
--- a/src/backends/rendering.cpp
+++ b/src/backends/rendering.cpp
@@ -339,11 +339,13 @@ void RenderThread::worker()
if(resizeNeeded)
{
+ //Order of the operations here matters for requestResize
windowWidth=newWidth;
windowHeight=newHeight;
+ resizeNeeded=false;
newWidth=0;
newHeight=0;
- resizeNeeded=false;
+ //End of order critical part
LOG(LOG_INFO,_("Window resized to ") << windowWidth << 'x' << windowHeight);
commonGLResize();
m_sys->resizeCompleted();
@@ -709,8 +711,18 @@ void RenderThread::commonGLResize()
void RenderThread::requestResize(uint32_t w, uint32_t h, bool force)
{
- if(!force && windowWidth==w && windowHeight==h)
+ //We can skip the resize if the current size is correct
+ //and there is no pending resize or if there is already a
+ //pending resize with the correct size
+
+ //This test is correct only if the order of operation where
+ //the resize is handled does not change!
+ if(!force &&
+ ((windowWidth==w && windowHeight==h && resizeNeeded==false) ||
+ (newWidth==w && newHeight==h)))
+ {
return;
+ }
newWidth=w;
newHeight=h;
resizeNeeded=true;
diff --git a/src/backends/rendering.h b/src/backends/rendering.h
index 778b5e3..ab96bd8 100644
--- a/src/backends/rendering.h
+++ b/src/backends/rendering.h
@@ -67,8 +67,8 @@ class RenderThread: public ITickJob, public GLRenderContext
void handleUpload();
Semaphore event;
std::string fontPath;
- uint32_t newWidth;
- uint32_t newHeight;
+ volatile uint32_t newWidth;
+ volatile uint32_t newHeight;
float scaleX;
float scaleY;
int offsetX;
@@ -157,8 +157,8 @@ class RenderThread: public ITickJob, public GLRenderContext
//OpenGL programs
int gpu_program;
TextureBuffer tempTex;
- uint32_t windowWidth;
- uint32_t windowHeight;
+ volatile uint32_t windowWidth;
+ volatile uint32_t windowHeight;
bool hasNPOTTextures;
GLint fragmentTexScaleUniform;
GLint directUniform;
--
1.7.10