From b440246ca64ba1c807428f24e9fc9645bc65ba5d Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Sun, 17 Jun 2018 15:47:36 -0500 Subject: [PATCH] [Base] Remove ui::Window references from Profiler --- src/xenia/base/profiling.cc | 69 +++-------------------------- src/xenia/base/profiling.h | 9 ++-- src/xenia/ui/microprofile_drawer.cc | 11 ++--- src/xenia/ui/microprofile_drawer.h | 16 +++---- 4 files changed, 23 insertions(+), 82 deletions(-) diff --git a/src/xenia/base/profiling.cc b/src/xenia/base/profiling.cc index 073adaa82..a3c4b7b90 100644 --- a/src/xenia/base/profiling.cc +++ b/src/xenia/base/profiling.cc @@ -47,7 +47,6 @@ DEFINE_bool(show_profiler, false, "Show profiling UI by default."); namespace xe { #if XE_OPTION_PROFILING_UI -ui::Window* Profiler::window_ = nullptr; std::unique_ptr Profiler::drawer_ = nullptr; #endif // XE_OPTION_PROFILING_UI @@ -97,7 +96,6 @@ void Profiler::Dump() { void Profiler::Shutdown() { drawer_.reset(); - window_ = nullptr; MicroProfileShutdown(); } @@ -176,72 +174,19 @@ void Profiler::TogglePause() {} #endif // XE_OPTION_PROFILING_UI -void Profiler::set_window(ui::Window* window) { - assert_null(window_); - if (!window) { - return; - } - window_ = window; - drawer_ = std::make_unique(window); - - window_->on_painted.AddListener([](ui::UIEvent* e) { Profiler::Present(); }); - - // Pass through mouse events. - window_->on_mouse_down.AddListener([](ui::MouseEvent* e) { - if (Profiler::is_visible()) { - Profiler::OnMouseDown(e->button() == ui::MouseEvent::Button::kLeft, - e->button() == ui::MouseEvent::Button::kRight); - e->set_handled(true); - window_->Invalidate(); - } - }); - window_->on_mouse_up.AddListener([](ui::MouseEvent* e) { - if (Profiler::is_visible()) { - Profiler::OnMouseUp(); - e->set_handled(true); - window_->Invalidate(); - } - }); - window_->on_mouse_move.AddListener([](ui::MouseEvent* e) { - if (Profiler::is_visible()) { - Profiler::OnMouseMove(e->x(), e->y()); - e->set_handled(true); - window_->Invalidate(); - } - }); - window_->on_mouse_wheel.AddListener([](ui::MouseEvent* e) { - if (Profiler::is_visible()) { - Profiler::OnMouseWheel(e->x(), e->y(), -e->dy()); - e->set_handled(true); - window_->Invalidate(); - } - }); - - // Watch for toggle/mode keys and such. - window_->on_key_down.AddListener([](ui::KeyEvent* e) { - if (Profiler::is_visible()) { - Profiler::OnKeyDown(e->key_code()); - e->set_handled(true); - window_->Invalidate(); - } - }); - window_->on_key_up.AddListener([](ui::KeyEvent* e) { - if (Profiler::is_visible()) { - Profiler::OnKeyUp(e->key_code()); - e->set_handled(true); - window_->Invalidate(); - } - }); +void Profiler::set_context(ui::GraphicsContext* graphics_context) { + drawer_ = std::make_unique(graphics_context); } -void Profiler::Present() { +void Profiler::Present(uint32_t width, uint32_t height) { SCOPE_profile_cpu_f("internal"); #if XE_OPTION_PROFILING_UI - if (!window_ || !drawer_) { + if (!drawer_) { + assert_always(); return; } - drawer_->Begin(); - MicroProfileDraw(window_->scaled_width(), window_->scaled_height()); + drawer_->Begin(width, height); + MicroProfileDraw(width, height); drawer_->End(); #endif // XE_OPTION_PROFILING_UI } diff --git a/src/xenia/base/profiling.h b/src/xenia/base/profiling.h index d6cc42d41..e47de64f2 100644 --- a/src/xenia/base/profiling.h +++ b/src/xenia/base/profiling.h @@ -30,7 +30,7 @@ namespace xe { namespace ui { class MicroprofileDrawer; -class Window; +class GraphicsContext; } // namespace ui } // namespace xe @@ -180,17 +180,16 @@ class Profiler { static void ToggleDisplay(); static void TogglePause(); - // Initializes input and drawing with the given display. - static void set_window(ui::Window* window); + // Initializes drawing with the given context. + static void set_context(ui::GraphicsContext* graphics_context); // Gets the current display, if any. static ui::MicroprofileDrawer* drawer() { return drawer_.get(); } // Presents the profiler to the bound display, if any. - static void Present(); + static void Present(uint32_t width, uint32_t height); // Starts a new frame on the profiler static void Flip(); private: - static ui::Window* window_; static std::unique_ptr drawer_; }; diff --git a/src/xenia/ui/microprofile_drawer.cc b/src/xenia/ui/microprofile_drawer.cc index c73d0a18d..c4520db81 100644 --- a/src/xenia/ui/microprofile_drawer.cc +++ b/src/xenia/ui/microprofile_drawer.cc @@ -123,10 +123,8 @@ const uint8_t kFontData[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -MicroprofileDrawer::MicroprofileDrawer(xe::ui::Window* window) - : window_(window), - graphics_context_(window->context()), - vertices_(kMaxVertices) { +MicroprofileDrawer::MicroprofileDrawer(GraphicsContext* graphics_context) + : graphics_context_(graphics_context), vertices_(kMaxVertices) { SetupFont(); } @@ -177,9 +175,8 @@ void MicroprofileDrawer::SetupFont() { MicroprofileDrawer::~MicroprofileDrawer() = default; -void MicroprofileDrawer::Begin() { - graphics_context_->immediate_drawer()->Begin(window_->scaled_width(), - window_->scaled_height()); +void MicroprofileDrawer::Begin(uint32_t width, uint32_t height) { + graphics_context_->immediate_drawer()->Begin(width, height); } void MicroprofileDrawer::End() { diff --git a/src/xenia/ui/microprofile_drawer.h b/src/xenia/ui/microprofile_drawer.h index 1f285e1bc..9d2d59ad2 100644 --- a/src/xenia/ui/microprofile_drawer.h +++ b/src/xenia/ui/microprofile_drawer.h @@ -28,15 +28,16 @@ class MicroprofileDrawer { kFlat = 1, // MicroProfileBoxTypeFlat }; - MicroprofileDrawer(Window* window); + MicroprofileDrawer(GraphicsContext* graphics_context); ~MicroprofileDrawer(); - void Begin(); - void End(); - void DrawBox(int x0, int y0, int x1, int y1, uint32_t color, BoxType type); - void DrawLine2D(uint32_t count, float* vertices, uint32_t color); - void DrawText(int x, int y, uint32_t color, const char* text, - int text_length); + virtual void Begin(uint32_t width, uint32_t height); + virtual void End(); + virtual void DrawBox(int x0, int y0, int x1, int y1, uint32_t color, + BoxType type); + virtual void DrawLine2D(uint32_t count, float* vertices, uint32_t color); + virtual void DrawText(int x, int y, uint32_t color, const char* text, + int text_length); protected: void SetupFont(); @@ -46,7 +47,6 @@ class MicroprofileDrawer { void EndVertices(); void Flush(); - Window* window_ = nullptr; GraphicsContext* graphics_context_ = nullptr; std::vector vertices_;