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 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "base/threading/simple_thread.h" | 28 #include "base/threading/simple_thread.h" |
29 #include "base/threading/thread.h" | 29 #include "base/threading/thread.h" |
30 #include "base/threading/thread_checker.h" | 30 #include "base/threading/thread_checker.h" |
31 #include "cc/base/switches.h" | 31 #include "cc/base/switches.h" |
32 #include "cc/input/input_handler.h" | 32 #include "cc/input/input_handler.h" |
33 #include "cc/layers/layer.h" | 33 #include "cc/layers/layer.h" |
34 #include "cc/output/compositor_frame.h" | 34 #include "cc/output/compositor_frame.h" |
35 #include "cc/output/context_provider.h" | 35 #include "cc/output/context_provider.h" |
36 #include "cc/output/output_surface.h" | 36 #include "cc/output/output_surface.h" |
37 #include "cc/output/output_surface_client.h" | 37 #include "cc/output/output_surface_client.h" |
38 #include "cc/output/vulkan_in_process_context_provider.h" | |
38 #include "cc/raster/single_thread_task_graph_runner.h" | 39 #include "cc/raster/single_thread_task_graph_runner.h" |
39 #include "cc/scheduler/begin_frame_source.h" | 40 #include "cc/scheduler/begin_frame_source.h" |
40 #include "cc/surfaces/onscreen_display_client.h" | 41 #include "cc/surfaces/onscreen_display_client.h" |
41 #include "cc/surfaces/surface_display_output_surface.h" | 42 #include "cc/surfaces/surface_display_output_surface.h" |
42 #include "cc/surfaces/surface_id_allocator.h" | 43 #include "cc/surfaces/surface_id_allocator.h" |
43 #include "cc/surfaces/surface_manager.h" | 44 #include "cc/surfaces/surface_manager.h" |
44 #include "cc/trees/layer_tree_host.h" | 45 #include "cc/trees/layer_tree_host.h" |
45 #include "cc/trees/layer_tree_settings.h" | 46 #include "cc/trees/layer_tree_settings.h" |
46 #include "components/display_compositor/gl_helper.h" | 47 #include "components/display_compositor/gl_helper.h" |
47 #include "content/browser/android/child_process_launcher_android.h" | 48 #include "content/browser/android/child_process_launcher_android.h" |
48 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor_android.h" | 49 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor_android.h" |
49 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 50 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
50 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 51 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
51 #include "content/browser/gpu/compositor_util.h" | 52 #include "content/browser/gpu/compositor_util.h" |
52 #include "content/browser/gpu/gpu_surface_tracker.h" | 53 #include "content/browser/gpu/gpu_surface_tracker.h" |
53 #include "content/browser/renderer_host/render_widget_host_impl.h" | 54 #include "content/browser/renderer_host/render_widget_host_impl.h" |
54 #include "content/common/gpu/client/context_provider_command_buffer.h" | 55 #include "content/common/gpu/client/context_provider_command_buffer.h" |
55 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 56 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
56 #include "content/common/gpu_process_launch_causes.h" | 57 #include "content/common/gpu_process_launch_causes.h" |
57 #include "content/common/host_shared_bitmap_manager.h" | 58 #include "content/common/host_shared_bitmap_manager.h" |
58 #include "content/public/browser/android/compositor.h" | 59 #include "content/public/browser/android/compositor.h" |
59 #include "content/public/browser/android/compositor_client.h" | 60 #include "content/public/browser/android/compositor_client.h" |
60 #include "content/public/common/content_switches.h" | 61 #include "content/public/common/content_switches.h" |
61 #include "gpu/command_buffer/client/context_support.h" | 62 #include "gpu/command_buffer/client/context_support.h" |
62 #include "gpu/command_buffer/client/gles2_interface.h" | 63 #include "gpu/command_buffer/client/gles2_interface.h" |
63 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 64 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
64 #include "gpu/ipc/client/gpu_channel_host.h" | 65 #include "gpu/ipc/client/gpu_channel_host.h" |
66 #include "gpu/vulkan/vulkan_surface.h" | |
65 #include "third_party/khronos/GLES2/gl2.h" | 67 #include "third_party/khronos/GLES2/gl2.h" |
66 #include "third_party/khronos/GLES2/gl2ext.h" | 68 #include "third_party/khronos/GLES2/gl2ext.h" |
67 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 69 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
68 #include "ui/android/window_android.h" | 70 #include "ui/android/window_android.h" |
69 #include "ui/gfx/android/device_display_info.h" | 71 #include "ui/gfx/android/device_display_info.h" |
70 #include "ui/gfx/swap_result.h" | 72 #include "ui/gfx/swap_result.h" |
71 | 73 |
74 namespace gpu { | |
75 class VulkanSurface; | |
76 } | |
77 | |
72 namespace content { | 78 namespace content { |
73 | 79 |
74 namespace { | 80 namespace { |
75 | 81 |
76 const unsigned int kMaxDisplaySwapBuffers = 1U; | 82 const unsigned int kMaxDisplaySwapBuffers = 1U; |
77 | 83 |
78 class ExternalBeginFrameSource : public cc::BeginFrameSourceBase, | 84 class ExternalBeginFrameSource : public cc::BeginFrameSourceBase, |
79 public CompositorImpl::VSyncObserver { | 85 public CompositorImpl::VSyncObserver { |
80 public: | 86 public: |
81 ExternalBeginFrameSource(CompositorImpl* compositor) | 87 ExternalBeginFrameSource(CompositorImpl* compositor) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 private: | 220 private: |
215 CompositorImpl* compositor_; | 221 CompositorImpl* compositor_; |
216 base::Callback<void(gpu::Capabilities)> populate_gpu_capabilities_callback_; | 222 base::Callback<void(gpu::Capabilities)> populate_gpu_capabilities_callback_; |
217 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&, | 223 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&, |
218 gfx::SwapResult)> | 224 gfx::SwapResult)> |
219 swap_buffers_completion_callback_; | 225 swap_buffers_completion_callback_; |
220 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; | 226 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; |
221 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source_; | 227 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source_; |
222 }; | 228 }; |
223 | 229 |
230 class VulkanOutputSurface : public cc::OutputSurface { | |
piman
2016/04/28 21:29:40
I think this whole class needs to be inside #if de
sohanjg
2016/04/29 11:49:58
Done.
| |
231 public: | |
232 VulkanOutputSurface( | |
233 const scoped_refptr<cc::VulkanContextProvider>& vulkan_context_provider) | |
piman
2016/04/28 21:29:40
nit: scoped_refptr<cc::VulkanContextProvider> (not
sohanjg
2016/04/29 11:49:58
Done.
| |
234 : OutputSurface(nullptr, nullptr, vulkan_context_provider, nullptr) {} | |
piman
2016/04/28 21:29:40
nit: std::move(vulkan_context_provider)
sohanjg
2016/04/29 11:49:58
Done.
| |
235 | |
236 ~VulkanOutputSurface() override { Destroy(); } | |
237 | |
238 bool Initialize(gfx::AcceleratedWidget widget) { | |
239 DCHECK(!surface_); | |
240 std::unique_ptr<gpu::VulkanSurface> surface( | |
241 gpu::VulkanSurface::CreateViewSurface(widget)); | |
242 if (!surface->Initialize(vulkan_context_provider()->GetDeviceQueue(), | |
243 gpu::VulkanSurface::DEFAULT_SURFACE_FORMAT)) { | |
244 return false; | |
245 } | |
246 surface_ = std::move(surface); | |
247 | |
248 return true; | |
249 } | |
250 | |
251 void SwapBuffers(cc::CompositorFrame* frame) override { | |
252 surface_->SwapBuffers(); | |
253 PostSwapBuffersComplete(); | |
254 client_->DidSwapBuffers(); | |
255 } | |
256 | |
257 void Destroy() { | |
258 if (surface_) { | |
259 surface_->Destroy(); | |
260 surface_.reset(); | |
261 } | |
262 } | |
263 | |
264 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, | |
265 gfx::SwapResult result) { | |
266 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | |
267 OutputSurface::OnSwapBuffersComplete(); | |
268 } | |
269 | |
270 private: | |
271 std::unique_ptr<gpu::VulkanSurface> surface_; | |
piman
2016/04/28 21:29:40
nit: DISALLOW_COPY_AND_ASSIGN()
sohanjg
2016/04/29 11:49:58
Done.
| |
272 }; | |
273 | |
224 static bool g_initialized = false; | 274 static bool g_initialized = false; |
225 | 275 |
226 base::LazyInstance<cc::SurfaceManager> g_surface_manager = | 276 base::LazyInstance<cc::SurfaceManager> g_surface_manager = |
227 LAZY_INSTANCE_INITIALIZER; | 277 LAZY_INSTANCE_INITIALIZER; |
228 | 278 |
229 int g_surface_id_namespace = 0; | 279 int g_surface_id_namespace = 0; |
230 | 280 |
231 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { | 281 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { |
232 public: | 282 public: |
233 SingleThreadTaskGraphRunner() { | 283 SingleThreadTaskGraphRunner() { |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 // Texture uploads may use mapped memory so give a reasonable limit for them. | 622 // Texture uploads may use mapped memory so give a reasonable limit for them. |
573 limits.mapped_memory_reclaim_limit = full_screen_texture_size_in_bytes; | 623 limits.mapped_memory_reclaim_limit = full_screen_texture_size_in_bytes; |
574 | 624 |
575 scoped_refptr<ContextProviderCommandBuffer> context_provider( | 625 scoped_refptr<ContextProviderCommandBuffer> context_provider( |
576 new ContextProviderCommandBuffer( | 626 new ContextProviderCommandBuffer( |
577 base::WrapUnique(new WebGraphicsContext3DCommandBufferImpl( | 627 base::WrapUnique(new WebGraphicsContext3DCommandBufferImpl( |
578 surface_handle, url, gpu_channel_host.get(), attributes, | 628 surface_handle, url, gpu_channel_host.get(), attributes, |
579 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, | 629 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, |
580 nullptr)), | 630 nullptr)), |
581 limits, DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT)); | 631 limits, DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT)); |
582 DCHECK(context_provider.get()); | 632 DCHECK(context_provider.get()); |
piman
2016/04/28 21:29:40
All this code (from l.560 to here) should only exe
sohanjg
2016/04/29 11:49:58
Done.
| |
583 | 633 |
584 std::unique_ptr<cc::OutputSurface> real_output_surface( | 634 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = |
585 new OutputSurfaceWithoutParent( | 635 cc::VulkanInProcessContextProvider::Create(); |
piman
2016/04/28 21:29:40
I think we would want to share this across multipl
sohanjg
2016/04/29 11:49:58
Done.
| |
586 this, context_provider, | 636 std::unique_ptr<cc::OutputSurface> real_output_surface; |
587 base::Bind(&CompositorImpl::PopulateGpuCapabilities, | 637 #if defined(ENABLE_VULKAN) |
588 base::Unretained(this)), | 638 std::unique_ptr<VulkanOutputSurface> vulkan_surface; |
589 base::WrapUnique(new ExternalBeginFrameSource(this)))); | 639 if (vulkan_context_provider) { |
640 vulkan_surface.reset(new VulkanOutputSurface(vulkan_context_provider)); | |
piman
2016/04/28 21:29:40
nit: std::move(vulkan_context_provider)
sohanjg
2016/04/29 11:49:58
Done.
| |
641 if (!vulkan_surface->Initialize(window_)) { | |
642 vulkan_surface->Destroy(); | |
643 vulkan_surface.reset(); | |
644 } else { | |
645 real_output_surface = std::move(vulkan_surface); | |
646 } | |
647 } | |
648 #endif | |
649 | |
650 if (!real_output_surface) { | |
651 real_output_surface = base::WrapUnique(new OutputSurfaceWithoutParent( | |
652 this, context_provider, | |
653 base::Bind(&CompositorImpl::PopulateGpuCapabilities, | |
654 base::Unretained(this)), | |
655 base::WrapUnique(new ExternalBeginFrameSource(this)))); | |
656 } | |
590 | 657 |
591 cc::SurfaceManager* manager = GetSurfaceManager(); | 658 cc::SurfaceManager* manager = GetSurfaceManager(); |
592 display_client_.reset(new cc::OnscreenDisplayClient( | 659 display_client_.reset(new cc::OnscreenDisplayClient( |
593 std::move(real_output_surface), manager, | 660 std::move(real_output_surface), manager, |
594 HostSharedBitmapManager::current(), | 661 HostSharedBitmapManager::current(), |
595 BrowserGpuMemoryBufferManager::current(), | 662 BrowserGpuMemoryBufferManager::current(), |
596 host_->settings().renderer_settings, base::ThreadTaskRunnerHandle::Get(), | 663 host_->settings().renderer_settings, base::ThreadTaskRunnerHandle::Get(), |
597 surface_id_allocator_->id_namespace())); | 664 surface_id_allocator_->id_namespace())); |
598 std::unique_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( | 665 std::unique_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( |
599 new cc::SurfaceDisplayOutputSurface(manager, surface_id_allocator_.get(), | 666 new cc::SurfaceDisplayOutputSurface(manager, surface_id_allocator_.get(), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 void CompositorImpl::SetNeedsAnimate() { | 751 void CompositorImpl::SetNeedsAnimate() { |
685 needs_animate_ = true; | 752 needs_animate_ = true; |
686 if (!host_->visible()) | 753 if (!host_->visible()) |
687 return; | 754 return; |
688 | 755 |
689 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 756 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
690 host_->SetNeedsAnimate(); | 757 host_->SetNeedsAnimate(); |
691 } | 758 } |
692 | 759 |
693 } // namespace content | 760 } // namespace content |
OLD | NEW |