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 "content/common/gpu/client/gl_helper.h" | 5 #include "content/common/gpu/client/gl_helper.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Reads back bytes from the currently bound frame buffer. | 147 // Reads back bytes from the currently bound frame buffer. |
148 // Note that dst_size is specified in bytes, not pixels. | 148 // Note that dst_size is specified in bytes, not pixels. |
149 void ReadbackAsync( | 149 void ReadbackAsync( |
150 const gfx::Size& dst_size, | 150 const gfx::Size& dst_size, |
151 int32 bytes_per_row, // generally dst_size.width() * 4 | 151 int32 bytes_per_row, // generally dst_size.width() * 4 |
152 int32 row_stride_bytes, // generally dst_size.width() * 4 | 152 int32 row_stride_bytes, // generally dst_size.width() * 4 |
153 unsigned char* out, | 153 unsigned char* out, |
154 const base::Callback<void(bool)>& callback); | 154 const base::Callback<void(bool)>& callback); |
155 | 155 |
156 void ReadbackPlane(TextureFrameBufferPair* source, | 156 void ReadbackPlane(TextureFrameBufferPair* source, |
157 const scoped_refptr<media::VideoFrame>& target, | 157 media::VideoFrame* target, |
158 int plane, | 158 int plane, |
159 int size_shift, | 159 int size_shift, |
160 const gfx::Rect& dst_subrect, | 160 const gfx::Rect& dst_subrect, |
161 const base::Callback<void(bool)>& callback); | 161 const base::Callback<void(bool)>& callback); |
162 | 162 |
163 WebKit::WebGLId CopyAndScaleTexture(WebGLId texture, | 163 WebKit::WebGLId CopyAndScaleTexture(WebGLId texture, |
164 const gfx::Size& src_size, | 164 const gfx::Size& src_size, |
165 const gfx::Size& dst_size, | 165 const gfx::Size& dst_size, |
166 bool vertically_flip_texture, | 166 bool vertically_flip_texture, |
167 GLHelper::ScalerQuality quality); | 167 GLHelper::ScalerQuality quality); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 GLHelper::ScalerQuality quality, | 225 GLHelper::ScalerQuality quality, |
226 const gfx::Size& src_size, | 226 const gfx::Size& src_size, |
227 const gfx::Rect& src_subrect, | 227 const gfx::Rect& src_subrect, |
228 const gfx::Size& dst_size, | 228 const gfx::Size& dst_size, |
229 const gfx::Rect& dst_subrect, | 229 const gfx::Rect& dst_subrect, |
230 bool flip_vertically); | 230 bool flip_vertically); |
231 | 231 |
232 virtual void ReadbackYUV( | 232 virtual void ReadbackYUV( |
233 const gpu::Mailbox& mailbox, | 233 const gpu::Mailbox& mailbox, |
234 uint32 sync_point, | 234 uint32 sync_point, |
235 const scoped_refptr<media::VideoFrame>& target, | 235 media::VideoFrame* target, |
236 const base::Callback<void(bool)>& callback) OVERRIDE; | 236 const base::Callback<void(bool)>& callback) OVERRIDE; |
237 | 237 |
238 virtual ScalerInterface* scaler() OVERRIDE { | 238 virtual ScalerInterface* scaler() OVERRIDE { |
239 return scaler_.scaler(); | 239 return scaler_.scaler(); |
240 } | 240 } |
241 | 241 |
242 private: | 242 private: |
243 WebGraphicsContext3D* context_; | 243 WebGraphicsContext3D* context_; |
244 CopyTextureToImpl* copy_impl_; | 244 CopyTextureToImpl* copy_impl_; |
245 gfx::Size dst_size_; | 245 gfx::Size dst_size_; |
(...skipping 17 matching lines...) Expand all Loading... |
263 GLHelper::ScalerQuality quality, | 263 GLHelper::ScalerQuality quality, |
264 const gfx::Size& src_size, | 264 const gfx::Size& src_size, |
265 const gfx::Rect& src_subrect, | 265 const gfx::Rect& src_subrect, |
266 const gfx::Size& dst_size, | 266 const gfx::Size& dst_size, |
267 const gfx::Rect& dst_subrect, | 267 const gfx::Rect& dst_subrect, |
268 bool flip_vertically); | 268 bool flip_vertically); |
269 | 269 |
270 virtual void ReadbackYUV( | 270 virtual void ReadbackYUV( |
271 const gpu::Mailbox& mailbox, | 271 const gpu::Mailbox& mailbox, |
272 uint32 sync_point, | 272 uint32 sync_point, |
273 const scoped_refptr<media::VideoFrame>& target, | 273 media::VideoFrame* target, |
274 const base::Callback<void(bool)>& callback) OVERRIDE; | 274 const base::Callback<void(bool)>& callback) OVERRIDE; |
275 | 275 |
276 virtual ScalerInterface* scaler() OVERRIDE { | 276 virtual ScalerInterface* scaler() OVERRIDE { |
277 return scaler_.scaler(); | 277 return scaler_.scaler(); |
278 } | 278 } |
279 | 279 |
280 private: | 280 private: |
281 WebGraphicsContext3D* context_; | 281 WebGraphicsContext3D* context_; |
282 CopyTextureToImpl* copy_impl_; | 282 CopyTextureToImpl* copy_impl_; |
283 gfx::Size dst_size_; | 283 gfx::Size dst_size_; |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 const gfx::Size& size) { | 722 const gfx::Size& size) { |
723 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); | 723 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); |
724 context_->copyTexImage2D(GL_TEXTURE_2D, 0, | 724 context_->copyTexImage2D(GL_TEXTURE_2D, 0, |
725 GL_RGB, | 725 GL_RGB, |
726 0, 0, | 726 0, 0, |
727 size.width(), size.height(), 0); | 727 size.width(), size.height(), 0); |
728 } | 728 } |
729 | 729 |
730 void GLHelper::CopyTextureToImpl::ReadbackPlane( | 730 void GLHelper::CopyTextureToImpl::ReadbackPlane( |
731 TextureFrameBufferPair* source, | 731 TextureFrameBufferPair* source, |
732 const scoped_refptr<media::VideoFrame>& target, | 732 media::VideoFrame* target, |
733 int plane, | 733 int plane, |
734 int size_shift, | 734 int size_shift, |
735 const gfx::Rect& dst_subrect, | 735 const gfx::Rect& dst_subrect, |
736 const base::Callback<void(bool)>& callback) { | 736 const base::Callback<void(bool)>& callback) { |
737 context_->bindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); | 737 context_->bindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); |
738 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + | 738 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + |
739 (dst_subrect.x() >> size_shift); | 739 (dst_subrect.x() >> size_shift); |
740 ReadbackAsync( | 740 ReadbackAsync( |
741 source->size(), | 741 source->size(), |
742 dst_subrect.width() >> size_shift, | 742 dst_subrect.width() >> size_shift, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 false, | 806 false, |
807 kRGBtoVColorWeights)) { | 807 kRGBtoVColorWeights)) { |
808 DCHECK(!(dst_size.width() & 1)); | 808 DCHECK(!(dst_size.width() & 1)); |
809 DCHECK(!(dst_size.height() & 1)); | 809 DCHECK(!(dst_size.height() & 1)); |
810 DCHECK(!(dst_subrect.width() & 1)); | 810 DCHECK(!(dst_subrect.width() & 1)); |
811 DCHECK(!(dst_subrect.height() & 1)); | 811 DCHECK(!(dst_subrect.height() & 1)); |
812 DCHECK(!(dst_subrect.x() & 1)); | 812 DCHECK(!(dst_subrect.x() & 1)); |
813 DCHECK(!(dst_subrect.y() & 1)); | 813 DCHECK(!(dst_subrect.y() & 1)); |
814 } | 814 } |
815 | 815 |
816 static void CallbackKeepingVideoFrameAlive( | |
817 scoped_refptr<media::VideoFrame> video_frame, | |
818 const base::Callback<void(bool)>& callback, | |
819 bool success) { | |
820 callback.Run(success); | |
821 } | |
822 | 816 |
823 void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( | 817 void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( |
824 const gpu::Mailbox& mailbox, | 818 const gpu::Mailbox& mailbox, |
825 uint32 sync_point, | 819 uint32 sync_point, |
826 const scoped_refptr<media::VideoFrame>& target, | 820 media::VideoFrame *target, |
827 const base::Callback<void(bool)>& callback) { | 821 const base::Callback<void(bool)>& callback) { |
828 WebGLId mailbox_texture = | 822 WebGLId mailbox_texture = |
829 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); | 823 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); |
830 | 824 |
831 // Scale texture to right size. | 825 // Scale texture to right size. |
832 scaler_.Scale(mailbox_texture); | 826 scaler_.Scale(mailbox_texture); |
833 context_->deleteTexture(mailbox_texture); | 827 context_->deleteTexture(mailbox_texture); |
834 | 828 |
835 // Convert the scaled texture in to Y, U and V planes. | 829 // Convert the scaled texture in to Y, U and V planes. |
836 y_.Scale(scaler_.texture()); | 830 y_.Scale(scaler_.texture()); |
837 u_.Scale(scaler_.texture()); | 831 u_.Scale(scaler_.texture()); |
838 v_.Scale(scaler_.texture()); | 832 v_.Scale(scaler_.texture()); |
839 | 833 |
840 if (target->coded_size() != dst_size_) { | 834 if (target->coded_size() != dst_size_) { |
841 DCHECK(target->coded_size() == dst_size_); | 835 DCHECK(target->coded_size() == dst_size_); |
842 LOG(ERROR) << "ReadbackYUV size error!"; | 836 LOG(ERROR) << "ReadbackYUV size error!"; |
843 callback.Run(false); | 837 callback.Run(false); |
844 return; | 838 return; |
845 } | 839 } |
846 | 840 |
847 // Read back planes, one at a time. Keep the video frame alive while doing the | 841 // Read back planes, one at a time. |
848 // readback. | |
849 copy_impl_->ReadbackPlane(y_.texture_and_framebuffer(), | 842 copy_impl_->ReadbackPlane(y_.texture_and_framebuffer(), |
850 target, | 843 target, |
851 media::VideoFrame::kYPlane, | 844 media::VideoFrame::kYPlane, |
852 0, | 845 0, |
853 dst_subrect_, | 846 dst_subrect_, |
854 base::Bind(&nullcallback)); | 847 base::Bind(&nullcallback)); |
855 copy_impl_->ReadbackPlane(u_.texture_and_framebuffer(), | 848 copy_impl_->ReadbackPlane(u_.texture_and_framebuffer(), |
856 target, | 849 target, |
857 media::VideoFrame::kUPlane, | 850 media::VideoFrame::kUPlane, |
858 1, | 851 1, |
859 dst_subrect_, | 852 dst_subrect_, |
860 base::Bind(&nullcallback)); | 853 base::Bind(&nullcallback)); |
861 copy_impl_->ReadbackPlane(v_.texture_and_framebuffer(), | 854 copy_impl_->ReadbackPlane(v_.texture_and_framebuffer(), |
862 target, | 855 target, |
863 media::VideoFrame::kVPlane, | 856 media::VideoFrame::kVPlane, |
864 1, | 857 1, |
865 dst_subrect_, | 858 dst_subrect_, |
866 base::Bind(&CallbackKeepingVideoFrameAlive, | 859 callback); |
867 target, | |
868 callback)); | |
869 context_->bindFramebuffer(GL_FRAMEBUFFER, 0); | 860 context_->bindFramebuffer(GL_FRAMEBUFFER, 0); |
870 media::LetterboxYUV(target, dst_subrect_); | 861 media::LetterboxYUV(target, dst_subrect_); |
871 } | 862 } |
872 | 863 |
873 // YUV readback constructors. Initiates the main scaler pipeline and | 864 // YUV readback constructors. Initiates the main scaler pipeline and |
874 // one planar scaler for each of the Y, U and V planes. | 865 // one planar scaler for each of the Y, U and V planes. |
875 GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV_MRT( | 866 GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV_MRT( |
876 WebGraphicsContext3D* context, | 867 WebGraphicsContext3D* context, |
877 CopyTextureToImpl* copy_impl, | 868 CopyTextureToImpl* copy_impl, |
878 GLHelperScaling* scaler_impl, | 869 GLHelperScaling* scaler_impl, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 DCHECK(!(dst_size.height() & 1)); | 926 DCHECK(!(dst_size.height() & 1)); |
936 DCHECK(!(dst_subrect.width() & 1)); | 927 DCHECK(!(dst_subrect.width() & 1)); |
937 DCHECK(!(dst_subrect.height() & 1)); | 928 DCHECK(!(dst_subrect.height() & 1)); |
938 DCHECK(!(dst_subrect.x() & 1)); | 929 DCHECK(!(dst_subrect.x() & 1)); |
939 DCHECK(!(dst_subrect.y() & 1)); | 930 DCHECK(!(dst_subrect.y() & 1)); |
940 } | 931 } |
941 | 932 |
942 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( | 933 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( |
943 const gpu::Mailbox& mailbox, | 934 const gpu::Mailbox& mailbox, |
944 uint32 sync_point, | 935 uint32 sync_point, |
945 const scoped_refptr<media::VideoFrame>& target, | 936 media::VideoFrame *target, |
946 const base::Callback<void(bool)>& callback) { | 937 const base::Callback<void(bool)>& callback) { |
947 WebGLId mailbox_texture = | 938 WebGLId mailbox_texture = |
948 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); | 939 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); |
949 | 940 |
950 // Scale texture to right size. | 941 // Scale texture to right size. |
951 scaler_.Scale(mailbox_texture); | 942 scaler_.Scale(mailbox_texture); |
952 context_->deleteTexture(mailbox_texture); | 943 context_->deleteTexture(mailbox_texture); |
953 | 944 |
954 std::vector<WebKit::WebGLId> outputs(2); | 945 std::vector<WebKit::WebGLId> outputs(2); |
955 // Convert the scaled texture in to Y, U and V planes. | 946 // Convert the scaled texture in to Y, U and V planes. |
(...skipping 22 matching lines...) Expand all Loading... |
978 target, | 969 target, |
979 media::VideoFrame::kUPlane, | 970 media::VideoFrame::kUPlane, |
980 1, | 971 1, |
981 dst_subrect_, | 972 dst_subrect_, |
982 base::Bind(&nullcallback)); | 973 base::Bind(&nullcallback)); |
983 copy_impl_->ReadbackPlane(&v_, | 974 copy_impl_->ReadbackPlane(&v_, |
984 target, | 975 target, |
985 media::VideoFrame::kVPlane, | 976 media::VideoFrame::kVPlane, |
986 1, | 977 1, |
987 dst_subrect_, | 978 dst_subrect_, |
988 base::Bind(&CallbackKeepingVideoFrameAlive, | 979 callback); |
989 target, | |
990 callback)); | |
991 context_->bindFramebuffer(GL_FRAMEBUFFER, 0); | 980 context_->bindFramebuffer(GL_FRAMEBUFFER, 0); |
992 media::LetterboxYUV(target, dst_subrect_); | 981 media::LetterboxYUV(target, dst_subrect_); |
993 } | 982 } |
994 | 983 |
995 ReadbackYUVInterface* | 984 ReadbackYUVInterface* |
996 GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV( | 985 GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV( |
997 GLHelper::ScalerQuality quality, | 986 GLHelper::ScalerQuality quality, |
998 const gfx::Size& src_size, | 987 const gfx::Size& src_size, |
999 const gfx::Rect& src_subrect, | 988 const gfx::Rect& src_subrect, |
1000 const gfx::Size& dst_size, | 989 const gfx::Size& dst_size, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 quality, | 1029 quality, |
1041 src_size, | 1030 src_size, |
1042 src_subrect, | 1031 src_subrect, |
1043 dst_size, | 1032 dst_size, |
1044 dst_subrect, | 1033 dst_subrect, |
1045 flip_vertically, | 1034 flip_vertically, |
1046 use_mrt); | 1035 use_mrt); |
1047 } | 1036 } |
1048 | 1037 |
1049 } // namespace content | 1038 } // namespace content |
OLD | NEW |