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

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

Issue 2559343003: mus: Rename GpuService to Gpu. (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
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"
(...skipping 20 matching lines...) Expand all
31 31
32 void NotifyDestructionOnCorrectThread( 32 void NotifyDestructionOnCorrectThread(
33 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 33 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
34 const DestructionCallback& callback, 34 const DestructionCallback& callback,
35 const gpu::SyncToken& sync_token) { 35 const gpu::SyncToken& sync_token) {
36 task_runner->PostTask(FROM_HERE, base::Bind(callback, sync_token)); 36 task_runner->PostTask(FROM_HERE, base::Bind(callback, sync_token));
37 } 37 }
38 38
39 } // namespace 39 } // namespace
40 40
41 ClientGpuMemoryBufferManager::ClientGpuMemoryBufferManager( 41 ClientGpuMemoryBufferManager::ClientGpuMemoryBufferManager(mojom::GpuPtr gpu)
42 mojom::GpuServicePtr gpu_service)
43 : thread_("GpuMemoryThread"), weak_ptr_factory_(this) { 42 : thread_("GpuMemoryThread"), weak_ptr_factory_(this) {
44 CHECK(thread_.Start()); 43 CHECK(thread_.Start());
45 // 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
46 // the object has been destroyed. So Unretained() is safe. 45 // the object has been destroyed. So Unretained() is safe.
47 thread_.task_runner()->PostTask( 46 thread_.task_runner()->PostTask(
48 FROM_HERE, base::Bind(&ClientGpuMemoryBufferManager::InitThread, 47 FROM_HERE,
49 base::Unretained(this), 48 base::Bind(&ClientGpuMemoryBufferManager::InitThread,
50 base::Passed(gpu_service.PassInterface()))); 49 base::Unretained(this), base::Passed(gpu.PassInterface())));
51 } 50 }
52 51
53 ClientGpuMemoryBufferManager::~ClientGpuMemoryBufferManager() { 52 ClientGpuMemoryBufferManager::~ClientGpuMemoryBufferManager() {
54 thread_.task_runner()->PostTask( 53 thread_.task_runner()->PostTask(
55 FROM_HERE, base::Bind(&ClientGpuMemoryBufferManager::TearDownThread, 54 FROM_HERE, base::Bind(&ClientGpuMemoryBufferManager::TearDownThread,
56 base::Unretained(this))); 55 base::Unretained(this)));
57 thread_.Stop(); 56 thread_.Stop();
58 } 57 }
59 58
60 void ClientGpuMemoryBufferManager::InitThread( 59 void ClientGpuMemoryBufferManager::InitThread(mojom::GpuPtrInfo gpu_info) {
61 mojo::InterfacePtrInfo<mojom::GpuService> gpu_service_info) { 60 gpu_.Bind(std::move(gpu_info));
62 gpu_service_.Bind(std::move(gpu_service_info));
63 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); 61 weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
64 } 62 }
65 63
66 void ClientGpuMemoryBufferManager::TearDownThread() { 64 void ClientGpuMemoryBufferManager::TearDownThread() {
67 weak_ptr_factory_.InvalidateWeakPtrs(); 65 weak_ptr_factory_.InvalidateWeakPtrs();
68 gpu_service_.reset(); 66 gpu_.reset();
69 } 67 }
70 68
71 void ClientGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread( 69 void ClientGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread(
72 const gfx::Size& size, 70 const gfx::Size& size,
73 gfx::BufferFormat format, 71 gfx::BufferFormat format,
74 gfx::BufferUsage usage, 72 gfx::BufferUsage usage,
75 gfx::GpuMemoryBufferHandle* handle, 73 gfx::GpuMemoryBufferHandle* handle,
76 base::WaitableEvent* wait) { 74 base::WaitableEvent* wait) {
77 DCHECK(thread_.task_runner()->BelongsToCurrentThread()); 75 DCHECK(thread_.task_runner()->BelongsToCurrentThread());
78 // |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|
79 // is signaled. So it is safe for OnGpuMemoryBufferAllocated() to operate on 77 // is signaled. So it is safe for OnGpuMemoryBufferAllocated() to operate on
80 // these. 78 // these.
81 gpu_service_->CreateGpuMemoryBuffer( 79 gpu_->CreateGpuMemoryBuffer(
82 gfx::GpuMemoryBufferId(++counter_), size, format, usage, 80 gfx::GpuMemoryBufferId(++counter_), size, format, usage,
83 base::Bind(&OnGpuMemoryBufferAllocated, handle, wait)); 81 base::Bind(&OnGpuMemoryBufferAllocated, handle, wait));
84 } 82 }
85 83
86 void ClientGpuMemoryBufferManager::DeletedGpuMemoryBuffer( 84 void ClientGpuMemoryBufferManager::DeletedGpuMemoryBuffer(
87 gfx::GpuMemoryBufferId id, 85 gfx::GpuMemoryBufferId id,
88 const gpu::SyncToken& sync_token) { 86 const gpu::SyncToken& sync_token) {
89 if (!thread_.task_runner()->BelongsToCurrentThread()) { 87 if (!thread_.task_runner()->BelongsToCurrentThread()) {
90 thread_.task_runner()->PostTask( 88 thread_.task_runner()->PostTask(
91 FROM_HERE, 89 FROM_HERE,
92 base::Bind(&ClientGpuMemoryBufferManager::DeletedGpuMemoryBuffer, 90 base::Bind(&ClientGpuMemoryBufferManager::DeletedGpuMemoryBuffer,
93 base::Unretained(this), id, sync_token)); 91 base::Unretained(this), id, sync_token));
94 return; 92 return;
95 } 93 }
96 gpu_service_->DestroyGpuMemoryBuffer(id, sync_token); 94 gpu_->DestroyGpuMemoryBuffer(id, sync_token);
97 } 95 }
98 96
99 std::unique_ptr<gfx::GpuMemoryBuffer> 97 std::unique_ptr<gfx::GpuMemoryBuffer>
100 ClientGpuMemoryBufferManager::CreateGpuMemoryBuffer( 98 ClientGpuMemoryBufferManager::CreateGpuMemoryBuffer(
101 const gfx::Size& size, 99 const gfx::Size& size,
102 gfx::BufferFormat format, 100 gfx::BufferFormat format,
103 gfx::BufferUsage usage, 101 gfx::BufferUsage usage,
104 gpu::SurfaceHandle surface_handle) { 102 gpu::SurfaceHandle surface_handle) {
105 // Note: this can be called from multiple threads at the same time. Some of 103 // Note: this can be called from multiple threads at the same time. Some of
106 // those threads may not have a TaskRunner set. 104 // those threads may not have a TaskRunner set.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 141 }
144 142
145 void ClientGpuMemoryBufferManager::SetDestructionSyncToken( 143 void ClientGpuMemoryBufferManager::SetDestructionSyncToken(
146 gfx::GpuMemoryBuffer* buffer, 144 gfx::GpuMemoryBuffer* buffer,
147 const gpu::SyncToken& sync_token) { 145 const gpu::SyncToken& sync_token) {
148 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token( 146 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token(
149 sync_token); 147 sync_token);
150 } 148 }
151 149
152 } // namespace ui 150 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h ('k') | services/ui/public/cpp/gpu/gpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698