mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
Change when drawcontexts are allocated. Hook up backbuffer events to fix d3d9 resizing.
This commit is contained in:
parent
948e2284fd
commit
ad29974a56
@ -25,7 +25,7 @@ public:
|
||||
// Needs casting to the appropriate type, unfortunately. Should find a better solution..
|
||||
virtual void *GetAPIContext() { return nullptr; }
|
||||
|
||||
virtual Draw::DrawContext *CreateDrawContext() = 0;
|
||||
virtual Draw::DrawContext *GetDrawContext() = 0;
|
||||
};
|
||||
|
||||
class DummyGraphicsContext : public GraphicsContext {
|
||||
@ -35,5 +35,5 @@ public:
|
||||
void SwapBuffers() override {}
|
||||
void Resize() override {}
|
||||
|
||||
Draw::DrawContext *CreateDrawContext() override { return nullptr; }
|
||||
Draw::DrawContext *GetDrawContext() override { return nullptr; }
|
||||
};
|
@ -18,6 +18,7 @@
|
||||
#include <map>
|
||||
#include <d3d9.h>
|
||||
|
||||
#include <d3d9.h>
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "GPU/ge_constants.h"
|
||||
|
||||
|
@ -520,12 +520,10 @@ GPU_DX9::~GPU_DX9() {
|
||||
// Needs to be called on GPU thread, not reporting thread.
|
||||
void GPU_DX9::BuildReportingInfo() {
|
||||
using namespace Draw;
|
||||
DrawContext *thin3d = gfxCtx_->CreateDrawContext();
|
||||
DrawContext *thin3d = gfxCtx_->GetDrawContext();
|
||||
|
||||
reportingPrimaryInfo_ = thin3d->GetInfoString(InfoField::VENDORSTRING);
|
||||
reportingFullInfo_ = reportingPrimaryInfo_ + " - " + System_GetProperty(SYSPROP_GPUDRIVER_VERSION) + " - " + thin3d->GetInfoString(InfoField::SHADELANGVERSION);
|
||||
|
||||
thin3d->Release();
|
||||
}
|
||||
|
||||
void GPU_DX9::DeviceLost() {
|
||||
|
@ -1673,7 +1673,7 @@ void FramebufferManagerGLES::PackFramebufferSync_(VirtualFramebuffer *vfb, int x
|
||||
if (gl_extensions.GLES3 && glInvalidateFramebuffer != nullptr) {
|
||||
#ifdef USING_GLES2
|
||||
// GLES3 doesn't support using GL_READ_FRAMEBUFFER here.
|
||||
fbo_bind_as_render_target(vfb->fbo);
|
||||
draw_->fbo_bind_as_render_target(vfb->fbo);
|
||||
const GLenum target = GL_FRAMEBUFFER;
|
||||
#else
|
||||
const GLenum target = GL_READ_FRAMEBUFFER;
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) override;
|
||||
bool GetCurrentTexture(GPUDebugBuffer &buffer, int level) override;
|
||||
bool GetCurrentClut(GPUDebugBuffer &buffer) override;
|
||||
static bool GetOutputFramebuffer(GPUDebugBuffer &buffer);
|
||||
bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override;
|
||||
bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) override;
|
||||
|
||||
bool DescribeCodePtr(const u8 *ptr, std::string &name) override;
|
||||
|
@ -525,7 +525,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
|
||||
void NativeInitGraphics(GraphicsContext *graphicsContext) {
|
||||
using namespace Draw;
|
||||
Core_SetGraphicsContext(graphicsContext);
|
||||
g_draw = graphicsContext->CreateDrawContext();
|
||||
g_draw = graphicsContext->GetDrawContext();
|
||||
|
||||
ui_draw2d.SetAtlas(&ui_atlas);
|
||||
ui_draw2d_front.SetAtlas(&ui_atlas);
|
||||
@ -656,11 +656,6 @@ void NativeShutdownGraphics() {
|
||||
|
||||
colorPipeline->Release();
|
||||
texColorPipeline->Release();
|
||||
|
||||
// TODO: Reconsider this annoying ref counting stuff.
|
||||
if (g_draw->Release()) {
|
||||
g_draw = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void TakeScreenshot() {
|
||||
|
@ -15,10 +15,6 @@ void D3D11Context::SwapBuffers() {
|
||||
swapChain_->Present(0, 0);
|
||||
}
|
||||
|
||||
Draw::DrawContext *D3D11Context::CreateDrawContext() {
|
||||
return Draw::T3DCreateD3D11Context(device_, context_);
|
||||
}
|
||||
|
||||
static void GetRes(HWND hWnd, int &xres, int &yres) {
|
||||
RECT rc;
|
||||
GetClientRect(hWnd, &rc);
|
||||
@ -199,6 +195,7 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
|
||||
int xres, yres;
|
||||
GetRes(hWnd_, xres, yres);
|
||||
|
||||
draw_ = Draw::T3DCreateD3D11Context(device_, context_);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -211,8 +208,6 @@ void D3D11Context::Resize() {
|
||||
bool h_changed = pp.BackBufferHeight != yres;
|
||||
|
||||
if (device && (w_changed || h_changed)) {
|
||||
// DX9::fbo_shutdown();
|
||||
|
||||
pp.BackBufferWidth = xres;
|
||||
pp.BackBufferHeight = yres;
|
||||
HRESULT hr = device_->Reset(&pp);
|
||||
@ -221,19 +216,20 @@ void D3D11Context::Resize() {
|
||||
ERROR_LOG_REPORT(G3D, "Unable to reset D3D device");
|
||||
PanicAlert("Unable to reset D3D11 device");
|
||||
}
|
||||
// DX9::fbo_init(d3d);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void D3D11Context::Shutdown() {
|
||||
delete draw_;
|
||||
draw_ = nullptr;
|
||||
|
||||
context_->Release();
|
||||
context_ = nullptr;
|
||||
device_->Release();
|
||||
device_ = nullptr;
|
||||
/*
|
||||
DX9::DestroyShaders();
|
||||
DX9::fbo_shutdown();
|
||||
device->EndScene();
|
||||
device->Release();
|
||||
d3d->Release();
|
||||
|
@ -27,7 +27,7 @@ class DrawContext;
|
||||
|
||||
class D3D11Context : public WindowsGraphicsContext {
|
||||
public:
|
||||
D3D11Context() : adapterId(-1), hDC(nullptr), hWnd_(nullptr), hD3D11(nullptr) {
|
||||
D3D11Context() : draw_(nullptr), adapterId(-1), hDC(nullptr), hWnd_(nullptr), hD3D11(nullptr) {
|
||||
}
|
||||
|
||||
bool Init(HINSTANCE hInst, HWND window, std::string *error_message) override;
|
||||
@ -37,9 +37,10 @@ public:
|
||||
|
||||
void Resize() override;
|
||||
|
||||
Draw::DrawContext *CreateDrawContext() override;
|
||||
Draw::DrawContext *GetDrawContext() override { return draw_; }
|
||||
|
||||
private:
|
||||
Draw::DrawContext *draw_;
|
||||
ID3D11Device *device_;
|
||||
ID3D11DeviceContext *context_;
|
||||
IDXGISwapChain *swapChain_ = nullptr;
|
||||
|
@ -15,21 +15,17 @@
|
||||
#include "thin3d/d3dx9_loader.h"
|
||||
|
||||
void D3D9Context::SwapBuffers() {
|
||||
if (has9Ex) {
|
||||
deviceEx->EndScene();
|
||||
deviceEx->PresentEx(NULL, NULL, NULL, NULL, 0);
|
||||
deviceEx->BeginScene();
|
||||
if (has9Ex_) {
|
||||
deviceEx_->EndScene();
|
||||
deviceEx_->PresentEx(NULL, NULL, NULL, NULL, 0);
|
||||
deviceEx_->BeginScene();
|
||||
} else {
|
||||
device->EndScene();
|
||||
device->Present(NULL, NULL, NULL, NULL);
|
||||
device->BeginScene();
|
||||
device_->EndScene();
|
||||
device_->Present(NULL, NULL, NULL, NULL);
|
||||
device_->BeginScene();
|
||||
}
|
||||
}
|
||||
|
||||
Draw::DrawContext *D3D9Context::CreateDrawContext() {
|
||||
return Draw::T3DCreateDX9Context(d3d, d3dEx, adapterId, device, deviceEx);
|
||||
}
|
||||
|
||||
typedef HRESULT (__stdcall *DIRECT3DCREATE9EX)(UINT, IDirect3D9Ex**);
|
||||
|
||||
bool IsWin7OrLater() {
|
||||
@ -53,12 +49,12 @@ void D3D9Context::SwapInterval(int interval) {
|
||||
|
||||
bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
|
||||
bool windowed = true;
|
||||
hWnd = wnd;
|
||||
hWnd_ = wnd;
|
||||
|
||||
DIRECT3DCREATE9EX g_pfnCreate9ex;
|
||||
|
||||
hD3D9 = LoadLibrary(TEXT("d3d9.dll"));
|
||||
if (!hD3D9) {
|
||||
hD3D9_ = LoadLibrary(TEXT("d3d9.dll"));
|
||||
if (!hD3D9_) {
|
||||
ELOG("Missing d3d9.dll");
|
||||
*error_message = "D3D9.dll missing - try reinstalling DirectX.";
|
||||
return false;
|
||||
@ -70,21 +66,21 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
g_pfnCreate9ex = (DIRECT3DCREATE9EX)GetProcAddress(hD3D9, "Direct3DCreate9Ex");
|
||||
has9Ex = (g_pfnCreate9ex != NULL) && IsVistaOrHigher();
|
||||
g_pfnCreate9ex = (DIRECT3DCREATE9EX)GetProcAddress(hD3D9_, "Direct3DCreate9Ex");
|
||||
has9Ex_ = (g_pfnCreate9ex != NULL) && IsVistaOrHigher();
|
||||
|
||||
if (has9Ex) {
|
||||
HRESULT result = g_pfnCreate9ex(D3D_SDK_VERSION, &d3dEx);
|
||||
d3d = d3dEx;
|
||||
if (has9Ex_) {
|
||||
HRESULT result = g_pfnCreate9ex(D3D_SDK_VERSION, &d3dEx_);
|
||||
d3d_ = d3dEx_;
|
||||
if (FAILED(result)) {
|
||||
FreeLibrary(hD3D9);
|
||||
FreeLibrary(hD3D9_);
|
||||
*error_message = "D3D9Ex available but context creation failed. Try reinstalling DirectX.";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
if (!d3d) {
|
||||
FreeLibrary(hD3D9);
|
||||
d3d_ = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
if (!d3d_) {
|
||||
FreeLibrary(hD3D9_);
|
||||
*error_message = "Failed to create D3D9 context. Try reinstalling DirectX.";
|
||||
return false;
|
||||
}
|
||||
@ -93,21 +89,21 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
|
||||
D3DCAPS9 d3dCaps;
|
||||
|
||||
D3DDISPLAYMODE d3ddm;
|
||||
if (FAILED(d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) {
|
||||
if (FAILED(d3d_->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) {
|
||||
*error_message = "GetAdapterDisplayMode failed";
|
||||
d3d->Release();
|
||||
d3d_->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
adapterId = D3DADAPTER_DEFAULT;
|
||||
if (FAILED(d3d->GetDeviceCaps(adapterId, D3DDEVTYPE_HAL, &d3dCaps))) {
|
||||
adapterId_ = D3DADAPTER_DEFAULT;
|
||||
if (FAILED(d3d_->GetDeviceCaps(adapterId_, D3DDEVTYPE_HAL, &d3dCaps))) {
|
||||
*error_message = "GetDeviceCaps failed (???)";
|
||||
d3d->Release();
|
||||
d3d_->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
HRESULT hr;
|
||||
if (FAILED(hr = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT,
|
||||
if (FAILED(hr = d3d_->CheckDeviceFormat(D3DADAPTER_DEFAULT,
|
||||
D3DDEVTYPE_HAL,
|
||||
d3ddm.Format,
|
||||
D3DUSAGE_DEPTHSTENCIL,
|
||||
@ -115,7 +111,7 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
|
||||
D3DFMT_D24S8))) {
|
||||
if (hr == D3DERR_NOTAVAILABLE) {
|
||||
*error_message = "D24S8 depth/stencil not available";
|
||||
d3d->Release();
|
||||
d3d_->Release();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -127,84 +123,85 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
|
||||
dwBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
|
||||
|
||||
int xres, yres;
|
||||
GetRes(hWnd, xres, yres);
|
||||
GetRes(hWnd_, xres, yres);
|
||||
|
||||
memset(&pp, 0, sizeof(pp));
|
||||
pp.BackBufferWidth = xres;
|
||||
pp.BackBufferHeight = yres;
|
||||
pp.BackBufferFormat = d3ddm.Format;
|
||||
pp.MultiSampleType = D3DMULTISAMPLE_NONE;
|
||||
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
pp.Windowed = windowed;
|
||||
pp.hDeviceWindow = wnd;
|
||||
pp.EnableAutoDepthStencil = true;
|
||||
pp.AutoDepthStencilFormat = D3DFMT_D24S8;
|
||||
pp.PresentationInterval = (g_Config.bVSync) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
presentParams_ = {};
|
||||
presentParams_.BackBufferWidth = xres;
|
||||
presentParams_.BackBufferHeight = yres;
|
||||
presentParams_.BackBufferFormat = d3ddm.Format;
|
||||
presentParams_.MultiSampleType = D3DMULTISAMPLE_NONE;
|
||||
presentParams_.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
presentParams_.Windowed = windowed;
|
||||
presentParams_.hDeviceWindow = wnd;
|
||||
presentParams_.EnableAutoDepthStencil = true;
|
||||
presentParams_.AutoDepthStencilFormat = D3DFMT_D24S8;
|
||||
presentParams_.PresentationInterval = (g_Config.bVSync) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
|
||||
if (has9Ex) {
|
||||
if (has9Ex_) {
|
||||
if (windowed && IsWin7OrLater()) {
|
||||
// This new flip mode gives higher performance.
|
||||
// TODO: This makes it slower?
|
||||
// This "new" flip mode should give higher performance but doesn't.
|
||||
//pp.BackBufferCount = 2;
|
||||
//pp.SwapEffect = D3DSWAPEFFECT_FLIPEX;
|
||||
}
|
||||
hr = d3dEx->CreateDeviceEx(adapterId, D3DDEVTYPE_HAL, wnd, dwBehaviorFlags, &pp, NULL, &deviceEx);
|
||||
device = deviceEx;
|
||||
hr = d3dEx_->CreateDeviceEx(adapterId_, D3DDEVTYPE_HAL, wnd, dwBehaviorFlags, &presentParams_, NULL, &deviceEx_);
|
||||
device_ = deviceEx_;
|
||||
} else {
|
||||
hr = d3d->CreateDevice(adapterId, D3DDEVTYPE_HAL, wnd, dwBehaviorFlags, &pp, &device);
|
||||
hr = d3d_->CreateDevice(adapterId_, D3DDEVTYPE_HAL, wnd, dwBehaviorFlags, &presentParams_, &device_);
|
||||
}
|
||||
|
||||
if (FAILED(hr)) {
|
||||
*error_message = "Failed to create D3D device";
|
||||
d3d->Release();
|
||||
d3d_->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
device->BeginScene();
|
||||
DX9::pD3Ddevice = device;
|
||||
DX9::pD3DdeviceEx = deviceEx;
|
||||
device_->BeginScene();
|
||||
DX9::pD3Ddevice = device_;
|
||||
DX9::pD3DdeviceEx = deviceEx_;
|
||||
|
||||
if (deviceEx && IsWin7OrLater()) {
|
||||
if (deviceEx_ && IsWin7OrLater()) {
|
||||
// TODO: This makes it slower?
|
||||
//deviceEx->SetMaximumFrameLatency(1);
|
||||
}
|
||||
|
||||
draw_ = Draw::T3DCreateDX9Context(d3d_, d3dEx_, -1, device_, deviceEx_);
|
||||
if (draw_)
|
||||
draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER);
|
||||
return true;
|
||||
}
|
||||
|
||||
void D3D9Context::Resize() {
|
||||
// This should only be called from the emu thread.
|
||||
|
||||
int xres, yres;
|
||||
GetRes(hWnd, xres, yres);
|
||||
bool w_changed = pp.BackBufferWidth != xres;
|
||||
bool h_changed = pp.BackBufferHeight != yres;
|
||||
GetRes(hWnd_, xres, yres);
|
||||
bool w_changed = presentParams_.BackBufferWidth != xres;
|
||||
bool h_changed = presentParams_.BackBufferHeight != yres;
|
||||
|
||||
if (device && (w_changed || h_changed)) {
|
||||
// DX9::fbo_shutdown();
|
||||
|
||||
pp.BackBufferWidth = xres;
|
||||
pp.BackBufferHeight = yres;
|
||||
HRESULT hr = device->Reset(&pp);
|
||||
if (device_ && (w_changed || h_changed)) {
|
||||
draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER);
|
||||
presentParams_.BackBufferWidth = xres;
|
||||
presentParams_.BackBufferHeight = yres;
|
||||
HRESULT hr = device_->Reset(&presentParams_);
|
||||
if (FAILED(hr)) {
|
||||
// Had to remove DXGetErrorStringA calls here because dxerr.lib is deprecated and will not link with VS 2015.
|
||||
ERROR_LOG_REPORT(G3D, "Unable to reset D3D device");
|
||||
PanicAlert("Unable to reset D3D9 device");
|
||||
}
|
||||
// DX9::fbo_init(d3d, device);
|
||||
draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER);
|
||||
}
|
||||
}
|
||||
|
||||
void D3D9Context::Shutdown() {
|
||||
// DX9::fbo_shutdown();
|
||||
device->EndScene();
|
||||
device->Release();
|
||||
d3d->Release();
|
||||
draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER);
|
||||
delete draw_;
|
||||
draw_ = nullptr;
|
||||
device_->EndScene();
|
||||
device_->Release();
|
||||
d3d_->Release();
|
||||
UnloadD3DXDynamic();
|
||||
DX9::pD3Ddevice = nullptr;
|
||||
DX9::pD3DdeviceEx = nullptr;
|
||||
device = nullptr;
|
||||
hWnd = nullptr;
|
||||
FreeLibrary(hD3D9);
|
||||
hD3D9 = nullptr;
|
||||
device_ = nullptr;
|
||||
hWnd_ = nullptr;
|
||||
FreeLibrary(hD3D9_);
|
||||
hD3D9_ = nullptr;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace Draw {
|
||||
|
||||
class D3D9Context : public WindowsGraphicsContext {
|
||||
public:
|
||||
D3D9Context() : has9Ex(false), d3d(nullptr), d3dEx(nullptr), adapterId(-1), device(nullptr), deviceEx(nullptr), hDC(nullptr), hWnd(nullptr), hD3D9(nullptr), pp{} {
|
||||
D3D9Context() : draw_(nullptr), has9Ex_(false), d3d_(nullptr), d3dEx_(nullptr), adapterId_(-1), device_(nullptr), deviceEx_(nullptr), hDC_(nullptr), hWnd_(nullptr), hD3D9_(nullptr), presentParams_{} {
|
||||
}
|
||||
|
||||
bool Init(HINSTANCE hInst, HWND window, std::string *error_message) override;
|
||||
@ -39,18 +39,19 @@ public:
|
||||
|
||||
void Resize() override;
|
||||
|
||||
Draw::DrawContext *CreateDrawContext() override;
|
||||
Draw::DrawContext *GetDrawContext() override { return draw_; }
|
||||
|
||||
private:
|
||||
bool has9Ex;
|
||||
LPDIRECT3D9 d3d;
|
||||
LPDIRECT3D9EX d3dEx;
|
||||
int adapterId;
|
||||
LPDIRECT3DDEVICE9 device;
|
||||
LPDIRECT3DDEVICE9EX deviceEx;
|
||||
HDC hDC; // Private GDI Device Context
|
||||
HWND hWnd; // Holds Our Window Handle
|
||||
HMODULE hD3D9;
|
||||
D3DPRESENT_PARAMETERS pp;
|
||||
Draw::DrawContext *draw_;
|
||||
bool has9Ex_;
|
||||
LPDIRECT3D9 d3d_;
|
||||
LPDIRECT3D9EX d3dEx_;
|
||||
int adapterId_;
|
||||
LPDIRECT3DDEVICE9 device_;
|
||||
LPDIRECT3DDEVICE9EX deviceEx_;
|
||||
HDC hDC_; // Private GDI Device Context
|
||||
HWND hWnd_; // Holds Our Window Handle
|
||||
HMODULE hD3D9_;
|
||||
D3DPRESENT_PARAMETERS presentParams_;
|
||||
};
|
||||
|
||||
|
@ -362,6 +362,8 @@ bool WindowsGLContext::Init(HINSTANCE hInst, HWND window, std::string *error_mes
|
||||
pauseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
resumeEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
|
||||
CheckGLExtensions();
|
||||
draw_ = Draw::T3DCreateGLContext();
|
||||
return true; // Success
|
||||
}
|
||||
|
||||
@ -372,6 +374,8 @@ void WindowsGLContext::SwapInterval(int interval) {
|
||||
}
|
||||
|
||||
void WindowsGLContext::Shutdown() {
|
||||
delete draw_;
|
||||
draw_ = nullptr;
|
||||
CloseHandle(pauseEvent);
|
||||
CloseHandle(resumeEvent);
|
||||
if (hRC) {
|
||||
@ -399,8 +403,3 @@ void WindowsGLContext::Shutdown() {
|
||||
|
||||
void WindowsGLContext::Resize() {
|
||||
}
|
||||
|
||||
Draw::DrawContext *WindowsGLContext::CreateDrawContext() {
|
||||
CheckGLExtensions();
|
||||
return Draw::T3DCreateGLContext();
|
||||
}
|
||||
|
@ -21,9 +21,10 @@ public:
|
||||
|
||||
void Resize() override;
|
||||
|
||||
Draw::DrawContext *CreateDrawContext() override;
|
||||
Draw::DrawContext *GetDrawContext() override { return draw_; }
|
||||
|
||||
private:
|
||||
Draw::DrawContext *draw_;
|
||||
HDC hDC; // Private GDI Device Context
|
||||
HGLRC hRC; // Permanent Rendering Context
|
||||
HWND hWnd; // Holds Our Window Handle
|
||||
@ -32,5 +33,6 @@ private:
|
||||
HANDLE pauseEvent;
|
||||
HANDLE resumeEvent;
|
||||
|
||||
int xres, yres;
|
||||
int xres;
|
||||
int yres;
|
||||
};
|
||||
|
@ -193,10 +193,15 @@ bool WindowsVulkanContext::Init(HINSTANCE hInst, HWND hWnd, std::string *error_m
|
||||
g_Vulkan->InitSurfaceWin32(hInst, hWnd);
|
||||
g_Vulkan->InitObjects(true);
|
||||
|
||||
draw_ = Draw::T3DCreateVulkanContext(g_Vulkan);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WindowsVulkanContext::Shutdown() {
|
||||
delete draw_;
|
||||
draw_ = nullptr;
|
||||
|
||||
g_Vulkan->WaitUntilQueueIdle();
|
||||
g_Vulkan->DestroyObjects();
|
||||
g_Vulkan->DestroyDevice();
|
||||
@ -207,10 +212,6 @@ void WindowsVulkanContext::Shutdown() {
|
||||
finalize_glslang();
|
||||
}
|
||||
|
||||
Draw::DrawContext *WindowsVulkanContext::CreateDrawContext() {
|
||||
return Draw::T3DCreateVulkanContext(g_Vulkan);
|
||||
}
|
||||
|
||||
void WindowsVulkanContext::SwapBuffers() {
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
class WindowsVulkanContext : public WindowsGraphicsContext {
|
||||
public:
|
||||
WindowsVulkanContext() : draw_(nullptr) {}
|
||||
bool Init(HINSTANCE hInst, HWND window, std::string *error_message) override;
|
||||
void Shutdown() override;
|
||||
void SwapInterval(int interval) override;
|
||||
@ -31,6 +32,8 @@ public:
|
||||
|
||||
void *GetAPIContext();
|
||||
|
||||
Draw::DrawContext *CreateDrawContext() override;
|
||||
Draw::DrawContext *GetDrawContext() override { return draw_; }
|
||||
private:
|
||||
Draw::DrawContext *draw_;
|
||||
};
|
||||
|
||||
|
@ -229,7 +229,6 @@ EXEC_AND_LIB_FILES := \
|
||||
$(SRC)/GPU/GLES/FramebufferManagerGLES.cpp \
|
||||
$(SRC)/GPU/GLES/DepalettizeShaderGLES.cpp \
|
||||
$(SRC)/GPU/GLES/GPU_GLES.cpp.arm \
|
||||
$(SRC)/GPU/GLES/FBO.cpp \
|
||||
$(SRC)/GPU/GLES/StencilBufferGLES.cpp.arm \
|
||||
$(SRC)/GPU/GLES/TextureCacheGLES.cpp.arm \
|
||||
$(SRC)/GPU/GLES/DrawEngineGLES.cpp.arm \
|
||||
|
@ -74,18 +74,18 @@ public:
|
||||
|
||||
class AndroidEGLGraphicsContext : public AndroidGraphicsContext {
|
||||
public:
|
||||
AndroidEGLGraphicsContext() : wnd_(nullptr), gl(nullptr) {}
|
||||
AndroidEGLGraphicsContext() : draw_(nullptr), wnd_(nullptr), gl(nullptr) {}
|
||||
bool Init(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) override;
|
||||
void Shutdown() override;
|
||||
void SwapBuffers() override;
|
||||
void SwapInterval(int interval) override {}
|
||||
void Resize() override {}
|
||||
Draw::DrawContext *CreateDrawContext() override {
|
||||
CheckGLExtensions();
|
||||
return Draw::T3DCreateGLContext();
|
||||
Draw::DrawContext *GetDrawContext() override {
|
||||
return draw_;
|
||||
}
|
||||
|
||||
private:
|
||||
Draw::DrawContext *draw_;
|
||||
ANativeWindow *wnd_;
|
||||
cInterfaceBase *gl;
|
||||
};
|
||||
@ -108,7 +108,7 @@ bool AndroidEGLGraphicsContext::Init(ANativeWindow *wnd, int backbufferWidth, in
|
||||
// This workaround seems only be needed on some really old devices.
|
||||
if (androidVersion < ANDROID_VERSION_ICS) {
|
||||
switch (backbufferFormat) {
|
||||
case 4: // PixelFormat.RGB_565
|
||||
case 4: // PixelFormat.RGB_565
|
||||
use565 = true;
|
||||
break;
|
||||
default:
|
||||
@ -123,10 +123,14 @@ bool AndroidEGLGraphicsContext::Init(ANativeWindow *wnd, int backbufferWidth, in
|
||||
return false;
|
||||
}
|
||||
gl->MakeCurrent();
|
||||
CheckGLExtensions();
|
||||
draw_ = Draw::T3DCreateGLContext();
|
||||
return true;
|
||||
}
|
||||
|
||||
void AndroidEGLGraphicsContext::Shutdown() {
|
||||
delete draw_;
|
||||
draw_ = nullptr;
|
||||
gl->ClearCurrent();
|
||||
gl->Shutdown();
|
||||
delete gl;
|
||||
@ -140,16 +144,24 @@ void AndroidEGLGraphicsContext::SwapBuffers() {
|
||||
// Doesn't do much. Just to fit in.
|
||||
class AndroidJavaEGLGraphicsContext : public GraphicsContext {
|
||||
public:
|
||||
AndroidJavaEGLGraphicsContext() {}
|
||||
bool Init(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) { return true; }
|
||||
void Shutdown() override {}
|
||||
AndroidJavaEGLGraphicsContext() : draw_(nullptr) {}
|
||||
bool Init(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) {
|
||||
CheckGLExtensions();
|
||||
draw_ = Draw::T3DCreateGLContext();
|
||||
return true;
|
||||
}
|
||||
void Shutdown() override {
|
||||
delete draw_;
|
||||
draw_ = nullptr;
|
||||
}
|
||||
void SwapBuffers() override {}
|
||||
void SwapInterval(int interval) override {}
|
||||
void Resize() override {}
|
||||
Draw::DrawContext *CreateDrawContext() override {
|
||||
CheckGLExtensions();
|
||||
return Draw::T3DCreateGLContext();
|
||||
Draw::DrawContext *GetDrawContext() override {
|
||||
return draw_;
|
||||
}
|
||||
private:
|
||||
Draw::DrawContext *draw_;
|
||||
};
|
||||
|
||||
|
||||
@ -158,7 +170,7 @@ static VulkanContext *g_Vulkan;
|
||||
|
||||
class AndroidVulkanContext : public AndroidGraphicsContext {
|
||||
public:
|
||||
AndroidVulkanContext() {}
|
||||
AndroidVulkanContext() : draw_(nullptr) {}
|
||||
bool Init(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) override;
|
||||
void Shutdown() override;
|
||||
void SwapInterval(int interval) override;
|
||||
@ -167,9 +179,11 @@ public:
|
||||
|
||||
void *GetAPIContext() override { return g_Vulkan; }
|
||||
|
||||
Draw::DrawContext *CreateDrawContext() override {
|
||||
return Draw::T3DCreateVulkanContext(g_Vulkan);
|
||||
Draw::DrawContext *GetDrawContext() override {
|
||||
return draw_;
|
||||
}
|
||||
private:
|
||||
Draw::DrawContext *draw_;
|
||||
};
|
||||
|
||||
struct VulkanLogOptions {
|
||||
@ -274,7 +288,7 @@ bool AndroidVulkanContext::Init(ANativeWindow *wnd, int desiredBackbufferSizeX,
|
||||
g_Vulkan->InitDebugMsgCallback(&Vulkan_Dbg, bits, &g_LogOptions);
|
||||
}
|
||||
g_Vulkan->InitObjects(true);
|
||||
|
||||
draw_ = Draw::T3DCreateVulkanContext(g_Vulkan);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -283,6 +297,9 @@ void AndroidVulkanContext::Shutdown() {
|
||||
g_Vulkan->DestroyObjects();
|
||||
g_Vulkan->DestroyDebugMsgCallback();
|
||||
g_Vulkan->DestroyDevice();
|
||||
delete draw_;
|
||||
draw_ = nullptr;
|
||||
|
||||
delete g_Vulkan;
|
||||
g_Vulkan = nullptr;
|
||||
|
||||
@ -296,7 +313,7 @@ void AndroidVulkanContext::Resize() {
|
||||
g_Vulkan->WaitUntilQueueIdle();
|
||||
g_Vulkan->DestroyObjects();
|
||||
|
||||
// backbufferResize updated these values. TODO: Notify another way?
|
||||
// backbufferResize updated these values. TODO: Notify another way?
|
||||
g_Vulkan->ReinitSurfaceAndroid(pixel_xres, pixel_yres);
|
||||
g_Vulkan->InitObjects(g_Vulkan);
|
||||
}
|
||||
@ -330,7 +347,7 @@ static int deviceType;
|
||||
static int display_dpi;
|
||||
static int display_xres;
|
||||
static int display_yres;
|
||||
static int backbuffer_format; // Android PixelFormat enum
|
||||
static int backbuffer_format; // Android PixelFormat enum
|
||||
|
||||
static int desiredBackbufferSizeX;
|
||||
static int desiredBackbufferSizeY;
|
||||
@ -397,7 +414,7 @@ std::string System_GetProperty(SystemProperty prop) {
|
||||
switch (prop) {
|
||||
case SYSPROP_NAME:
|
||||
return systemName;
|
||||
case SYSPROP_LANGREGION: // "en_US"
|
||||
case SYSPROP_LANGREGION: // "en_US"
|
||||
return langRegion;
|
||||
case SYSPROP_MOGA_VERSION:
|
||||
return mogaVersion;
|
||||
@ -427,7 +444,7 @@ int System_GetPropertyInt(SystemProperty prop) {
|
||||
case SYSPROP_DISPLAY_REFRESH_RATE:
|
||||
return (int)(display_hz * 1000.0);
|
||||
case SYSPROP_SUPPORTS_PERMISSIONS:
|
||||
return androidVersion >= 23; // 6.0 Marshmallow introduced run time permissions.
|
||||
return androidVersion >= 23; // 6.0 Marshmallow introduced run time permissions.
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -480,7 +497,7 @@ extern "C" jstring Java_org_ppsspp_ppsspp_NativeApp_queryConfig
|
||||
}
|
||||
|
||||
extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
|
||||
(JNIEnv *env, jclass, jstring jmodel, jint jdeviceType, jstring jlangRegion, jstring japkpath,
|
||||
(JNIEnv *env, jclass, jstring jmodel, jint jdeviceType, jstring jlangRegion, jstring japkpath,
|
||||
jstring jdataDir, jstring jexternalDir, jstring jlibraryDir, jstring jcacheDir, jstring jshortcutParam,
|
||||
jint jAndroidVersion, jstring jboard) {
|
||||
jniEnvUI = env;
|
||||
@ -572,7 +589,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_audioInit(JNIEnv *, jclass) {
|
||||
sampleRate = 44100;
|
||||
}
|
||||
|
||||
ILOG("NativeApp.audioInit() -- Using OpenSL audio! frames/buffer: %i optimal sr: %i actual sr: %i", optimalFramesPerBuffer, optimalSampleRate, sampleRate);
|
||||
ILOG("NativeApp.audioInit() -- Using OpenSL audio! frames/buffer: %i optimal sr: %i actual sr: %i", optimalFramesPerBuffer, optimalSampleRate, sampleRate);
|
||||
AndroidAudio_Init(&NativeMix, library_path, framesPerBuffer, sampleRate);
|
||||
}
|
||||
|
||||
|
@ -48,10 +48,17 @@ SDLJoystick *joystick = NULL;
|
||||
|
||||
class GLDummyGraphicsContext : public DummyGraphicsContext {
|
||||
public:
|
||||
Draw::DrawContext *CreateDrawContext() override {
|
||||
GLDummyGraphicsContext() {
|
||||
CheckGLExtensions();
|
||||
return Draw::T3DCreateGLContext();
|
||||
draw_ = Draw::T3DCreateGLContext();
|
||||
}
|
||||
~GLDummyGraphicsContext() { delete draw_; }
|
||||
|
||||
Draw::DrawContext *GetDrawContext() override {
|
||||
return draw_;
|
||||
}
|
||||
private:
|
||||
Draw::DrawContext *draw_;
|
||||
};
|
||||
|
||||
GlobalUIState lastUIState = UISTATE_MENU;
|
||||
@ -204,20 +211,19 @@ void EGL_Close() {
|
||||
}
|
||||
#endif
|
||||
|
||||
int getDisplayNumber(void)
|
||||
{
|
||||
int displayNumber = 0;
|
||||
char * displayNumberStr;
|
||||
int getDisplayNumber(void) {
|
||||
int displayNumber = 0;
|
||||
char * displayNumberStr;
|
||||
|
||||
//get environment
|
||||
displayNumberStr=getenv("SDL_VIDEO_FULLSCREEN_HEAD");
|
||||
//get environment
|
||||
displayNumberStr=getenv("SDL_VIDEO_FULLSCREEN_HEAD");
|
||||
|
||||
if (displayNumberStr)
|
||||
{
|
||||
displayNumber = atoi(displayNumberStr);
|
||||
}
|
||||
if (displayNumberStr)
|
||||
{
|
||||
displayNumber = atoi(displayNumberStr);
|
||||
}
|
||||
|
||||
return displayNumber;
|
||||
return displayNumber;
|
||||
}
|
||||
|
||||
// Simple implementations of System functions
|
||||
|
@ -40,9 +40,18 @@ void SimulateGamepad(InputState *input);
|
||||
|
||||
class QtDummyGraphicsContext : public DummyGraphicsContext {
|
||||
public:
|
||||
Draw::DrawContext *CreateDrawContext() override {
|
||||
return Draw::T3DCreateGLContext();
|
||||
QtDummyGraphicsContext() {
|
||||
draw_ = Draw::T3DCreateGLContext();
|
||||
}
|
||||
~QtDummyGraphicsContext() {
|
||||
delete draw_;
|
||||
}
|
||||
|
||||
Draw::DrawContext *GetDrawContext() override {
|
||||
return draw_;
|
||||
}
|
||||
private:
|
||||
Draw::DrawContext *draw_;
|
||||
};
|
||||
|
||||
//GUI
|
||||
@ -50,32 +59,32 @@ class MainUI : public QGLWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainUI(QWidget *parent = 0);
|
||||
~MainUI();
|
||||
explicit MainUI(QWidget *parent = 0);
|
||||
~MainUI();
|
||||
|
||||
public slots:
|
||||
QString InputBoxGetQString(QString title, QString defaultValue);
|
||||
QString InputBoxGetQString(QString title, QString defaultValue);
|
||||
|
||||
signals:
|
||||
void doubleClick();
|
||||
void newFrame();
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *);
|
||||
void changeEvent(QEvent *e);
|
||||
bool event(QEvent *e);
|
||||
void timerEvent(QTimerEvent *);
|
||||
void changeEvent(QEvent *e);
|
||||
bool event(QEvent *e);
|
||||
|
||||
void initializeGL();
|
||||
void resizeGL(int w, int h);
|
||||
void paintGL();
|
||||
void initializeGL();
|
||||
void resizeGL(int w, int h);
|
||||
void paintGL();
|
||||
|
||||
void updateAccelerometer();
|
||||
void updateAccelerometer();
|
||||
|
||||
private:
|
||||
InputState input_state;
|
||||
QtDummyGraphicsContext *graphicsContext;
|
||||
|
||||
float xscale, yscale;
|
||||
float xscale, yscale;
|
||||
#if defined(MOBILE_DEVICE)
|
||||
QAccelerometer* acc;
|
||||
#endif
|
||||
@ -91,11 +100,11 @@ class MainAudio: public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainAudio() {}
|
||||
~MainAudio();
|
||||
~MainAudio();
|
||||
public slots:
|
||||
void run();
|
||||
void run();
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *);
|
||||
void timerEvent(QTimerEvent *);
|
||||
private:
|
||||
QIODevice* feed;
|
||||
QAudioOutput* output;
|
||||
|
@ -329,6 +329,12 @@ enum FBBlitFilter {
|
||||
FB_BLIT_LINEAR = 1,
|
||||
};
|
||||
|
||||
enum class Event {
|
||||
// These happen on D3D resize
|
||||
LOST_BACKBUFFER,
|
||||
GOT_BACKBUFFER,
|
||||
};
|
||||
|
||||
struct FramebufferDesc {
|
||||
int width;
|
||||
int height;
|
||||
@ -527,7 +533,7 @@ struct TextureDesc {
|
||||
std::vector<uint8_t *> initData;
|
||||
};
|
||||
|
||||
class DrawContext : public RefCountedObject {
|
||||
class DrawContext {
|
||||
public:
|
||||
virtual ~DrawContext();
|
||||
|
||||
@ -609,9 +615,10 @@ public:
|
||||
}
|
||||
|
||||
virtual std::string GetInfoString(InfoField info) const = 0;
|
||||
|
||||
virtual uintptr_t GetNativeObject(NativeObject obj) const = 0;
|
||||
|
||||
virtual void HandleEvent(Event ev) = 0;
|
||||
|
||||
protected:
|
||||
void CreatePresets();
|
||||
|
||||
|
@ -98,6 +98,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void HandleEvent(Event ev) override {}
|
||||
|
||||
private:
|
||||
void ApplyCurrentState();
|
||||
|
||||
@ -537,13 +539,6 @@ uint32_t D3D11DrawContext::GetDataFormatSupport(DataFormat fmt) const {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context) {
|
||||
return nullptr; // new D3D11DrawContext(device, context);
|
||||
}
|
||||
|
||||
|
||||
// A D3D11Framebuffer is a D3D11Framebuffer plus all the textures it owns.
|
||||
class D3D11Framebuffer : public Framebuffer {
|
||||
public:
|
||||
@ -579,4 +574,10 @@ void D3D11DrawContext::fbo_get_dimensions(Framebuffer *fbo, int *w, int *h) {
|
||||
*h = fb->height;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context) {
|
||||
return nullptr; // new D3D11DrawContext(device, context);
|
||||
}
|
||||
|
||||
} // namespace Draw
|
@ -623,6 +623,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void HandleEvent(Event ev) override;
|
||||
|
||||
private:
|
||||
LPDIRECT3D9 d3d_;
|
||||
LPDIRECT3D9EX d3dEx_;
|
||||
@ -662,8 +664,6 @@ D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, ID
|
||||
caps_.multiViewport = false;
|
||||
caps_.anisoSupported = true;
|
||||
caps_.depthRangeMinusOneToOne = false;
|
||||
device_->GetRenderTarget(0, &deviceRTsurf);
|
||||
device_->GetDepthStencilSurface(&deviceDSsurf);
|
||||
|
||||
if (d3d) {
|
||||
D3DDISPLAYMODE displayMode;
|
||||
@ -677,8 +677,6 @@ D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, ID
|
||||
}
|
||||
|
||||
D3D9Context::~D3D9Context() {
|
||||
deviceRTsurf->Release();
|
||||
deviceDSsurf->Release();
|
||||
}
|
||||
|
||||
ShaderModule *D3D9Context::CreateShaderModule(ShaderStage stage, ShaderLanguage language, const uint8_t *data, size_t size) {
|
||||
@ -1136,6 +1134,22 @@ bool D3D9Context::fbo_blit(Framebuffer *srcfb, int srcX1, int srcY1, int srcX2,
|
||||
return SUCCEEDED(device_->StretchRect(srcSurf, &srcRect, dstSurf, &dstRect, filter == FB_BLIT_LINEAR ? D3DTEXF_LINEAR : D3DTEXF_POINT));
|
||||
}
|
||||
|
||||
void D3D9Context::HandleEvent(Event ev) {
|
||||
switch (ev) {
|
||||
case Event::LOST_BACKBUFFER:
|
||||
if (deviceRTsurf)
|
||||
deviceRTsurf->Release();
|
||||
if (deviceDSsurf)
|
||||
deviceDSsurf->Release();
|
||||
deviceRTsurf = nullptr;
|
||||
deviceDSsurf = nullptr;
|
||||
break;
|
||||
case Event::GOT_BACKBUFFER:
|
||||
device_->GetRenderTarget(0, &deviceRTsurf);
|
||||
device_->GetDepthStencilSurface(&deviceDSsurf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DrawContext *T3DCreateDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx) {
|
||||
int d3dx_ver = LoadD3DX9Dynamic();
|
||||
|
@ -630,6 +630,8 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HandleEvent(Event ev) override {}
|
||||
|
||||
OpenGLFramebuffer *fbo_ext_create(const FramebufferDesc &desc);
|
||||
void fbo_bind_fb_target(bool read, GLuint name);
|
||||
GLenum fbo_get_fb_target(bool read, GLuint **cached);
|
||||
|
@ -442,6 +442,8 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HandleEvent(Event ev) override {}
|
||||
|
||||
private:
|
||||
void ApplyDynamicState();
|
||||
void DirtyDynamicState();
|
||||
|
@ -36,10 +36,18 @@
|
||||
|
||||
class IOSDummyGraphicsContext : public DummyGraphicsContext {
|
||||
public:
|
||||
Draw::DrawContext *CreateDrawContext() override {
|
||||
CheckGLExtensions();
|
||||
return Draw::T3DCreateGLContext();
|
||||
}
|
||||
IOSDummyGraphicsContext() {
|
||||
CheckGLExtensions();
|
||||
draw_ = Draw::T3DCreateGLContext();
|
||||
}
|
||||
~IOSDummyGraphicsContext() {
|
||||
delete draw_;
|
||||
}
|
||||
Draw::DrawContext *GetDrawContext() override {
|
||||
return draw_;
|
||||
}
|
||||
private:
|
||||
Draw::DrawContext *draw_;
|
||||
};
|
||||
|
||||
float dp_xscale = 1.0f;
|
||||
|
Loading…
Reference in New Issue
Block a user