Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: blimp/common/compositor/blimp_layer_tree_settings.cc

Issue 1295243003: Initial commit of the blimp/ folder and target (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some cleanup nits. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // TODO(dtrainor): This is temporary to get the compositor up and running.
72 // Much of this will either have to be pulled from the server or refactored to
73 // share the settings from render_widget_compositor.cc.
74 void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings& settings,
75 const base::CommandLine& cmd) {
76 // For web contents, layer transforms should scale up the contents of layers
77 // to keep content always crisp when possible.
78 settings.layer_transforms_should_scale_layer_contents = true;
79
80 if (cmd.HasSwitch(switches::kDisableGpuVsync)) {
81 std::string display_vsync_string =
82 cmd.GetSwitchValueASCII(switches::kDisableGpuVsync);
83 if (display_vsync_string == "gpu") {
84 settings.renderer_settings.disable_display_vsync = true;
85 } else if (display_vsync_string == "beginframe") {
86 settings.wait_for_beginframe_interval = false;
87 } else {
88 settings.renderer_settings.disable_display_vsync = true;
89 settings.wait_for_beginframe_interval = false;
90 }
91 }
92 settings.main_frame_before_activation_enabled =
93 cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation) &&
94 !cmd.HasSwitch(cc::switches::kDisableMainFrameBeforeActivation);
95 settings.accelerated_animation_enabled =
96 !cmd.HasSwitch(cc::switches::kDisableThreadedAnimation);
97 settings.use_display_lists = cmd.HasSwitch(switches::kEnableSlimmingPaint);
98
99 settings.default_tile_size = gfx::Size(256, 256);
100 if (cmd.HasSwitch(switches::kDefaultTileWidth)) {
101 int tile_width = 0;
102 GetSwitchValueAsInt(cmd, switches::kDefaultTileWidth, 1,
103 std::numeric_limits<int>::max(), &tile_width);
104 settings.default_tile_size.set_width(tile_width);
105 }
106 if (cmd.HasSwitch(switches::kDefaultTileHeight)) {
107 int tile_height = 0;
108 GetSwitchValueAsInt(cmd, switches::kDefaultTileHeight, 1,
109 std::numeric_limits<int>::max(), &tile_height);
110 settings.default_tile_size.set_height(tile_height);
111 }
112
113 int max_untiled_layer_width = settings.max_untiled_layer_size.width();
114 if (cmd.HasSwitch(switches::kMaxUntiledLayerWidth)) {
115 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerWidth, 1,
116 std::numeric_limits<int>::max(),
117 &max_untiled_layer_width);
118 }
119 int max_untiled_layer_height = settings.max_untiled_layer_size.height();
120 if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) {
121 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerHeight, 1,
122 std::numeric_limits<int>::max(),
123 &max_untiled_layer_height);
124 }
125
126 settings.max_untiled_layer_size =
127 gfx::Size(max_untiled_layer_width, max_untiled_layer_height);
128
129 settings.gpu_rasterization_msaa_sample_count = 0;
130 if (cmd.HasSwitch(switches::kGpuRasterizationMSAASampleCount)) {
131 GetSwitchValueAsInt(cmd, switches::kGpuRasterizationMSAASampleCount, 0,
132 std::numeric_limits<int>::max(),
133 &settings.gpu_rasterization_msaa_sample_count);
134 }
135
136 settings.gpu_rasterization_forced =
137 cmd.HasSwitch(switches::kForceGpuRasterization);
138 settings.gpu_rasterization_enabled =
139 cmd.HasSwitch(switches::kEnableGpuRasterization);
140
141 settings.can_use_lcd_text = false;
142 settings.use_distance_field_text =
143 cmd.HasSwitch(switches::kEnableDistanceFieldText);
144
145 settings.use_zero_copy = cmd.HasSwitch(switches::kEnableZeroCopy);
146 settings.use_one_copy = !cmd.HasSwitch(switches::kDisableOneCopy);
147 settings.enable_elastic_overscroll = false;
148
149 if (cmd.HasSwitch(switches::kContentImageTextureTarget)) {
150 settings.use_image_texture_targets.clear();
151 StringToUintVector(
152 cmd.GetSwitchValueASCII(switches::kContentImageTextureTarget),
153 &settings.use_image_texture_targets);
154 }
155
156 settings.gather_pixel_refs = false;
157 if (cmd.HasSwitch(switches::kNumRasterThreads)) {
158 int num_raster_threads = 0;
159 GetSwitchValueAsInt(cmd, switches::kNumRasterThreads, 0,
160 std::numeric_limits<int>::max(), &num_raster_threads);
161 settings.gather_pixel_refs = num_raster_threads > 1;
162 }
163
164 if (cmd.HasSwitch(cc::switches::kTopControlsShowThreshold)) {
165 std::string top_threshold_str =
166 cmd.GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold);
167 double show_threshold;
168 if (base::StringToDouble(top_threshold_str, &show_threshold) &&
169 show_threshold >= 0.f && show_threshold <= 1.f)
170 settings.top_controls_show_threshold = show_threshold;
171 }
172
173 if (cmd.HasSwitch(cc::switches::kTopControlsHideThreshold)) {
174 std::string top_threshold_str =
175 cmd.GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold);
176 double hide_threshold;
177 if (base::StringToDouble(top_threshold_str, &hide_threshold) &&
178 hide_threshold >= 0.f && hide_threshold <= 1.f)
179 settings.top_controls_hide_threshold = hide_threshold;
180 }
181
182 settings.verify_property_trees =
183 cmd.HasSwitch(cc::switches::kEnablePropertyTreeVerification);
184 settings.renderer_settings.allow_antialiasing &=
185 !cmd.HasSwitch(cc::switches::kDisableCompositedAntialiasing);
186 settings.single_thread_proxy_scheduler = false;
187
188 // These flags should be mirrored by UI versions in ui/compositor/.
189 settings.initial_debug_state.show_debug_borders =
190 cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders);
191 settings.initial_debug_state.show_fps_counter =
192 cmd.HasSwitch(cc::switches::kShowFPSCounter);
193 settings.initial_debug_state.show_layer_animation_bounds_rects =
194 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds);
195 settings.initial_debug_state.show_paint_rects =
196 cmd.HasSwitch(switches::kShowPaintRects);
197 settings.initial_debug_state.show_property_changed_rects =
198 cmd.HasSwitch(cc::switches::kShowPropertyChangedRects);
199 settings.initial_debug_state.show_surface_damage_rects =
200 cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects);
201 settings.initial_debug_state.show_screen_space_rects =
202 cmd.HasSwitch(cc::switches::kShowScreenSpaceRects);
203 settings.initial_debug_state.show_replica_screen_space_rects =
204 cmd.HasSwitch(cc::switches::kShowReplicaScreenSpaceRects);
205
206 settings.initial_debug_state.SetRecordRenderingStats(
207 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking));
208
209 if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) {
210 const int kMinSlowDownScaleFactor = 0;
211 const int kMaxSlowDownScaleFactor = INT_MAX;
212 GetSwitchValueAsInt(
213 cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor,
214 kMaxSlowDownScaleFactor,
215 &settings.initial_debug_state.slow_down_raster_scale_factor);
216 }
217
218 settings.invert_viewport_scroll_order =
219 cmd.HasSwitch(switches::kInvertViewportScrollOrder);
220
221 if (cmd.HasSwitch(cc::switches::kMaxUnusedResourceMemoryUsagePercentage)) {
222 int max_unused_resource_memory_percentage;
223 if (GetSwitchValueAsInt(
224 cmd, cc::switches::kMaxUnusedResourceMemoryUsagePercentage, 0, 100,
225 &max_unused_resource_memory_percentage)) {
226 settings.max_unused_resource_memory_percentage =
227 max_unused_resource_memory_percentage;
228 }
229 }
230
231 settings.strict_layer_property_change_checking =
232 cmd.HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking);
233
234 #if defined(OS_ANDROID)
235 if (base::SysInfo::IsLowEndDevice())
236 settings.gpu_rasterization_enabled = false;
237 settings.using_synchronous_renderer_compositor = false;
238 settings.record_full_layer = false;
239 settings.max_partial_texture_updates = 0;
240 settings.scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
241 settings.scrollbar_fade_delay_ms = 300;
242 settings.scrollbar_fade_resize_delay_ms = 2000;
243 settings.scrollbar_fade_duration_ms = 300;
244 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
245 settings.renderer_settings.highp_threshold_min = 2048;
246 settings.ignore_root_layer_flings = false;
247 bool use_low_memory_policy = base::SysInfo::IsLowEndDevice();
248 settings.renderer_settings.use_rgba_4444_textures = use_low_memory_policy;
249 if (use_low_memory_policy) {
250 // On low-end we want to be very carefull about killing other
251 // apps. So initially we use 50% more memory to avoid flickering
252 // or raster-on-demand.
253 settings.max_memory_for_prepaint_percentage = 67;
254 } else {
255 // On other devices we have increased memory excessively to avoid
256 // raster-on-demand already, so now we reserve 50% _only_ to avoid
257 // raster-on-demand, and use 50% of the memory otherwise.
258 settings.max_memory_for_prepaint_percentage = 50;
259 }
260 settings.renderer_settings.should_clear_root_render_pass = true;
261
262 // TODO(danakj): Only do this on low end devices.
263 settings.create_low_res_tiling = true;
264
265 // TODO(dtrainor): Investigate whether or not we want to use an external
266 // source here.
267 // settings.use_external_begin_frame_source = true;
268
269 #elif !defined(OS_MACOSX)
270 if (ui::IsOverlayScrollbarEnabled()) {
271 settings.scrollbar_animator = cc::LayerTreeSettings::THINNING;
272 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
273 } else {
274 settings.scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
275 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
276 }
277 settings.scrollbar_fade_delay_ms = 500;
278 settings.scrollbar_fade_resize_delay_ms = 500;
279 settings.scrollbar_fade_duration_ms = 300;
280
281 // When pinching in, only show the pinch-viewport overlay scrollbars if the
282 // page scale is at least some threshold away from the minimum. i.e. don't
283 // show the pinch scrollbars when at minimum scale.
284 settings.scrollbar_show_scale_threshold = 1.05f;
285 #endif
286
287 if (cmd.HasSwitch(switches::kEnableLowResTiling))
288 settings.create_low_res_tiling = true;
289 if (cmd.HasSwitch(switches::kDisableLowResTiling))
290 settings.create_low_res_tiling = false;
291 if (cmd.HasSwitch(cc::switches::kEnableBeginFrameScheduling))
292 settings.use_external_begin_frame_source = true;
293 }
294
295 } // blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698