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

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

Issue 2516943002: mus-gpu: Fix a couple of issues with MojoGpuMemoryBufferManager. (Closed)
Patch Set: Created 4 years 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/gpu/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/gpu/mojo_gpu_memory_buffer_manager.h" 5 #include "services/ui/public/cpp/gpu/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"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" 12 #include "gpu/ipc/client/gpu_memory_buffer_impl.h"
13 #include "mojo/public/cpp/system/buffer.h" 13 #include "mojo/public/cpp/system/buffer.h"
14 #include "mojo/public/cpp/system/platform_handle.h" 14 #include "mojo/public/cpp/system/platform_handle.h"
15 #include "services/service_manager/public/cpp/connector.h" 15 #include "services/service_manager/public/cpp/connector.h"
16 #include "services/ui/public/interfaces/constants.mojom.h" 16 #include "services/ui/public/interfaces/constants.mojom.h"
17 #include "ui/gfx/buffer_format_util.h" 17 #include "ui/gfx/buffer_format_util.h"
18 18
19 using DestructionCallback = base::Callback<void(const gpu::SyncToken& sync)>;
20
19 namespace ui { 21 namespace ui {
20 22
21 namespace { 23 namespace {
22 24
23 void OnGpuMemoryBufferAllocated(gfx::GpuMemoryBufferHandle* ret_handle, 25 void OnGpuMemoryBufferAllocated(gfx::GpuMemoryBufferHandle* ret_handle,
24 base::WaitableEvent* wait, 26 base::WaitableEvent* wait,
25 const gfx::GpuMemoryBufferHandle& handle) { 27 const gfx::GpuMemoryBufferHandle& handle) {
26 *ret_handle = handle; 28 *ret_handle = handle;
27 wait->Signal(); 29 wait->Signal();
28 } 30 }
29 31
32 void NotifyDestructionOnCorrectThread(
33 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
34 const DestructionCallback& callback,
35 const gpu::SyncToken& sync_token) {
36 task_runner->PostTask(FROM_HERE, base::Bind(callback, sync_token));
37 }
38
30 } // namespace 39 } // namespace
31 40
32 MojoGpuMemoryBufferManager::MojoGpuMemoryBufferManager( 41 MojoGpuMemoryBufferManager::MojoGpuMemoryBufferManager(
33 service_manager::Connector* connector) 42 mojom::GpuServicePtr gpu_service)
34 : thread_("GpuMemoryThread"), 43 : thread_("GpuMemoryThread"), weak_ptr_factory_(this) {
35 connector_(connector->Clone()),
36 weak_ptr_factory_(this) {
37 CHECK(thread_.Start()); 44 CHECK(thread_.Start());
38 // The thread is owned by this object. Which means the test will not run if 45 // The thread is owned by this object. Which means the task will not run if
39 // the object has been destroyed. So Unretained() is safe. 46 // the object has been destroyed. So Unretained() is safe.
40 thread_.task_runner()->PostTask( 47 thread_.task_runner()->PostTask(
41 FROM_HERE, base::Bind(&MojoGpuMemoryBufferManager::InitThread, 48 FROM_HERE, base::Bind(&MojoGpuMemoryBufferManager::InitThread,
42 base::Unretained(this))); 49 base::Unretained(this),
50 base::Passed(gpu_service.PassInterface())));
43 } 51 }
44 52
45 MojoGpuMemoryBufferManager::~MojoGpuMemoryBufferManager() { 53 MojoGpuMemoryBufferManager::~MojoGpuMemoryBufferManager() {
46 thread_.task_runner()->PostTask( 54 thread_.task_runner()->PostTask(
47 FROM_HERE, base::Bind(&MojoGpuMemoryBufferManager::TearDownThread, 55 FROM_HERE, base::Bind(&MojoGpuMemoryBufferManager::TearDownThread,
48 base::Unretained(this))); 56 base::Unretained(this)));
49 thread_.Stop(); 57 thread_.Stop();
50 } 58 }
51 59
52 void MojoGpuMemoryBufferManager::InitThread() { 60 void MojoGpuMemoryBufferManager::InitThread(
53 connector_->ConnectToInterface(ui::mojom::kServiceName, &gpu_service_); 61 mojo::InterfacePtrInfo<mojom::GpuService> gpu_service_info) {
62 gpu_service_.Bind(std::move(gpu_service_info));
63 weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
54 } 64 }
55 65
56 void MojoGpuMemoryBufferManager::TearDownThread() { 66 void MojoGpuMemoryBufferManager::TearDownThread() {
67 weak_ptr_factory_.InvalidateWeakPtrs();
57 gpu_service_.reset(); 68 gpu_service_.reset();
58 } 69 }
59 70
60 void MojoGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread( 71 void MojoGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread(
61 const gfx::Size& size, 72 const gfx::Size& size,
62 gfx::BufferFormat format, 73 gfx::BufferFormat format,
63 gfx::BufferUsage usage, 74 gfx::BufferUsage usage,
64 gfx::GpuMemoryBufferHandle* handle, 75 gfx::GpuMemoryBufferHandle* handle,
65 base::WaitableEvent* wait) { 76 base::WaitableEvent* wait) {
66 DCHECK(thread_.task_runner()->BelongsToCurrentThread()); 77 DCHECK(thread_.task_runner()->BelongsToCurrentThread());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, 110 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC,
100 base::WaitableEvent::InitialState::NOT_SIGNALED); 111 base::WaitableEvent::InitialState::NOT_SIGNALED);
101 thread_.task_runner()->PostTask( 112 thread_.task_runner()->PostTask(
102 FROM_HERE, 113 FROM_HERE,
103 base::Bind(&MojoGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread, 114 base::Bind(&MojoGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread,
104 base::Unretained(this), size, format, usage, &gmb_handle, 115 base::Unretained(this), size, format, usage, &gmb_handle,
105 &wait)); 116 &wait));
106 wait.Wait(); 117 wait.Wait();
107 if (gmb_handle.is_null()) 118 if (gmb_handle.is_null())
108 return nullptr; 119 return nullptr;
120
121 DestructionCallback callback =
122 base::Bind(&MojoGpuMemoryBufferManager::DeletedGpuMemoryBuffer, weak_ptr_,
123 gmb_handle.id);
109 std::unique_ptr<gpu::GpuMemoryBufferImpl> buffer( 124 std::unique_ptr<gpu::GpuMemoryBufferImpl> buffer(
110 gpu::GpuMemoryBufferImpl::CreateFromHandle( 125 gpu::GpuMemoryBufferImpl::CreateFromHandle(
111 gmb_handle, size, format, usage, 126 gmb_handle, size, format, usage,
112 base::Bind(&MojoGpuMemoryBufferManager::DeletedGpuMemoryBuffer, 127 base::Bind(&NotifyDestructionOnCorrectThread, thread_.task_runner(),
113 weak_ptr_factory_.GetWeakPtr(), gmb_handle.id))); 128 callback)));
114 if (!buffer) { 129 if (!buffer) {
115 DeletedGpuMemoryBuffer(gmb_handle.id, gpu::SyncToken()); 130 DeletedGpuMemoryBuffer(gmb_handle.id, gpu::SyncToken());
116 return nullptr; 131 return nullptr;
117 } 132 }
118 return std::move(buffer); 133 return std::move(buffer);
119 } 134 }
120 135
121 std::unique_ptr<gfx::GpuMemoryBuffer> 136 std::unique_ptr<gfx::GpuMemoryBuffer>
122 MojoGpuMemoryBufferManager::CreateGpuMemoryBufferFromHandle( 137 MojoGpuMemoryBufferManager::CreateGpuMemoryBufferFromHandle(
123 const gfx::GpuMemoryBufferHandle& handle, 138 const gfx::GpuMemoryBufferHandle& handle,
124 const gfx::Size& size, 139 const gfx::Size& size,
125 gfx::BufferFormat format) { 140 gfx::BufferFormat format) {
126 NOTIMPLEMENTED(); 141 NOTIMPLEMENTED();
127 return nullptr; 142 return nullptr;
128 } 143 }
129 144
130 void MojoGpuMemoryBufferManager::SetDestructionSyncToken( 145 void MojoGpuMemoryBufferManager::SetDestructionSyncToken(
131 gfx::GpuMemoryBuffer* buffer, 146 gfx::GpuMemoryBuffer* buffer,
132 const gpu::SyncToken& sync_token) { 147 const gpu::SyncToken& sync_token) {
133 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token( 148 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token(
134 sync_token); 149 sync_token);
135 } 150 }
136 151
137 } // namespace ui 152 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/gpu/mojo_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698