| 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_main.h" | 5 #include "services/ui/gpu/gpu_main.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/power_monitor/power_monitor_device_source.h" | 10 #include "base/power_monitor/power_monitor_device_source.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // base::Unretained here. | 128 // base::Unretained here. |
| 129 gpu_thread_task_runner_->PostTask( | 129 gpu_thread_task_runner_->PostTask( |
| 130 FROM_HERE, | 130 FROM_HERE, |
| 131 base::Bind(&GpuMain::CreateGpuServiceOnGpuThread, base::Unretained(this), | 131 base::Bind(&GpuMain::CreateGpuServiceOnGpuThread, base::Unretained(this), |
| 132 base::Passed(std::move(request)), | 132 base::Passed(std::move(request)), |
| 133 base::Passed(gpu_host.PassInterface()), preferences, | 133 base::Passed(gpu_host.PassInterface()), preferences, |
| 134 base::Passed( | 134 base::Passed( |
| 135 gpu::GpuProcessActivityFlags(std::move(activity_flags))))); | 135 gpu::GpuProcessActivityFlags(std::move(activity_flags))))); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void GpuMain::CreateDisplayCompositor( | 138 void GpuMain::CreateFrameSinkManager( |
| 139 cc::mojom::DisplayCompositorRequest request, | 139 cc::mojom::FrameSinkManagerRequest request, |
| 140 cc::mojom::DisplayCompositorClientPtr client) { | 140 cc::mojom::FrameSinkManagerClientPtr client) { |
| 141 if (!gpu_service_) { | 141 if (!gpu_service_) { |
| 142 pending_display_compositor_request_ = std::move(request); | 142 pending_frame_sink_manager_request_ = std::move(request); |
| 143 pending_display_compositor_client_info_ = client.PassInterface(); | 143 pending_frame_sink_manager_client_info_ = client.PassInterface(); |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 CreateDisplayCompositorInternal(std::move(request), client.PassInterface()); | 146 CreateFrameSinkManagerInternal(std::move(request), client.PassInterface()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void GpuMain::InitOnGpuThread( | 149 void GpuMain::InitOnGpuThread( |
| 150 scoped_refptr<base::SingleThreadTaskRunner> io_runner, | 150 scoped_refptr<base::SingleThreadTaskRunner> io_runner, |
| 151 scoped_refptr<base::SingleThreadTaskRunner> compositor_runner) { | 151 scoped_refptr<base::SingleThreadTaskRunner> compositor_runner) { |
| 152 gpu_init_.reset(new gpu::GpuInit()); | 152 gpu_init_.reset(new gpu::GpuInit()); |
| 153 gpu_init_->set_sandbox_helper(this); | 153 gpu_init_->set_sandbox_helper(this); |
| 154 bool success = gpu_init_->InitializeAndStartSandbox( | 154 bool success = gpu_init_->InitializeAndStartSandbox( |
| 155 *base::CommandLine::ForCurrentProcess()); | 155 *base::CommandLine::ForCurrentProcess()); |
| 156 if (!success) | 156 if (!success) |
| 157 return; | 157 return; |
| 158 | 158 |
| 159 gpu_service_ = base::MakeUnique<GpuService>( | 159 gpu_service_ = base::MakeUnique<GpuService>( |
| 160 gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), io_runner, | 160 gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), io_runner, |
| 161 gpu_init_->gpu_feature_info()); | 161 gpu_init_->gpu_feature_info()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void GpuMain::CreateDisplayCompositorInternal( | 164 void GpuMain::CreateFrameSinkManagerInternal( |
| 165 cc::mojom::DisplayCompositorRequest request, | 165 cc::mojom::FrameSinkManagerRequest request, |
| 166 cc::mojom::DisplayCompositorClientPtrInfo client_info) { | 166 cc::mojom::FrameSinkManagerClientPtrInfo client_info) { |
| 167 DCHECK(!gpu_command_service_); | 167 DCHECK(!gpu_command_service_); |
| 168 gpu_command_service_ = new gpu::GpuInProcessThreadService( | 168 gpu_command_service_ = new gpu::GpuInProcessThreadService( |
| 169 gpu_thread_task_runner_, gpu_service_->sync_point_manager(), | 169 gpu_thread_task_runner_, gpu_service_->sync_point_manager(), |
| 170 gpu_service_->mailbox_manager(), gpu_service_->share_group()); | 170 gpu_service_->mailbox_manager(), gpu_service_->share_group()); |
| 171 | 171 |
| 172 gpu::ImageFactory* image_factory = gpu_service_->gpu_image_factory(); | 172 gpu::ImageFactory* image_factory = gpu_service_->gpu_image_factory(); |
| 173 mojom::GpuServicePtr gpu_service; | 173 mojom::GpuServicePtr gpu_service; |
| 174 mojom::GpuServiceRequest gpu_service_request(&gpu_service); | 174 mojom::GpuServiceRequest gpu_service_request(&gpu_service); |
| 175 | 175 |
| 176 if (gpu_thread_task_runner_->BelongsToCurrentThread()) { | 176 if (gpu_thread_task_runner_->BelongsToCurrentThread()) { |
| 177 // If the DisplayCompositor creation was delayed because GpuService | 177 // If the FrameSinkManager creation was delayed because GpuService had not |
| 178 // had not been created yet, then this is called, in gpu thread, right after | 178 // been created yet, then this is called, in gpu thread, right after |
| 179 // GpuService is created. | 179 // GpuService is created. |
| 180 BindGpuInternalOnGpuThread(std::move(gpu_service_request)); | 180 BindGpuInternalOnGpuThread(std::move(gpu_service_request)); |
| 181 } else { | 181 } else { |
| 182 gpu_thread_task_runner_->PostTask( | 182 gpu_thread_task_runner_->PostTask( |
| 183 FROM_HERE, | 183 FROM_HERE, |
| 184 base::Bind(&GpuMain::BindGpuInternalOnGpuThread, base::Unretained(this), | 184 base::Bind(&GpuMain::BindGpuInternalOnGpuThread, base::Unretained(this), |
| 185 base::Passed(std::move(gpu_service_request)))); | 185 base::Passed(std::move(gpu_service_request)))); |
| 186 } | 186 } |
| 187 | 187 |
| 188 compositor_thread_task_runner_->PostTask( | 188 compositor_thread_task_runner_->PostTask( |
| 189 FROM_HERE, base::Bind(&GpuMain::CreateDisplayCompositorOnCompositorThread, | 189 FROM_HERE, base::Bind(&GpuMain::CreateFrameSinkManagerOnCompositorThread, |
| 190 base::Unretained(this), image_factory, | 190 base::Unretained(this), image_factory, |
| 191 base::Passed(gpu_service.PassInterface()), | 191 base::Passed(gpu_service.PassInterface()), |
| 192 base::Passed(std::move(request)), | 192 base::Passed(std::move(request)), |
| 193 base::Passed(std::move(client_info)))); | 193 base::Passed(std::move(client_info)))); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void GpuMain::CreateDisplayCompositorOnCompositorThread( | 196 void GpuMain::CreateFrameSinkManagerOnCompositorThread( |
| 197 gpu::ImageFactory* image_factory, | 197 gpu::ImageFactory* image_factory, |
| 198 mojom::GpuServicePtrInfo gpu_service_info, | 198 mojom::GpuServicePtrInfo gpu_service_info, |
| 199 cc::mojom::DisplayCompositorRequest request, | 199 cc::mojom::FrameSinkManagerRequest request, |
| 200 cc::mojom::DisplayCompositorClientPtrInfo client_info) { | 200 cc::mojom::FrameSinkManagerClientPtrInfo client_info) { |
| 201 DCHECK(!display_compositor_); | 201 DCHECK(!frame_sink_manager_); |
| 202 cc::mojom::DisplayCompositorClientPtr client; | 202 cc::mojom::FrameSinkManagerClientPtr client; |
| 203 client.Bind(std::move(client_info)); | 203 client.Bind(std::move(client_info)); |
| 204 | 204 |
| 205 gpu_internal_.Bind(std::move(gpu_service_info)); | 205 gpu_internal_.Bind(std::move(gpu_service_info)); |
| 206 | 206 |
| 207 display_provider_ = base::MakeUnique<MusDisplayProvider>( | 207 display_provider_ = base::MakeUnique<MusDisplayProvider>( |
| 208 gpu_command_service_, | 208 gpu_command_service_, |
| 209 base::MakeUnique<ServerGpuMemoryBufferManager>(gpu_internal_.get(), | 209 base::MakeUnique<ServerGpuMemoryBufferManager>(gpu_internal_.get(), |
| 210 1 /* client_id */), | 210 1 /* client_id */), |
| 211 image_factory); | 211 image_factory); |
| 212 | 212 |
| 213 display_compositor_ = base::MakeUnique<DisplayCompositor>( | 213 frame_sink_manager_ = base::MakeUnique<MojoFrameSinkManager>( |
| 214 display_provider_.get(), std::move(request), std::move(client)); | 214 display_provider_.get(), std::move(request), std::move(client)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void GpuMain::TearDownOnCompositorThread() { | 217 void GpuMain::TearDownOnCompositorThread() { |
| 218 display_compositor_.reset(); | 218 frame_sink_manager_.reset(); |
| 219 display_provider_.reset(); | 219 display_provider_.reset(); |
| 220 gpu_internal_.reset(); | 220 gpu_internal_.reset(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void GpuMain::TearDownOnGpuThread() { | 223 void GpuMain::TearDownOnGpuThread() { |
| 224 gpu_service_.reset(); | 224 gpu_service_.reset(); |
| 225 gpu_memory_buffer_factory_.reset(); | 225 gpu_memory_buffer_factory_.reset(); |
| 226 gpu_init_.reset(); | 226 gpu_init_.reset(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void GpuMain::CreateGpuServiceOnGpuThread( | 229 void GpuMain::CreateGpuServiceOnGpuThread( |
| 230 mojom::GpuServiceRequest request, | 230 mojom::GpuServiceRequest request, |
| 231 mojom::GpuHostPtrInfo gpu_host_info, | 231 mojom::GpuHostPtrInfo gpu_host_info, |
| 232 const gpu::GpuPreferences& preferences, | 232 const gpu::GpuPreferences& preferences, |
| 233 gpu::GpuProcessActivityFlags activity_flags) { | 233 gpu::GpuProcessActivityFlags activity_flags) { |
| 234 mojom::GpuHostPtr gpu_host; | 234 mojom::GpuHostPtr gpu_host; |
| 235 gpu_host.Bind(std::move(gpu_host_info)); | 235 gpu_host.Bind(std::move(gpu_host_info)); |
| 236 gpu_service_->UpdateGPUInfoFromPreferences(preferences); | 236 gpu_service_->UpdateGPUInfoFromPreferences(preferences); |
| 237 gpu_service_->InitializeWithHost(std::move(gpu_host), | 237 gpu_service_->InitializeWithHost(std::move(gpu_host), |
| 238 std::move(activity_flags)); | 238 std::move(activity_flags)); |
| 239 gpu_service_->Bind(std::move(request)); | 239 gpu_service_->Bind(std::move(request)); |
| 240 | 240 |
| 241 if (pending_display_compositor_request_.is_pending()) { | 241 if (pending_frame_sink_manager_request_.is_pending()) { |
| 242 CreateDisplayCompositorInternal( | 242 CreateFrameSinkManagerInternal( |
| 243 std::move(pending_display_compositor_request_), | 243 std::move(pending_frame_sink_manager_request_), |
| 244 std::move(pending_display_compositor_client_info_)); | 244 std::move(pending_frame_sink_manager_client_info_)); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 void GpuMain::BindGpuInternalOnGpuThread(mojom::GpuServiceRequest request) { | 248 void GpuMain::BindGpuInternalOnGpuThread(mojom::GpuServiceRequest request) { |
| 249 gpu_service_->Bind(std::move(request)); | 249 gpu_service_->Bind(std::move(request)); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void GpuMain::PreSandboxStartup() { | 252 void GpuMain::PreSandboxStartup() { |
| 253 // TODO(sad): https://crbug.com/645602 | 253 // TODO(sad): https://crbug.com/645602 |
| 254 } | 254 } |
| 255 | 255 |
| 256 bool GpuMain::EnsureSandboxInitialized( | 256 bool GpuMain::EnsureSandboxInitialized( |
| 257 gpu::GpuWatchdogThread* watchdog_thread) { | 257 gpu::GpuWatchdogThread* watchdog_thread) { |
| 258 // TODO(sad): https://crbug.com/645602 | 258 // TODO(sad): https://crbug.com/645602 |
| 259 return true; | 259 return true; |
| 260 } | 260 } |
| 261 | 261 |
| 262 } // namespace ui | 262 } // namespace ui |
| OLD | NEW |