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

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

Issue 2503113002: mus: Get GpuMemoryBuffer from gpu process when possible. (Closed)
Patch Set: . Created 4 years 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/bindings/strong_binding.h"
13 #include "mojo/public/cpp/system/buffer.h" 14 #include "mojo/public/cpp/system/buffer.h"
14 #include "mojo/public/cpp/system/platform_handle.h" 15 #include "mojo/public/cpp/system/platform_handle.h"
15 #include "services/service_manager/public/cpp/connection.h" 16 #include "services/service_manager/public/cpp/connection.h"
16 #include "services/ui/common/mus_gpu_memory_buffer_manager.h" 17 #include "services/ui/common/mus_gpu_memory_buffer_manager.h"
17 #include "services/ui/ws/gpu_service_proxy_delegate.h" 18 #include "services/ui/ws/gpu_service_proxy_delegate.h"
18 #include "ui/gfx/buffer_format_util.h" 19 #include "ui/gfx/buffer_format_util.h"
19 20
20 namespace ui { 21 namespace ui {
21 namespace ws { 22 namespace ws {
22 23
23 namespace { 24 namespace {
24 25
25 // The client Id 1 is reserved for the display compositor. 26 // The client Id 1 is reserved for the display compositor.
26 const int32_t kInternalGpuChannelClientId = 2; 27 const int32_t kInternalGpuChannelClientId = 2;
27 28
29 // The implementation that relays requests from clients to the real
30 // service implementation in the GPU process over mojom.GpuServiceInternal.
31 class GpuServiceImpl : public mojom::GpuService {
32 public:
33 GpuServiceImpl(int client_id,
34 gpu::GPUInfo* gpu_info,
35 MusGpuMemoryBufferManager* gpu_memory_buffer_manager,
36 mojom::GpuServiceInternal* gpu_service_internal)
37 : client_id_(client_id),
38 gpu_info_(gpu_info),
39 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
40 gpu_service_internal_(gpu_service_internal) {
41 DCHECK(gpu_memory_buffer_manager_);
42 DCHECK(gpu_service_internal_);
43 }
44 ~GpuServiceImpl() override {}
45
46 private:
47 void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback,
48 mojo::ScopedMessagePipeHandle channel_handle) {
49 callback.Run(client_id_, std::move(channel_handle), *gpu_info_);
50 }
51
52 // mojom::GpuService overrides:
53 void EstablishGpuChannel(
54 const EstablishGpuChannelCallback& callback) override {
55 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful
56 // tracing id.
57 const uint64_t client_tracing_id = 0;
58 constexpr bool is_gpu_host = false;
59 gpu_service_internal_->EstablishGpuChannel(
60 client_id_, client_tracing_id, is_gpu_host,
61 base::Bind(&GpuServiceImpl::OnGpuChannelEstablished,
62 base::Unretained(this), callback));
63 }
64
65 void CreateGpuMemoryBuffer(
66 gfx::GpuMemoryBufferId id,
67 const gfx::Size& size,
68 gfx::BufferFormat format,
69 gfx::BufferUsage usage,
70 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback)
71 override {
72 auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle(
73 id, client_id_, size, format, usage, gpu::kNullSurfaceHandle);
74 callback.Run(handle);
75 }
76
77 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
78 const gpu::SyncToken& sync_token) override {
79 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_,
80 sync_token);
81 }
82
83 const int client_id_;
84
85 // The objects these pointers refer to are owned by the GpuServiceProxy
86 // object.
87 const gpu::GPUInfo* gpu_info_;
88 MusGpuMemoryBufferManager* gpu_memory_buffer_manager_;
89 mojom::GpuServiceInternal* gpu_service_internal_;
90
91 DISALLOW_COPY_AND_ASSIGN(GpuServiceImpl);
92 };
93
28 } // namespace 94 } // namespace
29 95
30 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) 96 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate)
31 : delegate_(delegate), 97 : delegate_(delegate),
32 next_client_id_(kInternalGpuChannelClientId + 1), 98 next_client_id_(kInternalGpuChannelClientId + 1),
33 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) { 99 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {
34 gpu_main_.OnStart(); 100 gpu_main_.OnStart();
35 // TODO(sad): Once GPU process is split, this would look like: 101 // TODO(sad): Once GPU process is split, this would look like:
36 // connector->ConnectToInterface("gpu", &gpu_service_); 102 // connector->ConnectToInterface("gpu", &gpu_service_);
37 gpu_main_.Create(GetProxy(&gpu_service_)); 103 gpu_main_.Create(GetProxy(&gpu_service_));
38 gpu_service_->Initialize( 104 gpu_service_->Initialize(
39 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); 105 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this)));
40 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>( 106 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>(
41 gpu_service_.get(), next_client_id_++); 107 gpu_service_.get(), next_client_id_++);
42 } 108 }
43 109
44 GpuServiceProxy::~GpuServiceProxy() { 110 GpuServiceProxy::~GpuServiceProxy() {
45 } 111 }
46 112
47 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { 113 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) {
48 bindings_.AddBinding(this, std::move(request)); 114 mojo::MakeStrongBinding(
115 base::MakeUnique<GpuServiceImpl>(next_client_id_++, &gpu_info_,
116 gpu_memory_buffer_manager_.get(),
117 gpu_service_.get()),
118 std::move(request));
49 } 119 }
50 120
51 void GpuServiceProxy::CreateDisplayCompositor( 121 void GpuServiceProxy::CreateDisplayCompositor(
52 cc::mojom::DisplayCompositorRequest request, 122 cc::mojom::DisplayCompositorRequest request,
53 cc::mojom::DisplayCompositorClientPtr client) { 123 cc::mojom::DisplayCompositorClientPtr client) {
54 gpu_service_->CreateDisplayCompositor(std::move(request), std::move(client)); 124 gpu_service_->CreateDisplayCompositor(std::move(request), std::move(client));
55 } 125 }
56 126
57 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { 127 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) {
58 gpu_info_ = gpu_info; 128 gpu_info_ = gpu_info;
59
60 delegate_->OnGpuServiceInitialized(); 129 delegate_->OnGpuServiceInitialized();
61 } 130 }
62 131
63 void GpuServiceProxy::OnGpuChannelEstablished(
64 const EstablishGpuChannelCallback& callback,
65 int32_t client_id,
66 mojo::ScopedMessagePipeHandle channel_handle) {
67 callback.Run(client_id, std::move(channel_handle), gpu_info_);
68 }
69
70 void GpuServiceProxy::EstablishGpuChannel(
71 const EstablishGpuChannelCallback& callback) {
72 const int client_id = next_client_id_++;
73 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful tracing
74 // id.
75 const uint64_t client_tracing_id = 0;
76 constexpr bool is_gpu_host = false;
77 gpu_service_->EstablishGpuChannel(
78 client_id, client_tracing_id, is_gpu_host,
79 base::Bind(&GpuServiceProxy::OnGpuChannelEstablished,
80 base::Unretained(this), callback, client_id));
81 }
82
83 void GpuServiceProxy::CreateGpuMemoryBuffer(
84 gfx::GpuMemoryBufferId id,
85 const gfx::Size& size,
86 gfx::BufferFormat format,
87 gfx::BufferUsage usage,
88 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) {
89 // TODO(sad): Check to see if native gpu memory buffer can be used first.
90 if (!gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage) ||
91 !gpu::GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat(size,
92 format)) {
93 callback.Run(gfx::GpuMemoryBufferHandle());
94 return;
95 }
96 callback.Run(gpu::GpuMemoryBufferImplSharedMemory::CreateGpuMemoryBuffer(
97 id, size, format));
98 }
99
100 void GpuServiceProxy::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
101 const gpu::SyncToken& sync_token) {
102 // NOTIMPLEMENTED();
103 }
104
105 } // namespace ws 132 } // namespace ws
106 } // namespace ui 133 } // namespace ui
OLDNEW
« services/ui/common/mus_gpu_memory_buffer_manager.h ('K') | « services/ui/ws/gpu_service_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698