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
3 // found in the LICENSE file.
5 #include "content/renderer/gpu/render_widget_compositor.h"
10 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/synchronization/lock.h"
14 #include "base/sys_info.h"
15 #include "base/time/time.h"
16 #include "base/values.h"
17 #include "cc/base/latency_info_swap_promise.h"
18 #include "cc/base/latency_info_swap_promise_monitor.h"
19 #include "cc/base/swap_promise.h"
20 #include "cc/base/switches.h"
21 #include "cc/debug/layer_tree_debug_state.h"
22 #include "cc/debug/micro_benchmark.h"
23 #include "cc/input/layer_selection_bound.h"
24 #include "cc/layers/layer.h"
25 #include "cc/output/copy_output_request.h"
26 #include "cc/output/copy_output_result.h"
27 #include "cc/resources/single_release_callback.h"
28 #include "cc/trees/layer_tree_host.h"
29 #include "content/child/child_shared_bitmap_manager.h"
30 #include "content/common/content_switches_internal.h"
31 #include "content/common/gpu/client/context_provider_command_buffer.h"
32 #include "content/public/common/content_switches.h"
33 #include "content/renderer/compositor_bindings/web_layer_impl.h"
34 #include "content/renderer/input/input_handler_manager.h"
35 #include "content/renderer/render_thread_impl.h"
36 #include "gpu/command_buffer/client/gles2_interface.h"
37 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallback.h"
38 #include "third_party/WebKit/public/platform/WebSelectionBound.h"
39 #include "third_party/WebKit/public/platform/WebSize.h"
40 #include "third_party/WebKit/public/web/WebWidget.h"
41 #include "ui/gfx/frame_time.h"
42 #include "ui/gl/gl_switches.h"
43 #include "ui/native_theme/native_theme_switches.h"
45 #if defined(OS_ANDROID)
46 #include "content/renderer/android/synchronous_compositor_factory.h"
47 #include "ui/gfx/android/device_display_info.h"
58 using blink::WebFloatPoint
;
59 using blink::WebSelectionBound
;
66 bool GetSwitchValueAsInt(
67 const CommandLine
& command_line
,
68 const std::string
& switch_string
,
72 std::string string_value
= command_line
.GetSwitchValueASCII(switch_string
);
74 if (base::StringToInt(string_value
, &int_value
) &&
75 int_value
>= min_value
&& int_value
<= max_value
) {
79 LOG(WARNING
) << "Failed to parse switch " << switch_string
<< ": " <<
85 cc::LayerSelectionBound
ConvertWebSelectionBound(
86 const WebSelectionBound
& bound
) {
87 DCHECK(bound
.layerId
);
89 cc::LayerSelectionBound result
;
91 case blink::WebSelectionBound::Caret
:
92 result
.type
= cc::SELECTION_BOUND_CENTER
;
94 case blink::WebSelectionBound::SelectionLeft
:
95 result
.type
= cc::SELECTION_BOUND_LEFT
;
97 case blink::WebSelectionBound::SelectionRight
:
98 result
.type
= cc::SELECTION_BOUND_RIGHT
;
101 result
.layer_id
= bound
.layerId
;
102 result
.layer_rect
= gfx::Rect(bound
.edgeRectInLayer
);
106 gfx::Size
CalculateDefaultTileSize() {
107 int default_tile_size
= 256;
108 #if defined(OS_ANDROID)
109 // TODO(epenner): unify this for all platforms if it
110 // makes sense (http://crbug.com/159524)
112 gfx::DeviceDisplayInfo info
;
113 bool real_size_supported
= true;
114 int display_width
= info
.GetPhysicalDisplayWidth();
115 int display_height
= info
.GetPhysicalDisplayHeight();
116 if (display_width
== 0 || display_height
== 0) {
117 real_size_supported
= false;
118 display_width
= info
.GetDisplayWidth();
119 display_height
= info
.GetDisplayHeight();
122 int portrait_width
= std::min(display_width
, display_height
);
123 int landscape_width
= std::max(display_width
, display_height
);
125 if (real_size_supported
) {
126 // Maximum HD dimensions should be 768x1280
127 // Maximum FHD dimensions should be 1200x1920
128 if (portrait_width
> 768 || landscape_width
> 1280)
129 default_tile_size
= 384;
130 if (portrait_width
> 1200 || landscape_width
> 1920)
131 default_tile_size
= 512;
133 // Adjust for some resolutions that barely straddle an extra
134 // tile when in portrait mode. This helps worst case scroll/raster
135 // by not needing a full extra tile for each row.
136 if (default_tile_size
== 256 && portrait_width
== 768)
137 default_tile_size
+= 32;
138 if (default_tile_size
== 384 && portrait_width
== 1200)
139 default_tile_size
+= 32;
141 // We don't know the exact resolution due to screen controls etc.
142 // So this just estimates the values above using tile counts.
143 int numTiles
= (display_width
* display_height
) / (256 * 256);
145 default_tile_size
= 384;
147 default_tile_size
= 512;
150 return gfx::Size(default_tile_size
, default_tile_size
);
156 scoped_ptr
<RenderWidgetCompositor
> RenderWidgetCompositor::Create(
157 RenderWidget
* widget
,
159 scoped_ptr
<RenderWidgetCompositor
> compositor(
160 new RenderWidgetCompositor(widget
, threaded
));
162 CommandLine
* cmd
= CommandLine::ForCurrentProcess();
164 cc::LayerTreeSettings settings
;
166 // For web contents, layer transforms should scale up the contents of layers
167 // to keep content always crisp when possible.
168 settings
.layer_transforms_should_scale_layer_contents
= true;
170 settings
.throttle_frame_production
=
171 !cmd
->HasSwitch(switches::kDisableGpuVsync
);
172 settings
.begin_frame_scheduling_enabled
=
173 cmd
->HasSwitch(switches::kEnableBeginFrameScheduling
);
174 settings
.main_frame_before_activation_enabled
=
175 cmd
->HasSwitch(cc::switches::kEnableMainFrameBeforeActivation
) &&
176 !cmd
->HasSwitch(cc::switches::kDisableMainFrameBeforeActivation
);
177 settings
.main_frame_before_draw_enabled
=
178 !cmd
->HasSwitch(cc::switches::kDisableMainFrameBeforeDraw
);
179 settings
.report_overscroll_only_for_scrollable_axes
= true;
180 settings
.accelerated_animation_enabled
=
181 !cmd
->HasSwitch(cc::switches::kDisableThreadedAnimation
);
183 settings
.default_tile_size
= CalculateDefaultTileSize();
184 if (cmd
->HasSwitch(switches::kDefaultTileWidth
)) {
186 GetSwitchValueAsInt(*cmd
,
187 switches::kDefaultTileWidth
,
189 std::numeric_limits
<int>::max(),
191 settings
.default_tile_size
.set_width(tile_width
);
193 if (cmd
->HasSwitch(switches::kDefaultTileHeight
)) {
195 GetSwitchValueAsInt(*cmd
,
196 switches::kDefaultTileHeight
,
198 std::numeric_limits
<int>::max(),
200 settings
.default_tile_size
.set_height(tile_height
);
203 int max_untiled_layer_width
= settings
.max_untiled_layer_size
.width();
204 if (cmd
->HasSwitch(switches::kMaxUntiledLayerWidth
)) {
205 GetSwitchValueAsInt(*cmd
, switches::kMaxUntiledLayerWidth
, 1,
206 std::numeric_limits
<int>::max(),
207 &max_untiled_layer_width
);
209 int max_untiled_layer_height
= settings
.max_untiled_layer_size
.height();
210 if (cmd
->HasSwitch(switches::kMaxUntiledLayerHeight
)) {
211 GetSwitchValueAsInt(*cmd
, switches::kMaxUntiledLayerHeight
, 1,
212 std::numeric_limits
<int>::max(),
213 &max_untiled_layer_height
);
216 settings
.max_untiled_layer_size
= gfx::Size(max_untiled_layer_width
,
217 max_untiled_layer_height
);
219 RenderThreadImpl
* render_thread
= RenderThreadImpl::current();
220 // render_thread may be NULL in tests.
222 settings
.impl_side_painting
=
223 render_thread
->is_impl_side_painting_enabled();
224 settings
.gpu_rasterization_forced
=
225 render_thread
->is_gpu_rasterization_forced();
226 settings
.gpu_rasterization_enabled
=
227 render_thread
->is_gpu_rasterization_enabled();
228 settings
.create_low_res_tiling
= render_thread
->is_low_res_tiling_enabled();
229 settings
.can_use_lcd_text
= render_thread
->is_lcd_text_enabled();
230 settings
.use_distance_field_text
=
231 render_thread
->is_distance_field_text_enabled();
232 settings
.use_zero_copy
= render_thread
->is_zero_copy_enabled();
233 settings
.use_one_copy
= render_thread
->is_one_copy_enabled();
236 if (cmd
->HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths
)) {
237 settings
.recording_mode
= cc::LayerTreeSettings::RecordWithSkRecord
;
240 settings
.calculate_top_controls_position
=
241 cmd
->HasSwitch(cc::switches::kEnableTopControlsPositionCalculation
);
242 if (cmd
->HasSwitch(cc::switches::kTopControlsHeight
)) {
243 std::string controls_height_str
=
244 cmd
->GetSwitchValueASCII(cc::switches::kTopControlsHeight
);
245 double controls_height
;
246 if (base::StringToDouble(controls_height_str
, &controls_height
) &&
248 settings
.top_controls_height
= controls_height
;
251 if (settings
.calculate_top_controls_position
&&
252 settings
.top_controls_height
<= 0) {
254 << "Top controls repositioning enabled without valid height set.";
255 settings
.calculate_top_controls_position
= false;
258 if (cmd
->HasSwitch(cc::switches::kTopControlsShowThreshold
)) {
259 std::string top_threshold_str
=
260 cmd
->GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold
);
261 double show_threshold
;
262 if (base::StringToDouble(top_threshold_str
, &show_threshold
) &&
263 show_threshold
>= 0.f
&& show_threshold
<= 1.f
)
264 settings
.top_controls_show_threshold
= show_threshold
;
267 if (cmd
->HasSwitch(cc::switches::kTopControlsHideThreshold
)) {
268 std::string top_threshold_str
=
269 cmd
->GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold
);
270 double hide_threshold
;
271 if (base::StringToDouble(top_threshold_str
, &hide_threshold
) &&
272 hide_threshold
>= 0.f
&& hide_threshold
<= 1.f
)
273 settings
.top_controls_hide_threshold
= hide_threshold
;
276 settings
.use_pinch_virtual_viewport
=
277 cmd
->HasSwitch(cc::switches::kEnablePinchVirtualViewport
);
278 settings
.allow_antialiasing
&=
279 !cmd
->HasSwitch(cc::switches::kDisableCompositedAntialiasing
);
281 // These flags should be mirrored by UI versions in ui/compositor/.
282 settings
.initial_debug_state
.show_debug_borders
=
283 cmd
->HasSwitch(cc::switches::kShowCompositedLayerBorders
);
284 settings
.initial_debug_state
.show_fps_counter
=
285 cmd
->HasSwitch(cc::switches::kShowFPSCounter
);
286 settings
.initial_debug_state
.show_layer_animation_bounds_rects
=
287 cmd
->HasSwitch(cc::switches::kShowLayerAnimationBounds
);
288 settings
.initial_debug_state
.show_paint_rects
=
289 cmd
->HasSwitch(switches::kShowPaintRects
);
290 settings
.initial_debug_state
.show_property_changed_rects
=
291 cmd
->HasSwitch(cc::switches::kShowPropertyChangedRects
);
292 settings
.initial_debug_state
.show_surface_damage_rects
=
293 cmd
->HasSwitch(cc::switches::kShowSurfaceDamageRects
);
294 settings
.initial_debug_state
.show_screen_space_rects
=
295 cmd
->HasSwitch(cc::switches::kShowScreenSpaceRects
);
296 settings
.initial_debug_state
.show_replica_screen_space_rects
=
297 cmd
->HasSwitch(cc::switches::kShowReplicaScreenSpaceRects
);
298 settings
.initial_debug_state
.show_occluding_rects
=
299 cmd
->HasSwitch(cc::switches::kShowOccludingRects
);
300 settings
.initial_debug_state
.show_non_occluding_rects
=
301 cmd
->HasSwitch(cc::switches::kShowNonOccludingRects
);
303 settings
.initial_debug_state
.SetRecordRenderingStats(
304 cmd
->HasSwitch(cc::switches::kEnableGpuBenchmarking
));
306 if (cmd
->HasSwitch(cc::switches::kSlowDownRasterScaleFactor
)) {
307 const int kMinSlowDownScaleFactor
= 0;
308 const int kMaxSlowDownScaleFactor
= INT_MAX
;
311 cc::switches::kSlowDownRasterScaleFactor
,
312 kMinSlowDownScaleFactor
,
313 kMaxSlowDownScaleFactor
,
314 &settings
.initial_debug_state
.slow_down_raster_scale_factor
);
317 if (cmd
->HasSwitch(cc::switches::kMaxTilesForInterestArea
)) {
318 int max_tiles_for_interest_area
;
319 if (GetSwitchValueAsInt(*cmd
,
320 cc::switches::kMaxTilesForInterestArea
,
321 1, std::numeric_limits
<int>::max(),
322 &max_tiles_for_interest_area
))
323 settings
.max_tiles_for_interest_area
= max_tiles_for_interest_area
;
326 if (cmd
->HasSwitch(cc::switches::kMaxUnusedResourceMemoryUsagePercentage
)) {
327 int max_unused_resource_memory_percentage
;
328 if (GetSwitchValueAsInt(
330 cc::switches::kMaxUnusedResourceMemoryUsagePercentage
,
332 &max_unused_resource_memory_percentage
)) {
333 settings
.max_unused_resource_memory_percentage
=
334 max_unused_resource_memory_percentage
;
338 settings
.strict_layer_property_change_checking
=
339 cmd
->HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking
);
341 #if defined(OS_ANDROID)
342 SynchronousCompositorFactory
* synchronous_compositor_factory
=
343 SynchronousCompositorFactory::GetInstance();
345 settings
.using_synchronous_renderer_compositor
=
346 synchronous_compositor_factory
;
347 settings
.record_full_layer
=
348 synchronous_compositor_factory
&&
349 synchronous_compositor_factory
->RecordFullLayer();
350 settings
.report_overscroll_only_for_scrollable_axes
=
351 !synchronous_compositor_factory
;
352 settings
.max_partial_texture_updates
= 0;
353 if (synchronous_compositor_factory
) {
354 // Android WebView uses system scrollbars, so make ours invisible.
355 settings
.scrollbar_animator
= cc::LayerTreeSettings::NoAnimator
;
356 settings
.solid_color_scrollbar_color
= SK_ColorTRANSPARENT
;
358 settings
.scrollbar_animator
= cc::LayerTreeSettings::LinearFade
;
359 settings
.scrollbar_fade_delay_ms
= 300;
360 settings
.scrollbar_fade_duration_ms
= 300;
361 settings
.solid_color_scrollbar_color
= SkColorSetARGB(128, 128, 128, 128);
363 settings
.highp_threshold_min
= 2048;
364 // Android WebView handles root layer flings itself.
365 settings
.ignore_root_layer_flings
=
366 synchronous_compositor_factory
;
367 // Memory policy on Android WebView does not depend on whether device is
368 // low end, so always use default policy.
369 bool is_low_end_device
=
370 base::SysInfo::IsLowEndDevice() && !synchronous_compositor_factory
;
371 // RGBA_4444 textures are only enabled for low end devices
372 // and are disabled for Android WebView as it doesn't support the format.
373 settings
.use_rgba_4444_textures
= is_low_end_device
;
374 if (is_low_end_device
) {
375 // On low-end we want to be very carefull about killing other
376 // apps. So initially we use 50% more memory to avoid flickering
377 // or raster-on-demand.
378 settings
.max_memory_for_prepaint_percentage
= 67;
380 // On other devices we have increased memory excessively to avoid
381 // raster-on-demand already, so now we reserve 50% _only_ to avoid
382 // raster-on-demand, and use 50% of the memory otherwise.
383 settings
.max_memory_for_prepaint_percentage
= 50;
385 // Webview does not own the surface so should not clear it.
386 settings
.should_clear_root_render_pass
=
387 !synchronous_compositor_factory
;
389 #elif !defined(OS_MACOSX)
390 if (ui::IsOverlayScrollbarEnabled()) {
391 settings
.scrollbar_animator
= cc::LayerTreeSettings::Thinning
;
392 settings
.solid_color_scrollbar_color
= SkColorSetARGB(128, 128, 128, 128);
393 } else if (cmd
->HasSwitch(cc::switches::kEnablePinchVirtualViewport
)) {
394 // use_pinch_zoom_scrollbars is only true on desktop when non-overlay
395 // scrollbars are in use.
396 settings
.use_pinch_zoom_scrollbars
= true;
397 settings
.scrollbar_animator
= cc::LayerTreeSettings::LinearFade
;
398 settings
.solid_color_scrollbar_color
= SkColorSetARGB(128, 128, 128, 128);
400 settings
.scrollbar_fade_delay_ms
= 500;
401 settings
.scrollbar_fade_duration_ms
= 300;
404 compositor
->Initialize(settings
);
406 return compositor
.Pass();
409 RenderWidgetCompositor::RenderWidgetCompositor(RenderWidget
* widget
,
411 : threaded_(threaded
),
412 suppress_schedule_composite_(false),
416 RenderWidgetCompositor::~RenderWidgetCompositor() {}
418 const base::WeakPtr
<cc::InputHandler
>&
419 RenderWidgetCompositor::GetInputHandler() {
420 return layer_tree_host_
->GetInputHandler();
423 void RenderWidgetCompositor::SetSuppressScheduleComposite(bool suppress
) {
424 if (suppress_schedule_composite_
== suppress
)
428 TRACE_EVENT_ASYNC_BEGIN0("gpu",
429 "RenderWidgetCompositor::SetSuppressScheduleComposite", this);
431 TRACE_EVENT_ASYNC_END0("gpu",
432 "RenderWidgetCompositor::SetSuppressScheduleComposite", this);
433 suppress_schedule_composite_
= suppress
;
436 bool RenderWidgetCompositor::BeginMainFrameRequested() const {
437 return layer_tree_host_
->BeginMainFrameRequested();
440 void RenderWidgetCompositor::UpdateAnimations(base::TimeTicks time
) {
441 layer_tree_host_
->UpdateClientAnimations(time
);
444 void RenderWidgetCompositor::SetNeedsDisplayOnAllLayers() {
445 layer_tree_host_
->SetNeedsDisplayOnAllLayers();
448 void RenderWidgetCompositor::SetRasterizeOnlyVisibleContent() {
449 cc::LayerTreeDebugState current
= layer_tree_host_
->debug_state();
450 current
.rasterize_only_visible_content
= true;
451 layer_tree_host_
->SetDebugState(current
);
454 void RenderWidgetCompositor::UpdateTopControlsState(
455 cc::TopControlsState constraints
,
456 cc::TopControlsState current
,
458 layer_tree_host_
->UpdateTopControlsState(constraints
,
463 void RenderWidgetCompositor::SetOverdrawBottomHeight(
464 float overdraw_bottom_height
) {
465 layer_tree_host_
->SetOverdrawBottomHeight(overdraw_bottom_height
);
468 void RenderWidgetCompositor::SetNeedsRedrawRect(gfx::Rect damage_rect
) {
469 layer_tree_host_
->SetNeedsRedrawRect(damage_rect
);
472 void RenderWidgetCompositor::SetNeedsForcedRedraw() {
473 layer_tree_host_
->SetNextCommitForcesRedraw();
477 scoped_ptr
<cc::SwapPromiseMonitor
>
478 RenderWidgetCompositor::CreateLatencyInfoSwapPromiseMonitor(
479 ui::LatencyInfo
* latency
) {
480 return scoped_ptr
<cc::SwapPromiseMonitor
>(
481 new cc::LatencyInfoSwapPromiseMonitor(
482 latency
, layer_tree_host_
.get(), NULL
));
485 void RenderWidgetCompositor::QueueSwapPromise(
486 scoped_ptr
<cc::SwapPromise
> swap_promise
) {
487 layer_tree_host_
->QueueSwapPromise(swap_promise
.Pass());
490 int RenderWidgetCompositor::GetLayerTreeId() const {
491 return layer_tree_host_
->id();
494 int RenderWidgetCompositor::GetSourceFrameNumber() const {
495 return layer_tree_host_
->source_frame_number();
498 void RenderWidgetCompositor::SetNeedsCommit() {
499 layer_tree_host_
->SetNeedsCommit();
502 void RenderWidgetCompositor::NotifyInputThrottledUntilCommit() {
503 layer_tree_host_
->NotifyInputThrottledUntilCommit();
506 const cc::Layer
* RenderWidgetCompositor::GetRootLayer() const {
507 return layer_tree_host_
->root_layer();
510 int RenderWidgetCompositor::ScheduleMicroBenchmark(
511 const std::string
& name
,
512 scoped_ptr
<base::Value
> value
,
513 const base::Callback
<void(scoped_ptr
<base::Value
>)>& callback
) {
514 return layer_tree_host_
->ScheduleMicroBenchmark(name
, value
.Pass(), callback
);
517 bool RenderWidgetCompositor::SendMessageToMicroBenchmark(
519 scoped_ptr
<base::Value
> value
) {
520 return layer_tree_host_
->SendMessageToMicroBenchmark(id
, value
.Pass());
523 void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings
) {
524 scoped_refptr
<base::MessageLoopProxy
> compositor_message_loop_proxy
;
525 RenderThreadImpl
* render_thread
= RenderThreadImpl::current();
526 cc::SharedBitmapManager
* shared_bitmap_manager
= NULL
;
527 // render_thread may be NULL in tests.
529 compositor_message_loop_proxy
=
530 render_thread
->compositor_message_loop_proxy();
531 shared_bitmap_manager
= render_thread
->shared_bitmap_manager();
533 if (compositor_message_loop_proxy
.get()) {
534 layer_tree_host_
= cc::LayerTreeHost::CreateThreaded(
536 shared_bitmap_manager
,
538 base::MessageLoopProxy::current(),
539 compositor_message_loop_proxy
);
541 layer_tree_host_
= cc::LayerTreeHost::CreateSingleThreaded(
544 shared_bitmap_manager
,
546 base::MessageLoopProxy::current());
548 DCHECK(layer_tree_host_
);
551 void RenderWidgetCompositor::setSurfaceReady() {
552 layer_tree_host_
->SetLayerTreeHostClientReady();
555 void RenderWidgetCompositor::setRootLayer(const blink::WebLayer
& layer
) {
556 layer_tree_host_
->SetRootLayer(
557 static_cast<const WebLayerImpl
*>(&layer
)->layer());
560 void RenderWidgetCompositor::clearRootLayer() {
561 layer_tree_host_
->SetRootLayer(scoped_refptr
<cc::Layer
>());
564 void RenderWidgetCompositor::setViewportSize(
566 const WebSize
& device_viewport_size
) {
567 layer_tree_host_
->SetViewportSize(device_viewport_size
);
570 void RenderWidgetCompositor::setViewportSize(
571 const WebSize
& device_viewport_size
) {
572 layer_tree_host_
->SetViewportSize(device_viewport_size
);
575 WebSize
RenderWidgetCompositor::layoutViewportSize() const {
576 return layer_tree_host_
->device_viewport_size();
579 WebSize
RenderWidgetCompositor::deviceViewportSize() const {
580 return layer_tree_host_
->device_viewport_size();
583 WebFloatPoint
RenderWidgetCompositor::adjustEventPointForPinchZoom(
584 const WebFloatPoint
& point
) const {
588 void RenderWidgetCompositor::setDeviceScaleFactor(float device_scale
) {
589 layer_tree_host_
->SetDeviceScaleFactor(device_scale
);
592 float RenderWidgetCompositor::deviceScaleFactor() const {
593 return layer_tree_host_
->device_scale_factor();
596 void RenderWidgetCompositor::setBackgroundColor(blink::WebColor color
) {
597 layer_tree_host_
->set_background_color(color
);
600 void RenderWidgetCompositor::setHasTransparentBackground(bool transparent
) {
601 layer_tree_host_
->set_has_transparent_background(transparent
);
604 void RenderWidgetCompositor::setOverhangBitmap(const SkBitmap
& bitmap
) {
605 layer_tree_host_
->SetOverhangBitmap(bitmap
);
608 void RenderWidgetCompositor::setVisible(bool visible
) {
609 layer_tree_host_
->SetVisible(visible
);
612 void RenderWidgetCompositor::setPageScaleFactorAndLimits(
613 float page_scale_factor
, float minimum
, float maximum
) {
614 layer_tree_host_
->SetPageScaleFactorAndLimits(
615 page_scale_factor
, minimum
, maximum
);
618 void RenderWidgetCompositor::startPageScaleAnimation(
619 const blink::WebPoint
& destination
,
621 float new_page_scale
,
622 double duration_sec
) {
623 base::TimeDelta duration
= base::TimeDelta::FromMicroseconds(
624 duration_sec
* base::Time::kMicrosecondsPerSecond
);
625 layer_tree_host_
->StartPageScaleAnimation(
626 gfx::Vector2d(destination
.x
, destination
.y
),
632 void RenderWidgetCompositor::heuristicsForGpuRasterizationUpdated(
633 bool matches_heuristics
) {
634 layer_tree_host_
->SetHasGpuRasterizationTrigger(matches_heuristics
);
637 void RenderWidgetCompositor::setNeedsAnimate() {
638 layer_tree_host_
->SetNeedsAnimate();
641 bool RenderWidgetCompositor::commitRequested() const {
642 return layer_tree_host_
->CommitRequested();
645 void RenderWidgetCompositor::didStopFlinging() {
646 layer_tree_host_
->DidStopFlinging();
649 void RenderWidgetCompositor::registerForAnimations(blink::WebLayer
* layer
) {
650 cc::Layer
* cc_layer
= static_cast<WebLayerImpl
*>(layer
)->layer();
651 cc_layer
->layer_animation_controller()->SetAnimationRegistrar(
652 layer_tree_host_
->animation_registrar());
655 void RenderWidgetCompositor::registerViewportLayers(
656 const blink::WebLayer
* pageScaleLayer
,
657 const blink::WebLayer
* innerViewportScrollLayer
,
658 const blink::WebLayer
* outerViewportScrollLayer
) {
659 layer_tree_host_
->RegisterViewportLayers(
660 static_cast<const WebLayerImpl
*>(pageScaleLayer
)->layer(),
661 static_cast<const WebLayerImpl
*>(innerViewportScrollLayer
)->layer(),
662 // The outer viewport layer will only exist when using pinch virtual
664 outerViewportScrollLayer
665 ? static_cast<const WebLayerImpl
*>(outerViewportScrollLayer
)->layer()
669 void RenderWidgetCompositor::clearViewportLayers() {
670 layer_tree_host_
->RegisterViewportLayers(scoped_refptr
<cc::Layer
>(),
671 scoped_refptr
<cc::Layer
>(),
672 scoped_refptr
<cc::Layer
>());
675 void RenderWidgetCompositor::registerSelection(
676 const blink::WebSelectionBound
& start
,
677 const blink::WebSelectionBound
& end
) {
678 layer_tree_host_
->RegisterSelection(ConvertWebSelectionBound(start
),
679 ConvertWebSelectionBound(end
));
682 void RenderWidgetCompositor::clearSelection() {
683 cc::LayerSelectionBound empty_selection
;
684 layer_tree_host_
->RegisterSelection(empty_selection
, empty_selection
);
687 void CompositeAndReadbackAsyncCallback(
688 blink::WebCompositeAndReadbackAsyncCallback
* callback
,
689 scoped_ptr
<cc::CopyOutputResult
> result
) {
690 if (result
->HasBitmap()) {
691 scoped_ptr
<SkBitmap
> result_bitmap
= result
->TakeBitmap();
692 callback
->didCompositeAndReadback(*result_bitmap
);
694 callback
->didCompositeAndReadback(SkBitmap());
698 void RenderWidgetCompositor::compositeAndReadbackAsync(
699 blink::WebCompositeAndReadbackAsyncCallback
* callback
) {
700 DCHECK(layer_tree_host_
->root_layer());
701 scoped_ptr
<cc::CopyOutputRequest
> request
=
702 cc::CopyOutputRequest::CreateBitmapRequest(
703 base::Bind(&CompositeAndReadbackAsyncCallback
, callback
));
704 layer_tree_host_
->root_layer()->RequestCopyOfOutput(request
.Pass());
706 widget_
->webwidget()->animate(0.0);
707 widget_
->webwidget()->layout();
708 layer_tree_host_
->Composite(gfx::FrameTime::Now());
712 void RenderWidgetCompositor::finishAllRendering() {
713 layer_tree_host_
->FinishAllRendering();
716 void RenderWidgetCompositor::setDeferCommits(bool defer_commits
) {
717 layer_tree_host_
->SetDeferCommits(defer_commits
);
720 void RenderWidgetCompositor::setShowFPSCounter(bool show
) {
721 cc::LayerTreeDebugState debug_state
= layer_tree_host_
->debug_state();
722 debug_state
.show_fps_counter
= show
;
723 layer_tree_host_
->SetDebugState(debug_state
);
726 void RenderWidgetCompositor::setShowPaintRects(bool show
) {
727 cc::LayerTreeDebugState debug_state
= layer_tree_host_
->debug_state();
728 debug_state
.show_paint_rects
= show
;
729 layer_tree_host_
->SetDebugState(debug_state
);
732 void RenderWidgetCompositor::setShowDebugBorders(bool show
) {
733 cc::LayerTreeDebugState debug_state
= layer_tree_host_
->debug_state();
734 debug_state
.show_debug_borders
= show
;
735 layer_tree_host_
->SetDebugState(debug_state
);
738 void RenderWidgetCompositor::setContinuousPaintingEnabled(bool enabled
) {
739 cc::LayerTreeDebugState debug_state
= layer_tree_host_
->debug_state();
740 debug_state
.continuous_painting
= enabled
;
741 layer_tree_host_
->SetDebugState(debug_state
);
744 void RenderWidgetCompositor::setShowScrollBottleneckRects(bool show
) {
745 cc::LayerTreeDebugState debug_state
= layer_tree_host_
->debug_state();
746 debug_state
.show_touch_event_handler_rects
= show
;
747 debug_state
.show_wheel_event_handler_rects
= show
;
748 debug_state
.show_non_fast_scrollable_rects
= show
;
749 layer_tree_host_
->SetDebugState(debug_state
);
752 void RenderWidgetCompositor::WillBeginMainFrame(int frame_id
) {
753 widget_
->InstrumentWillBeginFrame(frame_id
);
754 widget_
->willBeginCompositorFrame();
757 void RenderWidgetCompositor::DidBeginMainFrame() {
758 widget_
->InstrumentDidBeginFrame();
761 void RenderWidgetCompositor::Animate(base::TimeTicks frame_begin_time
) {
762 widget_
->webwidget()->animate(
763 (frame_begin_time
- base::TimeTicks()).InSecondsF());
766 void RenderWidgetCompositor::Layout() {
767 widget_
->webwidget()->layout();
770 void RenderWidgetCompositor::ApplyScrollAndScale(
771 const gfx::Vector2d
& scroll_delta
,
773 widget_
->webwidget()->applyScrollAndScale(scroll_delta
, page_scale
);
776 scoped_ptr
<cc::OutputSurface
> RenderWidgetCompositor::CreateOutputSurface(
778 return widget_
->CreateOutputSurface(fallback
);
781 void RenderWidgetCompositor::DidInitializeOutputSurface() {
784 void RenderWidgetCompositor::WillCommit() {
785 widget_
->InstrumentWillComposite();
788 void RenderWidgetCompositor::DidCommit() {
789 widget_
->DidCommitCompositorFrame();
790 widget_
->didBecomeReadyForAdditionalInput();
793 void RenderWidgetCompositor::DidCommitAndDrawFrame() {
794 widget_
->didCommitAndDrawCompositorFrame();
797 void RenderWidgetCompositor::DidCompleteSwapBuffers() {
798 widget_
->didCompleteSwapBuffers();
800 widget_
->OnSwapBuffersComplete();
803 void RenderWidgetCompositor::ScheduleComposite() {
804 if (!suppress_schedule_composite_
)
805 widget_
->scheduleComposite();
808 void RenderWidgetCompositor::ScheduleAnimation() {
809 widget_
->scheduleAnimation();
812 void RenderWidgetCompositor::DidPostSwapBuffers() {
813 widget_
->OnSwapBuffersPosted();
816 void RenderWidgetCompositor::DidAbortSwapBuffers() {
817 widget_
->OnSwapBuffersAborted();
820 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() {
821 cc::ContextProvider
* provider
=
822 RenderThreadImpl::current()->SharedMainThreadContextProvider().get();
823 provider
->ContextGL()->RateLimitOffscreenContextCHROMIUM();
826 } // namespace content