OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_delegate_egl.h" | 5 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_egl.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" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 86 } |
87 virtual ~TransferThread() { | 87 virtual ~TransferThread() { |
88 Stop(); | 88 Stop(); |
89 } | 89 } |
90 | 90 |
91 virtual void Init() OVERRIDE { | 91 virtual void Init() OVERRIDE { |
92 gfx::GLShareGroup* share_group = NULL; | 92 gfx::GLShareGroup* share_group = NULL; |
93 bool software = false; | 93 bool software = false; |
94 surface_ = new gfx::PbufferGLSurfaceEGL(software, gfx::Size(1,1)); | 94 surface_ = new gfx::PbufferGLSurfaceEGL(software, gfx::Size(1,1)); |
95 surface_->Initialize(); | 95 surface_->Initialize(); |
96 context_ = gfx::GLContext::CreateGLContext(share_group, | 96 context_ = gfx::GLContext::CreateGLContext( |
97 surface_, | 97 share_group, surface_.get(), gfx::PreferDiscreteGpu); |
98 gfx::PreferDiscreteGpu); | 98 bool is_current = context_->MakeCurrent(surface_.get()); |
99 bool is_current = context_->MakeCurrent(surface_); | |
100 DCHECK(is_current); | 99 DCHECK(is_current); |
101 } | 100 } |
102 | 101 |
103 virtual void CleanUp() OVERRIDE { | 102 virtual void CleanUp() OVERRIDE { |
104 surface_ = NULL; | 103 surface_ = NULL; |
105 context_->ReleaseCurrent(surface_); | 104 context_->ReleaseCurrent(surface_.get()); |
106 context_ = NULL; | 105 context_ = NULL; |
107 } | 106 } |
108 | 107 |
109 SafeSharedMemoryPool* safe_shared_memory_pool() { | 108 SafeSharedMemoryPool* safe_shared_memory_pool() { |
110 return &safe_shared_memory_pool_; | 109 return &safe_shared_memory_pool_; |
111 } | 110 } |
112 | 111 |
113 private: | 112 private: |
114 scoped_refptr<gfx::GLContext> context_; | 113 scoped_refptr<gfx::GLContext> context_; |
115 scoped_refptr<gfx::GLSurface> surface_; | 114 scoped_refptr<gfx::GLSurface> surface_; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 "height", | 296 "height", |
298 tex_params.height); | 297 tex_params.height); |
299 | 298 |
300 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); | 299 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); |
301 DCHECK_EQ(0, tex_params.level); | 300 DCHECK_EQ(0, tex_params.level); |
302 | 301 |
303 void* data = | 302 void* data = |
304 AsyncPixelTransferDelegate::GetAddress(safe_shared_memory, mem_params); | 303 AsyncPixelTransferDelegate::GetAddress(safe_shared_memory, mem_params); |
305 | 304 |
306 base::TimeTicks begin_time; | 305 base::TimeTicks begin_time; |
307 if (texture_upload_stats) | 306 if (texture_upload_stats.get()) |
308 begin_time = base::TimeTicks::HighResNow(); | 307 begin_time = base::TimeTicks::HighResNow(); |
309 | 308 |
310 if (!thread_texture_id_) { | 309 if (!thread_texture_id_) { |
311 TRACE_EVENT0("gpu", "glEGLImageTargetTexture2DOES"); | 310 TRACE_EVENT0("gpu", "glEGLImageTargetTexture2DOES"); |
312 glGenTextures(1, &thread_texture_id_); | 311 glGenTextures(1, &thread_texture_id_); |
313 glActiveTexture(GL_TEXTURE0); | 312 glActiveTexture(GL_TEXTURE0); |
314 glBindTexture(GL_TEXTURE_2D, thread_texture_id_); | 313 glBindTexture(GL_TEXTURE_2D, thread_texture_id_); |
315 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image_); | 314 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image_); |
316 } else { | 315 } else { |
317 glActiveTexture(GL_TEXTURE0); | 316 glActiveTexture(GL_TEXTURE0); |
318 glBindTexture(GL_TEXTURE_2D, thread_texture_id_); | 317 glBindTexture(GL_TEXTURE_2D, thread_texture_id_); |
319 } | 318 } |
320 { | 319 { |
321 TRACE_EVENT0("gpu", "glTexSubImage2D"); | 320 TRACE_EVENT0("gpu", "glTexSubImage2D"); |
322 DoTexSubImage2D(tex_params, data); | 321 DoTexSubImage2D(tex_params, data); |
323 } | 322 } |
324 WaitForLastUpload(); | 323 WaitForLastUpload(); |
325 MarkAsCompleted(); | 324 MarkAsCompleted(); |
326 | 325 |
327 DCHECK(CHECK_GL()); | 326 DCHECK(CHECK_GL()); |
328 if (texture_upload_stats) { | 327 if (texture_upload_stats.get()) { |
329 texture_upload_stats->AddUpload(base::TimeTicks::HighResNow() - | 328 texture_upload_stats->AddUpload(base::TimeTicks::HighResNow() - |
330 begin_time); | 329 begin_time); |
331 } | 330 } |
332 } | 331 } |
333 | 332 |
334 protected: | 333 protected: |
335 friend class base::RefCountedThreadSafe<TransferStateInternal>; | 334 friend class base::RefCountedThreadSafe<TransferStateInternal>; |
336 friend class gpu::AsyncPixelTransferDelegateEGL; | 335 friend class gpu::AsyncPixelTransferDelegateEGL; |
337 | 336 |
338 static void DeleteTexture(GLuint id) { | 337 static void DeleteTexture(GLuint id) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 new ScopedSafeSharedMemory(safe_shared_memory_pool(), | 487 new ScopedSafeSharedMemory(safe_shared_memory_pool(), |
489 mem_params.shared_memory, | 488 mem_params.shared_memory, |
490 mem_params.shm_size)), | 489 mem_params.shm_size)), |
491 callback)); | 490 callback)); |
492 } | 491 } |
493 | 492 |
494 void AsyncPixelTransferDelegateEGL::WaitForTransferCompletion( | 493 void AsyncPixelTransferDelegateEGL::WaitForTransferCompletion( |
495 AsyncPixelTransferState* transfer_state) { | 494 AsyncPixelTransferState* transfer_state) { |
496 scoped_refptr<TransferStateInternal> state = | 495 scoped_refptr<TransferStateInternal> state = |
497 static_cast<AsyncTransferStateImpl*>(transfer_state)->internal_.get(); | 496 static_cast<AsyncTransferStateImpl*>(transfer_state)->internal_.get(); |
498 DCHECK(state); | 497 DCHECK(state.get()); |
499 DCHECK(state->texture_id_); | 498 DCHECK(state->texture_id_); |
500 | 499 |
501 if (state->TransferIsInProgress()) { | 500 if (state->TransferIsInProgress()) { |
502 #if defined(OS_ANDROID) || defined(OS_LINUX) | 501 #if defined(OS_ANDROID) || defined(OS_LINUX) |
503 g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Display); | 502 g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Display); |
504 #endif | 503 #endif |
505 | 504 |
506 state->WaitForTransferCompletion(); | 505 state->WaitForTransferCompletion(); |
507 DCHECK(!state->TransferIsInProgress()); | 506 DCHECK(!state->TransferIsInProgress()); |
508 | 507 |
(...skipping 10 matching lines...) Expand all Loading... |
519 const base::Closure& bind_callback) { | 518 const base::Closure& bind_callback) { |
520 if (WorkAroundAsyncTexImage2D(transfer_state, tex_params, | 519 if (WorkAroundAsyncTexImage2D(transfer_state, tex_params, |
521 mem_params, bind_callback)) | 520 mem_params, bind_callback)) |
522 return; | 521 return; |
523 | 522 |
524 scoped_refptr<TransferStateInternal> state = | 523 scoped_refptr<TransferStateInternal> state = |
525 static_cast<AsyncTransferStateImpl*>(transfer_state)->internal_.get(); | 524 static_cast<AsyncTransferStateImpl*>(transfer_state)->internal_.get(); |
526 DCHECK(mem_params.shared_memory); | 525 DCHECK(mem_params.shared_memory); |
527 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size, | 526 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size, |
528 mem_params.shm_size); | 527 mem_params.shm_size); |
529 DCHECK(state); | 528 DCHECK(state.get()); |
530 DCHECK(state->texture_id_); | 529 DCHECK(state->texture_id_); |
531 DCHECK(!state->TransferIsInProgress()); | 530 DCHECK(!state->TransferIsInProgress()); |
532 DCHECK_EQ(state->egl_image_, EGL_NO_IMAGE_KHR); | 531 DCHECK_EQ(state->egl_image_, EGL_NO_IMAGE_KHR); |
533 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); | 532 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); |
534 DCHECK_EQ(tex_params.level, 0); | 533 DCHECK_EQ(tex_params.level, 0); |
535 | 534 |
536 // Mark the transfer in progress and save the late bind | 535 // Mark the transfer in progress and save the late bind |
537 // callback, so we can notify the client when it is bound. | 536 // callback, so we can notify the client when it is bound. |
538 pending_allocations_.push_back(transfer_state->AsWeakPtr()); | 537 pending_allocations_.push_back(transfer_state->AsWeakPtr()); |
539 state->bind_callback_ = bind_callback; | 538 state->bind_callback_ = bind_callback; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 mem_params, | 593 mem_params, |
595 base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(), | 594 base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(), |
596 mem_params.shared_memory, | 595 mem_params.shared_memory, |
597 mem_params.shm_size)), | 596 mem_params.shm_size)), |
598 texture_upload_stats_)); | 597 texture_upload_stats_)); |
599 | 598 |
600 DCHECK(CHECK_GL()); | 599 DCHECK(CHECK_GL()); |
601 } | 600 } |
602 | 601 |
603 uint32 AsyncPixelTransferDelegateEGL::GetTextureUploadCount() { | 602 uint32 AsyncPixelTransferDelegateEGL::GetTextureUploadCount() { |
604 CHECK(texture_upload_stats_); | 603 CHECK(texture_upload_stats_.get()); |
605 return texture_upload_stats_->GetStats(NULL); | 604 return texture_upload_stats_->GetStats(NULL); |
606 } | 605 } |
607 | 606 |
608 base::TimeDelta AsyncPixelTransferDelegateEGL::GetTotalTextureUploadTime() { | 607 base::TimeDelta AsyncPixelTransferDelegateEGL::GetTotalTextureUploadTime() { |
609 CHECK(texture_upload_stats_); | 608 CHECK(texture_upload_stats_.get()); |
610 base::TimeDelta total_texture_upload_time; | 609 base::TimeDelta total_texture_upload_time; |
611 texture_upload_stats_->GetStats(&total_texture_upload_time); | 610 texture_upload_stats_->GetStats(&total_texture_upload_time); |
612 return total_texture_upload_time; | 611 return total_texture_upload_time; |
613 } | 612 } |
614 | 613 |
615 void AsyncPixelTransferDelegateEGL::ProcessMorePendingTransfers() { | 614 void AsyncPixelTransferDelegateEGL::ProcessMorePendingTransfers() { |
616 } | 615 } |
617 | 616 |
618 bool AsyncPixelTransferDelegateEGL::NeedsProcessMorePendingTransfers() { | 617 bool AsyncPixelTransferDelegateEGL::NeedsProcessMorePendingTransfers() { |
619 return false; | 618 return false; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 DCHECK_EQ(tex_params.xoffset, 0); | 723 DCHECK_EQ(tex_params.xoffset, 0); |
725 DCHECK_EQ(tex_params.yoffset, 0); | 724 DCHECK_EQ(tex_params.yoffset, 0); |
726 DCHECK_EQ(state->define_params_.width, tex_params.width); | 725 DCHECK_EQ(state->define_params_.width, tex_params.width); |
727 DCHECK_EQ(state->define_params_.height, tex_params.height); | 726 DCHECK_EQ(state->define_params_.height, tex_params.height); |
728 DCHECK_EQ(state->define_params_.level, tex_params.level); | 727 DCHECK_EQ(state->define_params_.level, tex_params.level); |
729 DCHECK_EQ(state->define_params_.format, tex_params.format); | 728 DCHECK_EQ(state->define_params_.format, tex_params.format); |
730 DCHECK_EQ(state->define_params_.type, tex_params.type); | 729 DCHECK_EQ(state->define_params_.type, tex_params.type); |
731 | 730 |
732 void* data = GetAddress(mem_params); | 731 void* data = GetAddress(mem_params); |
733 base::TimeTicks begin_time; | 732 base::TimeTicks begin_time; |
734 if (texture_upload_stats_) | 733 if (texture_upload_stats_.get()) |
735 begin_time = base::TimeTicks::HighResNow(); | 734 begin_time = base::TimeTicks::HighResNow(); |
736 { | 735 { |
737 TRACE_EVENT0("gpu", "glTexSubImage2D"); | 736 TRACE_EVENT0("gpu", "glTexSubImage2D"); |
738 // Note we use define_params_ instead of tex_params. | 737 // Note we use define_params_ instead of tex_params. |
739 // The DCHECKs above verify this is always the same. | 738 // The DCHECKs above verify this is always the same. |
740 DoTexImage2D(state->define_params_, data); | 739 DoTexImage2D(state->define_params_, data); |
741 } | 740 } |
742 if (texture_upload_stats_) { | 741 if (texture_upload_stats_.get()) { |
743 texture_upload_stats_->AddUpload( | 742 texture_upload_stats_->AddUpload(base::TimeTicks::HighResNow() - |
744 base::TimeTicks::HighResNow() - begin_time); | 743 begin_time); |
745 } | 744 } |
746 | 745 |
747 DCHECK(CHECK_GL()); | 746 DCHECK(CHECK_GL()); |
748 return true; | 747 return true; |
749 } | 748 } |
750 | 749 |
751 } // namespace gpu | 750 } // namespace gpu |
OLD | NEW |