diff options
author | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-13 09:57:45 +0000 |
---|---|---|
committer | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-13 09:57:45 +0000 |
commit | 4562defff60b7b819e69709b3d7e4e2f022a9ba0 (patch) | |
tree | df22044d5aa3e06ad04453a574594d9608299266 /ui/app_list | |
parent | 8f6ed7925270abb026b08394573239131f723211 (diff) | |
download | chromium_src-4562defff60b7b819e69709b3d7e4e2f022a9ba0.zip chromium_src-4562defff60b7b819e69709b3d7e4e2f022a9ba0.tar.gz chromium_src-4562defff60b7b819e69709b3d7e4e2f022a9ba0.tar.bz2 |
Make painting app list items more efficient by caching the labels.
BUG=170069
Review URL: https://chromiumcodereview.appspot.com/12771021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187822 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/app_list')
-rw-r--r-- | ui/app_list/app_list.gyp | 2 | ||||
-rw-r--r-- | ui/app_list/views/app_list_item_view.cc | 6 | ||||
-rw-r--r-- | ui/app_list/views/app_list_item_view.h | 3 | ||||
-rw-r--r-- | ui/app_list/views/cached_label.cc | 34 | ||||
-rw-r--r-- | ui/app_list/views/cached_label.h | 41 |
5 files changed, 84 insertions, 2 deletions
diff --git a/ui/app_list/app_list.gyp b/ui/app_list/app_list.gyp index 144b878..5827324 100644 --- a/ui/app_list/app_list.gyp +++ b/ui/app_list/app_list.gyp @@ -67,6 +67,8 @@ 'views/app_list_view.h', 'views/apps_grid_view.cc', 'views/apps_grid_view.h', + 'views/cached_label.cc', + 'views/cached_label.h', 'views/contents_view.cc', 'views/contents_view.h', 'views/page_switcher.cc', diff --git a/ui/app_list/views/app_list_item_view.cc b/ui/app_list/views/app_list_item_view.cc index dcf023a..640aa57 100644 --- a/ui/app_list/views/app_list_item_view.cc +++ b/ui/app_list/views/app_list_item_view.cc @@ -10,6 +10,7 @@ #include "grit/ui_resources.h" #include "ui/app_list/app_list_item_model.h" #include "ui/app_list/views/apps_grid_view.h" +#include "ui/app_list/views/cached_label.h" #include "ui/base/accessibility/accessible_view_state.h" #include "ui/base/animation/throb_animation.h" #include "ui/base/resource/resource_bundle.h" @@ -65,7 +66,7 @@ AppListItemView::AppListItemView(AppsGridView* apps_grid_view, model_(model), apps_grid_view_(apps_grid_view), icon_(new views::ImageView), - title_(new views::Label), + title_(new CachedLabel), ui_state_(UI_STATE_NORMAL), touch_dragging_(false) { icon_->set_interactive(false); @@ -77,6 +78,7 @@ AppListItemView::AppListItemView(AppsGridView* apps_grid_view, title_->SetFont(rb.GetFont(ui::ResourceBundle::SmallBoldFont)); title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); title_->SetVisible(!model_->is_installing()); + title_->Invalidate(); const gfx::ShadowValue kIconShadows[] = { gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)), @@ -176,6 +178,7 @@ void AppListItemView::ItemIconChanged() { void AppListItemView::ItemTitleChanged() { title_->SetText(UTF8ToUTF16(model_->title())); + title_->Invalidate(); } void AppListItemView::ItemHighlightedChanged() { @@ -296,6 +299,7 @@ void AppListItemView::StateChanged() { model_->SetHighlighted(false); title_->SetEnabledColor(kTitleColor); } + title_->Invalidate(); } bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) { diff --git a/ui/app_list/views/app_list_item_view.h b/ui/app_list/views/app_list_item_view.h index a037de2..c2f9d05 100644 --- a/ui/app_list/views/app_list_item_view.h +++ b/ui/app_list/views/app_list_item_view.h @@ -28,6 +28,7 @@ namespace app_list { class AppListItemModel; class AppsGridView; +class CachedLabel; class APP_LIST_EXPORT AppListItemView : public views::CustomButton, public views::ContextMenuController, @@ -95,7 +96,7 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton, AppsGridView* apps_grid_view_; // Owned by views hierarchy. views::ImageView* icon_; // Owned by views hierarchy. - views::Label* title_; // Owned by views hierarchy. + CachedLabel* title_; // Owned by views hierarchy. scoped_ptr<views::MenuRunner> context_menu_runner_; diff --git a/ui/app_list/views/cached_label.cc b/ui/app_list/views/cached_label.cc new file mode 100644 index 0000000..60f731e --- /dev/null +++ b/ui/app_list/views/cached_label.cc @@ -0,0 +1,34 @@ +// 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() { + gfx::Canvas canvas(size(), ui::SCALE_FACTOR_100P, false /* is_opaque */); + canvas.FillRect(GetLocalBounds(), SkColorSetARGB(0, 0, 0, 0), + SkXfermode::kSrc_Mode); + Label::OnPaint(&canvas); + image_ = gfx::ImageSkia(canvas.ExtractImageRep()); +} + +#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 diff --git a/ui/app_list/views/cached_label.h b/ui/app_list/views/cached_label.h new file mode 100644 index 0000000..a5a497a --- /dev/null +++ b/ui/app_list/views/cached_label.h @@ -0,0 +1,41 @@ +// 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. + +#ifndef UI_APP_LIST_VIEWS_CACHED_LABEL_H_ +#define UI_APP_LIST_VIEWS_CACHED_LABEL_H_ + +#include "ui/gfx/image/image_skia.h" +#include "ui/views/controls/label.h" +#include "ui/views/view.h" + +namespace gfx { +class Canvas; +} + +namespace app_list { + +// Subclass of views::Label that caches the rendered text in an ImageSkia. +class CachedLabel : public views::Label { + public: + CachedLabel(); + + // Have the next call to OnPaint() update the backing image. + void Invalidate() { needs_repaint_ = true; } + +#if defined(OS_WIN) + // views::View overrides. + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; +#endif + + private: + // Calls the base label's OnPaint() to paint into a backing image. + void PaintToBackingImage(); + + bool needs_repaint_; + gfx::ImageSkia image_; +}; + +} // namespace app_list + +#endif // UI_APP_LIST_VIEWS_CACHED_LABEL_H_ |