| 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 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa
nvas, | 901 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa
nvas, |
| 902 OffscreenCanvas* passedOffscreenCanvas, std::unique_ptr<WebGraphicsContext3D
Provider> contextProvider, | 902 OffscreenCanvas* passedOffscreenCanvas, std::unique_ptr<WebGraphicsContext3D
Provider> contextProvider, |
| 903 const CanvasContextCreationAttributes& requestedAttributes, unsigned version
) | 903 const CanvasContextCreationAttributes& requestedAttributes, unsigned version
) |
| 904 : CanvasRenderingContext(passedCanvas, passedOffscreenCanvas, requestedAttri
butes) | 904 : CanvasRenderingContext(passedCanvas, passedOffscreenCanvas, requestedAttri
butes) |
| 905 , m_isHidden(false) | 905 , m_isHidden(false) |
| 906 , m_contextLostMode(NotLostContext) | 906 , m_contextLostMode(NotLostContext) |
| 907 , m_autoRecoveryMethod(Manual) | 907 , m_autoRecoveryMethod(Manual) |
| 908 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch
ContextLostEvent) | 908 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch
ContextLostEvent) |
| 909 , m_restoreAllowed(false) | 909 , m_restoreAllowed(false) |
| 910 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) | 910 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) |
| 911 , m_preservedDefaultVAOObjectWrapper(false) | |
| 912 , m_generatedImageCache(4) | 911 , m_generatedImageCache(4) |
| 913 , m_synthesizedErrorsToConsole(true) | 912 , m_synthesizedErrorsToConsole(true) |
| 914 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) | 913 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) |
| 915 , m_onePlusMaxNonDefaultTextureUnit(0) | 914 , m_onePlusMaxNonDefaultTextureUnit(0) |
| 916 , m_isWebGL2FormatsTypesAdded(false) | 915 , m_isWebGL2FormatsTypesAdded(false) |
| 917 , m_isWebGL2InternalFormatsCopyTexImageAdded(false) | 916 , m_isWebGL2InternalFormatsCopyTexImageAdded(false) |
| 918 , m_isOESTextureFloatFormatsTypesAdded(false) | 917 , m_isOESTextureFloatFormatsTypesAdded(false) |
| 919 , m_isOESTextureHalfFloatFormatsTypesAdded(false) | 918 , m_isOESTextureHalfFloatFormatsTypesAdded(false) |
| 920 , m_isWebGLDepthTextureFormatsTypesAdded(false) | 919 , m_isWebGLDepthTextureFormatsTypesAdded(false) |
| 921 , m_isEXTsRGBFormatsTypesAdded(false) | 920 , m_isEXTsRGBFormatsTypesAdded(false) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 // These two values from EXT_draw_buffers are lazily queried. | 1041 // These two values from EXT_draw_buffers are lazily queried. |
| 1043 m_maxDrawBuffers = 0; | 1042 m_maxDrawBuffers = 0; |
| 1044 m_maxColorAttachments = 0; | 1043 m_maxColorAttachments = 0; |
| 1045 | 1044 |
| 1046 m_backDrawBuffer = GL_BACK; | 1045 m_backDrawBuffer = GL_BACK; |
| 1047 | 1046 |
| 1048 m_readBufferOfDefaultFramebuffer = GL_BACK; | 1047 m_readBufferOfDefaultFramebuffer = GL_BACK; |
| 1049 | 1048 |
| 1050 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLVerte
xArrayObjectBase::VaoTypeDefault); | 1049 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLVerte
xArrayObjectBase::VaoTypeDefault); |
| 1051 addContextObject(m_defaultVertexArrayObject.get()); | 1050 addContextObject(m_defaultVertexArrayObject.get()); |
| 1052 // It's not convenient or necessary to pass a ScriptState this far down; whi
le one is available | 1051 |
| 1053 // during WebGLRenderingContext construction, the wrapper for the context it
self hasn't been | |
| 1054 // created yet. It's simpler to instead lazily instantiate and preserve the
JavaScript wrapper | |
| 1055 // for the default VAO. (This object is never exposed to JavaScript, but we
need to link other | |
| 1056 // JavaScript wrappers to it.) | |
| 1057 m_preservedDefaultVAOObjectWrapper = false; | |
| 1058 m_boundVertexArrayObject = m_defaultVertexArrayObject; | 1052 m_boundVertexArrayObject = m_defaultVertexArrayObject; |
| 1059 | 1053 |
| 1060 m_vertexAttribType.resize(m_maxVertexAttribs); | 1054 m_vertexAttribType.resize(m_maxVertexAttribs); |
| 1061 | 1055 |
| 1062 contextGL()->Viewport(0, 0, drawingBufferWidth(), drawingBufferHeight()); | 1056 contextGL()->Viewport(0, 0, drawingBufferWidth(), drawingBufferHeight()); |
| 1063 contextGL()->Scissor(0, 0, drawingBufferWidth(), drawingBufferHeight()); | 1057 contextGL()->Scissor(0, 0, drawingBufferWidth(), drawingBufferHeight()); |
| 1064 | 1058 |
| 1065 drawingBuffer()->contextProvider()->setLostContextCallback( | 1059 drawingBuffer()->contextProvider()->setLostContextCallback( |
| 1066 WebClosure(WTF::bind( | 1060 WebClosure(WTF::bind( |
| 1067 &WebGLRenderingContextBase::forceLostContext, | 1061 &WebGLRenderingContextBase::forceLostContext, |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1421 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of
range"); | 1415 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of
range"); |
| 1422 return; | 1416 return; |
| 1423 } | 1417 } |
| 1424 m_activeTextureUnit = texture - GL_TEXTURE0; | 1418 m_activeTextureUnit = texture - GL_TEXTURE0; |
| 1425 contextGL()->ActiveTexture(texture); | 1419 contextGL()->ActiveTexture(texture); |
| 1426 | 1420 |
| 1427 drawingBuffer()->setActiveTextureUnit(texture); | 1421 drawingBuffer()->setActiveTextureUnit(texture); |
| 1428 | 1422 |
| 1429 } | 1423 } |
| 1430 | 1424 |
| 1431 void WebGLRenderingContextBase::attachShader(ScriptState* scriptState, WebGLProg
ram* program, WebGLShader* shader) | 1425 void WebGLRenderingContextBase::attachShader(WebGLProgram* program, WebGLShader*
shader) |
| 1432 { | 1426 { |
| 1433 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val
idateWebGLObject("attachShader", shader)) | 1427 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val
idateWebGLObject("attachShader", shader)) |
| 1434 return; | 1428 return; |
| 1435 if (!program->attachShader(shader)) { | 1429 if (!program->attachShader(shader)) { |
| 1436 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme
nt already has shader"); | 1430 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme
nt already has shader"); |
| 1437 return; | 1431 return; |
| 1438 } | 1432 } |
| 1439 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader)); | 1433 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader)); |
| 1440 shader->onAttached(); | 1434 shader->onAttached(); |
| 1441 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri
ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader
->type()), shader); | |
| 1442 } | 1435 } |
| 1443 | 1436 |
| 1444 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint
index, const String& name) | 1437 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint
index, const String& name) |
| 1445 { | 1438 { |
| 1446 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) | 1439 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) |
| 1447 return; | 1440 return; |
| 1448 if (!validateLocationLength("bindAttribLocation", name)) | 1441 if (!validateLocationLength("bindAttribLocation", name)) |
| 1449 return; | 1442 return; |
| 1450 if (isPrefixReserved(name)) { | 1443 if (isPrefixReserved(name)) { |
| 1451 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved
prefix"); | 1444 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved
prefix"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 default: | 1482 default: |
| 1490 ASSERT_NOT_REACHED(); | 1483 ASSERT_NOT_REACHED(); |
| 1491 return false; | 1484 return false; |
| 1492 } | 1485 } |
| 1493 | 1486 |
| 1494 if (buffer && !buffer->getInitialTarget()) | 1487 if (buffer && !buffer->getInitialTarget()) |
| 1495 buffer->setInitialTarget(target); | 1488 buffer->setInitialTarget(target); |
| 1496 return true; | 1489 return true; |
| 1497 } | 1490 } |
| 1498 | 1491 |
| 1499 void WebGLRenderingContextBase::bindBuffer(ScriptState* scriptState, GLenum targ
et, WebGLBuffer* buffer) | 1492 void WebGLRenderingContextBase::bindBuffer(GLenum target, WebGLBuffer* buffer) |
| 1500 { | 1493 { |
| 1501 bool deleted; | 1494 bool deleted; |
| 1502 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) | 1495 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) |
| 1503 return; | 1496 return; |
| 1504 if (deleted) | 1497 if (deleted) |
| 1505 buffer = 0; | 1498 buffer = 0; |
| 1506 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer)) | 1499 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer)) |
| 1507 return; | 1500 return; |
| 1508 | 1501 |
| 1509 contextGL()->BindBuffer(target, objectOrZero(buffer)); | 1502 contextGL()->BindBuffer(target, objectOrZero(buffer)); |
| 1510 PreservedWrapperIndex idx = PreservedArrayBuffer; | |
| 1511 switch (target) { | |
| 1512 case GL_ARRAY_BUFFER: | |
| 1513 idx = PreservedArrayBuffer; | |
| 1514 break; | |
| 1515 case GL_ELEMENT_ARRAY_BUFFER: | |
| 1516 idx = PreservedElementArrayBuffer; | |
| 1517 break; | |
| 1518 } | |
| 1519 | |
| 1520 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat
e->isolate()), &m_miscWrappers, static_cast<uint32_t>(idx), buffer); | |
| 1521 maybePreserveDefaultVAOObjectWrapper(scriptState); | |
| 1522 } | 1503 } |
| 1523 | 1504 |
| 1524 void WebGLRenderingContextBase::bindFramebuffer(ScriptState* scriptState, GLenum
target, WebGLFramebuffer* buffer) | 1505 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer*
buffer) |
| 1525 { | 1506 { |
| 1526 bool deleted; | 1507 bool deleted; |
| 1527 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) | 1508 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) |
| 1528 return; | 1509 return; |
| 1529 | 1510 |
| 1530 if (deleted) | 1511 if (deleted) |
| 1531 buffer = 0; | 1512 buffer = 0; |
| 1532 | 1513 |
| 1533 if (target != GL_FRAMEBUFFER) { | 1514 if (target != GL_FRAMEBUFFER) { |
| 1534 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); | 1515 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); |
| 1535 return; | 1516 return; |
| 1536 } | 1517 } |
| 1537 | 1518 |
| 1538 setFramebuffer(target, buffer); | 1519 setFramebuffer(target, buffer); |
| 1539 // This is called both internally and externally (from JavaScript). We only
update which wrapper | |
| 1540 // is preserved when it's called from JavaScript. | |
| 1541 if (scriptState) { | |
| 1542 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script
State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedFramebuffer),
buffer); | |
| 1543 } | |
| 1544 } | 1520 } |
| 1545 | 1521 |
| 1546 void WebGLRenderingContextBase::bindRenderbuffer(ScriptState* scriptState, GLenu
m target, WebGLRenderbuffer* renderBuffer) | 1522 void WebGLRenderingContextBase::bindRenderbuffer(GLenum target, WebGLRenderbuffe
r* renderBuffer) |
| 1547 { | 1523 { |
| 1548 bool deleted; | 1524 bool deleted; |
| 1549 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) | 1525 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) |
| 1550 return; | 1526 return; |
| 1551 if (deleted) | 1527 if (deleted) |
| 1552 renderBuffer = 0; | 1528 renderBuffer = 0; |
| 1553 if (target != GL_RENDERBUFFER) { | 1529 if (target != GL_RENDERBUFFER) { |
| 1554 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target")
; | 1530 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target")
; |
| 1555 return; | 1531 return; |
| 1556 } | 1532 } |
| 1557 m_renderbufferBinding = renderBuffer; | 1533 m_renderbufferBinding = renderBuffer; |
| 1558 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer)); | 1534 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer)); |
| 1559 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat
e->isolate()), &m_miscWrappers, PreservedRenderbuffer, renderBuffer); | |
| 1560 | 1535 |
| 1561 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer)); | 1536 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer)); |
| 1562 | 1537 |
| 1563 if (renderBuffer) | 1538 if (renderBuffer) |
| 1564 renderBuffer->setHasEverBeenBound(); | 1539 renderBuffer->setHasEverBeenBound(); |
| 1565 } | 1540 } |
| 1566 | 1541 |
| 1567 void WebGLRenderingContextBase::bindTexture(ScriptState* scriptState, GLenum tar
get, WebGLTexture* texture) | 1542 void WebGLRenderingContextBase::bindTexture(GLenum target, WebGLTexture* texture
) |
| 1568 { | 1543 { |
| 1569 bool deleted; | 1544 bool deleted; |
| 1570 if (!checkObjectToBeBound("bindTexture", texture, deleted)) | 1545 if (!checkObjectToBeBound("bindTexture", texture, deleted)) |
| 1571 return; | 1546 return; |
| 1572 if (deleted) | 1547 if (deleted) |
| 1573 texture = 0; | 1548 texture = 0; |
| 1574 if (texture && texture->getTarget() && texture->getTarget() != target) { | 1549 if (texture && texture->getTarget() && texture->getTarget() != target) { |
| 1575 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"); |
| 1576 return; | 1551 return; |
| 1577 } | 1552 } |
| 1578 | 1553 |
| 1579 // ScriptState may be null if this method is called internally | |
| 1580 // during restoration of texture unit bindings. Skip the | |
| 1581 // preserveObjectWrapper work in this case. | |
| 1582 v8::Local<v8::String> hiddenValueName; | |
| 1583 ScopedPersistent<v8::Array>* persistentCache = nullptr; | |
| 1584 if (target == GL_TEXTURE_2D) { | 1554 if (target == GL_TEXTURE_2D) { |
| 1585 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; | 1555 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; |
| 1586 | 1556 |
| 1587 if (!m_activeTextureUnit) | 1557 if (!m_activeTextureUnit) |
| 1588 drawingBuffer()->setTexture2DBinding(objectOrZero(texture)); | 1558 drawingBuffer()->setTexture2DBinding(objectOrZero(texture)); |
| 1589 if (scriptState) { | |
| 1590 hiddenValueName = V8HiddenValue::webgl2DTextures(scriptState->isolat
e()); | |
| 1591 persistentCache = &m_wrappersOf2DTextures; | |
| 1592 } | |
| 1593 } else if (target == GL_TEXTURE_CUBE_MAP) { | 1559 } else if (target == GL_TEXTURE_CUBE_MAP) { |
| 1594 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; | 1560 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; |
| 1595 if (scriptState) { | |
| 1596 hiddenValueName = V8HiddenValue::webglCubeMapTextures(scriptState->i
solate()); | |
| 1597 persistentCache = &m_cubeMapTextureWrappers; | |
| 1598 } | |
| 1599 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) { | 1561 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) { |
| 1600 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture; | 1562 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture; |
| 1601 if (scriptState) { | |
| 1602 hiddenValueName = V8HiddenValue::webgl2DArrayTextures(scriptState->i
solate()); | |
| 1603 persistentCache = &m_wrappersOf2DArrayTextures; | |
| 1604 } | |
| 1605 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) { | 1563 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) { |
| 1606 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture; | 1564 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture; |
| 1607 if (scriptState) { | |
| 1608 hiddenValueName = V8HiddenValue::webgl3DTextures(scriptState->isolat
e()); | |
| 1609 persistentCache = &m_wrappersOf3DTextures; | |
| 1610 } | |
| 1611 } else { | 1565 } else { |
| 1612 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); | 1566 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); |
| 1613 return; | 1567 return; |
| 1614 } | 1568 } |
| 1615 | 1569 |
| 1616 contextGL()->BindTexture(target, objectOrZero(texture)); | 1570 contextGL()->BindTexture(target, objectOrZero(texture)); |
| 1617 // This is called both internally and externally (from JavaScript). We only
update which wrapper | |
| 1618 // is preserved when it's called from JavaScript. | |
| 1619 if (scriptState) { | |
| 1620 preserveObjectWrapper(scriptState, this, hiddenValueName, persistentCach
e, m_activeTextureUnit, texture); | |
| 1621 } | |
| 1622 if (texture) { | 1571 if (texture) { |
| 1623 texture->setTarget(target); | 1572 texture->setTarget(target); |
| 1624 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl
usMaxNonDefaultTextureUnit); | 1573 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl
usMaxNonDefaultTextureUnit); |
| 1625 } else { | 1574 } else { |
| 1626 // If the disabled index is the current maximum, trace backwards to find
the new max enabled texture index | 1575 // If the disabled index is the current maximum, trace backwards to find
the new max enabled texture index |
| 1627 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) { | 1576 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) { |
| 1628 findNewMaxNonDefaultTextureUnit(); | 1577 findNewMaxNonDefaultTextureUnit(); |
| 1629 } | 1578 } |
| 1630 } | 1579 } |
| 1631 | 1580 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 | 1955 |
| 2007 WebGLRenderbuffer* WebGLRenderingContextBase::createRenderbuffer() | 1956 WebGLRenderbuffer* WebGLRenderingContextBase::createRenderbuffer() |
| 2008 { | 1957 { |
| 2009 if (isContextLost()) | 1958 if (isContextLost()) |
| 2010 return nullptr; | 1959 return nullptr; |
| 2011 WebGLRenderbuffer* o = WebGLRenderbuffer::create(this); | 1960 WebGLRenderbuffer* o = WebGLRenderbuffer::create(this); |
| 2012 addSharedObject(o); | 1961 addSharedObject(o); |
| 2013 return o; | 1962 return o; |
| 2014 } | 1963 } |
| 2015 | 1964 |
| 2016 void WebGLRenderingContextBase::setBoundVertexArrayObject(ScriptState* scriptSta
te, WebGLVertexArrayObjectBase* arrayObject) | 1965 void WebGLRenderingContextBase::setBoundVertexArrayObject(WebGLVertexArrayObject
Base* arrayObject) |
| 2017 { | 1966 { |
| 2018 if (arrayObject) | 1967 if (arrayObject) |
| 2019 m_boundVertexArrayObject = arrayObject; | 1968 m_boundVertexArrayObject = arrayObject; |
| 2020 else | 1969 else |
| 2021 m_boundVertexArrayObject = m_defaultVertexArrayObject; | 1970 m_boundVertexArrayObject = m_defaultVertexArrayObject; |
| 2022 | |
| 2023 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat
e->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedVAO), arrayObject
); | |
| 2024 } | 1971 } |
| 2025 | 1972 |
| 2026 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type) | 1973 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type) |
| 2027 { | 1974 { |
| 2028 if (isContextLost()) | 1975 if (isContextLost()) |
| 2029 return nullptr; | 1976 return nullptr; |
| 2030 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { | 1977 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { |
| 2031 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type"
); | 1978 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type"
); |
| 2032 return nullptr; | 1979 return nullptr; |
| 2033 } | 1980 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 if (isContextLost()) | 2111 if (isContextLost()) |
| 2165 return; | 2112 return; |
| 2166 // Check required by WebGL spec section 6.12 | 2113 // Check required by WebGL spec section 6.12 |
| 2167 if (zNear > zFar) { | 2114 if (zNear > zFar) { |
| 2168 synthesizeGLError(GL_INVALID_OPERATION, "depthRange", "zNear > zFar"); | 2115 synthesizeGLError(GL_INVALID_OPERATION, "depthRange", "zNear > zFar"); |
| 2169 return; | 2116 return; |
| 2170 } | 2117 } |
| 2171 contextGL()->DepthRangef(zNear, zFar); | 2118 contextGL()->DepthRangef(zNear, zFar); |
| 2172 } | 2119 } |
| 2173 | 2120 |
| 2174 void WebGLRenderingContextBase::detachShader(ScriptState* scriptState, WebGLProg
ram* program, WebGLShader* shader) | 2121 void WebGLRenderingContextBase::detachShader(WebGLProgram* program, WebGLShader*
shader) |
| 2175 { | 2122 { |
| 2176 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val
idateWebGLObject("detachShader", shader)) | 2123 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val
idateWebGLObject("detachShader", shader)) |
| 2177 return; | 2124 return; |
| 2178 if (!program->detachShader(shader)) { | 2125 if (!program->detachShader(shader)) { |
| 2179 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta
ched"); | 2126 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta
ched"); |
| 2180 return; | 2127 return; |
| 2181 } | 2128 } |
| 2182 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader)); | 2129 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader)); |
| 2183 shader->onDetached(contextGL()); | 2130 shader->onDetached(contextGL()); |
| 2184 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri
ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader
->type()), nullptr); | |
| 2185 } | 2131 } |
| 2186 | 2132 |
| 2187 void WebGLRenderingContextBase::disable(GLenum cap) | 2133 void WebGLRenderingContextBase::disable(GLenum cap) |
| 2188 { | 2134 { |
| 2189 if (isContextLost() || !validateCapability("disable", cap)) | 2135 if (isContextLost() || !validateCapability("disable", cap)) |
| 2190 return; | 2136 return; |
| 2191 if (cap == GL_STENCIL_TEST) { | 2137 if (cap == GL_STENCIL_TEST) { |
| 2192 m_stencilEnabled = false; | 2138 m_stencilEnabled = false; |
| 2193 applyStencilTest(); | 2139 applyStencilTest(); |
| 2194 return; | 2140 return; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2337 contextGL()->Flush(); // Intentionally a flush, not a finish. | 2283 contextGL()->Flush(); // Intentionally a flush, not a finish. |
| 2338 } | 2284 } |
| 2339 | 2285 |
| 2340 void WebGLRenderingContextBase::flush() | 2286 void WebGLRenderingContextBase::flush() |
| 2341 { | 2287 { |
| 2342 if (isContextLost()) | 2288 if (isContextLost()) |
| 2343 return; | 2289 return; |
| 2344 contextGL()->Flush(); | 2290 contextGL()->Flush(); |
| 2345 } | 2291 } |
| 2346 | 2292 |
| 2347 void WebGLRenderingContextBase::framebufferRenderbuffer(ScriptState* scriptState
, GLenum target, GLenum attachment, GLenum renderbuffertarget, WebGLRenderbuffer
* buffer) | 2293 void WebGLRenderingContextBase::framebufferRenderbuffer(GLenum target, GLenum at
tachment, GLenum renderbuffertarget, WebGLRenderbuffer* buffer) |
| 2348 { | 2294 { |
| 2349 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender
buffer", target, attachment)) | 2295 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender
buffer", target, attachment)) |
| 2350 return; | 2296 return; |
| 2351 if (renderbuffertarget != GL_RENDERBUFFER) { | 2297 if (renderbuffertarget != GL_RENDERBUFFER) { |
| 2352 synthesizeGLError(GL_INVALID_ENUM, "framebufferRenderbuffer", "invalid t
arget"); | 2298 synthesizeGLError(GL_INVALID_ENUM, "framebufferRenderbuffer", "invalid t
arget"); |
| 2353 return; | 2299 return; |
| 2354 } | 2300 } |
| 2355 if (buffer && !buffer->validate(contextGroup(), this)) { | 2301 if (buffer && !buffer->validate(contextGroup(), this)) { |
| 2356 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no b
uffer or buffer not from this context"); | 2302 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no b
uffer or buffer not from this context"); |
| 2357 return; | 2303 return; |
| 2358 } | 2304 } |
| 2359 // Don't allow the default framebuffer to be mutated; all current | 2305 // Don't allow the default framebuffer to be mutated; all current |
| 2360 // implementations use an FBO internally in place of the default | 2306 // implementations use an FBO internally in place of the default |
| 2361 // FBO. | 2307 // FBO. |
| 2362 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); | 2308 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
| 2363 if (!framebufferBinding || !framebufferBinding->object()) { | 2309 if (!framebufferBinding || !framebufferBinding->object()) { |
| 2364 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no f
ramebuffer bound"); | 2310 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no f
ramebuffer bound"); |
| 2365 return; | 2311 return; |
| 2366 } | 2312 } |
| 2367 GLuint bufferObject = objectOrZero(buffer); | 2313 GLuint bufferObject = objectOrZero(buffer); |
| 2368 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | 2314 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2369 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN
T + STENCIL_ATTACHMENT. | 2315 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN
T + STENCIL_ATTACHMENT. |
| 2370 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP
TH_STENCIL_ATTACHMENT in WebGL 2. | 2316 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP
TH_STENCIL_ATTACHMENT in WebGL 2. |
| 2371 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render
buffertarget, bufferObject); | 2317 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render
buffertarget, bufferObject); |
| 2372 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend
erbuffertarget, bufferObject); | 2318 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend
erbuffertarget, bufferObject); |
| 2373 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT
TACHMENT, buffer); | 2319 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT
TACHMENT, buffer); |
| 2374 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_
ATTACHMENT, buffer); | 2320 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_
ATTACHMENT, buffer); |
| 2375 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we
bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache()
, GL_DEPTH_ATTACHMENT, buffer); | |
| 2376 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we
bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache()
, GL_STENCIL_ATTACHMENT, buffer); | |
| 2377 } else { | 2321 } else { |
| 2378 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar
get, bufferObject); | 2322 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar
get, bufferObject); |
| 2379 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment,
buffer); | 2323 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment,
buffer); |
| 2380 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we
bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache()
, attachment, buffer); | |
| 2381 } | 2324 } |
| 2382 applyStencilTest(); | 2325 applyStencilTest(); |
| 2383 } | 2326 } |
| 2384 | 2327 |
| 2385 void WebGLRenderingContextBase::framebufferTexture2D(ScriptState* scriptState, G
Lenum target, GLenum attachment, GLenum textarget, WebGLTexture* texture, GLint
level) | 2328 void WebGLRenderingContextBase::framebufferTexture2D(GLenum target, GLenum attac
hment, GLenum textarget, WebGLTexture* texture, GLint level) |
| 2386 { | 2329 { |
| 2387 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur
e2D", target, attachment)) | 2330 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur
e2D", target, attachment)) |
| 2388 return; | 2331 return; |
| 2389 if (texture && !texture->validate(contextGroup(), this)) { | 2332 if (texture && !texture->validate(contextGroup(), this)) { |
| 2390 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text
ure or texture not from this context"); | 2333 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text
ure or texture not from this context"); |
| 2391 return; | 2334 return; |
| 2392 } | 2335 } |
| 2393 // Don't allow the default framebuffer to be mutated; all current | 2336 // Don't allow the default framebuffer to be mutated; all current |
| 2394 // implementations use an FBO internally in place of the default | 2337 // implementations use an FBO internally in place of the default |
| 2395 // FBO. | 2338 // FBO. |
| 2396 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); | 2339 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); |
| 2397 if (!framebufferBinding || !framebufferBinding->object()) { | 2340 if (!framebufferBinding || !framebufferBinding->object()) { |
| 2398 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram
ebuffer bound"); | 2341 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram
ebuffer bound"); |
| 2399 return; | 2342 return; |
| 2400 } | 2343 } |
| 2401 GLuint textureObject = objectOrZero(texture); | 2344 GLuint textureObject = objectOrZero(texture); |
| 2402 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | 2345 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2403 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN
T + STENCIL_ATTACHMENT. | 2346 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN
T + STENCIL_ATTACHMENT. |
| 2404 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP
TH_STENCIL_ATTACHMENT in WebGL 2. | 2347 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP
TH_STENCIL_ATTACHMENT in WebGL 2. |
| 2405 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget
, textureObject, level); | 2348 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget
, textureObject, level); |
| 2406 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg
et, textureObject, level); | 2349 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg
et, textureObject, level); |
| 2407 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT
TACHMENT, textarget, texture, level, 0); | 2350 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT
TACHMENT, textarget, texture, level, 0); |
| 2408 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_
ATTACHMENT, textarget, texture, level, 0); | 2351 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_
ATTACHMENT, textarget, texture, level, 0); |
| 2409 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we
bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache()
, GL_DEPTH_ATTACHMENT, texture); | |
| 2410 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we
bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache()
, GL_STENCIL_ATTACHMENT, texture); | |
| 2411 } else { | 2352 } else { |
| 2412 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture
Object, level); | 2353 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture
Object, level); |
| 2413 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment,
textarget, texture, level, 0); | 2354 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment,
textarget, texture, level, 0); |
| 2414 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we
bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache()
, attachment, texture); | |
| 2415 } | 2355 } |
| 2416 applyStencilTest(); | 2356 applyStencilTest(); |
| 2417 } | 2357 } |
| 2418 | 2358 |
| 2419 void WebGLRenderingContextBase::frontFace(GLenum mode) | 2359 void WebGLRenderingContextBase::frontFace(GLenum mode) |
| 2420 { | 2360 { |
| 2421 if (isContextLost()) | 2361 if (isContextLost()) |
| 2422 return; | 2362 return; |
| 2423 contextGL()->FrontFace(mode); | 2363 contextGL()->FrontFace(mode); |
| 2424 } | 2364 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2610 if (tracker->draft() && !RuntimeEnabledFeatures::webGLDraftExtensionsEnabled
()) | 2550 if (tracker->draft() && !RuntimeEnabledFeatures::webGLDraftExtensionsEnabled
()) |
| 2611 return false; | 2551 return false; |
| 2612 if (!tracker->supported(this)) | 2552 if (!tracker->supported(this)) |
| 2613 return false; | 2553 return false; |
| 2614 return true; | 2554 return true; |
| 2615 } | 2555 } |
| 2616 | 2556 |
| 2617 ScriptValue WebGLRenderingContextBase::getExtension(ScriptState* scriptState, co
nst String& name) | 2557 ScriptValue WebGLRenderingContextBase::getExtension(ScriptState* scriptState, co
nst String& name) |
| 2618 { | 2558 { |
| 2619 WebGLExtension* extension = nullptr; | 2559 WebGLExtension* extension = nullptr; |
| 2620 bool linkContextToExtension = false; | |
| 2621 | 2560 |
| 2622 if (!isContextLost()) { | 2561 if (!isContextLost()) { |
| 2623 for (size_t i = 0; i < m_extensions.size(); ++i) { | 2562 for (size_t i = 0; i < m_extensions.size(); ++i) { |
| 2624 ExtensionTracker* tracker = m_extensions[i]; | 2563 ExtensionTracker* tracker = m_extensions[i]; |
| 2625 if (tracker->matchesNameWithPrefixes(name)) { | 2564 if (tracker->matchesNameWithPrefixes(name)) { |
| 2626 if (extensionSupportedAndAllowed(tracker)) { | 2565 if (extensionSupportedAndAllowed(tracker)) { |
| 2627 extension = tracker->getExtension(this); | 2566 extension = tracker->getExtension(this); |
| 2628 if (extension) { | 2567 if (extension) { |
| 2629 if (!m_extensionEnabled[extension->name()]) { | 2568 if (!m_extensionEnabled[extension->name()]) { |
| 2630 linkContextToExtension = true; | |
| 2631 m_extensionEnabled[extension->name()] = true; | 2569 m_extensionEnabled[extension->name()] = true; |
| 2632 } | 2570 } |
| 2633 } | 2571 } |
| 2634 } | 2572 } |
| 2635 break; | 2573 break; |
| 2636 } | 2574 } |
| 2637 } | 2575 } |
| 2638 } | 2576 } |
| 2639 | 2577 |
| 2640 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context
()->Global(), scriptState->isolate()); | 2578 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context
()->Global(), scriptState->isolate()); |
| 2641 | 2579 |
| 2642 if (linkContextToExtension) { | |
| 2643 // Keep the extension's JavaScript wrapper alive as long as the context
is alive, so that | |
| 2644 // expando properties that are added to the extension persist. | |
| 2645 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglExtensions(
scriptState->isolate()), &m_extensionWrappers, static_cast<uint32_t>(extension->
name()), extension); | |
| 2646 } | |
| 2647 | |
| 2648 return ScriptValue(scriptState, wrappedExtension); | 2580 return ScriptValue(scriptState, wrappedExtension); |
| 2649 } | 2581 } |
| 2650 | 2582 |
| 2651 ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(ScriptS
tate* scriptState, GLenum target, GLenum attachment, GLenum pname) | 2583 ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(ScriptS
tate* scriptState, GLenum target, GLenum attachment, GLenum pname) |
| 2652 { | 2584 { |
| 2653 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt
achmentParameter", target, attachment)) | 2585 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt
achmentParameter", target, attachment)) |
| 2654 return ScriptValue::createNull(scriptState); | 2586 return ScriptValue::createNull(scriptState); |
| 2655 | 2587 |
| 2656 if (!m_framebufferBinding || !m_framebufferBinding->object()) { | 2588 if (!m_framebufferBinding || !m_framebufferBinding->object()) { |
| 2657 synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParamet
er", "no framebuffer bound"); | 2589 synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParamet
er", "no framebuffer bound"); |
| (...skipping 2281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4939 contextGL()->UniformMatrix4fv(location->location(), v->length() >> 4, transp
ose, v->data()); | 4871 contextGL()->UniformMatrix4fv(location->location(), v->length() >> 4, transp
ose, v->data()); |
| 4940 } | 4872 } |
| 4941 | 4873 |
| 4942 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc
ation, GLboolean transpose, Vector<GLfloat>& v) | 4874 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc
ation, GLboolean transpose, Vector<GLfloat>& v) |
| 4943 { | 4875 { |
| 4944 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv",
location, transpose, v.data(), v.size(), 16)) | 4876 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv",
location, transpose, v.data(), v.size(), 16)) |
| 4945 return; | 4877 return; |
| 4946 contextGL()->UniformMatrix4fv(location->location(), v.size() >> 4, transpose
, v.data()); | 4878 contextGL()->UniformMatrix4fv(location->location(), v.size() >> 4, transpose
, v.data()); |
| 4947 } | 4879 } |
| 4948 | 4880 |
| 4949 void WebGLRenderingContextBase::useProgram(ScriptState* scriptState, WebGLProgra
m* program) | 4881 void WebGLRenderingContextBase::useProgram(WebGLProgram* program) |
| 4950 { | 4882 { |
| 4951 bool deleted; | 4883 bool deleted; |
| 4952 if (!checkObjectToBeBound("useProgram", program, deleted)) | 4884 if (!checkObjectToBeBound("useProgram", program, deleted)) |
| 4953 return; | 4885 return; |
| 4954 if (deleted) | 4886 if (deleted) |
| 4955 program = 0; | 4887 program = 0; |
| 4956 if (program && !program->linkStatus(this)) { | 4888 if (program && !program->linkStatus(this)) { |
| 4957 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid
"); | 4889 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid
"); |
| 4958 return; | 4890 return; |
| 4959 } | 4891 } |
| 4960 | 4892 |
| 4961 if (m_currentProgram != program) { | 4893 if (m_currentProgram != program) { |
| 4962 if (m_currentProgram) | 4894 if (m_currentProgram) |
| 4963 m_currentProgram->onDetached(contextGL()); | 4895 m_currentProgram->onDetached(contextGL()); |
| 4964 m_currentProgram = program; | 4896 m_currentProgram = program; |
| 4965 contextGL()->UseProgram(objectOrZero(program)); | 4897 contextGL()->UseProgram(objectOrZero(program)); |
| 4966 if (program) | 4898 if (program) |
| 4967 program->onAttached(); | 4899 program->onAttached(); |
| 4968 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script
State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedProgram), pro
gram); | |
| 4969 } | 4900 } |
| 4970 } | 4901 } |
| 4971 | 4902 |
| 4972 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program) | 4903 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program) |
| 4973 { | 4904 { |
| 4974 if (isContextLost() || !validateWebGLObject("validateProgram", program)) | 4905 if (isContextLost() || !validateWebGLObject("validateProgram", program)) |
| 4975 return; | 4906 return; |
| 4976 contextGL()->ValidateProgram(objectOrZero(program)); | 4907 contextGL()->ValidateProgram(objectOrZero(program)); |
| 4977 } | 4908 } |
| 4978 | 4909 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5103 if (isContextLost()) | 5034 if (isContextLost()) |
| 5104 return; | 5035 return; |
| 5105 if (v.size() < 4) { | 5036 if (v.size() < 4) { |
| 5106 synthesizeGLError(GL_INVALID_VALUE, "vertexAttrib4fv", "invalid array"); | 5037 synthesizeGLError(GL_INVALID_VALUE, "vertexAttrib4fv", "invalid array"); |
| 5107 return; | 5038 return; |
| 5108 } | 5039 } |
| 5109 contextGL()->VertexAttrib4fv(index, v.data()); | 5040 contextGL()->VertexAttrib4fv(index, v.data()); |
| 5110 setVertexAttribType(index, Float32ArrayType); | 5041 setVertexAttribType(index, Float32ArrayType); |
| 5111 } | 5042 } |
| 5112 | 5043 |
| 5113 void WebGLRenderingContextBase::vertexAttribPointer(ScriptState* scriptState, GL
uint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, long
long offset) | 5044 void WebGLRenderingContextBase::vertexAttribPointer(GLuint index, GLint size, GL
enum type, GLboolean normalized, GLsizei stride, long long offset) |
| 5114 { | 5045 { |
| 5115 if (isContextLost()) | 5046 if (isContextLost()) |
| 5116 return; | 5047 return; |
| 5117 if (index >= m_maxVertexAttribs) { | 5048 if (index >= m_maxVertexAttribs) { |
| 5118 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "index out of
range"); | 5049 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribPointer", "index out of
range"); |
| 5119 return; | 5050 return; |
| 5120 } | 5051 } |
| 5121 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) | 5052 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) |
| 5122 return; | 5053 return; |
| 5123 if (!m_boundArrayBuffer) { | 5054 if (!m_boundArrayBuffer) { |
| 5124 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound
ARRAY_BUFFER"); | 5055 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound
ARRAY_BUFFER"); |
| 5125 return; | 5056 return; |
| 5126 } | 5057 } |
| 5127 | 5058 |
| 5128 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer.
get()); | 5059 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer.
get()); |
| 5129 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein
terpret_cast<void*>(static_cast<intptr_t>(offset))); | 5060 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein
terpret_cast<void*>(static_cast<intptr_t>(offset))); |
| 5130 maybePreserveDefaultVAOObjectWrapper(scriptState); | |
| 5131 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, V8HiddenValue::
webglBuffers(scriptState->isolate()), m_boundVertexArrayObject->getPersistentCac
he(), index, m_boundArrayBuffer); | |
| 5132 } | 5061 } |
| 5133 | 5062 |
| 5134 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di
visor) | 5063 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di
visor) |
| 5135 { | 5064 { |
| 5136 if (isContextLost()) | 5065 if (isContextLost()) |
| 5137 return; | 5066 return; |
| 5138 | 5067 |
| 5139 if (index >= m_maxVertexAttribs) { | 5068 if (index >= m_maxVertexAttribs) { |
| 5140 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o
ut of range"); | 5069 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o
ut of range"); |
| 5141 return; | 5070 return; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5261 { | 5190 { |
| 5262 ASSERT(!isContextLost()); | 5191 ASSERT(!isContextLost()); |
| 5263 m_contextGroup->addObject(object); | 5192 m_contextGroup->addObject(object); |
| 5264 } | 5193 } |
| 5265 | 5194 |
| 5266 void WebGLRenderingContextBase::removeContextObject(WebGLContextObject* object) | 5195 void WebGLRenderingContextBase::removeContextObject(WebGLContextObject* object) |
| 5267 { | 5196 { |
| 5268 m_contextObjects.remove(object); | 5197 m_contextObjects.remove(object); |
| 5269 } | 5198 } |
| 5270 | 5199 |
| 5200 void WebGLRenderingContextBase::trySetWrapperReferencesInAllWorlds(const v8::Per
sistent<v8::Object>& wrapper, ScriptWrappable* scriptWrappable, v8::Isolate* iso
late) |
| 5201 { |
| 5202 if (scriptWrappable) { |
| 5203 DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, scriptWrappabl
e, isolate); |
| 5204 } |
| 5205 } |
| 5206 |
| 5207 void WebGLRenderingContextBase::visitChildDOMWrappers(v8::Isolate* isolate, cons
t v8::Persistent<v8::Object>& wrapper) |
| 5208 { |
| 5209 if (isContextLost()) { |
| 5210 return; |
| 5211 } |
| 5212 trySetWrapperReferencesInAllWorlds(wrapper, m_boundArrayBuffer, isolate); |
| 5213 trySetWrapperReferencesInAllWorlds(wrapper, m_renderbufferBinding, isolate); |
| 5214 |
| 5215 for (auto& unit : m_textureUnits) { |
| 5216 trySetWrapperReferencesInAllWorlds(wrapper, unit.m_texture2DBinding, iso
late); |
| 5217 trySetWrapperReferencesInAllWorlds(wrapper, unit.m_textureCubeMapBinding
, isolate); |
| 5218 trySetWrapperReferencesInAllWorlds(wrapper, unit.m_texture3DBinding, iso
late); |
| 5219 trySetWrapperReferencesInAllWorlds(wrapper, unit.m_texture2DArrayBinding
, isolate); |
| 5220 } |
| 5221 |
| 5222 if (m_framebufferBinding) { |
| 5223 m_framebufferBinding->visitChildDOMWrappers(isolate, wrapper); |
| 5224 } |
| 5225 if (m_currentProgram) { |
| 5226 m_currentProgram->visitChildDOMWrappers(isolate, wrapper); |
| 5227 } |
| 5228 |
| 5229 if (m_boundVertexArrayObject) { |
| 5230 m_boundVertexArrayObject->visitChildDOMWrappers(isolate, wrapper); |
| 5231 } |
| 5232 |
| 5233 for (ExtensionTracker* tracker : m_extensions) { |
| 5234 WebGLExtension* extension = tracker->getExtensionObjectIfAlreadyEnabled(
); |
| 5235 if (extension) { |
| 5236 trySetWrapperReferencesInAllWorlds(wrapper, extension, isolate); |
| 5237 } |
| 5238 } |
| 5239 } |
| 5240 |
| 5271 void WebGLRenderingContextBase::addContextObject(WebGLContextObject* object) | 5241 void WebGLRenderingContextBase::addContextObject(WebGLContextObject* object) |
| 5272 { | 5242 { |
| 5273 ASSERT(!isContextLost()); | 5243 ASSERT(!isContextLost()); |
| 5274 m_contextObjects.add(object); | 5244 m_contextObjects.add(object); |
| 5275 } | 5245 } |
| 5276 | 5246 |
| 5277 void WebGLRenderingContextBase::detachAndRemoveAllObjects() | 5247 void WebGLRenderingContextBase::detachAndRemoveAllObjects() |
| 5278 { | 5248 { |
| 5279 while (m_contextObjects.size() > 0) { | 5249 while (m_contextObjects.size() > 0) { |
| 5280 // Following detachContext() will remove the iterated object from | 5250 // Following detachContext() will remove the iterated object from |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6355 if (!buffer) { | 6325 if (!buffer) { |
| 6356 // Instead of binding fb 0, bind the drawing buffer. | 6326 // Instead of binding fb 0, bind the drawing buffer. |
| 6357 drawingBuffer()->bind(target); | 6327 drawingBuffer()->bind(target); |
| 6358 } else { | 6328 } else { |
| 6359 contextGL()->BindFramebuffer(target, buffer->object()); | 6329 contextGL()->BindFramebuffer(target, buffer->object()); |
| 6360 } | 6330 } |
| 6361 } | 6331 } |
| 6362 | 6332 |
| 6363 void WebGLRenderingContextBase::restoreCurrentFramebuffer() | 6333 void WebGLRenderingContextBase::restoreCurrentFramebuffer() |
| 6364 { | 6334 { |
| 6365 bindFramebuffer(nullptr, GL_FRAMEBUFFER, m_framebufferBinding.get()); | 6335 bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding.get()); |
| 6366 } | 6336 } |
| 6367 | 6337 |
| 6368 void WebGLRenderingContextBase::restoreCurrentTexture2D() | 6338 void WebGLRenderingContextBase::restoreCurrentTexture2D() |
| 6369 { | 6339 { |
| 6370 bindTexture(nullptr, GL_TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_te
xture2DBinding.get()); | 6340 bindTexture(GL_TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_texture2DBi
nding.get()); |
| 6371 } | 6341 } |
| 6372 | 6342 |
| 6373 void WebGLRenderingContextBase::findNewMaxNonDefaultTextureUnit() | 6343 void WebGLRenderingContextBase::findNewMaxNonDefaultTextureUnit() |
| 6374 { | 6344 { |
| 6375 // Trace backwards from the current max to find the new max non-default text
ure unit | 6345 // Trace backwards from the current max to find the new max non-default text
ure unit |
| 6376 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1; | 6346 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1; |
| 6377 for (int i = startIndex; i >= 0; --i) { | 6347 for (int i = startIndex; i >= 0; --i) { |
| 6378 if (m_textureUnits[i].m_texture2DBinding | 6348 if (m_textureUnits[i].m_texture2DBinding |
| 6379 || m_textureUnits[i].m_textureCubeMapBinding) { | 6349 || m_textureUnits[i].m_textureCubeMapBinding) { |
| 6380 m_onePlusMaxNonDefaultTextureUnit = i + 1; | 6350 m_onePlusMaxNonDefaultTextureUnit = i + 1; |
| 6381 return; | 6351 return; |
| 6382 } | 6352 } |
| 6383 } | 6353 } |
| 6384 m_onePlusMaxNonDefaultTextureUnit = 0; | 6354 m_onePlusMaxNonDefaultTextureUnit = 0; |
| 6385 } | 6355 } |
| 6386 | 6356 |
| 6387 void WebGLRenderingContextBase::preserveObjectWrapper(ScriptState* scriptState,
ScriptWrappable* sourceObject, v8::Local<v8::String> hiddenValueName, ScopedPers
istent<v8::Array>* persistentCache, uint32_t index, ScriptWrappable* targetObjec
t) | |
| 6388 { | |
| 6389 v8::Isolate* isolate = scriptState->isolate(); | |
| 6390 if (persistentCache->isEmpty()) { | |
| 6391 // TODO(kbr): eliminate the persistent caches and just use | |
| 6392 // V8HiddenValue::getHiddenValue. Unfortunately, it's | |
| 6393 // currently too slow to use. crbug.com/611864 | |
| 6394 persistentCache->set(isolate, v8::Array::New(isolate)); | |
| 6395 V8HiddenValue::setHiddenValue( | |
| 6396 scriptState, | |
| 6397 sourceObject->mainWorldWrapper(isolate), | |
| 6398 hiddenValueName, | |
| 6399 persistentCache->newLocal(isolate)); | |
| 6400 // It is important to mark the persistent cache as weak | |
| 6401 // (phantom, actually). Otherwise there will be a reference | |
| 6402 // cycle between it and its JavaScript wrapper, and currently | |
| 6403 // there are problems collecting such cycles. | |
| 6404 persistentCache->setPhantom(); | |
| 6405 } | |
| 6406 | |
| 6407 v8::Local<v8::Array> localCache = persistentCache->newLocal(isolate); | |
| 6408 if (targetObject) { | |
| 6409 localCache->Set(scriptState->context(), index, targetObject->mainWorldWr
apper(isolate)).ToChecked(); | |
| 6410 } else { | |
| 6411 localCache->Set(scriptState->context(), index, v8::Null(isolate)).ToChec
ked(); | |
| 6412 } | |
| 6413 } | |
| 6414 | |
| 6415 void WebGLRenderingContextBase::maybePreserveDefaultVAOObjectWrapper(ScriptState
* scriptState) | |
| 6416 { | |
| 6417 ASSERT(scriptState); | |
| 6418 | |
| 6419 if (!m_preservedDefaultVAOObjectWrapper) { | |
| 6420 // The default VAO does not have a JavaScript wrapper created for it, bu
t one is needed to | |
| 6421 // link up the WebGLBuffers associated with the vertex attributes. | |
| 6422 toV8(m_defaultVertexArrayObject, scriptState->context()->Global(), scrip
tState->isolate()); | |
| 6423 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script
State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedDefaultVAO),
m_defaultVertexArrayObject); | |
| 6424 m_preservedDefaultVAOObjectWrapper = true; | |
| 6425 } | |
| 6426 } | |
| 6427 | |
| 6428 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState) | 6357 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState) |
| 6429 { | 6358 { |
| 6430 visitor->trace(m_texture2DBinding); | 6359 visitor->trace(m_texture2DBinding); |
| 6431 visitor->trace(m_textureCubeMapBinding); | 6360 visitor->trace(m_textureCubeMapBinding); |
| 6432 visitor->trace(m_texture3DBinding); | 6361 visitor->trace(m_texture3DBinding); |
| 6433 visitor->trace(m_texture2DArrayBinding); | 6362 visitor->trace(m_texture2DArrayBinding); |
| 6434 } | 6363 } |
| 6435 | 6364 |
| 6436 DEFINE_TRACE(WebGLRenderingContextBase) | 6365 DEFINE_TRACE(WebGLRenderingContextBase) |
| 6437 { | 6366 { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6492 | 6421 |
| 6493 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs
creenCanvas& result) const | 6422 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs
creenCanvas& result) const |
| 6494 { | 6423 { |
| 6495 if (canvas()) | 6424 if (canvas()) |
| 6496 result.setHTMLCanvasElement(canvas()); | 6425 result.setHTMLCanvasElement(canvas()); |
| 6497 else | 6426 else |
| 6498 result.setOffscreenCanvas(getOffscreenCanvas()); | 6427 result.setOffscreenCanvas(getOffscreenCanvas()); |
| 6499 } | 6428 } |
| 6500 | 6429 |
| 6501 } // namespace blink | 6430 } // namespace blink |
| OLD | NEW |