renderer_base.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. }
  15. namespace VideoCore {
  16. struct RendererSettings {
  17. std::atomic_bool use_framelimiter{false};
  18. std::atomic_bool set_background_color{false};
  19. // Screenshot
  20. std::atomic<bool> screenshot_requested{false};
  21. void* screenshot_bits;
  22. std::function<void()> screenshot_complete_callback;
  23. Layout::FramebufferLayout screenshot_framebuffer_layout;
  24. };
  25. class RendererBase : NonCopyable {
  26. public:
  27. explicit RendererBase(Core::Frontend::EmuWindow& window);
  28. virtual ~RendererBase();
  29. /// Initialize the renderer
  30. virtual bool Init() = 0;
  31. /// Shutdown the renderer
  32. virtual void ShutDown() = 0;
  33. /// Finalize rendering the guest frame and draw into the presentation texture
  34. virtual void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) = 0;
  35. /// Draws the latest frame to the window waiting timeout_ms for a frame to arrive (Renderer
  36. /// specific implementation)
  37. /// Returns true if a frame was drawn
  38. virtual bool TryPresent(int timeout_ms) = 0;
  39. // Getter/setter functions:
  40. // ------------------------
  41. f32 GetCurrentFPS() const {
  42. return m_current_fps;
  43. }
  44. int GetCurrentFrame() const {
  45. return m_current_frame;
  46. }
  47. RasterizerInterface& Rasterizer() {
  48. return *rasterizer;
  49. }
  50. const RasterizerInterface& Rasterizer() const {
  51. return *rasterizer;
  52. }
  53. Core::Frontend::EmuWindow& GetRenderWindow() {
  54. return render_window;
  55. }
  56. const Core::Frontend::EmuWindow& GetRenderWindow() const {
  57. return render_window;
  58. }
  59. RendererSettings& Settings() {
  60. return renderer_settings;
  61. }
  62. const RendererSettings& Settings() const {
  63. return renderer_settings;
  64. }
  65. /// Refreshes the settings common to all renderers
  66. void RefreshBaseSettings();
  67. /// Request a screenshot of the next frame
  68. void RequestScreenshot(void* data, std::function<void()> callback,
  69. const Layout::FramebufferLayout& layout);
  70. protected:
  71. Core::Frontend::EmuWindow& render_window; ///< Reference to the render window handle.
  72. std::unique_ptr<RasterizerInterface> rasterizer;
  73. f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer
  74. int m_current_frame = 0; ///< Current frame, should be set by the renderer
  75. RendererSettings renderer_settings;
  76. private:
  77. /// Updates the framebuffer layout of the contained render window handle.
  78. void UpdateCurrentFramebufferLayout();
  79. };
  80. } // namespace VideoCore