OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "blimp/common/compositor/blimp_layer_tree_settings.h" | |
6 | |
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 | |
20 namespace { | |
21 | |
22 bool GetSwitchValueAsInt(const base::CommandLine& command_line, | |
23 const std::string& switch_string, | |
24 int min_value, | |
25 int max_value, | |
26 int* result) { | |
27 std::string string_value = command_line.GetSwitchValueASCII(switch_string); | |
28 int int_value; | |
29 if (base::StringToInt(string_value, &int_value) && int_value >= min_value && | |
30 int_value <= max_value) { | |
31 *result = int_value; | |
32 return true; | |
33 } else { | |
34 return false; | |
35 } | |
36 } | |
37 | |
38 void StringToUintVector(const std::string& str, std::vector<unsigned>* vector) { | |
39 DCHECK(vector->empty()); | |
40 std::vector<std::string> pieces = | |
41 base::SplitString(str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
42 DCHECK_EQ(pieces.size(), static_cast<size_t>(gfx::BufferFormat::LAST) + 1); | |
43 for (size_t i = 0; i < pieces.size(); ++i) { | |
44 unsigned number = 0; | |
45 bool succeed = base::StringToUint(pieces[i], &number); | |
46 DCHECK(succeed); | |
47 vector->push_back(number); | |
48 } | |
49 } | |
50 | |
51 bool GetSwitchValueAsUInt(const base::CommandLine& command_line, | |
52 const std::string& switch_string, | |
53 unsigned min_value, | |
54 unsigned max_value, | |
55 unsigned* result) { | |
56 std::string string_value = command_line.GetSwitchValueASCII(switch_string); | |
57 unsigned uint_value; | |
58 if (base::StringToUint(string_value, &uint_value) && | |
59 uint_value >= min_value && uint_value <= max_value) { | |
60 *result = uint_value; | |
61 return true; | |
62 } else { | |
63 return false; | |
64 } | |
65 } | |
66 | |
67 } // namespace | |
68 | |
69 namespace blimp { | |
70 | |
71 void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings& settings, | |
David Trainor- moved to gerrit
2015/08/21 00:50:53
I pulled most of this from RenderWidgetCompositor,
| |
72 const base::CommandLine& cmd) { | |
73 // For web contents, layer transforms should scale up the contents of layers | |
74 // to keep content always crisp when possible. | |
75 settings.layer_transforms_should_scale_layer_contents = true; | |
76 | |
77 if (cmd.HasSwitch(switches::kDisableGpuVsync)) { | |
78 std::string display_vsync_string = | |
79 cmd.GetSwitchValueASCII(switches::kDisableGpuVsync); | |
80 if (display_vsync_string == "gpu") { | |
81 settings.renderer_settings.disable_display_vsync = true; | |
82 } else if (display_vsync_string == "beginframe") { | |
83 settings.wait_for_beginframe_interval = false; | |
84 } else { | |
85 settings.renderer_settings.disable_display_vsync = true; | |
86 settings.wait_for_beginframe_interval = false; | |
87 } | |
88 } | |
89 settings.main_frame_before_activation_enabled = | |
90 cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation) && | |
91 !cmd.HasSwitch(cc::switches::kDisableMainFrameBeforeActivation); | |
92 settings.accelerated_animation_enabled = | |
93 !cmd.HasSwitch(cc::switches::kDisableThreadedAnimation); | |
94 settings.use_display_lists = cmd.HasSwitch(switches::kEnableSlimmingPaint); | |
95 // if (cmd.HasSwitch(switches::kEnableCompositorAnimationTimelines)) { | |
96 // settings.use_compositor_animation_timelines = true; | |
97 // blink::WebRuntimeFeatures::enableCompositorAnimationTimelines(true); | |
98 //} | |
99 | |
100 settings.default_tile_size = gfx::Size(256, 256); | |
101 if (cmd.HasSwitch(switches::kDefaultTileWidth)) { | |
102 int tile_width = 0; | |
103 GetSwitchValueAsInt(cmd, switches::kDefaultTileWidth, 1, | |
104 std::numeric_limits<int>::max(), &tile_width); | |
105 settings.default_tile_size.set_width(tile_width); | |
106 } | |
107 if (cmd.HasSwitch(switches::kDefaultTileHeight)) { | |
108 int tile_height = 0; | |
109 GetSwitchValueAsInt(cmd, switches::kDefaultTileHeight, 1, | |
110 std::numeric_limits<int>::max(), &tile_height); | |
111 settings.default_tile_size.set_height(tile_height); | |
112 } | |
113 | |
114 int max_untiled_layer_width = settings.max_untiled_layer_size.width(); | |
115 if (cmd.HasSwitch(switches::kMaxUntiledLayerWidth)) { | |
116 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerWidth, 1, | |
117 std::numeric_limits<int>::max(), | |
118 &max_untiled_layer_width); | |
119 } | |
120 int max_untiled_layer_height = settings.max_untiled_layer_size.height(); | |
121 if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) { | |
122 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerHeight, 1, | |
123 std::numeric_limits<int>::max(), | |
124 &max_untiled_layer_height); | |
125 } | |
126 | |
127 settings.max_untiled_layer_size = | |
128 gfx::Size(max_untiled_layer_width, max_untiled_layer_height); | |
129 | |
130 settings.gpu_rasterization_msaa_sample_count = 0; | |
131 if (cmd.HasSwitch(switches::kGpuRasterizationMSAASampleCount)) { | |
132 GetSwitchValueAsInt(cmd, switches::kGpuRasterizationMSAASampleCount, 0, | |
133 std::numeric_limits<int>::max(), | |
134 &settings.gpu_rasterization_msaa_sample_count); | |
135 } | |
136 | |
137 settings.gpu_rasterization_forced = | |
138 cmd.HasSwitch(switches::kForceGpuRasterization); | |
139 settings.gpu_rasterization_enabled = | |
140 cmd.HasSwitch(switches::kEnableGpuRasterization); | |
141 | |
142 settings.can_use_lcd_text = false; | |
143 settings.use_distance_field_text = | |
144 cmd.HasSwitch(switches::kEnableDistanceFieldText); | |
145 | |
146 settings.use_zero_copy = cmd.HasSwitch(switches::kEnableZeroCopy); | |
147 settings.use_one_copy = !cmd.HasSwitch(switches::kDisableOneCopy); | |
148 settings.enable_elastic_overscroll = false; | |
149 | |
150 if (cmd.HasSwitch(switches::kContentImageTextureTarget)) { | |
151 settings.use_image_texture_targets.clear(); | |
152 StringToUintVector( | |
153 cmd.GetSwitchValueASCII(switches::kContentImageTextureTarget), | |
154 &settings.use_image_texture_targets); | |
155 } | |
156 | |
157 settings.gather_pixel_refs = false; | |
158 if (cmd.HasSwitch(switches::kNumRasterThreads)) { | |
159 int num_raster_threads = 0; | |
160 GetSwitchValueAsInt(cmd, switches::kNumRasterThreads, 0, | |
161 std::numeric_limits<int>::max(), &num_raster_threads); | |
162 settings.gather_pixel_refs = num_raster_threads > 1; | |
163 } | |
164 | |
165 if (cmd.HasSwitch(cc::switches::kTopControlsShowThreshold)) { | |
166 std::string top_threshold_str = | |
167 cmd.GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold); | |
168 double show_threshold; | |
169 if (base::StringToDouble(top_threshold_str, &show_threshold) && | |
170 show_threshold >= 0.f && show_threshold <= 1.f) | |
171 settings.top_controls_show_threshold = show_threshold; | |
172 } | |
173 | |
174 if (cmd.HasSwitch(cc::switches::kTopControlsHideThreshold)) { | |
175 std::string top_threshold_str = | |
176 cmd.GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold); | |
177 double hide_threshold; | |
178 if (base::StringToDouble(top_threshold_str, &hide_threshold) && | |
179 hide_threshold >= 0.f && hide_threshold <= 1.f) | |
180 settings.top_controls_hide_threshold = hide_threshold; | |
181 } | |
182 | |
183 settings.verify_property_trees = | |
184 cmd.HasSwitch(cc::switches::kEnablePropertyTreeVerification); | |
185 settings.renderer_settings.allow_antialiasing &= | |
186 !cmd.HasSwitch(cc::switches::kDisableCompositedAntialiasing); | |
187 // The means the renderer compositor has 2 possible modes: | |
188 // - Threaded compositing with a scheduler. | |
189 // - Single threaded compositing without a scheduler (for layout tests only). | |
190 // Using the scheduler in layout tests introduces additional composite steps | |
191 // that create flakiness. | |
192 settings.single_thread_proxy_scheduler = false; | |
193 | |
194 // These flags should be mirrored by UI versions in ui/compositor/. | |
195 settings.initial_debug_state.show_debug_borders = | |
196 cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders); | |
197 settings.initial_debug_state.show_fps_counter = | |
198 cmd.HasSwitch(cc::switches::kShowFPSCounter); | |
199 settings.initial_debug_state.show_layer_animation_bounds_rects = | |
200 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds); | |
201 settings.initial_debug_state.show_paint_rects = | |
202 cmd.HasSwitch(switches::kShowPaintRects); | |
203 settings.initial_debug_state.show_property_changed_rects = | |
204 cmd.HasSwitch(cc::switches::kShowPropertyChangedRects); | |
205 settings.initial_debug_state.show_surface_damage_rects = | |
206 cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects); | |
207 settings.initial_debug_state.show_screen_space_rects = | |
208 cmd.HasSwitch(cc::switches::kShowScreenSpaceRects); | |
209 settings.initial_debug_state.show_replica_screen_space_rects = | |
210 cmd.HasSwitch(cc::switches::kShowReplicaScreenSpaceRects); | |
211 | |
212 settings.initial_debug_state.SetRecordRenderingStats( | |
213 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking)); | |
214 | |
215 if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) { | |
216 const int kMinSlowDownScaleFactor = 0; | |
217 const int kMaxSlowDownScaleFactor = INT_MAX; | |
218 GetSwitchValueAsInt( | |
219 cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor, | |
220 kMaxSlowDownScaleFactor, | |
221 &settings.initial_debug_state.slow_down_raster_scale_factor); | |
222 } | |
223 | |
224 settings.invert_viewport_scroll_order = | |
225 cmd.HasSwitch(switches::kInvertViewportScrollOrder); | |
226 | |
227 if (cmd.HasSwitch(cc::switches::kMaxUnusedResourceMemoryUsagePercentage)) { | |
228 int max_unused_resource_memory_percentage; | |
229 if (GetSwitchValueAsInt( | |
230 cmd, cc::switches::kMaxUnusedResourceMemoryUsagePercentage, 0, 100, | |
231 &max_unused_resource_memory_percentage)) { | |
232 settings.max_unused_resource_memory_percentage = | |
233 max_unused_resource_memory_percentage; | |
234 } | |
235 } | |
236 | |
237 settings.strict_layer_property_change_checking = | |
238 cmd.HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking); | |
239 | |
240 #if defined(OS_ANDROID) | |
241 bool has_synchronous_compositor_factory = false; | |
242 // SynchronousCompositorFactory* synchronous_compositor_factory = | |
243 // SynchronousCompositorFactory::GetInstance(); | |
244 | |
245 // We can't use GPU rasterization on low-end devices, because the Ganesh | |
246 // cache would consume too much memory. | |
247 if (base::SysInfo::IsLowEndDevice()) | |
248 settings.gpu_rasterization_enabled = false; | |
249 settings.using_synchronous_renderer_compositor = | |
250 has_synchronous_compositor_factory; | |
251 settings.record_full_layer = false; // widget_->DoesRecordFullLayer(); | |
252 settings.max_partial_texture_updates = 0; | |
253 if (has_synchronous_compositor_factory) { | |
254 // Android WebView uses system scrollbars, so make ours invisible. | |
255 settings.scrollbar_animator = cc::LayerTreeSettings::NO_ANIMATOR; | |
256 settings.solid_color_scrollbar_color = SK_ColorTRANSPARENT; | |
257 } else { | |
258 settings.scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; | |
259 settings.scrollbar_fade_delay_ms = 300; | |
260 settings.scrollbar_fade_resize_delay_ms = 2000; | |
261 settings.scrollbar_fade_duration_ms = 300; | |
262 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); | |
263 } | |
264 settings.renderer_settings.highp_threshold_min = 2048; | |
265 // Android WebView handles root layer flings itself. | |
266 settings.ignore_root_layer_flings = has_synchronous_compositor_factory; | |
267 // Memory policy on Android WebView does not depend on whether device is | |
268 // low end, so always use default policy. | |
269 bool use_low_memory_policy = | |
270 base::SysInfo::IsLowEndDevice() && !has_synchronous_compositor_factory; | |
271 // RGBA_4444 textures are only enabled for low end devices | |
272 // and are disabled for Android WebView as it doesn't support the format. | |
273 settings.renderer_settings.use_rgba_4444_textures = use_low_memory_policy; | |
274 if (use_low_memory_policy) { | |
275 // On low-end we want to be very carefull about killing other | |
276 // apps. So initially we use 50% more memory to avoid flickering | |
277 // or raster-on-demand. | |
278 settings.max_memory_for_prepaint_percentage = 67; | |
279 } else { | |
280 // On other devices we have increased memory excessively to avoid | |
281 // raster-on-demand already, so now we reserve 50% _only_ to avoid | |
282 // raster-on-demand, and use 50% of the memory otherwise. | |
283 settings.max_memory_for_prepaint_percentage = 50; | |
284 } | |
285 // Webview does not own the surface so should not clear it. | |
286 settings.renderer_settings.should_clear_root_render_pass = | |
287 !has_synchronous_compositor_factory; | |
288 | |
289 // TODO(danakj): Only do this on low end devices. | |
290 settings.create_low_res_tiling = true; | |
291 | |
292 // settings.use_external_begin_frame_source = true; | |
293 | |
294 #elif !defined(OS_MACOSX) | |
295 if (ui::IsOverlayScrollbarEnabled()) { | |
296 settings.scrollbar_animator = cc::LayerTreeSettings::THINNING; | |
297 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); | |
298 } else { | |
299 settings.scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; | |
300 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); | |
301 } | |
302 settings.scrollbar_fade_delay_ms = 500; | |
303 settings.scrollbar_fade_resize_delay_ms = 500; | |
304 settings.scrollbar_fade_duration_ms = 300; | |
305 | |
306 // When pinching in, only show the pinch-viewport overlay scrollbars if the | |
307 // page scale is at least some threshold away from the minimum. i.e. don't | |
308 // show the pinch scrollbars when at minimum scale. | |
309 settings.scrollbar_show_scale_threshold = 1.05f; | |
310 #endif | |
311 | |
312 if (cmd.HasSwitch(switches::kEnableLowResTiling)) | |
313 settings.create_low_res_tiling = true; | |
314 if (cmd.HasSwitch(switches::kDisableLowResTiling)) | |
315 settings.create_low_res_tiling = false; | |
316 if (cmd.HasSwitch(cc::switches::kEnableBeginFrameScheduling)) | |
317 settings.use_external_begin_frame_source = true; | |
318 } | |
319 | |
320 } // blimp | |
OLD | NEW |