OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ |
6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ | 6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback_old.h" | |
13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/observer_list_threadsafe.h" | |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "base/task.h" | 16 #include "base/task.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 #include "content/common/gpu/gpu_feature_flags.h" | 19 #include "content/common/gpu/gpu_feature_flags.h" |
20 #include "content/public/common/gpu_info.h" | 20 #include "content/public/common/gpu_info.h" |
21 | 21 |
22 class CommandLine; | 22 class CommandLine; |
23 class GpuBlacklist; | 23 class GpuBlacklist; |
24 | 24 |
25 class CONTENT_EXPORT GpuDataManager { | 25 class CONTENT_EXPORT GpuDataManager { |
26 public: | 26 public: |
27 // Observers can register themselves via GpuDataManager::AddObserver, and | |
28 // can un-register with GpuDataManager::RemoveObserver. | |
29 class Observer { | |
30 public: | |
31 // Called for any observers whenever there is a GPU info update. | |
32 virtual void OnGpuInfoUpdate() = 0; | |
33 | |
34 protected: | |
35 virtual ~Observer() {} | |
36 }; | |
37 | |
27 // Getter for the singleton. This will return NULL on failure. | 38 // Getter for the singleton. This will return NULL on failure. |
28 static GpuDataManager* GetInstance(); | 39 static GpuDataManager* GetInstance(); |
29 | 40 |
30 // Requests complete GPUinfo if it has not already been requested | 41 // Requests complete GPUinfo if it has not already been requested |
31 void RequestCompleteGpuInfoIfNeeded(); | 42 void RequestCompleteGpuInfoIfNeeded(); |
32 | 43 |
33 // Only update if the current GPUInfo is not finalized. | 44 // Only update if the current GPUInfo is not finalized. |
34 void UpdateGpuInfo(const content::GPUInfo& gpu_info); | 45 void UpdateGpuInfo(const content::GPUInfo& gpu_info); |
35 | 46 |
36 const content::GPUInfo& gpu_info() const; | 47 const content::GPUInfo& gpu_info() const; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 GpuFeatureFlags GetGpuFeatureFlags(); | 86 GpuFeatureFlags GetGpuFeatureFlags(); |
76 | 87 |
77 // This indicator might change because we could collect more GPU info or | 88 // This indicator might change because we could collect more GPU info or |
78 // because the GPU blacklist could be updated. | 89 // because the GPU blacklist could be updated. |
79 // If this returns false, any further GPU access, including launching GPU | 90 // If this returns false, any further GPU access, including launching GPU |
80 // process, establish GPU channel, and GPU info collection, should be | 91 // process, establish GPU channel, and GPU info collection, should be |
81 // blocked. | 92 // blocked. |
82 // Can be called on any thread. | 93 // Can be called on any thread. |
83 bool GpuAccessAllowed(); | 94 bool GpuAccessAllowed(); |
84 | 95 |
85 // Add a callback. | 96 // Registers |observer|. The thread on which this is called is the thread |
86 void AddGpuInfoUpdateCallback(Callback0::Type* callback); | 97 // on which |observer| will be called back with notifications. |
98 void AddObserver(Observer* observer); | |
James Hawkins
2011/10/26 00:21:29
|observer| must not be NULL? Here and RemoveObser
csilv
2011/10/26 01:35:31
Wouldn't observer != NULL be assumed? ;-) Done.
James Hawkins
2011/10/26 01:45:28
I understand where you're coming from, but I've re
| |
87 | 99 |
88 // Remove a callback. | 100 // Unregisters |observer| from receiving notifications. This must be called |
James Hawkins
2011/10/26 00:21:29
Single space between comments.
csilv
2011/10/26 01:35:31
Done.
| |
89 // Returns true if removed, or false if it was not found. | 101 // on the same thread on which AddObserver() was called. |
90 bool RemoveGpuInfoUpdateCallback(Callback0::Type* callback); | 102 void RemoveObserver(Observer* observer); |
91 | 103 |
92 // Inserting disable-feature switches into renderer process command-line | 104 // Inserting disable-feature switches into renderer process command-line |
93 // in correspondance to preliminary gpu feature flags. | 105 // in correspondance to preliminary gpu feature flags. |
94 void AppendRendererCommandLine(CommandLine* command_line); | 106 void AppendRendererCommandLine(CommandLine* command_line); |
95 | 107 |
96 // Inserting switches into gpu process command-line: kUseGL, | 108 // Inserting switches into gpu process command-line: kUseGL, |
97 // kDisableGLMultisampling. | 109 // kDisableGLMultisampling. |
98 void AppendGpuCommandLine(CommandLine* command_line); | 110 void AppendGpuCommandLine(CommandLine* command_line); |
99 | 111 |
100 // Gives ownership of the built-in blacklist. This is always called on the | 112 // Gives ownership of the built-in blacklist. This is always called on the |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 bool disable_accelerated_compositing_; | 162 bool disable_accelerated_compositing_; |
151 bool disable_accelerated_layers_; | 163 bool disable_accelerated_layers_; |
152 bool disable_experimental_webgl_; | 164 bool disable_experimental_webgl_; |
153 bool disable_gl_multisampling_; | 165 bool disable_gl_multisampling_; |
154 | 166 |
155 bool ignore_gpu_blacklist_; | 167 bool ignore_gpu_blacklist_; |
156 | 168 |
157 std::string use_gl_; | 169 std::string use_gl_; |
158 }; | 170 }; |
159 | 171 |
172 typedef ObserverListThreadSafe<GpuDataManager::Observer> | |
James Hawkins
2011/10/26 00:21:29
Document var.
James Hawkins
2011/10/26 01:32:16
Oops, nm.
| |
173 GpuDataManagerObserverList; | |
174 | |
160 friend struct DefaultSingletonTraits<GpuDataManager>; | 175 friend struct DefaultSingletonTraits<GpuDataManager>; |
161 | 176 |
162 GpuDataManager(); | 177 GpuDataManager(); |
163 virtual ~GpuDataManager(); | 178 virtual ~GpuDataManager(); |
164 | 179 |
165 void Initialize(); | 180 void Initialize(); |
166 | 181 |
167 // Check if we should go ahead and use gpu blacklist. | 182 // Check if we should go ahead and use gpu blacklist. |
168 // If not, return NULL; otherwise, update and return the current list. | 183 // If not, return NULL; otherwise, update and return the current list. |
169 GpuBlacklist* GetGpuBlacklist() const; | 184 GpuBlacklist* GetGpuBlacklist() const; |
170 | 185 |
171 // If flags hasn't been set and GPUInfo is available, run through blacklist | 186 // If flags hasn't been set and GPUInfo is available, run through blacklist |
172 // and compute the flags. | 187 // and compute the flags. |
173 void UpdateGpuFeatureFlags(); | 188 void UpdateGpuFeatureFlags(); |
174 | 189 |
175 // Call all callbacks. | 190 // Notify all observers whenever there is a GPU info update. |
176 void RunGpuInfoUpdateCallbacks(); | 191 void NotifyGpuInfoUpdate(); |
177 | 192 |
178 // If use-gl switch is osmesa or any, return true. | 193 // If use-gl switch is osmesa or any, return true. |
179 bool UseGLIsOSMesaOrAny(); | 194 bool UseGLIsOSMesaOrAny(); |
180 | 195 |
181 // Merges the second GPUInfo object with the first. | 196 // Merges the second GPUInfo object with the first. |
182 // If it's the same GPU, i.e., device id and vendor id are the same, then | 197 // If it's the same GPU, i.e., device id and vendor id are the same, then |
183 // copy over the fields that are not set yet and ignore the rest. | 198 // copy over the fields that are not set yet and ignore the rest. |
184 // If it's a different GPU, then reset and copy over everything. | 199 // If it's a different GPU, then reset and copy over everything. |
185 // Return true if something changes that may affect blacklisting; currently | 200 // Return true if something changes that may affect blacklisting; currently |
186 // they are device_id, vendor_id, driver_vendor, driver_version, driver_date, | 201 // they are device_id, vendor_id, driver_vendor, driver_version, driver_date, |
187 // and gl_renderer. | 202 // and gl_renderer. |
188 static bool Merge(content::GPUInfo* object, const content::GPUInfo& other); | 203 static bool Merge(content::GPUInfo* object, const content::GPUInfo& other); |
189 | 204 |
190 bool complete_gpu_info_already_requested_; | 205 bool complete_gpu_info_already_requested_; |
191 | 206 |
192 GpuFeatureFlags gpu_feature_flags_; | 207 GpuFeatureFlags gpu_feature_flags_; |
193 GpuFeatureFlags preliminary_gpu_feature_flags_; | 208 GpuFeatureFlags preliminary_gpu_feature_flags_; |
194 | 209 |
195 UserFlags user_flags_; | 210 UserFlags user_flags_; |
196 | 211 |
197 content::GPUInfo gpu_info_; | 212 content::GPUInfo gpu_info_; |
198 mutable base::Lock gpu_info_lock_; | 213 mutable base::Lock gpu_info_lock_; |
199 | 214 |
200 scoped_ptr<GpuBlacklist> gpu_blacklist_; | 215 scoped_ptr<GpuBlacklist> gpu_blacklist_; |
201 | 216 |
202 // Map of callbacks. | 217 // Observers. |
203 std::set<Callback0::Type*> gpu_info_update_callbacks_; | 218 const scoped_refptr<GpuDataManagerObserverList> observer_list_; |
James Hawkins
2011/10/26 00:21:29
Why const?
csilv
2011/10/26 01:35:31
observer_list_ is initialized in the constructor a
James Hawkins
2011/10/26 01:45:28
No, was just curious.
| |
204 | 219 |
205 ListValue log_messages_; | 220 ListValue log_messages_; |
206 | 221 |
207 DISALLOW_COPY_AND_ASSIGN(GpuDataManager); | 222 DISALLOW_COPY_AND_ASSIGN(GpuDataManager); |
208 }; | 223 }; |
209 | 224 |
210 DISABLE_RUNNABLE_METHOD_REFCOUNT(GpuDataManager); | 225 DISABLE_RUNNABLE_METHOD_REFCOUNT(GpuDataManager); |
James Hawkins
2011/10/26 00:21:29
Assuming it's not safe to delete yet, add a TODO t
csilv
2011/10/26 01:35:31
Removed, I overlooked this in my prior CL.
| |
211 | 226 |
212 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ | 227 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ |
OLD | NEW |