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

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

Issue 2824883006: [ash-md] Reduce thread hopping for cheap wallpaper color extraction. (Closed)
Patch Set: Addressed comments from patch set patch set 6. Created 3 years, 8 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
« no previous file with comments | « no previous file | components/wallpaper/wallpaper_color_calculator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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_COLOR_CALCULATOR_H_ 5 #ifndef COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_
6 #define COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_ 6 #define COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "components/wallpaper/wallpaper_export.h" 13 #include "components/wallpaper/wallpaper_export.h"
14 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/color_analysis.h" 15 #include "ui/gfx/color_analysis.h"
16 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/image/image_skia.h"
17 17
18 namespace base { 18 namespace base {
19 class TaskRunner; 19 class TaskRunner;
20 } 20 }
21 21
22 namespace wallpaper { 22 namespace wallpaper {
23 class WallpaperColorCalculatorObserver; 23 class WallpaperColorCalculatorObserver;
24 24
25 // Asynchronously calculates colors based on a wallpaper image. 25 // Calculates colors based on a wallpaper image.
26 class WALLPAPER_EXPORT WallpaperColorCalculator { 26 class WALLPAPER_EXPORT WallpaperColorCalculator {
27 public: 27 public:
28 // |image|, |luma| and |saturation| are the input parameters to the color 28 // |image|, |luma| and |saturation| are the input parameters to the color
29 // calculation that is executed on the |task_runner|. 29 // calculation that is executed on the |task_runner|.
30 WallpaperColorCalculator(const gfx::ImageSkia& image, 30 WallpaperColorCalculator(const gfx::ImageSkia& image,
31 color_utils::LumaRange luma, 31 color_utils::LumaRange luma,
32 color_utils::SaturationRange saturation, 32 color_utils::SaturationRange saturation,
33 scoped_refptr<base::TaskRunner> task_runner); 33 scoped_refptr<base::TaskRunner> task_runner);
34 ~WallpaperColorCalculator(); 34 ~WallpaperColorCalculator();
35 35
36 void AddObserver(WallpaperColorCalculatorObserver* observer); 36 void AddObserver(WallpaperColorCalculatorObserver* observer);
37 37
38 void RemoveObserver(WallpaperColorCalculatorObserver* observer); 38 void RemoveObserver(WallpaperColorCalculatorObserver* observer);
39 39
40 // Initiates the calculation and returns false if the calculation fails to be 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. 41 // initiated. Observers may be notified synchronously or asynchronously.
42 // Callers should be aware that this will make |image_| read-only.
42 bool StartCalculation() WARN_UNUSED_RESULT; 43 bool StartCalculation() WARN_UNUSED_RESULT;
43 44
44 SkColor prominent_color() const { return prominent_color_; } 45 SkColor prominent_color() const { return prominent_color_; }
45 46
46 void set_prominent_color_for_test(SkColor prominent_color) { 47 void set_prominent_color_for_test(SkColor prominent_color) {
47 prominent_color_ = prominent_color; 48 prominent_color_ = prominent_color;
48 } 49 }
49 50
50 // Explicitly sets the |task_runner_| for testing. 51 // Explicitly sets the |task_runner_| for testing.
51 void SetTaskRunnerForTest(scoped_refptr<base::TaskRunner> task_runner); 52 void SetTaskRunnerForTest(scoped_refptr<base::TaskRunner> task_runner);
52 53
53 private: 54 private:
55 // Handles asynchronous calculation results. |async_start_time| is used to
56 // record duration metrics.
57 void OnAsyncCalculationComplete(base::TimeTicks async_start_time,
58 SkColor prominent_color);
59
54 // Notifies observers that a color calulation has completed. Called on the 60 // Notifies observers that a color calulation has completed. Called on the
55 // same thread that constructed |this|. 61 // same thread that constructed |this|.
56 void NotifyCalculationComplete(SkColor prominent_color); 62 void NotifyCalculationComplete(SkColor prominent_color);
57 63
58 // The result of the color calculation. 64 // The result of the color calculation.
59 SkColor prominent_color_ = SK_ColorTRANSPARENT; 65 SkColor prominent_color_ = SK_ColorTRANSPARENT;
60 66
61 // The image to calculate colors from. 67 // The image to calculate colors from.
62 gfx::ImageSkia image_; 68 gfx::ImageSkia image_;
63 69
64 // Input for the color calculation. 70 // Input for the color calculation.
65 color_utils::LumaRange luma_; 71 color_utils::LumaRange luma_;
66 72
67 // Input for the color calculation. 73 // Input for the color calculation.
68 color_utils::SaturationRange saturation_; 74 color_utils::SaturationRange saturation_;
69 75
70 // The task runner to run the calculation on. 76 // The task runner to run the calculation on.
71 scoped_refptr<base::TaskRunner> task_runner_; 77 scoped_refptr<base::TaskRunner> task_runner_;
72 78
73 // The time that StartCalculation() was last called. Used for recording
74 // timing metrics.
75 base::Time start_calculation_time_;
76
77 base::ObserverList<WallpaperColorCalculatorObserver> observers_; 79 base::ObserverList<WallpaperColorCalculatorObserver> observers_;
78 80
79 base::WeakPtrFactory<WallpaperColorCalculator> weak_ptr_factory_; 81 base::WeakPtrFactory<WallpaperColorCalculator> weak_ptr_factory_;
80 82
81 DISALLOW_COPY_AND_ASSIGN(WallpaperColorCalculator); 83 DISALLOW_COPY_AND_ASSIGN(WallpaperColorCalculator);
82 }; 84 };
83 85
84 } // namespace wallpaper 86 } // namespace wallpaper
85 87
86 #endif // COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_ 88 #endif // COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_
OLDNEW
« no previous file with comments | « no previous file | components/wallpaper/wallpaper_color_calculator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698