gpu_data_manager_impl_private.cc revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
1a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// found in the LICENSE file.
4a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
5a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/browser/gpu/gpu_data_manager_impl_private.h"
6a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
7a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/bind.h"
8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/bind_helpers.h"
9a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/command_line.h"
10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/debug/trace_event.h"
11a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/metrics/field_trial.h"
12a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/metrics/histogram.h"
133240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#include "base/metrics/sparse_histogram.h"
14a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/strings/string_number_conversions.h"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/stringprintf.h"
16a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/sys_info.h"
17a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/version.h"
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "cc/base/switches.h"
19a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/browser/gpu/gpu_process_host.h"
20a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/common/gpu/gpu_messages.h"
21a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/public/browser/browser_thread.h"
22a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/public/browser/gpu_data_manager_observer.h"
23a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/public/common/content_client.h"
24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/public/common/content_constants.h"
25a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/public/common/content_switches.h"
26a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "gpu/command_buffer/service/gpu_switches.h"
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "gpu/config/gpu_control_list_jsons.h"
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "gpu/config/gpu_driver_bug_workaround_type.h"
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "gpu/config/gpu_feature_type.h"
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "gpu/config/gpu_info_collector.h"
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "gpu/config/gpu_util.h"
32a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "ui/base/ui_base_switches.h"
33a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "ui/gl/gl_implementation.h"
34a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "ui/gl/gl_switches.h"
35a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "ui/gl/gpu_switching_manager.h"
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "webkit/common/webpreferences.h"
37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_MACOSX)
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <ApplicationServices/ApplicationServices.h>
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // OS_MACOSX
41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if defined(OS_WIN)
42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/win/windows_version.h"
4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // OS_WIN
4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_ANDROID)
45424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/android/build_info.h"
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/android/device_display_info.h"
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // OS_ANDROID
48a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace content {
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
51a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace {
52a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)enum GpuFeatureStatus {
5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    kGpuFeatureEnabled = 0,
5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    kGpuFeatureBlacklisted = 1,
5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    kGpuFeatureDisabled = 2,  // disabled by user but not blacklisted
5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    kGpuFeatureNumStatus
5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_WIN)
6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)enum WinSubVersion {
6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  kWinOthers = 0,
6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  kWinXP,
6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  kWinVista,
6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  kWin7,
677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  kWin8,
6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  kNumWinSubVersions
6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)int GetGpuBlacklistHistogramValueWin(GpuFeatureStatus status) {
7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static WinSubVersion sub_version = kNumWinSubVersions;
7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (sub_version == kNumWinSubVersions) {
7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    sub_version = kWinOthers;
7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    std::string version_str = base::SysInfo::OperatingSystemVersion();
7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    size_t pos = version_str.find_first_not_of("0123456789.");
7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if (pos != std::string::npos)
7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      version_str = version_str.substr(0, pos);
7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    Version os_version(version_str);
8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if (os_version.IsValid() && os_version.components().size() >= 2) {
8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      const std::vector<uint16>& version_numbers = os_version.components();
8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if (version_numbers[0] == 5)
8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        sub_version = kWinXP;
8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      else if (version_numbers[0] == 6 && version_numbers[1] == 0)
8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        sub_version = kWinVista;
8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      else if (version_numbers[0] == 6 && version_numbers[1] == 1)
8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        sub_version = kWin7;
887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      else if (version_numbers[0] == 6 && version_numbers[1] == 2)
897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch        sub_version = kWin8;
9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    }
9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  int entry_index = static_cast<int>(sub_version) * kGpuFeatureNumStatus;
9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  switch (status) {
9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    case kGpuFeatureEnabled:
9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      break;
9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    case kGpuFeatureBlacklisted:
9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      entry_index++;
9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      break;
9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    case kGpuFeatureDisabled:
10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      entry_index += 2;
10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      break;
10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return entry_index;
10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // OS_WIN
10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1073240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch// Send UMA histograms about the enabled features and GPU properties.
1083240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdochvoid UpdateStats(const gpu::GPUInfo& gpu_info,
1093240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch                 const gpu::GpuBlacklist* blacklist,
11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                 const std::set<int>& blacklisted_features) {
11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  uint32 max_entry_id = blacklist->max_entry_id();
11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (max_entry_id == 0) {
11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    // GPU Blacklist was not loaded.  No need to go further.
11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return;
11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool disabled = false;
1197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Use entry 0 to capture the total number of times that data
1217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // was recorded in this histogram in order to have a convenient
1227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // denominator to compute blacklist percentages for the rest of the
1237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // entries.
1247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry",
1257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      0, max_entry_id + 1);
1267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (blacklisted_features.size() != 0) {
12890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    std::vector<uint32> flag_entries;
12990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    blacklist->GetDecisionEntries(&flag_entries, disabled);
13090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    DCHECK_GT(flag_entries.size(), 0u);
13190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    for (size_t i = 0; i < flag_entries.size(); ++i) {
13290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry",
13390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)          flag_entries[i], max_entry_id + 1);
13490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    }
13590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
13690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
13790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // This counts how many users are affected by a disabled entry - this allows
13890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // us to understand the impact of an entry before enable it.
13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::vector<uint32> flag_disabled_entries;
14090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  disabled = true;
14190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  blacklist->GetDecisionEntries(&flag_disabled_entries, disabled);
14290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  for (size_t i = 0; i < flag_disabled_entries.size(); ++i) {
14390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerDisabledEntry",
14490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        flag_disabled_entries[i], max_entry_id + 1);
14590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
14690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
14790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const gpu::GpuFeatureType kGpuFeatures[] = {
14890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS,
14990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING,
1507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      gpu::GPU_FEATURE_TYPE_WEBGL,
1517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      gpu::GPU_FEATURE_TYPE_TEXTURE_SHARING
15290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  };
15390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const std::string kGpuBlacklistFeatureHistogramNames[] = {
15490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      "GPU.BlacklistFeatureTestResults.Accelerated2dCanvas",
15590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      "GPU.BlacklistFeatureTestResults.AcceleratedCompositing",
1567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      "GPU.BlacklistFeatureTestResults.Webgl",
1577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      "GPU.BlacklistFeatureTestResults.TextureSharing"
15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  };
15990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const bool kGpuFeatureUserFlags[] = {
16090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      command_line.HasSwitch(switches::kDisableAccelerated2dCanvas),
16190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      command_line.HasSwitch(switches::kDisableAcceleratedCompositing),
1627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      command_line.HasSwitch(switches::kDisableExperimentalWebGL),
1637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      command_line.HasSwitch(switches::kDisableImageTransportSurface)
16490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  };
16590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_WIN)
16690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const std::string kGpuBlacklistFeatureHistogramNamesWin[] = {
16790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      "GPU.BlacklistFeatureTestResultsWindows.Accelerated2dCanvas",
16890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      "GPU.BlacklistFeatureTestResultsWindows.AcceleratedCompositing",
1697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      "GPU.BlacklistFeatureTestResultsWindows.Webgl",
1707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      "GPU.BlacklistFeatureTestResultsWindows.TextureSharing"
17190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  };
17290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif
17390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const size_t kNumFeatures =
17490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      sizeof(kGpuFeatures) / sizeof(gpu::GpuFeatureType);
17590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  for (size_t i = 0; i < kNumFeatures; ++i) {
17690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    // We can't use UMA_HISTOGRAM_ENUMERATION here because the same name is
17790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    // expected if the macro is used within a loop.
17890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    GpuFeatureStatus value = kGpuFeatureEnabled;
17990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if (blacklisted_features.count(kGpuFeatures[i]))
18090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      value = kGpuFeatureBlacklisted;
18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    else if (kGpuFeatureUserFlags[i])
18290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      value = kGpuFeatureDisabled;
18390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet(
18490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        kGpuBlacklistFeatureHistogramNames[i],
18590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        1, kGpuFeatureNumStatus, kGpuFeatureNumStatus + 1,
18690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::HistogramBase::kUmaTargetedHistogramFlag);
18790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    histogram_pointer->Add(value);
18890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_WIN)
18990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    histogram_pointer = base::LinearHistogram::FactoryGet(
19090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        kGpuBlacklistFeatureHistogramNamesWin[i],
19190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        1, kNumWinSubVersions * kGpuFeatureNumStatus,
19290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        kNumWinSubVersions * kGpuFeatureNumStatus + 1,
19390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::HistogramBase::kUmaTargetedHistogramFlag);
19490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    histogram_pointer->Add(GetGpuBlacklistHistogramValueWin(value));
19590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif
19690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
1973240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch
1983240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  UMA_HISTOGRAM_SPARSE_SLOWLY("GPU.GLResetNotificationStrategy",
1993240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch      gpu_info.gl_reset_notification_strategy);
20090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
20190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
202a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Strip out the non-digital info; if after that, we get an empty string,
203a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// return "0".
204a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)std::string ProcessVersionString(const std::string& raw_string) {
205a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const std::string valid_set = "0123456789.";
206a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  size_t start_pos = raw_string.find_first_of(valid_set);
207a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (start_pos == std::string::npos)
208a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return "0";
209a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  size_t end_pos = raw_string.find_first_not_of(raw_string, start_pos);
210a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string version_string = raw_string.substr(
211a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      start_pos, end_pos - start_pos);
212a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (version_string.empty())
213a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return "0";
214a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return version_string;
215a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
216a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
217a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Combine the integers into a string, seperated by ','.
218a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)std::string IntSetToString(const std::set<int>& list) {
219a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string rt;
220a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  for (std::set<int>::const_iterator it = list.begin();
221a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)       it != list.end(); ++it) {
222a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (!rt.empty())
223a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      rt += ",";
224a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    rt += base::IntToString(*it);
225a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
226a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return rt;
227a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
228a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
229a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if defined(OS_MACOSX)
230a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void DisplayReconfigCallback(CGDirectDisplayID display,
231a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                             CGDisplayChangeSummaryFlags flags,
232a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                             void* gpu_data_manager) {
233424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  if (flags == kCGDisplayBeginConfigurationFlag)
234868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return; // This call contains no information about the display change
235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  GpuDataManagerImpl* manager =
237868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      reinterpret_cast<GpuDataManagerImpl*>(gpu_data_manager);
238868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DCHECK(manager);
239868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
240868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  uint32_t displayCount;
241868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  CGGetActiveDisplayList(0, NULL, &displayCount);
242868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
243868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool fireGpuSwitch = flags & kCGDisplayAddFlag;
244868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
245868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (displayCount != manager->GetDisplayCount()) {
246868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    manager->SetDisplayCount(displayCount);
247868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    fireGpuSwitch = true;
248a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
249868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
250868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (fireGpuSwitch)
251868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    manager->HandleGpuSwitch();
252a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
253a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif  // OS_MACOSX
254a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
25590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_ANDROID)
25690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void ApplyAndroidWorkarounds(const gpu::GPUInfo& gpu_info,
25790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                             CommandLine* command_line) {
25890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::string vendor(StringToLowerASCII(gpu_info.gl_vendor));
25990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::string renderer(StringToLowerASCII(gpu_info.gl_renderer));
26090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool is_img =
26190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu_info.gl_vendor.find("Imagination") != std::string::npos;
26290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool is_arm =
26390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu_info.gl_vendor.find("ARM") != std::string::npos;
26490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool is_qualcomm =
26590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu_info.gl_vendor.find("Qualcomm") != std::string::npos;
26690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool is_broadcom =
26790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu_info.gl_vendor.find("Broadcom") != std::string::npos;
26890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool is_mali_t604 = is_arm &&
26990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu_info.gl_renderer.find("Mali-T604") != std::string::npos;
270a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  bool is_nvidia =
271a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      gpu_info.gl_vendor.find("NVIDIA") != std::string::npos;
27290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
27390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool is_vivante =
27490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu_info.gl_extensions.find("GL_VIV_shader_binary") !=
27590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      std::string::npos;
27690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
27790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool is_nexus7 =
27890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu_info.machine_model.find("Nexus 7") != std::string::npos;
27990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool is_nexus10 =
28090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu_info.machine_model.find("Nexus 10") != std::string::npos;
28190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
282424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  int sdk_int = base::android::BuildInfo::GetInstance()->sdk_int();
283424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
28490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // IMG: avoid context switching perf problems, crashes with share groups
28590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Mali-T604: http://crbug.com/154715
28690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // QualComm, NVIDIA: Crashes with share groups
287424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  if (is_vivante || is_img || is_mali_t604 ||
288424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      ((is_nvidia || is_qualcomm) && sdk_int < 18) || is_broadcom) {
28990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    command_line->AppendSwitch(switches::kEnableVirtualGLContexts);
290424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  }
29190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
29290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  gfx::DeviceDisplayInfo info;
29390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  int default_tile_size = 256;
29490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
29590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // For very high resolution displays (eg. Nexus 10), set the default
29690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // tile size to be 512. This should be removed in favour of a generic
29790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // hueristic that works across all platforms and devices, once that
29890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // exists: http://crbug.com/159524. This switches to 512 for screens
29990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // containing 40 or more 256x256 tiles, such that 1080p devices do
30090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // not use 512x512 tiles (eg. 1920x1280 requires 37.5 tiles)
30190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  int numTiles = (info.GetDisplayWidth() *
30290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                  info.GetDisplayHeight()) / (256 * 256);
30390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (numTiles >= 40)
30490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    default_tile_size = 512;
30590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
30690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // IMG: Fast async texture uploads only work with non-power-of-two,
30790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // but still multiple-of-eight sizes.
30890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // http://crbug.com/168099
30990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (is_img)
31090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    default_tile_size -= 8;
31190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // If we are using the MapImage API double the tile size to reduce
3137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // the number of zero-copy buffers being used.
314424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  if (command_line->HasSwitch(cc::switches::kEnableMapImage))
3157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    default_tile_size *= 2;
3167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
31790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Set the command line if it isn't already set and we changed
31890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // the default tile size.
31990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (default_tile_size != 256 &&
32090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      !command_line->HasSwitch(switches::kDefaultTileWidth) &&
32190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      !command_line->HasSwitch(switches::kDefaultTileHeight)) {
32290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    std::stringstream size;
32390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    size << default_tile_size;
32490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    command_line->AppendSwitchASCII(
32590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        switches::kDefaultTileWidth, size.str());
32690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    command_line->AppendSwitchASCII(
32790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        switches::kDefaultTileHeight, size.str());
32890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
32990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
33090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Increase the resolution of low resolution tiles for Nexus tablets.
33190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if ((is_nexus7 || is_nexus10) &&
33290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      !command_line->HasSwitch(
33390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)          cc::switches::kLowResolutionContentsScaleFactor)) {
33490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    command_line->AppendSwitchASCII(
33590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        cc::switches::kLowResolutionContentsScaleFactor, "0.25");
33690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
33790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
33890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // OS_ANDROID
33990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
340a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Block all domains' use of 3D APIs for this many milliseconds if
341a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// approaching a threshold where system stability might be compromised.
342a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)const int64 kBlockAllDomainsMs = 10000;
343a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)const int kNumResetsWithinDuration = 1;
344a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
345a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Enums for UMA histograms.
346a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)enum BlockStatusHistogram {
347a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  BLOCK_STATUS_NOT_BLOCKED,
348a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED,
349a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  BLOCK_STATUS_ALL_DOMAINS_BLOCKED,
350a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  BLOCK_STATUS_MAX
351a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)};
352a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
353a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}  // namespace anonymous
354a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
355a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::InitializeForTesting(
356a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const std::string& gpu_blacklist_json,
35790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    const gpu::GPUInfo& gpu_info) {
358a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // This function is for testing only, so disable histograms.
359a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  update_histograms_ = false;
360a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
361a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  InitializeImpl(gpu_blacklist_json, std::string(), std::string(), gpu_info);
362a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
363a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
364a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)bool GpuDataManagerImplPrivate::IsFeatureBlacklisted(int feature) const {
3653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#if defined(OS_CHROMEOS)
3663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (feature == gpu::GPU_FEATURE_TYPE_PANEL_FITTING &&
3673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      CommandLine::ForCurrentProcess()->HasSwitch(
3683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)          switches::kDisablePanelFitting)) {
3693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    return true;
3703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
3713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#endif  // OS_CHROMEOS
372a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (use_swiftshader_) {
373a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // Skia's software rendering is probably more efficient than going through
374a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // software emulation of the GPU, so use that.
37590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if (feature == gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
376a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      return true;
377a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return false;
378a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
379a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
380a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return (blacklisted_features_.count(feature) == 1);
381a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
382a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
383424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)bool GpuDataManagerImplPrivate::IsDriverBugWorkaroundActive(int feature) const {
384424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  return (gpu_driver_bugs_.count(feature) == 1);
385424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
386424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
387a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)size_t GpuDataManagerImplPrivate::GetBlacklistedFeatureCount() const {
388a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (use_swiftshader_)
389a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return 1;
390a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return blacklisted_features_.size();
391a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
392a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
393868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void GpuDataManagerImplPrivate::SetDisplayCount(unsigned int display_count) {
394868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  display_count_ = display_count;
395868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
396868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
397868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)unsigned int GpuDataManagerImplPrivate::GetDisplayCount() const {
398868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return display_count_;
399868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
400868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
40190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)gpu::GPUInfo GpuDataManagerImplPrivate::GetGPUInfo() const {
402a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return gpu_info_;
403a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
404a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
405a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::GetGpuProcessHandles(
406a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const GpuDataManager::GetGpuProcessHandlesCallback& callback) const {
407a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GpuProcessHost::GetProcessHandles(callback);
408a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
409a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
410a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)bool GpuDataManagerImplPrivate::GpuAccessAllowed(
411a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    std::string* reason) const {
412a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (use_swiftshader_)
413a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return true;
414a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
415eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!gpu_process_accessible_) {
416a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (reason) {
417a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      *reason = "GPU process launch failed.";
418a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    }
419a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return false;
420a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
421a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
422a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (card_blacklisted_) {
423a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (reason) {
424a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      *reason = "GPU access is disabled ";
425a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      CommandLine* command_line = CommandLine::ForCurrentProcess();
426a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      if (command_line->HasSwitch(switches::kDisableGpu))
427a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        *reason += "through commandline switch --disable-gpu.";
428a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      else
429a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        *reason += "in chrome://settings.";
430a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    }
431a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return false;
432a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
433a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
434a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // We only need to block GPU process if more features are disallowed other
435a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // than those in the preliminary gpu feature flags because the latter work
436a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // through renderer commandline switches.
437a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::set<int> features = preliminary_blacklisted_features_;
43890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  gpu::MergeFeatureSets(&features, blacklisted_features_);
439a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (features.size() > preliminary_blacklisted_features_.size()) {
440a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (reason) {
441a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      *reason = "Features are disabled upon full but not preliminary GPU info.";
442a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    }
443a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return false;
444a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
445a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
44690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (blacklisted_features_.size() == gpu::NUMBER_OF_GPU_FEATURE_TYPES) {
447a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // On Linux, we use cached GL strings to make blacklist decsions at browser
448a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // startup time. We need to launch the GPU process to validate these
449a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // strings even if all features are blacklisted. If all GPU features are
450a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // disabled, the GPU process will only initialize GL bindings, create a GL
451a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // context, and collect full GPU info.
452a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if !defined(OS_LINUX)
453a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (reason) {
454a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      *reason = "All GPU features are blacklisted.";
455a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    }
456a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return false;
457a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif
458a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
459a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
460a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return true;
461a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
462a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
463a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::RequestCompleteGpuInfoIfNeeded() {
464a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (complete_gpu_info_already_requested_ || gpu_info_.finalized)
465a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return;
466a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  complete_gpu_info_already_requested_ = true;
467a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
468a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GpuProcessHost::SendOnIO(
469a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if defined(OS_WIN)
470a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      GpuProcessHost::GPU_PROCESS_KIND_UNSANDBOXED,
471a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#else
472a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
473a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif
474a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      CAUSE_FOR_GPU_LAUNCH_GPUDATAMANAGER_REQUESTCOMPLETEGPUINFOIFNEEDED,
475a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      new GpuMsg_CollectGraphicsInfo());
476a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
477a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
478a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)bool GpuDataManagerImplPrivate::IsCompleteGpuInfoAvailable() const {
479a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return gpu_info_.finalized;
480a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
481a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
482a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::RequestVideoMemoryUsageStatsUpdate() const {
483a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GpuProcessHost::SendOnIO(
484a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
485a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH,
486a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      new GpuMsg_GetVideoMemoryUsageStats());
487a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
488a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
489a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)bool GpuDataManagerImplPrivate::ShouldUseSwiftShader() const {
490a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return use_swiftshader_;
491a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
492a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
493a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::RegisterSwiftShaderPath(
494a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const base::FilePath& path) {
495a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  swiftshader_path_ = path;
496a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EnableSwiftShaderIfNecessary();
497a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
498a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
499a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::AddObserver(GpuDataManagerObserver* observer) {
500a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GpuDataManagerImpl::UnlockedSession session(owner_);
501a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  observer_list_->AddObserver(observer);
502a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
503a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
504a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::RemoveObserver(
505a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    GpuDataManagerObserver* observer) {
506a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GpuDataManagerImpl::UnlockedSession session(owner_);
507a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  observer_list_->RemoveObserver(observer);
508a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
509a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
510a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::UnblockDomainFrom3DAPIs(const GURL& url) {
511a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // This method must do two things:
512a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //
513a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //  1. If the specific domain is blocked, then unblock it.
514a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //
515a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //  2. Reset our notion of how many GPU resets have occurred recently.
516a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //     This is necessary even if the specific domain was blocked.
517a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //     Otherwise, if we call Are3DAPIsBlocked with the same domain right
518a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //     after unblocking it, it will probably still be blocked because of
519a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //     the recent GPU reset caused by that domain.
520a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //
521a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // These policies could be refined, but at a certain point the behavior
522a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // will become difficult to explain.
523a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string domain = GetDomainFromURL(url);
524a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
525a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  blocked_domains_.erase(domain);
526a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  timestamps_of_gpu_resets_.clear();
527a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
528a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
529a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::DisableGpuWatchdog() {
530a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GpuProcessHost::SendOnIO(
531a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
532a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH,
533a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      new GpuMsg_DisableWatchdog);
534a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
535a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
536a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::SetGLStrings(const std::string& gl_vendor,
537a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                             const std::string& gl_renderer,
538a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                             const std::string& gl_version) {
539a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (gl_vendor.empty() && gl_renderer.empty() && gl_version.empty())
540a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return;
541a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
542a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // If GPUInfo already got GL strings, do nothing.  This is for the rare
543a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // situation where GPU process collected GL strings before this call.
544a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!gpu_info_.gl_vendor.empty() ||
545a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      !gpu_info_.gl_renderer.empty() ||
546a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      !gpu_info_.gl_version_string.empty())
547a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return;
548a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
54990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  gpu::GPUInfo gpu_info = gpu_info_;
550a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
551a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  gpu_info.gl_vendor = gl_vendor;
552a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  gpu_info.gl_renderer = gl_renderer;
553a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  gpu_info.gl_version_string = gl_version;
554a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
55590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  gpu::CollectDriverInfoGL(&gpu_info);
556a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
557a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  UpdateGpuInfo(gpu_info);
558a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  UpdateGpuSwitchingManager(gpu_info);
559a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  UpdatePreliminaryBlacklistedFeatures();
560a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
561a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
562a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::GetGLStrings(std::string* gl_vendor,
563a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                             std::string* gl_renderer,
564a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                             std::string* gl_version) {
565a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DCHECK(gl_vendor && gl_renderer && gl_version);
566a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
567a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  *gl_vendor = gpu_info_.gl_vendor;
568a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  *gl_renderer = gpu_info_.gl_renderer;
569a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  *gl_version = gpu_info_.gl_version_string;
570a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
571a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
572a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::Initialize() {
573a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  TRACE_EVENT0("startup", "GpuDataManagerImpl::Initialize");
574a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  CommandLine* command_line = CommandLine::ForCurrentProcess();
5757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (command_line->HasSwitch(switches::kSkipGpuDataLoading) &&
5767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      !command_line->HasSwitch(switches::kUseGpuInTests))
577a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return;
578a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
57990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  gpu::GPUInfo gpu_info;
580a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  {
581a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    TRACE_EVENT0("startup",
582a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      "GpuDataManagerImpl::Initialize:CollectBasicGraphicsInfo");
58390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    gpu::CollectBasicGraphicsInfo(&gpu_info);
584a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
585a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if defined(ARCH_CPU_X86_FAMILY)
586a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!gpu_info.gpu.vendor_id || !gpu_info.gpu.device_id)
587a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    gpu_info.finalized = true;
588a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif
589a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
590a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string gpu_blacklist_string;
591a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string gpu_switching_list_string;
592a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string gpu_driver_bug_list_string;
5937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!command_line->HasSwitch(switches::kIgnoreGpuBlacklist) &&
5947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      !command_line->HasSwitch(switches::kUseGpuInTests)) {
59590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    gpu_blacklist_string = gpu::kSoftwareRenderingListJson;
59690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    gpu_switching_list_string = gpu::kGpuSwitchingListJson;
597a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
598a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds)) {
59990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    gpu_driver_bug_list_string = gpu::kGpuDriverBugListJson;
600a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
601a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  InitializeImpl(gpu_blacklist_string,
602a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                 gpu_switching_list_string,
603a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                 gpu_driver_bug_list_string,
604a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                 gpu_info);
605a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
606a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
60790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void GpuDataManagerImplPrivate::UpdateGpuInfo(const gpu::GPUInfo& gpu_info) {
608a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // No further update of gpu_info if falling back to SwiftShader.
609a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (use_swiftshader_)
610a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return;
611a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
61290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  gpu::MergeGPUInfo(&gpu_info_, gpu_info);
613a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  complete_gpu_info_already_requested_ =
614a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      complete_gpu_info_already_requested_ || gpu_info_.finalized;
615a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
616a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GetContentClient()->SetGpuInfo(gpu_info_);
617a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
618a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (gpu_blacklist_) {
619a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    std::set<int> features = gpu_blacklist_->MakeDecision(
62090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        gpu::GpuControlList::kOsAny, std::string(), gpu_info_);
621a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (update_histograms_)
6223240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch      UpdateStats(gpu_info_, gpu_blacklist_.get(), features);
623a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
624a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    UpdateBlacklistedFeatures(features);
625a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
626a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (gpu_switching_list_) {
627a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    std::set<int> option = gpu_switching_list_->MakeDecision(
62890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        gpu::GpuControlList::kOsAny, std::string(), gpu_info_);
629a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (option.size() == 1) {
630a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      // Blacklist decision should not overwrite commandline switch from users.
631a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      CommandLine* command_line = CommandLine::ForCurrentProcess();
63290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if (!command_line->HasSwitch(switches::kGpuSwitching)) {
63390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        gpu_switching_ = static_cast<gpu::GpuSwitchingOption>(
63490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            *(option.begin()));
63590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      }
636a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    }
637a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
63890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (gpu_driver_bug_list_) {
639a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    gpu_driver_bugs_ = gpu_driver_bug_list_->MakeDecision(
64090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        gpu::GpuControlList::kOsAny, std::string(), gpu_info_);
64190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
642a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
643a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // We have to update GpuFeatureType before notify all the observers.
644a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  NotifyGpuInfoUpdate();
645a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
646a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
647a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::UpdateVideoMemoryUsageStats(
648a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const GPUVideoMemoryUsageStats& video_memory_usage_stats) {
649a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GpuDataManagerImpl::UnlockedSession session(owner_);
650a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  observer_list_->Notify(&GpuDataManagerObserver::OnVideoMemoryUsageStatsUpdate,
651a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                         video_memory_usage_stats);
652a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
653a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
654a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::AppendRendererCommandLine(
655a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    CommandLine* command_line) const {
656a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DCHECK(command_line);
657a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
65890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)) {
659a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (!command_line->HasSwitch(switches::kDisableExperimentalWebGL))
660a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      command_line->AppendSwitch(switches::kDisableExperimentalWebGL);
661a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (!command_line->HasSwitch(switches::kDisablePepper3d))
662a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      command_line->AppendSwitch(switches::kDisablePepper3d);
663a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
66490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_MULTISAMPLING) &&
665a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      !command_line->HasSwitch(switches::kDisableGLMultisampling))
666a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitch(switches::kDisableGLMultisampling);
66790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) &&
668a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      !command_line->HasSwitch(switches::kDisableAcceleratedCompositing))
669a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitch(switches::kDisableAcceleratedCompositing);
67090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) &&
671a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      !command_line->HasSwitch(switches::kDisableAccelerated2dCanvas))
672a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas);
67390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE) &&
674a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      !command_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
675a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitch(switches::kDisableAcceleratedVideoDecode);
676a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
677a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (use_software_compositor_ &&
678a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      !command_line->HasSwitch(switches::kEnableSoftwareCompositing))
679a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    command_line->AppendSwitch(switches::kEnableSoftwareCompositing);
680a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
681a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#if defined(USE_AURA)
682a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (!CanUseGpuBrowserCompositor()) {
683a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    command_line->AppendSwitch(switches::kDisableGpuCompositing);
684a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    command_line->AppendSwitch(switches::kDisablePepper3d);
685a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
686a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#endif
687a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
688a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
689a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::AppendGpuCommandLine(
690a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    CommandLine* command_line) const {
691a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DCHECK(command_line);
692a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
6937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool reduce_sandbox = false;
6947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
695a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string use_gl =
696a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
697a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  base::FilePath swiftshader_path =
698a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      CommandLine::ForCurrentProcess()->GetSwitchValuePath(
699a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)          switches::kSwiftShaderPath);
70090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_MULTISAMPLING) &&
7017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      !command_line->HasSwitch(switches::kDisableGLMultisampling)) {
702a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitch(switches::kDisableGLMultisampling);
7037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
7047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_TEXTURE_SHARING)) {
705a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitch(switches::kDisableImageTransportSurface);
7067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    reduce_sandbox = true;
7077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
7087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (gpu_driver_bugs_.find(gpu::DISABLE_D3D11) != gpu_driver_bugs_.end())
7097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    command_line->AppendSwitch(switches::kDisableD3D11);
710a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (use_swiftshader_) {
711a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitchASCII(switches::kUseGL, "swiftshader");
712a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (swiftshader_path.empty())
713a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      swiftshader_path = swiftshader_path_;
71490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  } else if ((IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL) ||
71590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)              IsFeatureBlacklisted(
71690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                  gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) ||
71790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)              IsFeatureBlacklisted(
71890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                  gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)) &&
719a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      (use_gl == "any")) {
720a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitchASCII(
721a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        switches::kUseGL, gfx::kGLImplementationOSMesaName);
722a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  } else if (!use_gl.empty()) {
723a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitchASCII(switches::kUseGL, use_gl);
724a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
725a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
726a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitchASCII(switches::kSupportsDualGpus, "true");
727a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    switch (gpu_switching_) {
72890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case gpu::GPU_SWITCHING_OPTION_FORCE_DISCRETE:
729a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        command_line->AppendSwitchASCII(switches::kGpuSwitching,
730a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)            switches::kGpuSwitchingOptionNameForceDiscrete);
731a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        break;
73290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case gpu::GPU_SWITCHING_OPTION_FORCE_INTEGRATED:
733a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        command_line->AppendSwitchASCII(switches::kGpuSwitching,
734a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)            switches::kGpuSwitchingOptionNameForceIntegrated);
735a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        break;
73690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case gpu::GPU_SWITCHING_OPTION_AUTOMATIC:
73790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case gpu::GPU_SWITCHING_OPTION_UNKNOWN:
738a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        break;
739a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    }
740a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  } else {
741a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitchASCII(switches::kSupportsDualGpus, "false");
742a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
743a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
7447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!swiftshader_path.empty()) {
745a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitchPath(switches::kSwiftShaderPath,
746a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                   swiftshader_path);
7477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
748a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
749a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!gpu_driver_bugs_.empty()) {
750a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitchASCII(switches::kGpuDriverBugWorkarounds,
751a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                    IntSetToString(gpu_driver_bugs_));
752a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
753a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
7543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE) &&
7553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      !command_line->HasSwitch(switches::kDisableAcceleratedVideoDecode)) {
7563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    command_line->AppendSwitch(switches::kDisableAcceleratedVideoDecode);
7573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
7583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
759a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if defined(OS_WIN)
760a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // DisplayLink 7.1 and earlier can cause the GPU process to crash on startup.
761a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // http://crbug.com/177611
762a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Thinkpad USB Port Replicator driver causes GPU process to crash when the
763a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // sandbox is enabled. http://crbug.com/181665.
764a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if ((gpu_info_.display_link_version.IsValid()
765a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      && gpu_info_.display_link_version.IsOlderThan("7.2")) ||
766a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      gpu_info_.lenovo_dcute) {
7677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    reduce_sandbox = true;
768a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
769a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif
770a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
771a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (gpu_info_.optimus)
7727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    reduce_sandbox = true;
7737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (reduce_sandbox)
7757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    command_line->AppendSwitch(switches::kReduceGpuSandbox);
7767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
777a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Pass GPU and driver information to GPU process. We try to avoid full GPU
778a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // info collection at GPU process startup, but we need gpu vendor_id,
779a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // device_id, driver_vendor, driver_version for deciding whether we need to
780a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // collect full info (on Linux) and for crash reporting purpose.
781a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  command_line->AppendSwitchASCII(switches::kGpuVendorID,
782a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      base::StringPrintf("0x%04x", gpu_info_.gpu.vendor_id));
783a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  command_line->AppendSwitchASCII(switches::kGpuDeviceID,
784a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      base::StringPrintf("0x%04x", gpu_info_.gpu.device_id));
785a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  command_line->AppendSwitchASCII(switches::kGpuDriverVendor,
786a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      gpu_info_.driver_vendor);
787a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  command_line->AppendSwitchASCII(switches::kGpuDriverVersion,
788a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      gpu_info_.driver_version);
789a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
790a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
791a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::AppendPluginCommandLine(
792a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    CommandLine* command_line) const {
793a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DCHECK(command_line);
794a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
795a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if defined(OS_MACOSX)
796a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // TODO(jbauman): Add proper blacklist support for core animation plugins so
797a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // special-casing this video card won't be necessary. See
798a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // http://crbug.com/134015
79990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) ||
800a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      CommandLine::ForCurrentProcess()->HasSwitch(
801a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)          switches::kDisableAcceleratedCompositing)) {
802a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (!command_line->HasSwitch(
803a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)           switches::kDisableCoreAnimationPlugins))
804a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      command_line->AppendSwitch(
805a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)          switches::kDisableCoreAnimationPlugins);
806a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
807a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif
808a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
809a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
810a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::UpdateRendererWebPrefs(
811a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    WebPreferences* prefs) const {
812a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DCHECK(prefs);
813a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
81490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING))
815a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->accelerated_compositing_enabled = false;
81690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL))
817a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->experimental_webgl_enabled = false;
81890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH3D))
819a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->flash_3d_enabled = false;
82090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D)) {
821a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->flash_stage3d_enabled = false;
822a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->flash_stage3d_baseline_enabled = false;
823a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
82490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D_BASELINE))
825a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->flash_stage3d_baseline_enabled = false;
82690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS))
827a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->accelerated_2d_canvas_enabled = false;
828424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_MULTISAMPLING) ||
829424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      (IsDriverBugWorkaroundActive(gpu::DISABLE_MULTIMONITOR_MULTISAMPLING) &&
830424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)          display_count_ > 1))
831a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->gl_multisampling_enabled = false;
83290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_3D_CSS)) {
833a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->accelerated_compositing_for_3d_transforms_enabled = false;
834a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->accelerated_compositing_for_animation_enabled = false;
835a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
83690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO))
837a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->accelerated_compositing_for_video_enabled = false;
838a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
839a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Accelerated video and animation are slower than regular when using
840a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // SwiftShader. 3D CSS may also be too slow to be worthwhile.
841a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (ShouldUseSwiftShader()) {
842a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->accelerated_compositing_for_video_enabled = false;
843a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->accelerated_compositing_for_animation_enabled = false;
844a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->accelerated_compositing_for_3d_transforms_enabled = false;
845a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    prefs->accelerated_compositing_for_plugins_enabled = false;
846a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
847a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
848a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (use_software_compositor_) {
849a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    prefs->force_compositing_mode = true;
850a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    prefs->accelerated_compositing_enabled = true;
851a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    prefs->accelerated_compositing_for_3d_transforms_enabled = true;
852a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    prefs->accelerated_compositing_for_plugins_enabled = true;
8533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    prefs->accelerated_compositing_for_video_enabled = true;
854a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
855a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
856a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#if defined(USE_AURA)
857a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (!CanUseGpuBrowserCompositor())
858a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    prefs->accelerated_2d_canvas_enabled = false;
859a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#endif
860a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
861a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
86290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)gpu::GpuSwitchingOption
86390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)GpuDataManagerImplPrivate::GetGpuSwitchingOption() const {
864a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus())
86590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return gpu::GPU_SWITCHING_OPTION_UNKNOWN;
866a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return gpu_switching_;
867a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
868a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
869a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::DisableHardwareAcceleration() {
870a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  card_blacklisted_ = true;
871a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
87290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  for (int i = 0; i < gpu::NUMBER_OF_GPU_FEATURE_TYPES; ++i)
873a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    blacklisted_features_.insert(i);
874a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
875a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EnableSwiftShaderIfNecessary();
876a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  NotifyGpuInfoUpdate();
877a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
878a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
879a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)std::string GpuDataManagerImplPrivate::GetBlacklistVersion() const {
880a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (gpu_blacklist_)
881a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return gpu_blacklist_->version();
882a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return "0";
883a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
884a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
885868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)std::string GpuDataManagerImplPrivate::GetDriverBugListVersion() const {
886868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (gpu_driver_bug_list_)
887868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return gpu_driver_bug_list_->version();
888868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return "0";
889868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
890868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
891868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void GpuDataManagerImplPrivate::GetBlacklistReasons(
892868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    base::ListValue* reasons) const {
893a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (gpu_blacklist_)
894a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    gpu_blacklist_->GetReasons(reasons);
895868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
896868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
897868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void GpuDataManagerImplPrivate::GetDriverBugWorkarounds(
898868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    base::ListValue* workarounds) const {
899868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for (std::set<int>::const_iterator it = gpu_driver_bugs_.begin();
900868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)       it != gpu_driver_bugs_.end(); ++it) {
901868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    workarounds->AppendString(
902868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        gpu::GpuDriverBugWorkaroundTypeToString(
903868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)            static_cast<gpu::GpuDriverBugWorkaroundType>(*it)));
904868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
905a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
906a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
907a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::AddLogMessage(
908a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    int level, const std::string& header, const std::string& message) {
9097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  base::DictionaryValue* dict = new base::DictionaryValue();
910a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  dict->SetInteger("level", level);
911a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  dict->SetString("header", header);
912a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  dict->SetString("message", message);
913a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  log_messages_.Append(dict);
914a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
915a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
916a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::ProcessCrashed(
917a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    base::TerminationStatus exit_code) {
918a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
919a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // Unretained is ok, because it's posted to UI thread, the thread
920a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // where the singleton GpuDataManagerImpl lives until the end.
921a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    BrowserThread::PostTask(
922a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        BrowserThread::UI,
923a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        FROM_HERE,
924a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        base::Bind(&GpuDataManagerImpl::ProcessCrashed,
925a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                   base::Unretained(owner_),
926a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                   exit_code));
927a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return;
928a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
929a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  {
930a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    GpuDataManagerImpl::UnlockedSession session(owner_);
931a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    observer_list_->Notify(
932a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        &GpuDataManagerObserver::OnGpuProcessCrashed, exit_code);
933a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
934a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
935a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
936a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)base::ListValue* GpuDataManagerImplPrivate::GetLogMessages() const {
937a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  base::ListValue* value;
938a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  value = log_messages_.DeepCopy();
939a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return value;
940a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
941a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
942a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::HandleGpuSwitch() {
943a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GpuDataManagerImpl::UnlockedSession session(owner_);
944a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  observer_list_->Notify(&GpuDataManagerObserver::OnGpuSwitching);
945a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
946a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
947a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if defined(OS_WIN)
948a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)bool GpuDataManagerImplPrivate::IsUsingAcceleratedSurface() const {
949a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (base::win::GetVersion() < base::win::VERSION_VISTA)
950a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return false;
951a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
952a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (use_swiftshader_)
953a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return false;
954a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  CommandLine* command_line = CommandLine::ForCurrentProcess();
955a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (command_line->HasSwitch(switches::kDisableImageTransportSurface))
956a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return false;
95790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return !IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_TEXTURE_SHARING);
958a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
959a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif
960a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
9617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochbool GpuDataManagerImplPrivate::CanUseGpuBrowserCompositor() const {
962a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return !ShouldUseSwiftShader() &&
963a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)         !IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) &&
964a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)         !IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE);
9657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
9667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
967a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIs(
968a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const GURL& url, GpuDataManagerImpl::DomainGuilt guilt) {
969a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  BlockDomainFrom3DAPIsAtTime(url, guilt, base::Time::Now());
970a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
971a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
972a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)bool GpuDataManagerImplPrivate::Are3DAPIsBlocked(const GURL& url,
973a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                                 int render_process_id,
974a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                                 int render_view_id,
975a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                                 ThreeDAPIType requester) {
976a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  bool blocked = Are3DAPIsBlockedAtTime(url, base::Time::Now()) !=
977a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED;
978a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (blocked) {
979a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // Unretained is ok, because it's posted to UI thread, the thread
980a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // where the singleton GpuDataManagerImpl lives until the end.
981a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    BrowserThread::PostTask(
982a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        BrowserThread::UI, FROM_HERE,
983a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        base::Bind(&GpuDataManagerImpl::Notify3DAPIBlocked,
984a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                   base::Unretained(owner_), url, render_process_id,
985a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                   render_view_id, requester));
986a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
987a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
988a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return blocked;
989a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
990a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
991a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::DisableDomainBlockingFor3DAPIsForTesting() {
992a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  domain_blocking_enabled_ = false;
993a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
994a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
995a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// static
996a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)GpuDataManagerImplPrivate* GpuDataManagerImplPrivate::Create(
997a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    GpuDataManagerImpl* owner) {
998a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return new GpuDataManagerImplPrivate(owner);
999a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1000a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1001a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)GpuDataManagerImplPrivate::GpuDataManagerImplPrivate(
1002a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    GpuDataManagerImpl* owner)
1003a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    : complete_gpu_info_already_requested_(false),
100490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      gpu_switching_(gpu::GPU_SWITCHING_OPTION_AUTOMATIC),
1005a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      observer_list_(new GpuDataManagerObserverList),
1006a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      use_swiftshader_(false),
1007a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      card_blacklisted_(false),
1008a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      update_histograms_(true),
1009a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      window_count_(0),
1010a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      domain_blocking_enabled_(true),
1011868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      owner_(owner),
1012eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      display_count_(0),
1013a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      gpu_process_accessible_(true),
1014a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      use_software_compositor_(false) {
1015a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DCHECK(owner_);
1016a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  CommandLine* command_line = CommandLine::ForCurrentProcess();
1017a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
1018a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas);
1019a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    command_line->AppendSwitch(switches::kDisableAcceleratedLayers);
1020a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1021a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (command_line->HasSwitch(switches::kDisableGpu))
1022a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    DisableHardwareAcceleration();
1023a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (command_line->HasSwitch(switches::kEnableSoftwareCompositing))
1024a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    use_software_compositor_ = true;
10253240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  //TODO(jbauman): enable for Chrome OS and Linux
10263240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(USE_AURA) && defined(OS_WIN)
10273240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  use_software_compositor_ = true;
10283240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#endif
1029a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (command_line->HasSwitch(switches::kGpuSwitching)) {
1030a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    std::string option_string = command_line->GetSwitchValueASCII(
1031a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        switches::kGpuSwitching);
103290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    gpu::GpuSwitchingOption option =
103390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        gpu::StringToGpuSwitchingOption(option_string);
103490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if (option != gpu::GPU_SWITCHING_OPTION_UNKNOWN)
1035a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      gpu_switching_ = option;
1036a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1037a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1038a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if defined(OS_MACOSX)
1039868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  CGGetActiveDisplayList (0, NULL, &display_count_);
1040a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  CGDisplayRegisterReconfigurationCallback(DisplayReconfigCallback, owner_);
1041a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif  // OS_MACOSX
1042a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1043a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1044a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)GpuDataManagerImplPrivate::~GpuDataManagerImplPrivate() {
1045a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#if defined(OS_MACOSX)
1046a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  CGDisplayRemoveReconfigurationCallback(DisplayReconfigCallback, owner_);
1047a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif
1048a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1049a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1050a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::InitializeImpl(
1051a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const std::string& gpu_blacklist_json,
1052a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const std::string& gpu_switching_list_json,
1053a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const std::string& gpu_driver_bug_list_json,
105490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    const gpu::GPUInfo& gpu_info) {
1055a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string browser_version_string = ProcessVersionString(
1056a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      GetContentClient()->GetProduct());
1057a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  CHECK(!browser_version_string.empty());
1058a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1059a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!gpu_blacklist_json.empty()) {
106090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    gpu_blacklist_.reset(gpu::GpuBlacklist::Create());
1061a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    gpu_blacklist_->LoadList(
1062a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        browser_version_string, gpu_blacklist_json,
106390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        gpu::GpuControlList::kCurrentOsOnly);
1064a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1065a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!gpu_switching_list_json.empty()) {
106690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    gpu_switching_list_.reset(gpu::GpuSwitchingList::Create());
1067a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    gpu_switching_list_->LoadList(
1068a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        browser_version_string, gpu_switching_list_json,
106990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        gpu::GpuControlList::kCurrentOsOnly);
1070a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1071a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!gpu_driver_bug_list_json.empty()) {
107290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    gpu_driver_bug_list_.reset(gpu::GpuDriverBugList::Create());
1073a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    gpu_driver_bug_list_->LoadList(
1074a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        browser_version_string, gpu_driver_bug_list_json,
107590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        gpu::GpuControlList::kCurrentOsOnly);
1076a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1077a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1078a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  gpu_info_ = gpu_info;
1079a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  UpdateGpuInfo(gpu_info);
1080a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  UpdateGpuSwitchingManager(gpu_info);
1081a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  UpdatePreliminaryBlacklistedFeatures();
108290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
108390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CommandLine* command_line = CommandLine::ForCurrentProcess();
108490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // We pass down the list to GPU command buffer through commandline
108590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // switches at GPU process launch. However, in situations where we don't
108690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // have a GPU process, we append the browser process commandline.
108790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (command_line->HasSwitch(switches::kSingleProcess) ||
108890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      command_line->HasSwitch(switches::kInProcessGPU)) {
108990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if (!gpu_driver_bugs_.empty()) {
109090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      command_line->AppendSwitchASCII(switches::kGpuDriverBugWorkarounds,
109190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                      IntSetToString(gpu_driver_bugs_));
109290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    }
109390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
109490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_ANDROID)
109590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ApplyAndroidWorkarounds(gpu_info, command_line);
109690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // OS_ANDROID
1097a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1098a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1099a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::UpdateBlacklistedFeatures(
1100a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const std::set<int>& features) {
1101a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  CommandLine* command_line = CommandLine::ForCurrentProcess();
1102a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  blacklisted_features_ = features;
1103a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1104a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Force disable using the GPU for these features, even if they would
1105a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // otherwise be allowed.
1106a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (card_blacklisted_ ||
1107a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      command_line->HasSwitch(switches::kBlacklistAcceleratedCompositing)) {
110890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    blacklisted_features_.insert(
110990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING);
1110a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1111a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (card_blacklisted_ ||
1112a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      command_line->HasSwitch(switches::kBlacklistWebGL)) {
111390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_WEBGL);
1114a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1115a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1116a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EnableSwiftShaderIfNecessary();
1117a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1118a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1119a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::UpdatePreliminaryBlacklistedFeatures() {
1120a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  preliminary_blacklisted_features_ = blacklisted_features_;
1121a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1122a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1123a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::UpdateGpuSwitchingManager(
112490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    const gpu::GPUInfo& gpu_info) {
1125a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ui::GpuSwitchingManager::GetInstance()->SetGpuCount(
1126a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      gpu_info.secondary_gpus.size() + 1);
1127a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1128a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
1129a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    switch (gpu_switching_) {
113090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case gpu::GPU_SWITCHING_OPTION_FORCE_DISCRETE:
1131a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu();
1132a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        break;
113390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case gpu::GPU_SWITCHING_OPTION_FORCE_INTEGRATED:
1134a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu();
1135a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        break;
113690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case gpu::GPU_SWITCHING_OPTION_AUTOMATIC:
113790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      case gpu::GPU_SWITCHING_OPTION_UNKNOWN:
1138a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        break;
1139a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    }
1140a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1141a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1142a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1143a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::NotifyGpuInfoUpdate() {
1144a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  observer_list_->Notify(&GpuDataManagerObserver::OnGpuInfoUpdate);
1145a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1146a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1147a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::EnableSwiftShaderIfNecessary() {
1148a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!GpuAccessAllowed(NULL) ||
114990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      blacklisted_features_.count(gpu::GPU_FEATURE_TYPE_WEBGL)) {
1150a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (!swiftshader_path_.empty() &&
1151a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        !CommandLine::ForCurrentProcess()->HasSwitch(
1152a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)             switches::kDisableSoftwareRasterizer))
1153a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      use_swiftshader_ = true;
1154a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1155a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1156a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1157a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)std::string GpuDataManagerImplPrivate::GetDomainFromURL(
1158a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const GURL& url) const {
1159a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // For the moment, we just use the host, or its IP address, as the
1160a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // entry in the set, rather than trying to figure out the top-level
1161a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // domain. This does mean that a.foo.com and b.foo.com will be
1162a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // treated independently in the blocking of a given domain, but it
1163a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // would require a third-party library to reliably figure out the
1164a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // top-level domain from a URL.
1165a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!url.has_host()) {
1166a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return std::string();
1167a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1168a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1169a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return url.host();
1170a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1171a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1172a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIsAtTime(
1173a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const GURL& url,
1174a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    GpuDataManagerImpl::DomainGuilt guilt,
1175a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    base::Time at_time) {
1176a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!domain_blocking_enabled_)
1177a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return;
1178a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1179a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string domain = GetDomainFromURL(url);
1180a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1181a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DomainBlockEntry& entry = blocked_domains_[domain];
1182a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  entry.last_guilt = guilt;
1183a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  timestamps_of_gpu_resets_.push_back(at_time);
1184a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1185a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1186a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)GpuDataManagerImpl::DomainBlockStatus
1187a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)GpuDataManagerImplPrivate::Are3DAPIsBlockedAtTime(
1188a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const GURL& url, base::Time at_time) const {
1189a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (!domain_blocking_enabled_)
1190a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED;
1191a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1192a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Note: adjusting the policies in this code will almost certainly
1193a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // require adjusting the associated unit tests.
1194a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string domain = GetDomainFromURL(url);
1195a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1196a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DomainBlockMap::const_iterator iter = blocked_domains_.find(domain);
1197a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (iter != blocked_domains_.end()) {
1198a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // Err on the side of caution, and assume that if a particular
1199a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // domain shows up in the block map, it's there for a good
1200a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // reason and don't let its presence there automatically expire.
1201a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1202a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs",
1203a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                              BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED,
1204a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                              BLOCK_STATUS_MAX);
1205a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1206a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED;
1207a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1208a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1209a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Look at the timestamps of the recent GPU resets to see if there are
1210a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // enough within the threshold which would cause us to blacklist all
1211a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // domains. This doesn't need to be overly precise -- if time goes
1212a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // backward due to a system clock adjustment, that's fine.
1213a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //
1214a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // TODO(kbr): make this pay attention to the TDR thresholds in the
1215a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Windows registry, but make sure it continues to be testable.
1216a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  {
1217a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    std::list<base::Time>::iterator iter = timestamps_of_gpu_resets_.begin();
1218a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    int num_resets_within_timeframe = 0;
1219a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    while (iter != timestamps_of_gpu_resets_.end()) {
1220a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      base::Time time = *iter;
1221a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      base::TimeDelta delta_t = at_time - time;
1222a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1223a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      // If this entry has "expired", just remove it.
1224a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      if (delta_t.InMilliseconds() > kBlockAllDomainsMs) {
1225a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        iter = timestamps_of_gpu_resets_.erase(iter);
1226a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        continue;
1227a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      }
1228a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1229a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      ++num_resets_within_timeframe;
1230a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      ++iter;
1231a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    }
1232a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1233a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (num_resets_within_timeframe >= kNumResetsWithinDuration) {
1234a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs",
1235a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                BLOCK_STATUS_ALL_DOMAINS_BLOCKED,
1236a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                BLOCK_STATUS_MAX);
1237a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1238a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED;
1239a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    }
1240a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
1241a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1242a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs",
1243a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                            BLOCK_STATUS_NOT_BLOCKED,
1244a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                            BLOCK_STATUS_MAX);
1245a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1246a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED;
1247a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1248a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1249a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)int64 GpuDataManagerImplPrivate::GetBlockAllDomainsDurationInMs() const {
1250a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return kBlockAllDomainsMs;
1251a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1252a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1253a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void GpuDataManagerImplPrivate::Notify3DAPIBlocked(const GURL& url,
1254a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                                   int render_process_id,
1255a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                                   int render_view_id,
1256a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                                   ThreeDAPIType requester) {
1257a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  GpuDataManagerImpl::UnlockedSession session(owner_);
1258a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  observer_list_->Notify(&GpuDataManagerObserver::DidBlock3DAPIs,
1259a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                         url, render_process_id, render_view_id, requester);
1260a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
1261a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1262eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid GpuDataManagerImplPrivate::OnGpuProcessInitFailure() {
1263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  gpu_process_accessible_ = false;
1264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  gpu_info_.finalized = true;
1265eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  complete_gpu_info_already_requested_ = true;
1266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Some observers might be waiting.
1267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  NotifyGpuInfoUpdate();
1268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1269eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1270a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}  // namespace content
1271