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

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

Issue 2023603003: Fix content scripts that use WebGL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@yukishiino-v8privateproperty-fix
Patch Set: Reintroduced persistent caches. Created 4 years, 6 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
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 void WebGLRenderingContextBase::attachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) 1406 void WebGLRenderingContextBase::attachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader)
1407 { 1407 {
1408 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) 1408 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader))
1409 return; 1409 return;
1410 if (!program->attachShader(shader)) { 1410 if (!program->attachShader(shader)) {
1411 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader"); 1411 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader");
1412 return; 1412 return;
1413 } 1413 }
1414 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader)); 1414 contextGL()->AttachShader(objectOrZero(program), objectOrZero(shader));
1415 shader->onAttached(); 1415 shader->onAttached();
1416 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader ->type()), shader); 1416 preserveObjectWrapper(scriptState, program, V8PrivateProperty::getWebGLProgr amShaders(scriptState->isolate()), program->getPersistentCache(), static_cast<ui nt32_t>(shader->type()), shader);
1417 } 1417 }
1418 1418
1419 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name) 1419 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name)
1420 { 1420 {
1421 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) 1421 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program))
1422 return; 1422 return;
1423 if (!validateLocationLength("bindAttribLocation", name)) 1423 if (!validateLocationLength("bindAttribLocation", name))
1424 return; 1424 return;
1425 if (isPrefixReserved(name)) { 1425 if (isPrefixReserved(name)) {
1426 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix"); 1426 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix");
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 PreservedWrapperIndex idx = PreservedArrayBuffer; 1485 PreservedWrapperIndex idx = PreservedArrayBuffer;
1486 switch (target) { 1486 switch (target) {
1487 case GL_ARRAY_BUFFER: 1487 case GL_ARRAY_BUFFER:
1488 idx = PreservedArrayBuffer; 1488 idx = PreservedArrayBuffer;
1489 break; 1489 break;
1490 case GL_ELEMENT_ARRAY_BUFFER: 1490 case GL_ELEMENT_ARRAY_BUFFER:
1491 idx = PreservedElementArrayBuffer; 1491 idx = PreservedElementArrayBuffer;
1492 break; 1492 break;
1493 } 1493 }
1494 1494
1495 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, static_cast<uint32_t>(idx), buffer); 1495 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRenderin gContextMisc(scriptState->isolate()), &m_miscWrappers, static_cast<uint32_t>(idx ), buffer);
1496 maybePreserveDefaultVAOObjectWrapper(scriptState); 1496 maybePreserveDefaultVAOObjectWrapper(scriptState);
1497 } 1497 }
1498 1498
1499 void WebGLRenderingContextBase::bindFramebuffer(ScriptState* scriptState, GLenum target, WebGLFramebuffer* buffer) 1499 void WebGLRenderingContextBase::bindFramebuffer(ScriptState* scriptState, GLenum target, WebGLFramebuffer* buffer)
1500 { 1500 {
1501 bool deleted; 1501 bool deleted;
1502 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) 1502 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted))
1503 return; 1503 return;
1504 1504
1505 if (deleted) 1505 if (deleted)
1506 buffer = 0; 1506 buffer = 0;
1507 1507
1508 if (target != GL_FRAMEBUFFER) { 1508 if (target != GL_FRAMEBUFFER) {
1509 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); 1509 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target");
1510 return; 1510 return;
1511 } 1511 }
1512 1512
1513 setFramebuffer(target, buffer); 1513 setFramebuffer(target, buffer);
1514 // This is called both internally and externally (from JavaScript). We only update which wrapper 1514 // This is called both internally and externally (from JavaScript). We only update which wrapper
1515 // is preserved when it's called from JavaScript. 1515 // is preserved when it's called from JavaScript.
1516 if (scriptState) { 1516 if (scriptState) {
1517 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedFramebuffer), buffer); 1517 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRend eringContextMisc(scriptState->isolate()), &m_miscWrappers, static_cast<uint32_t> (PreservedFramebuffer), buffer);
1518 } 1518 }
1519 } 1519 }
1520 1520
1521 void WebGLRenderingContextBase::bindRenderbuffer(ScriptState* scriptState, GLenu m target, WebGLRenderbuffer* renderBuffer) 1521 void WebGLRenderingContextBase::bindRenderbuffer(ScriptState* scriptState, GLenu m target, WebGLRenderbuffer* renderBuffer)
1522 { 1522 {
1523 bool deleted; 1523 bool deleted;
1524 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) 1524 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted))
1525 return; 1525 return;
1526 if (deleted) 1526 if (deleted)
1527 renderBuffer = 0; 1527 renderBuffer = 0;
1528 if (target != GL_RENDERBUFFER) { 1528 if (target != GL_RENDERBUFFER) {
1529 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ; 1529 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ;
1530 return; 1530 return;
1531 } 1531 }
1532 m_renderbufferBinding = renderBuffer; 1532 m_renderbufferBinding = renderBuffer;
1533 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer)); 1533 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer));
1534 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, PreservedRenderbuffer, renderBuffer); 1534 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRenderin gContextMisc(scriptState->isolate()), &m_miscWrappers, PreservedRenderbuffer, re nderBuffer);
1535 1535
1536 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer)); 1536 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer));
1537 1537
1538 if (renderBuffer) 1538 if (renderBuffer)
1539 renderBuffer->setHasEverBeenBound(); 1539 renderBuffer->setHasEverBeenBound();
1540 } 1540 }
1541 1541
1542 void WebGLRenderingContextBase::bindTexture(ScriptState* scriptState, GLenum tar get, WebGLTexture* texture) 1542 void WebGLRenderingContextBase::bindTexture(ScriptState* scriptState, GLenum tar get, WebGLTexture* texture)
1543 { 1543 {
1544 bool deleted; 1544 bool deleted;
1545 if (!checkObjectToBeBound("bindTexture", texture, deleted)) 1545 if (!checkObjectToBeBound("bindTexture", texture, deleted))
1546 return; 1546 return;
1547 if (deleted) 1547 if (deleted)
1548 texture = 0; 1548 texture = 0;
1549 if (texture && texture->getTarget() && texture->getTarget() != target) { 1549 if (texture && texture->getTarget() && texture->getTarget() != target) {
1550 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets"); 1550 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets");
1551 return; 1551 return;
1552 } 1552 }
1553 1553
1554 // ScriptState may be null if this method is called internally 1554 // ScriptState may be null if this method is called internally
1555 // during restoration of texture unit bindings. Skip the 1555 // during restoration of texture unit bindings. Skip the
1556 // preserveObjectWrapper work in this case. 1556 // preserveObjectWrapper work in this case.
1557 v8::Local<v8::String> hiddenValueName; 1557 V8PrivateProperty::Symbol (*privateSymbolFn)(v8::Isolate* isolate) = nullptr ;
1558 ScopedPersistent<v8::Array>* persistentCache = nullptr; 1558 ScopedPersistent<v8::Array>* persistentCache = nullptr;
1559 if (target == GL_TEXTURE_2D) { 1559 if (target == GL_TEXTURE_2D) {
1560 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; 1560 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture;
1561 1561
1562 if (!m_activeTextureUnit) 1562 if (!m_activeTextureUnit)
1563 drawingBuffer()->setTexture2DBinding(objectOrZero(texture)); 1563 drawingBuffer()->setTexture2DBinding(objectOrZero(texture));
1564 if (scriptState) { 1564 if (scriptState) {
1565 hiddenValueName = V8HiddenValue::webgl2DTextures(scriptState->isolat e());
1566 persistentCache = &m_2DTextureWrappers; 1565 persistentCache = &m_2DTextureWrappers;
1566 privateSymbolFn = &V8PrivateProperty::getWebGLRenderingContextTextur es2D;
1567 } 1567 }
1568 } else if (target == GL_TEXTURE_CUBE_MAP) { 1568 } else if (target == GL_TEXTURE_CUBE_MAP) {
1569 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; 1569 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture;
1570 if (scriptState) { 1570 if (scriptState) {
1571 hiddenValueName = V8HiddenValue::webglCubeMapTextures(scriptState->i solate());
1572 persistentCache = &m_cubeMapTextureWrappers; 1571 persistentCache = &m_cubeMapTextureWrappers;
1572 privateSymbolFn = &V8PrivateProperty::getWebGLRenderingContextTextur esCubeMap;
1573 } 1573 }
1574 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) { 1574 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) {
1575 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture; 1575 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture;
1576 if (scriptState) { 1576 if (scriptState) {
1577 hiddenValueName = V8HiddenValue::webgl2DArrayTextures(scriptState->i solate());
1578 persistentCache = &m_2DArrayTextureWrappers; 1577 persistentCache = &m_2DArrayTextureWrappers;
1578 privateSymbolFn = &V8PrivateProperty::getWebGLRenderingContextTextur es2DArray;
1579 } 1579 }
1580 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) { 1580 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) {
1581 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture; 1581 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture;
1582 if (scriptState) { 1582 if (scriptState) {
1583 hiddenValueName = V8HiddenValue::webgl3DTextures(scriptState->isolat e());
1584 persistentCache = &m_3DTextureWrappers; 1583 persistentCache = &m_3DTextureWrappers;
1584 privateSymbolFn = &V8PrivateProperty::getWebGLRenderingContextTextur es3D;
1585 } 1585 }
1586 } else { 1586 } else {
1587 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); 1587 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target");
1588 return; 1588 return;
1589 } 1589 }
1590 1590
1591 contextGL()->BindTexture(target, objectOrZero(texture)); 1591 contextGL()->BindTexture(target, objectOrZero(texture));
1592 // This is called both internally and externally (from JavaScript). We only update which wrapper 1592 // This is called both internally and externally (from JavaScript). We only update which wrapper
1593 // is preserved when it's called from JavaScript. 1593 // is preserved when it's called from JavaScript.
1594 if (scriptState) { 1594 if (scriptState) {
1595 preserveObjectWrapper(scriptState, this, hiddenValueName, persistentCach e, m_activeTextureUnit, texture); 1595 preserveObjectWrapper(scriptState, this, privateSymbolFn(scriptState->is olate()), persistentCache, m_activeTextureUnit, texture);
1596 } 1596 }
1597 if (texture) { 1597 if (texture) {
1598 texture->setTarget(target); 1598 texture->setTarget(target);
1599 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit); 1599 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit);
1600 } else { 1600 } else {
1601 // If the disabled index is the current maximum, trace backwards to find the new max enabled texture index 1601 // If the disabled index is the current maximum, trace backwards to find the new max enabled texture index
1602 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) { 1602 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) {
1603 findNewMaxNonDefaultTextureUnit(); 1603 findNewMaxNonDefaultTextureUnit();
1604 } 1604 }
1605 } 1605 }
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 return o; 1988 return o;
1989 } 1989 }
1990 1990
1991 void WebGLRenderingContextBase::setBoundVertexArrayObject(ScriptState* scriptSta te, WebGLVertexArrayObjectBase* arrayObject) 1991 void WebGLRenderingContextBase::setBoundVertexArrayObject(ScriptState* scriptSta te, WebGLVertexArrayObjectBase* arrayObject)
1992 { 1992 {
1993 if (arrayObject) 1993 if (arrayObject)
1994 m_boundVertexArrayObject = arrayObject; 1994 m_boundVertexArrayObject = arrayObject;
1995 else 1995 else
1996 m_boundVertexArrayObject = m_defaultVertexArrayObject; 1996 m_boundVertexArrayObject = m_defaultVertexArrayObject;
1997 1997
1998 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(scriptStat e->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedVAO), arrayObject ); 1998 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRenderin gContextMisc(scriptState->isolate()), &m_miscWrappers, static_cast<uint32_t>(Pre servedVAO), arrayObject);
1999 } 1999 }
2000 2000
2001 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type) 2001 WebGLShader* WebGLRenderingContextBase::createShader(GLenum type)
2002 { 2002 {
2003 if (isContextLost()) 2003 if (isContextLost())
2004 return nullptr; 2004 return nullptr;
2005 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { 2005 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) {
2006 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" ); 2006 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" );
2007 return nullptr; 2007 return nullptr;
2008 } 2008 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 void WebGLRenderingContextBase::detachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader) 2149 void WebGLRenderingContextBase::detachShader(ScriptState* scriptState, WebGLProg ram* program, WebGLShader* shader)
2150 { 2150 {
2151 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) 2151 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader))
2152 return; 2152 return;
2153 if (!program->detachShader(shader)) { 2153 if (!program->detachShader(shader)) {
2154 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched"); 2154 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched");
2155 return; 2155 return;
2156 } 2156 }
2157 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader)); 2157 contextGL()->DetachShader(objectOrZero(program), objectOrZero(shader));
2158 shader->onDetached(contextGL()); 2158 shader->onDetached(contextGL());
2159 preserveObjectWrapper(scriptState, program, V8HiddenValue::webglShaders(scri ptState->isolate()), program->getPersistentCache(), static_cast<uint32_t>(shader ->type()), nullptr); 2159 preserveObjectWrapper(scriptState, program, V8PrivateProperty::getWebGLProgr amShaders(scriptState->isolate()), program->getPersistentCache(), static_cast<ui nt32_t>(shader->type()), nullptr);
2160 } 2160 }
2161 2161
2162 void WebGLRenderingContextBase::disable(GLenum cap) 2162 void WebGLRenderingContextBase::disable(GLenum cap)
2163 { 2163 {
2164 if (isContextLost() || !validateCapability("disable", cap)) 2164 if (isContextLost() || !validateCapability("disable", cap))
2165 return; 2165 return;
2166 if (cap == GL_STENCIL_TEST) { 2166 if (cap == GL_STENCIL_TEST) {
2167 m_stencilEnabled = false; 2167 m_stencilEnabled = false;
2168 applyStencilTest(); 2168 applyStencilTest();
2169 return; 2169 return;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 return; 2323 return;
2324 } 2324 }
2325 GLuint bufferObject = objectOrZero(buffer); 2325 GLuint bufferObject = objectOrZero(buffer);
2326 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { 2326 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
2327 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. 2327 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT.
2328 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. 2328 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2.
2329 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render buffertarget, bufferObject); 2329 contextGL()->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, render buffertarget, bufferObject);
2330 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend erbuffertarget, bufferObject); 2330 contextGL()->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, rend erbuffertarget, bufferObject);
2331 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, buffer); 2331 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, buffer);
2332 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, buffer); 2332 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, buffer);
2333 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_DEPTH_ATTACHMENT, buffer); 2333 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), framebufferBinding->ge tPersistentCache(), GL_DEPTH_ATTACHMENT, buffer);
2334 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_STENCIL_ATTACHMENT, buffer); 2334 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), framebufferBinding->ge tPersistentCache(), GL_STENCIL_ATTACHMENT, buffer);
2335 } else { 2335 } else {
2336 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar get, bufferObject); 2336 contextGL()->FramebufferRenderbuffer(target, attachment, renderbuffertar get, bufferObject);
2337 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, buffer); 2337 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, buffer);
2338 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , attachment, buffer); 2338 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), framebufferBinding->ge tPersistentCache(), attachment, buffer);
2339 } 2339 }
2340 applyStencilTest(); 2340 applyStencilTest();
2341 } 2341 }
2342 2342
2343 void WebGLRenderingContextBase::framebufferTexture2D(ScriptState* scriptState, G Lenum target, GLenum attachment, GLenum textarget, WebGLTexture* texture, GLint level) 2343 void WebGLRenderingContextBase::framebufferTexture2D(ScriptState* scriptState, G Lenum target, GLenum attachment, GLenum textarget, WebGLTexture* texture, GLint level)
2344 { 2344 {
2345 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) 2345 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment))
2346 return; 2346 return;
2347 if (texture && !texture->validate(contextGroup(), this)) { 2347 if (texture && !texture->validate(contextGroup(), this)) {
2348 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context"); 2348 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context");
2349 return; 2349 return;
2350 } 2350 }
2351 // Don't allow the default framebuffer to be mutated; all current 2351 // Don't allow the default framebuffer to be mutated; all current
2352 // implementations use an FBO internally in place of the default 2352 // implementations use an FBO internally in place of the default
2353 // FBO. 2353 // FBO.
2354 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target); 2354 WebGLFramebuffer* framebufferBinding = getFramebufferBinding(target);
2355 if (!framebufferBinding || !framebufferBinding->object()) { 2355 if (!framebufferBinding || !framebufferBinding->object()) {
2356 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound"); 2356 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound");
2357 return; 2357 return;
2358 } 2358 }
2359 GLuint textureObject = objectOrZero(texture); 2359 GLuint textureObject = objectOrZero(texture);
2360 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { 2360 if (isWebGL2OrHigher() && attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
2361 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT. 2361 // On ES3, DEPTH_STENCIL_ATTACHMENT is like an alias for DEPTH_ATTACHMEN T + STENCIL_ATTACHMENT.
2362 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2. 2362 // We divide it here so in WebGLFramebuffer, we don't have to handle DEP TH_STENCIL_ATTACHMENT in WebGL 2.
2363 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget , textureObject, level); 2363 contextGL()->FramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget , textureObject, level);
2364 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg et, textureObject, level); 2364 contextGL()->FramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarg et, textureObject, level);
2365 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, textarget, texture, level, 0); 2365 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_DEPTH_AT TACHMENT, textarget, texture, level, 0);
2366 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, textarget, texture, level, 0); 2366 framebufferBinding->setAttachmentForBoundFramebuffer(target, GL_STENCIL_ ATTACHMENT, textarget, texture, level, 0);
2367 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_DEPTH_ATTACHMENT, texture); 2367 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), framebufferBinding->ge tPersistentCache(), GL_DEPTH_ATTACHMENT, texture);
2368 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , GL_STENCIL_ATTACHMENT, texture); 2368 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), framebufferBinding->ge tPersistentCache(), GL_STENCIL_ATTACHMENT, texture);
2369 } else { 2369 } else {
2370 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture Object, level); 2370 contextGL()->FramebufferTexture2D(target, attachment, textarget, texture Object, level);
2371 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, textarget, texture, level, 0); 2371 framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, textarget, texture, level, 0);
2372 preserveObjectWrapper(scriptState, framebufferBinding, V8HiddenValue::we bglAttachments(scriptState->isolate()), framebufferBinding->getPersistentCache() , attachment, texture); 2372 preserveObjectWrapper(scriptState, framebufferBinding, V8PrivateProperty ::getWebGLFramebufferAttachments(scriptState->isolate()), framebufferBinding->ge tPersistentCache(), attachment, texture);
2373 } 2373 }
2374 applyStencilTest(); 2374 applyStencilTest();
2375 } 2375 }
2376 2376
2377 void WebGLRenderingContextBase::frontFace(GLenum mode) 2377 void WebGLRenderingContextBase::frontFace(GLenum mode)
2378 { 2378 {
2379 if (isContextLost()) 2379 if (isContextLost())
2380 return; 2380 return;
2381 contextGL()->FrontFace(mode); 2381 contextGL()->FrontFace(mode);
2382 } 2382 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2593 break; 2593 break;
2594 } 2594 }
2595 } 2595 }
2596 } 2596 }
2597 2597
2598 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context ()->Global(), scriptState->isolate()); 2598 v8::Local<v8::Value> wrappedExtension = toV8(extension, scriptState->context ()->Global(), scriptState->isolate());
2599 2599
2600 if (linkContextToExtension) { 2600 if (linkContextToExtension) {
2601 // Keep the extension's JavaScript wrapper alive as long as the context is alive, so that 2601 // Keep the extension's JavaScript wrapper alive as long as the context is alive, so that
2602 // expando properties that are added to the extension persist. 2602 // expando properties that are added to the extension persist.
2603 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglExtensions( scriptState->isolate()), &m_extensionWrappers, static_cast<uint32_t>(extension-> name()), extension); 2603 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRend eringContextExtensions(scriptState->isolate()), &m_extensionWrappers, static_cas t<uint32_t>(extension->name()), extension);
2604 } 2604 }
2605 2605
2606 return ScriptValue(scriptState, wrappedExtension); 2606 return ScriptValue(scriptState, wrappedExtension);
2607 } 2607 }
2608 2608
2609 ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(ScriptS tate* scriptState, GLenum target, GLenum attachment, GLenum pname) 2609 ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(ScriptS tate* scriptState, GLenum target, GLenum attachment, GLenum pname)
2610 { 2610 {
2611 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment)) 2611 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment))
2612 return ScriptValue::createNull(scriptState); 2612 return ScriptValue::createNull(scriptState);
2613 2613
(...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after
4918 return; 4918 return;
4919 } 4919 }
4920 4920
4921 if (m_currentProgram != program) { 4921 if (m_currentProgram != program) {
4922 if (m_currentProgram) 4922 if (m_currentProgram)
4923 m_currentProgram->onDetached(contextGL()); 4923 m_currentProgram->onDetached(contextGL());
4924 m_currentProgram = program; 4924 m_currentProgram = program;
4925 contextGL()->UseProgram(objectOrZero(program)); 4925 contextGL()->UseProgram(objectOrZero(program));
4926 if (program) 4926 if (program)
4927 program->onAttached(); 4927 program->onAttached();
4928 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedProgram), pro gram); 4928 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRend eringContextMisc(scriptState->isolate()), &m_miscWrappers, static_cast<uint32_t> (PreservedProgram), program);
4929 } 4929 }
4930 } 4930 }
4931 4931
4932 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program) 4932 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program)
4933 { 4933 {
4934 if (isContextLost() || !validateWebGLObject("validateProgram", program)) 4934 if (isContextLost() || !validateWebGLObject("validateProgram", program))
4935 return; 4935 return;
4936 contextGL()->ValidateProgram(objectOrZero(program)); 4936 contextGL()->ValidateProgram(objectOrZero(program));
4937 } 4937 }
4938 4938
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
5081 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset)) 5081 if (!validateValueFitNonNegInt32("vertexAttribPointer", "offset", offset))
5082 return; 5082 return;
5083 if (!m_boundArrayBuffer) { 5083 if (!m_boundArrayBuffer) {
5084 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER"); 5084 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "no bound ARRAY_BUFFER");
5085 return; 5085 return;
5086 } 5086 }
5087 5087
5088 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer. get()); 5088 m_boundVertexArrayObject->setArrayBufferForAttrib(index, m_boundArrayBuffer. get());
5089 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein terpret_cast<void*>(static_cast<intptr_t>(offset))); 5089 contextGL()->VertexAttribPointer(index, size, type, normalized, stride, rein terpret_cast<void*>(static_cast<intptr_t>(offset)));
5090 maybePreserveDefaultVAOObjectWrapper(scriptState); 5090 maybePreserveDefaultVAOObjectWrapper(scriptState);
5091 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, V8HiddenValue:: webglBuffers(scriptState->isolate()), m_boundVertexArrayObject->getPersistentCac he(), index, m_boundArrayBuffer); 5091 preserveObjectWrapper(scriptState, m_boundVertexArrayObject, V8PrivateProper ty::getWebGLVertexArrayObjectBaseBuffers(scriptState->isolate()), m_boundVertexA rrayObject->getPersistentCache(), index, m_boundArrayBuffer);
5092 } 5092 }
5093 5093
5094 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor) 5094 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor)
5095 { 5095 {
5096 if (isContextLost()) 5096 if (isContextLost())
5097 return; 5097 return;
5098 5098
5099 if (index >= m_maxVertexAttribs) { 5099 if (index >= m_maxVertexAttribs) {
5100 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); 5100 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range");
5101 return; 5101 return;
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after
6317 for (int i = startIndex; i >= 0; --i) { 6317 for (int i = startIndex; i >= 0; --i) {
6318 if (m_textureUnits[i].m_texture2DBinding 6318 if (m_textureUnits[i].m_texture2DBinding
6319 || m_textureUnits[i].m_textureCubeMapBinding) { 6319 || m_textureUnits[i].m_textureCubeMapBinding) {
6320 m_onePlusMaxNonDefaultTextureUnit = i + 1; 6320 m_onePlusMaxNonDefaultTextureUnit = i + 1;
6321 return; 6321 return;
6322 } 6322 }
6323 } 6323 }
6324 m_onePlusMaxNonDefaultTextureUnit = 0; 6324 m_onePlusMaxNonDefaultTextureUnit = 0;
6325 } 6325 }
6326 6326
6327 void WebGLRenderingContextBase::preserveObjectWrapper(ScriptState* scriptState, ScriptWrappable* sourceObject, v8::Local<v8::String> hiddenValueName, ScopedPers istent<v8::Array>* persistentCache, uint32_t index, ScriptWrappable* targetObjec t) 6327 void WebGLRenderingContextBase::preserveObjectWrapper(ScriptState* scriptState, ScriptWrappable* sourceObject, const V8PrivateProperty::Symbol& privateSymbol, S copedPersistent<v8::Array>* persistentCache, uint32_t index, ScriptWrappable* ta rgetObject)
6328 { 6328 {
6329 v8::Isolate* isolate = scriptState->isolate(); 6329 v8::Isolate* isolate = scriptState->isolate();
6330 if (persistentCache->isEmpty()) { 6330 v8::Local<v8::Context> context = scriptState->context();
6331 // TODO(kbr): eliminate the persistent caches and just use 6331 if (scriptState->world().isMainWorld()) {
6332 // V8HiddenValue::getHiddenValue. Unfortunately, it's 6332 // This code path is very hot, especially for applications
6333 // currently too slow to use. crbug.com/611864 6333 // that make a lot of draw calls per frame, so it's crucial to
6334 persistentCache->set(isolate, v8::Array::New(isolate)); 6334 // optimize it as much as possible. The persistent caches are
6335 V8HiddenValue::setHiddenValue( 6335 // used in the main world because fetching from them is faster
6336 scriptState, 6336 // than calling V8PrivateProperty::Symbol::getOrUndefined.
6337 sourceObject->mainWorldWrapper(isolate), 6337 v8::Local<v8::Array> localCache;
6338 hiddenValueName, 6338 if (persistentCache->isEmpty()) {
6339 persistentCache->newLocal(isolate)); 6339 localCache = v8::Array::New(isolate);
6340 // It is important to mark the persistent cache as weak 6340 persistentCache->set(isolate, localCache);
6341 // (phantom, actually). Otherwise there will be a reference 6341 privateSymbol.set(context, sourceObject->mainWorldWrapper(isolate), localCache);
6342 // cycle between it and its JavaScript wrapper, and currently 6342 // It is important to mark the persistent cache as weak
6343 // there are problems collecting such cycles. 6343 // (phantom, actually). Otherwise there will be a reference
6344 persistentCache->setPhantom(); 6344 // cycle between it and its JavaScript wrapper, and currently
6345 } 6345 // there are problems collecting such cycles.
6346 6346 persistentCache->setPhantom();
6347 v8::Local<v8::Array> localCache = persistentCache->newLocal(isolate); 6347 } else {
6348 if (targetObject) { 6348 localCache = persistentCache->newLocal(isolate);
6349 v8CallOrCrash(localCache->Set(scriptState->context(), index, targetObjec t->mainWorldWrapper(isolate))); 6349 }
6350 if (targetObject) {
6351 v8CallOrCrash(localCache->Set(context, index, targetObject->mainWorl dWrapper(isolate)));
6352 } else {
6353 v8CallOrCrash(localCache->Set(context, index, v8::Null(isolate)));
6354 }
6350 } else { 6355 } else {
6351 v8CallOrCrash(localCache->Set(scriptState->context(), index, v8::Null(is olate))); 6356 // Not in the main world; either a content script, or running
6357 // in a worker. Ideally this would be made as efficient as the
6358 // code path above.
6359 v8::Local<v8::Object> sourceWrapper = v8::Local<v8::Object>::Cast(toV8(
6360 sourceObject, context->Global(), isolate));
6361 v8::Local<v8::Value> currentValue =
6362 privateSymbol.getOrUndefined(context, sourceWrapper);
6363 if (currentValue.IsEmpty() || !currentValue->IsArray()) {
6364 currentValue = v8::Array::New(isolate);
6365 privateSymbol.set(context, sourceWrapper, currentValue);
6366 }
6367 v8::Local<v8::Array> localCache = v8::Local<v8::Array>::Cast(currentValu e);
6368 if (targetObject) {
6369 v8CallOrCrash(localCache->Set(context, index, toV8(targetObject, sou rceWrapper, isolate)));
6370 } else {
6371 v8CallOrCrash(localCache->Set(context, index, v8::Null(isolate)));
6372 }
6352 } 6373 }
6353 } 6374 }
6354 6375
6355 void WebGLRenderingContextBase::maybePreserveDefaultVAOObjectWrapper(ScriptState * scriptState) 6376 void WebGLRenderingContextBase::maybePreserveDefaultVAOObjectWrapper(ScriptState * scriptState)
6356 { 6377 {
6357 ASSERT(scriptState); 6378 ASSERT(scriptState);
6358 6379
6359 if (!m_preservedDefaultVAOObjectWrapper) { 6380 if (!m_preservedDefaultVAOObjectWrapper) {
6360 // The default VAO does not have a JavaScript wrapper created for it, bu t one is needed to 6381 // The default VAO does not have a JavaScript wrapper created for it, bu t one is needed to
6361 // link up the WebGLBuffers associated with the vertex attributes. 6382 // link up the WebGLBuffers associated with the vertex attributes.
6362 toV8(m_defaultVertexArrayObject, scriptState->context()->Global(), scrip tState->isolate()); 6383 toV8(m_defaultVertexArrayObject, scriptState->context()->Global(), scrip tState->isolate());
6363 preserveObjectWrapper(scriptState, this, V8HiddenValue::webglMisc(script State->isolate()), &m_miscWrappers, static_cast<uint32_t>(PreservedDefaultVAO), m_defaultVertexArrayObject); 6384 preserveObjectWrapper(scriptState, this, V8PrivateProperty::getWebGLRend eringContextMisc(scriptState->isolate()), &m_miscWrappers, static_cast<uint32_t> (PreservedDefaultVAO), m_defaultVertexArrayObject);
6364 m_preservedDefaultVAOObjectWrapper = true; 6385 m_preservedDefaultVAOObjectWrapper = true;
6365 } 6386 }
6366 } 6387 }
6367 6388
6368 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState) 6389 DEFINE_TRACE(WebGLRenderingContextBase::TextureUnitState)
6369 { 6390 {
6370 visitor->trace(m_texture2DBinding); 6391 visitor->trace(m_texture2DBinding);
6371 visitor->trace(m_textureCubeMapBinding); 6392 visitor->trace(m_textureCubeMapBinding);
6372 visitor->trace(m_texture3DBinding); 6393 visitor->trace(m_texture3DBinding);
6373 visitor->trace(m_texture2DArrayBinding); 6394 visitor->trace(m_texture2DArrayBinding);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
6424 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6445 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6425 } 6446 }
6426 6447
6427 void WebGLRenderingContextBase::restoreUnpackParameters() 6448 void WebGLRenderingContextBase::restoreUnpackParameters()
6428 { 6449 {
6429 if (m_unpackAlignment != 1) 6450 if (m_unpackAlignment != 1)
6430 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6451 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6431 } 6452 }
6432 6453
6433 } // namespace blink 6454 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698