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

Side by Side Diff: ui/app_list/app_list_item_view.cc

Issue 10453035: Clean up SkBitmapOperations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/app_list/app_list_item_view.h" 5 #include "ui/app_list/app_list_item_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "base/synchronization/cancellation_flag.h" 12 #include "base/synchronization/cancellation_flag.h"
12 #include "base/threading/worker_pool.h" 13 #include "base/threading/worker_pool.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "skia/ext/image_operations.h"
14 #include "ui/app_list/app_list_item_model.h" 16 #include "ui/app_list/app_list_item_model.h"
15 #include "ui/app_list/apps_grid_view.h" 17 #include "ui/app_list/apps_grid_view.h"
16 #include "ui/app_list/drop_shadow_label.h" 18 #include "ui/app_list/drop_shadow_label.h"
17 #include "ui/app_list/icon_cache.h" 19 #include "ui/app_list/icon_cache.h"
18 #include "ui/base/accessibility/accessible_view_state.h" 20 #include "ui/base/accessibility/accessible_view_state.h"
19 #include "ui/base/animation/throb_animation.h" 21 #include "ui/base/animation/throb_animation.h"
20 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/font.h" 24 #include "ui/gfx/font.h"
23 #include "ui/gfx/shadow_value.h" 25 #include "ui/gfx/shadow_value.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 121
120 static void Run(scoped_refptr<IconOperation> op) { 122 static void Run(scoped_refptr<IconOperation> op) {
121 op->ResizeAndGenerateShadow(); 123 op->ResizeAndGenerateShadow();
122 } 124 }
123 125
124 // Padding space around icon to contain its shadow. Note it should be at least 126 // Padding space around icon to contain its shadow. Note it should be at least
125 // the max size of shadow radius + shadow offset in shadow generation code. 127 // the max size of shadow radius + shadow offset in shadow generation code.
126 static const int kShadowPadding = 15; 128 static const int kShadowPadding = 15;
127 129
128 void ResizeAndGenerateShadow() { 130 void ResizeAndGenerateShadow() {
129 // If you change shadow radius and shadow offset, please also update 131 if (cancel_flag_.IsSet())
130 // kShadowPaddingAbove. 132 return;
131 const SkColor kShadowColor[] = { 133
132 SkColorSetARGB(0xCC, 0, 0, 0), 134 if (size_ != gfx::Size(bitmap_.width(), bitmap_.height())) {
133 SkColorSetARGB(0x33, 0, 0, 0), 135 bitmap_ = skia::ImageOperations::Resize(bitmap_,
134 SkColorSetARGB(0x4C, 0, 0, 0), 136 skia::ImageOperations::RESIZE_BEST, size_.width(), size_.height());
135 }; 137 }
136 const gfx::Point kShadowOffset[] = {
137 gfx::Point(0, 0),
138 gfx::Point(0, 4),
139 gfx::Point(0, 5),
140 };
141 const SkScalar kShadowRadius[] = {
142 SkIntToScalar(2),
143 SkIntToScalar(4),
144 SkIntToScalar(10),
145 };
146 138
147 if (cancel_flag_.IsSet()) 139 if (cancel_flag_.IsSet())
148 return; 140 return;
149 141
150 if (size_ != gfx::Size(bitmap_.width(), bitmap_.height())) 142 // If you change shadow radius and shadow offset, please also update
151 bitmap_ = SkBitmapOperations::CreateResizedBitmap(bitmap_, size_); 143 // kShadowPaddingAbove.
144 const gfx::ShadowValue kShadows[] = {
145 gfx::ShadowValue(gfx::Point(0, 0), 2, SkColorSetARGB(0xCC, 0, 0, 0)),
146 gfx::ShadowValue(gfx::Point(0, 4), 4, SkColorSetARGB(0x33, 0, 0, 0)),
147 gfx::ShadowValue(gfx::Point(0, 5), 10, SkColorSetARGB(0x4C, 0, 0, 0)),
148 };
149 const std::vector<gfx::ShadowValue> shadows(
150 &kShadows[0],
151 &kShadows[arraysize(kShadows)]);
Alexei Svitkine (slow) 2012/05/25 18:16:06 I think initializing with (kShadows, kShadows + ar
xiyuan 2012/05/25 19:34:01 Done.
152 152
153 if (cancel_flag_.IsSet()) 153 bitmap_ = SkBitmapOperations::CreateDropShadow(bitmap_, shadows);
154 return;
155
156 bitmap_ = SkBitmapOperations::CreateDropShadow(
157 bitmap_,
158 arraysize(kShadowColor),
159 kShadowColor,
160 kShadowOffset,
161 kShadowRadius);
162 } 154 }
163 155
164 void Cancel() { 156 void Cancel() {
165 cancel_flag_.Set(); 157 cancel_flag_.Set();
166 } 158 }
167 159
168 const SkBitmap& bitmap() const { 160 const SkBitmap& bitmap() const {
169 return bitmap_; 161 return bitmap_;
170 } 162 }
171 163
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 void AppListItemView::StateChanged() { 399 void AppListItemView::StateChanged() {
408 if (state() == BS_HOT || state() == BS_PUSHED) { 400 if (state() == BS_HOT || state() == BS_PUSHED) {
409 list_model_view_->SetSelectedItem(this); 401 list_model_view_->SetSelectedItem(this);
410 } else { 402 } else {
411 list_model_view_->ClearSelectedItem(this); 403 list_model_view_->ClearSelectedItem(this);
412 model_->SetHighlighted(false); 404 model_->SetHighlighted(false);
413 } 405 }
414 } 406 }
415 407
416 } // namespace app_list 408 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698