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 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 922 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, | 922 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, |
| 923 OffscreenCanvas* passedOffscreenCanvas, std::unique_ptr<WebGraphicsContext3D Provider> contextProvider, | 923 OffscreenCanvas* passedOffscreenCanvas, std::unique_ptr<WebGraphicsContext3D Provider> contextProvider, |
| 924 const CanvasContextCreationAttributes& requestedAttributes, unsigned version ) | 924 const CanvasContextCreationAttributes& requestedAttributes, unsigned version ) |
| 925 : CanvasRenderingContext(passedCanvas, passedOffscreenCanvas, requestedAttri butes) | 925 : CanvasRenderingContext(passedCanvas, passedOffscreenCanvas, requestedAttri butes) |
| 926 , m_isHidden(false) | 926 , m_isHidden(false) |
| 927 , m_contextLostMode(NotLostContext) | 927 , m_contextLostMode(NotLostContext) |
| 928 , m_autoRecoveryMethod(Manual) | 928 , m_autoRecoveryMethod(Manual) |
| 929 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) | 929 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) |
| 930 , m_restoreAllowed(false) | 930 , m_restoreAllowed(false) |
| 931 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) | 931 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) |
| 932 , m_preservedDefaultVAOObjectWrapper(false) | |
| 933 , m_generatedImageCache(4) | 932 , m_generatedImageCache(4) |
| 934 , m_synthesizedErrorsToConsole(true) | 933 , m_synthesizedErrorsToConsole(true) |
| 935 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) | 934 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) |
| 936 , m_onePlusMaxNonDefaultTextureUnit(0) | 935 , m_onePlusMaxNonDefaultTextureUnit(0) |
| 937 , m_isWebGL2FormatsTypesAdded(false) | 936 , m_isWebGL2FormatsTypesAdded(false) |
| 938 , m_isWebGL2InternalFormatsCopyTexImageAdded(false) | 937 , m_isWebGL2InternalFormatsCopyTexImageAdded(false) |
| 939 , m_isOESTextureFloatFormatsTypesAdded(false) | 938 , m_isOESTextureFloatFormatsTypesAdded(false) |
| 940 , m_isOESTextureHalfFloatFormatsTypesAdded(false) | 939 , m_isOESTextureHalfFloatFormatsTypesAdded(false) |
| 941 , m_isWebGLDepthTextureFormatsTypesAdded(false) | 940 , m_isWebGLDepthTextureFormatsTypesAdded(false) |
| 942 , m_isEXTsRGBFormatsTypesAdded(false) | 941 , m_isEXTsRGBFormatsTypesAdded(false) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 // These two values from EXT_draw_buffers are lazily queried. | 1062 // These two values from EXT_draw_buffers are lazily queried. |
| 1064 m_maxDrawBuffers = 0; | 1063 m_maxDrawBuffers = 0; |
| 1065 m_maxColorAttachments = 0; | 1064 m_maxColorAttachments = 0; |
| 1066 | 1065 |
| 1067 m_backDrawBuffer = GL_BACK; | 1066 m_backDrawBuffer = GL_BACK; |
| 1068 | 1067 |
| 1069 m_readBufferOfDefaultFramebuffer = GL_BACK; | 1068 m_readBufferOfDefaultFramebuffer = GL_BACK; |
| 1070 | 1069 |
| 1071 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLVerte xArrayObjectBase::VaoTypeDefault); | 1070 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLVerte xArrayObjectBase::VaoTypeDefault); |
| 1072 addContextObject(m_defaultVertexArrayObject.get()); | 1071 addContextObject(m_defaultVertexArrayObject.get()); |
| 1073 // It's not convenient or necessary to pass a ScriptState this far down; whi le one is available | 1072 |
| 1074 // during WebGLRenderingContext construction, the wrapper for the context it self hasn't been | |
| 1075 // created yet. It's simpler to instead lazily instantiate and preserve the JavaScript wrapper | |
| 1076 // for the default VAO. (This object is never exposed to JavaScript, but we need to link other | |
| 1077 // JavaScript wrappers to it.) | |
| 1078 m_preservedDefaultVAOObjectWrapper = false; | |
| 1079 m_boundVertexArrayObject = m_defaultVertexArrayObject; | 1073 m_boundVertexArrayObject = m_defaultVertexArrayObject; |
| 1080 | 1074 |
| 1081 m_vertexAttribType.resize(m_maxVertexAttribs); | 1075 m_vertexAttribType.resize(m_maxVertexAttribs); |
| 1082 | 1076 |
| 1083 contextGL()->Viewport(0, 0, drawingBufferWidth(), drawingBufferHeight()); | 1077 contextGL()->Viewport(0, 0, drawingBufferWidth(), drawingBufferHeight()); |
| 1084 contextGL()->Scissor(0, 0, drawingBufferWidth(), drawingBufferHeight()); | 1078 contextGL()->Scissor(0, 0, drawingBufferWidth(), drawingBufferHeight()); |
| 1085 | 1079 |
| 1086 drawingBuffer()->contextProvider()->setLostContextCallback( | 1080 drawingBuffer()->contextProvider()->setLostContextCallback( |
| 1087 WebClosure(WTF::bind( | 1081 WebClosure(WTF::bind( |
| 1088 &WebGLRenderingContextBase::forceLostContext, | 1082 &WebGLRenderingContextBase::forceLostContext, |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1442 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of range"); | 1436 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of range"); |
| 1443 return; | 1437 return; |
| 1444 } | 1438 } |
| 1445 m_activeTextureUnit = texture - GL_TEXTURE0; | 1439 m_activeTextureUnit = texture - GL_TEXTURE0; |
| 1446 contextGL()->ActiveTexture(texture); | 1440 contextGL()->ActiveTexture(texture); |
| 1447 | 1441 |
| 1448 drawingBuffer()->setActiveTextureUnit(texture); | 1442 drawingBuffer()->setActiveTextureUnit(texture); |
| 1449 | 1443 |
| 1450 } | 1444 } |
| 1451 | 1445 |
| 1452 void WebGLRenderingContextBase::attachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) | 1446 void WebGLRenderingContextBase::attachShader(WebGLProgram* program, WebGLShader* shader) |
| 1453 { | 1447 { |
| 1454 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) | 1448 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) |
| 1455 return; | 1449 return; |
| 1456 if (!program->attachShader(shader)) { | 1450 if (!program->attachShader(shader)) { |
| 1457 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader"); | 1451 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader"); |
| 1458 return; | 1452 return; |
| 1459 } | 1453 } |
| 1460 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader)); | 1454 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader)); |
| 1461 shader->onAttached(); | 1455 shader->onAttached(); |
| 1462 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader ->type()), shader); | |
| 1463 } | 1456 } |
| 1464 | 1457 |
| 1465 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name) | 1458 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name) |
| 1466 { | 1459 { |
| 1467 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) | 1460 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) |
| 1468 return; | 1461 return; |
| 1469 if (!validateLocationLength("bindAttribLocation", name)) | 1462 if (!validateLocationLength("bindAttribLocation", name)) |
| 1470 return; | 1463 return; |
| 1471 if (isPrefixReserved(name)) { | 1464 if (isPrefixReserved(name)) { |
| 1472 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix"); | 1465 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1510 default: | 1503 default: |
| 1511 ASSERT_NOT_REACHED(); | 1504 ASSERT_NOT_REACHED(); |
| 1512 return false; | 1505 return false; |
| 1513 } | 1506 } |
| 1514 | 1507 |
| 1515 if (buffer && !buffer->getInitialTarget()) | 1508 if (buffer && !buffer->getInitialTarget()) |
| 1516 buffer->setInitialTarget(target); | 1509 buffer->setInitialTarget(target); |
| 1517 return true; | 1510 return true; |
| 1518 } | 1511 } |
| 1519 | 1512 |
| 1520 void WebGLRenderingContextBase::bindBuffer(ScriptState* scriptState, GLenum targ et, WebGLBuffer* buffer) | 1513 void WebGLRenderingContextBase::bindBuffer(GLenum target, WebGLBuffer* buffer) |
| 1521 { | 1514 { |
| 1522 bool deleted; | 1515 bool deleted; |
| 1523 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) | 1516 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) |
| 1524 return; | 1517 return; |
| 1525 if (deleted) | 1518 if (deleted) |
| 1526 buffer = 0; | 1519 buffer = 0; |
| 1527 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer)) | 1520 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer)) |
| 1528 return; | 1521 return; |
| 1529 | 1522 |
| 1530 contextGL()->BindBuffer(target, objectOrZero(buffer)); | 1523 contextGL()->BindBuffer(target, objectOrZero(buffer)); |
| 1531 PreservedWrapperIndex idx = PreservedArrayBuffer; | |
| 1532 switch (target) { | |
| 1533 case GL_ARRAY_BUFFER: | |
| 1534 idx = PreservedArrayBuffer; | |
| 1535 break; | |
| 1536 case GL_ELEMENT_ARRAY_BUFFER: | |
| 1537 idx = PreservedElementArrayBuffer; | |
| 1538 break; | |
| 1539 } | |
| 1540 | |
| 1541 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, static_cast<uint32_t>(idx), buffer); | |
| 1542 maybePreserveDefaultVAOObjectWrapper(scriptState); | |
| 1543 } | 1524 } |
| 1544 | 1525 |
| 1545 void WebGLRenderingContextBase::bindFramebuffer(ScriptState* scriptState, GLenum target, WebGLFramebuffer* buffer) | 1526 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer* buffer) |
| 1546 { | 1527 { |
| 1547 bool deleted; | 1528 bool deleted; |
| 1548 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) | 1529 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) |
| 1549 return; | 1530 return; |
| 1550 | 1531 |
| 1551 if (deleted) | 1532 if (deleted) |
| 1552 buffer = 0; | 1533 buffer = 0; |
| 1553 | 1534 |
| 1554 if (target != GL_FRAMEBUFFER) { | 1535 if (target != GL_FRAMEBUFFER) { |
| 1555 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); | 1536 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); |
| 1556 return; | 1537 return; |
| 1557 } | 1538 } |
| 1558 | 1539 |
| 1559 setFramebuffer(target, buffer); | 1540 setFramebuffer(target, buffer); |
| 1560 // This is called both internally and externally (from JavaScript). We only update which wrapper | |
| 1561 // is preserved when it's called from JavaScript. | |
| 1562 if (scriptState) { | |
| 1563 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedFramebuffer), buffer); | |
| 1564 } | |
| 1565 } | 1541 } |
| 1566 | 1542 |
| 1567 void WebGLRenderingContextBase::bindRenderbuffer(ScriptState* scriptState, GLenu m target, WebGLRenderbuffer* renderBuffer) | 1543 void WebGLRenderingContextBase::bindRenderbuffer(GLenum target, WebGLRenderbuffe r* renderBuffer) |
| 1568 { | 1544 { |
| 1569 bool deleted; | 1545 bool deleted; |
| 1570 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) | 1546 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) |
| 1571 return; | 1547 return; |
| 1572 if (deleted) | 1548 if (deleted) |
| 1573 renderBuffer = 0; | 1549 renderBuffer = 0; |
| 1574 if (target != GL_RENDERBUFFER) { | 1550 if (target != GL_RENDERBUFFER) { |
| 1575 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ; | 1551 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ; |
| 1576 return; | 1552 return; |
| 1577 } | 1553 } |
| 1578 m_renderbufferBinding = renderBuffer; | 1554 m_renderbufferBinding = renderBuffer; |
| 1579 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer)); | 1555 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer)); |
| 1580 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, PreservedRenderbuffer, renderBuffer); | |
| 1581 | 1556 |
| 1582 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer)); | 1557 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer)); |
| 1583 | 1558 |
| 1584 if (renderBuffer) | 1559 if (renderBuffer) |
| 1585 renderBuffer->setHasEverBeenBound(); | 1560 renderBuffer->setHasEverBeenBound(); |
| 1586 } | 1561 } |
| 1587 | 1562 |
| 1588 void WebGLRenderingContextBase::bindTexture(ScriptState* scriptState, GLenum tar get, WebGLTexture* texture) | 1563 void WebGLRenderingContextBase::bindTexture(GLenum target, WebGLTexture* texture ) |
| 1589 { | 1564 { |
| 1590 bool deleted; | 1565 bool deleted; |
| 1591 if (!checkObjectToBeBound("bindTexture", texture, deleted)) | 1566 if (!checkObjectToBeBound("bindTexture", texture, deleted)) |
| 1592 return; | 1567 return; |
| 1593 if (deleted) | 1568 if (deleted) |
| 1594 texture = 0; | 1569 texture = 0; |
| 1595 if (texture && texture->getTarget() && texture->getTarget() != target) { | 1570 if (texture && texture->getTarget() && texture->getTarget() != target) { |
| 1596 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets"); | 1571 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets"); |
| 1597 return; | 1572 return; |
| 1598 } | 1573 } |
| 1599 | 1574 |
| 1600 // ScriptState may be null if this method is called internally | |
| 1601 // during restoration of texture unit bindings. Skip the | |
| 1602 // preserveObjectWrapper work in this case. | |
| 1603 v8::Local<v8::String> hiddenValueName; | |
| 1604 ScopedPersistent<v8::Array>* persistentCache = nullptr; | |
| 1605 if (target == GL_TEXTURE_2D) { | 1575 if (target == GL_TEXTURE_2D) { |
| 1606 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; | 1576 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; |
| 1607 | 1577 |
| 1608 if (!m_activeTextureUnit) | 1578 if (!m_activeTextureUnit) |
| 1609 drawingBuffer()->setTexture2DBinding(objectOrZero(texture)); | 1579 drawingBuffer()->setTexture2DBinding(objectOrZero(texture)); |
| 1610 if (scriptState) { | |
| 1611 hiddenValueName = V8HiddenValue::webgl2DTextures(scriptState->isolat e()); | |
| 1612 persistentCache = &m_wrappersOf2DTextures; | |
| 1613 } | |
| 1614 } else if (target == GL_TEXTURE_CUBE_MAP) { | 1580 } else if (target == GL_TEXTURE_CUBE_MAP) { |
| 1615 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; | 1581 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; |
| 1616 if (scriptState) { | |
| 1617 hiddenValueName = V8HiddenValue::webglCubeMapTextures(scriptState->i solate()); | |
| 1618 persistentCache = &m_cubeMapTextureWrappers; | |
| 1619 } | |
| 1620 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) { | 1582 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) { |
| 1621 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture; | 1583 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture; |
| 1622 if (scriptState) { | |
| 1623 hiddenValueName = V8HiddenValue::webgl2DArrayTextures(scriptState->i solate()); | |
| 1624 persistentCache = &m_wrappersOf2DArrayTextures; | |
| 1625 } | |
| 1626 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) { | 1584 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) { |
| 1627 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture; | 1585 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture; |
| 1628 if (scriptState) { | |
| 1629 hiddenValueName = V8HiddenValue::webgl3DTextures(scriptState->isolat e()); | |
| 1630 persistentCache = &m_wrappersOf3DTextures; | |
| 1631 } | |
| 1632 } else { | 1586 } else { |
| 1633 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); | 1587 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); |
| 1634 return; | 1588 return; |
| 1635 } | 1589 } |
| 1636 | 1590 |
| 1637 contextGL()->BindTexture(target, objectOrZero(texture)); | 1591 contextGL()->BindTexture(target, objectOrZero(texture)); |
| 1638 // This is called both internally and externally (from JavaScript). We only update which wrapper | |
| 1639 // is preserved when it's called from JavaScript. | |
| 1640 if (scriptState) { | |
| 1641 preserveObjectWrapper(scriptState, this, hiddenValueName, persistentCach e, m_activeTextureUnit, texture); | |
| 1642 } | |
| 1643 if (texture) { | 1592 if (texture) { |
| 1644 texture->setTarget(target); | 1593 texture->setTarget(target); |
| 1645 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit); | 1594 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit); |
| 1646 } else { | 1595 } else { |
| 1647 // 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 |
| 1648 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) { | 1597 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) { |
| 1649 findNewMaxNonDefaultTextureUnit(); | 1598 findNewMaxNonDefaultTextureUnit(); |
| 1650 } | 1599 } |
| 1651 } | 1600 } |
| 1652 | 1601 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2027 | 1976 |
| 2028 WebGLRenderbuffer* WebGLRenderingContextBase::createRenderbuffer() | 1977 WebGLRenderbuffer* WebGLRenderingContextBase::createRenderbuffer() |
| 2029 { | 1978 { |
| 2030 if (isContextLost()) | 1979 if (isContextLost()) |
| 2031 return nullptr; | 1980 return nullptr; |
| 2032 WebGLRenderbuffer* o = WebGLRenderbuffer::create(this); | 1981 WebGLRenderbuffer* o = WebGLRenderbuffer::create(this); |
| 2033 addSharedObject(o); | 1982 addSharedObject(o); |
| 2034 return o; | 1983 return o; |
| 2035 } | 1984 } |
| 2036 | 1985 |
| 2037 void WebGLRenderingContextBase::setBoundVertexArrayObject(ScriptState* scriptSta te, WebGLVertexArrayObjectBase* arrayObject) | 1986 void WebGLRenderingContextBase::setBoundVertexArrayObject(WebGLVertexArrayObject Base* arrayObject) |
| 2038 { | 1987 { |
| 2039 if (arrayObject) | 1988 if (arrayObject) |
| 2040 m_boundVertexArrayObject = arrayObject; | 1989 m_boundVertexArrayObject = arrayObject; |
| 2041 else | 1990 else |
| 2042 m_boundVertexArrayObject = m_defaultVertexArrayObject; | 1991 m_boundVertexArrayObject = m_defaultVertexArrayObject; |
| 2043 | |
| 2044 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedVAO), arrayObject ); | |
| 2045 } | 1992 } |
| 2046 | 1993 |
| 2047 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type) | 1994 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type) |
| 2048 { | 1995 { |
| 2049 if (isContextLost()) | 1996 if (isContextLost()) |
| 2050 return nullptr; | 1997 return nullptr; |
| 2051 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { | 1998 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { |
| 2052 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" ); | 1999 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" ); |
| 2053 return nullptr; | 2000 return nullptr; |
| 2054 } | 2001 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2185 if (isContextLost()) | 2132 if (isContextLost()) |
| 2186 return; | 2133 return; |
| 2187 // Check required by WebGL spec section 6.12 | 2134 // Check required by WebGL spec section 6.12 |
| 2188 if (zNear > zFar) { | 2135 if (zNear > zFar) { |
| 2189 synthesizeGLError(GL_INVALID_OPERATION, "depthRange", "zNear > zFar"); | 2136 synthesizeGLError(GL_INVALID_OPERATION, "depthRange", "zNear > zFar"); |
| 2190 return; | 2137 return; |
| 2191 } | 2138 } |
| 2192 contextGL()->DepthRangef(zNear, zFar); | 2139 contextGL()->DepthRangef(zNear, zFar); |
| 2193 } | 2140 } |
| 2194 | 2141 |
| 2195 void WebGLRenderingContextBase::detachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) | 2142 void WebGLRenderingContextBase::detachShader(WebGLProgram* program, WebGLShader* shader) |
| 2196 { | 2143 { |
| 2197 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) | 2144 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) |
| 2198 return; | 2145 return; |
| 2199 if (!program->detachShader(shader)) { | 2146 if (!program->detachShader(shader)) { |
| 2200 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched"); | 2147 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched"); |
| 2201 return; | 2148 return; |
| 2202 } | 2149 } |
| 2203 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader)); | 2150 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader)); |
| 2204 shader->onDetached(contextGL()); | 2151 shader->onDetached(contextGL()); |
| 2205 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader ->type()), nullptr); | |
| 2206 } | 2152 } |
| 2207 | 2153 |
| 2208 void WebGLRenderingContextBase::disable(GLenum cap) | 2154 void WebGLRenderingContextBase::disable(GLenum cap) |
| 2209 { | 2155 { |
| 2210 if (isContextLost() || !validateCapability("disable", cap)) | 2156 if (isContextLost() || !validateCapability("disable", cap)) |
| 2211 return; | 2157 return; |
| 2212 if (cap == GL_STENCIL_TEST) { | 2158 if (cap == GL_STENCIL_TEST) { |
| 2213 m_stencilEnabled = false; | 2159 m_stencilEnabled = false; |
| 2214 applyStencilTest(); | 2160 applyStencilTest(); |
| 2215 return; | 2161 return; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2358 contextGL()->Flush(); // Intentionally a flush, not a finish. | 2304 contextGL()->Flush(); // Intentionally a flush, not a finish. |
| 2359 } | 2305 } |
| 2360 | 2306 |
| 2361 void WebGLRenderingContextBase::flush() | 2307 void WebGLRenderingContextBase::flush() |
| 2362 { | 2308 { |
| 2363 if (isContextLost()) | 2309 if (isContextLost()) |
| 2364 return; | 2310 return; |
| 2365 contextGL()->Flush(); | 2311 contextGL()->Flush(); |
| 2366 } | 2312 } |
| 2367 | 2313 |
| 2368 void WebGLRenderingContextBase::framebufferRenderbuffer(ScriptState* scriptState , GLenum target, GLenum attachment, GLenum renderbuffertarget, WebGLRenderbuffer * buffer) | 2314 void WebGLRenderingContextBase::framebufferRenderbuffer(GLenum target, GLenum at tachment, GLenum renderbuffertarget, WebGLRenderbuffer* buffer) |
| 2369 { | 2315 { |
| 2370 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment)) | 2316 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment)) |
| 2371 return; | 2317 return; |
| 2372 if (renderbuffertarget != GL_RENDERBUFFER) { | 2318 if (renderbuffertarget != GL_RENDERBUFFER) { |
| 2373 synthesizeGLError(GL_INVALID_ENUM, "framebufferRenderbuffer", "invalid t arget"); | 2319 synthesizeGLError(GL_INVALID_ENUM, "framebufferRenderbuffer", "invalid t arget"); |
| 2374 return; | 2320 return; |
| 2375 } | 2321 } |
| 2376 if (buffer && !buffer->validate(contextGroup(), this)) { | 2322 if (buffer && !buffer->validate(contextGroup(), this)) { |
| 2377 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no b uffer or buffer not from this context"); | 2323 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no b uffer or buffer not from this context"); |
| 2378 return; | 2324 return; |
| 2379 } | 2325 } |
| 2380 // Don't allow the default framebuffer to be mutated; all current | 2326 // Don't allow the default framebuffer to be mutated; all current |
| 2381 // implementations use an FBO internally in place of the default | 2327 // implementations use an FBO internally in place of the default |
| 2382 // FBO. | 2328 // FBO. |
| 2383 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); | 2329 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
| 2384 if (!framebufferBinding || !framebufferBinding->object()) { | 2330 if (!framebufferBinding || !framebufferBinding->object()) { |
| 2385 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no f ramebuffer bound"); | 2331 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no f ramebuffer bound"); |
| 2386 return; | 2332 return; |
| 2387 } | 2333 } |
| 2388 GLuint bufferObject = objectOrZero(buffer); | 2334 GLuint bufferObject = objectOrZero(buffer); |
| 2389 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | 2335 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2390 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. | 2336 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. |
| 2391 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. | 2337 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. |
| 2392 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render buffertarget, bufferObject); | 2338 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render buffertarget, bufferObject); |
| 2393 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend erbuffertarget, bufferObject); | 2339 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend erbuffertarget, bufferObject); |
| 2394 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, buffer); | 2340 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, buffer); |
| 2395 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, buffer); | 2341 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, buffer); |
| 2396 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_DEPTH_ATTACHMENT, buffer); | |
| 2397 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_STENCIL_ATTACHMENT, buffer); | |
| 2398 } else { | 2342 } else { |
| 2399 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar get, bufferObject); | 2343 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar get, bufferObject); |
| 2400 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, buffer); | 2344 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, buffer); |
| 2401 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , attachment, buffer); | |
| 2402 } | 2345 } |
| 2403 applyStencilTest(); | 2346 applyStencilTest(); |
| 2404 } | 2347 } |
| 2405 | 2348 |
| 2406 void WebGLRenderingContextBase::framebufferTexture2D(ScriptState* scriptState, G Lenum target, GLenum attachment, GLenum textarget, WebGLTexture* texture, GLint level) | 2349 void WebGLRenderingContextBase::framebufferTexture2D(GLenum target, GLenum attac hment, GLenum textarget, WebGLTexture* texture, GLint level) |
| 2407 { | 2350 { |
| 2408 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) | 2351 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) |
| 2409 return; | 2352 return; |
| 2410 if (texture && !texture->validate(contextGroup(), this)) { | 2353 if (texture && !texture->validate(contextGroup(), this)) { |
| 2411 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context"); | 2354 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context"); |
| 2412 return; | 2355 return; |
| 2413 } | 2356 } |
| 2414 // Don't allow the default framebuffer to be mutated; all current | 2357 // Don't allow the default framebuffer to be mutated; all current |
| 2415 // implementations use an FBO internally in place of the default | 2358 // implementations use an FBO internally in place of the default |
| 2416 // FBO. | 2359 // FBO. |
| 2417 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); | 2360 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
| 2418 if (!framebufferBinding || !framebufferBinding->object()) { | 2361 if (!framebufferBinding || !framebufferBinding->object()) { |
| 2419 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound"); | 2362 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound"); |
| 2420 return; | 2363 return; |
| 2421 } | 2364 } |
| 2422 GLuint textureObject = objectOrZero(texture); | 2365 GLuint textureObject = objectOrZero(texture); |
| 2423 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | 2366 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2424 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. | 2367 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. |
| 2425 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. | 2368 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. |
| 2426 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget , textureObject, level); | 2369 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget , textureObject, level); |
| 2427 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg et, textureObject, level); | 2370 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg et, textureObject, level); |
| 2428 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, textarget, texture, level, 0); | 2371 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, textarget, texture, level, 0); |
| 2429 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, textarget, texture, level, 0); | 2372 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, textarget, texture, level, 0); |
| 2430 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_DEPTH_ATTACHMENT, texture); | |
| 2431 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_STENCIL_ATTACHMENT, texture); | |
| 2432 } else { | 2373 } else { |
| 2433 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture Object, level); | 2374 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture Object, level); |
| 2434 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, textarget, texture, level, 0); | 2375 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, textarget, texture, level, 0); |
| 2435 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , attachment, texture); | |
| 2436 } | 2376 } |
| 2437 applyStencilTest(); | 2377 applyStencilTest(); |
| 2438 } | 2378 } |
| 2439 | 2379 |
| 2440 void WebGLRenderingContextBase::frontFace(GLenum mode) | 2380 void WebGLRenderingContextBase::frontFace(GLenum mode) |
| 2441 { | 2381 { |
| 2442 if (isContextLost()) | 2382 if (isContextLost()) |
| 2443 return; | 2383 return; |
| 2444 contextGL()->FrontFace(mode); | 2384 contextGL()->FrontFace(mode); |
| 2445 } | 2385 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2631 if (tracker->draft() && !RuntimeEnabledFeatures::webGLDraftExtensionsEnabled ()) | 2571 if (tracker->draft() && !RuntimeEnabledFeatures::webGLDraftExtensionsEnabled ()) |
| 2632 return false; | 2572 return false; |
| 2633 if (!tracker->supported(this)) | 2573 if (!tracker->supported(this)) |
| 2634 return false; | 2574 return false; |
| 2635 return true; | 2575 return true; |
| 2636 } | 2576 } |
| 2637 | 2577 |
| 2638 ScriptValue WebGLRenderingContextBase::getExtension(ScriptState* scriptState, co nst String& name) | 2578 ScriptValue WebGLRenderingContextBase::getExtension(ScriptState* scriptState, co nst String& name) |
| 2639 { | 2579 { |
| 2640 WebGLExtension* extension = nullptr; | 2580 WebGLExtension* extension = nullptr; |
| 2641 bool linkContextToExtension = false; | |
| 2642 | 2581 |
| 2643 if (!isContextLost()) { | 2582 if (!isContextLost()) { |
| 2644 for (size_t i = 0; i < m_extensions.size(); ++i) { | 2583 for (size_t i = 0; i < m_extensions.size(); ++i) { |
| 2645 ExtensionTracker* tracker = m_extensions[i]; | 2584 ExtensionTracker* tracker = m_extensions[i]; |
| 2646 if (tracker->matchesNameWithPrefixes(name)) { | 2585 if (tracker->matchesNameWithPrefixes(name)) { |
| 2647 if (extensionSupportedAndAllowed(tracker)) { | 2586 if (extensionSupportedAndAllowed(tracker)) { |
| 2648 extension = tracker->getExtension(this); | 2587 extension = tracker->getExtension(this); |
| 2649 if (extension) { | 2588 if (extension) { |
| 2650 if (!m_extensionEnabled[extension->name()]) { | 2589 if (!m_extensionEnabled[extension->name()]) { |
| 2651 linkContextToExtension = true; | |
| 2652 m_extensionEnabled[extension->name()] = true; | 2590 m_extensionEnabled[extension->name()] = true; |
| 2653 } | 2591 } |
| 2654 } | 2592 } |
| 2655 } | 2593 } |
| 2656 break; | 2594 break; |
| 2657 } | 2595 } |
| 2658 } | 2596 } |
| 2659 } | 2597 } |
| 2660 | 2598 |
| 2661 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context ()->Global(), scriptState->isolate()); | 2599 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context ()->Global(), scriptState->isolate()); |
| 2662 | 2600 |
| 2663 if (linkContextToExtension) { | |
| 2664 // Keep the extension's JavaScript wrapper alive as long as the context is alive, so that | |
| 2665 // expando properties that are added to the extension persist. | |
| 2666 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglExtensions( scriptState->isolate()), &m_extensionWrappers, static_cast<uint32_t>(extension-> name()), extension); | |
| 2667 } | |
| 2668 | |
| 2669 return ScriptValue(scriptState, wrappedExtension); | 2601 return ScriptValue(scriptState, wrappedExtension); |
| 2670 } | 2602 } |
| 2671 | 2603 |
| 2672 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) |
| 2673 { | 2605 { |
| 2674 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment)) | 2606 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment)) |
| 2675 return ScriptValue::createNull(scriptState); | 2607 return ScriptValue::createNull(scriptState); |
| 2676 | 2608 |
| 2677 if (!m_framebufferBinding || !m_framebufferBinding->object()) { | 2609 if (!m_framebufferBinding || !m_framebufferBinding->object()) { |
| 2678 synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParamet er", "no framebuffer bound"); | 2610 synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParamet er", "no framebuffer bound"); |
| (...skipping 2281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4960 contextGL()->UniformMatrix4fv(location->location(), v->length() >> 4, transp ose, v->data()); | 4892 contextGL()->UniformMatrix4fv(location->location(), v->length() >> 4, transp ose, v->data()); |
| 4961 } | 4893 } |
| 4962 | 4894 |
| 4963 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Vector<GLfloat>& v) | 4895 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Vector<GLfloat>& v) |
| 4964 { | 4896 { |
| 4965 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v.data(), v.size(), 16)) | 4897 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v.data(), v.size(), 16)) |
| 4966 return; | 4898 return; |
| 4967 contextGL()->UniformMatrix4fv(location->location(), v.size() >> 4, transpose , v.data()); | 4899 contextGL()->UniformMatrix4fv(location->location(), v.size() >> 4, transpose , v.data()); |
| 4968 } | 4900 } |
| 4969 | 4901 |
| 4970 void WebGLRenderingContextBase::useProgram(ScriptState* scriptState, WebGLProgra m* program) | 4902 void WebGLRenderingContextBase::useProgram(WebGLProgram* program) |
| 4971 { | 4903 { |
| 4972 bool deleted; | 4904 bool deleted; |
| 4973 if (!checkObjectToBeBound("useProgram", program, deleted)) | 4905 if (!checkObjectToBeBound("useProgram", program, deleted)) |
| 4974 return; | 4906 return; |
| 4975 if (deleted) | 4907 if (deleted) |
| 4976 program = 0; | 4908 program = 0; |
| 4977 if (program && !program->linkStatus(this)) { | 4909 if (program && !program->linkStatus(this)) { |
| 4978 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid "); | 4910 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid "); |
| 4979 return; | 4911 return; |
| 4980 } | 4912 } |
| 4981 | 4913 |
| 4982 if (m_currentProgram != program) { | 4914 if (m_currentProgram != program) { |
| 4983 if (m_currentProgram) | 4915 if (m_currentProgram) |
| 4984 m_currentProgram->onDetached(contextGL()); | 4916 m_currentProgram->onDetached(contextGL()); |
| 4985 m_currentProgram = program; | 4917 m_currentProgram = program; |
| 4986 contextGL()->UseProgram(objectOrZero(program)); | 4918 contextGL()->UseProgram(objectOrZero(program)); |
| 4987 if (program) | 4919 if (program) |
| 4988 program->onAttached(); | 4920 program->onAttached(); |
| 4989 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedProgram), pro gram); | |
| 4990 } | 4921 } |
| 4991 } | 4922 } |
| 4992 | 4923 |
| 4993 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program) | 4924 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program) |
| 4994 { | 4925 { |
| 4995 if (isContextLost() || !validateWebGLObject("validateProgram", program)) | 4926 if (isContextLost() || !validateWebGLObject("validateProgram", program)) |
| 4996 return; | 4927 return; |
| 4997 contextGL()->ValidateProgram(objectOrZero(program)); | 4928 contextGL()->ValidateProgram(objectOrZero(program)); |
| 4998 } | 4929 } |
| 4999 | 4930 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5124 if (isContextLost()) | 5055 if (isContextLost()) |
| 5125 return; | 5056 return; |
| 5126 if (v.size() < 4) { | 5057 if (v.size() < 4) { |
| 5127 synthesizeGLError(GL_INVALID_VALUE, "vertexAttrib4fv", "invalid array"); | 5058 synthesizeGLError(GL_INVALID_VALUE, "vertexAttrib4fv", "invalid array"); |
| 5128 return; | 5059 return; |
| 5129 } | 5060 } |
| 5130 contextGL()->VertexAttrib4fv(index, v.data()); | 5061 contextGL()->VertexAttrib4fv(index, v.data()); |
| 5131 setVertexAttribType(index, Float32ArrayType); | 5062 setVertexAttribType(index, Float32ArrayType); |
| 5132 } | 5063 } |
| 5133 | 5064 |
| 5134 void WebGLRenderingContextBase::vertexAttribPointer(ScriptState* scriptState, GL uint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, long long offset) | 5065 void WebGLRenderingContextBase::vertexAttribPointer(GLuint index, GLint size, GL enum type, GLboolean normalized, GLsizei stride, long long offset) |
| 5135 { | 5066 { |
| 5136 if (isContextLost()) | 5067 if (isContextLost()) |
| 5137 return; | 5068 return; |
| 5138 if (index >= m_maxVertexAttribs) { | 5069 if (index >= m_maxVertexAttribs) { |
| 5139 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "index out of range"); | 5070 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "index out of range"); |
| 5140 return; | 5071 return; |
| 5141 } | 5072 } |
| 5142 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) | 5073 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) |
| 5143 return; | 5074 return; |
| 5144 if (!m_boundArrayBuffer) { | 5075 if (!m_boundArrayBuffer) { |
| 5145 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER"); | 5076 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER"); |
| 5146 return; | 5077 return; |
| 5147 } | 5078 } |
| 5148 | 5079 |
| 5149 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer. get()); | 5080 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer. get()); |
| 5150 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein terpret_cast<void*>(static_cast<intptr_t>(offset))); | 5081 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein terpret_cast<void*>(static_cast<intptr_t>(offset))); |
| 5151 maybePreserveDefaultVAOObjectWrapper(scriptState); | |
| 5152 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, V8HiddenValue:: webglBuffers(scriptState->isolate()), m_boundVertexArrayObject->getPersistentCac he(), index, m_boundArrayBuffer); | |
| 5153 } | 5082 } |
| 5154 | 5083 |
| 5155 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor) | 5084 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor) |
| 5156 { | 5085 { |
| 5157 if (isContextLost()) | 5086 if (isContextLost()) |
| 5158 return; | 5087 return; |
| 5159 | 5088 |
| 5160 if (index >= m_maxVertexAttribs) { | 5089 if (index >= m_maxVertexAttribs) { |
| 5161 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); | 5090 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); |
| 5162 return; | 5091 return; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5282 { | 5211 { |
| 5283 ASSERT(!isContextLost()); | 5212 ASSERT(!isContextLost()); |
| 5284 m_contextGroup->addObject(object); | 5213 m_contextGroup->addObject(object); |
| 5285 } | 5214 } |
| 5286 | 5215 |
| 5287 void WebGLRenderingContextBase::removeContextObject(WebGLContextObject* object) | 5216 void WebGLRenderingContextBase::removeContextObject(WebGLContextObject* object) |
| 5288 { | 5217 { |
| 5289 m_contextObjects.remove(object); | 5218 m_contextObjects.remove(object); |
| 5290 } | 5219 } |
| 5291 | 5220 |
| 5221 void WebGLRenderingContextBase::visitChildDOMWrappers(v8::Isolate* isolate, cons t v8::Persistent<v8::Object>& wrapper) | |
| 5222 { | |
| 5223 if (isContextLost()) { | |
| 5224 return; | |
| 5225 } | |
| 5226 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, m_boundArrayBuffer , isolate); | |
| 5227 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, m_renderbufferBind ing, isolate); | |
| 5228 | |
| 5229 for (auto& unit : m_textureUnits) { | |
| 5230 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, unit.m_texture 2DBinding, isolate); | |
| 5231 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, unit.m_texture CubeMapBinding, isolate); | |
| 5232 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, unit.m_texture 3DBinding, isolate); | |
| 5233 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, unit.m_texture 2DArrayBinding, isolate); | |
| 5234 } | |
| 5235 | |
| 5236 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, m_framebufferBindi ng, isolate); | |
| 5237 if (m_framebufferBinding) { | |
| 5238 m_framebufferBinding->visitChildDOMWrappers(isolate, wrapper); | |
| 5239 } | |
| 5240 | |
| 5241 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, m_currentProgram, isolate); | |
| 5242 if (m_currentProgram) { | |
| 5243 m_currentProgram->visitChildDOMWrappers(isolate, wrapper); | |
| 5244 } | |
| 5245 | |
| 5246 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, m_boundVertexArray Object, isolate); | |
| 5247 if (m_boundVertexArrayObject) { | |
| 5248 m_boundVertexArrayObject->visitChildDOMWrappers(isolate, wrapper); | |
| 5249 } | |
| 5250 | |
| 5251 for (ExtensionTracker* tracker : m_extensions) { | |
| 5252 WebGLExtension* extension = tracker->getExtensionObjectIfAlreadyEnabled( ); | |
| 5253 if (extension) { | |
|
Ken Russell (switch to Gerrit)
2016/09/02 19:13:57
This null-check isn't needed.
Kai Ninomiya
2016/09/03 01:02:05
Done.
| |
| 5254 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, extension, isolate); | |
| 5255 } | |
| 5256 } | |
| 5257 } | |
| 5258 | |
| 5292 void WebGLRenderingContextBase::addContextObject(WebGLContextObject* object) | 5259 void WebGLRenderingContextBase::addContextObject(WebGLContextObject* object) |
| 5293 { | 5260 { |
| 5294 ASSERT(!isContextLost()); | 5261 ASSERT(!isContextLost()); |
| 5295 m_contextObjects.add(object); | 5262 m_contextObjects.add(object); |
| 5296 } | 5263 } |
| 5297 | 5264 |
| 5298 void WebGLRenderingContextBase::detachAndRemoveAllObjects() | 5265 void WebGLRenderingContextBase::detachAndRemoveAllObjects() |
| 5299 { | 5266 { |
| 5300 while (m_contextObjects.size() > 0) { | 5267 while (m_contextObjects.size() > 0) { |
| 5301 // Following detachContext() will remove the iterated object from | 5268 // Following detachContext() will remove the iterated object from |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6376 if (!buffer) { | 6343 if (!buffer) { |
| 6377 // Instead of binding fb 0, bind the drawing buffer. | 6344 // Instead of binding fb 0, bind the drawing buffer. |
| 6378 drawingBuffer()->bind(target); | 6345 drawingBuffer()->bind(target); |
| 6379 } else { | 6346 } else { |
| 6380 contextGL()->BindFramebuffer(target, buffer->object()); | 6347 contextGL()->BindFramebuffer(target, buffer->object()); |
| 6381 } | 6348 } |
| 6382 } | 6349 } |
| 6383 | 6350 |
| 6384 void WebGLRenderingContextBase::restoreCurrentFramebuffer() | 6351 void WebGLRenderingContextBase::restoreCurrentFramebuffer() |
| 6385 { | 6352 { |
| 6386 bindFramebuffer(nullptr, GL_FRAMEBUFFER, m_framebufferBinding.get()); | 6353 bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding.get()); |
| 6387 } | 6354 } |
| 6388 | 6355 |
| 6389 void WebGLRenderingContextBase::restoreCurrentTexture2D() | 6356 void WebGLRenderingContextBase::restoreCurrentTexture2D() |
| 6390 { | 6357 { |
| 6391 bindTexture(nullptr, GL_TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_te xture2DBinding.get()); | 6358 bindTexture(GL_TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_texture2DBi nding.get()); |
| 6392 } | 6359 } |
| 6393 | 6360 |
| 6394 void WebGLRenderingContextBase::findNewMaxNonDefaultTextureUnit() | 6361 void WebGLRenderingContextBase::findNewMaxNonDefaultTextureUnit() |
| 6395 { | 6362 { |
| 6396 // Trace backwards from the current max to find the new max non-default text ure unit | 6363 // Trace backwards from the current max to find the new max non-default text ure unit |
| 6397 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1; | 6364 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1; |
| 6398 for (int i = startIndex; i >= 0; --i) { | 6365 for (int i = startIndex; i >= 0; --i) { |
| 6399 if (m_textureUnits[i].m_texture2DBinding | 6366 if (m_textureUnits[i].m_texture2DBinding |
| 6400 || m_textureUnits[i].m_textureCubeMapBinding) { | 6367 || m_textureUnits[i].m_textureCubeMapBinding) { |
| 6401 m_onePlusMaxNonDefaultTextureUnit = i + 1; | 6368 m_onePlusMaxNonDefaultTextureUnit = i + 1; |
| 6402 return; | 6369 return; |
| 6403 } | 6370 } |
| 6404 } | 6371 } |
| 6405 m_onePlusMaxNonDefaultTextureUnit = 0; | 6372 m_onePlusMaxNonDefaultTextureUnit = 0; |
| 6406 } | 6373 } |
| 6407 | 6374 |
| 6408 void WebGLRenderingContextBase::preserveObjectWrapper(ScriptState* scriptState, ScriptWrappable* sourceObject, v8::Local<v8::String> hiddenValueName, ScopedPers istent<v8::Array>* persistentCache, uint32_t index, ScriptWrappable* targetObjec t) | |
| 6409 { | |
| 6410 v8::Isolate* isolate = scriptState->isolate(); | |
| 6411 if (persistentCache->isEmpty()) { | |
| 6412 // TODO(kbr): eliminate the persistent caches and just use | |
| 6413 // V8HiddenValue::getHiddenValue. Unfortunately, it's | |
| 6414 // currently too slow to use. crbug.com/611864 | |
| 6415 persistentCache->set(isolate, v8::Array::New(isolate)); | |
| 6416 V8HiddenValue::setHiddenValue( | |
| 6417 scriptState, | |
| 6418 sourceObject->mainWorldWrapper(isolate), | |
| 6419 hiddenValueName, | |
| 6420 persistentCache->newLocal(isolate)); | |
| 6421 // It is important to mark the persistent cache as weak | |
| 6422 // (phantom, actually). Otherwise there will be a reference | |
| 6423 // cycle between it and its JavaScript wrapper, and currently | |
| 6424 // there are problems collecting such cycles. | |
| 6425 persistentCache->setPhantom(); | |
| 6426 } | |
| 6427 | |
| 6428 v8::Local<v8::Array> localCache = persistentCache->newLocal(isolate); | |
| 6429 if (targetObject) { | |
| 6430 localCache->Set(scriptState->context(), index, targetObject->mainWorldWr apper(isolate)).ToChecked(); | |
| 6431 } else { | |
| 6432 localCache->Set(scriptState->context(), index, v8::Null(isolate)).ToChec ked(); | |
| 6433 } | |
| 6434 } | |
| 6435 | |
| 6436 void WebGLRenderingContextBase::maybePreserveDefaultVAOObjectWrapper(ScriptState * scriptState) | |
| 6437 { | |
| 6438 ASSERT(scriptState); | |
| 6439 | |
| 6440 if (!m_preservedDefaultVAOObjectWrapper) { | |
| 6441 // The default VAO does not have a JavaScript wrapper created for it, bu t one is needed to | |
| 6442 // link up the WebGLBuffers associated with the vertex attributes. | |
| 6443 toV8(m_defaultVertexArrayObject, scriptState->context()->Global(), scrip tState->isolate()); | |
| 6444 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedDefaultVAO), m_defaultVertexArrayObject); | |
| 6445 m_preservedDefaultVAOObjectWrapper = true; | |
| 6446 } | |
| 6447 } | |
| 6448 | |
| 6449 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState) | 6375 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState) |
| 6450 { | 6376 { |
| 6451 visitor->trace(m_texture2DBinding); | 6377 visitor->trace(m_texture2DBinding); |
| 6452 visitor->trace(m_textureCubeMapBinding); | 6378 visitor->trace(m_textureCubeMapBinding); |
| 6453 visitor->trace(m_texture3DBinding); | 6379 visitor->trace(m_texture3DBinding); |
| 6454 visitor->trace(m_texture2DArrayBinding); | 6380 visitor->trace(m_texture2DArrayBinding); |
| 6455 } | 6381 } |
| 6456 | 6382 |
| 6457 DEFINE_TRACE(WebGLRenderingContextBase) | 6383 DEFINE_TRACE(WebGLRenderingContextBase) |
| 6458 { | 6384 { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6513 | 6439 |
| 6514 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const | 6440 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const |
| 6515 { | 6441 { |
| 6516 if (canvas()) | 6442 if (canvas()) |
| 6517 result.setHTMLCanvasElement(canvas()); | 6443 result.setHTMLCanvasElement(canvas()); |
| 6518 else | 6444 else |
| 6519 result.setOffscreenCanvas(getOffscreenCanvas()); | 6445 result.setOffscreenCanvas(getOffscreenCanvas()); |
| 6520 } | 6446 } |
| 6521 | 6447 |
| 6522 } // namespace blink | 6448 } // namespace blink |
| OLD | NEW |