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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 private: | 98 private: |
99 TextureFrameBufferPair texture_and_framebuffer_; | 99 TextureFrameBufferPair texture_and_framebuffer_; |
100 scoped_ptr<content::GLHelper::ScalerInterface> scaler_; | 100 scoped_ptr<content::GLHelper::ScalerInterface> scaler_; |
101 | 101 |
102 DISALLOW_COPY_AND_ASSIGN(ScalerHolder); | 102 DISALLOW_COPY_AND_ASSIGN(ScalerHolder); |
103 }; | 103 }; |
104 | 104 |
105 } // namespace | 105 } // namespace |
106 | 106 |
107 namespace content { | 107 namespace content { |
| 108 typedef GLHelperReadbackSupport::FormatSupport FormatSupport; |
108 | 109 |
109 // Implements GLHelper::CropScaleReadbackAndCleanTexture and encapsulates | 110 // Implements GLHelper::CropScaleReadbackAndCleanTexture and encapsulates |
110 // the data needed for it. | 111 // the data needed for it. |
111 class GLHelper::CopyTextureToImpl | 112 class GLHelper::CopyTextureToImpl |
112 : public base::SupportsWeakPtr<GLHelper::CopyTextureToImpl> { | 113 : public base::SupportsWeakPtr<GLHelper::CopyTextureToImpl> { |
113 public: | 114 public: |
114 CopyTextureToImpl(GLES2Interface* gl, | 115 CopyTextureToImpl(GLES2Interface* gl, |
115 gpu::ContextSupport* context_support, | 116 gpu::ContextSupport* context_support, |
116 GLHelper* helper) | 117 GLHelper* helper) |
117 : gl_(gl), | 118 : gl_(gl), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 unsigned char* out, | 156 unsigned char* out, |
156 SkColorType color_type, | 157 SkColorType color_type, |
157 const base::Callback<void(bool)>& callback); | 158 const base::Callback<void(bool)>& callback); |
158 | 159 |
159 // Reads back bytes from the currently bound frame buffer. | 160 // Reads back bytes from the currently bound frame buffer. |
160 // Note that dst_size is specified in bytes, not pixels. | 161 // Note that dst_size is specified in bytes, not pixels. |
161 void ReadbackAsync(const gfx::Size& dst_size, | 162 void ReadbackAsync(const gfx::Size& dst_size, |
162 int32 bytes_per_row, // generally dst_size.width() * 4 | 163 int32 bytes_per_row, // generally dst_size.width() * 4 |
163 int32 row_stride_bytes, // generally dst_size.width() * 4 | 164 int32 row_stride_bytes, // generally dst_size.width() * 4 |
164 unsigned char* out, | 165 unsigned char* out, |
165 const SkColorType color_type, | 166 GLenum format, |
166 ReadbackSwizzle swizzle, | 167 GLenum type, |
| 168 size_t bytes_per_pixel, |
167 const base::Callback<void(bool)>& callback); | 169 const base::Callback<void(bool)>& callback); |
168 | 170 |
169 void ReadbackPlane(TextureFrameBufferPair* source, | 171 void ReadbackPlane(TextureFrameBufferPair* source, |
170 const scoped_refptr<media::VideoFrame>& target, | 172 const scoped_refptr<media::VideoFrame>& target, |
171 int plane, | 173 int plane, |
172 int size_shift, | 174 int size_shift, |
173 const gfx::Rect& dst_subrect, | 175 const gfx::Rect& dst_subrect, |
174 ReadbackSwizzle swizzle, | 176 ReadbackSwizzle swizzle, |
175 const base::Callback<void(bool)>& callback); | 177 const base::Callback<void(bool)>& callback); |
176 | 178 |
177 GLuint CopyAndScaleTexture(GLuint texture, | 179 GLuint CopyAndScaleTexture(GLuint texture, |
178 const gfx::Size& src_size, | 180 const gfx::Size& src_size, |
179 const gfx::Size& dst_size, | 181 const gfx::Size& dst_size, |
180 bool vertically_flip_texture, | 182 bool vertically_flip_texture, |
181 GLHelper::ScalerQuality quality); | 183 GLHelper::ScalerQuality quality); |
182 | 184 |
183 ReadbackYUVInterface* CreateReadbackPipelineYUV( | 185 ReadbackYUVInterface* CreateReadbackPipelineYUV( |
184 GLHelper::ScalerQuality quality, | 186 GLHelper::ScalerQuality quality, |
185 const gfx::Size& src_size, | 187 const gfx::Size& src_size, |
186 const gfx::Rect& src_subrect, | 188 const gfx::Rect& src_subrect, |
187 const gfx::Size& dst_size, | 189 const gfx::Size& dst_size, |
188 const gfx::Rect& dst_subrect, | 190 const gfx::Rect& dst_subrect, |
189 bool flip_vertically, | 191 bool flip_vertically, |
190 bool use_mrt); | 192 bool use_mrt); |
191 | 193 |
192 // Returns the maximum number of draw buffers available, | 194 // Returns the maximum number of draw buffers available, |
193 // 0 if GL_EXT_draw_buffers is not available. | 195 // 0 if GL_EXT_draw_buffers is not available. |
194 GLint MaxDrawBuffers() const { return max_draw_buffers_; } | 196 GLint MaxDrawBuffers() const { return max_draw_buffers_; } |
195 | 197 |
196 bool IsReadbackConfigSupported(SkColorType color_type); | 198 FormatSupport GetReadbackConfig(SkColorType color_type, |
| 199 bool can_swizzle, |
| 200 GLenum* format, |
| 201 GLenum* type, |
| 202 size_t* bytes_per_pixel); |
197 | 203 |
198 private: | 204 private: |
199 // A single request to CropScaleReadbackAndCleanTexture. | 205 // A single request to CropScaleReadbackAndCleanTexture. |
200 // The main thread can cancel the request, before it's handled by the helper | 206 // The main thread can cancel the request, before it's handled by the helper |
201 // thread, by resetting the texture and pixels fields. Alternatively, the | 207 // thread, by resetting the texture and pixels fields. Alternatively, the |
202 // thread marks that it handles the request by resetting the pixels field | 208 // thread marks that it handles the request by resetting the pixels field |
203 // (meaning it guarantees that the callback with be called). | 209 // (meaning it guarantees that the callback with be called). |
204 // In either case, the callback must be called exactly once, and the texture | 210 // In either case, the callback must be called exactly once, and the texture |
205 // must be deleted by the main thread gl. | 211 // must be deleted by the main thread gl. |
206 struct Request { | 212 struct Request { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 363 |
358 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( | 364 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( |
359 GLuint src_texture, | 365 GLuint src_texture, |
360 const gfx::Size& src_size, | 366 const gfx::Size& src_size, |
361 const gfx::Rect& src_subrect, | 367 const gfx::Rect& src_subrect, |
362 const gfx::Size& dst_size, | 368 const gfx::Size& dst_size, |
363 bool vertically_flip_texture, | 369 bool vertically_flip_texture, |
364 bool swizzle, | 370 bool swizzle, |
365 SkColorType color_type, | 371 SkColorType color_type, |
366 GLHelper::ScalerQuality quality) { | 372 GLHelper::ScalerQuality quality) { |
367 if (!IsReadbackConfigSupported(color_type)) | |
368 return 0; | |
369 | |
370 scoped_ptr<ScalerInterface> scaler( | |
371 helper_->CreateScaler(quality, | |
372 src_size, | |
373 src_subrect, | |
374 dst_size, | |
375 vertically_flip_texture, | |
376 swizzle)); | |
377 GLuint dst_texture = 0u; | 373 GLuint dst_texture = 0u; |
378 // Start with ARGB8888 params as any other format which is not | |
379 // supported is already asserted above. | |
380 GLenum format = GL_RGBA , type = GL_UNSIGNED_BYTE; | |
381 gl_->GenTextures(1, &dst_texture); | 374 gl_->GenTextures(1, &dst_texture); |
382 { | 375 { |
| 376 GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE; |
383 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | 377 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); |
384 switch (color_type) { | 378 |
385 case kN32_SkColorType: | 379 // Use GL_RGBA for destination/temporary texture unless we're working with |
386 // Do nothing params already set. | 380 // 16-bit data |
387 break; | 381 if (color_type == kRGB_565_SkColorType) { |
388 case kRGB_565_SkColorType: | 382 format = GL_RGB; |
389 format = GL_RGB; | 383 type = GL_UNSIGNED_SHORT_5_6_5; |
390 type = GL_UNSIGNED_SHORT_5_6_5; | |
391 break; | |
392 default: | |
393 NOTREACHED(); | |
394 break; | |
395 } | 384 } |
| 385 |
396 gl_->TexImage2D(GL_TEXTURE_2D, | 386 gl_->TexImage2D(GL_TEXTURE_2D, |
397 0, | 387 0, |
398 format, | 388 format, |
399 dst_size.width(), | 389 dst_size.width(), |
400 dst_size.height(), | 390 dst_size.height(), |
401 0, | 391 0, |
402 format, | 392 format, |
403 type, | 393 type, |
404 NULL); | 394 NULL); |
405 } | 395 } |
| 396 scoped_ptr<ScalerInterface> scaler( |
| 397 helper_->CreateScaler(quality, |
| 398 src_size, |
| 399 src_subrect, |
| 400 dst_size, |
| 401 vertically_flip_texture, |
| 402 swizzle)); |
406 scaler->Scale(src_texture, dst_texture); | 403 scaler->Scale(src_texture, dst_texture); |
407 return dst_texture; | 404 return dst_texture; |
408 } | 405 } |
409 | 406 |
410 void GLHelper::CopyTextureToImpl::ReadbackAsync( | 407 void GLHelper::CopyTextureToImpl::ReadbackAsync( |
411 const gfx::Size& dst_size, | 408 const gfx::Size& dst_size, |
412 int32 bytes_per_row, | 409 int32 bytes_per_row, |
413 int32 row_stride_bytes, | 410 int32 row_stride_bytes, |
414 unsigned char* out, | 411 unsigned char* out, |
415 const SkColorType color_type, | 412 GLenum format, |
416 ReadbackSwizzle swizzle, | 413 GLenum type, |
| 414 size_t bytes_per_pixel, |
417 const base::Callback<void(bool)>& callback) { | 415 const base::Callback<void(bool)>& callback) { |
418 if (!IsReadbackConfigSupported(color_type)) { | |
419 callback.Run(false); | |
420 return; | |
421 } | |
422 Request* request = | 416 Request* request = |
423 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); | 417 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); |
424 request_queue_.push(request); | 418 request_queue_.push(request); |
425 request->buffer = 0u; | 419 request->buffer = 0u; |
426 // Start with ARGB8888 params as any other format which is not | |
427 // supported is already asserted above. | |
428 GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE; | |
429 int bytes_per_pixel = 4; | |
430 | 420 |
431 switch (color_type) { | |
432 case kN32_SkColorType: | |
433 if (swizzle == kSwizzleBGRA) | |
434 format = GL_BGRA_EXT; | |
435 break; | |
436 case kRGB_565_SkColorType: | |
437 format = GL_RGB; | |
438 type = GL_UNSIGNED_SHORT_5_6_5; | |
439 bytes_per_pixel = 2; | |
440 break; | |
441 default: | |
442 NOTREACHED(); | |
443 break; | |
444 } | |
445 gl_->GenBuffers(1, &request->buffer); | 421 gl_->GenBuffers(1, &request->buffer); |
446 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); | 422 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); |
447 gl_->BufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 423 gl_->BufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
448 bytes_per_pixel * dst_size.GetArea(), | 424 bytes_per_pixel * dst_size.GetArea(), |
449 NULL, | 425 NULL, |
450 GL_STREAM_READ); | 426 GL_STREAM_READ); |
451 | 427 |
452 request->query = 0u; | 428 request->query = 0u; |
453 gl_->GenQueriesEXT(1, &request->query); | 429 gl_->GenQueriesEXT(1, &request->query); |
454 gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, request->query); | 430 gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, request->query); |
(...skipping 13 matching lines...) Expand all Loading... |
468 } | 444 } |
469 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( | 445 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( |
470 GLuint src_texture, | 446 GLuint src_texture, |
471 const gfx::Size& src_size, | 447 const gfx::Size& src_size, |
472 const gfx::Rect& src_subrect, | 448 const gfx::Rect& src_subrect, |
473 const gfx::Size& dst_size, | 449 const gfx::Size& dst_size, |
474 unsigned char* out, | 450 unsigned char* out, |
475 const SkColorType color_type, | 451 const SkColorType color_type, |
476 const base::Callback<void(bool)>& callback, | 452 const base::Callback<void(bool)>& callback, |
477 GLHelper::ScalerQuality quality) { | 453 GLHelper::ScalerQuality quality) { |
478 if (!IsReadbackConfigSupported(color_type)) { | 454 GLenum format, type; |
| 455 size_t bytes_per_pixel; |
| 456 FormatSupport supported = |
| 457 GetReadbackConfig(color_type, true, &format, &type, &bytes_per_pixel); |
| 458 if (supported == GLHelperReadbackSupport::NOT_SUPPORTED) { |
479 callback.Run(false); | 459 callback.Run(false); |
480 return; | 460 return; |
481 } | 461 } |
| 462 |
482 GLuint texture = ScaleTexture(src_texture, | 463 GLuint texture = ScaleTexture(src_texture, |
483 src_size, | 464 src_size, |
484 src_subrect, | 465 src_subrect, |
485 dst_size, | 466 dst_size, |
486 true, | 467 true, |
487 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT | 468 (supported == GLHelperReadbackSupport::SWIZZLE), |
488 true, | |
489 #else | |
490 false, | |
491 #endif | |
492 color_type, | 469 color_type, |
493 quality); | 470 quality); |
494 DCHECK(texture); | 471 DCHECK(texture); |
495 ScopedFramebuffer dst_framebuffer(gl_); | 472 ScopedFramebuffer dst_framebuffer(gl_); |
496 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 473 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
497 dst_framebuffer); | 474 dst_framebuffer); |
498 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 475 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
499 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | 476 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
500 GL_COLOR_ATTACHMENT0, | 477 GL_COLOR_ATTACHMENT0, |
501 GL_TEXTURE_2D, | 478 GL_TEXTURE_2D, |
502 texture, | 479 texture, |
503 0); | 480 0); |
504 int bytes_per_pixel = 4; | |
505 switch (color_type) { | |
506 case kN32_SkColorType: | |
507 // Do nothing params already set. | |
508 break; | |
509 case kRGB_565_SkColorType: | |
510 bytes_per_pixel = 2; | |
511 break; | |
512 default: | |
513 NOTREACHED(); | |
514 break; | |
515 } | |
516 ReadbackAsync(dst_size, | 481 ReadbackAsync(dst_size, |
517 dst_size.width() * bytes_per_pixel, | 482 dst_size.width() * bytes_per_pixel, |
518 dst_size.width() * bytes_per_pixel, | 483 dst_size.width() * bytes_per_pixel, |
519 out, | 484 out, |
520 color_type, | 485 format, |
521 kSwizzleNone, | 486 type, |
| 487 bytes_per_pixel, |
522 callback); | 488 callback); |
523 gl_->DeleteTextures(1, &texture); | 489 gl_->DeleteTextures(1, &texture); |
524 } | 490 } |
525 | 491 |
526 void GLHelper::CopyTextureToImpl::ReadbackTextureSync( | 492 void GLHelper::CopyTextureToImpl::ReadbackTextureSync( |
527 GLuint texture, | 493 GLuint texture, |
528 const gfx::Rect& src_rect, | 494 const gfx::Rect& src_rect, |
529 unsigned char* out, | 495 unsigned char* out, |
530 SkColorType color_type) { | 496 SkColorType color_type) { |
531 if (!IsReadbackConfigSupported(color_type)) | 497 GLenum format, type; |
| 498 size_t bytes_per_pixel; |
| 499 FormatSupport supported = |
| 500 GetReadbackConfig(color_type, false, &format, &type, &bytes_per_pixel); |
| 501 if (supported == GLHelperReadbackSupport::NOT_SUPPORTED) { |
532 return; | 502 return; |
| 503 } |
533 | 504 |
534 ScopedFramebuffer dst_framebuffer(gl_); | 505 ScopedFramebuffer dst_framebuffer(gl_); |
535 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 506 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
536 dst_framebuffer); | 507 dst_framebuffer); |
537 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 508 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
538 gl_->FramebufferTexture2D( | 509 gl_->FramebufferTexture2D( |
539 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); | 510 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
540 GLenum format = | |
541 (color_type == kRGB_565_SkColorType) ? GL_RGB : GL_RGBA; | |
542 GLenum type = (color_type == kRGB_565_SkColorType) | |
543 ? GL_UNSIGNED_SHORT_5_6_5 | |
544 : GL_UNSIGNED_BYTE; | |
545 gl_->ReadPixels(src_rect.x(), | 511 gl_->ReadPixels(src_rect.x(), |
546 src_rect.y(), | 512 src_rect.y(), |
547 src_rect.width(), | 513 src_rect.width(), |
548 src_rect.height(), | 514 src_rect.height(), |
549 format, | 515 format, |
550 type, | 516 type, |
551 out); | 517 out); |
552 } | 518 } |
553 | 519 |
554 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( | 520 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( |
555 GLuint texture, | 521 GLuint texture, |
556 const gfx::Size& dst_size, | 522 const gfx::Size& dst_size, |
557 unsigned char* out, | 523 unsigned char* out, |
558 SkColorType color_type, | 524 SkColorType color_type, |
559 const base::Callback<void(bool)>& callback) { | 525 const base::Callback<void(bool)>& callback) { |
560 if (!IsReadbackConfigSupported(color_type)) | 526 GLenum format, type; |
| 527 size_t bytes_per_pixel; |
| 528 FormatSupport supported = |
| 529 GetReadbackConfig(color_type, false, &format, &type, &bytes_per_pixel); |
| 530 if (supported == GLHelperReadbackSupport::NOT_SUPPORTED) { |
| 531 callback.Run(false); |
561 return; | 532 return; |
| 533 } |
562 | 534 |
563 ScopedFramebuffer dst_framebuffer(gl_); | 535 ScopedFramebuffer dst_framebuffer(gl_); |
564 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 536 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
565 dst_framebuffer); | 537 dst_framebuffer); |
566 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 538 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
567 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | 539 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
568 GL_COLOR_ATTACHMENT0, | 540 GL_COLOR_ATTACHMENT0, |
569 GL_TEXTURE_2D, | 541 GL_TEXTURE_2D, |
570 texture, | 542 texture, |
571 0); | 543 0); |
572 int bytes_per_pixel = (color_type == kRGB_565_SkColorType) ? 2 : 4; | |
573 ReadbackAsync(dst_size, | 544 ReadbackAsync(dst_size, |
574 dst_size.width() * bytes_per_pixel, | 545 dst_size.width() * bytes_per_pixel, |
575 dst_size.width() * bytes_per_pixel, | 546 dst_size.width() * bytes_per_pixel, |
576 out, | 547 out, |
577 color_type, | 548 format, |
578 kSwizzleNone, | 549 type, |
| 550 bytes_per_pixel, |
579 callback); | 551 callback); |
580 } | 552 } |
581 | 553 |
582 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( | 554 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( |
583 GLuint src_texture, | 555 GLuint src_texture, |
584 const gfx::Size& src_size, | 556 const gfx::Size& src_size, |
585 const gfx::Size& dst_size, | 557 const gfx::Size& dst_size, |
586 bool vertically_flip_texture, | 558 bool vertically_flip_texture, |
587 GLHelper::ScalerQuality quality) { | 559 GLHelper::ScalerQuality quality) { |
588 return ScaleTexture(src_texture, | 560 return ScaleTexture(src_texture, |
589 src_size, | 561 src_size, |
590 gfx::Rect(src_size), | 562 gfx::Rect(src_size), |
591 dst_size, | 563 dst_size, |
592 vertically_flip_texture, | 564 vertically_flip_texture, |
593 false, | 565 false, |
594 kN32_SkColorType, | 566 kRGBA_8888_SkColorType, // GL_RGBA |
595 quality); | 567 quality); |
596 } | 568 } |
597 | 569 |
598 bool GLHelper::CopyTextureToImpl::IsReadbackConfigSupported( | |
599 SkColorType color_type) { | |
600 if (!helper_) { | |
601 DCHECK(helper_); | |
602 return false; | |
603 } | |
604 return helper_->IsReadbackConfigSupported(color_type); | |
605 } | |
606 | |
607 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, | 570 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, |
608 int bytes_per_pixel) { | 571 int bytes_per_pixel) { |
609 TRACE_EVENT0("mirror", | 572 TRACE_EVENT0("mirror", |
610 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); | 573 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); |
611 finished_request->done = true; | 574 finished_request->done = true; |
612 | 575 |
613 // We process transfer requests in the order they were received, regardless | 576 // We process transfer requests in the order they were received, regardless |
614 // of the order we get the callbacks in. | 577 // of the order we get the callbacks in. |
615 while (!request_queue_.empty()) { | 578 while (!request_queue_.empty()) { |
616 Request* request = request_queue_.front(); | 579 Request* request = request_queue_.front(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 delete request; | 625 delete request; |
663 } | 626 } |
664 | 627 |
665 void GLHelper::CopyTextureToImpl::CancelRequests() { | 628 void GLHelper::CopyTextureToImpl::CancelRequests() { |
666 while (!request_queue_.empty()) { | 629 while (!request_queue_.empty()) { |
667 Request* request = request_queue_.front(); | 630 Request* request = request_queue_.front(); |
668 FinishRequest(request, false); | 631 FinishRequest(request, false); |
669 } | 632 } |
670 } | 633 } |
671 | 634 |
| 635 FormatSupport GLHelper::CopyTextureToImpl::GetReadbackConfig( |
| 636 SkColorType color_type, |
| 637 bool can_swizzle, |
| 638 GLenum* format, |
| 639 GLenum* type, |
| 640 size_t* bytes_per_pixel) { |
| 641 return helper_->readback_support_->GetReadbackConfig( |
| 642 color_type, can_swizzle, format, type, bytes_per_pixel); |
| 643 } |
| 644 |
672 GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support) | 645 GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support) |
673 : gl_(gl), | 646 : gl_(gl), |
674 context_support_(context_support), | 647 context_support_(context_support), |
675 readback_support_(new GLHelperReadbackSupport(gl)) {} | 648 readback_support_(new GLHelperReadbackSupport(gl)) {} |
676 | 649 |
677 GLHelper::~GLHelper() {} | 650 GLHelper::~GLHelper() {} |
678 | 651 |
679 void GLHelper::CropScaleReadbackAndCleanTexture( | 652 void GLHelper::CropScaleReadbackAndCleanTexture( |
680 GLuint src_texture, | 653 GLuint src_texture, |
681 const gfx::Size& src_size, | 654 const gfx::Size& src_size, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 const gfx::Rect& dst_subrect, | 881 const gfx::Rect& dst_subrect, |
909 ReadbackSwizzle swizzle, | 882 ReadbackSwizzle swizzle, |
910 const base::Callback<void(bool)>& callback) { | 883 const base::Callback<void(bool)>& callback) { |
911 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); | 884 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); |
912 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + | 885 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + |
913 (dst_subrect.x() >> size_shift); | 886 (dst_subrect.x() >> size_shift); |
914 ReadbackAsync(source->size(), | 887 ReadbackAsync(source->size(), |
915 dst_subrect.width() >> size_shift, | 888 dst_subrect.width() >> size_shift, |
916 target->stride(plane), | 889 target->stride(plane), |
917 target->data(plane) + offset, | 890 target->data(plane) + offset, |
918 kN32_SkColorType, | 891 (swizzle == kSwizzleBGRA) ? GL_BGRA_EXT : GL_RGBA, |
919 swizzle, | 892 GL_UNSIGNED_BYTE, |
| 893 4, |
920 callback); | 894 callback); |
921 } | 895 } |
922 | 896 |
923 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = { | 897 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = { |
924 0.257f, 0.504f, 0.098f, 0.0625f}; | 898 0.257f, 0.504f, 0.098f, 0.0625f}; |
925 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = { | 899 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = { |
926 -0.148f, -0.291f, 0.439f, 0.5f}; | 900 -0.148f, -0.291f, 0.439f, 0.5f}; |
927 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = { | 901 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = { |
928 0.439f, -0.368f, -0.071f, 0.5f}; | 902 0.439f, -0.368f, -0.071f, 0.5f}; |
929 | 903 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 target, | 1159 target, |
1186 media::VideoFrame::kVPlane, | 1160 media::VideoFrame::kVPlane, |
1187 1, | 1161 1, |
1188 dst_subrect_, | 1162 dst_subrect_, |
1189 swizzle_, | 1163 swizzle_, |
1190 base::Bind(&CallbackKeepingVideoFrameAlive, target, callback)); | 1164 base::Bind(&CallbackKeepingVideoFrameAlive, target, callback)); |
1191 gl_->BindFramebuffer(GL_FRAMEBUFFER, 0); | 1165 gl_->BindFramebuffer(GL_FRAMEBUFFER, 0); |
1192 media::LetterboxYUV(target, dst_subrect_); | 1166 media::LetterboxYUV(target, dst_subrect_); |
1193 } | 1167 } |
1194 | 1168 |
1195 bool GLHelper::IsReadbackConfigSupported(SkColorType texture_format) { | 1169 bool GLHelper::IsReadbackConfigSupported(SkColorType color_type) { |
1196 DCHECK(readback_support_.get()); | 1170 DCHECK(readback_support_.get()); |
1197 return readback_support_.get()->IsReadbackConfigSupported(texture_format); | 1171 GLenum format, type; |
| 1172 size_t bytes_per_pixel; |
| 1173 FormatSupport support = readback_support_->GetReadbackConfig( |
| 1174 color_type, false, &format, &type, &bytes_per_pixel); |
| 1175 |
| 1176 return (support == GLHelperReadbackSupport::SUPPORTED); |
1198 } | 1177 } |
1199 | 1178 |
1200 ReadbackYUVInterface* GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV( | 1179 ReadbackYUVInterface* GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV( |
1201 GLHelper::ScalerQuality quality, | 1180 GLHelper::ScalerQuality quality, |
1202 const gfx::Size& src_size, | 1181 const gfx::Size& src_size, |
1203 const gfx::Rect& src_subrect, | 1182 const gfx::Rect& src_subrect, |
1204 const gfx::Size& dst_size, | 1183 const gfx::Size& dst_size, |
1205 const gfx::Rect& dst_subrect, | 1184 const gfx::Rect& dst_subrect, |
1206 bool flip_vertically, | 1185 bool flip_vertically, |
1207 bool use_mrt) { | 1186 bool use_mrt) { |
1208 helper_->InitScalerImpl(); | 1187 helper_->InitScalerImpl(); |
1209 // Query preferred format for glReadPixels, if is is GL_BGRA then use that | 1188 // Just query if the best readback configuration needs a swizzle In |
1210 // and trigger the appropriate swizzle in the YUV shaders. | 1189 // ReadbackPlane() we will choose GL_RGBA/GL_BGRA_EXT based on swizzle |
1211 GLint format = 0, type = 0; | 1190 GLenum format, type; |
| 1191 size_t bytes_per_pixel; |
| 1192 FormatSupport supported = GetReadbackConfig( |
| 1193 kRGBA_8888_SkColorType, true, &format, &type, &bytes_per_pixel); |
| 1194 DCHECK((format == GL_RGBA || format == GL_BGRA_EXT) && |
| 1195 type == GL_UNSIGNED_BYTE); |
| 1196 |
1212 ReadbackSwizzle swizzle = kSwizzleNone; | 1197 ReadbackSwizzle swizzle = kSwizzleNone; |
1213 helper_->readback_support_.get()->GetAdditionalFormat(GL_RGBA, | 1198 if (supported == GLHelperReadbackSupport::SWIZZLE) |
1214 GL_UNSIGNED_BYTE, | |
1215 &format, &type); | |
1216 if (format == GL_BGRA_EXT && type == GL_UNSIGNED_BYTE) | |
1217 swizzle = kSwizzleBGRA; | 1199 swizzle = kSwizzleBGRA; |
| 1200 |
1218 if (max_draw_buffers_ >= 2 && use_mrt) { | 1201 if (max_draw_buffers_ >= 2 && use_mrt) { |
1219 return new ReadbackYUV_MRT(gl_, | 1202 return new ReadbackYUV_MRT(gl_, |
1220 this, | 1203 this, |
1221 helper_->scaler_impl_.get(), | 1204 helper_->scaler_impl_.get(), |
1222 quality, | 1205 quality, |
1223 src_size, | 1206 src_size, |
1224 src_subrect, | 1207 src_subrect, |
1225 dst_size, | 1208 dst_size, |
1226 dst_subrect, | 1209 dst_subrect, |
1227 flip_vertically, | 1210 flip_vertically, |
(...skipping 23 matching lines...) Expand all Loading... |
1251 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, | 1234 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
1252 src_size, | 1235 src_size, |
1253 src_subrect, | 1236 src_subrect, |
1254 dst_size, | 1237 dst_size, |
1255 dst_subrect, | 1238 dst_subrect, |
1256 flip_vertically, | 1239 flip_vertically, |
1257 use_mrt); | 1240 use_mrt); |
1258 } | 1241 } |
1259 | 1242 |
1260 } // namespace content | 1243 } // namespace content |
OLD | NEW |