| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 unsigned char* out, | 129 unsigned char* out, |
| 130 const SkBitmap::Config config, | 130 const SkBitmap::Config config, |
| 131 const base::Callback<void(bool)>& callback, | 131 const base::Callback<void(bool)>& callback, |
| 132 GLHelper::ScalerQuality quality); | 132 GLHelper::ScalerQuality quality); |
| 133 | 133 |
| 134 void ReadbackTextureSync(GLuint texture, | 134 void ReadbackTextureSync(GLuint texture, |
| 135 const gfx::Rect& src_rect, | 135 const gfx::Rect& src_rect, |
| 136 unsigned char* out, | 136 unsigned char* out, |
| 137 SkBitmap::Config format); | 137 SkBitmap::Config format); |
| 138 | 138 |
| 139 void ReadbackTextureAsync(GLuint texture, |
| 140 const gfx::Size& dst_size, |
| 141 unsigned char* out, |
| 142 SkBitmap::Config config, |
| 143 const base::Callback<void(bool)>& callback); |
| 144 |
| 139 // Reads back bytes from the currently bound frame buffer. | 145 // Reads back bytes from the currently bound frame buffer. |
| 140 // Note that dst_size is specified in bytes, not pixels. | 146 // Note that dst_size is specified in bytes, not pixels. |
| 141 void ReadbackAsync(const gfx::Size& dst_size, | 147 void ReadbackAsync(const gfx::Size& dst_size, |
| 142 int32 bytes_per_row, // generally dst_size.width() * 4 | 148 int32 bytes_per_row, // generally dst_size.width() * 4 |
| 143 int32 row_stride_bytes, // generally dst_size.width() * 4 | 149 int32 row_stride_bytes, // generally dst_size.width() * 4 |
| 144 unsigned char* out, | 150 unsigned char* out, |
| 145 const SkBitmap::Config config, | 151 const SkBitmap::Config config, |
| 146 const base::Callback<void(bool)>& callback); | 152 const base::Callback<void(bool)>& callback); |
| 147 | 153 |
| 148 void ReadbackPlane(TextureFrameBufferPair* source, | 154 void ReadbackPlane(TextureFrameBufferPair* source, |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 GL_UNSIGNED_BYTE; | 528 GL_UNSIGNED_BYTE; |
| 523 gl_->ReadPixels(src_rect.x(), | 529 gl_->ReadPixels(src_rect.x(), |
| 524 src_rect.y(), | 530 src_rect.y(), |
| 525 src_rect.width(), | 531 src_rect.width(), |
| 526 src_rect.height(), | 532 src_rect.height(), |
| 527 format, | 533 format, |
| 528 type, | 534 type, |
| 529 out); | 535 out); |
| 530 } | 536 } |
| 531 | 537 |
| 538 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( |
| 539 GLuint texture, |
| 540 const gfx::Size& dst_size, |
| 541 unsigned char* out, |
| 542 SkBitmap::Config config, |
| 543 const base::Callback<void(bool)>& callback) { |
| 544 // Only ARGB888 and RGB565 supported as of now. |
| 545 bool format_support = ((config == SkBitmap::kRGB_565_Config) || |
| 546 (config == SkBitmap::kARGB_8888_Config)); |
| 547 if (!format_support) { |
| 548 DCHECK(format_support); |
| 549 return; |
| 550 } |
| 551 ScopedFramebuffer dst_framebuffer(gl_); |
| 552 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
| 553 dst_framebuffer); |
| 554 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
| 555 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
| 556 GL_COLOR_ATTACHMENT0, |
| 557 GL_TEXTURE_2D, |
| 558 texture, |
| 559 0); |
| 560 int bytes_per_pixel = (config == SkBitmap::kRGB_565_Config) ? 2 : 4; |
| 561 ReadbackAsync(dst_size, |
| 562 dst_size.width() * bytes_per_pixel, |
| 563 dst_size.width() * bytes_per_pixel, |
| 564 out, |
| 565 config, |
| 566 callback); |
| 567 } |
| 568 |
| 532 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( | 569 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( |
| 533 GLuint src_texture, | 570 GLuint src_texture, |
| 534 const gfx::Size& src_size, | 571 const gfx::Size& src_size, |
| 535 const gfx::Size& dst_size, | 572 const gfx::Size& dst_size, |
| 536 bool vertically_flip_texture, | 573 bool vertically_flip_texture, |
| 537 GLHelper::ScalerQuality quality) { | 574 GLHelper::ScalerQuality quality) { |
| 538 return ScaleTexture(src_texture, | 575 return ScaleTexture(src_texture, |
| 539 src_size, | 576 src_size, |
| 540 gfx::Rect(src_size), | 577 gfx::Rect(src_size), |
| 541 dst_size, | 578 dst_size, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 } | 693 } |
| 657 | 694 |
| 658 void GLHelper::ReadbackTextureSync(GLuint texture, | 695 void GLHelper::ReadbackTextureSync(GLuint texture, |
| 659 const gfx::Rect& src_rect, | 696 const gfx::Rect& src_rect, |
| 660 unsigned char* out, | 697 unsigned char* out, |
| 661 SkBitmap::Config format) { | 698 SkBitmap::Config format) { |
| 662 InitCopyTextToImpl(); | 699 InitCopyTextToImpl(); |
| 663 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out, format); | 700 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out, format); |
| 664 } | 701 } |
| 665 | 702 |
| 703 void GLHelper::ReadbackTextureAsync( |
| 704 GLuint texture, |
| 705 const gfx::Size& dst_size, |
| 706 unsigned char* out, |
| 707 SkBitmap::Config config, |
| 708 const base::Callback<void(bool)>& callback) { |
| 709 InitCopyTextToImpl(); |
| 710 copy_texture_to_impl_->ReadbackTextureAsync(texture, |
| 711 dst_size, |
| 712 out, |
| 713 config, |
| 714 callback); |
| 715 } |
| 716 |
| 666 GLuint GLHelper::CopyTexture(GLuint texture, const gfx::Size& size) { | 717 GLuint GLHelper::CopyTexture(GLuint texture, const gfx::Size& size) { |
| 667 InitCopyTextToImpl(); | 718 InitCopyTextToImpl(); |
| 668 return copy_texture_to_impl_->CopyAndScaleTexture( | 719 return copy_texture_to_impl_->CopyAndScaleTexture( |
| 669 texture, size, size, false, GLHelper::SCALER_QUALITY_FAST); | 720 texture, size, size, false, GLHelper::SCALER_QUALITY_FAST); |
| 670 } | 721 } |
| 671 | 722 |
| 672 GLuint GLHelper::CopyAndScaleTexture(GLuint texture, | 723 GLuint GLHelper::CopyAndScaleTexture(GLuint texture, |
| 673 const gfx::Size& src_size, | 724 const gfx::Size& src_size, |
| 674 const gfx::Size& dst_size, | 725 const gfx::Size& dst_size, |
| 675 bool vertically_flip_texture, | 726 bool vertically_flip_texture, |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, | 1237 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
| 1187 src_size, | 1238 src_size, |
| 1188 src_subrect, | 1239 src_subrect, |
| 1189 dst_size, | 1240 dst_size, |
| 1190 dst_subrect, | 1241 dst_subrect, |
| 1191 flip_vertically, | 1242 flip_vertically, |
| 1192 use_mrt); | 1243 use_mrt); |
| 1193 } | 1244 } |
| 1194 | 1245 |
| 1195 } // namespace content | 1246 } // namespace content |
| OLD | NEW |