| 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 <queue> | 7 #include <queue> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 InProcessCommandBuffer::~InProcessCommandBuffer() { | 220 InProcessCommandBuffer::~InProcessCommandBuffer() { |
| 221 Destroy(); | 221 Destroy(); |
| 222 base::AutoLock lock(default_thread_clients_lock_.Get()); | 222 base::AutoLock lock(default_thread_clients_lock_.Get()); |
| 223 default_thread_clients_.Get().erase(this); | 223 default_thread_clients_.Get().erase(this); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void InProcessCommandBuffer::OnResizeView(gfx::Size size, float scale_factor) { | 226 void InProcessCommandBuffer::OnResizeView(gfx::Size size, float scale_factor) { |
| 227 CheckSequencedThread(); | |
| 228 DCHECK(!surface_->IsOffscreen()); | 227 DCHECK(!surface_->IsOffscreen()); |
| 229 surface_->Resize(size); | 228 surface_->Resize(size); |
| 230 } | 229 } |
| 231 | 230 |
| 232 bool InProcessCommandBuffer::MakeCurrent() { | 231 bool InProcessCommandBuffer::MakeCurrent() { |
| 233 CheckSequencedThread(); | |
| 234 command_buffer_lock_.AssertAcquired(); | 232 command_buffer_lock_.AssertAcquired(); |
| 235 | 233 |
| 236 if (!context_lost_ && decoder_->MakeCurrent()) | 234 if (!context_lost_ && decoder_->MakeCurrent()) |
| 237 return true; | 235 return true; |
| 238 DLOG(ERROR) << "Context lost because MakeCurrent failed."; | 236 DLOG(ERROR) << "Context lost because MakeCurrent failed."; |
| 239 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | 237 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
| 240 command_buffer_->SetParseError(gpu::error::kLostContext); | 238 command_buffer_->SetParseError(gpu::error::kLostContext); |
| 241 return false; | 239 return false; |
| 242 } | 240 } |
| 243 | 241 |
| 244 void InProcessCommandBuffer::PumpCommands() { | 242 void InProcessCommandBuffer::PumpCommands() { |
| 245 CheckSequencedThread(); | |
| 246 command_buffer_lock_.AssertAcquired(); | 243 command_buffer_lock_.AssertAcquired(); |
| 247 | 244 |
| 248 if (!MakeCurrent()) | 245 if (!MakeCurrent()) |
| 249 return; | 246 return; |
| 250 | 247 |
| 251 gpu_scheduler_->PutChanged(); | 248 gpu_scheduler_->PutChanged(); |
| 252 } | 249 } |
| 253 | 250 |
| 254 bool InProcessCommandBuffer::GetBufferChanged(int32 transfer_buffer_id) { | 251 bool InProcessCommandBuffer::GetBufferChanged(int32 transfer_buffer_id) { |
| 255 CheckSequencedThread(); | |
| 256 command_buffer_lock_.AssertAcquired(); | 252 command_buffer_lock_.AssertAcquired(); |
| 257 command_buffer_->SetGetBuffer(transfer_buffer_id); | 253 command_buffer_->SetGetBuffer(transfer_buffer_id); |
| 258 return true; | 254 return true; |
| 259 } | 255 } |
| 260 | 256 |
| 261 bool InProcessCommandBuffer::Initialize( | 257 bool InProcessCommandBuffer::Initialize( |
| 262 scoped_refptr<gfx::GLSurface> surface, | 258 gfx::GLSurface* surface, |
| 263 bool is_offscreen, | 259 bool is_offscreen, |
| 264 gfx::AcceleratedWidget window, | 260 gfx::AcceleratedWidget window, |
| 265 const gfx::Size& size, | 261 const gfx::Size& size, |
| 266 const std::vector<int32>& attribs, | 262 const std::vector<int32>& attribs, |
| 267 gfx::GpuPreference gpu_preference, | 263 gfx::GpuPreference gpu_preference, |
| 268 const base::Closure& context_lost_callback, | 264 const base::Closure& context_lost_callback, |
| 269 InProcessCommandBuffer* share_group) { | 265 InProcessCommandBuffer* share_group) { |
| 270 DCHECK(!share_group || service_ == share_group->service_); | 266 DCHECK(!share_group || service_ == share_group->service_); |
| 271 context_lost_callback_ = WrapCallback(context_lost_callback); | 267 context_lost_callback_ = WrapCallback(context_lost_callback); |
| 272 | 268 |
| 273 if (surface) { | |
| 274 // GPU thread must be the same as client thread due to GLSurface not being | |
| 275 // thread safe. | |
| 276 sequence_checker_.reset(new base::SequenceChecker); | |
| 277 surface_ = surface; | |
| 278 } | |
| 279 | |
| 280 gpu::Capabilities capabilities; | 269 gpu::Capabilities capabilities; |
| 281 InitializeOnGpuThreadParams params(is_offscreen, | 270 InitializeOnGpuThreadParams params(surface, |
| 271 is_offscreen, |
| 282 window, | 272 window, |
| 283 size, | 273 size, |
| 284 attribs, | 274 attribs, |
| 285 gpu_preference, | 275 gpu_preference, |
| 286 &capabilities, | 276 &capabilities, |
| 287 share_group); | 277 share_group); |
| 288 | 278 |
| 289 base::Callback<bool(void)> init_task = | 279 base::Callback<bool(void)> init_task = |
| 290 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, | 280 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, |
| 291 base::Unretained(this), | 281 base::Unretained(this), |
| 292 params); | 282 params); |
| 293 | 283 |
| 294 base::WaitableEvent completion(true, false); | 284 base::WaitableEvent completion(true, false); |
| 295 bool result = false; | 285 bool result = false; |
| 296 QueueTask( | 286 QueueTask( |
| 297 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); | 287 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); |
| 298 completion.Wait(); | 288 completion.Wait(); |
| 299 | 289 |
| 300 if (result) { | 290 if (result) { |
| 301 capabilities_ = capabilities; | 291 capabilities_ = capabilities; |
| 302 capabilities_.map_image = | 292 capabilities_.map_image = |
| 303 capabilities_.map_image && g_gpu_memory_buffer_factory; | 293 capabilities_.map_image && g_gpu_memory_buffer_factory; |
| 304 } | 294 } |
| 305 return result; | 295 return result; |
| 306 } | 296 } |
| 307 | 297 |
| 308 bool InProcessCommandBuffer::InitializeOnGpuThread( | 298 bool InProcessCommandBuffer::InitializeOnGpuThread( |
| 309 const InitializeOnGpuThreadParams& params) { | 299 const InitializeOnGpuThreadParams& params) { |
| 310 CheckSequencedThread(); | |
| 311 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); | 300 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); |
| 312 | 301 |
| 313 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); | 302 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); |
| 314 | 303 |
| 304 surface_ = params.surface; |
| 305 |
| 315 TransferBufferManager* manager = new TransferBufferManager(); | 306 TransferBufferManager* manager = new TransferBufferManager(); |
| 316 transfer_buffer_manager_.reset(manager); | 307 transfer_buffer_manager_.reset(manager); |
| 317 manager->Initialize(); | 308 manager->Initialize(); |
| 318 | 309 |
| 319 scoped_ptr<CommandBufferService> command_buffer( | 310 scoped_ptr<CommandBufferService> command_buffer( |
| 320 new CommandBufferService(transfer_buffer_manager_.get())); | 311 new CommandBufferService(transfer_buffer_manager_.get())); |
| 321 command_buffer->SetPutOffsetChangeCallback(base::Bind( | 312 command_buffer->SetPutOffsetChangeCallback(base::Bind( |
| 322 &InProcessCommandBuffer::PumpCommands, gpu_thread_weak_ptr_)); | 313 &InProcessCommandBuffer::PumpCommands, gpu_thread_weak_ptr_)); |
| 323 command_buffer->SetParseErrorCallback(base::Bind( | 314 command_buffer->SetParseErrorCallback(base::Bind( |
| 324 &InProcessCommandBuffer::OnContextLost, gpu_thread_weak_ptr_)); | 315 &InProcessCommandBuffer::OnContextLost, gpu_thread_weak_ptr_)); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (!params.is_offscreen) { | 413 if (!params.is_offscreen) { |
| 423 decoder_->SetResizeCallback(base::Bind( | 414 decoder_->SetResizeCallback(base::Bind( |
| 424 &InProcessCommandBuffer::OnResizeView, gpu_thread_weak_ptr_)); | 415 &InProcessCommandBuffer::OnResizeView, gpu_thread_weak_ptr_)); |
| 425 } | 416 } |
| 426 decoder_->SetWaitSyncPointCallback(base::Bind(&WaitSyncPoint)); | 417 decoder_->SetWaitSyncPointCallback(base::Bind(&WaitSyncPoint)); |
| 427 | 418 |
| 428 return true; | 419 return true; |
| 429 } | 420 } |
| 430 | 421 |
| 431 void InProcessCommandBuffer::Destroy() { | 422 void InProcessCommandBuffer::Destroy() { |
| 432 CheckSequencedThread(); | |
| 433 | |
| 434 base::WaitableEvent completion(true, false); | 423 base::WaitableEvent completion(true, false); |
| 435 bool result = false; | 424 bool result = false; |
| 436 base::Callback<bool(void)> destroy_task = base::Bind( | 425 base::Callback<bool(void)> destroy_task = base::Bind( |
| 437 &InProcessCommandBuffer::DestroyOnGpuThread, base::Unretained(this)); | 426 &InProcessCommandBuffer::DestroyOnGpuThread, base::Unretained(this)); |
| 438 QueueTask( | 427 QueueTask( |
| 439 base::Bind(&RunTaskWithResult<bool>, destroy_task, &result, &completion)); | 428 base::Bind(&RunTaskWithResult<bool>, destroy_task, &result, &completion)); |
| 440 completion.Wait(); | 429 completion.Wait(); |
| 441 } | 430 } |
| 442 | 431 |
| 443 bool InProcessCommandBuffer::DestroyOnGpuThread() { | 432 bool InProcessCommandBuffer::DestroyOnGpuThread() { |
| 444 CheckSequencedThread(); | |
| 445 gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs(); | 433 gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 446 command_buffer_.reset(); | 434 command_buffer_.reset(); |
| 447 // Clean up GL resources if possible. | 435 // Clean up GL resources if possible. |
| 448 bool have_context = context_ && context_->MakeCurrent(surface_); | 436 bool have_context = context_ && context_->MakeCurrent(surface_); |
| 449 if (decoder_) { | 437 if (decoder_) { |
| 450 decoder_->Destroy(have_context); | 438 decoder_->Destroy(have_context); |
| 451 decoder_.reset(); | 439 decoder_.reset(); |
| 452 } | 440 } |
| 453 context_ = NULL; | 441 context_ = NULL; |
| 454 surface_ = NULL; | 442 surface_ = NULL; |
| 455 gl_share_group_ = NULL; | 443 gl_share_group_ = NULL; |
| 456 #if defined(OS_ANDROID) | 444 #if defined(OS_ANDROID) |
| 457 stream_texture_manager_.reset(); | 445 stream_texture_manager_.reset(); |
| 458 #endif | 446 #endif |
| 459 | 447 |
| 460 return true; | 448 return true; |
| 461 } | 449 } |
| 462 | 450 |
| 463 void InProcessCommandBuffer::CheckSequencedThread() { | |
| 464 DCHECK(!sequence_checker_ || | |
| 465 sequence_checker_->CalledOnValidSequencedThread()); | |
| 466 } | |
| 467 | |
| 468 void InProcessCommandBuffer::OnContextLost() { | 451 void InProcessCommandBuffer::OnContextLost() { |
| 469 CheckSequencedThread(); | |
| 470 if (!context_lost_callback_.is_null()) { | 452 if (!context_lost_callback_.is_null()) { |
| 471 context_lost_callback_.Run(); | 453 context_lost_callback_.Run(); |
| 472 context_lost_callback_.Reset(); | 454 context_lost_callback_.Reset(); |
| 473 } | 455 } |
| 474 | 456 |
| 475 context_lost_ = true; | 457 context_lost_ = true; |
| 476 } | 458 } |
| 477 | 459 |
| 478 CommandBuffer::State InProcessCommandBuffer::GetStateFast() { | 460 CommandBuffer::State InProcessCommandBuffer::GetStateFast() { |
| 479 CheckSequencedThread(); | |
| 480 base::AutoLock lock(state_after_last_flush_lock_); | 461 base::AutoLock lock(state_after_last_flush_lock_); |
| 481 if (state_after_last_flush_.generation - last_state_.generation < 0x80000000U) | 462 if (state_after_last_flush_.generation - last_state_.generation < 0x80000000U) |
| 482 last_state_ = state_after_last_flush_; | 463 last_state_ = state_after_last_flush_; |
| 483 return last_state_; | 464 return last_state_; |
| 484 } | 465 } |
| 485 | 466 |
| 486 CommandBuffer::State InProcessCommandBuffer::GetLastState() { | 467 CommandBuffer::State InProcessCommandBuffer::GetLastState() { |
| 487 CheckSequencedThread(); | |
| 488 return last_state_; | 468 return last_state_; |
| 489 } | 469 } |
| 490 | 470 |
| 491 int32 InProcessCommandBuffer::GetLastToken() { | 471 int32 InProcessCommandBuffer::GetLastToken() { |
| 492 CheckSequencedThread(); | |
| 493 GetStateFast(); | 472 GetStateFast(); |
| 494 return last_state_.token; | 473 return last_state_.token; |
| 495 } | 474 } |
| 496 | 475 |
| 497 void InProcessCommandBuffer::FlushOnGpuThread(int32 put_offset) { | 476 void InProcessCommandBuffer::FlushOnGpuThread(int32 put_offset) { |
| 498 CheckSequencedThread(); | |
| 499 ScopedEvent handle_flush(&flush_event_); | 477 ScopedEvent handle_flush(&flush_event_); |
| 500 base::AutoLock lock(command_buffer_lock_); | 478 base::AutoLock lock(command_buffer_lock_); |
| 501 command_buffer_->Flush(put_offset); | 479 command_buffer_->Flush(put_offset); |
| 502 { | 480 { |
| 503 // Update state before signaling the flush event. | 481 // Update state before signaling the flush event. |
| 504 base::AutoLock lock(state_after_last_flush_lock_); | 482 base::AutoLock lock(state_after_last_flush_lock_); |
| 505 state_after_last_flush_ = command_buffer_->GetLastState(); | 483 state_after_last_flush_ = command_buffer_->GetLastState(); |
| 506 } | 484 } |
| 507 DCHECK((!error::IsError(state_after_last_flush_.error) && !context_lost_) || | 485 DCHECK((!error::IsError(state_after_last_flush_.error) && !context_lost_) || |
| 508 (error::IsError(state_after_last_flush_.error) && context_lost_)); | 486 (error::IsError(state_after_last_flush_.error) && context_lost_)); |
| 509 | 487 |
| 510 // If we've processed all pending commands but still have pending queries, | 488 // If we've processed all pending commands but still have pending queries, |
| 511 // pump idle work until the query is passed. | 489 // pump idle work until the query is passed. |
| 512 if (put_offset == state_after_last_flush_.get_offset && | 490 if (put_offset == state_after_last_flush_.get_offset && |
| 513 gpu_scheduler_->HasMoreWork()) { | 491 gpu_scheduler_->HasMoreWork()) { |
| 514 service_->ScheduleIdleWork( | 492 service_->ScheduleIdleWork( |
| 515 base::Bind(&InProcessCommandBuffer::ScheduleMoreIdleWork, | 493 base::Bind(&InProcessCommandBuffer::ScheduleMoreIdleWork, |
| 516 gpu_thread_weak_ptr_)); | 494 gpu_thread_weak_ptr_)); |
| 517 } | 495 } |
| 518 } | 496 } |
| 519 | 497 |
| 520 void InProcessCommandBuffer::ScheduleMoreIdleWork() { | 498 void InProcessCommandBuffer::ScheduleMoreIdleWork() { |
| 521 CheckSequencedThread(); | |
| 522 base::AutoLock lock(command_buffer_lock_); | 499 base::AutoLock lock(command_buffer_lock_); |
| 523 if (gpu_scheduler_->HasMoreWork()) { | 500 if (gpu_scheduler_->HasMoreWork()) { |
| 524 gpu_scheduler_->PerformIdleWork(); | 501 gpu_scheduler_->PerformIdleWork(); |
| 525 service_->ScheduleIdleWork( | 502 service_->ScheduleIdleWork( |
| 526 base::Bind(&InProcessCommandBuffer::ScheduleMoreIdleWork, | 503 base::Bind(&InProcessCommandBuffer::ScheduleMoreIdleWork, |
| 527 gpu_thread_weak_ptr_)); | 504 gpu_thread_weak_ptr_)); |
| 528 } | 505 } |
| 529 } | 506 } |
| 530 | 507 |
| 531 void InProcessCommandBuffer::Flush(int32 put_offset) { | 508 void InProcessCommandBuffer::Flush(int32 put_offset) { |
| 532 CheckSequencedThread(); | |
| 533 if (last_state_.error != gpu::error::kNoError) | 509 if (last_state_.error != gpu::error::kNoError) |
| 534 return; | 510 return; |
| 535 | 511 |
| 536 if (last_put_offset_ == put_offset) | 512 if (last_put_offset_ == put_offset) |
| 537 return; | 513 return; |
| 538 | 514 |
| 539 last_put_offset_ = put_offset; | 515 last_put_offset_ = put_offset; |
| 540 base::Closure task = base::Bind(&InProcessCommandBuffer::FlushOnGpuThread, | 516 base::Closure task = base::Bind(&InProcessCommandBuffer::FlushOnGpuThread, |
| 541 gpu_thread_weak_ptr_, | 517 gpu_thread_weak_ptr_, |
| 542 put_offset); | 518 put_offset); |
| 543 QueueTask(task); | 519 QueueTask(task); |
| 544 } | 520 } |
| 545 | 521 |
| 546 void InProcessCommandBuffer::WaitForTokenInRange(int32 start, int32 end) { | 522 void InProcessCommandBuffer::WaitForTokenInRange(int32 start, int32 end) { |
| 547 CheckSequencedThread(); | |
| 548 while (!InRange(start, end, GetLastToken()) && | 523 while (!InRange(start, end, GetLastToken()) && |
| 549 last_state_.error == gpu::error::kNoError) | 524 last_state_.error == gpu::error::kNoError) |
| 550 flush_event_.Wait(); | 525 flush_event_.Wait(); |
| 551 } | 526 } |
| 552 | 527 |
| 553 void InProcessCommandBuffer::WaitForGetOffsetInRange(int32 start, int32 end) { | 528 void InProcessCommandBuffer::WaitForGetOffsetInRange(int32 start, int32 end) { |
| 554 CheckSequencedThread(); | |
| 555 | |
| 556 GetStateFast(); | 529 GetStateFast(); |
| 557 while (!InRange(start, end, last_state_.get_offset) && | 530 while (!InRange(start, end, last_state_.get_offset) && |
| 558 last_state_.error == gpu::error::kNoError) { | 531 last_state_.error == gpu::error::kNoError) { |
| 559 flush_event_.Wait(); | 532 flush_event_.Wait(); |
| 560 GetStateFast(); | 533 GetStateFast(); |
| 561 } | 534 } |
| 562 } | 535 } |
| 563 | 536 |
| 564 void InProcessCommandBuffer::SetGetBuffer(int32 shm_id) { | 537 void InProcessCommandBuffer::SetGetBuffer(int32 shm_id) { |
| 565 CheckSequencedThread(); | |
| 566 if (last_state_.error != gpu::error::kNoError) | 538 if (last_state_.error != gpu::error::kNoError) |
| 567 return; | 539 return; |
| 568 | 540 |
| 569 { | 541 { |
| 570 base::AutoLock lock(command_buffer_lock_); | 542 base::AutoLock lock(command_buffer_lock_); |
| 571 command_buffer_->SetGetBuffer(shm_id); | 543 command_buffer_->SetGetBuffer(shm_id); |
| 572 last_put_offset_ = 0; | 544 last_put_offset_ = 0; |
| 573 } | 545 } |
| 574 { | 546 { |
| 575 base::AutoLock lock(state_after_last_flush_lock_); | 547 base::AutoLock lock(state_after_last_flush_lock_); |
| 576 state_after_last_flush_ = command_buffer_->GetLastState(); | 548 state_after_last_flush_ = command_buffer_->GetLastState(); |
| 577 } | 549 } |
| 578 } | 550 } |
| 579 | 551 |
| 580 scoped_refptr<Buffer> InProcessCommandBuffer::CreateTransferBuffer(size_t size, | 552 scoped_refptr<Buffer> InProcessCommandBuffer::CreateTransferBuffer(size_t size, |
| 581 int32* id) { | 553 int32* id) { |
| 582 CheckSequencedThread(); | |
| 583 base::AutoLock lock(command_buffer_lock_); | 554 base::AutoLock lock(command_buffer_lock_); |
| 584 return command_buffer_->CreateTransferBuffer(size, id); | 555 return command_buffer_->CreateTransferBuffer(size, id); |
| 585 } | 556 } |
| 586 | 557 |
| 587 void InProcessCommandBuffer::DestroyTransferBuffer(int32 id) { | 558 void InProcessCommandBuffer::DestroyTransferBuffer(int32 id) { |
| 588 CheckSequencedThread(); | |
| 589 base::Closure task = | 559 base::Closure task = |
| 590 base::Bind(&InProcessCommandBuffer::DestroyTransferBufferOnGputhread, | 560 base::Bind(&InProcessCommandBuffer::DestroyTransferBufferOnGputhread, |
| 591 base::Unretained(this), | 561 base::Unretained(this), |
| 592 id); | 562 id); |
| 593 | 563 |
| 594 QueueTask(task); | 564 QueueTask(task); |
| 595 } | 565 } |
| 596 | 566 |
| 597 void InProcessCommandBuffer::DestroyTransferBufferOnGputhread(int32 id) { | 567 void InProcessCommandBuffer::DestroyTransferBufferOnGputhread(int32 id) { |
| 598 base::AutoLock lock(command_buffer_lock_); | 568 base::AutoLock lock(command_buffer_lock_); |
| 599 command_buffer_->DestroyTransferBuffer(id); | 569 command_buffer_->DestroyTransferBuffer(id); |
| 600 } | 570 } |
| 601 | 571 |
| 602 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { | 572 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { |
| 603 return capabilities_; | 573 return capabilities_; |
| 604 } | 574 } |
| 605 | 575 |
| 606 gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer( | 576 gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer( |
| 607 size_t width, | 577 size_t width, |
| 608 size_t height, | 578 size_t height, |
| 609 unsigned internalformat, | 579 unsigned internalformat, |
| 610 unsigned usage, | 580 unsigned usage, |
| 611 int32* id) { | 581 int32* id) { |
| 612 CheckSequencedThread(); | |
| 613 | 582 |
| 614 *id = -1; | 583 *id = -1; |
| 615 linked_ptr<gfx::GpuMemoryBuffer> buffer = | 584 linked_ptr<gfx::GpuMemoryBuffer> buffer = |
| 616 make_linked_ptr(g_gpu_memory_buffer_factory->CreateGpuMemoryBuffer( | 585 make_linked_ptr(g_gpu_memory_buffer_factory->CreateGpuMemoryBuffer( |
| 617 width, height, internalformat, usage)); | 586 width, height, internalformat, usage)); |
| 618 if (!buffer.get()) | 587 if (!buffer.get()) |
| 619 return NULL; | 588 return NULL; |
| 620 | 589 |
| 621 static int32 next_id = 1; | 590 static int32 next_id = 1; |
| 622 *id = next_id++; | 591 *id = next_id++; |
| 623 | 592 |
| 624 base::Closure task = base::Bind(&GpuControlService::RegisterGpuMemoryBuffer, | 593 base::Closure task = base::Bind(&GpuControlService::RegisterGpuMemoryBuffer, |
| 625 base::Unretained(gpu_control_.get()), | 594 base::Unretained(gpu_control_.get()), |
| 626 *id, | 595 *id, |
| 627 buffer->GetHandle(), | 596 buffer->GetHandle(), |
| 628 width, | 597 width, |
| 629 height, | 598 height, |
| 630 internalformat); | 599 internalformat); |
| 631 | 600 |
| 632 QueueTask(task); | 601 QueueTask(task); |
| 633 | 602 |
| 634 gpu_memory_buffers_[*id] = buffer; | 603 gpu_memory_buffers_[*id] = buffer; |
| 635 return buffer.get(); | 604 return buffer.get(); |
| 636 } | 605 } |
| 637 | 606 |
| 638 void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) { | 607 void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) { |
| 639 CheckSequencedThread(); | |
| 640 GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); | 608 GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); |
| 641 if (it != gpu_memory_buffers_.end()) | 609 if (it != gpu_memory_buffers_.end()) |
| 642 gpu_memory_buffers_.erase(it); | 610 gpu_memory_buffers_.erase(it); |
| 643 base::Closure task = base::Bind(&GpuControlService::UnregisterGpuMemoryBuffer, | 611 base::Closure task = base::Bind(&GpuControlService::UnregisterGpuMemoryBuffer, |
| 644 base::Unretained(gpu_control_.get()), | 612 base::Unretained(gpu_control_.get()), |
| 645 id); | 613 id); |
| 646 | 614 |
| 647 QueueTask(task); | 615 QueueTask(task); |
| 648 } | 616 } |
| 649 | 617 |
| 650 uint32 InProcessCommandBuffer::InsertSyncPoint() { | 618 uint32 InProcessCommandBuffer::InsertSyncPoint() { |
| 651 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); | 619 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); |
| 652 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, | 620 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, |
| 653 base::Unretained(this), | 621 base::Unretained(this), |
| 654 sync_point)); | 622 sync_point)); |
| 655 return sync_point; | 623 return sync_point; |
| 656 } | 624 } |
| 657 | 625 |
| 658 void InProcessCommandBuffer::RetireSyncPointOnGpuThread(uint32 sync_point) { | 626 void InProcessCommandBuffer::RetireSyncPointOnGpuThread(uint32 sync_point) { |
| 659 gles2::MailboxManager* mailbox_manager = | 627 gles2::MailboxManager* mailbox_manager = |
| 660 decoder_->GetContextGroup()->mailbox_manager(); | 628 decoder_->GetContextGroup()->mailbox_manager(); |
| 661 if (mailbox_manager->UsesSync() && MakeCurrent()) | 629 if (mailbox_manager->UsesSync() && MakeCurrent()) |
| 662 mailbox_manager->PushTextureUpdates(); | 630 mailbox_manager->PushTextureUpdates(); |
| 663 g_sync_point_manager.Get().RetireSyncPoint(sync_point); | 631 g_sync_point_manager.Get().RetireSyncPoint(sync_point); |
| 664 } | 632 } |
| 665 | 633 |
| 666 void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point, | 634 void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point, |
| 667 const base::Closure& callback) { | 635 const base::Closure& callback) { |
| 668 CheckSequencedThread(); | |
| 669 QueueTask(base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, | 636 QueueTask(base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, |
| 670 base::Unretained(this), | 637 base::Unretained(this), |
| 671 sync_point, | 638 sync_point, |
| 672 WrapCallback(callback))); | 639 WrapCallback(callback))); |
| 673 } | 640 } |
| 674 | 641 |
| 675 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( | 642 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( |
| 676 unsigned sync_point, | 643 unsigned sync_point, |
| 677 const base::Closure& callback) { | 644 const base::Closure& callback) { |
| 678 if (g_sync_point_manager.Get().IsSyncPointPassed(sync_point)) { | 645 if (g_sync_point_manager.Get().IsSyncPointPassed(sync_point)) { |
| 679 callback.Run(); | 646 callback.Run(); |
| 680 } else { | 647 } else { |
| 681 service_->ScheduleIdleWork( | 648 service_->ScheduleIdleWork( |
| 682 base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, | 649 base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, |
| 683 gpu_thread_weak_ptr_, | 650 gpu_thread_weak_ptr_, |
| 684 sync_point, | 651 sync_point, |
| 685 callback)); | 652 callback)); |
| 686 } | 653 } |
| 687 } | 654 } |
| 688 | 655 |
| 689 void InProcessCommandBuffer::SignalQuery(unsigned query, | 656 void InProcessCommandBuffer::SignalQuery(unsigned query, |
| 690 const base::Closure& callback) { | 657 const base::Closure& callback) { |
| 691 CheckSequencedThread(); | |
| 692 QueueTask(base::Bind(&GpuControlService::SignalQuery, | 658 QueueTask(base::Bind(&GpuControlService::SignalQuery, |
| 693 base::Unretained(gpu_control_.get()), | 659 base::Unretained(gpu_control_.get()), |
| 694 query, | 660 query, |
| 695 WrapCallback(callback))); | 661 WrapCallback(callback))); |
| 696 } | 662 } |
| 697 | 663 |
| 698 void InProcessCommandBuffer::SetSurfaceVisible(bool visible) {} | 664 void InProcessCommandBuffer::SetSurfaceVisible(bool visible) {} |
| 699 | 665 |
| 700 void InProcessCommandBuffer::SendManagedMemoryStats( | 666 void InProcessCommandBuffer::SendManagedMemoryStats( |
| 701 const gpu::ManagedMemoryStats& stats) { | 667 const gpu::ManagedMemoryStats& stats) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 722 uint32 client_texture_id) { | 688 uint32 client_texture_id) { |
| 723 #if defined(OS_ANDROID) | 689 #if defined(OS_ANDROID) |
| 724 return stream_texture_manager_->CreateStreamTexture( | 690 return stream_texture_manager_->CreateStreamTexture( |
| 725 client_texture_id, decoder_->GetContextGroup()->texture_manager()); | 691 client_texture_id, decoder_->GetContextGroup()->texture_manager()); |
| 726 #else | 692 #else |
| 727 return 0; | 693 return 0; |
| 728 #endif | 694 #endif |
| 729 } | 695 } |
| 730 | 696 |
| 731 gpu::error::Error InProcessCommandBuffer::GetLastError() { | 697 gpu::error::Error InProcessCommandBuffer::GetLastError() { |
| 732 CheckSequencedThread(); | |
| 733 return last_state_.error; | 698 return last_state_.error; |
| 734 } | 699 } |
| 735 | 700 |
| 736 bool InProcessCommandBuffer::Initialize() { | 701 bool InProcessCommandBuffer::Initialize() { |
| 737 NOTREACHED(); | 702 NOTREACHED(); |
| 738 return false; | 703 return false; |
| 739 } | 704 } |
| 740 | 705 |
| 741 namespace { | 706 namespace { |
| 742 | 707 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 } | 742 } |
| 778 #endif | 743 #endif |
| 779 | 744 |
| 780 // static | 745 // static |
| 781 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( | 746 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( |
| 782 GpuMemoryBufferFactory* factory) { | 747 GpuMemoryBufferFactory* factory) { |
| 783 g_gpu_memory_buffer_factory = factory; | 748 g_gpu_memory_buffer_factory = factory; |
| 784 } | 749 } |
| 785 | 750 |
| 786 } // namespace gpu | 751 } // namespace gpu |
| OLD | NEW |