1 // Copyright (c) 2012 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/browser/renderer_host/compositor_impl_android.h"
7 #include <android/bitmap.h>
8 #include <android/native_window_jni.h>
10 #include "base/android/jni_android.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/bind.h"
13 #include "base/cancelable_callback.h"
14 #include "base/command_line.h"
15 #include "base/containers/hash_tables.h"
16 #include "base/lazy_instance.h"
17 #include "base/logging.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/single_thread_task_runner.h"
20 #include "base/synchronization/lock.h"
21 #include "base/threading/thread.h"
22 #include "base/threading/thread_checker.h"
23 #include "cc/base/switches.h"
24 #include "cc/input/input_handler.h"
25 #include "cc/layers/layer.h"
26 #include "cc/output/compositor_frame.h"
27 #include "cc/output/context_provider.h"
28 #include "cc/output/output_surface.h"
29 #include "cc/output/output_surface_client.h"
30 #include "cc/scheduler/begin_frame_source.h"
31 #include "cc/surfaces/onscreen_display_client.h"
32 #include "cc/surfaces/surface_display_output_surface.h"
33 #include "cc/surfaces/surface_id_allocator.h"
34 #include "cc/surfaces/surface_manager.h"
35 #include "cc/trees/layer_tree_host.h"
36 #include "content/browser/android/child_process_launcher_android.h"
37 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
38 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
39 #include "content/browser/gpu/compositor_util.h"
40 #include "content/browser/gpu/gpu_surface_tracker.h"
41 #include "content/browser/renderer_host/render_widget_host_impl.h"
42 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
43 #include "content/common/gpu/client/context_provider_command_buffer.h"
44 #include "content/common/gpu/client/gl_helper.h"
45 #include "content/common/gpu/client/gpu_channel_host.h"
46 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
47 #include "content/common/gpu/gpu_process_launch_causes.h"
48 #include "content/common/host_shared_bitmap_manager.h"
49 #include "content/public/browser/android/compositor_client.h"
50 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h"
51 #include "gpu/command_buffer/client/context_support.h"
52 #include "gpu/command_buffer/client/gles2_interface.h"
53 #include "third_party/khronos/GLES2/gl2.h"
54 #include "third_party/khronos/GLES2/gl2ext.h"
55 #include "third_party/skia/include/core/SkMallocPixelRef.h"
56 #include "ui/android/window_android.h"
57 #include "ui/gfx/android/device_display_info.h"
58 #include "ui/gfx/frame_time.h"
59 #include "webkit/common/gpu/context_provider_in_process.h"
65 const unsigned int kMaxSwapBuffers
= 2U;
67 // Used to override capabilities_.adjust_deadline_for_parent to false
68 class OutputSurfaceWithoutParent
: public cc::OutputSurface
{
70 OutputSurfaceWithoutParent(
71 const scoped_refptr
<ContextProviderCommandBuffer
>& context_provider
,
72 base::WeakPtr
<CompositorImpl
> compositor_impl
)
73 : cc::OutputSurface(context_provider
),
74 swap_buffers_completion_callback_(
75 base::Bind(&OutputSurfaceWithoutParent::OnSwapBuffersCompleted
,
76 base::Unretained(this))) {
77 capabilities_
.adjust_deadline_for_parent
= false;
78 capabilities_
.max_frames_pending
= 2;
79 compositor_impl_
= compositor_impl
;
80 main_thread_
= base::MessageLoopProxy::current();
83 void SwapBuffers(cc::CompositorFrame
* frame
) override
{
84 GetCommandBufferProxy()->SetLatencyInfo(frame
->metadata
.latency_info
);
85 DCHECK(frame
->gl_frame_data
->sub_buffer_rect
==
86 gfx::Rect(frame
->gl_frame_data
->size
));
87 context_provider_
->ContextSupport()->Swap();
88 client_
->DidSwapBuffers();
91 bool BindToClient(cc::OutputSurfaceClient
* client
) override
{
92 if (!OutputSurface::BindToClient(client
))
95 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback(
96 swap_buffers_completion_callback_
.callback());
98 main_thread_
->PostTask(
100 base::Bind(&CompositorImpl::PopulateGpuCapabilities
,
102 context_provider_
->ContextCapabilities().gpu
));
108 CommandBufferProxyImpl
* GetCommandBufferProxy() {
109 ContextProviderCommandBuffer
* provider_command_buffer
=
110 static_cast<content::ContextProviderCommandBuffer
*>(
111 context_provider_
.get());
112 CommandBufferProxyImpl
* command_buffer_proxy
=
113 provider_command_buffer
->GetCommandBufferProxy();
114 DCHECK(command_buffer_proxy
);
115 return command_buffer_proxy
;
118 void OnSwapBuffersCompleted(
119 const std::vector
<ui::LatencyInfo
>& latency_info
) {
120 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info
);
121 OutputSurface::OnSwapBuffersComplete();
124 base::CancelableCallback
<void(const std::vector
<ui::LatencyInfo
>&)>
125 swap_buffers_completion_callback_
;
127 scoped_refptr
<base::MessageLoopProxy
> main_thread_
;
128 base::WeakPtr
<CompositorImpl
> compositor_impl_
;
131 static bool g_initialized
= false;
133 bool g_use_surface_manager
= false;
134 base::LazyInstance
<cc::SurfaceManager
> g_surface_manager
=
135 LAZY_INSTANCE_INITIALIZER
;
137 cc::SurfaceManager
* GetSurfaceManager() {
138 if (!g_use_surface_manager
)
140 return g_surface_manager
.Pointer();
143 int g_surface_id_namespace
= 0;
145 } // anonymous namespace
148 Compositor
* Compositor::Create(CompositorClient
* client
,
149 gfx::NativeWindow root_window
) {
150 return client
? new CompositorImpl(client
, root_window
) : NULL
;
154 void Compositor::Initialize() {
155 DCHECK(!CompositorImpl::IsInitialized());
156 g_initialized
= true;
157 g_use_surface_manager
= UseSurfacesEnabled();
161 bool CompositorImpl::IsInitialized() {
162 return g_initialized
;
165 CompositorImpl::CompositorImpl(CompositorClient
* client
,
166 gfx::NativeWindow root_window
)
167 : root_layer_(cc::Layer::Create()),
168 resource_manager_(&ui_resource_provider_
),
169 surface_id_allocator_(
170 new cc::SurfaceIdAllocator(++g_surface_id_namespace
)),
171 has_transparent_background_(false),
172 device_scale_factor_(1),
176 root_window_(root_window
),
177 did_post_swapbuffers_(false),
178 ignore_schedule_composite_(false),
179 needs_composite_(false),
180 needs_animate_(false),
181 will_composite_immediately_(false),
182 composite_on_vsync_trigger_(DO_NOT_COMPOSITE
),
183 pending_swapbuffers_(0U),
184 num_successive_context_creation_failures_(0),
185 output_surface_request_pending_(false),
186 weak_factory_(this) {
189 root_window
->AttachCompositor(this);
192 CompositorImpl::~CompositorImpl() {
193 root_window_
->DetachCompositor();
194 // Clean-up any surface references.
198 void CompositorImpl::PostComposite(CompositingTrigger trigger
) {
199 DCHECK(needs_composite_
);
200 DCHECK(trigger
== COMPOSITE_IMMEDIATELY
|| trigger
== COMPOSITE_EVENTUALLY
);
202 if (will_composite_immediately_
||
203 (trigger
== COMPOSITE_EVENTUALLY
&& WillComposite())) {
204 // We will already composite soon enough.
205 DCHECK(WillComposite());
209 if (DidCompositeThisFrame()) {
210 DCHECK(!WillCompositeThisFrame());
211 if (composite_on_vsync_trigger_
!= COMPOSITE_IMMEDIATELY
) {
212 composite_on_vsync_trigger_
= trigger
;
213 root_window_
->RequestVSyncUpdate();
215 DCHECK(WillComposite());
219 base::TimeDelta delay
;
220 if (trigger
== COMPOSITE_IMMEDIATELY
) {
221 will_composite_immediately_
= true;
222 composite_on_vsync_trigger_
= DO_NOT_COMPOSITE
;
224 DCHECK(!WillComposite());
225 const base::TimeDelta estimated_composite_time
= vsync_period_
/ 4;
226 const base::TimeTicks now
= base::TimeTicks::Now();
228 if (!last_vsync_
.is_null() && (now
- last_vsync_
) < vsync_period_
) {
229 base::TimeTicks next_composite
=
230 last_vsync_
+ vsync_period_
- estimated_composite_time
;
231 if (next_composite
< now
) {
232 // It's too late, we will reschedule composite as needed on the next
234 composite_on_vsync_trigger_
= COMPOSITE_EVENTUALLY
;
235 root_window_
->RequestVSyncUpdate();
236 DCHECK(WillComposite());
240 delay
= next_composite
- now
;
243 TRACE_EVENT2("cc,benchmark", "CompositorImpl::PostComposite",
245 "delay", delay
.InMillisecondsF());
247 DCHECK(composite_on_vsync_trigger_
== DO_NOT_COMPOSITE
);
248 if (current_composite_task_
)
249 current_composite_task_
->Cancel();
251 // Unretained because we cancel the task on shutdown.
252 current_composite_task_
.reset(new base::CancelableClosure(
253 base::Bind(&CompositorImpl::Composite
, base::Unretained(this), trigger
)));
254 base::MessageLoop::current()->PostDelayedTask(
255 FROM_HERE
, current_composite_task_
->callback(), delay
);
258 void CompositorImpl::Composite(CompositingTrigger trigger
) {
259 if (trigger
== COMPOSITE_IMMEDIATELY
)
260 will_composite_immediately_
= false;
263 DCHECK(trigger
== COMPOSITE_IMMEDIATELY
|| trigger
== COMPOSITE_EVENTUALLY
);
264 DCHECK(needs_composite_
);
265 DCHECK(!DidCompositeThisFrame());
267 DCHECK_LE(pending_swapbuffers_
, kMaxSwapBuffers
);
268 // Swap Ack accounting is unreliable if the OutputSurface was lost.
269 // In that case still attempt to composite, which will cause creation of a
270 // new OutputSurface and reset pending_swapbuffers_.
271 if (pending_swapbuffers_
== kMaxSwapBuffers
&&
272 !host_
->output_surface_lost()) {
273 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit");
277 // Reset state before Layout+Composite since that might create more
278 // requests to Composite that we need to respect.
279 needs_composite_
= false;
281 // Only allow compositing once per vsync.
282 current_composite_task_
->Cancel();
283 DCHECK(DidCompositeThisFrame() && !WillComposite());
285 // Ignore ScheduleComposite() from layer tree changes during layout and
286 // animation updates that will already be reflected in the current frame
287 // we are about to draw.
288 ignore_schedule_composite_
= true;
290 const base::TimeTicks frame_time
= gfx::FrameTime::Now();
291 if (needs_animate_
) {
292 needs_animate_
= false;
293 root_window_
->Animate(frame_time
);
295 ignore_schedule_composite_
= false;
297 did_post_swapbuffers_
= false;
298 host_
->Composite(frame_time
);
299 if (did_post_swapbuffers_
)
300 pending_swapbuffers_
++;
302 // Need to track vsync to avoid compositing more than once per frame.
303 root_window_
->RequestVSyncUpdate();
306 ui::UIResourceProvider
& CompositorImpl::GetUIResourceProvider() {
307 return ui_resource_provider_
;
310 ui::ResourceManager
& CompositorImpl::GetResourceManager() {
311 return resource_manager_
;
314 void CompositorImpl::SetRootLayer(scoped_refptr
<cc::Layer
> root_layer
) {
315 if (subroot_layer_
.get()) {
316 subroot_layer_
->RemoveFromParent();
317 subroot_layer_
= NULL
;
319 if (root_layer
.get()) {
320 subroot_layer_
= root_layer
;
321 root_layer_
->AddChild(root_layer
);
325 void CompositorImpl::SetWindowSurface(ANativeWindow
* window
) {
326 GpuSurfaceTracker
* tracker
= GpuSurfaceTracker::Get();
329 tracker
->RemoveSurface(surface_id_
);
330 ANativeWindow_release(window_
);
338 ANativeWindow_acquire(window
);
339 surface_id_
= tracker
->AddSurfaceForNativeWidget(window
);
340 tracker
->SetSurfaceHandle(
342 gfx::GLSurfaceHandle(gfx::kNullPluginWindow
, gfx::NATIVE_DIRECT
));
347 void CompositorImpl::SetSurface(jobject surface
) {
348 JNIEnv
* env
= base::android::AttachCurrentThread();
349 base::android::ScopedJavaLocalRef
<jobject
> j_surface(env
, surface
);
351 // First, cleanup any existing surface references.
353 UnregisterViewSurface(surface_id_
);
354 SetWindowSurface(NULL
);
356 // Now, set the new surface if we have one.
357 ANativeWindow
* window
= NULL
;
359 // Note: This ensures that any local references used by
360 // ANativeWindow_fromSurface are released immediately. This is needed as a
361 // workaround for https://code.google.com/p/android/issues/detail?id=68174
362 base::android::ScopedJavaLocalFrame
scoped_local_reference_frame(env
);
363 window
= ANativeWindow_fromSurface(env
, surface
);
366 SetWindowSurface(window
);
367 ANativeWindow_release(window
);
368 RegisterViewSurface(surface_id_
, j_surface
.obj());
372 void CompositorImpl::CreateLayerTreeHost() {
374 DCHECK(!WillCompositeThisFrame());
375 needs_composite_
= false;
376 pending_swapbuffers_
= 0;
377 cc::LayerTreeSettings settings
;
378 settings
.renderer_settings
.refresh_rate
= 60.0;
379 settings
.renderer_settings
.allow_antialiasing
= false;
380 settings
.renderer_settings
.highp_threshold_min
= 2048;
381 settings
.impl_side_painting
= true;
382 settings
.calculate_top_controls_position
= false;
384 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
385 settings
.initial_debug_state
.SetRecordRenderingStats(
386 command_line
->HasSwitch(cc::switches::kEnableGpuBenchmarking
));
387 settings
.initial_debug_state
.show_fps_counter
=
388 command_line
->HasSwitch(cc::switches::kUIShowFPSCounter
);
389 // TODO(enne): Update this this compositor to use the scheduler.
390 settings
.single_thread_proxy_scheduler
= false;
392 host_
= cc::LayerTreeHost::CreateSingleThreaded(
395 HostSharedBitmapManager::current(),
396 BrowserGpuMemoryBufferManager::current(),
398 base::MessageLoopProxy::current(),
400 host_
->SetRootLayer(root_layer_
);
402 host_
->SetVisible(true);
403 host_
->SetLayerTreeHostClientReady();
404 host_
->SetViewportSize(size_
);
405 host_
->set_has_transparent_background(has_transparent_background_
);
406 host_
->SetDeviceScaleFactor(device_scale_factor_
);
409 host_
->SetNeedsAnimate();
412 void CompositorImpl::SetVisible(bool visible
) {
415 // Look for any layers that were attached to the root for readback
416 // and are waiting for Composite() to happen.
417 bool readback_pending
= false;
418 for (size_t i
= 0; i
< root_layer_
->children().size(); ++i
) {
419 if (root_layer_
->children()[i
]->HasCopyRequest()) {
420 readback_pending
= true;
424 if (readback_pending
) {
425 ignore_schedule_composite_
= true;
426 host_
->Composite(base::TimeTicks::Now());
427 ignore_schedule_composite_
= false;
431 ui_resource_provider_
.SetLayerTreeHost(NULL
);
433 establish_gpu_channel_timeout_
.Stop();
434 output_surface_request_pending_
= false;
435 display_client_
.reset();
436 if (current_composite_task_
) {
437 current_composite_task_
->Cancel();
438 current_composite_task_
.reset();
441 CreateLayerTreeHost();
442 ui_resource_provider_
.SetLayerTreeHost(host_
.get());
446 void CompositorImpl::setDeviceScaleFactor(float factor
) {
447 device_scale_factor_
= factor
;
449 host_
->SetDeviceScaleFactor(factor
);
452 void CompositorImpl::SetWindowBounds(const gfx::Size
& size
) {
458 host_
->SetViewportSize(size
);
460 display_client_
->display()->Resize(size
);
461 root_layer_
->SetBounds(size
);
464 void CompositorImpl::SetHasTransparentBackground(bool flag
) {
465 has_transparent_background_
= flag
;
467 host_
->set_has_transparent_background(flag
);
470 void CompositorImpl::SetNeedsComposite() {
473 DCHECK(!needs_composite_
|| WillComposite());
475 needs_composite_
= true;
476 PostComposite(COMPOSITE_IMMEDIATELY
);
479 static scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
>
480 CreateGpuProcessViewContext(
481 const scoped_refptr
<GpuChannelHost
>& gpu_channel_host
,
482 const blink::WebGraphicsContext3D::Attributes attributes
,
484 GURL
url("chrome://gpu/Compositor::createContext3D");
485 static const size_t kBytesPerPixel
= 4;
486 gfx::DeviceDisplayInfo display_info
;
487 size_t full_screen_texture_size_in_bytes
=
488 display_info
.GetDisplayHeight() *
489 display_info
.GetDisplayWidth() *
491 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits
;
492 limits
.command_buffer_size
= 64 * 1024;
493 limits
.start_transfer_buffer_size
= 64 * 1024;
494 limits
.min_transfer_buffer_size
= 64 * 1024;
495 limits
.max_transfer_buffer_size
= std::min(
496 3 * full_screen_texture_size_in_bytes
, kDefaultMaxTransferBufferSize
);
497 limits
.mapped_memory_reclaim_limit
= 2 * 1024 * 1024;
498 bool lose_context_when_out_of_memory
= true;
499 return make_scoped_ptr(
500 new WebGraphicsContext3DCommandBufferImpl(surface_id
,
502 gpu_channel_host
.get(),
504 lose_context_when_out_of_memory
,
509 void CompositorImpl::Layout() {
510 ignore_schedule_composite_
= true;
512 ignore_schedule_composite_
= false;
515 void CompositorImpl::OnGpuChannelEstablished() {
516 establish_gpu_channel_timeout_
.Stop();
517 CreateOutputSurface();
520 void CompositorImpl::OnGpuChannelTimeout() {
521 LOG(FATAL
) << "Timed out waiting for GPU channel.";
524 void CompositorImpl::RequestNewOutputSurface() {
525 output_surface_request_pending_
= true;
527 BrowserGpuChannelHostFactory
* factory
=
528 BrowserGpuChannelHostFactory::instance();
529 if (!factory
->GetGpuChannel() || factory
->GetGpuChannel()->IsLost()) {
530 factory
->EstablishGpuChannel(
531 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE
,
532 base::Bind(&CompositorImpl::OnGpuChannelEstablished
,
533 weak_factory_
.GetWeakPtr()));
534 establish_gpu_channel_timeout_
.Start(
535 FROM_HERE
, base::TimeDelta::FromSeconds(7), this,
536 &CompositorImpl::OnGpuChannelTimeout
);
540 CreateOutputSurface();
543 void CompositorImpl::DidInitializeOutputSurface() {
544 num_successive_context_creation_failures_
= 0;
545 output_surface_request_pending_
= false;
548 void CompositorImpl::DidFailToInitializeOutputSurface() {
549 LOG(ERROR
) << "Failed to init OutputSurface for compositor.";
550 LOG_IF(FATAL
, ++num_successive_context_creation_failures_
>= 2)
551 << "Too many context creation failures. Giving up... ";
552 RequestNewOutputSurface();
555 void CompositorImpl::CreateOutputSurface() {
556 // We might have had a request from a LayerTreeHost that was then
558 if (!output_surface_request_pending_
)
561 blink::WebGraphicsContext3D::Attributes attrs
;
562 attrs
.shareResources
= true;
563 attrs
.noAutomaticFlushes
= true;
564 pending_swapbuffers_
= 0;
569 BrowserGpuChannelHostFactory
* factory
=
570 BrowserGpuChannelHostFactory::instance();
571 // This channel might be lost (and even if it isn't right now, it might
572 // still get marked as lost from the IO thread, at any point in time really).
573 // But from here on just try and always lead to either
574 // DidInitializeOutputSurface() or DidFailToInitializeOutputSurface().
575 scoped_refptr
<GpuChannelHost
> gpu_channel_host(factory
->GetGpuChannel());
576 scoped_refptr
<ContextProviderCommandBuffer
> context_provider(
577 ContextProviderCommandBuffer::Create(
578 CreateGpuProcessViewContext(gpu_channel_host
, attrs
, surface_id_
),
579 "BrowserCompositor"));
580 DCHECK(context_provider
.get());
582 scoped_ptr
<cc::OutputSurface
> real_output_surface(
583 new OutputSurfaceWithoutParent(context_provider
,
584 weak_factory_
.GetWeakPtr()));
586 cc::SurfaceManager
* manager
= GetSurfaceManager();
588 display_client_
.reset(new cc::OnscreenDisplayClient(
589 real_output_surface
.Pass(), manager
, HostSharedBitmapManager::current(),
590 BrowserGpuMemoryBufferManager::current(),
591 host_
->settings().renderer_settings
,
592 base::MessageLoopProxy::current()));
593 scoped_ptr
<cc::SurfaceDisplayOutputSurface
> surface_output_surface(
594 new cc::SurfaceDisplayOutputSurface(
595 manager
, surface_id_allocator_
.get(), context_provider
));
597 display_client_
->set_surface_output_surface(surface_output_surface
.get());
598 surface_output_surface
->set_display_client(display_client_
.get());
599 display_client_
->display()->Resize(size_
);
600 host_
->SetOutputSurface(surface_output_surface
.Pass());
602 host_
->SetOutputSurface(real_output_surface
.Pass());
606 void CompositorImpl::PopulateGpuCapabilities(
607 gpu::Capabilities gpu_capabilities
) {
608 ui_resource_provider_
.SetSupportsETC1NonPowerOfTwo(
609 gpu_capabilities
.texture_format_etc1_npot
);
612 void CompositorImpl::ScheduleComposite() {
613 DCHECK(!needs_composite_
|| WillComposite());
614 if (ignore_schedule_composite_
)
617 needs_composite_
= true;
618 // We currently expect layer tree invalidations at most once per frame
619 // during normal operation and therefore try to composite immediately
620 // to minimize latency.
621 PostComposite(COMPOSITE_IMMEDIATELY
);
624 void CompositorImpl::ScheduleAnimation() {
625 DCHECK(!needs_composite_
|| WillComposite());
626 needs_animate_
= true;
628 if (needs_composite_
)
631 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation");
632 needs_composite_
= true;
633 PostComposite(COMPOSITE_EVENTUALLY
);
636 void CompositorImpl::DidPostSwapBuffers() {
637 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers");
638 did_post_swapbuffers_
= true;
641 void CompositorImpl::DidCompleteSwapBuffers() {
642 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers");
643 DCHECK_GT(pending_swapbuffers_
, 0U);
644 if (pending_swapbuffers_
-- == kMaxSwapBuffers
&& needs_composite_
)
645 PostComposite(COMPOSITE_IMMEDIATELY
);
646 client_
->OnSwapBuffersCompleted(pending_swapbuffers_
);
649 void CompositorImpl::DidAbortSwapBuffers() {
650 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers");
651 // This really gets called only once from
652 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the
655 client_
->OnSwapBuffersCompleted(0);
658 void CompositorImpl::DidCommit() {
659 root_window_
->OnCompositingDidCommit();
662 void CompositorImpl::AttachLayerForReadback(scoped_refptr
<cc::Layer
> layer
) {
663 root_layer_
->AddChild(layer
);
666 void CompositorImpl::RequestCopyOfOutputOnRootLayer(
667 scoped_ptr
<cc::CopyOutputRequest
> request
) {
668 root_layer_
->RequestCopyOfOutput(request
.Pass());
671 void CompositorImpl::OnVSync(base::TimeTicks frame_time
,
672 base::TimeDelta vsync_period
) {
673 vsync_period_
= vsync_period
;
674 last_vsync_
= frame_time
;
676 if (WillCompositeThisFrame()) {
677 // We somehow missed the last vsync interval, so reschedule for deadline.
678 // We cannot schedule immediately, or will get us out-of-phase with new
681 composite_on_vsync_trigger_
= COMPOSITE_EVENTUALLY
;
683 current_composite_task_
.reset();
686 DCHECK(!DidCompositeThisFrame() && !WillCompositeThisFrame());
687 if (composite_on_vsync_trigger_
!= DO_NOT_COMPOSITE
) {
688 CompositingTrigger trigger
= composite_on_vsync_trigger_
;
689 composite_on_vsync_trigger_
= DO_NOT_COMPOSITE
;
690 PostComposite(trigger
);
694 void CompositorImpl::SetNeedsAnimate() {
695 needs_animate_
= true;
699 host_
->SetNeedsAnimate();
702 } // namespace content