OLD | NEW |
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 // Stores the current wallpaper data and resize it to |target_size| if needed. | 21 // Stores the current wallpaper data and resize it to |target_size| if needed. |
22 class ASH_EXPORT WallpaperResizer { | 22 class ASH_EXPORT WallpaperResizer { |
23 public: | 23 public: |
| 24 // Returns a unique identifier corresponding to |image|, suitable for |
| 25 // comparison against the value returned by original_image_id(). If the image |
| 26 // is modified, its ID will change. |
| 27 static uint32_t GetImageId(const gfx::ImageSkia& image); |
| 28 |
24 WallpaperResizer(int image_resource_id, | 29 WallpaperResizer(int image_resource_id, |
25 const gfx::Size& target_size, | 30 const gfx::Size& target_size, |
26 WallpaperLayout layout); | 31 WallpaperLayout layout); |
27 | 32 |
28 WallpaperResizer(const gfx::ImageSkia& image, | 33 WallpaperResizer(const gfx::ImageSkia& image, |
29 const gfx::Size& target_size, | 34 const gfx::Size& target_size, |
30 WallpaperLayout layout); | 35 WallpaperLayout layout); |
31 | 36 |
32 ~WallpaperResizer(); | 37 ~WallpaperResizer(); |
33 | 38 |
34 const gfx::ImageSkia& wallpaper_image() const { return wallpaper_image_; } | 39 const gfx::ImageSkia& image() const { return image_; } |
35 const WallpaperLayout layout() const { return layout_; } | 40 uint32_t original_image_id() const { return original_image_id_; } |
| 41 WallpaperLayout layout() const { return layout_; } |
36 | 42 |
37 // Called on the UI thread to run Resize() on the worker pool and post an | 43 // Called on the UI thread to run Resize() on the worker pool and post an |
38 // OnResizeFinished() task back to the UI thread on completion. | 44 // OnResizeFinished() task back to the UI thread on completion. |
39 void StartResize(); | 45 void StartResize(); |
40 | 46 |
41 // Add/Remove observers. | 47 // Add/Remove observers. |
42 void AddObserver(WallpaperResizerObserver* observer); | 48 void AddObserver(WallpaperResizerObserver* observer); |
43 void RemoveObserver(WallpaperResizerObserver* observer); | 49 void RemoveObserver(WallpaperResizerObserver* observer); |
44 | 50 |
45 private: | 51 private: |
46 // Copies |resized_bitmap| to |wallpaper_image_| and notifies observers | 52 // Copies |resized_bitmap| to |image_| and notifies observers after Resize() |
47 // after Resize() has finished running. | 53 // has finished running. |
48 void OnResizeFinished(SkBitmap* resized_bitmap); | 54 void OnResizeFinished(SkBitmap* resized_bitmap); |
49 | 55 |
50 ObserverList<WallpaperResizerObserver> observers_; | 56 ObserverList<WallpaperResizerObserver> observers_; |
51 | 57 |
52 // Image that should currently be used for wallpaper. It initially | 58 // Image that should currently be used for wallpaper. It initially |
53 // contains the original image and is updated to contain the resized | 59 // contains the original image and is updated to contain the resized |
54 // image by OnResizeFinished(). | 60 // image by OnResizeFinished(). |
55 gfx::ImageSkia wallpaper_image_; | 61 gfx::ImageSkia image_; |
| 62 |
| 63 // Unique identifier corresponding to the original (i.e. pre-resize) |image_|. |
| 64 uint32_t original_image_id_; |
56 | 65 |
57 gfx::Size target_size_; | 66 gfx::Size target_size_; |
58 | 67 |
59 WallpaperLayout layout_; | 68 WallpaperLayout layout_; |
60 | 69 |
61 base::WeakPtrFactory<WallpaperResizer> weak_ptr_factory_; | 70 base::WeakPtrFactory<WallpaperResizer> weak_ptr_factory_; |
62 | 71 |
63 DISALLOW_COPY_AND_ASSIGN(WallpaperResizer); | 72 DISALLOW_COPY_AND_ASSIGN(WallpaperResizer); |
64 }; | 73 }; |
65 | 74 |
66 } // namespace ash | 75 } // namespace ash |
67 | 76 |
68 | 77 |
69 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_ | 78 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_WALLPAPER_RESIZER_H_ |
OLD | NEW |