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

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 gpu_memory_buffer_manager_->DestroyAllGpuMemoryBufferForClient(client_id_);
46 }
47
48 private:
49 void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback,
50 mojo::ScopedMessagePipeHandle channel_handle) {
51 callback.Run(client_id_, std::move(channel_handle), *gpu_info_);
52 }
53
54 // mojom::GpuService overrides:
55 void EstablishGpuChannel(
56 const EstablishGpuChannelCallback& callback) override {
57 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful
58 // tracing id.
59 const uint64_t client_tracing_id = 0;
60 constexpr bool is_gpu_host = false;
61 gpu_service_internal_->EstablishGpuChannel(
62 client_id_, client_tracing_id, is_gpu_host,
63 base::Bind(&GpuServiceImpl::OnGpuChannelEstablished,
64 base::Unretained(this), callback));
65 }
66
67 void CreateGpuMemoryBuffer(
68 gfx::GpuMemoryBufferId id,
69 const gfx::Size& size,
70 gfx::BufferFormat format,
71 gfx::BufferUsage usage,
72 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback)
73 override {
74 auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle(
75 id, client_id_, size, format, usage, gpu::kNullSurfaceHandle);
76 callback.Run(handle);
77 }
78
79 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
80 const gpu::SyncToken& sync_token) override {
81 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_,
82 sync_token);
83 }
84
85 const int client_id_;
86
87 // The objects these pointers refer to are owned by the GpuServiceProxy
88 // object.
89 const gpu::GPUInfo* gpu_info_;
90 MusGpuMemoryBufferManager* gpu_memory_buffer_manager_;
91 mojom::GpuServiceInternal* gpu_service_internal_;
92
93 DISALLOW_COPY_AND_ASSIGN(GpuServiceImpl);
94 };
95
28 } // namespace 96 } // namespace
29 97
30 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) 98 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate)
31 : delegate_(delegate), 99 : delegate_(delegate),
32 next_client_id_(kInternalGpuChannelClientId + 1), 100 next_client_id_(kInternalGpuChannelClientId + 1),
33 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) { 101 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {
34 gpu_main_.OnStart(); 102 gpu_main_.OnStart();
35 // TODO(sad): Once GPU process is split, this would look like: 103 // TODO(sad): Once GPU process is split, this would look like:
36 // connector->ConnectToInterface("gpu", &gpu_service_); 104 // connector->ConnectToInterface("gpu", &gpu_service_);
37 gpu_main_.Create(GetProxy(&gpu_service_)); 105 gpu_main_.Create(GetProxy(&gpu_service_));
38 gpu_service_->Initialize( 106 gpu_service_->Initialize(
39 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); 107 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this)));
40 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>( 108 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>(
41 gpu_service_.get(), next_client_id_++); 109 gpu_service_.get(), next_client_id_++);
42 } 110 }
43 111
44 GpuServiceProxy::~GpuServiceProxy() { 112 GpuServiceProxy::~GpuServiceProxy() {
45 } 113 }
46 114
47 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { 115 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) {
48 bindings_.AddBinding(this, std::move(request)); 116 mojo::MakeStrongBinding(
117 base::MakeUnique<GpuServiceImpl>(next_client_id_++, &gpu_info_,
118 gpu_memory_buffer_manager_.get(),
119 gpu_service_.get()),
120 std::move(request));
49 } 121 }
50 122
51 void GpuServiceProxy::CreateDisplayCompositor( 123 void GpuServiceProxy::CreateDisplayCompositor(
52 cc::mojom::DisplayCompositorRequest request, 124 cc::mojom::DisplayCompositorRequest request,
53 cc::mojom::DisplayCompositorClientPtr client) { 125 cc::mojom::DisplayCompositorClientPtr client) {
54 gpu_service_->CreateDisplayCompositor(std::move(request), std::move(client)); 126 gpu_service_->CreateDisplayCompositor(std::move(request), std::move(client));
55 } 127 }
56 128
57 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { 129 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) {
58 gpu_info_ = gpu_info; 130 gpu_info_ = gpu_info;
59
60 delegate_->OnGpuServiceInitialized(); 131 delegate_->OnGpuServiceInitialized();
61 } 132 }
62 133
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 134 } // namespace ws
106 } // namespace ui 135 } // namespace ui
OLDNEW
« services/ui/common/mus_gpu_memory_buffer_manager.cc ('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