OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_client.h" |
| 6 |
| 7 #include "services/ui/common/server_gpu_memory_buffer_manager.h" |
| 8 #include "services/ui/gpu/interfaces/gpu_service.mojom.h" |
| 9 |
| 10 namespace ui { |
| 11 namespace ws { |
| 12 |
| 13 GpuClient::GpuClient(int client_id, |
| 14 gpu::GPUInfo* gpu_info, |
| 15 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 16 mojom::GpuService* gpu_service) |
| 17 : client_id_(client_id), |
| 18 gpu_info_(gpu_info), |
| 19 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 20 gpu_service_(gpu_service), |
| 21 weak_factory_(this) { |
| 22 DCHECK(gpu_memory_buffer_manager_); |
| 23 DCHECK(gpu_service_); |
| 24 } |
| 25 |
| 26 GpuClient::~GpuClient() { |
| 27 gpu_memory_buffer_manager_->DestroyAllGpuMemoryBufferForClient(client_id_); |
| 28 } |
| 29 |
| 30 void GpuClient::OnGpuChannelEstablished( |
| 31 const EstablishGpuChannelCallback& callback, |
| 32 mojo::ScopedMessagePipeHandle channel_handle) { |
| 33 callback.Run(client_id_, std::move(channel_handle), *gpu_info_); |
| 34 } |
| 35 |
| 36 // mojom::Gpu overrides: |
| 37 void GpuClient::EstablishGpuChannel( |
| 38 const EstablishGpuChannelCallback& callback) { |
| 39 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful |
| 40 // tracing id. |
| 41 const uint64_t client_tracing_id = 0; |
| 42 constexpr bool is_gpu_host = false; |
| 43 gpu_service_->EstablishGpuChannel( |
| 44 client_id_, client_tracing_id, is_gpu_host, |
| 45 base::Bind(&GpuClient::OnGpuChannelEstablished, |
| 46 weak_factory_.GetWeakPtr(), callback)); |
| 47 } |
| 48 |
| 49 void GpuClient::CreateGpuMemoryBuffer( |
| 50 gfx::GpuMemoryBufferId id, |
| 51 const gfx::Size& size, |
| 52 gfx::BufferFormat format, |
| 53 gfx::BufferUsage usage, |
| 54 const mojom::Gpu::CreateGpuMemoryBufferCallback& callback) { |
| 55 auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle( |
| 56 id, client_id_, size, format, usage, gpu::kNullSurfaceHandle); |
| 57 callback.Run(handle); |
| 58 } |
| 59 |
| 60 void GpuClient::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 61 const gpu::SyncToken& sync_token) { |
| 62 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_, |
| 63 sync_token); |
| 64 } |
| 65 |
| 66 } // namespace ws |
| 67 } // namespace ui |
OLD | NEW |