| 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 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 if (!lock) { | 546 if (!lock) { |
| 547 frame_ready_cb.Run(video_frame); | 547 frame_ready_cb.Run(video_frame); |
| 548 return; | 548 return; |
| 549 } | 549 } |
| 550 gpu::gles2::GLES2Interface* gles2 = lock->ContextGL(); | 550 gpu::gles2::GLES2Interface* gles2 = lock->ContextGL(); |
| 551 | 551 |
| 552 const size_t num_planes = VideoFrame::NumPlanes(output_format_); | 552 const size_t num_planes = VideoFrame::NumPlanes(output_format_); |
| 553 const size_t planes_per_copy = PlanesPerCopy(output_format_); | 553 const size_t planes_per_copy = PlanesPerCopy(output_format_); |
| 554 const gfx::Size coded_size = CodedSize(video_frame, output_format_); | 554 const gfx::Size coded_size = CodedSize(video_frame, output_format_); |
| 555 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; | 555 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; |
| 556 gfx::GpuMemoryBufferId gpu_memory_buffer_ids[VideoFrame::kMaxPlanes]; |
| 556 // Set up the planes creating the mailboxes needed to refer to the textures. | 557 // Set up the planes creating the mailboxes needed to refer to the textures. |
| 557 for (size_t i = 0; i < num_planes; i += planes_per_copy) { | 558 for (size_t i = 0; i < num_planes; i += planes_per_copy) { |
| 558 PlaneResource& plane_resource = frame_resources->plane_resources[i]; | 559 PlaneResource& plane_resource = frame_resources->plane_resources[i]; |
| 559 const gfx::BufferFormat buffer_format = | 560 const gfx::BufferFormat buffer_format = |
| 560 GpuMemoryBufferFormat(output_format_, i); | 561 GpuMemoryBufferFormat(output_format_, i); |
| 561 unsigned texture_target = gpu_factories_->ImageTextureTarget(buffer_format); | 562 unsigned texture_target = gpu_factories_->ImageTextureTarget(buffer_format); |
| 562 // Bind the texture and create or rebind the image. | 563 // Bind the texture and create or rebind the image. |
| 563 gles2->BindTexture(texture_target, plane_resource.texture_id); | 564 gles2->BindTexture(texture_target, plane_resource.texture_id); |
| 564 | 565 |
| 565 if (plane_resource.gpu_memory_buffer && !plane_resource.image_id) { | 566 if (plane_resource.gpu_memory_buffer && !plane_resource.image_id) { |
| 566 const size_t width = | 567 const size_t width = |
| 567 VideoFrame::Columns(i, output_format_, coded_size.width()); | 568 VideoFrame::Columns(i, output_format_, coded_size.width()); |
| 568 const size_t height = | 569 const size_t height = |
| 569 VideoFrame::Rows(i, output_format_, coded_size.height()); | 570 VideoFrame::Rows(i, output_format_, coded_size.height()); |
| 570 plane_resource.image_id = gles2->CreateImageCHROMIUM( | 571 plane_resource.image_id = gles2->CreateImageCHROMIUM( |
| 571 plane_resource.gpu_memory_buffer->AsClientBuffer(), width, height, | 572 plane_resource.gpu_memory_buffer->AsClientBuffer(), width, height, |
| 572 ImageInternalFormat(output_format_, i)); | 573 ImageInternalFormat(output_format_, i)); |
| 573 } else if (plane_resource.image_id) { | 574 } else if (plane_resource.image_id) { |
| 574 gles2->ReleaseTexImage2DCHROMIUM(texture_target, plane_resource.image_id); | 575 gles2->ReleaseTexImage2DCHROMIUM(texture_target, plane_resource.image_id); |
| 575 } | 576 } |
| 577 if (plane_resource.gpu_memory_buffer) |
| 578 gpu_memory_buffer_ids[i] = plane_resource.gpu_memory_buffer->GetId(); |
| 576 if (plane_resource.image_id) | 579 if (plane_resource.image_id) |
| 577 gles2->BindTexImage2DCHROMIUM(texture_target, plane_resource.image_id); | 580 gles2->BindTexImage2DCHROMIUM(texture_target, plane_resource.image_id); |
| 578 mailbox_holders[i] = gpu::MailboxHolder(plane_resource.mailbox, | 581 mailbox_holders[i] = gpu::MailboxHolder(plane_resource.mailbox, |
| 579 gpu::SyncToken(), texture_target); | 582 gpu::SyncToken(), texture_target); |
| 580 } | 583 } |
| 581 | 584 |
| 582 // Insert a sync_token, this is needed to make sure that the textures the | 585 // Insert a sync_token, this is needed to make sure that the textures the |
| 583 // mailboxes refer to will be used only after all the previous commands posted | 586 // mailboxes refer to will be used only after all the previous commands posted |
| 584 // in the command buffer have been processed. | 587 // in the command buffer have been processed. |
| 585 const GLuint64 fence_sync = gles2->InsertFenceSyncCHROMIUM(); | 588 const GLuint64 fence_sync = gles2->InsertFenceSyncCHROMIUM(); |
| 586 gles2->OrderingBarrierCHROMIUM(); | 589 gles2->OrderingBarrierCHROMIUM(); |
| 587 | 590 |
| 588 gpu::SyncToken sync_token; | 591 gpu::SyncToken sync_token; |
| 589 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 592 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 590 for (size_t i = 0; i < num_planes; i += planes_per_copy) | 593 for (size_t i = 0; i < num_planes; i += planes_per_copy) |
| 591 mailbox_holders[i].sync_token = sync_token; | 594 mailbox_holders[i].sync_token = sync_token; |
| 592 | 595 |
| 593 | 596 |
| 594 auto release_mailbox_callback = BindToCurrentLoop( | 597 auto release_mailbox_callback = BindToCurrentLoop( |
| 595 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources)); | 598 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources)); |
| 596 | 599 |
| 597 // Create the VideoFrame backed by native textures. | 600 // Create the VideoFrame backed by native textures. |
| 598 gfx::Size visible_size = video_frame->visible_rect().size(); | 601 gfx::Size visible_size = video_frame->visible_rect().size(); |
| 599 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTextures( | 602 scoped_refptr<VideoFrame> frame = |
| 600 output_format_, mailbox_holders, release_mailbox_callback, coded_size, | 603 VideoFrame::WrapGpuMemoryBufferBackedNativeTextures( |
| 601 gfx::Rect(visible_size), video_frame->natural_size(), | 604 output_format_, mailbox_holders, gpu_memory_buffer_ids, |
| 602 video_frame->timestamp()); | 605 release_mailbox_callback, coded_size, gfx::Rect(visible_size), |
| 606 video_frame->natural_size(), video_frame->timestamp()); |
| 603 | 607 |
| 604 if (!frame) { | 608 if (!frame) { |
| 605 release_mailbox_callback.Run(gpu::SyncToken()); | 609 release_mailbox_callback.Run(gpu::SyncToken()); |
| 606 frame_ready_cb.Run(video_frame); | 610 frame_ready_cb.Run(video_frame); |
| 607 return; | 611 return; |
| 608 } | 612 } |
| 609 | 613 |
| 610 bool allow_overlay = false; | 614 bool allow_overlay = false; |
| 611 switch (output_format_) { | 615 switch (output_format_) { |
| 612 case PIXEL_FORMAT_I420: | 616 case PIXEL_FORMAT_I420: |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 } | 767 } |
| 764 | 768 |
| 765 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( | 769 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( |
| 766 const scoped_refptr<VideoFrame>& video_frame, | 770 const scoped_refptr<VideoFrame>& video_frame, |
| 767 const FrameReadyCB& frame_ready_cb) { | 771 const FrameReadyCB& frame_ready_cb) { |
| 768 DCHECK(video_frame); | 772 DCHECK(video_frame); |
| 769 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); | 773 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); |
| 770 } | 774 } |
| 771 | 775 |
| 772 } // namespace media | 776 } // namespace media |
| OLD | NEW |