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 internalformat) { | 403 unsigned internal_format) { |
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_point = false; | 419 bool requires_sync_token = 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_point); | 422 &requires_sync_token); |
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 } | |
423 | 431 |
424 DCHECK(gpu::ImageFactory::IsGpuMemoryBufferFormatSupported( | 432 DCHECK(gpu::ImageFactory::IsGpuMemoryBufferFormatSupported( |
425 gpu_memory_buffer->GetFormat(), capabilities_)); | 433 gpu_memory_buffer->GetFormat(), capabilities_)); |
426 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( | 434 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( |
427 gfx::Size(width, height), gpu_memory_buffer->GetFormat())); | 435 gfx::Size(width, height), gpu_memory_buffer->GetFormat())); |
428 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | 436 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( |
429 internalformat, gpu_memory_buffer->GetFormat())); | 437 internal_format, gpu_memory_buffer->GetFormat())); |
430 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, | 438 |
431 new_id, | 439 GpuCommandBufferMsg_CreateImage_Params params; |
432 handle, | 440 params.id = new_id; |
433 gfx::Size(width, height), | 441 params.gpu_memory_buffer = handle; |
434 gpu_memory_buffer->GetFormat(), | 442 params.size = gfx::Size(width, height); |
435 internalformat))) { | 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))) | |
436 return -1; | 448 return -1; |
437 } | |
438 | 449 |
439 if (requires_sync_point) { | 450 if (image_fence_sync) { |
440 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, | 451 gpu::SyncToken sync_token(GetNamespaceID(), GetCommandBufferID(), |
441 InsertSyncPoint()); | 452 image_fence_sync); |
453 | |
454 // Force a synchronous IPC to validate sync token. | |
455 channel_->ValidateFlushIDReachedServer(stream_id_, true); | |
piman
2015/11/05 00:04:36
A potential optimization: we could make GpuCommand
David Yen
2015/11/05 00:34:27
One advantage to having GpuChannelHost doing it is
| |
456 sync_token.SetVerifyFlush(); | |
457 | |
458 gpu_memory_buffer_manager->SetDestructionSyncToken(gpu_memory_buffer, | |
459 sync_token); | |
442 } | 460 } |
443 | 461 |
444 return new_id; | 462 return new_id; |
445 } | 463 } |
446 | 464 |
447 void CommandBufferProxyImpl::DestroyImage(int32 id) { | 465 void CommandBufferProxyImpl::DestroyImage(int32 id) { |
448 CheckLock(); | 466 CheckLock(); |
449 if (last_state_.error != gpu::error::kNoError) | 467 if (last_state_.error != gpu::error::kNoError) |
450 return; | 468 return; |
451 | 469 |
452 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); | 470 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); |
453 } | 471 } |
454 | 472 |
455 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( | 473 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( |
456 size_t width, | 474 size_t width, |
457 size_t height, | 475 size_t height, |
458 unsigned internalformat, | 476 unsigned internal_format, |
459 unsigned usage) { | 477 unsigned usage) { |
460 CheckLock(); | 478 CheckLock(); |
461 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | 479 scoped_ptr<gfx::GpuMemoryBuffer> buffer( |
462 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | 480 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
463 gfx::Size(width, height), | 481 gfx::Size(width, height), |
464 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internalformat), | 482 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internal_format), |
465 gfx::BufferUsage::SCANOUT)); | 483 gfx::BufferUsage::SCANOUT)); |
466 if (!buffer) | 484 if (!buffer) |
467 return -1; | 485 return -1; |
468 | 486 |
469 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); | 487 return CreateImage(buffer->AsClientBuffer(), width, height, internal_format); |
470 } | 488 } |
471 | 489 |
472 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { | 490 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { |
473 CheckLock(); | 491 CheckLock(); |
474 if (last_state_.error != gpu::error::kNoError) | 492 if (last_state_.error != gpu::error::kNoError) |
475 return 0; | 493 return 0; |
476 | 494 |
477 int32 stream_id = channel_->GenerateRouteID(); | 495 int32 stream_id = channel_->GenerateRouteID(); |
478 bool succeeded = false; | 496 bool succeeded = false; |
479 Send(new GpuCommandBufferMsg_CreateStreamTexture( | 497 Send(new GpuCommandBufferMsg_CreateStreamTexture( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 | 541 |
524 // Check if we have actually flushed the fence sync release. | 542 // Check if we have actually flushed the fence sync release. |
525 if (release <= flushed_fence_sync_release_) { | 543 if (release <= flushed_fence_sync_release_) { |
526 DCHECK(!flushed_release_flush_id_.empty()); | 544 DCHECK(!flushed_release_flush_id_.empty()); |
527 // Check if it has already been validated by another context. | 545 // Check if it has already been validated by another context. |
528 UpdateVerifiedReleases(channel_->GetHighestValidatedFlushID(stream_id_)); | 546 UpdateVerifiedReleases(channel_->GetHighestValidatedFlushID(stream_id_)); |
529 if (release <= verified_fence_sync_release_) | 547 if (release <= verified_fence_sync_release_) |
530 return true; | 548 return true; |
531 | 549 |
532 // Has not been validated, validate it now. | 550 // Has not been validated, validate it now. |
533 UpdateVerifiedReleases(channel_->ValidateFlushIDReachedServer(stream_id_)); | 551 UpdateVerifiedReleases( |
552 channel_->ValidateFlushIDReachedServer(stream_id_, false)); | |
534 return release <= verified_fence_sync_release_; | 553 return release <= verified_fence_sync_release_; |
535 } | 554 } |
536 | 555 |
537 return false; | 556 return false; |
538 } | 557 } |
539 | 558 |
540 void CommandBufferProxyImpl::SignalSyncToken(const gpu::SyncToken& sync_token, | 559 void CommandBufferProxyImpl::SignalSyncToken(const gpu::SyncToken& sync_token, |
541 const base::Closure& callback) { | 560 const base::Closure& callback) { |
542 CheckLock(); | 561 CheckLock(); |
543 if (last_state_.error != gpu::error::kNoError) | 562 if (last_state_.error != gpu::error::kNoError) |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 } | 757 } |
739 } | 758 } |
740 | 759 |
741 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, | 760 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, |
742 base::TimeDelta interval) { | 761 base::TimeDelta interval) { |
743 if (!update_vsync_parameters_completion_callback_.is_null()) | 762 if (!update_vsync_parameters_completion_callback_.is_null()) |
744 update_vsync_parameters_completion_callback_.Run(timebase, interval); | 763 update_vsync_parameters_completion_callback_.Run(timebase, interval); |
745 } | 764 } |
746 | 765 |
747 } // namespace content | 766 } // namespace content |
OLD | NEW |