summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-26 18:01:21 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-26 18:01:21 +0000
commitce00ec6f6a3942db3d89ce0657ac3211260f3125 (patch)
tree0d589b6c5d37196ea68efdfe51d1a3f0a6dd0899 /ui
parent6901d70a4a4ffc6e886bf1f3029fadca55d29a96 (diff)
downloadchromium_src-ce00ec6f6a3942db3d89ce0657ac3211260f3125.zip
chromium_src-ce00ec6f6a3942db3d89ce0657ac3211260f3125.tar.gz
chromium_src-ce00ec6f6a3942db3d89ce0657ac3211260f3125.tar.bz2
Merge 82972 - Fix glitchy drawing in faded tab titlesWhen fading tab titles we would sometimes have some glitches when transitioning from the solid title to the faded title.The problem was that we were switching the front from normal clear type to cleartype off. This changed caused visible glitches when transitioning between the two fonts.Initially I switched clear type off to make it easier to calculate the alpha of the text. msw recomended using the luminosity of the text to determine the alpha. It turns out that this works great and we no longer have to turn off clear type in the faded sections.BUG=78869TEST=Reproduced the bug. Applied my patch and verified that the bug no longer reproduced.Review URL: http://codereview.chromium.org/6902016
TBR=sail@chromium.org Review URL: http://codereview.chromium.org/6880211 git-svn-id: svn://svn.chromium.org/chrome/branches/742/src@83043 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/canvas_skia_win.cc23
-rw-r--r--ui/gfx/color_utils.cc18
-rw-r--r--ui/gfx/color_utils.h4
3 files changed, 22 insertions, 23 deletions
diff --git a/ui/gfx/canvas_skia_win.cc b/ui/gfx/canvas_skia_win.cc
index 048cbf6..9024673 100644
--- a/ui/gfx/canvas_skia_win.cc
+++ b/ui/gfx/canvas_skia_win.cc
@@ -13,6 +13,7 @@
#include "skia/ext/bitmap_platform_device.h"
#include "skia/ext/skia_utils_win.h"
#include "third_party/skia/include/core/SkShader.h"
+#include "ui/gfx/color_utils.h"
#include "ui/gfx/font.h"
#include "ui/gfx/rect.h"
@@ -209,8 +210,9 @@ void DrawTextAndClearBackground(skia::BitmapPlatformDevice& bmp_device,
// Gets the color directly. DrawText doesn't premultiply alpha so
// using SkBitmap::getColor() won't work here.
SkColor color = *bmp.getAddr32(x, y);
- // Use any of the color channels as alpha.
- BYTE alpha = 0xFF - SkColorGetB(color);
+ // Calculate the alpha using the luminance. Since this is black text
+ // on a white background the luminosity must be inverted.
+ BYTE alpha = 0xFF - color_utils::GetLuminanceForColor(color);
*bmp.getAddr32(x, y) = SkPreMultiplyColor(
SkColorSetARGB(alpha, text_color_r, text_color_b, text_color_g));
}
@@ -550,13 +552,6 @@ void CanvasSkia::DrawFadeTruncatingString(
text_rect.set_x(text_rect.x() - offset_x);
text_rect.set_width(text_rect.width() + offset_x);
- // Disable clear type. This makes the text render in gray scale which
- // makes it easier to compute the alpha value.
- LOGFONT font_info;
- GetObject(font.GetNativeFont(), sizeof(font_info), &font_info);
- font_info.lfQuality = ANTIALIASED_QUALITY;
- base::win::ScopedHFONT gray_scale_font(CreateFontIndirect(&font_info));
-
// Create a temporary bitmap to draw the gradient to.
scoped_ptr<skia::BitmapPlatformDevice> gradient_bitmap(
skia::BitmapPlatformDevice::create(
@@ -565,11 +560,13 @@ void CanvasSkia::DrawFadeTruncatingString(
HDC hdc = beginPlatformPaint();
if (is_truncating_head)
- DrawTextGradientPart(hdc, *gradient_bitmap, text, color, gray_scale_font,
- text_rect, head_part, is_rtl, flags);
+ DrawTextGradientPart(hdc, *gradient_bitmap, text, color,
+ font.GetNativeFont(), text_rect, head_part, is_rtl,
+ flags);
if (is_truncating_tail)
- DrawTextGradientPart(hdc, *gradient_bitmap, text, color, gray_scale_font,
- text_rect, tail_part, !is_rtl, flags);
+ DrawTextGradientPart(hdc, *gradient_bitmap, text, color,
+ font.GetNativeFont(), text_rect, tail_part, !is_rtl,
+ flags);
endPlatformPaint();
// Draw the solid part.
diff --git a/ui/gfx/color_utils.cc b/ui/gfx/color_utils.cc
index 3dacb44..eb639f9 100644
--- a/ui/gfx/color_utils.cc
+++ b/ui/gfx/color_utils.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -43,13 +43,6 @@ int calcHue(double temp1, double temp2, double hue) {
return static_cast<int>(result * 255 + .5);
}
-int GetLumaForColor(SkColor* color) {
- int luma = static_cast<int>((0.3 * SkColorGetR(*color)) +
- (0.59 * SkColorGetG(*color)) +
- (0.11 * SkColorGetB(*color)));
- return std::max(std::min(luma, 255), 0);
-}
-
// Next two functions' formulas from:
// http://www.w3.org/TR/WCAG20/#relativeluminancedef
// http://www.w3.org/TR/WCAG20/#contrast-ratiodef
@@ -79,6 +72,13 @@ double ContrastRatio(double foreground_luminance, double background_luminance) {
// ----------------------------------------------------------------------------
+unsigned char GetLuminanceForColor(SkColor color) {
+ int luma = static_cast<int>((0.3 * SkColorGetR(color)) +
+ (0.59 * SkColorGetG(color)) +
+ (0.11 * SkColorGetB(color)));
+ return std::max(std::min(luma, 255), 0);
+}
+
double RelativeLuminance(SkColor color) {
return (0.2126 * ConvertSRGB(SkColorGetR(color))) +
(0.7152 * ConvertSRGB(SkColorGetG(color))) +
@@ -249,7 +249,7 @@ void BuildLumaHistogram(SkBitmap* bitmap, int histogram[256]) {
for (int y = 0; y < pixel_height; ++y) {
SkColor* current_color = static_cast<uint32_t*>(bitmap->getAddr32(0, y));
for (int x = 0; x < pixel_width; ++x, ++current_color)
- histogram[GetLumaForColor(current_color)]++;
+ histogram[GetLuminanceForColor(*current_color)]++;
}
}
diff --git a/ui/gfx/color_utils.h b/ui/gfx/color_utils.h
index a043b82..86eb055 100644
--- a/ui/gfx/color_utils.h
+++ b/ui/gfx/color_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -19,6 +19,8 @@ struct HSL {
double l;
};
+unsigned char GetLuminanceForColor(SkColor color);
+
// Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef
double RelativeLuminance(SkColor color);