| 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.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/client/gpu_memory_buffer_manager.h" |
| 13 #include "gpu/command_buffer/service/gpu_switches.h" | 13 #include "gpu/command_buffer/service/gpu_switches.h" |
| 14 #include "gpu/command_buffer/service/sync_point_manager.h" | 14 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 15 #include "gpu/config/gpu_info_collector.h" | 15 #include "gpu/config/gpu_info_collector.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 29 #include "media/gpu/ipc/service/media_gpu_channel_manager.h" | 29 #include "media/gpu/ipc/service/media_gpu_channel_manager.h" |
| 30 #include "mojo/public/cpp/bindings/strong_binding.h" | 30 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 31 #include "ui/gl/gl_implementation.h" | 31 #include "ui/gl/gl_implementation.h" |
| 32 #include "ui/gl/gl_switches.h" | 32 #include "ui/gl/gl_switches.h" |
| 33 #include "ui/gl/gpu_switching_manager.h" | 33 #include "ui/gl/gpu_switching_manager.h" |
| 34 #include "ui/gl/init/gl_factory.h" | 34 #include "ui/gl/init/gl_factory.h" |
| 35 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 36 | 36 |
| 37 namespace ui { | 37 namespace ui { |
| 38 | 38 |
| 39 GpuServiceInternal::GpuServiceInternal( | 39 GpuService::GpuService(const gpu::GPUInfo& gpu_info, |
| 40 const gpu::GPUInfo& gpu_info, | 40 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, |
| 41 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, | 41 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| 42 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 42 scoped_refptr<base::SingleThreadTaskRunner> io_runner) |
| 43 scoped_refptr<base::SingleThreadTaskRunner> io_runner) | |
| 44 : io_runner_(std::move(io_runner)), | 43 : io_runner_(std::move(io_runner)), |
| 45 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 44 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 46 base::WaitableEvent::InitialState::NOT_SIGNALED), | 45 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 47 watchdog_thread_(std::move(watchdog_thread)), | 46 watchdog_thread_(std::move(watchdog_thread)), |
| 48 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 47 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
| 49 gpu_info_(gpu_info) {} | 48 gpu_info_(gpu_info) {} |
| 50 | 49 |
| 51 GpuServiceInternal::~GpuServiceInternal() { | 50 GpuService::~GpuService() { |
| 52 bindings_.CloseAllBindings(); | 51 bindings_.CloseAllBindings(); |
| 53 media_gpu_channel_manager_.reset(); | 52 media_gpu_channel_manager_.reset(); |
| 54 gpu_channel_manager_.reset(); | 53 gpu_channel_manager_.reset(); |
| 55 owned_sync_point_manager_.reset(); | 54 owned_sync_point_manager_.reset(); |
| 56 | 55 |
| 57 // Signal this event before destroying the child process. That way all | 56 // Signal this event before destroying the child process. That way all |
| 58 // background threads can cleanup. | 57 // background threads can cleanup. |
| 59 // 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 |
| 60 // 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. |
| 61 shutdown_event_.Signal(); | 60 shutdown_event_.Signal(); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void GpuServiceInternal::InitializeWithHost(mojom::GpuServiceHostPtr gpu_host) { | 63 void GpuService::InitializeWithHost(mojom::GpuHostPtr gpu_host) { |
| 65 DCHECK(CalledOnValidThread()); | 64 DCHECK(CalledOnValidThread()); |
| 66 DCHECK(!gpu_host_); | 65 DCHECK(!gpu_host_); |
| 67 gpu_host_ = std::move(gpu_host); | 66 gpu_host_ = std::move(gpu_host); |
| 68 gpu_info_.video_decode_accelerator_capabilities = | 67 gpu_info_.video_decode_accelerator_capabilities = |
| 69 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); | 68 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); |
| 70 gpu_info_.video_encode_accelerator_supported_profiles = | 69 gpu_info_.video_encode_accelerator_supported_profiles = |
| 71 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); | 70 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); |
| 72 gpu_info_.jpeg_decode_accelerator_supported = | 71 gpu_info_.jpeg_decode_accelerator_supported = |
| 73 media::GpuJpegDecodeAccelerator::IsSupported(); | 72 media::GpuJpegDecodeAccelerator::IsSupported(); |
| 74 gpu_host_->DidInitialize(gpu_info_); | 73 gpu_host_->DidInitialize(gpu_info_); |
| 75 | 74 |
| 76 DCHECK(!owned_sync_point_manager_); | 75 DCHECK(!owned_sync_point_manager_); |
| 77 const bool allow_threaded_wait = false; | 76 const bool allow_threaded_wait = false; |
| 78 owned_sync_point_manager_.reset( | 77 owned_sync_point_manager_.reset( |
| 79 new gpu::SyncPointManager(allow_threaded_wait)); | 78 new gpu::SyncPointManager(allow_threaded_wait)); |
| 80 | 79 |
| 81 // Defer creation of the render thread. This is to prevent it from handling | 80 // Defer creation of the render thread. This is to prevent it from handling |
| 82 // IPC messages before the sandbox has been enabled and all other necessary | 81 // IPC messages before the sandbox has been enabled and all other necessary |
| 83 // initialization has succeeded. | 82 // initialization has succeeded. |
| 84 gpu_channel_manager_.reset(new gpu::GpuChannelManager( | 83 gpu_channel_manager_.reset(new gpu::GpuChannelManager( |
| 85 gpu_preferences_, this, watchdog_thread_.get(), | 84 gpu_preferences_, this, watchdog_thread_.get(), |
| 86 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), | 85 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), |
| 87 &shutdown_event_, owned_sync_point_manager_.get(), | 86 &shutdown_event_, owned_sync_point_manager_.get(), |
| 88 gpu_memory_buffer_factory_)); | 87 gpu_memory_buffer_factory_)); |
| 89 | 88 |
| 90 media_gpu_channel_manager_.reset( | 89 media_gpu_channel_manager_.reset( |
| 91 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); | 90 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); |
| 92 } | 91 } |
| 93 | 92 |
| 94 void GpuServiceInternal::Bind(mojom::GpuServiceInternalRequest request) { | 93 void GpuService::Bind(mojom::GpuServiceRequest request) { |
| 95 bindings_.AddBinding(this, std::move(request)); | 94 bindings_.AddBinding(this, std::move(request)); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void GpuServiceInternal::CreateGpuMemoryBuffer( | 97 void GpuService::CreateGpuMemoryBuffer( |
| 99 gfx::GpuMemoryBufferId id, | 98 gfx::GpuMemoryBufferId id, |
| 100 const gfx::Size& size, | 99 const gfx::Size& size, |
| 101 gfx::BufferFormat format, | 100 gfx::BufferFormat format, |
| 102 gfx::BufferUsage usage, | 101 gfx::BufferUsage usage, |
| 103 int client_id, | 102 int client_id, |
| 104 gpu::SurfaceHandle surface_handle, | 103 gpu::SurfaceHandle surface_handle, |
| 105 const CreateGpuMemoryBufferCallback& callback) { | 104 const CreateGpuMemoryBufferCallback& callback) { |
| 106 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
| 107 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | 106 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( |
| 108 id, size, format, usage, client_id, surface_handle)); | 107 id, size, format, usage, client_id, surface_handle)); |
| 109 } | 108 } |
| 110 | 109 |
| 111 void GpuServiceInternal::DestroyGpuMemoryBuffer( | 110 void GpuService::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 112 gfx::GpuMemoryBufferId id, | 111 int client_id, |
| 113 int client_id, | 112 const gpu::SyncToken& sync_token) { |
| 114 const gpu::SyncToken& sync_token) { | |
| 115 DCHECK(CalledOnValidThread()); | 113 DCHECK(CalledOnValidThread()); |
| 116 if (gpu_channel_manager_) | 114 if (gpu_channel_manager_) |
| 117 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); | 115 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); |
| 118 } | 116 } |
| 119 | 117 |
| 120 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) { | 118 void GpuService::DidCreateOffscreenContext(const GURL& active_url) { |
| 121 gpu_host_->DidCreateOffscreenContext(active_url); | 119 gpu_host_->DidCreateOffscreenContext(active_url); |
| 122 } | 120 } |
| 123 | 121 |
| 124 void GpuServiceInternal::DidDestroyChannel(int client_id) { | 122 void GpuService::DidDestroyChannel(int client_id) { |
| 125 media_gpu_channel_manager_->RemoveChannel(client_id); | 123 media_gpu_channel_manager_->RemoveChannel(client_id); |
| 126 gpu_host_->DidDestroyChannel(client_id); | 124 gpu_host_->DidDestroyChannel(client_id); |
| 127 } | 125 } |
| 128 | 126 |
| 129 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { | 127 void GpuService::DidDestroyOffscreenContext(const GURL& active_url) { |
| 130 gpu_host_->DidDestroyOffscreenContext(active_url); | 128 gpu_host_->DidDestroyOffscreenContext(active_url); |
| 131 } | 129 } |
| 132 | 130 |
| 133 void GpuServiceInternal::DidLoseContext(bool offscreen, | 131 void GpuService::DidLoseContext(bool offscreen, |
| 134 gpu::error::ContextLostReason reason, | 132 gpu::error::ContextLostReason reason, |
| 135 const GURL& active_url) { | 133 const GURL& active_url) { |
| 136 gpu_host_->DidLoseContext(offscreen, reason, active_url); | 134 gpu_host_->DidLoseContext(offscreen, reason, active_url); |
| 137 } | 135 } |
| 138 | 136 |
| 139 void GpuServiceInternal::StoreShaderToDisk(int client_id, | 137 void GpuService::StoreShaderToDisk(int client_id, |
| 140 const std::string& key, | 138 const std::string& key, |
| 141 const std::string& shader) { | 139 const std::string& shader) { |
| 142 gpu_host_->StoreShaderToDisk(client_id, key, shader); | 140 gpu_host_->StoreShaderToDisk(client_id, key, shader); |
| 143 } | 141 } |
| 144 | 142 |
| 145 #if defined(OS_WIN) | 143 #if defined(OS_WIN) |
| 146 void GpuServiceInternal::SendAcceleratedSurfaceCreatedChildWindow( | 144 void GpuService::SendAcceleratedSurfaceCreatedChildWindow( |
| 147 gpu::SurfaceHandle parent_window, | 145 gpu::SurfaceHandle parent_window, |
| 148 gpu::SurfaceHandle child_window) { | 146 gpu::SurfaceHandle child_window) { |
| 149 ::SetParent(child_window, parent_window); | 147 ::SetParent(child_window, parent_window); |
| 150 } | 148 } |
| 151 #endif | 149 #endif |
| 152 | 150 |
| 153 void GpuServiceInternal::SetActiveURL(const GURL& url) { | 151 void GpuService::SetActiveURL(const GURL& url) { |
| 154 // TODO(penghuang): implement this function. | 152 // TODO(penghuang): implement this function. |
| 155 } | 153 } |
| 156 | 154 |
| 157 void GpuServiceInternal::EstablishGpuChannel( | 155 void GpuService::EstablishGpuChannel( |
| 158 int32_t client_id, | 156 int32_t client_id, |
| 159 uint64_t client_tracing_id, | 157 uint64_t client_tracing_id, |
| 160 bool is_gpu_host, | 158 bool is_gpu_host, |
| 161 const EstablishGpuChannelCallback& callback) { | 159 const EstablishGpuChannelCallback& callback) { |
| 162 DCHECK(CalledOnValidThread()); | 160 DCHECK(CalledOnValidThread()); |
| 163 | 161 |
| 164 if (!gpu_channel_manager_) { | 162 if (!gpu_channel_manager_) { |
| 165 callback.Run(mojo::ScopedMessagePipeHandle()); | 163 callback.Run(mojo::ScopedMessagePipeHandle()); |
| 166 return; | 164 return; |
| 167 } | 165 } |
| 168 | 166 |
| 169 const bool preempts = is_gpu_host; | 167 const bool preempts = is_gpu_host; |
| 170 const bool allow_view_command_buffers = is_gpu_host; | 168 const bool allow_view_command_buffers = is_gpu_host; |
| 171 const bool allow_real_time_streams = is_gpu_host; | 169 const bool allow_real_time_streams = is_gpu_host; |
| 172 mojo::ScopedMessagePipeHandle channel_handle; | 170 mojo::ScopedMessagePipeHandle channel_handle; |
| 173 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( | 171 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( |
| 174 client_id, client_tracing_id, preempts, allow_view_command_buffers, | 172 client_id, client_tracing_id, preempts, allow_view_command_buffers, |
| 175 allow_real_time_streams); | 173 allow_real_time_streams); |
| 176 channel_handle.reset(handle.mojo_handle); | 174 channel_handle.reset(handle.mojo_handle); |
| 177 media_gpu_channel_manager_->AddChannel(client_id); | 175 media_gpu_channel_manager_->AddChannel(client_id); |
| 178 callback.Run(std::move(channel_handle)); | 176 callback.Run(std::move(channel_handle)); |
| 179 } | 177 } |
| 180 | 178 |
| 181 } // namespace ui | 179 } // namespace ui |
| OLD | NEW |