summaryrefslogtreecommitdiffstats
path: root/content/browser/gpu/compositor_util.cc
blob: 878aaa392609193c4cfc37703b28d3dae17fefc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/public/browser/compositor_util.h"

#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"

namespace {

using content::GpuDataManager;

bool CanDoAcceleratedCompositing() {
  const GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
  content::GpuFeatureType blacklisted_features =
      gpu_data_manager->GetBlacklistedFeatures();

  // Don't run the field trial if gpu access has been blocked or
  // accelerated compositing is blacklisted.
  if (!gpu_data_manager->GpuAccessAllowed() ||
      blacklisted_features & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
    return false;

  // Check for the software rasterizer (SwiftShader).
  if (gpu_data_manager->ShouldUseSoftwareRendering())
    return false;

  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
  if (command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
    return false;

  return true;
}

}  // namespace

namespace content {

bool IsThreadedCompositingEnabled() {
#if defined(OS_WIN) && defined(USE_AURA)
  // We always want compositing on Aura Windows.
  return true;
#endif

  if (!CanDoAcceleratedCompositing())
    return false;

  const CommandLine& command_line = *CommandLine::ForCurrentProcess();

  // Command line switches take precedence over field trials.
  if (command_line.HasSwitch(switches::kDisableForceCompositingMode) ||
      command_line.HasSwitch(switches::kDisableThreadedCompositing))
    return false;

  if (command_line.HasSwitch(switches::kEnableThreadedCompositing))
    return true;

  base::FieldTrial* trial =
      base::FieldTrialList::Find(content::kGpuCompositingFieldTrialName);
  return trial &&
         trial->group_name() ==
             content::kGpuCompositingFieldTrialThreadEnabledName;
}

bool IsForceCompositingModeEnabled() {
#if defined(OS_WIN) && defined(USE_AURA)
  // We always want compositing on Aura Windows.
  return true;
#endif

  if (!CanDoAcceleratedCompositing())
    return false;

  const CommandLine& command_line = *CommandLine::ForCurrentProcess();

  // Command line switches take precedence over field trials.
  if (command_line.HasSwitch(switches::kDisableForceCompositingMode))
    return false;

  if (command_line.HasSwitch(switches::kForceCompositingMode))
    return true;

  base::FieldTrial* trial =
      base::FieldTrialList::Find(content::kGpuCompositingFieldTrialName);

  // Force compositing is enabled in both the force compositing
  // and threaded compositing mode field trials.
  return trial &&
        (trial->group_name() ==
            content::kGpuCompositingFieldTrialForceCompositingEnabledName ||
         trial->group_name() ==
            content::kGpuCompositingFieldTrialThreadEnabledName);
}

}  // namespace content