Explorar el Código

Profiler: Extract percentage gradient calculation into its own file

Stephan Unverwerth hace 3 años
padre
commit
1c3a82d59e

+ 1 - 0
Userland/DevTools/Profiler/CMakeLists.txt

@@ -9,6 +9,7 @@ set(SOURCES
         main.cpp
         main.cpp
         IndividualSampleModel.cpp
         IndividualSampleModel.cpp
         FlameGraphView.cpp
         FlameGraphView.cpp
+        Gradient.cpp
         Process.cpp
         Process.cpp
         Profile.cpp
         Profile.cpp
         ProfileModel.cpp
         ProfileModel.cpp

+ 1 - 18
Userland/DevTools/Profiler/DisassemblyModel.cpp

@@ -5,11 +5,11 @@
  */
  */
 
 
 #include "DisassemblyModel.h"
 #include "DisassemblyModel.h"
+#include "Gradient.h"
 #include "Profile.h"
 #include "Profile.h"
 #include <LibCore/MappedFile.h>
 #include <LibCore/MappedFile.h>
 #include <LibDebug/DebugInfo.h>
 #include <LibDebug/DebugInfo.h>
 #include <LibELF/Image.h>
 #include <LibELF/Image.h>
-#include <LibGUI/Painter.h>
 #include <LibSymbolication/Symbolication.h>
 #include <LibSymbolication/Symbolication.h>
 #include <LibX86/Disassembler.h>
 #include <LibX86/Disassembler.h>
 #include <LibX86/ELFSymbolProvider.h>
 #include <LibX86/ELFSymbolProvider.h>
@@ -17,23 +17,6 @@
 
 
 namespace Profiler {
 namespace Profiler {
 
 
-static Gfx::Bitmap const& heat_gradient()
-{
-    static RefPtr<Gfx::Bitmap> bitmap;
-    if (!bitmap) {
-        bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 101, 1 }).release_value_but_fixme_should_propagate_errors();
-        GUI::Painter painter(*bitmap);
-        painter.fill_rect_with_gradient(Orientation::Horizontal, bitmap->rect(), Color::from_rgb(0xffc080), Color::from_rgb(0xff3000));
-    }
-    return *bitmap;
-}
-
-static Color color_for_percent(int percent)
-{
-    VERIFY(percent >= 0 && percent <= 100);
-    return heat_gradient().get_pixel(percent, 0);
-}
-
 static Optional<MappedObject> s_kernel_binary;
 static Optional<MappedObject> s_kernel_binary;
 
 
 static ELF::Image* try_load_kernel_binary()
 static ELF::Image* try_load_kernel_binary()

+ 29 - 0
Userland/DevTools/Profiler/Gradient.cpp

@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "Gradient.h"
+#include <LibGUI/Painter.h>
+
+namespace Profiler {
+
+static Gfx::Bitmap const& heat_gradient()
+{
+    static RefPtr<Gfx::Bitmap> bitmap;
+    if (!bitmap) {
+        bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 101, 1 }).release_value_but_fixme_should_propagate_errors();
+        GUI::Painter painter(*bitmap);
+        painter.fill_rect_with_gradient(Orientation::Horizontal, bitmap->rect(), Color::from_rgb(0xffc080), Color::from_rgb(0xff3000));
+    }
+    return *bitmap;
+}
+
+Color color_for_percent(u8 percent)
+{
+    VERIFY(percent <= 100);
+    return heat_gradient().get_pixel(percent, 0);
+}
+
+}

+ 15 - 0
Userland/DevTools/Profiler/Gradient.h

@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibGfx/Color.h>
+
+namespace Profiler {
+
+Color color_for_percent(u8 percent);
+
+}

+ 2 - 18
Userland/DevTools/Profiler/SourceModel.cpp

@@ -5,9 +5,10 @@
  */
  */
 
 
 #include "SourceModel.h"
 #include "SourceModel.h"
+#include "Gradient.h"
 #include "Profile.h"
 #include "Profile.h"
 #include <LibDebug/DebugInfo.h>
 #include <LibDebug/DebugInfo.h>
-#include <LibGUI/Painter.h>
+#include <LibGfx/FontDatabase.h>
 #include <LibSymbolication/Symbolication.h>
 #include <LibSymbolication/Symbolication.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
@@ -53,23 +54,6 @@ private:
     Vector<Line> m_lines;
     Vector<Line> m_lines;
 };
 };
 
 
-static Gfx::Bitmap const& heat_gradient()
-{
-    static RefPtr<Gfx::Bitmap> bitmap;
-    if (!bitmap) {
-        bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 101, 1 }).release_value_but_fixme_should_propagate_errors();
-        GUI::Painter painter(*bitmap);
-        painter.fill_rect_with_gradient(Orientation::Horizontal, bitmap->rect(), Color::from_rgb(0xffc080), Color::from_rgb(0xff3000));
-    }
-    return *bitmap;
-}
-
-static Color color_for_percent(int percent)
-{
-    VERIFY(percent >= 0 && percent <= 100);
-    return heat_gradient().get_pixel(percent, 0);
-}
-
 SourceModel::SourceModel(Profile& profile, ProfileNode& node)
 SourceModel::SourceModel(Profile& profile, ProfileNode& node)
     : m_profile(profile)
     : m_profile(profile)
     , m_node(node)
     , m_node(node)