renderer_base.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <atomic>
  6. #include <memory>
  7. #include <optional>
  8. #include "common/common_types.h"
  9. #include "core/frontend/emu_window.h"
  10. #include "video_core/gpu.h"
  11. #include "video_core/rasterizer_interface.h"
  12. namespace Core::Frontend {
  13. class EmuWindow;
  14. class GraphicsContext;
  15. } // namespace Core::Frontend
  16. namespace VideoCore {
  17. struct RendererSettings {
  18. std::atomic_bool use_framelimiter{false};
  19. std::atomic_bool set_background_color{false};
  20. // Screenshot
  21. std::atomic<bool> screenshot_requested{false};
  22. void* screenshot_bits{};
  23. std::function<void()> screenshot_complete_callback;
  24. Layout::FramebufferLayout screenshot_framebuffer_layout;
  25. };
  26. class RendererBase : NonCopyable {
  27. public:
  28. explicit RendererBase(Core::Frontend::EmuWindow& window,
  29. std::unique_ptr<Core::Frontend::GraphicsContext> context);
  30. virtual ~RendererBase();
  31. /// Initialize the renderer
  32. virtual bool Init() = 0;
  33. /// Shutdown the renderer
  34. virtual void ShutDown() = 0;
  35. /// Finalize rendering the guest frame and draw into the presentation texture
  36. virtual void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) = 0;
  37. /// Draws the latest frame to the window waiting timeout_ms for a frame to arrive (Renderer
  38. /// specific implementation)
  39. /// Returns true if a frame was drawn
  40. virtual bool TryPresent(int timeout_ms) = 0;
  41. // Getter/setter functions:
  42. // ------------------------
  43. f32 GetCurrentFPS() const {
  44. return m_current_fps;
  45. }
  46. int GetCurrentFrame() const {
  47. return m_current_frame;
  48. }
  49. RasterizerInterface& Rasterizer() {
  50. return *rasterizer;
  51. }
  52. const RasterizerInterface& Rasterizer() const {
  53. return *rasterizer;
  54. }
  55. Core::Frontend::GraphicsContext& Context() {
  56. return *context;
  57. }
  58. const Core::Frontend::GraphicsContext& Context() const {
  59. return *context;
  60. }
  61. Core::Frontend::EmuWindow& GetRenderWindow() {
  62. return render_window;
  63. }
  64. const Core::Frontend::EmuWindow& GetRenderWindow() const {
  65. return render_window;
  66. }
  67. RendererSettings& Settings() {
  68. return renderer_settings;
  69. }
  70. const RendererSettings& Settings() const {
  71. return renderer_settings;
  72. }
  73. /// Refreshes the settings common to all renderers
  74. void RefreshBaseSettings();
  75. /// Request a screenshot of the next frame
  76. void RequestScreenshot(void* data, std::function<void()> callback,
  77. const Layout::FramebufferLayout& layout);
  78. protected:
  79. Core::Frontend::EmuWindow& render_window; ///< Reference to the render window handle.
  80. std::unique_ptr<RasterizerInterface> rasterizer;
  81. std::unique_ptr<Core::Frontend::GraphicsContext> context;
  82. f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer
  83. int m_current_frame = 0; ///< Current frame, should be set by the renderer
  84. RendererSettings renderer_settings;
  85. private:
  86. /// Updates the framebuffer layout of the contained render window handle.
  87. void UpdateCurrentFramebufferLayout();
  88. };
  89. } // namespace VideoCore