Chromium Code Reviews| Index: ui/app_list/views/cached_label.cc |
| diff --git a/ui/app_list/views/cached_label.cc b/ui/app_list/views/cached_label.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1094ab2b225a9f9c7b408deacdfdee29a4f8e929 |
| --- /dev/null |
| +++ b/ui/app_list/views/cached_label.cc |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2013 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. |
| + |
| +#include "ui/app_list/views/cached_label.h" |
| + |
| +#include "base/utf_string_conversions.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/gfx/canvas.h" |
| + |
| +namespace app_list { |
| + |
| +CachedLabel::CachedLabel() |
| + : needs_repaint_(true) { |
| +} |
| + |
| +void CachedLabel::PaintToBackingImage() { |
| + if (bitmap_.width() != width() || bitmap_.height() != height()) { |
| + bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width(), height()); |
| + bitmap_.allocPixels(); |
| + image_ = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_); |
| + } |
| + |
| + SkCanvas sk_canvas(bitmap_); |
| + scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( |
| + &sk_canvas, ui::SCALE_FACTOR_100P)); |
| + |
| + canvas->FillRect(gfx::Rect(0, 0, width(), height()), |
| + SkColorSetARGB(0x0, 0, 0, 0), SkXfermode::kSrc_Mode); |
|
xiyuan
2013/03/13 04:14:50
Transparency might break ClearType painting and ha
koz (OOO until 15th September)
2013/03/13 04:43:28
The difficulty I found with opaque backgrounds is
|
| + Label::OnPaint(canvas.get()); |
|
xiyuan
2013/03/13 04:14:50
Are you using a SkBitmap to save some allocation?
koz (OOO until 15th September)
2013/03/13 04:43:28
Everything I do here is out of ignorance of a bett
|
| +} |
| + |
| +#if defined(OS_WIN) |
| +void CachedLabel::OnPaint(gfx::Canvas* canvas) { |
| + if (needs_repaint_) |
| + PaintToBackingImage(); |
| + needs_repaint_ = false; |
| + canvas->DrawImageInt(image_, 0, 0); |
| +} |
| +#endif |
| + |
| +} // namespace app_list |