| 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 COMPONENTS_WALLPAPER_WALLPAPER_RESIZER_H_ | 5 #ifndef COMPONENTS_WALLPAPER_WALLPAPER_RESIZER_H_ |
| 6 #define COMPONENTS_WALLPAPER_WALLPAPER_RESIZER_H_ | 6 #define COMPONENTS_WALLPAPER_WALLPAPER_RESIZER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 13 #include "components/wallpaper/wallpaper_layout.h" | 14 #include "components/wallpaper/wallpaper_layout.h" |
| 14 #include "components/wallpaper/wallpaper_resizer_observer.h" | 15 #include "components/wallpaper/wallpaper_resizer_observer.h" |
| 15 #include "skia/ext/image_operations.h" | 16 #include "skia/ext/image_operations.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 18 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 19 #include "ui/gfx/image/image_skia.h" | 20 #include "ui/gfx/image/image_skia.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class SequencedWorkerPool; | 23 class TaskRunner; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace wallpaper { | 26 namespace wallpaper { |
| 26 | 27 |
| 27 class WallpaperResizerObserver; | 28 class WallpaperResizerObserver; |
| 28 | 29 |
| 29 // Stores the current wallpaper data and resize it to |target_size| if needed. | 30 // Stores the current wallpaper data and resize it to |target_size| if needed. |
| 30 class WALLPAPER_EXPORT WallpaperResizer { | 31 class WALLPAPER_EXPORT WallpaperResizer { |
| 31 public: | 32 public: |
| 32 // Returns a unique identifier corresponding to |image|, suitable for | 33 // Returns a unique identifier corresponding to |image|, suitable for |
| 33 // comparison against the value returned by original_image_id(). If the image | 34 // comparison against the value returned by original_image_id(). If the image |
| 34 // is modified, its ID will change. | 35 // is modified, its ID will change. |
| 35 static uint32_t GetImageId(const gfx::ImageSkia& image); | 36 static uint32_t GetImageId(const gfx::ImageSkia& image); |
| 36 | 37 |
| 37 WallpaperResizer(const gfx::ImageSkia& image, | 38 WallpaperResizer(const gfx::ImageSkia& image, |
| 38 const gfx::Size& target_size, | 39 const gfx::Size& target_size, |
| 39 WallpaperLayout layout, | 40 WallpaperLayout layout, |
| 40 base::SequencedWorkerPool* worker_pool_ptr); | 41 const scoped_refptr<base::TaskRunner>& task_runner); |
| 41 | 42 |
| 42 ~WallpaperResizer(); | 43 ~WallpaperResizer(); |
| 43 | 44 |
| 44 const gfx::ImageSkia& image() const { return image_; } | 45 const gfx::ImageSkia& image() const { return image_; } |
| 45 uint32_t original_image_id() const { return original_image_id_; } | 46 uint32_t original_image_id() const { return original_image_id_; } |
| 46 WallpaperLayout layout() const { return layout_; } | 47 WallpaperLayout layout() const { return layout_; } |
| 47 base::SequencedWorkerPool* worker_pool() const { return worker_pool_; } | |
| 48 | 48 |
| 49 // Called on the UI thread to run Resize() on the worker pool and post an | 49 // Called on the UI thread to run Resize() on the task runner and post an |
| 50 // OnResizeFinished() task back to the UI thread on completion. | 50 // OnResizeFinished() task back to the UI thread on completion. |
| 51 void StartResize(); | 51 void StartResize(); |
| 52 | 52 |
| 53 // Add/Remove observers. | 53 // Add/Remove observers. |
| 54 void AddObserver(WallpaperResizerObserver* observer); | 54 void AddObserver(WallpaperResizerObserver* observer); |
| 55 void RemoveObserver(WallpaperResizerObserver* observer); | 55 void RemoveObserver(WallpaperResizerObserver* observer); |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 // Copies |resized_bitmap| to |image_| and notifies observers after Resize() | 58 // Copies |resized_bitmap| to |image_| and notifies observers after Resize() |
| 59 // has finished running. | 59 // has finished running. |
| 60 void OnResizeFinished(SkBitmap* resized_bitmap); | 60 void OnResizeFinished(SkBitmap* resized_bitmap); |
| 61 | 61 |
| 62 base::ObserverList<WallpaperResizerObserver> observers_; | 62 base::ObserverList<WallpaperResizerObserver> observers_; |
| 63 | 63 |
| 64 // Image that should currently be used for wallpaper. It initially | 64 // Image that should currently be used for wallpaper. It initially |
| 65 // contains the original image and is updated to contain the resized | 65 // contains the original image and is updated to contain the resized |
| 66 // image by OnResizeFinished(). | 66 // image by OnResizeFinished(). |
| 67 gfx::ImageSkia image_; | 67 gfx::ImageSkia image_; |
| 68 | 68 |
| 69 // Unique identifier corresponding to the original (i.e. pre-resize) |image_|. | 69 // Unique identifier corresponding to the original (i.e. pre-resize) |image_|. |
| 70 uint32_t original_image_id_; | 70 uint32_t original_image_id_; |
| 71 | 71 |
| 72 gfx::Size target_size_; | 72 gfx::Size target_size_; |
| 73 | 73 |
| 74 WallpaperLayout layout_; | 74 WallpaperLayout layout_; |
| 75 | 75 |
| 76 base::SequencedWorkerPool* worker_pool_; | 76 scoped_refptr<base::TaskRunner> task_runner_; |
| 77 | 77 |
| 78 base::WeakPtrFactory<WallpaperResizer> weak_ptr_factory_; | 78 base::WeakPtrFactory<WallpaperResizer> weak_ptr_factory_; |
| 79 | 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(WallpaperResizer); | 80 DISALLOW_COPY_AND_ASSIGN(WallpaperResizer); |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 } // namespace wallpaper | 83 } // namespace wallpaper |
| 84 | 84 |
| 85 #endif // COMPONENTS_WALLPAPER_WALLPAPER_RESIZER_H_ | 85 #endif // COMPONENTS_WALLPAPER_WALLPAPER_RESIZER_H_ |
| OLD | NEW |