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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 return; | 126 return; |
127 std::string extensions_string = | 127 std::string extensions_string = |
128 " " + std::string(reinterpret_cast<const char*>(extensions)) + " "; | 128 " " + std::string(reinterpret_cast<const char*>(extensions)) + " "; |
129 if (extensions_string.find(" GL_EXT_draw_buffers ") != std::string::npos) { | 129 if (extensions_string.find(" GL_EXT_draw_buffers ") != std::string::npos) { |
130 gl_->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &max_draw_buffers_); | 130 gl_->GetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &max_draw_buffers_); |
131 } | 131 } |
132 } | 132 } |
133 ~CopyTextureToImpl() { CancelRequests(); } | 133 ~CopyTextureToImpl() { CancelRequests(); } |
134 | 134 |
135 GLuint ConsumeMailboxToTexture(const gpu::Mailbox& mailbox, | 135 GLuint ConsumeMailboxToTexture(const gpu::Mailbox& mailbox, |
136 uint32 sync_point) { | 136 uint32 sync_point, |
137 return helper_->ConsumeMailboxToTexture(mailbox, sync_point); | 137 const gpu::SyncToken& sync_token) { |
| 138 return helper_->ConsumeMailboxToTexture(mailbox, sync_point, sync_token); |
138 } | 139 } |
139 | 140 |
140 void CropScaleReadbackAndCleanTexture( | 141 void CropScaleReadbackAndCleanTexture( |
141 GLuint src_texture, | 142 GLuint src_texture, |
142 const gfx::Size& src_size, | 143 const gfx::Size& src_size, |
143 const gfx::Rect& src_subrect, | 144 const gfx::Rect& src_subrect, |
144 const gfx::Size& dst_size, | 145 const gfx::Size& dst_size, |
145 unsigned char* out, | 146 unsigned char* out, |
146 const SkColorType out_color_type, | 147 const SkColorType out_color_type, |
147 const base::Callback<void(bool)>& callback, | 148 const base::Callback<void(bool)>& callback, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 GLHelperScaling* scaler_impl, | 268 GLHelperScaling* scaler_impl, |
268 GLHelper::ScalerQuality quality, | 269 GLHelper::ScalerQuality quality, |
269 const gfx::Size& src_size, | 270 const gfx::Size& src_size, |
270 const gfx::Rect& src_subrect, | 271 const gfx::Rect& src_subrect, |
271 const gfx::Size& dst_size, | 272 const gfx::Size& dst_size, |
272 bool flip_vertically, | 273 bool flip_vertically, |
273 ReadbackSwizzle swizzle); | 274 ReadbackSwizzle swizzle); |
274 | 275 |
275 void ReadbackYUV(const gpu::Mailbox& mailbox, | 276 void ReadbackYUV(const gpu::Mailbox& mailbox, |
276 uint32 sync_point, | 277 uint32 sync_point, |
| 278 const gpu::SyncToken& sync_token, |
277 const scoped_refptr<media::VideoFrame>& target, | 279 const scoped_refptr<media::VideoFrame>& target, |
278 const gfx::Point& paste_location, | 280 const gfx::Point& paste_location, |
279 const base::Callback<void(bool)>& callback) override; | 281 const base::Callback<void(bool)>& callback) override; |
280 | 282 |
281 ScalerInterface* scaler() override { return scaler_.scaler(); } | 283 ScalerInterface* scaler() override { return scaler_.scaler(); } |
282 | 284 |
283 private: | 285 private: |
284 GLES2Interface* gl_; | 286 GLES2Interface* gl_; |
285 CopyTextureToImpl* copy_impl_; | 287 CopyTextureToImpl* copy_impl_; |
286 gfx::Size dst_size_; | 288 gfx::Size dst_size_; |
(...skipping 16 matching lines...) Expand all Loading... |
303 GLHelperScaling* scaler_impl, | 305 GLHelperScaling* scaler_impl, |
304 GLHelper::ScalerQuality quality, | 306 GLHelper::ScalerQuality quality, |
305 const gfx::Size& src_size, | 307 const gfx::Size& src_size, |
306 const gfx::Rect& src_subrect, | 308 const gfx::Rect& src_subrect, |
307 const gfx::Size& dst_size, | 309 const gfx::Size& dst_size, |
308 bool flip_vertically, | 310 bool flip_vertically, |
309 ReadbackSwizzle swizzle); | 311 ReadbackSwizzle swizzle); |
310 | 312 |
311 void ReadbackYUV(const gpu::Mailbox& mailbox, | 313 void ReadbackYUV(const gpu::Mailbox& mailbox, |
312 uint32 sync_point, | 314 uint32 sync_point, |
| 315 const gpu::SyncToken& sync_token, |
313 const scoped_refptr<media::VideoFrame>& target, | 316 const scoped_refptr<media::VideoFrame>& target, |
314 const gfx::Point& paste_location, | 317 const gfx::Point& paste_location, |
315 const base::Callback<void(bool)>& callback) override; | 318 const base::Callback<void(bool)>& callback) override; |
316 | 319 |
317 ScalerInterface* scaler() override { return scaler_.scaler(); } | 320 ScalerInterface* scaler() override { return scaler_.scaler(); } |
318 | 321 |
319 private: | 322 private: |
320 GLES2Interface* gl_; | 323 GLES2Interface* gl_; |
321 CopyTextureToImpl* copy_impl_; | 324 CopyTextureToImpl* copy_impl_; |
322 gfx::Size dst_size_; | 325 gfx::Size dst_size_; |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 dst_size, | 812 dst_size, |
810 out, | 813 out, |
811 out_color_type, | 814 out_color_type, |
812 callback, | 815 callback, |
813 quality); | 816 quality); |
814 } | 817 } |
815 | 818 |
816 void GLHelper::CropScaleReadbackAndCleanMailbox( | 819 void GLHelper::CropScaleReadbackAndCleanMailbox( |
817 const gpu::Mailbox& src_mailbox, | 820 const gpu::Mailbox& src_mailbox, |
818 uint32 sync_point, | 821 uint32 sync_point, |
| 822 const gpu::SyncToken& sync_token, |
819 const gfx::Size& src_size, | 823 const gfx::Size& src_size, |
820 const gfx::Rect& src_subrect, | 824 const gfx::Rect& src_subrect, |
821 const gfx::Size& dst_size, | 825 const gfx::Size& dst_size, |
822 unsigned char* out, | 826 unsigned char* out, |
823 const SkColorType out_color_type, | 827 const SkColorType out_color_type, |
824 const base::Callback<void(bool)>& callback, | 828 const base::Callback<void(bool)>& callback, |
825 GLHelper::ScalerQuality quality) { | 829 GLHelper::ScalerQuality quality) { |
826 GLuint mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); | 830 GLuint mailbox_texture = |
| 831 ConsumeMailboxToTexture(src_mailbox, sync_point, sync_token); |
827 CropScaleReadbackAndCleanTexture(mailbox_texture, | 832 CropScaleReadbackAndCleanTexture(mailbox_texture, |
828 src_size, | 833 src_size, |
829 src_subrect, | 834 src_subrect, |
830 dst_size, | 835 dst_size, |
831 out, | 836 out, |
832 out_color_type, | 837 out_color_type, |
833 callback, | 838 callback, |
834 quality); | 839 quality); |
835 gl_->DeleteTextures(1, &mailbox_texture); | 840 gl_->DeleteTextures(1, &mailbox_texture); |
836 } | 841 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 952 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
948 return texture; | 953 return texture; |
949 } | 954 } |
950 | 955 |
951 void GLHelper::DeleteTexture(GLuint texture_id) { | 956 void GLHelper::DeleteTexture(GLuint texture_id) { |
952 gl_->DeleteTextures(1, &texture_id); | 957 gl_->DeleteTextures(1, &texture_id); |
953 } | 958 } |
954 | 959 |
955 uint32 GLHelper::InsertSyncPoint() { return gl_->InsertSyncPointCHROMIUM(); } | 960 uint32 GLHelper::InsertSyncPoint() { return gl_->InsertSyncPointCHROMIUM(); } |
956 | 961 |
957 void GLHelper::WaitSyncPoint(uint32 sync_point) { | 962 void GLHelper::WaitSyncPoint(uint32 sync_point, |
958 gl_->WaitSyncPointCHROMIUM(sync_point); | 963 const gpu::SyncToken& sync_token) { |
| 964 gl_->WaitSyncPointCHROMIUM(sync_point, sync_token.GetConstData()); |
959 } | 965 } |
960 | 966 |
961 gpu::MailboxHolder GLHelper::ProduceMailboxHolderFromTexture( | 967 gpu::MailboxHolder GLHelper::ProduceMailboxHolderFromTexture( |
962 GLuint texture_id) { | 968 GLuint texture_id) { |
963 gpu::Mailbox mailbox; | 969 gpu::Mailbox mailbox; |
964 gl_->GenMailboxCHROMIUM(mailbox.name); | 970 gl_->GenMailboxCHROMIUM(mailbox.name); |
965 gl_->ProduceTextureDirectCHROMIUM(texture_id, GL_TEXTURE_2D, mailbox.name); | 971 gl_->ProduceTextureDirectCHROMIUM(texture_id, GL_TEXTURE_2D, mailbox.name); |
966 return gpu::MailboxHolder(mailbox, GL_TEXTURE_2D, InsertSyncPoint()); | 972 return gpu::MailboxHolder(mailbox, InsertSyncPoint(), gpu::SyncToken(), |
| 973 GL_TEXTURE_2D); |
967 } | 974 } |
968 | 975 |
969 GLuint GLHelper::ConsumeMailboxToTexture(const gpu::Mailbox& mailbox, | 976 GLuint GLHelper::ConsumeMailboxToTexture(const gpu::Mailbox& mailbox, |
970 uint32 sync_point) { | 977 uint32 sync_point, |
| 978 const gpu::SyncToken& sync_token) { |
971 if (mailbox.IsZero()) | 979 if (mailbox.IsZero()) |
972 return 0; | 980 return 0; |
973 if (sync_point) | 981 if (sync_point || sync_token.HasData()) |
974 WaitSyncPoint(sync_point); | 982 WaitSyncPoint(sync_point, sync_token); |
975 GLuint texture = | 983 GLuint texture = |
976 gl_->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 984 gl_->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
977 return texture; | 985 return texture; |
978 } | 986 } |
979 | 987 |
980 void GLHelper::ResizeTexture(GLuint texture, const gfx::Size& size) { | 988 void GLHelper::ResizeTexture(GLuint texture, const gfx::Size& size) { |
981 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 989 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
982 gl_->TexImage2D(GL_TEXTURE_2D, | 990 gl_->TexImage2D(GL_TEXTURE_2D, |
983 0, | 991 0, |
984 GL_RGB, | 992 GL_RGB, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 static void CallbackKeepingVideoFrameAlive( | 1119 static void CallbackKeepingVideoFrameAlive( |
1112 scoped_refptr<media::VideoFrame> video_frame, | 1120 scoped_refptr<media::VideoFrame> video_frame, |
1113 const base::Callback<void(bool)>& callback, | 1121 const base::Callback<void(bool)>& callback, |
1114 bool success) { | 1122 bool success) { |
1115 callback.Run(success); | 1123 callback.Run(success); |
1116 } | 1124 } |
1117 | 1125 |
1118 void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( | 1126 void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( |
1119 const gpu::Mailbox& mailbox, | 1127 const gpu::Mailbox& mailbox, |
1120 uint32 sync_point, | 1128 uint32 sync_point, |
| 1129 const gpu::SyncToken& sync_token, |
1121 const scoped_refptr<media::VideoFrame>& target, | 1130 const scoped_refptr<media::VideoFrame>& target, |
1122 const gfx::Point& paste_location, | 1131 const gfx::Point& paste_location, |
1123 const base::Callback<void(bool)>& callback) { | 1132 const base::Callback<void(bool)>& callback) { |
1124 DCHECK(!(paste_location.x() & 1)); | 1133 DCHECK(!(paste_location.x() & 1)); |
1125 DCHECK(!(paste_location.y() & 1)); | 1134 DCHECK(!(paste_location.y() & 1)); |
1126 | 1135 |
1127 GLuint mailbox_texture = | 1136 GLuint mailbox_texture = |
1128 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); | 1137 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point, sync_token); |
1129 | 1138 |
1130 // Scale texture to right size. | 1139 // Scale texture to right size. |
1131 scaler_.Scale(mailbox_texture); | 1140 scaler_.Scale(mailbox_texture); |
1132 gl_->DeleteTextures(1, &mailbox_texture); | 1141 gl_->DeleteTextures(1, &mailbox_texture); |
1133 | 1142 |
1134 // Convert the scaled texture in to Y, U and V planes. | 1143 // Convert the scaled texture in to Y, U and V planes. |
1135 y_.Scale(scaler_.texture()); | 1144 y_.Scale(scaler_.texture()); |
1136 u_.Scale(scaler_.texture()); | 1145 u_.Scale(scaler_.texture()); |
1137 v_.Scale(scaler_.texture()); | 1146 v_.Scale(scaler_.texture()); |
1138 | 1147 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 dst_size.height(), | 1241 dst_size.height(), |
1233 0, | 1242 0, |
1234 GL_RGBA, | 1243 GL_RGBA, |
1235 GL_UNSIGNED_BYTE, | 1244 GL_UNSIGNED_BYTE, |
1236 NULL); | 1245 NULL); |
1237 } | 1246 } |
1238 | 1247 |
1239 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( | 1248 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( |
1240 const gpu::Mailbox& mailbox, | 1249 const gpu::Mailbox& mailbox, |
1241 uint32 sync_point, | 1250 uint32 sync_point, |
| 1251 const gpu::SyncToken& sync_token, |
1242 const scoped_refptr<media::VideoFrame>& target, | 1252 const scoped_refptr<media::VideoFrame>& target, |
1243 const gfx::Point& paste_location, | 1253 const gfx::Point& paste_location, |
1244 const base::Callback<void(bool)>& callback) { | 1254 const base::Callback<void(bool)>& callback) { |
1245 DCHECK(!(paste_location.x() & 1)); | 1255 DCHECK(!(paste_location.x() & 1)); |
1246 DCHECK(!(paste_location.y() & 1)); | 1256 DCHECK(!(paste_location.y() & 1)); |
1247 | 1257 |
1248 GLuint mailbox_texture = | 1258 GLuint mailbox_texture = |
1249 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); | 1259 copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point, sync_token); |
1250 | 1260 |
1251 GLuint texture; | 1261 GLuint texture; |
1252 if (quality_ == GLHelper::SCALER_QUALITY_FAST) { | 1262 if (quality_ == GLHelper::SCALER_QUALITY_FAST) { |
1253 // Optimization: SCALER_QUALITY_FAST is just a single bilinear | 1263 // Optimization: SCALER_QUALITY_FAST is just a single bilinear |
1254 // pass, which pass1_shader_ can do just as well, so let's skip | 1264 // pass, which pass1_shader_ can do just as well, so let's skip |
1255 // the actual scaling in that case. | 1265 // the actual scaling in that case. |
1256 texture = mailbox_texture; | 1266 texture = mailbox_texture; |
1257 } else { | 1267 } else { |
1258 // Scale texture to right size. | 1268 // Scale texture to right size. |
1259 scaler_.Scale(mailbox_texture); | 1269 scaler_.Scale(mailbox_texture); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 InitCopyTextToImpl(); | 1379 InitCopyTextToImpl(); |
1370 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, | 1380 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
1371 src_size, | 1381 src_size, |
1372 src_subrect, | 1382 src_subrect, |
1373 dst_size, | 1383 dst_size, |
1374 flip_vertically, | 1384 flip_vertically, |
1375 use_mrt); | 1385 use_mrt); |
1376 } | 1386 } |
1377 | 1387 |
1378 } // namespace content | 1388 } // namespace content |
OLD | NEW |