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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 | 67 |
68 namespace { | 68 namespace { |
69 | 69 |
70 const unsigned int kMaxSwapBuffers = 2U; | 70 const unsigned int kMaxSwapBuffers = 2U; |
71 | 71 |
72 // Used to override capabilities_.adjust_deadline_for_parent to false | 72 // Used to override capabilities_.adjust_deadline_for_parent to false |
73 class OutputSurfaceWithoutParent : public cc::OutputSurface { | 73 class OutputSurfaceWithoutParent : public cc::OutputSurface { |
74 public: | 74 public: |
75 OutputSurfaceWithoutParent( | 75 OutputSurfaceWithoutParent( |
76 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 76 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
77 base::WeakPtr<CompositorImpl> compositor_impl) | 77 const base::Callback<void(gpu::Capabilities)>& |
78 populate_gpu_capabilities_callback) | |
78 : cc::OutputSurface(context_provider), | 79 : cc::OutputSurface(context_provider), |
80 populate_gpu_capabilities_callback_(populate_gpu_capabilities_callback), | |
79 swap_buffers_completion_callback_( | 81 swap_buffers_completion_callback_( |
80 base::Bind(&OutputSurfaceWithoutParent::OnSwapBuffersCompleted, | 82 base::Bind(&OutputSurfaceWithoutParent::OnSwapBuffersCompleted, |
81 base::Unretained(this))) { | 83 base::Unretained(this))) { |
82 capabilities_.adjust_deadline_for_parent = false; | 84 capabilities_.adjust_deadline_for_parent = false; |
83 capabilities_.max_frames_pending = 2; | 85 capabilities_.max_frames_pending = 2; |
84 compositor_impl_ = compositor_impl; | |
85 } | 86 } |
86 | 87 |
87 void SwapBuffers(cc::CompositorFrame* frame) override { | 88 void SwapBuffers(cc::CompositorFrame* frame) override { |
88 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); | 89 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); |
89 DCHECK(frame->gl_frame_data->sub_buffer_rect == | 90 DCHECK(frame->gl_frame_data->sub_buffer_rect == |
90 gfx::Rect(frame->gl_frame_data->size)); | 91 gfx::Rect(frame->gl_frame_data->size)); |
91 context_provider_->ContextSupport()->Swap(); | 92 context_provider_->ContextSupport()->Swap(); |
92 client_->DidSwapBuffers(); | 93 client_->DidSwapBuffers(); |
93 } | 94 } |
94 | 95 |
95 bool BindToClient(cc::OutputSurfaceClient* client) override { | 96 bool BindToClient(cc::OutputSurfaceClient* client) override { |
96 if (!OutputSurface::BindToClient(client)) | 97 if (!OutputSurface::BindToClient(client)) |
97 return false; | 98 return false; |
98 | 99 |
99 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( | 100 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( |
100 swap_buffers_completion_callback_.callback()); | 101 swap_buffers_completion_callback_.callback()); |
101 | 102 |
102 compositor_impl_->PopulateGpuCapabilities( | 103 populate_gpu_capabilities_callback_.Run( |
103 context_provider_->ContextCapabilities().gpu); | 104 context_provider_->ContextCapabilities().gpu); |
104 | 105 |
105 return true; | 106 return true; |
106 } | 107 } |
107 | 108 |
108 private: | 109 private: |
109 CommandBufferProxyImpl* GetCommandBufferProxy() { | 110 CommandBufferProxyImpl* GetCommandBufferProxy() { |
110 ContextProviderCommandBuffer* provider_command_buffer = | 111 ContextProviderCommandBuffer* provider_command_buffer = |
111 static_cast<content::ContextProviderCommandBuffer*>( | 112 static_cast<content::ContextProviderCommandBuffer*>( |
112 context_provider_.get()); | 113 context_provider_.get()); |
113 CommandBufferProxyImpl* command_buffer_proxy = | 114 CommandBufferProxyImpl* command_buffer_proxy = |
114 provider_command_buffer->GetCommandBufferProxy(); | 115 provider_command_buffer->GetCommandBufferProxy(); |
115 DCHECK(command_buffer_proxy); | 116 DCHECK(command_buffer_proxy); |
116 return command_buffer_proxy; | 117 return command_buffer_proxy; |
117 } | 118 } |
118 | 119 |
119 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, | 120 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, |
120 gfx::SwapResult result) { | 121 gfx::SwapResult result) { |
121 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | 122 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); |
122 OutputSurface::OnSwapBuffersComplete(); | 123 OutputSurface::OnSwapBuffersComplete(); |
123 } | 124 } |
124 | 125 |
126 base::Callback<void(gpu::Capabilities)> populate_gpu_capabilities_callback_; | |
125 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&, | 127 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&, |
126 gfx::SwapResult)> | 128 gfx::SwapResult)> |
127 swap_buffers_completion_callback_; | 129 swap_buffers_completion_callback_; |
128 | |
129 base::WeakPtr<CompositorImpl> compositor_impl_; | |
130 }; | 130 }; |
131 | 131 |
132 static bool g_initialized = false; | 132 static bool g_initialized = false; |
133 | 133 |
134 bool g_use_surface_manager = false; | 134 bool g_use_surface_manager = false; |
135 base::LazyInstance<cc::SurfaceManager> g_surface_manager = | 135 base::LazyInstance<cc::SurfaceManager> g_surface_manager = |
136 LAZY_INSTANCE_INITIALIZER; | 136 LAZY_INSTANCE_INITIALIZER; |
137 | 137 |
138 | 138 |
139 int g_surface_id_namespace = 0; | 139 int g_surface_id_namespace = 0; |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 // But from here on just try and always lead to either | 636 // But from here on just try and always lead to either |
637 // DidInitializeOutputSurface() or DidFailToInitializeOutputSurface(). | 637 // DidInitializeOutputSurface() or DidFailToInitializeOutputSurface(). |
638 scoped_refptr<GpuChannelHost> gpu_channel_host(factory->GetGpuChannel()); | 638 scoped_refptr<GpuChannelHost> gpu_channel_host(factory->GetGpuChannel()); |
639 scoped_refptr<ContextProviderCommandBuffer> context_provider( | 639 scoped_refptr<ContextProviderCommandBuffer> context_provider( |
640 ContextProviderCommandBuffer::Create( | 640 ContextProviderCommandBuffer::Create( |
641 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_), | 641 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_), |
642 BROWSER_COMPOSITOR_ONSCREEN_CONTEXT)); | 642 BROWSER_COMPOSITOR_ONSCREEN_CONTEXT)); |
643 DCHECK(context_provider.get()); | 643 DCHECK(context_provider.get()); |
644 | 644 |
645 scoped_ptr<cc::OutputSurface> real_output_surface( | 645 scoped_ptr<cc::OutputSurface> real_output_surface( |
646 new OutputSurfaceWithoutParent(context_provider, | 646 new OutputSurfaceWithoutParent( |
647 weak_factory_.GetWeakPtr())); | 647 context_provider, base::Bind(&CompositorImpl::PopulateGpuCapabilities, |
648 weak_factory_.GetWeakPtr()))); | |
no sievers
2015/06/09 22:48:30
The OutputSurface should not be able to outlive th
sunnyps
2015/06/09 23:39:35
Done.
| |
648 | 649 |
649 cc::SurfaceManager* manager = GetSurfaceManager(); | 650 cc::SurfaceManager* manager = GetSurfaceManager(); |
650 if (manager) { | 651 if (manager) { |
651 display_client_.reset(new cc::OnscreenDisplayClient( | 652 display_client_.reset(new cc::OnscreenDisplayClient( |
652 real_output_surface.Pass(), manager, HostSharedBitmapManager::current(), | 653 real_output_surface.Pass(), manager, HostSharedBitmapManager::current(), |
653 BrowserGpuMemoryBufferManager::current(), | 654 BrowserGpuMemoryBufferManager::current(), |
654 host_->settings().renderer_settings, | 655 host_->settings().renderer_settings, |
655 base::ThreadTaskRunnerHandle::Get())); | 656 base::ThreadTaskRunnerHandle::Get())); |
656 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( | 657 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( |
657 new cc::SurfaceDisplayOutputSurface( | 658 new cc::SurfaceDisplayOutputSurface( |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 | 757 |
757 void CompositorImpl::SetNeedsAnimate() { | 758 void CompositorImpl::SetNeedsAnimate() { |
758 needs_animate_ = true; | 759 needs_animate_ = true; |
759 if (!host_) | 760 if (!host_) |
760 return; | 761 return; |
761 | 762 |
762 host_->SetNeedsAnimate(); | 763 host_->SetNeedsAnimate(); |
763 } | 764 } |
764 | 765 |
765 } // namespace content | 766 } // namespace content |
OLD | NEW |