Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Unified Diff: ui/app_list/views/cached_label.cc

Issue 12771021: Make painting app list items more efficient by caching the labels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/app_list/views/cached_label.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ui/app_list/views/cached_label.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698