1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "blimp/common/compositor/blimp_layer_tree_settings.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h"
12 #include "base/sys_info.h"
13 #include "cc/base/switches.h"
14 #include "cc/trees/layer_tree_settings.h"
15 #include "content/public/common/content_switches.h"
16 #include "third_party/skia/include/core/SkColor.h"
17 #include "ui/gfx/buffer_types.h"
18 #include "ui/gl/gl_switches.h"
19 #include "ui/native_theme/native_theme_switches.h"
23 bool GetSwitchValueAsInt(const base::CommandLine
& command_line
,
24 const std::string
& switch_string
,
28 std::string string_value
= command_line
.GetSwitchValueASCII(switch_string
);
30 if (base::StringToInt(string_value
, &int_value
) && int_value
>= min_value
&&
31 int_value
<= max_value
) {
39 void StringToUintVector(const std::string
& str
, std::vector
<unsigned>* vector
) {
40 DCHECK(vector
->empty());
41 std::vector
<std::string
> pieces
=
42 base::SplitString(str
, ",", base::TRIM_WHITESPACE
, base::SPLIT_WANT_ALL
);
43 DCHECK_EQ(pieces
.size(), static_cast<size_t>(gfx::BufferFormat::LAST
) + 1);
44 for (size_t i
= 0; i
< pieces
.size(); ++i
) {
46 bool succeed
= base::StringToUint(pieces
[i
], &number
);
48 vector
->push_back(number
);
56 // TODO(dtrainor): This is temporary to get the compositor up and running.
57 // Much of this will either have to be pulled from the server or refactored to
58 // share the settings from render_widget_compositor.cc.
59 void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings
* settings
) {
60 const base::CommandLine
& cmd
= *base::CommandLine::ForCurrentProcess();
61 // For web contents, layer transforms should scale up the contents of layers
62 // to keep content always crisp when possible.
63 settings
->layer_transforms_should_scale_layer_contents
= true;
65 if (cmd
.HasSwitch(switches::kDisableGpuVsync
)) {
66 std::string display_vsync_string
=
67 cmd
.GetSwitchValueASCII(switches::kDisableGpuVsync
);
68 if (display_vsync_string
== "gpu") {
69 settings
->renderer_settings
.disable_display_vsync
= true;
70 } else if (display_vsync_string
== "beginframe") {
71 settings
->wait_for_beginframe_interval
= false;
73 settings
->renderer_settings
.disable_display_vsync
= true;
74 settings
->wait_for_beginframe_interval
= false;
77 settings
->main_frame_before_activation_enabled
=
78 cmd
.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation
) &&
79 !cmd
.HasSwitch(cc::switches::kDisableMainFrameBeforeActivation
);
80 settings
->accelerated_animation_enabled
=
81 !cmd
.HasSwitch(cc::switches::kDisableThreadedAnimation
);
83 settings
->default_tile_size
= gfx::Size(256, 256);
84 if (cmd
.HasSwitch(switches::kDefaultTileWidth
)) {
86 GetSwitchValueAsInt(cmd
, switches::kDefaultTileWidth
, 1,
87 std::numeric_limits
<int>::max(), &tile_width
);
88 settings
->default_tile_size
.set_width(tile_width
);
90 if (cmd
.HasSwitch(switches::kDefaultTileHeight
)) {
92 GetSwitchValueAsInt(cmd
, switches::kDefaultTileHeight
, 1,
93 std::numeric_limits
<int>::max(), &tile_height
);
94 settings
->default_tile_size
.set_height(tile_height
);
97 int max_untiled_layer_width
= settings
->max_untiled_layer_size
.width();
98 if (cmd
.HasSwitch(switches::kMaxUntiledLayerWidth
)) {
99 GetSwitchValueAsInt(cmd
, switches::kMaxUntiledLayerWidth
, 1,
100 std::numeric_limits
<int>::max(),
101 &max_untiled_layer_width
);
103 int max_untiled_layer_height
= settings
->max_untiled_layer_size
.height();
104 if (cmd
.HasSwitch(switches::kMaxUntiledLayerHeight
)) {
105 GetSwitchValueAsInt(cmd
, switches::kMaxUntiledLayerHeight
, 1,
106 std::numeric_limits
<int>::max(),
107 &max_untiled_layer_height
);
110 settings
->max_untiled_layer_size
=
111 gfx::Size(max_untiled_layer_width
, max_untiled_layer_height
);
113 settings
->gpu_rasterization_msaa_sample_count
= 0;
114 if (cmd
.HasSwitch(switches::kGpuRasterizationMSAASampleCount
)) {
115 GetSwitchValueAsInt(cmd
, switches::kGpuRasterizationMSAASampleCount
, 0,
116 std::numeric_limits
<int>::max(),
117 &settings
->gpu_rasterization_msaa_sample_count
);
120 settings
->gpu_rasterization_forced
=
121 cmd
.HasSwitch(switches::kForceGpuRasterization
);
122 settings
->gpu_rasterization_enabled
=
123 cmd
.HasSwitch(switches::kEnableGpuRasterization
);
125 settings
->can_use_lcd_text
= false;
126 settings
->use_distance_field_text
=
127 cmd
.HasSwitch(switches::kEnableDistanceFieldText
);
129 settings
->use_zero_copy
= cmd
.HasSwitch(switches::kEnableZeroCopy
);
130 settings
->enable_elastic_overscroll
= false;
132 if (cmd
.HasSwitch(switches::kContentImageTextureTarget
)) {
133 settings
->use_image_texture_targets
.clear();
135 cmd
.GetSwitchValueASCII(switches::kContentImageTextureTarget
),
136 &settings
->use_image_texture_targets
);
139 settings
->gather_images
= false;
140 if (cmd
.HasSwitch(switches::kNumRasterThreads
)) {
141 int num_raster_threads
= 0;
142 GetSwitchValueAsInt(cmd
, switches::kNumRasterThreads
, 0,
143 std::numeric_limits
<int>::max(), &num_raster_threads
);
144 settings
->gather_images
= num_raster_threads
> 1;
147 if (cmd
.HasSwitch(cc::switches::kTopControlsShowThreshold
)) {
148 std::string top_threshold_str
=
149 cmd
.GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold
);
150 double show_threshold
;
151 if (base::StringToDouble(top_threshold_str
, &show_threshold
) &&
152 show_threshold
>= 0.f
&& show_threshold
<= 1.f
)
153 settings
->top_controls_show_threshold
= show_threshold
;
156 if (cmd
.HasSwitch(cc::switches::kTopControlsHideThreshold
)) {
157 std::string top_threshold_str
=
158 cmd
.GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold
);
159 double hide_threshold
;
160 if (base::StringToDouble(top_threshold_str
, &hide_threshold
) &&
161 hide_threshold
>= 0.f
&& hide_threshold
<= 1.f
)
162 settings
->top_controls_hide_threshold
= hide_threshold
;
165 settings
->verify_property_trees
=
166 cmd
.HasSwitch(cc::switches::kEnablePropertyTreeVerification
);
167 settings
->renderer_settings
.allow_antialiasing
&=
168 !cmd
.HasSwitch(cc::switches::kDisableCompositedAntialiasing
);
169 settings
->single_thread_proxy_scheduler
= false;
171 // These flags should be mirrored by UI versions in ui/compositor/.
172 settings
->initial_debug_state
.show_debug_borders
=
173 cmd
.HasSwitch(cc::switches::kShowCompositedLayerBorders
);
174 settings
->initial_debug_state
.show_fps_counter
=
175 cmd
.HasSwitch(cc::switches::kShowFPSCounter
);
176 settings
->initial_debug_state
.show_layer_animation_bounds_rects
=
177 cmd
.HasSwitch(cc::switches::kShowLayerAnimationBounds
);
178 settings
->initial_debug_state
.show_paint_rects
=
179 cmd
.HasSwitch(switches::kShowPaintRects
);
180 settings
->initial_debug_state
.show_property_changed_rects
=
181 cmd
.HasSwitch(cc::switches::kShowPropertyChangedRects
);
182 settings
->initial_debug_state
.show_surface_damage_rects
=
183 cmd
.HasSwitch(cc::switches::kShowSurfaceDamageRects
);
184 settings
->initial_debug_state
.show_screen_space_rects
=
185 cmd
.HasSwitch(cc::switches::kShowScreenSpaceRects
);
186 settings
->initial_debug_state
.show_replica_screen_space_rects
=
187 cmd
.HasSwitch(cc::switches::kShowReplicaScreenSpaceRects
);
189 settings
->initial_debug_state
.SetRecordRenderingStats(
190 cmd
.HasSwitch(cc::switches::kEnableGpuBenchmarking
));
192 if (cmd
.HasSwitch(cc::switches::kSlowDownRasterScaleFactor
)) {
193 const int kMinSlowDownScaleFactor
= 0;
194 const int kMaxSlowDownScaleFactor
= INT_MAX
;
196 cmd
, cc::switches::kSlowDownRasterScaleFactor
, kMinSlowDownScaleFactor
,
197 kMaxSlowDownScaleFactor
,
198 &settings
->initial_debug_state
.slow_down_raster_scale_factor
);
201 settings
->strict_layer_property_change_checking
=
202 cmd
.HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking
);
204 #if defined(OS_ANDROID)
205 if (base::SysInfo::IsLowEndDevice())
206 settings
->gpu_rasterization_enabled
= false;
207 settings
->using_synchronous_renderer_compositor
= false;
208 settings
->record_full_layer
= false;
209 settings
->scrollbar_animator
= cc::LayerTreeSettings::LINEAR_FADE
;
210 settings
->scrollbar_fade_delay_ms
= 300;
211 settings
->scrollbar_fade_resize_delay_ms
= 2000;
212 settings
->scrollbar_fade_duration_ms
= 300;
213 settings
->solid_color_scrollbar_color
= SkColorSetARGB(128, 128, 128, 128);
214 settings
->renderer_settings
.highp_threshold_min
= 2048;
215 settings
->ignore_root_layer_flings
= false;
216 bool use_low_memory_policy
= base::SysInfo::IsLowEndDevice();
217 settings
->renderer_settings
.use_rgba_4444_textures
= use_low_memory_policy
;
218 if (use_low_memory_policy
) {
219 // On low-end we want to be very carefull about killing other
220 // apps. So initially we use 50% more memory to avoid flickering
221 // or raster-on-demand.
222 settings
->max_memory_for_prepaint_percentage
= 67;
224 // On other devices we have increased memory excessively to avoid
225 // raster-on-demand already, so now we reserve 50% _only_ to avoid
226 // raster-on-demand, and use 50% of the memory otherwise.
227 settings
->max_memory_for_prepaint_percentage
= 50;
229 settings
->renderer_settings
.should_clear_root_render_pass
= true;
231 // TODO(danakj): Only do this on low end devices.
232 settings
->create_low_res_tiling
= true;
234 // TODO(dtrainor): Investigate whether or not we want to use an external
236 // settings->use_external_begin_frame_source = true;
238 #elif !defined(OS_MACOSX)
239 if (ui::IsOverlayScrollbarEnabled()) {
240 settings
->scrollbar_animator
= cc::LayerTreeSettings::THINNING
;
241 settings
->solid_color_scrollbar_color
= SkColorSetARGB(128, 128, 128, 128);
243 settings
->scrollbar_animator
= cc::LayerTreeSettings::LINEAR_FADE
;
244 settings
->solid_color_scrollbar_color
= SkColorSetARGB(128, 128, 128, 128);
246 settings
->scrollbar_fade_delay_ms
= 500;
247 settings
->scrollbar_fade_resize_delay_ms
= 500;
248 settings
->scrollbar_fade_duration_ms
= 300;
250 // When pinching in, only show the pinch-viewport overlay scrollbars if the
251 // page scale is at least some threshold away from the minimum. i.e. don't
252 // show the pinch scrollbars when at minimum scale.
253 // TODO(dtrainor): Update this since https://crrev.com/1267603004 landed.
254 // settings->scrollbar_show_scale_threshold = 1.05f;
257 if (cmd
.HasSwitch(switches::kEnableLowResTiling
))
258 settings
->create_low_res_tiling
= true;
259 if (cmd
.HasSwitch(switches::kDisableLowResTiling
))
260 settings
->create_low_res_tiling
= false;
261 if (cmd
.HasSwitch(cc::switches::kEnableBeginFrameScheduling
))
262 settings
->use_external_begin_frame_source
= true;