Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.cc

Issue 1785483002: Handle UNPACK_SKIP_* and PACK_SKIP_* parameters on the client side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gpu/command_buffer/client/gles2_implementation_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // A class to emulate GLES2 over command buffers. 5 // A class to emulate GLES2 over command buffers.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 case GL_MINOR_VERSION: 951 case GL_MINOR_VERSION:
952 *params = capabilities_.minor_version; 952 *params = capabilities_.minor_version;
953 return true; 953 return true;
954 case GL_NUM_EXTENSIONS: 954 case GL_NUM_EXTENSIONS:
955 UpdateCachedExtensionsIfNeeded(); 955 UpdateCachedExtensionsIfNeeded();
956 *params = cached_extensions_.size(); 956 *params = cached_extensions_.size();
957 return true; 957 return true;
958 case GL_NUM_PROGRAM_BINARY_FORMATS: 958 case GL_NUM_PROGRAM_BINARY_FORMATS:
959 *params = capabilities_.num_program_binary_formats; 959 *params = capabilities_.num_program_binary_formats;
960 return true; 960 return true;
961 case GL_PACK_SKIP_PIXELS:
962 *params = pack_skip_pixels_;
963 return true;
964 case GL_PACK_SKIP_ROWS:
965 *params = pack_skip_rows_;
966 return true;
961 case GL_PIXEL_PACK_BUFFER_BINDING: 967 case GL_PIXEL_PACK_BUFFER_BINDING:
962 *params = bound_pixel_pack_buffer_; 968 *params = bound_pixel_pack_buffer_;
963 return true; 969 return true;
964 case GL_PIXEL_UNPACK_BUFFER_BINDING: 970 case GL_PIXEL_UNPACK_BUFFER_BINDING:
965 *params = bound_pixel_unpack_buffer_; 971 *params = bound_pixel_unpack_buffer_;
966 return true; 972 return true;
967 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: 973 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
968 *params = bound_transform_feedback_buffer_; 974 *params = bound_transform_feedback_buffer_;
969 return true; 975 return true;
970 case GL_UNIFORM_BUFFER_BINDING: 976 case GL_UNIFORM_BUFFER_BINDING:
971 *params = bound_uniform_buffer_; 977 *params = bound_uniform_buffer_;
972 return true; 978 return true;
973 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: 979 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
974 *params = capabilities_.uniform_buffer_offset_alignment; 980 *params = capabilities_.uniform_buffer_offset_alignment;
975 return true; 981 return true;
982 case GL_UNPACK_SKIP_IMAGES:
983 *params = unpack_skip_images_;
984 return true;
985 case GL_UNPACK_SKIP_PIXELS:
986 *params = unpack_skip_pixels_;
987 return true;
988 case GL_UNPACK_SKIP_ROWS:
989 *params = unpack_skip_rows_;
990 return true;
976 991
977 // Non-cached ES3 parameters. 992 // Non-cached ES3 parameters.
978 case GL_DRAW_BUFFER0: 993 case GL_DRAW_BUFFER0:
979 case GL_DRAW_BUFFER1: 994 case GL_DRAW_BUFFER1:
980 case GL_DRAW_BUFFER2: 995 case GL_DRAW_BUFFER2:
981 case GL_DRAW_BUFFER3: 996 case GL_DRAW_BUFFER3:
982 case GL_DRAW_BUFFER4: 997 case GL_DRAW_BUFFER4:
983 case GL_DRAW_BUFFER5: 998 case GL_DRAW_BUFFER5:
984 case GL_DRAW_BUFFER6: 999 case GL_DRAW_BUFFER6:
985 case GL_DRAW_BUFFER7: 1000 case GL_DRAW_BUFFER7:
986 case GL_DRAW_BUFFER8: 1001 case GL_DRAW_BUFFER8:
987 case GL_DRAW_BUFFER9: 1002 case GL_DRAW_BUFFER9:
988 case GL_DRAW_BUFFER10: 1003 case GL_DRAW_BUFFER10:
989 case GL_DRAW_BUFFER11: 1004 case GL_DRAW_BUFFER11:
990 case GL_DRAW_BUFFER12: 1005 case GL_DRAW_BUFFER12:
991 case GL_DRAW_BUFFER13: 1006 case GL_DRAW_BUFFER13:
992 case GL_DRAW_BUFFER14: 1007 case GL_DRAW_BUFFER14:
993 case GL_DRAW_BUFFER15: 1008 case GL_DRAW_BUFFER15:
994 case GL_DRAW_FRAMEBUFFER_BINDING: 1009 case GL_DRAW_FRAMEBUFFER_BINDING:
995 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: 1010 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
996 case GL_PACK_ROW_LENGTH: 1011 case GL_PACK_ROW_LENGTH:
997 case GL_PACK_SKIP_PIXELS:
998 case GL_PACK_SKIP_ROWS:
999 case GL_PRIMITIVE_RESTART_FIXED_INDEX: 1012 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1000 case GL_PROGRAM_BINARY_FORMATS: 1013 case GL_PROGRAM_BINARY_FORMATS:
1001 case GL_RASTERIZER_DISCARD: 1014 case GL_RASTERIZER_DISCARD:
1002 case GL_READ_BUFFER: 1015 case GL_READ_BUFFER:
1003 case GL_READ_FRAMEBUFFER_BINDING: 1016 case GL_READ_FRAMEBUFFER_BINDING:
1004 case GL_SAMPLER_BINDING: 1017 case GL_SAMPLER_BINDING:
1005 case GL_TEXTURE_BINDING_2D_ARRAY: 1018 case GL_TEXTURE_BINDING_2D_ARRAY:
1006 case GL_TEXTURE_BINDING_3D: 1019 case GL_TEXTURE_BINDING_3D:
1007 case GL_TRANSFORM_FEEDBACK_BINDING: 1020 case GL_TRANSFORM_FEEDBACK_BINDING:
1008 case GL_TRANSFORM_FEEDBACK_ACTIVE: 1021 case GL_TRANSFORM_FEEDBACK_ACTIVE:
1009 case GL_TRANSFORM_FEEDBACK_PAUSED: 1022 case GL_TRANSFORM_FEEDBACK_PAUSED:
1010 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: 1023 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
1011 case GL_TRANSFORM_FEEDBACK_BUFFER_START: 1024 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
1012 case GL_UNIFORM_BUFFER_SIZE: 1025 case GL_UNIFORM_BUFFER_SIZE:
1013 case GL_UNIFORM_BUFFER_START: 1026 case GL_UNIFORM_BUFFER_START:
1014 case GL_UNPACK_IMAGE_HEIGHT: 1027 case GL_UNPACK_IMAGE_HEIGHT:
1015 case GL_UNPACK_ROW_LENGTH: 1028 case GL_UNPACK_ROW_LENGTH:
1016 case GL_UNPACK_SKIP_IMAGES:
1017 case GL_UNPACK_SKIP_PIXELS:
1018 case GL_UNPACK_SKIP_ROWS:
1019 case GL_VERTEX_ARRAY_BINDING: 1029 case GL_VERTEX_ARRAY_BINDING:
1020 return false; 1030 return false;
1021 default: 1031 default:
1022 return false; 1032 return false;
1023 } 1033 }
1024 } 1034 }
1025 1035
1026 bool GLES2Implementation::GetBooleanvHelper(GLenum pname, GLboolean* params) { 1036 bool GLES2Implementation::GetBooleanvHelper(GLenum pname, GLboolean* params) {
1027 // TODO(gman): Make this handle pnames that return more than 1 value. 1037 // TODO(gman): Make this handle pnames that return more than 1 value.
1028 GLint value; 1038 GLint value;
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
1757 buffer.offset() + shader_id_size, 1767 buffer.offset() + shader_id_size,
1758 length); 1768 length);
1759 CheckGLError(); 1769 CheckGLError();
1760 } 1770 }
1761 1771
1762 void GLES2Implementation::PixelStorei(GLenum pname, GLint param) { 1772 void GLES2Implementation::PixelStorei(GLenum pname, GLint param) {
1763 GPU_CLIENT_SINGLE_THREAD_CHECK(); 1773 GPU_CLIENT_SINGLE_THREAD_CHECK();
1764 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glPixelStorei(" 1774 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glPixelStorei("
1765 << GLES2Util::GetStringPixelStore(pname) << ", " 1775 << GLES2Util::GetStringPixelStore(pname) << ", "
1766 << param << ")"); 1776 << param << ")");
1777 // We have to validate before caching these parameters because we use them
1778 // to compute image sizes on the client side.
1779 switch (pname) {
1780 case GL_PACK_ALIGNMENT:
1781 case GL_UNPACK_ALIGNMENT:
1782 if (param != 1 && param != 2 && param != 4 && param != 8) {
1783 SetGLError(GL_INVALID_VALUE, "glPixelStorei", "invalid param");
1784 return;
1785 }
1786 break;
1787 case GL_PACK_ROW_LENGTH:
1788 case GL_PACK_SKIP_PIXELS:
1789 case GL_PACK_SKIP_ROWS:
1790 case GL_UNPACK_IMAGE_HEIGHT:
1791 case GL_UNPACK_SKIP_IMAGES:
1792 if (capabilities_.major_version < 3) {
1793 SetGLError(GL_INVALID_ENUM, "glPixelStorei", "invalid pname");
1794 return;
1795 }
1796 if (param < 0) {
1797 SetGLError(GL_INVALID_VALUE, "glPixelStorei", "invalid param");
1798 return;
1799 }
1800 break;
1801 case GL_UNPACK_ROW_LENGTH:
1802 case GL_UNPACK_SKIP_ROWS:
1803 case GL_UNPACK_SKIP_PIXELS:
1804 // These parameters are always enabled in ES2 by EXT_unpack_subimage.
1805 if (param < 0) {
1806 SetGLError(GL_INVALID_VALUE, "glPixelStorei", "invalid param");
1807 return;
1808 }
1809 break;
1810 default:
1811 SetGLError(GL_INVALID_ENUM, "glPixelStorei", "invalid pname");
1812 return;
1813 }
1814 // Do not send SKIP parameters to the service side.
1815 // Handle them on the client side.
1767 switch (pname) { 1816 switch (pname) {
1768 case GL_PACK_ALIGNMENT: 1817 case GL_PACK_ALIGNMENT:
1769 pack_alignment_ = param; 1818 pack_alignment_ = param;
1770 break; 1819 break;
1771 case GL_PACK_ROW_LENGTH: 1820 case GL_PACK_ROW_LENGTH:
1772 pack_row_length_ = param; 1821 pack_row_length_ = param;
1773 break; 1822 break;
1774 case GL_PACK_SKIP_PIXELS: 1823 case GL_PACK_SKIP_PIXELS:
1775 pack_skip_pixels_ = param; 1824 pack_skip_pixels_ = param;
1776 break; 1825 return;
1777 case GL_PACK_SKIP_ROWS: 1826 case GL_PACK_SKIP_ROWS:
1778 pack_skip_rows_ = param; 1827 pack_skip_rows_ = param;
1779 break; 1828 return;
1780 case GL_UNPACK_ALIGNMENT: 1829 case GL_UNPACK_ALIGNMENT:
1781 unpack_alignment_ = param; 1830 unpack_alignment_ = param;
1782 break; 1831 break;
1783 case GL_UNPACK_ROW_LENGTH_EXT: 1832 case GL_UNPACK_ROW_LENGTH:
1784 unpack_row_length_ = param; 1833 unpack_row_length_ = param;
1834 if (capabilities_.major_version < 3) {
1835 // In ES2 with EXT_unpack_subimage, it's handled on the client side
1836 // and there is no need to send it to the service side.
1837 return;
1838 }
1785 break; 1839 break;
1786 case GL_UNPACK_IMAGE_HEIGHT: 1840 case GL_UNPACK_IMAGE_HEIGHT:
1787 unpack_image_height_ = param; 1841 unpack_image_height_ = param;
1788 break; 1842 break;
1789 case GL_UNPACK_SKIP_ROWS_EXT: 1843 case GL_UNPACK_SKIP_ROWS:
1790 unpack_skip_rows_ = param; 1844 unpack_skip_rows_ = param;
1791 break; 1845 return;
1792 case GL_UNPACK_SKIP_PIXELS_EXT: 1846 case GL_UNPACK_SKIP_PIXELS:
1793 unpack_skip_pixels_ = param; 1847 unpack_skip_pixels_ = param;
1794 break; 1848 return;
1795 case GL_UNPACK_SKIP_IMAGES: 1849 case GL_UNPACK_SKIP_IMAGES:
1796 unpack_skip_images_ = param; 1850 unpack_skip_images_ = param;
1797 break; 1851 return;
1798 default: 1852 default:
1853 NOTREACHED();
1799 break; 1854 break;
1800 } 1855 }
1801 helper_->PixelStorei(pname, param); 1856 helper_->PixelStorei(pname, param);
1802 CheckGLError(); 1857 CheckGLError();
1803 } 1858 }
1804 1859
1805 void GLES2Implementation::VertexAttribIPointer( 1860 void GLES2Implementation::VertexAttribIPointer(
1806 GLuint index, GLint size, GLenum type, GLsizei stride, const void* ptr) { 1861 GLuint index, GLint size, GLenum type, GLsizei stride, const void* ptr) {
1807 GPU_CLIENT_SINGLE_THREAD_CHECK(); 1862 GPU_CLIENT_SINGLE_THREAD_CHECK();
1808 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glVertexAttribIPointer(" 1863 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glVertexAttribIPointer("
(...skipping 1731 matching lines...) Expand 10 before | Expand all | Expand 10 after
3540 3595
3541 // glReadPixel pads the size of each row of pixels by an amount specified by 3596 // glReadPixel pads the size of each row of pixels by an amount specified by
3542 // glPixelStorei. So, we have to take that into account both in the fact that 3597 // glPixelStorei. So, we have to take that into account both in the fact that
3543 // the pixels returned from the ReadPixel command will include that padding 3598 // the pixels returned from the ReadPixel command will include that padding
3544 // and that when we copy the results to the user's buffer we need to not 3599 // and that when we copy the results to the user's buffer we need to not
3545 // write those padding bytes but leave them as they are. 3600 // write those padding bytes but leave them as they are.
3546 3601
3547 TRACE_EVENT0("gpu", "GLES2::ReadPixels"); 3602 TRACE_EVENT0("gpu", "GLES2::ReadPixels");
3548 typedef cmds::ReadPixels::Result Result; 3603 typedef cmds::ReadPixels::Result Result;
3549 3604
3550 if (bound_pixel_pack_buffer_) {
3551 GLuint offset = ToGLuint(pixels);
3552 helper_->ReadPixels(
3553 xoffset, yoffset, width, height, format, type, 0, offset, 0, 0, false);
3554 CheckGLError();
3555 return;
3556 }
3557
3558 uint32_t size; 3605 uint32_t size;
3559 uint32_t unpadded_row_size; 3606 uint32_t unpadded_row_size;
3560 uint32_t padded_row_size; 3607 uint32_t padded_row_size;
3561 uint32_t skip_size; 3608 uint32_t skip_size;
3562 PixelStoreParams params; 3609 PixelStoreParams params;
3563 params.alignment = pack_alignment_; 3610 params.alignment = pack_alignment_;
3564 params.row_length = pack_row_length_; 3611 params.row_length = pack_row_length_;
3565 params.skip_pixels = pack_skip_pixels_; 3612 params.skip_pixels = pack_skip_pixels_;
3566 params.skip_rows = pack_skip_rows_; 3613 params.skip_rows = pack_skip_rows_;
3567 if (!GLES2Util::ComputeImageDataSizesES3(width, height, 1, 3614 if (!GLES2Util::ComputeImageDataSizesES3(width, height, 1,
3568 format, type, 3615 format, type,
3569 params, 3616 params,
3570 &size, 3617 &size,
3571 &unpadded_row_size, 3618 &unpadded_row_size,
3572 &padded_row_size, 3619 &padded_row_size,
3573 &skip_size, 3620 &skip_size,
3574 nullptr)) { 3621 nullptr)) {
3575 SetGLError(GL_INVALID_VALUE, "glReadPixels", "size too large."); 3622 SetGLError(GL_INVALID_VALUE, "glReadPixels", "size too large.");
3576 return; 3623 return;
3577 } 3624 }
3625
3626 if (bound_pixel_pack_buffer_) {
3627 base::CheckedNumeric<GLuint> offset = ToGLuint(pixels);
3628 offset += skip_size;
3629 if (!offset.IsValid()) {
3630 SetGLError(GL_INVALID_VALUE, "glReadPixels", "skip size too large.");
3631 return;
3632 }
3633 helper_->ReadPixels(xoffset, yoffset, width, height, format, type, 0,
3634 offset.ValueOrDefault(0), 0, 0, false);
3635 CheckGLError();
3636 return;
3637 }
3638
3578 uint32_t service_padded_row_size = 0; 3639 uint32_t service_padded_row_size = 0;
3579 if (pack_row_length_ > 0 && pack_row_length_ != width) { 3640 if (pack_row_length_ > 0 && pack_row_length_ != width) {
3580 if (!GLES2Util::ComputeImagePaddedRowSize(width, 3641 if (!GLES2Util::ComputeImagePaddedRowSize(width,
3581 format, type, 3642 format, type,
3582 pack_alignment_, 3643 pack_alignment_,
3583 &service_padded_row_size)) { 3644 &service_padded_row_size)) {
3584 SetGLError(GL_INVALID_VALUE, "glReadPixels", "size too large."); 3645 SetGLError(GL_INVALID_VALUE, "glReadPixels", "size too large.");
3585 return; 3646 return;
3586 } 3647 }
3587 } else { 3648 } else {
3588 service_padded_row_size = padded_row_size; 3649 service_padded_row_size = padded_row_size;
3589 } 3650 }
3590 3651
3591 if (bound_pixel_pack_transfer_buffer_id_) { 3652 if (bound_pixel_pack_transfer_buffer_id_) {
3592 if (pack_row_length_ > 0 || pack_skip_pixels_ > 0 || pack_skip_rows_ > 0) { 3653 if (pack_row_length_ > 0 || pack_skip_pixels_ > 0 || pack_skip_rows_ > 0) {
3593 SetGLError(GL_INVALID_OPERATION, "glReadPixels", 3654 SetGLError(GL_INVALID_OPERATION, "glReadPixels",
3594 "No ES3 pack parameters with pixel pack transfer buffer."); 3655 "No ES3 pack parameters with pixel pack transfer buffer.");
3595 return; 3656 return;
3596 } 3657 }
3597 DCHECK_EQ(0u, skip_size); 3658 DCHECK_EQ(0u, skip_size);
3598 GLuint offset = ToGLuint(pixels); 3659 GLuint offset = ToGLuint(pixels);
3599 BufferTracker::Buffer* buffer = GetBoundPixelUnpackTransferBufferIfValid( 3660 BufferTracker::Buffer* buffer = GetBoundPixelUnpackTransferBufferIfValid(
3600 bound_pixel_pack_transfer_buffer_id_, "glReadPixels", offset, size); 3661 bound_pixel_pack_transfer_buffer_id_, "glReadPixels", offset, size);
3601 if (buffer && buffer->shm_id() != -1) { 3662 if (buffer && buffer->shm_id() != -1) {
3602 helper_->ReadPixels(xoffset, yoffset, width, height, format, type, 3663 helper_->ReadPixels(xoffset, yoffset, width, height, format, type,
3603 buffer->shm_id(), buffer->shm_offset(), 3664 buffer->shm_id(), buffer->shm_offset() + offset,
3604 0, 0, true); 3665 0, 0, true);
3605 CheckGLError(); 3666 CheckGLError();
3606 } 3667 }
3607 return; 3668 return;
3608 } 3669 }
3609 3670
3610 if (!pixels) { 3671 if (!pixels) {
3611 SetGLError(GL_INVALID_OPERATION, "glReadPixels", "pixels = NULL"); 3672 SetGLError(GL_INVALID_OPERATION, "glReadPixels", "pixels = NULL");
3612 return; 3673 return;
3613 } 3674 }
(...skipping 2960 matching lines...) Expand 10 before | Expand all | Expand 10 after
6574 cached_extensions_.clear(); 6635 cached_extensions_.clear();
6575 } 6636 }
6576 6637
6577 // Include the auto-generated part of this file. We split this because it means 6638 // Include the auto-generated part of this file. We split this because it means
6578 // we can easily edit the non-auto generated parts right here in this file 6639 // we can easily edit the non-auto generated parts right here in this file
6579 // instead of having to edit some template or the code generator. 6640 // instead of having to edit some template or the code generator.
6580 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" 6641 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h"
6581 6642
6582 } // namespace gles2 6643 } // namespace gles2
6583 } // namespace gpu 6644 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/client/gles2_implementation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698