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