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

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

Issue 1834983003: Remove string-getting methods from WebGraphicsContext3D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "core/loader/FrameLoader.h" 46 #include "core/loader/FrameLoader.h"
47 #include "core/loader/FrameLoaderClient.h" 47 #include "core/loader/FrameLoaderClient.h"
48 #include "gpu/command_buffer/client/gles2_interface.h" 48 #include "gpu/command_buffer/client/gles2_interface.h"
49 #include "modules/webgl/ANGLEInstancedArrays.h" 49 #include "modules/webgl/ANGLEInstancedArrays.h"
50 #include "modules/webgl/CHROMIUMSubscribeUniform.h" 50 #include "modules/webgl/CHROMIUMSubscribeUniform.h"
51 #include "modules/webgl/CHROMIUMValuebuffer.h" 51 #include "modules/webgl/CHROMIUMValuebuffer.h"
52 #include "modules/webgl/EXTBlendMinMax.h" 52 #include "modules/webgl/EXTBlendMinMax.h"
53 #include "modules/webgl/EXTFragDepth.h" 53 #include "modules/webgl/EXTFragDepth.h"
54 #include "modules/webgl/EXTShaderTextureLOD.h" 54 #include "modules/webgl/EXTShaderTextureLOD.h"
55 #include "modules/webgl/EXTTextureFilterAnisotropic.h" 55 #include "modules/webgl/EXTTextureFilterAnisotropic.h"
56 #include "modules/webgl/GLStringQuery.h"
56 #include "modules/webgl/OESElementIndexUint.h" 57 #include "modules/webgl/OESElementIndexUint.h"
57 #include "modules/webgl/OESStandardDerivatives.h" 58 #include "modules/webgl/OESStandardDerivatives.h"
58 #include "modules/webgl/OESTextureFloat.h" 59 #include "modules/webgl/OESTextureFloat.h"
59 #include "modules/webgl/OESTextureFloatLinear.h" 60 #include "modules/webgl/OESTextureFloatLinear.h"
60 #include "modules/webgl/OESTextureHalfFloat.h" 61 #include "modules/webgl/OESTextureHalfFloat.h"
61 #include "modules/webgl/OESTextureHalfFloatLinear.h" 62 #include "modules/webgl/OESTextureHalfFloatLinear.h"
62 #include "modules/webgl/OESVertexArrayObject.h" 63 #include "modules/webgl/OESVertexArrayObject.h"
63 #include "modules/webgl/WebGLActiveInfo.h" 64 #include "modules/webgl/WebGLActiveInfo.h"
64 #include "modules/webgl/WebGLBuffer.h" 65 #include "modules/webgl/WebGLBuffer.h"
65 #include "modules/webgl/WebGLCompressedTextureASTC.h" 66 #include "modules/webgl/WebGLCompressedTextureASTC.h"
(...skipping 2203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2269 return; 2270 return;
2270 if (!validateTextureBinding("generateMipmap", target)) 2271 if (!validateTextureBinding("generateMipmap", target))
2271 return; 2272 return;
2272 contextGL()->GenerateMipmap(target); 2273 contextGL()->GenerateMipmap(target);
2273 } 2274 }
2274 2275
2275 WebGLActiveInfo* WebGLRenderingContextBase::getActiveAttrib(WebGLProgram* progra m, GLuint index) 2276 WebGLActiveInfo* WebGLRenderingContextBase::getActiveAttrib(WebGLProgram* progra m, GLuint index)
2276 { 2277 {
2277 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program)) 2278 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program))
2278 return nullptr; 2279 return nullptr;
2279 WebGraphicsContext3D::ActiveInfo info;
2280 GLuint programId = objectNonZero(program); 2280 GLuint programId = objectNonZero(program);
2281 GLint maxNameLength = -1; 2281 GLint maxNameLength = -1;
2282 contextGL()->GetProgramiv(programId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNam eLength); 2282 contextGL()->GetProgramiv(programId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNam eLength);
2283 if (maxNameLength < 0) 2283 if (maxNameLength < 0)
2284 return nullptr; 2284 return nullptr;
2285 if (maxNameLength == 0) { 2285 if (maxNameLength == 0) {
2286 synthesizeGLError(GL_INVALID_VALUE, "getActiveAttrib", "no active attrib utes exist"); 2286 synthesizeGLError(GL_INVALID_VALUE, "getActiveAttrib", "no active attrib utes exist");
2287 return nullptr; 2287 return nullptr;
2288 } 2288 }
2289 if (!webContext()->getActiveAttrib(objectOrZero(program), index, info)) 2289 LChar* namePtr;
2290 RefPtr<StringImpl> nameImpl = StringImpl::createUninitialized(maxNameLength, namePtr);
2291 GLsizei length = 0;
2292 GLint size = -1;
2293 GLenum type = 0;
2294 contextGL()->GetActiveAttrib(programId, index, maxNameLength, &length, &size , &type, reinterpret_cast<GLchar*>(namePtr));
2295 if (size < 0)
2290 return nullptr; 2296 return nullptr;
2291 return WebGLActiveInfo::create(info.name, info.type, info.size); 2297 return WebGLActiveInfo::create(nameImpl.release(), type, size);
2292 } 2298 }
2293 2299
2294 WebGLActiveInfo* WebGLRenderingContextBase::getActiveUniform(WebGLProgram* progr am, GLuint index) 2300 WebGLActiveInfo* WebGLRenderingContextBase::getActiveUniform(WebGLProgram* progr am, GLuint index)
2295 { 2301 {
2296 if (isContextLost() || !validateWebGLObject("getActiveUniform", program)) 2302 if (isContextLost() || !validateWebGLObject("getActiveUniform", program))
2297 return nullptr; 2303 return nullptr;
2298 GLuint programId = objectNonZero(program); 2304 GLuint programId = objectNonZero(program);
2299 GLint maxNameLength = -1; 2305 GLint maxNameLength = -1;
2300 contextGL()->GetProgramiv(programId, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameL ength); 2306 contextGL()->GetProgramiv(programId, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameL ength);
2301 if (maxNameLength < 0) 2307 if (maxNameLength < 0)
2302 return nullptr; 2308 return nullptr;
2303 if (maxNameLength == 0) { 2309 if (maxNameLength == 0) {
2304 synthesizeGLError(GL_INVALID_VALUE, "getActiveUniform", "no active unifo rms exist"); 2310 synthesizeGLError(GL_INVALID_VALUE, "getActiveUniform", "no active unifo rms exist");
2305 return nullptr; 2311 return nullptr;
2306 } 2312 }
2307 WebGraphicsContext3D::ActiveInfo info; 2313 LChar* namePtr;
2308 if (!webContext()->getActiveUniform(programId, index, info)) 2314 RefPtr<StringImpl> nameImpl = StringImpl::createUninitialized(maxNameLength, namePtr);
2315 GLsizei length = 0;
2316 GLint size = -1;
2317 GLenum type = 0;
2318 contextGL()->GetActiveUniform(programId, index, maxNameLength, &length, &siz e, &type, reinterpret_cast<GLchar*>(namePtr));
2319 if (size < 0)
2309 return nullptr; 2320 return nullptr;
2310 return WebGLActiveInfo::create(info.name, info.type, info.size); 2321 return WebGLActiveInfo::create(nameImpl.release(), type, size);
2311 } 2322 }
2312 2323
2313 Nullable<HeapVector<Member<WebGLShader>>> WebGLRenderingContextBase::getAttached Shaders(WebGLProgram* program) 2324 Nullable<HeapVector<Member<WebGLShader>>> WebGLRenderingContextBase::getAttached Shaders(WebGLProgram* program)
2314 { 2325 {
2315 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program)) 2326 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program))
2316 return nullptr; 2327 return nullptr;
2317 2328
2318 HeapVector<Member<WebGLShader>> shaderObjects; 2329 HeapVector<Member<WebGLShader>> shaderObjects;
2319 const GLenum shaderType[] = { 2330 const GLenum shaderType[] = {
2320 GL_VERTEX_SHADER, 2331 GL_VERTEX_SHADER,
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2831 default: 2842 default:
2832 synthesizeGLError(GL_INVALID_ENUM, "getProgramParameter", "invalid param eter name"); 2843 synthesizeGLError(GL_INVALID_ENUM, "getProgramParameter", "invalid param eter name");
2833 return ScriptValue::createNull(scriptState); 2844 return ScriptValue::createNull(scriptState);
2834 } 2845 }
2835 } 2846 }
2836 2847
2837 String WebGLRenderingContextBase::getProgramInfoLog(WebGLProgram* program) 2848 String WebGLRenderingContextBase::getProgramInfoLog(WebGLProgram* program)
2838 { 2849 {
2839 if (isContextLost() || !validateWebGLObject("getProgramInfoLog", program)) 2850 if (isContextLost() || !validateWebGLObject("getProgramInfoLog", program))
2840 return String(); 2851 return String();
2841 return ensureNotNull(webContext()->getProgramInfoLog(objectOrZero(program))) ; 2852
2853 GLStringQuery query(contextGL());
2854 return query.Run<GLStringQuery::ProgramInfoLog>(objectNonZero(program));
2842 } 2855 }
2843 2856
2844 ScriptValue WebGLRenderingContextBase::getRenderbufferParameter(ScriptState* scr iptState, GLenum target, GLenum pname) 2857 ScriptValue WebGLRenderingContextBase::getRenderbufferParameter(ScriptState* scr iptState, GLenum target, GLenum pname)
2845 { 2858 {
2846 if (isContextLost()) 2859 if (isContextLost())
2847 return ScriptValue::createNull(scriptState); 2860 return ScriptValue::createNull(scriptState);
2848 if (target != GL_RENDERBUFFER) { 2861 if (target != GL_RENDERBUFFER) {
2849 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid target"); 2862 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid target");
2850 return ScriptValue::createNull(scriptState); 2863 return ScriptValue::createNull(scriptState);
2851 } 2864 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2898 default: 2911 default:
2899 synthesizeGLError(GL_INVALID_ENUM, "getShaderParameter", "invalid parame ter name"); 2912 synthesizeGLError(GL_INVALID_ENUM, "getShaderParameter", "invalid parame ter name");
2900 return ScriptValue::createNull(scriptState); 2913 return ScriptValue::createNull(scriptState);
2901 } 2914 }
2902 } 2915 }
2903 2916
2904 String WebGLRenderingContextBase::getShaderInfoLog(WebGLShader* shader) 2917 String WebGLRenderingContextBase::getShaderInfoLog(WebGLShader* shader)
2905 { 2918 {
2906 if (isContextLost() || !validateWebGLObject("getShaderInfoLog", shader)) 2919 if (isContextLost() || !validateWebGLObject("getShaderInfoLog", shader))
2907 return String(); 2920 return String();
2908 return ensureNotNull(webContext()->getShaderInfoLog(objectOrZero(shader))); 2921 GLStringQuery query(contextGL());
2922 return query.Run<GLStringQuery::ShaderInfoLog>(objectNonZero(shader));
2909 } 2923 }
2910 2924
2911 WebGLShaderPrecisionFormat* WebGLRenderingContextBase::getShaderPrecisionFormat( GLenum shaderType, GLenum precisionType) 2925 WebGLShaderPrecisionFormat* WebGLRenderingContextBase::getShaderPrecisionFormat( GLenum shaderType, GLenum precisionType)
2912 { 2926 {
2913 if (isContextLost()) 2927 if (isContextLost())
2914 return nullptr; 2928 return nullptr;
2915 switch (shaderType) { 2929 switch (shaderType) {
2916 case GL_VERTEX_SHADER: 2930 case GL_VERTEX_SHADER:
2917 case GL_FRAGMENT_SHADER: 2931 case GL_FRAGMENT_SHADER:
2918 break; 2932 break;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
3000 ScriptValue WebGLRenderingContextBase::getUniform(ScriptState* scriptState, WebG LProgram* program, const WebGLUniformLocation* uniformLocation) 3014 ScriptValue WebGLRenderingContextBase::getUniform(ScriptState* scriptState, WebG LProgram* program, const WebGLUniformLocation* uniformLocation)
3001 { 3015 {
3002 if (isContextLost() || !validateWebGLObject("getUniform", program)) 3016 if (isContextLost() || !validateWebGLObject("getUniform", program))
3003 return ScriptValue::createNull(scriptState); 3017 return ScriptValue::createNull(scriptState);
3004 if (!uniformLocation || uniformLocation->program() != program) { 3018 if (!uniformLocation || uniformLocation->program() != program) {
3005 synthesizeGLError(GL_INVALID_OPERATION, "getUniform", "no uniformlocatio n or not valid for this program"); 3019 synthesizeGLError(GL_INVALID_OPERATION, "getUniform", "no uniformlocatio n or not valid for this program");
3006 return ScriptValue::createNull(scriptState); 3020 return ScriptValue::createNull(scriptState);
3007 } 3021 }
3008 GLint location = uniformLocation->location(); 3022 GLint location = uniformLocation->location();
3009 3023
3024 GLuint programId = objectNonZero(program);
3025 GLint maxNameLength = -1;
3026 contextGL()->GetProgramiv(programId, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameL ength);
danakj 2016/03/25 21:13:07 This pulls the maxNameLength query out of the loop
3027 if (maxNameLength < 0)
3028 return ScriptValue::createNull(scriptState);
3029 if (maxNameLength == 0) {
danakj 2016/03/25 21:13:07 If 0, we would skip the for loop below, before, an
3030 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "no active uniforms ex ist");
3031 return ScriptValue::createNull(scriptState);
3032 }
3033
3010 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it 3034 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it
3011 GLint activeUniforms = 0; 3035 GLint activeUniforms = 0;
3012 contextGL()->GetProgramiv(objectOrZero(program), GL_ACTIVE_UNIFORMS, &active Uniforms); 3036 contextGL()->GetProgramiv(programId, GL_ACTIVE_UNIFORMS, &activeUniforms);
3013 for (GLint i = 0; i < activeUniforms; i++) { 3037 for (GLint i = 0; i < activeUniforms; i++) {
3014 WebGraphicsContext3D::ActiveInfo info; 3038 LChar* namePtr;
3015 if (!webContext()->getActiveUniform(objectOrZero(program), i, info)) 3039 RefPtr<StringImpl> nameImpl = StringImpl::createUninitialized(maxNameLen gth, namePtr);
3040 GLsizei length = 0;
3041 GLint size = -1;
3042 GLenum type = 0;
3043 contextGL()->GetActiveUniform(programId, i, maxNameLength, &length, &siz e, &type, reinterpret_cast<GLchar*>(namePtr));
3044 if (size < 0)
3016 return ScriptValue::createNull(scriptState); 3045 return ScriptValue::createNull(scriptState);
3017 String name = info.name; 3046 String name(nameImpl);
3018 StringBuilder nameBuilder; 3047 StringBuilder nameBuilder;
3019 // Strip "[0]" from the name if it's an array. 3048 // Strip "[0]" from the name if it's an array.
3020 if (info.size > 1 && name.endsWith("[0]")) 3049 if (size > 1 && name.endsWith("[0]"))
3021 info.name = name.left(name.length() - 3); 3050 name = name.left(name.length() - 3);
danakj 2016/03/25 21:13:07 The old code had a mix of info.name and name here,
3022 // If it's an array, we need to iterate through each element, appending "[index]" to the name. 3051 // If it's an array, we need to iterate through each element, appending "[index]" to the name.
3023 for (GLint index = 0; index < info.size; ++index) { 3052 for (GLint index = 0; index < size; ++index) {
3024 nameBuilder.clear(); 3053 nameBuilder.clear();
3025 nameBuilder.append(info.name); 3054 nameBuilder.append(name);
3026 if (info.size > 1 && index >= 1) { 3055 if (size > 1 && index >= 1) {
3027 nameBuilder.append('['); 3056 nameBuilder.append('[');
3028 nameBuilder.appendNumber(index); 3057 nameBuilder.appendNumber(index);
3029 nameBuilder.append(']'); 3058 nameBuilder.append(']');
3030 } 3059 }
3031 // Now need to look this up by name again to find its location 3060 // Now need to look this up by name again to find its location
3032 GLint loc = contextGL()->GetUniformLocation(objectOrZero(program), n ameBuilder.toString().utf8().data()); 3061 GLint loc = contextGL()->GetUniformLocation(objectOrZero(program), n ameBuilder.toString().utf8().data());
3033 if (loc == location) { 3062 if (loc == location) {
3034 // Found it. Use the type in the ActiveInfo to determine the ret urn type. 3063 // Found it. Use the type in the ActiveInfo to determine the ret urn type.
3035 GLenum baseType; 3064 GLenum baseType;
3036 unsigned length; 3065 unsigned length;
3037 switch (info.type) { 3066 switch (type) {
3038 case GL_BOOL: 3067 case GL_BOOL:
3039 baseType = GL_BOOL; 3068 baseType = GL_BOOL;
3040 length = 1; 3069 length = 1;
3041 break; 3070 break;
3042 case GL_BOOL_VEC2: 3071 case GL_BOOL_VEC2:
3043 baseType = GL_BOOL; 3072 baseType = GL_BOOL;
3044 length = 2; 3073 length = 2;
3045 break; 3074 break;
3046 case GL_BOOL_VEC3: 3075 case GL_BOOL_VEC3:
3047 baseType = GL_BOOL; 3076 baseType = GL_BOOL;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3100 baseType = GL_INT; 3129 baseType = GL_INT;
3101 length = 1; 3130 length = 1;
3102 break; 3131 break;
3103 default: 3132 default:
3104 if (!isWebGL2OrHigher()) { 3133 if (!isWebGL2OrHigher()) {
3105 // Can't handle this type 3134 // Can't handle this type
3106 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "unhan dled type"); 3135 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "unhan dled type");
3107 return ScriptValue::createNull(scriptState); 3136 return ScriptValue::createNull(scriptState);
3108 } 3137 }
3109 // handle GLenums for WebGL 2.0 or higher 3138 // handle GLenums for WebGL 2.0 or higher
3110 switch (info.type) { 3139 switch (type) {
3111 case GL_UNSIGNED_INT: 3140 case GL_UNSIGNED_INT:
3112 baseType = GL_UNSIGNED_INT; 3141 baseType = GL_UNSIGNED_INT;
3113 length = 1; 3142 length = 1;
3114 break; 3143 break;
3115 case GL_UNSIGNED_INT_VEC2: 3144 case GL_UNSIGNED_INT_VEC2:
3116 baseType = GL_UNSIGNED_INT; 3145 baseType = GL_UNSIGNED_INT;
3117 length = 2; 3146 length = 2;
3118 break; 3147 break;
3119 case GL_UNSIGNED_INT_VEC3: 3148 case GL_UNSIGNED_INT_VEC3:
3120 baseType = GL_UNSIGNED_INT; 3149 baseType = GL_UNSIGNED_INT;
(...skipping 3190 matching lines...) Expand 10 before | Expand all | Expand 10 after
6311 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6340 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6312 } 6341 }
6313 6342
6314 void WebGLRenderingContextBase::restoreUnpackParameters() 6343 void WebGLRenderingContextBase::restoreUnpackParameters()
6315 { 6344 {
6316 if (m_unpackAlignment != 1) 6345 if (m_unpackAlignment != 1)
6317 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6346 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6318 } 6347 }
6319 6348
6320 } // namespace blink 6349 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698