| 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. |observer| |
| 98 // must not be NULL. |
| 99 void AddObserver(Observer* observer); |
| 87 | 100 |
| 88 // Remove a callback. | 101 // Unregisters |observer| from receiving notifications. This must be called |
| 89 // Returns true if removed, or false if it was not found. | 102 // on the same thread on which AddObserver() was called. |observer| |
| 90 bool RemoveGpuInfoUpdateCallback(Callback0::Type* callback); | 103 // must not be NULL. |
| 104 void RemoveObserver(Observer* observer); |
| 91 | 105 |
| 92 // Inserting disable-feature switches into renderer process command-line | 106 // Inserting disable-feature switches into renderer process command-line |
| 93 // in correspondance to preliminary gpu feature flags. | 107 // in correspondance to preliminary gpu feature flags. |
| 94 void AppendRendererCommandLine(CommandLine* command_line); | 108 void AppendRendererCommandLine(CommandLine* command_line); |
| 95 | 109 |
| 96 // Inserting switches into gpu process command-line: kUseGL, | 110 // Inserting switches into gpu process command-line: kUseGL, |
| 97 // kDisableGLMultisampling. | 111 // kDisableGLMultisampling. |
| 98 void AppendGpuCommandLine(CommandLine* command_line); | 112 void AppendGpuCommandLine(CommandLine* command_line); |
| 99 | 113 |
| 100 // Gives ownership of the built-in blacklist. This is always called on the | 114 // 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_; | 164 bool disable_accelerated_compositing_; |
| 151 bool disable_accelerated_layers_; | 165 bool disable_accelerated_layers_; |
| 152 bool disable_experimental_webgl_; | 166 bool disable_experimental_webgl_; |
| 153 bool disable_gl_multisampling_; | 167 bool disable_gl_multisampling_; |
| 154 | 168 |
| 155 bool ignore_gpu_blacklist_; | 169 bool ignore_gpu_blacklist_; |
| 156 | 170 |
| 157 std::string use_gl_; | 171 std::string use_gl_; |
| 158 }; | 172 }; |
| 159 | 173 |
| 174 typedef ObserverListThreadSafe<GpuDataManager::Observer> |
| 175 GpuDataManagerObserverList; |
| 176 |
| 160 friend struct DefaultSingletonTraits<GpuDataManager>; | 177 friend struct DefaultSingletonTraits<GpuDataManager>; |
| 161 | 178 |
| 162 GpuDataManager(); | 179 GpuDataManager(); |
| 163 virtual ~GpuDataManager(); | 180 virtual ~GpuDataManager(); |
| 164 | 181 |
| 165 void Initialize(); | 182 void Initialize(); |
| 166 | 183 |
| 167 // Check if we should go ahead and use gpu blacklist. | 184 // Check if we should go ahead and use gpu blacklist. |
| 168 // If not, return NULL; otherwise, update and return the current list. | 185 // If not, return NULL; otherwise, update and return the current list. |
| 169 GpuBlacklist* GetGpuBlacklist() const; | 186 GpuBlacklist* GetGpuBlacklist() const; |
| 170 | 187 |
| 171 // If flags hasn't been set and GPUInfo is available, run through blacklist | 188 // If flags hasn't been set and GPUInfo is available, run through blacklist |
| 172 // and compute the flags. | 189 // and compute the flags. |
| 173 void UpdateGpuFeatureFlags(); | 190 void UpdateGpuFeatureFlags(); |
| 174 | 191 |
| 175 // Call all callbacks. | 192 // Notify all observers whenever there is a GPU info update. |
| 176 void RunGpuInfoUpdateCallbacks(); | 193 void NotifyGpuInfoUpdate(); |
| 177 | 194 |
| 178 // If use-gl switch is osmesa or any, return true. | 195 // If use-gl switch is osmesa or any, return true. |
| 179 bool UseGLIsOSMesaOrAny(); | 196 bool UseGLIsOSMesaOrAny(); |
| 180 | 197 |
| 181 // Merges the second GPUInfo object with the first. | 198 // 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 | 199 // 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. | 200 // 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. | 201 // If it's a different GPU, then reset and copy over everything. |
| 185 // Return true if something changes that may affect blacklisting; currently | 202 // Return true if something changes that may affect blacklisting; currently |
| 186 // they are device_id, vendor_id, driver_vendor, driver_version, driver_date, | 203 // they are device_id, vendor_id, driver_vendor, driver_version, driver_date, |
| 187 // and gl_renderer. | 204 // and gl_renderer. |
| 188 static bool Merge(content::GPUInfo* object, const content::GPUInfo& other); | 205 static bool Merge(content::GPUInfo* object, const content::GPUInfo& other); |
| 189 | 206 |
| 190 bool complete_gpu_info_already_requested_; | 207 bool complete_gpu_info_already_requested_; |
| 191 | 208 |
| 192 GpuFeatureFlags gpu_feature_flags_; | 209 GpuFeatureFlags gpu_feature_flags_; |
| 193 GpuFeatureFlags preliminary_gpu_feature_flags_; | 210 GpuFeatureFlags preliminary_gpu_feature_flags_; |
| 194 | 211 |
| 195 UserFlags user_flags_; | 212 UserFlags user_flags_; |
| 196 | 213 |
| 197 content::GPUInfo gpu_info_; | 214 content::GPUInfo gpu_info_; |
| 198 mutable base::Lock gpu_info_lock_; | 215 mutable base::Lock gpu_info_lock_; |
| 199 | 216 |
| 200 scoped_ptr<GpuBlacklist> gpu_blacklist_; | 217 scoped_ptr<GpuBlacklist> gpu_blacklist_; |
| 201 | 218 |
| 202 // Map of callbacks. | 219 // Observers. |
| 203 std::set<Callback0::Type*> gpu_info_update_callbacks_; | 220 const scoped_refptr<GpuDataManagerObserverList> observer_list_; |
| 204 | 221 |
| 205 ListValue log_messages_; | 222 ListValue log_messages_; |
| 206 | 223 |
| 207 DISALLOW_COPY_AND_ASSIGN(GpuDataManager); | 224 DISALLOW_COPY_AND_ASSIGN(GpuDataManager); |
| 208 }; | 225 }; |
| 209 | 226 |
| 210 DISABLE_RUNNABLE_METHOD_REFCOUNT(GpuDataManager); | |
| 211 | |
| 212 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ | 227 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ |
| OLD | NEW |