Debian Codegraph @

Source/Core/VideoCommon/OnScreenUI.h

raw symbols SCIP
1 // Copyright 2023 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <map>
7 #include <memory>
8 #include <mutex>
9 #include <span>
10 #include <vector>
11
12 #include "Common/CommonTypes.h"
13 #include "VideoCommon/OnScreenUIKeyMap.h"
14
15 class NativeVertexFormat;
16 class AbstractTexture;
17 class AbstractPipeline;
18 struct ImTextureData;
19
20 namespace VideoCommon
21 {
22 // OnScreenUI handles all the ImGui rendering.
23 class OnScreenUI
24 {
25 public:
26 OnScreenUI() = default;
27 ~OnScreenUI();
28
29 // ImGui initialization depends on being able to create textures and pipelines, so do it last.
30 bool Initialize(u32 width, u32 height, float scale);
31
32 // Returns a lock for the ImGui mutex, enabling data structures to be modified from outside.
33 // Use with care, only non-drawing functions should be called from outside the video thread,
34 // as the drawing is tied to a "frame".
35 std::unique_lock<std::mutex> GetImGuiLock();
36
37 bool IsReady() { return m_ready; }
38
39 // Sets up ImGui state for the next frame.
40 // This function itself acquires the ImGui lock, so it should not be held.
41 void BeginImGuiFrame(u32 width, u32 height);
42
43 // Same as above but without locking the ImGui lock.
44 void BeginImGuiFrameUnlocked(u32 width, u32 height);
45
46 // Renders ImGui windows to the currently-bound framebuffer.
47 // Should be called with the ImGui lock held.
48 void DrawImGui();
49
50 // Recompiles ImGui pipeline - call when stereo mode changes.
51 bool RecompileImGuiPipeline();
52
53 void SetScale(float backbuffer_scale);
54
55 void Finalize();
56
57 // Receive keyboard and mouse from QT
58 void SetKeyMap(const DolphinKeyMap& key_map);
59 void SetKey(u32 key, bool is_down, const char* chars);
60 void SetMousePos(float x, float y);
61 void SetMousePress(u32 button_mask);
62
63 private:
64 void DrawDebugText();
65 void DrawChallengesAndLeaderboards();
66 void UpdateImguiTexture(ImTextureData* tex);
67
68 // ImGui resources.
69 std::unique_ptr<NativeVertexFormat> m_imgui_vertex_format;
70 std::vector<std::unique_ptr<AbstractTexture>> m_imgui_textures;
71 std::unique_ptr<AbstractPipeline> m_imgui_pipeline;
72 std::map<u32, int> m_dolphin_to_imgui_map;
73 std::mutex m_imgui_mutex;
74 u64 m_imgui_last_frame_time = 0;
75
76 u32 m_backbuffer_width = 1;
77 u32 m_backbuffer_height = 1;
78 float m_backbuffer_scale = 1.0;
79
80 #ifdef USE_RETRO_ACHIEVEMENTS
81 std::map<int, std::unique_ptr<AbstractTexture>, std::less<>> m_challenge_texture_map;
82 #endif // USE_RETRO_ACHIEVEMENTS
83
84 bool m_ready = false;
85 };
86 } // namespace VideoCommon