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

Unified 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: style fix 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/desktop_background/wallpaper_resizer.cc
diff --git a/ash/desktop_background/wallpaper_resizer.cc b/ash/desktop_background/wallpaper_resizer.cc
index b75e262e25f2ac8dbd1bb81a7e465a11fc21acaf..06d8c97da7d53c54b0e06d40c72c8488314c314c 100644
--- a/ash/desktop_background/wallpaper_resizer.cc
+++ b/ash/desktop_background/wallpaper_resizer.cc
@@ -10,7 +10,9 @@
#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/worker_pool.h"
#include "content/public/browser/browser_thread.h"
+#include "third_party/skia/include/core/SkImage.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image_skia_rep.h"
#include "ui/gfx/skia_util.h"
using content::BrowserThread;
@@ -91,23 +93,33 @@ void Resize(SkBitmap orig_bitmap,
} // namespace
+// static
+uint32_t WallpaperResizer::GetImageId(const gfx::ImageSkia& image) {
+ const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(1.0f);
+ return image_rep.is_null() ? 0 : image_rep.sk_bitmap().getGenerationID();
+}
+
WallpaperResizer::WallpaperResizer(int image_resource_id,
const gfx::Size& target_size,
WallpaperLayout layout)
- : wallpaper_image_(*(ui::ResourceBundle::GetSharedInstance().
+ : image_(*(ui::ResourceBundle::GetSharedInstance().
GetImageNamed(image_resource_id).ToImageSkia())),
+ original_image_id_(GetImageId(image_)),
target_size_(target_size),
layout_(layout),
weak_ptr_factory_(this) {
+ image_.MakeThreadSafe();
}
WallpaperResizer::WallpaperResizer(const gfx::ImageSkia& image,
const gfx::Size& target_size,
WallpaperLayout layout)
- : wallpaper_image_(image),
+ : image_(image),
+ original_image_id_(GetImageId(image_)),
target_size_(target_size),
layout_(layout),
weak_ptr_factory_(this) {
+ image_.MakeThreadSafe();
}
WallpaperResizer::~WallpaperResizer() {
@@ -118,7 +130,7 @@ void WallpaperResizer::StartResize() {
SkBitmap* resized_bitmap = new SkBitmap;
if (!content::BrowserThread::PostBlockingPoolTaskAndReply(
FROM_HERE,
- base::Bind(&Resize, *wallpaper_image_.bitmap(), target_size_,
+ base::Bind(&Resize, *image_.bitmap(), target_size_,
layout_, resized_bitmap),
base::Bind(&WallpaperResizer::OnResizeFinished,
weak_ptr_factory_.GetWeakPtr(),
@@ -138,7 +150,7 @@ void WallpaperResizer::RemoveObserver(WallpaperResizerObserver* observer) {
void WallpaperResizer::OnResizeFinished(SkBitmap* resized_bitmap) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- wallpaper_image_ = gfx::ImageSkia::CreateFrom1xBitmap(*resized_bitmap);
+ image_ = gfx::ImageSkia::CreateFrom1xBitmap(*resized_bitmap);
FOR_EACH_OBSERVER(WallpaperResizerObserver, observers_,
OnWallpaperResized());
}
« 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