CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/libretro/LibretroGraphicsContext.h
Views: 1401
#pragma once1#include <atomic>23#include "libretro/libretro.h"4#include "Common/GraphicsContext.h"5#include "Common/GPU/thin3d_create.h"67#include "Core/Config.h"8#include "Core/System.h"9#include "GPU/GPUState.h"10#include "GPU/Software/SoftGpu.h"11#include "headless/Compare.h"12#include "Common/Data/Convert/ColorConv.h"1314#define NATIVEWIDTH 48015#define NATIVEHEIGHT 27216#define SOFT_BMP_SIZE NATIVEWIDTH * NATIVEHEIGHT * 41718class LibretroGraphicsContext : public GraphicsContext {19public:20LibretroGraphicsContext() {}21~LibretroGraphicsContext() override { Shutdown(); }2223virtual bool Init() = 0;24virtual void SetRenderTarget() {}25virtual GPUCore GetGPUCore() = 0;26virtual const char *Ident() = 0;2728void Shutdown() override {29DestroyDrawContext();30}31virtual void SwapBuffers() = 0;32void Resize() override {}3334virtual void GotBackbuffer();35virtual void LostBackbuffer();3637virtual void CreateDrawContext() {}38virtual void DestroyDrawContext() {39if (!draw_) {40return;41}42delete draw_;43draw_ = nullptr;44}45Draw::DrawContext *GetDrawContext() override { return draw_; }4647static LibretroGraphicsContext *CreateGraphicsContext();4849static retro_video_refresh_t video_cb;5051protected:52Draw::DrawContext *draw_ = nullptr;53};5455class LibretroHWRenderContext : public LibretroGraphicsContext {56public:57LibretroHWRenderContext(retro_hw_context_type context_type, unsigned version_major = 0, unsigned version_minor = 0);58bool Init(bool cache_context);59void SetRenderTarget() override {}60void SwapBuffers() override {61video_cb(RETRO_HW_FRAME_BUFFER_VALID, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, 0);62}63virtual void ContextReset();64virtual void ContextDestroy();6566protected:67retro_hw_render_callback hw_render_ = {};68};6970#ifdef _WIN3271class LibretroD3D9Context : public LibretroHWRenderContext {72public:73LibretroD3D9Context() : LibretroHWRenderContext(RETRO_HW_CONTEXT_DIRECT3D, 9) {}74bool Init() override { return false; }7576void CreateDrawContext() override {77draw_ = Draw::T3DCreateDX9Context(nullptr, nullptr, 0, nullptr, nullptr);78draw_->CreatePresets();79}8081GPUCore GetGPUCore() override { return GPUCORE_DIRECTX9; }82const char *Ident() override { return "DirectX 9"; }83};84#endif8586class LibretroSoftwareContext : public LibretroGraphicsContext {87public:88LibretroSoftwareContext() {}89bool Init() override { return true; }90void SwapBuffers() override {91GPUDebugBuffer buf;92u16 w = NATIVEWIDTH;93u16 h = NATIVEHEIGHT;94gpuDebug->GetOutputFramebuffer(buf);95const std::vector<u32> pixels = TranslateDebugBufferToCompare(&buf, w, h);96memcpy(soft_bmp, pixels.data(), SOFT_BMP_SIZE);97u32 offset = g_Config.bDisplayCropTo16x9 ? w << 1 : 0;98h -= g_Config.bDisplayCropTo16x9 ? 2 : 0;99video_cb(soft_bmp + offset, w, h, w << 2);100}101GPUCore GetGPUCore() override { return GPUCORE_SOFTWARE; }102const char *Ident() override { return "Software"; }103104u16 soft_bmp[SOFT_BMP_SIZE] = {0};105};106107namespace Libretro {108extern LibretroGraphicsContext *ctx;109extern retro_environment_t environ_cb;110extern retro_hw_context_type backend;111112enum class EmuThreadState {113DISABLED,114START_REQUESTED,115RUNNING,116PAUSE_REQUESTED,117PAUSED,118QUIT_REQUESTED,119STOPPED,120};121extern bool useEmuThread;122extern std::atomic<EmuThreadState> emuThreadState;123void EmuThreadStart();124void EmuThreadStop();125void EmuThreadPause();126} // namespace Libretro127128129