| 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 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 <set> | 8 #include <list> |
| 9 #include <map> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 12 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 16 #include "base/observer_list_threadsafe.h" | 17 #include "base/observer_list_threadsafe.h" |
| 17 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 19 #include "base/time.h" |
| 18 #include "base/values.h" | 20 #include "base/values.h" |
| 19 #include "content/browser/gpu/gpu_blacklist.h" | 21 #include "content/browser/gpu/gpu_blacklist.h" |
| 20 #include "content/public/browser/gpu_data_manager.h" | 22 #include "content/public/browser/gpu_data_manager.h" |
| 21 #include "content/public/common/gpu_info.h" | 23 #include "content/public/common/gpu_info.h" |
| 22 #include "content/public/common/gpu_memory_stats.h" | 24 #include "content/public/common/gpu_memory_stats.h" |
| 23 | 25 |
| 24 class CommandLine; | 26 class CommandLine; |
| 27 class GURL; |
| 25 | 28 |
| 26 namespace content { | 29 namespace content { |
| 27 | 30 |
| 28 class CONTENT_EXPORT GpuDataManagerImpl | 31 class CONTENT_EXPORT GpuDataManagerImpl |
| 29 : public NON_EXPORTED_BASE(GpuDataManager) { | 32 : public NON_EXPORTED_BASE(GpuDataManager) { |
| 30 public: | 33 public: |
| 34 // Indicates the guilt level of a domain which caused a GPU reset. |
| 35 // If a domain is 100% known to be guilty of resetting the GPU, then |
| 36 // it will generally not cause other domains' use of 3D APIs to be |
| 37 // blocked, unless system stability would be compromised. |
| 38 enum DomainGuilt { |
| 39 DOMAIN_GUILT_KNOWN, |
| 40 DOMAIN_GUILT_UNKNOWN |
| 41 }; |
| 42 |
| 43 // Indicates the reason that access to a given client API (like |
| 44 // WebGL or Pepper 3D) was blocked or not. This state is distinct |
| 45 // from blacklisting of an entire feature. |
| 46 enum DomainBlockStatus { |
| 47 DOMAIN_BLOCK_STATUS_BLOCKED, |
| 48 DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED, |
| 49 DOMAIN_BLOCK_STATUS_NOT_BLOCKED |
| 50 }; |
| 51 |
| 31 // Getter for the singleton. This will return NULL on failure. | 52 // Getter for the singleton. This will return NULL on failure. |
| 32 static GpuDataManagerImpl* GetInstance(); | 53 static GpuDataManagerImpl* GetInstance(); |
| 33 | 54 |
| 34 // GpuDataManager implementation. | 55 // GpuDataManager implementation. |
| 35 virtual void InitializeForTesting( | 56 virtual void InitializeForTesting( |
| 36 const std::string& gpu_blacklist_json, | 57 const std::string& gpu_blacklist_json, |
| 37 const GPUInfo& gpu_info) OVERRIDE; | 58 const GPUInfo& gpu_info) OVERRIDE; |
| 38 virtual GpuFeatureType GetBlacklistedFeatures() const OVERRIDE; | 59 virtual GpuFeatureType GetBlacklistedFeatures() const OVERRIDE; |
| 39 virtual GpuSwitchingOption GetGpuSwitchingOption() const OVERRIDE; | 60 virtual GpuSwitchingOption GetGpuSwitchingOption() const OVERRIDE; |
| 40 virtual base::ListValue* GetBlacklistReasons() const OVERRIDE; | 61 virtual base::ListValue* GetBlacklistReasons() const OVERRIDE; |
| 41 virtual std::string GetBlacklistVersion() const OVERRIDE; | 62 virtual std::string GetBlacklistVersion() const OVERRIDE; |
| 42 virtual GPUInfo GetGPUInfo() const OVERRIDE; | 63 virtual GPUInfo GetGPUInfo() const OVERRIDE; |
| 43 virtual bool GpuAccessAllowed() const OVERRIDE; | 64 virtual bool GpuAccessAllowed() const OVERRIDE; |
| 44 virtual void RequestCompleteGpuInfoIfNeeded() OVERRIDE; | 65 virtual void RequestCompleteGpuInfoIfNeeded() OVERRIDE; |
| 45 virtual bool IsCompleteGpuInfoAvailable() const OVERRIDE; | 66 virtual bool IsCompleteGpuInfoAvailable() const OVERRIDE; |
| 46 virtual void RequestVideoMemoryUsageStatsUpdate() const OVERRIDE; | 67 virtual void RequestVideoMemoryUsageStatsUpdate() const OVERRIDE; |
| 47 virtual bool ShouldUseSoftwareRendering() const OVERRIDE; | 68 virtual bool ShouldUseSoftwareRendering() const OVERRIDE; |
| 48 virtual void RegisterSwiftShaderPath(const FilePath& path) OVERRIDE; | 69 virtual void RegisterSwiftShaderPath(const FilePath& path) OVERRIDE; |
| 49 virtual void AddLogMessage(int level, const std::string& header, | 70 virtual void AddLogMessage(int level, const std::string& header, |
| 50 const std::string& message) OVERRIDE; | 71 const std::string& message) OVERRIDE; |
| 51 virtual base::ListValue* GetLogMessages() const OVERRIDE; | 72 virtual base::ListValue* GetLogMessages() const OVERRIDE; |
| 52 virtual void AddObserver(GpuDataManagerObserver* observer) OVERRIDE; | 73 virtual void AddObserver(GpuDataManagerObserver* observer) OVERRIDE; |
| 53 virtual void RemoveObserver(GpuDataManagerObserver* observer) OVERRIDE; | 74 virtual void RemoveObserver(GpuDataManagerObserver* observer) OVERRIDE; |
| 54 virtual void SetWindowCount(uint32 count) OVERRIDE; | 75 virtual void SetWindowCount(uint32 count) OVERRIDE; |
| 55 virtual uint32 GetWindowCount() const OVERRIDE; | 76 virtual uint32 GetWindowCount() const OVERRIDE; |
| 77 virtual void UnblockDomainFrom3DAPIs(const GURL& url) OVERRIDE; |
| 78 virtual void DisableDomainBlockingFor3DAPIsForTesting() OVERRIDE; |
| 56 | 79 |
| 57 // This collects preliminary GPU info, load GpuBlacklist, and compute the | 80 // This collects preliminary GPU info, load GpuBlacklist, and compute the |
| 58 // preliminary blacklisted features; it should only be called at browser | 81 // preliminary blacklisted features; it should only be called at browser |
| 59 // startup time in UI thread before the IO restriction is turned on. | 82 // startup time in UI thread before the IO restriction is turned on. |
| 60 void Initialize(); | 83 void Initialize(); |
| 61 | 84 |
| 62 // Only update if the current GPUInfo is not finalized. If blacklist is | 85 // Only update if the current GPUInfo is not finalized. If blacklist is |
| 63 // loaded, run through blacklist and update blacklisted features. | 86 // loaded, run through blacklist and update blacklisted features. |
| 64 void UpdateGpuInfo(const GPUInfo& gpu_info); | 87 void UpdateGpuInfo(const GPUInfo& gpu_info); |
| 65 | 88 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 84 | 107 |
| 85 // Called when switching gpu. | 108 // Called when switching gpu. |
| 86 void HandleGpuSwitch(); | 109 void HandleGpuSwitch(); |
| 87 | 110 |
| 88 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
| 89 // Is the GPU process using the accelerated surface to present, instead of | 112 // Is the GPU process using the accelerated surface to present, instead of |
| 90 // presenting by itself. | 113 // presenting by itself. |
| 91 bool IsUsingAcceleratedSurface() const; | 114 bool IsUsingAcceleratedSurface() const; |
| 92 #endif | 115 #endif |
| 93 | 116 |
| 117 // Maintenance of domains requiring explicit user permission before |
| 118 // using client-facing 3D APIs (WebGL, Pepper 3D), either because |
| 119 // the domain has caused the GPU to reset, or because too many GPU |
| 120 // resets have been observed globally recently, and system stability |
| 121 // might be compromised. |
| 122 // |
| 123 // The given URL may be a partial URL (including at least the host) |
| 124 // or a full URL to a page. |
| 125 // |
| 126 // Note that the unblocking API must be part of the content API |
| 127 // because it is called from Chrome side code. |
| 128 void BlockDomainFrom3DAPIs(const GURL& url, DomainGuilt guilt); |
| 129 DomainBlockStatus Are3DAPIsBlocked(const GURL& url) const; |
| 130 |
| 94 private: | 131 private: |
| 132 struct DomainBlockEntry { |
| 133 DomainGuilt last_guilt; |
| 134 }; |
| 135 |
| 136 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap; |
| 137 |
| 95 typedef ObserverListThreadSafe<GpuDataManagerObserver> | 138 typedef ObserverListThreadSafe<GpuDataManagerObserver> |
| 96 GpuDataManagerObserverList; | 139 GpuDataManagerObserverList; |
| 97 | 140 |
| 98 friend class GpuDataManagerImplTest; | 141 friend class GpuDataManagerImplTest; |
| 99 friend struct DefaultSingletonTraits<GpuDataManagerImpl>; | 142 friend struct DefaultSingletonTraits<GpuDataManagerImpl>; |
| 100 | 143 |
| 101 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideBlacklisting); | 144 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideBlacklisting); |
| 102 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideExceptions); | 145 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideExceptions); |
| 103 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, BlacklistCard); | 146 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, BlacklistCard); |
| 104 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SoftwareRendering); | 147 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SoftwareRendering); |
| 105 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SoftwareRendering2); | 148 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SoftwareRendering2); |
| 106 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuInfoUpdate); | 149 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuInfoUpdate); |
| 107 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | 150 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 108 NoGpuInfoUpdateWithSoftwareRendering); | 151 NoGpuInfoUpdateWithSoftwareRendering); |
| 109 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | 152 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 110 GPUVideoMemoryUsageStatsUpdate); | 153 GPUVideoMemoryUsageStatsUpdate); |
| 154 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 155 BlockAllDomainsFrom3DAPIs); |
| 156 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 157 UnblockGuiltyDomainFrom3DAPIs); |
| 158 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 159 UnblockDomainOfUnknownGuiltFrom3DAPIs); |
| 160 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 161 UnblockOtherDomainFrom3DAPIs); |
| 162 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 163 UnblockThisDomainFrom3DAPIs); |
| 111 | 164 |
| 112 GpuDataManagerImpl(); | 165 GpuDataManagerImpl(); |
| 113 virtual ~GpuDataManagerImpl(); | 166 virtual ~GpuDataManagerImpl(); |
| 114 | 167 |
| 115 void InitializeImpl(const std::string& gpu_blacklist_json, | 168 void InitializeImpl(const std::string& gpu_blacklist_json, |
| 116 const GPUInfo& gpu_info); | 169 const GPUInfo& gpu_info); |
| 117 | 170 |
| 118 void UpdateBlacklistedFeatures(GpuFeatureType features); | 171 void UpdateBlacklistedFeatures(GpuFeatureType features); |
| 119 | 172 |
| 120 // This should only be called once at initialization time, when preliminary | 173 // This should only be called once at initialization time, when preliminary |
| 121 // gpu info is collected. | 174 // gpu info is collected. |
| 122 void UpdatePreliminaryBlacklistedFeatures(); | 175 void UpdatePreliminaryBlacklistedFeatures(); |
| 123 | 176 |
| 124 // Update the GPU switching status. | 177 // Update the GPU switching status. |
| 125 // This should only be called once at initialization time. | 178 // This should only be called once at initialization time. |
| 126 void UpdateGpuSwitchingManager(const GPUInfo& gpu_info); | 179 void UpdateGpuSwitchingManager(const GPUInfo& gpu_info); |
| 127 | 180 |
| 128 // Notify all observers whenever there is a GPU info update. | 181 // Notify all observers whenever there is a GPU info update. |
| 129 void NotifyGpuInfoUpdate(); | 182 void NotifyGpuInfoUpdate(); |
| 130 | 183 |
| 131 // Try to switch to software rendering, if possible and necessary. | 184 // Try to switch to software rendering, if possible and necessary. |
| 132 void EnableSoftwareRenderingIfNecessary(); | 185 void EnableSoftwareRenderingIfNecessary(); |
| 133 | 186 |
| 187 // Helper to extract the domain from a given URL. |
| 188 std::string GetDomainFromURL(const GURL& url) const; |
| 189 |
| 190 // Implementation functions for blocking of 3D graphics APIs, used |
| 191 // for unit testing. |
| 192 void BlockDomainFrom3DAPIsAtTime( |
| 193 const GURL& url, DomainGuilt guilt, base::Time at_time); |
| 194 DomainBlockStatus Are3DAPIsBlockedAtTime( |
| 195 const GURL& url, base::Time at_time) const; |
| 196 int64 GetBlockAllDomainsDurationInMs() const; |
| 197 |
| 134 bool complete_gpu_info_already_requested_; | 198 bool complete_gpu_info_already_requested_; |
| 135 | 199 |
| 136 GpuFeatureType blacklisted_features_; | 200 GpuFeatureType blacklisted_features_; |
| 137 GpuFeatureType preliminary_blacklisted_features_; | 201 GpuFeatureType preliminary_blacklisted_features_; |
| 138 | 202 |
| 139 GpuSwitchingOption gpu_switching_; | 203 GpuSwitchingOption gpu_switching_; |
| 140 | 204 |
| 141 GPUInfo gpu_info_; | 205 GPUInfo gpu_info_; |
| 142 mutable base::Lock gpu_info_lock_; | 206 mutable base::Lock gpu_info_lock_; |
| 143 | 207 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 // the --disable-gpu commandline switch. | 220 // the --disable-gpu commandline switch. |
| 157 bool card_blacklisted_; | 221 bool card_blacklisted_; |
| 158 | 222 |
| 159 // We disable histogram stuff in testing, especially in unit tests because | 223 // We disable histogram stuff in testing, especially in unit tests because |
| 160 // they cause random failures. | 224 // they cause random failures. |
| 161 bool update_histograms_; | 225 bool update_histograms_; |
| 162 | 226 |
| 163 // Number of currently open windows, to be used in gpu memory allocation. | 227 // Number of currently open windows, to be used in gpu memory allocation. |
| 164 int window_count_; | 228 int window_count_; |
| 165 | 229 |
| 230 DomainBlockMap blocked_domains_; |
| 231 mutable std::list<base::Time> timestamps_of_gpu_resets_; |
| 232 bool domain_blocking_enabled_; |
| 233 |
| 166 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl); | 234 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl); |
| 167 }; | 235 }; |
| 168 | 236 |
| 169 } // namespace content | 237 } // namespace content |
| 170 | 238 |
| 171 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ | 239 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ |
| OLD | NEW |