| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 #include "third_party/khronos/GLES2/gl2ext.h" | 60 #include "third_party/khronos/GLES2/gl2ext.h" |
| 61 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 61 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
| 62 #include "ui/android/window_android.h" | 62 #include "ui/android/window_android.h" |
| 63 #include "ui/gfx/android/device_display_info.h" | 63 #include "ui/gfx/android/device_display_info.h" |
| 64 #include "ui/gfx/swap_result.h" | 64 #include "ui/gfx/swap_result.h" |
| 65 | 65 |
| 66 namespace content { | 66 namespace content { |
| 67 | 67 |
| 68 namespace { | 68 namespace { |
| 69 | 69 |
| 70 const unsigned int kMaxSwapBuffers = 2U; | 70 const unsigned int kMaxUiSwapBuffers = 1U; |
| 71 const unsigned int kMaxDisplaySwapBuffers = 1U; |
| 71 | 72 |
| 72 // Used to override capabilities_.adjust_deadline_for_parent to false | 73 // Used to override capabilities_.adjust_deadline_for_parent to false |
| 73 class OutputSurfaceWithoutParent : public cc::OutputSurface, | 74 class OutputSurfaceWithoutParent : public cc::OutputSurface, |
| 74 public CompositorImpl::VSyncObserver { | 75 public CompositorImpl::VSyncObserver { |
| 75 public: | 76 public: |
| 76 OutputSurfaceWithoutParent( | 77 OutputSurfaceWithoutParent( |
| 77 CompositorImpl* compositor, | 78 CompositorImpl* compositor, |
| 78 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 79 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
| 79 const base::Callback<void(gpu::Capabilities)>& | 80 const base::Callback<void(gpu::Capabilities)>& |
| 80 populate_gpu_capabilities_callback) | 81 populate_gpu_capabilities_callback) |
| 81 : cc::OutputSurface(context_provider), | 82 : cc::OutputSurface(context_provider), |
| 82 compositor_(compositor), | 83 compositor_(compositor), |
| 83 populate_gpu_capabilities_callback_(populate_gpu_capabilities_callback), | 84 populate_gpu_capabilities_callback_(populate_gpu_capabilities_callback), |
| 84 swap_buffers_completion_callback_( | 85 swap_buffers_completion_callback_( |
| 85 base::Bind(&OutputSurfaceWithoutParent::OnSwapBuffersCompleted, | 86 base::Bind(&OutputSurfaceWithoutParent::OnSwapBuffersCompleted, |
| 86 base::Unretained(this))) { | 87 base::Unretained(this))) { |
| 87 capabilities_.adjust_deadline_for_parent = false; | 88 capabilities_.adjust_deadline_for_parent = false; |
| 88 capabilities_.max_frames_pending = 2; | 89 capabilities_.max_frames_pending = kMaxDisplaySwapBuffers; |
| 89 } | 90 } |
| 90 | 91 |
| 91 ~OutputSurfaceWithoutParent() override { compositor_->RemoveObserver(this); } | 92 ~OutputSurfaceWithoutParent() override { compositor_->RemoveObserver(this); } |
| 92 | 93 |
| 93 void SwapBuffers(cc::CompositorFrame* frame) override { | 94 void SwapBuffers(cc::CompositorFrame* frame) override { |
| 94 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); | 95 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); |
| 95 DCHECK(frame->gl_frame_data->sub_buffer_rect == | 96 DCHECK(frame->gl_frame_data->sub_buffer_rect == |
| 96 gfx::Rect(frame->gl_frame_data->size)); | 97 gfx::Rect(frame->gl_frame_data->size)); |
| 97 context_provider_->ContextSupport()->Swap(); | 98 context_provider_->ContextSupport()->Swap(); |
| 98 client_->DidSwapBuffers(); | 99 client_->DidSwapBuffers(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 323 |
| 323 void CompositorImpl::Composite(CompositingTrigger trigger) { | 324 void CompositorImpl::Composite(CompositingTrigger trigger) { |
| 324 if (trigger == COMPOSITE_IMMEDIATELY) | 325 if (trigger == COMPOSITE_IMMEDIATELY) |
| 325 will_composite_immediately_ = false; | 326 will_composite_immediately_ = false; |
| 326 | 327 |
| 327 DCHECK(host_); | 328 DCHECK(host_); |
| 328 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); | 329 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); |
| 329 DCHECK(needs_composite_); | 330 DCHECK(needs_composite_); |
| 330 DCHECK(!DidCompositeThisFrame()); | 331 DCHECK(!DidCompositeThisFrame()); |
| 331 | 332 |
| 332 DCHECK_LE(pending_swapbuffers_, kMaxSwapBuffers); | 333 DCHECK_LE(pending_swapbuffers_, kMaxUiSwapBuffers); |
| 333 // Swap Ack accounting is unreliable if the OutputSurface was lost. | 334 // Swap Ack accounting is unreliable if the OutputSurface was lost. |
| 334 // In that case still attempt to composite, which will cause creation of a | 335 // In that case still attempt to composite, which will cause creation of a |
| 335 // new OutputSurface and reset pending_swapbuffers_. | 336 // new OutputSurface and reset pending_swapbuffers_. |
| 336 if (pending_swapbuffers_ == kMaxSwapBuffers && | 337 if (pending_swapbuffers_ == kMaxUiSwapBuffers && |
| 337 !host_->output_surface_lost()) { | 338 !host_->output_surface_lost()) { |
| 338 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit"); | 339 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit"); |
| 339 return; | 340 return; |
| 340 } | 341 } |
| 341 | 342 |
| 342 // Reset state before Layout+Composite since that might create more | 343 // Reset state before Layout+Composite since that might create more |
| 343 // requests to Composite that we need to respect. | 344 // requests to Composite that we need to respect. |
| 344 needs_composite_ = false; | 345 needs_composite_ = false; |
| 345 | 346 |
| 346 // Only allow compositing once per vsync. | 347 // Only allow compositing once per vsync. |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 } | 724 } |
| 724 | 725 |
| 725 void CompositorImpl::DidPostSwapBuffers() { | 726 void CompositorImpl::DidPostSwapBuffers() { |
| 726 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); | 727 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); |
| 727 did_post_swapbuffers_ = true; | 728 did_post_swapbuffers_ = true; |
| 728 } | 729 } |
| 729 | 730 |
| 730 void CompositorImpl::DidCompleteSwapBuffers() { | 731 void CompositorImpl::DidCompleteSwapBuffers() { |
| 731 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); | 732 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); |
| 732 DCHECK_GT(pending_swapbuffers_, 0U); | 733 DCHECK_GT(pending_swapbuffers_, 0U); |
| 733 if (pending_swapbuffers_-- == kMaxSwapBuffers && needs_composite_) | 734 if (pending_swapbuffers_-- == kMaxUiSwapBuffers && needs_composite_) |
| 734 PostComposite(COMPOSITE_IMMEDIATELY); | 735 PostComposite(COMPOSITE_IMMEDIATELY); |
| 735 client_->OnSwapBuffersCompleted(pending_swapbuffers_); | 736 client_->OnSwapBuffersCompleted(pending_swapbuffers_); |
| 736 } | 737 } |
| 737 | 738 |
| 738 void CompositorImpl::DidAbortSwapBuffers() { | 739 void CompositorImpl::DidAbortSwapBuffers() { |
| 739 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); | 740 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); |
| 740 // This really gets called only once from | 741 // This really gets called only once from |
| 741 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the | 742 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the |
| 742 // context was lost. | 743 // context was lost. |
| 743 ScheduleComposite(); | 744 ScheduleComposite(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 786 |
| 786 void CompositorImpl::SetNeedsAnimate() { | 787 void CompositorImpl::SetNeedsAnimate() { |
| 787 needs_animate_ = true; | 788 needs_animate_ = true; |
| 788 if (!host_) | 789 if (!host_) |
| 789 return; | 790 return; |
| 790 | 791 |
| 791 host_->SetNeedsAnimate(); | 792 host_->SetNeedsAnimate(); |
| 792 } | 793 } |
| 793 | 794 |
| 794 } // namespace content | 795 } // namespace content |
| OLD | NEW |