OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/compositor_impl_android.h" | 5 #include "content/browser/renderer_host/compositor_impl_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
9 | 9 |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 } | 231 } |
232 | 232 |
233 CompositorImpl::CompositorImpl(CompositorClient* client, | 233 CompositorImpl::CompositorImpl(CompositorClient* client, |
234 gfx::NativeWindow root_window) | 234 gfx::NativeWindow root_window) |
235 : root_layer_(cc::Layer::Create()), | 235 : root_layer_(cc::Layer::Create()), |
236 has_transparent_background_(false), | 236 has_transparent_background_(false), |
237 device_scale_factor_(1), | 237 device_scale_factor_(1), |
238 window_(NULL), | 238 window_(NULL), |
239 surface_id_(0), | 239 surface_id_(0), |
240 client_(client), | 240 client_(client), |
241 root_window_(root_window) { | 241 root_window_(root_window), |
242 did_post_swapbuffers_(false), | |
243 need_to_composite_(false), | |
244 can_composite_outside_vsync_(true), | |
245 pending_swapbuffers_(0U), | |
246 weak_factory_(this) { | |
242 DCHECK(client); | 247 DCHECK(client); |
243 DCHECK(root_window); | 248 DCHECK(root_window); |
244 ImageTransportFactoryAndroid::AddObserver(this); | 249 ImageTransportFactoryAndroid::AddObserver(this); |
245 root_window->AttachCompositor(this); | 250 root_window->AttachCompositor(this); |
246 } | 251 } |
247 | 252 |
248 CompositorImpl::~CompositorImpl() { | 253 CompositorImpl::~CompositorImpl() { |
249 root_window_->DetachCompositor(); | 254 root_window_->DetachCompositor(); |
250 ImageTransportFactoryAndroid::RemoveObserver(this); | 255 ImageTransportFactoryAndroid::RemoveObserver(this); |
251 // Clean-up any surface references. | 256 // Clean-up any surface references. |
252 SetSurface(NULL); | 257 SetSurface(NULL); |
253 } | 258 } |
254 | 259 |
255 void CompositorImpl::Composite() { | 260 void CompositorImpl::Composite(bool is_vsync) { |
256 if (host_) | 261 if (!host_) |
257 host_->Composite(gfx::FrameTime::Now()); | 262 return; |
263 | |
264 if (!need_to_composite_) | |
265 return; | |
266 | |
267 if (!is_vsync && !can_composite_outside_vsync_) { | |
268 TRACE_EVENT0("compositor", "CompositorImpl_DeferComposite"); | |
269 root_window_->RequestVSyncUpdate(); | |
270 return; | |
271 } | |
272 | |
273 const unsigned int kMaxSwapBuffers = 2U; | |
274 DCHECK_LE(pending_swapbuffers_, kMaxSwapBuffers); | |
275 if (pending_swapbuffers_ == kMaxSwapBuffers) { | |
276 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit"); | |
277 root_window_->RequestVSyncUpdate(); | |
278 return; | |
279 } | |
280 | |
281 // Don't allow compositing immediately more than once per vsync. | |
282 can_composite_outside_vsync_ = false; | |
283 | |
284 did_post_swapbuffers_ = false; | |
285 host_->Composite(gfx::FrameTime::Now()); | |
286 if (did_post_swapbuffers_) | |
287 pending_swapbuffers_++; | |
288 | |
289 need_to_composite_ = false; | |
258 } | 290 } |
259 | 291 |
260 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 292 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
261 root_layer_->RemoveAllChildren(); | 293 root_layer_->RemoveAllChildren(); |
262 root_layer_->AddChild(root_layer); | 294 root_layer_->AddChild(root_layer); |
263 } | 295 } |
264 | 296 |
265 void CompositorImpl::SetWindowSurface(ANativeWindow* window) { | 297 void CompositorImpl::SetWindowSurface(ANativeWindow* window) { |
266 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 298 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
267 | 299 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 return make_scoped_ptr( | 490 return make_scoped_ptr( |
459 new WebGraphicsContext3DCommandBufferImpl(surface_id, | 491 new WebGraphicsContext3DCommandBufferImpl(surface_id, |
460 url, | 492 url, |
461 gpu_channel_host.get(), | 493 gpu_channel_host.get(), |
462 attributes, | 494 attributes, |
463 lose_context_when_out_of_memory, | 495 lose_context_when_out_of_memory, |
464 limits, | 496 limits, |
465 NULL)); | 497 NULL)); |
466 } | 498 } |
467 | 499 |
500 void CompositorImpl::Layout() { | |
501 client_->Layout(); | |
502 } | |
503 | |
468 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( | 504 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( |
469 bool fallback) { | 505 bool fallback) { |
470 blink::WebGraphicsContext3D::Attributes attrs; | 506 blink::WebGraphicsContext3D::Attributes attrs; |
471 attrs.shareResources = true; | 507 attrs.shareResources = true; |
472 attrs.noAutomaticFlushes = true; | 508 attrs.noAutomaticFlushes = true; |
473 | 509 |
474 DCHECK(window_); | 510 DCHECK(window_); |
475 DCHECK(surface_id_); | 511 DCHECK(surface_id_); |
476 | 512 |
477 scoped_refptr<ContextProviderCommandBuffer> context_provider = | 513 scoped_refptr<ContextProviderCommandBuffer> context_provider = |
(...skipping 13 matching lines...) Expand all Loading... | |
491 } | 527 } |
492 | 528 |
493 scoped_refptr<cc::ContextProvider> CompositorImpl::OffscreenContextProvider() { | 529 scoped_refptr<cc::ContextProvider> CompositorImpl::OffscreenContextProvider() { |
494 // There is no support for offscreen contexts, or compositor filters that | 530 // There is no support for offscreen contexts, or compositor filters that |
495 // would require them in this compositor instance. If they are needed, | 531 // would require them in this compositor instance. If they are needed, |
496 // then implement a context provider that provides contexts from | 532 // then implement a context provider that provides contexts from |
497 // ImageTransportSurfaceAndroid. | 533 // ImageTransportSurfaceAndroid. |
498 return NULL; | 534 return NULL; |
499 } | 535 } |
500 | 536 |
501 void CompositorImpl::DidCompleteSwapBuffers() { | 537 void CompositorImpl::ScheduleComposite() { |
502 client_->OnSwapBuffersCompleted(); | 538 // We already scheduled something. |
Sami
2014/04/16 15:16:30
The consumePendingRendererFrame() logic made sure
| |
503 } | 539 if (need_to_composite_) |
540 return; | |
504 | 541 |
505 void CompositorImpl::ScheduleComposite() { | 542 need_to_composite_ = true; |
506 client_->ScheduleComposite(); | 543 base::MessageLoop::current()->PostTask( |
no sievers
2014/04/16 02:17:28
It definitely loses the 'post to front of queue' b
Sami
2014/04/16 15:16:30
I *think* it's still an issue (here's the original
no sievers
2014/05/09 00:30:05
Do you mind if I follow up on this separately? Han
| |
544 FROM_HERE, | |
545 base::Bind( | |
546 &CompositorImpl::Composite, weak_factory_.GetWeakPtr(), false)); | |
507 } | 547 } |
508 | 548 |
509 void CompositorImpl::ScheduleAnimation() { | 549 void CompositorImpl::ScheduleAnimation() { |
510 ScheduleComposite(); | 550 ScheduleComposite(); |
511 } | 551 } |
512 | 552 |
513 void CompositorImpl::DidPostSwapBuffers() { | 553 void CompositorImpl::DidPostSwapBuffers() { |
514 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); | 554 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); |
515 client_->OnSwapBuffersPosted(); | 555 client_->OnSwapBuffersPosted(); |
556 did_post_swapbuffers_ = true; | |
557 } | |
558 | |
559 void CompositorImpl::DidCompleteSwapBuffers() { | |
560 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); | |
561 DCHECK_GT(pending_swapbuffers_, 0U); | |
562 pending_swapbuffers_--; | |
516 } | 563 } |
517 | 564 |
518 void CompositorImpl::DidAbortSwapBuffers() { | 565 void CompositorImpl::DidAbortSwapBuffers() { |
519 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); | 566 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); |
520 client_->OnSwapBuffersCompleted(); | 567 DCHECK_GT(pending_swapbuffers_, 0U); |
568 pending_swapbuffers_--; | |
521 } | 569 } |
522 | 570 |
523 void CompositorImpl::DidCommit() { | 571 void CompositorImpl::DidCommit() { |
524 root_window_->OnCompositingDidCommit(); | 572 root_window_->OnCompositingDidCommit(); |
525 } | 573 } |
526 | 574 |
527 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { | 575 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { |
528 root_layer_->AddChild(layer); | 576 root_layer_->AddChild(layer); |
529 } | 577 } |
530 | 578 |
579 void CompositorImpl::OnVSync(base::TimeTicks frame_time, | |
580 base::TimeDelta vsync_period) { | |
581 Composite(true); | |
582 can_composite_outside_vsync_ = true; | |
583 } | |
584 | |
531 } // namespace content | 585 } // namespace content |
OLD | NEW |