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 media::VideoFrame* target, | 157 const scoped_refptr<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 media::VideoFrame* target, | 235 const scoped_refptr<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 media::VideoFrame* target, | 273 const scoped_refptr<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 media::VideoFrame* target, | 732 const scoped_refptr<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 } |
816 | 822 |
817 void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( | 823 void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( |
818 const gpu::Mailbox& mailbox, | 824 const gpu::Mailbox& mailbox, |
819 uint32 sync_point, | 825 uint32 sync_point, |
820 media::VideoFrame *target, | 826 const scoped_refptr<media::VideoFrame>& target, |
821 const base::Callback<void(bool)>& callback) { | 827 const base::Callback<void(bool)>& callback) { |
822 WebGLId mailbox_texture = | 828 WebGLId mailbox_texture = |
823 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); | 829 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); |
824 | 830 |
825 // Scale texture to right size. | 831 // Scale texture to right size. |
826 scaler_.Scale(mailbox_texture); | 832 scaler_.Scale(mailbox_texture); |
827 context_->deleteTexture(mailbox_texture); | 833 context_->deleteTexture(mailbox_texture); |
828 | 834 |
829 // Convert the scaled texture in to Y, U and V planes. | 835 // Convert the scaled texture in to Y, U and V planes. |
830 y_.Scale(scaler_.texture()); | 836 y_.Scale(scaler_.texture()); |
831 u_.Scale(scaler_.texture()); | 837 u_.Scale(scaler_.texture()); |
832 v_.Scale(scaler_.texture()); | 838 v_.Scale(scaler_.texture()); |
833 | 839 |
834 if (target->coded_size() != dst_size_) { | 840 if (target->coded_size() != dst_size_) { |
835 DCHECK(target->coded_size() == dst_size_); | 841 DCHECK(target->coded_size() == dst_size_); |
836 LOG(ERROR) << "ReadbackYUV size error!"; | 842 LOG(ERROR) << "ReadbackYUV size error!"; |
837 callback.Run(false); | 843 callback.Run(false); |
838 return; | 844 return; |
839 } | 845 } |
840 | 846 |
841 // Read back planes, one at a time. | 847 // Read back planes, one at a time. Keep the video frame alive while doing the |
| 848 // readback. |
842 copy_impl_->ReadbackPlane(y_.texture_and_framebuffer(), | 849 copy_impl_->ReadbackPlane(y_.texture_and_framebuffer(), |
843 target, | 850 target, |
844 media::VideoFrame::kYPlane, | 851 media::VideoFrame::kYPlane, |
845 0, | 852 0, |
846 dst_subrect_, | 853 dst_subrect_, |
847 base::Bind(&nullcallback)); | 854 base::Bind(&nullcallback)); |
848 copy_impl_->ReadbackPlane(u_.texture_and_framebuffer(), | 855 copy_impl_->ReadbackPlane(u_.texture_and_framebuffer(), |
849 target, | 856 target, |
850 media::VideoFrame::kUPlane, | 857 media::VideoFrame::kUPlane, |
851 1, | 858 1, |
852 dst_subrect_, | 859 dst_subrect_, |
853 base::Bind(&nullcallback)); | 860 base::Bind(&nullcallback)); |
854 copy_impl_->ReadbackPlane(v_.texture_and_framebuffer(), | 861 copy_impl_->ReadbackPlane(v_.texture_and_framebuffer(), |
855 target, | 862 target, |
856 media::VideoFrame::kVPlane, | 863 media::VideoFrame::kVPlane, |
857 1, | 864 1, |
858 dst_subrect_, | 865 dst_subrect_, |
859 callback); | 866 base::Bind(&CallbackKeepingVideoFrameAlive, |
| 867 target, |
| 868 callback)); |
860 context_->bindFramebuffer(GL_FRAMEBUFFER, 0); | 869 context_->bindFramebuffer(GL_FRAMEBUFFER, 0); |
861 media::LetterboxYUV(target, dst_subrect_); | 870 media::LetterboxYUV(target, dst_subrect_); |
862 } | 871 } |
863 | 872 |
864 // YUV readback constructors. Initiates the main scaler pipeline and | 873 // YUV readback constructors. Initiates the main scaler pipeline and |
865 // one planar scaler for each of the Y, U and V planes. | 874 // one planar scaler for each of the Y, U and V planes. |
866 GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV_MRT( | 875 GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV_MRT( |
867 WebGraphicsContext3D* context, | 876 WebGraphicsContext3D* context, |
868 CopyTextureToImpl* copy_impl, | 877 CopyTextureToImpl* copy_impl, |
869 GLHelperScaling* scaler_impl, | 878 GLHelperScaling* scaler_impl, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 DCHECK(!(dst_size.height() & 1)); | 935 DCHECK(!(dst_size.height() & 1)); |
927 DCHECK(!(dst_subrect.width() & 1)); | 936 DCHECK(!(dst_subrect.width() & 1)); |
928 DCHECK(!(dst_subrect.height() & 1)); | 937 DCHECK(!(dst_subrect.height() & 1)); |
929 DCHECK(!(dst_subrect.x() & 1)); | 938 DCHECK(!(dst_subrect.x() & 1)); |
930 DCHECK(!(dst_subrect.y() & 1)); | 939 DCHECK(!(dst_subrect.y() & 1)); |
931 } | 940 } |
932 | 941 |
933 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( | 942 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( |
934 const gpu::Mailbox& mailbox, | 943 const gpu::Mailbox& mailbox, |
935 uint32 sync_point, | 944 uint32 sync_point, |
936 media::VideoFrame *target, | 945 const scoped_refptr<media::VideoFrame>& target, |
937 const base::Callback<void(bool)>& callback) { | 946 const base::Callback<void(bool)>& callback) { |
938 WebGLId mailbox_texture = | 947 WebGLId mailbox_texture = |
939 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); | 948 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); |
940 | 949 |
941 // Scale texture to right size. | 950 // Scale texture to right size. |
942 scaler_.Scale(mailbox_texture); | 951 scaler_.Scale(mailbox_texture); |
943 context_->deleteTexture(mailbox_texture); | 952 context_->deleteTexture(mailbox_texture); |
944 | 953 |
945 std::vector<WebKit::WebGLId> outputs(2); | 954 std::vector<WebKit::WebGLId> outputs(2); |
946 // Convert the scaled texture in to Y, U and V planes. | 955 // Convert the scaled texture in to Y, U and V planes. |
(...skipping 22 matching lines...) Expand all Loading... |
969 target, | 978 target, |
970 media::VideoFrame::kUPlane, | 979 media::VideoFrame::kUPlane, |
971 1, | 980 1, |
972 dst_subrect_, | 981 dst_subrect_, |
973 base::Bind(&nullcallback)); | 982 base::Bind(&nullcallback)); |
974 copy_impl_->ReadbackPlane(&v_, | 983 copy_impl_->ReadbackPlane(&v_, |
975 target, | 984 target, |
976 media::VideoFrame::kVPlane, | 985 media::VideoFrame::kVPlane, |
977 1, | 986 1, |
978 dst_subrect_, | 987 dst_subrect_, |
979 callback); | 988 base::Bind(&CallbackKeepingVideoFrameAlive, |
| 989 target, |
| 990 callback)); |
980 context_->bindFramebuffer(GL_FRAMEBUFFER, 0); | 991 context_->bindFramebuffer(GL_FRAMEBUFFER, 0); |
981 media::LetterboxYUV(target, dst_subrect_); | 992 media::LetterboxYUV(target, dst_subrect_); |
982 } | 993 } |
983 | 994 |
984 ReadbackYUVInterface* | 995 ReadbackYUVInterface* |
985 GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV( | 996 GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV( |
986 GLHelper::ScalerQuality quality, | 997 GLHelper::ScalerQuality quality, |
987 const gfx::Size& src_size, | 998 const gfx::Size& src_size, |
988 const gfx::Rect& src_subrect, | 999 const gfx::Rect& src_subrect, |
989 const gfx::Size& dst_size, | 1000 const gfx::Size& dst_size, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 quality, | 1040 quality, |
1030 src_size, | 1041 src_size, |
1031 src_subrect, | 1042 src_subrect, |
1032 dst_size, | 1043 dst_size, |
1033 dst_subrect, | 1044 dst_subrect, |
1034 flip_vertically, | 1045 flip_vertically, |
1035 use_mrt); | 1046 use_mrt); |
1036 } | 1047 } |
1037 | 1048 |
1038 } // namespace content | 1049 } // namespace content |
OLD | NEW |