2018-03-24 11:44:53 +00:00
|
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
#include "libretro/libretro.h"
|
|
|
|
#include "Common/GraphicsContext.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/GPU/thin3d_create.h"
|
2018-03-24 11:44:53 +00:00
|
|
|
|
2024-06-01 02:38:43 +00:00
|
|
|
#include "Core/Config.h"
|
2018-03-24 11:44:53 +00:00
|
|
|
#include "Core/System.h"
|
|
|
|
#include "GPU/GPUState.h"
|
2024-05-31 02:26:12 +00:00
|
|
|
#include "GPU/Software/SoftGpu.h"
|
|
|
|
#include "headless/Compare.h"
|
|
|
|
#include "Common/Data/Convert/ColorConv.h"
|
2018-03-24 11:44:53 +00:00
|
|
|
|
2024-06-01 02:38:43 +00:00
|
|
|
#define NATIVEWIDTH 480
|
|
|
|
#define NATIVEHEIGHT 272
|
2024-06-02 21:08:32 +00:00
|
|
|
#define SOFT_BMP_SIZE NATIVEWIDTH * NATIVEHEIGHT * 4
|
2024-06-01 02:38:43 +00:00
|
|
|
|
2018-03-24 11:44:53 +00:00
|
|
|
class LibretroGraphicsContext : public GraphicsContext {
|
2018-03-26 16:37:34 +00:00
|
|
|
public:
|
2018-03-24 11:44:53 +00:00
|
|
|
LibretroGraphicsContext() {}
|
2018-03-26 16:37:34 +00:00
|
|
|
~LibretroGraphicsContext() override { Shutdown(); }
|
2018-03-24 11:44:53 +00:00
|
|
|
|
|
|
|
virtual bool Init() = 0;
|
|
|
|
virtual void SetRenderTarget() {}
|
|
|
|
virtual GPUCore GetGPUCore() = 0;
|
|
|
|
virtual const char *Ident() = 0;
|
|
|
|
|
2018-03-26 16:37:34 +00:00
|
|
|
void Shutdown() override {
|
2018-03-24 11:44:53 +00:00
|
|
|
DestroyDrawContext();
|
|
|
|
}
|
2023-08-11 13:51:54 +00:00
|
|
|
virtual void SwapBuffers() = 0;
|
2018-03-24 11:44:53 +00:00
|
|
|
void Resize() override {}
|
|
|
|
|
2018-03-25 22:07:02 +00:00
|
|
|
virtual void GotBackbuffer();
|
|
|
|
virtual void LostBackbuffer();
|
|
|
|
|
2018-03-24 11:44:53 +00:00
|
|
|
virtual void CreateDrawContext() {}
|
2018-03-26 16:37:34 +00:00
|
|
|
virtual void DestroyDrawContext() {
|
|
|
|
if (!draw_) {
|
2018-03-24 11:44:53 +00:00
|
|
|
return;
|
2018-03-26 16:37:34 +00:00
|
|
|
}
|
2018-03-24 11:44:53 +00:00
|
|
|
delete draw_;
|
|
|
|
draw_ = nullptr;
|
|
|
|
}
|
|
|
|
Draw::DrawContext *GetDrawContext() override { return draw_; }
|
|
|
|
|
|
|
|
static LibretroGraphicsContext *CreateGraphicsContext();
|
|
|
|
|
|
|
|
static retro_video_refresh_t video_cb;
|
|
|
|
|
2018-03-26 16:37:34 +00:00
|
|
|
protected:
|
2018-03-24 11:44:53 +00:00
|
|
|
Draw::DrawContext *draw_ = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LibretroHWRenderContext : public LibretroGraphicsContext {
|
2018-03-26 16:37:34 +00:00
|
|
|
public:
|
2018-03-24 11:44:53 +00:00
|
|
|
LibretroHWRenderContext(retro_hw_context_type context_type, unsigned version_major = 0, unsigned version_minor = 0);
|
2018-03-26 16:21:11 +00:00
|
|
|
bool Init(bool cache_context);
|
2018-03-24 11:44:53 +00:00
|
|
|
void SetRenderTarget() override {}
|
2018-03-26 16:37:34 +00:00
|
|
|
void SwapBuffers() override {
|
2024-06-01 02:38:43 +00:00
|
|
|
video_cb(RETRO_HW_FRAME_BUFFER_VALID, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, 0);
|
2018-03-24 11:44:53 +00:00
|
|
|
}
|
|
|
|
virtual void ContextReset();
|
|
|
|
virtual void ContextDestroy();
|
|
|
|
|
2018-03-26 16:37:34 +00:00
|
|
|
protected:
|
2018-03-24 11:44:53 +00:00
|
|
|
retro_hw_render_callback hw_render_ = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
class LibretroD3D9Context : public LibretroHWRenderContext {
|
2018-03-26 16:37:34 +00:00
|
|
|
public:
|
2018-03-24 11:44:53 +00:00
|
|
|
LibretroD3D9Context() : LibretroHWRenderContext(RETRO_HW_CONTEXT_DIRECT3D, 9) {}
|
|
|
|
bool Init() override { return false; }
|
2018-03-24 12:39:05 +00:00
|
|
|
|
2018-03-26 16:37:34 +00:00
|
|
|
void CreateDrawContext() override {
|
2018-03-24 21:47:12 +00:00
|
|
|
draw_ = Draw::T3DCreateDX9Context(nullptr, nullptr, 0, nullptr, nullptr);
|
2018-03-24 12:39:05 +00:00
|
|
|
draw_->CreatePresets();
|
|
|
|
}
|
|
|
|
|
2018-03-24 11:44:53 +00:00
|
|
|
GPUCore GetGPUCore() override { return GPUCORE_DIRECTX9; }
|
|
|
|
const char *Ident() override { return "DirectX 9"; }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class LibretroSoftwareContext : public LibretroGraphicsContext {
|
2018-03-26 16:37:34 +00:00
|
|
|
public:
|
2018-03-24 11:44:53 +00:00
|
|
|
LibretroSoftwareContext() {}
|
|
|
|
bool Init() override { return true; }
|
2024-05-31 02:26:12 +00:00
|
|
|
void SwapBuffers() override {
|
|
|
|
GPUDebugBuffer buf;
|
2024-06-02 21:08:32 +00:00
|
|
|
u16 w = NATIVEWIDTH;
|
|
|
|
u16 h = NATIVEHEIGHT;
|
2024-06-01 02:38:43 +00:00
|
|
|
gpuDebug->GetOutputFramebuffer(buf);
|
2024-06-02 21:08:32 +00:00
|
|
|
const std::vector<u32> pixels = TranslateDebugBufferToCompare(&buf, w, h);
|
|
|
|
memcpy(soft_bmp, pixels.data(), SOFT_BMP_SIZE);
|
|
|
|
u32 offset = g_Config.bDisplayCropTo16x9 ? w << 1 : 0;
|
|
|
|
h -= g_Config.bDisplayCropTo16x9 ? 2 : 0;
|
|
|
|
video_cb(soft_bmp + offset, w, h, w << 2);
|
2024-05-31 02:26:12 +00:00
|
|
|
}
|
2018-03-24 11:44:53 +00:00
|
|
|
GPUCore GetGPUCore() override { return GPUCORE_SOFTWARE; }
|
|
|
|
const char *Ident() override { return "Software"; }
|
2024-06-02 21:08:32 +00:00
|
|
|
|
|
|
|
u16 soft_bmp[SOFT_BMP_SIZE] = {0};
|
2018-03-24 11:44:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace Libretro {
|
|
|
|
extern LibretroGraphicsContext *ctx;
|
|
|
|
extern retro_environment_t environ_cb;
|
2024-06-02 21:08:32 +00:00
|
|
|
extern retro_hw_context_type backend;
|
2018-03-24 11:44:53 +00:00
|
|
|
|
2018-03-26 16:37:34 +00:00
|
|
|
enum class EmuThreadState {
|
2018-03-24 11:44:53 +00:00
|
|
|
DISABLED,
|
|
|
|
START_REQUESTED,
|
|
|
|
RUNNING,
|
|
|
|
PAUSE_REQUESTED,
|
|
|
|
PAUSED,
|
|
|
|
QUIT_REQUESTED,
|
|
|
|
STOPPED,
|
|
|
|
};
|
|
|
|
extern bool useEmuThread;
|
|
|
|
extern std::atomic<EmuThreadState> emuThreadState;
|
|
|
|
void EmuThreadStart();
|
|
|
|
void EmuThreadStop();
|
|
|
|
void EmuThreadPause();
|
2018-03-26 16:37:34 +00:00
|
|
|
} // namespace Libretro
|