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

Side by Side Diff: ash/desktop_background/wallpaper_resizer.cc

Issue 81393004: ash: Avoid reloading already-resized custom wallpaper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add another MakeThreadSafe() call to WallpaperResizer Created 7 years, 1 month 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ash/desktop_background/wallpaper_resizer.h" 5 #include "ash/desktop_background/wallpaper_resizer.h"
6 6
7 #include "ash/desktop_background/wallpaper_resizer_observer.h" 7 #include "ash/desktop_background/wallpaper_resizer_observer.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
11 #include "base/threading/worker_pool.h" 11 #include "base/threading/worker_pool.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "third_party/skia/include/core/SkImage.h"
13 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/image/image_skia_rep.h"
14 #include "ui/gfx/skia_util.h" 16 #include "ui/gfx/skia_util.h"
15 17
16 using content::BrowserThread; 18 using content::BrowserThread;
17 19
18 namespace ash { 20 namespace ash {
19 namespace { 21 namespace {
20 22
21 // For our scaling ratios we need to round positive numbers. 23 // For our scaling ratios we need to round positive numbers.
22 int RoundPositive(double x) { 24 int RoundPositive(double x) {
23 return static_cast<int>(floor(x + 0.5)); 25 return static_cast<int>(floor(x + 0.5));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 86 }
85 } 87 }
86 } 88 }
87 89
88 *resized_bitmap_out = new_bitmap; 90 *resized_bitmap_out = new_bitmap;
89 resized_bitmap_out->setImmutable(); 91 resized_bitmap_out->setImmutable();
90 } 92 }
91 93
92 } // namespace 94 } // namespace
93 95
96 // static
97 uint32_t WallpaperResizer::GetImageId(const gfx::ImageSkia& image) {
98 const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(1.0f);
Daniel Erat 2013/11/22 15:33:20 Oshima, can you comment on whether I'm doing the r
99 return image_rep.is_null() ? 0 : image_rep.sk_bitmap().getGenerationID();
100 }
101
94 WallpaperResizer::WallpaperResizer(int image_resource_id, 102 WallpaperResizer::WallpaperResizer(int image_resource_id,
95 const gfx::Size& target_size, 103 const gfx::Size& target_size,
96 WallpaperLayout layout) 104 WallpaperLayout layout)
97 : wallpaper_image_(*(ui::ResourceBundle::GetSharedInstance(). 105 : image_(*(ui::ResourceBundle::GetSharedInstance().
98 GetImageNamed(image_resource_id).ToImageSkia())), 106 GetImageNamed(image_resource_id).ToImageSkia())),
107 original_image_id_(GetImageId(image_)),
99 target_size_(target_size), 108 target_size_(target_size),
100 layout_(layout), 109 layout_(layout),
101 weak_ptr_factory_(this) { 110 weak_ptr_factory_(this) {
111 image_.MakeThreadSafe();
102 } 112 }
103 113
104 WallpaperResizer::WallpaperResizer(const gfx::ImageSkia& image, 114 WallpaperResizer::WallpaperResizer(const gfx::ImageSkia& image,
105 const gfx::Size& target_size, 115 const gfx::Size& target_size,
106 WallpaperLayout layout) 116 WallpaperLayout layout)
107 : wallpaper_image_(image), 117 : image_(image),
118 original_image_id_(GetImageId(image_)),
108 target_size_(target_size), 119 target_size_(target_size),
109 layout_(layout), 120 layout_(layout),
110 weak_ptr_factory_(this) { 121 weak_ptr_factory_(this) {
111 } 122 }
112 123
113 WallpaperResizer::~WallpaperResizer() { 124 WallpaperResizer::~WallpaperResizer() {
114 } 125 }
115 126
116 void WallpaperResizer::StartResize() { 127 void WallpaperResizer::StartResize() {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
118 SkBitmap* resized_bitmap = new SkBitmap; 129 SkBitmap* resized_bitmap = new SkBitmap;
119 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( 130 if (!content::BrowserThread::PostBlockingPoolTaskAndReply(
120 FROM_HERE, 131 FROM_HERE,
121 base::Bind(&Resize, *wallpaper_image_.bitmap(), target_size_, 132 base::Bind(&Resize, *image_.bitmap(), target_size_,
122 layout_, resized_bitmap), 133 layout_, resized_bitmap),
123 base::Bind(&WallpaperResizer::OnResizeFinished, 134 base::Bind(&WallpaperResizer::OnResizeFinished,
124 weak_ptr_factory_.GetWeakPtr(), 135 weak_ptr_factory_.GetWeakPtr(),
125 base::Owned(resized_bitmap)))) { 136 base::Owned(resized_bitmap)))) {
126 LOG(WARNING) << "PostSequencedWorkerTask failed. " 137 LOG(WARNING) << "PostSequencedWorkerTask failed. "
127 << "Wallpaper may not be resized."; 138 << "Wallpaper may not be resized.";
128 } 139 }
129 } 140 }
130 141
131 void WallpaperResizer::AddObserver(WallpaperResizerObserver* observer) { 142 void WallpaperResizer::AddObserver(WallpaperResizerObserver* observer) {
132 observers_.AddObserver(observer); 143 observers_.AddObserver(observer);
133 } 144 }
134 145
135 void WallpaperResizer::RemoveObserver(WallpaperResizerObserver* observer) { 146 void WallpaperResizer::RemoveObserver(WallpaperResizerObserver* observer) {
136 observers_.RemoveObserver(observer); 147 observers_.RemoveObserver(observer);
137 } 148 }
138 149
139 void WallpaperResizer::OnResizeFinished(SkBitmap* resized_bitmap) { 150 void WallpaperResizer::OnResizeFinished(SkBitmap* resized_bitmap) {
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
141 wallpaper_image_ = gfx::ImageSkia::CreateFrom1xBitmap(*resized_bitmap); 152 image_ = gfx::ImageSkia::CreateFrom1xBitmap(*resized_bitmap);
153 image_.MakeThreadSafe();
142 FOR_EACH_OBSERVER(WallpaperResizerObserver, observers_, 154 FOR_EACH_OBSERVER(WallpaperResizerObserver, observers_,
143 OnWallpaperResized()); 155 OnWallpaperResized());
144 } 156 }
145 157
146 } // namespace ash 158 } // namespace ash
OLDNEW
« no previous file with comments | « ash/desktop_background/wallpaper_resizer.h ('k') | ash/desktop_background/wallpaper_resizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698