summaryrefslogtreecommitdiffstats
path: root/app/gfx
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-11 19:25:02 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-11 19:25:02 +0000
commitc6bd178914f5692f9bc59994d656a3d571c494fb (patch)
tree1a7563970f4fe43a2e689838981fa6b0293b614d /app/gfx
parentbc104572de180e30823b9f828ed19d032bedfe1d (diff)
downloadchromium_src-c6bd178914f5692f9bc59994d656a3d571c494fb.zip
chromium_src-c6bd178914f5692f9bc59994d656a3d571c494fb.tar.gz
chromium_src-c6bd178914f5692f9bc59994d656a3d571c494fb.tar.bz2
Fix a bug where some bitmaps were being tinted wrong. It turns out
that when converting from RGB to HSL we were comparing doubles and in on some CPUs, a register spill would cause us to do the conversion wrong. BUG=28243 Review URL: http://codereview.chromium.org/491036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34362 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gfx')
-rw-r--r--app/gfx/color_utils.cc8
-rw-r--r--app/gfx/color_utils_unittest.cc11
2 files changed, 16 insertions, 3 deletions
diff --git a/app/gfx/color_utils.cc b/app/gfx/color_utils.cc
index 483e857..05b8bfa 100644
--- a/app/gfx/color_utils.cc
+++ b/app/gfx/color_utils.cc
@@ -95,11 +95,13 @@ void SkColorToHSL(SkColor c, HSL* hsl) {
double dr = (((vmax - r) / 6.0) + (delta / 2.0)) / delta;
double dg = (((vmax - g) / 6.0) + (delta / 2.0)) / delta;
double db = (((vmax - b) / 6.0) + (delta / 2.0)) / delta;
- if (r == vmax)
+ // We need to compare for the max value because comparing vmax to r,
+ // g or b can sometimes result in values overflowing registers.
+ if (r >= g && r >= b)
hsl->h = db - dg;
- else if (g == vmax)
+ else if (g >= r && g >= b)
hsl->h = (1.0 / 3.0) + dr - db;
- else // (b == vmax)
+ else // (b >= r && b >= g)
hsl->h = (2.0 / 3.0) + dg - dr;
if (hsl->h < 0.0)
diff --git a/app/gfx/color_utils_unittest.cc b/app/gfx/color_utils_unittest.cc
index 4e7f414..9ba7cb8 100644
--- a/app/gfx/color_utils_unittest.cc
+++ b/app/gfx/color_utils_unittest.cc
@@ -36,3 +36,14 @@ TEST(ColorUtils, HSLToSkColorWithAlpha) {
EXPECT_EQ(SkColorGetB(red), SkColorGetB(result));
}
+TEST(ColorUtils, ColorToHSLRegisterSpill) {
+ // In a opt build on Linux, this was causing a register spill on my laptop
+ // (Pentium M) when converting from SkColor to HSL.
+ SkColor input = SkColorSetARGB(255, 206, 154, 89);
+ color_utils::HSL hsl = { -1, -1, -1 };
+ SkColor result = color_utils::HSLShift(input, hsl);
+ EXPECT_EQ(255U, SkColorGetA(result));
+ EXPECT_EQ(206U, SkColorGetR(result));
+ EXPECT_EQ(153U, SkColorGetG(result));
+ EXPECT_EQ(88U, SkColorGetB(result));
+}