Changeset 64660 in webkit
- Timestamp:
- Aug 4, 2010 11:39:02 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r64659 r64660 1 2010-08-03 Kenneth Russell <kbr@google.com> 2 3 Reviewed by Nate Chapin. 4 5 Move WebGL-specific code out of GraphicsContext3D so that G3D can be used as a generic accelerated drawing API 6 https://bugs.webkit.org/show_bug.cgi?id=43221 7 8 Added a helper function to extract the contents of WebGL objects 9 to reduce duplicated code and fix a couple of potential crashes 10 introduced in the previous refactoring. 11 12 No new tests; ran existing WebGL tests. 13 14 * html/canvas/WebGLRenderingContext.cpp: 15 (WebCore::WebGLRenderingContext::attachShader): 16 (WebCore::WebGLRenderingContext::bindAttribLocation): 17 (WebCore::WebGLRenderingContext::bindBuffer): 18 (WebCore::WebGLRenderingContext::bindFramebuffer): 19 (WebCore::WebGLRenderingContext::bindRenderbuffer): 20 (WebCore::WebGLRenderingContext::bindTexture): 21 (WebCore::WebGLRenderingContext::compileShader): 22 (WebCore::WebGLRenderingContext::detachShader): 23 (WebCore::WebGLRenderingContext::framebufferRenderbuffer): 24 (WebCore::WebGLRenderingContext::framebufferTexture2D): 25 (WebCore::WebGLRenderingContext::getActiveAttrib): 26 (WebCore::WebGLRenderingContext::getActiveUniform): 27 (WebCore::WebGLRenderingContext::getAttachedShaders): 28 (WebCore::WebGLRenderingContext::getAttribLocation): 29 (WebCore::WebGLRenderingContext::getProgramParameter): 30 (WebCore::WebGLRenderingContext::getProgramInfoLog): 31 (WebCore::WebGLRenderingContext::getShaderParameter): 32 (WebCore::WebGLRenderingContext::getShaderInfoLog): 33 (WebCore::WebGLRenderingContext::getShaderSource): 34 (WebCore::WebGLRenderingContext::getUniform): 35 (WebCore::WebGLRenderingContext::getUniformLocation): 36 (WebCore::WebGLRenderingContext::linkProgram): 37 (WebCore::WebGLRenderingContext::shaderSource): 38 (WebCore::WebGLRenderingContext::useProgram): 39 (WebCore::WebGLRenderingContext::validateProgram): 40 (WebCore::WebGLRenderingContext::handleNPOTTextures): 41 (WebCore::WebGLRenderingContext::restoreStatesAfterVertexAttrib0Simulation): 42 1 43 2010-08-04 Mario Sanchez Prada <msanchez@igalia.com> 2 44 -
trunk/WebCore/html/canvas/WebGLRenderingContext.cpp
r64582 r64660 58 58 namespace WebCore { 59 59 60 static inline Platform3DObject objectOrZero(CanvasObject* object) 61 { 62 return object ? object->object() : 0; 63 } 64 60 65 class WebGLStateRestorer { 61 66 public: … … 221 226 if (!validateWebGLObject(program) || !validateWebGLObject(shader)) 222 227 return; 223 m_context->attachShader( program ? program->object() : 0, shader ? shader->object() : 0);228 m_context->attachShader(objectOrZero(program), objectOrZero(shader)); 224 229 cleanupAfterGraphicsCall(false); 225 230 } … … 230 235 if (!validateWebGLObject(program)) 231 236 return; 232 m_context->bindAttribLocation( program ? program->object() : 0, index, name);237 m_context->bindAttribLocation(objectOrZero(program), index, name); 233 238 cleanupAfterGraphicsCall(false); 234 239 } … … 255 260 } 256 261 257 m_context->bindBuffer(target, buffer ? buffer->object() : 0);262 m_context->bindBuffer(target, objectOrZero(buffer)); 258 263 if (buffer) 259 264 buffer->setTarget(target); … … 274 279 } 275 280 m_framebufferBinding = buffer; 276 m_context->bindFramebuffer(target, buffer ? buffer->object() : 0);281 m_context->bindFramebuffer(target, objectOrZero(buffer)); 277 282 if (m_framebufferBinding) 278 283 m_framebufferBinding->onBind(); … … 292 297 } 293 298 m_renderbufferBinding = renderBuffer; 294 m_context->bindRenderbuffer(target, renderBuffer ? renderBuffer->object() : 0);299 m_context->bindRenderbuffer(target, objectOrZero(renderBuffer)); 295 300 cleanupAfterGraphicsCall(false); 296 301 } … … 315 320 return; 316 321 } 317 m_context->bindTexture(target, texture ? texture->object() : 0);322 m_context->bindTexture(target, objectOrZero(texture)); 318 323 if (!isGLES2Compliant() && texture) 319 324 texture->setTarget(target, maxLevel); … … 517 522 if (!validateWebGLObject(shader)) 518 523 return; 519 m_context->compileShader( shader ? shader->object() : 0);524 m_context->compileShader(objectOrZero(shader)); 520 525 cleanupAfterGraphicsCall(false); 521 526 } … … 707 712 if (!validateWebGLObject(program) || !validateWebGLObject(shader)) 708 713 return; 709 m_context->detachShader( program ? program->object() : 0, shader ? shader->object() : 0);714 m_context->detachShader(objectOrZero(program), objectOrZero(shader)); 710 715 cleanupAfterGraphicsCall(false); 711 716 } … … 1076 1081 } 1077 1082 } 1078 m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer ? buffer->object() : 0);1083 m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, objectOrZero(buffer)); 1079 1084 m_framebufferBinding->setAttachment(attachment, buffer); 1080 1085 cleanupAfterGraphicsCall(false); … … 1101 1106 return; 1102 1107 } 1103 m_context->framebufferTexture2D(target, attachment, textarget, texture ? texture->object() : 0, level);1108 m_context->framebufferTexture2D(target, attachment, textarget, objectOrZero(texture), level); 1104 1109 m_framebufferBinding->setAttachment(attachment, texture); 1105 1110 cleanupAfterGraphicsCall(false); … … 1139 1144 if (!validateWebGLObject(program)) 1140 1145 return 0; 1141 if (!m_context->getActiveAttrib( program ? program->object() : 0, index, info)) {1146 if (!m_context->getActiveAttrib(objectOrZero(program), index, info)) { 1142 1147 return 0; 1143 1148 } … … 1151 1156 if (!validateWebGLObject(program)) 1152 1157 return 0; 1153 if (!m_context->getActiveUniform( program ? program->object() : 0, index, info)) {1158 if (!m_context->getActiveUniform(objectOrZero(program), index, info)) { 1154 1159 return 0; 1155 1160 } … … 1168 1173 return false; 1169 1174 int numShaders = 0; 1170 m_context->getProgramiv( program ? program->object() : 0, GraphicsContext3D::ATTACHED_SHADERS, &numShaders);1175 m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ATTACHED_SHADERS, &numShaders); 1171 1176 if (numShaders) { 1172 1177 OwnArrayPtr<unsigned int> shaders(new unsigned int[numShaders]); 1173 1178 int count; 1174 m_context->getAttachedShaders( program ? program->object() : 0, numShaders, &count, shaders.get());1179 m_context->getAttachedShaders(objectOrZero(program), numShaders, &count, shaders.get()); 1175 1180 if (count != numShaders) 1176 1181 return false; … … 1190 1195 int WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const String& name) 1191 1196 { 1192 return m_context->getAttribLocation( program ? program->object() : 0, name);1197 return m_context->getAttribLocation(objectOrZero(program), name); 1193 1198 } 1194 1199 … … 1468 1473 case GraphicsContext3D::DELETE_STATUS: 1469 1474 case GraphicsContext3D::VALIDATE_STATUS: 1470 m_context->getProgramiv( program ? program->object() : 0, pname, &value);1475 m_context->getProgramiv(objectOrZero(program), pname, &value); 1471 1476 return WebGLGetInfo(static_cast<bool>(value)); 1472 1477 case GraphicsContext3D::LINK_STATUS: 1473 1478 if (program->isLinkFailureFlagSet()) 1474 1479 return WebGLGetInfo(false); 1475 m_context->getProgramiv( program ? program->object() : 0, pname, &value);1480 m_context->getProgramiv(objectOrZero(program), pname, &value); 1476 1481 return WebGLGetInfo(static_cast<bool>(value)); 1477 1482 case GraphicsContext3D::INFO_LOG_LENGTH: … … 1481 1486 case GraphicsContext3D::ACTIVE_UNIFORMS: 1482 1487 case GraphicsContext3D::ACTIVE_UNIFORM_MAX_LENGTH: 1483 m_context->getProgramiv( program ? program->object() : 0, pname, &value);1488 m_context->getProgramiv(objectOrZero(program), pname, &value); 1484 1489 return WebGLGetInfo(static_cast<long>(value)); 1485 1490 default: … … 1495 1500 return ""; 1496 1501 WebGLStateRestorer(this, false); 1497 return m_context->getProgramInfoLog( program ? program->object() : 0);1502 return m_context->getProgramInfoLog(objectOrZero(program)); 1498 1503 } 1499 1504 … … 1541 1546 case GraphicsContext3D::DELETE_STATUS: 1542 1547 case GraphicsContext3D::COMPILE_STATUS: 1543 m_context->getShaderiv( shader ? shader->object() : 0, pname, &value);1548 m_context->getShaderiv(objectOrZero(shader), pname, &value); 1544 1549 return WebGLGetInfo(static_cast<bool>(value)); 1545 1550 case GraphicsContext3D::SHADER_TYPE: 1546 m_context->getShaderiv( shader ? shader->object() : 0, pname, &value);1551 m_context->getShaderiv(objectOrZero(shader), pname, &value); 1547 1552 return WebGLGetInfo(static_cast<unsigned long>(value)); 1548 1553 case GraphicsContext3D::INFO_LOG_LENGTH: 1549 1554 case GraphicsContext3D::SHADER_SOURCE_LENGTH: 1550 m_context->getShaderiv( shader ? shader->object() : 0, pname, &value);1555 m_context->getShaderiv(objectOrZero(shader), pname, &value); 1551 1556 return WebGLGetInfo(static_cast<long>(value)); 1552 1557 default: … … 1562 1567 return ""; 1563 1568 WebGLStateRestorer(this, false); 1564 return m_context->getShaderInfoLog( shader ? shader->object() : 0);1569 return m_context->getShaderInfoLog(objectOrZero(shader)); 1565 1570 } 1566 1571 … … 1571 1576 return ""; 1572 1577 WebGLStateRestorer(this, false); 1573 return m_context->getShaderSource( shader ? shader->object() : 0);1578 return m_context->getShaderSource(objectOrZero(shader)); 1574 1579 } 1575 1580 … … 1621 1626 // FIXME: make this more efficient using WebGLUniformLocation and caching types in it 1622 1627 int activeUniforms = 0; 1623 m_context->getProgramiv( program ? program->object() : 0, GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms);1628 m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms); 1624 1629 for (int i = 0; i < activeUniforms; i++) { 1625 1630 ActiveInfo info; 1626 if (!m_context->getActiveUniform( program ? program->object() : 0, i, info))1631 if (!m_context->getActiveUniform(objectOrZero(program), i, info)) 1627 1632 return WebGLGetInfo(); 1628 1633 // Strip "[0]" from the name if it's an array. … … 1638 1643 } 1639 1644 // Now need to look this up by name again to find its location 1640 long loc = m_context->getUniformLocation( program ? program->object() : 0, name);1645 long loc = m_context->getUniformLocation(objectOrZero(program), name); 1641 1646 if (loc == location) { 1642 1647 // Found it. Use the type in the ActiveInfo to determine the return type. … … 1713 1718 case GraphicsContext3D::FLOAT: { 1714 1719 float value[16] = {0}; 1715 m_context->getUniformfv( program ? program->object() : 0, location, value);1720 m_context->getUniformfv(objectOrZero(program), location, value); 1716 1721 if (length == 1) 1717 1722 return WebGLGetInfo(value[0]); … … 1720 1725 case GraphicsContext3D::INT: { 1721 1726 int value[16] = {0}; 1722 m_context->getUniformiv( program ? program->object() : 0, location, value);1727 m_context->getUniformiv(objectOrZero(program), location, value); 1723 1728 if (length == 1) 1724 1729 return WebGLGetInfo(static_cast<long>(value[0])); … … 1727 1732 case GraphicsContext3D::BOOL: { 1728 1733 int value[16] = {0}; 1729 m_context->getUniformiv( program ? program->object() : 0, location, value);1734 m_context->getUniformiv(objectOrZero(program), location, value); 1730 1735 if (length > 1) { 1731 1736 unsigned char boolValue[16] = {0}; … … 1753 1758 return 0; 1754 1759 WebGLStateRestorer(this, false); 1755 long uniformLocation = m_context->getUniformLocation( program ? program->object() : 0, name);1760 long uniformLocation = m_context->getUniformLocation(objectOrZero(program), name); 1756 1761 if (uniformLocation == -1) 1757 1762 return 0; … … 1916 1921 } 1917 1922 1918 m_context->linkProgram( program ? program->object() : 0);1923 m_context->linkProgram(objectOrZero(program)); 1919 1924 program->cacheActiveAttribLocations(); 1920 1925 cleanupAfterGraphicsCall(false); … … 2061 2066 if (!validateWebGLObject(shader)) 2062 2067 return; 2063 m_context->shaderSource( shader ? shader->object() : 0, string);2068 m_context->shaderSource(objectOrZero(shader), string); 2064 2069 cleanupAfterGraphicsCall(false); 2065 2070 } … … 2950 2955 } 2951 2956 m_currentProgram = program; 2952 m_context->useProgram( program ? program->object() : 0);2957 m_context->useProgram(objectOrZero(program)); 2953 2958 cleanupAfterGraphicsCall(false); 2954 2959 } … … 2959 2964 if (!validateWebGLObject(program)) 2960 2965 return; 2961 m_context->validateProgram( program ? program->object() : 0);2966 m_context->validateProgram(objectOrZero(program)); 2962 2967 cleanupAfterGraphicsCall(false); 2963 2968 } … … 3262 3267 } 3263 3268 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_texture2DBinding->needToUseBlackTexture()) 3264 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, tex2D->object());3269 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZero(tex2D)); 3265 3270 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii].m_textureCubeMapBinding->needToUseBlackTexture()) 3266 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, texCubeMap->object());3271 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, objectOrZero(texCubeMap)); 3267 3272 } 3268 3273 } … … 3784 3789 const VertexAttribState& state = m_vertexAttribState[0]; 3785 3790 if (state.bufferBinding != m_vertexAttrib0Buffer) { 3786 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, state.bufferBinding->object());3791 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, objectOrZero(state.bufferBinding.get())); 3787 3792 m_context->vertexAttribPointer(0, state.size, state.type, state.normalized, state.originalStride, state.offset); 3788 3793 } 3789 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_boundArrayBuffer->object());3794 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, objectOrZero(m_boundArrayBuffer.get())); 3790 3795 } 3791 3796
Note: See TracChangeset
for help on using the changeset viewer.