VideoBackendBase.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2011 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <memory>
  5. #include <optional>
  6. #include <string>
  7. #include <vector>
  8. #include "Common/CommonTypes.h"
  9. #include "Common/WindowSystemInfo.h"
  10. #include "VideoCommon/PerfQueryBase.h"
  11. namespace MMIO
  12. {
  13. class Mapping;
  14. }
  15. class PointerWrap;
  16. class AbstractGfx;
  17. class BoundingBox;
  18. class Renderer;
  19. class TextureCacheBase;
  20. class VertexManagerBase;
  21. enum class FieldType
  22. {
  23. Odd,
  24. Even,
  25. };
  26. enum class EFBAccessType
  27. {
  28. PeekZ,
  29. PokeZ,
  30. PeekColor,
  31. PokeColor
  32. };
  33. class VideoBackendBase
  34. {
  35. public:
  36. virtual ~VideoBackendBase() {}
  37. virtual bool Initialize(const WindowSystemInfo& wsi) = 0;
  38. virtual void Shutdown() = 0;
  39. virtual std::string GetName() const = 0;
  40. virtual std::string GetDisplayName() const { return GetName(); }
  41. virtual void InitBackendInfo(const WindowSystemInfo& wsi) = 0;
  42. virtual std::optional<std::string> GetWarningMessage() const { return {}; }
  43. // Prepares a native window for rendering. This is called on the main thread, or the
  44. // thread which owns the window.
  45. virtual void PrepareWindow(WindowSystemInfo& wsi) {}
  46. static std::string BadShaderFilename(const char* shader_stage, int counter);
  47. void Video_ExitLoop();
  48. void Video_OutputXFB(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u64 ticks);
  49. u32 Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 data);
  50. u32 Video_GetQueryResult(PerfQueryType type);
  51. u16 Video_GetBoundingBox(int index);
  52. static std::string GetDefaultBackendConfigName();
  53. static std::string GetDefaultBackendDisplayName();
  54. static const std::vector<std::unique_ptr<VideoBackendBase>>& GetAvailableBackends();
  55. static void ActivateBackend(const std::string& name);
  56. // Fills the backend_info fields with the capabilities of the selected backend/device.
  57. static void PopulateBackendInfo(const WindowSystemInfo& wsi);
  58. // Wrapper function which pushes the event to the GPU thread.
  59. void DoState(PointerWrap& p);
  60. protected:
  61. // For hardware backends
  62. bool InitializeShared(std::unique_ptr<AbstractGfx> gfx,
  63. std::unique_ptr<VertexManagerBase> vertex_manager,
  64. std::unique_ptr<PerfQueryBase> perf_query,
  65. std::unique_ptr<BoundingBox> bounding_box);
  66. // For software and null backends. Allows overriding the default Renderer and Texture Cache
  67. bool InitializeShared(std::unique_ptr<AbstractGfx> gfx,
  68. std::unique_ptr<VertexManagerBase> vertex_manager,
  69. std::unique_ptr<PerfQueryBase> perf_query,
  70. std::unique_ptr<BoundingBox> bounding_box,
  71. std::unique_ptr<Renderer> renderer,
  72. std::unique_ptr<TextureCacheBase> texture_cache);
  73. void ShutdownShared();
  74. bool m_initialized = false;
  75. };
  76. extern VideoBackendBase* g_video_backend;