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

Side by Side Diff: services/ui/public/cpp/mojo_gpu_memory_buffer_manager.cc

Issue 2490503002: gpu: A common GpuMemoryBufferManager implemenetation for clients. (Closed)
Patch Set: tot merge Created 4 years, 1 month 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/public/cpp/mojo_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/public/cpp/mojo_gpu_memory_buffer_manager.h" 5 #include "services/ui/public/cpp/mojo_gpu_memory_buffer_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 13 matching lines...) Expand all
24 const gfx::GpuMemoryBufferHandle& handle) { 24 const gfx::GpuMemoryBufferHandle& handle) {
25 *ret_handle = handle; 25 *ret_handle = handle;
26 wait->Signal(); 26 wait->Signal();
27 } 27 }
28 28
29 } // namespace 29 } // namespace
30 30
31 MojoGpuMemoryBufferManager::MojoGpuMemoryBufferManager( 31 MojoGpuMemoryBufferManager::MojoGpuMemoryBufferManager(
32 service_manager::Connector* connector) 32 service_manager::Connector* connector)
33 : thread_("GpuMemoryThread"), 33 : thread_("GpuMemoryThread"),
34 connector_(connector->Clone()), 34 gpu_memory_buffer_manager_(
35 weak_ptr_factory_(this) { 35 make_scoped_refptr(new gpu::ClientGpuMemoryBufferManager(this))),
36 connector_(connector->Clone()) {
36 CHECK(thread_.Start()); 37 CHECK(thread_.Start());
37 // The thread is owned by this object. Which means the test will not run if 38 // The thread is owned by this object. Which means the test will not run if
38 // the object has been destroyed. So Unretained() is safe. 39 // the object has been destroyed. So Unretained() is safe.
39 thread_.task_runner()->PostTask( 40 thread_.task_runner()->PostTask(
40 FROM_HERE, base::Bind(&MojoGpuMemoryBufferManager::InitThread, 41 FROM_HERE, base::Bind(&MojoGpuMemoryBufferManager::InitThread,
41 base::Unretained(this))); 42 base::Unretained(this)));
42 } 43 }
43 44
44 MojoGpuMemoryBufferManager::~MojoGpuMemoryBufferManager() { 45 MojoGpuMemoryBufferManager::~MojoGpuMemoryBufferManager() {
45 thread_.task_runner()->PostTask( 46 thread_.task_runner()->PostTask(
46 FROM_HERE, base::Bind(&MojoGpuMemoryBufferManager::TearDownThread, 47 FROM_HERE, base::Bind(&MojoGpuMemoryBufferManager::TearDownThread,
47 base::Unretained(this))); 48 base::Unretained(this)));
48 thread_.Stop(); 49 thread_.Stop();
50 gpu_memory_buffer_manager_->reset_delegate();
49 } 51 }
50 52
51 void MojoGpuMemoryBufferManager::InitThread() { 53 void MojoGpuMemoryBufferManager::InitThread() {
52 connector_->ConnectToInterface("service:ui", &gpu_service_); 54 connector_->ConnectToInterface("service:ui", &gpu_service_);
53 } 55 }
54 56
55 void MojoGpuMemoryBufferManager::TearDownThread() { 57 void MojoGpuMemoryBufferManager::TearDownThread() {
56 gpu_service_.reset(); 58 gpu_service_.reset();
57 } 59 }
58 60
59 void MojoGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread( 61 void MojoGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread(
60 const gfx::Size& size, 62 const gfx::Size& size,
61 gfx::BufferFormat format, 63 gfx::BufferFormat format,
62 gfx::BufferUsage usage, 64 gfx::BufferUsage usage,
63 gfx::GpuMemoryBufferHandle* handle, 65 gfx::GpuMemoryBufferHandle* handle,
64 base::WaitableEvent* wait) { 66 base::WaitableEvent* wait) {
65 DCHECK(thread_.task_runner()->BelongsToCurrentThread()); 67 DCHECK(thread_.task_runner()->BelongsToCurrentThread());
66 // |handle| and |wait| are both on the stack, and will be alive until |wait| 68 // |handle| and |wait| are both on the stack, and will be alive until |wait|
67 // is signaled. So it is safe for OnGpuMemoryBufferAllocated() to operate on 69 // is signaled. So it is safe for OnGpuMemoryBufferAllocated() to operate on
68 // these. 70 // these.
69 gpu_service_->CreateGpuMemoryBuffer( 71 gpu_service_->CreateGpuMemoryBuffer(
70 gfx::GpuMemoryBufferId(++counter_), size, format, usage, 72 gfx::GpuMemoryBufferId(++counter_), size, format, usage,
71 base::Bind(&OnGpuMemoryBufferAllocated, handle, wait)); 73 base::Bind(&OnGpuMemoryBufferAllocated, handle, wait));
72 } 74 }
73 75
74 void MojoGpuMemoryBufferManager::DeletedGpuMemoryBuffer( 76 gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferManager::GetSharedMemoryHandle(
75 gfx::GpuMemoryBufferId id,
76 const gpu::SyncToken& sync_token) {
77 if (!thread_.task_runner()->BelongsToCurrentThread()) {
78 thread_.task_runner()->PostTask(
79 FROM_HERE,
80 base::Bind(&MojoGpuMemoryBufferManager::DeletedGpuMemoryBuffer,
81 base::Unretained(this), id, sync_token));
82 return;
83 }
84 gpu_service_->DestroyGpuMemoryBuffer(id, sync_token);
85 }
86
87 std::unique_ptr<gfx::GpuMemoryBuffer>
88 MojoGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
89 const gfx::Size& size, 77 const gfx::Size& size,
90 gfx::BufferFormat format, 78 gfx::BufferFormat format,
91 gfx::BufferUsage usage, 79 gfx::BufferUsage usage) {
92 gpu::SurfaceHandle surface_handle) {
93 // Note: this can be called from multiple threads at the same time. Some of
94 // those threads may not have a TaskRunner set.
95 DCHECK_EQ(gpu::kNullSurfaceHandle, surface_handle);
96 CHECK(!thread_.task_runner()->BelongsToCurrentThread()); 80 CHECK(!thread_.task_runner()->BelongsToCurrentThread());
97 gfx::GpuMemoryBufferHandle gmb_handle; 81 gfx::GpuMemoryBufferHandle gmb_handle;
98 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, 82 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC,
99 base::WaitableEvent::InitialState::NOT_SIGNALED); 83 base::WaitableEvent::InitialState::NOT_SIGNALED);
100 thread_.task_runner()->PostTask( 84 thread_.task_runner()->PostTask(
101 FROM_HERE, 85 FROM_HERE,
102 base::Bind(&MojoGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread, 86 base::Bind(&MojoGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread,
103 base::Unretained(this), size, format, usage, &gmb_handle, 87 base::Unretained(this), size, format, usage, &gmb_handle,
104 &wait)); 88 &wait));
105 wait.Wait(); 89 wait.Wait();
106 if (gmb_handle.is_null()) 90 return gmb_handle;
107 return nullptr;
108 std::unique_ptr<gpu::GpuMemoryBufferImpl> buffer(
109 gpu::GpuMemoryBufferImpl::CreateFromHandle(
110 gmb_handle, size, format, usage,
111 base::Bind(&MojoGpuMemoryBufferManager::DeletedGpuMemoryBuffer,
112 weak_ptr_factory_.GetWeakPtr(), gmb_handle.id)));
113 if (!buffer) {
114 DeletedGpuMemoryBuffer(gmb_handle.id, gpu::SyncToken());
115 return nullptr;
116 }
117 return std::move(buffer);
118 } 91 }
119 92
120 std::unique_ptr<gfx::GpuMemoryBuffer> 93 void MojoGpuMemoryBufferManager::DeletedGpuMemoryBuffer(
121 MojoGpuMemoryBufferManager::CreateGpuMemoryBufferFromHandle( 94 gfx::GpuMemoryBufferId id,
122 const gfx::GpuMemoryBufferHandle& handle,
123 const gfx::Size& size,
124 gfx::BufferFormat format) {
125 NOTIMPLEMENTED();
126 return nullptr;
127 }
128
129 gfx::GpuMemoryBuffer*
130 MojoGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
131 ClientBuffer buffer) {
132 return gpu::GpuMemoryBufferImpl::FromClientBuffer(buffer);
133 }
134
135 void MojoGpuMemoryBufferManager::SetDestructionSyncToken(
136 gfx::GpuMemoryBuffer* buffer,
137 const gpu::SyncToken& sync_token) { 95 const gpu::SyncToken& sync_token) {
138 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token( 96 if (!thread_.task_runner()->BelongsToCurrentThread()) {
139 sync_token); 97 thread_.task_runner()->PostTask(
98 FROM_HERE,
99 base::Bind(&MojoGpuMemoryBufferManager::DeletedGpuMemoryBuffer,
100 base::Unretained(this), id, sync_token));
101 return;
102 }
103 gpu_service_->DestroyGpuMemoryBuffer(id, sync_token);
140 } 104 }
141 105
142 } // namespace ui 106 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/mojo_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698