Chromium Code Reviews| 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/in_process_command_buffer.h" | 5 #include "gpu/command_buffer/service/in_process_command_buffer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 gpu_preferences().gpu_program_cache_size, | 202 gpu_preferences().gpu_program_cache_size, |
| 203 gpu_preferences().disable_gpu_shader_disk_cache)); | 203 gpu_preferences().disable_gpu_shader_disk_cache)); |
| 204 } | 204 } |
| 205 return program_cache_.get(); | 205 return program_cache_.get(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 InProcessCommandBuffer::InProcessCommandBuffer( | 208 InProcessCommandBuffer::InProcessCommandBuffer( |
| 209 const scoped_refptr<Service>& service) | 209 const scoped_refptr<Service>& service) |
| 210 : command_buffer_id_( | 210 : command_buffer_id_( |
| 211 CommandBufferId::FromUnsafeValue(g_next_command_buffer_id.GetNext())), | 211 CommandBufferId::FromUnsafeValue(g_next_command_buffer_id.GetNext())), |
| 212 context_lost_(false), | |
| 213 delayed_work_pending_(false), | 212 delayed_work_pending_(false), |
| 214 image_factory_(nullptr), | 213 image_factory_(nullptr), |
| 215 last_put_offset_(-1), | 214 last_put_offset_(-1), |
| 216 gpu_memory_buffer_manager_(nullptr), | 215 gpu_memory_buffer_manager_(nullptr), |
| 217 next_fence_sync_release_(1), | 216 next_fence_sync_release_(1), |
| 218 flushed_fence_sync_release_(0), | 217 flushed_fence_sync_release_(0), |
| 219 flush_event_(false, false), | 218 flush_event_(false, false), |
| 220 service_(GetInitialService(service)), | 219 service_(GetInitialService(service)), |
| 221 fence_sync_wait_event_(false, false), | 220 fence_sync_wait_event_(false, false), |
| 222 gpu_thread_weak_ptr_factory_(this) { | 221 gpu_thread_weak_ptr_factory_(this) { |
| 223 DCHECK(service_.get()); | 222 DCHECK(service_.get()); |
| 224 next_image_id_.GetNext(); | 223 next_image_id_.GetNext(); |
| 225 } | 224 } |
| 226 | 225 |
| 227 InProcessCommandBuffer::~InProcessCommandBuffer() { | 226 InProcessCommandBuffer::~InProcessCommandBuffer() { |
| 228 Destroy(); | 227 Destroy(); |
| 229 } | 228 } |
| 230 | 229 |
| 231 bool InProcessCommandBuffer::MakeCurrent() { | 230 bool InProcessCommandBuffer::MakeCurrent() { |
| 232 CheckSequencedThread(); | 231 CheckSequencedThread(); |
| 233 command_buffer_lock_.AssertAcquired(); | 232 command_buffer_lock_.AssertAcquired(); |
| 234 | 233 |
| 235 if (!context_lost_ && decoder_->MakeCurrent()) | 234 if (error::IsError(command_buffer_->GetLastState().error)) { |
| 236 return true; | 235 DLOG(ERROR) << "MakeCurrent failed because context lost."; |
| 237 DLOG(ERROR) << "Context lost because MakeCurrent failed."; | 236 return false; |
| 238 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | 237 } |
| 239 command_buffer_->SetParseError(gpu::error::kLostContext); | 238 if (!decoder_->MakeCurrent()) { |
| 240 return false; | 239 DLOG(ERROR) << "Context lost because MakeCurrent failed."; |
| 240 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | |
| 241 command_buffer_->SetParseError(gpu::error::kLostContext); | |
| 242 return false; | |
| 243 } | |
| 244 return true; | |
| 241 } | 245 } |
| 242 | 246 |
| 243 void InProcessCommandBuffer::PumpCommands() { | 247 void InProcessCommandBuffer::PumpCommands() { |
| 244 CheckSequencedThread(); | 248 CheckSequencedThread(); |
| 245 command_buffer_lock_.AssertAcquired(); | 249 command_buffer_lock_.AssertAcquired(); |
| 246 | 250 |
| 247 if (!MakeCurrent()) | 251 if (!MakeCurrent()) |
| 248 return; | 252 return; |
| 249 | 253 |
| 250 executor_->PutChanged(); | 254 executor_->PutChanged(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); | 321 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); |
| 318 | 322 |
| 319 TransferBufferManager* manager = new TransferBufferManager(nullptr); | 323 TransferBufferManager* manager = new TransferBufferManager(nullptr); |
| 320 transfer_buffer_manager_ = manager; | 324 transfer_buffer_manager_ = manager; |
| 321 manager->Initialize(); | 325 manager->Initialize(); |
| 322 | 326 |
| 323 scoped_ptr<CommandBufferService> command_buffer( | 327 scoped_ptr<CommandBufferService> command_buffer( |
| 324 new CommandBufferService(transfer_buffer_manager_.get())); | 328 new CommandBufferService(transfer_buffer_manager_.get())); |
| 325 command_buffer->SetPutOffsetChangeCallback(base::Bind( | 329 command_buffer->SetPutOffsetChangeCallback(base::Bind( |
| 326 &InProcessCommandBuffer::PumpCommands, gpu_thread_weak_ptr_)); | 330 &InProcessCommandBuffer::PumpCommands, gpu_thread_weak_ptr_)); |
| 327 command_buffer->SetParseErrorCallback(base::Bind( | |
|
danakj
2016/04/06 23:44:42
Oops, gotta put this back too. :) Done.
| |
| 328 &InProcessCommandBuffer::OnContextLost, gpu_thread_weak_ptr_)); | |
| 329 | 331 |
| 330 if (!command_buffer->Initialize()) { | 332 if (!command_buffer->Initialize()) { |
| 331 LOG(ERROR) << "Could not initialize command buffer."; | 333 LOG(ERROR) << "Could not initialize command buffer."; |
| 332 DestroyOnGpuThread(); | 334 DestroyOnGpuThread(); |
| 333 return false; | 335 return false; |
| 334 } | 336 } |
| 335 | 337 |
| 336 gl_share_group_ = params.context_group | 338 gl_share_group_ = params.context_group |
| 337 ? params.context_group->gl_share_group_ | 339 ? params.context_group->gl_share_group_ |
| 338 : service_->share_group(); | 340 : service_->share_group(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 DCHECK(!sequence_checker_ || | 491 DCHECK(!sequence_checker_ || |
| 490 sequence_checker_->CalledOnValidSequencedThread()); | 492 sequence_checker_->CalledOnValidSequencedThread()); |
| 491 } | 493 } |
| 492 | 494 |
| 493 void InProcessCommandBuffer::OnContextLost() { | 495 void InProcessCommandBuffer::OnContextLost() { |
| 494 CheckSequencedThread(); | 496 CheckSequencedThread(); |
| 495 if (!context_lost_callback_.is_null()) { | 497 if (!context_lost_callback_.is_null()) { |
| 496 context_lost_callback_.Run(); | 498 context_lost_callback_.Run(); |
| 497 context_lost_callback_.Reset(); | 499 context_lost_callback_.Reset(); |
| 498 } | 500 } |
| 499 | |
| 500 context_lost_ = true; | |
| 501 } | 501 } |
| 502 | 502 |
| 503 CommandBuffer::State InProcessCommandBuffer::GetStateFast() { | 503 CommandBuffer::State InProcessCommandBuffer::GetStateFast() { |
| 504 CheckSequencedThread(); | 504 CheckSequencedThread(); |
| 505 base::AutoLock lock(state_after_last_flush_lock_); | 505 base::AutoLock lock(state_after_last_flush_lock_); |
| 506 if (state_after_last_flush_.generation - last_state_.generation < 0x80000000U) | 506 if (state_after_last_flush_.generation - last_state_.generation < 0x80000000U) |
| 507 last_state_ = state_after_last_flush_; | 507 last_state_ = state_after_last_flush_; |
| 508 return last_state_; | 508 return last_state_; |
| 509 } | 509 } |
| 510 | 510 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 527 | 527 |
| 528 { | 528 { |
| 529 ScopedOrderNumberProcessor scoped_order_num(sync_point_order_data_.get(), | 529 ScopedOrderNumberProcessor scoped_order_num(sync_point_order_data_.get(), |
| 530 order_num); | 530 order_num); |
| 531 command_buffer_->Flush(put_offset); | 531 command_buffer_->Flush(put_offset); |
| 532 { | 532 { |
| 533 // Update state before signaling the flush event. | 533 // Update state before signaling the flush event. |
| 534 base::AutoLock lock(state_after_last_flush_lock_); | 534 base::AutoLock lock(state_after_last_flush_lock_); |
| 535 state_after_last_flush_ = command_buffer_->GetLastState(); | 535 state_after_last_flush_ = command_buffer_->GetLastState(); |
| 536 } | 536 } |
| 537 DCHECK((!error::IsError(state_after_last_flush_.error) && !context_lost_) || | |
| 538 (error::IsError(state_after_last_flush_.error) && context_lost_)); | |
| 539 | 537 |
| 540 // Currently the in process command buffer does not support being | 538 // Currently the in process command buffer does not support being |
| 541 // descheduled, if it does we would need to back off on calling the finish | 539 // descheduled, if it does we would need to back off on calling the finish |
| 542 // processing number function until the message is rescheduled and finished | 540 // processing number function until the message is rescheduled and finished |
| 543 // processing. This DCHECK is to enforce this. | 541 // processing. This DCHECK is to enforce this. |
| 544 DCHECK(context_lost_ || put_offset == state_after_last_flush_.get_offset); | 542 DCHECK(error::IsError(state_after_last_flush_.error) || |
| 543 put_offset == state_after_last_flush_.get_offset); | |
| 545 } | 544 } |
| 546 | 545 |
| 547 // If we've processed all pending commands but still have pending queries, | 546 // If we've processed all pending commands but still have pending queries, |
| 548 // pump idle work until the query is passed. | 547 // pump idle work until the query is passed. |
| 549 if (put_offset == state_after_last_flush_.get_offset && | 548 if (put_offset == state_after_last_flush_.get_offset && |
| 550 (executor_->HasMoreIdleWork() || executor_->HasPendingQueries())) { | 549 (executor_->HasMoreIdleWork() || executor_->HasPendingQueries())) { |
| 551 ScheduleDelayedWorkOnGpuThread(); | 550 ScheduleDelayedWorkOnGpuThread(); |
| 552 } | 551 } |
| 553 } | 552 } |
| 554 | 553 |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 909 DCHECK(query_manager_); | 908 DCHECK(query_manager_); |
| 910 | 909 |
| 911 gles2::QueryManager::Query* query = query_manager_->GetQuery(query_id); | 910 gles2::QueryManager::Query* query = query_manager_->GetQuery(query_id); |
| 912 if (!query) | 911 if (!query) |
| 913 callback.Run(); | 912 callback.Run(); |
| 914 else | 913 else |
| 915 query->AddCallback(callback); | 914 query->AddCallback(callback); |
| 916 } | 915 } |
| 917 | 916 |
| 918 void InProcessCommandBuffer::SetLock(base::Lock*) { | 917 void InProcessCommandBuffer::SetLock(base::Lock*) { |
| 918 // No support for using on multiple threads. | |
| 919 NOTREACHED(); | |
| 919 } | 920 } |
| 920 | 921 |
| 921 bool InProcessCommandBuffer::IsGpuChannelLost() { | 922 bool InProcessCommandBuffer::IsGpuChannelLost() { |
| 922 // There is no such channel to lose for in-process contexts. This only | 923 // There is no such channel to lose for in-process contexts. This only |
| 923 // makes sense for out-of-process command buffers. | 924 // makes sense for out-of-process command buffers. |
| 924 return false; | 925 return false; |
| 925 } | 926 } |
| 926 | 927 |
| 927 void InProcessCommandBuffer::EnsureWorkVisible() { | 928 void InProcessCommandBuffer::EnsureWorkVisible() { |
| 928 // This is only relevant for out-of-process command buffers. | 929 // This is only relevant for out-of-process command buffers. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1091 framebuffer_completeness_cache_ = | 1092 framebuffer_completeness_cache_ = |
| 1092 new gpu::gles2::FramebufferCompletenessCache; | 1093 new gpu::gles2::FramebufferCompletenessCache; |
| 1093 return framebuffer_completeness_cache_; | 1094 return framebuffer_completeness_cache_; |
| 1094 } | 1095 } |
| 1095 | 1096 |
| 1096 SyncPointManager* GpuInProcessThread::sync_point_manager() { | 1097 SyncPointManager* GpuInProcessThread::sync_point_manager() { |
| 1097 return sync_point_manager_; | 1098 return sync_point_manager_; |
| 1098 } | 1099 } |
| 1099 | 1100 |
| 1100 } // namespace gpu | 1101 } // namespace gpu |
| OLD | NEW |