Add trace event for addition/removal of GPU rasterization trigger
[chromium-blink-merge.git] / content / renderer / gpu / render_widget_compositor.cc
blobf1f6101c2d1422c07ff1b10c9d6f021ef7a8c7f0
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"
7 #include <limits>
8 #include <string>
10 #if defined(OS_ANDROID)
11 #include "base/android/sys_utils.h"
12 #endif
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"
45 namespace base {
46 class Value;
49 namespace cc {
50 class Layer;
53 using blink::WebFloatPoint;
54 using blink::WebSize;
55 using blink::WebRect;
57 namespace content {
58 namespace {
60 bool GetSwitchValueAsInt(
61 const CommandLine& command_line,
62 const std::string& switch_string,
63 int min_value,
64 int max_value,
65 int* result) {
66 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
67 int int_value;
68 if (base::StringToInt(string_value, &int_value) &&
69 int_value >= min_value && int_value <= max_value) {
70 *result = int_value;
71 return true;
72 } else {
73 LOG(WARNING) << "Failed to parse switch " << switch_string << ": " <<
74 string_value;
75 return false;
79 } // namespace
81 // static
82 scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create(
83 RenderWidget* widget,
84 bool threaded) {
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.
145 if (render_thread) {
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) &&
171 controls_height > 0)
172 settings.top_controls_height = controls_height;
175 if (settings.calculate_top_controls_position &&
176 settings.top_controls_height <= 0) {
177 DCHECK(false)
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;
233 GetSwitchValueAsInt(
234 *cmd,
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(
253 *cmd,
254 cc::switches::kMaxUnusedResourceMemoryUsagePercentage,
255 0, 100,
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;
271 } else {
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;
293 } else {
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 settings.scrollbar_animator = cc::LayerTreeSettings::Thinning;
306 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
307 } else if (cmd->HasSwitch(cc::switches::kEnablePinchVirtualViewport)) {
308 // use_pinch_zoom_scrollbars is only true on desktop when non-overlay
309 // scrollbars are in use.
310 settings.use_pinch_zoom_scrollbars = true;
311 settings.scrollbar_animator = cc::LayerTreeSettings::LinearFade;
312 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
314 settings.scrollbar_fade_delay_ms = 500;
315 settings.scrollbar_fade_duration_ms = 300;
316 #endif
318 compositor->Initialize(settings);
320 return compositor.Pass();
323 RenderWidgetCompositor::RenderWidgetCompositor(RenderWidget* widget,
324 bool threaded)
325 : threaded_(threaded),
326 suppress_schedule_composite_(false),
327 widget_(widget) {
330 RenderWidgetCompositor::~RenderWidgetCompositor() {}
332 const base::WeakPtr<cc::InputHandler>&
333 RenderWidgetCompositor::GetInputHandler() {
334 return layer_tree_host_->GetInputHandler();
337 void RenderWidgetCompositor::SetSuppressScheduleComposite(bool suppress) {
338 if (suppress_schedule_composite_ == suppress)
339 return;
341 if (suppress)
342 TRACE_EVENT_ASYNC_BEGIN0("gpu",
343 "RenderWidgetCompositor::SetSuppressScheduleComposite", this);
344 else
345 TRACE_EVENT_ASYNC_END0("gpu",
346 "RenderWidgetCompositor::SetSuppressScheduleComposite", this);
347 suppress_schedule_composite_ = suppress;
350 bool RenderWidgetCompositor::BeginMainFrameRequested() const {
351 return layer_tree_host_->BeginMainFrameRequested();
354 void RenderWidgetCompositor::UpdateAnimations(base::TimeTicks time) {
355 layer_tree_host_->UpdateClientAnimations(time);
358 void RenderWidgetCompositor::SetNeedsDisplayOnAllLayers() {
359 layer_tree_host_->SetNeedsDisplayOnAllLayers();
362 void RenderWidgetCompositor::SetRasterizeOnlyVisibleContent() {
363 cc::LayerTreeDebugState current = layer_tree_host_->debug_state();
364 current.rasterize_only_visible_content = true;
365 layer_tree_host_->SetDebugState(current);
368 void RenderWidgetCompositor::UpdateTopControlsState(
369 cc::TopControlsState constraints,
370 cc::TopControlsState current,
371 bool animate) {
372 layer_tree_host_->UpdateTopControlsState(constraints,
373 current,
374 animate);
377 void RenderWidgetCompositor::SetOverdrawBottomHeight(
378 float overdraw_bottom_height) {
379 layer_tree_host_->SetOverdrawBottomHeight(overdraw_bottom_height);
382 void RenderWidgetCompositor::SetNeedsRedrawRect(gfx::Rect damage_rect) {
383 layer_tree_host_->SetNeedsRedrawRect(damage_rect);
386 void RenderWidgetCompositor::SetNeedsForcedRedraw() {
387 layer_tree_host_->SetNextCommitForcesRedraw();
388 setNeedsAnimate();
391 scoped_ptr<cc::SwapPromiseMonitor>
392 RenderWidgetCompositor::CreateLatencyInfoSwapPromiseMonitor(
393 ui::LatencyInfo* latency) {
394 return scoped_ptr<cc::SwapPromiseMonitor>(
395 new cc::LatencyInfoSwapPromiseMonitor(
396 latency, layer_tree_host_.get(), NULL));
399 void RenderWidgetCompositor::QueueSwapPromise(
400 scoped_ptr<cc::SwapPromise> swap_promise) {
401 layer_tree_host_->QueueSwapPromise(swap_promise.Pass());
404 int RenderWidgetCompositor::GetLayerTreeId() const {
405 return layer_tree_host_->id();
408 void RenderWidgetCompositor::NotifyInputThrottledUntilCommit() {
409 layer_tree_host_->NotifyInputThrottledUntilCommit();
412 const cc::Layer* RenderWidgetCompositor::GetRootLayer() const {
413 return layer_tree_host_->root_layer();
416 int RenderWidgetCompositor::ScheduleMicroBenchmark(
417 const std::string& name,
418 scoped_ptr<base::Value> value,
419 const base::Callback<void(scoped_ptr<base::Value>)>& callback) {
420 return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback);
423 bool RenderWidgetCompositor::SendMessageToMicroBenchmark(
424 int id,
425 scoped_ptr<base::Value> value) {
426 return layer_tree_host_->SendMessageToMicroBenchmark(id, value.Pass());
429 void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) {
430 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy;
431 RenderThreadImpl* render_thread = RenderThreadImpl::current();
432 cc::SharedBitmapManager* shared_bitmap_manager = NULL;
433 // render_thread may be NULL in tests.
434 if (render_thread) {
435 compositor_message_loop_proxy =
436 render_thread->compositor_message_loop_proxy();
437 shared_bitmap_manager = render_thread->shared_bitmap_manager();
439 if (compositor_message_loop_proxy.get()) {
440 layer_tree_host_ = cc::LayerTreeHost::CreateThreaded(
441 this, shared_bitmap_manager, settings, compositor_message_loop_proxy);
442 } else {
443 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(
444 this, this, shared_bitmap_manager, settings);
446 DCHECK(layer_tree_host_);
449 void RenderWidgetCompositor::setSurfaceReady() {
450 layer_tree_host_->SetLayerTreeHostClientReady();
453 void RenderWidgetCompositor::setRootLayer(const blink::WebLayer& layer) {
454 layer_tree_host_->SetRootLayer(
455 static_cast<const webkit::WebLayerImpl*>(&layer)->layer());
458 void RenderWidgetCompositor::clearRootLayer() {
459 layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
462 void RenderWidgetCompositor::setViewportSize(
463 const WebSize&,
464 const WebSize& device_viewport_size) {
465 layer_tree_host_->SetViewportSize(device_viewport_size);
468 void RenderWidgetCompositor::setViewportSize(
469 const WebSize& device_viewport_size) {
470 layer_tree_host_->SetViewportSize(device_viewport_size);
473 WebSize RenderWidgetCompositor::layoutViewportSize() const {
474 return layer_tree_host_->device_viewport_size();
477 WebSize RenderWidgetCompositor::deviceViewportSize() const {
478 return layer_tree_host_->device_viewport_size();
481 WebFloatPoint RenderWidgetCompositor::adjustEventPointForPinchZoom(
482 const WebFloatPoint& point) const {
483 return point;
486 void RenderWidgetCompositor::setDeviceScaleFactor(float device_scale) {
487 layer_tree_host_->SetDeviceScaleFactor(device_scale);
490 float RenderWidgetCompositor::deviceScaleFactor() const {
491 return layer_tree_host_->device_scale_factor();
494 void RenderWidgetCompositor::setBackgroundColor(blink::WebColor color) {
495 layer_tree_host_->set_background_color(color);
498 void RenderWidgetCompositor::setHasTransparentBackground(bool transparent) {
499 layer_tree_host_->set_has_transparent_background(transparent);
502 void RenderWidgetCompositor::setOverhangBitmap(const SkBitmap& bitmap) {
503 layer_tree_host_->SetOverhangBitmap(bitmap);
506 void RenderWidgetCompositor::setVisible(bool visible) {
507 layer_tree_host_->SetVisible(visible);
510 void RenderWidgetCompositor::setPageScaleFactorAndLimits(
511 float page_scale_factor, float minimum, float maximum) {
512 layer_tree_host_->SetPageScaleFactorAndLimits(
513 page_scale_factor, minimum, maximum);
516 void RenderWidgetCompositor::startPageScaleAnimation(
517 const blink::WebPoint& destination,
518 bool use_anchor,
519 float new_page_scale,
520 double duration_sec) {
521 base::TimeDelta duration = base::TimeDelta::FromMicroseconds(
522 duration_sec * base::Time::kMicrosecondsPerSecond);
523 layer_tree_host_->StartPageScaleAnimation(
524 gfx::Vector2d(destination.x, destination.y),
525 use_anchor,
526 new_page_scale,
527 duration);
530 void RenderWidgetCompositor::heuristicsForGpuRasterizationUpdated(
531 bool matches_heuristics) {
532 layer_tree_host_->SetHasGpuRasterizationTrigger(matches_heuristics);
535 void RenderWidgetCompositor::setNeedsAnimate() {
536 layer_tree_host_->SetNeedsAnimate();
539 bool RenderWidgetCompositor::commitRequested() const {
540 return layer_tree_host_->CommitRequested();
543 void RenderWidgetCompositor::didStopFlinging() {
544 layer_tree_host_->DidStopFlinging();
547 void RenderWidgetCompositor::registerForAnimations(blink::WebLayer* layer) {
548 cc::Layer* cc_layer = static_cast<webkit::WebLayerImpl*>(layer)->layer();
549 cc_layer->layer_animation_controller()->SetAnimationRegistrar(
550 layer_tree_host_->animation_registrar());
553 void RenderWidgetCompositor::registerViewportLayers(
554 const blink::WebLayer* pageScaleLayer,
555 const blink::WebLayer* innerViewportScrollLayer,
556 const blink::WebLayer* outerViewportScrollLayer) {
557 layer_tree_host_->RegisterViewportLayers(
558 static_cast<const webkit::WebLayerImpl*>(pageScaleLayer)->layer(),
559 static_cast<const webkit::WebLayerImpl*>(innerViewportScrollLayer)
560 ->layer(),
561 // The outer viewport layer will only exist when using pinch virtual
562 // viewports.
563 outerViewportScrollLayer ? static_cast<const webkit::WebLayerImpl*>(
564 outerViewportScrollLayer)->layer()
565 : NULL);
568 void RenderWidgetCompositor::clearViewportLayers() {
569 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
570 scoped_refptr<cc::Layer>(),
571 scoped_refptr<cc::Layer>());
574 void CompositeAndReadbackAsyncCallback(
575 blink::WebCompositeAndReadbackAsyncCallback* callback,
576 scoped_ptr<cc::CopyOutputResult> result) {
577 if (result->HasBitmap()) {
578 scoped_ptr<SkBitmap> result_bitmap = result->TakeBitmap();
579 callback->didCompositeAndReadback(*result_bitmap);
580 } else {
581 callback->didCompositeAndReadback(SkBitmap());
585 void RenderWidgetCompositor::compositeAndReadbackAsync(
586 blink::WebCompositeAndReadbackAsyncCallback* callback) {
587 DCHECK(layer_tree_host_->root_layer());
588 scoped_ptr<cc::CopyOutputRequest> request =
589 cc::CopyOutputRequest::CreateBitmapRequest(
590 base::Bind(&CompositeAndReadbackAsyncCallback, callback));
591 layer_tree_host_->root_layer()->RequestCopyOfOutput(request.Pass());
592 if (!threaded_) {
593 widget_->webwidget()->animate(0.0);
594 widget_->webwidget()->layout();
595 layer_tree_host_->Composite(gfx::FrameTime::Now());
599 void RenderWidgetCompositor::finishAllRendering() {
600 layer_tree_host_->FinishAllRendering();
603 void RenderWidgetCompositor::setDeferCommits(bool defer_commits) {
604 layer_tree_host_->SetDeferCommits(defer_commits);
607 void RenderWidgetCompositor::setShowFPSCounter(bool show) {
608 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
609 debug_state.show_fps_counter = show;
610 layer_tree_host_->SetDebugState(debug_state);
613 void RenderWidgetCompositor::setShowPaintRects(bool show) {
614 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
615 debug_state.show_paint_rects = show;
616 layer_tree_host_->SetDebugState(debug_state);
619 void RenderWidgetCompositor::setShowDebugBorders(bool show) {
620 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
621 debug_state.show_debug_borders = show;
622 layer_tree_host_->SetDebugState(debug_state);
625 void RenderWidgetCompositor::setContinuousPaintingEnabled(bool enabled) {
626 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
627 debug_state.continuous_painting = enabled;
628 layer_tree_host_->SetDebugState(debug_state);
631 void RenderWidgetCompositor::setShowScrollBottleneckRects(bool show) {
632 cc::LayerTreeDebugState debug_state = layer_tree_host_->debug_state();
633 debug_state.show_touch_event_handler_rects = show;
634 debug_state.show_wheel_event_handler_rects = show;
635 debug_state.show_non_fast_scrollable_rects = show;
636 layer_tree_host_->SetDebugState(debug_state);
639 void RenderWidgetCompositor::WillBeginMainFrame(int frame_id) {
640 widget_->InstrumentWillBeginFrame(frame_id);
641 widget_->willBeginCompositorFrame();
644 void RenderWidgetCompositor::DidBeginMainFrame() {
645 widget_->InstrumentDidBeginFrame();
648 void RenderWidgetCompositor::Animate(base::TimeTicks frame_begin_time) {
649 widget_->webwidget()->animate(
650 (frame_begin_time - base::TimeTicks()).InSecondsF());
653 void RenderWidgetCompositor::Layout() {
654 widget_->webwidget()->layout();
657 void RenderWidgetCompositor::ApplyScrollAndScale(
658 const gfx::Vector2d& scroll_delta,
659 float page_scale) {
660 widget_->webwidget()->applyScrollAndScale(scroll_delta, page_scale);
663 scoped_ptr<cc::OutputSurface> RenderWidgetCompositor::CreateOutputSurface(
664 bool fallback) {
665 return widget_->CreateOutputSurface(fallback);
668 void RenderWidgetCompositor::DidInitializeOutputSurface() {
671 void RenderWidgetCompositor::WillCommit() {
672 widget_->InstrumentWillComposite();
675 void RenderWidgetCompositor::DidCommit() {
676 widget_->DidCommitCompositorFrame();
677 widget_->didBecomeReadyForAdditionalInput();
680 void RenderWidgetCompositor::DidCommitAndDrawFrame() {
681 widget_->didCommitAndDrawCompositorFrame();
684 void RenderWidgetCompositor::DidCompleteSwapBuffers() {
685 widget_->didCompleteSwapBuffers();
686 if (!threaded_)
687 widget_->OnSwapBuffersComplete();
690 void RenderWidgetCompositor::ScheduleComposite() {
691 if (!suppress_schedule_composite_)
692 widget_->scheduleComposite();
695 void RenderWidgetCompositor::ScheduleAnimation() {
696 widget_->scheduleAnimation();
699 void RenderWidgetCompositor::DidPostSwapBuffers() {
700 widget_->OnSwapBuffersPosted();
703 void RenderWidgetCompositor::DidAbortSwapBuffers() {
704 widget_->OnSwapBuffersAborted();
707 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() {
708 cc::ContextProvider* provider =
709 RenderThreadImpl::current()->SharedMainThreadContextProvider().get();
710 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM();
713 } // namespace content