浏览代码

LibGfx: Move Color::mixed_with() inline

This seems to give a small speedup to gradient painting and removes
Color::mixed_with() (which was 10% of the time) from the profile.
MacDue 2 年之前
父节点
当前提交
e5a39d134b
共有 2 个文件被更改,包括 23 次插入25 次删除
  1. 0 24
      Userland/Libraries/LibGfx/Color.cpp
  2. 23 1
      Userland/Libraries/LibGfx/Color.h

+ 0 - 24
Userland/Libraries/LibGfx/Color.cpp

@@ -315,30 +315,6 @@ Optional<Color> Color::from_string(StringView string)
     return Color(r.value(), g.value(), b.value(), a.value());
     return Color(r.value(), g.value(), b.value(), a.value());
 }
 }
 
 
-Color Color::mixed_with(Color other, float weight) const
-{
-    if (alpha() == other.alpha() || with_alpha(0) == other.with_alpha(0)) {
-        return Gfx::Color {
-            round_to<u8>(mix<float>(red(), other.red(), weight)),
-            round_to<u8>(mix<float>(green(), other.green(), weight)),
-            round_to<u8>(mix<float>(blue(), other.blue(), weight)),
-            round_to<u8>(mix<float>(alpha(), other.alpha(), weight)),
-        };
-    }
-    // Fallback to slower, but more visually pleasing premultiplied alpha mix.
-    // This is needed for linear-gradient()s in LibWeb.
-    auto mixed_alpha = mix<float>(alpha(), other.alpha(), weight);
-    auto premultiplied_mix_channel = [&](float channel, float other_channel, float weight) {
-        return round_to<u8>(mix<float>(channel * alpha(), other_channel * other.alpha(), weight) / mixed_alpha);
-    };
-    return Gfx::Color {
-        premultiplied_mix_channel(red(), other.red(), weight),
-        premultiplied_mix_channel(green(), other.green(), weight),
-        premultiplied_mix_channel(blue(), other.blue(), weight),
-        round_to<u8>(mixed_alpha),
-    };
-}
-
 Vector<Color> Color::shades(u32 steps, float max) const
 Vector<Color> Color::shades(u32 steps, float max) const
 {
 {
     float shade = 1.f;
     float shade = 1.f;

+ 23 - 1
Userland/Libraries/LibGfx/Color.h

@@ -237,7 +237,29 @@ public:
 #endif
 #endif
     }
     }
 
 
-    Color mixed_with(Color other, float weight) const;
+    Color mixed_with(Color other, float weight) const
+    {
+        if (alpha() == other.alpha() || with_alpha(0) == other.with_alpha(0)) {
+            return Gfx::Color {
+                round_to<u8>(mix<float>(red(), other.red(), weight)),
+                round_to<u8>(mix<float>(green(), other.green(), weight)),
+                round_to<u8>(mix<float>(blue(), other.blue(), weight)),
+                round_to<u8>(mix<float>(alpha(), other.alpha(), weight)),
+            };
+        }
+        // Fallback to slower, but more visually pleasing premultiplied alpha mix.
+        // This is needed for linear-gradient()s in LibWeb.
+        auto mixed_alpha = mix<float>(alpha(), other.alpha(), weight);
+        auto premultiplied_mix_channel = [&](float channel, float other_channel, float weight) {
+            return round_to<u8>(mix<float>(channel * alpha(), other_channel * other.alpha(), weight) / mixed_alpha);
+        };
+        return Gfx::Color {
+            premultiplied_mix_channel(red(), other.red(), weight),
+            premultiplied_mix_channel(green(), other.green(), weight),
+            premultiplied_mix_channel(blue(), other.blue(), weight),
+            round_to<u8>(mixed_alpha),
+        };
+    }
 
 
     Color interpolate(Color other, float weight) const noexcept
     Color interpolate(Color other, float weight) const noexcept
     {
     {