Chromium Code Reviews| 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 // This enum is used to get the corresponding prominent color from the |
| 58 // is disabled (e.g. command line, lock/login screens). | 60 // calculation results of |color_calculator_|. |
| 59 static constexpr SkColor kInvalidColor = SK_ColorTRANSPARENT; | 61 enum ColorProfileIndex { |
| 62 COLOR_PROFILE_INDEX_DARK_VIBRANT = 0, | |
| 63 COLOR_PROFILE_INDEX_NORMAL_VIBRANT, | |
| 64 COLOR_PROFILE_INDEX_LIGHT_VIBRANT, | |
| 65 COLOR_PROFILE_INDEX_DARK_MUTED, | |
| 66 COLOR_PROFILE_INDEX_NORMAL_MUTED, | |
| 67 COLOR_PROFILE_INDEX_LIGHT_MUTED, | |
| 68 }; | |
| 69 | |
| 70 // The value assigned if extraction fails or the feature is disabled (e.g. | |
| 71 // command line, lock/login screens). | |
| 72 static const SkColor kInvalidColor; | |
|
xdai1
2017/06/21 16:29:30
I think we prefer constexpr now?
And for static c
Qiang(Joe) Xu
2017/06/21 22:35:26
as discussed offline with xiyuan, constexpr by def
| |
| 60 | 73 |
| 61 WallpaperController(); | 74 WallpaperController(); |
| 62 ~WallpaperController() override; | 75 ~WallpaperController() override; |
| 63 | 76 |
| 64 // Binds the mojom::WallpaperController interface request to this object. | 77 // Binds the mojom::WallpaperController interface request to this object. |
| 65 void BindRequest(mojom::WallpaperControllerRequest request); | 78 void BindRequest(mojom::WallpaperControllerRequest request); |
| 66 | 79 |
| 67 // Add/Remove observers. | 80 // Add/Remove observers. |
| 68 void AddObserver(WallpaperControllerObserver* observer); | 81 void AddObserver(WallpaperControllerObserver* observer); |
| 69 void RemoveObserver(WallpaperControllerObserver* observer); | 82 void RemoveObserver(WallpaperControllerObserver* observer); |
| 70 | 83 |
| 71 SkColor prominent_color() const { return prominent_color_; } | 84 std::vector<SkColor> prominent_colors() const { return prominent_colors_; } |
| 85 | |
| 86 // Returns the corresponding color profile index based on the color profiles | |
| 87 // passed to the |color_calculator_|. | |
| 88 WallpaperController::ColorProfileIndex GetColorProfileIndex( | |
|
bruthig
2017/06/21 15:54:17
nit:Do WallpaperController clients really need to
Qiang(Joe) Xu
2017/06/21 22:35:27
Done.
bruthig
2017/06/22 15:31:09
Much thanks =D
| |
| 89 color_utils::ColorProfile color_profile) const; | |
| 72 | 90 |
| 73 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there | 91 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there |
| 74 // is no image, e.g. wallpaper is none. | 92 // is no image, e.g. wallpaper is none. |
| 75 gfx::ImageSkia GetWallpaper() const; | 93 gfx::ImageSkia GetWallpaper() const; |
| 76 uint32_t GetWallpaperOriginalImageId() const; | 94 uint32_t GetWallpaperOriginalImageId() const; |
| 77 | 95 |
| 78 wallpaper::WallpaperLayout GetWallpaperLayout() const; | 96 wallpaper::WallpaperLayout GetWallpaperLayout() const; |
| 79 | 97 |
| 80 // Sets the wallpaper and alerts observers of changes. | 98 // Sets the wallpaper and alerts observers of changes. |
| 81 void SetWallpaperImage(const gfx::ImageSkia& image, | 99 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. | 163 // Returns true if a wallpaper moved. |
| 146 bool ReparentWallpaper(int container); | 164 bool ReparentWallpaper(int container); |
| 147 | 165 |
| 148 // Returns the wallpaper container id for unlocked and locked states. | 166 // Returns the wallpaper container id for unlocked and locked states. |
| 149 int GetWallpaperContainerId(bool locked); | 167 int GetWallpaperContainerId(bool locked); |
| 150 | 168 |
| 151 // Reload the wallpaper. |clear_cache| specifies whether to clear the | 169 // Reload the wallpaper. |clear_cache| specifies whether to clear the |
| 152 // wallpaper cahce or not. | 170 // wallpaper cahce or not. |
| 153 void UpdateWallpaper(bool clear_cache); | 171 void UpdateWallpaper(bool clear_cache); |
| 154 | 172 |
| 155 // Sets |prominent_color_| and notifies the observers if there is a change. | 173 // Sets |prominent_colors_| and notifies the observers if there is a change. |
| 156 void SetProminentColor(SkColor color); | 174 void SetProminentColors(const std::vector<SkColor>& prominent_colors); |
| 157 | 175 |
| 158 // Calculates a prominent color based on the wallpaper image and notifies | 176 // Calculates prominent colors based on the wallpaper image and notifies |
| 159 // |observers_| of the value, either synchronously or asynchronously. In some | 177 // |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 | 178 // cases the wallpaper image will not actually be processed (e.g. user isn't |
| 161 // logged in, feature isn't enabled). | 179 // logged in, feature isn't enabled). |
| 162 // If an existing calculation is in progress it is destroyed. | 180 // If an existing calculation is in progress it is destroyed. |
| 163 void CalculateWallpaperColors(); | 181 void CalculateWallpaperColors(); |
| 164 | 182 |
| 165 // Returns false when the color extraction algorithm shouldn't be run based on | 183 // Returns false when the color extraction algorithm shouldn't be run based on |
| 166 // system state (e.g. wallpaper image, SessionState, etc.). | 184 // system state (e.g. wallpaper image, SessionState, etc.). |
| 167 bool ShouldCalculateColors() const; | 185 bool ShouldCalculateColors() const; |
| 168 | 186 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 190 // Bindings for the WallpaperController interface. | 208 // Bindings for the WallpaperController interface. |
| 191 mojo::BindingSet<mojom::WallpaperController> bindings_; | 209 mojo::BindingSet<mojom::WallpaperController> bindings_; |
| 192 | 210 |
| 193 base::ObserverList<WallpaperControllerObserver> observers_; | 211 base::ObserverList<WallpaperControllerObserver> observers_; |
| 194 | 212 |
| 195 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; | 213 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; |
| 196 | 214 |
| 197 // Asynchronous task to extract colors from the wallpaper. | 215 // Asynchronous task to extract colors from the wallpaper. |
| 198 std::unique_ptr<wallpaper::WallpaperColorCalculator> color_calculator_; | 216 std::unique_ptr<wallpaper::WallpaperColorCalculator> color_calculator_; |
| 199 | 217 |
| 200 // The prominent color extracted from the current wallpaper. | 218 // The prominent colors extracted from the current wallpaper. |
| 201 // kInvalidColor is used by default or if extracting colors fails. | 219 // kInvalidColor is used by default or if extracting colors fails. |
| 202 SkColor prominent_color_; | 220 std::vector<SkColor> prominent_colors_; |
| 221 | |
| 222 // Caches the color profiles that need to do wallpaper color extracting. | |
| 223 const std::vector<color_utils::ColorProfile> color_profiles_; | |
| 203 | 224 |
| 204 gfx::Size current_max_display_size_; | 225 gfx::Size current_max_display_size_; |
| 205 | 226 |
| 206 base::OneShotTimer timer_; | 227 base::OneShotTimer timer_; |
| 207 | 228 |
| 208 int wallpaper_reload_delay_; | 229 int wallpaper_reload_delay_; |
| 209 | 230 |
| 210 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 231 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| 211 | 232 |
| 212 ScopedSessionObserver scoped_session_observer_; | 233 ScopedSessionObserver scoped_session_observer_; |
| 213 | 234 |
| 214 std::unique_ptr<ui::CompositorLock> compositor_lock_; | 235 std::unique_ptr<ui::CompositorLock> compositor_lock_; |
| 215 | 236 |
| 216 DISALLOW_COPY_AND_ASSIGN(WallpaperController); | 237 DISALLOW_COPY_AND_ASSIGN(WallpaperController); |
| 217 }; | 238 }; |
| 218 | 239 |
| 219 } // namespace ash | 240 } // namespace ash |
| 220 | 241 |
| 221 #endif // ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ | 242 #endif // ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ |
| OLD | NEW |