OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 7 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
8 | 8 |
9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #ifndef GL_GLEXT_PROTOTYPES | 10 #ifndef GL_GLEXT_PROTOTYPES |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 // creation attributes. | 809 // creation attributes. |
810 memcpy(scanline, row_b, row_bytes); | 810 memcpy(scanline, row_b, row_bytes); |
811 memcpy(row_b, row_a, row_bytes); | 811 memcpy(row_b, row_a, row_bytes); |
812 memcpy(row_a, scanline, row_bytes); | 812 memcpy(row_a, scanline, row_bytes); |
813 } | 813 } |
814 } | 814 } |
815 #endif | 815 #endif |
816 | 816 |
817 bool WebGraphicsContext3DInProcessCommandBufferImpl::readBackFramebuffer( | 817 bool WebGraphicsContext3DInProcessCommandBufferImpl::readBackFramebuffer( |
818 unsigned char* pixels, | 818 unsigned char* pixels, |
819 size_t buffer_size) { | 819 size_t buffer_size, |
| 820 WebGLId framebuffer, |
| 821 int width, |
| 822 int height) { |
820 // TODO(gmam): See if we can comment this in. | 823 // TODO(gmam): See if we can comment this in. |
821 // ClearContext(); | 824 // ClearContext(); |
822 if (buffer_size != static_cast<size_t>(4 * width() * height())) { | 825 if (buffer_size != static_cast<size_t>(4 * width * height)) { |
823 return false; | 826 return false; |
824 } | 827 } |
825 | 828 |
826 // Earlier versions of this code used the GPU to flip the | 829 // Earlier versions of this code used the GPU to flip the |
827 // framebuffer vertically before reading it back for compositing | 830 // framebuffer vertically before reading it back for compositing |
828 // via software. This code was quite complicated, used a lot of | 831 // via software. This code was quite complicated, used a lot of |
829 // GPU memory, and didn't provide an obvious speedup. Since this | 832 // GPU memory, and didn't provide an obvious speedup. Since this |
830 // vertical flip is only a temporary solution anyway until Chrome | 833 // vertical flip is only a temporary solution anyway until Chrome |
831 // is fully GPU composited, it wasn't worth the complexity. | 834 // is fully GPU composited, it wasn't worth the complexity. |
832 | 835 |
833 bool mustRestoreFBO = (bound_fbo_ != 0); | 836 bool mustRestoreFBO = (bound_fbo_ != framebuffer); |
834 if (mustRestoreFBO) { | 837 if (mustRestoreFBO) { |
835 gl_->BindFramebuffer(GL_FRAMEBUFFER, 0); | 838 gl_->BindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
836 } | 839 } |
837 gl_->ReadPixels(0, 0, cached_width_, cached_height_, | 840 gl_->ReadPixels(0, 0, width, height, |
838 GL_RGBA, GL_UNSIGNED_BYTE, pixels); | 841 GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
839 | 842 |
840 // Swizzle red and blue channels | 843 // Swizzle red and blue channels |
841 // TODO(kbr): expose GL_BGRA as extension | 844 // TODO(kbr): expose GL_BGRA as extension |
842 for (size_t i = 0; i < buffer_size; i += 4) { | 845 for (size_t i = 0; i < buffer_size; i += 4) { |
843 std::swap(pixels[i], pixels[i + 2]); | 846 std::swap(pixels[i], pixels[i + 2]); |
844 } | 847 } |
845 | 848 |
846 if (mustRestoreFBO) { | 849 if (mustRestoreFBO) { |
847 gl_->BindFramebuffer(GL_FRAMEBUFFER, bound_fbo_); | 850 gl_->BindFramebuffer(GL_FRAMEBUFFER, bound_fbo_); |
848 } | 851 } |
849 | 852 |
850 #ifdef FLIP_FRAMEBUFFER_VERTICALLY | 853 #ifdef FLIP_FRAMEBUFFER_VERTICALLY |
851 if (pixels) { | 854 if (pixels) { |
852 FlipVertically(pixels, cached_width_, cached_height_); | 855 FlipVertically(pixels, width, height); |
853 } | 856 } |
854 #endif | 857 #endif |
855 | 858 |
856 return true; | 859 return true; |
857 } | 860 } |
858 | 861 |
| 862 bool WebGraphicsContext3DInProcessCommandBufferImpl::readBackFramebuffer( |
| 863 unsigned char* pixels, |
| 864 size_t buffer_size) { |
| 865 return readBackFramebuffer(pixels, buffer_size, 0, width(), height()); |
| 866 } |
| 867 |
859 void WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError( | 868 void WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError( |
860 WGC3Denum error) { | 869 WGC3Denum error) { |
861 if (find(synthetic_errors_.begin(), synthetic_errors_.end(), error) == | 870 if (find(synthetic_errors_.begin(), synthetic_errors_.end(), error) == |
862 synthetic_errors_.end()) { | 871 synthetic_errors_.end()) { |
863 synthetic_errors_.push_back(error); | 872 synthetic_errors_.push_back(error); |
864 } | 873 } |
865 } | 874 } |
866 | 875 |
867 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferSubDataCHROMIUM( | 876 void* WebGraphicsContext3DInProcessCommandBufferImpl::mapBufferSubDataCHROMIUM( |
868 WGC3Denum target, | 877 WGC3Denum target, |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 if (context_lost_callback_) { | 1630 if (context_lost_callback_) { |
1622 context_lost_callback_->onContextLost(); | 1631 context_lost_callback_->onContextLost(); |
1623 } | 1632 } |
1624 } | 1633 } |
1625 | 1634 |
1626 } // namespace gpu | 1635 } // namespace gpu |
1627 } // namespace webkit | 1636 } // namespace webkit |
1628 | 1637 |
1629 #endif // defined(ENABLE_GPU) | 1638 #endif // defined(ENABLE_GPU) |
1630 | 1639 |
OLD | NEW |