summaryrefslogtreecommitdiffstats
path: root/content/browser/gpu/gpu_data_manager_impl_private.h
diff options
context:
space:
mode:
authorzmo@google.com <zmo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-14 22:13:21 +0000
committerzmo@google.com <zmo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-14 22:13:21 +0000
commit3de7a5ddcea8b3948d8f28d87c07666390ff02d7 (patch)
tree3c9316a2a9fe7725e31e336445fdcbaaea48a2c3 /content/browser/gpu/gpu_data_manager_impl_private.h
parented5ecd3e104c3ded7d0f0b0c7214f4a60eaff2cd (diff)
downloadchromium_src-3de7a5ddcea8b3948d8f28d87c07666390ff02d7.zip
chromium_src-3de7a5ddcea8b3948d8f28d87c07666390ff02d7.tar.gz
chromium_src-3de7a5ddcea8b3948d8f28d87c07666390ff02d7.tar.bz2
Refactor GpuDataManagerImpl to make it thread-safe.
Try to reland r199530 after fixing an issue that causes Mac Debug to crash when switching GPUs. The original review can be found here: https://codereview.chromium.org/14794006/ BUG=232556 TBR=joi@chromium.org, kbr@chromium.org, piman@chromium.org Review URL: https://codereview.chromium.org/14981007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200086 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/gpu/gpu_data_manager_impl_private.h')
-rw-r--r--content/browser/gpu/gpu_data_manager_impl_private.h239
1 files changed, 239 insertions, 0 deletions
diff --git a/content/browser/gpu/gpu_data_manager_impl_private.h b/content/browser/gpu/gpu_data_manager_impl_private.h
new file mode 100644
index 0000000..fb91a46
--- /dev/null
+++ b/content/browser/gpu/gpu_data_manager_impl_private.h
@@ -0,0 +1,239 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
+#define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
+
+#include <list>
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/singleton.h"
+#include "base/observer_list_threadsafe.h"
+#include "content/browser/gpu/gpu_blacklist.h"
+#include "content/browser/gpu/gpu_data_manager_impl.h"
+#include "content/browser/gpu/gpu_driver_bug_list.h"
+#include "content/browser/gpu/gpu_switching_list.h"
+
+namespace content {
+
+class CONTENT_EXPORT GpuDataManagerImplPrivate {
+ public:
+ static GpuDataManagerImplPrivate* Create(GpuDataManagerImpl* owner);
+
+ void InitializeForTesting(
+ const std::string& gpu_blacklist_json,
+ const GPUInfo& gpu_info);
+ bool IsFeatureBlacklisted(int feature) const;
+ GPUInfo GetGPUInfo() const;
+ void GetGpuProcessHandles(
+ const GpuDataManager::GetGpuProcessHandlesCallback& callback) const;
+ bool GpuAccessAllowed(std::string* reason) const;
+ void RequestCompleteGpuInfoIfNeeded();
+ bool IsCompleteGpuInfoAvailable() const;
+ void RequestVideoMemoryUsageStatsUpdate() const;
+ bool ShouldUseSwiftShader() const;
+ void RegisterSwiftShaderPath(const base::FilePath& path);
+ void AddObserver(GpuDataManagerObserver* observer);
+ void RemoveObserver(GpuDataManagerObserver* observer);
+ void UnblockDomainFrom3DAPIs(const GURL& url);
+ void DisableGpuWatchdog();
+ void SetGLStrings(const std::string& gl_vendor,
+ const std::string& gl_renderer,
+ const std::string& gl_version);
+ void GetGLStrings(std::string* gl_vendor,
+ std::string* gl_renderer,
+ std::string* gl_version);
+ void DisableHardwareAcceleration();
+
+ void Initialize();
+
+ void UpdateGpuInfo(const GPUInfo& gpu_info);
+
+ void UpdateVideoMemoryUsageStats(
+ const GPUVideoMemoryUsageStats& video_memory_usage_stats);
+
+ void AppendRendererCommandLine(CommandLine* command_line) const;
+
+ void AppendGpuCommandLine(CommandLine* command_line) const;
+
+ void AppendPluginCommandLine(CommandLine* command_line) const;
+
+ void UpdateRendererWebPrefs(WebPreferences* prefs) const;
+
+ GpuSwitchingOption GetGpuSwitchingOption() const;
+
+ std::string GetBlacklistVersion() const;
+
+ base::ListValue* GetBlacklistReasons() const;
+
+ void AddLogMessage(int level,
+ const std::string& header,
+ const std::string& message);
+
+ void ProcessCrashed(base::TerminationStatus exit_code);
+
+ base::ListValue* GetLogMessages() const;
+
+ void HandleGpuSwitch();
+
+#if defined(OS_WIN)
+ // Is the GPU process using the accelerated surface to present, instead of
+ // presenting by itself.
+ bool IsUsingAcceleratedSurface() const;
+#endif
+
+ void BlockDomainFrom3DAPIs(
+ const GURL& url, GpuDataManagerImpl::DomainGuilt guilt);
+ bool Are3DAPIsBlocked(const GURL& url,
+ int render_process_id,
+ int render_view_id,
+ ThreeDAPIType requester);
+
+ void DisableDomainBlockingFor3DAPIsForTesting();
+
+ void Notify3DAPIBlocked(const GURL& url,
+ int render_process_id,
+ int render_view_id,
+ ThreeDAPIType requester);
+
+ size_t GetBlacklistedFeatureCount() const;
+
+ virtual ~GpuDataManagerImplPrivate();
+
+ private:
+ friend class GpuDataManagerImplPrivateTest;
+
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ GpuSideBlacklisting);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ GpuSideExceptions);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ DisableHardwareAcceleration);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ SwiftShaderRendering);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ SwiftShaderRendering2);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ GpuInfoUpdate);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ NoGpuInfoUpdateWithSwiftShader);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ GPUVideoMemoryUsageStatsUpdate);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ BlockAllDomainsFrom3DAPIs);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ UnblockGuiltyDomainFrom3DAPIs);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ UnblockDomainOfUnknownGuiltFrom3DAPIs);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ UnblockOtherDomainFrom3DAPIs);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ UnblockThisDomainFrom3DAPIs);
+#if defined(OS_LINUX)
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ SetGLStrings);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ SetGLStringsNoEffects);
+#endif
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ GpuDriverBugListSingle);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ GpuDriverBugListMultiple);
+ FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
+ BlacklistAllFeatures);
+
+ struct DomainBlockEntry {
+ GpuDataManagerImpl::DomainGuilt last_guilt;
+ };
+
+ typedef std::map<std::string, DomainBlockEntry> DomainBlockMap;
+
+ typedef ObserverListThreadSafe<GpuDataManagerObserver>
+ GpuDataManagerObserverList;
+
+ explicit GpuDataManagerImplPrivate(GpuDataManagerImpl* owner);
+
+ void InitializeImpl(const std::string& gpu_blacklist_json,
+ const std::string& gpu_switching_list_json,
+ const std::string& gpu_driver_bug_list_json,
+ const GPUInfo& gpu_info);
+
+ void UpdateBlacklistedFeatures(const std::set<int>& features);
+
+ // This should only be called once at initialization time, when preliminary
+ // gpu info is collected.
+ void UpdatePreliminaryBlacklistedFeatures();
+
+ // Update the GPU switching status.
+ // This should only be called once at initialization time.
+ void UpdateGpuSwitchingManager(const GPUInfo& gpu_info);
+
+ // Notify all observers whenever there is a GPU info update.
+ void NotifyGpuInfoUpdate();
+
+ // Try to switch to SwiftShader rendering, if possible and necessary.
+ void EnableSwiftShaderIfNecessary();
+
+ // Helper to extract the domain from a given URL.
+ std::string GetDomainFromURL(const GURL& url) const;
+
+ // Implementation functions for blocking of 3D graphics APIs, used
+ // for unit testing.
+ void BlockDomainFrom3DAPIsAtTime(const GURL& url,
+ GpuDataManagerImpl::DomainGuilt guilt,
+ base::Time at_time);
+ GpuDataManagerImpl::DomainBlockStatus Are3DAPIsBlockedAtTime(
+ const GURL& url, base::Time at_time) const;
+ int64 GetBlockAllDomainsDurationInMs() const;
+
+ bool complete_gpu_info_already_requested_;
+
+ std::set<int> blacklisted_features_;
+ std::set<int> preliminary_blacklisted_features_;
+
+ GpuSwitchingOption gpu_switching_;
+
+ std::set<int> gpu_driver_bugs_;
+
+ GPUInfo gpu_info_;
+
+ scoped_ptr<GpuBlacklist> gpu_blacklist_;
+ scoped_ptr<GpuSwitchingList> gpu_switching_list_;
+ scoped_ptr<GpuDriverBugList> gpu_driver_bug_list_;
+
+ const scoped_refptr<GpuDataManagerObserverList> observer_list_;
+
+ ListValue log_messages_;
+
+ bool use_swiftshader_;
+
+ base::FilePath swiftshader_path_;
+
+ // Current card force-blacklisted due to GPU crashes, or disabled through
+ // the --disable-gpu commandline switch.
+ bool card_blacklisted_;
+
+ // We disable histogram stuff in testing, especially in unit tests because
+ // they cause random failures.
+ bool update_histograms_;
+
+ // Number of currently open windows, to be used in gpu memory allocation.
+ int window_count_;
+
+ DomainBlockMap blocked_domains_;
+ mutable std::list<base::Time> timestamps_of_gpu_resets_;
+ bool domain_blocking_enabled_;
+
+ GpuDataManagerImpl* owner_;
+
+ DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImplPrivate);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
+