diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-16 01:22:32 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-16 01:22:32 +0000 |
commit | 79078dfd0b7c6a2160b98345dce07cf9ab5ec4de (patch) | |
tree | 870de4615f582c77be40b2255bf81056979c440a | |
parent | d9550e31f7cbbccfce0f6a6572126225869cbbe1 (diff) | |
download | chromium_src-79078dfd0b7c6a2160b98345dce07cf9ab5ec4de.zip chromium_src-79078dfd0b7c6a2160b98345dce07cf9ab5ec4de.tar.gz chromium_src-79078dfd0b7c6a2160b98345dce07cf9ab5ec4de.tar.bz2 |
Add a Content API around GpuDataManager and use that from chrome. I moved GpuPerformanceStats to chrome since it wasn't used in content.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9401026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122211 0039d316-1c4b-4281-b951-d872f2087c98
29 files changed, 282 insertions, 209 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 030deb8..63e5c08 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -56,7 +56,6 @@ include_rules = [ "+content/browser/find_pasteboard.h", "+content/browser/font_list_async.h", "+content/browser/geolocation/wifi_data_provider_common.h", - "+content/browser/gpu/gpu_data_manager.h", "+content/browser/in_process_webkit/dom_storage_context.h", "+content/browser/in_process_webkit/session_storage_namespace.h", "+content/browser/in_process_webkit/webkit_context.h", diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index 62c7158..c03bc0d 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -96,8 +96,8 @@ #include "chrome/common/pref_names.h" #include "chrome/common/profiling.h" #include "chrome/installer/util/google_update_settings.h" -#include "content/browser/gpu/gpu_data_manager.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/gpu_data_manager.h" #include "content/public/common/content_client.h" #include "content/public/common/main_function_params.h" #include "grit/app_locale_settings.h" @@ -453,7 +453,7 @@ Profile* CreateProfile(const content::MainFunctionParams& parameters, // Load GPU Blacklist, collect preliminary gpu info, and compute preliminary // gpu feature flags. void InitializeGpuDataManager(const CommandLine& parsed_command_line) { - GpuDataManager::GetInstance(); + content::GpuDataManager::GetInstance(); if (parsed_command_line.HasSwitch(switches::kSkipGpuDataLoading) || parsed_command_line.HasSwitch(switches::kIgnoreGpuBlacklist)) return; diff --git a/chrome/browser/component_updater/swiftshader_component_installer.cc b/chrome/browser/component_updater/swiftshader_component_installer.cc index ad447ec..03b9482 100644 --- a/chrome/browser/component_updater/swiftshader_component_installer.cc +++ b/chrome/browser/component_updater/swiftshader_component_installer.cc @@ -16,9 +16,11 @@ #include "chrome/browser/component_updater/component_updater_service.h" #include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_thread.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager_observer.h" using content::BrowserThread; +using content::GpuDataManager; namespace { @@ -150,7 +152,7 @@ void FinishSwiftShaderUpdateRegistration(ComponentUpdateService* cus, } } -class UpdateChecker : public GpuDataManager::Observer { +class UpdateChecker : public content::GpuDataManagerObserver { public: explicit UpdateChecker(ComponentUpdateService* cus); @@ -170,7 +172,7 @@ void UpdateChecker::OnGpuInfoUpdate() { if (!gpu_data_manager->GpuAccessAllowed() || (gpu_data_manager->GetGpuFeatureType() & content::GPU_FEATURE_TYPE_WEBGL) || - gpu_data_manager->software_rendering()) { + gpu_data_manager->ShouldUseSoftwareRendering()) { gpu_data_manager->RemoveObserver(this); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); FilePath path = GetSwiftShaderBaseDirectory(); diff --git a/chrome/browser/extensions/extension_webstore_private_api.cc b/chrome/browser/extensions/extension_webstore_private_api.cc index c85b35d..5517250 100644 --- a/chrome/browser/extensions/extension_webstore_private_api.cc +++ b/chrome/browser/extensions/extension_webstore_private_api.cc @@ -27,6 +27,7 @@ #include "chrome/common/extensions/extension_error_utils.h" #include "chrome/common/extensions/extension_l10n_util.h" #include "chrome/common/net/gaia/gaia_constants.h" +#include "content/public/browser/gpu_data_manager.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/web_contents.h" @@ -34,6 +35,8 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" +using content::GpuDataManager; + namespace { const char kAppInstallBubbleKey[] = "appInstallBubble"; @@ -508,7 +511,7 @@ bool GetWebGLStatusFunction::RunImpl() { #endif GpuDataManager* manager = GpuDataManager::GetInstance(); - if (manager->complete_gpu_info_available()) + if (manager->IsCompleteGPUInfoAvailable()) finalized = true; bool webgl_allowed = IsWebGLAllowed(manager); diff --git a/chrome/browser/extensions/extension_webstore_private_api.h b/chrome/browser/extensions/extension_webstore_private_api.h index efb6413..0c1f09d 100644 --- a/chrome/browser/extensions/extension_webstore_private_api.h +++ b/chrome/browser/extensions/extension_webstore_private_api.h @@ -13,12 +13,16 @@ #include "chrome/browser/extensions/webstore_install_helper.h" #include "chrome/browser/extensions/webstore_installer.h" #include "chrome/common/net/gaia/google_service_auth_error.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager_observer.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" class ProfileSyncService; +namespace content { +class GpuDataManager; +} + class WebstorePrivateApi { public: // Allows you to set the ProfileSyncService the function will use for @@ -161,11 +165,11 @@ class SetStoreLoginFunction : public SyncExtensionFunction { }; class GetWebGLStatusFunction : public AsyncExtensionFunction, - public GpuDataManager::Observer { + public content::GpuDataManagerObserver { public: GetWebGLStatusFunction(); - // Implementing GpuDataManager::Observer interface. + // Implementing GpuDataManagerObserver interface. virtual void OnGpuInfoUpdate() OVERRIDE; protected: @@ -177,7 +181,7 @@ class GetWebGLStatusFunction : public AsyncExtensionFunction, // A false return value is always valid, but a true one is only valid if full // GPU info has been collected in a GPU process. - static bool IsWebGLAllowed(GpuDataManager* manager); + static bool IsWebGLAllowed(content::GpuDataManager* manager); DECLARE_EXTENSION_FUNCTION_NAME("webstorePrivate.getWebGLStatus"); }; diff --git a/chrome/browser/extensions/extension_webstore_private_apitest.cc b/chrome/browser/extensions/extension_webstore_private_apitest.cc index 155ca46..cf46462 100644 --- a/chrome/browser/extensions/extension_webstore_private_apitest.cc +++ b/chrome/browser/extensions/extension_webstore_private_apitest.cc @@ -21,6 +21,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/test/base/test_launcher_utils.h" #include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/gpu_data_manager.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "net/base/mock_host_resolver.h" @@ -311,7 +312,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) { ASSERT_TRUE(blacklist->LoadGpuBlacklist( "1.0", json_blacklist, GpuBlacklist::kAllOs)); blacklist->UpdateGpuDataManager(); - GpuFeatureType type = GpuDataManager::GetInstance()->GetGpuFeatureType(); + GpuFeatureType type = + content::GpuDataManager::GetInstance()->GetGpuFeatureType(); EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL); bool webgl_allowed = false; diff --git a/chrome/browser/gpu_blacklist.cc b/chrome/browser/gpu_blacklist.cc index b81d69c..405cd8c 100644 --- a/chrome/browser/gpu_blacklist.cc +++ b/chrome/browser/gpu_blacklist.cc @@ -13,9 +13,11 @@ #include "base/sys_info.h" #include "base/version.h" #include "chrome/browser/gpu_util.h" +#include "content/public/browser/gpu_data_manager.h" #include "content/public/common/content_switches.h" #include "content/public/common/gpu_info.h" +using content::GpuDataManager; using content::GpuFeatureType; namespace { @@ -748,7 +750,7 @@ GpuFeatureType GpuBlacklist::DetermineGpuFeatureType( void GpuBlacklist::UpdateGpuDataManager() { content::GpuFeatureType feature_type = DetermineGpuFeatureType( - GpuBlacklist::kOsAny, NULL, GpuDataManager::GetInstance()->gpu_info()); + GpuBlacklist::kOsAny, NULL, GpuDataManager::GetInstance()->GetGPUInfo()); GpuDataManager::GetInstance()->SetGpuFeatureType(feature_type); gpu_util::UpdateStats(); } diff --git a/chrome/browser/gpu_blacklist.h b/chrome/browser/gpu_blacklist.h index 7fbb056..ca02cf9 100644 --- a/chrome/browser/gpu_blacklist.h +++ b/chrome/browser/gpu_blacklist.h @@ -15,17 +15,16 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "base/values.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager_observer.h" #include "content/public/common/gpu_feature_type.h" -class GpuDataManager; class Version; namespace content { struct GPUInfo; } -class GpuBlacklist : public GpuDataManager::Observer { +class GpuBlacklist : public content::GpuDataManagerObserver { public: enum OsType { kOsLinux, diff --git a/chrome/browser/gpu_blacklist_unittest.cc b/chrome/browser/gpu_blacklist_unittest.cc index 5d334c2..6472800 100644 --- a/chrome/browser/gpu_blacklist_unittest.cc +++ b/chrome/browser/gpu_blacklist_unittest.cc @@ -11,6 +11,7 @@ #include "base/path_service.h" #include "base/version.h" #include "chrome/browser/gpu_blacklist.h" +#include "content/public/browser/gpu_data_manager.h" #include "content/public/common/gpu_info.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/content/browser/gpu/gpu_performance_stats.cc b/chrome/browser/gpu_performance_stats.cc index 6780d63..93d1932 100644 --- a/content/browser/gpu/gpu_performance_stats.cc +++ b/chrome/browser/gpu_performance_stats.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/gpu/gpu_performance_stats.h" +#include "chrome/browser/gpu_performance_stats.h" #include "base/stringprintf.h" diff --git a/content/browser/gpu/gpu_performance_stats.h b/chrome/browser/gpu_performance_stats.h index 50e752a..d6aa019 100644 --- a/content/browser/gpu/gpu_performance_stats.h +++ b/chrome/browser/gpu_performance_stats.h @@ -2,13 +2,12 @@ // 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_PERFORMANCE_STATS_H_ -#define CONTENT_BROWSER_GPU_GPU_PERFORMANCE_STATS_H_ +#ifndef CHROME_BROWSER_GPU_PERFORMANCE_STATS_H_ +#define CHROME_BROWSER_GPU_PERFORMANCE_STATS_H_ #include "base/values.h" -#include "content/common/content_export.h" -class CONTENT_EXPORT GpuPerformanceStats { +class GpuPerformanceStats { public: GpuPerformanceStats() : graphics(0.f), gaming(0.f), overall(0.f) { } @@ -23,4 +22,4 @@ class CONTENT_EXPORT GpuPerformanceStats { }; -#endif // CONTENT_BROWSER_GPU_GPU_PERFORMANCE_STATS_H_ +#endif // CHROME_BROWSER_GPU_PERFORMANCE_STATS_H_ diff --git a/content/browser/gpu/gpu_performance_stats_win.cc b/chrome/browser/gpu_performance_stats_win.cc index 5bdd783..7472e92 100644 --- a/content/browser/gpu/gpu_performance_stats_win.cc +++ b/chrome/browser/gpu_performance_stats_win.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/gpu/gpu_performance_stats.h" +#include "chrome/browser/gpu_performance_stats.h" #include <winsatcominterfacei.h> diff --git a/chrome/browser/gpu_util.cc b/chrome/browser/gpu_util.cc index f03ca9d..3ca6c79 100644 --- a/chrome/browser/gpu_util.cc +++ b/chrome/browser/gpu_util.cc @@ -15,9 +15,11 @@ #include "base/values.h" #include "base/version.h" #include "chrome/browser/gpu_blacklist.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager.h" #include "content/public/common/content_switches.h" +#include "content/public/common/gpu_info.h" +using content::GpuDataManager; using content::GpuFeatureType; namespace { @@ -47,7 +49,7 @@ struct GpuFeatureInfo { // Determine if accelerated-2d-canvas is supported, which depends on whether // lose_context could happen and whether skia is the backend. bool SupportsAccelerated2dCanvas() { - if (GpuDataManager::GetInstance()->gpu_info().can_lose_context) + if (GpuDataManager::GetInstance()->GetGPUInfo().can_lose_context) return false; #if defined(USE_SKIA) return true; @@ -243,7 +245,7 @@ Value* GetFeatureStatus() { status += "_software"; else status += "_off"; - } else if (GpuDataManager::GetInstance()->software_rendering()) { + } else if (GpuDataManager::GetInstance()->ShouldUseSoftwareRendering()) { status = "unavailable_software"; } else if (kGpuFeatureInfo[i].blocked || gpu_access_blocked) { @@ -299,7 +301,7 @@ Value* GetFeatureStatus() { } DictionaryValue* GpuInfoAsDictionaryValue() { - content::GPUInfo gpu_info = GpuDataManager::GetInstance()->gpu_info(); + content::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo(); ListValue* basic_info = new ListValue(); basic_info->Append(NewDescriptionValuePair( "Initialization time", diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 978ac56..7170b03 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -26,7 +26,8 @@ #include "chrome/common/chrome_version_info.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/pref_names.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager.h" +#include "content/public/common/gpu_info.h" #include "googleurl/src/gurl.h" #include "ui/gfx/screen.h" #include "webkit/plugins/webplugininfo.h" @@ -38,6 +39,8 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; #endif +using content::GpuDataManager; + namespace { // Returns the date at which the current metrics client ID was created as @@ -375,11 +378,9 @@ void MetricsLog::RecordEnvironment( { OPEN_ELEMENT_FOR_SCOPE("gpu"); - GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance(); - if (gpu_data_manager) { - WriteIntAttribute("vendorid", gpu_data_manager->gpu_info().vendor_id); - WriteIntAttribute("deviceid", gpu_data_manager->gpu_info().device_id); - } + content::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo(); + WriteIntAttribute("vendorid", gpu_info.vendor_id); + WriteIntAttribute("deviceid", gpu_info.device_id); } { diff --git a/chrome/browser/ui/webui/flash_ui.cc b/chrome/browser/ui/webui/flash_ui.cc index f885c39..888cb75 100644 --- a/chrome/browser/ui/webui/flash_ui.cc +++ b/chrome/browser/ui/webui/flash_ui.cc @@ -26,12 +26,14 @@ #include "chrome/browser/ui/webui/crashes_ui.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/url_constants.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager_observer.h" #include "content/public/browser/plugin_service.h" #include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_message_handler.h" +#include "content/public/common/gpu_info.h" #include "grit/browser_resources.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -44,6 +46,7 @@ #include "base/win/windows_version.h" #endif +using content::GpuDataManager; using content::PluginService; using content::UserMetricsAction; using content::WebContents; @@ -74,7 +77,7 @@ const int kTimeout = 8 * 1000; // 8 seconds. // The handler for JavaScript messages for the about:flags page. class FlashDOMHandler : public WebUIMessageHandler, public CrashUploadList::Delegate, - public GpuDataManager::Observer { + public content::GpuDataManagerObserver { public: FlashDOMHandler(); virtual ~FlashDOMHandler(); @@ -109,9 +112,6 @@ class FlashDOMHandler : public WebUIMessageHandler, // A timer to keep track of when the data fetching times out. base::OneShotTimer<FlashDOMHandler> timeout_; - // GPU variables. - GpuDataManager* gpu_data_manager_; - // Crash list. scoped_refptr<CrashUploadList> upload_list_; @@ -141,16 +141,15 @@ FlashDOMHandler::FlashDOMHandler() upload_list_->LoadCrashListAsynchronously(); // Watch for changes in GPUInfo. - gpu_data_manager_ = GpuDataManager::GetInstance(); - gpu_data_manager_->AddObserver(this); + GpuDataManager::GetInstance()->AddObserver(this); // Tell GpuDataManager it should have full GpuInfo. If the // GPU process has not run yet, this will trigger its launch. - gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); + GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded(); // GPU access might not be allowed at all, which will cause us not to get a // call back. - if (!gpu_data_manager_->GpuAccessAllowed()) + if (!GpuDataManager::GetInstance()->GpuAccessAllowed()) OnGpuInfoUpdate(); PluginService::GetInstance()->GetPlugins(base::Bind( @@ -163,7 +162,7 @@ FlashDOMHandler::FlashDOMHandler() } FlashDOMHandler::~FlashDOMHandler() { - gpu_data_manager_->RemoveObserver(this); + GpuDataManager::GetInstance()->RemoveObserver(this); } void FlashDOMHandler::RegisterMessages() { @@ -306,9 +305,9 @@ void FlashDOMHandler::MaybeRespondToPage() { // GPU information. AddPair(list, string16(), "--- GPU information ---"); - const content::GPUInfo& gpu_info = gpu_data_manager_->gpu_info(); + content::GPUInfo gpu_info = GpuDataManager::GetInstance()->GetGPUInfo(); - if (!gpu_data_manager_->GpuAccessAllowed()) + if (!GpuDataManager::GetInstance()->GpuAccessAllowed()) AddPair(list, ASCIIToUTF16("WARNING:"), "GPU access is not allowed"); #if defined(OS_WIN) const content::DxDiagNode& node = gpu_info.dx_diagnostics; diff --git a/chrome/browser/ui/webui/gpu_internals_ui.cc b/chrome/browser/ui/webui/gpu_internals_ui.cc index 5ebaf36..133b7c8 100644 --- a/chrome/browser/ui/webui/gpu_internals_ui.cc +++ b/chrome/browser/ui/webui/gpu_internals_ui.cc @@ -14,13 +14,15 @@ #include "base/sys_info.h" #include "base/values.h" #include "chrome/browser/gpu_blacklist.h" +#include "chrome/browser/gpu_performance_stats.h" #include "chrome/browser/gpu_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/url_constants.h" -#include "content/browser/gpu/gpu_data_manager.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager_observer.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_message_handler.h" @@ -30,6 +32,7 @@ #include "ui/base/l10n/l10n_util.h" using content::BrowserThread; +using content::GpuDataManager; using content::WebContents; using content::WebUIMessageHandler; @@ -51,7 +54,7 @@ ChromeWebUIDataSource* CreateGpuHTMLSource() { class GpuMessageHandler : public WebUIMessageHandler, public base::SupportsWeakPtr<GpuMessageHandler>, - public GpuDataManager::Observer { + public content::GpuDataManagerObserver { public: GpuMessageHandler(); virtual ~GpuMessageHandler(); @@ -59,7 +62,7 @@ class GpuMessageHandler // WebUIMessageHandler implementation. virtual void RegisterMessages() OVERRIDE; - // GpuDataManager::Observer implementation. + // GpuDataManagerObserver implementation. virtual void OnGpuInfoUpdate() OVERRIDE; // Messages @@ -76,9 +79,6 @@ class GpuMessageHandler const Value* value); private: - // Cache the Singleton for efficiency. - GpuDataManager* gpu_data_manager_; - DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); }; @@ -89,12 +89,10 @@ class GpuMessageHandler //////////////////////////////////////////////////////////////////////////////// GpuMessageHandler::GpuMessageHandler() { - gpu_data_manager_ = GpuDataManager::GetInstance(); - DCHECK(gpu_data_manager_); } GpuMessageHandler::~GpuMessageHandler() { - gpu_data_manager_->RemoveObserver(this); + GpuDataManager::GetInstance()->RemoveObserver(this); } /* BrowserBridge.callAsync prepends a requestID to these messages. */ @@ -160,11 +158,11 @@ void GpuMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Watch for changes in GPUInfo - gpu_data_manager_->AddObserver(this); + GpuDataManager::GetInstance()->AddObserver(this); // Tell GpuDataManager it should have full GpuInfo. If the // Gpu process has not run yet, this will trigger its launch. - gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); + GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded(); // Run callback immediately in case the info is ready and no update in the // future. @@ -209,7 +207,7 @@ Value* GpuMessageHandler::OnRequestClientInfo(const ListValue* list) { GpuBlacklist::GetInstance()->GetVersion()); GpuPerformanceStats stats = - GpuDataManager::GetInstance()->GetPerformanceStats(); + GpuPerformanceStats::RetrieveGpuPerformanceStats(); dict->Set("performance", stats.ToValue()); return dict; @@ -218,7 +216,7 @@ Value* GpuMessageHandler::OnRequestClientInfo(const ListValue* list) { Value* GpuMessageHandler::OnRequestLogMessages(const ListValue*) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - return gpu_data_manager_->log_messages().DeepCopy(); + return GpuDataManager::GetInstance()->GetLogMessages().DeepCopy(); } void GpuMessageHandler::OnGpuInfoUpdate() { diff --git a/chrome/browser/ui/webui/tracing_ui.cc b/chrome/browser/ui/webui/tracing_ui.cc index 36c14a5..3a1c492 100644 --- a/chrome/browser/ui/webui/tracing_ui.cc +++ b/chrome/browser/ui/webui/tracing_ui.cc @@ -20,10 +20,11 @@ #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/url_constants.h" -#include "content/browser/gpu/gpu_data_manager.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/trace_controller.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager_observer.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "content/public/browser/web_ui.h" @@ -33,6 +34,7 @@ #include "ui/base/l10n/l10n_util.h" using content::BrowserThread; +using content::GpuDataManager; using content::WebContents; using content::WebUIMessageHandler; @@ -57,7 +59,7 @@ class TracingMessageHandler public SelectFileDialog::Listener, public base::SupportsWeakPtr<TracingMessageHandler>, public TraceSubscriber, - public GpuDataManager::Observer { + public content::GpuDataManagerObserver { public: TracingMessageHandler(); virtual ~TracingMessageHandler(); @@ -74,7 +76,7 @@ class TracingMessageHandler virtual void OnTraceDataCollected(const std::string& trace_fragment); virtual void OnTraceBufferPercentFullReply(float percent_full); - // GpuDataManager::Observer implementation. + // GpuDataManagerObserver implementation. virtual void OnGpuInfoUpdate() OVERRIDE; // Messages. @@ -103,9 +105,6 @@ class TracingMessageHandler // True while tracing is active. bool trace_enabled_; - // Cache the Singleton for efficiency. - GpuDataManager* gpu_data_manager_; - DISALLOW_COPY_AND_ASSIGN(TracingMessageHandler); }; @@ -144,12 +143,10 @@ class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { TracingMessageHandler::TracingMessageHandler() : select_trace_file_dialog_type_(SelectFileDialog::SELECT_NONE), trace_enabled_(false) { - gpu_data_manager_ = GpuDataManager::GetInstance(); - DCHECK(gpu_data_manager_); } TracingMessageHandler::~TracingMessageHandler() { - gpu_data_manager_->RemoveObserver(this); + GpuDataManager::GetInstance()->RemoveObserver(this); if (select_trace_file_dialog_) select_trace_file_dialog_->ListenerDestroyed(); @@ -186,11 +183,11 @@ void TracingMessageHandler::OnTracingControllerInitialized( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Watch for changes in GPUInfo - gpu_data_manager_->AddObserver(this); + GpuDataManager::GetInstance()->AddObserver(this); // Tell GpuDataManager it should have full GpuInfo. If the // Gpu process has not run yet, this will trigger its launch. - gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); + GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded(); // Run callback immediately in case the info is ready and no update in the // future. diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f69c6e7..e5f94ac 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1022,8 +1022,8 @@ 'browser/extensions/app_notify_channel_setup.h', 'browser/extensions/app_notify_channel_ui.cc', 'browser/extensions/app_notify_channel_ui.h', - 'browser/extensions/app_shortcut_manager.cc', - 'browser/extensions/app_shortcut_manager.h', + 'browser/extensions/app_shortcut_manager.cc', + 'browser/extensions/app_shortcut_manager.h', 'browser/extensions/apps_promo.cc', 'browser/extensions/apps_promo.h', 'browser/extensions/browser_action_test_util.h', @@ -1397,6 +1397,9 @@ 'browser/google/google_util.h', 'browser/gpu_blacklist.cc', 'browser/gpu_blacklist.h', + 'browser/gpu_performance_stats.cc', + 'browser/gpu_performance_stats.h', + 'browser/gpu_performance_stats_win.cc', 'browser/gpu_util.cc', 'browser/gpu_util.h', 'browser/hang_monitor/hung_plugin_action.cc', diff --git a/chrome/test/gpu/gpu_feature_browsertest.cc b/chrome/test/gpu/gpu_feature_browsertest.cc index 412bc39..0d290a61 100644 --- a/chrome/test/gpu/gpu_feature_browsertest.cc +++ b/chrome/test/gpu/gpu_feature_browsertest.cc @@ -15,11 +15,12 @@ #include "chrome/test/base/test_launcher_utils.h" #include "chrome/test/base/tracing.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/public/browser/gpu_data_manager.h" #include "content/public/common/content_switches.h" #include "net/base/net_util.h" #include "ui/gfx/gl/gl_switches.h" +using content::GpuDataManager; using content::GpuFeatureType; namespace { diff --git a/content/browser/gpu/browser_gpu_channel_host_factory.cc b/content/browser/gpu/browser_gpu_channel_host_factory.cc index 06ef537..a706fb3 100644 --- a/content/browser/gpu/browser_gpu_channel_host_factory.cc +++ b/content/browser/gpu/browser_gpu_channel_host_factory.cc @@ -5,7 +5,7 @@ #include "content/browser/gpu/browser_gpu_channel_host_factory.h" #include "base/bind.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_surface_tracker.h" #include "content/common/gpu/gpu_messages.h" @@ -168,7 +168,7 @@ GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync( return gpu_channel_.get(); } // Ensure initialization on the main thread. - GpuDataManager::GetInstance(); + GpuDataManagerImpl::GetInstance(); EstablishRequest request; GetIOLoopProxy()->PostTask( diff --git a/content/browser/gpu/gpu_data_manager.cc b/content/browser/gpu/gpu_data_manager_impl.cc index c175b67..0194706 100644 --- a/content/browser/gpu/gpu_data_manager.cc +++ b/content/browser/gpu/gpu_data_manager_impl.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/browser/gpu/gpu_data_manager_impl.h" #if defined(OS_MACOSX) #include <CoreGraphics/CGDisplayConfiguration.h> @@ -21,6 +21,7 @@ #include "content/common/gpu/gpu_messages.h" #include "content/gpu/gpu_info_collector.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/gpu_data_manager_observer.h" #include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" #include "ui/gfx/gl/gl_implementation.h" @@ -28,6 +29,7 @@ #include "webkit/plugins/plugin_switches.h" using content::BrowserThread; +using content::GpuDataManagerObserver; using content::GpuFeatureType; namespace { @@ -40,8 +42,8 @@ void DisplayReconfigCallback(CGDirectDisplayID display, LOG(INFO) << "Display re-configuration: flags = 0x" << base::StringPrintf("%04x", flags); if (flags & kCGDisplayAddFlag) { - GpuDataManager* manager = - reinterpret_cast<GpuDataManager*>(gpu_data_manager); + GpuDataManagerImpl* manager = + reinterpret_cast<GpuDataManagerImpl*>(gpu_data_manager); DCHECK(manager); manager->HandleGpuSwitch(); } @@ -50,7 +52,17 @@ void DisplayReconfigCallback(CGDirectDisplayID display, } // namespace anonymous -GpuDataManager::GpuDataManager() +// static +content::GpuDataManager* content::GpuDataManager::GetInstance() { + return GpuDataManagerImpl::GetInstance(); +} + +// static +GpuDataManagerImpl* GpuDataManagerImpl::GetInstance() { + return Singleton<GpuDataManagerImpl>::get(); +} + +GpuDataManagerImpl::GpuDataManagerImpl() : complete_gpu_info_already_requested_(false), complete_gpu_info_available_(false), gpu_feature_type_(content::GPU_FEATURE_TYPE_UNKNOWN), @@ -61,7 +73,7 @@ GpuDataManager::GpuDataManager() Initialize(); } -void GpuDataManager::Initialize() { +void GpuDataManagerImpl::Initialize() { CommandLine* command_line = CommandLine::ForCurrentProcess(); if (command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); @@ -82,18 +94,13 @@ void GpuDataManager::Initialize() { #endif } -GpuDataManager::~GpuDataManager() { +GpuDataManagerImpl::~GpuDataManagerImpl() { #if defined(OS_MACOSX) CGDisplayRemoveReconfigurationCallback(DisplayReconfigCallback, this); #endif } -// static -GpuDataManager* GpuDataManager::GetInstance() { - return Singleton<GpuDataManager>::get(); -} - -void GpuDataManager::RequestCompleteGpuInfoIfNeeded() { +void GpuDataManagerImpl::RequestCompleteGpuInfoIfNeeded() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (complete_gpu_info_already_requested_ || complete_gpu_info_available_) @@ -106,7 +113,11 @@ void GpuDataManager::RequestCompleteGpuInfoIfNeeded() { new GpuMsg_CollectGraphicsInfo()); } -void GpuDataManager::UpdateGpuInfo(const content::GPUInfo& gpu_info) { +bool GpuDataManagerImpl::IsCompleteGPUInfoAvailable() const { + return complete_gpu_info_available_; +} + +void GpuDataManagerImpl::UpdateGpuInfo(const content::GPUInfo& gpu_info) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); complete_gpu_info_available_ = @@ -124,26 +135,16 @@ void GpuDataManager::UpdateGpuInfo(const content::GPUInfo& gpu_info) { NotifyGpuInfoUpdate(); } -const content::GPUInfo& GpuDataManager::gpu_info() const { - base::AutoLock auto_lock(gpu_info_lock_); +content::GPUInfo GpuDataManagerImpl::GetGPUInfo() const { return gpu_info_; } -GpuPerformanceStats GpuDataManager::GetPerformanceStats() const { - return GpuPerformanceStats::RetrieveGpuPerformanceStats(); -} - -void GpuDataManager::AddLogMessage(Value* msg) { +void GpuDataManagerImpl::AddLogMessage(Value* msg) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); log_messages_.Append(msg); } -const ListValue& GpuDataManager::log_messages() const { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - return log_messages_; -} - -GpuFeatureType GpuDataManager::GetGpuFeatureType() { +GpuFeatureType GpuDataManagerImpl::GetGpuFeatureType() { if (software_rendering_) { GpuFeatureType flags; @@ -156,8 +157,8 @@ GpuFeatureType GpuDataManager::GetGpuFeatureType() { return gpu_feature_type_; } -bool GpuDataManager::GpuAccessAllowed() { - if (software_rendering()) +bool GpuDataManagerImpl::GpuAccessAllowed() { + if (software_rendering_) return true; // We only need to block GPU process if more features are disallowed other @@ -167,15 +168,15 @@ bool GpuDataManager::GpuAccessAllowed() { return (gpu_feature_type_ & mask) == 0; } -void GpuDataManager::AddObserver(Observer* observer) { +void GpuDataManagerImpl::AddObserver(GpuDataManagerObserver* observer) { observer_list_->AddObserver(observer); } -void GpuDataManager::RemoveObserver(Observer* observer) { +void GpuDataManagerImpl::RemoveObserver(GpuDataManagerObserver* observer) { observer_list_->RemoveObserver(observer); } -void GpuDataManager::AppendRendererCommandLine( +void GpuDataManagerImpl::AppendRendererCommandLine( CommandLine* command_line) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(command_line); @@ -198,7 +199,7 @@ void GpuDataManager::AppendRendererCommandLine( command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); } -void GpuDataManager::AppendGpuCommandLine( +void GpuDataManagerImpl::AppendGpuCommandLine( CommandLine* command_line) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(command_line); @@ -224,17 +225,20 @@ void GpuDataManager::AppendGpuCommandLine( command_line->AppendSwitchASCII(switches::kUseGL, use_gl); } - if (gpu_info().optimus) - command_line->AppendSwitch(switches::kReduceGpuSandbox); + { + base::AutoLock auto_lock(gpu_info_lock_); + if (gpu_info_.optimus) + command_line->AppendSwitch(switches::kReduceGpuSandbox); + } } -void GpuDataManager::SetGpuFeatureType(GpuFeatureType feature_type) { +void GpuDataManagerImpl::SetGpuFeatureType(GpuFeatureType feature_type) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); UpdateGpuFeatureType(feature_type); preliminary_gpu_feature_type_ = gpu_feature_type_; } -void GpuDataManager::HandleGpuSwitch() { +void GpuDataManagerImpl::HandleGpuSwitch() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); content::GPUInfo gpu_info; gpu_info_collector::CollectVideoCardInfo(&gpu_info); @@ -246,11 +250,11 @@ void GpuDataManager::HandleGpuSwitch() { // relaunch GPU process. } -void GpuDataManager::NotifyGpuInfoUpdate() { - observer_list_->Notify(&GpuDataManager::Observer::OnGpuInfoUpdate); +void GpuDataManagerImpl::NotifyGpuInfoUpdate() { + observer_list_->Notify(&GpuDataManagerObserver::OnGpuInfoUpdate); } -void GpuDataManager::UpdateGpuFeatureType( +void GpuDataManagerImpl::UpdateGpuFeatureType( GpuFeatureType embedder_feature_type) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -272,12 +276,17 @@ void GpuDataManager::UpdateGpuFeatureType( EnableSoftwareRenderingIfNecessary(); } -void GpuDataManager::RegisterSwiftShaderPath(FilePath path) { +void GpuDataManagerImpl::RegisterSwiftShaderPath(FilePath path) { swiftshader_path_ = path; EnableSoftwareRenderingIfNecessary(); } -void GpuDataManager::EnableSoftwareRenderingIfNecessary() { +const base::ListValue& GpuDataManagerImpl::GetLogMessages() const { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + return log_messages_; +} + +void GpuDataManagerImpl::EnableSoftwareRenderingIfNecessary() { if (!GpuAccessAllowed() || (gpu_feature_type_ & content::GPU_FEATURE_TYPE_WEBGL)) { #if defined(ENABLE_SWIFTSHADER) @@ -289,11 +298,11 @@ void GpuDataManager::EnableSoftwareRenderingIfNecessary() { } } -bool GpuDataManager::software_rendering() { +bool GpuDataManagerImpl::ShouldUseSoftwareRendering() { return software_rendering_; } -void GpuDataManager::BlacklistCard() { +void GpuDataManagerImpl::BlacklistCard() { card_blacklisted_ = true; { @@ -308,8 +317,8 @@ void GpuDataManager::BlacklistCard() { NotifyGpuInfoUpdate(); } -bool GpuDataManager::Merge(content::GPUInfo* object, - const content::GPUInfo& other) { +bool GpuDataManagerImpl::Merge(content::GPUInfo* object, + const content::GPUInfo& other) { if (object->device_id != other.device_id || object->vendor_id != other.vendor_id) { *object = other; diff --git a/content/browser/gpu/gpu_data_manager.h b/content/browser/gpu/gpu_data_manager_impl.h index 76977bf..40c6b38 100644 --- a/content/browser/gpu/gpu_data_manager.h +++ b/content/browser/gpu/gpu_data_manager_impl.h @@ -2,8 +2,8 @@ // 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_H_ -#define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ +#ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ +#define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ #pragma once #include <set> @@ -15,68 +15,36 @@ #include "base/observer_list_threadsafe.h" #include "base/synchronization/lock.h" #include "base/values.h" -#include "content/browser/gpu/gpu_performance_stats.h" -#include "content/common/content_export.h" -#include "content/public/common/gpu_feature_type.h" +#include "content/public/browser/gpu_data_manager.h" #include "content/public/common/gpu_info.h" class CommandLine; -class CONTENT_EXPORT GpuDataManager { +class CONTENT_EXPORT GpuDataManagerImpl + : public NON_EXPORTED_BASE(content::GpuDataManager) { public: - // Observers can register themselves via GpuDataManager::AddObserver, and - // can un-register with GpuDataManager::RemoveObserver. - class Observer { - public: - // Called for any observers whenever there is a GPU info update. - virtual void OnGpuInfoUpdate() = 0; - - protected: - virtual ~Observer() {} - }; - // Getter for the singleton. This will return NULL on failure. - static GpuDataManager* GetInstance(); - - // Requests complete GPUinfo if it has not already been requested - void RequestCompleteGpuInfoIfNeeded(); + static GpuDataManagerImpl* GetInstance(); + + // GpuDataManager implementation: + virtual content::GpuFeatureType GetGpuFeatureType() OVERRIDE; + virtual void SetGpuFeatureType(content::GpuFeatureType feature_type) OVERRIDE; + virtual content::GPUInfo GetGPUInfo() const OVERRIDE; + virtual bool GpuAccessAllowed() OVERRIDE; + virtual void RequestCompleteGpuInfoIfNeeded() OVERRIDE; + virtual bool IsCompleteGPUInfoAvailable() const OVERRIDE; + virtual bool ShouldUseSoftwareRendering() OVERRIDE; + virtual void RegisterSwiftShaderPath(FilePath path) OVERRIDE; + virtual const base::ListValue& GetLogMessages() const OVERRIDE; + virtual void AddObserver(content::GpuDataManagerObserver* observer) OVERRIDE; + virtual void RemoveObserver( + content::GpuDataManagerObserver* observer) OVERRIDE; // Only update if the current GPUInfo is not finalized. void UpdateGpuInfo(const content::GPUInfo& gpu_info); - const content::GPUInfo& gpu_info() const; - - bool complete_gpu_info_available() const { - return complete_gpu_info_available_; - } - - GpuPerformanceStats GetPerformanceStats() const; - void AddLogMessage(Value* msg); - const ListValue& log_messages() const; - - // Can be called on any thread. - content::GpuFeatureType GetGpuFeatureType(); - - // This indicator might change because we could collect more GPU info or - // because the GPU blacklist could be updated. - // If this returns false, any further GPU access, including launching GPU - // process, establish GPU channel, and GPU info collection, should be - // blocked. - // Can be called on any thread. - bool GpuAccessAllowed(); - - // Registers |observer|. The thread on which this is called is the thread - // on which |observer| will be called back with notifications. |observer| - // must not be NULL. - void AddObserver(Observer* observer); - - // Unregisters |observer| from receiving notifications. This must be called - // on the same thread on which AddObserver() was called. |observer| - // must not be NULL. - void RemoveObserver(Observer* observer); - // Inserting disable-feature switches into renderer process command-line // in correspondance to preliminary gpu feature flags. void AppendRendererCommandLine(CommandLine* command_line); @@ -85,30 +53,21 @@ class CONTENT_EXPORT GpuDataManager { // kDisableGLMultisampling. void AppendGpuCommandLine(CommandLine* command_line); - // Gives the new feature flags. This is always called on the UI thread. - void SetGpuFeatureType(content::GpuFeatureType feature_type); - // This gets called when switching GPU might have happened. void HandleGpuSwitch(); - // Returns true if the software rendering should currently be used. - bool software_rendering(); - - // Register a path to the SwiftShader software renderer. - void RegisterSwiftShaderPath(FilePath path); - // Force the current card to be blacklisted (usually due to GPU process // crashes). void BlacklistCard(); private: - typedef ObserverListThreadSafe<GpuDataManager::Observer> + typedef ObserverListThreadSafe<content::GpuDataManagerObserver> GpuDataManagerObserverList; - friend struct DefaultSingletonTraits<GpuDataManager>; + friend struct DefaultSingletonTraits<GpuDataManagerImpl>; - GpuDataManager(); - virtual ~GpuDataManager(); + GpuDataManagerImpl(); + virtual ~GpuDataManagerImpl(); void Initialize(); @@ -154,7 +113,7 @@ class CONTENT_EXPORT GpuDataManager { // Current card force-blacklisted due to GPU crashes. bool card_blacklisted_; - DISALLOW_COPY_AND_ASSIGN(GpuDataManager); + DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl); }; -#endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_H_ +#endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc index 8a981521..e6f5d93 100644 --- a/content/browser/gpu/gpu_process_host.cc +++ b/content/browser/gpu/gpu_process_host.cc @@ -16,7 +16,7 @@ #include "base/string_piece.h" #include "base/threading/thread.h" #include "content/browser/browser_child_process_host_impl.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_process_host_ui_shim.h" #include "content/browser/gpu/gpu_surface_tracker.h" #include "content/browser/renderer_host/render_widget_host.h" @@ -178,7 +178,7 @@ bool GpuProcessHost::HostIsValid(GpuProcessHost* host) { if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU) || host->software_rendering() || - !GpuDataManager::GetInstance()->software_rendering()) { + !GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()) { return true; } @@ -192,7 +192,7 @@ GpuProcessHost* GpuProcessHost::GetForClient( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // Don't grant further access to GPU if it is not allowed. - GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance(); + GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); if (gpu_data_manager != NULL && !gpu_data_manager->GpuAccessAllowed()) return NULL; @@ -303,7 +303,7 @@ GpuProcessHost::~GpuProcessHost() { // The gpu process is too unstable to use. Disable it for current // session. hardware_gpu_enabled_ = false; - GpuDataManager::GetInstance()->BlacklistCard(); + GpuDataManagerImpl::GetInstance()->BlacklistCard(); } } } @@ -422,7 +422,7 @@ void GpuProcessHost::EstablishGpuChannel( TRACE_EVENT0("gpu", "GpuProcessHostUIShim::EstablishGpuChannel"); // If GPU features are already blacklisted, no need to establish the channel. - if (!GpuDataManager::GetInstance()->GpuAccessAllowed()) { + if (!GpuDataManagerImpl::GetInstance()->GpuAccessAllowed()) { EstablishChannelError( callback, IPC::ChannelHandle(), base::kNullProcessHandle, content::GPUInfo()); @@ -483,7 +483,7 @@ void GpuProcessHost::OnChannelEstablished( // Currently if any of the GPU features are blacklisted, we don't establish a // GPU channel. if (!channel_handle.name.empty() && - !GpuDataManager::GetInstance()->GpuAccessAllowed()) { + !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed()) { Send(new GpuMsg_CloseChannel(channel_handle)); EstablishChannelError(callback, IPC::ChannelHandle(), @@ -496,8 +496,8 @@ void GpuProcessHost::OnChannelEstablished( return; } - callback.Run( - channel_handle, gpu_process_, GpuDataManager::GetInstance()->gpu_info()); + callback.Run(channel_handle, gpu_process_, + GpuDataManagerImpl::GetInstance()->GetGPUInfo()); } void GpuProcessHost::OnCommandBufferCreated(const int32 route_id) { @@ -587,7 +587,8 @@ void GpuProcessHost::ForceShutdown() { } bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { - if (!(gpu_enabled_ && GpuDataManager::GetInstance()->software_rendering()) && + if (!(gpu_enabled_ && + GpuDataManagerImpl::GetInstance()->ShouldUseSoftwareRendering()) && !hardware_gpu_enabled_) { SendOutstandingReplies(); return false; @@ -645,7 +646,7 @@ bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { content::GetContentClient()->browser()->AppendExtraCommandLineSwitches( cmd_line, process_->GetData().id); - GpuDataManager::GetInstance()->AppendGpuCommandLine(cmd_line); + GpuDataManagerImpl::GetInstance()->AppendGpuCommandLine(cmd_line); if (cmd_line->HasSwitch(switches::kUseGL)) software_rendering_ = diff --git a/content/browser/gpu/gpu_process_host_ui_shim.cc b/content/browser/gpu/gpu_process_host_ui_shim.cc index 924efe4..ef3f310 100644 --- a/content/browser/gpu/gpu_process_host_ui_shim.cc +++ b/content/browser/gpu/gpu_process_host_ui_shim.cc @@ -11,7 +11,7 @@ #include "base/id_map.h" #include "base/lazy_instance.h" #include "base/process_util.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_surface_tracker.h" #include "content/browser/renderer_host/render_process_host_impl.h" @@ -221,7 +221,7 @@ void GpuProcessHostUIShim::OnLogMessage( dict->SetInteger("level", level); dict->SetString("header", header); dict->SetString("message", message); - GpuDataManager::GetInstance()->AddLogMessage(dict); + GpuDataManagerImpl::GetInstance()->AddLogMessage(dict); } void GpuProcessHostUIShim::OnGraphicsInfoCollected( @@ -230,7 +230,7 @@ void GpuProcessHostUIShim::OnGraphicsInfoCollected( // initializes GL. TRACE_EVENT0("test_gpu", "OnGraphicsInfoCollected"); - GpuDataManager::GetInstance()->UpdateGpuInfo(gpu_info); + GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info); } #if defined(TOOLKIT_USES_GTK) || defined(OS_WIN) diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index cc3fdb8..327a396 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -45,7 +45,7 @@ #include "content/browser/download/mhtml_generation_manager.h" #include "content/browser/file_system/file_system_dispatcher_host.h" #include "content/browser/geolocation/geolocation_dispatcher_host.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_process_host.h" #include "content/browser/in_process_webkit/dom_storage_message_filter.h" #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" @@ -608,7 +608,7 @@ void RenderProcessHostImpl::AppendRendererCommandLine( command_line, GetID()); // Appending disable-gpu-feature switches due to software rendering list. - GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance(); + GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); DCHECK(gpu_data_manager); gpu_data_manager->AppendRendererCommandLine(command_line); } diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index d9a2688..e621d89 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -17,7 +17,7 @@ #include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/download/download_stats.h" #include "content/browser/download/save_package.h" -#include "content/browser/gpu/gpu_data_manager.h" +#include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_process_host.h" #include "content/browser/host_zoom_map_impl.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" @@ -412,7 +412,7 @@ WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh, command_line.HasSwitch(switches::kEnablePerTilePainting); { // Certain GPU features might have been blacklisted. - GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance(); + GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); DCHECK(gpu_data_manager); uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType(); if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) @@ -426,7 +426,7 @@ WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh, // Accelerated video and animation are slower than regular when using a // software 3d rasterizer. - if (gpu_data_manager->software_rendering()) { + if (gpu_data_manager->ShouldUseSoftwareRendering()) { prefs.accelerated_video_enabled = false; prefs.accelerated_animation_enabled = false; } diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 1010d5e..d792939 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -61,6 +61,8 @@ 'public/browser/favicon_status.h', 'public/browser/geolocation_permission_context.h', 'public/browser/global_request_id.h', + 'public/browser/gpu_data_manager.h', + 'public/browser/gpu_data_manager_observer.h', 'public/browser/host_zoom_map.h', 'public/browser/interstitial_page.h', 'public/browser/invalidate_type.h', @@ -317,11 +319,8 @@ 'browser/geolocation/win7_location_provider_win.h', 'browser/gpu/browser_gpu_channel_host_factory.cc', 'browser/gpu/browser_gpu_channel_host_factory.h', - 'browser/gpu/gpu_data_manager.cc', - 'browser/gpu/gpu_data_manager.h', - 'browser/gpu/gpu_performance_stats.cc', - 'browser/gpu/gpu_performance_stats.h', - 'browser/gpu/gpu_performance_stats_win.cc', + 'browser/gpu/gpu_data_manager_impl.cc', + 'browser/gpu/gpu_data_manager_impl.h', 'browser/gpu/gpu_process_host.cc', 'browser/gpu/gpu_process_host.h', 'browser/gpu/gpu_process_host_ui_shim.cc', diff --git a/content/public/browser/gpu_data_manager.h b/content/public/browser/gpu_data_manager.h new file mode 100644 index 0000000..d78d58f --- /dev/null +++ b/content/public/browser/gpu_data_manager.h @@ -0,0 +1,67 @@ +// Copyright (c) 2012 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_PUBLIC_BROWSER_GPU_DATA_MANAGER_H_ +#define CONTENT_PUBLIC_BROWSER_GPU_DATA_MANAGER_H_ +#pragma once + +#include "content/common/content_export.h" +#include "content/public/common/gpu_feature_type.h" + +namespace base { +class ListValue; +} + +namespace content { + +class GpuDataManagerObserver; +struct GPUInfo; + +// This class lives on the UI thread. Only methods that expliclity state that +// they can be called on other threads are thread-safe. +class GpuDataManager { + public: + // Getter for the singleton. + CONTENT_EXPORT static GpuDataManager* GetInstance(); + + // Can be called on any thread. + virtual GpuFeatureType GetGpuFeatureType() = 0; + + // Gives the new feature flags. This is always called on the UI thread. + virtual void SetGpuFeatureType(GpuFeatureType feature_type) = 0; + + virtual GPUInfo GetGPUInfo() const = 0; + + // This indicator might change because we could collect more GPU info or + // because the GPU blacklist could be updated. + // If this returns false, any further GPU access, including launching GPU + // process, establish GPU channel, and GPU info collection, should be + // blocked. + // Can be called on any thread. + virtual bool GpuAccessAllowed() = 0; + + // Requests complete GPUinfo if it has not already been requested + virtual void RequestCompleteGpuInfoIfNeeded() = 0; + + virtual bool IsCompleteGPUInfoAvailable() const = 0; + + // Returns true if the software rendering should currently be used. + virtual bool ShouldUseSoftwareRendering() = 0; + + // Register a path to the SwiftShader software renderer. + virtual void RegisterSwiftShaderPath(FilePath path) = 0; + + virtual const base::ListValue& GetLogMessages() const = 0; + + // Registers/unregister |observer|. + virtual void AddObserver(GpuDataManagerObserver* observer) = 0; + virtual void RemoveObserver(GpuDataManagerObserver* observer) = 0; + + protected: + virtual ~GpuDataManager() {} +}; + +}; // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_GPU_DATA_MANAGER_H_ diff --git a/content/public/browser/gpu_data_manager_observer.h b/content/public/browser/gpu_data_manager_observer.h new file mode 100644 index 0000000..58f851b --- /dev/null +++ b/content/public/browser/gpu_data_manager_observer.h @@ -0,0 +1,26 @@ +// Copyright (c) 2012 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_PUBLIC_BROWSER_GPU_DATA_MANAGER_OBSERVER_H_ +#define CONTENT_PUBLIC_BROWSER_GPU_DATA_MANAGER_OBSERVER_H_ +#pragma once + +#include "content/common/content_export.h" + +namespace content { + +// Observers can register themselves via GpuDataManager::AddObserver, and +// can un-register with GpuDataManager::RemoveObserver. +class GpuDataManagerObserver { + public: + // Called for any observers whenever there is a GPU info update. + virtual void OnGpuInfoUpdate() = 0; + + protected: + virtual ~GpuDataManagerObserver() {} +}; + +}; // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_GPU_DATA_MANAGER_OBSERVER_H_ |