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/public/cpp/gpu/gpu.h" | 5 #include "services/ui/public/cpp/gpu/gpu.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" | 10 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" |
11 #include "mojo/public/cpp/system/platform_handle.h" | 11 #include "mojo/public/cpp/system/platform_handle.h" |
12 #include "services/service_manager/public/cpp/connector.h" | 12 #include "services/service_manager/public/cpp/connector.h" |
13 #include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h" | 13 #include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h" |
14 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 14 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
15 #include "services/ui/public/interfaces/constants.mojom.h" | 15 #include "services/ui/public/interfaces/constants.mojom.h" |
16 #include "services/ui/public/interfaces/gpu.mojom.h" | 16 #include "services/ui/public/interfaces/gpu.mojom.h" |
17 | 17 |
18 namespace ui { | 18 namespace ui { |
19 | 19 |
20 Gpu::Gpu(service_manager::Connector* connector, | 20 Gpu::Gpu(service_manager::Connector* connector, |
21 service_manager::InterfaceProvider* provider, | 21 const std::string& service_name, |
22 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 22 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
23 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 23 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
24 io_task_runner_(std::move(task_runner)), | 24 io_task_runner_(std::move(task_runner)), |
25 connector_(connector), | 25 connector_(connector), |
26 interface_provider_(provider), | 26 service_name_(service_name), |
27 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 27 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
28 base::WaitableEvent::InitialState::NOT_SIGNALED) { | 28 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
29 DCHECK(main_task_runner_); | 29 DCHECK(main_task_runner_); |
30 DCHECK(connector_ || interface_provider_); | 30 DCHECK(connector_); |
31 mojom::GpuPtr gpu_ptr; | 31 mojom::GpuPtr gpu_ptr; |
32 if (connector_) | 32 connector_->BindInterface(service_name_, &gpu_ptr); |
33 connector_->BindInterface(ui::mojom::kServiceName, &gpu_ptr); | |
34 else | |
35 interface_provider_->GetInterface(&gpu_ptr); | |
36 gpu_memory_buffer_manager_ = | 33 gpu_memory_buffer_manager_ = |
37 base::MakeUnique<ClientGpuMemoryBufferManager>(std::move(gpu_ptr)); | 34 base::MakeUnique<ClientGpuMemoryBufferManager>(std::move(gpu_ptr)); |
38 if (!io_task_runner_) { | 35 if (!io_task_runner_) { |
39 io_thread_.reset(new base::Thread("GPUIOThread")); | 36 io_thread_.reset(new base::Thread("GPUIOThread")); |
40 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 37 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
41 thread_options.priority = base::ThreadPriority::NORMAL; | 38 thread_options.priority = base::ThreadPriority::NORMAL; |
42 CHECK(io_thread_->StartWithOptions(thread_options)); | 39 CHECK(io_thread_->StartWithOptions(thread_options)); |
43 io_task_runner_ = io_thread_->task_runner(); | 40 io_task_runner_ = io_thread_->task_runner(); |
44 } | 41 } |
45 } | 42 } |
46 | 43 |
47 Gpu::~Gpu() { | 44 Gpu::~Gpu() { |
48 DCHECK(IsMainThread()); | 45 DCHECK(IsMainThread()); |
49 shutdown_event_.Signal(); | 46 shutdown_event_.Signal(); |
50 if (gpu_channel_) | 47 if (gpu_channel_) |
51 gpu_channel_->DestroyChannel(); | 48 gpu_channel_->DestroyChannel(); |
52 } | 49 } |
53 | 50 |
54 // static | 51 // static |
55 std::unique_ptr<Gpu> Gpu::Create( | 52 std::unique_ptr<Gpu> Gpu::Create( |
56 service_manager::Connector* connector, | 53 service_manager::Connector* connector, |
| 54 const std::string& service_name, |
57 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 55 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
58 return base::WrapUnique(new Gpu(connector, nullptr, std::move(task_runner))); | 56 return base::WrapUnique( |
59 } | 57 new Gpu(connector, service_name, std::move(task_runner))); |
60 | |
61 std::unique_ptr<Gpu> Gpu::Create( | |
62 service_manager::InterfaceProvider* provider, | |
63 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
64 return base::WrapUnique(new Gpu(nullptr, provider, std::move(task_runner))); | |
65 } | 58 } |
66 | 59 |
67 scoped_refptr<cc::ContextProvider> Gpu::CreateContextProvider( | 60 scoped_refptr<cc::ContextProvider> Gpu::CreateContextProvider( |
68 scoped_refptr<gpu::GpuChannelHost> gpu_channel) { | 61 scoped_refptr<gpu::GpuChannelHost> gpu_channel) { |
69 constexpr bool automatic_flushes = false; | 62 constexpr bool automatic_flushes = false; |
70 constexpr bool support_locking = false; | 63 constexpr bool support_locking = false; |
71 gpu::gles2::ContextCreationAttribHelper attributes; | 64 gpu::gles2::ContextCreationAttribHelper attributes; |
72 attributes.alpha_size = -1; | 65 attributes.alpha_size = -1; |
73 attributes.depth_size = 0; | 66 attributes.depth_size = 0; |
74 attributes.stencil_size = 0; | 67 attributes.stencil_size = 0; |
(...skipping 16 matching lines...) Expand all Loading... |
91 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); | 84 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); |
92 if (channel) { | 85 if (channel) { |
93 main_task_runner_->PostTask(FROM_HERE, | 86 main_task_runner_->PostTask(FROM_HERE, |
94 base::Bind(callback, std::move(channel))); | 87 base::Bind(callback, std::move(channel))); |
95 return; | 88 return; |
96 } | 89 } |
97 establish_callbacks_.push_back(callback); | 90 establish_callbacks_.push_back(callback); |
98 if (gpu_) | 91 if (gpu_) |
99 return; | 92 return; |
100 | 93 |
101 if (connector_) | 94 connector_->BindInterface(service_name_, &gpu_); |
102 connector_->BindInterface(ui::mojom::kServiceName, &gpu_); | |
103 else | |
104 interface_provider_->GetInterface(&gpu_); | |
105 gpu_->EstablishGpuChannel( | 95 gpu_->EstablishGpuChannel( |
106 base::Bind(&Gpu::OnEstablishedGpuChannel, base::Unretained(this))); | 96 base::Bind(&Gpu::OnEstablishedGpuChannel, base::Unretained(this))); |
107 } | 97 } |
108 | 98 |
109 scoped_refptr<gpu::GpuChannelHost> Gpu::EstablishGpuChannelSync() { | 99 scoped_refptr<gpu::GpuChannelHost> Gpu::EstablishGpuChannelSync() { |
110 DCHECK(IsMainThread()); | 100 DCHECK(IsMainThread()); |
111 if (GetGpuChannel()) | 101 if (GetGpuChannel()) |
112 return gpu_channel_; | 102 return gpu_channel_; |
113 | 103 |
114 int client_id = 0; | 104 int client_id = 0; |
115 mojo::ScopedMessagePipeHandle channel_handle; | 105 mojo::ScopedMessagePipeHandle channel_handle; |
116 gpu::GPUInfo gpu_info; | 106 gpu::GPUInfo gpu_info; |
117 if (connector_) | 107 connector_->BindInterface(service_name_, &gpu_); |
118 connector_->BindInterface(ui::mojom::kServiceName, &gpu_); | |
119 else | |
120 interface_provider_->GetInterface(&gpu_); | |
121 | 108 |
122 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; | 109 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; |
123 if (!gpu_->EstablishGpuChannel(&client_id, &channel_handle, &gpu_info)) { | 110 if (!gpu_->EstablishGpuChannel(&client_id, &channel_handle, &gpu_info)) { |
124 DLOG(WARNING) | 111 DLOG(WARNING) |
125 << "Channel encountered error while establishing gpu channel."; | 112 << "Channel encountered error while establishing gpu channel."; |
126 return nullptr; | 113 return nullptr; |
127 } | 114 } |
128 OnEstablishedGpuChannel(client_id, std::move(channel_handle), gpu_info); | 115 OnEstablishedGpuChannel(client_id, std::move(channel_handle), gpu_info); |
129 return gpu_channel_; | 116 return gpu_channel_; |
130 } | 117 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 168 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
182 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 169 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
183 if (result != MOJO_RESULT_OK) | 170 if (result != MOJO_RESULT_OK) |
184 return nullptr; | 171 return nullptr; |
185 DCHECK_EQ(shared_memory_size, size); | 172 DCHECK_EQ(shared_memory_size, size); |
186 | 173 |
187 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 174 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
188 } | 175 } |
189 | 176 |
190 } // namespace ui | 177 } // namespace ui |
OLD | NEW |