Roll src/third_party/WebKit a452221:9ff6d11 (svn 202117:202119)
[chromium-blink-merge.git] / blimp / common / compositor / blimp_layer_tree_settings.cc
blob12a58ec55a1bd8676db86e419aa69d360fbae6a0
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"
21 namespace {
23 bool GetSwitchValueAsInt(const base::CommandLine& command_line,
24 const std::string& switch_string,
25 int min_value,
26 int max_value,
27 int* result) {
28 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
29 int int_value;
30 if (base::StringToInt(string_value, &int_value) && int_value >= min_value &&
31 int_value <= max_value) {
32 *result = int_value;
33 return true;
34 } else {
35 return false;
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) {
45 unsigned number = 0;
46 bool succeed = base::StringToUint(pieces[i], &number);
47 DCHECK(succeed);
48 vector->push_back(number);
52 } // namespace
54 namespace blimp {
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;
72 } else {
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);
82 settings->use_display_lists = cmd.HasSwitch(switches::kEnableSlimmingPaint);
84 settings->default_tile_size = gfx::Size(256, 256);
85 if (cmd.HasSwitch(switches::kDefaultTileWidth)) {
86 int tile_width = 0;
87 GetSwitchValueAsInt(cmd, switches::kDefaultTileWidth, 1,
88 std::numeric_limits<int>::max(), &tile_width);
89 settings->default_tile_size.set_width(tile_width);
91 if (cmd.HasSwitch(switches::kDefaultTileHeight)) {
92 int tile_height = 0;
93 GetSwitchValueAsInt(cmd, switches::kDefaultTileHeight, 1,
94 std::numeric_limits<int>::max(), &tile_height);
95 settings->default_tile_size.set_height(tile_height);
98 int max_untiled_layer_width = settings->max_untiled_layer_size.width();
99 if (cmd.HasSwitch(switches::kMaxUntiledLayerWidth)) {
100 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerWidth, 1,
101 std::numeric_limits<int>::max(),
102 &max_untiled_layer_width);
104 int max_untiled_layer_height = settings->max_untiled_layer_size.height();
105 if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) {
106 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerHeight, 1,
107 std::numeric_limits<int>::max(),
108 &max_untiled_layer_height);
111 settings->max_untiled_layer_size =
112 gfx::Size(max_untiled_layer_width, max_untiled_layer_height);
114 settings->gpu_rasterization_msaa_sample_count = 0;
115 if (cmd.HasSwitch(switches::kGpuRasterizationMSAASampleCount)) {
116 GetSwitchValueAsInt(cmd, switches::kGpuRasterizationMSAASampleCount, 0,
117 std::numeric_limits<int>::max(),
118 &settings->gpu_rasterization_msaa_sample_count);
121 settings->gpu_rasterization_forced =
122 cmd.HasSwitch(switches::kForceGpuRasterization);
123 settings->gpu_rasterization_enabled =
124 cmd.HasSwitch(switches::kEnableGpuRasterization);
126 settings->can_use_lcd_text = false;
127 settings->use_distance_field_text =
128 cmd.HasSwitch(switches::kEnableDistanceFieldText);
130 settings->use_zero_copy = cmd.HasSwitch(switches::kEnableZeroCopy);
131 settings->enable_elastic_overscroll = false;
133 if (cmd.HasSwitch(switches::kContentImageTextureTarget)) {
134 settings->use_image_texture_targets.clear();
135 StringToUintVector(
136 cmd.GetSwitchValueASCII(switches::kContentImageTextureTarget),
137 &settings->use_image_texture_targets);
140 settings->gather_images = false;
141 if (cmd.HasSwitch(switches::kNumRasterThreads)) {
142 int num_raster_threads = 0;
143 GetSwitchValueAsInt(cmd, switches::kNumRasterThreads, 0,
144 std::numeric_limits<int>::max(), &num_raster_threads);
145 settings->gather_images = num_raster_threads > 1;
148 if (cmd.HasSwitch(cc::switches::kTopControlsShowThreshold)) {
149 std::string top_threshold_str =
150 cmd.GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold);
151 double show_threshold;
152 if (base::StringToDouble(top_threshold_str, &show_threshold) &&
153 show_threshold >= 0.f && show_threshold <= 1.f)
154 settings->top_controls_show_threshold = show_threshold;
157 if (cmd.HasSwitch(cc::switches::kTopControlsHideThreshold)) {
158 std::string top_threshold_str =
159 cmd.GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold);
160 double hide_threshold;
161 if (base::StringToDouble(top_threshold_str, &hide_threshold) &&
162 hide_threshold >= 0.f && hide_threshold <= 1.f)
163 settings->top_controls_hide_threshold = hide_threshold;
166 settings->verify_property_trees =
167 cmd.HasSwitch(cc::switches::kEnablePropertyTreeVerification);
168 settings->renderer_settings.allow_antialiasing &=
169 !cmd.HasSwitch(cc::switches::kDisableCompositedAntialiasing);
170 settings->single_thread_proxy_scheduler = false;
172 // These flags should be mirrored by UI versions in ui/compositor/.
173 settings->initial_debug_state.show_debug_borders =
174 cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders);
175 settings->initial_debug_state.show_fps_counter =
176 cmd.HasSwitch(cc::switches::kShowFPSCounter);
177 settings->initial_debug_state.show_layer_animation_bounds_rects =
178 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds);
179 settings->initial_debug_state.show_paint_rects =
180 cmd.HasSwitch(switches::kShowPaintRects);
181 settings->initial_debug_state.show_property_changed_rects =
182 cmd.HasSwitch(cc::switches::kShowPropertyChangedRects);
183 settings->initial_debug_state.show_surface_damage_rects =
184 cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects);
185 settings->initial_debug_state.show_screen_space_rects =
186 cmd.HasSwitch(cc::switches::kShowScreenSpaceRects);
187 settings->initial_debug_state.show_replica_screen_space_rects =
188 cmd.HasSwitch(cc::switches::kShowReplicaScreenSpaceRects);
190 settings->initial_debug_state.SetRecordRenderingStats(
191 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking));
193 if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) {
194 const int kMinSlowDownScaleFactor = 0;
195 const int kMaxSlowDownScaleFactor = INT_MAX;
196 GetSwitchValueAsInt(
197 cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor,
198 kMaxSlowDownScaleFactor,
199 &settings->initial_debug_state.slow_down_raster_scale_factor);
202 settings->invert_viewport_scroll_order =
203 cmd.HasSwitch(switches::kInvertViewportScrollOrder);
205 settings->strict_layer_property_change_checking =
206 cmd.HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking);
208 #if defined(OS_ANDROID)
209 if (base::SysInfo::IsLowEndDevice())
210 settings->gpu_rasterization_enabled = false;
211 settings->using_synchronous_renderer_compositor = false;
212 settings->record_full_layer = false;
213 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
214 settings->scrollbar_fade_delay_ms = 300;
215 settings->scrollbar_fade_resize_delay_ms = 2000;
216 settings->scrollbar_fade_duration_ms = 300;
217 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
218 settings->renderer_settings.highp_threshold_min = 2048;
219 settings->ignore_root_layer_flings = false;
220 bool use_low_memory_policy = base::SysInfo::IsLowEndDevice();
221 settings->renderer_settings.use_rgba_4444_textures = use_low_memory_policy;
222 if (use_low_memory_policy) {
223 // On low-end we want to be very carefull about killing other
224 // apps. So initially we use 50% more memory to avoid flickering
225 // or raster-on-demand.
226 settings->max_memory_for_prepaint_percentage = 67;
227 } else {
228 // On other devices we have increased memory excessively to avoid
229 // raster-on-demand already, so now we reserve 50% _only_ to avoid
230 // raster-on-demand, and use 50% of the memory otherwise.
231 settings->max_memory_for_prepaint_percentage = 50;
233 settings->renderer_settings.should_clear_root_render_pass = true;
235 // TODO(danakj): Only do this on low end devices.
236 settings->create_low_res_tiling = true;
238 // TODO(dtrainor): Investigate whether or not we want to use an external
239 // source here.
240 // settings->use_external_begin_frame_source = true;
242 #elif !defined(OS_MACOSX)
243 if (ui::IsOverlayScrollbarEnabled()) {
244 settings->scrollbar_animator = cc::LayerTreeSettings::THINNING;
245 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
246 } else {
247 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
248 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
250 settings->scrollbar_fade_delay_ms = 500;
251 settings->scrollbar_fade_resize_delay_ms = 500;
252 settings->scrollbar_fade_duration_ms = 300;
254 // When pinching in, only show the pinch-viewport overlay scrollbars if the
255 // page scale is at least some threshold away from the minimum. i.e. don't
256 // show the pinch scrollbars when at minimum scale.
257 // TODO(dtrainor): Update this since https://crrev.com/1267603004 landed.
258 // settings->scrollbar_show_scale_threshold = 1.05f;
259 #endif
261 if (cmd.HasSwitch(switches::kEnableLowResTiling))
262 settings->create_low_res_tiling = true;
263 if (cmd.HasSwitch(switches::kDisableLowResTiling))
264 settings->create_low_res_tiling = false;
265 if (cmd.HasSwitch(cc::switches::kEnableBeginFrameScheduling))
266 settings->use_external_begin_frame_source = true;
269 } // namespace blimp