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_host.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/bindings/strong_binding.h" |
14 #include "mojo/public/cpp/system/buffer.h" | 14 #include "mojo/public/cpp/system/buffer.h" |
15 #include "mojo/public/cpp/system/platform_handle.h" | 15 #include "mojo/public/cpp/system/platform_handle.h" |
16 #include "services/service_manager/public/cpp/connection.h" | 16 #include "services/service_manager/public/cpp/connection.h" |
17 #include "services/ui/common/server_gpu_memory_buffer_manager.h" | 17 #include "services/ui/common/server_gpu_memory_buffer_manager.h" |
18 #include "services/ui/ws/gpu_service_proxy_delegate.h" | 18 #include "services/ui/ws/gpu_host_delegate.h" |
19 #include "ui/gfx/buffer_format_util.h" | 19 #include "ui/gfx/buffer_format_util.h" |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 namespace ws { | 22 namespace ws { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // The client Id 1 is reserved for the display compositor. | 26 // The client Id 1 is reserved for the display compositor. |
27 const int32_t kInternalGpuChannelClientId = 2; | 27 const int32_t kInternalGpuChannelClientId = 2; |
28 | 28 |
29 // The implementation that relays requests from clients to the real | 29 // The implementation that relays requests from clients to the real |
30 // service implementation in the GPU process over mojom.GpuServiceInternal. | 30 // service implementation in the GPU process over mojom.GpuService. |
31 class GpuServiceImpl : public mojom::Gpu { | 31 class GpuClient : public mojom::Gpu { |
32 public: | 32 public: |
33 GpuServiceImpl(int client_id, | 33 GpuClient(int client_id, |
34 gpu::GPUInfo* gpu_info, | 34 gpu::GPUInfo* gpu_info, |
35 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager, | 35 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager, |
36 mojom::GpuServiceInternal* gpu_service_internal) | 36 mojom::GpuService* gpu_service) |
37 : client_id_(client_id), | 37 : client_id_(client_id), |
38 gpu_info_(gpu_info), | 38 gpu_info_(gpu_info), |
39 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 39 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
40 gpu_service_internal_(gpu_service_internal) { | 40 gpu_service_(gpu_service) { |
41 DCHECK(gpu_memory_buffer_manager_); | 41 DCHECK(gpu_memory_buffer_manager_); |
42 DCHECK(gpu_service_internal_); | 42 DCHECK(gpu_service_); |
43 } | 43 } |
44 ~GpuServiceImpl() override { | 44 ~GpuClient() override { |
45 gpu_memory_buffer_manager_->DestroyAllGpuMemoryBufferForClient(client_id_); | 45 gpu_memory_buffer_manager_->DestroyAllGpuMemoryBufferForClient(client_id_); |
46 } | 46 } |
47 | 47 |
48 private: | 48 private: |
49 void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback, | 49 void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback, |
50 mojo::ScopedMessagePipeHandle channel_handle) { | 50 mojo::ScopedMessagePipeHandle channel_handle) { |
51 callback.Run(client_id_, std::move(channel_handle), *gpu_info_); | 51 callback.Run(client_id_, std::move(channel_handle), *gpu_info_); |
52 } | 52 } |
53 | 53 |
54 // mojom::Gpu overrides: | 54 // mojom::Gpu overrides: |
55 void EstablishGpuChannel( | 55 void EstablishGpuChannel( |
56 const EstablishGpuChannelCallback& callback) override { | 56 const EstablishGpuChannelCallback& callback) override { |
57 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful | 57 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful |
58 // tracing id. | 58 // tracing id. |
59 const uint64_t client_tracing_id = 0; | 59 const uint64_t client_tracing_id = 0; |
60 constexpr bool is_gpu_host = false; | 60 constexpr bool is_gpu_host = false; |
61 gpu_service_internal_->EstablishGpuChannel( | 61 gpu_service_->EstablishGpuChannel( |
62 client_id_, client_tracing_id, is_gpu_host, | 62 client_id_, client_tracing_id, is_gpu_host, |
63 base::Bind(&GpuServiceImpl::OnGpuChannelEstablished, | 63 base::Bind(&GpuClient::OnGpuChannelEstablished, base::Unretained(this), |
64 base::Unretained(this), callback)); | 64 callback)); |
65 } | 65 } |
66 | 66 |
67 void CreateGpuMemoryBuffer( | 67 void CreateGpuMemoryBuffer( |
68 gfx::GpuMemoryBufferId id, | 68 gfx::GpuMemoryBufferId id, |
69 const gfx::Size& size, | 69 const gfx::Size& size, |
70 gfx::BufferFormat format, | 70 gfx::BufferFormat format, |
71 gfx::BufferUsage usage, | 71 gfx::BufferUsage usage, |
72 const mojom::Gpu::CreateGpuMemoryBufferCallback& callback) override { | 72 const mojom::Gpu::CreateGpuMemoryBufferCallback& callback) override { |
73 auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle( | 73 auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle( |
74 id, client_id_, size, format, usage, gpu::kNullSurfaceHandle); | 74 id, client_id_, size, format, usage, gpu::kNullSurfaceHandle); |
75 callback.Run(handle); | 75 callback.Run(handle); |
76 } | 76 } |
77 | 77 |
78 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 78 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
79 const gpu::SyncToken& sync_token) override { | 79 const gpu::SyncToken& sync_token) override { |
80 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_, | 80 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_, |
81 sync_token); | 81 sync_token); |
82 } | 82 } |
83 | 83 |
84 const int client_id_; | 84 const int client_id_; |
85 | 85 |
86 // The objects these pointers refer to are owned by the GpuServiceProxy | 86 // The objects these pointers refer to are owned by the GpuHost object. |
87 // object. | |
88 const gpu::GPUInfo* gpu_info_; | 87 const gpu::GPUInfo* gpu_info_; |
89 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager_; | 88 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager_; |
90 mojom::GpuServiceInternal* gpu_service_internal_; | 89 mojom::GpuService* gpu_service_; |
91 | 90 |
92 DISALLOW_COPY_AND_ASSIGN(GpuServiceImpl); | 91 DISALLOW_COPY_AND_ASSIGN(GpuClient); |
93 }; | 92 }; |
94 | 93 |
95 } // namespace | 94 } // namespace |
96 | 95 |
97 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) | 96 GpuHost::GpuHost(GpuHostDelegate* delegate) |
98 : delegate_(delegate), | 97 : delegate_(delegate), |
99 next_client_id_(kInternalGpuChannelClientId + 1), | 98 next_client_id_(kInternalGpuChannelClientId + 1), |
100 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 99 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
101 gpu_host_binding_(this) { | 100 gpu_host_binding_(this) { |
102 gpu_main_impl_ = base::MakeUnique<GpuMain>(GetProxy(&gpu_main_)); | 101 gpu_main_impl_ = base::MakeUnique<GpuMain>(GetProxy(&gpu_main_)); |
103 gpu_main_impl_->OnStart(); | 102 gpu_main_impl_->OnStart(); |
104 // TODO(sad): Once GPU process is split, this would look like: | 103 // TODO(sad): Once GPU process is split, this would look like: |
105 // connector->ConnectToInterface("gpu", &gpu_main_); | 104 // connector->ConnectToInterface("gpu", &gpu_main_); |
106 gpu_main_->CreateGpuService(GetProxy(&gpu_service_), | 105 gpu_main_->CreateGpuService(GetProxy(&gpu_service_), |
107 gpu_host_binding_.CreateInterfacePtrAndBind()); | 106 gpu_host_binding_.CreateInterfacePtrAndBind()); |
108 gpu_memory_buffer_manager_ = base::MakeUnique<ServerGpuMemoryBufferManager>( | 107 gpu_memory_buffer_manager_ = base::MakeUnique<ServerGpuMemoryBufferManager>( |
109 gpu_service_.get(), next_client_id_++); | 108 gpu_service_.get(), next_client_id_++); |
110 } | 109 } |
111 | 110 |
112 GpuServiceProxy::~GpuServiceProxy() { | 111 GpuHost::~GpuHost() {} |
113 } | |
114 | 112 |
115 void GpuServiceProxy::Add(mojom::GpuRequest request) { | 113 void GpuHost::Add(mojom::GpuRequest request) { |
116 mojo::MakeStrongBinding( | 114 mojo::MakeStrongBinding( |
117 base::MakeUnique<GpuServiceImpl>(next_client_id_++, &gpu_info_, | 115 base::MakeUnique<GpuClient>(next_client_id_++, &gpu_info_, |
118 gpu_memory_buffer_manager_.get(), | 116 gpu_memory_buffer_manager_.get(), |
119 gpu_service_.get()), | 117 gpu_service_.get()), |
120 std::move(request)); | 118 std::move(request)); |
121 } | 119 } |
122 | 120 |
123 void GpuServiceProxy::CreateDisplayCompositor( | 121 void GpuHost::CreateDisplayCompositor( |
124 cc::mojom::DisplayCompositorRequest request, | 122 cc::mojom::DisplayCompositorRequest request, |
125 cc::mojom::DisplayCompositorClientPtr client) { | 123 cc::mojom::DisplayCompositorClientPtr client) { |
126 gpu_main_->CreateDisplayCompositor(std::move(request), std::move(client)); | 124 gpu_main_->CreateDisplayCompositor(std::move(request), std::move(client)); |
127 } | 125 } |
128 | 126 |
129 void GpuServiceProxy::DidInitialize(const gpu::GPUInfo& gpu_info) { | 127 void GpuHost::DidInitialize(const gpu::GPUInfo& gpu_info) { |
130 gpu_info_ = gpu_info; | 128 gpu_info_ = gpu_info; |
131 delegate_->OnGpuServiceInitialized(); | 129 delegate_->OnGpuServiceInitialized(); |
132 } | 130 } |
133 | 131 |
134 void GpuServiceProxy::DidCreateOffscreenContext(const GURL& url) {} | 132 void GpuHost::DidCreateOffscreenContext(const GURL& url) {} |
135 | 133 |
136 void GpuServiceProxy::DidDestroyOffscreenContext(const GURL& url) {} | 134 void GpuHost::DidDestroyOffscreenContext(const GURL& url) {} |
137 | 135 |
138 void GpuServiceProxy::DidDestroyChannel(int32_t client_id) {} | 136 void GpuHost::DidDestroyChannel(int32_t client_id) {} |
139 | 137 |
140 void GpuServiceProxy::DidLoseContext(bool offscreen, | 138 void GpuHost::DidLoseContext(bool offscreen, |
141 gpu::error::ContextLostReason reason, | 139 gpu::error::ContextLostReason reason, |
142 const GURL& active_url) {} | 140 const GURL& active_url) {} |
143 | 141 |
144 void GpuServiceProxy::StoreShaderToDisk(int32_t client_id, | 142 void GpuHost::StoreShaderToDisk(int32_t client_id, |
145 const std::string& key, | 143 const std::string& key, |
146 const std::string& shader) {} | 144 const std::string& shader) {} |
147 | 145 |
148 } // namespace ws | 146 } // namespace ws |
149 } // namespace ui | 147 } // namespace ui |
OLD | NEW |