Chromium Code Reviews| 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" | |
| 8 #include "base/memory/singleton.h" | |
| 9 #include "base/synchronization/waitable_event.h" | |
| 10 #include "base/threading/thread_task_runner_handle.h" | |
| 11 #include "components/mus/gpu/gpu_memory_buffer_manager_mus_local.h" | |
| 12 #include "gpu/command_buffer/service/gpu_switches.h" | |
| 13 #include "gpu/command_buffer/service/sync_point_manager.h" | |
| 14 #include "gpu/config/gpu_info_collector.h" | |
| 15 #include "gpu/config/gpu_switches.h" | |
| 16 #include "gpu/config/gpu_util.h" | |
| 17 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | |
| 18 #include "gpu/ipc/common/memory_stats.h" | |
| 7 #include "gpu/ipc/common/surface_handle.h" | 19 #include "gpu/ipc/common/surface_handle.h" |
| 20 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | |
| 21 #include "ipc/ipc_channel_handle.h" | |
| 22 #include "ipc/ipc_sync_message_filter.h" | |
| 23 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" | |
| 24 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" | |
| 25 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" | |
| 26 #include "media/gpu/ipc/service/media_service.h" | |
| 27 #include "ui/gl/gl_implementation.h" | |
| 28 #include "ui/gl/gl_switches.h" | |
| 29 #include "ui/gl/gpu_switching_manager.h" | |
| 30 #include "url/gurl.h" | |
| 8 | 31 |
| 9 namespace mus { | 32 namespace mus { |
| 33 namespace { | |
| 10 | 34 |
| 11 GpuServiceMus::GpuServiceMus() {} | 35 const int kLocalGpuChannelClientId = 1; |
| 12 | 36 const uint64_t kLocalGpuChannelClientTracingId = 1; |
| 13 GpuServiceMus::~GpuServiceMus() {} | |
| 14 | |
| 15 void GpuServiceMus::EstablishGpuChannel( | |
| 16 bool prempts, | |
| 17 bool allow_view_command_buffers, | |
| 18 bool allow_real_time_streams, | |
| 19 const mojom::GpuService::EstablishGpuChannelCallback& callback) { | |
| 20 NOTIMPLEMENTED(); | |
| 21 } | 37 } |
| 22 | 38 |
| 23 void GpuServiceMus::CreateGpuMemoryBuffer( | 39 GpuServiceMus::GpuServiceMus() |
| 24 mojom::GpuMemoryBufferIdPtr id, | 40 : main_message_loop_(base::MessageLoop::current()), |
| 25 mojo::SizePtr size, | 41 shutdown_event_(true, false), |
| 26 mojom::BufferFormat format, | 42 gpu_thread_("GpuThread"), |
| 27 mojom::BufferUsage usage, | 43 io_thread_("GpuIOThread"), |
| 28 uint64_t surface_id, | 44 io_thread_local_("GpuIOThreadLocal") { |
| 29 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) { | 45 Initialize(); |
| 30 NOTIMPLEMENTED(); | |
| 31 } | 46 } |
| 32 | 47 |
| 33 void GpuServiceMus::CreateGpuMemoryBufferFromHandle( | 48 GpuServiceMus::~GpuServiceMus() { |
| 34 mojom::GpuMemoryBufferHandlePtr buffer_handle, | 49 // Signal this event before destroying the child process. That way all |
| 35 mojom::GpuMemoryBufferIdPtr id, | 50 // background threads can cleanup. |
| 36 mojo::SizePtr size, | 51 // For example, in the renderer the RenderThread instances will be able to |
| 37 mojom::BufferFormat format, | 52 // notice shutdown before the render process begins waiting for them to exit. |
| 38 const mojom::GpuService::CreateGpuMemoryBufferFromHandleCallback& | 53 shutdown_event_.Signal(); |
| 39 callback) { | 54 io_thread_.Stop(); |
| 40 NOTIMPLEMENTED(); | |
| 41 } | 55 } |
| 42 | 56 |
| 43 void GpuServiceMus::DestroyGpuMemoryBuffer(mojom::GpuMemoryBufferIdPtr id, | 57 IPC::ChannelHandle GpuServiceMus::EstablishGpuChannel( |
| 58 int client_id, | |
| 59 uint64_t client_tracing_id, | |
| 60 bool preempts, | |
| 61 bool allow_view_command_buffers, | |
| 62 bool allow_real_time_streams) { | |
| 63 CHECK_GT(client_id, kLocalGpuChannelClientId); | |
|
piman
2016/05/24 22:46:54
nit: DCHECK_GT
Peng
2016/05/25 19:42:55
Done.
| |
| 64 | |
| 65 if (!gpu_channel_manager_) | |
| 66 return IPC::ChannelHandle(); | |
| 67 | |
| 68 IPC::ChannelHandle channel_handle; | |
| 69 bool manual_reset = true; | |
| 70 bool initially_signaled = false; | |
| 71 base::WaitableEvent event(manual_reset, initially_signaled); | |
| 72 gpu_thread_.task_runner()->PostTask( | |
| 73 FROM_HERE, | |
| 74 base::Bind(&GpuServiceMus::EstablishGpuChannelOnGpuThread, | |
| 75 base::Unretained(this), client_id, client_tracing_id, preempts, | |
| 76 allow_view_command_buffers, allow_real_time_streams, | |
| 77 &channel_handle, &event)); | |
| 78 event.Wait(); | |
| 79 return channel_handle; | |
| 80 } | |
| 81 | |
| 82 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBuffer( | |
| 83 gfx::GpuMemoryBufferId id, | |
| 84 const gfx::Size& size, | |
| 85 gfx::BufferFormat format, | |
| 86 gfx::BufferUsage usage, | |
| 87 int client_id, | |
| 88 int32_t surface_handle) { | |
| 89 return gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | |
| 90 id, size, format, usage, client_id, | |
| 91 static_cast<gpu::SurfaceHandle>(surface_handle)); | |
| 92 } | |
| 93 | |
| 94 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBufferFromeHandle( | |
| 95 gfx::GpuMemoryBufferHandle buffer_handle, | |
| 96 gfx::GpuMemoryBufferId id, | |
| 97 const gfx::Size& size, | |
| 98 gfx::BufferFormat format, | |
| 99 int client_id) { | |
| 100 return gpu_memory_buffer_factory_->CreateGpuMemoryBufferFromHandle( | |
| 101 buffer_handle, id, size, format, client_id); | |
| 102 } | |
| 103 | |
| 104 void GpuServiceMus::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | |
| 105 int client_id, | |
| 44 const gpu::SyncToken& sync_token) { | 106 const gpu::SyncToken& sync_token) { |
| 45 NOTIMPLEMENTED(); | 107 if (gpu_channel_manager_) |
| 108 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); | |
| 46 } | 109 } |
| 47 | 110 |
| 48 void GpuServiceMus::DidCreateOffscreenContext(const GURL& active_url) { | 111 void GpuServiceMus::DidCreateOffscreenContext(const GURL& active_url) { |
| 49 NOTIMPLEMENTED(); | 112 NOTIMPLEMENTED(); |
| 50 } | 113 } |
| 51 | 114 |
| 52 void GpuServiceMus::DidDestroyChannel(int client_id) { | 115 void GpuServiceMus::DidDestroyChannel(int client_id) { |
| 116 media_service_->RemoveChannel(client_id); | |
| 53 NOTIMPLEMENTED(); | 117 NOTIMPLEMENTED(); |
| 54 } | 118 } |
| 55 | 119 |
| 56 void GpuServiceMus::DidDestroyOffscreenContext(const GURL& active_url) { | 120 void GpuServiceMus::DidDestroyOffscreenContext(const GURL& active_url) { |
| 57 NOTIMPLEMENTED(); | 121 NOTIMPLEMENTED(); |
| 58 } | 122 } |
| 59 | 123 |
| 60 void GpuServiceMus::DidLoseContext(bool offscreen, | 124 void GpuServiceMus::DidLoseContext(bool offscreen, |
| 61 gpu::error::ContextLostReason reason, | 125 gpu::error::ContextLostReason reason, |
| 62 const GURL& active_url) { | 126 const GURL& active_url) { |
| 63 NOTIMPLEMENTED(); | 127 NOTIMPLEMENTED(); |
| 64 } | 128 } |
| 65 | 129 |
| 66 void GpuServiceMus::GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) { | 130 void GpuServiceMus::GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) { |
| 67 NOTIMPLEMENTED(); | 131 NOTIMPLEMENTED(); |
| 68 } | 132 } |
| 69 | 133 |
| 70 void GpuServiceMus::StoreShaderToDisk(int32_t client_id, | 134 void GpuServiceMus::StoreShaderToDisk(int client_id, |
| 71 const std::string& key, | 135 const std::string& key, |
| 72 const std::string& shader) { | 136 const std::string& shader) { |
| 73 NOTIMPLEMENTED(); | 137 NOTIMPLEMENTED(); |
| 74 } | 138 } |
| 75 | 139 |
| 76 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
| 77 void GpuServiceMus::SendAcceleratedSurfaceCreatedChildWindow( | 141 void GpuServiceMus::SendAcceleratedSurfaceCreatedChildWindow( |
| 78 gpu::SurfaceHandle parent_window, | 142 gpu::SurfaceHandle parent_window, |
| 79 gpu::SurfaceHandle child_window) { | 143 gpu::SurfaceHandle child_window) { |
| 80 NOTIMPLEMENTED(); | 144 NOTIMPLEMENTED(); |
| 81 } | 145 } |
| 82 #endif | 146 #endif |
| 83 | 147 |
| 84 void GpuServiceMus::SetActiveURL(const GURL& url) { | 148 void GpuServiceMus::SetActiveURL(const GURL& url) { |
| 85 NOTIMPLEMENTED(); | 149 NOTIMPLEMENTED(); |
| 86 } | 150 } |
| 87 | 151 |
| 152 void GpuServiceMus::Initialize() { | |
| 153 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0); | |
| 154 thread_options.priority = base::ThreadPriority::NORMAL; | |
| 155 CHECK(gpu_thread_.StartWithOptions(thread_options)); | |
| 156 | |
| 157 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); | |
| 158 thread_options.priority = base::ThreadPriority::NORMAL; | |
| 159 #if defined(OS_ANDROID) | |
| 160 // TODO(reveman): Remove this in favor of setting it explicitly for each type | |
| 161 // of process. | |
| 162 thread_options.priority = base::ThreadPriority::DISPLAY; | |
| 163 #endif | |
| 164 CHECK(io_thread_.StartWithOptions(thread_options)); | |
| 165 CHECK(io_thread_local_.StartWithOptions(thread_options)); | |
| 166 | |
| 167 IPC::ChannelHandle channel_handle; | |
| 168 bool manual_reset = true; | |
| 169 bool initially_signaled = false; | |
| 170 base::WaitableEvent event(manual_reset, initially_signaled); | |
| 171 gpu_thread_.task_runner()->PostTask( | |
| 172 FROM_HERE, base::Bind(&GpuServiceMus::InitializeOnGpuThread, | |
| 173 base::Unretained(this), &channel_handle, &event)); | |
| 174 event.Wait(); | |
| 175 | |
| 176 gpu_memory_buffer_manager_mus_local_.reset(new GpuMemoryBufferManagerMusLocal( | |
| 177 kLocalGpuChannelClientId, kLocalGpuChannelClientTracingId)); | |
| 178 gpu_channel_local_ = gpu::GpuChannelHost::Create( | |
| 179 this, kLocalGpuChannelClientId, gpu_info_, channel_handle, | |
| 180 &shutdown_event_, gpu_memory_buffer_manager_mus_local_.get()); | |
| 181 } | |
| 182 | |
| 183 void GpuServiceMus::InitializeOnGpuThread(IPC::ChannelHandle* channel_handle, | |
| 184 base::WaitableEvent* event) { | |
| 185 gpu_info_.video_decode_accelerator_capabilities = | |
| 186 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | |
| 187 gpu_info_.video_encode_accelerator_supported_profiles = | |
| 188 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | |
| 189 gpu_info_.jpeg_decode_accelerator_supported = | |
| 190 media::GpuJpegDecodeAccelerator::IsSupported(); | |
| 191 | |
| 192 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) { | |
| 193 gpu_memory_buffer_factory_ = | |
| 194 gpu::GpuMemoryBufferFactory::CreateNativeType(); | |
| 195 } | |
| 196 | |
| 197 if (!gfx::GLSurface::InitializeOneOff()) | |
| 198 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; | |
| 199 | |
| 200 DCHECK(!owned_sync_point_manager_); | |
| 201 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); | |
|
Fady Samuel
2016/05/25 17:06:47
What's this false?
Peng
2016/05/25 19:42:55
Done.
| |
| 202 | |
| 203 // Defer creation of the render thread. This is to prevent it from handling | |
| 204 // IPC messages before the sandbox has been enabled and all other necessary | |
| 205 // initialization has succeeded. | |
| 206 gpu::GpuWatchdog* watchdog = nullptr; | |
|
Fady Samuel
2016/05/25 17:06:47
Add a TODO here please to implement a watchdog thr
Peng
2016/05/25 19:42:55
Done.
| |
| 207 gpu_channel_manager_.reset(new gpu::GpuChannelManager( | |
| 208 gpu_preferences_, this, watchdog, | |
| 209 base::ThreadTaskRunnerHandle::Get().get(), io_thread_.task_runner().get(), | |
| 210 &shutdown_event_, owned_sync_point_manager_.get(), | |
| 211 gpu_memory_buffer_factory_.get())); | |
| 212 | |
| 213 media_service_.reset(new media::MediaService(gpu_channel_manager_.get())); | |
| 214 | |
| 215 #if defined(USE_OZONE) | |
| 216 ui::OzonePlatform::GetInstance() | |
| 217 ->GetGpuPlatformSupport() | |
| 218 ->OnChannelEstablished(this); | |
| 219 #endif | |
| 220 const bool preempts = true; | |
| 221 const bool allow_view_command_buffers = true; | |
| 222 const bool allow_real_time_streams = true; | |
| 223 EstablishGpuChannelOnGpuThread( | |
| 224 kLocalGpuChannelClientId, kLocalGpuChannelClientTracingId, preempts, | |
| 225 allow_view_command_buffers, allow_real_time_streams, channel_handle, | |
| 226 event); | |
| 227 } | |
| 228 | |
| 229 void GpuServiceMus::EstablishGpuChannelOnGpuThread( | |
| 230 int client_id, | |
| 231 uint64_t client_tracing_id, | |
| 232 bool preempts, | |
| 233 bool allow_view_command_buffers, | |
| 234 bool allow_real_time_streams, | |
| 235 IPC::ChannelHandle* channel_handle, | |
| 236 base::WaitableEvent* event) { | |
| 237 if (gpu_channel_manager_) { | |
| 238 *channel_handle = gpu_channel_manager_->EstablishChannel( | |
| 239 client_id, client_tracing_id, preempts, allow_view_command_buffers, | |
| 240 allow_real_time_streams); | |
| 241 media_service_->AddChannel(client_id); | |
| 242 } | |
| 243 event->Signal(); | |
| 244 } | |
| 245 | |
| 246 bool GpuServiceMus::IsMainThread() { | |
| 247 return main_message_loop_ == base::MessageLoop::current(); | |
| 248 } | |
| 249 | |
| 250 scoped_refptr<base::SingleThreadTaskRunner> | |
| 251 GpuServiceMus::GetIOThreadTaskRunner() { | |
| 252 return io_thread_local_.task_runner(); | |
| 253 } | |
| 254 | |
| 255 std::unique_ptr<base::SharedMemory> GpuServiceMus::AllocateSharedMemory( | |
| 256 size_t size) { | |
| 257 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | |
| 258 if (!shm->CreateAnonymous(size)) | |
| 259 return std::unique_ptr<base::SharedMemory>(); | |
| 260 return shm; | |
| 261 } | |
| 262 | |
| 263 // static | |
| 264 GpuServiceMus* GpuServiceMus::GetInstance() { | |
| 265 return base::Singleton<GpuServiceMus>::get(); | |
| 266 } | |
| 267 | |
| 88 } // namespace mus | 268 } // namespace mus |
| OLD | NEW |