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 "content/common/gpu/client/command_buffer_proxy_impl.h" | 5 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); | 393 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); |
394 } | 394 } |
395 | 395 |
396 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { | 396 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { |
397 return capabilities_; | 397 return capabilities_; |
398 } | 398 } |
399 | 399 |
400 int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, | 400 int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, |
401 size_t width, | 401 size_t width, |
402 size_t height, | 402 size_t height, |
403 unsigned internal_format) { | 403 unsigned internalformat) { |
404 CheckLock(); | 404 CheckLock(); |
405 if (last_state_.error != gpu::error::kNoError) | 405 if (last_state_.error != gpu::error::kNoError) |
406 return -1; | 406 return -1; |
407 | 407 |
408 int32 new_id = channel_->ReserveImageId(); | 408 int32 new_id = channel_->ReserveImageId(); |
409 | 409 |
410 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = | 410 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = |
411 channel_->gpu_memory_buffer_manager(); | 411 channel_->gpu_memory_buffer_manager(); |
412 gfx::GpuMemoryBuffer* gpu_memory_buffer = | 412 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
413 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffer); | 413 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffer); |
414 DCHECK(gpu_memory_buffer); | 414 DCHECK(gpu_memory_buffer); |
415 | 415 |
416 // This handle is owned by the GPU process and must be passed to it or it | 416 // This handle is owned by the GPU process and must be passed to it or it |
417 // will leak. In otherwords, do not early out on error between here and the | 417 // will leak. In otherwords, do not early out on error between here and the |
418 // sending of the CreateImage IPC below. | 418 // sending of the CreateImage IPC below. |
419 bool requires_sync_token = false; | 419 bool requires_sync_point = false; |
420 gfx::GpuMemoryBufferHandle handle = | 420 gfx::GpuMemoryBufferHandle handle = |
421 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), | 421 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), |
422 &requires_sync_token); | 422 &requires_sync_point); |
423 | |
424 uint64_t image_fence_sync = 0; | |
425 if (requires_sync_token) { | |
426 image_fence_sync = GenerateFenceSyncRelease(); | |
427 | |
428 // Make sure fence syncs were flushed before CreateImage() was called. | |
429 DCHECK_LE(image_fence_sync - 1, flushed_fence_sync_release_); | |
430 } | |
431 | 423 |
432 DCHECK(gpu::ImageFactory::IsGpuMemoryBufferFormatSupported( | 424 DCHECK(gpu::ImageFactory::IsGpuMemoryBufferFormatSupported( |
433 gpu_memory_buffer->GetFormat(), capabilities_)); | 425 gpu_memory_buffer->GetFormat(), capabilities_)); |
434 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( | 426 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( |
435 gfx::Size(width, height), gpu_memory_buffer->GetFormat())); | 427 gfx::Size(width, height), gpu_memory_buffer->GetFormat())); |
436 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | 428 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( |
437 internal_format, gpu_memory_buffer->GetFormat())); | 429 internalformat, gpu_memory_buffer->GetFormat())); |
| 430 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, |
| 431 new_id, |
| 432 handle, |
| 433 gfx::Size(width, height), |
| 434 gpu_memory_buffer->GetFormat(), |
| 435 internalformat))) { |
| 436 return -1; |
| 437 } |
438 | 438 |
439 GpuCommandBufferMsg_CreateImage_Params params; | 439 if (requires_sync_point) { |
440 params.id = new_id; | 440 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, |
441 params.gpu_memory_buffer = handle; | 441 InsertSyncPoint()); |
442 params.size = gfx::Size(width, height); | |
443 params.format = gpu_memory_buffer->GetFormat(); | |
444 params.internal_format = internal_format; | |
445 params.image_release_count = image_fence_sync; | |
446 | |
447 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, params))) | |
448 return -1; | |
449 | |
450 if (image_fence_sync) { | |
451 gpu::SyncToken sync_token(GetNamespaceID(), GetCommandBufferID(), | |
452 image_fence_sync); | |
453 | |
454 // Force a synchronous IPC to validate sync token. | |
455 channel_->ValidateFlushIDReachedServer(stream_id_, true); | |
456 sync_token.SetVerifyFlush(); | |
457 | |
458 gpu_memory_buffer_manager->SetDestructionSyncToken(gpu_memory_buffer, | |
459 sync_token); | |
460 } | 442 } |
461 | 443 |
462 return new_id; | 444 return new_id; |
463 } | 445 } |
464 | 446 |
465 void CommandBufferProxyImpl::DestroyImage(int32 id) { | 447 void CommandBufferProxyImpl::DestroyImage(int32 id) { |
466 CheckLock(); | 448 CheckLock(); |
467 if (last_state_.error != gpu::error::kNoError) | 449 if (last_state_.error != gpu::error::kNoError) |
468 return; | 450 return; |
469 | 451 |
470 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); | 452 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); |
471 } | 453 } |
472 | 454 |
473 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( | 455 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( |
474 size_t width, | 456 size_t width, |
475 size_t height, | 457 size_t height, |
476 unsigned internal_format, | 458 unsigned internalformat, |
477 unsigned usage) { | 459 unsigned usage) { |
478 CheckLock(); | 460 CheckLock(); |
479 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | 461 scoped_ptr<gfx::GpuMemoryBuffer> buffer( |
480 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | 462 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
481 gfx::Size(width, height), | 463 gfx::Size(width, height), |
482 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internal_format), | 464 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internalformat), |
483 gfx::BufferUsage::SCANOUT)); | 465 gfx::BufferUsage::SCANOUT)); |
484 if (!buffer) | 466 if (!buffer) |
485 return -1; | 467 return -1; |
486 | 468 |
487 return CreateImage(buffer->AsClientBuffer(), width, height, internal_format); | 469 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); |
488 } | 470 } |
489 | 471 |
490 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { | 472 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { |
491 CheckLock(); | 473 CheckLock(); |
492 if (last_state_.error != gpu::error::kNoError) | 474 if (last_state_.error != gpu::error::kNoError) |
493 return 0; | 475 return 0; |
494 | 476 |
495 int32 stream_id = channel_->GenerateRouteID(); | 477 int32 stream_id = channel_->GenerateRouteID(); |
496 bool succeeded = false; | 478 bool succeeded = false; |
497 Send(new GpuCommandBufferMsg_CreateStreamTexture( | 479 Send(new GpuCommandBufferMsg_CreateStreamTexture( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 523 |
542 // Check if we have actually flushed the fence sync release. | 524 // Check if we have actually flushed the fence sync release. |
543 if (release <= flushed_fence_sync_release_) { | 525 if (release <= flushed_fence_sync_release_) { |
544 DCHECK(!flushed_release_flush_id_.empty()); | 526 DCHECK(!flushed_release_flush_id_.empty()); |
545 // Check if it has already been validated by another context. | 527 // Check if it has already been validated by another context. |
546 UpdateVerifiedReleases(channel_->GetHighestValidatedFlushID(stream_id_)); | 528 UpdateVerifiedReleases(channel_->GetHighestValidatedFlushID(stream_id_)); |
547 if (release <= verified_fence_sync_release_) | 529 if (release <= verified_fence_sync_release_) |
548 return true; | 530 return true; |
549 | 531 |
550 // Has not been validated, validate it now. | 532 // Has not been validated, validate it now. |
551 UpdateVerifiedReleases( | 533 UpdateVerifiedReleases(channel_->ValidateFlushIDReachedServer(stream_id_)); |
552 channel_->ValidateFlushIDReachedServer(stream_id_, false)); | |
553 return release <= verified_fence_sync_release_; | 534 return release <= verified_fence_sync_release_; |
554 } | 535 } |
555 | 536 |
556 return false; | 537 return false; |
557 } | 538 } |
558 | 539 |
559 void CommandBufferProxyImpl::SignalSyncToken(const gpu::SyncToken& sync_token, | 540 void CommandBufferProxyImpl::SignalSyncToken(const gpu::SyncToken& sync_token, |
560 const base::Closure& callback) { | 541 const base::Closure& callback) { |
561 CheckLock(); | 542 CheckLock(); |
562 if (last_state_.error != gpu::error::kNoError) | 543 if (last_state_.error != gpu::error::kNoError) |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 } | 738 } |
758 } | 739 } |
759 | 740 |
760 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, | 741 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, |
761 base::TimeDelta interval) { | 742 base::TimeDelta interval) { |
762 if (!update_vsync_parameters_completion_callback_.is_null()) | 743 if (!update_vsync_parameters_completion_callback_.is_null()) |
763 update_vsync_parameters_completion_callback_.Run(timebase, interval); | 744 update_vsync_parameters_completion_callback_.Run(timebase, interval); |
764 } | 745 } |
765 | 746 |
766 } // namespace content | 747 } // namespace content |
OLD | NEW |