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

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

Issue 1129903002: gpu: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 5 years, 7 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
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_egl.h" 5 #include "gpu/command_buffer/service/async_pixel_transfer_manager_egl.h"
6 6
7 #include <list> 7 #include <list>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/location.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/single_thread_task_runner.h"
14 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
15 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
16 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
17 #include "base/trace_event/trace_event_synthetic_delay.h" 19 #include "base/trace_event/trace_event_synthetic_delay.h"
18 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" 20 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h"
19 #include "ui/gl/gl_context.h" 21 #include "ui/gl/gl_context.h"
20 #include "ui/gl/gl_surface_egl.h" 22 #include "ui/gl/gl_surface_egl.h"
21 #include "ui/gl/scoped_binders.h" 23 #include "ui/gl/scoped_binders.h"
22 24
23 namespace gpu { 25 namespace gpu {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 private: 116 private:
115 scoped_refptr<gfx::GLContext> context_; 117 scoped_refptr<gfx::GLContext> context_;
116 scoped_refptr<gfx::GLSurface> surface_; 118 scoped_refptr<gfx::GLSurface> surface_;
117 119
118 DISALLOW_COPY_AND_ASSIGN(TransferThread); 120 DISALLOW_COPY_AND_ASSIGN(TransferThread);
119 }; 121 };
120 122
121 base::LazyInstance<TransferThread> 123 base::LazyInstance<TransferThread>
122 g_transfer_thread = LAZY_INSTANCE_INITIALIZER; 124 g_transfer_thread = LAZY_INSTANCE_INITIALIZER;
123 125
124 base::MessageLoopProxy* transfer_message_loop_proxy() { 126 base::SingleThreadTaskRunner* transfer_task_runner() {
125 return g_transfer_thread.Pointer()->message_loop_proxy().get(); 127 return g_transfer_thread.Pointer()->task_runner().get();
126 } 128 }
127 129
128 // Class which holds async pixel transfers state (EGLImage). 130 // Class which holds async pixel transfers state (EGLImage).
129 // The EGLImage is accessed by either thread, but everything 131 // The EGLImage is accessed by either thread, but everything
130 // else accessed only on the main thread. 132 // else accessed only on the main thread.
131 class TransferStateInternal 133 class TransferStateInternal
132 : public base::RefCountedThreadSafe<TransferStateInternal> { 134 : public base::RefCountedThreadSafe<TransferStateInternal> {
133 public: 135 public:
134 TransferStateInternal(GLuint texture_id, 136 TransferStateInternal(GLuint texture_id,
135 const AsyncTexImage2DParams& define_params, 137 const AsyncTexImage2DParams& define_params,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 static void DeleteTexture(GLuint id) { 347 static void DeleteTexture(GLuint id) {
346 glDeleteTextures(1, &id); 348 glDeleteTextures(1, &id);
347 } 349 }
348 350
349 virtual ~TransferStateInternal() { 351 virtual ~TransferStateInternal() {
350 if (egl_image_ != EGL_NO_IMAGE_KHR) { 352 if (egl_image_ != EGL_NO_IMAGE_KHR) {
351 EGLDisplay display = eglGetCurrentDisplay(); 353 EGLDisplay display = eglGetCurrentDisplay();
352 eglDestroyImageKHR(display, egl_image_); 354 eglDestroyImageKHR(display, egl_image_);
353 } 355 }
354 if (thread_texture_id_) { 356 if (thread_texture_id_) {
355 transfer_message_loop_proxy()->PostTask(FROM_HERE, 357 transfer_task_runner()->PostTask(
356 base::Bind(&DeleteTexture, thread_texture_id_)); 358 FROM_HERE, base::Bind(&DeleteTexture, thread_texture_id_));
357 } 359 }
358 } 360 }
359 361
360 // The 'real' texture. 362 // The 'real' texture.
361 GLuint texture_id_; 363 GLuint texture_id_;
362 364
363 // The EGLImage sibling on the upload thread. 365 // The EGLImage sibling on the upload thread.
364 GLuint thread_texture_id_; 366 GLuint thread_texture_id_;
365 367
366 // Definition params for texture that needs binding. 368 // Definition params for texture that needs binding.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // Mark the transfer in progress and save the late bind 495 // Mark the transfer in progress and save the late bind
494 // callback, so we can notify the client when it is bound. 496 // callback, so we can notify the client when it is bound.
495 shared_state_->pending_allocations.push_back(AsWeakPtr()); 497 shared_state_->pending_allocations.push_back(AsWeakPtr());
496 state_->bind_callback_ = bind_callback; 498 state_->bind_callback_ = bind_callback;
497 499
498 // Mark the transfer in progress. 500 // Mark the transfer in progress.
499 state_->MarkAsTransferIsInProgress(); 501 state_->MarkAsTransferIsInProgress();
500 502
501 // Duplicate the shared memory so there is no way we can get 503 // Duplicate the shared memory so there is no way we can get
502 // a use-after-free of the raw pixels. 504 // a use-after-free of the raw pixels.
503 transfer_message_loop_proxy()->PostTask(FROM_HERE, 505 transfer_task_runner()->PostTask(
504 base::Bind( 506 FROM_HERE,
505 &TransferStateInternal::PerformAsyncTexImage2D, 507 base::Bind(&TransferStateInternal::PerformAsyncTexImage2D, state_,
506 state_, 508 tex_params, mem_params, shared_state_->texture_upload_stats));
507 tex_params,
508 mem_params,
509 shared_state_->texture_upload_stats));
510 509
511 DCHECK(CHECK_GL()); 510 DCHECK(CHECK_GL());
512 } 511 }
513 512
514 void AsyncPixelTransferDelegateEGL::AsyncTexSubImage2D( 513 void AsyncPixelTransferDelegateEGL::AsyncTexSubImage2D(
515 const AsyncTexSubImage2DParams& tex_params, 514 const AsyncTexSubImage2DParams& tex_params,
516 const AsyncMemoryParams& mem_params) { 515 const AsyncMemoryParams& mem_params) {
517 TRACE_EVENT2("gpu", "AsyncTexSubImage2D", 516 TRACE_EVENT2("gpu", "AsyncTexSubImage2D",
518 "width", tex_params.width, 517 "width", tex_params.width,
519 "height", tex_params.height); 518 "height", tex_params.height);
520 if (WorkAroundAsyncTexSubImage2D(tex_params, mem_params)) 519 if (WorkAroundAsyncTexSubImage2D(tex_params, mem_params))
521 return; 520 return;
522 DCHECK(!state_->TransferIsInProgress()); 521 DCHECK(!state_->TransferIsInProgress());
523 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); 522 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target);
524 DCHECK_EQ(tex_params.level, 0); 523 DCHECK_EQ(tex_params.level, 0);
525 524
526 // Mark the transfer in progress. 525 // Mark the transfer in progress.
527 state_->MarkAsTransferIsInProgress(); 526 state_->MarkAsTransferIsInProgress();
528 527
529 // If this wasn't async allocated, we don't have an EGLImage yet. 528 // If this wasn't async allocated, we don't have an EGLImage yet.
530 // Create the EGLImage if it hasn't already been created. 529 // Create the EGLImage if it hasn't already been created.
531 state_->CreateEglImageOnMainThreadIfNeeded(); 530 state_->CreateEglImageOnMainThreadIfNeeded();
532 531
533 // Duplicate the shared memory so there are no way we can get 532 // Duplicate the shared memory so there are no way we can get
534 // a use-after-free of the raw pixels. 533 // a use-after-free of the raw pixels.
535 transfer_message_loop_proxy()->PostTask(FROM_HERE, 534 transfer_task_runner()->PostTask(
536 base::Bind( 535 FROM_HERE,
537 &TransferStateInternal::PerformAsyncTexSubImage2D, 536 base::Bind(&TransferStateInternal::PerformAsyncTexSubImage2D, state_,
538 state_, 537 tex_params, mem_params, shared_state_->texture_upload_stats));
539 tex_params,
540 mem_params,
541 shared_state_->texture_upload_stats));
542 538
543 DCHECK(CHECK_GL()); 539 DCHECK(CHECK_GL());
544 } 540 }
545 541
546 namespace { 542 namespace {
547 bool IsPowerOfTwo (unsigned int x) { 543 bool IsPowerOfTwo (unsigned int x) {
548 return ((x != 0) && !(x & (x - 1))); 544 return ((x != 0) && !(x & (x - 1)));
549 } 545 }
550 546
551 bool IsMultipleOfEight(unsigned int x) { 547 bool IsMultipleOfEight(unsigned int x) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 delegate->BindTransfer(); 690 delegate->BindTransfer();
695 shared_state_.pending_allocations.pop_front(); 691 shared_state_.pending_allocations.pop_front();
696 } 692 }
697 } 693 }
698 694
699 void AsyncPixelTransferManagerEGL::AsyncNotifyCompletion( 695 void AsyncPixelTransferManagerEGL::AsyncNotifyCompletion(
700 const AsyncMemoryParams& mem_params, 696 const AsyncMemoryParams& mem_params,
701 AsyncPixelTransferCompletionObserver* observer) { 697 AsyncPixelTransferCompletionObserver* observer) {
702 // Post a PerformNotifyCompletion task to the upload thread. This task 698 // Post a PerformNotifyCompletion task to the upload thread. This task
703 // will run after all async transfers are complete. 699 // will run after all async transfers are complete.
704 transfer_message_loop_proxy()->PostTask( 700 transfer_task_runner()->PostTask(
705 FROM_HERE, 701 FROM_HERE, base::Bind(&PerformNotifyCompletion, mem_params,
706 base::Bind(&PerformNotifyCompletion, 702 make_scoped_refptr(observer)));
707 mem_params,
708 make_scoped_refptr(observer)));
709 } 703 }
710 704
711 uint32 AsyncPixelTransferManagerEGL::GetTextureUploadCount() { 705 uint32 AsyncPixelTransferManagerEGL::GetTextureUploadCount() {
712 return shared_state_.texture_upload_stats->GetStats(NULL); 706 return shared_state_.texture_upload_stats->GetStats(NULL);
713 } 707 }
714 708
715 base::TimeDelta AsyncPixelTransferManagerEGL::GetTotalTextureUploadTime() { 709 base::TimeDelta AsyncPixelTransferManagerEGL::GetTotalTextureUploadTime() {
716 base::TimeDelta total_texture_upload_time; 710 base::TimeDelta total_texture_upload_time;
717 shared_state_.texture_upload_stats->GetStats(&total_texture_upload_time); 711 shared_state_.texture_upload_stats->GetStats(&total_texture_upload_time);
718 return total_texture_upload_time; 712 return total_texture_upload_time;
(...skipping 18 matching lines...) Expand all
737 731
738 AsyncPixelTransferDelegate* 732 AsyncPixelTransferDelegate*
739 AsyncPixelTransferManagerEGL::CreatePixelTransferDelegateImpl( 733 AsyncPixelTransferManagerEGL::CreatePixelTransferDelegateImpl(
740 gles2::TextureRef* ref, 734 gles2::TextureRef* ref,
741 const AsyncTexImage2DParams& define_params) { 735 const AsyncTexImage2DParams& define_params) {
742 return new AsyncPixelTransferDelegateEGL( 736 return new AsyncPixelTransferDelegateEGL(
743 &shared_state_, ref->service_id(), define_params); 737 &shared_state_, ref->service_id(), define_params);
744 } 738 }
745 739
746 } // namespace gpu 740 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698