Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: services/ui/ws/gpu_service_proxy.cc

Issue 2481263002: Introduce Display Compositor mojo interface. Use InProcessContextProvider. (Closed)
Patch Set: Speculative fix for android build issue Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
35 base::WaitableEvent::InitialState::NOT_SIGNALED) {
36 gpu_main_.OnStart(); 33 gpu_main_.OnStart();
37 // TODO(sad): Once GPU process is split, this would look like: 34 // TODO(sad): Once GPU process is split, this would look like:
38 // connector->ConnectToInterface("gpu", &gpu_service_); 35 // connector->ConnectToInterface("gpu", &gpu_service_);
39 gpu_main_.Create(GetProxy(&gpu_service_)); 36 gpu_main_.Create(GetProxy(&gpu_service_));
40 gpu_service_->Initialize( 37 gpu_service_->Initialize(
41 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); 38 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this)));
42 } 39 }
43 40
44 GpuServiceProxy::~GpuServiceProxy() { 41 GpuServiceProxy::~GpuServiceProxy() {
45 if (gpu_channel_)
46 gpu_channel_->DestroyChannel();
47 } 42 }
48 43
49 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { 44 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) {
50 bindings_.AddBinding(this, std::move(request)); 45 bindings_.AddBinding(this, std::move(request));
51 } 46 }
52 47
48 void GpuServiceProxy::CreateDisplayCompositor(
49 cc::mojom::DisplayCompositorRequest request,
50 cc::mojom::DisplayCompositorClientPtr client) {
51 gpu_service_->CreateDisplayCompositor(std::move(request), std::move(client));
52 }
53
53 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { 54 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) {
54 gpu_info_ = gpu_info; 55 gpu_info_ = gpu_info;
55 56
56 constexpr bool is_gpu_host = true; 57 delegate_->OnGpuServiceInitialized();
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");
66 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
67 thread_options.priority = base::ThreadPriority::NORMAL;
68 CHECK(io_thread_->StartWithOptions(thread_options));
69
70 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>(
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 } 58 }
79 59
80 void GpuServiceProxy::OnGpuChannelEstablished( 60 void GpuServiceProxy::OnGpuChannelEstablished(
81 const EstablishGpuChannelCallback& callback, 61 const EstablishGpuChannelCallback& callback,
82 int32_t client_id, 62 int32_t client_id,
83 mojo::ScopedMessagePipeHandle channel_handle) { 63 mojo::ScopedMessagePipeHandle channel_handle) {
84 callback.Run(client_id, std::move(channel_handle), gpu_info_); 64 callback.Run(client_id, std::move(channel_handle), gpu_info_);
85 } 65 }
86 66
87 void GpuServiceProxy::EstablishGpuChannel( 67 void GpuServiceProxy::EstablishGpuChannel(
(...skipping 24 matching lines...) Expand all
112 } 92 }
113 callback.Run(gpu::GpuMemoryBufferImplSharedMemory::AllocateGpuMemoryBuffer( 93 callback.Run(gpu::GpuMemoryBufferImplSharedMemory::AllocateGpuMemoryBuffer(
114 id, size, format)); 94 id, size, format));
115 } 95 }
116 96
117 void GpuServiceProxy::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, 97 void GpuServiceProxy::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
118 const gpu::SyncToken& sync_token) { 98 const gpu::SyncToken& sync_token) {
119 // NOTIMPLEMENTED(); 99 // NOTIMPLEMENTED();
120 } 100 }
121 101
122 bool GpuServiceProxy::IsMainThread() {
123 return main_thread_task_runner_->BelongsToCurrentThread();
124 }
125
126 scoped_refptr<base::SingleThreadTaskRunner>
127 GpuServiceProxy::GetIOThreadTaskRunner() {
128 return io_thread_->task_runner();
129 }
130
131 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory(
132 size_t size) {
133 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
134 if (!shm->CreateAnonymous(size))
135 shm.reset();
136 return shm;
137 }
138
139 } // namespace ws 102 } // namespace ws
140 } // namespace ui 103 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698