[Bf-blender-cvs] [e13a3896d1b] profiler-editor: compute vertical extends

Jacques Lucke noreply at git.blender.org
Thu Apr 29 11:30:48 CEST 2021


Commit: e13a3896d1b95461a3aaaf4ae18eaa5d67d96358
Author: Jacques Lucke
Date:   Tue Apr 27 17:14:44 2021 +0200
Branches: profiler-editor
https://developer.blender.org/rBe13a3896d1b95461a3aaaf4ae18eaa5d67d96358

compute vertical extends

===================================================================

M	source/blender/editors/space_profiler/profiler_draw.cc
M	source/blender/editors/space_profiler/profiler_layout.hh
M	source/blender/editors/space_profiler/space_profiler.cc

===================================================================

diff --git a/source/blender/editors/space_profiler/profiler_draw.cc b/source/blender/editors/space_profiler/profiler_draw.cc
index 6957461f129..00dde364304 100644
--- a/source/blender/editors/space_profiler/profiler_draw.cc
+++ b/source/blender/editors/space_profiler/profiler_draw.cc
@@ -41,6 +41,8 @@ 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)
@@ -53,11 +55,45 @@ class ProfilerDrawer {
     }
     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();
+  }
+
+  void compute_vertical_extends_of_all_nodes()
+  {
+    int top_y = region_->winy;
+    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()) {
+      node.bottom_y -= parallel_padding_;
+      node.bottom_y = this->compute_vertical_extends_of_nodes(children, node.bottom_y);
+    }
   }
 };
 
diff --git a/source/blender/editors/space_profiler/profiler_layout.hh b/source/blender/editors/space_profiler/profiler_layout.hh
index 7f8c375b73f..57a91d15e40 100644
--- a/source/blender/editors/space_profiler/profiler_layout.hh
+++ b/source/blender/editors/space_profiler/profiler_layout.hh
@@ -45,11 +45,12 @@ class ProfileNode {
   /* These nodes still have to be inserted into the vectors above. They are not sorted. */
   Vector<ProfileNode *> children_to_pack_;
 
+  friend ProfilerLayout;
+
+ public:
   int top_y;
   int bottom_y;
 
-  friend ProfilerLayout;
-
  public:
   StringRefNull name() const
   {
@@ -81,12 +82,12 @@ class ProfileNode {
     return thread_id_;
   }
 
-  Span<const ProfileNode *> children_on_same_thread() const
+  Span<ProfileNode *> direct_children()
   {
     return direct_children_;
   }
 
-  Span<Vector<ProfileNode *>> stacked_children_in_other_threads() const
+  Span<Vector<ProfileNode *>> parallel_children() const
   {
     return parallel_children_;
   }
diff --git a/source/blender/editors/space_profiler/space_profiler.cc b/source/blender/editors/space_profiler/space_profiler.cc
index 32d980ea5e2..9e21bde224d 100644
--- a/source/blender/editors/space_profiler/space_profiler.cc
+++ b/source/blender/editors/space_profiler/space_profiler.cc
@@ -63,8 +63,10 @@ static SpaceLink *profiler_create(const ScrArea *UNUSED(area), const Scene *UNUS
   return (SpaceLink *)sprofiler;
 }
 
-static void profiler_free(SpaceLink *UNUSED(sl))
+static void profiler_free(SpaceLink *sl)
 {
+  SpaceProfiler *sprofiler = (SpaceProfiler *)sl;
+  delete sprofiler->runtime;
 }
 
 static void profiler_init(wmWindowManager *UNUSED(wm), ScrArea *area)



More information about the Bf-blender-cvs mailing list