| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 class WallpaperResizer; | 32 class WallpaperResizer; |
| 33 } | 33 } |
| 34 | 34 |
| 35 namespace ash { | 35 namespace ash { |
| 36 | 36 |
| 37 class WallpaperControllerObserver; | 37 class WallpaperControllerObserver; |
| 38 | 38 |
| 39 // Controls the desktop background wallpaper: | 39 // Controls the desktop background wallpaper: |
| 40 // - Sets a wallpaper image and layout; | 40 // - Sets a wallpaper image and layout; |
| 41 // - Handles display change (add/remove display, configuration change etc); | 41 // - Handles display change (add/remove display, configuration change etc); |
| 42 // - Calculates prominent color for shelf; | 42 // - Calculates prominent colors. |
| 43 // - Move wallpaper to locked container(s) when session state is not ACTIVE to | 43 // - 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 | 44 // hide the user desktop and move it to unlocked container when session |
| 45 // state is ACTIVE; | 45 // state is ACTIVE; |
| 46 class ASH_EXPORT WallpaperController | 46 class ASH_EXPORT WallpaperController |
| 47 : public NON_EXPORTED_BASE(mojom::WallpaperController), | 47 : public NON_EXPORTED_BASE(mojom::WallpaperController), |
| 48 public WindowTreeHostManager::Observer, | 48 public WindowTreeHostManager::Observer, |
| 49 public ShellObserver, | 49 public ShellObserver, |
| 50 public wallpaper::WallpaperResizerObserver, | 50 public wallpaper::WallpaperResizerObserver, |
| 51 public wallpaper::WallpaperColorCalculatorObserver, | 51 public wallpaper::WallpaperColorCalculatorObserver, |
| 52 public SessionObserver, | 52 public SessionObserver, |
| 53 public NON_EXPORTED_BASE(ui::CompositorLockClient) { | 53 public NON_EXPORTED_BASE(ui::CompositorLockClient) { |
| 54 public: | 54 public: |
| 55 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; | 55 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; |
| 56 | 56 |
| 57 // The value assigned to |prominent_color_| if extraction fails or the feature | 57 // This enum is used to get the corresponding prominent color from the |
| 58 // is disabled (e.g. command line, lock/login screens). | 58 // calculation results of |color_calculator_|. |
| 59 static constexpr SkColor kInvalidColor = SK_ColorTRANSPARENT; | 59 enum ColorProfileIndex { |
| 60 COLOR_PROFILE_INDEX_DARK_VIBRANT = 0, |
| 61 COLOR_PROFILE_INDEX_NORMAL_VIBRANT, |
| 62 COLOR_PROFILE_INDEX_LIGHT_VIBRANT, |
| 63 COLOR_PROFILE_INDEX_DARK_MUTED, |
| 64 COLOR_PROFILE_INDEX_NORMAL_MUTED, |
| 65 COLOR_PROFILE_INDEX_LIGHT_MUTED, |
| 66 }; |
| 67 |
| 68 // The value assigned if extraction fails or the feature is disabled (e.g. |
| 69 // command line, lock/login screens). |
| 70 static const SkColor kInvalidColor; |
| 60 | 71 |
| 61 WallpaperController(); | 72 WallpaperController(); |
| 62 ~WallpaperController() override; | 73 ~WallpaperController() override; |
| 63 | 74 |
| 64 // Binds the mojom::WallpaperController interface request to this object. | 75 // Binds the mojom::WallpaperController interface request to this object. |
| 65 void BindRequest(mojom::WallpaperControllerRequest request); | 76 void BindRequest(mojom::WallpaperControllerRequest request); |
| 66 | 77 |
| 67 // Add/Remove observers. | 78 // Add/Remove observers. |
| 68 void AddObserver(WallpaperControllerObserver* observer); | 79 void AddObserver(WallpaperControllerObserver* observer); |
| 69 void RemoveObserver(WallpaperControllerObserver* observer); | 80 void RemoveObserver(WallpaperControllerObserver* observer); |
| 70 | 81 |
| 71 SkColor prominent_color() const { return prominent_color_; } | 82 std::vector<SkColor> prominent_colors() const { return prominent_colors_; } |
| 83 |
| 84 // Returns the corresponding color profile index based on the color profiles |
| 85 // passed to the |color_calculator_|. |
| 86 WallpaperController::ColorProfileIndex GetColorProfileIndex( |
| 87 color_utils::ColorProfile color_profile) const; |
| 72 | 88 |
| 73 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there | 89 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there |
| 74 // is no image, e.g. wallpaper is none. | 90 // is no image, e.g. wallpaper is none. |
| 75 gfx::ImageSkia GetWallpaper() const; | 91 gfx::ImageSkia GetWallpaper() const; |
| 76 uint32_t GetWallpaperOriginalImageId() const; | 92 uint32_t GetWallpaperOriginalImageId() const; |
| 77 | 93 |
| 78 wallpaper::WallpaperLayout GetWallpaperLayout() const; | 94 wallpaper::WallpaperLayout GetWallpaperLayout() const; |
| 79 | 95 |
| 80 // Sets the wallpaper and alerts observers of changes. | 96 // Sets the wallpaper and alerts observers of changes. |
| 81 void SetWallpaperImage(const gfx::ImageSkia& image, | 97 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. | 161 // Returns true if a wallpaper moved. |
| 146 bool ReparentWallpaper(int container); | 162 bool ReparentWallpaper(int container); |
| 147 | 163 |
| 148 // Returns the wallpaper container id for unlocked and locked states. | 164 // Returns the wallpaper container id for unlocked and locked states. |
| 149 int GetWallpaperContainerId(bool locked); | 165 int GetWallpaperContainerId(bool locked); |
| 150 | 166 |
| 151 // Reload the wallpaper. |clear_cache| specifies whether to clear the | 167 // Reload the wallpaper. |clear_cache| specifies whether to clear the |
| 152 // wallpaper cahce or not. | 168 // wallpaper cahce or not. |
| 153 void UpdateWallpaper(bool clear_cache); | 169 void UpdateWallpaper(bool clear_cache); |
| 154 | 170 |
| 155 // Sets |prominent_color_| and notifies the observers if there is a change. | 171 // Sets |prominent_colors_| and notifies the observers if there is a change. |
| 156 void SetProminentColor(SkColor color); | 172 void SetProminentColors(const std::vector<SkColor>& prominent_colors); |
| 157 | 173 |
| 158 // Calculates a prominent color based on the wallpaper image and notifies | 174 // Calculates prominent colors based on the wallpaper image and notifies |
| 159 // |observers_| of the value, either synchronously or asynchronously. In some | 175 // |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 | 176 // cases the wallpaper image will not actually be processed (e.g. user isn't |
| 161 // logged in, feature isn't enabled). | 177 // logged in, feature isn't enabled). |
| 162 // If an existing calculation is in progress it is destroyed. | 178 // If an existing calculation is in progress it is destroyed. |
| 163 void CalculateWallpaperColors(); | 179 void CalculateWallpaperColors(); |
| 164 | 180 |
| 165 // Returns false when the color extraction algorithm shouldn't be run based on | 181 // Returns false when the color extraction algorithm shouldn't be run based on |
| 166 // system state (e.g. wallpaper image, SessionState, etc.). | 182 // system state (e.g. wallpaper image, SessionState, etc.). |
| 167 bool ShouldCalculateColors() const; | 183 bool ShouldCalculateColors() const; |
| 168 | 184 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 190 // Bindings for the WallpaperController interface. | 206 // Bindings for the WallpaperController interface. |
| 191 mojo::BindingSet<mojom::WallpaperController> bindings_; | 207 mojo::BindingSet<mojom::WallpaperController> bindings_; |
| 192 | 208 |
| 193 base::ObserverList<WallpaperControllerObserver> observers_; | 209 base::ObserverList<WallpaperControllerObserver> observers_; |
| 194 | 210 |
| 195 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; | 211 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; |
| 196 | 212 |
| 197 // Asynchronous task to extract colors from the wallpaper. | 213 // Asynchronous task to extract colors from the wallpaper. |
| 198 std::unique_ptr<wallpaper::WallpaperColorCalculator> color_calculator_; | 214 std::unique_ptr<wallpaper::WallpaperColorCalculator> color_calculator_; |
| 199 | 215 |
| 200 // The prominent color extracted from the current wallpaper. | 216 // The prominent colors extracted from the current wallpaper. |
| 201 // kInvalidColor is used by default or if extracting colors fails. | 217 // kInvalidColor is used by default or if extracting colors fails. |
| 202 SkColor prominent_color_; | 218 std::vector<SkColor> prominent_colors_; |
| 219 |
| 220 // Caches the color profiles that need to do wallpaper color extracting. |
| 221 const color_utils::ColorProfiles color_profiles_; |
| 203 | 222 |
| 204 gfx::Size current_max_display_size_; | 223 gfx::Size current_max_display_size_; |
| 205 | 224 |
| 206 base::OneShotTimer timer_; | 225 base::OneShotTimer timer_; |
| 207 | 226 |
| 208 int wallpaper_reload_delay_; | 227 int wallpaper_reload_delay_; |
| 209 | 228 |
| 210 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 229 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| 211 | 230 |
| 212 ScopedSessionObserver scoped_session_observer_; | 231 ScopedSessionObserver scoped_session_observer_; |
| 213 | 232 |
| 214 std::unique_ptr<ui::CompositorLock> compositor_lock_; | 233 std::unique_ptr<ui::CompositorLock> compositor_lock_; |
| 215 | 234 |
| 216 DISALLOW_COPY_AND_ASSIGN(WallpaperController); | 235 DISALLOW_COPY_AND_ASSIGN(WallpaperController); |
| 217 }; | 236 }; |
| 218 | 237 |
| 219 } // namespace ash | 238 } // namespace ash |
| 220 | 239 |
| 221 #endif // ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ | 240 #endif // ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ |
| OLD | NEW |