| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 395 |
| 395 void CompositorImpl::SetVisible(bool visible) { | 396 void CompositorImpl::SetVisible(bool visible) { |
| 396 if (!visible) { | 397 if (!visible) { |
| 397 if (WillComposite()) | 398 if (WillComposite()) |
| 398 CancelComposite(); | 399 CancelComposite(); |
| 399 ui_resource_provider_.SetLayerTreeHost(NULL); | 400 ui_resource_provider_.SetLayerTreeHost(NULL); |
| 400 host_.reset(); | 401 host_.reset(); |
| 401 } else if (!host_) { | 402 } else if (!host_) { |
| 402 DCHECK(!WillComposite()); | 403 DCHECK(!WillComposite()); |
| 403 needs_composite_ = false; | 404 needs_composite_ = false; |
| 405 needs_animate_ = false; |
| 404 pending_swapbuffers_ = 0; | 406 pending_swapbuffers_ = 0; |
| 405 cc::LayerTreeSettings settings; | 407 cc::LayerTreeSettings settings; |
| 406 settings.refresh_rate = 60.0; | 408 settings.refresh_rate = 60.0; |
| 407 settings.impl_side_painting = false; | 409 settings.impl_side_painting = false; |
| 408 settings.allow_antialiasing = false; | 410 settings.allow_antialiasing = false; |
| 409 settings.calculate_top_controls_position = false; | 411 settings.calculate_top_controls_position = false; |
| 410 settings.top_controls_height = 0.f; | 412 settings.top_controls_height = 0.f; |
| 411 settings.highp_threshold_min = 2048; | 413 settings.highp_threshold_min = 2048; |
| 412 | 414 |
| 413 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 415 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 414 settings.initial_debug_state.SetRecordRenderingStats( | 416 settings.initial_debug_state.SetRecordRenderingStats( |
| 415 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 417 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
| 416 settings.initial_debug_state.show_fps_counter = | 418 settings.initial_debug_state.show_fps_counter = |
| 417 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); | 419 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); |
| 418 // TODO(enne): Update this this compositor to use the scheduler. | |
| 419 settings.single_thread_proxy_scheduler = false; | |
| 420 | 420 |
| 421 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 421 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
| 422 this, this, HostSharedBitmapManager::current(), settings); | 422 this, this, HostSharedBitmapManager::current(), settings); |
| 423 host_->SetRootLayer(root_layer_); | 423 host_->SetRootLayer(root_layer_); |
| 424 | 424 |
| 425 host_->SetVisible(true); | 425 host_->SetVisible(true); |
| 426 host_->SetLayerTreeHostClientReady(); | 426 host_->SetLayerTreeHostClientReady(); |
| 427 host_->SetViewportSize(size_); | 427 host_->SetViewportSize(size_); |
| 428 host_->set_has_transparent_background(has_transparent_background_); | 428 host_->set_has_transparent_background(has_transparent_background_); |
| 429 host_->SetDeviceScaleFactor(device_scale_factor_); | 429 host_->SetDeviceScaleFactor(device_scale_factor_); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 new WebGraphicsContext3DCommandBufferImpl(surface_id, | 488 new WebGraphicsContext3DCommandBufferImpl(surface_id, |
| 489 url, | 489 url, |
| 490 gpu_channel_host.get(), | 490 gpu_channel_host.get(), |
| 491 attributes, | 491 attributes, |
| 492 lose_context_when_out_of_memory, | 492 lose_context_when_out_of_memory, |
| 493 limits, | 493 limits, |
| 494 NULL)); | 494 NULL)); |
| 495 } | 495 } |
| 496 | 496 |
| 497 void CompositorImpl::Layout() { | 497 void CompositorImpl::Layout() { |
| 498 ignore_schedule_composite_ = true; | 498 // TODO: If we get this callback from the SingleThreadProxy, we need |
| 499 // to stop calling it ourselves in CompositorImpl::Composite(). |
| 500 NOTREACHED(); |
| 499 client_->Layout(); | 501 client_->Layout(); |
| 500 ignore_schedule_composite_ = false; | |
| 501 } | 502 } |
| 502 | 503 |
| 503 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( | 504 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( |
| 504 bool fallback) { | 505 bool fallback) { |
| 505 blink::WebGraphicsContext3D::Attributes attrs; | 506 blink::WebGraphicsContext3D::Attributes attrs; |
| 506 attrs.shareResources = true; | 507 attrs.shareResources = true; |
| 507 attrs.noAutomaticFlushes = true; | 508 attrs.noAutomaticFlushes = true; |
| 508 pending_swapbuffers_ = 0; | 509 pending_swapbuffers_ = 0; |
| 509 | 510 |
| 510 DCHECK(window_); | 511 DCHECK(window_); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 539 return; | 540 return; |
| 540 | 541 |
| 541 needs_composite_ = true; | 542 needs_composite_ = true; |
| 542 // We currently expect layer tree invalidations at most once per frame | 543 // We currently expect layer tree invalidations at most once per frame |
| 543 // during normal operation and therefore try to composite immediately | 544 // during normal operation and therefore try to composite immediately |
| 544 // to minimize latency. | 545 // to minimize latency. |
| 545 PostComposite(COMPOSITE_IMMEDIATELY); | 546 PostComposite(COMPOSITE_IMMEDIATELY); |
| 546 } | 547 } |
| 547 | 548 |
| 548 void CompositorImpl::ScheduleAnimation() { | 549 void CompositorImpl::ScheduleAnimation() { |
| 550 DCHECK(!needs_animate_ || needs_composite_); |
| 549 DCHECK(!needs_composite_ || WillComposite()); | 551 DCHECK(!needs_composite_ || WillComposite()); |
| 550 needs_animate_ = true; | 552 needs_animate_ = true; |
| 551 | 553 |
| 552 if (needs_composite_) | 554 if (needs_composite_) |
| 553 return; | 555 return; |
| 554 | 556 |
| 555 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation"); | 557 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation"); |
| 556 needs_composite_ = true; | 558 needs_composite_ = true; |
| 557 PostComposite(COMPOSITE_EVENTUALLY); | 559 PostComposite(COMPOSITE_EVENTUALLY); |
| 558 } | 560 } |
| 559 | 561 |
| 560 void CompositorImpl::DidPostSwapBuffers() { | 562 void CompositorImpl::DidPostSwapBuffers() { |
| 561 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); | 563 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); |
| 562 did_post_swapbuffers_ = true; | 564 did_post_swapbuffers_ = true; |
| 563 } | 565 } |
| 564 | 566 |
| 565 void CompositorImpl::DidCompleteSwapBuffers() { | 567 void CompositorImpl::DidCompleteSwapBuffers() { |
| 566 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); | 568 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); |
| 567 DCHECK_GT(pending_swapbuffers_, 0U); | 569 DCHECK_GT(pending_swapbuffers_, 0U); |
| 568 if (pending_swapbuffers_-- == kMaxSwapBuffers && needs_composite_) | 570 if (pending_swapbuffers_-- == kMaxSwapBuffers && needs_composite_) |
| 569 PostComposite(COMPOSITE_IMMEDIATELY); | 571 PostComposite(COMPOSITE_IMMEDIATELY); |
| 570 client_->OnSwapBuffersCompleted(pending_swapbuffers_); | 572 client_->OnSwapBuffersCompleted(pending_swapbuffers_); |
| 571 } | 573 } |
| 572 | 574 |
| 573 void CompositorImpl::DidAbortSwapBuffers() { | 575 void CompositorImpl::DidAbortSwapBuffers() { |
| 574 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); | 576 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); |
| 575 // This really gets called only once from | 577 // This really gets called only once from |
| 576 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the | 578 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the |
| 577 // context was lost. | 579 // context was lost. |
| 578 ScheduleComposite(); | |
| 579 client_->OnSwapBuffersCompleted(0); | 580 client_->OnSwapBuffersCompleted(0); |
| 580 } | 581 } |
| 581 | 582 |
| 582 void CompositorImpl::DidCommit() { | 583 void CompositorImpl::DidCommit() { |
| 583 root_window_->OnCompositingDidCommit(); | 584 root_window_->OnCompositingDidCommit(); |
| 584 } | 585 } |
| 585 | 586 |
| 586 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { | 587 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { |
| 587 root_layer_->AddChild(layer); | 588 root_layer_->AddChild(layer); |
| 588 } | 589 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 616 } | 617 } |
| 617 | 618 |
| 618 void CompositorImpl::SetNeedsAnimate() { | 619 void CompositorImpl::SetNeedsAnimate() { |
| 619 if (!host_) | 620 if (!host_) |
| 620 return; | 621 return; |
| 621 | 622 |
| 622 host_->SetNeedsAnimate(); | 623 host_->SetNeedsAnimate(); |
| 623 } | 624 } |
| 624 | 625 |
| 625 } // namespace content | 626 } // namespace content |
| OLD | NEW |