OLD | NEW |
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/debug/trace_event_synthetic_delay.h" | 9 #include "base/debug/trace_event_synthetic_delay.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 void AsyncPixelTransferDelegateIdle::AsyncTexImage2D( | 83 void AsyncPixelTransferDelegateIdle::AsyncTexImage2D( |
84 const AsyncTexImage2DParams& tex_params, | 84 const AsyncTexImage2DParams& tex_params, |
85 const AsyncMemoryParams& mem_params, | 85 const AsyncMemoryParams& mem_params, |
86 const base::Closure& bind_callback) { | 86 const base::Closure& bind_callback) { |
87 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); | 87 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); |
88 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); | 88 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); |
89 | 89 |
90 shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task( | 90 shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task( |
91 id_, | 91 id_, |
| 92 this, |
92 base::Bind(&AsyncPixelTransferDelegateIdle::PerformAsyncTexImage2D, | 93 base::Bind(&AsyncPixelTransferDelegateIdle::PerformAsyncTexImage2D, |
93 AsWeakPtr(), | 94 AsWeakPtr(), |
94 tex_params, | 95 tex_params, |
95 mem_params, | 96 mem_params, |
96 bind_callback))); | 97 bind_callback))); |
97 | 98 |
98 transfer_in_progress_ = true; | 99 transfer_in_progress_ = true; |
99 } | 100 } |
100 | 101 |
101 void AsyncPixelTransferDelegateIdle::AsyncTexSubImage2D( | 102 void AsyncPixelTransferDelegateIdle::AsyncTexSubImage2D( |
102 const AsyncTexSubImage2DParams& tex_params, | 103 const AsyncTexSubImage2DParams& tex_params, |
103 const AsyncMemoryParams& mem_params) { | 104 const AsyncMemoryParams& mem_params) { |
104 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); | 105 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); |
105 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); | 106 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); |
106 | 107 |
107 shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task( | 108 shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task( |
108 id_, | 109 id_, |
| 110 this, |
109 base::Bind(&AsyncPixelTransferDelegateIdle::PerformAsyncTexSubImage2D, | 111 base::Bind(&AsyncPixelTransferDelegateIdle::PerformAsyncTexSubImage2D, |
110 AsWeakPtr(), | 112 AsWeakPtr(), |
111 tex_params, | 113 tex_params, |
112 mem_params))); | 114 mem_params))); |
113 | 115 |
114 transfer_in_progress_ = true; | 116 transfer_in_progress_ = true; |
115 } | 117 } |
116 | 118 |
117 bool AsyncPixelTransferDelegateIdle::TransferIsInProgress() { | 119 bool AsyncPixelTransferDelegateIdle::TransferIsInProgress() { |
118 return transfer_in_progress_; | 120 return transfer_in_progress_; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 219 } |
218 | 220 |
219 TRACE_EVENT_SYNTHETIC_DELAY_END("gpu.AsyncTexImage"); | 221 TRACE_EVENT_SYNTHETIC_DELAY_END("gpu.AsyncTexImage"); |
220 transfer_in_progress_ = false; | 222 transfer_in_progress_ = false; |
221 shared_state_->texture_upload_count++; | 223 shared_state_->texture_upload_count++; |
222 shared_state_->total_texture_upload_time += | 224 shared_state_->total_texture_upload_time += |
223 base::TimeTicks::HighResNow() - begin_time; | 225 base::TimeTicks::HighResNow() - begin_time; |
224 } | 226 } |
225 | 227 |
226 AsyncPixelTransferManagerIdle::Task::Task( | 228 AsyncPixelTransferManagerIdle::Task::Task( |
227 uint64 transfer_id, const base::Closure& task) | 229 uint64 transfer_id, |
| 230 AsyncPixelTransferDelegate* delegate, |
| 231 const base::Closure& task) |
228 : transfer_id(transfer_id), | 232 : transfer_id(transfer_id), |
| 233 delegate(delegate), |
229 task(task) { | 234 task(task) { |
230 } | 235 } |
231 | 236 |
232 AsyncPixelTransferManagerIdle::Task::~Task() {} | 237 AsyncPixelTransferManagerIdle::Task::~Task() {} |
233 | 238 |
234 AsyncPixelTransferManagerIdle::SharedState::SharedState() | 239 AsyncPixelTransferManagerIdle::SharedState::SharedState() |
235 : texture_upload_count(0) {} | 240 : texture_upload_count(0) {} |
236 | 241 |
237 AsyncPixelTransferManagerIdle::SharedState::~SharedState() {} | 242 AsyncPixelTransferManagerIdle::SharedState::~SharedState() {} |
238 | 243 |
(...skipping 21 matching lines...) Expand all Loading... |
260 void AsyncPixelTransferManagerIdle::AsyncNotifyCompletion( | 265 void AsyncPixelTransferManagerIdle::AsyncNotifyCompletion( |
261 const AsyncMemoryParams& mem_params, | 266 const AsyncMemoryParams& mem_params, |
262 AsyncPixelTransferCompletionObserver* observer) { | 267 AsyncPixelTransferCompletionObserver* observer) { |
263 if (shared_state_.tasks.empty()) { | 268 if (shared_state_.tasks.empty()) { |
264 observer->DidComplete(mem_params); | 269 observer->DidComplete(mem_params); |
265 return; | 270 return; |
266 } | 271 } |
267 | 272 |
268 shared_state_.tasks.push_back( | 273 shared_state_.tasks.push_back( |
269 Task(0, // 0 transfer_id for notification tasks. | 274 Task(0, // 0 transfer_id for notification tasks. |
| 275 NULL, |
270 base::Bind( | 276 base::Bind( |
271 &PerformNotifyCompletion, | 277 &PerformNotifyCompletion, |
272 mem_params, | 278 mem_params, |
273 make_scoped_refptr(observer)))); | 279 make_scoped_refptr(observer)))); |
274 } | 280 } |
275 | 281 |
276 uint32 AsyncPixelTransferManagerIdle::GetTextureUploadCount() { | 282 uint32 AsyncPixelTransferManagerIdle::GetTextureUploadCount() { |
277 return shared_state_.texture_upload_count; | 283 return shared_state_.texture_upload_count; |
278 } | 284 } |
279 | 285 |
(...skipping 10 matching lines...) Expand all Loading... |
290 shared_state_.tasks.front().task.Run(); | 296 shared_state_.tasks.front().task.Run(); |
291 shared_state_.tasks.pop_front(); | 297 shared_state_.tasks.pop_front(); |
292 | 298 |
293 shared_state_.ProcessNotificationTasks(); | 299 shared_state_.ProcessNotificationTasks(); |
294 } | 300 } |
295 | 301 |
296 bool AsyncPixelTransferManagerIdle::NeedsProcessMorePendingTransfers() { | 302 bool AsyncPixelTransferManagerIdle::NeedsProcessMorePendingTransfers() { |
297 return !shared_state_.tasks.empty(); | 303 return !shared_state_.tasks.empty(); |
298 } | 304 } |
299 | 305 |
| 306 void AsyncPixelTransferManagerIdle::WaitAllAsyncTexImage2D() { |
| 307 if (shared_state_.tasks.empty()) |
| 308 return; |
| 309 |
| 310 const Task& task = shared_state_.tasks.back(); |
| 311 if (task.delegate) |
| 312 task.delegate->WaitForTransferCompletion(); |
| 313 } |
| 314 |
300 AsyncPixelTransferDelegate* | 315 AsyncPixelTransferDelegate* |
301 AsyncPixelTransferManagerIdle::CreatePixelTransferDelegateImpl( | 316 AsyncPixelTransferManagerIdle::CreatePixelTransferDelegateImpl( |
302 gles2::TextureRef* ref, | 317 gles2::TextureRef* ref, |
303 const AsyncTexImage2DParams& define_params) { | 318 const AsyncTexImage2DParams& define_params) { |
304 return new AsyncPixelTransferDelegateIdle(&shared_state_, | 319 return new AsyncPixelTransferDelegateIdle(&shared_state_, |
305 ref->service_id(), | 320 ref->service_id(), |
306 define_params); | 321 define_params); |
307 } | 322 } |
308 | 323 |
309 } // namespace gpu | 324 } // namespace gpu |
OLD | NEW |