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

Side by Side Diff: components/viz/common/server_gpu_memory_buffer_manager.cc

Issue 2941933002: viz: Convert a sync api in ServerGpuMemoryBufferManager into async. (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
OLDNEW
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 "components/viz/common/server_gpu_memory_buffer_manager.h" 5 #include "components/viz/common/server_gpu_memory_buffer_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/threading/thread_task_runner_handle.h"
danakj 2017/06/15 23:02:42 sequenced
sadrul 2017/06/16 12:52:19 Done.
8 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" 9 #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/client/gpu_memory_buffer_impl_shared_memory.h"
10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" 11 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
11 #include "services/ui/gpu/interfaces/gpu_service.mojom.h" 12 #include "services/ui/gpu/interfaces/gpu_service.mojom.h"
12 13
13 namespace viz { 14 namespace viz {
14 15
15 ServerGpuMemoryBufferManager::ServerGpuMemoryBufferManager( 16 ServerGpuMemoryBufferManager::ServerGpuMemoryBufferManager(
16 ui::mojom::GpuService* gpu_service, 17 ui::mojom::GpuService* gpu_service,
17 int client_id) 18 int client_id)
18 : gpu_service_(gpu_service), 19 : gpu_service_(gpu_service),
19 client_id_(client_id), 20 client_id_(client_id),
20 native_configurations_(gpu::GetNativeGpuMemoryBufferConfigurations()), 21 native_configurations_(gpu::GetNativeGpuMemoryBufferConfigurations()),
22 task_runner_(base::ThreadTaskRunnerHandle::Get()),
danakj 2017/06/15 23:02:42 sequenced?
sadrul 2017/06/16 12:52:19 Done.
21 weak_factory_(this) {} 23 weak_factory_(this) {}
22 24
23 ServerGpuMemoryBufferManager::~ServerGpuMemoryBufferManager() {} 25 ServerGpuMemoryBufferManager::~ServerGpuMemoryBufferManager() {}
24 26
25 gfx::GpuMemoryBufferHandle 27 void ServerGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
26 ServerGpuMemoryBufferManager::CreateGpuMemoryBufferHandle(
27 gfx::GpuMemoryBufferId id, 28 gfx::GpuMemoryBufferId id,
28 int client_id, 29 int client_id,
29 const gfx::Size& size, 30 const gfx::Size& size,
30 gfx::BufferFormat format, 31 gfx::BufferFormat format,
31 gfx::BufferUsage usage, 32 gfx::BufferUsage usage,
32 gpu::SurfaceHandle surface_handle) { 33 gpu::SurfaceHandle surface_handle,
33 DCHECK(CalledOnValidThread()); 34 base::OnceCallback<void(const gfx::GpuMemoryBufferHandle&)> callback) {
35 DCHECK(task_runner_->BelongsToCurrentThread());
34 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) { 36 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) {
35 const bool is_native = native_configurations_.find(std::make_pair( 37 const bool is_native = native_configurations_.find(std::make_pair(
36 format, usage)) != native_configurations_.end(); 38 format, usage)) != native_configurations_.end();
37 if (is_native) { 39 if (is_native) {
38 gfx::GpuMemoryBufferHandle handle; 40 pending_buffers_.insert(client_id);
39 gpu_service_->CreateGpuMemoryBuffer(id, size, format, usage, client_id, 41 gpu_service_->CreateGpuMemoryBuffer(
danakj 2017/06/15 23:02:42 I guess I'm a lil confused why we're going to use
sadrul 2017/06/16 12:52:19 viz does not actually see ServerGpuMemoryBufferMan
sadrul 2017/06/17 02:54:04 I have put up https://codereview.chromium.org/2942
danakj 2017/06/20 16:27:26 After that, does this class still belong in viz/co
sadrul 2017/06/20 18:21:02 It should move to viz/host. I have a follow up CL
40 surface_handle, &handle); 42 id, size, format, usage, client_id, surface_handle,
41 if (!handle.is_null()) 43 base::Bind(&ServerGpuMemoryBufferManager::OnGpuMemoryBufferAllocated,
42 native_buffers_[client_id].insert(handle.id); 44 weak_factory_.GetWeakPtr(), client_id,
43 return handle; 45 base::Passed(std::move(callback))));
46 return;
44 } 47 }
45 } 48 }
46 49
47 DCHECK(gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage)) 50 // Early out if we cannot fallback to shared memory buffer.
48 << static_cast<int>(usage); 51 if (!gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage) ||
danakj 2017/06/15 23:02:42 we used to dcheck, is this now possible?
49 return gpu::GpuMemoryBufferImplSharedMemory::CreateGpuMemoryBuffer(id, size, 52 !gpu::GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat(size,
danakj 2017/06/15 23:02:42 why did this appear here?
sadrul 2017/06/16 12:52:19 See comments in https://codereview.chromium.org/29
sadrul 2017/06/17 02:54:04 I have removed this, and restored the DCHECK(). Tu
50 format); 53 format)) {
54 std::move(callback).Run(gfx::GpuMemoryBufferHandle());
55 return;
56 }
57
58 std::move(callback).Run(
59 gpu::GpuMemoryBufferImplSharedMemory::CreateGpuMemoryBuffer(id, size,
60 format));
51 } 61 }
52 62
53 std::unique_ptr<gfx::GpuMemoryBuffer> 63 std::unique_ptr<gfx::GpuMemoryBuffer>
54 ServerGpuMemoryBufferManager::CreateGpuMemoryBuffer( 64 ServerGpuMemoryBufferManager::CreateGpuMemoryBuffer(
55 const gfx::Size& size, 65 const gfx::Size& size,
56 gfx::BufferFormat format, 66 gfx::BufferFormat format,
57 gfx::BufferUsage usage, 67 gfx::BufferUsage usage,
58 gpu::SurfaceHandle surface_handle) { 68 gpu::SurfaceHandle surface_handle) {
59 gfx::GpuMemoryBufferId id(next_gpu_memory_id_++); 69 gfx::GpuMemoryBufferId id(next_gpu_memory_id_++);
60 gfx::GpuMemoryBufferHandle handle = CreateGpuMemoryBufferHandle( 70 gfx::GpuMemoryBufferHandle handle;
61 id, client_id_, size, format, usage, surface_handle); 71 base::WaitableEvent wait_event(
72 base::WaitableEvent::ResetPolicy::MANUAL,
73 base::WaitableEvent::InitialState::NOT_SIGNALED);
74 // We block with a WaitableEvent until the callbacks are run. So using
75 // base::Unretained() is safe here.
76 DCHECK(!task_runner_->BelongsToCurrentThread());
77 auto reply_callback = base::BindOnce(
78 &ServerGpuMemoryBufferManager::SignalGpuMemoryBufferAllocated,
79 base::Unretained(this), &handle, &wait_event);
80 auto allocate_callback =
81 base::BindOnce(&ServerGpuMemoryBufferManager::AllocateGpuMemoryBuffer,
82 base::Unretained(this), id, client_id_, size, format,
83 usage, surface_handle, std::move(reply_callback));
84 task_runner_->PostTask(FROM_HERE, std::move(allocate_callback));
85 base::ThreadRestrictions::ScopedAllowWait allow_wait;
86 wait_event.Wait();
62 if (handle.is_null()) 87 if (handle.is_null())
63 return nullptr; 88 return nullptr;
64 return gpu::GpuMemoryBufferImpl::CreateFromHandle( 89 return gpu::GpuMemoryBufferImpl::CreateFromHandle(
65 handle, size, format, usage, 90 handle, size, format, usage,
66 base::Bind(&ServerGpuMemoryBufferManager::DestroyGpuMemoryBuffer, 91 base::Bind(&ServerGpuMemoryBufferManager::DestroyGpuMemoryBuffer,
67 weak_factory_.GetWeakPtr(), id, client_id_)); 92 weak_factory_.GetWeakPtr(), id, client_id_));
68 } 93 }
69 94
70 void ServerGpuMemoryBufferManager::SetDestructionSyncToken( 95 void ServerGpuMemoryBufferManager::SetDestructionSyncToken(
71 gfx::GpuMemoryBuffer* buffer, 96 gfx::GpuMemoryBuffer* buffer,
72 const gpu::SyncToken& sync_token) { 97 const gpu::SyncToken& sync_token) {
73 DCHECK(CalledOnValidThread());
74 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token( 98 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token(
75 sync_token); 99 sync_token);
76 } 100 }
77 101
78 void ServerGpuMemoryBufferManager::DestroyGpuMemoryBuffer( 102 void ServerGpuMemoryBufferManager::DestroyGpuMemoryBuffer(
79 gfx::GpuMemoryBufferId id, 103 gfx::GpuMemoryBufferId id,
80 int client_id, 104 int client_id,
81 const gpu::SyncToken& sync_token) { 105 const gpu::SyncToken& sync_token) {
82 DCHECK(CalledOnValidThread()); 106 DCHECK(task_runner_->BelongsToCurrentThread());
83 if (native_buffers_[client_id].erase(id)) 107 if (native_buffers_[client_id].erase(id))
84 gpu_service_->DestroyGpuMemoryBuffer(id, client_id, sync_token); 108 gpu_service_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
85 } 109 }
86 110
87 void ServerGpuMemoryBufferManager::DestroyAllGpuMemoryBufferForClient( 111 void ServerGpuMemoryBufferManager::DestroyAllGpuMemoryBufferForClient(
88 int client_id) { 112 int client_id) {
89 DCHECK(CalledOnValidThread()); 113 DCHECK(task_runner_->BelongsToCurrentThread());
90 for (gfx::GpuMemoryBufferId id : native_buffers_[client_id]) 114 for (gfx::GpuMemoryBufferId id : native_buffers_[client_id])
91 gpu_service_->DestroyGpuMemoryBuffer(id, client_id, gpu::SyncToken()); 115 gpu_service_->DestroyGpuMemoryBuffer(id, client_id, gpu::SyncToken());
92 native_buffers_.erase(client_id); 116 native_buffers_.erase(client_id);
117 pending_buffers_.erase(client_id);
118 }
119
120 void ServerGpuMemoryBufferManager::OnGpuMemoryBufferAllocated(
121 int client_id,
122 base::OnceCallback<void(const gfx::GpuMemoryBufferHandle&)> callback,
123 const gfx::GpuMemoryBufferHandle& handle) {
124 DCHECK(task_runner_->BelongsToCurrentThread());
125 if (pending_buffers_.find(client_id) == pending_buffers_.end()) {
126 // The client has been destroyed since the allocation request was made.
127 if (!handle.is_null())
danakj 2017/06/15 23:02:42 {}
sadrul 2017/06/16 12:52:19 Done.
128 gpu_service_->DestroyGpuMemoryBuffer(handle.id, client_id,
129 gpu::SyncToken());
130 std::move(callback).Run(gfx::GpuMemoryBufferHandle());
131 return;
132 }
133 if (!handle.is_null())
134 native_buffers_[client_id].insert(handle.id);
135 std::move(callback).Run(handle);
136 }
137
138 void ServerGpuMemoryBufferManager::SignalGpuMemoryBufferAllocated(
139 gfx::GpuMemoryBufferHandle* handle,
140 base::WaitableEvent* wait_event,
141 const gfx::GpuMemoryBufferHandle& allocated_handle) {
142 *handle = allocated_handle;
143 wait_event->Signal();
93 } 144 }
94 145
95 } // namespace viz 146 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698