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

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

Issue 2370703003: Validate internalformat/format/type for uploading DOM elements to texture (Closed)
Patch Set: fix extension Created 4 years, 2 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 | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 GL_RGBA8_SNORM, 767 GL_RGBA8_SNORM,
768 GL_RGBA16F, 768 GL_RGBA16F,
769 GL_RGBA32F, 769 GL_RGBA32F,
770 GL_DEPTH_COMPONENT16, 770 GL_DEPTH_COMPONENT16,
771 GL_DEPTH_COMPONENT24, 771 GL_DEPTH_COMPONENT24,
772 GL_DEPTH_COMPONENT32F, 772 GL_DEPTH_COMPONENT32F,
773 GL_DEPTH24_STENCIL8, 773 GL_DEPTH24_STENCIL8,
774 GL_DEPTH32F_STENCIL8, 774 GL_DEPTH32F_STENCIL8,
775 }; 775 };
776 776
777 // ES3 enums supported by TexImageSource
778 static const GLenum kSupportedInternalFormatsTexImageSourceES3[] = {
779 GL_R8,
780 GL_R16F,
781 GL_R32F,
782 GL_R8UI,
783 GL_RG8,
784 GL_RG16F,
785 GL_RG32F,
786 GL_RG8UI,
787 GL_RGB8,
788 GL_SRGB8,
789 GL_RGB565,
790 GL_R11F_G11F_B10F,
791 GL_RGB9_E5,
792 GL_RGB16F,
793 GL_RGB32F,
794 GL_RGB8UI,
795 GL_RGBA8,
796 GL_SRGB8_ALPHA8,
797 GL_RGB5_A1,
798 GL_RGBA4,
799 GL_RGBA16F,
800 GL_RGBA32F,
801 GL_RGBA8UI,
802 };
803
777 // ES2 enums 804 // ES2 enums
778 static const GLenum kSupportedFormatsES2[] = { 805 static const GLenum kSupportedFormatsES2[] = {
779 GL_RGB, 806 GL_RGB,
780 GL_RGBA, 807 GL_RGBA,
781 GL_LUMINANCE_ALPHA, 808 GL_LUMINANCE_ALPHA,
782 GL_LUMINANCE, 809 GL_LUMINANCE,
783 GL_ALPHA, 810 GL_ALPHA,
784 }; 811 };
785 812
786 // Exposed by GL_ANGLE_depth_texture 813 // Exposed by GL_ANGLE_depth_texture
(...skipping 15 matching lines...) Expand all
802 GL_RG, 829 GL_RG,
803 GL_RG_INTEGER, 830 GL_RG_INTEGER,
804 GL_RGB, 831 GL_RGB,
805 GL_RGB_INTEGER, 832 GL_RGB_INTEGER,
806 GL_RGBA, 833 GL_RGBA,
807 GL_RGBA_INTEGER, 834 GL_RGBA_INTEGER,
808 GL_DEPTH_COMPONENT, 835 GL_DEPTH_COMPONENT,
809 GL_DEPTH_STENCIL, 836 GL_DEPTH_STENCIL,
810 }; 837 };
811 838
839 // ES3 enums supported by TexImageSource
840 static const GLenum kSupportedFormatsTexImageSourceES3[] = {
841 GL_RED,
842 GL_RED_INTEGER,
843 GL_RG,
844 GL_RG_INTEGER,
845 GL_RGB,
846 GL_RGB_INTEGER,
847 GL_RGBA,
848 GL_RGBA_INTEGER,
849 };
850
812 // ES2 enums 851 // ES2 enums
813 static const GLenum kSupportedTypesES2[] = { 852 static const GLenum kSupportedTypesES2[] = {
814 GL_UNSIGNED_BYTE, 853 GL_UNSIGNED_BYTE,
815 GL_UNSIGNED_SHORT_5_6_5, 854 GL_UNSIGNED_SHORT_5_6_5,
816 GL_UNSIGNED_SHORT_4_4_4_4, 855 GL_UNSIGNED_SHORT_4_4_4_4,
817 GL_UNSIGNED_SHORT_5_5_5_1, 856 GL_UNSIGNED_SHORT_5_5_5_1,
818 }; 857 };
819 858
820 // Exposed by GL_OES_texture_float 859 // Exposed by GL_OES_texture_float
821 static const GLenum kSupportedTypesOESTexFloat[] = { 860 static const GLenum kSupportedTypesOESTexFloat[] = {
(...skipping 21 matching lines...) Expand all
843 GL_INT, 882 GL_INT,
844 GL_HALF_FLOAT, 883 GL_HALF_FLOAT,
845 GL_FLOAT, 884 GL_FLOAT,
846 GL_UNSIGNED_INT_2_10_10_10_REV, 885 GL_UNSIGNED_INT_2_10_10_10_REV,
847 GL_UNSIGNED_INT_10F_11F_11F_REV, 886 GL_UNSIGNED_INT_10F_11F_11F_REV,
848 GL_UNSIGNED_INT_5_9_9_9_REV, 887 GL_UNSIGNED_INT_5_9_9_9_REV,
849 GL_UNSIGNED_INT_24_8, 888 GL_UNSIGNED_INT_24_8,
850 GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 889 GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
851 }; 890 };
852 891
892 // ES3 enums supported by TexImageSource
893 static const GLenum kSupportedTypesTexImageSourceES3[] = {
894 GL_UNSIGNED_SHORT,
895 GL_SHORT,
896 GL_UNSIGNED_INT,
897 GL_INT,
Ken Russell (switch to Gerrit) 2016/10/01 03:52:05 From the table for texImage2D taking TexImageSourc
qiankun 2016/10/01 14:27:30 Yes. These types are excluded. Thanks.
898 GL_HALF_FLOAT,
899 GL_FLOAT,
900 GL_UNSIGNED_INT_10F_11F_11F_REV,
901 };
902
853 bool isUnsignedIntegerFormat(GLenum internalformat) 903 bool isUnsignedIntegerFormat(GLenum internalformat)
854 { 904 {
855 switch (internalformat) { 905 switch (internalformat) {
856 case GL_R8UI: 906 case GL_R8UI:
857 case GL_R16UI: 907 case GL_R16UI:
858 case GL_R32UI: 908 case GL_R32UI:
859 case GL_RG8UI: 909 case GL_RG8UI:
860 case GL_RG16UI: 910 case GL_RG16UI:
861 case GL_RG32UI: 911 case GL_RG32UI:
862 case GL_RGB8UI: 912 case GL_RGB8UI:
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 , m_contextLostMode(NotLostContext) 996 , m_contextLostMode(NotLostContext)
947 , m_autoRecoveryMethod(Manual) 997 , m_autoRecoveryMethod(Manual)
948 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) 998 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent)
949 , m_restoreAllowed(false) 999 , m_restoreAllowed(false)
950 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) 1000 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
951 , m_generatedImageCache(4) 1001 , m_generatedImageCache(4)
952 , m_synthesizedErrorsToConsole(true) 1002 , m_synthesizedErrorsToConsole(true)
953 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) 1003 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
954 , m_onePlusMaxNonDefaultTextureUnit(0) 1004 , m_onePlusMaxNonDefaultTextureUnit(0)
955 , m_isWebGL2FormatsTypesAdded(false) 1005 , m_isWebGL2FormatsTypesAdded(false)
1006 , m_isWebGL2TexImageSourceFormatsTypesAdded(false)
956 , m_isWebGL2InternalFormatsCopyTexImageAdded(false) 1007 , m_isWebGL2InternalFormatsCopyTexImageAdded(false)
957 , m_isOESTextureFloatFormatsTypesAdded(false) 1008 , m_isOESTextureFloatFormatsTypesAdded(false)
958 , m_isOESTextureHalfFloatFormatsTypesAdded(false) 1009 , m_isOESTextureHalfFloatFormatsTypesAdded(false)
959 , m_isWebGLDepthTextureFormatsTypesAdded(false) 1010 , m_isWebGLDepthTextureFormatsTypesAdded(false)
960 , m_isEXTsRGBFormatsTypesAdded(false) 1011 , m_isEXTsRGBFormatsTypesAdded(false)
961 , m_version(version) 1012 , m_version(version)
962 { 1013 {
963 ASSERT(contextProvider); 1014 ASSERT(contextProvider);
964 1015
965 m_contextGroup = WebGLContextGroup::create(); 1016 m_contextGroup = WebGLContextGroup::create();
(...skipping 12 matching lines...) Expand all
978 m_drawingBuffer->addNewMailboxCallback(WTF::bind(&WebGLRenderingContextBase: :notifyCanvasContextChanged, wrapWeakPersistent(this))); 1029 m_drawingBuffer->addNewMailboxCallback(WTF::bind(&WebGLRenderingContextBase: :notifyCanvasContextChanged, wrapWeakPersistent(this)));
979 drawingBuffer()->bind(GL_FRAMEBUFFER); 1030 drawingBuffer()->bind(GL_FRAMEBUFFER);
980 setupFlags(); 1031 setupFlags();
981 1032
982 #define ADD_VALUES_TO_SET(set, values) \ 1033 #define ADD_VALUES_TO_SET(set, values) \
983 for (size_t i = 0; i < WTF_ARRAY_LENGTH(values); ++i) { \ 1034 for (size_t i = 0; i < WTF_ARRAY_LENGTH(values); ++i) { \
984 set.insert(values[i]); \ 1035 set.insert(values[i]); \
985 } 1036 }
986 1037
987 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); 1038 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2);
1039 ADD_VALUES_TO_SET(m_supportedTexImageSourceInternalFormats, kSupportedIntern alFormatsES2);
Ken Russell (switch to Gerrit) 2016/10/01 03:52:05 Minor nit: kSupportedInternalFormatsES2 is redunda
qiankun 2016/10/01 14:27:30 Right, they are same. Removed kSupportedInternalFo
988 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2); 1040 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2);
989 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); 1041 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2);
1042 ADD_VALUES_TO_SET(m_supportedTexImageSourceFormats, kSupportedFormatsES2);
990 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); 1043 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2);
1044 ADD_VALUES_TO_SET(m_supportedTexImageSourceTypes, kSupportedTypesES2);
991 } 1045 }
992 1046
993 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(std::un ique_ptr<WebGraphicsContext3DProvider> contextProvider) 1047 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(std::un ique_ptr<WebGraphicsContext3DProvider> contextProvider)
994 { 1048 {
995 bool premultipliedAlpha = creationAttributes().premultipliedAlpha(); 1049 bool premultipliedAlpha = creationAttributes().premultipliedAlpha();
996 bool wantAlphaChannel = creationAttributes().alpha(); 1050 bool wantAlphaChannel = creationAttributes().alpha();
997 bool wantDepthBuffer = creationAttributes().depth(); 1051 bool wantDepthBuffer = creationAttributes().depth();
998 bool wantStencilBuffer = creationAttributes().stencil(); 1052 bool wantStencilBuffer = creationAttributes().stencil();
999 bool wantAntialiasing = creationAttributes().antialias(); 1053 bool wantAntialiasing = creationAttributes().antialias();
1000 DrawingBuffer::PreserveDrawingBuffer preserve = creationAttributes().preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 1054 DrawingBuffer::PreserveDrawingBuffer preserve = creationAttributes().preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 if (isWebGL2OrHigher()) 1167 if (isWebGL2OrHigher())
1114 contextGL()->Enable(GL_PRIMITIVE_RESTART_FIXED_INDEX); 1168 contextGL()->Enable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
1115 1169
1116 // This ensures that the context has a valid "lastFlushID" and won't be mist akenly identified as the "least recently used" context. 1170 // This ensures that the context has a valid "lastFlushID" and won't be mist akenly identified as the "least recently used" context.
1117 contextGL()->Flush(); 1171 contextGL()->Flush();
1118 1172
1119 for (int i = 0; i < WebGLExtensionNameCount; ++i) 1173 for (int i = 0; i < WebGLExtensionNameCount; ++i)
1120 m_extensionEnabled[i] = false; 1174 m_extensionEnabled[i] = false;
1121 1175
1122 m_isWebGL2FormatsTypesAdded = false; 1176 m_isWebGL2FormatsTypesAdded = false;
1177 m_isWebGL2TexImageSourceFormatsTypesAdded = false;
1123 m_isWebGL2InternalFormatsCopyTexImageAdded = false; 1178 m_isWebGL2InternalFormatsCopyTexImageAdded = false;
1124 m_isOESTextureFloatFormatsTypesAdded = false; 1179 m_isOESTextureFloatFormatsTypesAdded = false;
1125 m_isOESTextureHalfFloatFormatsTypesAdded = false; 1180 m_isOESTextureHalfFloatFormatsTypesAdded = false;
1126 m_isWebGLDepthTextureFormatsTypesAdded = false; 1181 m_isWebGLDepthTextureFormatsTypesAdded = false;
1127 m_isEXTsRGBFormatsTypesAdded = false; 1182 m_isEXTsRGBFormatsTypesAdded = false;
1128 1183
1129 m_supportedInternalFormats.clear(); 1184 m_supportedInternalFormats.clear();
1130 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); 1185 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2);
1186 m_supportedTexImageSourceInternalFormats.clear();
1187 ADD_VALUES_TO_SET(m_supportedTexImageSourceInternalFormats, kSupportedIntern alFormatsES2);
1131 m_supportedInternalFormatsCopyTexImage.clear(); 1188 m_supportedInternalFormatsCopyTexImage.clear();
1132 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2); 1189 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2);
1133 m_supportedFormats.clear(); 1190 m_supportedFormats.clear();
1134 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); 1191 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2);
1192 m_supportedTexImageSourceFormats.clear();
1193 ADD_VALUES_TO_SET(m_supportedTexImageSourceFormats, kSupportedFormatsES2);
1135 m_supportedTypes.clear(); 1194 m_supportedTypes.clear();
1136 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); 1195 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2);
1196 m_supportedTexImageSourceTypes.clear();
1197 ADD_VALUES_TO_SET(m_supportedTexImageSourceTypes, kSupportedTypesES2);
1137 1198
1138 activateContext(this); 1199 activateContext(this);
1139 } 1200 }
1140 1201
1141 void WebGLRenderingContextBase::setupFlags() 1202 void WebGLRenderingContextBase::setupFlags()
1142 { 1203 {
1143 ASSERT(drawingBuffer()); 1204 ASSERT(drawingBuffer());
1144 if (canvas()) { 1205 if (canvas()) {
1145 if (Page* p = canvas()->document().page()) { 1206 if (Page* p = canvas()->document().page()) {
1146 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEna bled(); 1207 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEna bled();
(...skipping 2876 matching lines...) Expand 10 before | Expand all | Expand 10 after
4023 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, ima geExtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needCon version ? data.data() : imagePixelData); 4084 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, ima geExtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needCon version ? data.data() : imagePixelData);
4024 } 4085 }
4025 restoreUnpackParameters(); 4086 restoreUnpackParameters();
4026 } 4087 }
4027 4088
4028 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d epth, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset, GL int zoffset) 4089 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d epth, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset, GL int zoffset)
4029 { 4090 {
4030 if (!validateTexFuncLevel(functionName, target, level)) 4091 if (!validateTexFuncLevel(functionName, target, level))
4031 return false; 4092 return false;
4032 4093
4033 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, depth, border, format, type)) 4094 if (!validateTexFuncParameters(functionName, functionType, sourceType, targe t, level, internalformat, width, height, depth, border, format, type))
4034 return false; 4095 return false;
4035 4096
4036 if (functionType == TexSubImage) { 4097 if (functionType == TexSubImage) {
4037 if (!validateSettableTexFormat(functionName, format)) 4098 if (!validateSettableTexFormat(functionName, format))
4038 return false; 4099 return false;
4039 if (!validateSize(functionName, xoffset, yoffset, zoffset)) 4100 if (!validateSize(functionName, xoffset, yoffset, zoffset))
4040 return false; 4101 return false;
4041 } else { 4102 } else {
4042 // For SourceArrayBufferView, function validateTexFuncData() would handl e whether to validate the SettableTexFormat 4103 // For SourceArrayBufferView, function validateTexFuncData() would handl e whether to validate the SettableTexFormat
4043 // by checking if the ArrayBufferView is null or not. 4104 // by checking if the ArrayBufferView is null or not.
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
5519 continue; 5580 continue;
5520 } 5581 }
5521 if (!validateCharacter(string[i])) { 5582 if (!validateCharacter(string[i])) {
5522 synthesizeGLError(GL_INVALID_VALUE, "shaderSource", "string not ASCI I"); 5583 synthesizeGLError(GL_INVALID_VALUE, "shaderSource", "string not ASCI I");
5523 return false; 5584 return false;
5524 } 5585 }
5525 } 5586 }
5526 return true; 5587 return true;
5527 } 5588 }
5528 5589
5590 void WebGLRenderingContextBase::addExtensionSupportedFormatsTypes()
5591 {
5592 if (!m_isOESTextureFloatFormatsTypesAdded && extensionEnabled(OESTextureFloa tName)) {
5593 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesOESTexFloat);
5594 ADD_VALUES_TO_SET(m_supportedTexImageSourceTypes, kSupportedTypesOESTexF loat);
5595 m_isOESTextureFloatFormatsTypesAdded = true;
5596 }
5597
5598 if (!m_isOESTextureHalfFloatFormatsTypesAdded && extensionEnabled(OESTexture HalfFloatName)) {
5599 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesOESTexHalfFloat);
5600 ADD_VALUES_TO_SET(m_supportedTexImageSourceTypes, kSupportedTypesOESTexH alfFloat);
5601 m_isOESTextureHalfFloatFormatsTypesAdded = true;
5602 }
5603
5604 if (!m_isWebGLDepthTextureFormatsTypesAdded && extensionEnabled(WebGLDepthTe xtureName)) {
5605 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsO ESDepthTex);
5606 ADD_VALUES_TO_SET(m_supportedTexImageSourceInternalFormats, kSupportedIn ternalFormatsOESDepthTex);
5607 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsOESDepthTex);
5608 ADD_VALUES_TO_SET(m_supportedTexImageSourceFormats, kSupportedFormatsOES DepthTex);
5609 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesOESDepthTex);
5610 ADD_VALUES_TO_SET(m_supportedTexImageSourceTypes, kSupportedTypesOESDept hTex);
5611 m_isWebGLDepthTextureFormatsTypesAdded = true;
5612 }
5613
5614 if (!m_isEXTsRGBFormatsTypesAdded && extensionEnabled(EXTsRGBName)) {
5615 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsE XTsRGB);
5616 ADD_VALUES_TO_SET(m_supportedTexImageSourceInternalFormats, kSupportedIn ternalFormatsEXTsRGB);
5617 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsEXTsRGB);
5618 ADD_VALUES_TO_SET(m_supportedTexImageSourceFormats, kSupportedFormatsEXT sRGB);
5619 m_isEXTsRGBFormatsTypesAdded = true;
5620 }
5621 }
5622
5623 bool WebGLRenderingContextBase::validateTexImageSourceFormatAndType(const char* functionName, TexImageFunctionType functionType, GLenum internalformat, GLenum f ormat, GLenum type)
5624 {
5625 if (!m_isWebGL2TexImageSourceFormatsTypesAdded && isWebGL2OrHigher()) {
5626 ADD_VALUES_TO_SET(m_supportedTexImageSourceInternalFormats, kSupportedIn ternalFormatsTexImageSourceES3);
5627 ADD_VALUES_TO_SET(m_supportedTexImageSourceFormats, kSupportedFormatsTex ImageSourceES3);
5628 ADD_VALUES_TO_SET(m_supportedTexImageSourceTypes, kSupportedTypesTexImag eSourceES3);
5629 m_isWebGL2TexImageSourceFormatsTypesAdded = true;
5630 }
5631
5632 if (!isWebGL2OrHigher()) {
5633 addExtensionSupportedFormatsTypes();
5634 }
5635
5636 if (internalformat != 0 && m_supportedTexImageSourceInternalFormats.find(int ernalformat) == m_supportedTexImageSourceInternalFormats.end()) {
5637 if (functionType == TexImage) {
5638 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid internalf ormat");
5639 } else {
5640 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid internalfo rmat");
5641 }
5642 return false;
5643 }
5644 if (m_supportedTexImageSourceFormats.find(format) == m_supportedTexImageSour ceFormats.end()) {
5645 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid format");
5646 return false;
5647 }
5648 if (m_supportedTexImageSourceTypes.find(type) == m_supportedTexImageSourceTy pes.end()) {
5649 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid type");
5650 return false;
5651 }
Ken Russell (switch to Gerrit) 2016/10/01 03:52:05 Only some of these internalformat/format/type comb
qiankun 2016/10/01 14:27:30 Thanks for catching this potential issue. Code in
5652
5653 return true;
5654 }
5655
5529 bool WebGLRenderingContextBase::validateTexFuncFormatAndType(const char* functio nName, TexImageFunctionType functionType, GLenum internalformat, GLenum format, GLenum type, GLint level) 5656 bool WebGLRenderingContextBase::validateTexFuncFormatAndType(const char* functio nName, TexImageFunctionType functionType, GLenum internalformat, GLenum format, GLenum type, GLint level)
5530 { 5657 {
5531 if (!m_isWebGL2FormatsTypesAdded && isWebGL2OrHigher()) { 5658 if (!m_isWebGL2FormatsTypesAdded && isWebGL2OrHigher()) {
5532 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsE S3); 5659 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsE S3);
5533 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsT exImageES3); 5660 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsT exImageES3);
5534 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES3); 5661 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES3);
5535 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES3); 5662 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES3);
5536 m_isWebGL2FormatsTypesAdded = true; 5663 m_isWebGL2FormatsTypesAdded = true;
5537 } 5664 }
5538 5665
5539 if (!isWebGL2OrHigher()) { 5666 if (!isWebGL2OrHigher()) {
5540 if (!m_isOESTextureFloatFormatsTypesAdded && extensionEnabled(OESTexture FloatName)) { 5667 addExtensionSupportedFormatsTypes();
5541 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesOESTexFloat);
5542 m_isOESTextureFloatFormatsTypesAdded = true;
5543 }
5544
5545 if (!m_isOESTextureHalfFloatFormatsTypesAdded && extensionEnabled(OESTex tureHalfFloatName)) {
5546 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesOESTexHalfFloat);
5547 m_isOESTextureHalfFloatFormatsTypesAdded = true;
5548 }
5549
5550 if (!m_isWebGLDepthTextureFormatsTypesAdded && extensionEnabled(WebGLDep thTextureName)) {
5551 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalForm atsOESDepthTex);
5552 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsOESDepthTex);
5553 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesOESDepthTex);
5554 m_isWebGLDepthTextureFormatsTypesAdded = true;
5555 }
5556
5557 if (!m_isEXTsRGBFormatsTypesAdded && extensionEnabled(EXTsRGBName)) {
5558 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalForm atsEXTsRGB);
5559 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsEXTsRGB);
5560 m_isEXTsRGBFormatsTypesAdded = true;
5561 }
5562 } 5668 }
5563 5669
5564 if (internalformat != 0 && m_supportedInternalFormats.find(internalformat) = = m_supportedInternalFormats.end()) { 5670 if (internalformat != 0 && m_supportedInternalFormats.find(internalformat) = = m_supportedInternalFormats.end()) {
5565 if (functionType == TexImage) { 5671 if (functionType == TexImage) {
5566 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid internalf ormat"); 5672 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid internalf ormat");
5567 } else { 5673 } else {
5568 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid internalfo rmat"); 5674 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid internalfo rmat");
5569 } 5675 }
5570 return false; 5676 return false;
5571 } 5677 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
5671 } 5777 }
5672 break; 5778 break;
5673 } 5779 }
5674 default: 5780 default:
5675 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); 5781 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target");
5676 return false; 5782 return false;
5677 } 5783 }
5678 return true; 5784 return true;
5679 } 5785 }
5680 5786
5681 bool WebGLRenderingContextBase::validateTexFuncParameters(const char* functionNa me, TexImageFunctionType functionType, GLenum target, 5787 bool WebGLRenderingContextBase::validateTexFuncParameters(const char* functionNa me, TexImageFunctionType functionType, TexFuncValidationSourceType sourceType, G Lenum target,
5682 GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d epth, GLint border, GLenum format, GLenum type) 5788 GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d epth, GLint border, GLenum format, GLenum type)
5683 { 5789 {
5684 // We absolutely have to validate the format and type combination. 5790 // We absolutely have to validate the format and type combination.
5685 // The texImage2D entry points taking HTMLImage, etc. will produce 5791 // The texImage2D entry points taking HTMLImage, etc. will produce
5686 // temporary data based on this combination, so it must be legal. 5792 // temporary data based on this combination, so it must be legal.
5687 if (!validateTexFuncFormatAndType(functionName, functionType, internalformat , format, type, level)) 5793 if (sourceType == SourceHTMLImageElement || sourceType == SourceHTMLCanvasEl ement || sourceType == SourceHTMLVideoElement
5688 return false; 5794 || sourceType == SourceImageData || sourceType == SourceImageBitmap) {
5795 if (!validateTexImageSourceFormatAndType(functionName, functionType, int ernalformat, format, type))
5796 return false;
5797 } else {
5798 if (!validateTexFuncFormatAndType(functionName, functionType, internalfo rmat, format, type, level))
5799 return false;
5800 }
5689 5801
5690 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height, depth)) 5802 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height, depth))
5691 return false; 5803 return false;
5692 5804
5693 if (border) { 5805 if (border) {
5694 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0"); 5806 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0");
5695 return false; 5807 return false;
5696 } 5808 }
5697 5809
5698 return true; 5810 return true;
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
6473 6585
6474 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const 6586 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const
6475 { 6587 {
6476 if (canvas()) 6588 if (canvas())
6477 result.setHTMLCanvasElement(canvas()); 6589 result.setHTMLCanvasElement(canvas());
6478 else 6590 else
6479 result.setOffscreenCanvas(getOffscreenCanvas()); 6591 result.setOffscreenCanvas(getOffscreenCanvas());
6480 } 6592 }
6481 6593
6482 } // namespace blink 6594 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698