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