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 bool readback_config_rgb565, | 130 bool readback_config_rgb565, |
| 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 bool readback_config_rgb565, | 151 bool readback_config_rgb565, |
| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 GL_UNSIGNED_BYTE; | 472 GL_UNSIGNED_BYTE; |
| 467 gl_->ReadPixels(src_rect.x(), | 473 gl_->ReadPixels(src_rect.x(), |
| 468 src_rect.y(), | 474 src_rect.y(), |
| 469 src_rect.width(), | 475 src_rect.width(), |
| 470 src_rect.height(), | 476 src_rect.height(), |
| 471 format, | 477 format, |
| 472 type, | 478 type, |
| 473 out); | 479 out); |
| 474 } | 480 } |
| 475 | 481 |
| 482 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( | |
| 483 GLuint texture, | |
| 484 const gfx::Size& dst_size, | |
| 485 unsigned char* out, | |
| 486 SkBitmap::Config config, | |
| 487 const base::Callback<void(bool)>& callback) { | |
|
piman
2014/01/23 20:43:57
Can you add DCHECKs on the supported formats?
sivag
2014/01/24 15:56:40
Done.
| |
| 488 ScopedFramebuffer dst_framebuffer(gl_); | |
| 489 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | |
| 490 dst_framebuffer); | |
| 491 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | |
| 492 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | |
| 493 GL_COLOR_ATTACHMENT0, | |
| 494 GL_TEXTURE_2D, | |
| 495 texture, | |
| 496 0); | |
| 497 int readback_config_rgb565 = (config == SkBitmap::kRGB_565_Config); | |
| 498 int bytes_per_pixel = readback_config_rgb565 ? 2 : 4; | |
| 499 ReadbackAsync(dst_size, | |
| 500 dst_size.width() * bytes_per_pixel, | |
| 501 dst_size.width() * bytes_per_pixel, | |
| 502 out, | |
| 503 readback_config_rgb565, | |
|
piman
2014/01/23 20:43:57
This would change when rebasing on top of your htt
sivag
2014/01/24 15:56:40
Thanks for sharing this tip :). As my branches are
| |
| 504 callback); | |
| 505 } | |
| 506 | |
| 476 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( | 507 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( |
| 477 GLuint src_texture, | 508 GLuint src_texture, |
| 478 const gfx::Size& src_size, | 509 const gfx::Size& src_size, |
| 479 const gfx::Size& dst_size, | 510 const gfx::Size& dst_size, |
| 480 bool vertically_flip_texture, | 511 bool vertically_flip_texture, |
| 481 GLHelper::ScalerQuality quality) { | 512 GLHelper::ScalerQuality quality) { |
| 482 return ScaleTexture(src_texture, | 513 return ScaleTexture(src_texture, |
| 483 src_size, | 514 src_size, |
| 484 gfx::Rect(src_size), | 515 gfx::Rect(src_size), |
| 485 dst_size, | 516 dst_size, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 } | 631 } |
| 601 | 632 |
| 602 void GLHelper::ReadbackTextureSync(GLuint texture, | 633 void GLHelper::ReadbackTextureSync(GLuint texture, |
| 603 const gfx::Rect& src_rect, | 634 const gfx::Rect& src_rect, |
| 604 unsigned char* out, | 635 unsigned char* out, |
| 605 SkBitmap::Config format) { | 636 SkBitmap::Config format) { |
| 606 InitCopyTextToImpl(); | 637 InitCopyTextToImpl(); |
| 607 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out, format); | 638 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out, format); |
| 608 } | 639 } |
| 609 | 640 |
| 641 void GLHelper::ReadbackTextureAsync( | |
| 642 GLuint texture, | |
| 643 const gfx::Size& dst_size, | |
| 644 unsigned char* out, | |
| 645 SkBitmap::Config config, | |
| 646 const base::Callback<void(bool)>& callback) { | |
| 647 InitCopyTextToImpl(); | |
| 648 copy_texture_to_impl_->ReadbackTextureAsync(texture, | |
| 649 dst_size, | |
| 650 out, | |
| 651 config, | |
| 652 callback); | |
| 653 } | |
| 654 | |
| 610 GLuint GLHelper::CopyTexture(GLuint texture, const gfx::Size& size) { | 655 GLuint GLHelper::CopyTexture(GLuint texture, const gfx::Size& size) { |
| 611 InitCopyTextToImpl(); | 656 InitCopyTextToImpl(); |
| 612 return copy_texture_to_impl_->CopyAndScaleTexture( | 657 return copy_texture_to_impl_->CopyAndScaleTexture( |
| 613 texture, size, size, false, GLHelper::SCALER_QUALITY_FAST); | 658 texture, size, size, false, GLHelper::SCALER_QUALITY_FAST); |
| 614 } | 659 } |
| 615 | 660 |
| 616 GLuint GLHelper::CopyAndScaleTexture(GLuint texture, | 661 GLuint GLHelper::CopyAndScaleTexture(GLuint texture, |
| 617 const gfx::Size& src_size, | 662 const gfx::Size& src_size, |
| 618 const gfx::Size& dst_size, | 663 const gfx::Size& dst_size, |
| 619 bool vertically_flip_texture, | 664 bool vertically_flip_texture, |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1130 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, | 1175 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
| 1131 src_size, | 1176 src_size, |
| 1132 src_subrect, | 1177 src_subrect, |
| 1133 dst_size, | 1178 dst_size, |
| 1134 dst_subrect, | 1179 dst_subrect, |
| 1135 flip_vertically, | 1180 flip_vertically, |
| 1136 use_mrt); | 1181 use_mrt); |
| 1137 } | 1182 } |
| 1138 | 1183 |
| 1139 } // namespace content | 1184 } // namespace content |
| OLD | NEW |