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_mus.h" | 5 #include "services/ui/gpu/gpu_service_internal.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 "build/build_config.h" | 11 #include "build/build_config.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" |
(...skipping 20 matching lines...) Expand all Loading... |
36 | 36 |
37 namespace ui { | 37 namespace ui { |
38 namespace { | 38 namespace { |
39 | 39 |
40 const int kLocalGpuChannelClientId = 1; | 40 const int kLocalGpuChannelClientId = 1; |
41 const uint64_t kLocalGpuChannelClientTracingId = 1; | 41 const uint64_t kLocalGpuChannelClientTracingId = 1; |
42 | 42 |
43 void EstablishGpuChannelDone( | 43 void EstablishGpuChannelDone( |
44 int client_id, | 44 int client_id, |
45 mojo::ScopedMessagePipeHandle* channel_handle, | 45 mojo::ScopedMessagePipeHandle* channel_handle, |
46 const GpuServiceMus::EstablishGpuChannelCallback& callback) { | 46 const GpuServiceInternal::EstablishGpuChannelCallback& callback) { |
47 callback.Run(client_id, std::move(*channel_handle)); | 47 callback.Run(client_id, std::move(*channel_handle)); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 GpuServiceMus::GpuServiceMus() | 51 GpuServiceInternal::GpuServiceInternal() |
52 : next_client_id_(kLocalGpuChannelClientId), | 52 : next_client_id_(kLocalGpuChannelClientId), |
53 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 53 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
54 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 54 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
55 base::WaitableEvent::InitialState::NOT_SIGNALED), | 55 base::WaitableEvent::InitialState::NOT_SIGNALED), |
56 gpu_thread_("GpuThread"), | 56 gpu_thread_("GpuThread"), |
57 io_thread_("GpuIOThread") { | 57 io_thread_("GpuIOThread") { |
58 Initialize(); | 58 Initialize(); |
59 } | 59 } |
60 | 60 |
61 GpuServiceMus::~GpuServiceMus() { | 61 GpuServiceInternal::~GpuServiceInternal() { |
62 // Signal this event before destroying the child process. That way all | 62 // Signal this event before destroying the child process. That way all |
63 // background threads can cleanup. | 63 // background threads can cleanup. |
64 // For example, in the renderer the RenderThread instances will be able to | 64 // For example, in the renderer the RenderThread instances will be able to |
65 // notice shutdown before the render process begins waiting for them to exit. | 65 // notice shutdown before the render process begins waiting for them to exit. |
66 shutdown_event_.Signal(); | 66 shutdown_event_.Signal(); |
67 io_thread_.Stop(); | 67 io_thread_.Stop(); |
68 } | 68 } |
69 | 69 |
70 void GpuServiceMus::EstablishGpuChannel( | 70 void GpuServiceInternal::EstablishGpuChannel( |
71 uint64_t client_tracing_id, | 71 uint64_t client_tracing_id, |
72 bool preempts, | 72 bool preempts, |
73 bool allow_view_command_buffers, | 73 bool allow_view_command_buffers, |
74 bool allow_real_time_streams, | 74 bool allow_real_time_streams, |
75 const EstablishGpuChannelCallback& callback) { | 75 const EstablishGpuChannelCallback& callback) { |
76 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
77 | 77 |
78 if (!gpu_channel_manager_) { | 78 if (!gpu_channel_manager_) { |
79 callback.Run(-1, mojo::ScopedMessagePipeHandle()); | 79 callback.Run(-1, mojo::ScopedMessagePipeHandle()); |
80 return; | 80 return; |
81 } | 81 } |
82 | 82 |
83 const int client_id = ++next_client_id_; | 83 const int client_id = ++next_client_id_; |
84 auto* channel_handle = new mojo::ScopedMessagePipeHandle; | 84 auto* channel_handle = new mojo::ScopedMessagePipeHandle; |
85 gpu_thread_.task_runner()->PostTaskAndReply( | 85 gpu_thread_.task_runner()->PostTaskAndReply( |
86 FROM_HERE, | 86 FROM_HERE, |
87 base::Bind(&GpuServiceMus::EstablishGpuChannelOnGpuThread, | 87 base::Bind(&GpuServiceInternal::EstablishGpuChannelOnGpuThread, |
88 base::Unretained(this), client_id, client_tracing_id, preempts, | 88 base::Unretained(this), client_id, client_tracing_id, preempts, |
89 allow_view_command_buffers, allow_real_time_streams, | 89 allow_view_command_buffers, allow_real_time_streams, |
90 base::Unretained(channel_handle)), | 90 base::Unretained(channel_handle)), |
91 base::Bind(&EstablishGpuChannelDone, client_id, | 91 base::Bind(&EstablishGpuChannelDone, client_id, |
92 base::Owned(channel_handle), callback)); | 92 base::Owned(channel_handle), callback)); |
93 } | 93 } |
94 | 94 |
95 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBuffer( | 95 gfx::GpuMemoryBufferHandle GpuServiceInternal::CreateGpuMemoryBuffer( |
96 gfx::GpuMemoryBufferId id, | 96 gfx::GpuMemoryBufferId id, |
97 const gfx::Size& size, | 97 const gfx::Size& size, |
98 gfx::BufferFormat format, | 98 gfx::BufferFormat format, |
99 gfx::BufferUsage usage, | 99 gfx::BufferUsage usage, |
100 int client_id, | 100 int client_id, |
101 gpu::SurfaceHandle surface_handle) { | 101 gpu::SurfaceHandle surface_handle) { |
102 DCHECK(CalledOnValidThread()); | 102 DCHECK(CalledOnValidThread()); |
103 return gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | 103 return gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( |
104 id, size, format, usage, client_id, surface_handle); | 104 id, size, format, usage, client_id, surface_handle); |
105 } | 105 } |
106 | 106 |
107 void GpuServiceMus::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 107 void GpuServiceInternal::DestroyGpuMemoryBuffer( |
108 int client_id, | 108 gfx::GpuMemoryBufferId id, |
109 const gpu::SyncToken& sync_token) { | 109 int client_id, |
| 110 const gpu::SyncToken& sync_token) { |
110 DCHECK(CalledOnValidThread()); | 111 DCHECK(CalledOnValidThread()); |
111 | 112 |
112 if (gpu_channel_manager_) | 113 if (gpu_channel_manager_) |
113 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); | 114 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); |
114 } | 115 } |
115 | 116 |
116 void GpuServiceMus::DidCreateOffscreenContext(const GURL& active_url) { | 117 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) { |
117 NOTIMPLEMENTED(); | 118 NOTIMPLEMENTED(); |
118 } | 119 } |
119 | 120 |
120 void GpuServiceMus::DidDestroyChannel(int client_id) { | 121 void GpuServiceInternal::DidDestroyChannel(int client_id) { |
121 media_service_->RemoveChannel(client_id); | 122 media_service_->RemoveChannel(client_id); |
122 NOTIMPLEMENTED(); | 123 NOTIMPLEMENTED(); |
123 } | 124 } |
124 | 125 |
125 void GpuServiceMus::DidDestroyOffscreenContext(const GURL& active_url) { | 126 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { |
126 NOTIMPLEMENTED(); | 127 NOTIMPLEMENTED(); |
127 } | 128 } |
128 | 129 |
129 void GpuServiceMus::DidLoseContext(bool offscreen, | 130 void GpuServiceInternal::DidLoseContext(bool offscreen, |
130 gpu::error::ContextLostReason reason, | 131 gpu::error::ContextLostReason reason, |
131 const GURL& active_url) { | 132 const GURL& active_url) { |
132 NOTIMPLEMENTED(); | 133 NOTIMPLEMENTED(); |
133 } | 134 } |
134 | 135 |
135 void GpuServiceMus::GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) { | 136 void GpuServiceInternal::GpuMemoryUmaStats( |
| 137 const gpu::GPUMemoryUmaStats& params) { |
136 NOTIMPLEMENTED(); | 138 NOTIMPLEMENTED(); |
137 } | 139 } |
138 | 140 |
139 void GpuServiceMus::StoreShaderToDisk(int client_id, | 141 void GpuServiceInternal::StoreShaderToDisk(int client_id, |
140 const std::string& key, | 142 const std::string& key, |
141 const std::string& shader) { | 143 const std::string& shader) { |
142 NOTIMPLEMENTED(); | 144 NOTIMPLEMENTED(); |
143 } | 145 } |
144 | 146 |
145 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
146 void GpuServiceMus::SendAcceleratedSurfaceCreatedChildWindow( | 148 void GpuServiceInternal::SendAcceleratedSurfaceCreatedChildWindow( |
147 gpu::SurfaceHandle parent_window, | 149 gpu::SurfaceHandle parent_window, |
148 gpu::SurfaceHandle child_window) { | 150 gpu::SurfaceHandle child_window) { |
149 ::SetParent(child_window, parent_window); | 151 ::SetParent(child_window, parent_window); |
150 } | 152 } |
151 #endif | 153 #endif |
152 | 154 |
153 void GpuServiceMus::SetActiveURL(const GURL& url) { | 155 void GpuServiceInternal::SetActiveURL(const GURL& url) { |
154 // TODO(penghuang): implement this function. | 156 // TODO(penghuang): implement this function. |
155 } | 157 } |
156 | 158 |
157 void GpuServiceMus::Initialize() { | 159 void GpuServiceInternal::Initialize() { |
158 DCHECK(CalledOnValidThread()); | 160 DCHECK(CalledOnValidThread()); |
159 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0); | 161 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0); |
160 thread_options.priority = base::ThreadPriority::NORMAL; | 162 thread_options.priority = base::ThreadPriority::NORMAL; |
161 CHECK(gpu_thread_.StartWithOptions(thread_options)); | 163 CHECK(gpu_thread_.StartWithOptions(thread_options)); |
162 | 164 |
163 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); | 165 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); |
164 thread_options.priority = base::ThreadPriority::NORMAL; | 166 thread_options.priority = base::ThreadPriority::NORMAL; |
165 #if defined(OS_ANDROID) | 167 #if defined(OS_ANDROID) |
166 // TODO(reveman): Remove this in favor of setting it explicitly for each type | 168 // TODO(reveman): Remove this in favor of setting it explicitly for each type |
167 // of process. | 169 // of process. |
168 thread_options.priority = base::ThreadPriority::DISPLAY; | 170 thread_options.priority = base::ThreadPriority::DISPLAY; |
169 #endif | 171 #endif |
170 CHECK(io_thread_.StartWithOptions(thread_options)); | 172 CHECK(io_thread_.StartWithOptions(thread_options)); |
171 | 173 |
172 mojo::ScopedMessagePipeHandle channel_handle; | 174 mojo::ScopedMessagePipeHandle channel_handle; |
173 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, | 175 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
174 base::WaitableEvent::InitialState::NOT_SIGNALED); | 176 base::WaitableEvent::InitialState::NOT_SIGNALED); |
175 gpu_thread_.task_runner()->PostTask( | 177 gpu_thread_.task_runner()->PostTask( |
176 FROM_HERE, base::Bind(&GpuServiceMus::InitializeOnGpuThread, | 178 FROM_HERE, base::Bind(&GpuServiceInternal::InitializeOnGpuThread, |
177 base::Unretained(this), &channel_handle, &event)); | 179 base::Unretained(this), &channel_handle, &event)); |
178 event.Wait(); | 180 event.Wait(); |
179 | 181 |
180 gpu_memory_buffer_manager_local_.reset( | 182 gpu_memory_buffer_manager_local_.reset( |
181 new MusGpuMemoryBufferManager(this, kLocalGpuChannelClientId)); | 183 new MusGpuMemoryBufferManager(this, kLocalGpuChannelClientId)); |
182 gpu_channel_local_ = gpu::GpuChannelHost::Create( | 184 gpu_channel_local_ = gpu::GpuChannelHost::Create( |
183 this, kLocalGpuChannelClientId, gpu_info_, | 185 this, kLocalGpuChannelClientId, gpu_info_, |
184 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, | 186 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, |
185 gpu_memory_buffer_manager_local_.get()); | 187 gpu_memory_buffer_manager_local_.get()); |
186 } | 188 } |
187 | 189 |
188 void GpuServiceMus::InitializeOnGpuThread( | 190 void GpuServiceInternal::InitializeOnGpuThread( |
189 mojo::ScopedMessagePipeHandle* channel_handle, | 191 mojo::ScopedMessagePipeHandle* channel_handle, |
190 base::WaitableEvent* event) { | 192 base::WaitableEvent* event) { |
191 gpu_info_.video_decode_accelerator_capabilities = | 193 gpu_info_.video_decode_accelerator_capabilities = |
192 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 194 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
193 gpu_info_.video_encode_accelerator_supported_profiles = | 195 gpu_info_.video_encode_accelerator_supported_profiles = |
194 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | 196 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); |
195 gpu_info_.jpeg_decode_accelerator_supported = | 197 gpu_info_.jpeg_decode_accelerator_supported = |
196 media::GpuJpegDecodeAccelerator::IsSupported(); | 198 media::GpuJpegDecodeAccelerator::IsSupported(); |
197 | 199 |
198 #if defined(USE_OZONE) | 200 #if defined(USE_OZONE) |
(...skipping 30 matching lines...) Expand all Loading... |
229 | 231 |
230 const bool preempts = true; | 232 const bool preempts = true; |
231 const bool allow_view_command_buffers = true; | 233 const bool allow_view_command_buffers = true; |
232 const bool allow_real_time_streams = true; | 234 const bool allow_real_time_streams = true; |
233 EstablishGpuChannelOnGpuThread( | 235 EstablishGpuChannelOnGpuThread( |
234 kLocalGpuChannelClientId, kLocalGpuChannelClientTracingId, preempts, | 236 kLocalGpuChannelClientId, kLocalGpuChannelClientTracingId, preempts, |
235 allow_view_command_buffers, allow_real_time_streams, channel_handle); | 237 allow_view_command_buffers, allow_real_time_streams, channel_handle); |
236 event->Signal(); | 238 event->Signal(); |
237 } | 239 } |
238 | 240 |
239 void GpuServiceMus::EstablishGpuChannelOnGpuThread( | 241 void GpuServiceInternal::EstablishGpuChannelOnGpuThread( |
240 int client_id, | 242 int client_id, |
241 uint64_t client_tracing_id, | 243 uint64_t client_tracing_id, |
242 bool preempts, | 244 bool preempts, |
243 bool allow_view_command_buffers, | 245 bool allow_view_command_buffers, |
244 bool allow_real_time_streams, | 246 bool allow_real_time_streams, |
245 mojo::ScopedMessagePipeHandle* channel_handle) { | 247 mojo::ScopedMessagePipeHandle* channel_handle) { |
246 if (gpu_channel_manager_) { | 248 if (gpu_channel_manager_) { |
247 auto handle = gpu_channel_manager_->EstablishChannel( | 249 auto handle = gpu_channel_manager_->EstablishChannel( |
248 client_id, client_tracing_id, preempts, allow_view_command_buffers, | 250 client_id, client_tracing_id, preempts, allow_view_command_buffers, |
249 allow_real_time_streams); | 251 allow_real_time_streams); |
250 channel_handle->reset(handle.mojo_handle); | 252 channel_handle->reset(handle.mojo_handle); |
251 media_service_->AddChannel(client_id); | 253 media_service_->AddChannel(client_id); |
252 } | 254 } |
253 } | 255 } |
254 | 256 |
255 bool GpuServiceMus::IsMainThread() { | 257 bool GpuServiceInternal::IsMainThread() { |
256 return main_task_runner_->BelongsToCurrentThread(); | 258 return main_task_runner_->BelongsToCurrentThread(); |
257 } | 259 } |
258 | 260 |
259 scoped_refptr<base::SingleThreadTaskRunner> | 261 scoped_refptr<base::SingleThreadTaskRunner> |
260 GpuServiceMus::GetIOThreadTaskRunner() { | 262 GpuServiceInternal::GetIOThreadTaskRunner() { |
261 return io_thread_.task_runner(); | 263 return io_thread_.task_runner(); |
262 } | 264 } |
263 | 265 |
264 std::unique_ptr<base::SharedMemory> GpuServiceMus::AllocateSharedMemory( | 266 std::unique_ptr<base::SharedMemory> GpuServiceInternal::AllocateSharedMemory( |
265 size_t size) { | 267 size_t size) { |
266 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 268 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
267 if (!shm->CreateAnonymous(size)) | 269 if (!shm->CreateAnonymous(size)) |
268 return std::unique_ptr<base::SharedMemory>(); | 270 return std::unique_ptr<base::SharedMemory>(); |
269 return shm; | 271 return shm; |
270 } | 272 } |
271 | 273 |
272 // static | 274 // static |
273 GpuServiceMus* GpuServiceMus::GetInstance() { | 275 GpuServiceInternal* GpuServiceInternal::GetInstance() { |
274 return base::Singleton<GpuServiceMus, | 276 return base::Singleton<GpuServiceInternal, |
275 base::LeakySingletonTraits<GpuServiceMus>>::get(); | 277 base::LeakySingletonTraits<GpuServiceInternal>>::get(); |
276 } | 278 } |
277 | 279 |
278 } // namespace ui | 280 } // namespace ui |
OLD | NEW |