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" | 7 #include "base/memory/shared_memory.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "gpu/ipc/client/gpu_channel_host.h" | 11 #include "gpu/ipc/client/gpu_channel_host.h" |
12 #include "services/shell/public/cpp/connection.h" | 12 #include "services/shell/public/cpp/connection.h" |
| 13 #include "services/ui/gpu/gpu_service_internal.h" |
13 #include "services/ui/ws/gpu_service_proxy_delegate.h" | 14 #include "services/ui/ws/gpu_service_proxy_delegate.h" |
14 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" | 15 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" |
15 | 16 |
16 namespace ui { | 17 namespace ui { |
17 namespace ws { | 18 namespace ws { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const int32_t kInternalGpuChannelClientId = 1; | 22 const int32_t kInternalGpuChannelClientId = 1; |
22 const uint64_t kInternalGpuChannelClientTracingId = 1; | 23 const uint64_t kInternalGpuChannelClientTracingId = 1; |
23 | 24 |
24 } // namespace | 25 } // namespace |
25 | 26 |
26 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) | 27 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) |
27 : delegate_(delegate), | 28 : delegate_(delegate), |
28 next_client_id_(kInternalGpuChannelClientId), | 29 next_client_id_(kInternalGpuChannelClientId), |
29 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 30 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
30 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 31 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
31 base::WaitableEvent::InitialState::NOT_SIGNALED) { | 32 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
32 // TODO(sad): Once GPU process is split, this would look like: | 33 // TODO(sad): Once GPU process is split, this would look like: |
33 // connector->ConnectToInterface("mojo:gpu", &gpu_service_); | 34 // connector->ConnectToInterface("mojo:gpu", &gpu_service_); |
34 gpu_main_.Add(GetProxy(&gpu_service_)); | 35 GpuServiceInternal::GetInstance()->Add(GetProxy(&gpu_service_)); |
35 gpu_service_->Initialize( | 36 gpu_service_->Initialize( |
36 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); | 37 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); |
37 } | 38 } |
38 | 39 |
39 GpuServiceProxy::~GpuServiceProxy() {} | 40 GpuServiceProxy::~GpuServiceProxy() {} |
40 | 41 |
41 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { | 42 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { |
42 bindings_.AddBinding(this, std::move(request)); | 43 bindings_.AddBinding(this, std::move(request)); |
43 } | 44 } |
44 | 45 |
45 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { | 46 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { |
46 gpu_info_ = gpu_info; | 47 gpu_info_ = gpu_info; |
47 | 48 |
48 constexpr bool is_gpu_host = true; | 49 constexpr bool is_gpu_host = true; |
49 gpu_service_->EstablishGpuChannel( | 50 gpu_service_->EstablishGpuChannel( |
50 kInternalGpuChannelClientId, kInternalGpuChannelClientTracingId, | 51 kInternalGpuChannelClientId, kInternalGpuChannelClientTracingId, |
51 is_gpu_host, base::Bind(&GpuServiceProxy::OnInternalGpuChannelEstablished, | 52 is_gpu_host, base::Bind(&GpuServiceProxy::OnInternalGpuChannelEstablished, |
52 base::Unretained(this))); | 53 base::Unretained(this))); |
53 next_client_id_ = kInternalGpuChannelClientId + 1; | 54 next_client_id_ = kInternalGpuChannelClientId + 1; |
54 } | 55 } |
55 | 56 |
56 void GpuServiceProxy::OnInternalGpuChannelEstablished( | 57 void GpuServiceProxy::OnInternalGpuChannelEstablished( |
57 mojo::ScopedMessagePipeHandle channel_handle) { | 58 mojo::ScopedMessagePipeHandle channel_handle) { |
58 io_thread_.reset(new base::Thread("GPUIOThread")); | 59 io_thread_.reset(new base::Thread("GPUIOThread")); |
59 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 60 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
60 thread_options.priority = base::ThreadPriority::NORMAL; | 61 thread_options.priority = base::ThreadPriority::NORMAL; |
61 CHECK(io_thread_->StartWithOptions(thread_options)); | 62 CHECK(io_thread_->StartWithOptions(thread_options)); |
62 | 63 |
63 gpu_memory_buffer_manager_.reset(new MusGpuMemoryBufferManager( | 64 gpu_memory_buffer_manager_.reset(new MusGpuMemoryBufferManager( |
64 gpu_main_.gpu_service(), kInternalGpuChannelClientId)); | 65 GpuServiceInternal::GetInstance(), kInternalGpuChannelClientId)); |
65 gpu_channel_ = gpu::GpuChannelHost::Create( | 66 gpu_channel_ = gpu::GpuChannelHost::Create( |
66 this, kInternalGpuChannelClientId, gpu_info_, | 67 this, kInternalGpuChannelClientId, gpu_info_, |
67 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, | 68 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, |
68 gpu_memory_buffer_manager_.get()); | 69 gpu_memory_buffer_manager_.get()); |
69 if (delegate_) | 70 if (delegate_) |
70 delegate_->OnGpuChannelEstablished(gpu_channel_); | 71 delegate_->OnGpuChannelEstablished(gpu_channel_); |
71 } | 72 } |
72 | 73 |
73 void GpuServiceProxy::OnGpuChannelEstablished( | 74 void GpuServiceProxy::OnGpuChannelEstablished( |
74 const EstablishGpuChannelCallback& callback, | 75 const EstablishGpuChannelCallback& callback, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( | 118 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( |
118 size_t size) { | 119 size_t size) { |
119 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 120 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
120 if (!shm->CreateAnonymous(size)) | 121 if (!shm->CreateAnonymous(size)) |
121 shm.reset(); | 122 shm.reset(); |
122 return shm; | 123 return shm; |
123 } | 124 } |
124 | 125 |
125 } // namespace ws | 126 } // namespace ws |
126 } // namespace ui | 127 } // namespace ui |
OLD | NEW |