Just some random driveby code cleanup

This commit is contained in:
Henrik Rydgård 2023-08-10 10:28:25 +02:00
parent 4e77c63b97
commit 96506544b7
8 changed files with 23 additions and 43 deletions

View file

@ -33,12 +33,6 @@
#error This file should not be compiled for UWP.
#endif
D3D11Context::D3D11Context() : draw_(nullptr), adapterId(-1), hDC(nullptr), hWnd_(nullptr), hD3D11(nullptr) {
}
D3D11Context::~D3D11Context() {
}
void D3D11Context::SwapBuffers() {
swapChain_->Present(swapInterval_, 0);
draw_->HandleEvent(Draw::Event::PRESENTED, 0, 0, nullptr, nullptr);
@ -81,13 +75,6 @@ HRESULT D3D11Context::CreateTheDevice(IDXGIAdapter *adapter) {
return hr;
}
static void GetRes(HWND hWnd, int &xres, int &yres) {
RECT rc;
GetClientRect(hWnd, &rc);
xres = rc.right - rc.left;
yres = rc.bottom - rc.top;
}
bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
hWnd_ = wnd;
LoadD3D11Error result = LoadD3D11();
@ -178,7 +165,7 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
int width;
int height;
GetRes(hWnd_, width, height);
W32Util::GetWindowRes(hWnd_, &width, &height);
// Obtain DXGI factory from device (since we used nullptr for pAdapter above)
IDXGIFactory1 *dxgiFactory = nullptr;
@ -249,7 +236,7 @@ void D3D11Context::Resize() {
LostBackbuffer();
int width;
int height;
GetRes(hWnd_, width, height);
W32Util::GetWindowRes(hWnd_, &width, &height);
swapChain_->ResizeBuffers(0, width, height, DXGI_FORMAT_UNKNOWN, 0);
GotBackbuffer();
}

View file

@ -28,8 +28,6 @@ class DrawContext;
class D3D11Context : public WindowsGraphicsContext {
public:
D3D11Context();
~D3D11Context();
bool Init(HINSTANCE hInst, HWND window, std::string *error_message) override;
void Shutdown() override;
void SwapInterval(int interval) override;
@ -59,13 +57,12 @@ private:
ID3D11Debug *d3dDebug_ = nullptr;
ID3D11InfoQueue *d3dInfoQueue_ = nullptr;
#endif
D3D_FEATURE_LEVEL featureLevel_ = D3D_FEATURE_LEVEL_11_0;
int adapterId;
HDC hDC; // Private GDI Device Context
HWND hWnd_; // Holds Our Window Handle
HMODULE hD3D11;
int width;
int height;
int adapterId = -1;
HDC hDC = nullptr; // Private GDI Device Context
HWND hWnd_ = nullptr; // Holds Our Window Handle
HMODULE hD3D11 = nullptr;
int width = 0;
int height = 0;
int swapInterval_ = 0;
};

View file

@ -35,13 +35,6 @@ void D3D9Context::SwapBuffers() {
typedef HRESULT (__stdcall *DIRECT3DCREATE9EX)(UINT, IDirect3D9Ex**);
static void GetRes(HWND hWnd, int &xres, int &yres) {
RECT rc;
GetClientRect(hWnd, &rc);
xres = rc.right - rc.left;
yres = rc.bottom - rc.top;
}
void D3D9Context::SwapInterval(int interval) {
swapInterval_ = interval;
}
@ -126,7 +119,7 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
dwBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
int xres, yres;
GetRes(hWnd_, xres, yres);
W32Util::GetWindowRes(hWnd_, &xres, &yres);
presentParams_ = {};
presentParams_.BackBufferWidth = xres;
@ -183,8 +176,8 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
void D3D9Context::Resize() {
// This should only be called from the emu thread.
int xres, yres;
GetRes(hWnd_, xres, yres);
uint32_t newInterval = swapInterval_ == 1 ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;;
W32Util::GetWindowRes(hWnd_, &xres, &yres);
uint32_t newInterval = swapInterval_ == 1 ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
bool w_changed = presentParams_.BackBufferWidth != xres;
bool h_changed = presentParams_.BackBufferHeight != yres;
bool i_changed = presentParams_.PresentationInterval != newInterval;

View file

@ -285,11 +285,8 @@ namespace MainWindow
System_PostUIMessage("window minimized", "false");
}
int width = 0, height = 0;
RECT rc;
GetClientRect(hwndMain, &rc);
width = rc.right - rc.left;
height = rc.bottom - rc.top;
int width, height;
W32Util::GetWindowRes(hwndMain, &width, &height);
// Moves the internal display window to match the inner size of the main window.
MoveWindow(hwndDisplay, 0, 0, width, height, TRUE);

View file

@ -87,6 +87,13 @@ namespace W32Util
SetWindowPos(hwnd, style, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
}
void GetWindowRes(HWND hWnd, int *xres, int *yres) {
RECT rc;
GetClientRect(hWnd, &rc);
*xres = rc.right - rc.left;
*yres = rc.bottom - rc.top;
}
static const wchar_t *RemoveExecutableFromCommandLine(const wchar_t *cmdline) {
if (!cmdline) {
return L"";

View file

@ -15,6 +15,8 @@ namespace W32Util
void SpawnNewInstance(bool overrideArgs = false, const std::string &args = "");
void GetSelfExecuteParams(std::wstring &workingDirectory, std::wstring &moduleFilename);
void GetWindowRes(HWND hWnd, int *xres, int *yres);
struct ClipboardData {
ClipboardData(const char *format, size_t sz);
ClipboardData(UINT format, size_t sz);

View file

@ -161,9 +161,6 @@ void AndroidVulkanContext::Shutdown() {
INFO_LOG(G3D, "AndroidVulkanContext::Shutdown completed");
}
void AndroidVulkanContext::SwapBuffers() {
}
void AndroidVulkanContext::Resize() {
INFO_LOG(G3D, "AndroidVulkanContext::Resize begin (oldsize: %dx%d)", g_Vulkan->GetBackbufferWidth(), g_Vulkan->GetBackbufferHeight());

View file

@ -16,7 +16,7 @@ public:
void Shutdown() override;
void SwapInterval(int interval) override;
void SwapBuffers() override;
void SwapBuffers() override {}
void Resize() override;
void *GetAPIContext() override { return g_Vulkan; }