From 3398288bd00614dd16fa427e524ecfc8e6aeec73 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Fri, 1 Jan 2016 12:50:38 +0100 Subject: [PATCH] Some cleanup around input_state --- Core/Core.cpp | 4 ---- Windows/EmuThread.cpp | 4 ++++ Windows/GPU/D3D9Context.cpp | 21 +++------------------ Windows/GPU/D3D9Context.h | 18 ++++++++++++++++++ Windows/GPU/WindowsGLContext.cpp | 10 ---------- Windows/GPU/WindowsGLContext.h | 11 +++++++++++ android/jni/app-android.cpp | 7 ++++--- headless/Headless.cpp | 2 -- unittest/UnitTest.cpp | 8 ++++++-- 9 files changed, 46 insertions(+), 39 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 2287406e07..356f105262 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -56,11 +56,7 @@ static double lastActivity = 0.0; static double lastKeepAwake = 0.0; static GraphicsContext *graphicsContext; -#ifdef _WIN32 -InputState input_state; -#else extern InputState input_state; -#endif void Core_NotifyWindowHidden(bool hidden) { windowHidden = hidden; diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 40f32028b2..4bac1facf4 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -4,7 +4,9 @@ #include "base/NativeApp.h" #include "base/mutex.h" #include "i18n/i18n.h" +#include "input/input_state.h" #include "util/text/utf8.h" + #include "Common/Log.h" #include "Common/StringUtils.h" #include "../Globals.h" @@ -29,6 +31,8 @@ static recursive_mutex emuThreadLock; static HANDLE emuThread; static volatile long emuThreadReady; +InputState input_state; + extern std::vector GetWideCmdLine(); enum EmuThreadStatus : long diff --git a/Windows/GPU/D3D9Context.cpp b/Windows/GPU/D3D9Context.cpp index 78c8ac7bad..9866cd4b7d 100644 --- a/Windows/GPU/D3D9Context.cpp +++ b/Windows/GPU/D3D9Context.cpp @@ -1,6 +1,5 @@ #include "Common/CommonWindows.h" #include -#include #include "GPU/Directx9/helper/global.h" #include "GPU/Directx9/helper/dx_fbo.h" @@ -16,20 +15,6 @@ #include "thin3d/thin3d.h" #include "thin3d/d3dx9_loader.h" -// TODO: Move these into the context class. -static bool has9Ex = false; -static LPDIRECT3D9 d3d; -static LPDIRECT3D9EX d3dEx; -static int adapterId; -static LPDIRECT3DDEVICE9 device; -static LPDIRECT3DDEVICE9EX deviceEx; -static HDC hDC; // Private GDI Device Context -static HGLRC hRC; // Permanent Rendering Context -static HWND hWnd; // Holds Our Window Handle -static D3DPRESENT_PARAMETERS pp; -static HMODULE hD3D9; - - void D3D9Context::SwapBuffers() { if (has9Ex) { deviceEx->EndScene(); @@ -56,7 +41,7 @@ bool IsWin7OrLater() { return (major > 6) || ((major == 6) && (minor >= 1)); } -static void GetRes(int &xres, int &yres) { +static void GetRes(HWND hWnd, int &xres, int &yres) { RECT rc; GetClientRect(hWnd, &rc); xres = rc.right - rc.left; @@ -143,7 +128,7 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { dwBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; int xres, yres; - GetRes(xres, yres); + GetRes(hWnd, xres, yres); memset(&pp, 0, sizeof(pp)); pp.BackBufferWidth = xres; @@ -206,7 +191,7 @@ void D3D9Context::Resize() { // This should only be called from the emu thread. int xres, yres; - GetRes(xres, yres); + GetRes(hWnd, xres, yres); bool w_changed = pp.BackBufferWidth != xres; bool h_changed = pp.BackBufferHeight != yres; diff --git a/Windows/GPU/D3D9Context.h b/Windows/GPU/D3D9Context.h index 876fb5850e..11d334ca92 100644 --- a/Windows/GPU/D3D9Context.h +++ b/Windows/GPU/D3D9Context.h @@ -4,11 +4,16 @@ #include "Common/CommonWindows.h" #include "Windows/GPU/WindowsGraphicsContext.h" +#include class Thin3DContext; class D3D9Context : public WindowsGraphicsContext { public: + D3D9Context() : has9Ex(false), d3d(nullptr), d3dEx(nullptr), adapterId(-1), device(nullptr), deviceEx(nullptr), hDC(nullptr), hRC(nullptr), hWnd(nullptr), hD3D9(nullptr) { + memset(&pp, 0, sizeof(pp)); + } + bool Init(HINSTANCE hInst, HWND window, std::string *error_message) override; void Shutdown() override; void SwapInterval(int interval) override; @@ -17,5 +22,18 @@ public: void Resize() override; Thin3DContext *CreateThin3DContext() override; + +private: + bool has9Ex; + LPDIRECT3D9 d3d; + LPDIRECT3D9EX d3dEx; + int adapterId; + LPDIRECT3DDEVICE9 device; + LPDIRECT3DDEVICE9EX deviceEx; + HDC hDC; // Private GDI Device Context + HGLRC hRC; // Permanent Rendering Context + HWND hWnd; // Holds Our Window Handle + HMODULE hD3D9; + D3DPRESENT_PARAMETERS pp; }; diff --git a/Windows/GPU/WindowsGLContext.cpp b/Windows/GPU/WindowsGLContext.cpp index 953173d6d7..072af0a5b5 100644 --- a/Windows/GPU/WindowsGLContext.cpp +++ b/Windows/GPU/WindowsGLContext.cpp @@ -31,16 +31,6 @@ #include "Windows/W32Util/Misc.h" #include "Windows/GPU/WindowsGLContext.h" -static HDC hDC; // Private GDI Device Context -static HGLRC hRC; // Permanent Rendering Context -static HWND hWnd; // Holds Our Window Handle -static volatile bool pauseRequested; -static volatile bool resumeRequested; -static HANDLE pauseEvent; -static HANDLE resumeEvent; - -static int xres, yres; - void WindowsGLContext::SwapBuffers() { ::SwapBuffers(hDC); diff --git a/Windows/GPU/WindowsGLContext.h b/Windows/GPU/WindowsGLContext.h index 0581b87cfa..54289c9efe 100644 --- a/Windows/GPU/WindowsGLContext.h +++ b/Windows/GPU/WindowsGLContext.h @@ -20,4 +20,15 @@ public: void Resize() override; Thin3DContext *CreateThin3DContext() override; + +private: + HDC hDC; // Private GDI Device Context + HGLRC hRC; // Permanent Rendering Context + HWND hWnd; // Holds Our Window Handle + volatile bool pauseRequested; + volatile bool resumeRequested; + HANDLE pauseEvent; + HANDLE resumeEvent; + + int xres, yres; }; diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index b139a3bdd5..6c3348c999 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -87,6 +87,7 @@ bool AndroidEGLGraphicsContext::Init(ANativeWindow *wnd, int backbufferWidth, in return false; } gl->MakeCurrent(); + return true; } void AndroidEGLGraphicsContext::Shutdown() { @@ -134,10 +135,10 @@ static int desiredBackbufferSizeY; static jmethodID postCommand; static jobject nativeActivity; static volatile bool exitRenderLoop; -bool renderLoopRunning; +static bool renderLoopRunning; -float dp_xscale = 1.0f; -float dp_yscale = 1.0f; +static float dp_xscale = 1.0f; +static float dp_yscale = 1.0f; InputState input_state; diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 8406f5109c..cd20f5507c 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -83,9 +83,7 @@ bool System_InputBoxGetWString(const wchar_t *title, const std::wstring &default void System_AskForPermission(SystemPermission permission) {} PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; } -#ifndef _WIN32 InputState input_state; -#endif int printUsage(const char *progname, const char *reason) { diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index f762adab5d..e020d61191 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -33,11 +33,13 @@ #include "base/NativeApp.h" #include "base/logging.h" -#include "Common/CPUDetect.h" -#include "Common/ArmEmitter.h" +#include "input/input_state.h" #include "ext/disarm.h" #include "math/math_util.h" #include "util/text/parsers.h" + +#include "Common/CPUDetect.h" +#include "Common/ArmEmitter.h" #include "Core/Config.h" #include "Core/MIPS/MIPSVFPUUtils.h" #include "Core/FileSystems/ISOFileSystem.h" @@ -46,6 +48,8 @@ #include "unittest/TestVertexJit.h" #include "unittest/UnitTest.h" +InputState input_state; + std::string System_GetProperty(SystemProperty prop) { return ""; } int System_GetPropertyInt(SystemProperty prop) { return -1; } void NativeMessageReceived(const char *message, const char *value) {}