| 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" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 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 : io_runner_(std::move(io_runner)), | 46 : io_runner_(std::move(io_runner)), |
| 47 compositor_runner_(std::move(compositor_runner)), |
| 46 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 48 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 47 base::WaitableEvent::InitialState::NOT_SIGNALED), | 49 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 48 watchdog_thread_(std::move(watchdog_thread)), | 50 watchdog_thread_(std::move(watchdog_thread)), |
| 49 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 51 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
| 50 gpu_info_(gpu_info), | 52 gpu_info_(gpu_info) {} |
| 51 compositor_thread_("DisplayCompositorThread") { | |
| 52 compositor_thread_.Start(); | |
| 53 } | |
| 54 | 53 |
| 55 GpuServiceInternal::~GpuServiceInternal() { | 54 GpuServiceInternal::~GpuServiceInternal() { |
| 56 bindings_.CloseAllBindings(); | 55 bindings_.CloseAllBindings(); |
| 57 media_gpu_channel_manager_.reset(); | 56 media_gpu_channel_manager_.reset(); |
| 58 gpu_channel_manager_.reset(); | 57 gpu_channel_manager_.reset(); |
| 59 owned_sync_point_manager_.reset(); | 58 owned_sync_point_manager_.reset(); |
| 60 | 59 |
| 61 // Signal this event before destroying the child process. That way all | 60 // Signal this event before destroying the child process. That way all |
| 62 // background threads can cleanup. | 61 // background threads can cleanup. |
| 63 // For example, in the renderer the RenderThread instances will be able to | 62 // For example, in the renderer the RenderThread instances will be able to |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 cc::mojom::DisplayCompositorRequest request, | 94 cc::mojom::DisplayCompositorRequest request, |
| 96 cc::mojom::DisplayCompositorClientPtr client) { | 95 cc::mojom::DisplayCompositorClientPtr client) { |
| 97 DCHECK(CalledOnValidThread()); | 96 DCHECK(CalledOnValidThread()); |
| 98 DCHECK(!gpu_command_service_); | 97 DCHECK(!gpu_command_service_); |
| 99 gpu_command_service_ = new gpu::GpuInProcessThreadService( | 98 gpu_command_service_ = new gpu::GpuInProcessThreadService( |
| 100 base::ThreadTaskRunnerHandle::Get(), owned_sync_point_manager_.get(), | 99 base::ThreadTaskRunnerHandle::Get(), owned_sync_point_manager_.get(), |
| 101 gpu_channel_manager_->mailbox_manager(), | 100 gpu_channel_manager_->mailbox_manager(), |
| 102 gpu_channel_manager_->share_group()); | 101 gpu_channel_manager_->share_group()); |
| 103 mojom::GpuServiceInternalPtr gpu_service_ptr; | 102 mojom::GpuServiceInternalPtr gpu_service_ptr; |
| 104 Add(mojo::GetProxy(&gpu_service_ptr)); | 103 Add(mojo::GetProxy(&gpu_service_ptr)); |
| 105 compositor_thread_.task_runner()->PostTask( | 104 compositor_runner_->PostTask( |
| 106 FROM_HERE, | 105 FROM_HERE, |
| 107 base::Bind(&GpuServiceInternal::CreateDisplayCompositorOnCompositorThread, | 106 base::Bind(&GpuServiceInternal::CreateDisplayCompositorOnCompositorThread, |
| 108 base::Unretained(this), | 107 base::Unretained(this), |
| 109 base::Passed(gpu_service_ptr.PassInterface()), | 108 base::Passed(gpu_service_ptr.PassInterface()), |
| 110 base::Passed(&request), base::Passed(client.PassInterface()))); | 109 base::Passed(&request), base::Passed(client.PassInterface()))); |
| 111 } | 110 } |
| 112 | 111 |
| 113 void GpuServiceInternal::CreateDisplayCompositorOnCompositorThread( | 112 void GpuServiceInternal::CreateDisplayCompositorOnCompositorThread( |
| 114 mojom::GpuServiceInternalPtrInfo gpu_service_info, | 113 mojom::GpuServiceInternalPtrInfo gpu_service_info, |
| 115 cc::mojom::DisplayCompositorRequest request, | 114 cc::mojom::DisplayCompositorRequest request, |
| 116 cc::mojom::DisplayCompositorClientPtrInfo client_info) { | 115 cc::mojom::DisplayCompositorClientPtrInfo client_info) { |
| 117 DCHECK(compositor_thread_.task_runner()->BelongsToCurrentThread()); | 116 DCHECK(compositor_runner_->BelongsToCurrentThread()); |
| 118 mojom::GpuServiceInternalPtr gpu_service_ptr; | 117 mojom::GpuServiceInternalPtr gpu_service_ptr; |
| 119 gpu_service_ptr.Bind(std::move(gpu_service_info)); | 118 gpu_service_ptr.Bind(std::move(gpu_service_info)); |
| 120 | 119 |
| 121 cc::mojom::DisplayCompositorClientPtr client_ptr; | 120 cc::mojom::DisplayCompositorClientPtr client_ptr; |
| 122 client_ptr.Bind(std::move(client_info)); | 121 client_ptr.Bind(std::move(client_info)); |
| 123 | 122 |
| 124 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager = | 123 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager = |
| 125 base::MakeUnique<MusGpuMemoryBufferManager>(std::move(gpu_service_ptr), | 124 base::MakeUnique<MusGpuMemoryBufferManager>(std::move(gpu_service_ptr), |
| 126 1 /* client_id */); | 125 1 /* client_id */); |
| 127 // |gpu_memory_buffer_factory_| is null in tests. | 126 // |gpu_memory_buffer_factory_| is null in tests. |
| 128 gpu::ImageFactory* image_factory = | 127 gpu::ImageFactory* image_factory = |
| 129 gpu_memory_buffer_factory_ ? gpu_memory_buffer_factory_->AsImageFactory() | 128 gpu_memory_buffer_factory_ ? gpu_memory_buffer_factory_->AsImageFactory() |
| 130 : nullptr; | 129 : nullptr; |
| 131 mojo::MakeStrongBinding( | 130 display_compositor_ = base::MakeUnique<DisplayCompositor>( |
| 132 base::MakeUnique<DisplayCompositor>(gpu_command_service_, | 131 gpu_command_service_, std::move(gpu_memory_buffer_manager), image_factory, |
| 133 std::move(gpu_memory_buffer_manager), | 132 std::move(request), std::move(client_ptr)); |
| 134 image_factory, std::move(client_ptr)), | |
| 135 std::move(request)); | |
| 136 } | 133 } |
| 134 |
| 135 void GpuServiceInternal::DestroyDisplayCompositor() { |
| 136 if (compositor_runner_->BelongsToCurrentThread()) { |
| 137 DestroyDisplayCompositorOnCompositorThread(); |
| 138 return; |
| 139 } |
| 140 compositor_runner_->PostTask( |
| 141 FROM_HERE, |
| 142 base::Bind( |
| 143 &GpuServiceInternal::DestroyDisplayCompositorOnCompositorThread, |
| 144 base::Unretained(this))); |
| 145 } |
| 146 |
| 147 void GpuServiceInternal::DestroyDisplayCompositorOnCompositorThread() { |
| 148 display_compositor_.reset(); |
| 149 } |
| 150 |
| 137 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) { | 151 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) { |
| 138 NOTIMPLEMENTED(); | 152 NOTIMPLEMENTED(); |
| 139 } | 153 } |
| 140 | 154 |
| 141 void GpuServiceInternal::DidDestroyChannel(int client_id) { | 155 void GpuServiceInternal::DidDestroyChannel(int client_id) { |
| 142 media_gpu_channel_manager_->RemoveChannel(client_id); | 156 media_gpu_channel_manager_->RemoveChannel(client_id); |
| 143 NOTIMPLEMENTED(); | 157 NOTIMPLEMENTED(); |
| 144 } | 158 } |
| 145 | 159 |
| 146 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { | 160 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 mojo::ScopedMessagePipeHandle channel_handle; | 232 mojo::ScopedMessagePipeHandle channel_handle; |
| 219 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( | 233 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( |
| 220 client_id, client_tracing_id, preempts, allow_view_command_buffers, | 234 client_id, client_tracing_id, preempts, allow_view_command_buffers, |
| 221 allow_real_time_streams); | 235 allow_real_time_streams); |
| 222 channel_handle.reset(handle.mojo_handle); | 236 channel_handle.reset(handle.mojo_handle); |
| 223 media_gpu_channel_manager_->AddChannel(client_id); | 237 media_gpu_channel_manager_->AddChannel(client_id); |
| 224 callback.Run(std::move(channel_handle)); | 238 callback.Run(std::move(channel_handle)); |
| 225 } | 239 } |
| 226 | 240 |
| 227 } // namespace ui | 241 } // namespace ui |
| OLD | NEW |