Chromium Code Reviews| 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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 m_maxCubeMapTextureLevel = WebGLTexture::computeLevelCount(m_maxCubeMapTextu reSize, m_maxCubeMapTextureSize, 1); | 717 m_maxCubeMapTextureLevel = WebGLTexture::computeLevelCount(m_maxCubeMapTextu reSize, m_maxCubeMapTextureSize, 1); |
| 718 m_maxRenderbufferSize = 0; | 718 m_maxRenderbufferSize = 0; |
| 719 webContext()->getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_maxRenderbufferSize); | 719 webContext()->getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_maxRenderbufferSize); |
| 720 | 720 |
| 721 // These two values from EXT_draw_buffers are lazily queried. | 721 // These two values from EXT_draw_buffers are lazily queried. |
| 722 m_maxDrawBuffers = 0; | 722 m_maxDrawBuffers = 0; |
| 723 m_maxColorAttachments = 0; | 723 m_maxColorAttachments = 0; |
| 724 | 724 |
| 725 m_backDrawBuffer = GL_BACK; | 725 m_backDrawBuffer = GL_BACK; |
| 726 | 726 |
| 727 // set the default read color buffer for FBO | |
| 728 m_readbufferOfFBO = GL_COLOR_ATTACHMENT0; | |
| 729 | |
| 727 if (isWebGL2OrHigher()) { | 730 if (isWebGL2OrHigher()) { |
| 728 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLV ertexArrayObjectBase::VaoTypeDefault); | 731 m_defaultVertexArrayObject = WebGLVertexArrayObject::create(this, WebGLV ertexArrayObjectBase::VaoTypeDefault); |
| 729 } else { | 732 } else { |
| 730 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, Web GLVertexArrayObjectBase::VaoTypeDefault); | 733 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, Web GLVertexArrayObjectBase::VaoTypeDefault); |
| 731 } | 734 } |
| 732 addContextObject(m_defaultVertexArrayObject.get()); | 735 addContextObject(m_defaultVertexArrayObject.get()); |
| 733 m_boundVertexArrayObject = m_defaultVertexArrayObject; | 736 m_boundVertexArrayObject = m_defaultVertexArrayObject; |
| 734 | 737 |
| 735 m_vertexAttribValue.resize(m_maxVertexAttribs); | 738 m_vertexAttribValue.resize(m_maxVertexAttribs); |
| 736 | 739 |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1532 | 1535 |
| 1533 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format) | 1536 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format) |
| 1534 { | 1537 { |
| 1535 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers ion::ChannelDepthStencil) { | 1538 if (WebGLImageConversion::getChannelBitsByFormat(format) & WebGLImageConvers ion::ChannelDepthStencil) { |
| 1536 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); | 1539 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); |
| 1537 return false; | 1540 return false; |
| 1538 } | 1541 } |
| 1539 return true; | 1542 return true; |
| 1540 } | 1543 } |
| 1541 | 1544 |
| 1545 bool WebGLRenderingContextBase::validateReadBufferAttachment(WebGLFramebuffer* r eadFramebufferBinding) | |
| 1546 { | |
| 1547 if (readFramebufferBinding) { | |
| 1548 WebGLSharedObject* attachmentObject = readFramebufferBinding->getAttachm entObject(m_readbufferOfFBO); | |
| 1549 if (!attachmentObject) { | |
| 1550 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "no image attached to read buffer"); | |
| 1551 return false; | |
| 1552 } | |
| 1553 } | |
| 1554 return true; | |
| 1555 } | |
| 1556 | |
| 1542 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) | 1557 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) |
| 1543 { | 1558 { |
| 1544 if (isContextLost()) | 1559 if (isContextLost()) |
| 1545 return; | 1560 return; |
| 1546 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) | 1561 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) |
| 1547 return; | 1562 return; |
| 1548 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) | 1563 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) |
| 1549 return; | 1564 return; |
| 1550 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); | 1565 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); |
| 1551 if (!tex) | 1566 if (!tex) |
| 1552 return; | 1567 return; |
| 1553 if (tex->isImmutable()) { | 1568 if (tex->isImmutable()) { |
| 1554 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "attempted to modify immutable texture"); | 1569 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "attempted to modify immutable texture"); |
| 1555 return; | 1570 return; |
| 1556 } | 1571 } |
| 1557 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) { | 1572 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) { |
| 1558 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "framebuffer i s incompatible format"); | 1573 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "framebuffer i s incompatible format"); |
| 1559 return; | 1574 return; |
| 1560 } | 1575 } |
| 1561 if (isNPOTStrict() && level && WebGLTexture::isNPOT(width, height)) { | 1576 if (isNPOTStrict() && level && WebGLTexture::isNPOT(width, height)) { |
| 1562 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2"); | 1577 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2"); |
| 1563 return; | 1578 return; |
| 1564 } | 1579 } |
| 1565 const char* reason = "framebuffer incomplete"; | 1580 const char* reason = "framebuffer incomplete"; |
| 1566 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) { | 1581 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) { |
| 1567 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); | 1582 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); |
| 1568 return; | 1583 return; |
| 1569 } | 1584 } |
| 1585 if (!validateReadBufferAttachment("copyTexImage2D", readFramebufferBinding)) | |
|
Ken Russell (switch to Gerrit)
2015/06/24 00:24:38
Has this code path been tested? It looks to me lik
yunchao
2015/06/24 08:50:51
Good catch. I have updated the patch to translate
| |
| 1586 return; | |
| 1570 clearIfComposited(); | 1587 clearIfComposited(); |
| 1571 ScopedDrawingBufferBinder binder(drawingBuffer(), m_framebufferBinding.get() ); | 1588 ScopedDrawingBufferBinder binder(drawingBuffer(), m_framebufferBinding.get() ); |
| 1572 webContext()->copyTexImage2D(target, level, internalformat, x, y, width, hei ght, border); | 1589 webContext()->copyTexImage2D(target, level, internalformat, x, y, width, hei ght, border); |
| 1573 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted. | 1590 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted. |
| 1574 tex->setLevelInfo(target, level, internalformat, width, height, 1, GL_UNSIGN ED_BYTE); | 1591 tex->setLevelInfo(target, level, internalformat, width, height, 1, GL_UNSIGN ED_BYTE); |
| 1575 } | 1592 } |
| 1576 | 1593 |
| 1577 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) | 1594 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) |
| 1578 { | 1595 { |
| 1579 if (isContextLost()) | 1596 if (isContextLost()) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1603 return; | 1620 return; |
| 1604 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) { | 1621 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) { |
| 1605 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format"); | 1622 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format"); |
| 1606 return; | 1623 return; |
| 1607 } | 1624 } |
| 1608 const char* reason = "framebuffer incomplete"; | 1625 const char* reason = "framebuffer incomplete"; |
| 1609 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) { | 1626 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) { |
| 1610 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); | 1627 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); |
| 1611 return; | 1628 return; |
| 1612 } | 1629 } |
| 1630 if (!validateReadBufferAttachment("copyTexSubImage2D", readFramebufferBindin g)) | |
| 1631 return; | |
| 1613 clearIfComposited(); | 1632 clearIfComposited(); |
| 1614 ScopedDrawingBufferBinder binder(drawingBuffer(), m_framebufferBinding.get() ); | 1633 ScopedDrawingBufferBinder binder(drawingBuffer(), m_framebufferBinding.get() ); |
| 1615 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width , height); | 1634 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width , height); |
| 1616 } | 1635 } |
| 1617 | 1636 |
| 1618 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() | 1637 PassRefPtrWillBeRawPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() |
| 1619 { | 1638 { |
| 1620 if (isContextLost()) | 1639 if (isContextLost()) |
| 1621 return nullptr; | 1640 return nullptr; |
| 1622 RefPtrWillBeRawPtr<WebGLBuffer> o = WebGLBuffer::create(this); | 1641 RefPtrWillBeRawPtr<WebGLBuffer> o = WebGLBuffer::create(this); |
| (...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3336 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); | 3355 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); |
| 3337 if (error != GL_NO_ERROR) { | 3356 if (error != GL_NO_ERROR) { |
| 3338 synthesizeGLError(error, "readPixels", "invalid dimensions"); | 3357 synthesizeGLError(error, "readPixels", "invalid dimensions"); |
| 3339 return; | 3358 return; |
| 3340 } | 3359 } |
| 3341 if (pixels->byteLength() < totalBytesRequired) { | 3360 if (pixels->byteLength() < totalBytesRequired) { |
| 3342 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions"); | 3361 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions"); |
| 3343 return; | 3362 return; |
| 3344 } | 3363 } |
| 3345 | 3364 |
| 3365 if (!validateReadBufferAttachment("readPixels", readFramebufferBinding)) | |
| 3366 return; | |
| 3367 | |
| 3346 clearIfComposited(); | 3368 clearIfComposited(); |
| 3347 void* data = pixels->baseAddress(); | 3369 void* data = pixels->baseAddress(); |
| 3348 | 3370 |
| 3349 { | 3371 { |
| 3350 ScopedDrawingBufferBinder binder(drawingBuffer(), m_framebufferBinding.g et()); | 3372 ScopedDrawingBufferBinder binder(drawingBuffer(), m_framebufferBinding.g et()); |
| 3351 webContext()->readPixels(x, y, width, height, format, type, data); | 3373 webContext()->readPixels(x, y, width, height, format, type, data); |
| 3352 } | 3374 } |
| 3353 | 3375 |
| 3354 #if OS(MACOSX) | 3376 #if OS(MACOSX) |
| 3355 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e., | 3377 // 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... | |
| 6216 | 6238 |
| 6217 return totalBytesPerPixel; | 6239 return totalBytesPerPixel; |
| 6218 } | 6240 } |
| 6219 | 6241 |
| 6220 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 6242 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
| 6221 { | 6243 { |
| 6222 return m_drawingBuffer.get(); | 6244 return m_drawingBuffer.get(); |
| 6223 } | 6245 } |
| 6224 | 6246 |
| 6225 } // namespace blink | 6247 } // namespace blink |
| OLD | NEW |