OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "services/ui/ws/gpu_service_proxy.h" | |
6 | |
7 #include "base/memory/shared_memory.h" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "base/run_loop.h" | |
10 #include "base/threading/thread_task_runner_handle.h" | |
11 #include "gpu/ipc/client/gpu_channel_host.h" | |
12 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" | |
13 #include "mojo/public/cpp/bindings/strong_binding.h" | |
14 #include "mojo/public/cpp/system/buffer.h" | |
15 #include "mojo/public/cpp/system/platform_handle.h" | |
16 #include "services/service_manager/public/cpp/connection.h" | |
17 #include "services/ui/common/server_gpu_memory_buffer_manager.h" | |
18 #include "services/ui/ws/gpu_service_proxy_delegate.h" | |
19 #include "ui/gfx/buffer_format_util.h" | |
20 | |
21 namespace ui { | |
22 namespace ws { | |
23 | |
24 namespace { | |
25 | |
26 // The client Id 1 is reserved for the display compositor. | |
27 const int32_t kInternalGpuChannelClientId = 2; | |
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::Gpu { | |
32 public: | |
33 GpuServiceImpl(int client_id, | |
34 gpu::GPUInfo* gpu_info, | |
35 ServerGpuMemoryBufferManager* 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::Gpu 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::Gpu::CreateGpuMemoryBufferCallback& callback) override { | |
73 auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle( | |
74 id, client_id_, size, format, usage, gpu::kNullSurfaceHandle); | |
75 callback.Run(handle); | |
76 } | |
77 | |
78 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | |
79 const gpu::SyncToken& sync_token) override { | |
80 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_, | |
81 sync_token); | |
82 } | |
83 | |
84 const int client_id_; | |
85 | |
86 // The objects these pointers refer to are owned by the GpuServiceProxy | |
87 // object. | |
88 const gpu::GPUInfo* gpu_info_; | |
89 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager_; | |
90 mojom::GpuServiceInternal* gpu_service_internal_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(GpuServiceImpl); | |
93 }; | |
94 | |
95 } // namespace | |
96 | |
97 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) | |
98 : delegate_(delegate), | |
99 next_client_id_(kInternalGpuChannelClientId + 1), | |
100 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | |
101 gpu_host_binding_(this) { | |
102 gpu_main_impl_ = base::MakeUnique<GpuMain>(GetProxy(&gpu_main_)); | |
103 gpu_main_impl_->OnStart(); | |
104 // TODO(sad): Once GPU process is split, this would look like: | |
105 // connector->ConnectToInterface("gpu", &gpu_main_); | |
106 gpu_main_->CreateGpuService(GetProxy(&gpu_service_), | |
107 gpu_host_binding_.CreateInterfacePtrAndBind()); | |
108 gpu_memory_buffer_manager_ = base::MakeUnique<ServerGpuMemoryBufferManager>( | |
109 gpu_service_.get(), next_client_id_++); | |
110 } | |
111 | |
112 GpuServiceProxy::~GpuServiceProxy() { | |
113 } | |
114 | |
115 void GpuServiceProxy::Add(mojom::GpuRequest 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)); | |
121 } | |
122 | |
123 void GpuServiceProxy::CreateDisplayCompositor( | |
124 cc::mojom::DisplayCompositorRequest request, | |
125 cc::mojom::DisplayCompositorClientPtr client) { | |
126 gpu_main_->CreateDisplayCompositor(std::move(request), std::move(client)); | |
127 } | |
128 | |
129 void GpuServiceProxy::DidInitialize(const gpu::GPUInfo& gpu_info) { | |
130 gpu_info_ = gpu_info; | |
131 delegate_->OnGpuServiceInitialized(); | |
132 } | |
133 | |
134 void GpuServiceProxy::DidCreateOffscreenContext(const GURL& url) {} | |
135 | |
136 void GpuServiceProxy::DidDestroyOffscreenContext(const GURL& url) {} | |
137 | |
138 void GpuServiceProxy::DidDestroyChannel(int32_t client_id) {} | |
139 | |
140 void GpuServiceProxy::DidLoseContext(bool offscreen, | |
141 gpu::error::ContextLostReason reason, | |
142 const GURL& active_url) {} | |
143 | |
144 void GpuServiceProxy::StoreShaderToDisk(int32_t client_id, | |
145 const std::string& key, | |
146 const std::string& shader) {} | |
147 | |
148 } // namespace ws | |
149 } // namespace ui | |
OLD | NEW |