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

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: Created 5 years, 3 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 } // namespace
52
53 namespace blimp {
54
55 // TODO(dtrainor): This is temporary to get the compositor up and running.
56 // Much of this will either have to be pulled from the server or refactored to
57 // share the settings from render_widget_compositor.cc.
58 void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings* settings,
59 const base::CommandLine& cmd) {
60 // For web contents, layer transforms should scale up the contents of layers
61 // to keep content always crisp when possible.
62 settings->layer_transforms_should_scale_layer_contents = true;
63
64 if (cmd.HasSwitch(switches::kDisableGpuVsync)) {
65 std::string display_vsync_string =
66 cmd.GetSwitchValueASCII(switches::kDisableGpuVsync);
67 if (display_vsync_string == "gpu") {
68 settings->renderer_settings.disable_display_vsync = true;
69 } else if (display_vsync_string == "beginframe") {
70 settings->wait_for_beginframe_interval = false;
71 } else {
72 settings->renderer_settings.disable_display_vsync = true;
73 settings->wait_for_beginframe_interval = false;
74 }
75 }
76 settings->main_frame_before_activation_enabled =
77 cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation) &&
78 !cmd.HasSwitch(cc::switches::kDisableMainFrameBeforeActivation);
79 settings->accelerated_animation_enabled =
80 !cmd.HasSwitch(cc::switches::kDisableThreadedAnimation);
81 settings->use_display_lists = cmd.HasSwitch(switches::kEnableSlimmingPaint);
82
83 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;
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);
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;
126 settings->use_distance_field_text =
127 cmd.HasSwitch(switches::kEnableDistanceFieldText);
128
129 settings->use_zero_copy = cmd.HasSwitch(switches::kEnableZeroCopy);
130 settings->use_one_copy = !cmd.HasSwitch(switches::kDisableOneCopy);
131 settings->enable_elastic_overscroll = false;
132
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);
138 }
139
140 settings->gather_pixel_refs = 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_pixel_refs = num_raster_threads > 1;
146 }
147
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;
155 }
156
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;
164 }
165
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;
171
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);
189
190 settings->initial_debug_state.SetRecordRenderingStats(
191 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking));
192
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);
200 }
201
202 settings->invert_viewport_scroll_order =
203 cmd.HasSwitch(switches::kInvertViewportScrollOrder);
204
205 if (cmd.HasSwitch(cc::switches::kMaxUnusedResourceMemoryUsagePercentage)) {
206 int max_unused_resource_memory_percentage;
207 if (GetSwitchValueAsInt(
208 cmd, cc::switches::kMaxUnusedResourceMemoryUsagePercentage, 0, 100,
209 &max_unused_resource_memory_percentage)) {
210 settings->max_unused_resource_memory_percentage =
211 max_unused_resource_memory_percentage;
212 }
213 }
214
215 settings->strict_layer_property_change_checking =
216 cmd.HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking);
217
218 #if defined(OS_ANDROID)
219 if (base::SysInfo::IsLowEndDevice())
220 settings->gpu_rasterization_enabled = false;
221 settings->using_synchronous_renderer_compositor = false;
222 settings->record_full_layer = false;
223 settings->max_partial_texture_updates = 0;
224 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
225 settings->scrollbar_fade_delay_ms = 300;
226 settings->scrollbar_fade_resize_delay_ms = 2000;
227 settings->scrollbar_fade_duration_ms = 300;
228 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
229 settings->renderer_settings.highp_threshold_min = 2048;
230 settings->ignore_root_layer_flings = false;
231 bool use_low_memory_policy = base::SysInfo::IsLowEndDevice();
232 settings->renderer_settings.use_rgba_4444_textures = use_low_memory_policy;
233 if (use_low_memory_policy) {
234 // On low-end we want to be very carefull about killing other
235 // apps. So initially we use 50% more memory to avoid flickering
236 // or raster-on-demand.
237 settings->max_memory_for_prepaint_percentage = 67;
238 } else {
239 // On other devices we have increased memory excessively to avoid
240 // raster-on-demand already, so now we reserve 50% _only_ to avoid
241 // raster-on-demand, and use 50% of the memory otherwise.
242 settings->max_memory_for_prepaint_percentage = 50;
243 }
244 settings->renderer_settings.should_clear_root_render_pass = true;
245
246 // TODO(danakj): Only do this on low end devices.
247 settings->create_low_res_tiling = true;
248
249 // TODO(dtrainor): Investigate whether or not we want to use an external
250 // source here.
251 // settings->use_external_begin_frame_source = true;
252
253 #elif !defined(OS_MACOSX)
254 if (ui::IsOverlayScrollbarEnabled()) {
255 settings->scrollbar_animator = cc::LayerTreeSettings::THINNING;
256 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
257 } else {
258 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
259 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
260 }
261 settings->scrollbar_fade_delay_ms = 500;
262 settings->scrollbar_fade_resize_delay_ms = 500;
263 settings->scrollbar_fade_duration_ms = 300;
264
265 // When pinching in, only show the pinch-viewport overlay scrollbars if the
266 // page scale is at least some threshold away from the minimum. i.e. don't
267 // show the pinch scrollbars when at minimum scale.
268 settings->scrollbar_show_scale_threshold = 1.05f;
269 #endif
270
271 if (cmd.HasSwitch(switches::kEnableLowResTiling))
272 settings->create_low_res_tiling = true;
273 if (cmd.HasSwitch(switches::kDisableLowResTiling))
274 settings->create_low_res_tiling = false;
275 if (cmd.HasSwitch(cc::switches::kEnableBeginFrameScheduling))
276 settings->use_external_begin_frame_source = true;
277 }
278
279 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698