Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ |
| 6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ | 6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | |
| 9 #include <map> | |
| 10 #include <set> | |
| 11 #include <string> | 8 #include <string> |
| 12 #include <vector> | |
| 13 | 9 |
| 14 #include "base/callback.h" | 10 #include "base/callback.h" |
| 15 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 16 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 17 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/ref_counted.h" | 14 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 20 #include "base/observer_list_threadsafe.h" | |
| 21 #include "base/process_util.h" | 16 #include "base/process_util.h" |
| 22 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 23 #include "base/time.h" | 18 #include "base/time.h" |
| 24 #include "base/values.h" | 19 #include "base/values.h" |
| 25 #include "content/browser/gpu/gpu_blacklist.h" | |
| 26 #include "content/browser/gpu/gpu_driver_bug_list.h" | |
| 27 #include "content/browser/gpu/gpu_switching_list.h" | |
| 28 #include "content/public/browser/gpu_data_manager.h" | 20 #include "content/public/browser/gpu_data_manager.h" |
| 29 #include "content/public/common/gpu_info.h" | 21 #include "content/public/common/gpu_info.h" |
| 30 #include "content/public/common/gpu_memory_stats.h" | 22 #include "content/public/common/gpu_memory_stats.h" |
| 31 #include "content/public/common/gpu_switching_option.h" | 23 #include "content/public/common/gpu_switching_option.h" |
| 32 #include "content/public/common/three_d_api_types.h" | 24 #include "content/public/common/three_d_api_types.h" |
| 33 | 25 |
| 34 class CommandLine; | 26 class CommandLine; |
| 35 class GURL; | 27 class GURL; |
| 36 struct WebPreferences; | 28 struct WebPreferences; |
| 37 | 29 |
| 38 namespace content { | 30 namespace content { |
| 39 | 31 |
| 32 class GpuDataManagerImplPrivate; | |
| 33 | |
| 40 class CONTENT_EXPORT GpuDataManagerImpl | 34 class CONTENT_EXPORT GpuDataManagerImpl |
| 41 : public NON_EXPORTED_BASE(GpuDataManager) { | 35 : public NON_EXPORTED_BASE(GpuDataManager) { |
| 42 public: | 36 public: |
| 43 // Indicates the guilt level of a domain which caused a GPU reset. | 37 // Indicates the guilt level of a domain which caused a GPU reset. |
| 44 // If a domain is 100% known to be guilty of resetting the GPU, then | 38 // If a domain is 100% known to be guilty of resetting the GPU, then |
| 45 // it will generally not cause other domains' use of 3D APIs to be | 39 // it will generally not cause other domains' use of 3D APIs to be |
| 46 // blocked, unless system stability would be compromised. | 40 // blocked, unless system stability would be compromised. |
| 47 enum DomainGuilt { | 41 enum DomainGuilt { |
| 48 DOMAIN_GUILT_KNOWN, | 42 DOMAIN_GUILT_KNOWN, |
| 49 DOMAIN_GUILT_UNKNOWN | 43 DOMAIN_GUILT_UNKNOWN |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 // Get number of features being blacklisted. | 160 // Get number of features being blacklisted. |
| 167 size_t GetBlacklistedFeatureCount() const; | 161 size_t GetBlacklistedFeatureCount() const; |
| 168 | 162 |
| 169 typedef base::Callback<void()> GpuSwitchCallback; | 163 typedef base::Callback<void()> GpuSwitchCallback; |
| 170 | 164 |
| 171 // Add and remove gpu switch callback. | 165 // Add and remove gpu switch callback. |
| 172 void AddGpuSwitchCallback(const GpuSwitchCallback& callback); | 166 void AddGpuSwitchCallback(const GpuSwitchCallback& callback); |
| 173 void RemoveGpuSwitchCallback(const GpuSwitchCallback& callback); | 167 void RemoveGpuSwitchCallback(const GpuSwitchCallback& callback); |
| 174 | 168 |
| 175 private: | 169 private: |
| 176 struct DomainBlockEntry { | |
| 177 DomainGuilt last_guilt; | |
| 178 }; | |
| 179 | |
| 180 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap; | |
| 181 | |
| 182 typedef ObserverListThreadSafe<GpuDataManagerObserver> | |
| 183 GpuDataManagerObserverList; | |
| 184 | |
| 185 friend class GpuDataManagerImplTest; | |
| 186 friend struct DefaultSingletonTraits<GpuDataManagerImpl>; | 170 friend struct DefaultSingletonTraits<GpuDataManagerImpl>; |
| 187 | 171 |
| 188 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideBlacklisting); | |
| 189 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideExceptions); | |
| 190 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | |
| 191 DisableHardwareAcceleration); | |
| 192 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SwiftShaderRendering); | |
| 193 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SwiftShaderRendering2); | |
| 194 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuInfoUpdate); | |
| 195 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | |
| 196 NoGpuInfoUpdateWithSwiftShader); | |
| 197 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | |
| 198 GPUVideoMemoryUsageStatsUpdate); | |
| 199 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | |
| 200 BlockAllDomainsFrom3DAPIs); | |
| 201 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | |
| 202 UnblockGuiltyDomainFrom3DAPIs); | |
| 203 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | |
| 204 UnblockDomainOfUnknownGuiltFrom3DAPIs); | |
| 205 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | |
| 206 UnblockOtherDomainFrom3DAPIs); | |
| 207 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | |
| 208 UnblockThisDomainFrom3DAPIs); | |
| 209 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuDriverBugListSingle); | |
| 210 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuDriverBugListMultiple); | |
| 211 | |
| 212 GpuDataManagerImpl(); | 172 GpuDataManagerImpl(); |
| 213 virtual ~GpuDataManagerImpl(); | 173 virtual ~GpuDataManagerImpl(); |
| 214 | 174 |
| 215 void InitializeImpl(const std::string& gpu_blacklist_json, | 175 scoped_ptr<GpuDataManagerImplPrivate> private_; |
| 216 const std::string& gpu_switching_list_json, | 176 mutable base::Lock lock_; |
|
piman
2013/05/09 20:18:23
nit: it's nice to put the lock above the members i
Zhenyao Mo
2013/05/09 23:35:12
Done.
| |
| 217 const std::string& gpu_driver_bug_list_json, | |
| 218 const GPUInfo& gpu_info); | |
| 219 | |
| 220 void UpdateBlacklistedFeatures(const std::set<int>& features); | |
| 221 | |
| 222 // This should only be called once at initialization time, when preliminary | |
| 223 // gpu info is collected. | |
| 224 void UpdatePreliminaryBlacklistedFeatures(); | |
| 225 | |
| 226 // Update the GPU switching status. | |
| 227 // This should only be called once at initialization time. | |
| 228 void UpdateGpuSwitchingManager(const GPUInfo& gpu_info); | |
| 229 | |
| 230 // Notify all observers whenever there is a GPU info update. | |
| 231 void NotifyGpuInfoUpdate(); | |
| 232 | |
| 233 // Try to switch to SwiftShader rendering, if possible and necessary. | |
| 234 void EnableSwiftShaderIfNecessary(); | |
| 235 | |
| 236 // Helper to extract the domain from a given URL. | |
| 237 std::string GetDomainFromURL(const GURL& url) const; | |
| 238 | |
| 239 // Implementation functions for blocking of 3D graphics APIs, used | |
| 240 // for unit testing. | |
| 241 void BlockDomainFrom3DAPIsAtTime( | |
| 242 const GURL& url, DomainGuilt guilt, base::Time at_time); | |
| 243 DomainBlockStatus Are3DAPIsBlockedAtTime( | |
| 244 const GURL& url, base::Time at_time) const; | |
| 245 int64 GetBlockAllDomainsDurationInMs() const; | |
| 246 | |
| 247 void Notify3DAPIBlocked(const GURL& url, | |
| 248 int render_process_id, | |
| 249 int render_view_id, | |
| 250 ThreeDAPIType requester); | |
| 251 | |
| 252 bool complete_gpu_info_already_requested_; | |
| 253 | |
| 254 std::set<int> blacklisted_features_; | |
| 255 std::set<int> preliminary_blacklisted_features_; | |
| 256 | |
| 257 GpuSwitchingOption gpu_switching_; | |
| 258 | |
| 259 std::set<int> gpu_driver_bugs_; | |
| 260 | |
| 261 GPUInfo gpu_info_; | |
| 262 mutable base::Lock gpu_info_lock_; | |
| 263 | |
| 264 scoped_ptr<GpuBlacklist> gpu_blacklist_; | |
| 265 scoped_ptr<GpuSwitchingList> gpu_switching_list_; | |
| 266 scoped_ptr<GpuDriverBugList> gpu_driver_bug_list_; | |
| 267 | |
| 268 const scoped_refptr<GpuDataManagerObserverList> observer_list_; | |
| 269 | |
| 270 ListValue log_messages_; | |
| 271 mutable base::Lock log_messages_lock_; | |
| 272 | |
| 273 bool use_swiftshader_; | |
| 274 | |
| 275 base::FilePath swiftshader_path_; | |
| 276 | |
| 277 // Current card force-blacklisted due to GPU crashes, or disabled through | |
| 278 // the --disable-gpu commandline switch. | |
| 279 bool card_blacklisted_; | |
| 280 | |
| 281 // We disable histogram stuff in testing, especially in unit tests because | |
| 282 // they cause random failures. | |
| 283 bool update_histograms_; | |
| 284 | |
| 285 // Number of currently open windows, to be used in gpu memory allocation. | |
| 286 int window_count_; | |
| 287 | |
| 288 DomainBlockMap blocked_domains_; | |
| 289 mutable std::list<base::Time> timestamps_of_gpu_resets_; | |
| 290 bool domain_blocking_enabled_; | |
| 291 | |
| 292 std::vector<GpuSwitchCallback> gpu_switch_callbacks_; | |
| 293 | 177 |
| 294 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl); | 178 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl); |
| 295 }; | 179 }; |
| 296 | 180 |
| 297 } // namespace content | 181 } // namespace content |
| 298 | 182 |
| 299 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ | 183 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ |
| OLD | NEW |