Skip to content

Commit

Permalink
Move gpu blacklist to content side (second try)
Browse files Browse the repository at this point in the history
When it's on the content side, it can be part of the GpuDataManager, so we don't need to make it a Singleton.

Also, this CL did some cleanup related to this moving.

The main reason for this refactoring is because blacklist is tightly coupled with GpuDataManager. Putting them on the this side makes it much easier to test the code, and the design is much better.

BUG=
TEST=bots
Review URL: https://chromiumcodereview.appspot.com/10907106

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155823 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
zmo@chromium.org committed Sep 10, 2012
1 parent ef681d9 commit 04a088f
Show file tree
Hide file tree
Showing 24 changed files with 891 additions and 888 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/chrome_browser_field_trials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/auto_launch_trial.h"
#include "chrome/browser/autocomplete/autocomplete_field_trial.h"
#include "chrome/browser/chrome_gpu_util.h"
#include "chrome/browser/extensions/default_apps_trial.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/gpu_util.h"
#include "chrome/browser/instant/instant_field_trials.h"
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/prerender/prerender_field_trial.h"
Expand Down
25 changes: 3 additions & 22 deletions chrome/browser/chrome_browser_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
#include "chrome/browser/browser_process_impl.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/chrome_browser_main_extra_parts.h"
#include "chrome/browser/chrome_gpu_util.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/extension_protocols.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/startup_helper.h"
#include "chrome/browser/first_run/upgrade_util.h"
#include "chrome/browser/google/google_search_counter.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/gpu_blacklist.h"
#include "chrome/browser/jankometer.h"
#include "chrome/browser/language_usage_metrics.h"
#include "chrome/browser/managed_mode.h"
Expand Down Expand Up @@ -396,25 +396,6 @@ Profile* CreateProfile(const content::MainFunctionParams& parameters,
return NULL;
}

// Load GPU Blacklist, collect preliminary gpu info, and compute preliminary
// gpu feature flags.
void InitializeGpuDataManager(const CommandLine& parsed_command_line) {
content::GpuDataManager::GetInstance()->InitializeGpuInfo();
if (parsed_command_line.HasSwitch(switches::kSkipGpuDataLoading) ||
parsed_command_line.HasSwitch(switches::kIgnoreGpuBlacklist)) {
return;
}

const base::StringPiece gpu_blacklist_json(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_GPU_BLACKLIST, ui::SCALE_FACTOR_NONE));
GpuBlacklist* gpu_blacklist = GpuBlacklist::GetInstance();
bool succeed = gpu_blacklist->LoadGpuBlacklist(
gpu_blacklist_json.as_string(), GpuBlacklist::kCurrentOsOnly);
DCHECK(succeed);
gpu_blacklist->UpdateGpuDataManager();
}

#if defined(OS_MACOSX)
OSStatus KeychainCallback(SecKeychainEvent keychain_event,
SecKeychainCallbackInfo* info, void* context) {
Expand Down Expand Up @@ -1333,8 +1314,8 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
CloudPrintProxyServiceFactory::GetForProfile(profile_);
#endif

// Load GPU Blacklist.
InitializeGpuDataManager(parsed_command_line());
// Load GPU Blacklist; load preliminary GPU info.
gpu_util::InitializeGpuDataManager(parsed_command_line());

// Start watching all browser threads for responsiveness.
ThreadWatcherList::StartWatchingAll(parsed_command_line());
Expand Down
123 changes: 123 additions & 0 deletions chrome/browser/chrome_gpu_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// 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.

#include "chrome/browser/chrome_gpu_util.h"

#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/version.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#endif
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "grit/browser_resources.h"
#include "ui/base/resource/resource_bundle.h"

using content::GpuDataManager;

namespace gpu_util {

void InitializeCompositingFieldTrial() {
// Enable the field trial only on desktop OS's.
#if !(defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX))
return;
#endif
#if defined(OS_WIN)
// Don't run the trial on Windows XP.
if (base::win::GetVersion() < base::win::VERSION_VISTA)
return;
#endif

// The performance of accelerated compositing is too low with software
// rendering.
if (content::GpuDataManager::GetInstance()->ShouldUseSoftwareRendering())
return;

// Don't activate the field trial if force-compositing-mode has been
// explicitly disabled from the command line.
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableForceCompositingMode))
return;

const base::FieldTrial::Probability kDivisor = 3;
scoped_refptr<base::FieldTrial> trial(
base::FieldTrialList::FactoryGetFieldTrial(
content::kGpuCompositingFieldTrialName, kDivisor,
"disable", 2012, 12, 31, NULL));

// Produce the same result on every run of this client.
trial->UseOneTimeRandomization();

base::FieldTrial::Probability force_compositing_mode_probability = 0;
base::FieldTrial::Probability threaded_compositing_probability = 0;

chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
channel == chrome::VersionInfo::CHANNEL_BETA) {
// Stable and Beta channels: Non-threaded force-compositing-mode on by
// default (mac and windows only).
#if defined(OS_WIN) || defined(OS_MACOSX)
force_compositing_mode_probability = 3;
#endif
} else if (channel == chrome::VersionInfo::CHANNEL_DEV ||
channel == chrome::VersionInfo::CHANNEL_CANARY) {
// Dev and Canary channels: force-compositing-mode and
// threaded-compositing on with 1/3 probability each.
force_compositing_mode_probability = 1;

#if defined(OS_MACOSX) || defined(OS_LINUX)
// Threaded compositing mode isn't feature complete on mac or linux yet:
// http://crbug.com/133602 for mac
// http://crbug.com/140866 for linux
threaded_compositing_probability = 0;
#else
if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableThreadedCompositing))
threaded_compositing_probability = 1;
#endif
}

