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) | 45 : gpu_runner_(base::ThreadTaskRunnerHandle::Get()), |
46 : io_runner_(std::move(io_runner)), | 46 io_runner_(std::move(io_runner)), |
47 compositor_runner_(std::move(compositor_runner)), | |
48 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 47 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
49 base::WaitableEvent::InitialState::NOT_SIGNALED), | 48 base::WaitableEvent::InitialState::NOT_SIGNALED), |
50 watchdog_thread_(std::move(watchdog_thread)), | 49 watchdog_thread_(std::move(watchdog_thread)), |
51 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 50 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
52 gpu_info_(gpu_info) {} | 51 gpu_info_(gpu_info) {} |
53 | 52 |
54 GpuServiceInternal::~GpuServiceInternal() { | 53 GpuServiceInternal::~GpuServiceInternal() { |
55 bindings_.CloseAllBindings(); | 54 bindings_.CloseAllBindings(); |
56 media_gpu_channel_manager_.reset(); | 55 media_gpu_channel_manager_.reset(); |
57 gpu_channel_manager_.reset(); | 56 gpu_channel_manager_.reset(); |
58 owned_sync_point_manager_.reset(); | 57 owned_sync_point_manager_.reset(); |
59 | 58 |
60 // Signal this event before destroying the child process. That way all | 59 // Signal this event before destroying the child process. That way all |
61 // background threads can cleanup. | 60 // background threads can cleanup. |
62 // For example, in the renderer the RenderThread instances will be able to | 61 // 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. | 62 // notice shutdown before the render process begins waiting for them to exit. |
64 shutdown_event_.Signal(); | 63 shutdown_event_.Signal(); |
65 } | 64 } |
66 | 65 |
67 void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) { | 66 void GpuServiceInternal::Bind(mojom::GpuServiceInternalRequest request) { |
68 bindings_.AddBinding(this, std::move(request)); | 67 bindings_.AddBinding(this, std::move(request)); |
69 } | 68 } |
70 | 69 |
71 void GpuServiceInternal::CreateGpuMemoryBuffer( | 70 void GpuServiceInternal::CreateGpuMemoryBuffer( |
72 gfx::GpuMemoryBufferId id, | 71 gfx::GpuMemoryBufferId id, |
73 const gfx::Size& size, | 72 const gfx::Size& size, |
74 gfx::BufferFormat format, | 73 gfx::BufferFormat format, |
75 gfx::BufferUsage usage, | 74 gfx::BufferUsage usage, |
76 int client_id, | 75 int client_id, |
77 gpu::SurfaceHandle surface_handle, | 76 gpu::SurfaceHandle surface_handle, |
78 const CreateGpuMemoryBufferCallback& callback) { | 77 const CreateGpuMemoryBufferCallback& callback) { |
79 DCHECK(CalledOnValidThread()); | 78 DCHECK(CalledOnValidThread()); |
80 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | 79 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( |
81 id, size, format, usage, client_id, surface_handle)); | 80 id, size, format, usage, client_id, surface_handle)); |
82 } | 81 } |
83 | 82 |
84 void GpuServiceInternal::DestroyGpuMemoryBuffer( | 83 void GpuServiceInternal::DestroyGpuMemoryBuffer( |
85 gfx::GpuMemoryBufferId id, | 84 gfx::GpuMemoryBufferId id, |
86 int client_id, | 85 int client_id, |
87 const gpu::SyncToken& sync_token) { | 86 const gpu::SyncToken& sync_token) { |
88 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
89 if (gpu_channel_manager_) | 88 if (gpu_channel_manager_) |
90 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); | 89 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); |
91 } | 90 } |
92 | 91 |
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) { | 92 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) { |
152 NOTIMPLEMENTED(); | 93 NOTIMPLEMENTED(); |
153 } | 94 } |
154 | 95 |
155 void GpuServiceInternal::DidDestroyChannel(int client_id) { | 96 void GpuServiceInternal::DidDestroyChannel(int client_id) { |
156 media_gpu_channel_manager_->RemoveChannel(client_id); | 97 media_gpu_channel_manager_->RemoveChannel(client_id); |
157 NOTIMPLEMENTED(); | 98 NOTIMPLEMENTED(); |
158 } | 99 } |
159 | 100 |
160 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { | 101 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 mojo::ScopedMessagePipeHandle channel_handle; | 173 mojo::ScopedMessagePipeHandle channel_handle; |
233 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( | 174 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( |
234 client_id, client_tracing_id, preempts, allow_view_command_buffers, | 175 client_id, client_tracing_id, preempts, allow_view_command_buffers, |
235 allow_real_time_streams); | 176 allow_real_time_streams); |
236 channel_handle.reset(handle.mojo_handle); | 177 channel_handle.reset(handle.mojo_handle); |
237 media_gpu_channel_manager_->AddChannel(client_id); | 178 media_gpu_channel_manager_->AddChannel(client_id); |
238 callback.Run(std::move(channel_handle)); | 179 callback.Run(std::move(channel_handle)); |
239 } | 180 } |
240 | 181 |
241 } // namespace ui | 182 } // namespace ui |
OLD | NEW |