Chromium Code Reviews| 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" |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/weak_ptr.h" | |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 20 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
| 21 #include "cc/base/switches.h" | 22 #include "cc/base/switches.h" |
| 22 #include "cc/input/input_handler.h" | 23 #include "cc/input/input_handler.h" |
| 23 #include "cc/layers/layer.h" | 24 #include "cc/layers/layer.h" |
| 24 #include "cc/output/compositor_frame.h" | 25 #include "cc/output/compositor_frame.h" |
| 25 #include "cc/output/context_provider.h" | 26 #include "cc/output/context_provider.h" |
| 26 #include "cc/output/output_surface.h" | 27 #include "cc/output/output_surface.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 49 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" | 50 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 53 const unsigned int kMaxSwapBuffers = 2U; | 54 const unsigned int kMaxSwapBuffers = 2U; |
| 54 | 55 |
| 55 // Used to override capabilities_.adjust_deadline_for_parent to false | 56 // Used to override capabilities_.adjust_deadline_for_parent to false |
| 56 class OutputSurfaceWithoutParent : public cc::OutputSurface { | 57 class OutputSurfaceWithoutParent : public cc::OutputSurface { |
| 57 public: | 58 public: |
| 58 OutputSurfaceWithoutParent(const scoped_refptr< | 59 OutputSurfaceWithoutParent(const scoped_refptr< |
| 59 content::ContextProviderCommandBuffer>& context_provider) | 60 content::ContextProviderCommandBuffer>& context_provider, |
| 61 base::WeakPtr<content::CompositorImpl> compositor_impl) | |
| 60 : cc::OutputSurface(context_provider) { | 62 : cc::OutputSurface(context_provider) { |
| 61 capabilities_.adjust_deadline_for_parent = false; | 63 capabilities_.adjust_deadline_for_parent = false; |
| 64 compositor_impl_ = compositor_impl; | |
| 65 main_thread_ = base::MessageLoop::current(); | |
|
no sievers
2014/08/25 17:24:49
use MessageLoopProxy instead of MessagLoop, and th
| |
| 62 } | 66 } |
| 63 | 67 |
| 64 virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE { | 68 virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE { |
| 65 content::ContextProviderCommandBuffer* provider_command_buffer = | 69 content::ContextProviderCommandBuffer* provider_command_buffer = |
| 66 static_cast<content::ContextProviderCommandBuffer*>( | 70 static_cast<content::ContextProviderCommandBuffer*>( |
| 67 context_provider_.get()); | 71 context_provider_.get()); |
| 68 content::CommandBufferProxyImpl* command_buffer_proxy = | 72 content::CommandBufferProxyImpl* command_buffer_proxy = |
| 69 provider_command_buffer->GetCommandBufferProxy(); | 73 provider_command_buffer->GetCommandBufferProxy(); |
| 70 DCHECK(command_buffer_proxy); | 74 DCHECK(command_buffer_proxy); |
| 71 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); | 75 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); |
| 72 | 76 |
| 73 OutputSurface::SwapBuffers(frame); | 77 OutputSurface::SwapBuffers(frame); |
| 74 } | 78 } |
| 79 | |
| 80 virtual bool BindToClient(cc::OutputSurfaceClient* client) { | |
| 81 if (!OutputSurface::BindToClient(client)) | |
| 82 return false; | |
| 83 | |
| 84 main_thread_->PostTask( | |
| 85 FROM_HERE, | |
| 86 base::Bind(&content::CompositorImpl::PopulateGpuCapabilities, | |
| 87 compositor_impl_, | |
| 88 context_provider_->ContextCapabilities().gpu)); | |
| 89 | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 base::MessageLoop* main_thread_; | |
| 94 base::WeakPtr<content::CompositorImpl> compositor_impl_; | |
| 75 }; | 95 }; |
| 76 | 96 |
| 77 class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker { | 97 class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker { |
| 78 public: | 98 public: |
| 79 SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) { | 99 SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) { |
| 80 thread_checker_.DetachFromThread(); | 100 thread_checker_.DetachFromThread(); |
| 81 } | 101 } |
| 82 | 102 |
| 83 // Overridden from gfx::SurfaceTextureTracker: | 103 // Overridden from gfx::SurfaceTextureTracker: |
| 84 virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture( | 104 virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture( |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 if (gpu_channel_host && !gpu_channel_host->IsLost()) { | 566 if (gpu_channel_host && !gpu_channel_host->IsLost()) { |
| 547 context_provider = ContextProviderCommandBuffer::Create( | 567 context_provider = ContextProviderCommandBuffer::Create( |
| 548 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_), | 568 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_), |
| 549 "BrowserCompositor"); | 569 "BrowserCompositor"); |
| 550 } | 570 } |
| 551 if (!context_provider.get()) { | 571 if (!context_provider.get()) { |
| 552 LOG(ERROR) << "Failed to create 3D context for compositor."; | 572 LOG(ERROR) << "Failed to create 3D context for compositor."; |
| 553 return scoped_ptr<cc::OutputSurface>(); | 573 return scoped_ptr<cc::OutputSurface>(); |
| 554 } | 574 } |
| 555 | 575 |
| 556 return scoped_ptr<cc::OutputSurface>( | 576 return scoped_ptr<cc::OutputSurface>(new OutputSurfaceWithoutParent( |
| 557 new OutputSurfaceWithoutParent(context_provider)); | 577 context_provider, weak_factory_.GetWeakPtr())); |
| 578 } | |
| 579 | |
| 580 void CompositorImpl::PopulateGpuCapabilities( | |
| 581 gpu::Capabilities gpu_capabilities) { | |
| 582 ui_resource_provider_.SetSupportsETC1NonPowerOfTwo( | |
| 583 gpu_capabilities.texture_format_etc1_npot); | |
| 558 } | 584 } |
| 559 | 585 |
| 560 void CompositorImpl::OnLostResources() { | 586 void CompositorImpl::OnLostResources() { |
| 561 client_->DidLoseResources(); | 587 client_->DidLoseResources(); |
| 562 ui_resource_provider_.UIResourcesAreInvalid(); | 588 ui_resource_provider_.UIResourcesAreInvalid(); |
| 563 } | 589 } |
| 564 | 590 |
| 565 void CompositorImpl::ScheduleComposite() { | 591 void CompositorImpl::ScheduleComposite() { |
| 566 DCHECK(!needs_composite_ || WillComposite()); | 592 DCHECK(!needs_composite_ || WillComposite()); |
| 567 if (ignore_schedule_composite_) | 593 if (ignore_schedule_composite_) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 645 } | 671 } |
| 646 | 672 |
| 647 void CompositorImpl::SetNeedsAnimate() { | 673 void CompositorImpl::SetNeedsAnimate() { |
| 648 if (!host_) | 674 if (!host_) |
| 649 return; | 675 return; |
| 650 | 676 |
| 651 host_->SetNeedsAnimate(); | 677 host_->SetNeedsAnimate(); |
| 652 } | 678 } |
| 653 | 679 |
| 654 } // namespace content | 680 } // namespace content |
| OLD | NEW |