renderer_base.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-FileCopyrightText: 2014 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <atomic>
  5. #include <functional>
  6. #include <memory>
  7. #include "common/common_funcs.h"
  8. #include "common/common_types.h"
  9. #include "core/frontend/framebuffer_layout.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. // Screenshot
  19. std::atomic<bool> screenshot_requested{false};
  20. void* screenshot_bits{};
  21. std::function<void(bool)> screenshot_complete_callback;
  22. Layout::FramebufferLayout screenshot_framebuffer_layout;
  23. };
  24. class RendererBase {
  25. public:
  26. YUZU_NON_COPYABLE(RendererBase);
  27. YUZU_NON_MOVEABLE(RendererBase);
  28. explicit RendererBase(Core::Frontend::EmuWindow& window,
  29. std::unique_ptr<Core::Frontend::GraphicsContext> context);
  30. virtual ~RendererBase();
  31. /// Finalize rendering the guest frame and draw into the presentation texture
  32. virtual void Composite(std::span<const Tegra::FramebufferConfig> layers) = 0;
  33. /// Get the tiled applet layer capture buffer
  34. virtual std::vector<u8> GetAppletCaptureBuffer() = 0;
  35. [[nodiscard]] virtual RasterizerInterface* ReadRasterizer() = 0;
  36. [[nodiscard]] virtual std::string GetDeviceVendor() const = 0;
  37. // Getter/setter functions:
  38. // ------------------------
  39. [[nodiscard]] f32 GetCurrentFPS() const {
  40. return m_current_fps;
  41. }
  42. [[nodiscard]] int GetCurrentFrame() const {
  43. return m_current_frame;
  44. }
  45. [[nodiscard]] Core::Frontend::GraphicsContext& Context() {
  46. return *context;
  47. }
  48. [[nodiscard]] const Core::Frontend::GraphicsContext& Context() const {
  49. return *context;
  50. }
  51. [[nodiscard]] Core::Frontend::EmuWindow& GetRenderWindow() {
  52. return render_window;
  53. }
  54. [[nodiscard]] const Core::Frontend::EmuWindow& GetRenderWindow() const {
  55. return render_window;
  56. }
  57. [[nodiscard]] RendererSettings& Settings() {
  58. return renderer_settings;
  59. }
  60. [[nodiscard]] const RendererSettings& Settings() const {
  61. return renderer_settings;
  62. }
  63. /// Refreshes the settings common to all renderers
  64. void RefreshBaseSettings();
  65. /// Returns true if a screenshot is being processed
  66. bool IsScreenshotPending() const;
  67. /// Request a screenshot of the next frame
  68. void RequestScreenshot(void* data, std::function<void(bool)> callback,
  69. const Layout::FramebufferLayout& layout);
  70. protected:
  71. Core::Frontend::EmuWindow& render_window; ///< Reference to the render window handle.
  72. std::unique_ptr<Core::Frontend::GraphicsContext> context;
  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