| 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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/location.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/single_thread_task_runner.h" |
| 14 #include "base/synchronization/cancellation_flag.h" | 16 #include "base/synchronization/cancellation_flag.h" |
| 15 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 16 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 17 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 18 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 19 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
| 20 #include "base/trace_event/trace_event_synthetic_delay.h" | 22 #include "base/trace_event/trace_event_synthetic_delay.h" |
| 21 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" | 23 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
| 22 #include "ui/gl/gl_bindings.h" | 24 #include "ui/gl/gl_bindings.h" |
| 23 #include "ui/gl/gl_context.h" | 25 #include "ui/gl/gl_context.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // The only instance of this class was declared leaky. | 57 // The only instance of this class was declared leaky. |
| 56 NOTREACHED(); | 58 NOTREACHED(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void InitializeOnMainThread(gfx::GLContext* parent_context) { | 61 void InitializeOnMainThread(gfx::GLContext* parent_context) { |
| 60 TRACE_EVENT0("gpu", "TransferThread::InitializeOnMainThread"); | 62 TRACE_EVENT0("gpu", "TransferThread::InitializeOnMainThread"); |
| 61 if (initialized_) | 63 if (initialized_) |
| 62 return; | 64 return; |
| 63 | 65 |
| 64 base::WaitableEvent wait_for_init(true, false); | 66 base::WaitableEvent wait_for_init(true, false); |
| 65 message_loop_proxy()->PostTask( | 67 task_runner()->PostTask( |
| 66 FROM_HERE, | 68 FROM_HERE, |
| 67 base::Bind(&TransferThread::InitializeOnTransferThread, | 69 base::Bind(&TransferThread::InitializeOnTransferThread, |
| 68 base::Unretained(this), | 70 base::Unretained(this), base::Unretained(parent_context), |
| 69 base::Unretained(parent_context), | 71 &wait_for_init)); |
| 70 &wait_for_init)); | |
| 71 wait_for_init.Wait(); | 72 wait_for_init.Wait(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void CleanUp() override { | 75 void CleanUp() override { |
| 75 surface_ = NULL; | 76 surface_ = NULL; |
| 76 context_ = NULL; | 77 context_ = NULL; |
| 77 } | 78 } |
| 78 | 79 |
| 79 private: | 80 private: |
| 80 bool initialized_; | 81 bool initialized_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 initialized_ = true; | 117 initialized_ = true; |
| 117 caller_wait->Signal(); | 118 caller_wait->Signal(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 DISALLOW_COPY_AND_ASSIGN(TransferThread); | 121 DISALLOW_COPY_AND_ASSIGN(TransferThread); |
| 121 }; | 122 }; |
| 122 | 123 |
| 123 base::LazyInstance<TransferThread>::Leaky | 124 base::LazyInstance<TransferThread>::Leaky |
| 124 g_transfer_thread = LAZY_INSTANCE_INITIALIZER; | 125 g_transfer_thread = LAZY_INSTANCE_INITIALIZER; |
| 125 | 126 |
| 126 base::MessageLoopProxy* transfer_message_loop_proxy() { | 127 base::SingleThreadTaskRunner* transfer_task_runner() { |
| 127 return g_transfer_thread.Pointer()->message_loop_proxy().get(); | 128 return g_transfer_thread.Pointer()->task_runner().get(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 class PendingTask : public base::RefCountedThreadSafe<PendingTask> { | 131 class PendingTask : public base::RefCountedThreadSafe<PendingTask> { |
| 131 public: | 132 public: |
| 132 explicit PendingTask(const base::Closure& task) | 133 explicit PendingTask(const base::Closure& task) |
| 133 : task_(task), task_pending_(true, false) {} | 134 : task_(task), task_pending_(true, false) {} |
| 134 | 135 |
| 135 bool TryRun() { | 136 bool TryRun() { |
| 136 // This is meant to be called on the main thread where the texture | 137 // This is meant to be called on the main thread where the texture |
| 137 // is already bound. | 138 // is already bound. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 const AsyncMemoryParams mem_params, | 240 const AsyncMemoryParams mem_params, |
| 240 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats, | 241 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats, |
| 241 const base::Closure& bind_callback) { | 242 const base::Closure& bind_callback) { |
| 242 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); | 243 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); |
| 243 pending_upload_task_ = new PendingTask(base::Bind( | 244 pending_upload_task_ = new PendingTask(base::Bind( |
| 244 &TransferStateInternal::PerformAsyncTexImage2D, | 245 &TransferStateInternal::PerformAsyncTexImage2D, |
| 245 this, | 246 this, |
| 246 tex_params, | 247 tex_params, |
| 247 mem_params, | 248 mem_params, |
| 248 texture_upload_stats)); | 249 texture_upload_stats)); |
| 249 transfer_message_loop_proxy()->PostTask( | 250 transfer_task_runner()->PostTask( |
| 250 FROM_HERE, | 251 FROM_HERE, base::Bind(&PendingTask::BindAndRun, pending_upload_task_, |
| 251 base::Bind( | 252 texture_id_)); |
| 252 &PendingTask::BindAndRun, pending_upload_task_, texture_id_)); | |
| 253 | 253 |
| 254 // Save the late bind callback, so we can notify the client when it is | 254 // Save the late bind callback, so we can notify the client when it is |
| 255 // bound. | 255 // bound. |
| 256 bind_callback_ = bind_callback; | 256 bind_callback_ = bind_callback; |
| 257 } | 257 } |
| 258 | 258 |
| 259 void ScheduleAsyncTexSubImage2D( | 259 void ScheduleAsyncTexSubImage2D( |
| 260 AsyncTexSubImage2DParams tex_params, | 260 AsyncTexSubImage2DParams tex_params, |
| 261 AsyncMemoryParams mem_params, | 261 AsyncMemoryParams mem_params, |
| 262 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats) { | 262 scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats) { |
| 263 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); | 263 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("gpu.AsyncTexImage"); |
| 264 pending_upload_task_ = new PendingTask(base::Bind( | 264 pending_upload_task_ = new PendingTask(base::Bind( |
| 265 &TransferStateInternal::PerformAsyncTexSubImage2D, | 265 &TransferStateInternal::PerformAsyncTexSubImage2D, |
| 266 this, | 266 this, |
| 267 tex_params, | 267 tex_params, |
| 268 mem_params, | 268 mem_params, |
| 269 texture_upload_stats)); | 269 texture_upload_stats)); |
| 270 transfer_message_loop_proxy()->PostTask( | 270 transfer_task_runner()->PostTask( |
| 271 FROM_HERE, | 271 FROM_HERE, base::Bind(&PendingTask::BindAndRun, pending_upload_task_, |
| 272 base::Bind( | 272 texture_id_)); |
| 273 &PendingTask::BindAndRun, pending_upload_task_, texture_id_)); | |
| 274 } | 273 } |
| 275 | 274 |
| 276 private: | 275 private: |
| 277 friend class base::RefCountedThreadSafe<TransferStateInternal>; | 276 friend class base::RefCountedThreadSafe<TransferStateInternal>; |
| 278 | 277 |
| 279 virtual ~TransferStateInternal() { | 278 virtual ~TransferStateInternal() { |
| 280 } | 279 } |
| 281 | 280 |
| 282 void PerformAsyncTexImage2D( | 281 void PerformAsyncTexImage2D( |
| 283 AsyncTexImage2DParams tex_params, | 282 AsyncTexImage2DParams tex_params, |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 497 |
| 499 shared_state_.pending_allocations.pop_front(); | 498 shared_state_.pending_allocations.pop_front(); |
| 500 } | 499 } |
| 501 } | 500 } |
| 502 | 501 |
| 503 void AsyncPixelTransferManagerShareGroup::AsyncNotifyCompletion( | 502 void AsyncPixelTransferManagerShareGroup::AsyncNotifyCompletion( |
| 504 const AsyncMemoryParams& mem_params, | 503 const AsyncMemoryParams& mem_params, |
| 505 AsyncPixelTransferCompletionObserver* observer) { | 504 AsyncPixelTransferCompletionObserver* observer) { |
| 506 // Post a PerformNotifyCompletion task to the upload thread. This task | 505 // Post a PerformNotifyCompletion task to the upload thread. This task |
| 507 // will run after all async transfers are complete. | 506 // will run after all async transfers are complete. |
| 508 transfer_message_loop_proxy()->PostTask( | 507 transfer_task_runner()->PostTask( |
| 509 FROM_HERE, | 508 FROM_HERE, base::Bind(&PerformNotifyCompletion, mem_params, |
| 510 base::Bind(&PerformNotifyCompletion, | 509 make_scoped_refptr(observer))); |
| 511 mem_params, | |
| 512 make_scoped_refptr(observer))); | |
| 513 } | 510 } |
| 514 | 511 |
| 515 uint32 AsyncPixelTransferManagerShareGroup::GetTextureUploadCount() { | 512 uint32 AsyncPixelTransferManagerShareGroup::GetTextureUploadCount() { |
| 516 return shared_state_.texture_upload_stats->GetStats(NULL); | 513 return shared_state_.texture_upload_stats->GetStats(NULL); |
| 517 } | 514 } |
| 518 | 515 |
| 519 base::TimeDelta | 516 base::TimeDelta |
| 520 AsyncPixelTransferManagerShareGroup::GetTotalTextureUploadTime() { | 517 AsyncPixelTransferManagerShareGroup::GetTotalTextureUploadTime() { |
| 521 base::TimeDelta total_texture_upload_time; | 518 base::TimeDelta total_texture_upload_time; |
| 522 shared_state_.texture_upload_stats->GetStats(&total_texture_upload_time); | 519 shared_state_.texture_upload_stats->GetStats(&total_texture_upload_time); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 542 | 539 |
| 543 AsyncPixelTransferDelegate* | 540 AsyncPixelTransferDelegate* |
| 544 AsyncPixelTransferManagerShareGroup::CreatePixelTransferDelegateImpl( | 541 AsyncPixelTransferManagerShareGroup::CreatePixelTransferDelegateImpl( |
| 545 gles2::TextureRef* ref, | 542 gles2::TextureRef* ref, |
| 546 const AsyncTexImage2DParams& define_params) { | 543 const AsyncTexImage2DParams& define_params) { |
| 547 return new AsyncPixelTransferDelegateShareGroup( | 544 return new AsyncPixelTransferDelegateShareGroup( |
| 548 &shared_state_, ref->service_id(), define_params); | 545 &shared_state_, ref->service_id(), define_params); |
| 549 } | 546 } |
| 550 | 547 |
| 551 } // namespace gpu | 548 } // namespace gpu |
| OLD | NEW |