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

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

Issue 2658603004: Revert of Fix potential shutdown deadlock in UI service (Closed)
Patch Set: Created 3 years, 11 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/public/cpp/gpu/client_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/client_gpu_memory_buffer_manager.h" 5 #include "services/ui/public/cpp/gpu/client_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)>; 19 using DestructionCallback = base::Callback<void(const gpu::SyncToken& sync)>;
20 20
21 namespace ui { 21 namespace ui {
22 22
23 namespace { 23 namespace {
24 24
25 void OnGpuMemoryBufferAllocated(gfx::GpuMemoryBufferHandle* ret_handle,
26 base::WaitableEvent* wait,
27 const gfx::GpuMemoryBufferHandle& handle) {
28 *ret_handle = handle;
29 wait->Signal();
30 }
31
25 void NotifyDestructionOnCorrectThread( 32 void NotifyDestructionOnCorrectThread(
26 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 33 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
27 const DestructionCallback& callback, 34 const DestructionCallback& callback,
28 const gpu::SyncToken& sync_token) { 35 const gpu::SyncToken& sync_token) {
29 task_runner->PostTask(FROM_HERE, base::Bind(callback, sync_token)); 36 task_runner->PostTask(FROM_HERE, base::Bind(callback, sync_token));
30 } 37 }
31 38
32 } // namespace 39 } // namespace
33 40
34 ClientGpuMemoryBufferManager::ClientGpuMemoryBufferManager(mojom::GpuPtr gpu) 41 ClientGpuMemoryBufferManager::ClientGpuMemoryBufferManager(mojom::GpuPtr gpu)
35 : thread_("GpuMemoryThread"), weak_ptr_factory_(this) { 42 : thread_("GpuMemoryThread"), weak_ptr_factory_(this) {
36 CHECK(thread_.Start()); 43 CHECK(thread_.Start());
37 // The thread is owned by this object. Which means the task will not run if 44 // The thread is owned by this object. Which means the task will not run if
38 // the object has been destroyed. So Unretained() is safe. 45 // the object has been destroyed. So Unretained() is safe.
39 thread_.task_runner()->PostTask( 46 thread_.task_runner()->PostTask(
40 FROM_HERE, 47 FROM_HERE,
41 base::Bind(&ClientGpuMemoryBufferManager::InitThread, 48 base::Bind(&ClientGpuMemoryBufferManager::InitThread,
42 base::Unretained(this), base::Passed(gpu.PassInterface()))); 49 base::Unretained(this), base::Passed(gpu.PassInterface())));
43 } 50 }
44 51
45 ClientGpuMemoryBufferManager::~ClientGpuMemoryBufferManager() { 52 ClientGpuMemoryBufferManager::~ClientGpuMemoryBufferManager() {
46 thread_.task_runner()->PostTask( 53 thread_.task_runner()->PostTask(
47 FROM_HERE, base::Bind(&ClientGpuMemoryBufferManager::TearDownThread, 54 FROM_HERE, base::Bind(&ClientGpuMemoryBufferManager::TearDownThread,
48 base::Unretained(this))); 55 base::Unretained(this)));
49 thread_.Stop(); 56 thread_.Stop();
50 } 57 }
51 58
52 void ClientGpuMemoryBufferManager::InitThread(mojom::GpuPtrInfo gpu_info) { 59 void ClientGpuMemoryBufferManager::InitThread(mojom::GpuPtrInfo gpu_info) {
53 gpu_.Bind(std::move(gpu_info)); 60 gpu_.Bind(std::move(gpu_info));
54 gpu_.set_connection_error_handler(
55 base::Bind(&ClientGpuMemoryBufferManager::DisconnectGpuOnThread,
56 base::Unretained(this)));
57 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); 61 weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
58 } 62 }
59 63
60 void ClientGpuMemoryBufferManager::TearDownThread() { 64 void ClientGpuMemoryBufferManager::TearDownThread() {
61 weak_ptr_factory_.InvalidateWeakPtrs(); 65 weak_ptr_factory_.InvalidateWeakPtrs();
62 DisconnectGpuOnThread();
63 }
64
65 void ClientGpuMemoryBufferManager::DisconnectGpuOnThread() {
66 if (!gpu_.is_bound())
67 return;
68 gpu_.reset(); 66 gpu_.reset();
69 for (auto& waiter : pending_allocation_waiters_)
70 waiter->Signal();
71 pending_allocation_waiters_.clear();
72 } 67 }
73 68
74 void ClientGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread( 69 void ClientGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread(
75 const gfx::Size& size, 70 const gfx::Size& size,
76 gfx::BufferFormat format, 71 gfx::BufferFormat format,
77 gfx::BufferUsage usage, 72 gfx::BufferUsage usage,
78 gfx::GpuMemoryBufferHandle* handle, 73 gfx::GpuMemoryBufferHandle* handle,
79 base::WaitableEvent* wait) { 74 base::WaitableEvent* wait) {
80 DCHECK(thread_.task_runner()->BelongsToCurrentThread()); 75 DCHECK(thread_.task_runner()->BelongsToCurrentThread());
81 // |handle| and |wait| are both on the stack, and will be alive until |wait| 76 // |handle| and |wait| are both on the stack, and will be alive until |wait|
82 // is signaled. So it is safe for OnGpuMemoryBufferAllocated() to operate on 77 // is signaled. So it is safe for OnGpuMemoryBufferAllocated() to operate on
83 // these. 78 // these.
84 pending_allocation_waiters_.insert(wait);
85 gpu_->CreateGpuMemoryBuffer( 79 gpu_->CreateGpuMemoryBuffer(
86 gfx::GpuMemoryBufferId(++counter_), size, format, usage, 80 gfx::GpuMemoryBufferId(++counter_), size, format, usage,
87 base::Bind( 81 base::Bind(&OnGpuMemoryBufferAllocated, handle, wait));
88 &ClientGpuMemoryBufferManager::OnGpuMemoryBufferAllocatedOnThread,
89 base::Unretained(this), handle, wait));
90 }
91
92 void ClientGpuMemoryBufferManager::OnGpuMemoryBufferAllocatedOnThread(
93 gfx::GpuMemoryBufferHandle* ret_handle,
94 base::WaitableEvent* wait,
95 const gfx::GpuMemoryBufferHandle& handle) {
96 auto it = pending_allocation_waiters_.find(wait);
97 DCHECK(it != pending_allocation_waiters_.end());
98 pending_allocation_waiters_.erase(it);
99
100 *ret_handle = handle;
101 wait->Signal();
102 } 82 }
103 83
104 void ClientGpuMemoryBufferManager::DeletedGpuMemoryBuffer( 84 void ClientGpuMemoryBufferManager::DeletedGpuMemoryBuffer(
105 gfx::GpuMemoryBufferId id, 85 gfx::GpuMemoryBufferId id,
106 const gpu::SyncToken& sync_token) { 86 const gpu::SyncToken& sync_token) {
107 if (!thread_.task_runner()->BelongsToCurrentThread()) { 87 if (!thread_.task_runner()->BelongsToCurrentThread()) {
108 thread_.task_runner()->PostTask( 88 thread_.task_runner()->PostTask(
109 FROM_HERE, 89 FROM_HERE,
110 base::Bind(&ClientGpuMemoryBufferManager::DeletedGpuMemoryBuffer, 90 base::Bind(&ClientGpuMemoryBufferManager::DeletedGpuMemoryBuffer,
111 base::Unretained(this), id, sync_token)); 91 base::Unretained(this), id, sync_token));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 132 }
153 133
154 void ClientGpuMemoryBufferManager::SetDestructionSyncToken( 134 void ClientGpuMemoryBufferManager::SetDestructionSyncToken(
155 gfx::GpuMemoryBuffer* buffer, 135 gfx::GpuMemoryBuffer* buffer,
156 const gpu::SyncToken& sync_token) { 136 const gpu::SyncToken& sync_token) {
157 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token( 137 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token(
158 sync_token); 138 sync_token);
159 } 139 }
160 140
161 } // namespace ui 141 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698