[Base] Remove ui::Window references from Profiler
This commit is contained in:
parent
e309e6ce6d
commit
b440246ca6
|
@ -47,7 +47,6 @@ DEFINE_bool(show_profiler, false, "Show profiling UI by default.");
|
||||||
namespace xe {
|
namespace xe {
|
||||||
|
|
||||||
#if XE_OPTION_PROFILING_UI
|
#if XE_OPTION_PROFILING_UI
|
||||||
ui::Window* Profiler::window_ = nullptr;
|
|
||||||
std::unique_ptr<ui::MicroprofileDrawer> Profiler::drawer_ = nullptr;
|
std::unique_ptr<ui::MicroprofileDrawer> Profiler::drawer_ = nullptr;
|
||||||
#endif // XE_OPTION_PROFILING_UI
|
#endif // XE_OPTION_PROFILING_UI
|
||||||
|
|
||||||
|
@ -97,7 +96,6 @@ void Profiler::Dump() {
|
||||||
|
|
||||||
void Profiler::Shutdown() {
|
void Profiler::Shutdown() {
|
||||||
drawer_.reset();
|
drawer_.reset();
|
||||||
window_ = nullptr;
|
|
||||||
MicroProfileShutdown();
|
MicroProfileShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,72 +174,19 @@ void Profiler::TogglePause() {}
|
||||||
|
|
||||||
#endif // XE_OPTION_PROFILING_UI
|
#endif // XE_OPTION_PROFILING_UI
|
||||||
|
|
||||||
void Profiler::set_window(ui::Window* window) {
|
void Profiler::set_context(ui::GraphicsContext* graphics_context) {
|
||||||
assert_null(window_);
|
drawer_ = std::make_unique<ui::MicroprofileDrawer>(graphics_context);
|
||||||
if (!window) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
window_ = window;
|
|
||||||
drawer_ = std::make_unique<ui::MicroprofileDrawer>(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::Present() {
|
void Profiler::Present(uint32_t width, uint32_t height) {
|
||||||
SCOPE_profile_cpu_f("internal");
|
SCOPE_profile_cpu_f("internal");
|
||||||
#if XE_OPTION_PROFILING_UI
|
#if XE_OPTION_PROFILING_UI
|
||||||
if (!window_ || !drawer_) {
|
if (!drawer_) {
|
||||||
|
assert_always();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
drawer_->Begin();
|
drawer_->Begin(width, height);
|
||||||
MicroProfileDraw(window_->scaled_width(), window_->scaled_height());
|
MicroProfileDraw(width, height);
|
||||||
drawer_->End();
|
drawer_->End();
|
||||||
#endif // XE_OPTION_PROFILING_UI
|
#endif // XE_OPTION_PROFILING_UI
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace ui {
|
namespace ui {
|
||||||
class MicroprofileDrawer;
|
class MicroprofileDrawer;
|
||||||
class Window;
|
class GraphicsContext;
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
} // namespace xe
|
} // namespace xe
|
||||||
|
|
||||||
|
@ -180,17 +180,16 @@ class Profiler {
|
||||||
static void ToggleDisplay();
|
static void ToggleDisplay();
|
||||||
static void TogglePause();
|
static void TogglePause();
|
||||||
|
|
||||||
// Initializes input and drawing with the given display.
|
// Initializes drawing with the given context.
|
||||||
static void set_window(ui::Window* window);
|
static void set_context(ui::GraphicsContext* graphics_context);
|
||||||
// Gets the current display, if any.
|
// Gets the current display, if any.
|
||||||
static ui::MicroprofileDrawer* drawer() { return drawer_.get(); }
|
static ui::MicroprofileDrawer* drawer() { return drawer_.get(); }
|
||||||
// Presents the profiler to the bound display, if any.
|
// 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
|
// Starts a new frame on the profiler
|
||||||
static void Flip();
|
static void Flip();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static ui::Window* window_;
|
|
||||||
static std::unique_ptr<ui::MicroprofileDrawer> drawer_;
|
static std::unique_ptr<ui::MicroprofileDrawer> drawer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -123,10 +123,8 @@ const uint8_t kFontData[] = {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
};
|
};
|
||||||
|
|
||||||
MicroprofileDrawer::MicroprofileDrawer(xe::ui::Window* window)
|
MicroprofileDrawer::MicroprofileDrawer(GraphicsContext* graphics_context)
|
||||||
: window_(window),
|
: graphics_context_(graphics_context), vertices_(kMaxVertices) {
|
||||||
graphics_context_(window->context()),
|
|
||||||
vertices_(kMaxVertices) {
|
|
||||||
SetupFont();
|
SetupFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,9 +175,8 @@ void MicroprofileDrawer::SetupFont() {
|
||||||
|
|
||||||
MicroprofileDrawer::~MicroprofileDrawer() = default;
|
MicroprofileDrawer::~MicroprofileDrawer() = default;
|
||||||
|
|
||||||
void MicroprofileDrawer::Begin() {
|
void MicroprofileDrawer::Begin(uint32_t width, uint32_t height) {
|
||||||
graphics_context_->immediate_drawer()->Begin(window_->scaled_width(),
|
graphics_context_->immediate_drawer()->Begin(width, height);
|
||||||
window_->scaled_height());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MicroprofileDrawer::End() {
|
void MicroprofileDrawer::End() {
|
||||||
|
|
|
@ -28,15 +28,16 @@ class MicroprofileDrawer {
|
||||||
kFlat = 1, // MicroProfileBoxTypeFlat
|
kFlat = 1, // MicroProfileBoxTypeFlat
|
||||||
};
|
};
|
||||||
|
|
||||||
MicroprofileDrawer(Window* window);
|
MicroprofileDrawer(GraphicsContext* graphics_context);
|
||||||
~MicroprofileDrawer();
|
~MicroprofileDrawer();
|
||||||
|
|
||||||
void Begin();
|
virtual void Begin(uint32_t width, uint32_t height);
|
||||||
void End();
|
virtual void End();
|
||||||
void DrawBox(int x0, int y0, int x1, int y1, uint32_t color, BoxType type);
|
virtual void DrawBox(int x0, int y0, int x1, int y1, uint32_t color,
|
||||||
void DrawLine2D(uint32_t count, float* vertices, uint32_t color);
|
BoxType type);
|
||||||
void DrawText(int x, int y, uint32_t color, const char* text,
|
virtual void DrawLine2D(uint32_t count, float* vertices, uint32_t color);
|
||||||
int text_length);
|
virtual void DrawText(int x, int y, uint32_t color, const char* text,
|
||||||
|
int text_length);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetupFont();
|
void SetupFont();
|
||||||
|
@ -46,7 +47,6 @@ class MicroprofileDrawer {
|
||||||
void EndVertices();
|
void EndVertices();
|
||||||
void Flush();
|
void Flush();
|
||||||
|
|
||||||
Window* window_ = nullptr;
|
|
||||||
GraphicsContext* graphics_context_ = nullptr;
|
GraphicsContext* graphics_context_ = nullptr;
|
||||||
|
|
||||||
std::vector<ImmediateVertex> vertices_;
|
std::vector<ImmediateVertex> vertices_;
|
||||||
|
|
Loading…
Reference in New Issue