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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 1566283003: Upgrade blink side ReadPixels size validation to consider ES3 pack parameters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 3788 matching lines...) Expand 10 before | Expand all | Expand 10 after
3799 case GL_FLOAT: 3799 case GL_FLOAT:
3800 return DOMArrayBufferView::TypeFloat32; 3800 return DOMArrayBufferView::TypeFloat32;
3801 case GL_HALF_FLOAT_OES: 3801 case GL_HALF_FLOAT_OES:
3802 return DOMArrayBufferView::TypeUint16; 3802 return DOMArrayBufferView::TypeUint16;
3803 default: 3803 default:
3804 ASSERT_NOT_REACHED(); 3804 ASSERT_NOT_REACHED();
3805 return DOMArrayBufferView::TypeUint8; 3805 return DOMArrayBufferView::TypeUint8;
3806 } 3806 }
3807 } 3807 }
3808 3808
3809 WebGLImageConversion::PixelStoreParams WebGLRenderingContextBase::getPackPixelSt oreParams()
3810 {
3811 WebGLImageConversion::PixelStoreParams params;
3812 params.alignment = m_packAlignment;
3813 return params;
3814 }
3815
3816 WebGLImageConversion::PixelStoreParams WebGLRenderingContextBase::getUnpackPixel StoreParams()
3817 {
3818 WebGLImageConversion::PixelStoreParams params;
3819 params.alignment = m_unpackAlignment;
3820 return params;
3821 }
3822
3809 bool WebGLRenderingContextBase::validateReadPixelsFuncParameters(GLsizei width, GLsizei height, GLenum format, GLenum type, long long bufferSize) 3823 bool WebGLRenderingContextBase::validateReadPixelsFuncParameters(GLsizei width, GLsizei height, GLenum format, GLenum type, long long bufferSize)
3810 { 3824 {
3811 if (!validateReadPixelsFormatAndType(format, type)) 3825 if (!validateReadPixelsFormatAndType(format, type))
3812 return false; 3826 return false;
3813 WebGLFramebuffer* readFramebufferBinding = nullptr; 3827 WebGLFramebuffer* readFramebufferBinding = nullptr;
3814 GLenum readBufferInternalFormat = 0, readBufferType = 0; 3828 GLenum readBufferInternalFormat = 0, readBufferType = 0;
3815 if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &rea dBufferInternalFormat, &readBufferType)) 3829 if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &rea dBufferInternalFormat, &readBufferType))
3816 return false; 3830 return false;
3817 if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInterna lFormat, readBufferType)) 3831 if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInterna lFormat, readBufferType))
3818 return false; 3832 return false;
3819 3833
3820 // Calculate array size, taking into consideration of PACK_ALIGNMENT. 3834 // Calculate array size, taking into consideration of pack parameters.
3821 unsigned totalBytesRequired = 0; 3835 unsigned totalBytesRequired = 0, totalSkipBytes = 0;
3822 unsigned padding = 0; 3836 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, 1, getPackPixelStoreParams(), &totalBytesRequired, 0, &totalSkipBy tes);
3823 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, 1, m_packAlignment, &totalBytesRequired, &padding);
3824 if (error != GL_NO_ERROR) { 3837 if (error != GL_NO_ERROR) {
3825 synthesizeGLError(error, "readPixels", "invalid dimensions"); 3838 synthesizeGLError(error, "readPixels", "invalid dimensions");
3826 return false; 3839 return false;
3827 } 3840 }
3828 if (bufferSize < static_cast<long long>(totalBytesRequired)) { 3841 if (bufferSize < static_cast<long long>(totalBytesRequired + totalSkipBytes) ) {
3829 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "buffer is not lar ge enough for dimensions"); 3842 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "buffer is not lar ge enough for dimensions");
3830 return false; 3843 return false;
3831 } 3844 }
3832 return true; 3845 return true;
3833 } 3846 }
3834 3847
3835 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, DOMArrayBufferView* pixels) 3848 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, DOMArrayBufferView* pixels)
3836 { 3849 {
3837 if (isContextLost()) 3850 if (isContextLost())
3838 return; 3851 return;
(...skipping 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after
5855 if (pixels->type() != DOMArrayBufferView::TypeUint16) { 5868 if (pixels->type() != DOMArrayBufferView::TypeUint16) {
5856 synthesizeGLError(GL_INVALID_OPERATION, functionName, "type HALF_FLO AT_OES but ArrayBufferView is not NULL and not Uint16Array"); 5869 synthesizeGLError(GL_INVALID_OPERATION, functionName, "type HALF_FLO AT_OES but ArrayBufferView is not NULL and not Uint16Array");
5857 return false; 5870 return false;
5858 } 5871 }
5859 break; 5872 break;
5860 default: 5873 default:
5861 ASSERT_NOT_REACHED(); 5874 ASSERT_NOT_REACHED();
5862 } 5875 }
5863 5876
5864 unsigned totalBytesRequired; 5877 unsigned totalBytesRequired;
5865 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, depth, m_unpackAlignment, &totalBytesRequired, 0); 5878 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, depth, getUnpackPixelStoreParams(), &totalBytesRequired, 0, 0);
5866 if (error != GL_NO_ERROR) { 5879 if (error != GL_NO_ERROR) {
5867 synthesizeGLError(error, functionName, "invalid texture dimensions"); 5880 synthesizeGLError(error, functionName, "invalid texture dimensions");
5868 return false; 5881 return false;
5869 } 5882 }
5870 if (pixels->byteLength() < totalBytesRequired) { 5883 if (pixels->byteLength() < totalBytesRequired) {
5871 if (m_unpackAlignment != 1) {
5872 error = WebGLImageConversion::computeImageSizeInBytes(format, type, width, height, depth, 1, &totalBytesRequired, 0);
5873 if (pixels->byteLength() == totalBytesRequired) {
5874 synthesizeGLError(GL_INVALID_OPERATION, functionName, "ArrayBuff erView not big enough for request with UNPACK_ALIGNMENT > 1");
5875 return false;
5876 }
5877 }
5878 synthesizeGLError(GL_INVALID_OPERATION, functionName, "ArrayBufferView n ot big enough for request"); 5884 synthesizeGLError(GL_INVALID_OPERATION, functionName, "ArrayBufferView n ot big enough for request");
5879 return false; 5885 return false;
5880 } 5886 }
5881 return true; 5887 return true;
5882 } 5888 }
5883 5889
5884 bool WebGLRenderingContextBase::validateCopyTexSubImage(const char* functionName , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) 5890 bool WebGLRenderingContextBase::validateCopyTexSubImage(const char* functionName , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
5885 { 5891 {
5886 if (!validateTexFuncLevel(functionName, target, level)) 5892 if (!validateTexFuncLevel(functionName, target, level))
5887 return false; 5893 return false;
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
6931 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 6937 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
6932 } 6938 }
6933 6939
6934 void WebGLRenderingContextBase::restoreUnpackParameters() 6940 void WebGLRenderingContextBase::restoreUnpackParameters()
6935 { 6941 {
6936 if (m_unpackAlignment != 1) 6942 if (m_unpackAlignment != 1)
6937 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6943 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6938 } 6944 }
6939 6945
6940 } // namespace blink 6946 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698