| 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 "ui/aura/mus/gpu_service.h" | 5 #include "ui/aura/mus/gpu_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.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 "mojo/public/cpp/bindings/sync_call_restrictions.h" | 11 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" |
| 12 #include "mojo/public/cpp/system/platform_handle.h" | 12 #include "mojo/public/cpp/system/platform_handle.h" |
| 13 #include "services/service_manager/public/cpp/connector.h" | 13 #include "services/service_manager/public/cpp/connector.h" |
| 14 #include "services/ui/public/interfaces/constants.mojom.h" |
| 14 #include "services/ui/public/interfaces/gpu_service.mojom.h" | 15 #include "services/ui/public/interfaces/gpu_service.mojom.h" |
| 15 #include "ui/aura/mus/mojo_gpu_memory_buffer_manager.h" | 16 #include "ui/aura/mus/mojo_gpu_memory_buffer_manager.h" |
| 16 | 17 |
| 17 namespace aura { | 18 namespace aura { |
| 18 | 19 |
| 19 GpuService::GpuService(service_manager::Connector* connector, | 20 GpuService::GpuService(service_manager::Connector* connector, |
| 20 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 21 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 21 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 22 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 22 io_task_runner_(std::move(task_runner)), | 23 io_task_runner_(std::move(task_runner)), |
| 23 connector_(connector), | 24 connector_(connector), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); | 58 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); |
| 58 if (channel) { | 59 if (channel) { |
| 59 main_task_runner_->PostTask(FROM_HERE, | 60 main_task_runner_->PostTask(FROM_HERE, |
| 60 base::Bind(callback, std::move(channel))); | 61 base::Bind(callback, std::move(channel))); |
| 61 return; | 62 return; |
| 62 } | 63 } |
| 63 establish_callbacks_.push_back(callback); | 64 establish_callbacks_.push_back(callback); |
| 64 if (gpu_service_) | 65 if (gpu_service_) |
| 65 return; | 66 return; |
| 66 | 67 |
| 67 connector_->ConnectToInterface("ui", &gpu_service_); | 68 connector_->ConnectToInterface(ui::mojom::kServiceName, &gpu_service_); |
| 68 gpu_service_->EstablishGpuChannel( | 69 gpu_service_->EstablishGpuChannel( |
| 69 base::Bind(&GpuService::OnEstablishedGpuChannel, base::Unretained(this))); | 70 base::Bind(&GpuService::OnEstablishedGpuChannel, base::Unretained(this))); |
| 70 } | 71 } |
| 71 | 72 |
| 72 scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannelSync() { | 73 scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannelSync() { |
| 73 DCHECK(IsMainThread()); | 74 DCHECK(IsMainThread()); |
| 74 if (GetGpuChannel()) | 75 if (GetGpuChannel()) |
| 75 return gpu_channel_; | 76 return gpu_channel_; |
| 76 | 77 |
| 77 int client_id = 0; | 78 int client_id = 0; |
| 78 mojo::ScopedMessagePipeHandle channel_handle; | 79 mojo::ScopedMessagePipeHandle channel_handle; |
| 79 gpu::GPUInfo gpu_info; | 80 gpu::GPUInfo gpu_info; |
| 80 connector_->ConnectToInterface("ui", &gpu_service_); | 81 connector_->ConnectToInterface(ui::mojom::kServiceName, &gpu_service_); |
| 81 | 82 |
| 82 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 83 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
| 83 if (!gpu_service_->EstablishGpuChannel(&client_id, &channel_handle, | 84 if (!gpu_service_->EstablishGpuChannel(&client_id, &channel_handle, |
| 84 &gpu_info)) { | 85 &gpu_info)) { |
| 85 DLOG(WARNING) | 86 DLOG(WARNING) |
| 86 << "Channel encountered error while establishing gpu channel."; | 87 << "Channel encountered error while establishing gpu channel."; |
| 87 return nullptr; | 88 return nullptr; |
| 88 } | 89 } |
| 89 OnEstablishedGpuChannel(client_id, std::move(channel_handle), gpu_info); | 90 OnEstablishedGpuChannel(client_id, std::move(channel_handle), gpu_info); |
| 90 return gpu_channel_; | 91 return gpu_channel_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 146 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
| 146 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 147 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
| 147 if (result != MOJO_RESULT_OK) | 148 if (result != MOJO_RESULT_OK) |
| 148 return nullptr; | 149 return nullptr; |
| 149 DCHECK_EQ(shared_memory_size, size); | 150 DCHECK_EQ(shared_memory_size, size); |
| 150 | 151 |
| 151 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 152 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
| 152 } | 153 } |
| 153 | 154 |
| 154 } // namespace aura | 155 } // namespace aura |
| OLD | NEW |