OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "blimp/client/compositor/blimp_layer_tree_settings.h" | 5 #include "blimp/client/compositor/blimp_layer_tree_settings.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
13 #include "cc/base/switches.h" | 13 #include "cc/base/switches.h" |
14 #include "cc/trees/layer_tree_settings.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" | 15 #include "third_party/skia/include/core/SkColor.h" |
17 #include "ui/gfx/buffer_types.h" | 16 #include "ui/gfx/buffer_types.h" |
18 #include "ui/gl/gl_switches.h" | 17 #include "ui/gl/gl_switches.h" |
19 #include "ui/native_theme/native_theme_switches.h" | |
20 | |
21 namespace { | |
22 | |
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; | |
36 } | |
37 } | |
38 | |
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); | |
49 } | |
50 } | |
51 | |
52 } // namespace | |
53 | 18 |
54 namespace blimp { | 19 namespace blimp { |
55 | 20 |
56 // TODO(dtrainor): This is temporary to get the compositor up and running. | 21 // 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 | 22 // Much of this will either have to be pulled from the server or refactored to |
58 // share the settings from render_widget_compositor.cc. | 23 // share the settings from render_widget_compositor.cc. |
59 void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings* settings) { | 24 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 | 25 // For web contents, layer transforms should scale up the contents of layers |
62 // to keep content always crisp when possible. | 26 // to keep content always crisp when possible. |
63 settings->layer_transforms_should_scale_layer_contents = true; | 27 settings->layer_transforms_should_scale_layer_contents = true; |
64 | 28 |
65 if (cmd.HasSwitch(switches::kDisableGpuVsync)) { | 29 settings->main_frame_before_activation_enabled = false; |
66 std::string display_vsync_string = | 30 settings->accelerated_animation_enabled = true; |
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; | |
75 } | |
76 } | |
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 | |
83 settings->default_tile_size = gfx::Size(256, 256); | 31 settings->default_tile_size = gfx::Size(256, 256); |
84 if (cmd.HasSwitch(switches::kDefaultTileWidth)) { | |
85 int tile_width = 0; | |
86 GetSwitchValueAsInt(cmd, switches::kDefaultTileWidth, 1, | |
87 std::numeric_limits<int>::max(), &tile_width); | |
88 settings->default_tile_size.set_width(tile_width); | |
89 } | |
90 if (cmd.HasSwitch(switches::kDefaultTileHeight)) { | |
91 int tile_height = 0; | |
92 GetSwitchValueAsInt(cmd, switches::kDefaultTileHeight, 1, | |
93 std::numeric_limits<int>::max(), &tile_height); | |
94 settings->default_tile_size.set_height(tile_height); | |
95 } | |
96 | |
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); | |
102 } | |
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); | |
108 } | |
109 | |
110 settings->max_untiled_layer_size = | |
111 gfx::Size(max_untiled_layer_width, max_untiled_layer_height); | |
112 | |
113 settings->gpu_rasterization_msaa_sample_count = 0; | 32 settings->gpu_rasterization_msaa_sample_count = 0; |
114 if (cmd.HasSwitch(switches::kGpuRasterizationMSAASampleCount)) { | 33 settings->gpu_rasterization_forced = false; |
115 GetSwitchValueAsInt(cmd, switches::kGpuRasterizationMSAASampleCount, 0, | 34 settings->gpu_rasterization_enabled = false; |
116 std::numeric_limits<int>::max(), | |
117 &settings->gpu_rasterization_msaa_sample_count); | |
118 } | |
119 | |
120 settings->gpu_rasterization_forced = | |
121 cmd.HasSwitch(switches::kForceGpuRasterization); | |
122 settings->gpu_rasterization_enabled = | |
123 cmd.HasSwitch(switches::kEnableGpuRasterization); | |
124 | |
125 settings->can_use_lcd_text = false; | 35 settings->can_use_lcd_text = false; |
126 settings->use_distance_field_text = | 36 settings->use_distance_field_text = false; |
127 cmd.HasSwitch(switches::kEnableDistanceFieldText); | |
128 | |
129 #if defined(OS_MACOSX) | 37 #if defined(OS_MACOSX) |
130 settings->use_zero_copy = !cmd.HasSwitch(switches::kDisableZeroCopy); | 38 settings->use_zero_copy = true; |
131 #else | 39 #else |
132 settings->use_zero_copy = cmd.HasSwitch(switches::kEnableZeroCopy); | 40 settings->use_zero_copy = false; |
133 #endif | 41 #endif |
134 | |
135 settings->enable_elastic_overscroll = false; | 42 settings->enable_elastic_overscroll = false; |
136 | |
137 if (cmd.HasSwitch(switches::kContentImageTextureTarget)) { | |
138 settings->use_image_texture_targets.clear(); | |
139 StringToUintVector( | |
140 cmd.GetSwitchValueASCII(switches::kContentImageTextureTarget), | |
141 &settings->use_image_texture_targets); | |
142 } | |
143 | |
144 settings->image_decode_tasks_enabled = false; | 43 settings->image_decode_tasks_enabled = false; |
145 if (cmd.HasSwitch(switches::kNumRasterThreads)) { | 44 settings->verify_property_trees = false; |
146 int num_raster_threads = 0; | |
147 GetSwitchValueAsInt(cmd, switches::kNumRasterThreads, 0, | |
148 std::numeric_limits<int>::max(), &num_raster_threads); | |
149 settings->image_decode_tasks_enabled = num_raster_threads > 1; | |
150 } | |
151 | |
152 if (cmd.HasSwitch(cc::switches::kTopControlsShowThreshold)) { | |
153 std::string top_threshold_str = | |
154 cmd.GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold); | |
155 double show_threshold; | |
156 if (base::StringToDouble(top_threshold_str, &show_threshold) && | |
157 show_threshold >= 0.f && show_threshold <= 1.f) | |
158 settings->top_controls_show_threshold = show_threshold; | |
159 } | |
160 | |
161 if (cmd.HasSwitch(cc::switches::kTopControlsHideThreshold)) { | |
162 std::string top_threshold_str = | |
163 cmd.GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold); | |
164 double hide_threshold; | |
165 if (base::StringToDouble(top_threshold_str, &hide_threshold) && | |
166 hide_threshold >= 0.f && hide_threshold <= 1.f) | |
167 settings->top_controls_hide_threshold = hide_threshold; | |
168 } | |
169 | |
170 settings->verify_property_trees = | |
171 cmd.HasSwitch(cc::switches::kEnablePropertyTreeVerification); | |
172 settings->renderer_settings.allow_antialiasing &= | |
173 !cmd.HasSwitch(cc::switches::kDisableCompositedAntialiasing); | |
174 settings->single_thread_proxy_scheduler = false; | 45 settings->single_thread_proxy_scheduler = false; |
175 | 46 settings->initial_debug_state.show_debug_borders = false; |
176 // These flags should be mirrored by UI versions in ui/compositor/. | 47 settings->initial_debug_state.show_fps_counter = false; |
177 settings->initial_debug_state.show_debug_borders = | 48 settings->initial_debug_state.show_layer_animation_bounds_rects = false; |
178 cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders); | 49 settings->initial_debug_state.show_paint_rects = false; |
179 settings->initial_debug_state.show_fps_counter = | 50 settings->initial_debug_state.show_property_changed_rects = false; |
180 cmd.HasSwitch(cc::switches::kShowFPSCounter); | 51 settings->initial_debug_state.show_surface_damage_rects = false; |
181 settings->initial_debug_state.show_layer_animation_bounds_rects = | 52 settings->initial_debug_state.show_screen_space_rects = false; |
182 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds); | 53 settings->initial_debug_state.show_replica_screen_space_rects = false; |
183 settings->initial_debug_state.show_paint_rects = | 54 settings->initial_debug_state.SetRecordRenderingStats(false); |
184 cmd.HasSwitch(switches::kShowPaintRects); | 55 settings->strict_layer_property_change_checking = false; |
185 settings->initial_debug_state.show_property_changed_rects = | |
186 cmd.HasSwitch(cc::switches::kShowPropertyChangedRects); | |
187 settings->initial_debug_state.show_surface_damage_rects = | |
188 cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects); | |
189 settings->initial_debug_state.show_screen_space_rects = | |
190 cmd.HasSwitch(cc::switches::kShowScreenSpaceRects); | |
191 settings->initial_debug_state.show_replica_screen_space_rects = | |
192 cmd.HasSwitch(cc::switches::kShowReplicaScreenSpaceRects); | |
193 | |
194 settings->initial_debug_state.SetRecordRenderingStats( | |
195 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking)); | |
196 | |
197 if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) { | |
198 const int kMinSlowDownScaleFactor = 0; | |
199 const int kMaxSlowDownScaleFactor = INT_MAX; | |
200 GetSwitchValueAsInt( | |
201 cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor, | |
202 kMaxSlowDownScaleFactor, | |
203 &settings->initial_debug_state.slow_down_raster_scale_factor); | |
204 } | |
205 | |
206 settings->strict_layer_property_change_checking = | |
207 cmd.HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking); | |
208 | 56 |
209 #if defined(OS_ANDROID) | 57 #if defined(OS_ANDROID) |
210 if (base::SysInfo::IsLowEndDevice()) | 58 if (base::SysInfo::IsLowEndDevice()) |
211 settings->gpu_rasterization_enabled = false; | 59 settings->gpu_rasterization_enabled = false; |
212 settings->using_synchronous_renderer_compositor = false; | 60 settings->using_synchronous_renderer_compositor = false; |
213 settings->record_full_layer = false; | 61 settings->record_full_layer = false; |
214 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; | 62 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; |
215 settings->scrollbar_fade_delay_ms = 300; | 63 settings->scrollbar_fade_delay_ms = 300; |
216 settings->scrollbar_fade_resize_delay_ms = 2000; | 64 settings->scrollbar_fade_resize_delay_ms = 2000; |
217 settings->scrollbar_fade_duration_ms = 300; | 65 settings->scrollbar_fade_duration_ms = 300; |
(...skipping 16 matching lines...) Expand all Loading... |
234 settings->renderer_settings.should_clear_root_render_pass = true; | 82 settings->renderer_settings.should_clear_root_render_pass = true; |
235 | 83 |
236 // TODO(danakj): Only do this on low end devices. | 84 // TODO(danakj): Only do this on low end devices. |
237 settings->create_low_res_tiling = true; | 85 settings->create_low_res_tiling = true; |
238 | 86 |
239 // TODO(dtrainor): Investigate whether or not we want to use an external | 87 // TODO(dtrainor): Investigate whether or not we want to use an external |
240 // source here. | 88 // source here. |
241 // settings->use_external_begin_frame_source = true; | 89 // settings->use_external_begin_frame_source = true; |
242 | 90 |
243 #elif !defined(OS_MACOSX) | 91 #elif !defined(OS_MACOSX) |
244 if (ui::IsOverlayScrollbarEnabled()) { | 92 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; |
245 settings->scrollbar_animator = cc::LayerTreeSettings::THINNING; | 93 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); |
246 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); | |
247 } else { | |
248 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; | |
249 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); | |
250 } | |
251 settings->scrollbar_fade_delay_ms = 500; | 94 settings->scrollbar_fade_delay_ms = 500; |
252 settings->scrollbar_fade_resize_delay_ms = 500; | 95 settings->scrollbar_fade_resize_delay_ms = 500; |
253 settings->scrollbar_fade_duration_ms = 300; | 96 settings->scrollbar_fade_duration_ms = 300; |
254 | 97 |
255 // When pinching in, only show the pinch-viewport overlay scrollbars if the | 98 // When pinching in, only show the pinch-viewport overlay scrollbars if the |
256 // page scale is at least some threshold away from the minimum. i.e. don't | 99 // page scale is at least some threshold away from the minimum. i.e. don't |
257 // show the pinch scrollbars when at minimum scale. | 100 // show the pinch scrollbars when at minimum scale. |
258 // TODO(dtrainor): Update this since https://crrev.com/1267603004 landed. | 101 // TODO(dtrainor): Update this since https://crrev.com/1267603004 landed. |
259 // settings->scrollbar_show_scale_threshold = 1.05f; | 102 // settings->scrollbar_show_scale_threshold = 1.05f; |
260 #endif | 103 #endif |
261 | |
262 if (cmd.HasSwitch(switches::kEnableLowResTiling)) | |
263 settings->create_low_res_tiling = true; | |
264 if (cmd.HasSwitch(switches::kDisableLowResTiling)) | |
265 settings->create_low_res_tiling = false; | |
266 if (cmd.HasSwitch(cc::switches::kEnableBeginFrameScheduling)) | |
267 settings->use_external_begin_frame_source = true; | |
268 } | 104 } |
269 | 105 |
270 } // namespace blimp | 106 } // namespace blimp |
OLD | NEW |