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 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <limits> | 10 #include <limits> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 namespace content { | 86 namespace content { |
87 namespace { | 87 namespace { |
88 | 88 |
89 bool GetSwitchValueAsInt(const base::CommandLine& command_line, | 89 bool GetSwitchValueAsInt(const base::CommandLine& command_line, |
90 const std::string& switch_string, | 90 const std::string& switch_string, |
91 int min_value, | 91 int min_value, |
92 int max_value, | 92 int max_value, |
93 int* result) { | 93 int* result) { |
94 std::string string_value = command_line.GetSwitchValueASCII(switch_string); | 94 std::string string_value = command_line.GetSwitchValueASCII(switch_string); |
95 int int_value; | 95 int int_value; |
96 if (base::StringToInt(string_value, &int_value) && | 96 if (base::StringToInt(string_value, &int_value) && int_value >= min_value && |
97 int_value >= min_value && int_value <= max_value) { | 97 int_value <= max_value) { |
98 *result = int_value; | 98 *result = int_value; |
99 return true; | 99 return true; |
100 } else { | 100 } else { |
101 LOG(WARNING) << "Failed to parse switch " << switch_string << ": " << | 101 LOG(WARNING) << "Failed to parse switch " << switch_string << ": " |
102 string_value; | 102 << string_value; |
103 return false; | 103 return false; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 cc::LayerSelectionBound ConvertWebSelectionBound( | 107 cc::LayerSelectionBound ConvertWebSelectionBound( |
108 const WebSelection& web_selection, | 108 const WebSelection& web_selection, |
109 bool is_start) { | 109 bool is_start) { |
110 cc::LayerSelectionBound cc_bound; | 110 cc::LayerSelectionBound cc_bound; |
111 if (web_selection.isNone()) | 111 if (web_selection.isNone()) |
112 return cc_bound; | 112 return cc_bound; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 std::numeric_limits<int>::max(), | 296 std::numeric_limits<int>::max(), |
297 &max_untiled_layer_width); | 297 &max_untiled_layer_width); |
298 } | 298 } |
299 int max_untiled_layer_height = settings.max_untiled_layer_size.height(); | 299 int max_untiled_layer_height = settings.max_untiled_layer_size.height(); |
300 if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) { | 300 if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) { |
301 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerHeight, 1, | 301 GetSwitchValueAsInt(cmd, switches::kMaxUntiledLayerHeight, 1, |
302 std::numeric_limits<int>::max(), | 302 std::numeric_limits<int>::max(), |
303 &max_untiled_layer_height); | 303 &max_untiled_layer_height); |
304 } | 304 } |
305 | 305 |
306 settings.max_untiled_layer_size = gfx::Size(max_untiled_layer_width, | 306 settings.max_untiled_layer_size = |
307 max_untiled_layer_height); | 307 gfx::Size(max_untiled_layer_width, max_untiled_layer_height); |
308 | 308 |
309 settings.gpu_rasterization_msaa_sample_count = | 309 settings.gpu_rasterization_msaa_sample_count = |
310 compositor_deps->GetGpuRasterizationMSAASampleCount(); | 310 compositor_deps->GetGpuRasterizationMSAASampleCount(); |
311 settings.gpu_rasterization_forced = | 311 settings.gpu_rasterization_forced = |
312 compositor_deps->IsGpuRasterizationForced(); | 312 compositor_deps->IsGpuRasterizationForced(); |
313 settings.async_worker_context_enabled = | 313 settings.async_worker_context_enabled = |
314 compositor_deps->IsAsyncWorkerContextEnabled(); | 314 compositor_deps->IsAsyncWorkerContextEnabled(); |
315 | 315 |
316 settings.can_use_lcd_text = compositor_deps->IsLcdTextEnabled(); | 316 settings.can_use_lcd_text = compositor_deps->IsLcdTextEnabled(); |
317 settings.use_distance_field_text = | 317 settings.use_distance_field_text = |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 settings.using_synchronous_renderer_compositor = using_synchronous_compositor; | 379 settings.using_synchronous_renderer_compositor = using_synchronous_compositor; |
380 if (using_synchronous_compositor) { | 380 if (using_synchronous_compositor) { |
381 // Android WebView uses system scrollbars, so make ours invisible. | 381 // Android WebView uses system scrollbars, so make ours invisible. |
382 // http://crbug.com/677348: This can't be done using hide_scrollbars | 382 // http://crbug.com/677348: This can't be done using hide_scrollbars |
383 // setting because supporting -webkit custom scrollbars is still desired | 383 // setting because supporting -webkit custom scrollbars is still desired |
384 // on sublayers. | 384 // on sublayers. |
385 settings.scrollbar_animator = cc::LayerTreeSettings::NO_ANIMATOR; | 385 settings.scrollbar_animator = cc::LayerTreeSettings::NO_ANIMATOR; |
386 settings.solid_color_scrollbar_color = SK_ColorTRANSPARENT; | 386 settings.solid_color_scrollbar_color = SK_ColorTRANSPARENT; |
387 } else { | 387 } else { |
388 settings.scrollbar_animator = cc::LayerTreeSettings::ANDROID_OVERLAY; | 388 settings.scrollbar_animator = cc::LayerTreeSettings::ANDROID_OVERLAY; |
389 settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(300); | 389 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(300); |
390 settings.scrollbar_fade_resize_delay = | 390 settings.scrollbar_fade_out_resize_delay = |
391 base::TimeDelta::FromMilliseconds(2000); | 391 base::TimeDelta::FromMilliseconds(2000); |
392 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300); | 392 settings.scrollbar_fade_out_duration = |
| 393 base::TimeDelta::FromMilliseconds(300); |
393 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); | 394 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); |
394 } | 395 } |
395 settings.renderer_settings.highp_threshold_min = 2048; | 396 settings.renderer_settings.highp_threshold_min = 2048; |
396 // Android WebView handles root layer flings itself. | 397 // Android WebView handles root layer flings itself. |
397 settings.ignore_root_layer_flings = using_synchronous_compositor; | 398 settings.ignore_root_layer_flings = using_synchronous_compositor; |
398 // Memory policy on Android WebView does not depend on whether device is | 399 // Memory policy on Android WebView does not depend on whether device is |
399 // low end, so always use default policy. | 400 // low end, so always use default policy. |
400 bool use_low_memory_policy = | 401 bool use_low_memory_policy = |
401 base::SysInfo::IsLowEndDevice() && !using_synchronous_compositor; | 402 base::SysInfo::IsLowEndDevice() && !using_synchronous_compositor; |
402 if (use_low_memory_policy) { | 403 if (use_low_memory_policy) { |
(...skipping 15 matching lines...) Expand all Loading... |
418 // Webview does not own the surface so should not clear it. | 419 // Webview does not own the surface so should not clear it. |
419 settings.renderer_settings.should_clear_root_render_pass = | 420 settings.renderer_settings.should_clear_root_render_pass = |
420 !using_synchronous_compositor; | 421 !using_synchronous_compositor; |
421 | 422 |
422 // TODO(danakj): Only do this on low end devices. | 423 // TODO(danakj): Only do this on low end devices. |
423 settings.create_low_res_tiling = true; | 424 settings.create_low_res_tiling = true; |
424 #else // defined(OS_ANDROID) | 425 #else // defined(OS_ANDROID) |
425 #if !defined(OS_MACOSX) | 426 #if !defined(OS_MACOSX) |
426 if (ui::IsOverlayScrollbarEnabled()) { | 427 if (ui::IsOverlayScrollbarEnabled()) { |
427 settings.scrollbar_animator = cc::LayerTreeSettings::AURA_OVERLAY; | 428 settings.scrollbar_animator = cc::LayerTreeSettings::AURA_OVERLAY; |
428 settings.scrollbar_fade_delay = ui::kOverlayScrollbarFadeOutDelay; | 429 settings.scrollbar_show_delay = ui::kOverlayScrollbarShowDelay; |
429 settings.scrollbar_fade_resize_delay = | 430 settings.scrollbar_fade_out_delay = ui::kOverlayScrollbarFadeOutDelay; |
| 431 settings.scrollbar_fade_out_resize_delay = |
430 ui::kOverlayScrollbarFadeOutDelay; | 432 ui::kOverlayScrollbarFadeOutDelay; |
431 settings.scrollbar_fade_duration = | 433 settings.scrollbar_fade_out_duration = ui::kOverlayScrollbarFadeOutDuration; |
432 ui::kOverlayScrollbarFadeOutDuration; | |
433 settings.scrollbar_thinning_duration = | 434 settings.scrollbar_thinning_duration = |
434 ui::kOverlayScrollbarThinningDuration; | 435 ui::kOverlayScrollbarThinningDuration; |
435 } else { | 436 } else { |
436 // TODO(bokan): This section is probably unneeded? We don't use scrollbar | 437 // TODO(bokan): This section is probably unneeded? We don't use scrollbar |
437 // animations for non overlay scrollbars. | 438 // animations for non overlay scrollbars. |
438 settings.scrollbar_animator = cc::LayerTreeSettings::ANDROID_OVERLAY; | 439 settings.scrollbar_animator = cc::LayerTreeSettings::ANDROID_OVERLAY; |
439 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); | 440 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); |
440 settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(500); | 441 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(500); |
441 settings.scrollbar_fade_resize_delay = | 442 settings.scrollbar_fade_out_resize_delay = |
442 base::TimeDelta::FromMilliseconds(500); | 443 base::TimeDelta::FromMilliseconds(500); |
443 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300); | 444 settings.scrollbar_fade_out_duration = |
| 445 base::TimeDelta::FromMilliseconds(300); |
444 } | 446 } |
445 #endif // !defined(OS_MACOSX) | 447 #endif // !defined(OS_MACOSX) |
446 | 448 |
447 // On desktop, if there's over 4GB of memory on the machine, increase the | 449 // On desktop, if there's over 4GB of memory on the machine, increase the |
448 // image decode budget to 256MB for both gpu and software. | 450 // image decode budget to 256MB for both gpu and software. |
449 const int kImageDecodeMemoryThresholdMB = 4 * 1024; | 451 const int kImageDecodeMemoryThresholdMB = 4 * 1024; |
450 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= | 452 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= |
451 kImageDecodeMemoryThresholdMB) { | 453 kImageDecodeMemoryThresholdMB) { |
452 settings.gpu_decoded_image_budget_bytes = 256 * 1024 * 1024; | 454 settings.gpu_decoded_image_budget_bytes = 256 * 1024 * 1024; |
453 settings.software_decoded_image_budget_bytes = 256 * 1024 * 1024; | 455 settings.software_decoded_image_budget_bytes = 256 * 1024 * 1024; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 } | 688 } |
687 | 689 |
688 void RenderWidgetCompositor::setVisible(bool visible) { | 690 void RenderWidgetCompositor::setVisible(bool visible) { |
689 if (never_visible_) | 691 if (never_visible_) |
690 return; | 692 return; |
691 | 693 |
692 layer_tree_host_->SetVisible(visible); | 694 layer_tree_host_->SetVisible(visible); |
693 } | 695 } |
694 | 696 |
695 void RenderWidgetCompositor::setPageScaleFactorAndLimits( | 697 void RenderWidgetCompositor::setPageScaleFactorAndLimits( |
696 float page_scale_factor, float minimum, float maximum) { | 698 float page_scale_factor, |
| 699 float minimum, |
| 700 float maximum) { |
697 layer_tree_host_->SetPageScaleFactorAndLimits(page_scale_factor, minimum, | 701 layer_tree_host_->SetPageScaleFactorAndLimits(page_scale_factor, minimum, |
698 maximum); | 702 maximum); |
699 } | 703 } |
700 | 704 |
701 void RenderWidgetCompositor::startPageScaleAnimation( | 705 void RenderWidgetCompositor::startPageScaleAnimation( |
702 const blink::WebPoint& destination, | 706 const blink::WebPoint& destination, |
703 bool use_anchor, | 707 bool use_anchor, |
704 float new_page_scale, | 708 float new_page_scale, |
705 double duration_sec) { | 709 double duration_sec) { |
706 base::TimeDelta duration = base::TimeDelta::FromMicroseconds( | 710 base::TimeDelta duration = base::TimeDelta::FromMicroseconds( |
(...skipping 28 matching lines...) Expand all Loading... |
735 const blink::WebLayer* overscrollElasticityLayer, | 739 const blink::WebLayer* overscrollElasticityLayer, |
736 const blink::WebLayer* pageScaleLayer, | 740 const blink::WebLayer* pageScaleLayer, |
737 const blink::WebLayer* innerViewportScrollLayer, | 741 const blink::WebLayer* innerViewportScrollLayer, |
738 const blink::WebLayer* outerViewportScrollLayer) { | 742 const blink::WebLayer* outerViewportScrollLayer) { |
739 layer_tree_host_->RegisterViewportLayers( | 743 layer_tree_host_->RegisterViewportLayers( |
740 // TODO(bokan): This check can probably be removed now, but it looks | 744 // TODO(bokan): This check can probably be removed now, but it looks |
741 // like overscroll elasticity may still be NULL until VisualViewport | 745 // like overscroll elasticity may still be NULL until VisualViewport |
742 // registers its layers. | 746 // registers its layers. |
743 // The scroll elasticity layer will only exist when using pinch virtual | 747 // The scroll elasticity layer will only exist when using pinch virtual |
744 // viewports. | 748 // viewports. |
745 overscrollElasticityLayer | 749 overscrollElasticityLayer ? static_cast<const cc_blink::WebLayerImpl*>( |
746 ? static_cast<const cc_blink::WebLayerImpl*>( | 750 overscrollElasticityLayer) |
747 overscrollElasticityLayer) | 751 ->layer() |
748 ->layer() | 752 : NULL, |
749 : NULL, | |
750 static_cast<const cc_blink::WebLayerImpl*>(pageScaleLayer)->layer(), | 753 static_cast<const cc_blink::WebLayerImpl*>(pageScaleLayer)->layer(), |
751 static_cast<const cc_blink::WebLayerImpl*>(innerViewportScrollLayer) | 754 static_cast<const cc_blink::WebLayerImpl*>(innerViewportScrollLayer) |
752 ->layer(), | 755 ->layer(), |
753 // TODO(bokan): This check can probably be removed now, but it looks | 756 // TODO(bokan): This check can probably be removed now, but it looks |
754 // like overscroll elasticity may still be NULL until VisualViewport | 757 // like overscroll elasticity may still be NULL until VisualViewport |
755 // registers its layers. | 758 // registers its layers. |
756 // The outer viewport layer will only exist when using pinch virtual | 759 // The outer viewport layer will only exist when using pinch virtual |
757 // viewports. | 760 // viewports. |
758 outerViewportScrollLayer | 761 outerViewportScrollLayer |
759 ? static_cast<const cc_blink::WebLayerImpl*>(outerViewportScrollLayer) | 762 ? static_cast<const cc_blink::WebLayerImpl*>(outerViewportScrollLayer) |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 } | 1005 } |
1003 | 1006 |
1004 void RenderWidgetCompositor::setBottomControlsHeight(float height) { | 1007 void RenderWidgetCompositor::setBottomControlsHeight(float height) { |
1005 layer_tree_host_->SetBottomControlsHeight(height); | 1008 layer_tree_host_->SetBottomControlsHeight(height); |
1006 } | 1009 } |
1007 | 1010 |
1008 void RenderWidgetCompositor::WillBeginMainFrame() { | 1011 void RenderWidgetCompositor::WillBeginMainFrame() { |
1009 delegate_->WillBeginCompositorFrame(); | 1012 delegate_->WillBeginCompositorFrame(); |
1010 } | 1013 } |
1011 | 1014 |
1012 void RenderWidgetCompositor::DidBeginMainFrame() { | 1015 void RenderWidgetCompositor::DidBeginMainFrame() {} |
1013 } | |
1014 | 1016 |
1015 void RenderWidgetCompositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 1017 void RenderWidgetCompositor::BeginMainFrame(const cc::BeginFrameArgs& args) { |
1016 compositor_deps_->GetRendererScheduler()->WillBeginFrame(args); | 1018 compositor_deps_->GetRendererScheduler()->WillBeginFrame(args); |
1017 double frame_time_sec = (args.frame_time - base::TimeTicks()).InSecondsF(); | 1019 double frame_time_sec = (args.frame_time - base::TimeTicks()).InSecondsF(); |
1018 delegate_->BeginMainFrame(frame_time_sec); | 1020 delegate_->BeginMainFrame(frame_time_sec); |
1019 } | 1021 } |
1020 | 1022 |
1021 void RenderWidgetCompositor::BeginMainFrameNotExpectedSoon() { | 1023 void RenderWidgetCompositor::BeginMainFrameNotExpectedSoon() { |
1022 compositor_deps_->GetRendererScheduler()->BeginFrameNotExpectedSoon(); | 1024 compositor_deps_->GetRendererScheduler()->BeginFrameNotExpectedSoon(); |
1023 } | 1025 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 void RenderWidgetCompositor::DidSubmitCompositorFrame() {} | 1105 void RenderWidgetCompositor::DidSubmitCompositorFrame() {} |
1104 | 1106 |
1105 void RenderWidgetCompositor::DidLoseCompositorFrameSink() {} | 1107 void RenderWidgetCompositor::DidLoseCompositorFrameSink() {} |
1106 | 1108 |
1107 void RenderWidgetCompositor::SetFrameSinkId( | 1109 void RenderWidgetCompositor::SetFrameSinkId( |
1108 const cc::FrameSinkId& frame_sink_id) { | 1110 const cc::FrameSinkId& frame_sink_id) { |
1109 frame_sink_id_ = frame_sink_id; | 1111 frame_sink_id_ = frame_sink_id; |
1110 layer_tree_host_->SetFrameSinkId(frame_sink_id); | 1112 layer_tree_host_->SetFrameSinkId(frame_sink_id); |
1111 } | 1113 } |
1112 | 1114 |
1113 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( | 1115 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor(float device_scale) { |
1114 float device_scale) { | |
1115 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); | 1116 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); |
1116 } | 1117 } |
1117 | 1118 |
1118 void RenderWidgetCompositor::SetDeviceColorSpace( | 1119 void RenderWidgetCompositor::SetDeviceColorSpace( |
1119 const gfx::ColorSpace& color_space) { | 1120 const gfx::ColorSpace& color_space) { |
1120 layer_tree_host_->SetDeviceColorSpace(color_space); | 1121 layer_tree_host_->SetDeviceColorSpace(color_space); |
1121 } | 1122 } |
1122 | 1123 |
1123 void RenderWidgetCompositor::SetIsForOopif(bool is_for_oopif) { | 1124 void RenderWidgetCompositor::SetIsForOopif(bool is_for_oopif) { |
1124 is_for_oopif_ = is_for_oopif; | 1125 is_for_oopif_ = is_for_oopif; |
1125 } | 1126 } |
1126 | 1127 |
1127 } // namespace content | 1128 } // namespace content |
OLD | NEW |