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

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

Issue 2679133003: [ash-md] Wired in the Shelf color to be derived from the Wallpaper. (Closed)
Patch Set: Ready for review. Created 3 years, 10 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_WALLPAPER_COLOR_CALCULATOR_H_
bshe 2017/02/24 18:30:36 nit: should this be COMPONENTS_WALLPAPER_WALLPAPER
bruthig 2017/02/25 17:51:18 Done.
6 #define COMPONENTS_WALLPAPER_COLOR_CALCULATOR_H_
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "components/wallpaper/wallpaper_color_calculator_observer.h"
13 #include "components/wallpaper/wallpaper_export.h"
14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/color_analysis.h"
16 #include "ui/gfx/image/image_skia.h"
17
18 namespace base {
19 class TaskRunner;
20 }
21
22 namespace wallpaper {
23 class WallpaperColorCalculatorObserver;
24
25 // Asynchronously calculates colors based on a wallpaper image.
26 class WALLPAPER_EXPORT WallpaperColorCalculator {
27 public:
28 // |image|, |luma| and |saturation| are the input parameters to the color
29 // calculation that is executed on the |task_runner|.
30 WallpaperColorCalculator(const gfx::ImageSkia& image,
31 color_utils::LumaRange luma,
32 color_utils::SaturationRange saturation,
33 scoped_refptr<base::TaskRunner> task_runner);
34 ~WallpaperColorCalculator();
35
36 void AddObserver(WallpaperColorCalculatorObserver* observer);
37
38 void RemoveObserver(WallpaperColorCalculatorObserver* observer);
39
40 // Initiates the calculation and returns false if the calculation fails to be
41 // initiated. Callers should be aware that this will make |image_| read-only.
42 bool StartCalculation() WARN_UNUSED_RESULT;
43
44 SkColor prominent_color() const { return prominent_color_; }
45
46 void set_prominent_color_for_test(SkColor prominent_color) {
47 prominent_color_ = prominent_color;
48 }
49
50 // Explicitly sets the |task_runner_| for testing.
51 void SetTaskRunnerForTest(scoped_refptr<base::TaskRunner> task_runner);
52
53 private:
54 // Notifies observers that a color calulation has completed. Called on the
55 // same thread that constructed |this|.
56 void NotifyCalculationComplete(SkColor prominent_color);
57
58 // The result of the color calculation.
59 SkColor prominent_color_ = SK_ColorTRANSPARENT;
60
61 // The image to calculate colors from.
62 gfx::ImageSkia image_;
63
64 // Input for the color calculation.
65 color_utils::LumaRange luma_;
66
67 // Input for the color calculation.
68 color_utils::SaturationRange saturation_;
69
70 // The task runner to run the calculation on.
71 scoped_refptr<base::TaskRunner> task_runner_;
72
73 base::ObserverList<WallpaperColorCalculatorObserver> observers_;
74
75 base::WeakPtrFactory<WallpaperColorCalculator> weak_ptr_factory_;
76
77 DISALLOW_COPY_AND_ASSIGN(WallpaperColorCalculator);
78 };
79
80 } // namespace wallpaper
81
82 #endif // COMPONENTS_WALLPAPER_COLOR_CALCULATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698