renderer_base.h
1 // Copyright 2014 Citra Emulator Project 2 // Licensed under GPLv2 or any later version 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include "common/common_types.h" 8 #include "core/frontend/framebuffer_layout.h" 9 #include "video_core/rasterizer_interface.h" 10 11 namespace Frontend { 12 class EmuWindow; 13 } 14 15 namespace Core { 16 class System; 17 } 18 19 namespace VideoCore { 20 21 enum class ScreenId : u32 { 22 TopLeft, 23 TopRight, 24 Bottom, 25 }; 26 27 struct RendererSettings { 28 // Screenshot 29 std::atomic_bool screenshot_requested{false}; 30 void* screenshot_bits{}; 31 std::function<void(bool)> screenshot_complete_callback; 32 Layout::FramebufferLayout screenshot_framebuffer_layout; 33 // Renderer 34 std::atomic_bool bg_color_update_requested{false}; 35 std::atomic_bool shader_update_requested{false}; 36 }; 37 38 class RendererBase : NonCopyable { 39 public: 40 explicit RendererBase(Core::System& system, Frontend::EmuWindow& window, 41 Frontend::EmuWindow* secondary_window); 42 virtual ~RendererBase(); 43 44 /// Returns the rasterizer owned by the renderer 45 virtual VideoCore::RasterizerInterface* Rasterizer() = 0; 46 47 /// Finalize rendering the guest frame and draw into the presentation texture 48 virtual void SwapBuffers() = 0; 49 50 /// Draws the latest frame to the window waiting timeout_ms for a frame to arrive (Renderer 51 /// specific implementation) 52 virtual void TryPresent(int timeout_ms, bool is_secondary) = 0; 53 virtual void TryPresent(int timeout_ms) { 54 TryPresent(timeout_ms, false); 55 } 56 57 /// Prepares for video dumping (e.g. create necessary buffers, etc) 58 virtual void PrepareVideoDumping() {} 59 60 /// Cleans up after video dumping is ended 61 virtual void CleanupVideoDumping() {} 62 63 /// Synchronizes fixed function renderer state 64 virtual void Sync() {} 65 66 /// This is called to notify the rendering backend of a surface change 67 virtual void NotifySurfaceChanged() {} 68 69 /// Returns the resolution scale factor relative to the native 3DS screen resolution 70 u32 GetResolutionScaleFactor(); 71 72 /// Updates the framebuffer layout of the contained render window handle. 73 void UpdateCurrentFramebufferLayout(bool is_portrait_mode = {}); 74 75 /// Ends the current frame 76 void EndFrame(); 77 78 f32 GetCurrentFPS() const { 79 return current_fps; 80 } 81 82 s32 GetCurrentFrame() const { 83 return current_frame; 84 } 85 86 Frontend::EmuWindow& GetRenderWindow() { 87 return render_window; 88 } 89 90 const Frontend::EmuWindow& GetRenderWindow() const { 91 return render_window; 92 } 93 94 [[nodiscard]] RendererSettings& Settings() { 95 return settings; 96 } 97 98 [[nodiscard]] const RendererSettings& Settings() const { 99 return settings; 100 } 101 102 /// Returns true if a screenshot is being processed 103 [[nodiscard]] bool IsScreenshotPending() const; 104 105 /// Request a screenshot of the next frame 106 void RequestScreenshot(void* data, std::function<void(bool)> callback, 107 const Layout::FramebufferLayout& layout); 108 109 protected: 110 Core::System& system; 111 RendererSettings settings; 112 Frontend::EmuWindow& render_window; ///< Reference to the render window handle. 113 Frontend::EmuWindow* secondary_window; ///< Reference to the secondary render window handle. 114 f32 current_fps = 0.0f; ///< Current framerate, should be set by the renderer 115 s32 current_frame = 0; ///< Current frame, should be set by the renderer 116 }; 117 118 } // namespace VideoCore