OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/gpu/gpu_service_internal.h" | 5 #include "services/ui/gpu/gpu_service_internal.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "cc/output/in_process_context_provider.h" | 11 #include "cc/output/in_process_context_provider.h" |
| 12 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
12 #include "gpu/command_buffer/service/gpu_switches.h" | 13 #include "gpu/command_buffer/service/gpu_switches.h" |
13 #include "gpu/command_buffer/service/sync_point_manager.h" | 14 #include "gpu/command_buffer/service/sync_point_manager.h" |
14 #include "gpu/config/gpu_info_collector.h" | 15 #include "gpu/config/gpu_info_collector.h" |
15 #include "gpu/config/gpu_switches.h" | 16 #include "gpu/config/gpu_switches.h" |
16 #include "gpu/config/gpu_util.h" | 17 #include "gpu/config/gpu_util.h" |
17 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 18 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
18 #include "gpu/ipc/common/memory_stats.h" | 19 #include "gpu/ipc/common/memory_stats.h" |
19 #include "gpu/ipc/gpu_in_process_thread_service.h" | 20 #include "gpu/ipc/gpu_in_process_thread_service.h" |
20 #include "gpu/ipc/service/gpu_channel_manager.h" | 21 #include "gpu/ipc/service/gpu_channel_manager.h" |
21 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 22 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
22 #include "gpu/ipc/service/gpu_watchdog_thread.h" | 23 #include "gpu/ipc/service/gpu_watchdog_thread.h" |
23 #include "ipc/ipc_channel_handle.h" | 24 #include "ipc/ipc_channel_handle.h" |
24 #include "ipc/ipc_sync_message_filter.h" | 25 #include "ipc/ipc_sync_message_filter.h" |
25 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" | 26 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" |
26 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" | 27 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" |
27 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" | 28 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" |
28 #include "media/gpu/ipc/service/media_gpu_channel_manager.h" | 29 #include "media/gpu/ipc/service/media_gpu_channel_manager.h" |
29 #include "mojo/public/cpp/bindings/strong_binding.h" | 30 #include "mojo/public/cpp/bindings/strong_binding.h" |
30 #include "services/ui/common/mus_gpu_memory_buffer_manager.h" | 31 #include "services/ui/common/mus_gpu_memory_buffer_manager.h" |
31 #include "services/ui/surfaces/display_compositor.h" | |
32 #include "ui/gl/gl_implementation.h" | 32 #include "ui/gl/gl_implementation.h" |
33 #include "ui/gl/gl_switches.h" | 33 #include "ui/gl/gl_switches.h" |
34 #include "ui/gl/gpu_switching_manager.h" | 34 #include "ui/gl/gpu_switching_manager.h" |
35 #include "ui/gl/init/gl_factory.h" | 35 #include "ui/gl/init/gl_factory.h" |
36 #include "url/gurl.h" | 36 #include "url/gurl.h" |
37 | 37 |
38 namespace ui { | 38 namespace ui { |
39 | 39 |
40 GpuServiceInternal::GpuServiceInternal( | 40 GpuServiceInternal::GpuServiceInternal( |
41 const gpu::GPUInfo& gpu_info, | 41 const gpu::GPUInfo& gpu_info, |
42 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, | 42 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, |
43 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 43 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
44 scoped_refptr<base::SingleThreadTaskRunner> io_runner, | 44 scoped_refptr<base::SingleThreadTaskRunner> io_runner) |
45 scoped_refptr<base::SingleThreadTaskRunner> compositor_runner) | |
46 : io_runner_(std::move(io_runner)), | 45 : io_runner_(std::move(io_runner)), |
47 compositor_runner_(std::move(compositor_runner)), | |
48 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 46 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
49 base::WaitableEvent::InitialState::NOT_SIGNALED), | 47 base::WaitableEvent::InitialState::NOT_SIGNALED), |
50 watchdog_thread_(std::move(watchdog_thread)), | 48 watchdog_thread_(std::move(watchdog_thread)), |
51 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 49 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
52 gpu_info_(gpu_info) {} | 50 gpu_info_(gpu_info) {} |
53 | 51 |
54 GpuServiceInternal::~GpuServiceInternal() { | 52 GpuServiceInternal::~GpuServiceInternal() { |
55 bindings_.CloseAllBindings(); | 53 bindings_.CloseAllBindings(); |
56 media_gpu_channel_manager_.reset(); | 54 media_gpu_channel_manager_.reset(); |
57 gpu_channel_manager_.reset(); | 55 gpu_channel_manager_.reset(); |
58 owned_sync_point_manager_.reset(); | 56 owned_sync_point_manager_.reset(); |
59 | 57 |
60 // Signal this event before destroying the child process. That way all | 58 // Signal this event before destroying the child process. That way all |
61 // background threads can cleanup. | 59 // background threads can cleanup. |
62 // For example, in the renderer the RenderThread instances will be able to | 60 // For example, in the renderer the RenderThread instances will be able to |
63 // notice shutdown before the render process begins waiting for them to exit. | 61 // notice shutdown before the render process begins waiting for them to exit. |
64 shutdown_event_.Signal(); | 62 shutdown_event_.Signal(); |
65 } | 63 } |
66 | 64 |
67 void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) { | 65 void GpuServiceInternal::Bind(mojom::GpuServiceInternalRequest request) { |
68 bindings_.AddBinding(this, std::move(request)); | 66 bindings_.AddBinding(this, std::move(request)); |
69 } | 67 } |
70 | 68 |
71 void GpuServiceInternal::CreateGpuMemoryBuffer( | 69 void GpuServiceInternal::CreateGpuMemoryBuffer( |
72 gfx::GpuMemoryBufferId id, | 70 gfx::GpuMemoryBufferId id, |
73 const gfx::Size& size, | 71 const gfx::Size& size, |
74 gfx::BufferFormat format, | 72 gfx::BufferFormat format, |
75 gfx::BufferUsage usage, | 73 gfx::BufferUsage usage, |
76 int client_id, | 74 int client_id, |
77 gpu::SurfaceHandle surface_handle, | 75 gpu::SurfaceHandle surface_handle, |
78 const CreateGpuMemoryBufferCallback& callback) { | 76 const CreateGpuMemoryBufferCallback& callback) { |
79 DCHECK(CalledOnValidThread()); | 77 DCHECK(CalledOnValidThread()); |
80 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | 78 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( |
81 id, size, format, usage, client_id, surface_handle)); | 79 id, size, format, usage, client_id, surface_handle)); |
82 } | 80 } |
83 | 81 |
84 void GpuServiceInternal::DestroyGpuMemoryBuffer( | 82 void GpuServiceInternal::DestroyGpuMemoryBuffer( |
85 gfx::GpuMemoryBufferId id, | 83 gfx::GpuMemoryBufferId id, |
86 int client_id, | 84 int client_id, |
87 const gpu::SyncToken& sync_token) { | 85 const gpu::SyncToken& sync_token) { |
88 DCHECK(CalledOnValidThread()); | 86 DCHECK(CalledOnValidThread()); |
89 if (gpu_channel_manager_) | 87 if (gpu_channel_manager_) |
90 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); | 88 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); |
91 } | 89 } |
92 | 90 |
93 void GpuServiceInternal::CreateDisplayCompositor( | |
94 cc::mojom::DisplayCompositorRequest request, | |
95 cc::mojom::DisplayCompositorClientPtr client) { | |
96 DCHECK(CalledOnValidThread()); | |
97 DCHECK(!gpu_command_service_); | |
98 gpu_command_service_ = new gpu::GpuInProcessThreadService( | |
99 base::ThreadTaskRunnerHandle::Get(), owned_sync_point_manager_.get(), | |
100 gpu_channel_manager_->mailbox_manager(), | |
101 gpu_channel_manager_->share_group()); | |
102 mojom::GpuServiceInternalPtr gpu_service_ptr; | |
103 Add(mojo::GetProxy(&gpu_service_ptr)); | |
104 compositor_runner_->PostTask( | |
105 FROM_HERE, | |
106 base::Bind(&GpuServiceInternal::CreateDisplayCompositorOnCompositorThread, | |
107 base::Unretained(this), | |
108 base::Passed(gpu_service_ptr.PassInterface()), | |
109 base::Passed(&request), base::Passed(client.PassInterface()))); | |
110 } | |
111 | |
112 void GpuServiceInternal::CreateDisplayCompositorOnCompositorThread( | |
113 mojom::GpuServiceInternalPtrInfo gpu_service_info, | |
114 cc::mojom::DisplayCompositorRequest request, | |
115 cc::mojom::DisplayCompositorClientPtrInfo client_info) { | |
116 DCHECK(compositor_runner_->BelongsToCurrentThread()); | |
117 gpu_internal_.Bind(std::move(gpu_service_info)); | |
118 | |
119 cc::mojom::DisplayCompositorClientPtr client_ptr; | |
120 client_ptr.Bind(std::move(client_info)); | |
121 | |
122 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager = | |
123 base::MakeUnique<MusGpuMemoryBufferManager>(gpu_internal_.get(), | |
124 1 /* client_id */); | |
125 // |gpu_memory_buffer_factory_| is null in tests. | |
126 gpu::ImageFactory* image_factory = | |
127 gpu_memory_buffer_factory_ ? gpu_memory_buffer_factory_->AsImageFactory() | |
128 : nullptr; | |
129 display_compositor_ = base::MakeUnique<DisplayCompositor>( | |
130 gpu_command_service_, std::move(gpu_memory_buffer_manager), image_factory, | |
131 std::move(request), std::move(client_ptr)); | |
132 } | |
133 | |
134 void GpuServiceInternal::DestroyDisplayCompositor() { | |
135 if (compositor_runner_->BelongsToCurrentThread()) { | |
136 DestroyDisplayCompositorOnCompositorThread(); | |
137 return; | |
138 } | |
139 compositor_runner_->PostTask( | |
140 FROM_HERE, | |
141 base::Bind( | |
142 &GpuServiceInternal::DestroyDisplayCompositorOnCompositorThread, | |
143 base::Unretained(this))); | |
144 } | |
145 | |
146 void GpuServiceInternal::DestroyDisplayCompositorOnCompositorThread() { | |
147 display_compositor_.reset(); | |
148 gpu_internal_.reset(); | |
149 } | |
150 | |
151 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) { | 91 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) { |
152 NOTIMPLEMENTED(); | 92 NOTIMPLEMENTED(); |
153 } | 93 } |
154 | 94 |
155 void GpuServiceInternal::DidDestroyChannel(int client_id) { | 95 void GpuServiceInternal::DidDestroyChannel(int client_id) { |
156 media_gpu_channel_manager_->RemoveChannel(client_id); | 96 media_gpu_channel_manager_->RemoveChannel(client_id); |
157 NOTIMPLEMENTED(); | 97 NOTIMPLEMENTED(); |
158 } | 98 } |
159 | 99 |
160 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { | 100 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { |
(...skipping 17 matching lines...) Expand all Loading... |
178 gpu::SurfaceHandle parent_window, | 118 gpu::SurfaceHandle parent_window, |
179 gpu::SurfaceHandle child_window) { | 119 gpu::SurfaceHandle child_window) { |
180 ::SetParent(child_window, parent_window); | 120 ::SetParent(child_window, parent_window); |
181 } | 121 } |
182 #endif | 122 #endif |
183 | 123 |
184 void GpuServiceInternal::SetActiveURL(const GURL& url) { | 124 void GpuServiceInternal::SetActiveURL(const GURL& url) { |
185 // TODO(penghuang): implement this function. | 125 // TODO(penghuang): implement this function. |
186 } | 126 } |
187 | 127 |
188 void GpuServiceInternal::Initialize(const InitializeCallback& callback) { | 128 void GpuServiceInternal::Initialize() { |
189 DCHECK(CalledOnValidThread()); | 129 DCHECK(CalledOnValidThread()); |
190 gpu_info_.video_decode_accelerator_capabilities = | 130 gpu_info_.video_decode_accelerator_capabilities = |
191 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 131 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
192 gpu_info_.video_encode_accelerator_supported_profiles = | 132 gpu_info_.video_encode_accelerator_supported_profiles = |
193 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | 133 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); |
194 gpu_info_.jpeg_decode_accelerator_supported = | 134 gpu_info_.jpeg_decode_accelerator_supported = |
195 media::GpuJpegDecodeAccelerator::IsSupported(); | 135 media::GpuJpegDecodeAccelerator::IsSupported(); |
196 | 136 |
197 DCHECK(!owned_sync_point_manager_); | 137 DCHECK(!owned_sync_point_manager_); |
198 const bool allow_threaded_wait = false; | 138 const bool allow_threaded_wait = false; |
199 owned_sync_point_manager_.reset( | 139 owned_sync_point_manager_.reset( |
200 new gpu::SyncPointManager(allow_threaded_wait)); | 140 new gpu::SyncPointManager(allow_threaded_wait)); |
201 | 141 |
202 // Defer creation of the render thread. This is to prevent it from handling | 142 // Defer creation of the render thread. This is to prevent it from handling |
203 // IPC messages before the sandbox has been enabled and all other necessary | 143 // IPC messages before the sandbox has been enabled and all other necessary |
204 // initialization has succeeded. | 144 // initialization has succeeded. |
205 gpu_channel_manager_.reset(new gpu::GpuChannelManager( | 145 gpu_channel_manager_.reset(new gpu::GpuChannelManager( |
206 gpu_preferences_, this, watchdog_thread_.get(), | 146 gpu_preferences_, this, watchdog_thread_.get(), |
207 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), | 147 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), |
208 &shutdown_event_, owned_sync_point_manager_.get(), | 148 &shutdown_event_, owned_sync_point_manager_.get(), |
209 gpu_memory_buffer_factory_)); | 149 gpu_memory_buffer_factory_)); |
210 | 150 |
211 media_gpu_channel_manager_.reset( | 151 media_gpu_channel_manager_.reset( |
212 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); | 152 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); |
213 | |
214 callback.Run(gpu_info_); | |
215 } | 153 } |
216 | 154 |
217 void GpuServiceInternal::EstablishGpuChannel( | 155 void GpuServiceInternal::EstablishGpuChannel( |
218 int32_t client_id, | 156 int32_t client_id, |
219 uint64_t client_tracing_id, | 157 uint64_t client_tracing_id, |
220 bool is_gpu_host, | 158 bool is_gpu_host, |
221 const EstablishGpuChannelCallback& callback) { | 159 const EstablishGpuChannelCallback& callback) { |
222 DCHECK(CalledOnValidThread()); | 160 DCHECK(CalledOnValidThread()); |
223 | 161 |
224 if (!gpu_channel_manager_) { | 162 if (!gpu_channel_manager_) { |
225 callback.Run(mojo::ScopedMessagePipeHandle()); | 163 callback.Run(mojo::ScopedMessagePipeHandle()); |
226 return; | 164 return; |
227 } | 165 } |
228 | 166 |
229 const bool preempts = is_gpu_host; | 167 const bool preempts = is_gpu_host; |
230 const bool allow_view_command_buffers = is_gpu_host; | 168 const bool allow_view_command_buffers = is_gpu_host; |
231 const bool allow_real_time_streams = is_gpu_host; | 169 const bool allow_real_time_streams = is_gpu_host; |
232 mojo::ScopedMessagePipeHandle channel_handle; | 170 mojo::ScopedMessagePipeHandle channel_handle; |
233 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( | 171 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( |
234 client_id, client_tracing_id, preempts, allow_view_command_buffers, | 172 client_id, client_tracing_id, preempts, allow_view_command_buffers, |
235 allow_real_time_streams); | 173 allow_real_time_streams); |
236 channel_handle.reset(handle.mojo_handle); | 174 channel_handle.reset(handle.mojo_handle); |
237 media_gpu_channel_manager_->AddChannel(client_id); | 175 media_gpu_channel_manager_->AddChannel(client_id); |
238 callback.Run(std::move(channel_handle)); | 176 callback.Run(std::move(channel_handle)); |
239 } | 177 } |
240 | 178 |
241 } // namespace ui | 179 } // namespace ui |
OLD | NEW |