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 4106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4117 case TexSubImage3D: | 4117 case TexSubImage3D: |
4118 return "texSubImage3D"; | 4118 return "texSubImage3D"; |
4119 case TexImage3D: | 4119 case TexImage3D: |
4120 return "texImage3D"; | 4120 return "texImage3D"; |
4121 default: // Adding default to prevent compile error | 4121 default: // Adding default to prevent compile error |
4122 return ""; | 4122 return ""; |
4123 } | 4123 } |
4124 } | 4124 } |
4125 | 4125 |
4126 void WebGLRenderingContextBase::texImageHelperDOMArrayBufferView(TexImageFunctio
nID functionID, | 4126 void WebGLRenderingContextBase::texImageHelperDOMArrayBufferView(TexImageFunctio
nID functionID, |
4127 GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei hei
ght, GLint border, | 4127 GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei hei
ght, GLsizei depth, |
4128 GLenum format, GLenum type, GLsizei depth, GLint xoffset, GLint yoffset, GLi
nt zoffset, DOMArrayBufferView* pixels) | 4128 GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset, GLin
t zoffset, |
| 4129 DOMArrayBufferView* pixels, NullDisposition nullDisposition, GLuint srcOffse
t) |
4129 { | 4130 { |
4130 const char* funcName = getTexImageFunctionName(functionID); | 4131 const char* funcName = getTexImageFunctionName(functionID); |
4131 if (isContextLost()) | 4132 if (isContextLost()) |
4132 return; | 4133 return; |
4133 if (!validateTexImageBinding(funcName, functionID, target)) | 4134 if (!validateTexImageBinding(funcName, functionID, target)) |
4134 return; | 4135 return; |
4135 TexImageFunctionType functionType; | 4136 TexImageFunctionType functionType; |
4136 if (functionID == TexImage2D || functionID == TexImage3D) | 4137 if (functionID == TexImage2D || functionID == TexImage3D) |
4137 functionType = TexImage; | 4138 functionType = TexImage; |
4138 else | 4139 else |
4139 functionType = TexSubImage; | 4140 functionType = TexSubImage; |
4140 if (!validateTexFunc(funcName, functionType, SourceArrayBufferView, target,
level, internalformat, width, height, depth, border, format, type, xoffset, yoff
set, zoffset)) | 4141 if (!validateTexFunc(funcName, functionType, SourceArrayBufferView, target,
level, internalformat, width, height, depth, border, format, type, xoffset, yoff
set, zoffset)) |
4141 return; | 4142 return; |
4142 TexImageDimension sourceType; | 4143 TexImageDimension sourceType; |
4143 if (functionID == TexImage2D || functionID == TexSubImage2D) | 4144 if (functionID == TexImage2D || functionID == TexSubImage2D) |
4144 sourceType = Tex2D; | 4145 sourceType = Tex2D; |
4145 else | 4146 else |
4146 sourceType = Tex3D; | 4147 sourceType = Tex3D; |
4147 switch (functionID) { | 4148 if (!validateTexFuncData(funcName, sourceType, level, width, height, depth,
format, type, pixels, nullDisposition, srcOffset)) |
4148 case TexImage2D: | 4149 return; |
4149 case TexImage3D: | 4150 uint8_t* data = reinterpret_cast<uint8_t*>(pixels ? pixels->baseAddress() :
0); |
4150 if (!validateTexFuncData(funcName, sourceType, level, width, height, dep
th, format, type, pixels, NullAllowed)) | 4151 if (srcOffset) { |
4151 return; | 4152 DCHECK(pixels); |
4152 break; | 4153 // No need to check overflow because validateTexFuncData() already did. |
4153 case TexSubImage2D: | 4154 data += srcOffset * pixels->typeSize(); |
4154 case TexSubImage3D: | |
4155 if (!validateTexFuncData(funcName, sourceType, level, width, height, dep
th, format, type, pixels, NullNotAllowed)) | |
4156 return; | |
4157 } | 4155 } |
4158 void* data = pixels ? pixels->baseAddress() : 0; | |
4159 Vector<uint8_t> tempData; | 4156 Vector<uint8_t> tempData; |
4160 bool changeUnpackAlignment = false; | 4157 bool changeUnpackAlignment = false; |
4161 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { | 4158 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { |
4162 if (sourceType == Tex2D) { | 4159 if (sourceType == Tex2D) { |
4163 if (!WebGLImageConversion::extractTextureData(width, height, format,
type, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempDat
a)) | 4160 if (!WebGLImageConversion::extractTextureData(width, height, format,
type, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempDat
a)) |
4164 return; | 4161 return; |
4165 data = tempData.data(); | 4162 data = tempData.data(); |
4166 } | 4163 } |
4167 changeUnpackAlignment = true; | 4164 changeUnpackAlignment = true; |
4168 } | 4165 } |
(...skipping 14 matching lines...) Expand all Loading... |
4183 else if (functionID == TexSubImage2D) | 4180 else if (functionID == TexSubImage2D) |
4184 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, heigh
t, format, type, data); | 4181 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, heigh
t, format, type, data); |
4185 if (changeUnpackAlignment) | 4182 if (changeUnpackAlignment) |
4186 restoreUnpackParameters(); | 4183 restoreUnpackParameters(); |
4187 } | 4184 } |
4188 | 4185 |
4189 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4186 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
4190 GLsizei width, GLsizei height, GLint border, | 4187 GLsizei width, GLsizei height, GLint border, |
4191 GLenum format, GLenum type, DOMArrayBufferView* pixels) | 4188 GLenum format, GLenum type, DOMArrayBufferView* pixels) |
4192 { | 4189 { |
4193 texImageHelperDOMArrayBufferView(TexImage2D, target, level, internalformat,
width, height, border, format, type, 1, 0, 0, 0, pixels); | 4190 texImageHelperDOMArrayBufferView(TexImage2D, target, level, internalformat,
width, height, 1, border, format, type, 0, 0, 0, pixels, NullAllowed, 0); |
4194 } | 4191 } |
4195 | 4192 |
4196 void WebGLRenderingContextBase::texImageHelperImageData(TexImageFunctionID funct
ionID, | 4193 void WebGLRenderingContextBase::texImageHelperImageData(TexImageFunctionID funct
ionID, |
4197 GLenum target, GLint level, GLint internalformat, GLint border, GLenum forma
t, | 4194 GLenum target, GLint level, GLint internalformat, GLint border, GLenum forma
t, |
4198 GLenum type, GLsizei depth, GLint xoffset, GLint yoffset, GLint zoffset, Ima
geData* pixels) | 4195 GLenum type, GLsizei depth, GLint xoffset, GLint yoffset, GLint zoffset, Ima
geData* pixels) |
4199 { | 4196 { |
4200 const char* funcName = getTexImageFunctionName(functionID); | 4197 const char* funcName = getTexImageFunctionName(functionID); |
4201 if (isContextLost()) | 4198 if (isContextLost()) |
4202 return; | 4199 return; |
4203 if (!pixels) { | 4200 if (!pixels) { |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4636 | 4633 |
4637 void WebGLRenderingContextBase::texParameteri(GLenum target, GLenum pname, GLint
param) | 4634 void WebGLRenderingContextBase::texParameteri(GLenum target, GLenum pname, GLint
param) |
4638 { | 4635 { |
4639 texParameter(target, pname, 0, param, false); | 4636 texParameter(target, pname, 0, param, false); |
4640 } | 4637 } |
4641 | 4638 |
4642 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, | 4639 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, |
4643 GLsizei width, GLsizei height, | 4640 GLsizei width, GLsizei height, |
4644 GLenum format, GLenum type, DOMArrayBufferView* pixels) | 4641 GLenum format, GLenum type, DOMArrayBufferView* pixels) |
4645 { | 4642 { |
4646 texImageHelperDOMArrayBufferView(TexSubImage2D, target, level, 0, width, hei
ght, 0, format, type, 1, xoffset, yoffset, 0, pixels); | 4643 texImageHelperDOMArrayBufferView(TexSubImage2D, target, level, 0, width, hei
ght, 1, 0, format, type, xoffset, yoffset, 0, pixels, NullNotAllowed, 0); |
4647 } | 4644 } |
4648 | 4645 |
4649 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, | 4646 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, |
4650 GLenum format, GLenum type, ImageData* pixels) | 4647 GLenum format, GLenum type, ImageData* pixels) |
4651 { | 4648 { |
4652 texImageHelperImageData(TexSubImage2D, target, level, 0, 0, format, type, 1,
xoffset, yoffset, 0, pixels); | 4649 texImageHelperImageData(TexSubImage2D, target, level, 0, 0, format, type, 1,
xoffset, yoffset, 0, pixels); |
4653 } | 4650 } |
4654 | 4651 |
4655 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, | 4652 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, |
4656 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti
onState) | 4653 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti
onState) |
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5673 return false; | 5670 return false; |
5674 | 5671 |
5675 if (border) { | 5672 if (border) { |
5676 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0"); | 5673 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0"); |
5677 return false; | 5674 return false; |
5678 } | 5675 } |
5679 | 5676 |
5680 return true; | 5677 return true; |
5681 } | 5678 } |
5682 | 5679 |
5683 bool WebGLRenderingContextBase::validateTexFuncData(const char* functionName, Te
xImageDimension texDimension, GLint level, GLsizei width, GLsizei height, GLsize
i depth, GLenum format, GLenum type, DOMArrayBufferView* pixels, NullDisposition
disposition) | 5680 bool WebGLRenderingContextBase::validateTexFuncData(const char* functionName, Te
xImageDimension texDimension, GLint level, GLsizei width, GLsizei height, GLsize
i depth, GLenum format, GLenum type, DOMArrayBufferView* pixels, NullDisposition
disposition, GLuint srcOffset) |
5684 { | 5681 { |
5685 // All calling functions check isContextLost, so a duplicate check is not ne
eded here. | 5682 // All calling functions check isContextLost, so a duplicate check is not ne
eded here. |
5686 if (!pixels) { | 5683 if (!pixels) { |
| 5684 DCHECK_NE(disposition, NullNotReachable); |
5687 if (disposition == NullAllowed) | 5685 if (disposition == NullAllowed) |
5688 return true; | 5686 return true; |
5689 synthesizeGLError(GL_INVALID_VALUE, functionName, "no pixels"); | 5687 synthesizeGLError(GL_INVALID_VALUE, functionName, "no pixels"); |
5690 return false; | 5688 return false; |
5691 } | 5689 } |
5692 | 5690 |
5693 if (!validateSettableTexFormat(functionName, format)) | 5691 if (!validateSettableTexFormat(functionName, format)) |
5694 return false; | 5692 return false; |
5695 | 5693 |
5696 switch (type) { | 5694 switch (type) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5758 default: | 5756 default: |
5759 ASSERT_NOT_REACHED(); | 5757 ASSERT_NOT_REACHED(); |
5760 } | 5758 } |
5761 | 5759 |
5762 unsigned totalBytesRequired, skipBytes; | 5760 unsigned totalBytesRequired, skipBytes; |
5763 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w
idth, height, depth, getUnpackPixelStoreParams(texDimension), &totalBytesRequire
d, 0, &skipBytes); | 5761 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w
idth, height, depth, getUnpackPixelStoreParams(texDimension), &totalBytesRequire
d, 0, &skipBytes); |
5764 if (error != GL_NO_ERROR) { | 5762 if (error != GL_NO_ERROR) { |
5765 synthesizeGLError(error, functionName, "invalid texture dimensions"); | 5763 synthesizeGLError(error, functionName, "invalid texture dimensions"); |
5766 return false; | 5764 return false; |
5767 } | 5765 } |
5768 if (pixels->byteLength() < totalBytesRequired + skipBytes) { | 5766 CheckedInt<uint32_t> total = srcOffset; |
| 5767 total *= pixels->typeSize(); |
| 5768 total += totalBytesRequired; |
| 5769 total += skipBytes; |
| 5770 if (!total.isValid() || pixels->byteLength() < total.value()) { |
5769 synthesizeGLError(GL_INVALID_OPERATION, functionName, "ArrayBufferView n
ot big enough for request"); | 5771 synthesizeGLError(GL_INVALID_OPERATION, functionName, "ArrayBufferView n
ot big enough for request"); |
5770 return false; | 5772 return false; |
5771 } | 5773 } |
5772 return true; | 5774 return true; |
5773 } | 5775 } |
5774 | 5776 |
5775 bool WebGLRenderingContextBase::validateCompressedTexFormat(const char* function
Name, GLenum format) | 5777 bool WebGLRenderingContextBase::validateCompressedTexFormat(const char* function
Name, GLenum format) |
5776 { | 5778 { |
5777 if (!m_compressedTextureFormats.contains(format)) { | 5779 if (!m_compressedTextureFormats.contains(format)) { |
5778 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid format"); | 5780 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid format"); |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6491 | 6493 |
6492 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs
creenCanvas& result) const | 6494 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs
creenCanvas& result) const |
6493 { | 6495 { |
6494 if (canvas()) | 6496 if (canvas()) |
6495 result.setHTMLCanvasElement(canvas()); | 6497 result.setHTMLCanvasElement(canvas()); |
6496 else | 6498 else |
6497 result.setOffscreenCanvas(getOffscreenCanvas()); | 6499 result.setOffscreenCanvas(getOffscreenCanvas()); |
6498 } | 6500 } |
6499 | 6501 |
6500 } // namespace blink | 6502 } // namespace blink |
OLD | NEW |