summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-02 15:33:36 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-02 15:33:36 +0000
commit3bf21e1dcd73903dfae5c4d9a7c8f2e55ed238d5 (patch)
treea94a8f6dd838343f95fe828d1e212ba14b594a42 /ui/gfx
parent50b1e9993b22101eef851fc4dfc84574a92079a2 (diff)
downloadchromium_src-3bf21e1dcd73903dfae5c4d9a7c8f2e55ed238d5.zip
chromium_src-3bf21e1dcd73903dfae5c4d9a7c8f2e55ed238d5.tar.gz
chromium_src-3bf21e1dcd73903dfae5c4d9a7c8f2e55ed238d5.tar.bz2
Fix ugly non-ClearType text rendering in tab strip.
Draw the text to a layer and restore it faded by drawing a rect in kDstIn_Mode mode. Workaround for: http://code.google.com/p/skia/issues/detail?id=590 BUG=122743, 105550 TEST=Turn off ClearType in Windows setting. Open Chrome to a tab where its title doesn't fit in the tab and must get faded. Observe that the title text looks okay. Review URL: http://codereview.chromium.org/10266017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134922 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r--ui/gfx/render_text.cc38
-rw-r--r--ui/gfx/render_text.h5
2 files changed, 38 insertions, 5 deletions
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 6fff6f7..3f8de7f 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -19,6 +19,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/native_theme.h"
+#include "ui/gfx/skia_util.h"
#include "ui/gfx/shadow_value.h"
namespace {
@@ -176,7 +177,8 @@ namespace gfx {
namespace internal {
SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas)
- : canvas_skia_(canvas->sk_canvas()) {
+ : canvas_skia_(canvas->sk_canvas()),
+ started_drawing_(false) {
DCHECK(canvas_skia_);
paint_.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
paint_.setStyle(SkPaint::kFill_Style);
@@ -186,6 +188,18 @@ SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas)
}
SkiaTextRenderer::~SkiaTextRenderer() {
+ // Work-around for http://crbug.com/122743, where non-ClearType text is
+ // rendered with incorrect gamma when using the fade shader. Draw the text
+ // to a layer and restore it faded by drawing a rect in kDstIn_Mode mode.
+ //
+ // TODO(asvitkine): Remove this work-around once the Skia bug is fixed.
+ // http://code.google.com/p/skia/issues/detail?id=590
+ if (deferred_fade_shader_.get()) {
+ paint_.setShader(deferred_fade_shader_.get());
+ paint_.setXfermodeMode(SkXfermode::kDstIn_Mode);
+ canvas_skia_->drawRect(bounds_, paint_);
+ canvas_skia_->restore();
+ }
}
void SkiaTextRenderer::SetDrawLooper(SkDrawLooper* draw_looper) {
@@ -229,14 +243,30 @@ void SkiaTextRenderer::SetForegroundColor(SkColor foreground) {
paint_.setColor(foreground);
}
-void SkiaTextRenderer::SetShader(SkShader* shader) {
+void SkiaTextRenderer::SetShader(SkShader* shader, const Rect& bounds) {
+ bounds_ = RectToSkRect(bounds);
paint_.setShader(shader);
}
void SkiaTextRenderer::DrawPosText(const SkPoint* pos,
const uint16* glyphs,
size_t glyph_count) {
- size_t byte_length = glyph_count * sizeof(glyphs[0]);
+ if (!started_drawing_) {
+ started_drawing_ = true;
+ // Work-around for http://crbug.com/122743, where non-ClearType text is
+ // rendered with incorrect gamma when using the fade shader. Draw the text
+ // to a layer and restore it faded by drawing a rect in kDstIn_Mode mode.
+ //
+ // TODO(asvitkine): Remove this work-around once the Skia bug is fixed.
+ // http://code.google.com/p/skia/issues/detail?id=590
+ if (!paint_.isLCDRenderText() && paint_.getShader()) {
+ deferred_fade_shader_ = paint_.getShader();
+ paint_.setShader(NULL);
+ canvas_skia_->saveLayer(&bounds_, NULL);
+ }
+ }
+
+ const size_t byte_length = glyph_count * sizeof(glyphs[0]);
canvas_skia_->drawPosText(&glyphs[0], byte_length, &pos[0], paint_);
}
@@ -800,7 +830,7 @@ void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) {
SkAutoUnref auto_unref(shader);
if (shader) {
// |renderer| adds its own ref. So don't |release()| it from the ref ptr.
- renderer->SetShader(shader);
+ renderer->SetShader(shader, display_rect());
}
}
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index 8077828..79758cc 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -45,7 +45,7 @@ class SkiaTextRenderer {
void SetTextSize(int size);
void SetFontFamilyWithStyle(const std::string& family, int font_style);
void SetForegroundColor(SkColor foreground);
- void SetShader(SkShader* shader);
+ void SetShader(SkShader* shader, const Rect& bounds);
void DrawSelection(const std::vector<Rect>& selection, SkColor color);
void DrawPosText(const SkPoint* pos,
const uint16* glyphs,
@@ -54,7 +54,10 @@ class SkiaTextRenderer {
private:
SkCanvas* canvas_skia_;
+ bool started_drawing_;
SkPaint paint_;
+ SkRect bounds_;
+ SkRefPtr<SkShader> deferred_fade_shader_;
DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer);
};