[Base] Remove ui::Window references from Profiler

This commit is contained in:
Dr. Chat 2018-06-17 15:47:36 -05:00
parent e309e6ce6d
commit b440246ca6
4 changed files with 23 additions and 82 deletions

View File

@ -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
}

View File

@ -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_;
};

View File

@ -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() {

View File

@ -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<ImmediateVertex> vertices_;