Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: services/ui/common/server_gpu_memory_buffer_manager.cc

Issue 2939953004: viz: Move some code into //components/viz/common. (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/common/server_gpu_memory_buffer_manager.h ('k') | services/ui/gpu/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/common/server_gpu_memory_buffer_manager.h"
6
7 #include "base/logging.h"
8 #include "gpu/ipc/client/gpu_memory_buffer_impl.h"
9 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h"
10 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
11 #include "services/ui/gpu/interfaces/gpu_service.mojom.h"
12
13 namespace ui {
14
15 ServerGpuMemoryBufferManager::ServerGpuMemoryBufferManager(
16 mojom::GpuService* gpu_service,
17 int client_id)
18 : gpu_service_(gpu_service),
19 client_id_(client_id),
20 native_configurations_(gpu::GetNativeGpuMemoryBufferConfigurations()),
21 weak_factory_(this) {}
22
23 ServerGpuMemoryBufferManager::~ServerGpuMemoryBufferManager() {}
24
25 gfx::GpuMemoryBufferHandle
26 ServerGpuMemoryBufferManager::CreateGpuMemoryBufferHandle(
27 gfx::GpuMemoryBufferId id,
28 int client_id,
29 const gfx::Size& size,
30 gfx::BufferFormat format,
31 gfx::BufferUsage usage,
32 gpu::SurfaceHandle surface_handle) {
33 DCHECK(CalledOnValidThread());
34 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) {
35 const bool is_native = native_configurations_.find(std::make_pair(
36 format, usage)) != native_configurations_.end();
37 if (is_native) {
38 gfx::GpuMemoryBufferHandle handle;
39 gpu_service_->CreateGpuMemoryBuffer(id, size, format, usage, client_id,
40 surface_handle, &handle);
41 if (!handle.is_null())
42 native_buffers_[client_id].insert(handle.id);
43 return handle;
44 }
45 }
46
47 DCHECK(gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage))
48 << static_cast<int>(usage);
49 return gpu::GpuMemoryBufferImplSharedMemory::CreateGpuMemoryBuffer(id, size,
50 format);
51 }
52
53 std::unique_ptr<gfx::GpuMemoryBuffer>
54 ServerGpuMemoryBufferManager::CreateGpuMemoryBuffer(
55 const gfx::Size& size,
56 gfx::BufferFormat format,
57 gfx::BufferUsage usage,
58 gpu::SurfaceHandle surface_handle) {
59 gfx::GpuMemoryBufferId id(next_gpu_memory_id_++);
60 gfx::GpuMemoryBufferHandle handle = CreateGpuMemoryBufferHandle(
61 id, client_id_, size, format, usage, surface_handle);
62 if (handle.is_null())
63 return nullptr;
64 return gpu::GpuMemoryBufferImpl::CreateFromHandle(
65 handle, size, format, usage,
66 base::Bind(&ServerGpuMemoryBufferManager::DestroyGpuMemoryBuffer,
67 weak_factory_.GetWeakPtr(), id, client_id_));
68 }
69
70 void ServerGpuMemoryBufferManager::SetDestructionSyncToken(
71 gfx::GpuMemoryBuffer* buffer,
72 const gpu::SyncToken& sync_token) {
73 DCHECK(CalledOnValidThread());
74 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token(
75 sync_token);
76 }
77
78 void ServerGpuMemoryBufferManager::DestroyGpuMemoryBuffer(
79 gfx::GpuMemoryBufferId id,
80 int client_id,
81 const gpu::SyncToken& sync_token) {
82 DCHECK(CalledOnValidThread());
83 if (native_buffers_[client_id].erase(id))
84 gpu_service_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
85 }
86
87 void ServerGpuMemoryBufferManager::DestroyAllGpuMemoryBufferForClient(
88 int client_id) {
89 DCHECK(CalledOnValidThread());
90 for (gfx::GpuMemoryBufferId id : native_buffers_[client_id])
91 gpu_service_->DestroyGpuMemoryBuffer(id, client_id, gpu::SyncToken());
92 native_buffers_.erase(client_id);
93 }
94
95 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/common/server_gpu_memory_buffer_manager.h ('k') | services/ui/gpu/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698