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 "gpu/ipc/client/command_buffer_proxy_impl.h" | 5 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 return -1; | 448 return -1; |
449 | 449 |
450 int32_t new_id = channel_->ReserveImageId(); | 450 int32_t new_id = channel_->ReserveImageId(); |
451 | 451 |
452 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = | 452 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = |
453 channel_->gpu_memory_buffer_manager(); | 453 channel_->gpu_memory_buffer_manager(); |
454 gfx::GpuMemoryBuffer* gpu_memory_buffer = | 454 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
455 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffer); | 455 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffer); |
456 DCHECK(gpu_memory_buffer); | 456 DCHECK(gpu_memory_buffer); |
457 | 457 |
458 DCHECK(image_gmb_map_.find(new_id) == image_gmb_map_.end()); | |
459 image_gmb_map_[new_id].gpu_memory_buffer_id = gpu_memory_buffer->GetId().id; | |
460 | |
461 // This handle is owned by the GPU process and must be passed to it or it | 458 // This handle is owned by the GPU process and must be passed to it or it |
462 // will leak. In otherwords, do not early out on error between here and the | 459 // will leak. In otherwords, do not early out on error between here and the |
463 // sending of the CreateImage IPC below. | 460 // sending of the CreateImage IPC below. |
464 bool requires_sync_token = false; | 461 bool requires_sync_token = false; |
465 gfx::GpuMemoryBufferHandle handle = | 462 gfx::GpuMemoryBufferHandle handle = |
466 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), | 463 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), |
467 &requires_sync_token); | 464 &requires_sync_token); |
468 | 465 |
469 uint64_t image_fence_sync = 0; | 466 uint64_t image_fence_sync = 0; |
470 if (requires_sync_token) { | 467 if (requires_sync_token) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 } | 501 } |
505 | 502 |
506 return new_id; | 503 return new_id; |
507 } | 504 } |
508 | 505 |
509 void CommandBufferProxyImpl::DestroyImage(int32_t id) { | 506 void CommandBufferProxyImpl::DestroyImage(int32_t id) { |
510 CheckLock(); | 507 CheckLock(); |
511 if (last_state_.error != gpu::error::kNoError) | 508 if (last_state_.error != gpu::error::kNoError) |
512 return; | 509 return; |
513 | 510 |
514 auto it = image_gmb_map_.find(id); | |
515 if (it != image_gmb_map_.end()) | |
516 image_gmb_map_.erase(it); | |
517 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); | 511 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); |
518 } | 512 } |
519 | 513 |
520 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( | 514 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( |
521 size_t width, | 515 size_t width, |
522 size_t height, | 516 size_t height, |
523 unsigned internal_format, | 517 unsigned internal_format, |
524 unsigned usage) { | 518 unsigned usage) { |
525 CheckLock(); | 519 CheckLock(); |
526 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( | 520 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( |
527 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | 521 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
528 gfx::Size(width, height), | 522 gfx::Size(width, height), |
529 gpu::DefaultBufferFormatForImageFormat(internal_format), | 523 gpu::DefaultBufferFormatForImageFormat(internal_format), |
530 gfx::BufferUsage::SCANOUT, gpu::kNullSurfaceHandle)); | 524 gfx::BufferUsage::SCANOUT, gpu::kNullSurfaceHandle)); |
531 if (!buffer) | 525 if (!buffer) |
532 return -1; | 526 return -1; |
533 | 527 |
534 int32_t result = | 528 int32_t result = |
535 CreateImage(buffer->AsClientBuffer(), width, height, internal_format); | 529 CreateImage(buffer->AsClientBuffer(), width, height, internal_format); |
536 if (result != -1) | |
537 image_gmb_map_[result].owned_gpu_memory_buffer = std::move(buffer); | |
538 return result; | 530 return result; |
539 } | 531 } |
540 | 532 |
541 int32_t CommandBufferProxyImpl::GetImageGpuMemoryBufferId(unsigned image_id) { | |
542 CheckLock(); | |
543 auto it = image_gmb_map_.find(image_id); | |
544 if (it != image_gmb_map_.end()) | |
545 return it->second.gpu_memory_buffer_id; | |
546 return -1; | |
547 } | |
548 | |
549 uint32_t CommandBufferProxyImpl::CreateStreamTexture(uint32_t texture_id) { | 533 uint32_t CommandBufferProxyImpl::CreateStreamTexture(uint32_t texture_id) { |
550 CheckLock(); | 534 CheckLock(); |
551 if (last_state_.error != gpu::error::kNoError) | 535 if (last_state_.error != gpu::error::kNoError) |
552 return 0; | 536 return 0; |
553 | 537 |
554 int32_t stream_id = channel_->GenerateRouteID(); | 538 int32_t stream_id = channel_->GenerateRouteID(); |
555 bool succeeded = false; | 539 bool succeeded = false; |
556 Send(new GpuCommandBufferMsg_CreateStreamTexture(route_id_, texture_id, | 540 Send(new GpuCommandBufferMsg_CreateStreamTexture(route_id_, texture_id, |
557 stream_id, &succeeded)); | 541 stream_id, &succeeded)); |
558 if (!succeeded) { | 542 if (!succeeded) { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 if (!channel_) | 850 if (!channel_) |
867 return; | 851 return; |
868 channel_->FlushPendingStream(stream_id_); | 852 channel_->FlushPendingStream(stream_id_); |
869 channel_->Send(new GpuChannelMsg_DestroyCommandBuffer(route_id_)); | 853 channel_->Send(new GpuChannelMsg_DestroyCommandBuffer(route_id_)); |
870 channel_->RemoveRoute(route_id_); | 854 channel_->RemoveRoute(route_id_); |
871 channel_ = nullptr; | 855 channel_ = nullptr; |
872 if (gpu_control_client_) | 856 if (gpu_control_client_) |
873 gpu_control_client_->OnGpuControlLostContext(); | 857 gpu_control_client_->OnGpuControlLostContext(); |
874 } | 858 } |
875 | 859 |
876 CommandBufferProxyImpl::ImageInfo::ImageInfo() {} | |
877 CommandBufferProxyImpl::ImageInfo::~ImageInfo() {} | |
878 CommandBufferProxyImpl::ImageInfo::ImageInfo(ImageInfo&& other) = default; | |
879 CommandBufferProxyImpl::ImageInfo& CommandBufferProxyImpl::ImageInfo::operator=( | |
880 ImageInfo&& other) = default; | |
881 | |
882 } // namespace gpu | 860 } // namespace gpu |
OLD | NEW |