OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gl/async_pixel_transfer_delegate_android.h" | 5 #include "ui/gl/async_pixel_transfer_delegate_android.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
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" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
15 #include "base/shared_memory.h" | 15 #include "base/shared_memory.h" |
| 16 #include "base/synchronization/waitable_event.h" |
16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "ui/gl/async_pixel_transfer_delegate.h" | 19 #include "ui/gl/async_pixel_transfer_delegate.h" |
19 #include "ui/gl/async_pixel_transfer_delegate_stub.h" | 20 #include "ui/gl/async_pixel_transfer_delegate_stub.h" |
20 #include "ui/gl/egl_util.h" | 21 #include "ui/gl/egl_util.h" |
21 #include "ui/gl/gl_bindings.h" | 22 #include "ui/gl/gl_bindings.h" |
22 #include "ui/gl/gl_context.h" | 23 #include "ui/gl/gl_context.h" |
23 #include "ui/gl/gl_surface_egl.h" | 24 #include "ui/gl/gl_surface_egl.h" |
24 #include "ui/gl/safe_shared_memory_pool.h" | 25 #include "ui/gl/safe_shared_memory_pool.h" |
25 | 26 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 g_transfer_thread = LAZY_INSTANCE_INITIALIZER; | 192 g_transfer_thread = LAZY_INSTANCE_INITIALIZER; |
192 | 193 |
193 base::MessageLoopProxy* transfer_message_loop_proxy() { | 194 base::MessageLoopProxy* transfer_message_loop_proxy() { |
194 return g_transfer_thread.Pointer()->message_loop_proxy(); | 195 return g_transfer_thread.Pointer()->message_loop_proxy(); |
195 } | 196 } |
196 | 197 |
197 SafeSharedMemoryPool* safe_shared_memory_pool() { | 198 SafeSharedMemoryPool* safe_shared_memory_pool() { |
198 return g_transfer_thread.Pointer()->safe_shared_memory_pool(); | 199 return g_transfer_thread.Pointer()->safe_shared_memory_pool(); |
199 } | 200 } |
200 | 201 |
| 202 void SignalCompletion(base::WaitableEvent* completion) { |
| 203 completion->Signal(); |
| 204 } |
201 | 205 |
202 } // namespace | 206 } // namespace |
203 | 207 |
204 // Class which holds async pixel transfers state (EGLImage). | 208 // Class which holds async pixel transfers state (EGLImage). |
205 // The EGLImage is accessed by either thread, but everything | 209 // The EGLImage is accessed by either thread, but everything |
206 // else accessed only on the main thread. | 210 // else accessed only on the main thread. |
207 class TransferStateInternal | 211 class TransferStateInternal |
208 : public base::RefCountedThreadSafe<TransferStateInternal> { | 212 : public base::RefCountedThreadSafe<TransferStateInternal> { |
209 public: | 213 public: |
210 explicit TransferStateInternal(GLuint texture_id, | 214 explicit TransferStateInternal(GLuint texture_id, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 : public AsyncPixelTransferDelegate, | 377 : public AsyncPixelTransferDelegate, |
374 public base::SupportsWeakPtr<AsyncPixelTransferDelegateAndroid> { | 378 public base::SupportsWeakPtr<AsyncPixelTransferDelegateAndroid> { |
375 public: | 379 public: |
376 AsyncPixelTransferDelegateAndroid(); | 380 AsyncPixelTransferDelegateAndroid(); |
377 virtual ~AsyncPixelTransferDelegateAndroid(); | 381 virtual ~AsyncPixelTransferDelegateAndroid(); |
378 | 382 |
379 // implement AsyncPixelTransferDelegate: | 383 // implement AsyncPixelTransferDelegate: |
380 virtual void AsyncNotifyCompletion( | 384 virtual void AsyncNotifyCompletion( |
381 const AsyncMemoryParams& mem_params, | 385 const AsyncMemoryParams& mem_params, |
382 const CompletionCallback& callback) OVERRIDE; | 386 const CompletionCallback& callback) OVERRIDE; |
| 387 virtual void WaitOnUploadCompletion() OVERRIDE; |
383 virtual void AsyncTexImage2D( | 388 virtual void AsyncTexImage2D( |
384 AsyncPixelTransferState* state, | 389 AsyncPixelTransferState* state, |
385 const AsyncTexImage2DParams& tex_params, | 390 const AsyncTexImage2DParams& tex_params, |
386 const AsyncMemoryParams& mem_params) OVERRIDE; | 391 const AsyncMemoryParams& mem_params) OVERRIDE; |
387 virtual void AsyncTexSubImage2D( | 392 virtual void AsyncTexSubImage2D( |
388 AsyncPixelTransferState* state, | 393 AsyncPixelTransferState* state, |
389 const AsyncTexSubImage2DParams& tex_params, | 394 const AsyncTexSubImage2DParams& tex_params, |
390 const AsyncMemoryParams& mem_params) OVERRIDE; | 395 const AsyncMemoryParams& mem_params) OVERRIDE; |
391 virtual uint32 GetTextureUploadCount() OVERRIDE; | 396 virtual uint32 GetTextureUploadCount() OVERRIDE; |
392 virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; | 397 virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 FROM_HERE, | 502 FROM_HERE, |
498 base::Bind(&AsyncPixelTransferDelegateAndroid::PerformNotifyCompletion, | 503 base::Bind(&AsyncPixelTransferDelegateAndroid::PerformNotifyCompletion, |
499 mem_params, | 504 mem_params, |
500 base::Owned( | 505 base::Owned( |
501 new ScopedSafeSharedMemory(safe_shared_memory_pool(), | 506 new ScopedSafeSharedMemory(safe_shared_memory_pool(), |
502 mem_params.shared_memory, | 507 mem_params.shared_memory, |
503 mem_params.shm_size)), | 508 mem_params.shm_size)), |
504 callback)); | 509 callback)); |
505 } | 510 } |
506 | 511 |
| 512 void AsyncPixelTransferDelegateAndroid::WaitOnUploadCompletion() { |
| 513 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
| 514 int default_nice_value = 0; // Default priority. |
| 515 int idle_nice_value = 10; // Idle priority. |
| 516 setpriority(PRIO_PROCESS, |
| 517 g_transfer_thread.Pointer()->thread_id(), |
| 518 default_nice_value); |
| 519 |
| 520 base::WaitableEvent completion(true, false); |
| 521 transfer_message_loop_proxy()->PostTask( |
| 522 FROM_HERE, |
| 523 base::Bind(&SignalCompletion, &completion)); |
| 524 completion.Wait(); |
| 525 |
| 526 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
| 527 setpriority(PRIO_PROCESS, |
| 528 g_transfer_thread.Pointer()->thread_id(), |
| 529 idle_nice_value); |
| 530 } |
| 531 |
507 void AsyncPixelTransferDelegateAndroid::AsyncTexImage2D( | 532 void AsyncPixelTransferDelegateAndroid::AsyncTexImage2D( |
508 AsyncPixelTransferState* transfer_state, | 533 AsyncPixelTransferState* transfer_state, |
509 const AsyncTexImage2DParams& tex_params, | 534 const AsyncTexImage2DParams& tex_params, |
510 const AsyncMemoryParams& mem_params) { | 535 const AsyncMemoryParams& mem_params) { |
511 scoped_refptr<TransferStateInternal> state = | 536 scoped_refptr<TransferStateInternal> state = |
512 static_cast<AsyncTransferStateAndroid*>(transfer_state)->internal_.get(); | 537 static_cast<AsyncTransferStateAndroid*>(transfer_state)->internal_.get(); |
513 DCHECK(mem_params.shared_memory); | 538 DCHECK(mem_params.shared_memory); |
514 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size, | 539 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size, |
515 mem_params.shm_size); | 540 mem_params.shm_size); |
516 DCHECK(state); | 541 DCHECK(state); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 if (texture_upload_stats_) { | 851 if (texture_upload_stats_) { |
827 texture_upload_stats_->AddUpload( | 852 texture_upload_stats_->AddUpload( |
828 base::TimeTicks::HighResNow() - begin_time); | 853 base::TimeTicks::HighResNow() - begin_time); |
829 } | 854 } |
830 | 855 |
831 DCHECK(CHECK_GL()); | 856 DCHECK(CHECK_GL()); |
832 return true; | 857 return true; |
833 } | 858 } |
834 | 859 |
835 } // namespace gfx | 860 } // namespace gfx |
OLD | NEW |