| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/renderer/gpu/render_widget_compositor.h" | 5 #include "content/renderer/gpu/render_widget_compositor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 compositor->Initialize(device_scale_factor); | 214 compositor->Initialize(device_scale_factor); |
| 215 return compositor; | 215 return compositor; |
| 216 } | 216 } |
| 217 | 217 |
| 218 RenderWidgetCompositor::RenderWidgetCompositor( | 218 RenderWidgetCompositor::RenderWidgetCompositor( |
| 219 RenderWidgetCompositorDelegate* delegate, | 219 RenderWidgetCompositorDelegate* delegate, |
| 220 CompositorDependencies* compositor_deps) | 220 CompositorDependencies* compositor_deps) |
| 221 : num_failed_recreate_attempts_(0), | 221 : num_failed_recreate_attempts_(0), |
| 222 delegate_(delegate), | 222 delegate_(delegate), |
| 223 compositor_deps_(compositor_deps), | 223 compositor_deps_(compositor_deps), |
| 224 threaded_(!!compositor_deps_->GetCompositorImplThreadTaskRunner()), |
| 224 never_visible_(false), | 225 never_visible_(false), |
| 225 layout_and_paint_async_callback_(nullptr), | 226 layout_and_paint_async_callback_(nullptr), |
| 226 remote_proto_channel_receiver_(nullptr), | 227 remote_proto_channel_receiver_(nullptr), |
| 227 weak_factory_(this) {} | 228 weak_factory_(this) {} |
| 228 | 229 |
| 229 void RenderWidgetCompositor::Initialize(float device_scale_factor) { | 230 void RenderWidgetCompositor::Initialize(float device_scale_factor) { |
| 230 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | 231 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 232 cc::LayerTreeSettings settings = |
| 233 GenerateLayerTreeSettings(*cmd, compositor_deps_, device_scale_factor); |
| 234 cc::LayerTreeHost::InitParams params; |
| 235 params.client = this; |
| 236 params.shared_bitmap_manager = compositor_deps_->GetSharedBitmapManager(); |
| 237 params.gpu_memory_buffer_manager = |
| 238 compositor_deps_->GetGpuMemoryBufferManager(); |
| 239 params.settings = &settings; |
| 240 params.task_graph_runner = compositor_deps_->GetTaskGraphRunner(); |
| 241 params.main_task_runner = |
| 242 compositor_deps_->GetCompositorMainThreadTaskRunner(); |
| 243 if (settings.use_external_begin_frame_source) { |
| 244 params.external_begin_frame_source = |
| 245 delegate_->CreateExternalBeginFrameSource(); |
| 246 } |
| 247 params.animation_host = cc::AnimationHost::CreateMainInstance(); |
| 231 | 248 |
| 249 if (cmd->HasSwitch(switches::kUseRemoteCompositing)) { |
| 250 DCHECK(!threaded_); |
| 251 params.image_serialization_processor = |
| 252 compositor_deps_->GetImageSerializationProcessor(); |
| 253 layer_tree_host_ = cc::LayerTreeHost::CreateRemoteServer(this, ¶ms); |
| 254 } else if (!threaded_) { |
| 255 // Single-threaded layout tests. |
| 256 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
| 257 } else { |
| 258 layer_tree_host_ = cc::LayerTreeHost::CreateThreaded( |
| 259 compositor_deps_->GetCompositorImplThreadTaskRunner(), ¶ms); |
| 260 } |
| 261 DCHECK(layer_tree_host_); |
| 262 } |
| 263 |
| 264 RenderWidgetCompositor::~RenderWidgetCompositor() = default; |
| 265 |
| 266 // static |
| 267 cc::LayerTreeSettings RenderWidgetCompositor::GenerateLayerTreeSettings( |
| 268 const base::CommandLine& cmd, |
| 269 CompositorDependencies* compositor_deps, |
| 270 float device_scale_factor) { |
| 232 cc::LayerTreeSettings settings; | 271 cc::LayerTreeSettings settings; |
| 233 | 272 |
| 234 // For web contents, layer transforms should scale up the contents of layers | 273 // For web contents, layer transforms should scale up the contents of layers |
| 235 // to keep content always crisp when possible. | 274 // to keep content always crisp when possible. |
| 236 settings.layer_transforms_should_scale_layer_contents = true; | 275 settings.layer_transforms_should_scale_layer_contents = true; |
| 237 | 276 |
| 238 if (cmd->HasSwitch(switches::kDisableGpuVsync)) { | 277 if (cmd.HasSwitch(switches::kDisableGpuVsync)) { |
| 239 std::string display_vsync_string = | 278 std::string display_vsync_string = |
| 240 cmd->GetSwitchValueASCII(switches::kDisableGpuVsync); | 279 cmd.GetSwitchValueASCII(switches::kDisableGpuVsync); |
| 241 if (display_vsync_string == "gpu") { | 280 if (display_vsync_string == "gpu") { |
| 242 settings.renderer_settings.disable_display_vsync = true; | 281 settings.renderer_settings.disable_display_vsync = true; |
| 243 } else if (display_vsync_string == "beginframe") { | 282 } else if (display_vsync_string == "beginframe") { |
| 244 settings.wait_for_beginframe_interval = false; | 283 settings.wait_for_beginframe_interval = false; |
| 245 } else { | 284 } else { |
| 246 settings.renderer_settings.disable_display_vsync = true; | 285 settings.renderer_settings.disable_display_vsync = true; |
| 247 settings.wait_for_beginframe_interval = false; | 286 settings.wait_for_beginframe_interval = false; |
| 248 } | 287 } |
| 249 } | 288 } |
| 250 settings.main_frame_before_activation_enabled = | 289 settings.main_frame_before_activation_enabled = |
| 251 cmd->HasSwitch(cc::switches::kEnableMainFrameBeforeActivation); | 290 cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation); |
| 252 | 291 |
| 292 // TODO(danakj): This should not be a setting O_O; it should change when the |
| 293 // device scale factor on LayerTreeHost changes. |
| 253 settings.default_tile_size = CalculateDefaultTileSize(device_scale_factor); | 294 settings.default_tile_size = CalculateDefaultTileSize(device_scale_factor); |
| 254 if (cmd->HasSwitch(switches::kDefaultTileWidth)) { | 295 if (cmd.HasSwitch(switches::kDefaultTileWidth)) { |
| 255 int tile_width = 0; | 296 int tile_width = 0; |
| 256 GetSwitchValueAsInt(*cmd, | 297 GetSwitchValueAsInt(cmd, switches::kDefaultTileWidth, 1, |
| 257 switches::kDefaultTileWidth, | 298 std::numeric_limits<int>::max(), &tile_width); |
| 258 1, | |
| 259 std::numeric_limits<int>::max(), | |
| 260 &tile_width); | |
| 261 settings.default_tile_size.set_width(tile_width); | 299 settings.default_tile_size.set_width(tile_width); |
| 262 } | 300 } |
| 263 if (cmd->HasSwitch(switches::kDefaultTileHeight)) { | 301 if (cmd.HasSwitch(switches::kDefaultTileHeight)) { |
| 264 int tile_height = 0; | 302 int tile_height = 0; |
| 265 GetSwitchValueAsInt(*cmd, | 303 GetSwitchValueAsInt(cmd, switches::kDefaultTileHeight, 1, |
| 266 switches::kDefaultTileHeight, | 304 std::numeric_limits<int>::max(), &tile_height); |
| 267 1, | |
| 268 std::numeric_limits<int>::max(), | |
| 269 &tile_height); | |
| 270 settings.default_tile_size.set_height(tile_height); | 305 settings.default_tile_size.set_height(tile_height); |
| 271 } | 306 } |
| 272 | 307 |
| 273 int max_untiled_layer_width = settings.max_untiled_layer_size.width(); | 308 int max_untiled_layer_width = settings.max_untiled_layer_size.width(); |
| 274 if (cmd->HasSwitch(switches::kMaxUntiledLayerWidth)) { | 309 if (cmd.HasSwitch(switches::kMaxUntiledLayerWidth)) { |
| 275 GetSwitchValueAsInt(*cmd, switches::kMaxUntiledLayerWidth, 1, | 310 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerWidth, 1, |
| 276 std::numeric_limits<int>::max(), | 311 std::numeric_limits<int>::max(), |
| 277 &max_untiled_layer_width); | 312 &max_untiled_layer_width); |
| 278 } | 313 } |
| 279 int max_untiled_layer_height = settings.max_untiled_layer_size.height(); | 314 int max_untiled_layer_height = settings.max_untiled_layer_size.height(); |
| 280 if (cmd->HasSwitch(switches::kMaxUntiledLayerHeight)) { | 315 if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) { |
| 281 GetSwitchValueAsInt(*cmd, switches::kMaxUntiledLayerHeight, 1, | 316 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerHeight, 1, |
| 282 std::numeric_limits<int>::max(), | 317 std::numeric_limits<int>::max(), |
| 283 &max_untiled_layer_height); | 318 &max_untiled_layer_height); |
| 284 } | 319 } |
| 285 | 320 |
| 286 settings.max_untiled_layer_size = gfx::Size(max_untiled_layer_width, | 321 settings.max_untiled_layer_size = gfx::Size(max_untiled_layer_width, |
| 287 max_untiled_layer_height); | 322 max_untiled_layer_height); |
| 288 | 323 |
| 289 settings.gpu_rasterization_msaa_sample_count = | 324 settings.gpu_rasterization_msaa_sample_count = |
| 290 compositor_deps_->GetGpuRasterizationMSAASampleCount(); | 325 compositor_deps->GetGpuRasterizationMSAASampleCount(); |
| 291 settings.gpu_rasterization_forced = | 326 settings.gpu_rasterization_forced = |
| 292 compositor_deps_->IsGpuRasterizationForced(); | 327 compositor_deps->IsGpuRasterizationForced(); |
| 293 settings.gpu_rasterization_enabled = | 328 settings.gpu_rasterization_enabled = |
| 294 compositor_deps_->IsGpuRasterizationEnabled(); | 329 compositor_deps->IsGpuRasterizationEnabled(); |
| 295 settings.async_worker_context_enabled = | 330 settings.async_worker_context_enabled = |
| 296 compositor_deps_->IsAsyncWorkerContextEnabled(); | 331 compositor_deps->IsAsyncWorkerContextEnabled(); |
| 297 | 332 |
| 298 settings.can_use_lcd_text = compositor_deps_->IsLcdTextEnabled(); | 333 settings.can_use_lcd_text = compositor_deps->IsLcdTextEnabled(); |
| 299 settings.use_distance_field_text = | 334 settings.use_distance_field_text = |
| 300 compositor_deps_->IsDistanceFieldTextEnabled(); | 335 compositor_deps->IsDistanceFieldTextEnabled(); |
| 301 settings.use_zero_copy = compositor_deps_->IsZeroCopyEnabled(); | 336 settings.use_zero_copy = compositor_deps->IsZeroCopyEnabled(); |
| 302 settings.use_partial_raster = compositor_deps_->IsPartialRasterEnabled(); | 337 settings.use_partial_raster = compositor_deps->IsPartialRasterEnabled(); |
| 303 settings.enable_elastic_overscroll = | 338 settings.enable_elastic_overscroll = |
| 304 compositor_deps_->IsElasticOverscrollEnabled(); | 339 compositor_deps->IsElasticOverscrollEnabled(); |
| 305 settings.renderer_settings.use_gpu_memory_buffer_resources = | 340 settings.renderer_settings.use_gpu_memory_buffer_resources = |
| 306 compositor_deps_->IsGpuMemoryBufferCompositorResourcesEnabled(); | 341 compositor_deps->IsGpuMemoryBufferCompositorResourcesEnabled(); |
| 307 settings.use_image_texture_targets = | 342 settings.use_image_texture_targets = |
| 308 compositor_deps_->GetImageTextureTargets(); | 343 compositor_deps->GetImageTextureTargets(); |
| 309 settings.image_decode_tasks_enabled = | 344 settings.image_decode_tasks_enabled = |
| 310 compositor_deps_->AreImageDecodeTasksEnabled(); | 345 compositor_deps->AreImageDecodeTasksEnabled(); |
| 311 | 346 |
| 312 if (cmd->HasSwitch(cc::switches::kTopControlsShowThreshold)) { | 347 if (cmd.HasSwitch(cc::switches::kTopControlsShowThreshold)) { |
| 313 std::string top_threshold_str = | 348 std::string top_threshold_str = |
| 314 cmd->GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold); | 349 cmd.GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold); |
| 315 double show_threshold; | 350 double show_threshold; |
| 316 if (base::StringToDouble(top_threshold_str, &show_threshold) && | 351 if (base::StringToDouble(top_threshold_str, &show_threshold) && |
| 317 show_threshold >= 0.f && show_threshold <= 1.f) | 352 show_threshold >= 0.f && show_threshold <= 1.f) |
| 318 settings.top_controls_show_threshold = show_threshold; | 353 settings.top_controls_show_threshold = show_threshold; |
| 319 } | 354 } |
| 320 | 355 |
| 321 if (cmd->HasSwitch(cc::switches::kTopControlsHideThreshold)) { | 356 if (cmd.HasSwitch(cc::switches::kTopControlsHideThreshold)) { |
| 322 std::string top_threshold_str = | 357 std::string top_threshold_str = |
| 323 cmd->GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold); | 358 cmd.GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold); |
| 324 double hide_threshold; | 359 double hide_threshold; |
| 325 if (base::StringToDouble(top_threshold_str, &hide_threshold) && | 360 if (base::StringToDouble(top_threshold_str, &hide_threshold) && |
| 326 hide_threshold >= 0.f && hide_threshold <= 1.f) | 361 hide_threshold >= 0.f && hide_threshold <= 1.f) |
| 327 settings.top_controls_hide_threshold = hide_threshold; | 362 settings.top_controls_hide_threshold = hide_threshold; |
| 328 } | 363 } |
| 329 | 364 |
| 330 settings.use_layer_lists = cmd->HasSwitch(cc::switches::kEnableLayerLists); | 365 settings.use_layer_lists = cmd.HasSwitch(cc::switches::kEnableLayerLists); |
| 331 | 366 |
| 332 settings.renderer_settings.allow_antialiasing &= | 367 settings.renderer_settings.allow_antialiasing &= |
| 333 !cmd->HasSwitch(cc::switches::kDisableCompositedAntialiasing); | 368 !cmd.HasSwitch(cc::switches::kDisableCompositedAntialiasing); |
| 334 // The means the renderer compositor has 2 possible modes: | 369 // The means the renderer compositor has 2 possible modes: |
| 335 // - Threaded compositing with a scheduler. | 370 // - Threaded compositing with a scheduler. |
| 336 // - Single threaded compositing without a scheduler (for layout tests only). | 371 // - Single threaded compositing without a scheduler (for layout tests only). |
| 337 // Using the scheduler in layout tests introduces additional composite steps | 372 // Using the scheduler in layout tests introduces additional composite steps |
| 338 // that create flakiness. | 373 // that create flakiness. |
| 339 settings.single_thread_proxy_scheduler = false; | 374 settings.single_thread_proxy_scheduler = false; |
| 340 | 375 |
| 341 // These flags should be mirrored by UI versions in ui/compositor/. | 376 // These flags should be mirrored by UI versions in ui/compositor/. |
| 342 settings.initial_debug_state.show_debug_borders = | 377 settings.initial_debug_state.show_debug_borders = |
| 343 cmd->HasSwitch(cc::switches::kShowCompositedLayerBorders); | 378 cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders); |
| 344 settings.initial_debug_state.show_layer_animation_bounds_rects = | 379 settings.initial_debug_state.show_layer_animation_bounds_rects = |
| 345 cmd->HasSwitch(cc::switches::kShowLayerAnimationBounds); | 380 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds); |
| 346 settings.initial_debug_state.show_paint_rects = | 381 settings.initial_debug_state.show_paint_rects = |
| 347 cmd->HasSwitch(switches::kShowPaintRects); | 382 cmd.HasSwitch(switches::kShowPaintRects); |
| 348 settings.initial_debug_state.show_property_changed_rects = | 383 settings.initial_debug_state.show_property_changed_rects = |
| 349 cmd->HasSwitch(cc::switches::kShowPropertyChangedRects); | 384 cmd.HasSwitch(cc::switches::kShowPropertyChangedRects); |
| 350 settings.initial_debug_state.show_surface_damage_rects = | 385 settings.initial_debug_state.show_surface_damage_rects = |
| 351 cmd->HasSwitch(cc::switches::kShowSurfaceDamageRects); | 386 cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects); |
| 352 settings.initial_debug_state.show_screen_space_rects = | 387 settings.initial_debug_state.show_screen_space_rects = |
| 353 cmd->HasSwitch(cc::switches::kShowScreenSpaceRects); | 388 cmd.HasSwitch(cc::switches::kShowScreenSpaceRects); |
| 354 settings.initial_debug_state.show_replica_screen_space_rects = | 389 settings.initial_debug_state.show_replica_screen_space_rects = |
| 355 cmd->HasSwitch(cc::switches::kShowReplicaScreenSpaceRects); | 390 cmd.HasSwitch(cc::switches::kShowReplicaScreenSpaceRects); |
| 356 | 391 |
| 357 settings.initial_debug_state.SetRecordRenderingStats( | 392 settings.initial_debug_state.SetRecordRenderingStats( |
| 358 cmd->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 393 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
| 359 | 394 |
| 360 if (cmd->HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) { | 395 if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) { |
| 361 const int kMinSlowDownScaleFactor = 0; | 396 const int kMinSlowDownScaleFactor = 0; |
| 362 const int kMaxSlowDownScaleFactor = INT_MAX; | 397 const int kMaxSlowDownScaleFactor = INT_MAX; |
| 363 GetSwitchValueAsInt( | 398 GetSwitchValueAsInt( |
| 364 *cmd, | 399 cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor, |
| 365 cc::switches::kSlowDownRasterScaleFactor, | |
| 366 kMinSlowDownScaleFactor, | |
| 367 kMaxSlowDownScaleFactor, | 400 kMaxSlowDownScaleFactor, |
| 368 &settings.initial_debug_state.slow_down_raster_scale_factor); | 401 &settings.initial_debug_state.slow_down_raster_scale_factor); |
| 369 } | 402 } |
| 370 | 403 |
| 371 #if defined(OS_ANDROID) | 404 #if defined(OS_ANDROID) |
| 372 bool using_synchronous_compositor = | 405 bool using_synchronous_compositor = |
| 373 GetContentClient()->UsingSynchronousCompositing(); | 406 GetContentClient()->UsingSynchronousCompositing(); |
| 374 | 407 |
| 375 // We can't use GPU rasterization on low-end devices, because the Ganesh | 408 // We can't use GPU rasterization on low-end devices, because the Ganesh |
| 376 // cache would consume too much memory. | 409 // cache would consume too much memory. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 396 bool use_low_memory_policy = | 429 bool use_low_memory_policy = |
| 397 base::SysInfo::IsLowEndDevice() && !using_synchronous_compositor; | 430 base::SysInfo::IsLowEndDevice() && !using_synchronous_compositor; |
| 398 if (use_low_memory_policy) { | 431 if (use_low_memory_policy) { |
| 399 // On low-end we want to be very carefull about killing other | 432 // On low-end we want to be very carefull about killing other |
| 400 // apps. So initially we use 50% more memory to avoid flickering | 433 // apps. So initially we use 50% more memory to avoid flickering |
| 401 // or raster-on-demand. | 434 // or raster-on-demand. |
| 402 settings.max_memory_for_prepaint_percentage = 67; | 435 settings.max_memory_for_prepaint_percentage = 67; |
| 403 | 436 |
| 404 // RGBA_4444 textures are only enabled by default for low end devices | 437 // RGBA_4444 textures are only enabled by default for low end devices |
| 405 // and are disabled for Android WebView as it doesn't support the format. | 438 // and are disabled for Android WebView as it doesn't support the format. |
| 406 if (!cmd->HasSwitch(switches::kDisableRGBA4444Textures)) | 439 if (!cmd.HasSwitch(switches::kDisableRGBA4444Textures)) |
| 407 settings.renderer_settings.preferred_tile_format = cc::RGBA_4444; | 440 settings.renderer_settings.preferred_tile_format = cc::RGBA_4444; |
| 408 } else { | 441 } else { |
| 409 // On other devices we have increased memory excessively to avoid | 442 // On other devices we have increased memory excessively to avoid |
| 410 // raster-on-demand already, so now we reserve 50% _only_ to avoid | 443 // raster-on-demand already, so now we reserve 50% _only_ to avoid |
| 411 // raster-on-demand, and use 50% of the memory otherwise. | 444 // raster-on-demand, and use 50% of the memory otherwise. |
| 412 settings.max_memory_for_prepaint_percentage = 50; | 445 settings.max_memory_for_prepaint_percentage = 50; |
| 413 } | 446 } |
| 414 // Webview does not own the surface so should not clear it. | 447 // Webview does not own the surface so should not clear it. |
| 415 settings.renderer_settings.should_clear_root_render_pass = | 448 settings.renderer_settings.should_clear_root_render_pass = |
| 416 !using_synchronous_compositor; | 449 !using_synchronous_compositor; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 442 settings.gpu_decoded_image_budget_bytes = 256 * 1024 * 1024; | 475 settings.gpu_decoded_image_budget_bytes = 256 * 1024 * 1024; |
| 443 settings.software_decoded_image_budget_bytes = 256 * 1024 * 1024; | 476 settings.software_decoded_image_budget_bytes = 256 * 1024 * 1024; |
| 444 } else { | 477 } else { |
| 445 // These are the defaults, but recorded here as well. | 478 // These are the defaults, but recorded here as well. |
| 446 settings.gpu_decoded_image_budget_bytes = 96 * 1024 * 1024; | 479 settings.gpu_decoded_image_budget_bytes = 96 * 1024 * 1024; |
| 447 settings.software_decoded_image_budget_bytes = 128 * 1024 * 1024; | 480 settings.software_decoded_image_budget_bytes = 128 * 1024 * 1024; |
| 448 } | 481 } |
| 449 | 482 |
| 450 #endif // defined(OS_ANDROID) | 483 #endif // defined(OS_ANDROID) |
| 451 | 484 |
| 452 if (cmd->HasSwitch(switches::kEnableLowResTiling)) | 485 if (cmd.HasSwitch(switches::kEnableLowResTiling)) |
| 453 settings.create_low_res_tiling = true; | 486 settings.create_low_res_tiling = true; |
| 454 if (cmd->HasSwitch(switches::kDisableLowResTiling)) | 487 if (cmd.HasSwitch(switches::kDisableLowResTiling)) |
| 455 settings.create_low_res_tiling = false; | 488 settings.create_low_res_tiling = false; |
| 456 if (cmd->HasSwitch(cc::switches::kEnableBeginFrameScheduling)) | 489 if (cmd.HasSwitch(cc::switches::kEnableBeginFrameScheduling)) |
| 457 settings.use_external_begin_frame_source = true; | 490 settings.use_external_begin_frame_source = true; |
| 458 | 491 |
| 459 if (cmd->HasSwitch(switches::kEnableRGBA4444Textures) && | 492 if (cmd.HasSwitch(switches::kEnableRGBA4444Textures) && |
| 460 !cmd->HasSwitch(switches::kDisableRGBA4444Textures)) { | 493 !cmd.HasSwitch(switches::kDisableRGBA4444Textures)) { |
| 461 settings.renderer_settings.preferred_tile_format = cc::RGBA_4444; | 494 settings.renderer_settings.preferred_tile_format = cc::RGBA_4444; |
| 462 } | 495 } |
| 463 | 496 |
| 464 if (cmd->HasSwitch(cc::switches::kEnableTileCompression)) { | 497 if (cmd.HasSwitch(cc::switches::kEnableTileCompression)) { |
| 465 settings.renderer_settings.preferred_tile_format = cc::ETC1; | 498 settings.renderer_settings.preferred_tile_format = cc::ETC1; |
| 466 } | 499 } |
| 467 | 500 |
| 468 settings.max_staging_buffer_usage_in_bytes = 32 * 1024 * 1024; // 32MB | 501 settings.max_staging_buffer_usage_in_bytes = 32 * 1024 * 1024; // 32MB |
| 469 // Use 1/4th of staging buffers on low-end devices. | 502 // Use 1/4th of staging buffers on low-end devices. |
| 470 if (base::SysInfo::IsLowEndDevice()) | 503 if (base::SysInfo::IsLowEndDevice()) |
| 471 settings.max_staging_buffer_usage_in_bytes /= 4; | 504 settings.max_staging_buffer_usage_in_bytes /= 4; |
| 472 | 505 |
| 473 cc::ManagedMemoryPolicy current = settings.memory_policy_; | 506 cc::ManagedMemoryPolicy current = settings.memory_policy_; |
| 474 settings.memory_policy_ = GetGpuMemoryPolicy(current); | 507 settings.memory_policy_ = GetGpuMemoryPolicy(current); |
| 475 | 508 |
| 476 settings.use_cached_picture_raster = !cmd->HasSwitch( | 509 settings.use_cached_picture_raster = |
| 477 cc::switches::kDisableCachedPictureRaster); | 510 !cmd.HasSwitch(cc::switches::kDisableCachedPictureRaster); |
| 478 | 511 |
| 479 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = | 512 if (cmd.HasSwitch(switches::kUseRemoteCompositing)) |
| 480 compositor_deps_->GetCompositorImplThreadTaskRunner(); | |
| 481 scoped_refptr<base::SingleThreadTaskRunner> | |
| 482 main_thread_compositor_task_runner = | |
| 483 compositor_deps_->GetCompositorMainThreadTaskRunner(); | |
| 484 cc::SharedBitmapManager* shared_bitmap_manager = | |
| 485 compositor_deps_->GetSharedBitmapManager(); | |
| 486 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = | |
| 487 compositor_deps_->GetGpuMemoryBufferManager(); | |
| 488 cc::TaskGraphRunner* task_graph_runner = | |
| 489 compositor_deps_->GetTaskGraphRunner(); | |
| 490 | |
| 491 bool use_remote_compositing = cmd->HasSwitch(switches::kUseRemoteCompositing); | |
| 492 | |
| 493 if (use_remote_compositing) | |
| 494 settings.use_external_begin_frame_source = false; | 513 settings.use_external_begin_frame_source = false; |
| 495 | 514 |
| 496 std::unique_ptr<cc::BeginFrameSource> external_begin_frame_source; | 515 return settings; |
| 497 if (settings.use_external_begin_frame_source) { | 516 } |
| 498 external_begin_frame_source = delegate_->CreateExternalBeginFrameSource(); | 517 |
| 518 // static |
| 519 cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy( |
| 520 const cc::ManagedMemoryPolicy& policy) { |
| 521 cc::ManagedMemoryPolicy actual = policy; |
| 522 actual.bytes_limit_when_visible = 0; |
| 523 |
| 524 // If the value was overridden on the command line, use the specified value. |
| 525 static bool client_hard_limit_bytes_overridden = |
| 526 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 527 switches::kForceGpuMemAvailableMb); |
| 528 if (client_hard_limit_bytes_overridden) { |
| 529 if (base::StringToSizeT( |
| 530 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 531 switches::kForceGpuMemAvailableMb), |
| 532 &actual.bytes_limit_when_visible)) |
| 533 actual.bytes_limit_when_visible *= 1024 * 1024; |
| 534 return actual; |
| 499 } | 535 } |
| 500 | 536 |
| 501 cc::LayerTreeHost::InitParams params; | 537 #if defined(OS_ANDROID) |
| 502 params.client = this; | 538 // We can't query available GPU memory from the system on Android. |
| 503 params.shared_bitmap_manager = shared_bitmap_manager; | 539 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports |
| 504 params.gpu_memory_buffer_manager = gpu_memory_buffer_manager; | 540 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports |
| 505 params.settings = &settings; | 541 // 128MB java heap size). First we estimate physical memory using both. |
| 506 params.task_graph_runner = task_graph_runner; | 542 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); |
| 507 params.main_task_runner = main_thread_compositor_task_runner; | 543 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); |
| 508 params.external_begin_frame_source = std::move(external_begin_frame_source); | 544 size_t physical_memory_mb = 0; |
| 509 params.animation_host = cc::AnimationHost::CreateMainInstance(); | 545 if (dalvik_mb >= 256) |
| 510 if (use_remote_compositing) { | 546 physical_memory_mb = dalvik_mb * 4; |
| 511 DCHECK(!compositor_thread_task_runner.get()); | 547 else |
| 512 params.image_serialization_processor = | 548 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); |
| 513 compositor_deps_->GetImageSerializationProcessor(); | 549 |
| 514 layer_tree_host_ = cc::LayerTreeHost::CreateRemoteServer(this, ¶ms); | 550 // Now we take a default of 1/8th of memory on high-memory devices, |
| 515 } else if (compositor_thread_task_runner.get()) { | 551 // and gradually scale that back for low-memory devices (to be nicer |
| 516 layer_tree_host_ = cc::LayerTreeHost::CreateThreaded( | 552 // to other apps so they don't get killed). Examples: |
| 517 compositor_thread_task_runner, ¶ms); | 553 // Nexus 4/10(2GB) 256MB (normally 128MB) |
| 518 } else { | 554 // Droid Razr M(1GB) 114MB (normally 57MB) |
| 519 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 555 // Galaxy Nexus(1GB) 100MB (normally 50MB) |
| 556 // Xoom(1GB) 100MB (normally 50MB) |
| 557 // Nexus S(low-end) 8MB (normally 8MB) |
| 558 // Note that the compositor now uses only some of this memory for |
| 559 // pre-painting and uses the rest only for 'emergencies'. |
| 560 if (actual.bytes_limit_when_visible == 0) { |
| 561 // NOTE: Non-low-end devices use only 50% of these limits, |
| 562 // except during 'emergencies' where 100% can be used. |
| 563 if (!base::SysInfo::IsLowEndDevice()) { |
| 564 if (physical_memory_mb >= 1536) |
| 565 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB |
| 566 else if (physical_memory_mb >= 1152) |
| 567 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB |
| 568 else if (physical_memory_mb >= 768) |
| 569 actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB |
| 570 else |
| 571 actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB |
| 572 } else { |
| 573 // Low-end devices have 512MB or less memory by definition |
| 574 // so we hard code the limit rather than relying on the heuristics |
| 575 // above. Low-end devices use 4444 textures so we can use a lower limit. |
| 576 actual.bytes_limit_when_visible = 8; |
| 577 } |
| 578 actual.bytes_limit_when_visible = |
| 579 actual.bytes_limit_when_visible * 1024 * 1024; |
| 580 // Clamp the observed value to a specific range on Android. |
| 581 actual.bytes_limit_when_visible = std::max( |
| 582 actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024)); |
| 583 actual.bytes_limit_when_visible = |
| 584 std::min(actual.bytes_limit_when_visible, |
| 585 static_cast<size_t>(256 * 1024 * 1024)); |
| 520 } | 586 } |
| 521 DCHECK(layer_tree_host_); | 587 actual.priority_cutoff_when_visible = |
| 588 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; |
| 589 #else |
| 590 // Ignore what the system said and give all clients the same maximum |
| 591 // allocation on desktop platforms. |
| 592 actual.bytes_limit_when_visible = 512 * 1024 * 1024; |
| 593 actual.priority_cutoff_when_visible = |
| 594 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 595 #endif |
| 596 return actual; |
| 522 } | 597 } |
| 523 | 598 |
| 524 RenderWidgetCompositor::~RenderWidgetCompositor() {} | |
| 525 | |
| 526 void RenderWidgetCompositor::SetNeverVisible() { | 599 void RenderWidgetCompositor::SetNeverVisible() { |
| 527 DCHECK(!layer_tree_host_->visible()); | 600 DCHECK(!layer_tree_host_->visible()); |
| 528 never_visible_ = true; | 601 never_visible_ = true; |
| 529 } | 602 } |
| 530 | 603 |
| 531 const base::WeakPtr<cc::InputHandler>& | 604 const base::WeakPtr<cc::InputHandler>& |
| 532 RenderWidgetCompositor::GetInputHandler() { | 605 RenderWidgetCompositor::GetInputHandler() { |
| 533 return layer_tree_host_->GetInputHandler(); | 606 return layer_tree_host_->GetInputHandler(); |
| 534 } | 607 } |
| 535 | 608 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 std::unique_ptr<cc::CopyOutputResult> result) { | 879 std::unique_ptr<cc::CopyOutputResult> result) { |
| 807 if (result->HasBitmap()) { | 880 if (result->HasBitmap()) { |
| 808 std::unique_ptr<SkBitmap> result_bitmap = result->TakeBitmap(); | 881 std::unique_ptr<SkBitmap> result_bitmap = result->TakeBitmap(); |
| 809 callback->didCompositeAndReadback(*result_bitmap); | 882 callback->didCompositeAndReadback(*result_bitmap); |
| 810 } else { | 883 } else { |
| 811 callback->didCompositeAndReadback(SkBitmap()); | 884 callback->didCompositeAndReadback(SkBitmap()); |
| 812 } | 885 } |
| 813 } | 886 } |
| 814 | 887 |
| 815 bool RenderWidgetCompositor::CompositeIsSynchronous() const { | 888 bool RenderWidgetCompositor::CompositeIsSynchronous() const { |
| 816 return !compositor_deps_->GetCompositorImplThreadTaskRunner().get() && | 889 if (!threaded_) { |
| 817 !layer_tree_host_->settings().single_thread_proxy_scheduler; | 890 DCHECK(!layer_tree_host_->settings().single_thread_proxy_scheduler); |
| 891 return true; |
| 892 } |
| 893 return false; |
| 818 } | 894 } |
| 819 | 895 |
| 820 void RenderWidgetCompositor::layoutAndPaintAsync( | 896 void RenderWidgetCompositor::layoutAndPaintAsync( |
| 821 blink::WebLayoutAndPaintAsyncCallback* callback) { | 897 blink::WebLayoutAndPaintAsyncCallback* callback) { |
| 822 DCHECK(!temporary_copy_output_request_ && !layout_and_paint_async_callback_); | 898 DCHECK(!temporary_copy_output_request_ && !layout_and_paint_async_callback_); |
| 823 layout_and_paint_async_callback_ = callback; | 899 layout_and_paint_async_callback_ = callback; |
| 824 | 900 |
| 825 if (CompositeIsSynchronous()) { | 901 if (CompositeIsSynchronous()) { |
| 826 base::ThreadTaskRunnerHandle::Get()->PostTask( | 902 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 827 FROM_HERE, base::Bind(&RenderWidgetCompositor::LayoutAndUpdateLayers, | 903 FROM_HERE, base::Bind(&RenderWidgetCompositor::LayoutAndUpdateLayers, |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 delegate_->DidCommitCompositorFrame(); | 1085 delegate_->DidCommitCompositorFrame(); |
| 1010 compositor_deps_->GetRendererScheduler()->DidCommitFrameToCompositor(); | 1086 compositor_deps_->GetRendererScheduler()->DidCommitFrameToCompositor(); |
| 1011 } | 1087 } |
| 1012 | 1088 |
| 1013 void RenderWidgetCompositor::DidCommitAndDrawFrame() { | 1089 void RenderWidgetCompositor::DidCommitAndDrawFrame() { |
| 1014 delegate_->DidCommitAndDrawCompositorFrame(); | 1090 delegate_->DidCommitAndDrawCompositorFrame(); |
| 1015 } | 1091 } |
| 1016 | 1092 |
| 1017 void RenderWidgetCompositor::DidCompleteSwapBuffers() { | 1093 void RenderWidgetCompositor::DidCompleteSwapBuffers() { |
| 1018 delegate_->DidCompleteSwapBuffers(); | 1094 delegate_->DidCompleteSwapBuffers(); |
| 1019 bool threaded = !!compositor_deps_->GetCompositorImplThreadTaskRunner().get(); | 1095 if (!threaded_) |
| 1020 if (!threaded) | |
| 1021 delegate_->OnSwapBuffersComplete(); | 1096 delegate_->OnSwapBuffersComplete(); |
| 1022 } | 1097 } |
| 1023 | 1098 |
| 1024 void RenderWidgetCompositor::DidCompletePageScaleAnimation() { | 1099 void RenderWidgetCompositor::DidCompletePageScaleAnimation() { |
| 1025 delegate_->DidCompletePageScaleAnimation(); | 1100 delegate_->DidCompletePageScaleAnimation(); |
| 1026 } | 1101 } |
| 1027 | 1102 |
| 1028 void RenderWidgetCompositor::RequestScheduleAnimation() { | 1103 void RenderWidgetCompositor::RequestScheduleAnimation() { |
| 1029 delegate_->RequestScheduleAnimation(); | 1104 delegate_->RequestScheduleAnimation(); |
| 1030 } | 1105 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 new cc::proto::CompositorMessage); | 1138 new cc::proto::CompositorMessage); |
| 1064 int signed_size = base::checked_cast<int>(proto.size()); | 1139 int signed_size = base::checked_cast<int>(proto.size()); |
| 1065 if (!deserialized->ParseFromArray(proto.data(), signed_size)) { | 1140 if (!deserialized->ParseFromArray(proto.data(), signed_size)) { |
| 1066 LOG(ERROR) << "Unable to parse compositor proto."; | 1141 LOG(ERROR) << "Unable to parse compositor proto."; |
| 1067 return; | 1142 return; |
| 1068 } | 1143 } |
| 1069 | 1144 |
| 1070 remote_proto_channel_receiver_->OnProtoReceived(std::move(deserialized)); | 1145 remote_proto_channel_receiver_->OnProtoReceived(std::move(deserialized)); |
| 1071 } | 1146 } |
| 1072 | 1147 |
| 1073 cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy( | |
| 1074 const cc::ManagedMemoryPolicy& policy) { | |
| 1075 cc::ManagedMemoryPolicy actual = policy; | |
| 1076 actual.bytes_limit_when_visible = 0; | |
| 1077 | |
| 1078 // If the value was overridden on the command line, use the specified value. | |
| 1079 static bool client_hard_limit_bytes_overridden = | |
| 1080 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1081 switches::kForceGpuMemAvailableMb); | |
| 1082 if (client_hard_limit_bytes_overridden) { | |
| 1083 if (base::StringToSizeT( | |
| 1084 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 1085 switches::kForceGpuMemAvailableMb), | |
| 1086 &actual.bytes_limit_when_visible)) | |
| 1087 actual.bytes_limit_when_visible *= 1024 * 1024; | |
| 1088 return actual; | |
| 1089 } | |
| 1090 | |
| 1091 #if defined(OS_ANDROID) | |
| 1092 // We can't query available GPU memory from the system on Android. | |
| 1093 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports | |
| 1094 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports | |
| 1095 // 128MB java heap size). First we estimate physical memory using both. | |
| 1096 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); | |
| 1097 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); | |
| 1098 size_t physical_memory_mb = 0; | |
| 1099 if (dalvik_mb >= 256) | |
| 1100 physical_memory_mb = dalvik_mb * 4; | |
| 1101 else | |
| 1102 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); | |
| 1103 | |
| 1104 // Now we take a default of 1/8th of memory on high-memory devices, | |
| 1105 // and gradually scale that back for low-memory devices (to be nicer | |
| 1106 // to other apps so they don't get killed). Examples: | |
| 1107 // Nexus 4/10(2GB) 256MB (normally 128MB) | |
| 1108 // Droid Razr M(1GB) 114MB (normally 57MB) | |
| 1109 // Galaxy Nexus(1GB) 100MB (normally 50MB) | |
| 1110 // Xoom(1GB) 100MB (normally 50MB) | |
| 1111 // Nexus S(low-end) 8MB (normally 8MB) | |
| 1112 // Note that the compositor now uses only some of this memory for | |
| 1113 // pre-painting and uses the rest only for 'emergencies'. | |
| 1114 if (actual.bytes_limit_when_visible == 0) { | |
| 1115 // NOTE: Non-low-end devices use only 50% of these limits, | |
| 1116 // except during 'emergencies' where 100% can be used. | |
| 1117 if (!base::SysInfo::IsLowEndDevice()) { | |
| 1118 if (physical_memory_mb >= 1536) | |
| 1119 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB | |
| 1120 else if (physical_memory_mb >= 1152) | |
| 1121 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB | |
| 1122 else if (physical_memory_mb >= 768) | |
| 1123 actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB | |
| 1124 else | |
| 1125 actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB | |
| 1126 } else { | |
| 1127 // Low-end devices have 512MB or less memory by definition | |
| 1128 // so we hard code the limit rather than relying on the heuristics | |
| 1129 // above. Low-end devices use 4444 textures so we can use a lower limit. | |
| 1130 actual.bytes_limit_when_visible = 8; | |
| 1131 } | |
| 1132 actual.bytes_limit_when_visible = | |
| 1133 actual.bytes_limit_when_visible * 1024 * 1024; | |
| 1134 // Clamp the observed value to a specific range on Android. | |
| 1135 actual.bytes_limit_when_visible = std::max( | |
| 1136 actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024)); | |
| 1137 actual.bytes_limit_when_visible = | |
| 1138 std::min(actual.bytes_limit_when_visible, | |
| 1139 static_cast<size_t>(256 * 1024 * 1024)); | |
| 1140 } | |
| 1141 actual.priority_cutoff_when_visible = | |
| 1142 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; | |
| 1143 #else | |
| 1144 // Ignore what the system said and give all clients the same maximum | |
| 1145 // allocation on desktop platforms. | |
| 1146 actual.bytes_limit_when_visible = 512 * 1024 * 1024; | |
| 1147 actual.priority_cutoff_when_visible = | |
| 1148 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | |
| 1149 #endif | |
| 1150 return actual; | |
| 1151 } | |
| 1152 | |
| 1153 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( | 1148 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( |
| 1154 float device_scale) { | 1149 float device_scale) { |
| 1155 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); | 1150 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); |
| 1156 } | 1151 } |
| 1157 | 1152 |
| 1158 } // namespace content | 1153 } // namespace content |
| OLD | NEW |