summaryrefslogtreecommitdiff
path: root/chromium/services/ui/ws/gpu_client.cc
blob: c0ec4e6b5286054068e08380c6c5e083a8394106 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/ui/ws/gpu_client.h"

#include "services/ui/common/server_gpu_memory_buffer_manager.h"
#include "services/ui/gpu/interfaces/gpu_service.mojom.h"

namespace ui {
namespace ws {

GpuClient::GpuClient(int client_id,
                     gpu::GPUInfo* gpu_info,
                     ServerGpuMemoryBufferManager* gpu_memory_buffer_manager,
                     mojom::GpuService* gpu_service)
    : client_id_(client_id),
      gpu_info_(gpu_info),
      gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
      gpu_service_(gpu_service),
      weak_factory_(this) {
  DCHECK(gpu_memory_buffer_manager_);
  DCHECK(gpu_service_);
}

GpuClient::~GpuClient() {
  gpu_memory_buffer_manager_->DestroyAllGpuMemoryBufferForClient(client_id_);
}

void GpuClient::OnGpuChannelEstablished(
    const EstablishGpuChannelCallback& callback,
    mojo::ScopedMessagePipeHandle channel_handle) {
  callback.Run(client_id_, std::move(channel_handle), *gpu_info_);
}

// mojom::Gpu overrides:
void GpuClient::EstablishGpuChannel(
    const EstablishGpuChannelCallback& callback) {
  // TODO(sad): crbug.com/617415 figure out how to generate a meaningful
  // tracing id.
  const uint64_t client_tracing_id = 0;
  constexpr bool is_gpu_host = false;
  gpu_service_->EstablishGpuChannel(
      client_id_, client_tracing_id, is_gpu_host,
      base::Bind(&GpuClient::OnGpuChannelEstablished,
                 weak_factory_.GetWeakPtr(), callback));
}

void GpuClient::CreateGpuMemoryBuffer(
    gfx::GpuMemoryBufferId id,
    const gfx::Size& size,
    gfx::BufferFormat format,
    gfx::BufferUsage usage,
    const mojom::Gpu::CreateGpuMemoryBufferCallback& callback) {
  auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle(
      id, client_id_, size, format, usage, gpu::kNullSurfaceHandle);
  callback.Run(handle);
}

void GpuClient::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
                                       const gpu::SyncToken& sync_token) {
  gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_,
                                                     sync_token);
}

}  // namespace ws
}  // namespace ui