| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "media/video/gpu_memory_buffer_video_frame_pool.h" | 5 #include "media/video/gpu_memory_buffer_video_frame_pool.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // Get the resources needed for a frame out of the pool, or create them if | 117 // Get the resources needed for a frame out of the pool, or create them if |
| 118 // necessary. | 118 // necessary. |
| 119 // This also drops the LRU resources that can't be reuse for this frame. | 119 // This also drops the LRU resources that can't be reuse for this frame. |
| 120 FrameResources* GetOrCreateFrameResources(const gfx::Size& size, | 120 FrameResources* GetOrCreateFrameResources(const gfx::Size& size, |
| 121 VideoPixelFormat format); | 121 VideoPixelFormat format); |
| 122 | 122 |
| 123 // Callback called when a VideoFrame generated with GetFrameResources is no | 123 // Callback called when a VideoFrame generated with GetFrameResources is no |
| 124 // longer referenced. | 124 // longer referenced. |
| 125 // This could be called by any thread. | 125 // This could be called by any thread. |
| 126 void MailboxHoldersReleased(FrameResources* frame_resources, | 126 void MailboxHoldersReleased(FrameResources* frame_resources, |
| 127 uint32 sync_point); | 127 const gpu::SyncToken& sync_token); |
| 128 | 128 |
| 129 // Return frame resources to the pool. This has to be called on the thread | 129 // Return frame resources to the pool. This has to be called on the thread |
| 130 // where |media_task_runner_| is current. | 130 // where |media_task_runner_| is current. |
| 131 void ReturnFrameResources(FrameResources* frame_resources); | 131 void ReturnFrameResources(FrameResources* frame_resources); |
| 132 | 132 |
| 133 // Delete resources. This has to be called on the thread where |task_runner| | 133 // Delete resources. This has to be called on the thread where |task_runner| |
| 134 // is current. | 134 // is current. |
| 135 static void DeleteFrameResources(GpuVideoAcceleratorFactories* gpu_factories, | 135 static void DeleteFrameResources(GpuVideoAcceleratorFactories* gpu_factories, |
| 136 FrameResources* frame_resources); | 136 FrameResources* frame_resources); |
| 137 | 137 |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 VideoFrame::Rows(i, output_format_, coded_size.height()); | 547 VideoFrame::Rows(i, output_format_, coded_size.height()); |
| 548 plane_resource.image_id = gles2->CreateImageCHROMIUM( | 548 plane_resource.image_id = gles2->CreateImageCHROMIUM( |
| 549 plane_resource.gpu_memory_buffer->AsClientBuffer(), width, height, | 549 plane_resource.gpu_memory_buffer->AsClientBuffer(), width, height, |
| 550 ImageInternalFormat(output_format_, i)); | 550 ImageInternalFormat(output_format_, i)); |
| 551 } else if (plane_resource.image_id) { | 551 } else if (plane_resource.image_id) { |
| 552 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, | 552 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, |
| 553 plane_resource.image_id); | 553 plane_resource.image_id); |
| 554 } | 554 } |
| 555 if (plane_resource.image_id) | 555 if (plane_resource.image_id) |
| 556 gles2->BindTexImage2DCHROMIUM(texture_target_, plane_resource.image_id); | 556 gles2->BindTexImage2DCHROMIUM(texture_target_, plane_resource.image_id); |
| 557 mailbox_holders[i] = | 557 mailbox_holders[i] = gpu::MailboxHolder(plane_resource.mailbox, |
| 558 gpu::MailboxHolder(plane_resource.mailbox, texture_target_, 0); | 558 gpu::SyncToken(), texture_target_); |
| 559 } | 559 } |
| 560 | 560 |
| 561 // Insert a sync_point, this is needed to make sure that the textures the | 561 // Insert a sync_token, this is needed to make sure that the textures the |
| 562 // mailboxes refer to will be used only after all the previous commands posted | 562 // mailboxes refer to will be used only after all the previous commands posted |
| 563 // in the command buffer have been processed. | 563 // in the command buffer have been processed. |
| 564 unsigned sync_point = gles2->InsertSyncPointCHROMIUM(); | 564 gpu::SyncToken sync_token(gles2->InsertSyncPointCHROMIUM()); |
| 565 for (size_t i = 0; i < num_planes; i += planes_per_copy) | 565 for (size_t i = 0; i < num_planes; i += planes_per_copy) |
| 566 mailbox_holders[i].sync_point = sync_point; | 566 mailbox_holders[i].sync_token = sync_token; |
| 567 | 567 |
| 568 scoped_refptr<VideoFrame> frame; | 568 scoped_refptr<VideoFrame> frame; |
| 569 | 569 |
| 570 auto release_mailbox_callback = | 570 auto release_mailbox_callback = |
| 571 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources); | 571 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources); |
| 572 | 572 |
| 573 // Create the VideoFrame backed by native textures. | 573 // Create the VideoFrame backed by native textures. |
| 574 gfx::Size visible_size = video_frame->visible_rect().size(); | 574 gfx::Size visible_size = video_frame->visible_rect().size(); |
| 575 switch (output_format_) { | 575 switch (output_format_) { |
| 576 case PIXEL_FORMAT_I420: | 576 case PIXEL_FORMAT_I420: |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 if (plane_resource.image_id) | 685 if (plane_resource.image_id) |
| 686 gles2->DestroyImageCHROMIUM(plane_resource.image_id); | 686 gles2->DestroyImageCHROMIUM(plane_resource.image_id); |
| 687 if (plane_resource.texture_id) | 687 if (plane_resource.texture_id) |
| 688 gles2->DeleteTextures(1, &plane_resource.texture_id); | 688 gles2->DeleteTextures(1, &plane_resource.texture_id); |
| 689 } | 689 } |
| 690 } | 690 } |
| 691 | 691 |
| 692 // Called when a VideoFrame is no longer references. | 692 // Called when a VideoFrame is no longer references. |
| 693 void GpuMemoryBufferVideoFramePool::PoolImpl::MailboxHoldersReleased( | 693 void GpuMemoryBufferVideoFramePool::PoolImpl::MailboxHoldersReleased( |
| 694 FrameResources* frame_resources, | 694 FrameResources* frame_resources, |
| 695 uint32 sync_point) { | 695 const gpu::SyncToken& sync_token) { |
| 696 // Return the resource on the media thread. | 696 // Return the resource on the media thread. |
| 697 media_task_runner_->PostTask( | 697 media_task_runner_->PostTask( |
| 698 FROM_HERE, | 698 FROM_HERE, |
| 699 base::Bind(&PoolImpl::ReturnFrameResources, this, frame_resources)); | 699 base::Bind(&PoolImpl::ReturnFrameResources, this, frame_resources)); |
| 700 } | 700 } |
| 701 | 701 |
| 702 // Put back the resources in the pool. | 702 // Put back the resources in the pool. |
| 703 void GpuMemoryBufferVideoFramePool::PoolImpl::ReturnFrameResources( | 703 void GpuMemoryBufferVideoFramePool::PoolImpl::ReturnFrameResources( |
| 704 FrameResources* frame_resources) { | 704 FrameResources* frame_resources) { |
| 705 auto it = std::find(resources_pool_.begin(), resources_pool_.end(), | 705 auto it = std::find(resources_pool_.begin(), resources_pool_.end(), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 730 } | 730 } |
| 731 | 731 |
| 732 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( | 732 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( |
| 733 const scoped_refptr<VideoFrame>& video_frame, | 733 const scoped_refptr<VideoFrame>& video_frame, |
| 734 const FrameReadyCB& frame_ready_cb) { | 734 const FrameReadyCB& frame_ready_cb) { |
| 735 DCHECK(video_frame); | 735 DCHECK(video_frame); |
| 736 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); | 736 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); |
| 737 } | 737 } |
| 738 | 738 |
| 739 } // namespace media | 739 } // namespace media |
| OLD | NEW |