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_host.h" | 5 #include "services/ui/ws/gpu_host.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #endif | 24 #endif |
25 | 25 |
26 namespace ui { | 26 namespace ui { |
27 namespace ws { | 27 namespace ws { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // The client Id 1 is reserved for the display compositor. | 31 // The client Id 1 is reserved for the display compositor. |
32 const int32_t kInternalGpuChannelClientId = 2; | 32 const int32_t kInternalGpuChannelClientId = 2; |
33 | 33 |
34 // The implementation that relays requests from clients to the real | 34 } // namespace |
35 // service implementation in the GPU process over mojom.GpuService. | 35 |
36 class GpuClient : public mojom::Gpu { | 36 GpuHost::GpuClient::GpuClient( |
37 public: | 37 int client_id, |
38 GpuClient(int client_id, | 38 gpu::GPUInfo* gpu_info, |
39 gpu::GPUInfo* gpu_info, | 39 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager, |
40 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager, | 40 mojom::GpuService* gpu_service) |
41 mojom::GpuService* gpu_service) | 41 : client_id_(client_id), |
42 : client_id_(client_id), | 42 gpu_info_(gpu_info), |
43 gpu_info_(gpu_info), | 43 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
44 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 44 gpu_service_(gpu_service) { |
45 gpu_service_(gpu_service) { | 45 DCHECK(gpu_memory_buffer_manager_); |
46 DCHECK(gpu_memory_buffer_manager_); | 46 DCHECK(gpu_service_); |
47 DCHECK(gpu_service_); | |
48 } | 47 } |
49 ~GpuClient() override { | 48 |
49 GpuHost::GpuClient::~GpuClient() { | |
50 gpu_memory_buffer_manager_->DestroyAllGpuMemoryBufferForClient(client_id_); | 50 gpu_memory_buffer_manager_->DestroyAllGpuMemoryBufferForClient(client_id_); |
51 } | 51 } |
52 | 52 |
53 private: | 53 void GpuHost::GpuClient::OnGpuChannelEstablished( |
54 void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback, | 54 const EstablishGpuChannelCallback& callback, |
55 mojo::ScopedMessagePipeHandle channel_handle) { | 55 mojo::ScopedMessagePipeHandle channel_handle) { |
56 callback.Run(client_id_, std::move(channel_handle), *gpu_info_); | 56 callback.Run(client_id_, std::move(channel_handle), *gpu_info_); |
57 } | 57 } |
58 | 58 |
59 // mojom::Gpu overrides: | 59 // mojom::Gpu overrides: |
60 void EstablishGpuChannel( | 60 void GpuHost::GpuClient::EstablishGpuChannel( |
61 const EstablishGpuChannelCallback& callback) override { | 61 const EstablishGpuChannelCallback& callback) { |
62 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful | 62 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful |
63 // tracing id. | 63 // tracing id. |
64 const uint64_t client_tracing_id = 0; | 64 const uint64_t client_tracing_id = 0; |
65 constexpr bool is_gpu_host = false; | 65 constexpr bool is_gpu_host = false; |
66 gpu_service_->EstablishGpuChannel( | 66 gpu_service_->EstablishGpuChannel( |
67 client_id_, client_tracing_id, is_gpu_host, | 67 client_id_, client_tracing_id, is_gpu_host, |
68 base::Bind(&GpuClient::OnGpuChannelEstablished, base::Unretained(this), | 68 base::Bind(&GpuClient::OnGpuChannelEstablished, AsWeakPtr(), callback)); |
69 callback)); | |
70 } | 69 } |
71 | 70 |
72 void CreateGpuMemoryBuffer( | 71 void GpuHost::GpuClient::CreateGpuMemoryBuffer( |
73 gfx::GpuMemoryBufferId id, | 72 gfx::GpuMemoryBufferId id, |
74 const gfx::Size& size, | 73 const gfx::Size& size, |
75 gfx::BufferFormat format, | 74 gfx::BufferFormat format, |
76 gfx::BufferUsage usage, | 75 gfx::BufferUsage usage, |
77 const mojom::Gpu::CreateGpuMemoryBufferCallback& callback) override { | 76 const mojom::Gpu::CreateGpuMemoryBufferCallback& callback) { |
78 auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle( | 77 auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle( |
79 id, client_id_, size, format, usage, gpu::kNullSurfaceHandle); | 78 id, client_id_, size, format, usage, gpu::kNullSurfaceHandle); |
80 callback.Run(handle); | 79 callback.Run(handle); |
81 } | 80 } |
82 | 81 |
83 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 82 void GpuHost::GpuClient::DestroyGpuMemoryBuffer( |
84 const gpu::SyncToken& sync_token) override { | 83 gfx::GpuMemoryBufferId id, |
84 const gpu::SyncToken& sync_token) { | |
85 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_, | 85 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_, |
86 sync_token); | 86 sync_token); |
87 } | 87 } |
88 | 88 |
89 const int client_id_; | |
90 | |
91 // The objects these pointers refer to are owned by the GpuHost object. | |
92 const gpu::GPUInfo* gpu_info_; | |
93 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager_; | |
94 mojom::GpuService* gpu_service_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(GpuClient); | |
97 }; | |
98 | |
99 } // namespace | |
100 | |
101 GpuHost::GpuHost(GpuHostDelegate* delegate) | 89 GpuHost::GpuHost(GpuHostDelegate* delegate) |
102 : delegate_(delegate), | 90 : delegate_(delegate), |
103 next_client_id_(kInternalGpuChannelClientId + 1), | 91 next_client_id_(kInternalGpuChannelClientId + 1), |
104 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 92 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
105 gpu_host_binding_(this) { | 93 gpu_host_binding_(this) { |
106 // TODO(sad): Once GPU process is split, this would look like: | 94 // TODO(sad): Once GPU process is split, this would look like: |
107 // connector->BindInterface("gpu", &gpu_main_); | 95 // connector->BindInterface("gpu", &gpu_main_); |
108 gpu_main_impl_ = base::MakeUnique<GpuMain>(MakeRequest(&gpu_main_)); | 96 gpu_main_impl_ = base::MakeUnique<GpuMain>(MakeRequest(&gpu_main_)); |
109 gpu_main_impl_->OnStart(); | 97 gpu_main_impl_->OnStart(); |
110 | 98 |
111 // TODO(sad): Correctly initialize gpu::GpuPreferences (like it is initialized | 99 // TODO(sad): Correctly initialize gpu::GpuPreferences (like it is initialized |
112 // in GpuProcessHost::Init()). | 100 // in GpuProcessHost::Init()). |
113 gpu::GpuPreferences preferences; | 101 gpu::GpuPreferences preferences; |
114 gpu_main_->CreateGpuService(MakeRequest(&gpu_service_), | 102 gpu_main_->CreateGpuService(MakeRequest(&gpu_service_), |
115 gpu_host_binding_.CreateInterfacePtrAndBind(), | 103 gpu_host_binding_.CreateInterfacePtrAndBind(), |
116 preferences, mojo::ScopedSharedBufferHandle()); | 104 preferences, mojo::ScopedSharedBufferHandle()); |
117 gpu_memory_buffer_manager_ = base::MakeUnique<ServerGpuMemoryBufferManager>( | 105 gpu_memory_buffer_manager_ = base::MakeUnique<ServerGpuMemoryBufferManager>( |
118 gpu_service_.get(), next_client_id_++); | 106 gpu_service_.get(), next_client_id_++); |
119 } | 107 } |
120 | 108 |
121 GpuHost::~GpuHost() {} | 109 GpuHost::~GpuHost() {} |
122 | 110 |
123 void GpuHost::Add(mojom::GpuRequest request) { | 111 void GpuHost::Add(mojom::GpuRequest request) { |
124 mojo::MakeStrongBinding( | 112 AddInternal(std::move(request)); |
125 base::MakeUnique<GpuClient>(next_client_id_++, &gpu_info_, | |
126 gpu_memory_buffer_manager_.get(), | |
127 gpu_service_.get()), | |
128 std::move(request)); | |
129 } | 113 } |
130 | 114 |
131 void GpuHost::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { | 115 void GpuHost::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { |
132 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
133 gfx::RenderingWindowManager::GetInstance()->RegisterParent(widget); | 117 gfx::RenderingWindowManager::GetInstance()->RegisterParent(widget); |
134 #endif | 118 #endif |
135 } | 119 } |
136 | 120 |
137 void GpuHost::OnAcceleratedWidgetDestroyed(gfx::AcceleratedWidget widget) { | 121 void GpuHost::OnAcceleratedWidgetDestroyed(gfx::AcceleratedWidget widget) { |
138 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
139 gfx::RenderingWindowManager::GetInstance()->UnregisterParent(widget); | 123 gfx::RenderingWindowManager::GetInstance()->UnregisterParent(widget); |
140 #endif | 124 #endif |
141 } | 125 } |
142 | 126 |
143 void GpuHost::CreateDisplayCompositor( | 127 void GpuHost::CreateDisplayCompositor( |
144 cc::mojom::DisplayCompositorRequest request, | 128 cc::mojom::DisplayCompositorRequest request, |
145 cc::mojom::DisplayCompositorClientPtr client) { | 129 cc::mojom::DisplayCompositorClientPtr client) { |
146 gpu_main_->CreateDisplayCompositor(std::move(request), std::move(client)); | 130 gpu_main_->CreateDisplayCompositor(std::move(request), std::move(client)); |
147 } | 131 } |
148 | 132 |
133 mojom::Gpu* GpuHost::AddInternal(mojom::GpuRequest request) { | |
134 std::unique_ptr<GpuClient> client(base::MakeUnique<GpuClient>( | |
sadrul
2017/03/22 16:41:13
auto client = base::MakeUnique<...
jonross
2017/03/23 00:38:29
Done.
| |
135 next_client_id_++, &gpu_info_, gpu_memory_buffer_manager_.get(), | |
136 gpu_service_.get())); | |
137 GpuClient* client_ref = client.get(); | |
138 gpu_bindings_.AddBinding(std::move(client), std::move(request)); | |
139 return client_ref; | |
140 } | |
141 | |
149 void GpuHost::OnBadMessageFromGpu() { | 142 void GpuHost::OnBadMessageFromGpu() { |
150 // TODO(sad): Received some unexpected message from the gpu process. We | 143 // TODO(sad): Received some unexpected message from the gpu process. We |
151 // should kill the process and restart it. | 144 // should kill the process and restart it. |
152 NOTIMPLEMENTED(); | 145 NOTIMPLEMENTED(); |
153 } | 146 } |
154 | 147 |
155 void GpuHost::DidInitialize(const gpu::GPUInfo& gpu_info) { | 148 void GpuHost::DidInitialize(const gpu::GPUInfo& gpu_info) { |
156 gpu_info_ = gpu_info; | 149 gpu_info_ = gpu_info; |
157 delegate_->OnGpuServiceInitialized(); | 150 delegate_->OnGpuServiceInitialized(); |
158 } | 151 } |
(...skipping 29 matching lines...) Expand all Loading... | |
188 NOTREACHED(); | 181 NOTREACHED(); |
189 #endif | 182 #endif |
190 } | 183 } |
191 | 184 |
192 void GpuHost::StoreShaderToDisk(int32_t client_id, | 185 void GpuHost::StoreShaderToDisk(int32_t client_id, |
193 const std::string& key, | 186 const std::string& key, |
194 const std::string& shader) {} | 187 const std::string& shader) {} |
195 | 188 |
196 } // namespace ws | 189 } // namespace ws |
197 } // namespace ui | 190 } // namespace ui |
OLD | NEW |