From 270b241d110fe8d9ff25af7beb9bc59d1a15a37e Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Fri, 30 Sep 2016 15:36:23 +0200 Subject: [PATCH] [kandinsky] Optimize KDColor::blend Change-Id: Icb1701bf5f95023d49a96a355be7ff43c326f8eb --- kandinsky/src/color.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kandinsky/src/color.cpp b/kandinsky/src/color.cpp index 3d076b5f6..4b76f7314 100644 --- a/kandinsky/src/color.cpp +++ b/kandinsky/src/color.cpp @@ -1,6 +1,16 @@ #include KDColor KDColor::blend(KDColor first, KDColor second, uint8_t alpha) { + /* This function is a hot path since it's being called for every single pixel + * whenever we want to display a string. In this context, we're quite often + * calling it with a value of either 0 or 0xFF, which can be very trivially + * dealt with. So let's make a special case for them. */ + if (alpha == 0) { + return second; + } else if (alpha == 0xFF) { + return first; + } + // We want to do first*alpha + second*(1-alpha) // First is RRRRR GGGGGG BBBBB // Second is same