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 #if defined(OS_ANDROID)
11 #include "base/android/sys_utils.h"
14 #include "base/command_line.h"
15 #include "base/logging.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/synchronization/lock.h"
18 #include "base/time/time.h"
19 #include "base/values.h"
20 #include "cc/base/latency_info_swap_promise.h"
21 #include "cc/base/latency_info_swap_promise_monitor.h"
22 #include "cc/base/switches.h"
23 #include "cc/debug/layer_tree_debug_state.h"
24 #include "cc/debug/micro_benchmark.h"
25 #include "cc/layers/layer.h"
26 #include "cc/output/copy_output_request.h"
27 #include "cc/output/copy_output_result.h"
28 #include "cc/resources/single_release_callback.h"
29 #include "cc/trees/layer_tree_host.h"
30 #include "content/child/child_shared_bitmap_manager.h"
31 #include "content/common/content_switches_internal.h"
32 #include "content/common/gpu/client/context_provider_command_buffer.h"
33 #include "content/public/common/content_switches.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/WebSize.h"
39 #include "third_party/WebKit/public/web/WebWidget.h"
40 #include "ui/gfx/frame_time.h"
41 #include "ui/gl/gl_switches.h"
42 #include "ui/native_theme/native_theme_switches.h"
43 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
53 using blink::WebFloatPoint;
60 bool GetSwitchValueAsInt(
61 const CommandLine& command_line,
62 const std::string& switch_string,
66 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
68 if (base::StringToInt(string_value, &int_value) &&
69 int_value >= min_value && int_value <= max_value) {
73 LOG(WARNING) << "Failed to parse switch " << switch_string << ": " <<
82 scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create(
85 scoped_ptr<RenderWidgetCompositor> compositor(
86 new RenderWidgetCompositor(widget, threaded));
88 CommandLine* cmd = CommandLine::ForCurrentProcess();
90 cc::LayerTreeSettings settings;
92 // For web contents, layer transforms should scale up the contents of layers
93 // to keep content always crisp when possible.
94 settings.layer_transforms_should_scale_layer_contents = true;
96 settings.throttle_frame_production =
97 !cmd->HasSwitch(switches::kDisableGpuVsync);
98 settings.begin_frame_scheduling_enabled =
99 cmd->HasSwitch(switches::kEnableBeginFrameScheduling);
100 settings.main_frame_before_activation_enabled =
101 cmd->HasSwitch(cc::switches::kEnableMainFrameBeforeActivation) &&
102 !cmd->HasSwitch(cc::switches::kDisableMainFrameBeforeActivation);
103 settings.main_frame_before_draw_enabled =
104 !cmd->HasSwitch(cc::switches::kDisableMainFrameBeforeDraw);
105 settings.using_synchronous_renderer_compositor =
106 widget->UsingSynchronousRendererCompositor();
107 settings.report_overscroll_only_for_scrollable_axes =
108 !widget->UsingSynchronousRendererCompositor();
109 settings.accelerated_animation_enabled =
110 !cmd->HasSwitch(cc::switches::kDisableThreadedAnimation);
111 settings.touch_hit_testing =
112 !cmd->HasSwitch(cc::switches::kDisableCompositorTouchHitTesting);
114 int default_tile_width = settings.default_tile_size.width();
115 if (cmd->HasSwitch(switches::kDefaultTileWidth)) {
116 GetSwitchValueAsInt(*cmd, switches::kDefaultTileWidth, 1,
117 std::numeric_limits<int>::max(), &default_tile_width);
119 int default_tile_height = settings.default_tile_size.height();
120 if (cmd->HasSwitch(switches::kDefaultTileHeight)) {
121 GetSwitchValueAsInt(*cmd, switches::kDefaultTileHeight, 1,
122 std::numeric_limits<int>::max(), &default_tile_height);
124 settings.default_tile_size = gfx::Size(default_tile_width,
125 default_tile_height);
127 int max_untiled_layer_width = settings.max_untiled_layer_size.width();
128 if (cmd->HasSwitch(switches::kMaxUntiledLayerWidth)) {
129 GetSwitchValueAsInt(*cmd, switches::kMaxUntiledLayerWidth, 1,
130 std::numeric_limits<int>::max(),
131 &max_untiled_layer_width);
133 int max_untiled_layer_height = settings.max_untiled_layer_size.height();
134 if (cmd->HasSwitch(switches::kMaxUntiledLayerHeight)) {
135 GetSwitchValueAsInt(*cmd, switches::kMaxUntiledLayerHeight, 1,
136 std::numeric_limits<int>::max(),
137 &max_untiled_layer_height);
140 settings.max_untiled_layer_size = gfx::Size(max_untiled_layer_width,
141 max_untiled_layer_height);
143 RenderThreadImpl* render_thread = RenderThreadImpl::current();
144 // render_thread may be NULL in tests.
146 settings.impl_side_painting =
147 render_thread->is_impl_side_painting_enabled();
148 settings.gpu_rasterization_forced =
149 render_thread->is_gpu_rasterization_forced();
150 settings.gpu_rasterization_enabled =
151 render_thread->is_gpu_rasterization_enabled();
152 settings.create_low_res_tiling = render_thread->is_low_res_tiling_enabled();
153 settings.can_use_lcd_text = render_thread->is_lcd_text_enabled();
154 settings.use_distance_field_text =
155 render_thread->is_distance_field_text_enabled();
156 settings.use_zero_copy = render_thread->is_zero_copy_enabled();
157 settings.use_one_copy = render_thread->is_one_copy_enabled();
160 if (cmd->HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths)) {
161 settings.recording_mode = cc::LayerTreeSettings::RecordWithSkRecord;
164 settings.calculate_top_controls_position =
165 cmd->HasSwitch(cc::switches::kEnableTopControlsPositionCalculation);
166 if (cmd->HasSwitch(cc::switches::kTopControlsHeight)) {
167 std::string controls_height_str =
168 cmd->GetSwitchValueASCII(cc::switches::kTopControlsHeight);
169 double controls_height;
170 if (base::StringToDouble(controls_height_str, &controls_height) &&
172 settings.top_controls_height = controls_height;
175 if (settings.calculate_top_controls_position &&
176 settings.top_controls_height <= 0) {
178 << "Top controls repositioning enabled without valid height set.";
179 settings.calculate_top_controls_position = false;
182 if (cmd->HasSwitch(cc::switches::kTopControlsShowThreshold)) {
183 std::string top_threshold_str =
184 cmd->GetSwitchValueASCII(cc::switches::kTopControlsShowThreshold);
185 double show_threshold;
186 if (base::StringToDouble(top_threshold_str, &show_threshold) &&
187 show_threshold >= 0.f && show_threshold <= 1.f)
188 settings.top_controls_show_threshold = show_threshold;
191 if (cmd->HasSwitch(cc::switches::kTopControlsHideThreshold)) {
192 std::string top_threshold_str =
193 cmd->GetSwitchValueASCII(cc::switches::kTopControlsHideThreshold);
194 double hide_threshold;
195 if (base::StringToDouble(top_threshold_str, &hide_threshold) &&
196 hide_threshold >= 0.f && hide_threshold <= 1.f)
197 settings.top_controls_hide_threshold = hide_threshold;
200 settings.use_pinch_virtual_viewport =
201 cmd->HasSwitch(cc::switches::kEnablePinchVirtualViewport);
202 settings.allow_antialiasing &=
203 !cmd->HasSwitch(cc::switches::kDisableCompositedAntialiasing);
205 // These flags should be mirrored by UI versions in ui/compositor/.
206 settings.initial_debug_state.show_debug_borders =
207 cmd->HasSwitch(cc::switches::kShowCompositedLayerBorders);
208 settings.initial_debug_state.show_fps_counter =
209 cmd->HasSwitch(cc::switches::kShowFPSCounter);
210 settings.initial_debug_state.show_layer_animation_bounds_rects =
211 cmd->HasSwitch(cc::switches::kShowLayerAnimationBounds);
212 settings.initial_debug_state.show_paint_rects =
213 cmd->HasSwitch(switches::kShowPaintRects);
214 settings.initial_debug_state.show_property_changed_rects =
215 cmd->HasSwitch(cc::switches::kShowPropertyChangedRects);
216 settings.initial_debug_state.show_surface_damage_rects =
217 cmd->HasSwitch(cc::switches::kShowSurfaceDamageRects);
218 settings.initial_debug_state.show_screen_space_rects =
219 cmd->HasSwitch(cc::switches::kShowScreenSpaceRects);
220 settings.initial_debug_state.show_replica_screen_space_rects =
221 cmd->HasSwitch(cc::switches::kShowReplicaScreenSpaceRects);
222 settings.initial_debug_state.show_occluding_rects =
223 cmd->HasSwitch(cc::switches::kShowOccludingRects);
224 settings.initial_debug_state.show_non_occluding_rects =
225 cmd->HasSwitch(cc::switches::kShowNonOccludingRects);
227 settings.initial_debug_state.SetRecordRenderingStats(
228 cmd->HasSwitch(cc::switches::kEnableGpuBenchmarking));
230 if (cmd->HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) {
231 const int kMinSlowDownScaleFactor = 0;
232 const int kMaxSlowDownScaleFactor = INT_MAX;
235 cc::switches::kSlowDownRasterScaleFactor,
236 kMinSlowDownScaleFactor,
237 kMaxSlowDownScaleFactor,
238 &settings.initial_debug_state.slow_down_raster_scale_factor);
241 if (cmd->HasSwitch(cc::switches::kMaxTilesForInterestArea)) {
242 int max_tiles_for_interest_area;
243 if (GetSwitchValueAsInt(*cmd,
244 cc::switches::kMaxTilesForInterestArea,
245 1, std::numeric_limits<int>::max(),
246 &max_tiles_for_interest_area))
247 settings.max_tiles_for_interest_area = max_tiles_for_interest_area;
250 if (cmd->HasSwitch(cc::switches::kMaxUnusedResourceMemoryUsagePercentage)) {
251 int max_unused_resource_memory_percentage;
252 if (GetSwitchValueAsInt(
254 cc::switches::kMaxUnusedResourceMemoryUsagePercentage,
256 &max_unused_resource_memory_percentage)) {
257 settings.max_unused_resource_memory_percentage =
258 max_unused_resource_memory_percentage;
262 settings.strict_layer_property_change_checking =
263 cmd->HasSwitch(cc::switches::kStrictLayerPropertyChangeChecking);
265 #if defined(OS_ANDROID)
266 settings.max_partial_texture_updates = 0;
267 if (widget->UsingSynchronousRendererCompositor()) {
268 // Android WebView uses system scrollbars, so make ours invisible.
269 settings.scrollbar_animator = cc::LayerTreeSettings::NoAnimator;
270 settings.solid_color_scrollbar_color = SK_ColorTRANSPARENT;
272 settings.scrollbar_animator = cc::LayerTreeSettings::LinearFade;
273 settings.scrollbar_fade_delay_ms = 300;
274 settings.scrollbar_fade_duration_ms = 300;
275 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
277 settings.highp_threshold_min = 2048;
278 // Android WebView handles root layer flings itself.
279 settings.ignore_root_layer_flings =
280 widget->UsingSynchronousRendererCompositor();
281 // RGBA_4444 textures are only enabled for low end devices
282 // and are disabled for Android WebView as it doesn't support the format.
283 settings.use_rgba_4444_textures =
284 base::android::SysUtils::IsLowEndDevice() &&
285 !widget->UsingSynchronousRendererCompositor();
286 if (widget->UsingSynchronousRendererCompositor()) {
287 // TODO(boliu): Set this ratio for Webview.
288 } else if (base::android::SysUtils::IsLowEndDevice()) {
289 // On low-end we want to be very carefull about killing other
290 // apps. So initially we use 50% more memory to avoid flickering
291 // or raster-on-demand.
292 settings.max_memory_for_prepaint_percentage = 67;
294 // On other devices we have increased memory excessively to avoid
295 // raster-on-demand already, so now we reserve 50% _only_ to avoid
296 // raster-on-demand, and use 50% of the memory otherwise.
297 settings.max_memory_for_prepaint_percentage = 50;
299 // Webview does not own the surface so should not clear it.
300 settings.should_clear_root_render_pass =
301 !widget->UsingSynchronousRendererCompositor();
303 #elif !defined(OS_MACOSX)
304 if (ui::IsOverlayScrollbarEnabled()) {
305 #if defined(OS_TIZEN)
306 // Tizen fades out the scrollbar after contents interaction ends.
307 settings.scrollbar_animator = cc::LayerTreeSettings::LinearFade;
309 settings.scrollbar_animator = cc::LayerTreeSettings::Thinning;
311 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
312 } else if (cmd->HasSwitch(cc::switches::kEnablePinchVirtualViewport)) {
313 // use_pinch_zoom_scrollbars is only true on desktop when non-overlay
314 // scrollbars are in use.
315 settings.use_pinch_zoom_scrollbars = true;
316 settings.scrollbar_animator = cc::LayerTreeSettings::LinearFade;
317 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
319 settings.scrollbar_fade_delay_ms = 500;
320 settings.scrollbar_fade_duration_ms = 300;
323 compositor->Initialize(settings);
325 return compositor.Pass();
328 RenderWidgetCompositor::RenderWidgetCompositor(RenderWidget* widget,
330 : threaded_(threaded),
331 suppress_schedule_composite_(false),
335 RenderWidgetCompositor::~RenderWidgetCompositor() {}
337 const base::WeakPtr<cc::InputHandler>&
338 RenderWidgetCompositor::GetInputHandler() {
339 return layer_tree_host_->GetInputHandler();
342 void RenderWidgetCompositor::SetSuppressScheduleComposite(bool suppress) {
343 if (suppress_schedule_composite_ == suppress)
347 TRACE_EVENT_ASYNC_BEGIN0("gpu",
348 "RenderWidgetCompositor::SetSuppressScheduleComposite", this);
350 TRACE_EVENT_ASYNC_END0("gpu",
351 "RenderWidgetCompositor::SetSuppressScheduleComposite", this);
352 suppress_schedule_composite_ = suppress;
355 bool RenderWidgetCompositor::BeginMainFrameRequested() const {
356 return layer_tree_host_->BeginMainFrameRequested();
359 void RenderWidgetCompositor::UpdateAnimations(base::TimeTicks time) {
360 layer_tree_host_->UpdateClientAnimations(time);
363 void RenderWidgetCompositor::Composite(base::TimeTicks frame_begin_time) {
364 layer_tree_host_->Composite(frame_begin_time);
367 void RenderWidgetCompositor::SetNeedsDisplayOnAllLayers() {
368 layer_tree_host_->SetNeedsDisplayOnAllLayers();
371 void RenderWidgetCompositor::SetRasterizeOnlyVisibleContent() {
372 cc::LayerTreeDebugState current = layer_tree_host_->debug_state();
373 current.rasterize_only_visible_content = true;
374 layer_tree_host_->SetDebugState(current);
377 void RenderWidgetCompositor::UpdateTopControlsState(
378 cc::TopControlsState constraints,
379 cc::TopControlsState current,
381 layer_tree_host_->UpdateTopControlsState(constraints,
386 void RenderWidgetCompositor::SetOverdrawBottomHeight(
387 float overdraw_bottom_height) {
388 layer_tree_host_->SetOverdrawBottomHeight(overdraw_bottom_height);
391 void RenderWidgetCompositor::SetNeedsRedrawRect(gfx::Rect damage_rect) {
392 layer_tree_host_->SetNeedsRedrawRect(damage_rect);
395 void RenderWidgetCompositor::SetNeedsForcedRedraw() {
396 layer_tree_host_->SetNextCommitForcesRedraw();
400 scoped_ptr<cc::SwapPromiseMonitor>
401 RenderWidgetCompositor::CreateLatencyInfoSwapPromiseMonitor(
402 ui::LatencyInfo* latency) {
403 return scoped_ptr<cc::SwapPromiseMonitor>(
404 new cc::LatencyInfoSwapPromiseMonitor(
405 latency, layer_tree_host_.get(), NULL));
408 int RenderWidgetCompositor::GetLayerTreeId() const {
409 return layer_tree_host_->id();
412 void RenderWidgetCompositor::NotifyInputThrottledUntilCommit() {
413 layer_tree_host_->NotifyInputThrottledUntilCommit();
416 const cc::Layer* RenderWidgetCompositor::GetRootLayer() const {
417 return layer_tree_host_->root_layer();
420 bool RenderWidgetCompositor::ScheduleMicroBenchmark(
421 const std::string& name,
422 scoped_ptr<base::Value> value,
423 const base::Callback<void(scoped_ptr<base::Value>)>& callback) {
424 return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback);
427 void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) {
428 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy;
429 RenderThreadImpl* render_thread = RenderThreadImpl::current();
430 cc::SharedBitmapManager* shared_bitmap_manager = NULL;
431 // render_thread may be NULL in tests.
433 compositor_message_loop_proxy =
434 render_thread->compositor_message_loop_proxy();
435 shared_bitmap_manager = render_thread->shared_bitmap_manager();
437 if (compositor_message_loop_proxy.get()) {
438 layer_tree_host_ = cc::LayerTreeHost::CreateThreaded(
439 this, shared_bitmap_manager, settings, compositor_message_loop_proxy);
441 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(
442 this, this, shared_bitmap_manager, settings);
444 DCHECK(layer_tree_host_);
447 void RenderWidgetCompositor::setSurfaceReady() {
448 layer_tree_host_->SetLayerTreeHostClientReady();
451 void RenderWidgetCompositor::setRootLayer(const blink::WebLayer& layer) {
452 layer_tree_host_->SetRootLayer(
453 static_cast<const webkit::WebLayerImpl*>(&layer)->layer());
456 void RenderWidgetCompositor::clearRootLayer() {
457 layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
460 void RenderWidgetCompositor::setViewportSize(
462 const WebSize& device_viewport_size) {
463 layer_tree_host_->SetViewportSize(device_viewport_size);
466 WebSize RenderWidgetCompositor::layoutViewportSize() const {
467 return layer_tree_host_->device_viewport_size();
470 WebSize RenderWidgetCompositor::deviceViewportSize() const {
471 return layer_tree_host_->device_viewport_size();
474 WebFloatPoint RenderWidgetCompositor::adjustEventPointForPinchZoom(
475 const WebFloatPoint& point) const {
479 void RenderWidgetCompositor::setDeviceScaleFactor(float device_scale) {
480 layer_tree_host_->SetDeviceScaleFactor(device_scale);
483 float RenderWidgetCompositor::deviceScaleFactor() const {
484 return layer_tree_host_->device_scale_factor();
487 void RenderWidgetCompositor::setBackgroundColor(blink::WebColor color) {
488 layer_tree_host_->set_background_color(color);
491 void RenderWidgetCompositor::setHasTransparentBackground(bool transparent) {
492 layer_tree_host_->set_has_transparent_background(transparent);
495 void RenderWidgetCompositor::setOverhangBitmap(const SkBitmap& bitmap) {
496 layer_tree_host_->SetOverhangBitmap(bitmap);
499 void RenderWidgetCompositor::setVisible(bool visible) {
500 layer_tree_host_->SetVisible(visible);
503 void RenderWidgetCompositor::setPageScaleFactorAndLimits(
504 float page_scale_factor, float minimum, float maximum) {
505 layer_tree_host_->SetPageScaleFactorAndLimits(
506 page_scale_factor, minimum, maximum);
509 void RenderWidgetCompositor::startPageScaleAnimation(
510 const blink::WebPoint& destination,
512 float new_page_scale,
513 double duration_sec) {
514 base::TimeDelta duration = base::TimeDelta::FromMicroseconds(
515 duration_sec * base::Time::kMicrosecondsPerSecond);
516 layer_tree_host_->StartPageScaleAnimation(
517 gfx::Vector2d(destination.x, destination.y),
523 void RenderWidgetCompositor::heuristicsForGpuRasterizationUpdated(
524 bool matches_heuristics) {
525 layer_tree_host_->set_has_gpu_rasterization_trigger(matches_heuristics);
528 void RenderWidgetCompositor::setNeedsAnimate() {
529 layer_tree_host_->SetNeedsAnimate();
532 bool RenderWidgetCompositor::commitRequested() const {
533 return layer_tree_host_->CommitRequested();
536 void RenderWidgetCompositor::didStopFlinging() {
537 layer_tree_host_->DidStopFlinging();
540 void RenderWidgetCompositor::registerForAnimations(blink::WebLayer* layer) {
541 cc::Layer* cc_layer = static_cast<webkit::WebLayerImpl*>(layer)->layer();
542 cc_layer->layer_animation_controller()->SetAnimationRegistrar(
543 layer_tree_host_->animation_registrar());
546 void RenderWidgetCompositor::registerViewportLayers(
547 const blink::WebLayer* pageScaleLayer,
548 const blink::WebLayer* innerViewportScrollLayer,
549 const blink::WebLayer* outerViewportScrollLayer) {
550 layer_tree_host_->RegisterViewportLayers(
551 static_cast<const webkit::WebLayerImpl*>(pageScaleLayer)->layer(),
552 static_cast<const webkit::WebLayerImpl*>(innerViewportScrollLayer)
554 // The outer viewport layer will only exist when using pinch virtual
556 outerViewportScrollLayer ? static_cast<const webkit::WebLayerImpl*>(
557 outerViewportScrollLayer)->layer()
561 void RenderWidgetCompositor::clearViewportLayers() {
562 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
563 scoped_refptr<cc::Layer>(),
564 scoped_refptr<cc::Layer>());
567 bool RenderWidgetCompositor::compositeAndReadback(
568 void *pixels, const WebRect& rect_in_device_viewport) {
569 return layer_tree_host_->CompositeAndReadback(pixels,
570 rect_in_device_viewport);
573 void CompositeAndReadbackAsyncCallback(
574 blink::WebCompositeAndReadbackAsyncCallback* callback,
575 scoped_ptr<cc::CopyOutputResult> result) {
576 if (result->HasBitmap()) {
577 scoped_ptr<SkBitmap> result_bitmap = result->TakeBitmap();
578 callback->didCompositeAndReadback(*result_bitmap);
580 callback->didCompositeAndReadback(SkBitmap());
584 void RenderWidgetCompositor::compositeAndReadbackAsync(
585 blink::WebCompositeAndReadbackAsyncCallback* callback) {
586 DCHECK(layer_tree_host_->root_layer());
587 scoped_ptr<cc::CopyOutputRequest> request =
588 cc::CopyOutputRequest::CreateBitmapRequest(
589 base::Bind(&CompositeAndReadbackAsyncCallback, callback));
590 layer_tree_host_->root_layer()->RequestCopyOfOutput(request.Pass());
592 widget_->webwidget()->animate(0.0);
593 widget_->webwidget()->layout();
594 layer_tree_host_->Composite(gfx::FrameTime::Now());
598 void RenderWidgetCompositor::finishAllRendering() {
599 layer_tree_host_->FinishAllRendering();
602 void RenderWidgetCompositor::setDeferCommits(bool defer_commits) {
603 layer_tree_host_->SetDeferCommits(defer_commits);
606 void RenderWidgetCompositor::setShowFPSCounter(bool show) {
607 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
608 debug_state.show_fps_counter = show;
609 layer_tree_host_->SetDebugState(debug_state);
612 void RenderWidgetCompositor::setShowPaintRects(bool show) {
613 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
614 debug_state.show_paint_rects = show;
615 layer_tree_host_->SetDebugState(debug_state);
618 void RenderWidgetCompositor::setShowDebugBorders(bool show) {
619 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
620 debug_state.show_debug_borders = show;
621 layer_tree_host_->SetDebugState(debug_state);
624 void RenderWidgetCompositor::setContinuousPaintingEnabled(bool enabled) {
625 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
626 debug_state.continuous_painting = enabled;
627 layer_tree_host_->SetDebugState(debug_state);
630 void RenderWidgetCompositor::setShowScrollBottleneckRects(bool show) {
631 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
632 debug_state.show_touch_event_handler_rects = show;
633 debug_state.show_wheel_event_handler_rects = show;
634 debug_state.show_non_fast_scrollable_rects = show;
635 layer_tree_host_->SetDebugState(debug_state);
638 void RenderWidgetCompositor::WillBeginMainFrame(int frame_id) {
639 widget_->InstrumentWillBeginFrame(frame_id);
640 widget_->willBeginCompositorFrame();
643 void RenderWidgetCompositor::DidBeginMainFrame() {
644 widget_->InstrumentDidBeginFrame();
647 void RenderWidgetCompositor::Animate(base::TimeTicks frame_begin_time) {
648 widget_->webwidget()->animate(
649 (frame_begin_time - base::TimeTicks()).InSecondsF());
652 void RenderWidgetCompositor::Layout() {
653 widget_->webwidget()->layout();
656 void RenderWidgetCompositor::ApplyScrollAndScale(
657 const gfx::Vector2d& scroll_delta,
659 widget_->webwidget()->applyScrollAndScale(scroll_delta, page_scale);
662 scoped_ptr<cc::OutputSurface> RenderWidgetCompositor::CreateOutputSurface(
664 return widget_->CreateOutputSurface(fallback);
667 void RenderWidgetCompositor::DidInitializeOutputSurface() {
670 void RenderWidgetCompositor::WillCommit() {
671 widget_->InstrumentWillComposite();
674 void RenderWidgetCompositor::DidCommit() {
675 widget_->DidCommitCompositorFrame();
676 widget_->didBecomeReadyForAdditionalInput();
679 void RenderWidgetCompositor::DidCommitAndDrawFrame() {
680 widget_->didCommitAndDrawCompositorFrame();
683 void RenderWidgetCompositor::DidCompleteSwapBuffers() {
684 widget_->didCompleteSwapBuffers();
686 widget_->OnSwapBuffersComplete();
689 void RenderWidgetCompositor::ScheduleComposite() {
690 if (!suppress_schedule_composite_)
691 widget_->scheduleComposite();
694 void RenderWidgetCompositor::ScheduleAnimation() {
695 widget_->scheduleAnimation();
698 void RenderWidgetCompositor::DidPostSwapBuffers() {
699 widget_->OnSwapBuffersPosted();
702 void RenderWidgetCompositor::DidAbortSwapBuffers() {
703 widget_->OnSwapBuffersAborted();
706 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() {
707 cc::ContextProvider* provider =
708 RenderThreadImpl::current()->SharedMainThreadContextProvider().get();
709 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM();
712 } // namespace content