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/ws/gpu_service_proxy.h" | 5 #include "services/ui/ws/gpu_service_proxy.h" |
6 | 6 |
| 7 #include "base/memory/shared_memory.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "gpu/ipc/client/gpu_channel_host.h" |
7 #include "services/shell/public/cpp/connection.h" | 12 #include "services/shell/public/cpp/connection.h" |
8 #include "services/ui/common/gpu_type_converters.h" | 13 #include "services/ui/common/gpu_type_converters.h" |
9 #include "services/ui/gpu/gpu_service_internal.h" | 14 #include "services/ui/gpu/gpu_service_internal.h" |
| 15 #include "services/ui/ws/gpu_service_proxy_delegate.h" |
| 16 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" |
10 | 17 |
11 namespace ui { | 18 namespace ui { |
| 19 namespace ws { |
12 | 20 |
13 namespace { | 21 namespace { |
14 | 22 |
15 const int32_t kLocalGpuChannelClientId = 1; | 23 const int32_t kInternalGpuChannelClientId = 1; |
| 24 const uint64_t kInternalGpuChannelClientTracingId = 1; |
16 | 25 |
17 } // namespace | 26 } // namespace |
18 | 27 |
19 GpuServiceProxy::GpuServiceProxy() : next_client_id_(kLocalGpuChannelClientId) { | 28 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) |
| 29 : delegate_(delegate), |
| 30 next_client_id_(kInternalGpuChannelClientId), |
| 31 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 32 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 33 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
20 // TODO(sad): Once GPU process is split, this would look like: | 34 // TODO(sad): Once GPU process is split, this would look like: |
21 // connector->ConnectToInterface("mojo:gpu", &gpu_service_); | 35 // connector->ConnectToInterface("mojo:gpu", &gpu_service_); |
22 GpuServiceInternal::GetInstance()->Add(GetProxy(&gpu_service_)); | 36 GpuServiceInternal::GetInstance()->Add(GetProxy(&gpu_service_)); |
23 gpu_service_->Initialize( | 37 gpu_service_->Initialize( |
24 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); | 38 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); |
25 } | 39 } |
26 | 40 |
27 GpuServiceProxy::~GpuServiceProxy() {} | 41 GpuServiceProxy::~GpuServiceProxy() {} |
28 | 42 |
29 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { | 43 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { |
30 bindings_.AddBinding(this, std::move(request)); | 44 bindings_.AddBinding(this, std::move(request)); |
31 } | 45 } |
32 | 46 |
33 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { | 47 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { |
34 gpu_info_ = gpu_info; | 48 gpu_info_ = gpu_info; |
| 49 |
| 50 constexpr bool is_gpu_host = true; |
| 51 gpu_service_->EstablishGpuChannel( |
| 52 kInternalGpuChannelClientId, kInternalGpuChannelClientTracingId, |
| 53 is_gpu_host, base::Bind(&GpuServiceProxy::OnInternalGpuChannelEstablished, |
| 54 base::Unretained(this))); |
| 55 next_client_id_ = kInternalGpuChannelClientId + 1; |
| 56 } |
| 57 |
| 58 void GpuServiceProxy::OnInternalGpuChannelEstablished( |
| 59 mojo::ScopedMessagePipeHandle channel_handle) { |
| 60 io_thread_.reset(new base::Thread("GPUIOThread")); |
| 61 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 62 thread_options.priority = base::ThreadPriority::NORMAL; |
| 63 CHECK(io_thread_->StartWithOptions(thread_options)); |
| 64 |
| 65 gpu_memory_buffer_manager_.reset(new MusGpuMemoryBufferManager( |
| 66 GpuServiceInternal::GetInstance(), kInternalGpuChannelClientId)); |
| 67 gpu_channel_ = gpu::GpuChannelHost::Create( |
| 68 this, kInternalGpuChannelClientId, gpu_info_, |
| 69 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, |
| 70 gpu_memory_buffer_manager_.get()); |
| 71 if (delegate_) |
| 72 delegate_->OnGpuChannelEstablished(gpu_channel_); |
35 } | 73 } |
36 | 74 |
37 void GpuServiceProxy::OnGpuChannelEstablished( | 75 void GpuServiceProxy::OnGpuChannelEstablished( |
38 const EstablishGpuChannelCallback& callback, | 76 const EstablishGpuChannelCallback& callback, |
39 int32_t client_id, | 77 int32_t client_id, |
40 mojo::ScopedMessagePipeHandle channel_handle) { | 78 mojo::ScopedMessagePipeHandle channel_handle) { |
41 callback.Run(client_id, std::move(channel_handle), gpu_info_); | 79 callback.Run(client_id, std::move(channel_handle), gpu_info_); |
42 } | 80 } |
43 | 81 |
44 void GpuServiceProxy::EstablishGpuChannel( | 82 void GpuServiceProxy::EstablishGpuChannel( |
45 const EstablishGpuChannelCallback& callback) { | 83 const EstablishGpuChannelCallback& callback) { |
46 const int client_id = ++next_client_id_; | 84 const int client_id = ++next_client_id_; |
47 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful tracing | 85 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful tracing |
48 // id. | 86 // id. |
49 const uint64_t client_tracing_id = 0; | 87 const uint64_t client_tracing_id = 0; |
| 88 constexpr bool is_gpu_host = false; |
50 gpu_service_->EstablishGpuChannel( | 89 gpu_service_->EstablishGpuChannel( |
51 client_id, client_tracing_id, | 90 client_id, client_tracing_id, is_gpu_host, |
52 base::Bind(&GpuServiceProxy::OnGpuChannelEstablished, | 91 base::Bind(&GpuServiceProxy::OnGpuChannelEstablished, |
53 base::Unretained(this), callback, client_id)); | 92 base::Unretained(this), callback, client_id)); |
54 } | 93 } |
55 | 94 |
56 void GpuServiceProxy::CreateGpuMemoryBuffer( | 95 void GpuServiceProxy::CreateGpuMemoryBuffer( |
57 mojom::GpuMemoryBufferIdPtr id, | 96 mojom::GpuMemoryBufferIdPtr id, |
58 const gfx::Size& size, | 97 const gfx::Size& size, |
59 gfx::BufferFormat format, | 98 gfx::BufferFormat format, |
60 gfx::BufferUsage usage, | 99 gfx::BufferUsage usage, |
61 uint64_t surface_id, | 100 uint64_t surface_id, |
62 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) { | 101 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) { |
63 NOTIMPLEMENTED(); | 102 NOTIMPLEMENTED(); |
64 } | 103 } |
65 | 104 |
66 void GpuServiceProxy::DestroyGpuMemoryBuffer(mojom::GpuMemoryBufferIdPtr id, | 105 void GpuServiceProxy::DestroyGpuMemoryBuffer(mojom::GpuMemoryBufferIdPtr id, |
67 const gpu::SyncToken& sync_token) { | 106 const gpu::SyncToken& sync_token) { |
68 NOTIMPLEMENTED(); | 107 NOTIMPLEMENTED(); |
69 } | 108 } |
70 | 109 |
| 110 bool GpuServiceProxy::IsMainThread() { |
| 111 return main_thread_task_runner_->BelongsToCurrentThread(); |
| 112 } |
| 113 |
| 114 scoped_refptr<base::SingleThreadTaskRunner> |
| 115 GpuServiceProxy::GetIOThreadTaskRunner() { |
| 116 return io_thread_->task_runner(); |
| 117 } |
| 118 |
| 119 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( |
| 120 size_t size) { |
| 121 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
| 122 if (!shm->CreateAnonymous(size)) |
| 123 shm.reset(); |
| 124 return shm; |
| 125 } |
| 126 |
| 127 } // namespace ws |
71 } // namespace ui | 128 } // namespace ui |
OLD | NEW |