android: Don't invalidate UI resources if context is lost
[chromium-blink-merge.git] / content / browser / renderer_host / compositor_impl_android.cc
blob31a5d2d018d699b9b9d1c038a080da6d376d326c
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/command_line.h"
14 #include "base/containers/hash_tables.h"
15 #include "base/lazy_instance.h"
16 #include "base/logging.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/single_thread_task_runner.h"
19 #include "base/synchronization/lock.h"
20 #include "base/threading/thread.h"
21 #include "base/threading/thread_checker.h"
22 #include "cc/base/switches.h"
23 #include "cc/input/input_handler.h"
24 #include "cc/layers/layer.h"
25 #include "cc/output/compositor_frame.h"
26 #include "cc/output/context_provider.h"
27 #include "cc/output/output_surface.h"
28 #include "cc/trees/layer_tree_host.h"
29 #include "content/browser/android/child_process_launcher_android.h"
30 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
31 #include "content/browser/gpu/gpu_surface_tracker.h"
32 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
33 #include "content/common/gpu/client/context_provider_command_buffer.h"
34 #include "content/common/gpu/client/gl_helper.h"
35 #include "content/common/gpu/client/gpu_channel_host.h"
36 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
37 #include "content/common/gpu/gpu_process_launch_causes.h"
38 #include "content/common/host_shared_bitmap_manager.h"
39 #include "content/public/browser/android/compositor_client.h"
40 #include "gpu/command_buffer/client/gles2_interface.h"
41 #include "third_party/khronos/GLES2/gl2.h"
42 #include "third_party/khronos/GLES2/gl2ext.h"
43 #include "third_party/skia/include/core/SkMallocPixelRef.h"
44 #include "ui/base/android/window_android.h"
45 #include "ui/gfx/android/device_display_info.h"
46 #include "ui/gfx/frame_time.h"
47 #include "ui/gl/android/surface_texture.h"
48 #include "ui/gl/android/surface_texture_tracker.h"
49 #include "webkit/common/gpu/context_provider_in_process.h"
50 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
52 namespace {
54 const unsigned int kMaxSwapBuffers = 2U;
56 // Used to override capabilities_.adjust_deadline_for_parent to false
57 class OutputSurfaceWithoutParent : public cc::OutputSurface {
58 public:
59 OutputSurfaceWithoutParent(const scoped_refptr<
60 content::ContextProviderCommandBuffer>& context_provider,
61 base::WeakPtr<content::CompositorImpl> compositor_impl)
62 : cc::OutputSurface(context_provider) {
63 capabilities_.adjust_deadline_for_parent = false;
64 compositor_impl_ = compositor_impl;
65 main_thread_ = base::MessageLoopProxy::current();
68 virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE {
69 content::ContextProviderCommandBuffer* provider_command_buffer =
70 static_cast<content::ContextProviderCommandBuffer*>(
71 context_provider_.get());
72 content::CommandBufferProxyImpl* command_buffer_proxy =
73 provider_command_buffer->GetCommandBufferProxy();
74 DCHECK(command_buffer_proxy);
75 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info);
77 OutputSurface::SwapBuffers(frame);
80 virtual bool BindToClient(cc::OutputSurfaceClient* client) OVERRIDE {
81 if (!OutputSurface::BindToClient(client))
82 return false;
84 main_thread_->PostTask(
85 FROM_HERE,
86 base::Bind(&content::CompositorImpl::PopulateGpuCapabilities,
87 compositor_impl_,
88 context_provider_->ContextCapabilities().gpu));
90 return true;
93 scoped_refptr<base::MessageLoopProxy> main_thread_;
94 base::WeakPtr<content::CompositorImpl> compositor_impl_;
97 class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker {
98 public:
99 SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) {
100 thread_checker_.DetachFromThread();
103 // Overridden from gfx::SurfaceTextureTracker:
104 virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture(
105 int primary_id,
106 int secondary_id) OVERRIDE {
107 base::AutoLock lock(surface_textures_lock_);
108 SurfaceTextureMapKey key(primary_id, secondary_id);
109 SurfaceTextureMap::iterator it = surface_textures_.find(key);
110 if (it == surface_textures_.end())
111 return scoped_refptr<gfx::SurfaceTexture>();
112 scoped_refptr<gfx::SurfaceTexture> surface_texture = it->second;
113 surface_textures_.erase(it);
114 return surface_texture;
117 int AddSurfaceTexture(gfx::SurfaceTexture* surface_texture,
118 int child_process_id) {
119 DCHECK(thread_checker_.CalledOnValidThread());
120 int surface_texture_id = next_surface_texture_id_++;
121 if (next_surface_texture_id_ == INT_MAX)
122 next_surface_texture_id_ = 1;
124 base::AutoLock lock(surface_textures_lock_);
125 SurfaceTextureMapKey key(surface_texture_id, child_process_id);
126 DCHECK(surface_textures_.find(key) == surface_textures_.end());
127 surface_textures_[key] = surface_texture;
128 content::RegisterChildProcessSurfaceTexture(
129 surface_texture_id,
130 child_process_id,
131 surface_texture->j_surface_texture().obj());
132 return surface_texture_id;
135 void RemoveAllSurfaceTextures(int child_process_id) {
136 DCHECK(thread_checker_.CalledOnValidThread());
137 base::AutoLock lock(surface_textures_lock_);
138 SurfaceTextureMap::iterator it = surface_textures_.begin();
139 while (it != surface_textures_.end()) {
140 if (it->first.second == child_process_id) {
141 content::UnregisterChildProcessSurfaceTexture(it->first.first,
142 it->first.second);
143 surface_textures_.erase(it++);
144 } else {
145 ++it;
150 private:
151 typedef std::pair<int, int> SurfaceTextureMapKey;
152 typedef base::hash_map<SurfaceTextureMapKey,
153 scoped_refptr<gfx::SurfaceTexture> >
154 SurfaceTextureMap;
155 SurfaceTextureMap surface_textures_;
156 mutable base::Lock surface_textures_lock_;
157 int next_surface_texture_id_;
158 base::ThreadChecker thread_checker_;
160 base::LazyInstance<SurfaceTextureTrackerImpl> g_surface_texture_tracker =
161 LAZY_INSTANCE_INITIALIZER;
163 static bool g_initialized = false;
165 } // anonymous namespace
167 namespace content {
169 // static
170 Compositor* Compositor::Create(CompositorClient* client,
171 gfx::NativeWindow root_window) {
172 return client ? new CompositorImpl(client, root_window) : NULL;
175 // static
176 void Compositor::Initialize() {
177 DCHECK(!CompositorImpl::IsInitialized());
178 // SurfaceTextureTracker instance must be set before we create a GPU thread
179 // that could be using it to initialize GLImage instances.
180 gfx::SurfaceTextureTracker::InitInstance(g_surface_texture_tracker.Pointer());
181 g_initialized = true;
184 // static
185 bool CompositorImpl::IsInitialized() {
186 return g_initialized;
189 // static
190 int CompositorImpl::CreateSurfaceTexture(int child_process_id) {
191 // Note: this needs to be 0 as the surface texture implemenation will take
192 // ownership of the texture and call glDeleteTextures when the GPU service
193 // attaches the surface texture to a real texture id. glDeleteTextures
194 // silently ignores 0.
195 const int kDummyTextureId = 0;
196 scoped_refptr<gfx::SurfaceTexture> surface_texture =
197 gfx::SurfaceTexture::Create(kDummyTextureId);
198 return g_surface_texture_tracker.Pointer()->AddSurfaceTexture(
199 surface_texture.get(), child_process_id);
202 // static
203 void CompositorImpl::DestroyAllSurfaceTextures(int child_process_id) {
204 g_surface_texture_tracker.Pointer()->RemoveAllSurfaceTextures(
205 child_process_id);
208 CompositorImpl::CompositorImpl(CompositorClient* client,
209 gfx::NativeWindow root_window)
210 : root_layer_(cc::Layer::Create()),
211 has_transparent_background_(false),
212 device_scale_factor_(1),
213 window_(NULL),
214 surface_id_(0),
215 client_(client),
216 root_window_(root_window),
217 did_post_swapbuffers_(false),
218 ignore_schedule_composite_(false),
219 needs_composite_(false),
220 needs_animate_(false),
221 will_composite_immediately_(false),
222 composite_on_vsync_trigger_(DO_NOT_COMPOSITE),
223 pending_swapbuffers_(0U),
224 weak_factory_(this) {
225 DCHECK(client);
226 DCHECK(root_window);
227 ImageTransportFactoryAndroid::AddObserver(this);
228 root_window->AttachCompositor(this);
231 CompositorImpl::~CompositorImpl() {
232 root_window_->DetachCompositor();
233 ImageTransportFactoryAndroid::RemoveObserver(this);
234 // Clean-up any surface references.
235 SetSurface(NULL);
238 void CompositorImpl::PostComposite(CompositingTrigger trigger) {
239 DCHECK(needs_composite_);
240 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY);
242 if (will_composite_immediately_ ||
243 (trigger == COMPOSITE_EVENTUALLY && WillComposite())) {
244 // We will already composite soon enough.
245 DCHECK(WillComposite());
246 return;
249 if (DidCompositeThisFrame()) {
250 DCHECK(!WillCompositeThisFrame());
251 if (composite_on_vsync_trigger_ != COMPOSITE_IMMEDIATELY) {
252 composite_on_vsync_trigger_ = trigger;
253 root_window_->RequestVSyncUpdate();
255 DCHECK(WillComposite());
256 return;
259 base::TimeDelta delay;
260 if (trigger == COMPOSITE_IMMEDIATELY) {
261 will_composite_immediately_ = true;
262 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE;
263 } else {
264 DCHECK(!WillComposite());
265 const base::TimeDelta estimated_composite_time = vsync_period_ / 4;
266 const base::TimeTicks now = base::TimeTicks::Now();
268 if (!last_vsync_.is_null() && (now - last_vsync_) < vsync_period_) {
269 base::TimeTicks next_composite =
270 last_vsync_ + vsync_period_ - estimated_composite_time;
271 if (next_composite < now) {
272 // It's too late, we will reschedule composite as needed on the next
273 // vsync.
274 composite_on_vsync_trigger_ = COMPOSITE_EVENTUALLY;
275 root_window_->RequestVSyncUpdate();
276 DCHECK(WillComposite());
277 return;
280 delay = next_composite - now;
283 TRACE_EVENT2("cc", "CompositorImpl::PostComposite",
284 "trigger", trigger,
285 "delay", delay.InMillisecondsF());
287 DCHECK(composite_on_vsync_trigger_ == DO_NOT_COMPOSITE);
288 if (current_composite_task_)
289 current_composite_task_->Cancel();
291 // Unretained because we cancel the task on shutdown.
292 current_composite_task_.reset(new base::CancelableClosure(
293 base::Bind(&CompositorImpl::Composite, base::Unretained(this), trigger)));
294 base::MessageLoop::current()->PostDelayedTask(
295 FROM_HERE, current_composite_task_->callback(), delay);
298 void CompositorImpl::Composite(CompositingTrigger trigger) {
299 BrowserGpuChannelHostFactory* factory =
300 BrowserGpuChannelHostFactory::instance();
301 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) {
302 CauseForGpuLaunch cause =
303 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
304 factory->EstablishGpuChannel(
305 cause,
306 base::Bind(&CompositorImpl::OnGpuChannelEstablished,
307 weak_factory_.GetWeakPtr()));
308 return;
311 DCHECK(host_);
312 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY);
313 DCHECK(needs_composite_);
314 DCHECK(!DidCompositeThisFrame());
316 if (trigger == COMPOSITE_IMMEDIATELY)
317 will_composite_immediately_ = false;
319 DCHECK_LE(pending_swapbuffers_, kMaxSwapBuffers);
320 if (pending_swapbuffers_ == kMaxSwapBuffers) {
321 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit");
322 return;
325 // Reset state before Layout+Composite since that might create more
326 // requests to Composite that we need to respect.
327 needs_composite_ = false;
329 // Only allow compositing once per vsync.
330 current_composite_task_->Cancel();
331 DCHECK(DidCompositeThisFrame() && !WillComposite());
333 // Ignore ScheduleComposite() from layer tree changes during layout and
334 // animation updates that will already be reflected in the current frame
335 // we are about to draw.
336 ignore_schedule_composite_ = true;
338 const base::TimeTicks frame_time = gfx::FrameTime::Now();
339 if (needs_animate_) {
340 needs_animate_ = false;
341 root_window_->Animate(frame_time);
343 ignore_schedule_composite_ = false;
345 did_post_swapbuffers_ = false;
346 host_->Composite(frame_time);
347 if (did_post_swapbuffers_)
348 pending_swapbuffers_++;
350 // Need to track vsync to avoid compositing more than once per frame.
351 root_window_->RequestVSyncUpdate();
354 void CompositorImpl::OnGpuChannelEstablished() {
355 ScheduleComposite();
358 UIResourceProvider& CompositorImpl::GetUIResourceProvider() {
359 return ui_resource_provider_;
362 ui::SystemUIResourceManager& CompositorImpl::GetSystemUIResourceManager() {
363 return ui_resource_provider_.GetSystemUIResourceManager();
366 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) {
367 if (subroot_layer_) {
368 subroot_layer_->RemoveFromParent();
369 subroot_layer_ = NULL;
371 if (root_layer) {
372 subroot_layer_ = root_layer;
373 root_layer_->AddChild(root_layer);
377 void CompositorImpl::SetWindowSurface(ANativeWindow* window) {
378 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
380 if (window_) {
381 tracker->RemoveSurface(surface_id_);
382 ANativeWindow_release(window_);
383 window_ = NULL;
384 surface_id_ = 0;
385 SetVisible(false);
388 if (window) {
389 window_ = window;
390 ANativeWindow_acquire(window);
391 surface_id_ = tracker->AddSurfaceForNativeWidget(window);
392 tracker->SetSurfaceHandle(
393 surface_id_,
394 gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::NATIVE_DIRECT));
395 SetVisible(true);
399 void CompositorImpl::SetSurface(jobject surface) {
400 JNIEnv* env = base::android::AttachCurrentThread();
401 base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface);
403 // First, cleanup any existing surface references.
404 if (surface_id_)
405 content::UnregisterViewSurface(surface_id_);
406 SetWindowSurface(NULL);
408 // Now, set the new surface if we have one.
409 ANativeWindow* window = NULL;
410 if (surface) {
411 // Note: This ensures that any local references used by
412 // ANativeWindow_fromSurface are released immediately. This is needed as a
413 // workaround for https://code.google.com/p/android/issues/detail?id=68174
414 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
415 window = ANativeWindow_fromSurface(env, surface);
417 if (window) {
418 SetWindowSurface(window);
419 ANativeWindow_release(window);
420 content::RegisterViewSurface(surface_id_, j_surface.obj());
424 void CompositorImpl::SetVisible(bool visible) {
425 if (!visible) {
426 DCHECK(host_);
427 // Look for any layers that were attached to the root for readback
428 // and are waiting for Composite() to happen.
429 bool readback_pending = false;
430 for (size_t i = 0; i < root_layer_->children().size(); ++i) {
431 if (root_layer_->children()[i]->HasCopyRequest()) {
432 readback_pending = true;
433 break;
436 if (readback_pending) {
437 ignore_schedule_composite_ = true;
438 host_->Composite(base::TimeTicks::Now());
439 ignore_schedule_composite_ = false;
441 if (WillComposite())
442 CancelComposite();
443 ui_resource_provider_.SetLayerTreeHost(NULL);
444 host_.reset();
445 } else if (!host_) {
446 DCHECK(!WillComposite());
447 needs_composite_ = false;
448 pending_swapbuffers_ = 0;
449 cc::LayerTreeSettings settings;
450 settings.refresh_rate = 60.0;
451 settings.impl_side_painting = false;
452 settings.allow_antialiasing = false;
453 settings.calculate_top_controls_position = false;
454 settings.top_controls_height = 0.f;
455 settings.highp_threshold_min = 2048;
457 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
458 settings.initial_debug_state.SetRecordRenderingStats(
459 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking));
460 settings.initial_debug_state.show_fps_counter =
461 command_line->HasSwitch(cc::switches::kUIShowFPSCounter);
462 // TODO(enne): Update this this compositor to use the scheduler.
463 settings.single_thread_proxy_scheduler = false;
465 host_ = cc::LayerTreeHost::CreateSingleThreaded(
466 this,
467 this,
468 HostSharedBitmapManager::current(),
469 settings,
470 base::MessageLoopProxy::current());
471 host_->SetRootLayer(root_layer_);
473 host_->SetVisible(true);
474 host_->SetLayerTreeHostClientReady();
475 host_->SetViewportSize(size_);
476 host_->set_has_transparent_background(has_transparent_background_);
477 host_->SetDeviceScaleFactor(device_scale_factor_);
478 ui_resource_provider_.SetLayerTreeHost(host_.get());
482 void CompositorImpl::setDeviceScaleFactor(float factor) {
483 device_scale_factor_ = factor;
484 if (host_)
485 host_->SetDeviceScaleFactor(factor);
488 void CompositorImpl::SetWindowBounds(const gfx::Size& size) {
489 if (size_ == size)
490 return;
492 size_ = size;
493 if (host_)
494 host_->SetViewportSize(size);
495 root_layer_->SetBounds(size);
498 void CompositorImpl::SetHasTransparentBackground(bool flag) {
499 has_transparent_background_ = flag;
500 if (host_)
501 host_->set_has_transparent_background(flag);
504 void CompositorImpl::SetNeedsComposite() {
505 if (!host_.get())
506 return;
507 DCHECK(!needs_composite_ || WillComposite());
509 needs_composite_ = true;
510 PostComposite(COMPOSITE_IMMEDIATELY);
513 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
514 CreateGpuProcessViewContext(
515 const scoped_refptr<GpuChannelHost>& gpu_channel_host,
516 const blink::WebGraphicsContext3D::Attributes attributes,
517 int surface_id) {
518 DCHECK(gpu_channel_host);
520 GURL url("chrome://gpu/Compositor::createContext3D");
521 static const size_t kBytesPerPixel = 4;
522 gfx::DeviceDisplayInfo display_info;
523 size_t full_screen_texture_size_in_bytes =
524 display_info.GetDisplayHeight() *
525 display_info.GetDisplayWidth() *
526 kBytesPerPixel;
527 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
528 limits.command_buffer_size = 64 * 1024;
529 limits.start_transfer_buffer_size = 64 * 1024;
530 limits.min_transfer_buffer_size = 64 * 1024;
531 limits.max_transfer_buffer_size = std::min(
532 3 * full_screen_texture_size_in_bytes, kDefaultMaxTransferBufferSize);
533 limits.mapped_memory_reclaim_limit = 2 * 1024 * 1024;
534 bool lose_context_when_out_of_memory = true;
535 return make_scoped_ptr(
536 new WebGraphicsContext3DCommandBufferImpl(surface_id,
537 url,
538 gpu_channel_host.get(),
539 attributes,
540 lose_context_when_out_of_memory,
541 limits,
542 NULL));
545 void CompositorImpl::Layout() {
546 ignore_schedule_composite_ = true;
547 client_->Layout();
548 ignore_schedule_composite_ = false;
551 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface(
552 bool fallback) {
553 blink::WebGraphicsContext3D::Attributes attrs;
554 attrs.shareResources = true;
555 attrs.noAutomaticFlushes = true;
556 pending_swapbuffers_ = 0;
558 DCHECK(window_);
559 DCHECK(surface_id_);
561 scoped_refptr<ContextProviderCommandBuffer> context_provider;
562 BrowserGpuChannelHostFactory* factory =
563 BrowserGpuChannelHostFactory::instance();
564 scoped_refptr<GpuChannelHost> gpu_channel_host = factory->GetGpuChannel();
565 if (gpu_channel_host && !gpu_channel_host->IsLost()) {
566 context_provider = ContextProviderCommandBuffer::Create(
567 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_),
568 "BrowserCompositor");
570 if (!context_provider.get()) {
571 LOG(ERROR) << "Failed to create 3D context for compositor.";
572 return scoped_ptr<cc::OutputSurface>();
575 return scoped_ptr<cc::OutputSurface>(new OutputSurfaceWithoutParent(
576 context_provider, weak_factory_.GetWeakPtr()));
579 void CompositorImpl::PopulateGpuCapabilities(
580 gpu::Capabilities gpu_capabilities) {
581 ui_resource_provider_.SetSupportsETC1NonPowerOfTwo(
582 gpu_capabilities.texture_format_etc1_npot);
585 void CompositorImpl::OnLostResources() {
586 client_->DidLoseResources();
589 void CompositorImpl::ScheduleComposite() {
590 DCHECK(!needs_composite_ || WillComposite());
591 if (ignore_schedule_composite_)
592 return;
594 needs_composite_ = true;
595 // We currently expect layer tree invalidations at most once per frame
596 // during normal operation and therefore try to composite immediately
597 // to minimize latency.
598 PostComposite(COMPOSITE_IMMEDIATELY);
601 void CompositorImpl::ScheduleAnimation() {
602 DCHECK(!needs_composite_ || WillComposite());
603 needs_animate_ = true;
605 if (needs_composite_)
606 return;
608 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation");
609 needs_composite_ = true;
610 PostComposite(COMPOSITE_EVENTUALLY);
613 void CompositorImpl::DidPostSwapBuffers() {
614 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers");
615 did_post_swapbuffers_ = true;
618 void CompositorImpl::DidCompleteSwapBuffers() {
619 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers");
620 DCHECK_GT(pending_swapbuffers_, 0U);
621 if (pending_swapbuffers_-- == kMaxSwapBuffers && needs_composite_)
622 PostComposite(COMPOSITE_IMMEDIATELY);
623 client_->OnSwapBuffersCompleted(pending_swapbuffers_);
626 void CompositorImpl::DidAbortSwapBuffers() {
627 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers");
628 // This really gets called only once from
629 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the
630 // context was lost.
631 ScheduleComposite();
632 client_->OnSwapBuffersCompleted(0);
635 void CompositorImpl::DidCommit() {
636 root_window_->OnCompositingDidCommit();
639 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) {
640 root_layer_->AddChild(layer);
643 void CompositorImpl::RequestCopyOfOutputOnRootLayer(
644 scoped_ptr<cc::CopyOutputRequest> request) {
645 root_layer_->RequestCopyOfOutput(request.Pass());
648 void CompositorImpl::OnVSync(base::TimeTicks frame_time,
649 base::TimeDelta vsync_period) {
650 vsync_period_ = vsync_period;
651 last_vsync_ = frame_time;
653 if (WillCompositeThisFrame()) {
654 // We somehow missed the last vsync interval, so reschedule for deadline.
655 // We cannot schedule immediately, or will get us out-of-phase with new
656 // renderer frames.
657 CancelComposite();
658 composite_on_vsync_trigger_ = COMPOSITE_EVENTUALLY;
659 } else {
660 current_composite_task_.reset();
663 DCHECK(!DidCompositeThisFrame() && !WillCompositeThisFrame());
664 if (composite_on_vsync_trigger_ != DO_NOT_COMPOSITE) {
665 CompositingTrigger trigger = composite_on_vsync_trigger_;
666 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE;
667 PostComposite(trigger);
671 void CompositorImpl::SetNeedsAnimate() {
672 if (!host_)
673 return;
675 host_->SetNeedsAnimate();
678 } // namespace content