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

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

Issue 1205573003: WebGL 2: validate read buffer attachment when reading from FBO (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed kbr's feedback: reading from framebuffer with GL_NONE is invalid Created 5 years, 5 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 | « 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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 m_maxCubeMapTextureLevel = WebGLTexture::computeLevelCount(m_maxCubeMapTextu reSize, m_maxCubeMapTextureSize, 1); 720 m_maxCubeMapTextureLevel = WebGLTexture::computeLevelCount(m_maxCubeMapTextu reSize, m_maxCubeMapTextureSize, 1);
721 m_maxRenderbufferSize = 0; 721 m_maxRenderbufferSize = 0;
722 webContext()->getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_maxRenderbufferSize); 722 webContext()->getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_maxRenderbufferSize);
723 723
724 // These two values from EXT_draw_buffers are lazily queried. 724 // These two values from EXT_draw_buffers are lazily queried.
725 m_maxDrawBuffers = 0; 725 m_maxDrawBuffers = 0;
726 m_maxColorAttachments = 0; 726 m_maxColorAttachments = 0;
727 727
728 m_backDrawBuffer = GL_BACK; 728 m_backDrawBuffer = GL_BACK;
729 729
730 m_readBufferOfDefaultFramebuffer = GL_BACK;
731
730 if (isWebGL2OrHigher()) { 732 if (isWebGL2OrHigher()) {
731 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLV ertexArrayObjectBase::VaoTypeDefault); 733 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLV ertexArrayObjectBase::VaoTypeDefault);
732 } else { 734 } else {
733 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, Web GLVertexArrayObjectBase::VaoTypeDefault); 735 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, Web GLVertexArrayObjectBase::VaoTypeDefault);
734 } 736 }
735 addContextObject(m_defaultVertexArrayObject.get()); 737 addContextObject(m_defaultVertexArrayObject.get());
736 m_boundVertexArrayObject = m_defaultVertexArrayObject; 738 m_boundVertexArrayObject = m_defaultVertexArrayObject;
737 739
738 m_vertexAttribValue.resize(m_maxVertexAttribs); 740 m_vertexAttribValue.resize(m_maxVertexAttribs);
739 741
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 1538
1537 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format) 1539 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format)
1538 { 1540 {
1539 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers ion::ChannelDepthStencil) { 1541 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers ion::ChannelDepthStencil) {
1540 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); 1542 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to");
1541 return false; 1543 return false;
1542 } 1544 }
1543 return true; 1545 return true;
1544 } 1546 }
1545 1547
1548 bool WebGLRenderingContextBase::validateReadBufferAttachment(const char* functio nName, const WebGLFramebuffer* readFramebufferBinding)
1549 {
1550 if (readFramebufferBinding) {
1551 GLenum readBuffer = readFramebufferBinding->getReadBuffer();
1552 if (readBuffer == GL_NONE) {
1553 synthesizeGLError(GL_INVALID_OPERATION, functionName, "read buffer i s GL_NONE");
1554 return false;
1555 }
1556 WebGLSharedObject* attachmentObject = readFramebufferBinding->getAttachm entObject(readBuffer);
1557 if (!attachmentObject) {
1558 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no image atta ched to read buffer");
1559 return false;
1560 }
1561 } else if (m_readBufferOfDefaultFramebuffer == GL_NONE) {
1562 synthesizeGLError(GL_INVALID_OPERATION, functionName, "read buffer is GL _NONE");
1563 return false;
1564 }
1565 return true;
1566 }
1567
1546 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) 1568 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
1547 { 1569 {
1548 if (isContextLost()) 1570 if (isContextLost())
1549 return; 1571 return;
1550 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) 1572 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE))
1551 return; 1573 return;
1552 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) 1574 if (!validateSettableTexFormat("copyTexImage2D", internalformat))
1553 return; 1575 return;
1554 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); 1576 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true);
1555 if (!tex) 1577 if (!tex)
(...skipping 10 matching lines...) Expand all
1566 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2"); 1588 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2");
1567 return; 1589 return;
1568 } 1590 }
1569 const char* reason = "framebuffer incomplete"; 1591 const char* reason = "framebuffer incomplete";
1570 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; 1592 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER;
1571 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); 1593 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target);
1572 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { 1594 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) {
1573 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); 1595 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason);
1574 return; 1596 return;
1575 } 1597 }
1598 if (!validateReadBufferAttachment("copyTexImage2D", readFramebufferBinding))
1599 return;
1576 clearIfComposited(); 1600 clearIfComposited();
1577 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); 1601 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding);
1578 webContext()->copyTexImage2D(target, level, internalformat, x, y, width, hei ght, border); 1602 webContext()->copyTexImage2D(target, level, internalformat, x, y, width, hei ght, border);
1579 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted. 1603 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted.
1580 tex->setLevelInfo(target, level, internalformat, width, height, 1, GL_UNSIGN ED_BYTE); 1604 tex->setLevelInfo(target, level, internalformat, width, height, 1, GL_UNSIGN ED_BYTE);
1581 } 1605 }
1582 1606
1583 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) 1607 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1584 { 1608 {
1585 if (isContextLost()) 1609 if (isContextLost())
(...skipping 25 matching lines...) Expand all
1611 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format"); 1635 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format");
1612 return; 1636 return;
1613 } 1637 }
1614 const char* reason = "framebuffer incomplete"; 1638 const char* reason = "framebuffer incomplete";
1615 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; 1639 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER;
1616 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); 1640 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target);
1617 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { 1641 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) {
1618 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); 1642 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason);
1619 return; 1643 return;
1620 } 1644 }
1645 if (!validateReadBufferAttachment("copyTexSubImage2D", readFramebufferBindin g))
1646 return;
1621 clearIfComposited(); 1647 clearIfComposited();
1622 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); 1648 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding);
1623 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width , height); 1649 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width , height);
1624 } 1650 }
1625 1651
1626 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() 1652 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer()
1627 { 1653 {
1628 if (isContextLost()) 1654 if (isContextLost())
1629 return nullptr; 1655 return nullptr;
1630 RefPtrWillBeRawPtr<WebGLBuffer> o = WebGLBuffer::create(this); 1656 RefPtrWillBeRawPtr<WebGLBuffer> o = WebGLBuffer::create(this);
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after
3352 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); 3378 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding);
3353 if (error != GL_NO_ERROR) { 3379 if (error != GL_NO_ERROR) {
3354 synthesizeGLError(error, "readPixels", "invalid dimensions"); 3380 synthesizeGLError(error, "readPixels", "invalid dimensions");
3355 return; 3381 return;
3356 } 3382 }
3357 if (pixels->byteLength() < totalBytesRequired) { 3383 if (pixels->byteLength() < totalBytesRequired) {
3358 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions"); 3384 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions");
3359 return; 3385 return;
3360 } 3386 }
3361 3387
3388 if (!validateReadBufferAttachment("readPixels", readFramebufferBinding))
3389 return;
3390
3362 clearIfComposited(); 3391 clearIfComposited();
3363 void* data = pixels->baseAddress(); 3392 void* data = pixels->baseAddress();
3364 3393
3365 { 3394 {
3366 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding ); 3395 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding );
3367 webContext()->readPixels(x, y, width, height, format, type, data); 3396 webContext()->readPixels(x, y, width, height, format, type, data);
3368 } 3397 }
3369 3398
3370 #if OS(MACOSX) 3399 #if OS(MACOSX)
3371 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e., 3400 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e.,
(...skipping 2860 matching lines...) Expand 10 before | Expand all | Expand 10 after
6232 6261
6233 return totalBytesPerPixel; 6262 return totalBytesPerPixel;
6234 } 6263 }
6235 6264
6236 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6265 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6237 { 6266 {
6238 return m_drawingBuffer.get(); 6267 return m_drawingBuffer.get();
6239 } 6268 }
6240 6269
6241 } // namespace blink 6270 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698