[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 {
|
||||
|
||||
#if XE_OPTION_PROFILING_UI
|
||||
ui::Window* Profiler::window_ = nullptr;
|
||||
std::unique_ptr<ui::MicroprofileDrawer> 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<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::set_context(ui::GraphicsContext* graphics_context) {
|
||||
drawer_ = std::make_unique<ui::MicroprofileDrawer>(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
|
||||
}
|
||||
|
|
|
@ -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<ui::MicroprofileDrawer> drawer_;
|
||||
};
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -28,14 +28,15 @@ 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,
|
||||
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:
|
||||
|
@ -46,7 +47,6 @@ class MicroprofileDrawer {
|
|||
void EndVertices();
|
||||
void Flush();
|
||||
|
||||
Window* window_ = nullptr;
|
||||
GraphicsContext* graphics_context_ = nullptr;
|
||||
|
||||
std::vector<ImmediateVertex> vertices_;
|
||||
|
|
Loading…
Reference in New Issue