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

Side by Side Diff: gpu/command_buffer/service/async_pixel_transfer_manager_idle.cc

Issue 16175005: GPU: Replace AsyncPixelTransferState with AsyncPixelTransferDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "gpu/command_buffer/service/async_pixel_transfer_manager_idle.h" 5 #include "gpu/command_buffer/service/async_pixel_transfer_manager_idle.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/weak_ptr.h"
10 #include "gpu/command_buffer/service/safe_shared_memory_pool.h" 11 #include "gpu/command_buffer/service/safe_shared_memory_pool.h"
11 #include "ui/gl/scoped_binders.h" 12 #include "ui/gl/scoped_binders.h"
12 13
13 namespace gpu { 14 namespace gpu {
14 15
15 namespace { 16 namespace {
16 17
17 base::LazyInstance<SafeSharedMemoryPool> g_safe_shared_memory_pool = 18 base::LazyInstance<SafeSharedMemoryPool> g_safe_shared_memory_pool =
18 LAZY_INSTANCE_INITIALIZER; 19 LAZY_INSTANCE_INITIALIZER;
19 20
20 SafeSharedMemoryPool* safe_shared_memory_pool() { 21 SafeSharedMemoryPool* safe_shared_memory_pool() {
21 return g_safe_shared_memory_pool.Pointer(); 22 return g_safe_shared_memory_pool.Pointer();
22 } 23 }
23 24
24 static uint64 g_next_pixel_transfer_state_id = 1; 25 static uint64 g_next_pixel_transfer_state_id = 1;
25 26
26 void PerformNotifyCompletion( 27 void PerformNotifyCompletion(
27 AsyncMemoryParams mem_params, 28 AsyncMemoryParams mem_params,
28 ScopedSafeSharedMemory* safe_shared_memory, 29 ScopedSafeSharedMemory* safe_shared_memory,
29 const AsyncPixelTransferManager::CompletionCallback& callback) { 30 const AsyncPixelTransferManager::CompletionCallback& callback) {
30 TRACE_EVENT0("gpu", "PerformNotifyCompletion"); 31 TRACE_EVENT0("gpu", "PerformNotifyCompletion");
31 AsyncMemoryParams safe_mem_params = mem_params; 32 AsyncMemoryParams safe_mem_params = mem_params;
32 safe_mem_params.shared_memory = safe_shared_memory->shared_memory(); 33 safe_mem_params.shared_memory = safe_shared_memory->shared_memory();
33 callback.Run(safe_mem_params); 34 callback.Run(safe_mem_params);
34 } 35 }
35 36
36 class AsyncPixelTransferStateImpl : public AsyncPixelTransferState { 37 // TODO(backer): Merge this with Delegate in follow-up CL. It serves no purpose.
38 class AsyncPixelTransferState
39 : public base::SupportsWeakPtr<AsyncPixelTransferState> {
37 public: 40 public:
38 typedef base::Callback<void(GLuint)> TransferCallback; 41 typedef base::Callback<void(GLuint)> TransferCallback;
39 42
40 explicit AsyncPixelTransferStateImpl(GLuint texture_id) 43 explicit AsyncPixelTransferState(GLuint texture_id)
41 : id_(g_next_pixel_transfer_state_id++), 44 : id_(g_next_pixel_transfer_state_id++),
42 texture_id_(texture_id), 45 texture_id_(texture_id),
43 transfer_in_progress_(false) { 46 transfer_in_progress_(false) {
44 } 47 }
45 48
46 // Implement AsyncPixelTransferState: 49 virtual ~AsyncPixelTransferState() {}
47 virtual bool TransferIsInProgress() OVERRIDE { 50
51 bool TransferIsInProgress() {
48 return transfer_in_progress_; 52 return transfer_in_progress_;
49 } 53 }
50 54
51 uint64 id() const { return id_; } 55 uint64 id() const { return id_; }
52 56
53 void set_transfer_in_progress(bool transfer_in_progress) { 57 void set_transfer_in_progress(bool transfer_in_progress) {
54 transfer_in_progress_ = transfer_in_progress; 58 transfer_in_progress_ = transfer_in_progress;
55 } 59 }
56 60
57 void PerformTransfer(const TransferCallback& callback) { 61 void PerformTransfer(const TransferCallback& callback) {
58 DCHECK(texture_id_); 62 DCHECK(texture_id_);
59 DCHECK(transfer_in_progress_); 63 DCHECK(transfer_in_progress_);
60 callback.Run(texture_id_); 64 callback.Run(texture_id_);
61 transfer_in_progress_ = false; 65 transfer_in_progress_ = false;
62 } 66 }
63 67
64 private: 68 private:
65 virtual ~AsyncPixelTransferStateImpl() {}
66
67 uint64 id_; 69 uint64 id_;
68 GLuint texture_id_; 70 GLuint texture_id_;
69 bool transfer_in_progress_; 71 bool transfer_in_progress_;
72
73 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferState);
70 }; 74 };
71 75
72 } // namespace 76 } // namespace
73 77
74 // Class which handles async pixel transfers in a platform 78 // Class which handles async pixel transfers in a platform
75 // independent way. 79 // independent way.
76 class AsyncPixelTransferDelegateIdle : public AsyncPixelTransferDelegate, 80 class AsyncPixelTransferDelegateIdle : public AsyncPixelTransferDelegate,
77 public base::SupportsWeakPtr<AsyncPixelTransferDelegateIdle> { 81 public base::SupportsWeakPtr<AsyncPixelTransferDelegateIdle> {
78 public: 82 public:
79 explicit AsyncPixelTransferDelegateIdle( 83 AsyncPixelTransferDelegateIdle(
80 AsyncPixelTransferManagerIdle::SharedState* state); 84 AsyncPixelTransferManagerIdle::SharedState* state,
85 GLuint texture_id);
81 virtual ~AsyncPixelTransferDelegateIdle(); 86 virtual ~AsyncPixelTransferDelegateIdle();
82 87
83 // Implement AsyncPixelTransferDelegate: 88 // Implement AsyncPixelTransferDelegate:
84 virtual AsyncPixelTransferState* CreatePixelTransferState(
85 GLuint texture_id,
86 const AsyncTexImage2DParams& define_params) OVERRIDE;
87 virtual void AsyncTexImage2D( 89 virtual void AsyncTexImage2D(
88 AsyncPixelTransferState* transfer_state,
89 const AsyncTexImage2DParams& tex_params, 90 const AsyncTexImage2DParams& tex_params,
90 const AsyncMemoryParams& mem_params, 91 const AsyncMemoryParams& mem_params,
91 const base::Closure& bind_callback) OVERRIDE; 92 const base::Closure& bind_callback) OVERRIDE;
92 virtual void AsyncTexSubImage2D( 93 virtual void AsyncTexSubImage2D(
93 AsyncPixelTransferState* transfer_state,
94 const AsyncTexSubImage2DParams& tex_params, 94 const AsyncTexSubImage2DParams& tex_params,
95 const AsyncMemoryParams& mem_params) OVERRIDE; 95 const AsyncMemoryParams& mem_params) OVERRIDE;
96 virtual void WaitForTransferCompletion( 96 virtual bool TransferIsInProgress() OVERRIDE;
97 AsyncPixelTransferState* transfer_state) OVERRIDE; 97 virtual void WaitForTransferCompletion() OVERRIDE;
98 98
99 private: 99 private:
100 void PerformAsyncTexImage2D( 100 void PerformAsyncTexImage2D(
101 AsyncTexImage2DParams tex_params, 101 AsyncTexImage2DParams tex_params,
102 AsyncMemoryParams mem_params, 102 AsyncMemoryParams mem_params,
103 const base::Closure& bind_callback, 103 const base::Closure& bind_callback,
104 ScopedSafeSharedMemory* safe_shared_memory, 104 ScopedSafeSharedMemory* safe_shared_memory,
105 GLuint texture_id); 105 GLuint texture_id);
106 void PerformAsyncTexSubImage2D( 106 void PerformAsyncTexSubImage2D(
107 AsyncTexSubImage2DParams tex_params, 107 AsyncTexSubImage2DParams tex_params,
108 AsyncMemoryParams mem_params, 108 AsyncMemoryParams mem_params,
109 ScopedSafeSharedMemory* safe_shared_memory, 109 ScopedSafeSharedMemory* safe_shared_memory,
110 GLuint texture_id); 110 GLuint texture_id);
111 111
112 // Safe to hold a raw pointer because SharedState is owned by the Manager 112 // Safe to hold a raw pointer because SharedState is owned by the Manager
113 // which owns the Delegate. 113 // which owns the Delegate.
114 AsyncPixelTransferManagerIdle::SharedState* shared_state_; 114 AsyncPixelTransferManagerIdle::SharedState* shared_state_;
115 scoped_ptr<AsyncPixelTransferState> state_;
115 116
116 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateIdle); 117 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateIdle);
117 }; 118 };
118 119
119 AsyncPixelTransferDelegateIdle::AsyncPixelTransferDelegateIdle( 120 AsyncPixelTransferDelegateIdle::AsyncPixelTransferDelegateIdle(
120 AsyncPixelTransferManagerIdle::SharedState* shared_state) 121 AsyncPixelTransferManagerIdle::SharedState* shared_state,
121 : shared_state_(shared_state) {} 122 GLuint texture_id)
123 : shared_state_(shared_state),
124 state_(new AsyncPixelTransferState(texture_id)) {}
122 125
123 AsyncPixelTransferDelegateIdle::~AsyncPixelTransferDelegateIdle() {} 126 AsyncPixelTransferDelegateIdle::~AsyncPixelTransferDelegateIdle() {}
124 127
125 AsyncPixelTransferState* AsyncPixelTransferDelegateIdle::
126 CreatePixelTransferState(GLuint texture_id,
127 const AsyncTexImage2DParams& define_params) {
128 return new AsyncPixelTransferStateImpl(texture_id);
129 }
130
131 void AsyncPixelTransferDelegateIdle::AsyncTexImage2D( 128 void AsyncPixelTransferDelegateIdle::AsyncTexImage2D(
132 AsyncPixelTransferState* transfer_state,
133 const AsyncTexImage2DParams& tex_params, 129 const AsyncTexImage2DParams& tex_params,
134 const AsyncMemoryParams& mem_params, 130 const AsyncMemoryParams& mem_params,
135 const base::Closure& bind_callback) { 131 const base::Closure& bind_callback) {
136 AsyncPixelTransferStateImpl* state =
137 static_cast<AsyncPixelTransferStateImpl*>(transfer_state);
138 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); 132 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target);
139 DCHECK(mem_params.shared_memory); 133 DCHECK(mem_params.shared_memory);
140 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size, 134 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size,
141 mem_params.shm_size); 135 mem_params.shm_size);
142 DCHECK(state);
143 136
144 shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task( 137 shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task(
145 state->id(), 138 state_->id(),
146 base::Bind( 139 base::Bind(
147 &AsyncPixelTransferStateImpl::PerformTransfer, 140 &AsyncPixelTransferState::PerformTransfer,
148 base::AsWeakPtr(state), 141 state_->AsWeakPtr(),
149 base::Bind( 142 base::Bind(
150 &AsyncPixelTransferDelegateIdle::PerformAsyncTexImage2D, 143 &AsyncPixelTransferDelegateIdle::PerformAsyncTexImage2D,
151 AsWeakPtr(), 144 AsWeakPtr(),
152 tex_params, 145 tex_params,
153 mem_params, 146 mem_params,
154 bind_callback, 147 bind_callback,
155 base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(), 148 base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(),
156 mem_params.shared_memory, 149 mem_params.shared_memory,
157 mem_params.shm_size)))))); 150 mem_params.shm_size))))));
158 151
159 state->set_transfer_in_progress(true); 152 state_->set_transfer_in_progress(true);
160 } 153 }
161 154
162 void AsyncPixelTransferDelegateIdle::AsyncTexSubImage2D( 155 void AsyncPixelTransferDelegateIdle::AsyncTexSubImage2D(
163 AsyncPixelTransferState* transfer_state,
164 const AsyncTexSubImage2DParams& tex_params, 156 const AsyncTexSubImage2DParams& tex_params,
165 const AsyncMemoryParams& mem_params) { 157 const AsyncMemoryParams& mem_params) {
166 AsyncPixelTransferStateImpl* state =
167 static_cast<AsyncPixelTransferStateImpl*>(transfer_state);
168 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); 158 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target);
169 DCHECK(mem_params.shared_memory); 159 DCHECK(mem_params.shared_memory);
170 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size, 160 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size,
171 mem_params.shm_size); 161 mem_params.shm_size);
172 DCHECK(state);
173 162
174 shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task( 163 shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task(
175 state->id(), 164 state_->id(),
176 base::Bind( 165 base::Bind(
177 &AsyncPixelTransferStateImpl::PerformTransfer, 166 &AsyncPixelTransferState::PerformTransfer,
178 base::AsWeakPtr(state), 167 state_->AsWeakPtr(),
179 base::Bind( 168 base::Bind(
180 &AsyncPixelTransferDelegateIdle::PerformAsyncTexSubImage2D, 169 &AsyncPixelTransferDelegateIdle::PerformAsyncTexSubImage2D,
181 AsWeakPtr(), 170 AsWeakPtr(),
182 tex_params, 171 tex_params,
183 mem_params, 172 mem_params,
184 base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(), 173 base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(),
185 mem_params.shared_memory, 174 mem_params.shared_memory,
186 mem_params.shm_size)))))); 175 mem_params.shm_size))))));
187 176
188 state->set_transfer_in_progress(true); 177 state_->set_transfer_in_progress(true);
189 } 178 }
190 179
191 void AsyncPixelTransferDelegateIdle::WaitForTransferCompletion( 180 bool AsyncPixelTransferDelegateIdle::TransferIsInProgress() {
192 AsyncPixelTransferState* transfer_state) { 181 return state_->TransferIsInProgress();
193 AsyncPixelTransferStateImpl* state = 182 }
194 static_cast<AsyncPixelTransferStateImpl*>(transfer_state);
195 DCHECK(state);
196 183
184 void AsyncPixelTransferDelegateIdle::WaitForTransferCompletion() {
197 for (std::list<AsyncPixelTransferManagerIdle::Task>::iterator iter = 185 for (std::list<AsyncPixelTransferManagerIdle::Task>::iterator iter =
198 shared_state_->tasks.begin(); 186 shared_state_->tasks.begin();
199 iter != shared_state_->tasks.end(); 187 iter != shared_state_->tasks.end();
200 ++iter) { 188 ++iter) {
201 if (iter->transfer_id != state->id()) 189 if (iter->transfer_id != state_->id())
202 continue; 190 continue;
203 191
204 (*iter).task.Run(); 192 (*iter).task.Run();
205 shared_state_->tasks.erase(iter); 193 shared_state_->tasks.erase(iter);
206 break; 194 break;
207 } 195 }
208 196
209 shared_state_->ProcessNotificationTasks(); 197 shared_state_->ProcessNotificationTasks();
210 } 198 }
211 199
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // Stop when we reach a pixel transfer task. 280 // Stop when we reach a pixel transfer task.
293 if (tasks.front().transfer_id) 281 if (tasks.front().transfer_id)
294 return; 282 return;
295 283
296 tasks.front().task.Run(); 284 tasks.front().task.Run();
297 tasks.pop_front(); 285 tasks.pop_front();
298 } 286 }
299 } 287 }
300 288
301 AsyncPixelTransferManagerIdle::AsyncPixelTransferManagerIdle() 289 AsyncPixelTransferManagerIdle::AsyncPixelTransferManagerIdle()
302 : shared_state_(), 290 : shared_state_() {
303 delegate_(new AsyncPixelTransferDelegateIdle(&shared_state_)) {} 291 }
304 292
305 AsyncPixelTransferManagerIdle::~AsyncPixelTransferManagerIdle() {} 293 AsyncPixelTransferManagerIdle::~AsyncPixelTransferManagerIdle() {}
306 294
307 void AsyncPixelTransferManagerIdle::BindCompletedAsyncTransfers() { 295 void AsyncPixelTransferManagerIdle::BindCompletedAsyncTransfers() {
308 // Everything is already bound. 296 // Everything is already bound.
309 } 297 }
310 298
311 void AsyncPixelTransferManagerIdle::AsyncNotifyCompletion( 299 void AsyncPixelTransferManagerIdle::AsyncNotifyCompletion(
312 const AsyncMemoryParams& mem_params, 300 const AsyncMemoryParams& mem_params,
313 const CompletionCallback& callback) { 301 const CompletionCallback& callback) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 shared_state_.tasks.pop_front(); 333 shared_state_.tasks.pop_front();
346 334
347 shared_state_.ProcessNotificationTasks(); 335 shared_state_.ProcessNotificationTasks();
348 } 336 }
349 337
350 bool AsyncPixelTransferManagerIdle::NeedsProcessMorePendingTransfers() { 338 bool AsyncPixelTransferManagerIdle::NeedsProcessMorePendingTransfers() {
351 return !shared_state_.tasks.empty(); 339 return !shared_state_.tasks.empty();
352 } 340 }
353 341
354 AsyncPixelTransferDelegate* 342 AsyncPixelTransferDelegate*
355 AsyncPixelTransferManagerIdle::GetAsyncPixelTransferDelegate() { 343 AsyncPixelTransferManagerIdle::CreatePixelTransferDelegateImpl(
356 return delegate_.get(); 344 gles2::TextureRef* ref,
345 const AsyncTexImage2DParams& define_params) {
346 return new AsyncPixelTransferDelegateIdle(&shared_state_, ref->service_id());
357 } 347 }
358 348
359 } // namespace gpu 349 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698