Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1406 void WebGLRenderingContextBase::attachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) | 1406 void WebGLRenderingContextBase::attachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) |
| 1407 { | 1407 { |
| 1408 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) | 1408 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) |
| 1409 return; | 1409 return; |
| 1410 if (!program->attachShader(shader)) { | 1410 if (!program->attachShader(shader)) { |
| 1411 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader"); | 1411 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader"); |
| 1412 return; | 1412 return; |
| 1413 } | 1413 } |
| 1414 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader)); | 1414 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader)); |
| 1415 shader->onAttached(); | 1415 shader->onAttached(); |
| 1416 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader ->type()), shader); | 1416 preserveObjectWrapper(scriptState, program, V8PrivateProperty::getWebGLProgr amShaders(scriptState->isolate()), static_cast<uint32_t>(shader->type()), shader ); |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name) | 1419 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name) |
| 1420 { | 1420 { |
| 1421 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) | 1421 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) |
| 1422 return; | 1422 return; |
| 1423 if (!validateLocationLength("bindAttribLocation", name)) | 1423 if (!validateLocationLength("bindAttribLocation", name)) |
| 1424 return; | 1424 return; |
| 1425 if (isPrefixReserved(name)) { | 1425 if (isPrefixReserved(name)) { |
| 1426 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix"); | 1426 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix"); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1485 PreservedWrapperIndex idx = PreservedArrayBuffer; | 1485 PreservedWrapperIndex idx = PreservedArrayBuffer; |
| 1486 switch (target) { | 1486 switch (target) { |
| 1487 case GL_ARRAY_BUFFER: | 1487 case GL_ARRAY_BUFFER: |
| 1488 idx = PreservedArrayBuffer; | 1488 idx = PreservedArrayBuffer; |
| 1489 break; | 1489 break; |
| 1490 case GL_ELEMENT_ARRAY_BUFFER: | 1490 case GL_ELEMENT_ARRAY_BUFFER: |
| 1491 idx = PreservedElementArrayBuffer; | 1491 idx = PreservedElementArrayBuffer; |
| 1492 break; | 1492 break; |
| 1493 } | 1493 } |
| 1494 | 1494 |
| 1495 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, static_cast<uint32_t>(idx), buffer); | 1495 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRenderin gContextMisc(scriptState->isolate()), static_cast<uint32_t>(idx), buffer); |
| 1496 maybePreserveDefaultVAOObjectWrapper(scriptState); | 1496 maybePreserveDefaultVAOObjectWrapper(scriptState); |
| 1497 } | 1497 } |
| 1498 | 1498 |
| 1499 void WebGLRenderingContextBase::bindFramebuffer(ScriptState* scriptState, GLenum target, WebGLFramebuffer* buffer) | 1499 void WebGLRenderingContextBase::bindFramebuffer(ScriptState* scriptState, GLenum target, WebGLFramebuffer* buffer) |
| 1500 { | 1500 { |
| 1501 bool deleted; | 1501 bool deleted; |
| 1502 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) | 1502 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) |
| 1503 return; | 1503 return; |
| 1504 | 1504 |
| 1505 if (deleted) | 1505 if (deleted) |
| 1506 buffer = 0; | 1506 buffer = 0; |
| 1507 | 1507 |
| 1508 if (target != GL_FRAMEBUFFER) { | 1508 if (target != GL_FRAMEBUFFER) { |
| 1509 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); | 1509 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); |
| 1510 return; | 1510 return; |
| 1511 } | 1511 } |
| 1512 | 1512 |
| 1513 setFramebuffer(target, buffer); | 1513 setFramebuffer(target, buffer); |
| 1514 // This is called both internally and externally (from JavaScript). We only update which wrapper | 1514 // This is called both internally and externally (from JavaScript). We only update which wrapper |
| 1515 // is preserved when it's called from JavaScript. | 1515 // is preserved when it's called from JavaScript. |
| 1516 if (scriptState) { | 1516 if (scriptState) { |
| 1517 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedFramebuffer), buffer); | 1517 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRend eringContextMisc(scriptState->isolate()), static_cast<uint32_t>(PreservedFramebu ffer), buffer); |
| 1518 } | 1518 } |
| 1519 } | 1519 } |
| 1520 | 1520 |
| 1521 void WebGLRenderingContextBase::bindRenderbuffer(ScriptState* scriptState, GLenu m target, WebGLRenderbuffer* renderBuffer) | 1521 void WebGLRenderingContextBase::bindRenderbuffer(ScriptState* scriptState, GLenu m target, WebGLRenderbuffer* renderBuffer) |
| 1522 { | 1522 { |
| 1523 bool deleted; | 1523 bool deleted; |
| 1524 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) | 1524 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) |
| 1525 return; | 1525 return; |
| 1526 if (deleted) | 1526 if (deleted) |
| 1527 renderBuffer = 0; | 1527 renderBuffer = 0; |
| 1528 if (target != GL_RENDERBUFFER) { | 1528 if (target != GL_RENDERBUFFER) { |
| 1529 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ; | 1529 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ; |
| 1530 return; | 1530 return; |
| 1531 } | 1531 } |
| 1532 m_renderbufferBinding = renderBuffer; | 1532 m_renderbufferBinding = renderBuffer; |
| 1533 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer)); | 1533 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer)); |
| 1534 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, PreservedRenderbuffer, renderBuffer); | 1534 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRenderin gContextMisc(scriptState->isolate()), PreservedRenderbuffer, renderBuffer); |
| 1535 | 1535 |
| 1536 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer)); | 1536 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer)); |
| 1537 | 1537 |
| 1538 if (renderBuffer) | 1538 if (renderBuffer) |
| 1539 renderBuffer->setHasEverBeenBound(); | 1539 renderBuffer->setHasEverBeenBound(); |
| 1540 } | 1540 } |
| 1541 | 1541 |
| 1542 void WebGLRenderingContextBase::bindTexture(ScriptState* scriptState, GLenum tar get, WebGLTexture* texture) | 1542 void WebGLRenderingContextBase::bindTexture(ScriptState* scriptState, GLenum tar get, WebGLTexture* texture) |
| 1543 { | 1543 { |
| 1544 bool deleted; | 1544 bool deleted; |
| 1545 if (!checkObjectToBeBound("bindTexture", texture, deleted)) | 1545 if (!checkObjectToBeBound("bindTexture", texture, deleted)) |
| 1546 return; | 1546 return; |
| 1547 if (deleted) | 1547 if (deleted) |
| 1548 texture = 0; | 1548 texture = 0; |
| 1549 if (texture && texture->getTarget() && texture->getTarget() != target) { | 1549 if (texture && texture->getTarget() && texture->getTarget() != target) { |
| 1550 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets"); | 1550 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets"); |
| 1551 return; | 1551 return; |
| 1552 } | 1552 } |
| 1553 | 1553 |
| 1554 // ScriptState may be null if this method is called internally | 1554 // ScriptState may be null if this method is called internally |
| 1555 // during restoration of texture unit bindings. Skip the | 1555 // during restoration of texture unit bindings. Skip the |
| 1556 // preserveObjectWrapper work in this case. | 1556 // preserveObjectWrapper work in this case. |
| 1557 v8::Local<v8::String> hiddenValueName; | 1557 V8PrivateProperty::Symbol (*privateSymbolFn)(v8::Isolate* isolate) = nullptr ; |
| 1558 ScopedPersistent<v8::Array>* persistentCache = nullptr; | |
| 1559 if (target == GL_TEXTURE_2D) { | 1558 if (target == GL_TEXTURE_2D) { |
| 1560 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; | 1559 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; |
| 1561 | 1560 |
| 1562 if (!m_activeTextureUnit) | 1561 if (!m_activeTextureUnit) |
| 1563 drawingBuffer()->setTexture2DBinding(objectOrZero(texture)); | 1562 drawingBuffer()->setTexture2DBinding(objectOrZero(texture)); |
| 1564 if (scriptState) { | 1563 if (scriptState) { |
| 1565 hiddenValueName = V8HiddenValue::webgl2DTextures(scriptState->isolat e()); | 1564 privateSymbolFn = &V8PrivateProperty::getWebGLRenderingContextTextur es2D; |
| 1566 persistentCache = &m_2DTextureWrappers; | |
| 1567 } | 1565 } |
| 1568 } else if (target == GL_TEXTURE_CUBE_MAP) { | 1566 } else if (target == GL_TEXTURE_CUBE_MAP) { |
| 1569 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; | 1567 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; |
| 1570 if (scriptState) { | 1568 if (scriptState) { |
| 1571 hiddenValueName = V8HiddenValue::webglCubeMapTextures(scriptState->i solate()); | 1569 privateSymbolFn = &V8PrivateProperty::getWebGLRenderingContextTextur esCubeMap; |
| 1572 persistentCache = &m_cubeMapTextureWrappers; | |
| 1573 } | 1570 } |
| 1574 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) { | 1571 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) { |
| 1575 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture; | 1572 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture; |
| 1576 if (scriptState) { | 1573 if (scriptState) { |
| 1577 hiddenValueName = V8HiddenValue::webgl2DArrayTextures(scriptState->i solate()); | 1574 privateSymbolFn = &V8PrivateProperty::getWebGLRenderingContextTextur es2DArray; |
| 1578 persistentCache = &m_2DArrayTextureWrappers; | |
| 1579 } | 1575 } |
| 1580 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) { | 1576 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) { |
| 1581 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture; | 1577 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture; |
| 1582 if (scriptState) { | 1578 if (scriptState) { |
| 1583 hiddenValueName = V8HiddenValue::webgl3DTextures(scriptState->isolat e()); | 1579 privateSymbolFn = &V8PrivateProperty::getWebGLRenderingContextTextur es3D; |
| 1584 persistentCache = &m_3DTextureWrappers; | |
| 1585 } | 1580 } |
| 1586 } else { | 1581 } else { |
| 1587 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); | 1582 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); |
| 1588 return; | 1583 return; |
| 1589 } | 1584 } |
| 1590 | 1585 |
| 1591 contextGL()->BindTexture(target, objectOrZero(texture)); | 1586 contextGL()->BindTexture(target, objectOrZero(texture)); |
| 1592 // This is called both internally and externally (from JavaScript). We only update which wrapper | 1587 // This is called both internally and externally (from JavaScript). We only update which wrapper |
| 1593 // is preserved when it's called from JavaScript. | 1588 // is preserved when it's called from JavaScript. |
| 1594 if (scriptState) { | 1589 if (scriptState) { |
| 1595 preserveObjectWrapper(scriptState, this, hiddenValueName, persistentCach e, m_activeTextureUnit, texture); | 1590 preserveObjectWrapper(scriptState, this, privateSymbolFn(scriptState->is olate()), m_activeTextureUnit, texture); |
| 1596 } | 1591 } |
| 1597 if (texture) { | 1592 if (texture) { |
| 1598 texture->setTarget(target); | 1593 texture->setTarget(target); |
| 1599 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit); | 1594 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit); |
| 1600 } else { | 1595 } else { |
| 1601 // If the disabled index is the current maximum, trace backwards to find the new max enabled texture index | 1596 // If the disabled index is the current maximum, trace backwards to find the new max enabled texture index |
| 1602 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) { | 1597 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) { |
| 1603 findNewMaxNonDefaultTextureUnit(); | 1598 findNewMaxNonDefaultTextureUnit(); |
| 1604 } | 1599 } |
| 1605 } | 1600 } |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1988 return o; | 1983 return o; |
| 1989 } | 1984 } |
| 1990 | 1985 |
| 1991 void WebGLRenderingContextBase::setBoundVertexArrayObject(ScriptState* scriptSta te, WebGLVertexArrayObjectBase* arrayObject) | 1986 void WebGLRenderingContextBase::setBoundVertexArrayObject(ScriptState* scriptSta te, WebGLVertexArrayObjectBase* arrayObject) |
| 1992 { | 1987 { |
| 1993 if (arrayObject) | 1988 if (arrayObject) |
| 1994 m_boundVertexArrayObject = arrayObject; | 1989 m_boundVertexArrayObject = arrayObject; |
| 1995 else | 1990 else |
| 1996 m_boundVertexArrayObject = m_defaultVertexArrayObject; | 1991 m_boundVertexArrayObject = m_defaultVertexArrayObject; |
| 1997 | 1992 |
| 1998 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedVAO), arrayObject ); | 1993 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRenderin gContextMisc(scriptState->isolate()), static_cast<uint32_t>(PreservedVAO), array Object); |
| 1999 } | 1994 } |
| 2000 | 1995 |
| 2001 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type) | 1996 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type) |
| 2002 { | 1997 { |
| 2003 if (isContextLost()) | 1998 if (isContextLost()) |
| 2004 return nullptr; | 1999 return nullptr; |
| 2005 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { | 2000 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { |
| 2006 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" ); | 2001 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" ); |
| 2007 return nullptr; | 2002 return nullptr; |
| 2008 } | 2003 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2149 void WebGLRenderingContextBase::detachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) | 2144 void WebGLRenderingContextBase::detachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) |
| 2150 { | 2145 { |
| 2151 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) | 2146 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) |
| 2152 return; | 2147 return; |
| 2153 if (!program->detachShader(shader)) { | 2148 if (!program->detachShader(shader)) { |
| 2154 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched"); | 2149 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched"); |
| 2155 return; | 2150 return; |
| 2156 } | 2151 } |
| 2157 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader)); | 2152 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader)); |
| 2158 shader->onDetached(contextGL()); | 2153 shader->onDetached(contextGL()); |
| 2159 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader ->type()), nullptr); | 2154 preserveObjectWrapper(scriptState, program, V8PrivateProperty::getWebGLProgr amShaders(scriptState->isolate()), static_cast<uint32_t>(shader->type()), nullpt r); |
| 2160 } | 2155 } |
| 2161 | 2156 |
| 2162 void WebGLRenderingContextBase::disable(GLenum cap) | 2157 void WebGLRenderingContextBase::disable(GLenum cap) |
| 2163 { | 2158 { |
| 2164 if (isContextLost() || !validateCapability("disable", cap)) | 2159 if (isContextLost() || !validateCapability("disable", cap)) |
| 2165 return; | 2160 return; |
| 2166 if (cap == GL_STENCIL_TEST) { | 2161 if (cap == GL_STENCIL_TEST) { |
| 2167 m_stencilEnabled = false; | 2162 m_stencilEnabled = false; |
| 2168 applyStencilTest(); | 2163 applyStencilTest(); |
| 2169 return; | 2164 return; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2323 return; | 2318 return; |
| 2324 } | 2319 } |
| 2325 GLuint bufferObject = objectOrZero(buffer); | 2320 GLuint bufferObject = objectOrZero(buffer); |
| 2326 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | 2321 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2327 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. | 2322 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. |
| 2328 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. | 2323 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. |
| 2329 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render buffertarget, bufferObject); | 2324 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render buffertarget, bufferObject); |
| 2330 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend erbuffertarget, bufferObject); | 2325 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend erbuffertarget, bufferObject); |
| 2331 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, buffer); | 2326 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, buffer); |
| 2332 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, buffer); | 2327 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, buffer); |
| 2333 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_DEPTH_ATTACHMENT, buffer); | 2328 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), GL_DEPTH_ATTACHMENT, b uffer); |
| 2334 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_STENCIL_ATTACHMENT, buffer); | 2329 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), GL_STENCIL_ATTACHMENT, buffer); |
| 2335 } else { | 2330 } else { |
| 2336 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar get, bufferObject); | 2331 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar get, bufferObject); |
| 2337 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, buffer); | 2332 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, buffer); |
| 2338 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , attachment, buffer); | 2333 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), attachment, buffer); |
| 2339 } | 2334 } |
| 2340 applyStencilTest(); | 2335 applyStencilTest(); |
| 2341 } | 2336 } |
| 2342 | 2337 |
| 2343 void WebGLRenderingContextBase::framebufferTexture2D(ScriptState* scriptState, G Lenum target, GLenum attachment, GLenum textarget, WebGLTexture* texture, GLint level) | 2338 void WebGLRenderingContextBase::framebufferTexture2D(ScriptState* scriptState, G Lenum target, GLenum attachment, GLenum textarget, WebGLTexture* texture, GLint level) |
| 2344 { | 2339 { |
| 2345 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) | 2340 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) |
| 2346 return; | 2341 return; |
| 2347 if (texture && !texture->validate(contextGroup(), this)) { | 2342 if (texture && !texture->validate(contextGroup(), this)) { |
| 2348 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context"); | 2343 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context"); |
| 2349 return; | 2344 return; |
| 2350 } | 2345 } |
| 2351 // Don't allow the default framebuffer to be mutated; all current | 2346 // Don't allow the default framebuffer to be mutated; all current |
| 2352 // implementations use an FBO internally in place of the default | 2347 // implementations use an FBO internally in place of the default |
| 2353 // FBO. | 2348 // FBO. |
| 2354 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); | 2349 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
| 2355 if (!framebufferBinding || !framebufferBinding->object()) { | 2350 if (!framebufferBinding || !framebufferBinding->object()) { |
| 2356 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound"); | 2351 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound"); |
| 2357 return; | 2352 return; |
| 2358 } | 2353 } |
| 2359 GLuint textureObject = objectOrZero(texture); | 2354 GLuint textureObject = objectOrZero(texture); |
| 2360 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | 2355 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2361 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. | 2356 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. |
| 2362 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. | 2357 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. |
| 2363 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget , textureObject, level); | 2358 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget , textureObject, level); |
| 2364 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg et, textureObject, level); | 2359 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg et, textureObject, level); |
| 2365 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, textarget, texture, level, 0); | 2360 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, textarget, texture, level, 0); |
| 2366 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, textarget, texture, level, 0); | 2361 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, textarget, texture, level, 0); |
| 2367 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_DEPTH_ATTACHMENT, texture); | 2362 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), GL_DEPTH_ATTACHMENT, t exture); |
| 2368 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_STENCIL_ATTACHMENT, texture); | 2363 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), GL_STENCIL_ATTACHMENT, texture); |
| 2369 } else { | 2364 } else { |
| 2370 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture Object, level); | 2365 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture Object, level); |
| 2371 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, textarget, texture, level, 0); | 2366 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, textarget, texture, level, 0); |
| 2372 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , attachment, texture); | 2367 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), attachment, texture); |
| 2373 } | 2368 } |
| 2374 applyStencilTest(); | 2369 applyStencilTest(); |
| 2375 } | 2370 } |
| 2376 | 2371 |
| 2377 void WebGLRenderingContextBase::frontFace(GLenum mode) | 2372 void WebGLRenderingContextBase::frontFace(GLenum mode) |
| 2378 { | 2373 { |
| 2379 if (isContextLost()) | 2374 if (isContextLost()) |
| 2380 return; | 2375 return; |
| 2381 contextGL()->FrontFace(mode); | 2376 contextGL()->FrontFace(mode); |
| 2382 } | 2377 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2593 break; | 2588 break; |
| 2594 } | 2589 } |
| 2595 } | 2590 } |
| 2596 } | 2591 } |
| 2597 | 2592 |
| 2598 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context ()->Global(), scriptState->isolate()); | 2593 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context ()->Global(), scriptState->isolate()); |
| 2599 | 2594 |
| 2600 if (linkContextToExtension) { | 2595 if (linkContextToExtension) { |
| 2601 // Keep the extension's JavaScript wrapper alive as long as the context is alive, so that | 2596 // Keep the extension's JavaScript wrapper alive as long as the context is alive, so that |
| 2602 // expando properties that are added to the extension persist. | 2597 // expando properties that are added to the extension persist. |
| 2603 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglExtensions( scriptState->isolate()), &m_extensionWrappers, static_cast<uint32_t>(extension-> name()), extension); | 2598 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRend eringContextExtensions(scriptState->isolate()), static_cast<uint32_t>(extension- >name()), extension); |
| 2604 } | 2599 } |
| 2605 | 2600 |
| 2606 return ScriptValue(scriptState, wrappedExtension); | 2601 return ScriptValue(scriptState, wrappedExtension); |
| 2607 } | 2602 } |
| 2608 | 2603 |
| 2609 ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(ScriptS tate* scriptState, GLenum target, GLenum attachment, GLenum pname) | 2604 ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(ScriptS tate* scriptState, GLenum target, GLenum attachment, GLenum pname) |
| 2610 { | 2605 { |
| 2611 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment)) | 2606 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment)) |
| 2612 return ScriptValue::createNull(scriptState); | 2607 return ScriptValue::createNull(scriptState); |
| 2613 | 2608 |
| (...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4918 return; | 4913 return; |
| 4919 } | 4914 } |
| 4920 | 4915 |
| 4921 if (m_currentProgram != program) { | 4916 if (m_currentProgram != program) { |
| 4922 if (m_currentProgram) | 4917 if (m_currentProgram) |
| 4923 m_currentProgram->onDetached(contextGL()); | 4918 m_currentProgram->onDetached(contextGL()); |
| 4924 m_currentProgram = program; | 4919 m_currentProgram = program; |
| 4925 contextGL()->UseProgram(objectOrZero(program)); | 4920 contextGL()->UseProgram(objectOrZero(program)); |
| 4926 if (program) | 4921 if (program) |
| 4927 program->onAttached(); | 4922 program->onAttached(); |
| 4928 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedProgram), pro gram); | 4923 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRend eringContextMisc(scriptState->isolate()), static_cast<uint32_t>(PreservedProgram ), program); |
| 4929 } | 4924 } |
| 4930 } | 4925 } |
| 4931 | 4926 |
| 4932 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program) | 4927 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program) |
| 4933 { | 4928 { |
| 4934 if (isContextLost() || !validateWebGLObject("validateProgram", program)) | 4929 if (isContextLost() || !validateWebGLObject("validateProgram", program)) |
| 4935 return; | 4930 return; |
| 4936 contextGL()->ValidateProgram(objectOrZero(program)); | 4931 contextGL()->ValidateProgram(objectOrZero(program)); |
| 4937 } | 4932 } |
| 4938 | 4933 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5081 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) | 5076 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) |
| 5082 return; | 5077 return; |
| 5083 if (!m_boundArrayBuffer) { | 5078 if (!m_boundArrayBuffer) { |
| 5084 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER"); | 5079 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER"); |
| 5085 return; | 5080 return; |
| 5086 } | 5081 } |
| 5087 | 5082 |
| 5088 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer. get()); | 5083 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer. get()); |
| 5089 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein terpret_cast<void*>(static_cast<intptr_t>(offset))); | 5084 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein terpret_cast<void*>(static_cast<intptr_t>(offset))); |
| 5090 maybePreserveDefaultVAOObjectWrapper(scriptState); | 5085 maybePreserveDefaultVAOObjectWrapper(scriptState); |
| 5091 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, V8HiddenValue:: webglBuffers(scriptState->isolate()), m_boundVertexArrayObject->getPersistentCac he(), index, m_boundArrayBuffer); | 5086 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, V8PrivateProper ty::getWebGLVertexArrayObjectBaseBuffers(scriptState->isolate()), index, m_bound ArrayBuffer); |
| 5092 } | 5087 } |
| 5093 | 5088 |
| 5094 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor) | 5089 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor) |
| 5095 { | 5090 { |
| 5096 if (isContextLost()) | 5091 if (isContextLost()) |
| 5097 return; | 5092 return; |
| 5098 | 5093 |
| 5099 if (index >= m_maxVertexAttribs) { | 5094 if (index >= m_maxVertexAttribs) { |
| 5100 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); | 5095 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); |
| 5101 return; | 5096 return; |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6317 for (int i = startIndex; i >= 0; --i) { | 6312 for (int i = startIndex; i >= 0; --i) { |
| 6318 if (m_textureUnits[i].m_texture2DBinding | 6313 if (m_textureUnits[i].m_texture2DBinding |
| 6319 || m_textureUnits[i].m_textureCubeMapBinding) { | 6314 || m_textureUnits[i].m_textureCubeMapBinding) { |
| 6320 m_onePlusMaxNonDefaultTextureUnit = i + 1; | 6315 m_onePlusMaxNonDefaultTextureUnit = i + 1; |
| 6321 return; | 6316 return; |
| 6322 } | 6317 } |
| 6323 } | 6318 } |
| 6324 m_onePlusMaxNonDefaultTextureUnit = 0; | 6319 m_onePlusMaxNonDefaultTextureUnit = 0; |
| 6325 } | 6320 } |
| 6326 | 6321 |
| 6327 void WebGLRenderingContextBase::preserveObjectWrapper(ScriptState* scriptState, ScriptWrappable* sourceObject, v8::Local<v8::String> hiddenValueName, ScopedPers istent<v8::Array>* persistentCache, uint32_t index, ScriptWrappable* targetObjec t) | 6322 void WebGLRenderingContextBase::preserveObjectWrapper(ScriptState* scriptState, ScriptWrappable* sourceObject, const V8PrivateProperty::Symbol& privateSymbol, u int32_t index, ScriptWrappable* targetObject) |
| 6328 { | 6323 { |
| 6329 v8::Isolate* isolate = scriptState->isolate(); | 6324 v8::Isolate* isolate = scriptState->isolate(); |
| 6330 if (persistentCache->isEmpty()) { | 6325 v8::Local<v8::Context> context = scriptState->context(); |
| 6331 // TODO(kbr): eliminate the persistent caches and just use | 6326 v8::Local<v8::Object> sourceWrapper = v8::Local<v8::Object>::Cast(toV8( |
| 6332 // V8HiddenValue::getHiddenValue. Unfortunately, it's | 6327 sourceObject, context->Global(), isolate)); |
| 6333 // currently too slow to use. crbug.com/611864 | 6328 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( |
| 6334 persistentCache->set(isolate, v8::Array::New(isolate)); | 6329 privateSymbol.get(context, sourceWrapper)); |
| 6335 V8HiddenValue::setHiddenValue( | 6330 if (array.IsEmpty()) { |
| 6336 scriptState, | 6331 array = v8::Array::New(isolate); |
| 6337 sourceObject->mainWorldWrapper(isolate), | 6332 privateSymbol.set(context, sourceWrapper, array); |
| 6338 hiddenValueName, | |
| 6339 persistentCache->newLocal(isolate)); | |
| 6340 // It is important to mark the persistent cache as weak | |
| 6341 // (phantom, actually). Otherwise there will be a reference | |
| 6342 // cycle between it and its JavaScript wrapper, and currently | |
| 6343 // there are problems collecting such cycles. | |
| 6344 persistentCache->setPhantom(); | |
| 6345 } | 6333 } |
| 6346 | |
| 6347 v8::Local<v8::Array> localCache = persistentCache->newLocal(isolate); | |
| 6348 if (targetObject) { | 6334 if (targetObject) { |
| 6349 v8CallOrCrash(localCache->Set(scriptState->context(), index, targetObjec t->mainWorldWrapper(isolate))); | 6335 v8CallOrCrash(array->Set(context, index, toV8(targetObject, context->Glo bal(), isolate))); |
|
Yuki
2016/06/02 13:07:22
This is another reason why this CL is slower. |ta
Ken Russell (switch to Gerrit)
2016/06/03 00:59:19
Thanks for pointing this out. I tried adding two c
| |
| 6350 } else { | 6336 } else { |
| 6351 v8CallOrCrash(localCache->Set(scriptState->context(), index, v8::Null(is olate))); | 6337 v8CallOrCrash(array->Set(context, index, v8::Null(isolate))); |
| 6352 } | 6338 } |
| 6353 } | 6339 } |
| 6354 | 6340 |
| 6355 void WebGLRenderingContextBase::maybePreserveDefaultVAOObjectWrapper(ScriptState * scriptState) | 6341 void WebGLRenderingContextBase::maybePreserveDefaultVAOObjectWrapper(ScriptState * scriptState) |
| 6356 { | 6342 { |
| 6357 ASSERT(scriptState); | 6343 ASSERT(scriptState); |
| 6358 | 6344 |
| 6359 if (!m_preservedDefaultVAOObjectWrapper) { | 6345 if (!m_preservedDefaultVAOObjectWrapper) { |
| 6360 // The default VAO does not have a JavaScript wrapper created for it, bu t one is needed to | 6346 // The default VAO does not have a JavaScript wrapper created for it, bu t one is needed to |
| 6361 // link up the WebGLBuffers associated with the vertex attributes. | 6347 // link up the WebGLBuffers associated with the vertex attributes. |
| 6362 toV8(m_defaultVertexArrayObject, scriptState->context()->Global(), scrip tState->isolate()); | 6348 toV8(m_defaultVertexArrayObject, scriptState->context()->Global(), scrip tState->isolate()); |
| 6363 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedDefaultVAO), m_defaultVertexArrayObject); | 6349 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRend eringContextMisc(scriptState->isolate()), static_cast<uint32_t>(PreservedDefault VAO), m_defaultVertexArrayObject); |
| 6364 m_preservedDefaultVAOObjectWrapper = true; | 6350 m_preservedDefaultVAOObjectWrapper = true; |
| 6365 } | 6351 } |
| 6366 } | 6352 } |
| 6367 | 6353 |
| 6368 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState) | 6354 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState) |
| 6369 { | 6355 { |
| 6370 visitor->trace(m_texture2DBinding); | 6356 visitor->trace(m_texture2DBinding); |
| 6371 visitor->trace(m_textureCubeMapBinding); | 6357 visitor->trace(m_textureCubeMapBinding); |
| 6372 visitor->trace(m_texture3DBinding); | 6358 visitor->trace(m_texture3DBinding); |
| 6373 visitor->trace(m_texture2DArrayBinding); | 6359 visitor->trace(m_texture2DArrayBinding); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6424 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6410 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6425 } | 6411 } |
| 6426 | 6412 |
| 6427 void WebGLRenderingContextBase::restoreUnpackParameters() | 6413 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6428 { | 6414 { |
| 6429 if (m_unpackAlignment != 1) | 6415 if (m_unpackAlignment != 1) |
| 6430 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6416 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6431 } | 6417 } |
| 6432 | 6418 |
| 6433 } // namespace blink | 6419 } // namespace blink |
| OLD | NEW |