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

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

Issue 2407753002: Fix crash from state management cleanup (Closed)
Patch Set: Fix state restore missed Created 4 years, 2 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
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 std::move(drawingBuffer()->transferToStaticBitmapImage()), 707 std::move(drawingBuffer()->transferToStaticBitmapImage()),
708 drawingBuffer()->contextProvider()->isSoftwareRendering()); 708 drawingBuffer()->contextProvider()->isSoftwareRendering());
709 } 709 }
710 710
711 PassRefPtr<Image> WebGLRenderingContextBase::getImage( 711 PassRefPtr<Image> WebGLRenderingContextBase::getImage(
712 AccelerationHint hint, 712 AccelerationHint hint,
713 SnapshotReason reason) const { 713 SnapshotReason reason) const {
714 if (!drawingBuffer()) 714 if (!drawingBuffer())
715 return nullptr; 715 return nullptr;
716 716
717 drawingBuffer()->commit(); 717 drawingBuffer()->resolveAndBindForReadAndDraw();
718 IntSize size = clampedCanvasSize(); 718 IntSize size = clampedCanvasSize();
719 OpacityMode opacityMode = 719 OpacityMode opacityMode =
720 creationAttributes().hasAlpha() ? NonOpaque : Opaque; 720 creationAttributes().hasAlpha() ? NonOpaque : Opaque;
721 std::unique_ptr<AcceleratedImageBufferSurface> surface = 721 std::unique_ptr<AcceleratedImageBufferSurface> surface =
722 wrapUnique(new AcceleratedImageBufferSurface(size, opacityMode)); 722 wrapUnique(new AcceleratedImageBufferSurface(size, opacityMode));
723 if (!surface->isValid()) 723 if (!surface->isValid())
724 return nullptr; 724 return nullptr;
725 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(std::move(surface)); 725 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(std::move(surface));
726 if (!buffer->copyRenderingResultsFromDrawingBuffer(drawingBuffer(), 726 if (!buffer->copyRenderingResultsFromDrawingBuffer(drawingBuffer(),
727 BackBuffer)) { 727 BackBuffer)) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 : DrawingBuffer::Discard; 1046 : DrawingBuffer::Discard;
1047 DrawingBuffer::WebGLVersion webGLVersion = DrawingBuffer::WebGL1; 1047 DrawingBuffer::WebGLVersion webGLVersion = DrawingBuffer::WebGL1;
1048 if (version() == 1) { 1048 if (version() == 1) {
1049 webGLVersion = DrawingBuffer::WebGL1; 1049 webGLVersion = DrawingBuffer::WebGL1;
1050 } else if (version() == 2) { 1050 } else if (version() == 2) {
1051 webGLVersion = DrawingBuffer::WebGL2; 1051 webGLVersion = DrawingBuffer::WebGL2;
1052 } else { 1052 } else {
1053 NOTREACHED(); 1053 NOTREACHED();
1054 } 1054 }
1055 return DrawingBuffer::create( 1055 return DrawingBuffer::create(
1056 std::move(contextProvider), clampedCanvasSize(), premultipliedAlpha, 1056 std::move(contextProvider), this, clampedCanvasSize(), premultipliedAlpha,
1057 wantAlphaChannel, wantDepthBuffer, wantStencilBuffer, wantAntialiasing, 1057 wantAlphaChannel, wantDepthBuffer, wantStencilBuffer, wantAntialiasing,
1058 preserve, webGLVersion, chromiumImageUsage); 1058 preserve, webGLVersion, chromiumImageUsage);
1059 } 1059 }
1060 1060
1061 void WebGLRenderingContextBase::initializeNewContext() { 1061 void WebGLRenderingContextBase::initializeNewContext() {
1062 ASSERT(!isContextLost()); 1062 ASSERT(!isContextLost());
1063 ASSERT(drawingBuffer()); 1063 ASSERT(drawingBuffer());
1064 1064
1065 m_markedCanvasDirty = false; 1065 m_markedCanvasDirty = false;
1066 m_activeTextureUnit = 0; 1066 m_activeTextureUnit = 0;
(...skipping 10 matching lines...) Expand all
1077 m_stencilEnabled = false; 1077 m_stencilEnabled = false;
1078 m_stencilMask = 0xFFFFFFFF; 1078 m_stencilMask = 0xFFFFFFFF;
1079 m_stencilMaskBack = 0xFFFFFFFF; 1079 m_stencilMaskBack = 0xFFFFFFFF;
1080 m_stencilFuncRef = 0; 1080 m_stencilFuncRef = 0;
1081 m_stencilFuncRefBack = 0; 1081 m_stencilFuncRefBack = 0;
1082 m_stencilFuncMask = 0xFFFFFFFF; 1082 m_stencilFuncMask = 0xFFFFFFFF;
1083 m_stencilFuncMaskBack = 0xFFFFFFFF; 1083 m_stencilFuncMaskBack = 0xFFFFFFFF;
1084 m_numGLErrorsToConsoleAllowed = maxGLErrorsAllowedToConsole; 1084 m_numGLErrorsToConsoleAllowed = maxGLErrorsAllowedToConsole;
1085 1085
1086 m_clearColor[0] = m_clearColor[1] = m_clearColor[2] = m_clearColor[3] = 0; 1086 m_clearColor[0] = m_clearColor[1] = m_clearColor[2] = m_clearColor[3] = 0;
1087 drawingBuffer()->setClearColor(m_clearColor);
1088 m_scissorEnabled = false; 1087 m_scissorEnabled = false;
1089 m_clearDepth = 1; 1088 m_clearDepth = 1;
1090 m_clearStencil = 0; 1089 m_clearStencil = 0;
1091 m_colorMask[0] = m_colorMask[1] = m_colorMask[2] = m_colorMask[3] = true; 1090 m_colorMask[0] = m_colorMask[1] = m_colorMask[2] = m_colorMask[3] = true;
1092 drawingBuffer()->setColorMask(m_colorMask);
1093 1091
1094 GLint numCombinedTextureImageUnits = 0; 1092 GLint numCombinedTextureImageUnits = 0;
1095 contextGL()->GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, 1093 contextGL()->GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
1096 &numCombinedTextureImageUnits); 1094 &numCombinedTextureImageUnits);
1097 m_textureUnits.clear(); 1095 m_textureUnits.clear();
1098 m_textureUnits.resize(numCombinedTextureImageUnits); 1096 m_textureUnits.resize(numCombinedTextureImageUnits);
1099 1097
1100 GLint numVertexAttribs = 0; 1098 GLint numVertexAttribs = 0;
1101 contextGL()->GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribs); 1099 contextGL()->GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribs);
1102 m_maxVertexAttribs = numVertexAttribs; 1100 m_maxVertexAttribs = numVertexAttribs;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 contextGL()->ClearStencil(0); 1367 contextGL()->ClearStencil(0);
1370 clearMask |= GL_STENCIL_BUFFER_BIT; 1368 clearMask |= GL_STENCIL_BUFFER_BIT;
1371 contextGL()->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); 1369 contextGL()->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF);
1372 } 1370 }
1373 1371
1374 contextGL()->ColorMask( 1372 contextGL()->ColorMask(
1375 true, true, true, 1373 true, true, true,
1376 !drawingBuffer()->defaultBufferRequiresAlphaChannelToBePreserved()); 1374 !drawingBuffer()->defaultBufferRequiresAlphaChannelToBePreserved());
1377 drawingBuffer()->clearFramebuffers(clearMask); 1375 drawingBuffer()->clearFramebuffers(clearMask);
1378 1376
1379 restoreStateAfterClear(); 1377 // Call the DrawingBufferClient method to restore scissor test, mask, and
1380 drawingBuffer()->restoreFramebufferBindings(); 1378 // clear values, because we dirtied them above.
1379 DrawingBufferClientRestoreScissorTest();
1380 DrawingBufferClientRestoreMaskAndClearValues();
1381
1381 drawingBuffer()->setBufferClearNeeded(false); 1382 drawingBuffer()->setBufferClearNeeded(false);
1382 1383
1383 return combinedClear ? CombinedClear : JustClear; 1384 return combinedClear ? CombinedClear : JustClear;
1384 } 1385 }
1385 1386
1386 void WebGLRenderingContextBase::restoreScissorEnabled() { 1387 void WebGLRenderingContextBase::restoreScissorEnabled() {
1387 if (isContextLost()) 1388 if (isContextLost())
1388 return; 1389 return;
1389 1390
1390 if (m_scissorEnabled) { 1391 if (m_scissorEnabled) {
(...skipping 12 matching lines...) Expand all
1403 } 1404 }
1404 1405
1405 void WebGLRenderingContextBase::restoreClearColor() { 1406 void WebGLRenderingContextBase::restoreClearColor() {
1406 if (isContextLost()) 1407 if (isContextLost())
1407 return; 1408 return;
1408 1409
1409 contextGL()->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], 1410 contextGL()->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2],
1410 m_clearColor[3]); 1411 m_clearColor[3]);
1411 } 1412 }
1412 1413
1413 void WebGLRenderingContextBase::restoreClearDepthf() {
1414 if (isContextLost())
1415 return;
1416
1417 contextGL()->ClearDepthf(m_clearDepth);
1418 }
1419
1420 void WebGLRenderingContextBase::restoreClearStencil() {
1421 if (isContextLost())
1422 return;
1423
1424 contextGL()->ClearStencil(m_clearStencil);
1425 }
1426
1427 void WebGLRenderingContextBase::restoreStencilMaskSeparate() {
1428 if (isContextLost())
1429 return;
1430
1431 contextGL()->StencilMaskSeparate(GL_FRONT, m_stencilMask);
1432 }
1433
1434 void WebGLRenderingContextBase::restoreColorMask() { 1414 void WebGLRenderingContextBase::restoreColorMask() {
1435 if (isContextLost()) 1415 if (isContextLost())
1436 return; 1416 return;
1437 1417
1438 contextGL()->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], 1418 contextGL()->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2],
1439 m_colorMask[3]); 1419 m_colorMask[3]);
1440 } 1420 }
1441 1421
1442 void WebGLRenderingContextBase::restoreDepthMask() {
1443 if (isContextLost())
1444 return;
1445
1446 contextGL()->DepthMask(m_depthMask);
1447 }
1448
1449 void WebGLRenderingContextBase::restoreStateAfterClear() {
1450 // Restore clear-related state items back to what the context had set.
1451 restoreScissorEnabled();
1452 restoreClearColor();
1453 restoreColorMask();
1454 restoreClearDepthf();
1455 restoreClearStencil();
1456 restoreStencilMaskSeparate();
1457 restoreDepthMask();
1458 }
1459
1460 void WebGLRenderingContextBase::markLayerComposited() { 1422 void WebGLRenderingContextBase::markLayerComposited() {
1461 if (!isContextLost()) 1423 if (!isContextLost())
1462 drawingBuffer()->setBufferClearNeeded(true); 1424 drawingBuffer()->setBufferClearNeeded(true);
1463 } 1425 }
1464 1426
1465 void WebGLRenderingContextBase::setIsHidden(bool hidden) { 1427 void WebGLRenderingContextBase::setIsHidden(bool hidden) {
1466 m_isHidden = hidden; 1428 m_isHidden = hidden;
1467 if (drawingBuffer()) 1429 if (drawingBuffer())
1468 drawingBuffer()->setIsHidden(hidden); 1430 drawingBuffer()->setIsHidden(hidden);
1469 1431
(...skipping 15 matching lines...) Expand all
1485 1447
1486 canvas()->clearCopiedImage(); 1448 canvas()->clearCopiedImage();
1487 m_markedCanvasDirty = false; 1449 m_markedCanvasDirty = false;
1488 1450
1489 if (!canvas()->buffer()) 1451 if (!canvas()->buffer())
1490 return false; 1452 return false;
1491 1453
1492 ScopedTexture2DRestorer restorer(this); 1454 ScopedTexture2DRestorer restorer(this);
1493 ScopedFramebufferRestorer fboRestorer(this); 1455 ScopedFramebufferRestorer fboRestorer(this);
1494 1456
1495 drawingBuffer()->commit(); 1457 drawingBuffer()->resolveAndBindForReadAndDraw();
1496 if (!canvas()->buffer()->copyRenderingResultsFromDrawingBuffer( 1458 if (!canvas()->buffer()->copyRenderingResultsFromDrawingBuffer(
1497 drawingBuffer(), sourceBuffer)) { 1459 drawingBuffer(), sourceBuffer)) {
1498 // Currently, copyRenderingResultsFromDrawingBuffer is expected to always 1460 // Currently, copyRenderingResultsFromDrawingBuffer is expected to always
1499 // succeed because cases where canvas()-buffer() is not accelerated are 1461 // succeed because cases where canvas()-buffer() is not accelerated are
1500 // handle before reaching this point. If that assumption ever stops holding 1462 // handle before reaching this point. If that assumption ever stops holding
1501 // true, we may need to implement a fallback right here. 1463 // true, we may need to implement a fallback right here.
1502 ASSERT_NOT_REACHED(); 1464 ASSERT_NOT_REACHED();
1503 return false; 1465 return false;
1504 } 1466 }
1505 1467
1506 return true; 1468 return true;
1507 } 1469 }
1508 1470
1509 ImageData* WebGLRenderingContextBase::paintRenderingResultsToImageData( 1471 ImageData* WebGLRenderingContextBase::paintRenderingResultsToImageData(
1510 SourceDrawingBuffer sourceBuffer) { 1472 SourceDrawingBuffer sourceBuffer) {
1511 if (isContextLost()) 1473 if (isContextLost())
1512 return nullptr; 1474 return nullptr;
1513 if (creationAttributes().premultipliedAlpha()) 1475 if (creationAttributes().premultipliedAlpha())
1514 return nullptr; 1476 return nullptr;
1515 1477
1516 clearIfComposited(); 1478 clearIfComposited();
1517 drawingBuffer()->commit(); 1479 drawingBuffer()->resolveAndBindForReadAndDraw();
1518 ScopedFramebufferRestorer restorer(this); 1480 ScopedFramebufferRestorer restorer(this);
1519 int width, height; 1481 int width, height;
1520 WTF::ArrayBufferContents contents; 1482 WTF::ArrayBufferContents contents;
1521 if (!drawingBuffer()->paintRenderingResultsToImageData( 1483 if (!drawingBuffer()->paintRenderingResultsToImageData(
1522 width, height, sourceBuffer, contents)) 1484 width, height, sourceBuffer, contents))
1523 return nullptr; 1485 return nullptr;
1524 DOMArrayBuffer* imageDataPixels = DOMArrayBuffer::create(contents); 1486 DOMArrayBuffer* imageDataPixels = DOMArrayBuffer::create(contents);
1525 1487
1526 return ImageData::create( 1488 return ImageData::create(
1527 IntSize(width, height), 1489 IntSize(width, height),
(...skipping 27 matching lines...) Expand all
1555 // If we've exceeded the area limit scale the buffer down, preserving 1517 // If we've exceeded the area limit scale the buffer down, preserving
1556 // ascpect ratio, until it fits. 1518 // ascpect ratio, until it fits.
1557 float scaleFactor = 1519 float scaleFactor =
1558 sqrtf(static_cast<float>(maxArea) / static_cast<float>(currentArea)); 1520 sqrtf(static_cast<float>(maxArea) / static_cast<float>(currentArea));
1559 width = std::max(1, static_cast<int>(width * scaleFactor)); 1521 width = std::max(1, static_cast<int>(width * scaleFactor));
1560 height = std::max(1, static_cast<int>(height * scaleFactor)); 1522 height = std::max(1, static_cast<int>(height * scaleFactor));
1561 } 1523 }
1562 1524
1563 // We don't have to mark the canvas as dirty, since the newly created image 1525 // We don't have to mark the canvas as dirty, since the newly created image
1564 // buffer will also start off clear (and this matches what reshape will do). 1526 // buffer will also start off clear (and this matches what reshape will do).
1565 drawingBuffer()->reset(IntSize(width, height)); 1527 drawingBuffer()->resize(IntSize(width, height));
1566 restoreStateAfterClear();
1567
1568 contextGL()->BindTexture(
1569 GL_TEXTURE_2D,
1570 objectOrZero(
1571 m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get()));
1572 contextGL()->BindRenderbuffer(GL_RENDERBUFFER,
1573 objectOrZero(m_renderbufferBinding.get()));
1574 drawingBuffer()->restoreFramebufferBindings();
1575 drawingBuffer()->restorePixelUnpackBufferBindings();
1576 } 1528 }
1577 1529
1578 int WebGLRenderingContextBase::drawingBufferWidth() const { 1530 int WebGLRenderingContextBase::drawingBufferWidth() const {
1579 return isContextLost() ? 0 : drawingBuffer()->size().width(); 1531 return isContextLost() ? 0 : drawingBuffer()->size().width();
1580 } 1532 }
1581 1533
1582 int WebGLRenderingContextBase::drawingBufferHeight() const { 1534 int WebGLRenderingContextBase::drawingBufferHeight() const {
1583 return isContextLost() ? 0 : drawingBuffer()->size().height(); 1535 return isContextLost() ? 0 : drawingBuffer()->size().height();
1584 } 1536 }
1585 1537
1586 void WebGLRenderingContextBase::activeTexture(GLenum texture) { 1538 void WebGLRenderingContextBase::activeTexture(GLenum texture) {
1587 if (isContextLost()) 1539 if (isContextLost())
1588 return; 1540 return;
1589 if (texture - GL_TEXTURE0 >= m_textureUnits.size()) { 1541 if (texture - GL_TEXTURE0 >= m_textureUnits.size()) {
1590 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", 1542 synthesizeGLError(GL_INVALID_ENUM, "activeTexture",
1591 "texture unit out of range"); 1543 "texture unit out of range");
1592 return; 1544 return;
1593 } 1545 }
1594 m_activeTextureUnit = texture - GL_TEXTURE0; 1546 m_activeTextureUnit = texture - GL_TEXTURE0;
1595 contextGL()->ActiveTexture(texture); 1547 contextGL()->ActiveTexture(texture);
1596
1597 drawingBuffer()->setActiveTextureUnit(texture);
1598 } 1548 }
1599 1549
1600 void WebGLRenderingContextBase::attachShader(WebGLProgram* program, 1550 void WebGLRenderingContextBase::attachShader(WebGLProgram* program,
1601 WebGLShader* shader) { 1551 WebGLShader* shader) {
1602 if (isContextLost() || !validateWebGLObject("attachShader", program) || 1552 if (isContextLost() || !validateWebGLObject("attachShader", program) ||
1603 !validateWebGLObject("attachShader", shader)) 1553 !validateWebGLObject("attachShader", shader))
1604 return; 1554 return;
1605 if (!program->attachShader(shader)) { 1555 if (!program->attachShader(shader)) {
1606 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", 1556 synthesizeGLError(GL_INVALID_OPERATION, "attachShader",
1607 "shader attachment already has shader"); 1557 "shader attachment already has shader");
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 bool deleted; 1629 bool deleted;
1680 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) 1630 if (!checkObjectToBeBound("bindBuffer", buffer, deleted))
1681 return; 1631 return;
1682 if (deleted) { 1632 if (deleted) {
1683 synthesizeGLError(GL_INVALID_OPERATION, "bindBuffer", 1633 synthesizeGLError(GL_INVALID_OPERATION, "bindBuffer",
1684 "attempt to bind a deleted buffer"); 1634 "attempt to bind a deleted buffer");
1685 return; 1635 return;
1686 } 1636 }
1687 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer)) 1637 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer))
1688 return; 1638 return;
1689
1690 if (target == GL_PIXEL_UNPACK_BUFFER) {
1691 drawingBuffer()->setPixelUnpackBufferBinding(objectOrZero(buffer));
1692 }
1693 contextGL()->BindBuffer(target, objectOrZero(buffer)); 1639 contextGL()->BindBuffer(target, objectOrZero(buffer));
1694 } 1640 }
1695 1641
1696 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, 1642 void WebGLRenderingContextBase::bindFramebuffer(GLenum target,
1697 WebGLFramebuffer* buffer) { 1643 WebGLFramebuffer* buffer) {
1698 bool deleted; 1644 bool deleted;
1699 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) 1645 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted))
1700 return; 1646 return;
1701 if (deleted) { 1647 if (deleted) {
1702 synthesizeGLError(GL_INVALID_OPERATION, "bindFramebuffer", 1648 synthesizeGLError(GL_INVALID_OPERATION, "bindFramebuffer",
(...skipping 19 matching lines...) Expand all
1722 synthesizeGLError(GL_INVALID_OPERATION, "bindRenderbuffer", 1668 synthesizeGLError(GL_INVALID_OPERATION, "bindRenderbuffer",
1723 "attempt to bind a deleted renderbuffer"); 1669 "attempt to bind a deleted renderbuffer");
1724 return; 1670 return;
1725 } 1671 }
1726 if (target != GL_RENDERBUFFER) { 1672 if (target != GL_RENDERBUFFER) {
1727 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target"); 1673 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target");
1728 return; 1674 return;
1729 } 1675 }
1730 m_renderbufferBinding = renderBuffer; 1676 m_renderbufferBinding = renderBuffer;
1731 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer)); 1677 contextGL()->BindRenderbuffer(target, objectOrZero(renderBuffer));
1732
1733 drawingBuffer()->setRenderbufferBinding(objectOrZero(renderBuffer));
1734
1735 if (renderBuffer) 1678 if (renderBuffer)
1736 renderBuffer->setHasEverBeenBound(); 1679 renderBuffer->setHasEverBeenBound();
1737 } 1680 }
1738 1681
1739 void WebGLRenderingContextBase::bindTexture(GLenum target, 1682 void WebGLRenderingContextBase::bindTexture(GLenum target,
1740 WebGLTexture* texture) { 1683 WebGLTexture* texture) {
1741 bool deleted; 1684 bool deleted;
1742 if (!checkObjectToBeBound("bindTexture", texture, deleted)) 1685 if (!checkObjectToBeBound("bindTexture", texture, deleted))
1743 return; 1686 return;
1744 if (deleted) { 1687 if (deleted) {
1745 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", 1688 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture",
1746 "attempt to bind a deleted texture"); 1689 "attempt to bind a deleted texture");
1747 return; 1690 return;
1748 } 1691 }
1749 if (texture && texture->getTarget() && texture->getTarget() != target) { 1692 if (texture && texture->getTarget() && texture->getTarget() != target) {
1750 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", 1693 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture",
1751 "textures can not be used with multiple targets"); 1694 "textures can not be used with multiple targets");
1752 return; 1695 return;
1753 } 1696 }
1754 1697
1755 if (target == GL_TEXTURE_2D) { 1698 if (target == GL_TEXTURE_2D) {
1756 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; 1699 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture;
1757
1758 if (!m_activeTextureUnit)
1759 drawingBuffer()->setTexture2DBinding(objectOrZero(texture));
1760 } else if (target == GL_TEXTURE_CUBE_MAP) { 1700 } else if (target == GL_TEXTURE_CUBE_MAP) {
1761 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; 1701 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture;
1762 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) { 1702 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_2D_ARRAY) {
1763 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture; 1703 m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding = texture;
1764 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) { 1704 } else if (isWebGL2OrHigher() && target == GL_TEXTURE_3D) {
1765 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture; 1705 m_textureUnits[m_activeTextureUnit].m_texture3DBinding = texture;
1766 } else { 1706 } else {
1767 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); 1707 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target");
1768 return; 1708 return;
1769 } 1709 }
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 if (std::isnan(g)) 1951 if (std::isnan(g))
2012 g = 0; 1952 g = 0;
2013 if (std::isnan(b)) 1953 if (std::isnan(b))
2014 b = 0; 1954 b = 0;
2015 if (std::isnan(a)) 1955 if (std::isnan(a))
2016 a = 1; 1956 a = 1;
2017 m_clearColor[0] = r; 1957 m_clearColor[0] = r;
2018 m_clearColor[1] = g; 1958 m_clearColor[1] = g;
2019 m_clearColor[2] = b; 1959 m_clearColor[2] = b;
2020 m_clearColor[3] = a; 1960 m_clearColor[3] = a;
2021 drawingBuffer()->setClearColor(m_clearColor);
2022 contextGL()->ClearColor(r, g, b, a); 1961 contextGL()->ClearColor(r, g, b, a);
2023 } 1962 }
2024 1963
2025 void WebGLRenderingContextBase::clearDepth(GLfloat depth) { 1964 void WebGLRenderingContextBase::clearDepth(GLfloat depth) {
2026 if (isContextLost()) 1965 if (isContextLost())
2027 return; 1966 return;
2028 m_clearDepth = depth; 1967 m_clearDepth = depth;
2029 contextGL()->ClearDepthf(depth); 1968 contextGL()->ClearDepthf(depth);
2030 } 1969 }
2031 1970
2032 void WebGLRenderingContextBase::clearStencil(GLint s) { 1971 void WebGLRenderingContextBase::clearStencil(GLint s) {
2033 if (isContextLost()) 1972 if (isContextLost())
2034 return; 1973 return;
2035 m_clearStencil = s; 1974 m_clearStencil = s;
2036 contextGL()->ClearStencil(s); 1975 contextGL()->ClearStencil(s);
2037 } 1976 }
2038 1977
2039 void WebGLRenderingContextBase::colorMask(GLboolean red, 1978 void WebGLRenderingContextBase::colorMask(GLboolean red,
2040 GLboolean green, 1979 GLboolean green,
2041 GLboolean blue, 1980 GLboolean blue,
2042 GLboolean alpha) { 1981 GLboolean alpha) {
2043 if (isContextLost()) 1982 if (isContextLost())
2044 return; 1983 return;
2045 m_colorMask[0] = red; 1984 m_colorMask[0] = red;
2046 m_colorMask[1] = green; 1985 m_colorMask[1] = green;
2047 m_colorMask[2] = blue; 1986 m_colorMask[2] = blue;
2048 m_colorMask[3] = alpha; 1987 m_colorMask[3] = alpha;
2049 drawingBuffer()->setColorMask(m_colorMask);
2050 contextGL()->ColorMask(red, green, blue, alpha); 1988 contextGL()->ColorMask(red, green, blue, alpha);
2051 } 1989 }
2052 1990
2053 void WebGLRenderingContextBase::compileShader(WebGLShader* shader) { 1991 void WebGLRenderingContextBase::compileShader(WebGLShader* shader) {
2054 if (isContextLost() || !validateWebGLObject("compileShader", shader)) 1992 if (isContextLost() || !validateWebGLObject("compileShader", shader))
2055 return; 1993 return;
2056 contextGL()->CompileShader(objectOrZero(shader)); 1994 contextGL()->CompileShader(objectOrZero(shader));
2057 } 1995 }
2058 1996
2059 void WebGLRenderingContextBase::compressedTexImage2D(GLenum target, 1997 void WebGLRenderingContextBase::compressedTexImage2D(GLenum target,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 } 2188 }
2251 if (object->hasObject()) { 2189 if (object->hasObject()) {
2252 // We need to pass in context here because we want 2190 // We need to pass in context here because we want
2253 // things in this context unbound. 2191 // things in this context unbound.
2254 object->deleteObject(contextGL()); 2192 object->deleteObject(contextGL());
2255 } 2193 }
2256 return true; 2194 return true;
2257 } 2195 }
2258 2196
2259 void WebGLRenderingContextBase::deleteBuffer(WebGLBuffer* buffer) { 2197 void WebGLRenderingContextBase::deleteBuffer(WebGLBuffer* buffer) {
2260 GLuint bufferName = objectOrZero(buffer);
2261 if (!deleteObject(buffer)) 2198 if (!deleteObject(buffer))
2262 return; 2199 return;
2263 drawingBuffer()->notifyBufferDeleted(bufferName);
2264 removeBoundBuffer(buffer); 2200 removeBoundBuffer(buffer);
2265 } 2201 }
2266 2202
2267 void WebGLRenderingContextBase::deleteFramebuffer( 2203 void WebGLRenderingContextBase::deleteFramebuffer(
2268 WebGLFramebuffer* framebuffer) { 2204 WebGLFramebuffer* framebuffer) {
2269 if (!deleteObject(framebuffer)) 2205 if (!deleteObject(framebuffer))
2270 return; 2206 return;
2271 if (framebuffer == m_framebufferBinding) { 2207 if (framebuffer == m_framebufferBinding) {
2272 m_framebufferBinding = nullptr; 2208 m_framebufferBinding = nullptr;
2273 drawingBuffer()->setFramebufferBinding(GL_FRAMEBUFFER, 0);
2274 // Have to call drawingBuffer()->bind() here to bind back to internal fbo. 2209 // Have to call drawingBuffer()->bind() here to bind back to internal fbo.
2275 drawingBuffer()->bind(GL_FRAMEBUFFER); 2210 drawingBuffer()->bind(GL_FRAMEBUFFER);
2276 } 2211 }
2277 } 2212 }
2278 2213
2279 void WebGLRenderingContextBase::deleteProgram(WebGLProgram* program) { 2214 void WebGLRenderingContextBase::deleteProgram(WebGLProgram* program) {
2280 deleteObject(program); 2215 deleteObject(program);
2281 // We don't reset m_currentProgram to 0 here because the deletion of the 2216 // We don't reset m_currentProgram to 0 here because the deletion of the
2282 // current program is delayed. 2217 // current program is delayed.
2283 } 2218 }
2284 2219
2285 void WebGLRenderingContextBase::deleteRenderbuffer( 2220 void WebGLRenderingContextBase::deleteRenderbuffer(
2286 WebGLRenderbuffer* renderbuffer) { 2221 WebGLRenderbuffer* renderbuffer) {
2287 if (!deleteObject(renderbuffer)) 2222 if (!deleteObject(renderbuffer))
2288 return; 2223 return;
2289 if (renderbuffer == m_renderbufferBinding) { 2224 if (renderbuffer == m_renderbufferBinding) {
2290 m_renderbufferBinding = nullptr; 2225 m_renderbufferBinding = nullptr;
2291 drawingBuffer()->setRenderbufferBinding(0);
2292 } 2226 }
2293 if (m_framebufferBinding) 2227 if (m_framebufferBinding)
2294 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(GL_FRAMEBUFFER, 2228 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(GL_FRAMEBUFFER,
2295 renderbuffer); 2229 renderbuffer);
2296 if (getFramebufferBinding(GL_READ_FRAMEBUFFER)) 2230 if (getFramebufferBinding(GL_READ_FRAMEBUFFER))
2297 getFramebufferBinding(GL_READ_FRAMEBUFFER) 2231 getFramebufferBinding(GL_READ_FRAMEBUFFER)
2298 ->removeAttachmentFromBoundFramebuffer(GL_READ_FRAMEBUFFER, 2232 ->removeAttachmentFromBoundFramebuffer(GL_READ_FRAMEBUFFER,
2299 renderbuffer); 2233 renderbuffer);
2300 } 2234 }
2301 2235
2302 void WebGLRenderingContextBase::deleteShader(WebGLShader* shader) { 2236 void WebGLRenderingContextBase::deleteShader(WebGLShader* shader) {
2303 deleteObject(shader); 2237 deleteObject(shader);
2304 } 2238 }
2305 2239
2306 void WebGLRenderingContextBase::deleteTexture(WebGLTexture* texture) { 2240 void WebGLRenderingContextBase::deleteTexture(WebGLTexture* texture) {
2307 if (!deleteObject(texture)) 2241 if (!deleteObject(texture))
2308 return; 2242 return;
2309 2243
2310 int maxBoundTextureIndex = -1; 2244 int maxBoundTextureIndex = -1;
2311 for (size_t i = 0; i < m_onePlusMaxNonDefaultTextureUnit; ++i) { 2245 for (size_t i = 0; i < m_onePlusMaxNonDefaultTextureUnit; ++i) {
2312 if (texture == m_textureUnits[i].m_texture2DBinding) { 2246 if (texture == m_textureUnits[i].m_texture2DBinding) {
2313 m_textureUnits[i].m_texture2DBinding = nullptr; 2247 m_textureUnits[i].m_texture2DBinding = nullptr;
2314 maxBoundTextureIndex = i; 2248 maxBoundTextureIndex = i;
2315 if (!i)
2316 drawingBuffer()->setTexture2DBinding(0);
2317 } 2249 }
2318 if (texture == m_textureUnits[i].m_textureCubeMapBinding) { 2250 if (texture == m_textureUnits[i].m_textureCubeMapBinding) {
2319 m_textureUnits[i].m_textureCubeMapBinding = nullptr; 2251 m_textureUnits[i].m_textureCubeMapBinding = nullptr;
2320 maxBoundTextureIndex = i; 2252 maxBoundTextureIndex = i;
2321 } 2253 }
2322 if (isWebGL2OrHigher()) { 2254 if (isWebGL2OrHigher()) {
2323 if (texture == m_textureUnits[i].m_texture3DBinding) { 2255 if (texture == m_textureUnits[i].m_texture3DBinding) {
2324 m_textureUnits[i].m_texture3DBinding = nullptr; 2256 m_textureUnits[i].m_texture3DBinding = nullptr;
2325 maxBoundTextureIndex = i; 2257 maxBoundTextureIndex = i;
2326 } 2258 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 } 2316 }
2385 2317
2386 void WebGLRenderingContextBase::disable(GLenum cap) { 2318 void WebGLRenderingContextBase::disable(GLenum cap) {
2387 if (isContextLost() || !validateCapability("disable", cap)) 2319 if (isContextLost() || !validateCapability("disable", cap))
2388 return; 2320 return;
2389 if (cap == GL_STENCIL_TEST) { 2321 if (cap == GL_STENCIL_TEST) {
2390 m_stencilEnabled = false; 2322 m_stencilEnabled = false;
2391 applyStencilTest(); 2323 applyStencilTest();
2392 return; 2324 return;
2393 } 2325 }
2394 if (cap == GL_SCISSOR_TEST) { 2326 if (cap == GL_SCISSOR_TEST)
2395 m_scissorEnabled = false; 2327 m_scissorEnabled = false;
2396 drawingBuffer()->setScissorEnabled(m_scissorEnabled);
2397 }
2398 contextGL()->Disable(cap); 2328 contextGL()->Disable(cap);
2399 } 2329 }
2400 2330
2401 void WebGLRenderingContextBase::disableVertexAttribArray(GLuint index) { 2331 void WebGLRenderingContextBase::disableVertexAttribArray(GLuint index) {
2402 if (isContextLost()) 2332 if (isContextLost())
2403 return; 2333 return;
2404 if (index >= m_maxVertexAttribs) { 2334 if (index >= m_maxVertexAttribs) {
2405 synthesizeGLError(GL_INVALID_VALUE, "disableVertexAttribArray", 2335 synthesizeGLError(GL_INVALID_VALUE, "disableVertexAttribArray",
2406 "index out of range"); 2336 "index out of range");
2407 return; 2337 return;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 } 2453 }
2524 2454
2525 void WebGLRenderingContextBase::enable(GLenum cap) { 2455 void WebGLRenderingContextBase::enable(GLenum cap) {
2526 if (isContextLost() || !validateCapability("enable", cap)) 2456 if (isContextLost() || !validateCapability("enable", cap))
2527 return; 2457 return;
2528 if (cap == GL_STENCIL_TEST) { 2458 if (cap == GL_STENCIL_TEST) {
2529 m_stencilEnabled = true; 2459 m_stencilEnabled = true;
2530 applyStencilTest(); 2460 applyStencilTest();
2531 return; 2461 return;
2532 } 2462 }
2533 if (cap == GL_SCISSOR_TEST) { 2463 if (cap == GL_SCISSOR_TEST)
2534 m_scissorEnabled = true; 2464 m_scissorEnabled = true;
2535 drawingBuffer()->setScissorEnabled(m_scissorEnabled);
2536 }
2537 contextGL()->Enable(cap); 2465 contextGL()->Enable(cap);
2538 } 2466 }
2539 2467
2540 void WebGLRenderingContextBase::enableVertexAttribArray(GLuint index) { 2468 void WebGLRenderingContextBase::enableVertexAttribArray(GLuint index) {
2541 if (isContextLost()) 2469 if (isContextLost())
2542 return; 2470 return;
2543 if (index >= m_maxVertexAttribs) { 2471 if (index >= m_maxVertexAttribs) {
2544 synthesizeGLError(GL_INVALID_VALUE, "enableVertexAttribArray", 2472 synthesizeGLError(GL_INVALID_VALUE, "enableVertexAttribArray",
2545 "index out of range"); 2473 "index out of range");
2546 return; 2474 return;
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after
3927 GL_INVALID_VALUE, "pixelStorei", 3855 GL_INVALID_VALUE, "pixelStorei",
3928 "invalid parameter for UNPACK_COLORSPACE_CONVERSION_WEBGL"); 3856 "invalid parameter for UNPACK_COLORSPACE_CONVERSION_WEBGL");
3929 return; 3857 return;
3930 } 3858 }
3931 break; 3859 break;
3932 case GL_PACK_ALIGNMENT: 3860 case GL_PACK_ALIGNMENT:
3933 case GL_UNPACK_ALIGNMENT: 3861 case GL_UNPACK_ALIGNMENT:
3934 if (param == 1 || param == 2 || param == 4 || param == 8) { 3862 if (param == 1 || param == 2 || param == 4 || param == 8) {
3935 if (pname == GL_PACK_ALIGNMENT) { 3863 if (pname == GL_PACK_ALIGNMENT) {
3936 m_packAlignment = param; 3864 m_packAlignment = param;
3937 drawingBuffer()->setPackAlignment(param);
3938 } else { // GL_UNPACK_ALIGNMENT: 3865 } else { // GL_UNPACK_ALIGNMENT:
3939 m_unpackAlignment = param; 3866 m_unpackAlignment = param;
3940 } 3867 }
3941 contextGL()->PixelStorei(pname, param); 3868 contextGL()->PixelStorei(pname, param);
3942 } else { 3869 } else {
3943 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei", 3870 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei",
3944 "invalid parameter for alignment"); 3871 "invalid parameter for alignment");
3945 return; 3872 return;
3946 } 3873 }
3947 break; 3874 break;
(...skipping 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after
5946 void WebGLRenderingContextBase::loseContextImpl( 5873 void WebGLRenderingContextBase::loseContextImpl(
5947 WebGLRenderingContextBase::LostContextMode mode, 5874 WebGLRenderingContextBase::LostContextMode mode,
5948 AutoRecoveryMethod autoRecoveryMethod) { 5875 AutoRecoveryMethod autoRecoveryMethod) {
5949 if (isContextLost()) 5876 if (isContextLost())
5950 return; 5877 return;
5951 5878
5952 m_contextLostMode = mode; 5879 m_contextLostMode = mode;
5953 ASSERT(m_contextLostMode != NotLostContext); 5880 ASSERT(m_contextLostMode != NotLostContext);
5954 m_autoRecoveryMethod = autoRecoveryMethod; 5881 m_autoRecoveryMethod = autoRecoveryMethod;
5955 5882
5956 // Make absolutely sure we do not refer to an already-deleted texture or
5957 // framebuffer.
5958 drawingBuffer()->setTexture2DBinding(0);
5959 drawingBuffer()->setFramebufferBinding(GL_FRAMEBUFFER, 0);
5960 drawingBuffer()->setRenderbufferBinding(0);
5961
5962 detachAndRemoveAllObjects(); 5883 detachAndRemoveAllObjects();
5963 5884
5964 // Lose all the extensions. 5885 // Lose all the extensions.
5965 for (size_t i = 0; i < m_extensions.size(); ++i) { 5886 for (size_t i = 0; i < m_extensions.size(); ++i) {
5966 ExtensionTracker* tracker = m_extensions[i]; 5887 ExtensionTracker* tracker = m_extensions[i];
5967 tracker->loseExtension(false); 5888 tracker->loseExtension(false);
5968 } 5889 }
5969 5890
5970 for (size_t i = 0; i < WebGLExtensionNameCount; ++i) 5891 for (size_t i = 0; i < WebGLExtensionNameCount; ++i)
5971 m_extensionEnabled[i] = false; 5892 m_extensionEnabled[i] = false;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
6108 } 6029 }
6109 } 6030 }
6110 6031
6111 void WebGLRenderingContextBase::stop() { 6032 void WebGLRenderingContextBase::stop() {
6112 if (!isContextLost()) { 6033 if (!isContextLost()) {
6113 // Never attempt to restore the context because the page is being torn down. 6034 // Never attempt to restore the context because the page is being torn down.
6114 forceLostContext(SyntheticLostContext, Manual); 6035 forceLostContext(SyntheticLostContext, Manual);
6115 } 6036 }
6116 } 6037 }
6117 6038
6039 bool WebGLRenderingContextBase::DrawingBufferClientIsBoundForDraw() {
6040 return !m_framebufferBinding;
6041 }
6042
6043 void WebGLRenderingContextBase::DrawingBufferClientRestoreScissorTest() {
6044 if (!contextGL())
6045 return;
6046 if (m_scissorEnabled)
6047 contextGL()->Enable(GL_SCISSOR_TEST);
6048 else
6049 contextGL()->Disable(GL_SCISSOR_TEST);
6050 }
6051
6052 void WebGLRenderingContextBase::DrawingBufferClientRestoreMaskAndClearValues() {
6053 if (!contextGL())
6054 return;
6055 contextGL()->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2],
6056 m_colorMask[3]);
6057 contextGL()->DepthMask(m_depthMask);
6058 contextGL()->StencilMaskSeparate(GL_FRONT, m_stencilMask);
6059
6060 contextGL()->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2],
6061 m_clearColor[3]);
6062 contextGL()->ClearDepthf(m_clearDepth);
6063 contextGL()->ClearStencil(m_clearStencil);
6064 }
6065
6066 void WebGLRenderingContextBase::DrawingBufferClientRestorePixelPackAlignment() {
6067 if (!contextGL())
6068 return;
6069 contextGL()->PixelStorei(GL_PACK_ALIGNMENT, m_packAlignment);
6070 }
6071
6072 void WebGLRenderingContextBase::DrawingBufferClientRestoreTexture2DBinding() {
6073 if (!contextGL())
6074 return;
6075 restoreCurrentTexture2D();
6076 }
6077
6078 void WebGLRenderingContextBase::
6079 DrawingBufferClientRestoreRenderbufferBinding() {
6080 if (!contextGL())
6081 return;
6082 contextGL()->BindRenderbuffer(GL_RENDERBUFFER,
6083 objectOrZero(m_renderbufferBinding.get()));
6084 }
6085
6086 void WebGLRenderingContextBase::DrawingBufferClientRestoreFramebufferBinding() {
6087 if (!contextGL())
6088 return;
6089 restoreCurrentFramebuffer();
6090 }
6091
6092 void WebGLRenderingContextBase::
6093 DrawingBufferClientRestorePixelUnpackBufferBinding() {}
6094
6118 ScriptValue WebGLRenderingContextBase::getBooleanParameter( 6095 ScriptValue WebGLRenderingContextBase::getBooleanParameter(
6119 ScriptState* scriptState, 6096 ScriptState* scriptState,
6120 GLenum pname) { 6097 GLenum pname) {
6121 GLboolean value = 0; 6098 GLboolean value = 0;
6122 if (!isContextLost()) 6099 if (!isContextLost())
6123 contextGL()->GetBooleanv(pname, &value); 6100 contextGL()->GetBooleanv(pname, &value);
6124 return WebGLAny(scriptState, static_cast<bool>(value)); 6101 return WebGLAny(scriptState, static_cast<bool>(value));
6125 } 6102 }
6126 6103
6127 ScriptValue WebGLRenderingContextBase::getBooleanArrayParameter( 6104 ScriptValue WebGLRenderingContextBase::getBooleanArrayParameter(
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after
7401 7378
7402 void WebGLRenderingContextBase::setFramebuffer(GLenum target, 7379 void WebGLRenderingContextBase::setFramebuffer(GLenum target,
7403 WebGLFramebuffer* buffer) { 7380 WebGLFramebuffer* buffer) {
7404 if (buffer) 7381 if (buffer)
7405 buffer->setHasEverBeenBound(); 7382 buffer->setHasEverBeenBound();
7406 7383
7407 if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER) { 7384 if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER) {
7408 m_framebufferBinding = buffer; 7385 m_framebufferBinding = buffer;
7409 applyStencilTest(); 7386 applyStencilTest();
7410 } 7387 }
7411 drawingBuffer()->setFramebufferBinding(
7412 target, objectOrZero(getFramebufferBinding(target)));
7413
7414 if (!buffer) { 7388 if (!buffer) {
7415 // Instead of binding fb 0, bind the drawing buffer. 7389 // Instead of binding fb 0, bind the drawing buffer.
7416 drawingBuffer()->bind(target); 7390 drawingBuffer()->bind(target);
7417 } else { 7391 } else {
7418 contextGL()->BindFramebuffer(target, buffer->object()); 7392 contextGL()->BindFramebuffer(target, buffer->object());
7419 } 7393 }
7420 } 7394 }
7421 7395
7422 void WebGLRenderingContextBase::restoreCurrentFramebuffer() { 7396 void WebGLRenderingContextBase::restoreCurrentFramebuffer() {
7423 bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding.get()); 7397 bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding.get());
7424 } 7398 }
7425 7399
7426 void WebGLRenderingContextBase::restoreCurrentTexture2D() { 7400 void WebGLRenderingContextBase::restoreCurrentTexture2D() {
7427 bindTexture(GL_TEXTURE_2D, 7401 if (m_activeTextureUnit < m_textureUnits.size()) {
7428 m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get()); 7402 bindTexture(GL_TEXTURE_2D,
7403 m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get());
7404 }
7429 } 7405 }
7430 7406
7431 void WebGLRenderingContextBase::findNewMaxNonDefaultTextureUnit() { 7407 void WebGLRenderingContextBase::findNewMaxNonDefaultTextureUnit() {
7432 // Trace backwards from the current max to find the new max non-default 7408 // Trace backwards from the current max to find the new max non-default
7433 // texture unit 7409 // texture unit
7434 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1; 7410 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1;
7435 for (int i = startIndex; i >= 0; --i) { 7411 for (int i = startIndex; i >= 0; --i) {
7436 if (m_textureUnits[i].m_texture2DBinding || 7412 if (m_textureUnits[i].m_texture2DBinding ||
7437 m_textureUnits[i].m_textureCubeMapBinding) { 7413 m_textureUnits[i].m_textureCubeMapBinding) {
7438 m_onePlusMaxNonDefaultTextureUnit = i + 1; 7414 m_onePlusMaxNonDefaultTextureUnit = i + 1;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
7529 7505
7530 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( 7506 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(
7531 HTMLCanvasElementOrOffscreenCanvas& result) const { 7507 HTMLCanvasElementOrOffscreenCanvas& result) const {
7532 if (canvas()) 7508 if (canvas())
7533 result.setHTMLCanvasElement(canvas()); 7509 result.setHTMLCanvasElement(canvas());
7534 else 7510 else
7535 result.setOffscreenCanvas(getOffscreenCanvas()); 7511 result.setOffscreenCanvas(getOffscreenCanvas());
7536 } 7512 }
7537 7513
7538 } // namespace blink 7514 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698