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

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

Issue 1420883006: Move blimp_layer_tree_settings.h/cc to client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaked a comment. Created 5 years, 1 month 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
« no previous file with comments | « blimp/common/compositor/blimp_layer_tree_settings.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
54 namespace blimp {
55
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;
64
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;
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);
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 #if defined(OS_MACOSX)
130 settings->use_zero_copy = !cmd.HasSwitch(switches::kDisableZeroCopy);
131 #else
132 settings->use_zero_copy = cmd.HasSwitch(switches::kEnableZeroCopy);
133 #endif
134
135 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;
145 if (cmd.HasSwitch(switches::kNumRasterThreads)) {
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;
175
176 // These flags should be mirrored by UI versions in ui/compositor/.
177 settings->initial_debug_state.show_debug_borders =
178 cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders);
179 settings->initial_debug_state.show_fps_counter =
180 cmd.HasSwitch(cc::switches::kShowFPSCounter);
181 settings->initial_debug_state.show_layer_animation_bounds_rects =
182 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds);
183 settings->initial_debug_state.show_paint_rects =
184 cmd.HasSwitch(switches::kShowPaintRects);
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
209 #if defined(OS_ANDROID)
210 if (base::SysInfo::IsLowEndDevice())
211 settings->gpu_rasterization_enabled = false;
212 settings->using_synchronous_renderer_compositor = false;
213 settings->record_full_layer = false;
214 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
215 settings->scrollbar_fade_delay_ms = 300;
216 settings->scrollbar_fade_resize_delay_ms = 2000;
217 settings->scrollbar_fade_duration_ms = 300;
218 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
219 settings->renderer_settings.highp_threshold_min = 2048;
220 settings->ignore_root_layer_flings = false;
221 bool use_low_memory_policy = base::SysInfo::IsLowEndDevice();
222 settings->renderer_settings.use_rgba_4444_textures = use_low_memory_policy;
223 if (use_low_memory_policy) {
224 // On low-end we want to be very carefull about killing other
225 // apps. So initially we use 50% more memory to avoid flickering
226 // or raster-on-demand.
227 settings->max_memory_for_prepaint_percentage = 67;
228 } else {
229 // On other devices we have increased memory excessively to avoid
230 // raster-on-demand already, so now we reserve 50% _only_ to avoid
231 // raster-on-demand, and use 50% of the memory otherwise.
232 settings->max_memory_for_prepaint_percentage = 50;
233 }
234 settings->renderer_settings.should_clear_root_render_pass = true;
235
236 // TODO(danakj): Only do this on low end devices.
237 settings->create_low_res_tiling = true;
238
239 // TODO(dtrainor): Investigate whether or not we want to use an external
240 // source here.
241 // settings->use_external_begin_frame_source = true;
242
243 #elif !defined(OS_MACOSX)
244 if (ui::IsOverlayScrollbarEnabled()) {
245 settings->scrollbar_animator = cc::LayerTreeSettings::THINNING;
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;
252 settings->scrollbar_fade_resize_delay_ms = 500;
253 settings->scrollbar_fade_duration_ms = 300;
254
255 // 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
257 // show the pinch scrollbars when at minimum scale.
258 // TODO(dtrainor): Update this since https://crrev.com/1267603004 landed.
259 // settings->scrollbar_show_scale_threshold = 1.05f;
260 #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 }
269
270 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/common/compositor/blimp_layer_tree_settings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698