1 // Copyright 2011 Dolphin Emulator Project
2 // Licensed under GPLv2+
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #include <memory>
8 #include <optional>
9 #include <string>
10 #include <vector>
11 
12 #include "Common/CommonTypes.h"
13 #include "Common/WindowSystemInfo.h"
14 #include "VideoCommon/PerfQueryBase.h"
15 
16 namespace MMIO
17 {
18 class Mapping;
19 }
20 class PointerWrap;
21 
22 enum class FieldType
23 {
24   Odd,
25   Even,
26 };
27 
28 enum class EFBAccessType
29 {
30   PeekZ,
31   PokeZ,
32   PeekColor,
33   PokeColor
34 };
35 
36 class VideoBackendBase
37 {
38 public:
~VideoBackendBase()39   virtual ~VideoBackendBase() {}
40   virtual bool Initialize(const WindowSystemInfo& wsi) = 0;
41   virtual void Shutdown() = 0;
42 
43   virtual std::string GetName() const = 0;
GetDisplayName()44   virtual std::string GetDisplayName() const { return GetName(); }
45   virtual void InitBackendInfo() = 0;
GetWarningMessage()46   virtual std::optional<std::string> GetWarningMessage() const { return {}; }
47 
48   // Prepares a native window for rendering. This is called on the main thread, or the
49   // thread which owns the window.
PrepareWindow(WindowSystemInfo & wsi)50   virtual void PrepareWindow(WindowSystemInfo& wsi) {}
51 
52   static std::string BadShaderFilename(const char* shader_stage, int counter);
53 
54   void Video_ExitLoop();
55 
56   void Video_BeginField(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u64 ticks);
57 
58   u32 Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 data);
59   u32 Video_GetQueryResult(PerfQueryType type);
60   u16 Video_GetBoundingBox(int index);
61 
62   static std::string GetDefaultBackendName();
63   static void PopulateList();
64   static void ClearList();
65   static void ActivateBackend(const std::string& name);
66 
67   // Fills the backend_info fields with the capabilities of the selected backend/device.
68   static void PopulateBackendInfo();
69   // Called by the UI thread when the graphics config is opened.
70   static void PopulateBackendInfoFromUI();
71 
72   // Wrapper function which pushes the event to the GPU thread.
73   void DoState(PointerWrap& p);
74 
75 protected:
76   void InitializeShared();
77   void ShutdownShared();
78 
79   bool m_initialized = false;
80 };
81 
82 extern std::vector<std::unique_ptr<VideoBackendBase>> g_available_video_backends;
83 extern VideoBackendBase* g_video_backend;
84