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 "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" | 12 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" |
13 #include "mojo/public/cpp/system/buffer.h" | 13 #include "mojo/public/cpp/system/buffer.h" |
14 #include "mojo/public/cpp/system/platform_handle.h" | 14 #include "mojo/public/cpp/system/platform_handle.h" |
15 #include "services/service_manager/public/cpp/connection.h" | 15 #include "services/service_manager/public/cpp/connection.h" |
16 #include "services/ui/ws/gpu_service_proxy_delegate.h" | 16 #include "services/ui/ws/gpu_service_proxy_delegate.h" |
17 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" | |
18 #include "ui/gfx/buffer_format_util.h" | 17 #include "ui/gfx/buffer_format_util.h" |
19 | 18 |
20 namespace ui { | 19 namespace ui { |
21 namespace ws { | 20 namespace ws { |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 const int32_t kInternalGpuChannelClientId = 1; | 24 // The client Id 1 is reserved for the display compositor. |
26 const uint64_t kInternalGpuChannelClientTracingId = 1; | 25 const int32_t kInternalGpuChannelClientId = 2; |
27 | 26 |
28 } // namespace | 27 } // namespace |
29 | 28 |
30 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) | 29 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) |
31 : delegate_(delegate), | 30 : delegate_(delegate), |
32 next_client_id_(kInternalGpuChannelClientId + 1), | 31 next_client_id_(kInternalGpuChannelClientId + 1), |
33 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 32 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
34 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 33 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
35 base::WaitableEvent::InitialState::NOT_SIGNALED) { | 34 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
36 gpu_main_.OnStart(); | 35 gpu_main_.OnStart(); |
37 // TODO(sad): Once GPU process is split, this would look like: | 36 // TODO(sad): Once GPU process is split, this would look like: |
38 // connector->ConnectToInterface("gpu", &gpu_service_); | 37 // connector->ConnectToInterface("gpu", &gpu_service_); |
39 gpu_main_.Create(GetProxy(&gpu_service_)); | 38 gpu_main_.Create(GetProxy(&gpu_service_)); |
40 gpu_service_->Initialize( | 39 gpu_service_->Initialize( |
41 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); | 40 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); |
42 } | 41 } |
43 | 42 |
44 GpuServiceProxy::~GpuServiceProxy() { | 43 GpuServiceProxy::~GpuServiceProxy() { |
45 if (gpu_channel_) | 44 if (gpu_channel_) |
46 gpu_channel_->DestroyChannel(); | 45 gpu_channel_->DestroyChannel(); |
47 } | 46 } |
48 | 47 |
49 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { | 48 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { |
50 bindings_.AddBinding(this, std::move(request)); | 49 bindings_.AddBinding(this, std::move(request)); |
51 } | 50 } |
52 | 51 |
52 void GpuServiceProxy::CreateDisplayCompositor( | |
53 cc::mojom::DisplayCompositorRequest request, | |
54 cc::mojom::DisplayCompositorClientPtr client) { | |
55 gpu_service_->CreateDisplayCompositor(std::move(request), std::move(client)); | |
56 } | |
57 | |
53 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { | 58 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { |
54 gpu_info_ = gpu_info; | 59 gpu_info_ = gpu_info; |
55 | 60 |
56 constexpr bool is_gpu_host = true; | 61 // TODO(fsamuel): What is this thread used for? |
sadrul
2016/11/21 17:23:49
See comment in .h
Fady Samuel
2016/11/21 20:40:41
Deleted.
| |
57 gpu_service_->EstablishGpuChannel( | |
58 kInternalGpuChannelClientId, kInternalGpuChannelClientTracingId, | |
59 is_gpu_host, base::Bind(&GpuServiceProxy::OnInternalGpuChannelEstablished, | |
60 base::Unretained(this))); | |
61 } | |
62 | |
63 void GpuServiceProxy::OnInternalGpuChannelEstablished( | |
64 mojo::ScopedMessagePipeHandle channel_handle) { | |
65 io_thread_ = base::MakeUnique<base::Thread>("GPUIOThread"); | 62 io_thread_ = base::MakeUnique<base::Thread>("GPUIOThread"); |
66 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 63 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
67 thread_options.priority = base::ThreadPriority::NORMAL; | 64 thread_options.priority = base::ThreadPriority::NORMAL; |
68 CHECK(io_thread_->StartWithOptions(thread_options)); | 65 CHECK(io_thread_->StartWithOptions(thread_options)); |
69 | 66 |
70 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>( | 67 delegate_->OnGpuServiceInitialized(); |
71 gpu_service_.get(), kInternalGpuChannelClientId); | |
72 gpu_channel_ = gpu::GpuChannelHost::Create( | |
73 this, kInternalGpuChannelClientId, gpu_info_, | |
74 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, | |
75 gpu_memory_buffer_manager_.get()); | |
76 if (delegate_) | |
77 delegate_->OnGpuChannelEstablished(gpu_channel_); | |
78 } | 68 } |
79 | 69 |
80 void GpuServiceProxy::OnGpuChannelEstablished( | 70 void GpuServiceProxy::OnGpuChannelEstablished( |
81 const EstablishGpuChannelCallback& callback, | 71 const EstablishGpuChannelCallback& callback, |
82 int32_t client_id, | 72 int32_t client_id, |
83 mojo::ScopedMessagePipeHandle channel_handle) { | 73 mojo::ScopedMessagePipeHandle channel_handle) { |
84 callback.Run(client_id, std::move(channel_handle), gpu_info_); | 74 callback.Run(client_id, std::move(channel_handle), gpu_info_); |
85 } | 75 } |
86 | 76 |
87 void GpuServiceProxy::EstablishGpuChannel( | 77 void GpuServiceProxy::EstablishGpuChannel( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( | 121 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( |
132 size_t size) { | 122 size_t size) { |
133 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 123 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
134 if (!shm->CreateAnonymous(size)) | 124 if (!shm->CreateAnonymous(size)) |
135 shm.reset(); | 125 shm.reset(); |
136 return shm; | 126 return shm; |
137 } | 127 } |
138 | 128 |
139 } // namespace ws | 129 } // namespace ws |
140 } // namespace ui | 130 } // namespace ui |
OLD | NEW |