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 "components/mus/gpu/gpu_service_mus.h" | 5 #include "components/mus/gpu/gpu_service_mus.h" |
6 | 6 |
7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "components/mus/gpu/gpu_memory_buffer_manager_mus_local.h" | 11 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h" |
12 #include "gpu/command_buffer/service/gpu_switches.h" | 12 #include "gpu/command_buffer/service/gpu_switches.h" |
13 #include "gpu/command_buffer/service/sync_point_manager.h" | 13 #include "gpu/command_buffer/service/sync_point_manager.h" |
14 #include "gpu/config/gpu_info_collector.h" | 14 #include "gpu/config/gpu_info_collector.h" |
15 #include "gpu/config/gpu_switches.h" | 15 #include "gpu/config/gpu_switches.h" |
16 #include "gpu/config/gpu_util.h" | 16 #include "gpu/config/gpu_util.h" |
17 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 17 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
18 #include "gpu/ipc/common/memory_stats.h" | 18 #include "gpu/ipc/common/memory_stats.h" |
19 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 19 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
20 #include "ipc/ipc_channel_handle.h" | 20 #include "ipc/ipc_channel_handle.h" |
21 #include "ipc/ipc_sync_message_filter.h" | 21 #include "ipc/ipc_sync_message_filter.h" |
22 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" | 22 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" |
23 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" | 23 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" |
24 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" | 24 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" |
25 #include "media/gpu/ipc/service/media_service.h" | 25 #include "media/gpu/ipc/service/media_service.h" |
26 #include "ui/gl/gl_implementation.h" | 26 #include "ui/gl/gl_implementation.h" |
27 #include "ui/gl/gl_switches.h" | 27 #include "ui/gl/gl_switches.h" |
28 #include "ui/gl/gpu_switching_manager.h" | 28 #include "ui/gl/gpu_switching_manager.h" |
29 #include "ui/gl/init/gl_factory.h" | 29 #include "ui/gl/init/gl_factory.h" |
30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
31 | 31 |
32 namespace mus { | 32 namespace mus { |
33 namespace { | 33 namespace { |
34 | 34 |
35 const int kLocalGpuChannelClientId = 1; | 35 const int kLocalGpuChannelClientId = 1; |
36 const uint64_t kLocalGpuChannelClientTracingId = 1; | 36 const uint64_t kLocalGpuChannelClientTracingId = 1; |
37 | 37 |
38 void EstablishGpuChannelDone( | 38 void EstablishGpuChannelDone( |
| 39 int client_id, |
39 std::unique_ptr<IPC::ChannelHandle> channel_handle, | 40 std::unique_ptr<IPC::ChannelHandle> channel_handle, |
40 const GpuServiceMus::EstablishGpuChannelCallback& callback) { | 41 const GpuServiceMus::EstablishGpuChannelCallback& callback) { |
41 callback.Run(*channel_handle); | 42 callback.Run(channel_handle ? client_id : -1, *channel_handle); |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 GpuServiceMus::GpuServiceMus() | 46 GpuServiceMus::GpuServiceMus() |
46 : main_message_loop_(base::MessageLoop::current()), | 47 : next_client_id_(kLocalGpuChannelClientId), |
| 48 main_message_loop_(base::MessageLoop::current()), |
47 shutdown_event_(true, false), | 49 shutdown_event_(true, false), |
48 gpu_thread_("GpuThread"), | 50 gpu_thread_("GpuThread"), |
49 io_thread_("GpuIOThread") { | 51 io_thread_("GpuIOThread") { |
50 Initialize(); | 52 Initialize(); |
51 } | 53 } |
52 | 54 |
53 GpuServiceMus::~GpuServiceMus() { | 55 GpuServiceMus::~GpuServiceMus() { |
54 // Signal this event before destroying the child process. That way all | 56 // Signal this event before destroying the child process. That way all |
55 // background threads can cleanup. | 57 // background threads can cleanup. |
56 // For example, in the renderer the RenderThread instances will be able to | 58 // For example, in the renderer the RenderThread instances will be able to |
57 // notice shutdown before the render process begins waiting for them to exit. | 59 // notice shutdown before the render process begins waiting for them to exit. |
58 shutdown_event_.Signal(); | 60 shutdown_event_.Signal(); |
59 io_thread_.Stop(); | 61 io_thread_.Stop(); |
60 } | 62 } |
61 | 63 |
62 void GpuServiceMus::EstablishGpuChannel( | 64 void GpuServiceMus::EstablishGpuChannel( |
63 int client_id, | |
64 uint64_t client_tracing_id, | 65 uint64_t client_tracing_id, |
65 bool preempts, | 66 bool preempts, |
66 bool allow_view_command_buffers, | 67 bool allow_view_command_buffers, |
67 bool allow_real_time_streams, | 68 bool allow_real_time_streams, |
68 const EstablishGpuChannelCallback& callback) { | 69 const EstablishGpuChannelCallback& callback) { |
69 DCHECK_GT(client_id, kLocalGpuChannelClientId); | 70 DCHECK(CalledOnValidThread()); |
70 | 71 |
71 if (!gpu_channel_manager_) { | 72 if (!gpu_channel_manager_) { |
72 callback.Run(IPC::ChannelHandle()); | 73 callback.Run(-1, IPC::ChannelHandle()); |
73 return; | 74 return; |
74 } | 75 } |
75 | 76 |
| 77 const int client_id = ++next_client_id_; |
76 std::unique_ptr<IPC::ChannelHandle> channel_handle(new IPC::ChannelHandle); | 78 std::unique_ptr<IPC::ChannelHandle> channel_handle(new IPC::ChannelHandle); |
77 gpu_thread_.task_runner()->PostTaskAndReply( | 79 gpu_thread_.task_runner()->PostTaskAndReply( |
78 FROM_HERE, | 80 FROM_HERE, |
79 base::Bind(&GpuServiceMus::EstablishGpuChannelOnGpuThread, | 81 base::Bind(&GpuServiceMus::EstablishGpuChannelOnGpuThread, |
80 base::Unretained(this), client_id, client_tracing_id, preempts, | 82 base::Unretained(this), client_id, client_tracing_id, preempts, |
81 allow_view_command_buffers, allow_real_time_streams, | 83 allow_view_command_buffers, allow_real_time_streams, |
82 base::Unretained(channel_handle.get())), | 84 base::Unretained(channel_handle.get())), |
83 base::Bind(&EstablishGpuChannelDone, base::Passed(&channel_handle), | 85 base::Bind(&EstablishGpuChannelDone, client_id, |
84 callback)); | 86 base::Passed(&channel_handle), callback)); |
85 } | 87 } |
86 | 88 |
87 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBuffer( | 89 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBuffer( |
88 gfx::GpuMemoryBufferId id, | 90 gfx::GpuMemoryBufferId id, |
89 const gfx::Size& size, | 91 const gfx::Size& size, |
90 gfx::BufferFormat format, | 92 gfx::BufferFormat format, |
91 gfx::BufferUsage usage, | 93 gfx::BufferUsage usage, |
92 int client_id, | 94 int client_id, |
93 gpu::SurfaceHandle surface_handle) { | 95 gpu::SurfaceHandle surface_handle) { |
| 96 DCHECK(CalledOnValidThread()); |
94 return gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | 97 return gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( |
95 id, size, format, usage, client_id, surface_handle); | 98 id, size, format, usage, client_id, surface_handle); |
96 } | 99 } |
97 | 100 |
98 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBufferFromeHandle( | 101 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBufferFromeHandle( |
99 gfx::GpuMemoryBufferHandle buffer_handle, | 102 gfx::GpuMemoryBufferHandle buffer_handle, |
100 gfx::GpuMemoryBufferId id, | 103 gfx::GpuMemoryBufferId id, |
101 const gfx::Size& size, | 104 const gfx::Size& size, |
102 gfx::BufferFormat format, | 105 gfx::BufferFormat format, |
103 int client_id) { | 106 int client_id) { |
| 107 DCHECK(CalledOnValidThread()); |
| 108 |
104 return gpu_memory_buffer_factory_->CreateGpuMemoryBufferFromHandle( | 109 return gpu_memory_buffer_factory_->CreateGpuMemoryBufferFromHandle( |
105 buffer_handle, id, size, format, client_id); | 110 buffer_handle, id, size, format, client_id); |
106 } | 111 } |
107 | 112 |
108 void GpuServiceMus::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 113 void GpuServiceMus::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
109 int client_id, | 114 int client_id, |
110 const gpu::SyncToken& sync_token) { | 115 const gpu::SyncToken& sync_token) { |
| 116 DCHECK(CalledOnValidThread()); |
| 117 |
111 if (gpu_channel_manager_) | 118 if (gpu_channel_manager_) |
112 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); | 119 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); |
113 } | 120 } |
114 | 121 |
115 void GpuServiceMus::DidCreateOffscreenContext(const GURL& active_url) { | 122 void GpuServiceMus::DidCreateOffscreenContext(const GURL& active_url) { |
116 NOTIMPLEMENTED(); | 123 NOTIMPLEMENTED(); |
117 } | 124 } |
118 | 125 |
119 void GpuServiceMus::DidDestroyChannel(int client_id) { | 126 void GpuServiceMus::DidDestroyChannel(int client_id) { |
120 media_service_->RemoveChannel(client_id); | 127 media_service_->RemoveChannel(client_id); |
(...skipping 26 matching lines...) Expand all Loading... |
147 gpu::SurfaceHandle child_window) { | 154 gpu::SurfaceHandle child_window) { |
148 NOTIMPLEMENTED(); | 155 NOTIMPLEMENTED(); |
149 } | 156 } |
150 #endif | 157 #endif |
151 | 158 |
152 void GpuServiceMus::SetActiveURL(const GURL& url) { | 159 void GpuServiceMus::SetActiveURL(const GURL& url) { |
153 NOTIMPLEMENTED(); | 160 NOTIMPLEMENTED(); |
154 } | 161 } |
155 | 162 |
156 void GpuServiceMus::Initialize() { | 163 void GpuServiceMus::Initialize() { |
| 164 DCHECK(CalledOnValidThread()); |
157 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0); | 165 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0); |
158 thread_options.priority = base::ThreadPriority::NORMAL; | 166 thread_options.priority = base::ThreadPriority::NORMAL; |
159 CHECK(gpu_thread_.StartWithOptions(thread_options)); | 167 CHECK(gpu_thread_.StartWithOptions(thread_options)); |
160 | 168 |
161 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); | 169 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); |
162 thread_options.priority = base::ThreadPriority::NORMAL; | 170 thread_options.priority = base::ThreadPriority::NORMAL; |
163 #if defined(OS_ANDROID) | 171 #if defined(OS_ANDROID) |
164 // TODO(reveman): Remove this in favor of setting it explicitly for each type | 172 // TODO(reveman): Remove this in favor of setting it explicitly for each type |
165 // of process. | 173 // of process. |
166 thread_options.priority = base::ThreadPriority::DISPLAY; | 174 thread_options.priority = base::ThreadPriority::DISPLAY; |
167 #endif | 175 #endif |
168 CHECK(io_thread_.StartWithOptions(thread_options)); | 176 CHECK(io_thread_.StartWithOptions(thread_options)); |
169 | 177 |
170 IPC::ChannelHandle channel_handle; | 178 IPC::ChannelHandle channel_handle; |
171 bool manual_reset = true; | 179 bool manual_reset = true; |
172 bool initially_signaled = false; | 180 bool initially_signaled = false; |
173 base::WaitableEvent event(manual_reset, initially_signaled); | 181 base::WaitableEvent event(manual_reset, initially_signaled); |
174 gpu_thread_.task_runner()->PostTask( | 182 gpu_thread_.task_runner()->PostTask( |
175 FROM_HERE, base::Bind(&GpuServiceMus::InitializeOnGpuThread, | 183 FROM_HERE, base::Bind(&GpuServiceMus::InitializeOnGpuThread, |
176 base::Unretained(this), &channel_handle, &event)); | 184 base::Unretained(this), &channel_handle, &event)); |
177 event.Wait(); | 185 event.Wait(); |
178 | 186 |
179 gpu_memory_buffer_manager_mus_local_.reset(new GpuMemoryBufferManagerMusLocal( | 187 gpu_memory_buffer_manager_local_.reset(new MojoGpuMemoryBufferManager); |
180 kLocalGpuChannelClientId, kLocalGpuChannelClientTracingId)); | |
181 gpu_channel_local_ = gpu::GpuChannelHost::Create( | 188 gpu_channel_local_ = gpu::GpuChannelHost::Create( |
182 this, kLocalGpuChannelClientId, gpu_info_, channel_handle, | 189 this, kLocalGpuChannelClientId, gpu_info_, channel_handle, |
183 &shutdown_event_, gpu_memory_buffer_manager_mus_local_.get()); | 190 &shutdown_event_, gpu_memory_buffer_manager_local_.get()); |
184 } | 191 } |
185 | 192 |
186 void GpuServiceMus::InitializeOnGpuThread(IPC::ChannelHandle* channel_handle, | 193 void GpuServiceMus::InitializeOnGpuThread(IPC::ChannelHandle* channel_handle, |
187 base::WaitableEvent* event) { | 194 base::WaitableEvent* event) { |
188 gpu_info_.video_decode_accelerator_capabilities = | 195 gpu_info_.video_decode_accelerator_capabilities = |
189 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 196 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
190 gpu_info_.video_encode_accelerator_supported_profiles = | 197 gpu_info_.video_encode_accelerator_supported_profiles = |
191 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | 198 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); |
192 gpu_info_.jpeg_decode_accelerator_supported = | 199 gpu_info_.jpeg_decode_accelerator_supported = |
193 media::GpuJpegDecodeAccelerator::IsSupported(); | 200 media::GpuJpegDecodeAccelerator::IsSupported(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 return shm; | 266 return shm; |
260 } | 267 } |
261 | 268 |
262 // static | 269 // static |
263 GpuServiceMus* GpuServiceMus::GetInstance() { | 270 GpuServiceMus* GpuServiceMus::GetInstance() { |
264 return base::Singleton<GpuServiceMus, | 271 return base::Singleton<GpuServiceMus, |
265 base::LeakySingletonTraits<GpuServiceMus>>::get(); | 272 base::LeakySingletonTraits<GpuServiceMus>>::get(); |
266 } | 273 } |
267 | 274 |
268 } // namespace mus | 275 } // namespace mus |
OLD | NEW |