From 7154c1ce8da695520c412ee01ff37f9f892e30f7 Mon Sep 17 00:00:00 2001 From: Nicolas Capens Date: Wed, 30 Dec 2015 11:42:43 -0500 Subject: [PATCH] Eliminate duplicate window size query code. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ibe95427c6b626c308dff41996f636a7dc88f792c Reviewed-on: https://swiftshader-review.googlesource.com/4444 Tested-by: Nicolas Capens Reviewed-by: Alexis Hétu Reviewed-by: Nicolas Capens --- src/OpenGL/libEGL/Display.cpp | 10 ++----- src/OpenGL/libEGL/Surface.cpp | 66 ++++++++++++------------------------------- 2 files changed, 21 insertions(+), 55 deletions(-) diff --git a/src/OpenGL/libEGL/Display.cpp b/src/OpenGL/libEGL/Display.cpp index 3b2dbbc42..88dcb8283 100644 --- a/src/OpenGL/libEGL/Display.cpp +++ b/src/OpenGL/libEGL/Display.cpp @@ -21,18 +21,14 @@ #include "common/debug.h" #include "Common/MutexLock.hpp" -#if defined(__unix__) && !defined(__ANDROID__) -#include "Main/libX11.hpp" -#endif - #ifdef __ANDROID__ #include #include #include #include -#endif - -#if defined(__APPLE__) +#elif defined(__unix__) +#include "Main/libX11.hpp" +#elif defined(__APPLE__) #include "OSXUtils.hpp" #endif diff --git a/src/OpenGL/libEGL/Surface.cpp b/src/OpenGL/libEGL/Surface.cpp index 48a28e290..db189b2d0 100644 --- a/src/OpenGL/libEGL/Surface.cpp +++ b/src/OpenGL/libEGL/Surface.cpp @@ -25,13 +25,9 @@ #if defined(__unix__) && !defined(__ANDROID__) #include "Main/libX11.hpp" -#endif - -#if defined(_WIN32) +#elif defined(_WIN32) #include -#endif - -#if defined(__APPLE__) +#elif defined(__APPLE__) #include "OSXUtils.hpp" #endif @@ -238,30 +234,7 @@ bool WindowSurface::initialize() { ASSERT(!frameBuffer && !backBuffer && !depthStencil); - #if defined(_WIN32) - RECT windowRect; - GetClientRect(window, &windowRect); - - return reset(windowRect.right - windowRect.left, windowRect.bottom - windowRect.top); - #elif defined(__ANDROID__) - int width; window->query(window, NATIVE_WINDOW_WIDTH, &width); - int height; window->query(window, NATIVE_WINDOW_HEIGHT, &height); - - return reset(width, height); - #elif defined(__linux__) - XWindowAttributes windowAttributes; - libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes); - - return reset(windowAttributes.width, windowAttributes.height); - #elif defined(__APPLE__) - int width; - int height; - sw::OSX::GetNativeWindowSize(window, width, height); - - return reset(width, height); - #else - #error "WindowSurface::initialize unimplemented for this platform" - #endif + return checkForResize(); } void WindowSurface::swap() @@ -291,41 +264,38 @@ bool WindowSurface::checkForResize() return false; } - int clientWidth = client.right - client.left; - int clientHeight = client.bottom - client.top; + int windowWidth = client.right - client.left; + int windowHeight = client.bottom - client.top; #elif defined(__ANDROID__) - int clientWidth; window->query(window, NATIVE_WINDOW_WIDTH, &clientWidth); - int clientHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &clientHeight); + int windowWidth; window->query(window, NATIVE_WINDOW_WIDTH, &windowWidth); + int windowHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &windowHeight); #elif defined(__linux__) XWindowAttributes windowAttributes; libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes); - int clientWidth = windowAttributes.width; - int clientHeight = windowAttributes.height; + int windowWidth = windowAttributes.width; + int windowHeight = windowAttributes.height; #elif defined(__APPLE__) - int clientWidth; - int clientHeight; - sw::OSX::GetNativeWindowSize(window, clientWidth, clientHeight); - return true; + int windowWidth; + int windowHeight; + sw::OSX::GetNativeWindowSize(window, windowWidth, windowHeight); #else #error "WindowSurface::checkForResize unimplemented for this platform" #endif - bool sizeDirty = (clientWidth != width) || (clientHeight != height); - - if(sizeDirty) + if((windowWidth != width) || (windowHeight != height)) { - reset(clientWidth, clientHeight); + bool success = reset(windowWidth, windowHeight); - if(static_cast(getCurrentDrawSurface()) == this) + if(getCurrentDrawSurface() == this) { - static_cast(getCurrentContext())->makeCurrent(this); + getCurrentContext()->makeCurrent(this); } - return true; + return success; } - return false; + return true; // Success } void WindowSurface::deleteResources() -- 2.11.0