| 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: |
| 31 // Getter for the singleton. This will return NULL on failure. | 34 // Getter for the singleton. This will return NULL on failure. |
| 32 static GpuDataManagerImpl* GetInstance(); | 35 static GpuDataManagerImpl* GetInstance(); |
| 33 | 36 |
| 34 // GpuDataManager implementation. | 37 // GpuDataManager implementation. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 46 virtual void RequestVideoMemoryUsageStatsUpdate() const OVERRIDE; | 49 virtual void RequestVideoMemoryUsageStatsUpdate() const OVERRIDE; |
| 47 virtual bool ShouldUseSoftwareRendering() const OVERRIDE; | 50 virtual bool ShouldUseSoftwareRendering() const OVERRIDE; |
| 48 virtual void RegisterSwiftShaderPath(const FilePath& path) OVERRIDE; | 51 virtual void RegisterSwiftShaderPath(const FilePath& path) OVERRIDE; |
| 49 virtual void AddLogMessage(int level, const std::string& header, | 52 virtual void AddLogMessage(int level, const std::string& header, |
| 50 const std::string& message) OVERRIDE; | 53 const std::string& message) OVERRIDE; |
| 51 virtual base::ListValue* GetLogMessages() const OVERRIDE; | 54 virtual base::ListValue* GetLogMessages() const OVERRIDE; |
| 52 virtual void AddObserver(GpuDataManagerObserver* observer) OVERRIDE; | 55 virtual void AddObserver(GpuDataManagerObserver* observer) OVERRIDE; |
| 53 virtual void RemoveObserver(GpuDataManagerObserver* observer) OVERRIDE; | 56 virtual void RemoveObserver(GpuDataManagerObserver* observer) OVERRIDE; |
| 54 virtual void SetWindowCount(uint32 count) OVERRIDE; | 57 virtual void SetWindowCount(uint32 count) OVERRIDE; |
| 55 virtual uint32 GetWindowCount() const OVERRIDE; | 58 virtual uint32 GetWindowCount() const OVERRIDE; |
| 59 virtual void BlockDomainFrom3DAPIs( |
| 60 const GURL& url, DomainGuilt guilt) OVERRIDE; |
| 61 virtual DomainBlockStatus Are3DAPIsBlocked( |
| 62 const GURL& url) const OVERRIDE; |
| 63 virtual void UnblockDomainFrom3DAPIs(const GURL& url) OVERRIDE; |
| 64 virtual void DisableDomainBlockingFor3DAPIsForTesting() OVERRIDE; |
| 56 | 65 |
| 57 // This collects preliminary GPU info, load GpuBlacklist, and compute the | 66 // This collects preliminary GPU info, load GpuBlacklist, and compute the |
| 58 // preliminary blacklisted features; it should only be called at browser | 67 // preliminary blacklisted features; it should only be called at browser |
| 59 // startup time in UI thread before the IO restriction is turned on. | 68 // startup time in UI thread before the IO restriction is turned on. |
| 60 void Initialize(); | 69 void Initialize(); |
| 61 | 70 |
| 62 // Only update if the current GPUInfo is not finalized. If blacklist is | 71 // Only update if the current GPUInfo is not finalized. If blacklist is |
| 63 // loaded, run through blacklist and update blacklisted features. | 72 // loaded, run through blacklist and update blacklisted features. |
| 64 void UpdateGpuInfo(const GPUInfo& gpu_info); | 73 void UpdateGpuInfo(const GPUInfo& gpu_info); |
| 65 | 74 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 85 // Called when switching gpu. | 94 // Called when switching gpu. |
| 86 void HandleGpuSwitch(); | 95 void HandleGpuSwitch(); |
| 87 | 96 |
| 88 #if defined(OS_WIN) | 97 #if defined(OS_WIN) |
| 89 // Is the GPU process using the accelerated surface to present, instead of | 98 // Is the GPU process using the accelerated surface to present, instead of |
| 90 // presenting by itself. | 99 // presenting by itself. |
| 91 bool IsUsingAcceleratedSurface() const; | 100 bool IsUsingAcceleratedSurface() const; |
| 92 #endif | 101 #endif |
| 93 | 102 |
| 94 private: | 103 private: |
| 104 struct DomainBlockEntry { |
| 105 DomainGuilt last_guilt; |
| 106 }; |
| 107 |
| 108 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap; |
| 109 |
| 95 typedef ObserverListThreadSafe<GpuDataManagerObserver> | 110 typedef ObserverListThreadSafe<GpuDataManagerObserver> |
| 96 GpuDataManagerObserverList; | 111 GpuDataManagerObserverList; |
| 97 | 112 |
| 98 friend class GpuDataManagerImplTest; | 113 friend class GpuDataManagerImplTest; |
| 99 friend struct DefaultSingletonTraits<GpuDataManagerImpl>; | 114 friend struct DefaultSingletonTraits<GpuDataManagerImpl>; |
| 100 | 115 |
| 101 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideBlacklisting); | 116 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideBlacklisting); |
| 102 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideExceptions); | 117 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideExceptions); |
| 103 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, BlacklistCard); | 118 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, BlacklistCard); |
| 104 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SoftwareRendering); | 119 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SoftwareRendering); |
| 105 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SoftwareRendering2); | 120 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SoftwareRendering2); |
| 106 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuInfoUpdate); | 121 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuInfoUpdate); |
| 107 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | 122 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 108 NoGpuInfoUpdateWithSoftwareRendering); | 123 NoGpuInfoUpdateWithSoftwareRendering); |
| 109 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, | 124 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 110 GPUVideoMemoryUsageStatsUpdate); | 125 GPUVideoMemoryUsageStatsUpdate); |
| 126 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 127 BlockAllDomainsFrom3DAPIs); |
| 128 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 129 UnblockGuiltyDomainFrom3DAPIs); |
| 130 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 131 UnblockDomainOfUnknownGuiltFrom3DAPIs); |
| 132 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 133 UnblockOtherDomainFrom3DAPIs); |
| 134 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, |
| 135 UnblockThisDomainFrom3DAPIs); |
| 111 | 136 |
| 112 GpuDataManagerImpl(); | 137 GpuDataManagerImpl(); |
| 113 virtual ~GpuDataManagerImpl(); | 138 virtual ~GpuDataManagerImpl(); |
| 114 | 139 |
| 115 void InitializeImpl(const std::string& gpu_blacklist_json, | 140 void InitializeImpl(const std::string& gpu_blacklist_json, |
| 116 const GPUInfo& gpu_info); | 141 const GPUInfo& gpu_info); |
| 117 | 142 |
| 118 void UpdateBlacklistedFeatures(GpuFeatureType features); | 143 void UpdateBlacklistedFeatures(GpuFeatureType features); |
| 119 | 144 |
| 120 // This should only be called once at initialization time, when preliminary | 145 // This should only be called once at initialization time, when preliminary |
| 121 // gpu info is collected. | 146 // gpu info is collected. |
| 122 void UpdatePreliminaryBlacklistedFeatures(); | 147 void UpdatePreliminaryBlacklistedFeatures(); |
| 123 | 148 |
| 124 // Update the GPU switching status. | 149 // Update the GPU switching status. |
| 125 // This should only be called once at initialization time. | 150 // This should only be called once at initialization time. |
| 126 void UpdateGpuSwitchingManager(); | 151 void UpdateGpuSwitchingManager(); |
| 127 | 152 |
| 128 // Notify all observers whenever there is a GPU info update. | 153 // Notify all observers whenever there is a GPU info update. |
| 129 void NotifyGpuInfoUpdate(); | 154 void NotifyGpuInfoUpdate(); |
| 130 | 155 |
| 131 // Try to switch to software rendering, if possible and necessary. | 156 // Try to switch to software rendering, if possible and necessary. |
| 132 void EnableSoftwareRenderingIfNecessary(); | 157 void EnableSoftwareRenderingIfNecessary(); |
| 133 | 158 |
| 159 // Helper to extract the domain from a given URL. |
| 160 std::string GetDomainFromURL(const GURL& url) const; |
| 161 |
| 162 // Implementation functions for blocking of 3D graphics APIs, used |
| 163 // for unit testing. |
| 164 void BlockDomainFrom3DAPIsAtTime( |
| 165 const GURL& url, DomainGuilt guilt, base::Time at_time); |
| 166 DomainBlockStatus Are3DAPIsBlockedAtTime( |
| 167 const GURL& url, base::Time at_time) const; |
| 168 int64 GetBlockAllDomainsDurationInMs() const; |
| 169 |
| 134 bool complete_gpu_info_already_requested_; | 170 bool complete_gpu_info_already_requested_; |
| 135 | 171 |
| 136 GpuFeatureType blacklisted_features_; | 172 GpuFeatureType blacklisted_features_; |
| 137 GpuFeatureType preliminary_blacklisted_features_; | 173 GpuFeatureType preliminary_blacklisted_features_; |
| 138 | 174 |
| 139 GpuSwitchingOption gpu_switching_; | 175 GpuSwitchingOption gpu_switching_; |
| 140 | 176 |
| 141 GPUInfo gpu_info_; | 177 GPUInfo gpu_info_; |
| 142 mutable base::Lock gpu_info_lock_; | 178 mutable base::Lock gpu_info_lock_; |
| 143 | 179 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 // the --disable-gpu commandline switch. | 192 // the --disable-gpu commandline switch. |
| 157 bool card_blacklisted_; | 193 bool card_blacklisted_; |
| 158 | 194 |
| 159 // We disable histogram stuff in testing, especially in unit tests because | 195 // We disable histogram stuff in testing, especially in unit tests because |
| 160 // they cause random failures. | 196 // they cause random failures. |
| 161 bool update_histograms_; | 197 bool update_histograms_; |
| 162 | 198 |
| 163 // Number of currently open windows, to be used in gpu memory allocation. | 199 // Number of currently open windows, to be used in gpu memory allocation. |
| 164 int window_count_; | 200 int window_count_; |
| 165 | 201 |
| 202 DomainBlockMap blocked_domains_; |
| 203 mutable std::list<base::Time> timestamps_of_gpu_resets_; |
| 204 bool domain_blocking_enabled_; |
| 205 |
| 166 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl); | 206 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl); |
| 167 }; | 207 }; |
| 168 | 208 |
| 169 } // namespace content | 209 } // namespace content |
| 170 | 210 |
| 171 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ | 211 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ |
| OLD | NEW |