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_delegate_share_group.h
" | 5 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_share_group.h
" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 base::WaitableEvent* caller_wait) { | 79 base::WaitableEvent* caller_wait) { |
80 TRACE_EVENT0("gpu", "InitializeOnTransferThread"); | 80 TRACE_EVENT0("gpu", "InitializeOnTransferThread"); |
81 | 81 |
82 if (!parent_context) { | 82 if (!parent_context) { |
83 LOG(ERROR) << "No parent context provided."; | 83 LOG(ERROR) << "No parent context provided."; |
84 caller_wait->Signal(); | 84 caller_wait->Signal(); |
85 return; | 85 return; |
86 } | 86 } |
87 | 87 |
88 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)); | 88 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)); |
89 if (!surface_) { | 89 if (!surface_.get()) { |
90 LOG(ERROR) << "Unable to create GLSurface"; | 90 LOG(ERROR) << "Unable to create GLSurface"; |
91 caller_wait->Signal(); | 91 caller_wait->Signal(); |
92 return; | 92 return; |
93 } | 93 } |
94 | 94 |
95 // TODO(backer): This is coded for integrated GPUs. For discrete GPUs | 95 // TODO(backer): This is coded for integrated GPUs. For discrete GPUs |
96 // we would probably want to use a PBO texture upload for a true async | 96 // we would probably want to use a PBO texture upload for a true async |
97 // upload (that would hopefully be optimized as a DMA transfer by the | 97 // upload (that would hopefully be optimized as a DMA transfer by the |
98 // driver). | 98 // driver). |
99 context_ = gfx::GLContext::CreateGLContext(parent_context->share_group(), | 99 context_ = gfx::GLContext::CreateGLContext(parent_context->share_group(), |
100 surface_, | 100 surface_.get(), |
101 gfx::PreferIntegratedGpu); | 101 gfx::PreferIntegratedGpu); |
102 if (!context_) { | 102 if (!context_.get()) { |
103 LOG(ERROR) << "Unable to create GLContext."; | 103 LOG(ERROR) << "Unable to create GLContext."; |
104 caller_wait->Signal(); | 104 caller_wait->Signal(); |
105 return; | 105 return; |
106 } | 106 } |
107 | 107 |
108 context_->MakeCurrent(surface_); | 108 context_->MakeCurrent(surface_.get()); |
109 initialized_ = true; | 109 initialized_ = true; |
110 caller_wait->Signal(); | 110 caller_wait->Signal(); |
111 } | 111 } |
112 | 112 |
113 DISALLOW_COPY_AND_ASSIGN(TransferThread); | 113 DISALLOW_COPY_AND_ASSIGN(TransferThread); |
114 }; | 114 }; |
115 | 115 |
116 base::LazyInstance<TransferThread>::Leaky | 116 base::LazyInstance<TransferThread>::Leaky |
117 g_transfer_thread = LAZY_INSTANCE_INITIALIZER; | 117 g_transfer_thread = LAZY_INSTANCE_INITIALIZER; |
118 | 118 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 222 |
223 TRACE_EVENT2("gpu", | 223 TRACE_EVENT2("gpu", |
224 "PerformAsyncTexSubImage2D", | 224 "PerformAsyncTexSubImage2D", |
225 "width", | 225 "width", |
226 tex_params.width, | 226 tex_params.width, |
227 "height", | 227 "height", |
228 tex_params.height); | 228 tex_params.height); |
229 DCHECK_EQ(0, tex_params.level); | 229 DCHECK_EQ(0, tex_params.level); |
230 | 230 |
231 base::TimeTicks begin_time; | 231 base::TimeTicks begin_time; |
232 if (texture_upload_stats) | 232 if (texture_upload_stats.get()) |
233 begin_time = base::TimeTicks::HighResNow(); | 233 begin_time = base::TimeTicks::HighResNow(); |
234 | 234 |
235 void* data = | 235 void* data = |
236 AsyncPixelTransferDelegate::GetAddress(safe_shared_memory, mem_params); | 236 AsyncPixelTransferDelegate::GetAddress(safe_shared_memory, mem_params); |
237 | 237 |
238 { | 238 { |
239 TRACE_EVENT0("gpu", "glTexSubImage2D"); | 239 TRACE_EVENT0("gpu", "glTexSubImage2D"); |
240 glBindTexture(GL_TEXTURE_2D, texture_id_); | 240 glBindTexture(GL_TEXTURE_2D, texture_id_); |
241 glTexSubImage2D(GL_TEXTURE_2D, | 241 glTexSubImage2D(GL_TEXTURE_2D, |
242 tex_params.level, | 242 tex_params.level, |
243 tex_params.xoffset, | 243 tex_params.xoffset, |
244 tex_params.yoffset, | 244 tex_params.yoffset, |
245 tex_params.width, | 245 tex_params.width, |
246 tex_params.height, | 246 tex_params.height, |
247 tex_params.format, | 247 tex_params.format, |
248 tex_params.type, | 248 tex_params.type, |
249 data); | 249 data); |
250 glBindTexture(GL_TEXTURE_2D, 0); | 250 glBindTexture(GL_TEXTURE_2D, 0); |
251 } | 251 } |
252 | 252 |
253 MarkAsCompleted(); | 253 MarkAsCompleted(); |
254 | 254 |
255 if (texture_upload_stats) { | 255 if (texture_upload_stats.get()) { |
256 texture_upload_stats->AddUpload(base::TimeTicks::HighResNow() - | 256 texture_upload_stats->AddUpload(base::TimeTicks::HighResNow() - |
257 begin_time); | 257 begin_time); |
258 } | 258 } |
259 } | 259 } |
260 | 260 |
261 base::CancellationFlag* cancel_upload_flag() { return &cancel_upload_flag_; } | 261 base::CancellationFlag* cancel_upload_flag() { return &cancel_upload_flag_; } |
262 base::Lock* upload_lock() { return &upload_lock_; } | 262 base::Lock* upload_lock() { return &upload_lock_; } |
263 | 263 |
264 private: | 264 private: |
265 friend class base::RefCountedThreadSafe<TransferStateInternal>; | 265 friend class base::RefCountedThreadSafe<TransferStateInternal>; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 new ScopedSafeSharedMemory(safe_shared_memory_pool(), | 383 new ScopedSafeSharedMemory(safe_shared_memory_pool(), |
384 mem_params.shared_memory, | 384 mem_params.shared_memory, |
385 mem_params.shm_size)), | 385 mem_params.shm_size)), |
386 callback)); | 386 callback)); |
387 } | 387 } |
388 | 388 |
389 void AsyncPixelTransferDelegateShareGroup::WaitForTransferCompletion( | 389 void AsyncPixelTransferDelegateShareGroup::WaitForTransferCompletion( |
390 AsyncPixelTransferState* transfer_state) { | 390 AsyncPixelTransferState* transfer_state) { |
391 scoped_refptr<TransferStateInternal> state = | 391 scoped_refptr<TransferStateInternal> state = |
392 static_cast<AsyncTransferStateImpl*>(transfer_state)->internal(); | 392 static_cast<AsyncTransferStateImpl*>(transfer_state)->internal(); |
393 DCHECK(state); | 393 DCHECK(state.get()); |
394 DCHECK(state->texture_id()); | 394 DCHECK(state->texture_id()); |
395 | 395 |
396 if (state->TransferIsInProgress()) { | 396 if (state->TransferIsInProgress()) { |
397 #if defined(OS_ANDROID) || defined(OS_LINUX) | 397 #if defined(OS_ANDROID) || defined(OS_LINUX) |
398 g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Display); | 398 g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Display); |
399 #endif | 399 #endif |
400 | 400 |
401 state->WaitForTransferCompletion(); | 401 state->WaitForTransferCompletion(); |
402 DCHECK(!state->TransferIsInProgress()); | 402 DCHECK(!state->TransferIsInProgress()); |
403 | 403 |
404 #if defined(OS_ANDROID) || defined(OS_LINUX) | 404 #if defined(OS_ANDROID) || defined(OS_LINUX) |
405 g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Background); | 405 g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Background); |
406 #endif | 406 #endif |
407 } | 407 } |
408 } | 408 } |
409 | 409 |
410 void AsyncPixelTransferDelegateShareGroup::AsyncTexImage2D( | 410 void AsyncPixelTransferDelegateShareGroup::AsyncTexImage2D( |
411 AsyncPixelTransferState* transfer_state, | 411 AsyncPixelTransferState* transfer_state, |
412 const AsyncTexImage2DParams& tex_params, | 412 const AsyncTexImage2DParams& tex_params, |
413 const AsyncMemoryParams& mem_params, | 413 const AsyncMemoryParams& mem_params, |
414 const base::Closure& bind_callback) { | 414 const base::Closure& bind_callback) { |
415 scoped_refptr<TransferStateInternal> state = | 415 scoped_refptr<TransferStateInternal> state = |
416 static_cast<AsyncTransferStateImpl*>(transfer_state)->internal(); | 416 static_cast<AsyncTransferStateImpl*>(transfer_state)->internal(); |
417 DCHECK(mem_params.shared_memory); | 417 DCHECK(mem_params.shared_memory); |
418 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size, | 418 DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size, |
419 mem_params.shm_size); | 419 mem_params.shm_size); |
420 DCHECK(state); | 420 DCHECK(state.get()); |
421 DCHECK(state->texture_id()); | 421 DCHECK(state->texture_id()); |
422 DCHECK(!state->TransferIsInProgress()); | 422 DCHECK(!state->TransferIsInProgress()); |
423 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); | 423 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target); |
424 DCHECK_EQ(tex_params.level, 0); | 424 DCHECK_EQ(tex_params.level, 0); |
425 | 425 |
426 // Mark the transfer in progress and save the late bind | 426 // Mark the transfer in progress and save the late bind |
427 // callback, so we can notify the client when it is bound. | 427 // callback, so we can notify the client when it is bound. |
428 pending_allocations_.push_back(transfer_state->AsWeakPtr()); | 428 pending_allocations_.push_back(transfer_state->AsWeakPtr()); |
429 state->SetBindCallback(bind_callback); | 429 state->SetBindCallback(bind_callback); |
430 | 430 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 state, | 475 state, |
476 tex_params, | 476 tex_params, |
477 mem_params, | 477 mem_params, |
478 base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(), | 478 base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(), |
479 mem_params.shared_memory, | 479 mem_params.shared_memory, |
480 mem_params.shm_size)), | 480 mem_params.shm_size)), |
481 texture_upload_stats_)); | 481 texture_upload_stats_)); |
482 } | 482 } |
483 | 483 |
484 uint32 AsyncPixelTransferDelegateShareGroup::GetTextureUploadCount() { | 484 uint32 AsyncPixelTransferDelegateShareGroup::GetTextureUploadCount() { |
485 DCHECK(texture_upload_stats_); | 485 DCHECK(texture_upload_stats_.get()); |
486 return texture_upload_stats_->GetStats(NULL); | 486 return texture_upload_stats_->GetStats(NULL); |
487 } | 487 } |
488 | 488 |
489 base::TimeDelta | 489 base::TimeDelta |
490 AsyncPixelTransferDelegateShareGroup::GetTotalTextureUploadTime() { | 490 AsyncPixelTransferDelegateShareGroup::GetTotalTextureUploadTime() { |
491 DCHECK(texture_upload_stats_); | 491 DCHECK(texture_upload_stats_.get()); |
492 base::TimeDelta total_texture_upload_time; | 492 base::TimeDelta total_texture_upload_time; |
493 texture_upload_stats_->GetStats(&total_texture_upload_time); | 493 texture_upload_stats_->GetStats(&total_texture_upload_time); |
494 return total_texture_upload_time; | 494 return total_texture_upload_time; |
495 } | 495 } |
496 | 496 |
497 void AsyncPixelTransferDelegateShareGroup::ProcessMorePendingTransfers() { | 497 void AsyncPixelTransferDelegateShareGroup::ProcessMorePendingTransfers() { |
498 } | 498 } |
499 | 499 |
500 bool AsyncPixelTransferDelegateShareGroup::NeedsProcessMorePendingTransfers() { | 500 bool AsyncPixelTransferDelegateShareGroup::NeedsProcessMorePendingTransfers() { |
501 return false; | 501 return false; |
502 } | 502 } |
503 | 503 |
504 } // namespace gpu | 504 } // namespace gpu |
OLD | NEW |