[Bf-blender-cvs] [cc682ef2926] profiler-editor: don't compute y positions on every redraw
Jacques Lucke
noreply at git.blender.org
Sun May 2 15:50:34 CEST 2021
Commit: cc682ef2926af1d0fcbdaa287d157bae8a0e8d44
Author: Jacques Lucke
Date: Sun May 2 14:58:19 2021 +0200
Branches: profiler-editor
https://developer.blender.org/rBcc682ef2926af1d0fcbdaa287d157bae8a0e8d44
don't compute y positions on every redraw
===================================================================
M source/blender/editors/space_profiler/profiler_draw.cc
M source/blender/editors/space_profiler/profiler_layout.cc
M source/blender/editors/space_profiler/profiler_layout.hh
===================================================================
diff --git a/source/blender/editors/space_profiler/profiler_draw.cc b/source/blender/editors/space_profiler/profiler_draw.cc
index 794f6f52dc8..018f1c321b4 100644
--- a/source/blender/editors/space_profiler/profiler_draw.cc
+++ b/source/blender/editors/space_profiler/profiler_draw.cc
@@ -49,8 +49,6 @@ class ProfilerDrawer {
SpaceProfiler *sprofiler_;
SpaceProfiler_Runtime *runtime_;
ProfilerLayout *profiler_layout_;
- int row_height_;
- int parallel_padding_;
public:
ProfilerDrawer(const bContext *C, ARegion *region) : C(C), region_(region)
@@ -61,19 +59,16 @@ class ProfilerDrawer {
if (!runtime_->profiler_layout) {
runtime_->profiler_layout = std::make_unique<ProfilerLayout>();
}
- profile::ProfileListener::flush_to_all();
+ if (runtime_->profile_listener) {
+ profile::ProfileListener::flush_to_all();
+ }
profiler_layout_ = runtime_->profiler_layout.get();
-
- row_height_ = UI_UNIT_Y;
- parallel_padding_ = UI_UNIT_Y * 0.2f;
}
void draw()
{
UI_ThemeClearColor(TH_BACK);
- this->compute_vertical_extends_of_all_nodes();
-
Vector<ProfileNode *> nodes_to_draw;
this->find_all_nodes_to_draw(nodes_to_draw);
this->draw_nodes(nodes_to_draw);
@@ -93,39 +88,6 @@ class ProfilerDrawer {
UI_view2d_scrollers_draw(®ion_->v2d, nullptr);
}
- void compute_vertical_extends_of_all_nodes()
- {
- BLI_PROFILE_SCOPE(__func__);
- int top_y = region_->winy - region_->v2d.cur.ymax;
- for (Span<ProfileNode *> nodes : profiler_layout_->root_nodes()) {
- top_y = this->compute_vertical_extends_of_nodes(nodes, top_y);
- top_y -= parallel_padding_;
- }
- }
-
- float compute_vertical_extends_of_nodes(Span<ProfileNode *> nodes, const float top_y)
- {
- int bottom_y = top_y;
- for (ProfileNode *node : nodes) {
- node->top_y = top_y;
- this->compute_vertical_extends_of_node(*node);
- bottom_y = std::min(bottom_y, node->bottom_y);
- }
- return bottom_y;
- }
-
- void compute_vertical_extends_of_node(ProfileNode &node)
- {
- node.bottom_y = node.top_y - row_height_;
- node.bottom_y = this->compute_vertical_extends_of_nodes(node.direct_children(), node.bottom_y);
- for (Span<ProfileNode *> children : node.parallel_children()) {
- if (!children.is_empty()) {
- node.bottom_y -= parallel_padding_;
- node.bottom_y = this->compute_vertical_extends_of_nodes(children, node.bottom_y);
- }
- }
- }
-
void find_all_nodes_to_draw(Vector<ProfileNode *> &r_nodes)
{
BLI_PROFILE_SCOPE(__func__);
@@ -221,7 +183,8 @@ class ProfilerDrawer {
const Color4f color = this->get_node_color(node);
immUniformColor4fv(color);
- immRecti(pos, left_x, node.top_y, right_x, node.top_y - row_height_);
+ const float top_y = this->node_y_to_y(node.top_y);
+ immRecti(pos, left_x, top_y, right_x, top_y - UI_UNIT_Y);
immUnbindProgram();
@@ -238,6 +201,7 @@ class ProfilerDrawer {
{
const int x = std::max(0, left_x);
const int width = std::max(1, std::min<int>(right_x, region_->winx) - x);
+ const float top_y = this->node_y_to_y(node.top_y);
uiBut *but = uiDefIconTextBut(ui_block,
UI_BTYPE_BUT,
@@ -245,9 +209,9 @@ class ProfilerDrawer {
ICON_NONE,
node.name().c_str(),
x,
- node.top_y - row_height_,
+ top_y - UI_UNIT_Y,
width,
- row_height_,
+ UI_UNIT_Y,
nullptr,
0,
0,
@@ -315,6 +279,11 @@ class ProfilerDrawer {
return begin_time + ms_to_duration(ms_since_begin);
}
+ float node_y_to_y(const float y) const
+ {
+ return region_->winy + y * UI_UNIT_Y - region_->v2d.cur.ymax;
+ }
+
Color4f get_node_color(ProfileNode &node)
{
const uint64_t value = POINTER_AS_UINT(&node);
diff --git a/source/blender/editors/space_profiler/profiler_layout.cc b/source/blender/editors/space_profiler/profiler_layout.cc
index a47ffa93969..bc5fcb4fac4 100644
--- a/source/blender/editors/space_profiler/profiler_layout.cc
+++ b/source/blender/editors/space_profiler/profiler_layout.cc
@@ -25,6 +25,9 @@ using profile::ProfileTaskBeginNamed;
using profile::ProfileTaskBeginRange;
using profile::ProfileTaskEnd;
+static constexpr float node_height = 1.0f;
+static constexpr float parallel_padding = 0.1f;
+
bool ProfileNode::time_overlap(const ProfileNode &a, const ProfileNode &b)
{
const bool begin_of_a_is_in_b = (a.begin_time_ > b.begin_time_ && a.begin_time_ < b.end_time_);
@@ -233,6 +236,40 @@ void ProfilerLayout::add(const RecordedProfile &recorded_profile)
}
pack_into_vectors(root_nodes_, root_nodes_to_pack);
+
+ this->update_y_positions();
+}
+
+void ProfilerLayout::update_y_positions()
+{
+ float top_y = 0.0f;
+ for (Span<ProfileNode *> nodes : root_nodes_) {
+ top_y = this->update_y_positions_of_nodes(nodes, top_y);
+ top_y -= parallel_padding;
+ }
+}
+
+float ProfilerLayout::update_y_positions_of_nodes(Span<ProfileNode *> nodes, float top_y)
+{
+ float bottom_y = top_y;
+ for (ProfileNode *node : nodes) {
+ node->top_y = top_y;
+ this->update_y_position_of_node(*node);
+ bottom_y = std::min(bottom_y, node->bottom_y);
+ }
+ return bottom_y;
+}
+
+void ProfilerLayout::update_y_position_of_node(ProfileNode &node)
+{
+ node.bottom_y = node.top_y - node_height;
+ node.bottom_y = this->update_y_positions_of_nodes(node.direct_children(), node.bottom_y);
+ for (Span<ProfileNode *> children : node.parallel_children()) {
+ if (!children.is_empty()) {
+ node.bottom_y -= parallel_padding;
+ node.bottom_y = this->update_y_positions_of_nodes(children, node.bottom_y);
+ }
+ }
}
void ProfileNode::destruct_recursively()
diff --git a/source/blender/editors/space_profiler/profiler_layout.hh b/source/blender/editors/space_profiler/profiler_layout.hh
index 9672230901f..e7f38c929a3 100644
--- a/source/blender/editors/space_profiler/profiler_layout.hh
+++ b/source/blender/editors/space_profiler/profiler_layout.hh
@@ -49,8 +49,9 @@ class ProfileNode {
friend ProfilerLayout;
public:
- int top_y;
- int bottom_y;
+ /* In ui units. */
+ float top_y = 0.0f;
+ float bottom_y = 0.0f;
public:
StringRefNull name() const
@@ -135,6 +136,11 @@ class ProfilerLayout {
{
return end_time_;
}
+
+ private:
+ void update_y_positions();
+ float update_y_positions_of_nodes(Span<ProfileNode *> nodes, float top_y);
+ void update_y_position_of_node(ProfileNode &node);
};
} // namespace blender::ed::profiler
More information about the Bf-blender-cvs
mailing list