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

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

Issue 1974713003: Speed up fix for expando-loss conformance test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review feedback from haraken. Use phantom persistents. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "modules/webgl/WebGLRenderingContextBase.h" 26 #include "modules/webgl/WebGLRenderingContextBase.h"
27 27
28 #include "bindings/core/v8/ExceptionMessages.h" 28 #include "bindings/core/v8/ExceptionMessages.h"
29 #include "bindings/core/v8/ExceptionState.h" 29 #include "bindings/core/v8/ExceptionState.h"
30 #include "bindings/core/v8/V8BindingMacros.h"
30 #include "bindings/modules/v8/WebGLAny.h" 31 #include "bindings/modules/v8/WebGLAny.h"
31 #include "core/dom/DOMArrayBuffer.h" 32 #include "core/dom/DOMArrayBuffer.h"
32 #include "core/dom/DOMTypedArray.h" 33 #include "core/dom/DOMTypedArray.h"
33 #include "core/dom/FlexibleArrayBufferView.h" 34 #include "core/dom/FlexibleArrayBufferView.h"
34 #include "core/fetch/ImageResource.h" 35 #include "core/fetch/ImageResource.h"
35 #include "core/frame/ImageBitmap.h" 36 #include "core/frame/ImageBitmap.h"
36 #include "core/frame/LocalFrame.h" 37 #include "core/frame/LocalFrame.h"
37 #include "core/frame/Settings.h" 38 #include "core/frame/Settings.h"
38 #include "core/html/HTMLCanvasElement.h" 39 #include "core/html/HTMLCanvasElement.h"
39 #include "core/html/HTMLImageElement.h" 40 #include "core/html/HTMLImageElement.h"
(...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 void WebGLRenderingContextBase::attachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) 1396 void WebGLRenderingContextBase::attachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader)
1396 { 1397 {
1397 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) 1398 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader))
1398 return; 1399 return;
1399 if (!program->attachShader(shader)) { 1400 if (!program->attachShader(shader)) {
1400 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader"); 1401 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader");
1401 return; 1402 return;
1402 } 1403 }
1403 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader)); 1404 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader));
1404 shader->onAttached(); 1405 shader->onAttached();
1405 preserveObjectWrapper(scriptState, program, "shader", shader->type(), shader ); 1406 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader ->type()), shader);
1406 } 1407 }
1407 1408
1408 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name) 1409 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name)
1409 { 1410 {
1410 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) 1411 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program))
1411 return; 1412 return;
1412 if (!validateLocationLength("bindAttribLocation", name)) 1413 if (!validateLocationLength("bindAttribLocation", name))
1413 return; 1414 return;
1414 if (isPrefixReserved(name)) { 1415 if (isPrefixReserved(name)) {
1415 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix"); 1416 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 { 1465 {
1465 bool deleted; 1466 bool deleted;
1466 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) 1467 if (!checkObjectToBeBound("bindBuffer", buffer, deleted))
1467 return; 1468 return;
1468 if (deleted) 1469 if (deleted)
1469 buffer = 0; 1470 buffer = 0;
1470 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer)) 1471 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer))
1471 return; 1472 return;
1472 1473
1473 contextGL()->BindBuffer(target, objectOrZero(buffer)); 1474 contextGL()->BindBuffer(target, objectOrZero(buffer));
1474 preserveObjectWrapper(scriptState, this, "buffer", target, buffer); 1475 PreservedWrapperIndex idx;
1476 switch (target) {
1477 case GL_ARRAY_BUFFER:
1478 idx = PreservedArrayBuffer;
1479 break;
1480 case GL_ELEMENT_ARRAY_BUFFER:
1481 idx = PreservedElementArrayBuffer;
1482 break;
1483 }
1484
1485 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, static_cast<uint32_t>(idx), buffer);
1475 maybePreserveDefaultVAOObjectWrapper(scriptState); 1486 maybePreserveDefaultVAOObjectWrapper(scriptState);
1476 } 1487 }
1477 1488
1478 void WebGLRenderingContextBase::bindFramebuffer(ScriptState* scriptState, GLenum target, WebGLFramebuffer* buffer) 1489 void WebGLRenderingContextBase::bindFramebuffer(ScriptState* scriptState, GLenum target, WebGLFramebuffer* buffer)
1479 { 1490 {
1480 bool deleted; 1491 bool deleted;
1481 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) 1492 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted))
1482 return; 1493 return;
1483 1494
1484 if (deleted) 1495 if (deleted)
1485 buffer = 0; 1496 buffer = 0;
1486 1497
1487 if (target != GL_FRAMEBUFFER) { 1498 if (target != GL_FRAMEBUFFER) {
1488 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); 1499 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target");
1489 return; 1500 return;
1490 } 1501 }
1491 1502
1492 setFramebuffer(target, buffer); 1503 setFramebuffer(target, buffer);
1493 // This is called both internally and externally (from JavaScript). We only update which wrapper 1504 // This is called both internally and externally (from JavaScript). We only update which wrapper
1494 // is preserved when it's called from JavaScript. 1505 // is preserved when it's called from JavaScript.
1495 if (scriptState) 1506 if (scriptState) {
1496 preserveObjectWrapper(scriptState, this, "framebuffer", 0, buffer); 1507 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedFramebuffer), buffer);
1508 }
1497 } 1509 }
1498 1510
1499 void WebGLRenderingContextBase::bindRenderbuffer(ScriptState* scriptState, GLenu m target, WebGLRenderbuffer* renderBuffer) 1511 void WebGLRenderingContextBase::bindRenderbuffer(ScriptState* scriptState, GLenu m target, WebGLRenderbuffer* renderBuffer)
1500 { 1512 {
1501 bool deleted; 1513 bool deleted;
1502 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) 1514 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted))
1503 return; 1515 return;
1504 if (deleted) 1516 if (deleted)
1505 renderBuffer = 0; 1517 renderBuffer = 0;
1506 if (target != GL_RENDERBUFFER) { 1518 if (target != GL_RENDERBUFFER) {
1507 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ; 1519 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ;
1508 return; 1520 return;
1509 } 1521 }
1510 m_renderbufferBinding = renderBuffer; 1522 m_renderbufferBinding = renderBuffer;
1511 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer)); 1523 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer));
1512 preserveObjectWrapper(scriptState, this, "renderbuffer", 0, renderBuffer); 1524 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, PreservedRenderbuffer, renderBuffer);
1513 1525
1514 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer)); 1526 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer));
1515 1527
1516 if (renderBuffer) 1528 if (renderBuffer)
1517 renderBuffer->setHasEverBeenBound(); 1529 renderBuffer->setHasEverBeenBound();
1518 } 1530 }
1519 1531
1520 void WebGLRenderingContextBase::bindTexture(ScriptState* scriptState, GLenum tar get, WebGLTexture* texture) 1532 void WebGLRenderingContextBase::bindTexture(ScriptState* scriptState, GLenum tar get, WebGLTexture* texture)
1521 { 1533 {
1522 bool deleted; 1534 bool deleted;
1523 if (!checkObjectToBeBound("bindTexture", texture, deleted)) 1535 if (!checkObjectToBeBound("bindTexture", texture, deleted))
1524 return; 1536 return;
1525 if (deleted) 1537 if (deleted)
1526 texture = 0; 1538 texture = 0;
1527 if (texture && texture->getTarget() && texture->getTarget() != target) { 1539 if (texture && texture->getTarget() && texture->getTarget() != target) {
1528 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets"); 1540 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets");
1529 return; 1541 return;
1530 } 1542 }
1531 1543
1532 const char* bindingPointName = nullptr; 1544 // ScriptState may be null if this method is called internally
1545 // during restoration of texture unit bindings. Skip the
1546 // preserveObjectWrapper work in this case.
1547 v8::Local<v8::String> hiddenValueName;
1548 v8::Persistent<v8::Array>* persistentCache;
1533 if (target == GL_TEXTURE_2D) { 1549 if (target == GL_TEXTURE_2D) {
1534 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; 1550 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture;
1535 1551
1536 if (!m_activeTextureUnit) 1552 if (!m_activeTextureUnit)
1537 drawingBuffer()->setTexture2DBinding(objectOrZero(texture)); 1553 drawingBuffer()->setTexture2DBinding(objectOrZero(texture));
1538 bindingPointName = "texture_2d"; 1554 if (scriptState) {
1555 hiddenValueName = V8HiddenValue::webgl2DTextures(scriptState->isolat e());
1556 persistentCache = &m_2DTextureWrappers;
1557 }
1539 } else if (target == GL_TEXTURE_CUBE_MAP) { 1558 } else if (target == GL_TEXTURE_CUBE_MAP) {
1540 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; 1559 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture;
1541 bindingPointName = "texture_cube_map"; 1560 if (scriptState) {
1561 hiddenValueName = V8HiddenValue::webglCubeMapTextures(scriptState->i solate());
1562 persistentCache = &m_cubeMapTextureWrappers;
1563 }
1542 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) { 1564 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) {
1543 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture; 1565 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture;
1544 bindingPointName = "texture_2d_array"; 1566 if (scriptState) {
1567 hiddenValueName = V8HiddenValue::webgl2DArrayTextures(scriptState->i solate());
1568 persistentCache = &m_2DArrayTextureWrappers;
1569 }
1545 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) { 1570 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) {
1546 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture; 1571 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture;
1547 bindingPointName = "texture_3d"; 1572 if (scriptState) {
1573 hiddenValueName = V8HiddenValue::webgl3DTextures(scriptState->isolat e());
1574 persistentCache = &m_3DTextureWrappers;
1575 }
1548 } else { 1576 } else {
1549 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); 1577 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target");
1550 return; 1578 return;
1551 } 1579 }
1552 1580
1553 contextGL()->BindTexture(target, objectOrZero(texture)); 1581 contextGL()->BindTexture(target, objectOrZero(texture));
1554 // This is called both internally and externally (from JavaScript). We only update which wrapper 1582 // This is called both internally and externally (from JavaScript). We only update which wrapper
1555 // is preserved when it's called from JavaScript. 1583 // is preserved when it's called from JavaScript.
1556 if (scriptState) { 1584 if (scriptState) {
1557 preserveObjectWrapper(scriptState, this, bindingPointName, m_activeTextu reUnit, texture); 1585 preserveObjectWrapper(scriptState, this, hiddenValueName, persistentCach e, m_activeTextureUnit, texture);
1558 } 1586 }
1559 if (texture) { 1587 if (texture) {
1560 texture->setTarget(target); 1588 texture->setTarget(target);
1561 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit); 1589 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit);
1562 } else { 1590 } else {
1563 // If the disabled index is the current maximum, trace backwards to find the new max enabled texture index 1591 // If the disabled index is the current maximum, trace backwards to find the new max enabled texture index
1564 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) { 1592 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) {
1565 findNewMaxNonDefaultTextureUnit(); 1593 findNewMaxNonDefaultTextureUnit();
1566 } 1594 }
1567 } 1595 }
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 return o; 1978 return o;
1951 } 1979 }
1952 1980
1953 void WebGLRenderingContextBase::setBoundVertexArrayObject(ScriptState* scriptSta te, WebGLVertexArrayObjectBase* arrayObject) 1981 void WebGLRenderingContextBase::setBoundVertexArrayObject(ScriptState* scriptSta te, WebGLVertexArrayObjectBase* arrayObject)
1954 { 1982 {
1955 if (arrayObject) 1983 if (arrayObject)
1956 m_boundVertexArrayObject = arrayObject; 1984 m_boundVertexArrayObject = arrayObject;
1957 else 1985 else
1958 m_boundVertexArrayObject = m_defaultVertexArrayObject; 1986 m_boundVertexArrayObject = m_defaultVertexArrayObject;
1959 1987
1960 preserveObjectWrapper(scriptState, this, "boundvao", 0, arrayObject); 1988 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedVAO), arrayObject );
1961 } 1989 }
1962 1990
1963 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type) 1991 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type)
1964 { 1992 {
1965 if (isContextLost()) 1993 if (isContextLost())
1966 return nullptr; 1994 return nullptr;
1967 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { 1995 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) {
1968 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" ); 1996 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" );
1969 return nullptr; 1997 return nullptr;
1970 } 1998 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2111 void WebGLRenderingContextBase::detachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) 2139 void WebGLRenderingContextBase::detachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader)
2112 { 2140 {
2113 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) 2141 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader))
2114 return; 2142 return;
2115 if (!program->detachShader(shader)) { 2143 if (!program->detachShader(shader)) {
2116 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched"); 2144 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched");
2117 return; 2145 return;
2118 } 2146 }
2119 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader)); 2147 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader));
2120 shader->onDetached(contextGL()); 2148 shader->onDetached(contextGL());
2121 preserveObjectWrapper(scriptState, program, "shader", shader->type(), nullpt r); 2149 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader ->type()), nullptr);
2122 } 2150 }
2123 2151
2124 void WebGLRenderingContextBase::disable(GLenum cap) 2152 void WebGLRenderingContextBase::disable(GLenum cap)
2125 { 2153 {
2126 if (isContextLost() || !validateCapability("disable", cap)) 2154 if (isContextLost() || !validateCapability("disable", cap))
2127 return; 2155 return;
2128 if (cap == GL_STENCIL_TEST) { 2156 if (cap == GL_STENCIL_TEST) {
2129 m_stencilEnabled = false; 2157 m_stencilEnabled = false;
2130 applyStencilTest(); 2158 applyStencilTest();
2131 return; 2159 return;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 return; 2313 return;
2286 } 2314 }
2287 GLuint bufferObject = objectOrZero(buffer); 2315 GLuint bufferObject = objectOrZero(buffer);
2288 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { 2316 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
2289 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. 2317 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT.
2290 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. 2318 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2.
2291 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render buffertarget, bufferObject); 2319 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render buffertarget, bufferObject);
2292 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend erbuffertarget, bufferObject); 2320 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend erbuffertarget, bufferObject);
2293 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, buffer); 2321 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, buffer);
2294 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, buffer); 2322 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, buffer);
2295 preserveObjectWrapper(scriptState, framebufferBinding, "attachment", GL_ DEPTH_ATTACHMENT, buffer); 2323 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_DEPTH_ATTACHMENT, buffer);
2296 preserveObjectWrapper(scriptState, framebufferBinding, "attachment", GL_ STENCIL_ATTACHMENT, buffer); 2324 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_STENCIL_ATTACHMENT, buffer);
2297 } else { 2325 } else {
2298 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar get, bufferObject); 2326 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar get, bufferObject);
2299 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, buffer); 2327 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, buffer);
2300 preserveObjectWrapper(scriptState, framebufferBinding, "attachment", att achment, buffer); 2328 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , attachment, buffer);
2301 } 2329 }
2302 applyStencilTest(); 2330 applyStencilTest();
2303 } 2331 }
2304 2332
2305 void WebGLRenderingContextBase::framebufferTexture2D(ScriptState* scriptState, G Lenum target, GLenum attachment, GLenum textarget, WebGLTexture* texture, GLint level) 2333 void WebGLRenderingContextBase::framebufferTexture2D(ScriptState* scriptState, G Lenum target, GLenum attachment, GLenum textarget, WebGLTexture* texture, GLint level)
2306 { 2334 {
2307 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) 2335 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment))
2308 return; 2336 return;
2309 if (texture && !texture->validate(contextGroup(), this)) { 2337 if (texture && !texture->validate(contextGroup(), this)) {
2310 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context"); 2338 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context");
2311 return; 2339 return;
2312 } 2340 }
2313 // Don't allow the default framebuffer to be mutated; all current 2341 // Don't allow the default framebuffer to be mutated; all current
2314 // implementations use an FBO internally in place of the default 2342 // implementations use an FBO internally in place of the default
2315 // FBO. 2343 // FBO.
2316 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); 2344 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target);
2317 if (!framebufferBinding || !framebufferBinding->object()) { 2345 if (!framebufferBinding || !framebufferBinding->object()) {
2318 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound"); 2346 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound");
2319 return; 2347 return;
2320 } 2348 }
2321 GLuint textureObject = objectOrZero(texture); 2349 GLuint textureObject = objectOrZero(texture);
2322 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { 2350 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
2323 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. 2351 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT.
2324 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. 2352 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2.
2325 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget , textureObject, level); 2353 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget , textureObject, level);
2326 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg et, textureObject, level); 2354 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg et, textureObject, level);
2327 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, textarget, texture, level, 0); 2355 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, textarget, texture, level, 0);
2328 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, textarget, texture, level, 0); 2356 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, textarget, texture, level, 0);
2329 preserveObjectWrapper(scriptState, framebufferBinding, "attachment", GL_ DEPTH_ATTACHMENT, texture); 2357 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_DEPTH_ATTACHMENT, texture);
2330 preserveObjectWrapper(scriptState, framebufferBinding, "attachment", GL_ STENCIL_ATTACHMENT, texture); 2358 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_STENCIL_ATTACHMENT, texture);
2331 } else { 2359 } else {
2332 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture Object, level); 2360 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture Object, level);
2333 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, textarget, texture, level, 0); 2361 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, textarget, texture, level, 0);
2334 preserveObjectWrapper(scriptState, framebufferBinding, "attachment", att achment, texture); 2362 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , attachment, texture);
2335 } 2363 }
2336 applyStencilTest(); 2364 applyStencilTest();
2337 } 2365 }
2338 2366
2339 void WebGLRenderingContextBase::frontFace(GLenum mode) 2367 void WebGLRenderingContextBase::frontFace(GLenum mode)
2340 { 2368 {
2341 if (isContextLost()) 2369 if (isContextLost())
2342 return; 2370 return;
2343 contextGL()->FrontFace(mode); 2371 contextGL()->FrontFace(mode);
2344 } 2372 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2555 break; 2583 break;
2556 } 2584 }
2557 } 2585 }
2558 } 2586 }
2559 2587
2560 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context ()->Global(), scriptState->isolate()); 2588 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context ()->Global(), scriptState->isolate());
2561 2589
2562 if (linkContextToExtension) { 2590 if (linkContextToExtension) {
2563 // Keep the extension's JavaScript wrapper alive as long as the context is alive, so that 2591 // Keep the extension's JavaScript wrapper alive as long as the context is alive, so that
2564 // expando properties that are added to the extension persist. 2592 // expando properties that are added to the extension persist.
2565 preserveObjectWrapper(scriptState, this, "extension", static_cast<unsign ed long>(extension->name()), extension); 2593 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglExtensions( scriptState->isolate()), &m_extensionWrappers, static_cast<uint32_t>(extension-> name()), extension);
2566 } 2594 }
2567 2595
2568 return ScriptValue(scriptState, wrappedExtension); 2596 return ScriptValue(scriptState, wrappedExtension);
2569 } 2597 }
2570 2598
2571 ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(ScriptS tate* scriptState, GLenum target, GLenum attachment, GLenum pname) 2599 ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(ScriptS tate* scriptState, GLenum target, GLenum attachment, GLenum pname)
2572 { 2600 {
2573 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment)) 2601 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment))
2574 return ScriptValue::createNull(scriptState); 2602 return ScriptValue::createNull(scriptState);
2575 2603
(...skipping 2274 matching lines...) Expand 10 before | Expand all | Expand 10 after
4850 return; 4878 return;
4851 } 4879 }
4852 4880
4853 if (m_currentProgram != program) { 4881 if (m_currentProgram != program) {
4854 if (m_currentProgram) 4882 if (m_currentProgram)
4855 m_currentProgram->onDetached(contextGL()); 4883 m_currentProgram->onDetached(contextGL());
4856 m_currentProgram = program; 4884 m_currentProgram = program;
4857 contextGL()->UseProgram(objectOrZero(program)); 4885 contextGL()->UseProgram(objectOrZero(program));
4858 if (program) 4886 if (program)
4859 program->onAttached(); 4887 program->onAttached();
4860 preserveObjectWrapper(scriptState, this, "program", 0, program); 4888 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedProgram), pro gram);
4861 } 4889 }
4862 } 4890 }
4863 4891
4864 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program) 4892 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program)
4865 { 4893 {
4866 if (isContextLost() || !validateWebGLObject("validateProgram", program)) 4894 if (isContextLost() || !validateWebGLObject("validateProgram", program))
4867 return; 4895 return;
4868 contextGL()->ValidateProgram(objectOrZero(program)); 4896 contextGL()->ValidateProgram(objectOrZero(program));
4869 } 4897 }
4870 4898
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
5013 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) 5041 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset))
5014 return; 5042 return;
5015 if (!m_boundArrayBuffer) { 5043 if (!m_boundArrayBuffer) {
5016 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER"); 5044 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER");
5017 return; 5045 return;
5018 } 5046 }
5019 5047
5020 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer. get()); 5048 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer. get());
5021 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein terpret_cast<void*>(static_cast<intptr_t>(offset))); 5049 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein terpret_cast<void*>(static_cast<intptr_t>(offset)));
5022 maybePreserveDefaultVAOObjectWrapper(scriptState); 5050 maybePreserveDefaultVAOObjectWrapper(scriptState);
5023 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, "arraybuffer", index, m_boundArrayBuffer); 5051 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, V8HiddenValue:: webglBuffers(scriptState->isolate()), m_boundVertexArrayObject->getPersistentCac he(), index, m_boundArrayBuffer);
5024 } 5052 }
5025 5053
5026 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor) 5054 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor)
5027 { 5055 {
5028 if (isContextLost()) 5056 if (isContextLost())
5029 return; 5057 return;
5030 5058
5031 if (index >= m_maxVertexAttribs) { 5059 if (index >= m_maxVertexAttribs) {
5032 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); 5060 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range");
5033 return; 5061 return;
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after
6249 for (int i = startIndex; i >= 0; --i) { 6277 for (int i = startIndex; i >= 0; --i) {
6250 if (m_textureUnits[i].m_texture2DBinding 6278 if (m_textureUnits[i].m_texture2DBinding
6251 || m_textureUnits[i].m_textureCubeMapBinding) { 6279 || m_textureUnits[i].m_textureCubeMapBinding) {
6252 m_onePlusMaxNonDefaultTextureUnit = i + 1; 6280 m_onePlusMaxNonDefaultTextureUnit = i + 1;
6253 return; 6281 return;
6254 } 6282 }
6255 } 6283 }
6256 m_onePlusMaxNonDefaultTextureUnit = 0; 6284 m_onePlusMaxNonDefaultTextureUnit = 0;
6257 } 6285 }
6258 6286
6259 void WebGLRenderingContextBase::preserveObjectWrapper(ScriptState* scriptState, ScriptWrappable* sourceObject, const char* baseName, unsigned long index, Script Wrappable* targetObject) 6287 void WebGLRenderingContextBase::preserveObjectWrapper(ScriptState* scriptState, ScriptWrappable* sourceObject, v8::Local<v8::String> hiddenValueName, v8::Persis tent<v8::Array>* persistentCache, uint32_t index, ScriptWrappable* targetObject)
6260 { 6288 {
6261 ASSERT(scriptState);
6262
6263 v8::Local<v8::Value> value;
6264 v8::Isolate* isolate = scriptState->isolate(); 6289 v8::Isolate* isolate = scriptState->isolate();
6265 6290 if (persistentCache->IsEmpty()) {
6266 // TODO (kbr): move this logic to V8HiddenValue. The difficulty in doing so is that the index 6291 persistentCache->Reset(isolate, v8::Array::New(isolate));
6267 // may vary, so it'd be necessary to lazily instantiate the V8 internalized strings, and have
6268 // efficient lookup for already-created ones.
6269 StringBuilder builder;
6270 builder.append(baseName);
6271 builder.appendNumber(static_cast<unsigned>(index));
6272 CString name = builder.toString().utf8();
6273 v8::Local<v8::String> jsName = v8::String::NewFromUtf8(
6274 isolate,
6275 name.data(),
6276 v8::NewStringType::kNormal,
6277 name.length()).ToLocalChecked();
6278 if (targetObject) {
6279 V8HiddenValue::setHiddenValue( 6292 V8HiddenValue::setHiddenValue(
6280 scriptState, 6293 scriptState,
6281 sourceObject->newLocalWrapper(isolate), 6294 sourceObject->newLocalWrapper(isolate),
6282 jsName, 6295 hiddenValueName,
6283 targetObject->newLocalWrapper(isolate)); 6296 persistentCache->Get(isolate));
6297 // It is important to mark the persistent cache as weak
6298 // (phantom, actually). Otherwise there will be a reference
6299 // cycle between it and its JavaScript wrapper, and currently
6300 // there are problems collecting such cycles.
6301 persistentCache->SetWeak();
6302 }
6303
6304 v8::Local<v8::Array> localCache = persistentCache->Get(isolate);
6305 if (targetObject) {
6306 bool result;
6307 V8_CALL(result, localCache, Set(scriptState->context(), index, targetObj ect->newLocalWrapper(isolate)), return);
haraken 2016/05/13 04:33:00 v8CallOrCrash
6308 ASSERT_UNUSED(result, result);
6284 } else { 6309 } else {
6285 V8HiddenValue::deleteHiddenValue( 6310 bool result;
6286 scriptState, 6311 V8_CALL(result, localCache, Set(scriptState->context(), index, v8::Null( isolate)), return);
haraken 2016/05/13 04:33:00 v8CallOrCrash
6287 sourceObject->newLocalWrapper(isolate), 6312 ASSERT_UNUSED(result, result);
6288 jsName);
6289 } 6313 }
6290 } 6314 }
6291 6315
6292 void WebGLRenderingContextBase::maybePreserveDefaultVAOObjectWrapper(ScriptState * scriptState) 6316 void WebGLRenderingContextBase::maybePreserveDefaultVAOObjectWrapper(ScriptState * scriptState)
6293 { 6317 {
6294 ASSERT(scriptState); 6318 ASSERT(scriptState);
6295 6319
6296 if (!m_preservedDefaultVAOObjectWrapper) { 6320 if (!m_preservedDefaultVAOObjectWrapper) {
6297 // The default VAO does not have a JavaScript wrapper created for it, bu t one is needed to 6321 // The default VAO does not have a JavaScript wrapper created for it, bu t one is needed to
6298 // link up the WebGLBuffers associated with the vertex attributes. 6322 // link up the WebGLBuffers associated with the vertex attributes.
6299 toV8(m_defaultVertexArrayObject, scriptState->context()->Global(), scrip tState->isolate()); 6323 toV8(m_defaultVertexArrayObject, scriptState->context()->Global(), scrip tState->isolate());
6300 preserveObjectWrapper(scriptState, this, "defaultvao", 0, m_defaultVerte xArrayObject); 6324 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedDefaultVAO), m_defaultVertexArrayObject);
6301 m_preservedDefaultVAOObjectWrapper = true; 6325 m_preservedDefaultVAOObjectWrapper = true;
6302 } 6326 }
6303 } 6327 }
6304 6328
6305 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState) 6329 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState)
6306 { 6330 {
6307 visitor->trace(m_texture2DBinding); 6331 visitor->trace(m_texture2DBinding);
6308 visitor->trace(m_textureCubeMapBinding); 6332 visitor->trace(m_textureCubeMapBinding);
6309 visitor->trace(m_texture3DBinding); 6333 visitor->trace(m_texture3DBinding);
6310 visitor->trace(m_texture2DArrayBinding); 6334 visitor->trace(m_texture2DArrayBinding);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
6361 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6385 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6362 } 6386 }
6363 6387
6364 void WebGLRenderingContextBase::restoreUnpackParameters() 6388 void WebGLRenderingContextBase::restoreUnpackParameters()
6365 { 6389 {
6366 if (m_unpackAlignment != 1) 6390 if (m_unpackAlignment != 1)
6367 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6391 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6368 } 6392 }
6369 6393
6370 } // namespace blink 6394 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698