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 "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" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "components/viz/common/server_gpu_memory_buffer_manager.h" | 12 #include "components/viz/common/server_gpu_memory_buffer_manager.h" |
| 13 #include "components/viz/service/display_compositor/gpu_display_provider.h" | 13 #include "components/viz/service/display_compositor/gpu_display_provider.h" |
| 14 #include "components/viz/service/frame_sinks/mojo_frame_sink_manager.h" | 14 #include "components/viz/service/frame_sinks/mojo_frame_sink_manager.h" |
| 15 #include "gpu/command_buffer/common/activity_flags.h" | 15 #include "gpu/command_buffer/common/activity_flags.h" |
| 16 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" | |
| 16 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 17 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
| 17 #include "gpu/ipc/gpu_in_process_thread_service.h" | 18 #include "gpu/ipc/gpu_in_process_thread_service.h" |
| 18 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 19 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
| 19 #include "gpu/ipc/service/gpu_watchdog_thread.h" | 20 #include "gpu/ipc/service/gpu_watchdog_thread.h" |
| 20 #include "services/ui/gpu/gpu_service.h" | 21 #include "services/ui/gpu/gpu_service.h" |
| 21 | 22 |
| 22 #if defined(USE_OZONE) | 23 #if defined(USE_OZONE) |
| 23 #include "ui/ozone/public/ozone_platform.h" | 24 #include "ui/ozone/public/ozone_platform.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 37 base::MessageLoop::TYPE_DEFAULT); | 38 base::MessageLoop::TYPE_DEFAULT); |
| 38 } | 39 } |
| 39 #endif // defined(USE_X11) | 40 #endif // defined(USE_X11) |
| 40 | 41 |
| 41 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
| 42 std::unique_ptr<base::MessagePump> CreateMessagePumpMac() { | 43 std::unique_ptr<base::MessagePump> CreateMessagePumpMac() { |
| 43 return base::MakeUnique<base::MessagePumpCFRunLoop>(); | 44 return base::MakeUnique<base::MessagePumpCFRunLoop>(); |
| 44 } | 45 } |
| 45 #endif // defined(OS_MACOSX) | 46 #endif // defined(OS_MACOSX) |
| 46 | 47 |
| 48 class InProcessGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager { | |
|
Fady Samuel
2017/06/16 22:33:17
Move this to a separate file please
| |
| 49 public: | |
| 50 InProcessGpuMemoryBufferManager(gpu::GpuChannelManager* channel_manager, | |
| 51 gpu::GpuMemoryBufferFactory* memory_factory) | |
| 52 : client_id_(1), | |
| 53 channel_manager_(channel_manager), | |
| 54 memory_factory_(memory_factory), | |
| 55 weak_factory_(this) { | |
| 56 weak_ptr_ = weak_factory_.GetWeakPtr(); | |
| 57 } | |
| 58 | |
| 59 ~InProcessGpuMemoryBufferManager() override {} | |
| 60 | |
| 61 private: | |
| 62 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | |
| 63 int client_id, | |
| 64 const gpu::SyncToken& sync_token) { | |
| 65 channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); | |
| 66 } | |
| 67 | |
| 68 // gpu::GpuMemoryBufferManager: | |
| 69 std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer( | |
| 70 const gfx::Size& size, | |
| 71 gfx::BufferFormat format, | |
| 72 gfx::BufferUsage usage, | |
| 73 gpu::SurfaceHandle surface_handle) override { | |
| 74 gfx::GpuMemoryBufferId id(next_gpu_memory_id_++); | |
| 75 gfx::GpuMemoryBufferHandle buffer_handle = | |
| 76 memory_factory_->CreateGpuMemoryBuffer(id, size, format, usage, | |
| 77 client_id_, surface_handle); | |
| 78 return gpu::GpuMemoryBufferImpl::CreateFromHandle( | |
| 79 buffer_handle, size, format, usage, | |
| 80 base::Bind(&InProcessGpuMemoryBufferManager::DestroyGpuMemoryBuffer, | |
| 81 weak_ptr_, id, client_id_)); | |
| 82 } | |
| 83 | |
| 84 void SetDestructionSyncToken(gfx::GpuMemoryBuffer* buffer, | |
| 85 const gpu::SyncToken& sync_token) override { | |
| 86 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token( | |
| 87 sync_token); | |
| 88 } | |
| 89 | |
| 90 const int client_id_; | |
| 91 int next_gpu_memory_id_ = 1; | |
| 92 gpu::GpuChannelManager* channel_manager_; | |
| 93 gpu::GpuMemoryBufferFactory* memory_factory_; | |
| 94 base::WeakPtr<InProcessGpuMemoryBufferManager> weak_ptr_; | |
| 95 base::WeakPtrFactory<InProcessGpuMemoryBufferManager> weak_factory_; | |
| 96 DISALLOW_COPY_AND_ASSIGN(InProcessGpuMemoryBufferManager); | |
| 97 }; | |
| 98 | |
| 47 } // namespace | 99 } // namespace |
| 48 | 100 |
| 49 namespace ui { | 101 namespace ui { |
| 50 | 102 |
| 51 GpuMain::GpuMain(mojom::GpuMainRequest request) | 103 GpuMain::GpuMain(mojom::GpuMainRequest request) |
| 52 : gpu_thread_("GpuThread"), | 104 : gpu_thread_("GpuThread"), |
| 53 io_thread_("GpuIOThread"), | 105 io_thread_("GpuIOThread"), |
| 54 compositor_thread_("DisplayCompositorThread"), | 106 compositor_thread_("DisplayCompositorThread"), |
| 55 power_monitor_(base::MakeUnique<base::PowerMonitorDeviceSource>()), | 107 power_monitor_(base::MakeUnique<base::PowerMonitorDeviceSource>()), |
| 56 binding_(this) { | 108 binding_(this) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 cc::mojom::FrameSinkManagerRequest request, | 220 cc::mojom::FrameSinkManagerRequest request, |
| 169 cc::mojom::FrameSinkManagerClientPtrInfo client_info) { | 221 cc::mojom::FrameSinkManagerClientPtrInfo client_info) { |
| 170 DCHECK(!gpu_command_service_); | 222 DCHECK(!gpu_command_service_); |
| 171 DCHECK(gpu_service_); | 223 DCHECK(gpu_service_); |
| 172 DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread()); | 224 DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread()); |
| 173 gpu_command_service_ = new gpu::GpuInProcessThreadService( | 225 gpu_command_service_ = new gpu::GpuInProcessThreadService( |
| 174 gpu_thread_task_runner_, gpu_service_->sync_point_manager(), | 226 gpu_thread_task_runner_, gpu_service_->sync_point_manager(), |
| 175 gpu_service_->mailbox_manager(), gpu_service_->share_group()); | 227 gpu_service_->mailbox_manager(), gpu_service_->share_group()); |
| 176 | 228 |
| 177 gpu::ImageFactory* image_factory = gpu_service_->gpu_image_factory(); | 229 gpu::ImageFactory* image_factory = gpu_service_->gpu_image_factory(); |
| 178 | |
| 179 // If the FrameSinkManager creation was delayed because GpuService had not | |
| 180 // been created yet, then this is called, in gpu thread, right after | |
| 181 // GpuService is created. | |
| 182 mojom::GpuServicePtr gpu_service; | |
| 183 BindGpuInternalOnGpuThread(mojo::MakeRequest(&gpu_service)); | |
| 184 compositor_thread_task_runner_->PostTask( | 230 compositor_thread_task_runner_->PostTask( |
| 185 FROM_HERE, base::Bind(&GpuMain::CreateFrameSinkManagerOnCompositorThread, | 231 FROM_HERE, base::Bind(&GpuMain::CreateFrameSinkManagerOnCompositorThread, |
| 186 base::Unretained(this), image_factory, | 232 base::Unretained(this), image_factory, |
| 187 base::Passed(gpu_service.PassInterface()), | |
| 188 base::Passed(std::move(request)), | 233 base::Passed(std::move(request)), |
| 189 base::Passed(std::move(client_info)))); | 234 base::Passed(std::move(client_info)))); |
| 190 } | 235 } |
| 191 | 236 |
| 192 void GpuMain::CreateFrameSinkManagerOnCompositorThread( | 237 void GpuMain::CreateFrameSinkManagerOnCompositorThread( |
| 193 gpu::ImageFactory* image_factory, | 238 gpu::ImageFactory* image_factory, |
| 194 mojom::GpuServicePtrInfo gpu_service_info, | |
| 195 cc::mojom::FrameSinkManagerRequest request, | 239 cc::mojom::FrameSinkManagerRequest request, |
| 196 cc::mojom::FrameSinkManagerClientPtrInfo client_info) { | 240 cc::mojom::FrameSinkManagerClientPtrInfo client_info) { |
| 197 DCHECK(!frame_sink_manager_); | 241 DCHECK(!frame_sink_manager_); |
| 198 cc::mojom::FrameSinkManagerClientPtr client; | 242 cc::mojom::FrameSinkManagerClientPtr client; |
| 199 client.Bind(std::move(client_info)); | 243 client.Bind(std::move(client_info)); |
| 200 | 244 |
| 201 gpu_internal_.Bind(std::move(gpu_service_info)); | |
| 202 | |
| 203 display_provider_ = base::MakeUnique<viz::GpuDisplayProvider>( | 245 display_provider_ = base::MakeUnique<viz::GpuDisplayProvider>( |
| 204 gpu_command_service_, | 246 gpu_command_service_, |
| 205 base::MakeUnique<viz::ServerGpuMemoryBufferManager>(gpu_internal_.get(), | 247 base::MakeUnique<InProcessGpuMemoryBufferManager>( |
| 206 1 /* client_id */), | 248 gpu_service_->gpu_channel_manager(), |
| 249 gpu_service_->gpu_memory_buffer_factory()), | |
| 207 image_factory); | 250 image_factory); |
| 208 | 251 |
| 209 frame_sink_manager_ = base::MakeUnique<viz::MojoFrameSinkManager>( | 252 frame_sink_manager_ = base::MakeUnique<viz::MojoFrameSinkManager>( |
| 210 true, display_provider_.get()); | 253 true, display_provider_.get()); |
| 211 frame_sink_manager_->BindPtrAndSetClient(std::move(request), | 254 frame_sink_manager_->BindPtrAndSetClient(std::move(request), |
| 212 std::move(client)); | 255 std::move(client)); |
| 213 } | 256 } |
| 214 | 257 |
| 215 void GpuMain::TearDownOnCompositorThread() { | 258 void GpuMain::TearDownOnCompositorThread() { |
| 216 frame_sink_manager_.reset(); | 259 frame_sink_manager_.reset(); |
| 217 display_provider_.reset(); | 260 display_provider_.reset(); |
| 218 gpu_internal_.reset(); | |
| 219 } | 261 } |
| 220 | 262 |
| 221 void GpuMain::TearDownOnGpuThread() { | 263 void GpuMain::TearDownOnGpuThread() { |
| 222 binding_.Close(); | 264 binding_.Close(); |
| 223 gpu_service_.reset(); | 265 gpu_service_.reset(); |
| 224 gpu_memory_buffer_factory_.reset(); | 266 gpu_memory_buffer_factory_.reset(); |
| 225 gpu_init_.reset(); | 267 gpu_init_.reset(); |
| 226 } | 268 } |
| 227 | 269 |
| 228 void GpuMain::CreateGpuServiceOnGpuThread( | 270 void GpuMain::CreateGpuServiceOnGpuThread( |
| 229 mojom::GpuServiceRequest request, | 271 mojom::GpuServiceRequest request, |
| 230 mojom::GpuHostPtr gpu_host, | 272 mojom::GpuHostPtr gpu_host, |
| 231 const gpu::GpuPreferences& preferences, | 273 const gpu::GpuPreferences& preferences, |
| 232 gpu::GpuProcessActivityFlags activity_flags) { | 274 gpu::GpuProcessActivityFlags activity_flags) { |
| 233 gpu_service_->UpdateGPUInfoFromPreferences(preferences); | 275 gpu_service_->UpdateGPUInfoFromPreferences(preferences); |
| 234 gpu_service_->InitializeWithHost(std::move(gpu_host), | 276 gpu_service_->InitializeWithHost(std::move(gpu_host), |
| 235 std::move(activity_flags)); | 277 std::move(activity_flags)); |
| 236 gpu_service_->Bind(std::move(request)); | 278 gpu_service_->Bind(std::move(request)); |
| 237 | 279 |
| 238 if (pending_frame_sink_manager_request_.is_pending()) { | 280 if (pending_frame_sink_manager_request_.is_pending()) { |
| 239 CreateFrameSinkManagerInternal( | 281 CreateFrameSinkManagerInternal( |
| 240 std::move(pending_frame_sink_manager_request_), | 282 std::move(pending_frame_sink_manager_request_), |
| 241 std::move(pending_frame_sink_manager_client_info_)); | 283 std::move(pending_frame_sink_manager_client_info_)); |
| 242 } | 284 } |
| 243 } | 285 } |
| 244 | 286 |
| 245 void GpuMain::BindGpuInternalOnGpuThread(mojom::GpuServiceRequest request) { | |
| 246 gpu_service_->Bind(std::move(request)); | |
| 247 } | |
| 248 | |
| 249 void GpuMain::PreSandboxStartup() { | 287 void GpuMain::PreSandboxStartup() { |
| 250 // TODO(sad): https://crbug.com/645602 | 288 // TODO(sad): https://crbug.com/645602 |
| 251 } | 289 } |
| 252 | 290 |
| 253 bool GpuMain::EnsureSandboxInitialized( | 291 bool GpuMain::EnsureSandboxInitialized( |
| 254 gpu::GpuWatchdogThread* watchdog_thread) { | 292 gpu::GpuWatchdogThread* watchdog_thread) { |
| 255 // TODO(sad): https://crbug.com/645602 | 293 // TODO(sad): https://crbug.com/645602 |
| 256 return true; | 294 return true; |
| 257 } | 295 } |
| 258 | 296 |
| 259 } // namespace ui | 297 } // namespace ui |
| OLD | NEW |