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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 if (plane_resource.image_id) | 693 if (plane_resource.image_id) |
694 gles2->DestroyImageCHROMIUM(plane_resource.image_id); | 694 gles2->DestroyImageCHROMIUM(plane_resource.image_id); |
695 if (plane_resource.texture_id) | 695 if (plane_resource.texture_id) |
696 gles2->DeleteTextures(1, &plane_resource.texture_id); | 696 gles2->DeleteTextures(1, &plane_resource.texture_id); |
697 } | 697 } |
698 } | 698 } |
699 | 699 |
700 // Called when a VideoFrame is no longer references. | 700 // Called when a VideoFrame is no longer references. |
701 void GpuMemoryBufferVideoFramePool::PoolImpl::MailboxHoldersReleased( | 701 void GpuMemoryBufferVideoFramePool::PoolImpl::MailboxHoldersReleased( |
702 FrameResources* frame_resources, | 702 FrameResources* frame_resources, |
703 uint32 sync_point) { | 703 const gpu::SyncToken& sync_token) { |
704 // Return the resource on the media thread. | 704 // Return the resource on the media thread. |
705 media_task_runner_->PostTask( | 705 media_task_runner_->PostTask( |
706 FROM_HERE, | 706 FROM_HERE, |
707 base::Bind(&PoolImpl::ReturnFrameResources, this, frame_resources)); | 707 base::Bind(&PoolImpl::ReturnFrameResources, this, frame_resources)); |
708 } | 708 } |
709 | 709 |
710 // Put back the resources in the pool. | 710 // Put back the resources in the pool. |
711 void GpuMemoryBufferVideoFramePool::PoolImpl::ReturnFrameResources( | 711 void GpuMemoryBufferVideoFramePool::PoolImpl::ReturnFrameResources( |
712 FrameResources* frame_resources) { | 712 FrameResources* frame_resources) { |
713 auto it = std::find(resources_pool_.begin(), resources_pool_.end(), | 713 auto it = std::find(resources_pool_.begin(), resources_pool_.end(), |
(...skipping 24 matching lines...) Expand all Loading... |
738 } | 738 } |
739 | 739 |
740 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( | 740 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( |
741 const scoped_refptr<VideoFrame>& video_frame, | 741 const scoped_refptr<VideoFrame>& video_frame, |
742 const FrameReadyCB& frame_ready_cb) { | 742 const FrameReadyCB& frame_ready_cb) { |
743 DCHECK(video_frame); | 743 DCHECK(video_frame); |
744 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); | 744 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); |
745 } | 745 } |
746 | 746 |
747 } // namespace media | 747 } // namespace media |
OLD | NEW |