int force_compositing_group = trial->AppendGroup(
content::kGpuCompositingFieldTrialForceCompositingEnabledName,
force_compositing_mode_probability);
int thread_group = trial->AppendGroup(
content::kGpuCompositingFieldTrialThreadEnabledName,
threaded_compositing_probability);

bool force_compositing = (trial->group() == force_compositing_group);
bool thread = (trial->group() == thread_group);
UMA_HISTOGRAM_BOOLEAN("GPU.InForceCompositingModeFieldTrial",
force_compositing);
UMA_HISTOGRAM_BOOLEAN("GPU.InCompositorThreadFieldTrial", thread);
}

// Load GPU Blacklist, collect preliminary gpu info, and compute preliminary
// gpu feature flags.
void InitializeGpuDataManager(const CommandLine& command_line) {
if (command_line.HasSwitch(switches::kSkipGpuDataLoading))
return;

std::string chrome_version_string = "0";
std::string gpu_blacklist_json_string;
if (!command_line.HasSwitch(switches::kIgnoreGpuBlacklist)) {
chrome::VersionInfo chrome_version_info;
if (chrome_version_info.is_valid())
chrome_version_string = chrome_version_info.Version();

const base::StringPiece gpu_blacklist_json(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_GPU_BLACKLIST, ui::SCALE_FACTOR_NONE));
gpu_blacklist_json_string = gpu_blacklist_json.as_string();
}
content::GpuDataManager::GetInstance()->Initialize(
chrome_version_string, gpu_blacklist_json_string);
}

} // namespace gpu_util;

22 changes: 22 additions & 0 deletions chrome/browser/chrome_gpu_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 CHROME_BROWSER_CHROME_GPU_UTIL_H_
#define CHROME_BROWSER_CHROME_GPU_UTIL_H_

class CommandLine;

namespace gpu_util {

// Sets up force-compositing-mode and threaded compositing field trials.
void InitializeCompositingFieldTrial();

// Load GPU Blacklist, collect preliminary gpu info, and compute preliminary
// gpu feature flags.
void InitializeGpuDataManager(const CommandLine& command_line);

} // namespace gpu_util

#endif // CHROME_BROWSER_CHROME_GPU_UTIL_H_

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
#include "chrome/browser/extensions/webstore_installer.h"
#include "chrome/browser/gpu_blacklist.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_notification_types.h"
Expand Down Expand Up @@ -436,11 +435,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) {
" }\n"
" ]\n"
"}";
GpuBlacklist* blacklist = GpuBlacklist::GetInstance();

ASSERT_TRUE(blacklist->LoadGpuBlacklist(
json_blacklist, GpuBlacklist::kAllOs));
blacklist->UpdateGpuDataManager();
content::GpuDataManager::GetInstance()->Initialize("0", json_blacklist);
GpuFeatureType type =
content::GpuDataManager::GetInstance()->GetBlacklistedFeatures();
EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
Expand Down
Loading

0 comments on commit 04a088f

Please sign in to comment.