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

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

Issue 215293003: Move all wallpaper file loading and decoding from DesktopBackgroundController to WallpaperManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Call WM::SetDefaultWallpaper() from ShellBrowserMainParts::PreMainMessageLoopRun(). Created 6 years, 8 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
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 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_ 5 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_
6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_ 6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_
7 7
8 #include "ash/ash_export.h" 8 #include "ash/ash_export.h"
9 #include "ash/desktop_background/desktop_background_controller.h" 9 #include "ash/desktop_background/desktop_background_controller.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "skia/ext/image_operations.h" 12 #include "skia/ext/image_operations.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/image/image_skia.h" 14 #include "ui/gfx/image/image_skia.h"
15 #include "ui/gfx/size.h" 15 #include "ui/gfx/size.h"
16 16
17 namespace ash { 17 namespace ash {
18 18
19 class WallpaperResizerObserver; 19 class WallpaperResizerObserver;
20 20
21 extern const int kInvalidResourceID;
22
21 // Stores the current wallpaper data and resize it to |target_size| if needed. 23 // Stores the current wallpaper data and resize it to |target_size| if needed.
22 class ASH_EXPORT WallpaperResizer { 24 class ASH_EXPORT WallpaperResizer {
23 public: 25 public:
24 // Returns a unique identifier corresponding to |image|, suitable for 26 // Returns a unique identifier corresponding to |image|, suitable for
25 // comparison against the value returned by original_image_id(). If the image 27 // comparison against the value returned by original_image_id(). If the image
26 // is modified, its ID will change. 28 // is modified, its ID will change.
27 static uint32_t GetImageId(const gfx::ImageSkia& image); 29 static uint32_t GetImageId(const gfx::ImageSkia& image);
28 30
29 WallpaperResizer(int image_resource_id, 31 WallpaperResizer(int image_resource_id,
30 const gfx::Size& target_size, 32 const gfx::Size& target_size,
31 WallpaperLayout layout); 33 WallpaperLayout layout);
32 34
33 WallpaperResizer(const gfx::ImageSkia& image, 35 WallpaperResizer(const gfx::ImageSkia& image,
34 const gfx::Size& target_size, 36 const gfx::Size& target_size,
35 WallpaperLayout layout); 37 WallpaperLayout layout);
36 38
37 ~WallpaperResizer(); 39 ~WallpaperResizer();
38 40
39 const gfx::ImageSkia& image() const { return image_; } 41 const gfx::ImageSkia& image() const { return image_; }
40 uint32_t original_image_id() const { return original_image_id_; } 42 uint32_t original_image_id() const { return original_image_id_; }
41 WallpaperLayout layout() const { return layout_; } 43 WallpaperLayout layout() const { return layout_; }
42 44
45 int resource_id() const { return resource_id_; }
46
43 // Called on the UI thread to run Resize() on the worker pool and post an 47 // Called on the UI thread to run Resize() on the worker pool and post an
44 // OnResizeFinished() task back to the UI thread on completion. 48 // OnResizeFinished() task back to the UI thread on completion.
45 void StartResize(); 49 void StartResize();
46 50
47 // Add/Remove observers. 51 // Add/Remove observers.
48 void AddObserver(WallpaperResizerObserver* observer); 52 void AddObserver(WallpaperResizerObserver* observer);
49 void RemoveObserver(WallpaperResizerObserver* observer); 53 void RemoveObserver(WallpaperResizerObserver* observer);
50 54
51 private: 55 private:
52 // Copies |resized_bitmap| to |image_| and notifies observers after Resize() 56 // Copies |resized_bitmap| to |image_| and notifies observers after Resize()
53 // has finished running. 57 // has finished running.
54 void OnResizeFinished(SkBitmap* resized_bitmap); 58 void OnResizeFinished(SkBitmap* resized_bitmap);
55 59
56 ObserverList<WallpaperResizerObserver> observers_; 60 ObserverList<WallpaperResizerObserver> observers_;
57 61
58 // Image that should currently be used for wallpaper. It initially 62 // Image that should currently be used for wallpaper. It initially
59 // contains the original image and is updated to contain the resized 63 // contains the original image and is updated to contain the resized
60 // image by OnResizeFinished(). 64 // image by OnResizeFinished().
61 gfx::ImageSkia image_; 65 gfx::ImageSkia image_;
62 66
63 // Unique identifier corresponding to the original (i.e. pre-resize) |image_|. 67 // Unique identifier corresponding to the original (i.e. pre-resize) |image_|.
64 uint32_t original_image_id_; 68 uint32_t original_image_id_;
65 69
70 // kInvalidResourceID if image was not obtained from resources.
71 const int resource_id_;
72
66 gfx::Size target_size_; 73 gfx::Size target_size_;
67 74
68 WallpaperLayout layout_; 75 WallpaperLayout layout_;
69 76
70 base::WeakPtrFactory<WallpaperResizer> weak_ptr_factory_; 77 base::WeakPtrFactory<WallpaperResizer> weak_ptr_factory_;
71 78
72 DISALLOW_COPY_AND_ASSIGN(WallpaperResizer); 79 DISALLOW_COPY_AND_ASSIGN(WallpaperResizer);
73 }; 80 };
74 81
75 } // namespace ash 82 } // namespace ash
76 83
77 84
78 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_ 85 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698