| 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()); |
| 463 image_gmb_ids_map_[new_id] = gpu_memory_buffer->GetId().id; |
| 464 |
| 462 // 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 |
| 463 // 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 |
| 464 // sending of the CreateImage IPC below. | 467 // sending of the CreateImage IPC below. |
| 465 bool requires_sync_token = false; | 468 bool requires_sync_token = false; |
| 466 gfx::GpuMemoryBufferHandle handle = | 469 gfx::GpuMemoryBufferHandle handle = |
| 467 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), | 470 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), |
| 468 &requires_sync_token); | 471 &requires_sync_token); |
| 469 | 472 |
| 470 uint64_t image_fence_sync = 0; | 473 uint64_t image_fence_sync = 0; |
| 471 if (requires_sync_token) { | 474 if (requires_sync_token) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 } | 508 } |
| 506 | 509 |
| 507 return new_id; | 510 return new_id; |
| 508 } | 511 } |
| 509 | 512 |
| 510 void CommandBufferProxyImpl::DestroyImage(int32_t id) { | 513 void CommandBufferProxyImpl::DestroyImage(int32_t id) { |
| 511 CheckLock(); | 514 CheckLock(); |
| 512 if (last_state_.error != gpu::error::kNoError) | 515 if (last_state_.error != gpu::error::kNoError) |
| 513 return; | 516 return; |
| 514 | 517 |
| 518 auto it = image_gmb_ids_map_.find(id); |
| 519 if (it != image_gmb_ids_map_.end()) |
| 520 image_gmb_ids_map_.erase(it); |
| 515 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); | 521 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); |
| 516 } | 522 } |
| 517 | 523 |
| 518 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( | 524 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( |
| 519 size_t width, | 525 size_t width, |
| 520 size_t height, | 526 size_t height, |
| 521 unsigned internal_format, | 527 unsigned internal_format, |
| 522 unsigned usage) { | 528 unsigned usage) { |
| 523 CheckLock(); | 529 CheckLock(); |
| 524 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( | 530 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( |
| 525 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | 531 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
| 526 gfx::Size(width, height), | 532 gfx::Size(width, height), |
| 527 gpu::DefaultBufferFormatForImageFormat(internal_format), | 533 gpu::DefaultBufferFormatForImageFormat(internal_format), |
| 528 gfx::BufferUsage::SCANOUT, gpu::kNullSurfaceHandle)); | 534 gfx::BufferUsage::SCANOUT, gpu::kNullSurfaceHandle)); |
| 529 if (!buffer) | 535 if (!buffer) |
| 530 return -1; | 536 return -1; |
| 531 | 537 |
| 532 return CreateImage(buffer->AsClientBuffer(), width, height, internal_format); | 538 return CreateImage(buffer->AsClientBuffer(), width, height, internal_format); |
| 533 } | 539 } |
| 534 | 540 |
| 541 int32_t CommandBufferProxyImpl::GetImageGpuMemoryBufferId(unsigned image_id) { |
| 542 CheckLock(); |
| 543 auto it = image_gmb_ids_map_.find(image_id); |
| 544 if (it != image_gmb_ids_map_.end()) |
| 545 return it->second; |
| 546 return -1; |
| 547 } |
| 548 |
| 535 uint32_t CommandBufferProxyImpl::CreateStreamTexture(uint32_t texture_id) { | 549 uint32_t CommandBufferProxyImpl::CreateStreamTexture(uint32_t texture_id) { |
| 536 CheckLock(); | 550 CheckLock(); |
| 537 if (last_state_.error != gpu::error::kNoError) | 551 if (last_state_.error != gpu::error::kNoError) |
| 538 return 0; | 552 return 0; |
| 539 | 553 |
| 540 int32_t stream_id = channel_->GenerateRouteID(); | 554 int32_t stream_id = channel_->GenerateRouteID(); |
| 541 bool succeeded = false; | 555 bool succeeded = false; |
| 542 Send(new GpuCommandBufferMsg_CreateStreamTexture(route_id_, texture_id, | 556 Send(new GpuCommandBufferMsg_CreateStreamTexture(route_id_, texture_id, |
| 543 stream_id, &succeeded)); | 557 stream_id, &succeeded)); |
| 544 if (!succeeded) { | 558 if (!succeeded) { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 return; | 866 return; |
| 853 channel_->FlushPendingStream(stream_id_); | 867 channel_->FlushPendingStream(stream_id_); |
| 854 channel_->Send(new GpuChannelMsg_DestroyCommandBuffer(route_id_)); | 868 channel_->Send(new GpuChannelMsg_DestroyCommandBuffer(route_id_)); |
| 855 channel_->RemoveRoute(route_id_); | 869 channel_->RemoveRoute(route_id_); |
| 856 channel_ = nullptr; | 870 channel_ = nullptr; |
| 857 if (gpu_control_client_) | 871 if (gpu_control_client_) |
| 858 gpu_control_client_->OnGpuControlLostContext(); | 872 gpu_control_client_->OnGpuControlLostContext(); |
| 859 } | 873 } |
| 860 | 874 |
| 861 } // namespace gpu | 875 } // namespace gpu |
| OLD | NEW |