Chromium Code Reviews| 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 readback_config_rgb565 = (config == SkBitmap::kRGB_565_Config); | |
| 561 int bytes_per_pixel = readback_config_rgb565 ? 2 : 4; | |
|
piman
2014/01/24 20:26:31
nit: you're not otherwise using readback_config_rg
sivag
2014/01/25 08:34:02
Done.
| |
| 562 ReadbackAsync(dst_size, | |
| 563 dst_size.width() * bytes_per_pixel, | |
| 564 dst_size.width() * bytes_per_pixel, | |
| 565 out, | |
| 566 config, | |
| 567 callback); | |
| 568 } | |
| 569 | |
| 532 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( | 570 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( |
| 533 GLuint src_texture, | 571 GLuint src_texture, |
| 534 const gfx::Size& src_size, | 572 const gfx::Size& src_size, |
| 535 const gfx::Size& dst_size, | 573 const gfx::Size& dst_size, |
| 536 bool vertically_flip_texture, | 574 bool vertically_flip_texture, |
| 537 GLHelper::ScalerQuality quality) { | 575 GLHelper::ScalerQuality quality) { |
| 538 return ScaleTexture(src_texture, | 576 return ScaleTexture(src_texture, |
| 539 src_size, | 577 src_size, |
| 540 gfx::Rect(src_size), | 578 gfx::Rect(src_size), |
| 541 dst_size, | 579 dst_size, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 } | 694 } |
| 657 | 695 |
| 658 void GLHelper::ReadbackTextureSync(GLuint texture, | 696 void GLHelper::ReadbackTextureSync(GLuint texture, |
| 659 const gfx::Rect& src_rect, | 697 const gfx::Rect& src_rect, |
| 660 unsigned char* out, | 698 unsigned char* out, |
| 661 SkBitmap::Config format) { | 699 SkBitmap::Config format) { |
| 662 InitCopyTextToImpl(); | 700 InitCopyTextToImpl(); |
| 663 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out, format); | 701 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out, format); |
| 664 } | 702 } |
| 665 | 703 |
| 704 void GLHelper::ReadbackTextureAsync( | |
| 705 GLuint texture, | |
| 706 const gfx::Size& dst_size, | |
| 707 unsigned char* out, | |
| 708 SkBitmap::Config config, | |
| 709 const base::Callback<void(bool)>& callback) { | |
| 710 InitCopyTextToImpl(); | |
| 711 copy_texture_to_impl_->ReadbackTextureAsync(texture, | |
| 712 dst_size, | |
| 713 out, | |
| 714 config, | |
| 715 callback); | |
| 716 } | |
| 717 | |
| 666 GLuint GLHelper::CopyTexture(GLuint texture, const gfx::Size& size) { | 718 GLuint GLHelper::CopyTexture(GLuint texture, const gfx::Size& size) { |
| 667 InitCopyTextToImpl(); | 719 InitCopyTextToImpl(); |
| 668 return copy_texture_to_impl_->CopyAndScaleTexture( | 720 return copy_texture_to_impl_->CopyAndScaleTexture( |
| 669 texture, size, size, false, GLHelper::SCALER_QUALITY_FAST); | 721 texture, size, size, false, GLHelper::SCALER_QUALITY_FAST); |
| 670 } | 722 } |
| 671 | 723 |
| 672 GLuint GLHelper::CopyAndScaleTexture(GLuint texture, | 724 GLuint GLHelper::CopyAndScaleTexture(GLuint texture, |
| 673 const gfx::Size& src_size, | 725 const gfx::Size& src_size, |
| 674 const gfx::Size& dst_size, | 726 const gfx::Size& dst_size, |
| 675 bool vertically_flip_texture, | 727 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, | 1238 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
| 1187 src_size, | 1239 src_size, |
| 1188 src_subrect, | 1240 src_subrect, |
| 1189 dst_size, | 1241 dst_size, |
| 1190 dst_subrect, | 1242 dst_subrect, |
| 1191 flip_vertically, | 1243 flip_vertically, |
| 1192 use_mrt); | 1244 use_mrt); |
| 1193 } | 1245 } |
| 1194 | 1246 |
| 1195 } // namespace content | 1247 } // namespace content |
| OLD | NEW |