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_share_group.h" | 5 #include "gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 // Class which holds async pixel transfers state. | 196 // Class which holds async pixel transfers state. |
197 // The texture_id is accessed by either thread, but everything | 197 // The texture_id is accessed by either thread, but everything |
198 // else accessed only on the main thread. | 198 // else accessed only on the main thread. |
199 class TransferStateInternal | 199 class TransferStateInternal |
200 : public base::RefCountedThreadSafe<TransferStateInternal> { | 200 : public base::RefCountedThreadSafe<TransferStateInternal> { |
201 public: | 201 public: |
202 TransferStateInternal(GLuint texture_id, | 202 TransferStateInternal(GLuint texture_id, |
203 const AsyncTexImage2DParams& define_params) | 203 const AsyncTexImage2DParams& define_params) |
204 : texture_id_(texture_id), define_params_(define_params) {} | 204 : texture_id_(texture_id), define_params_(define_params) {} |
| 205 TransferStateInternal(GLuint texture_id, |
| 206 const AsyncCompressedTexImage2DParams& define_params) |
| 207 : texture_id_(texture_id), compressed_define_params_(define_params) {} |
205 | 208 |
206 bool TransferIsInProgress() { | 209 bool TransferIsInProgress() { |
207 return pending_upload_task_.get() && | 210 return pending_upload_task_.get() && |
208 pending_upload_task_->TaskIsInProgress(); | 211 pending_upload_task_->TaskIsInProgress(); |
209 } | 212 } |
210 | 213 |
211 void BindTransfer() { | 214 void BindTransfer() { |
212 TRACE_EVENT2("gpu", "BindAsyncTransfer", | 215 TRACE_EVENT2("gpu", "BindAsyncTransfer", |
213 "width", define_params_.width, | 216 "width", define_params_.width, |
214 "height", define_params_.height); | 217 "height", define_params_.height); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 this, | 269 this, |
267 tex_params, | 270 tex_params, |
268 mem_params, | 271 mem_params, |
269 texture_upload_stats)); | 272 texture_upload_stats)); |
270 transfer_message_loop_proxy()->PostTask( | 273 transfer_message_loop_proxy()->PostTask( |
271 FROM_HERE, | 274 FROM_HERE, |
272 base::Bind( | 275 base::Bind( |
273 &PendingTask::BindAndRun, pending_upload_task_, texture_id_)); | 276 &PendingTask::BindAndRun, pending_upload_task_, texture_id_)); |
274 } | 277 } |
275 | 278 |
| 279 void ScheduleAsyncCompressedTexImage2D( |
| 280 const AsyncCompressedTexImage2DParams tex_params, |
| 281 const AsyncMemoryParams mem_params, |
| 282 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats, |
| 283 const base::Closure& bind_callback) { |
| 284 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); |
| 285 pending_upload_task_ = new PendingTask( |
| 286 base::Bind(&TransferStateInternal::PerformAsyncCompressedTexImage2D, |
| 287 this, tex_params, mem_params, texture_upload_stats)); |
| 288 transfer_message_loop_proxy()->PostTask( |
| 289 FROM_HERE, base::Bind(&PendingTask::BindAndRun, pending_upload_task_, |
| 290 texture_id_)); |
| 291 |
| 292 // Save the late bind callback, so we can notify the client when it is |
| 293 // bound. |
| 294 bind_callback_ = bind_callback; |
| 295 } |
| 296 |
| 297 void ScheduleAsyncCompressedTexSubImage2D( |
| 298 AsyncCompressedTexSubImage2DParams tex_params, |
| 299 AsyncMemoryParams mem_params, |
| 300 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats) { |
| 301 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); |
| 302 pending_upload_task_ = new PendingTask( |
| 303 base::Bind(&TransferStateInternal::PerformAsyncCompressedTexSubImage2D, |
| 304 this, tex_params, mem_params, texture_upload_stats)); |
| 305 transfer_message_loop_proxy()->PostTask( |
| 306 FROM_HERE, base::Bind(&PendingTask::BindAndRun, pending_upload_task_, |
| 307 texture_id_)); |
| 308 } |
| 309 |
276 private: | 310 private: |
277 friend class base::RefCountedThreadSafe<TransferStateInternal>; | 311 friend class base::RefCountedThreadSafe<TransferStateInternal>; |
278 | 312 |
279 virtual ~TransferStateInternal() { | 313 virtual ~TransferStateInternal() { |
280 } | 314 } |
281 | 315 |
282 void PerformAsyncTexImage2D( | 316 void PerformAsyncTexImage2D( |
283 AsyncTexImage2DParams tex_params, | 317 AsyncTexImage2DParams tex_params, |
284 AsyncMemoryParams mem_params, | 318 AsyncMemoryParams mem_params, |
285 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats) { | 319 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 data); | 381 data); |
348 TRACE_EVENT_SYNTHETIC_DELAY_END("gpu.AsyncTexImage"); | 382 TRACE_EVENT_SYNTHETIC_DELAY_END("gpu.AsyncTexImage"); |
349 } | 383 } |
350 | 384 |
351 if (texture_upload_stats.get()) { | 385 if (texture_upload_stats.get()) { |
352 texture_upload_stats->AddUpload(base::TimeTicks::HighResNow() - | 386 texture_upload_stats->AddUpload(base::TimeTicks::HighResNow() - |
353 begin_time); | 387 begin_time); |
354 } | 388 } |
355 } | 389 } |
356 | 390 |
| 391 void PerformAsyncCompressedTexImage2D( |
| 392 AsyncCompressedTexImage2DParams tex_params, |
| 393 AsyncMemoryParams mem_params, |
| 394 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats) { |
| 395 TRACE_EVENT2("gpu", "PerformAsyncCompressedTexImage", "width", |
| 396 tex_params.width, "height", tex_params.height); |
| 397 DCHECK_EQ(0, tex_params.level); |
| 398 |
| 399 base::TimeTicks begin_time; |
| 400 if (texture_upload_stats.get()) |
| 401 begin_time = base::TimeTicks::HighResNow(); |
| 402 |
| 403 void* data = mem_params.GetDataAddress(); |
| 404 |
| 405 { |
| 406 TRACE_EVENT0("gpu", "glCompressedTexImage2D"); |
| 407 glCompressedTexImage2D(GL_TEXTURE_2D, tex_params.level, |
| 408 tex_params.internal_format, tex_params.width, |
| 409 tex_params.height, tex_params.border, |
| 410 tex_params.image_size, data); |
| 411 TRACE_EVENT_SYNTHETIC_DELAY_END("gpu.AsyncTexImage"); |
| 412 } |
| 413 |
| 414 if (texture_upload_stats.get()) { |
| 415 texture_upload_stats->AddUpload(base::TimeTicks::HighResNow() - |
| 416 begin_time); |
| 417 } |
| 418 } |
| 419 |
| 420 void PerformAsyncCompressedTexSubImage2D( |
| 421 AsyncCompressedTexSubImage2DParams tex_params, |
| 422 AsyncMemoryParams mem_params, |
| 423 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats) { |
| 424 TRACE_EVENT2("gpu", "PerformAsyncCompressedTexSubImage2D", "width", |
| 425 tex_params.width, "height", tex_params.height); |
| 426 DCHECK_EQ(0, tex_params.level); |
| 427 |
| 428 base::TimeTicks begin_time; |
| 429 if (texture_upload_stats.get()) |
| 430 begin_time = base::TimeTicks::HighResNow(); |
| 431 |
| 432 void* data = mem_params.GetDataAddress(); |
| 433 |
| 434 { |
| 435 TRACE_EVENT0("gpu", "glCompressedTexSubImage2D"); |
| 436 glCompressedTexSubImage2D(GL_TEXTURE_2D, tex_params.level, |
| 437 tex_params.xoffset, tex_params.yoffset, |
| 438 tex_params.width, tex_params.height, |
| 439 tex_params.format, tex_params.image_size, data); |
| 440 TRACE_EVENT_SYNTHETIC_DELAY_END("gpu.AsyncTexImage"); |
| 441 } |
| 442 |
| 443 if (texture_upload_stats.get()) { |
| 444 texture_upload_stats->AddUpload(base::TimeTicks::HighResNow() - |
| 445 begin_time); |
| 446 } |
| 447 } |
| 448 |
357 scoped_refptr<PendingTask> pending_upload_task_; | 449 scoped_refptr<PendingTask> pending_upload_task_; |
358 | 450 |
359 GLuint texture_id_; | 451 GLuint texture_id_; |
360 | 452 |
361 // Definition params for texture that needs binding. | 453 // Definition params for texture that needs binding. |
362 AsyncTexImage2DParams define_params_; | 454 union { |
| 455 AsyncTexImage2DParams define_params_; |
| 456 AsyncCompressedTexImage2DParams compressed_define_params_; |
| 457 }; |
363 | 458 |
364 // Callback to invoke when AsyncTexImage2D is complete | 459 // Callback to invoke when AsyncTexImage2D is complete |
365 // and the client can safely use the texture. This occurs | 460 // and the client can safely use the texture. This occurs |
366 // during BindCompletedAsyncTransfers(). | 461 // during BindCompletedAsyncTransfers(). |
367 base::Closure bind_callback_; | 462 base::Closure bind_callback_; |
368 }; | 463 }; |
369 | 464 |
370 } // namespace | 465 } // namespace |
371 | 466 |
372 class AsyncPixelTransferDelegateShareGroup | 467 class AsyncPixelTransferDelegateShareGroup |
373 : public AsyncPixelTransferDelegate, | 468 : public AsyncPixelTransferDelegate, |
374 public base::SupportsWeakPtr<AsyncPixelTransferDelegateShareGroup> { | 469 public base::SupportsWeakPtr<AsyncPixelTransferDelegateShareGroup> { |
375 public: | 470 public: |
376 AsyncPixelTransferDelegateShareGroup( | 471 AsyncPixelTransferDelegateShareGroup( |
377 AsyncPixelTransferManagerShareGroup::SharedState* shared_state, | 472 AsyncPixelTransferManagerShareGroup::SharedState* shared_state, |
378 GLuint texture_id, | 473 GLuint texture_id, |
379 const AsyncTexImage2DParams& define_params); | 474 const AsyncTexImage2DParams& define_params); |
| 475 AsyncPixelTransferDelegateShareGroup( |
| 476 AsyncPixelTransferManagerShareGroup::SharedState* shared_state, |
| 477 GLuint texture_id, |
| 478 const AsyncCompressedTexImage2DParams& define_params); |
380 ~AsyncPixelTransferDelegateShareGroup() override; | 479 ~AsyncPixelTransferDelegateShareGroup() override; |
381 | 480 |
382 void BindTransfer() { state_->BindTransfer(); } | 481 void BindTransfer() { state_->BindTransfer(); } |
383 | 482 |
384 // Implement AsyncPixelTransferDelegate: | 483 // Implement AsyncPixelTransferDelegate: |
385 void AsyncTexImage2D(const AsyncTexImage2DParams& tex_params, | 484 void AsyncTexImage2D(const AsyncTexImage2DParams& tex_params, |
386 const AsyncMemoryParams& mem_params, | 485 const AsyncMemoryParams& mem_params, |
387 const base::Closure& bind_callback) override; | 486 const base::Closure& bind_callback) override; |
388 void AsyncTexSubImage2D(const AsyncTexSubImage2DParams& tex_params, | 487 void AsyncTexSubImage2D(const AsyncTexSubImage2DParams& tex_params, |
389 const AsyncMemoryParams& mem_params) override; | 488 const AsyncMemoryParams& mem_params) override; |
| 489 void AsyncCompressedTexImage2D( |
| 490 const AsyncCompressedTexImage2DParams& tex_params, |
| 491 const AsyncMemoryParams& mem_params, |
| 492 const base::Closure& bind_callback) override; |
| 493 void AsyncCompressedTexSubImage2D( |
| 494 const AsyncCompressedTexSubImage2DParams& tex_params, |
| 495 const AsyncMemoryParams& mem_params) override; |
390 bool TransferIsInProgress() override; | 496 bool TransferIsInProgress() override; |
391 void WaitForTransferCompletion() override; | 497 void WaitForTransferCompletion() override; |
392 | 498 |
393 private: | 499 private: |
394 // A raw pointer is safe because the SharedState is owned by the Manager, | 500 // A raw pointer is safe because the SharedState is owned by the Manager, |
395 // which owns this Delegate. | 501 // which owns this Delegate. |
396 AsyncPixelTransferManagerShareGroup::SharedState* shared_state_; | 502 AsyncPixelTransferManagerShareGroup::SharedState* shared_state_; |
397 scoped_refptr<TransferStateInternal> state_; | 503 scoped_refptr<TransferStateInternal> state_; |
398 | 504 |
399 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateShareGroup); | 505 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateShareGroup); |
400 }; | 506 }; |
401 | 507 |
402 AsyncPixelTransferDelegateShareGroup::AsyncPixelTransferDelegateShareGroup( | 508 AsyncPixelTransferDelegateShareGroup::AsyncPixelTransferDelegateShareGroup( |
403 AsyncPixelTransferManagerShareGroup::SharedState* shared_state, | 509 AsyncPixelTransferManagerShareGroup::SharedState* shared_state, |
404 GLuint texture_id, | 510 GLuint texture_id, |
405 const AsyncTexImage2DParams& define_params) | 511 const AsyncTexImage2DParams& define_params) |
406 : shared_state_(shared_state), | 512 : shared_state_(shared_state), |
407 state_(new TransferStateInternal(texture_id, define_params)) {} | 513 state_(new TransferStateInternal(texture_id, define_params)) {} |
408 | 514 |
| 515 AsyncPixelTransferDelegateShareGroup::AsyncPixelTransferDelegateShareGroup( |
| 516 AsyncPixelTransferManagerShareGroup::SharedState* shared_state, |
| 517 GLuint texture_id, |
| 518 const AsyncCompressedTexImage2DParams& define_params) |
| 519 : shared_state_(shared_state), |
| 520 state_(new TransferStateInternal(texture_id, define_params)) { |
| 521 } |
| 522 |
409 AsyncPixelTransferDelegateShareGroup::~AsyncPixelTransferDelegateShareGroup() { | 523 AsyncPixelTransferDelegateShareGroup::~AsyncPixelTransferDelegateShareGroup() { |
410 TRACE_EVENT0("gpu", " ~AsyncPixelTransferDelegateShareGroup"); | 524 TRACE_EVENT0("gpu", " ~AsyncPixelTransferDelegateShareGroup"); |
411 state_->CancelUpload(); | 525 state_->CancelUpload(); |
412 } | 526 } |
413 | 527 |
414 bool AsyncPixelTransferDelegateShareGroup::TransferIsInProgress() { | 528 bool AsyncPixelTransferDelegateShareGroup::TransferIsInProgress() { |
415 return state_->TransferIsInProgress(); | 529 return state_->TransferIsInProgress(); |
416 } | 530 } |
417 | 531 |
418 void AsyncPixelTransferDelegateShareGroup::WaitForTransferCompletion() { | 532 void AsyncPixelTransferDelegateShareGroup::WaitForTransferCompletion() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 "width", tex_params.width, | 571 "width", tex_params.width, |
458 "height", tex_params.height); | 572 "height", tex_params.height); |
459 DCHECK(!state_->TransferIsInProgress()); | 573 DCHECK(!state_->TransferIsInProgress()); |
460 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); | 574 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); |
461 DCHECK_EQ(tex_params.level, 0); | 575 DCHECK_EQ(tex_params.level, 0); |
462 | 576 |
463 state_->ScheduleAsyncTexSubImage2D( | 577 state_->ScheduleAsyncTexSubImage2D( |
464 tex_params, mem_params, shared_state_->texture_upload_stats); | 578 tex_params, mem_params, shared_state_->texture_upload_stats); |
465 } | 579 } |
466 | 580 |
| 581 void AsyncPixelTransferDelegateShareGroup::AsyncCompressedTexImage2D( |
| 582 const AsyncCompressedTexImage2DParams& tex_params, |
| 583 const AsyncMemoryParams& mem_params, |
| 584 const base::Closure& bind_callback) { |
| 585 DCHECK(!state_->TransferIsInProgress()); |
| 586 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); |
| 587 DCHECK_EQ(tex_params.level, 0); |
| 588 |
| 589 shared_state_->pending_allocations.push_back(AsWeakPtr()); |
| 590 state_->ScheduleAsyncCompressedTexImage2D(tex_params, mem_params, |
| 591 shared_state_->texture_upload_stats, |
| 592 bind_callback); |
| 593 } |
| 594 |
| 595 void AsyncPixelTransferDelegateShareGroup::AsyncCompressedTexSubImage2D( |
| 596 const AsyncCompressedTexSubImage2DParams& tex_params, |
| 597 const AsyncMemoryParams& mem_params) { |
| 598 TRACE_EVENT2("gpu", "AsyncCompressedTexSubImage2D", "width", tex_params.width, |
| 599 "height", tex_params.height); |
| 600 DCHECK(!state_->TransferIsInProgress()); |
| 601 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); |
| 602 DCHECK_EQ(tex_params.level, 0); |
| 603 |
| 604 state_->ScheduleAsyncCompressedTexSubImage2D( |
| 605 tex_params, mem_params, shared_state_->texture_upload_stats); |
| 606 } |
| 607 |
467 AsyncPixelTransferManagerShareGroup::SharedState::SharedState() | 608 AsyncPixelTransferManagerShareGroup::SharedState::SharedState() |
468 // TODO(reveman): Skip this if --enable-gpu-benchmarking is not present. | 609 // TODO(reveman): Skip this if --enable-gpu-benchmarking is not present. |
469 : texture_upload_stats(new AsyncPixelTransferUploadStats) {} | 610 : texture_upload_stats(new AsyncPixelTransferUploadStats) {} |
470 | 611 |
471 AsyncPixelTransferManagerShareGroup::SharedState::~SharedState() {} | 612 AsyncPixelTransferManagerShareGroup::SharedState::~SharedState() {} |
472 | 613 |
473 AsyncPixelTransferManagerShareGroup::AsyncPixelTransferManagerShareGroup( | 614 AsyncPixelTransferManagerShareGroup::AsyncPixelTransferManagerShareGroup( |
474 gfx::GLContext* context) { | 615 gfx::GLContext* context) { |
475 g_transfer_thread.Pointer()->InitializeOnMainThread(context); | 616 g_transfer_thread.Pointer()->InitializeOnMainThread(context); |
476 } | 617 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 } | 684 } |
544 | 685 |
545 AsyncPixelTransferDelegate* | 686 AsyncPixelTransferDelegate* |
546 AsyncPixelTransferManagerShareGroup::CreatePixelTransferDelegateImpl( | 687 AsyncPixelTransferManagerShareGroup::CreatePixelTransferDelegateImpl( |
547 gles2::TextureRef* ref, | 688 gles2::TextureRef* ref, |
548 const AsyncTexImage2DParams& define_params) { | 689 const AsyncTexImage2DParams& define_params) { |
549 return new AsyncPixelTransferDelegateShareGroup( | 690 return new AsyncPixelTransferDelegateShareGroup( |
550 &shared_state_, ref->service_id(), define_params); | 691 &shared_state_, ref->service_id(), define_params); |
551 } | 692 } |
552 | 693 |
| 694 AsyncPixelTransferDelegate* |
| 695 AsyncPixelTransferManagerShareGroup::CreatePixelTransferDelegateImpl( |
| 696 gles2::TextureRef* ref, |
| 697 const AsyncCompressedTexImage2DParams& define_params) { |
| 698 return new AsyncPixelTransferDelegateShareGroup( |
| 699 &shared_state_, ref->service_id(), define_params); |
| 700 } |
| 701 |
553 } // namespace gpu | 702 } // namespace gpu |
OLD | NEW |