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 } // 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 = *base::CommandLine::ForCurrentProcess(); |
| 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->enable_elastic_overscroll = false; |
| 131 |
| 132 if (cmd.HasSwitch(switches::kContentImageTextureTarget)) { |
| 133 settings->use_image_texture_targets.clear(); |
| 134 StringToUintVector( |
| 135 cmd.GetSwitchValueASCII(switches::kContentImageTextureTarget), |
| 136 &settings->use_image_texture_targets); |
| 137 } |
| 138 |
| 139 settings->gather_pixel_refs = false; |
| 140 if (cmd.HasSwitch(switches::kNumRasterThreads)) { |
| 141 int num_raster_threads = 0; |
| 142 GetSwitchValueAsInt(cmd, switches::kNumRasterThreads, 0, |
| 143 std::numeric_limits<int>::max(), &num_raster_threads); |
| 144 settings->gather_pixel_refs = num_raster_threads > 1; |
| 145 } |
| 146 |
| 147 if (cmd.HasSwitch(cc::switches::kTopControlsShowThreshold)) { |
| 148 std::string top_threshold_str = |
| 149 cmd.GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold); |
| 150 double show_threshold; |
| 151 if (base::StringToDouble(top_threshold_str, &show_threshold) && |
| 152 show_threshold >= 0.f && show_threshold <= 1.f) |
| 153 settings->top_controls_show_threshold = show_threshold; |
| 154 } |
| 155 |
| 156 if (cmd.HasSwitch(cc::switches::kTopControlsHideThreshold)) { |
| 157 std::string top_threshold_str = |
| 158 cmd.GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold); |
| 159 double hide_threshold; |
| 160 if (base::StringToDouble(top_threshold_str, &hide_threshold) && |
| 161 hide_threshold >= 0.f && hide_threshold <= 1.f) |
| 162 settings->top_controls_hide_threshold = hide_threshold; |
| 163 } |
| 164 |
| 165 settings->verify_property_trees = |
| 166 cmd.HasSwitch(cc::switches::kEnablePropertyTreeVerification); |
| 167 settings->renderer_settings.allow_antialiasing &= |
| 168 !cmd.HasSwitch(cc::switches::kDisableCompositedAntialiasing); |
| 169 settings->single_thread_proxy_scheduler = false; |
| 170 |
| 171 // These flags should be mirrored by UI versions in ui/compositor/. |
| 172 settings->initial_debug_state.show_debug_borders = |
| 173 cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders); |
| 174 settings->initial_debug_state.show_fps_counter = |
| 175 cmd.HasSwitch(cc::switches::kShowFPSCounter); |
| 176 settings->initial_debug_state.show_layer_animation_bounds_rects = |
| 177 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds); |
| 178 settings->initial_debug_state.show_paint_rects = |
| 179 cmd.HasSwitch(switches::kShowPaintRects); |
| 180 settings->initial_debug_state.show_property_changed_rects = |
| 181 cmd.HasSwitch(cc::switches::kShowPropertyChangedRects); |
| 182 settings->initial_debug_state.show_surface_damage_rects = |
| 183 cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects); |
| 184 settings->initial_debug_state.show_screen_space_rects = |
| 185 cmd.HasSwitch(cc::switches::kShowScreenSpaceRects); |
| 186 settings->initial_debug_state.show_replica_screen_space_rects = |
| 187 cmd.HasSwitch(cc::switches::kShowReplicaScreenSpaceRects); |
| 188 |
| 189 settings->initial_debug_state.SetRecordRenderingStats( |
| 190 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
| 191 |
| 192 if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) { |
| 193 const int kMinSlowDownScaleFactor = 0; |
| 194 const int kMaxSlowDownScaleFactor = INT_MAX; |
| 195 GetSwitchValueAsInt( |
| 196 cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor, |
| 197 kMaxSlowDownScaleFactor, |
| 198 &settings->initial_debug_state.slow_down_raster_scale_factor); |
| 199 } |
| 200 |
| 201 settings->invert_viewport_scroll_order = |
| 202 cmd.HasSwitch(switches::kInvertViewportScrollOrder); |
| 203 |
| 204 settings->strict_layer_property_change_checking = |
| 205 cmd.HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking); |
| 206 |
| 207 #if defined(OS_ANDROID) |
| 208 if (base::SysInfo::IsLowEndDevice()) |
| 209 settings->gpu_rasterization_enabled = false; |
| 210 settings->using_synchronous_renderer_compositor = false; |
| 211 settings->record_full_layer = false; |
| 212 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; |
| 213 settings->scrollbar_fade_delay_ms = 300; |
| 214 settings->scrollbar_fade_resize_delay_ms = 2000; |
| 215 settings->scrollbar_fade_duration_ms = 300; |
| 216 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); |
| 217 settings->renderer_settings.highp_threshold_min = 2048; |
| 218 settings->ignore_root_layer_flings = false; |
| 219 bool use_low_memory_policy = base::SysInfo::IsLowEndDevice(); |
| 220 settings->renderer_settings.use_rgba_4444_textures = use_low_memory_policy; |
| 221 if (use_low_memory_policy) { |
| 222 // On low-end we want to be very carefull about killing other |
| 223 // apps. So initially we use 50% more memory to avoid flickering |
| 224 // or raster-on-demand. |
| 225 settings->max_memory_for_prepaint_percentage = 67; |
| 226 } else { |
| 227 // On other devices we have increased memory excessively to avoid |
| 228 // raster-on-demand already, so now we reserve 50% _only_ to avoid |
| 229 // raster-on-demand, and use 50% of the memory otherwise. |
| 230 settings->max_memory_for_prepaint_percentage = 50; |
| 231 } |
| 232 settings->renderer_settings.should_clear_root_render_pass = true; |
| 233 |
| 234 // TODO(danakj): Only do this on low end devices. |
| 235 settings->create_low_res_tiling = true; |
| 236 |
| 237 // TODO(dtrainor): Investigate whether or not we want to use an external |
| 238 // source here. |
| 239 // settings->use_external_begin_frame_source = true; |
| 240 |
| 241 #elif !defined(OS_MACOSX) |
| 242 if (ui::IsOverlayScrollbarEnabled()) { |
| 243 settings->scrollbar_animator = cc::LayerTreeSettings::THINNING; |
| 244 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); |
| 245 } else { |
| 246 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; |
| 247 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); |
| 248 } |
| 249 settings->scrollbar_fade_delay_ms = 500; |
| 250 settings->scrollbar_fade_resize_delay_ms = 500; |
| 251 settings->scrollbar_fade_duration_ms = 300; |
| 252 |
| 253 // When pinching in, only show the pinch-viewport overlay scrollbars if the |
| 254 // page scale is at least some threshold away from the minimum. i.e. don't |
| 255 // show the pinch scrollbars when at minimum scale. |
| 256 settings->scrollbar_show_scale_threshold = 1.05f; |
| 257 #endif |
| 258 |
| 259 if (cmd.HasSwitch(switches::kEnableLowResTiling)) |
| 260 settings->create_low_res_tiling = true; |
| 261 if (cmd.HasSwitch(switches::kDisableLowResTiling)) |
| 262 settings->create_low_res_tiling = false; |
| 263 if (cmd.HasSwitch(cc::switches::kEnableBeginFrameScheduling)) |
| 264 settings->use_external_begin_frame_source = true; |
| 265 } |
| 266 |
| 267 } // namespace blimp |
OLD | NEW |