OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_WALLPAPER_WALLPAPER_CONTROLLER_H_ | 5 #ifndef ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ |
6 #define ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ | 6 #define ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
11 #include "ash/display/window_tree_host_manager.h" | 11 #include "ash/display/window_tree_host_manager.h" |
12 #include "ash/public/interfaces/wallpaper.mojom.h" | 12 #include "ash/public/interfaces/wallpaper.mojom.h" |
13 #include "ash/session/session_observer.h" | 13 #include "ash/session/session_observer.h" |
14 #include "ash/shell_observer.h" | 14 #include "ash/shell_observer.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
18 #include "components/wallpaper/wallpaper_color_calculator_observer.h" | 18 #include "components/wallpaper/wallpaper_color_calculator_observer.h" |
19 #include "components/wallpaper/wallpaper_layout.h" | 19 #include "components/wallpaper/wallpaper_layout.h" |
20 #include "components/wallpaper/wallpaper_resizer_observer.h" | 20 #include "components/wallpaper/wallpaper_resizer_observer.h" |
21 #include "mojo/public/cpp/bindings/binding_set.h" | 21 #include "mojo/public/cpp/bindings/binding_set.h" |
22 #include "ui/compositor/compositor_lock.h" | 22 #include "ui/compositor/compositor_lock.h" |
23 #include "ui/gfx/color_analysis.h" | |
24 #include "ui/gfx/image/image_skia.h" | |
25 | 23 |
26 namespace base { | 24 namespace base { |
27 class SequencedTaskRunner; | 25 class SequencedTaskRunner; |
28 } | 26 } |
29 | 27 |
| 28 namespace color_utils { |
| 29 struct ColorProfile; |
| 30 } |
| 31 |
30 namespace wallpaper { | 32 namespace wallpaper { |
31 class WallpaperColorCalculator; | 33 class WallpaperColorCalculator; |
32 class WallpaperResizer; | 34 class WallpaperResizer; |
33 } | 35 } |
34 | 36 |
35 namespace ash { | 37 namespace ash { |
36 | 38 |
37 class WallpaperControllerObserver; | 39 class WallpaperControllerObserver; |
38 | 40 |
39 // Controls the desktop background wallpaper: | 41 // Controls the desktop background wallpaper: |
40 // - Sets a wallpaper image and layout; | 42 // - Sets a wallpaper image and layout; |
41 // - Handles display change (add/remove display, configuration change etc); | 43 // - Handles display change (add/remove display, configuration change etc); |
42 // - Calculates prominent color for shelf; | 44 // - Calculates prominent colors. |
43 // - Move wallpaper to locked container(s) when session state is not ACTIVE to | 45 // - Move wallpaper to locked container(s) when session state is not ACTIVE to |
44 // hide the user desktop and move it to unlocked container when session | 46 // hide the user desktop and move it to unlocked container when session |
45 // state is ACTIVE; | 47 // state is ACTIVE; |
46 class ASH_EXPORT WallpaperController | 48 class ASH_EXPORT WallpaperController |
47 : public NON_EXPORTED_BASE(mojom::WallpaperController), | 49 : public NON_EXPORTED_BASE(mojom::WallpaperController), |
48 public WindowTreeHostManager::Observer, | 50 public WindowTreeHostManager::Observer, |
49 public ShellObserver, | 51 public ShellObserver, |
50 public wallpaper::WallpaperResizerObserver, | 52 public wallpaper::WallpaperResizerObserver, |
51 public wallpaper::WallpaperColorCalculatorObserver, | 53 public wallpaper::WallpaperColorCalculatorObserver, |
52 public SessionObserver, | 54 public SessionObserver, |
53 public NON_EXPORTED_BASE(ui::CompositorLockClient) { | 55 public NON_EXPORTED_BASE(ui::CompositorLockClient) { |
54 public: | 56 public: |
55 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; | 57 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; |
56 | 58 |
57 // The value assigned to |prominent_color_| if extraction fails or the feature | 59 // The value assigned if extraction fails or the feature is disabled (e.g. |
58 // is disabled (e.g. command line, lock/login screens). | 60 // command line, lock/login screens). |
59 static constexpr SkColor kInvalidColor = SK_ColorTRANSPARENT; | 61 static const SkColor kInvalidColor; |
60 | 62 |
61 WallpaperController(); | 63 WallpaperController(); |
62 ~WallpaperController() override; | 64 ~WallpaperController() override; |
63 | 65 |
64 // Binds the mojom::WallpaperController interface request to this object. | 66 // Binds the mojom::WallpaperController interface request to this object. |
65 void BindRequest(mojom::WallpaperControllerRequest request); | 67 void BindRequest(mojom::WallpaperControllerRequest request); |
66 | 68 |
67 // Add/Remove observers. | 69 // Add/Remove observers. |
68 void AddObserver(WallpaperControllerObserver* observer); | 70 void AddObserver(WallpaperControllerObserver* observer); |
69 void RemoveObserver(WallpaperControllerObserver* observer); | 71 void RemoveObserver(WallpaperControllerObserver* observer); |
70 | 72 |
71 SkColor prominent_color() const { return prominent_color_; } | 73 // Returns the prominent color based on |color_profile|. |
| 74 SkColor GetProminentColor(color_utils::ColorProfile color_profile) const; |
72 | 75 |
73 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there | 76 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there |
74 // is no image, e.g. wallpaper is none. | 77 // is no image, e.g. wallpaper is none. |
75 gfx::ImageSkia GetWallpaper() const; | 78 gfx::ImageSkia GetWallpaper() const; |
76 uint32_t GetWallpaperOriginalImageId() const; | 79 uint32_t GetWallpaperOriginalImageId() const; |
77 | 80 |
78 wallpaper::WallpaperLayout GetWallpaperLayout() const; | 81 wallpaper::WallpaperLayout GetWallpaperLayout() const; |
79 | 82 |
80 // Sets the wallpaper and alerts observers of changes. | 83 // Sets the wallpaper and alerts observers of changes. |
81 void SetWallpaperImage(const gfx::ImageSkia& image, | 84 void SetWallpaperImage(const gfx::ImageSkia& image, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Returns true if a wallpaper moved. | 148 // Returns true if a wallpaper moved. |
146 bool ReparentWallpaper(int container); | 149 bool ReparentWallpaper(int container); |
147 | 150 |
148 // Returns the wallpaper container id for unlocked and locked states. | 151 // Returns the wallpaper container id for unlocked and locked states. |
149 int GetWallpaperContainerId(bool locked); | 152 int GetWallpaperContainerId(bool locked); |
150 | 153 |
151 // Reload the wallpaper. |clear_cache| specifies whether to clear the | 154 // Reload the wallpaper. |clear_cache| specifies whether to clear the |
152 // wallpaper cahce or not. | 155 // wallpaper cahce or not. |
153 void UpdateWallpaper(bool clear_cache); | 156 void UpdateWallpaper(bool clear_cache); |
154 | 157 |
155 // Sets |prominent_color_| and notifies the observers if there is a change. | 158 // Sets |prominent_colors_| and notifies the observers if there is a change. |
156 void SetProminentColor(SkColor color); | 159 void SetProminentColors(const std::vector<SkColor>& prominent_colors); |
157 | 160 |
158 // Calculates a prominent color based on the wallpaper image and notifies | 161 // Calculates prominent colors based on the wallpaper image and notifies |
159 // |observers_| of the value, either synchronously or asynchronously. In some | 162 // |observers_| of the value, either synchronously or asynchronously. In some |
160 // cases the wallpaper image will not actually be processed (e.g. user isn't | 163 // cases the wallpaper image will not actually be processed (e.g. user isn't |
161 // logged in, feature isn't enabled). | 164 // logged in, feature isn't enabled). |
162 // If an existing calculation is in progress it is destroyed. | 165 // If an existing calculation is in progress it is destroyed. |
163 void CalculateWallpaperColors(); | 166 void CalculateWallpaperColors(); |
164 | 167 |
165 // Returns false when the color extraction algorithm shouldn't be run based on | 168 // Returns false when the color extraction algorithm shouldn't be run based on |
166 // system state (e.g. wallpaper image, SessionState, etc.). | 169 // system state (e.g. wallpaper image, SessionState, etc.). |
167 bool ShouldCalculateColors() const; | 170 bool ShouldCalculateColors() const; |
168 | 171 |
(...skipping 21 matching lines...) Expand all Loading... |
190 // Bindings for the WallpaperController interface. | 193 // Bindings for the WallpaperController interface. |
191 mojo::BindingSet<mojom::WallpaperController> bindings_; | 194 mojo::BindingSet<mojom::WallpaperController> bindings_; |
192 | 195 |
193 base::ObserverList<WallpaperControllerObserver> observers_; | 196 base::ObserverList<WallpaperControllerObserver> observers_; |
194 | 197 |
195 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; | 198 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; |
196 | 199 |
197 // Asynchronous task to extract colors from the wallpaper. | 200 // Asynchronous task to extract colors from the wallpaper. |
198 std::unique_ptr<wallpaper::WallpaperColorCalculator> color_calculator_; | 201 std::unique_ptr<wallpaper::WallpaperColorCalculator> color_calculator_; |
199 | 202 |
200 // The prominent color extracted from the current wallpaper. | 203 // The prominent colors extracted from the current wallpaper. |
201 // kInvalidColor is used by default or if extracting colors fails. | 204 // kInvalidColor is used by default or if extracting colors fails. |
202 SkColor prominent_color_; | 205 std::vector<SkColor> prominent_colors_; |
| 206 |
| 207 // Caches the color profiles that need to do wallpaper color extracting. |
| 208 const std::vector<color_utils::ColorProfile> color_profiles_; |
203 | 209 |
204 gfx::Size current_max_display_size_; | 210 gfx::Size current_max_display_size_; |
205 | 211 |
206 base::OneShotTimer timer_; | 212 base::OneShotTimer timer_; |
207 | 213 |
208 int wallpaper_reload_delay_; | 214 int wallpaper_reload_delay_; |
209 | 215 |
210 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 216 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
211 | 217 |
212 ScopedSessionObserver scoped_session_observer_; | 218 ScopedSessionObserver scoped_session_observer_; |
213 | 219 |
214 std::unique_ptr<ui::CompositorLock> compositor_lock_; | 220 std::unique_ptr<ui::CompositorLock> compositor_lock_; |
215 | 221 |
216 DISALLOW_COPY_AND_ASSIGN(WallpaperController); | 222 DISALLOW_COPY_AND_ASSIGN(WallpaperController); |
217 }; | 223 }; |
218 | 224 |
219 } // namespace ash | 225 } // namespace ash |
220 | 226 |
221 #endif // ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ | 227 #endif // ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ |
OLD | NEW |