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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 needs_composite_ = false; | 307 needs_composite_ = false; |
308 | 308 |
309 // Only allow compositing once per vsync. | 309 // Only allow compositing once per vsync. |
310 current_composite_task_->Cancel(); | 310 current_composite_task_->Cancel(); |
311 DCHECK(DidCompositeThisFrame() && !WillComposite()); | 311 DCHECK(DidCompositeThisFrame() && !WillComposite()); |
312 | 312 |
313 // Ignore ScheduleComposite() from layer tree changes during layout and | 313 // Ignore ScheduleComposite() from layer tree changes during layout and |
314 // animation updates that will already be reflected in the current frame | 314 // animation updates that will already be reflected in the current frame |
315 // we are about to draw. | 315 // we are about to draw. |
316 ignore_schedule_composite_ = true; | 316 ignore_schedule_composite_ = true; |
| 317 client_->Layout(); |
317 | 318 |
318 const base::TimeTicks frame_time = gfx::FrameTime::Now(); | 319 const base::TimeTicks frame_time = gfx::FrameTime::Now(); |
319 if (needs_animate_) { | 320 if (needs_animate_) { |
320 needs_animate_ = false; | 321 needs_animate_ = false; |
321 root_window_->Animate(frame_time); | 322 root_window_->Animate(frame_time); |
322 } | 323 } |
323 ignore_schedule_composite_ = false; | 324 ignore_schedule_composite_ = false; |
324 | 325 |
325 did_post_swapbuffers_ = false; | 326 did_post_swapbuffers_ = false; |
326 host_->Composite(frame_time); | 327 host_->Composite(frame_time); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 host_->Composite(base::TimeTicks::Now()); | 419 host_->Composite(base::TimeTicks::Now()); |
419 ignore_schedule_composite_ = false; | 420 ignore_schedule_composite_ = false; |
420 } | 421 } |
421 if (WillComposite()) | 422 if (WillComposite()) |
422 CancelComposite(); | 423 CancelComposite(); |
423 ui_resource_provider_.SetLayerTreeHost(NULL); | 424 ui_resource_provider_.SetLayerTreeHost(NULL); |
424 host_.reset(); | 425 host_.reset(); |
425 } else if (!host_) { | 426 } else if (!host_) { |
426 DCHECK(!WillComposite()); | 427 DCHECK(!WillComposite()); |
427 needs_composite_ = false; | 428 needs_composite_ = false; |
| 429 needs_animate_ = false; |
428 pending_swapbuffers_ = 0; | 430 pending_swapbuffers_ = 0; |
429 cc::LayerTreeSettings settings; | 431 cc::LayerTreeSettings settings; |
430 settings.refresh_rate = 60.0; | 432 settings.refresh_rate = 60.0; |
431 settings.impl_side_painting = false; | 433 settings.impl_side_painting = false; |
432 settings.allow_antialiasing = false; | 434 settings.allow_antialiasing = false; |
433 settings.calculate_top_controls_position = false; | 435 settings.calculate_top_controls_position = false; |
434 settings.top_controls_height = 0.f; | 436 settings.top_controls_height = 0.f; |
435 settings.highp_threshold_min = 2048; | 437 settings.highp_threshold_min = 2048; |
436 | 438 |
437 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 439 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
438 settings.initial_debug_state.SetRecordRenderingStats( | 440 settings.initial_debug_state.SetRecordRenderingStats( |
439 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 441 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
440 settings.initial_debug_state.show_fps_counter = | 442 settings.initial_debug_state.show_fps_counter = |
441 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); | 443 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); |
442 // TODO(enne): Update this this compositor to use the scheduler. | |
443 settings.single_thread_proxy_scheduler = false; | |
444 | 444 |
445 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 445 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
446 this, | 446 this, |
447 this, | 447 this, |
448 HostSharedBitmapManager::current(), | 448 HostSharedBitmapManager::current(), |
449 settings, | 449 settings, |
450 base::MessageLoopProxy::current()); | 450 base::MessageLoopProxy::current()); |
451 host_->SetRootLayer(root_layer_); | 451 host_->SetRootLayer(root_layer_); |
452 | 452 |
453 host_->SetVisible(true); | 453 host_->SetVisible(true); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 new WebGraphicsContext3DCommandBufferImpl(surface_id, | 516 new WebGraphicsContext3DCommandBufferImpl(surface_id, |
517 url, | 517 url, |
518 gpu_channel_host.get(), | 518 gpu_channel_host.get(), |
519 attributes, | 519 attributes, |
520 lose_context_when_out_of_memory, | 520 lose_context_when_out_of_memory, |
521 limits, | 521 limits, |
522 NULL)); | 522 NULL)); |
523 } | 523 } |
524 | 524 |
525 void CompositorImpl::Layout() { | 525 void CompositorImpl::Layout() { |
526 ignore_schedule_composite_ = true; | 526 // TODO: If we get this callback from the SingleThreadProxy, we need |
| 527 // to stop calling it ourselves in CompositorImpl::Composite(). |
| 528 NOTREACHED(); |
527 client_->Layout(); | 529 client_->Layout(); |
528 ignore_schedule_composite_ = false; | |
529 } | 530 } |
530 | 531 |
531 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( | 532 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( |
532 bool fallback) { | 533 bool fallback) { |
533 blink::WebGraphicsContext3D::Attributes attrs; | 534 blink::WebGraphicsContext3D::Attributes attrs; |
534 attrs.shareResources = true; | 535 attrs.shareResources = true; |
535 attrs.noAutomaticFlushes = true; | 536 attrs.noAutomaticFlushes = true; |
536 pending_swapbuffers_ = 0; | 537 pending_swapbuffers_ = 0; |
537 | 538 |
538 DCHECK(window_); | 539 DCHECK(window_); |
(...skipping 28 matching lines...) Expand all Loading... |
567 return; | 568 return; |
568 | 569 |
569 needs_composite_ = true; | 570 needs_composite_ = true; |
570 // We currently expect layer tree invalidations at most once per frame | 571 // We currently expect layer tree invalidations at most once per frame |
571 // during normal operation and therefore try to composite immediately | 572 // during normal operation and therefore try to composite immediately |
572 // to minimize latency. | 573 // to minimize latency. |
573 PostComposite(COMPOSITE_IMMEDIATELY); | 574 PostComposite(COMPOSITE_IMMEDIATELY); |
574 } | 575 } |
575 | 576 |
576 void CompositorImpl::ScheduleAnimation() { | 577 void CompositorImpl::ScheduleAnimation() { |
| 578 DCHECK(!needs_animate_ || needs_composite_); |
577 DCHECK(!needs_composite_ || WillComposite()); | 579 DCHECK(!needs_composite_ || WillComposite()); |
578 needs_animate_ = true; | 580 needs_animate_ = true; |
579 | 581 |
580 if (needs_composite_) | 582 if (needs_composite_) |
581 return; | 583 return; |
582 | 584 |
583 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation"); | 585 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation"); |
584 needs_composite_ = true; | 586 needs_composite_ = true; |
585 PostComposite(COMPOSITE_EVENTUALLY); | 587 PostComposite(COMPOSITE_EVENTUALLY); |
586 } | 588 } |
587 | 589 |
588 void CompositorImpl::DidPostSwapBuffers() { | 590 void CompositorImpl::DidPostSwapBuffers() { |
589 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); | 591 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); |
590 did_post_swapbuffers_ = true; | 592 did_post_swapbuffers_ = true; |
591 } | 593 } |
592 | 594 |
593 void CompositorImpl::DidCompleteSwapBuffers() { | 595 void CompositorImpl::DidCompleteSwapBuffers() { |
594 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); | 596 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); |
595 DCHECK_GT(pending_swapbuffers_, 0U); | 597 DCHECK_GT(pending_swapbuffers_, 0U); |
596 if (pending_swapbuffers_-- == kMaxSwapBuffers && needs_composite_) | 598 if (pending_swapbuffers_-- == kMaxSwapBuffers && needs_composite_) |
597 PostComposite(COMPOSITE_IMMEDIATELY); | 599 PostComposite(COMPOSITE_IMMEDIATELY); |
598 client_->OnSwapBuffersCompleted(pending_swapbuffers_); | 600 client_->OnSwapBuffersCompleted(pending_swapbuffers_); |
599 } | 601 } |
600 | 602 |
601 void CompositorImpl::DidAbortSwapBuffers() { | 603 void CompositorImpl::DidAbortSwapBuffers() { |
602 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); | 604 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); |
603 // This really gets called only once from | 605 // This really gets called only once from |
604 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the | 606 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the |
605 // context was lost. | 607 // context was lost. |
606 ScheduleComposite(); | |
607 client_->OnSwapBuffersCompleted(0); | 608 client_->OnSwapBuffersCompleted(0); |
608 } | 609 } |
609 | 610 |
610 void CompositorImpl::DidCommit() { | 611 void CompositorImpl::DidCommit() { |
611 root_window_->OnCompositingDidCommit(); | 612 root_window_->OnCompositingDidCommit(); |
612 } | 613 } |
613 | 614 |
614 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { | 615 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { |
615 root_layer_->AddChild(layer); | 616 root_layer_->AddChild(layer); |
616 } | 617 } |
(...skipping 27 matching lines...) Expand all Loading... |
644 } | 645 } |
645 | 646 |
646 void CompositorImpl::SetNeedsAnimate() { | 647 void CompositorImpl::SetNeedsAnimate() { |
647 if (!host_) | 648 if (!host_) |
648 return; | 649 return; |
649 | 650 |
650 host_->SetNeedsAnimate(); | 651 host_->SetNeedsAnimate(); |
651 } | 652 } |
652 | 653 |
653 } // namespace content | 654 } // namespace content |
OLD | NEW |