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 "media/renderers/skcanvas_video_renderer.h" | 5 #include "media/renderers/skcanvas_video_renderer.h" |
6 | 6 |
7 #include <GLES3/gl3.h> | 7 #include <GLES3/gl3.h> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 | 177 |
178 gpu::gles2::GLES2Interface* gl = context_3d.gl; | 178 gpu::gles2::GLES2Interface* gl = context_3d.gl; |
179 unsigned source_texture = 0; | 179 unsigned source_texture = 0; |
180 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { | 180 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { |
181 // TODO(dcastagna): At the moment Skia doesn't support targets different | 181 // TODO(dcastagna): At the moment Skia doesn't support targets different |
182 // than GL_TEXTURE_2D. Avoid this copy once | 182 // than GL_TEXTURE_2D. Avoid this copy once |
183 // https://code.google.com/p/skia/issues/detail?id=3868 is addressed. | 183 // https://code.google.com/p/skia/issues/detail?id=3868 is addressed. |
184 gl->GenTextures(1, &source_texture); | 184 gl->GenTextures(1, &source_texture); |
185 DCHECK(source_texture); | 185 DCHECK(source_texture); |
186 gl->BindTexture(GL_TEXTURE_2D, source_texture); | 186 gl->BindTexture(GL_TEXTURE_2D, source_texture); |
187 const gfx::Size& natural_size = video_frame->natural_size(); | |
188 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, natural_size.width(), | |
189 natural_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
190 nullptr); | |
187 SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( | 191 SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( |
188 gl, video_frame, source_texture, GL_RGBA, GL_UNSIGNED_BYTE, true, | 192 gl, video_frame, source_texture, true, false); |
189 false); | |
190 } else { | 193 } else { |
191 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); | 194 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); |
192 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 195 source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
193 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 196 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
194 } | 197 } |
195 GrBackendTextureDesc desc; | 198 GrBackendTextureDesc desc; |
196 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 199 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
197 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 200 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
198 desc.fWidth = video_frame->coded_size().width(); | 201 desc.fWidth = video_frame->coded_size().width(); |
199 desc.fHeight = video_frame->coded_size().height(); | 202 desc.fHeight = video_frame->coded_size().height(); |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 case PIXEL_FORMAT_UNKNOWN: | 746 case PIXEL_FORMAT_UNKNOWN: |
744 NOTREACHED() << "Only YUV formats and Y16 are supported."; | 747 NOTREACHED() << "Only YUV formats and Y16 are supported."; |
745 } | 748 } |
746 } | 749 } |
747 | 750 |
748 // static | 751 // static |
749 void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( | 752 void SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( |
750 gpu::gles2::GLES2Interface* gl, | 753 gpu::gles2::GLES2Interface* gl, |
751 VideoFrame* video_frame, | 754 VideoFrame* video_frame, |
752 unsigned int texture, | 755 unsigned int texture, |
753 unsigned int internal_format, | |
754 unsigned int type, | |
755 bool premultiply_alpha, | 756 bool premultiply_alpha, |
756 bool flip_y) { | 757 bool flip_y) { |
757 DCHECK(video_frame); | 758 DCHECK(video_frame); |
758 DCHECK(video_frame->HasTextures()); | 759 DCHECK(video_frame->HasTextures()); |
759 | 760 |
760 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 761 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
761 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || | 762 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || |
762 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || | 763 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || |
763 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) | 764 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) |
764 << mailbox_holder.texture_target; | 765 << mailbox_holder.texture_target; |
765 | 766 |
766 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); | 767 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); |
767 uint32_t source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 768 uint32_t source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
768 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 769 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
769 | 770 |
770 // The video is stored in a unmultiplied format, so premultiply | 771 // The video is stored in a unmultiplied format, so premultiply |
771 // if necessary. | 772 // if necessary. |
772 // Application itself needs to take care of setting the right |flip_y| | 773 // Application itself needs to take care of setting the right |flip_y| |
773 // value down to get the expected result. | 774 // value down to get the expected result. |
774 // "flip_y == true" means to reverse the video orientation while | 775 // "flip_y == true" means to reverse the video orientation while |
775 // "flip_y == false" means to keep the intrinsic orientation. | 776 // "flip_y == false" means to keep the intrinsic orientation. |
776 gl->CopyTextureCHROMIUM(source_texture, texture, internal_format, type, | 777 |
777 flip_y, premultiply_alpha, false); | 778 // The video's texture might be larger than the natural size because |
779 // the encoder might have had to round up to the size of a macroblock. | |
780 // Make sure to only copy the natural size to avoid putting garbage | |
781 // into the bottom of the destination texture. | |
782 const gfx::Size& natural_size = video_frame->natural_size(); | |
783 gl->CopySubTextureCHROMIUM(source_texture, texture, 0, 0, 0, 0, | |
784 natural_size.width(), natural_size.height(), | |
785 flip_y, premultiply_alpha, false); | |
778 gl->DeleteTextures(1, &source_texture); | 786 gl->DeleteTextures(1, &source_texture); |
779 gl->Flush(); | 787 gl->Flush(); |
780 | 788 |
781 SyncTokenClientImpl client(gl); | 789 SyncTokenClientImpl client(gl); |
782 video_frame->UpdateReleaseSyncToken(&client); | 790 video_frame->UpdateReleaseSyncToken(&client); |
783 } | 791 } |
784 | 792 |
785 bool SkCanvasVideoRenderer::CopyVideoFrameTexturesToGLTexture( | 793 bool SkCanvasVideoRenderer::CopyVideoFrameTexturesToGLTexture( |
786 const Context3D& context_3d, | 794 const Context3D& context_3d, |
787 gpu::gles2::GLES2Interface* destination_gl, | 795 gpu::gles2::GLES2Interface* destination_gl, |
788 const scoped_refptr<VideoFrame>& video_frame, | 796 const scoped_refptr<VideoFrame>& video_frame, |
789 unsigned int texture, | 797 unsigned int texture, |
790 unsigned int internal_format, | |
791 unsigned int type, | |
792 bool premultiply_alpha, | 798 bool premultiply_alpha, |
793 bool flip_y) { | 799 bool flip_y) { |
794 DCHECK(thread_checker_.CalledOnValidThread()); | 800 DCHECK(thread_checker_.CalledOnValidThread()); |
795 DCHECK(video_frame); | 801 DCHECK(video_frame); |
796 DCHECK(video_frame->HasTextures()); | 802 DCHECK(video_frame->HasTextures()); |
797 if (media::VideoFrame::NumPlanes(video_frame->format()) > 1) { | 803 if (media::VideoFrame::NumPlanes(video_frame->format()) > 1) { |
798 if (!context_3d.gr_context) | 804 if (!context_3d.gr_context) |
799 return false; | 805 return false; |
800 if (!UpdateLastImage(video_frame, context_3d)) | 806 if (!UpdateLastImage(video_frame, context_3d)) |
801 return false; | 807 return false; |
(...skipping 16 matching lines...) Expand all Loading... | |
818 canvas_gl->ShallowFlushCHROMIUM(); | 824 canvas_gl->ShallowFlushCHROMIUM(); |
819 canvas_gl->GenSyncTokenCHROMIUM(fence_sync, | 825 canvas_gl->GenSyncTokenCHROMIUM(fence_sync, |
820 mailbox_holder.sync_token.GetData()); | 826 mailbox_holder.sync_token.GetData()); |
821 | 827 |
822 destination_gl->WaitSyncTokenCHROMIUM( | 828 destination_gl->WaitSyncTokenCHROMIUM( |
823 mailbox_holder.sync_token.GetConstData()); | 829 mailbox_holder.sync_token.GetConstData()); |
824 uint32_t intermediate_texture = | 830 uint32_t intermediate_texture = |
825 destination_gl->CreateAndConsumeTextureCHROMIUM( | 831 destination_gl->CreateAndConsumeTextureCHROMIUM( |
826 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 832 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
827 | 833 |
828 destination_gl->CopyTextureCHROMIUM(intermediate_texture, texture, | 834 // The video's texture might be larger than the natural size because |
829 internal_format, type, flip_y, | 835 // the encoder might have had to round up to the size of a macroblock. |
830 premultiply_alpha, false); | 836 // Make sure to only copy the natural size to avoid putting garbage |
837 // into the bottom of the destination texture. | |
838 gfx::Size natural_size = video_frame->natural_size(); | |
DaleCurtis
2016/12/12 19:12:23
const& for consistency?
Ken Russell (switch to Gerrit)
2016/12/20 04:45:33
Yes, thanks. Done.
| |
839 destination_gl->CopySubTextureCHROMIUM( | |
840 intermediate_texture, texture, 0, 0, 0, 0, natural_size.width(), | |
841 natural_size.height(), flip_y, premultiply_alpha, false); | |
831 destination_gl->DeleteTextures(1, &intermediate_texture); | 842 destination_gl->DeleteTextures(1, &intermediate_texture); |
832 | 843 |
833 // Wait for destination context to consume mailbox before deleting it in | 844 // Wait for destination context to consume mailbox before deleting it in |
834 // canvas context. | 845 // canvas context. |
835 const GLuint64 dest_fence_sync = destination_gl->InsertFenceSyncCHROMIUM(); | 846 const GLuint64 dest_fence_sync = destination_gl->InsertFenceSyncCHROMIUM(); |
836 destination_gl->ShallowFlushCHROMIUM(); | 847 destination_gl->ShallowFlushCHROMIUM(); |
837 gpu::SyncToken dest_sync_token; | 848 gpu::SyncToken dest_sync_token; |
838 destination_gl->GenSyncTokenCHROMIUM(dest_fence_sync, | 849 destination_gl->GenSyncTokenCHROMIUM(dest_fence_sync, |
839 dest_sync_token.GetData()); | 850 dest_sync_token.GetData()); |
840 canvas_gl->WaitSyncTokenCHROMIUM(dest_sync_token.GetConstData()); | 851 canvas_gl->WaitSyncTokenCHROMIUM(dest_sync_token.GetConstData()); |
841 | 852 |
842 SyncTokenClientImpl client(canvas_gl); | 853 SyncTokenClientImpl client(canvas_gl); |
843 video_frame->UpdateReleaseSyncToken(&client); | 854 video_frame->UpdateReleaseSyncToken(&client); |
844 } else { | 855 } else { |
845 CopyVideoFrameSingleTextureToGLTexture(destination_gl, video_frame.get(), | 856 CopyVideoFrameSingleTextureToGLTexture(destination_gl, video_frame.get(), |
846 texture, internal_format, type, | 857 texture, premultiply_alpha, flip_y); |
847 premultiply_alpha, flip_y); | |
848 } | 858 } |
849 | 859 |
850 return true; | 860 return true; |
851 } | 861 } |
852 | 862 |
853 bool SkCanvasVideoRenderer::TexImage2D(unsigned target, | 863 bool SkCanvasVideoRenderer::TexImage2D(unsigned target, |
854 gpu::gles2::GLES2Interface* gl, | 864 gpu::gles2::GLES2Interface* gl, |
855 VideoFrame* frame, | 865 VideoFrame* frame, |
856 int level, | 866 int level, |
857 int internalformat, | 867 int internalformat, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 last_image_->bounds().contains(visible_rect)) { | 955 last_image_->bounds().contains(visible_rect)) { |
946 last_image_ = last_image_->makeSubset(visible_rect); | 956 last_image_ = last_image_->makeSubset(visible_rect); |
947 } | 957 } |
948 } | 958 } |
949 | 959 |
950 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() { | 960 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() { |
951 return last_image_dimensions_for_testing_; | 961 return last_image_dimensions_for_testing_; |
952 } | 962 } |
953 | 963 |
954 } // namespace media | 964 } // namespace media |
OLD | NEW |