OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1536 | 1536 |
1537 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format) | 1537 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format) |
1538 { | 1538 { |
1539 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers ion::ChannelDepthStencil) { | 1539 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers ion::ChannelDepthStencil) { |
1540 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); | 1540 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); |
1541 return false; | 1541 return false; |
1542 } | 1542 } |
1543 return true; | 1543 return true; |
1544 } | 1544 } |
1545 | 1545 |
1546 bool WebGLRenderingContextBase::validateReadBufferAttachment(const char* functio nName, const WebGLFramebuffer* readFramebufferBinding) | |
1547 { | |
1548 if (readFramebufferBinding) { | |
1549 GLenum readBuffer = readFramebufferBinding->getReadBuffer(); | |
1550 WebGLSharedObject* attachmentObject = readFramebufferBinding->getAttachm entObject(readBuffer); | |
1551 if (!attachmentObject) { | |
1552 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no image atta ched to read buffer"); | |
1553 return false; | |
1554 } | |
1555 } | |
1556 return true; | |
Zhenyao Mo
2015/07/06 17:52:25
Shouldn't you also check here that the back buffer
Ken Russell (switch to Gerrit)
2015/07/06 21:19:13
Agree with Mo's observation, though if the underly
yunchao
2015/07/07 08:10:39
Done.
| |
1557 } | |
1558 | |
1546 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) | 1559 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) |
1547 { | 1560 { |
1548 if (isContextLost()) | 1561 if (isContextLost()) |
1549 return; | 1562 return; |
1550 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) | 1563 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) |
1551 return; | 1564 return; |
1552 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) | 1565 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) |
1553 return; | 1566 return; |
1554 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); | 1567 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); |
1555 if (!tex) | 1568 if (!tex) |
(...skipping 10 matching lines...) Expand all Loading... | |
1566 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2"); | 1579 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2"); |
1567 return; | 1580 return; |
1568 } | 1581 } |
1569 const char* reason = "framebuffer incomplete"; | 1582 const char* reason = "framebuffer incomplete"; |
1570 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; | 1583 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; |
1571 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); | 1584 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); |
1572 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { | 1585 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { |
1573 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); | 1586 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); |
1574 return; | 1587 return; |
1575 } | 1588 } |
1589 if (!validateReadBufferAttachment("copyTexImage2D", readFramebufferBinding)) | |
1590 return; | |
1576 clearIfComposited(); | 1591 clearIfComposited(); |
1577 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); | 1592 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); |
1578 webContext()->copyTexImage2D(target, level, internalformat, x, y, width, hei ght, border); | 1593 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. | 1594 // 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); | 1595 tex->setLevelInfo(target, level, internalformat, width, height, 1, GL_UNSIGN ED_BYTE); |
1581 } | 1596 } |
1582 | 1597 |
1583 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) | 1598 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) |
1584 { | 1599 { |
1585 if (isContextLost()) | 1600 if (isContextLost()) |
(...skipping 25 matching lines...) Expand all Loading... | |
1611 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format"); | 1626 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format"); |
1612 return; | 1627 return; |
1613 } | 1628 } |
1614 const char* reason = "framebuffer incomplete"; | 1629 const char* reason = "framebuffer incomplete"; |
1615 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; | 1630 GLenum framebufferTarget = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRA MEBUFFER; |
1616 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); | 1631 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(framebuffer Target); |
1617 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { | 1632 if (readFramebufferBinding && !readFramebufferBinding->onAccess(webContext() , &reason)) { |
1618 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); | 1633 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); |
1619 return; | 1634 return; |
1620 } | 1635 } |
1636 if (!validateReadBufferAttachment("copyTexSubImage2D", readFramebufferBindin g)) | |
1637 return; | |
1621 clearIfComposited(); | 1638 clearIfComposited(); |
1622 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); | 1639 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); |
1623 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width , height); | 1640 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width , height); |
1624 } | 1641 } |
1625 | 1642 |
1626 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() | 1643 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() |
1627 { | 1644 { |
1628 if (isContextLost()) | 1645 if (isContextLost()) |
1629 return nullptr; | 1646 return nullptr; |
1630 RefPtrWillBeRawPtr<WebGLBuffer> o = WebGLBuffer::create(this); | 1647 RefPtrWillBeRawPtr<WebGLBuffer> o = WebGLBuffer::create(this); |
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3352 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); | 3369 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); |
3353 if (error != GL_NO_ERROR) { | 3370 if (error != GL_NO_ERROR) { |
3354 synthesizeGLError(error, "readPixels", "invalid dimensions"); | 3371 synthesizeGLError(error, "readPixels", "invalid dimensions"); |
3355 return; | 3372 return; |
3356 } | 3373 } |
3357 if (pixels->byteLength() < totalBytesRequired) { | 3374 if (pixels->byteLength() < totalBytesRequired) { |
3358 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions"); | 3375 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions"); |
3359 return; | 3376 return; |
3360 } | 3377 } |
3361 | 3378 |
3379 if (!validateReadBufferAttachment("readPixels", readFramebufferBinding)) | |
3380 return; | |
3381 | |
3362 clearIfComposited(); | 3382 clearIfComposited(); |
3363 void* data = pixels->baseAddress(); | 3383 void* data = pixels->baseAddress(); |
3364 | 3384 |
3365 { | 3385 { |
3366 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding ); | 3386 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding ); |
3367 webContext()->readPixels(x, y, width, height, format, type, data); | 3387 webContext()->readPixels(x, y, width, height, format, type, data); |
3368 } | 3388 } |
3369 | 3389 |
3370 #if OS(MACOSX) | 3390 #if OS(MACOSX) |
3371 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e., | 3391 // 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 Loading... | |
6232 | 6252 |
6233 return totalBytesPerPixel; | 6253 return totalBytesPerPixel; |
6234 } | 6254 } |
6235 | 6255 |
6236 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 6256 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
6237 { | 6257 { |
6238 return m_drawingBuffer.get(); | 6258 return m_drawingBuffer.get(); |
6239 } | 6259 } |
6240 | 6260 |
6241 } // namespace blink | 6261 } // namespace blink |
OLD | NEW |