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 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1823 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); | 1823 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); |
| 1824 return false; | 1824 return false; |
| 1825 } | 1825 } |
| 1826 return true; | 1826 return true; |
| 1827 } | 1827 } |
| 1828 | 1828 |
| 1829 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) | 1829 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) |
| 1830 { | 1830 { |
| 1831 if (isContextLost()) | 1831 if (isContextLost()) |
| 1832 return; | 1832 return; |
| 1833 if (!validateTexFuncLevel("copyTexImage2D", target, level)) | |
| 1834 return; | |
| 1833 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) | 1835 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) |
| 1834 return; | 1836 return; |
| 1835 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) | 1837 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) |
| 1836 return; | 1838 return; |
| 1837 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); | 1839 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); |
| 1838 if (!tex) | 1840 if (!tex) |
| 1839 return; | 1841 return; |
| 1840 if (tex->isImmutable()) { | 1842 if (tex->isImmutable()) { |
| 1841 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "attempted to modify immutable texture"); | 1843 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "attempted to modify immutable texture"); |
| 1842 return; | 1844 return; |
| (...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3975 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgb")) | 3977 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgb")) |
| 3976 return GL_RGB32F_EXT; | 3978 return GL_RGB32F_EXT; |
| 3977 return internalformat; | 3979 return internalformat; |
| 3978 } | 3980 } |
| 3979 | 3981 |
| 3980 void WebGLRenderingContextBase::texImage2DBase(GLenum target, GLint level, GLenu m internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GL enum type, const void* pixels) | 3982 void WebGLRenderingContextBase::texImage2DBase(GLenum target, GLint level, GLenu m internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GL enum type, const void* pixels) |
| 3981 { | 3983 { |
| 3982 // All calling functions check isContextLost, so a duplicate check is not ne eded here. | 3984 // All calling functions check isContextLost, so a duplicate check is not ne eded here. |
| 3983 // FIXME: Handle errors. | 3985 // FIXME: Handle errors. |
| 3984 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true); | 3986 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true); |
| 3987 ASSERT(validateTexFuncLevel("texImage2D", target, level)); | |
| 3985 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type)); | 3988 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type)); |
| 3986 ASSERT(tex); | 3989 ASSERT(tex); |
| 3987 ASSERT(!isNPOTStrict() || !level || !WebGLTexture::isNPOT(width, height)); | 3990 ASSERT(!isNPOTStrict() || !level || !WebGLTexture::isNPOT(width, height)); |
| 3988 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat)); | 3991 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat)); |
| 3989 webContext()->texImage2D(target, level, convertTexInternalFormat(internalfor mat, type), width, height, border, format, type, pixels); | 3992 webContext()->texImage2D(target, level, convertTexInternalFormat(internalfor mat, type), width, height, border, format, type, pixels); |
| 3990 tex->setLevelInfo(target, level, internalformat, width, height, 1, type); | 3993 tex->setLevelInfo(target, level, internalformat, width, height, 1, type); |
| 3991 } | 3994 } |
| 3992 | 3995 |
| 3993 void WebGLRenderingContextBase::texImage2DImpl(GLenum target, GLint level, GLenu m internalformat, GLenum format, GLenum type, Image* image, WebGLImageConversion ::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha) | 3996 void WebGLRenderingContextBase::texImage2DImpl(GLenum target, GLint level, GLenu m internalformat, GLenum format, GLenum type, Image* image, WebGLImageConversion ::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha) |
| 3994 { | 3997 { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 4015 | 4018 |
| 4016 if (m_unpackAlignment != 1) | 4019 if (m_unpackAlignment != 1) |
| 4017 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); | 4020 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 4018 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData); | 4021 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData); |
| 4019 if (m_unpackAlignment != 1) | 4022 if (m_unpackAlignment != 1) |
| 4020 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 4023 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 4021 } | 4024 } |
| 4022 | 4025 |
| 4023 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint bor der, GLenum format, GLenum type, GLint xoffset, GLint yoffset) | 4026 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint bor der, GLenum format, GLenum type, GLint xoffset, GLint yoffset) |
| 4024 { | 4027 { |
| 4028 if (!validateTexFuncLevel(functionName, target, level)) | |
| 4029 return false; | |
| 4025 WebGLTexture* texture = validateTextureBinding(functionName, target, true); | 4030 WebGLTexture* texture = validateTextureBinding(functionName, target, true); |
| 4026 if (!texture) | 4031 if (!texture) |
| 4027 return false; | 4032 return false; |
| 4028 | 4033 |
| 4029 if (functionType == TexSubImage2D) { | 4034 if (functionType == TexSubImage2D) { |
| 4030 if (!validateTexFuncLevel(functionName, target, level)) | |
| 4031 return false; | |
| 4032 if (!texture->isValid(target, level)) { | 4035 if (!texture->isValid(target, level)) { |
| 4033 synthesizeGLError(GL_INVALID_OPERATION, "texSubImage2D", "no previou sly defined texture image"); | 4036 synthesizeGLError(GL_INVALID_OPERATION, "texSubImage2D", "no previou sly defined texture image"); |
| 4034 return false; | 4037 return false; |
| 4035 } | 4038 } |
| 4036 } | 4039 } |
| 4037 | 4040 |
| 4038 if (internalformat == 0) | 4041 if (internalformat == 0) |
| 4039 internalformat = texture->getInternalFormat(target, level); | 4042 internalformat = texture->getInternalFormat(target, level); |
| 4040 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type)) | 4043 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type)) |
| 4041 return false; | 4044 return false; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4109 SkPaint paint; | 4112 SkPaint paint; |
| 4110 image->draw(buf->canvas(), paint, destRect, srcRect, DoNotRespectImageOrient ation, Image::DoNotClampImageToSourceRect); | 4113 image->draw(buf->canvas(), paint, destRect, srcRect, DoNotRespectImageOrient ation, Image::DoNotClampImageToSourceRect); |
| 4111 return buf->newImageSnapshot(); | 4114 return buf->newImageSnapshot(); |
| 4112 } | 4115 } |
| 4113 | 4116 |
| 4114 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, | 4117 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, |
| 4115 GLsizei width, GLsizei height, GLint border, | 4118 GLsizei width, GLsizei height, GLint border, |
| 4116 GLenum format, GLenum type, DOMArrayBufferView* pixels) | 4119 GLenum format, GLenum type, DOMArrayBufferView* pixels) |
| 4117 { | 4120 { |
| 4118 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceArrayBufferView, target, level, internalformat, width, height, border, format, type, 0, 0) | 4121 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceArrayBufferView, target, level, internalformat, width, height, border, format, type, 0, 0) |
| 4119 || !validateTexFuncData("texImage2D", level, width, height, internalform at, format, type, pixels, NullAllowed)) | 4122 || !validateTexFuncData("texImage2D", level, width, height, format, type , pixels, NullAllowed)) |
| 4120 return; | 4123 return; |
| 4121 void* data = pixels ? pixels->baseAddress() : 0; | 4124 void* data = pixels ? pixels->baseAddress() : 0; |
| 4122 Vector<uint8_t> tempData; | 4125 Vector<uint8_t> tempData; |
| 4123 bool changeUnpackAlignment = false; | 4126 bool changeUnpackAlignment = false; |
| 4124 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { | 4127 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { |
| 4125 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData)) | 4128 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData)) |
| 4126 return; | 4129 return; |
| 4127 data = tempData.data(); | 4130 data = tempData.data(); |
| 4128 changeUnpackAlignment = true; | 4131 changeUnpackAlignment = true; |
| 4129 } | 4132 } |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4384 | 4387 |
| 4385 void WebGLRenderingContextBase::texSubImage2DBase(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels) | 4388 void WebGLRenderingContextBase::texSubImage2DBase(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels) |
| 4386 { | 4389 { |
| 4387 // FIXME: Handle errors. | 4390 // FIXME: Handle errors. |
| 4388 ASSERT(!isContextLost()); | 4391 ASSERT(!isContextLost()); |
| 4389 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true); | 4392 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true); |
| 4390 if (!tex) { | 4393 if (!tex) { |
| 4391 ASSERT_NOT_REACHED(); | 4394 ASSERT_NOT_REACHED(); |
| 4392 return; | 4395 return; |
| 4393 } | 4396 } |
| 4397 ASSERT(validateTexFuncLevel("texSubImage2D", target, level)); | |
| 4394 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev el, tex->getInternalFormat(target, level), width, height, 0, format, type)); | 4398 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev el, tex->getInternalFormat(target, level), width, height, 0, format, type)); |
| 4395 ASSERT(validateSize("texSubImage2D", xoffset, yoffset)); | 4399 ASSERT(validateSize("texSubImage2D", xoffset, yoffset)); |
| 4396 ASSERT(validateSettableTexFormat("texSubImage2D", format)); | 4400 ASSERT(validateSettableTexFormat("texSubImage2D", format)); |
| 4397 ASSERT((xoffset + width) >= 0); | 4401 ASSERT((xoffset + width) >= 0); |
| 4398 ASSERT((yoffset + height) >= 0); | 4402 ASSERT((yoffset + height) >= 0); |
| 4399 ASSERT(tex->getWidth(target, level) >= (xoffset + width)); | 4403 ASSERT(tex->getWidth(target, level) >= (xoffset + width)); |
| 4400 ASSERT(tex->getHeight(target, level) >= (yoffset + height)); | 4404 ASSERT(tex->getHeight(target, level) >= (yoffset + height)); |
| 4401 ASSERT(tex->getType(target, level) == type); | 4405 ASSERT(tex->getType(target, level) == type); |
| 4402 webContext()->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); | 4406 webContext()->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); |
| 4403 } | 4407 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 4433 } | 4437 } |
| 4434 | 4438 |
| 4435 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | 4439 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 4436 GLsizei width, GLsizei height, | 4440 GLsizei width, GLsizei height, |
| 4437 GLenum format, GLenum type, DOMArrayBufferView* pixels) | 4441 GLenum format, GLenum type, DOMArrayBufferView* pixels) |
| 4438 { | 4442 { |
| 4439 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true ); | 4443 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true ); |
| 4440 if (!texture) | 4444 if (!texture) |
| 4441 return; | 4445 return; |
| 4442 | 4446 |
| 4443 GLenum internalformat = texture->getInternalFormat(target, level); | |
| 4444 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset) | 4447 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset) |
| 4445 || !validateTexFuncData("texSubImage2D", level, width, height, internalf ormat, format, type, pixels, NullNotAllowed)) | 4448 || !validateTexFuncData("texSubImage2D", level, width, height, format, t ype, pixels, NullNotAllowed)) |
| 4446 return; | 4449 return; |
| 4447 void* data = pixels->baseAddress(); | 4450 void* data = pixels->baseAddress(); |
| 4448 Vector<uint8_t> tempData; | 4451 Vector<uint8_t> tempData; |
| 4449 bool changeUnpackAlignment = false; | 4452 bool changeUnpackAlignment = false; |
| 4450 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { | 4453 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { |
| 4451 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, | 4454 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, |
| 4452 m_unpackAlignment, | 4455 m_unpackAlignment, |
| 4453 m_unpackFlipY, m_unpackPremultiplyAlp ha, | 4456 m_unpackFlipY, m_unpackPremultiplyAlp ha, |
| 4454 data, | 4457 data, |
| 4455 tempData)) | 4458 tempData)) |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5487 default: | 5490 default: |
| 5488 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); | 5491 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); |
| 5489 return false; | 5492 return false; |
| 5490 } | 5493 } |
| 5491 return true; | 5494 return true; |
| 5492 } | 5495 } |
| 5493 | 5496 |
| 5494 bool WebGLRenderingContextBase::validateTexFuncParameters(const char* functionNa me, TexImageFunctionType functionType, GLenum target, | 5497 bool WebGLRenderingContextBase::validateTexFuncParameters(const char* functionNa me, TexImageFunctionType functionType, GLenum target, |
| 5495 GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint bor der, GLenum format, GLenum type) | 5498 GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint bor der, GLenum format, GLenum type) |
| 5496 { | 5499 { |
| 5497 if (!validateTexFuncLevel(functionName, target, level)) | |
| 5498 return false; | |
| 5499 | |
| 5500 // We absolutely have to validate the format and type combination. | 5500 // We absolutely have to validate the format and type combination. |
| 5501 // The texImage2D entry points taking HTMLImage, etc. will produce | 5501 // The texImage2D entry points taking HTMLImage, etc. will produce |
| 5502 // temporary data based on this combination, so it must be legal. | 5502 // temporary data based on this combination, so it must be legal. |
| 5503 if (!validateTexFuncFormatAndType(functionName, internalformat, format, type , level)) | 5503 if (!validateTexFuncFormatAndType(functionName, internalformat, format, type , level)) |
| 5504 return false; | 5504 return false; |
| 5505 | 5505 |
| 5506 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height)) | 5506 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height)) |
| 5507 return false; | 5507 return false; |
| 5508 | 5508 |
| 5509 if (border) { | 5509 if (border) { |
| 5510 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0"); | 5510 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0"); |
| 5511 return false; | 5511 return false; |
| 5512 } | 5512 } |
| 5513 | 5513 |
| 5514 return true; | 5514 return true; |
| 5515 } | 5515 } |
| 5516 | 5516 |
| 5517 bool WebGLRenderingContextBase::validateTexFuncData(const char* functionName, GL int level, GLsizei width, GLsizei height, GLenum internalformat, GLenum format, GLenum type, DOMArrayBufferView* pixels, NullDisposition disposition) | 5517 bool WebGLRenderingContextBase::validateTexFuncData(const char* functionName, GL int level, GLsizei width, GLsizei height, GLenum format, GLenum type, DOMArrayBu fferView* pixels, NullDisposition disposition) |
|
Ken Russell (switch to Gerrit)
2015/09/01 22:52:49
It's surprising that this argument was unused. I w
qiankun
2015/09/02 09:49:07
I move formats and types validation out of validat
| |
| 5518 { | 5518 { |
| 5519 // All calling functions check isContextLost, so a duplicate check is not ne eded here. | 5519 // All calling functions check isContextLost, so a duplicate check is not ne eded here. |
| 5520 if (!pixels) { | 5520 if (!pixels) { |
| 5521 if (disposition == NullAllowed) | 5521 if (disposition == NullAllowed) |
| 5522 return true; | 5522 return true; |
| 5523 synthesizeGLError(GL_INVALID_VALUE, functionName, "no pixels"); | 5523 synthesizeGLError(GL_INVALID_VALUE, functionName, "no pixels"); |
| 5524 return false; | 5524 return false; |
| 5525 } | 5525 } |
| 5526 | 5526 |
| 5527 if (!validateSettableTexFormat(functionName, format)) | 5527 if (!validateSettableTexFormat(functionName, format)) |
| (...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6687 | 6687 |
| 6688 return totalBytesPerPixel; | 6688 return totalBytesPerPixel; |
| 6689 } | 6689 } |
| 6690 | 6690 |
| 6691 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 6691 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
| 6692 { | 6692 { |
| 6693 return m_drawingBuffer.get(); | 6693 return m_drawingBuffer.get(); |
| 6694 } | 6694 } |
| 6695 | 6695 |
| 6696 } // namespace blink | 6696 } // namespace blink |
| OLD | NEW |