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

Side by Side Diff: components/wallpaper/wallpaper_resizer.h

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

Powered by Google App Engine
This is Rietveld 408576698