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 3690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3701 | 3701 |
3702 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, | 3702 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, |
3703 GC3Denum format, GC3Denum type, ImageData
* pixels, ExceptionCode& ec) | 3703 GC3Denum format, GC3Denum type, ImageData
* pixels, ExceptionCode& ec) |
3704 { | 3704 { |
3705 ec = 0; | 3705 ec = 0; |
3706 if (isContextLost()) | 3706 if (isContextLost()) |
3707 return; | 3707 return; |
3708 Vector<uint8_t> data; | 3708 Vector<uint8_t> data; |
3709 if (!pixels) | 3709 if (!pixels) |
3710 return; | 3710 return; |
| 3711 if (!validateTexFuncFormatAndType("texImage2D", format, type, level)) |
| 3712 return; |
| 3713 if (!validateSettableTexFormat("texImage2D", format)) |
| 3714 return; |
3711 bool needConversion = true; | 3715 bool needConversion = true; |
3712 // The data from ImageData is always of format RGBA8. | 3716 // The data from ImageData is always of format RGBA8. |
3713 // No conversion is needed if destination format is RGBA and type is USIGNED
_BYTE and no Flip or Premultiply operation is required. | 3717 // No conversion is needed if destination format is RGBA and type is USIGNED
_BYTE and no Flip or Premultiply operation is required. |
3714 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GraphicsContext
3D::RGBA && type == GraphicsContext3D::UNSIGNED_BYTE) | 3718 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GraphicsContext
3D::RGBA && type == GraphicsContext3D::UNSIGNED_BYTE) |
3715 needConversion = false; | 3719 needConversion = false; |
3716 else { | 3720 else { |
3717 if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_
unpackPremultiplyAlpha, data)) { | 3721 if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_
unpackPremultiplyAlpha, data)) { |
3718 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b
ad image data"); | 3722 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b
ad image data"); |
3719 return; | 3723 return; |
3720 } | 3724 } |
(...skipping 28 matching lines...) Expand all Loading... |
3749 if (isContextLost()) | 3753 if (isContextLost()) |
3750 return; | 3754 return; |
3751 if (!canvas || !canvas->buffer()) { | 3755 if (!canvas || !canvas->buffer()) { |
3752 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "no ca
nvas"); | 3756 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "no ca
nvas"); |
3753 return; | 3757 return; |
3754 } | 3758 } |
3755 if (wouldTaintOrigin(canvas)) { | 3759 if (wouldTaintOrigin(canvas)) { |
3756 ec = SECURITY_ERR; | 3760 ec = SECURITY_ERR; |
3757 return; | 3761 return; |
3758 } | 3762 } |
| 3763 if (!validateTexFuncFormatAndType("texImage2D", format, type, level)) |
| 3764 return; |
| 3765 if (!validateSettableTexFormat("texImage2D", format)) |
| 3766 return; |
3759 | 3767 |
3760 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); | 3768 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); |
3761 // If possible, copy from the canvas element directly to the texture | 3769 // If possible, copy from the canvas element directly to the texture |
3762 // via the GPU, without a read-back to system memory. | 3770 // via the GPU, without a read-back to system memory. |
3763 // | 3771 // |
3764 // FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE should be lifted when | 3772 // FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE should be lifted when |
3765 // ImageBuffer::copyToPlatformTexture implementations are fully functional. | 3773 // ImageBuffer::copyToPlatformTexture implementations are fully functional. |
3766 if (GraphicsContext3D::TEXTURE_2D == target && texture && type == texture->g
etType(target, level) | 3774 if (GraphicsContext3D::TEXTURE_2D == target && texture && type == texture->g
etType(target, level) |
3767 && (format == GraphicsContext3D::RGB || format == GraphicsContext3D::RGB
A) && type == GraphicsContext3D::UNSIGNED_BYTE) { | 3775 && (format == GraphicsContext3D::RGB || format == GraphicsContext3D::RGB
A) && type == GraphicsContext3D::UNSIGNED_BYTE) { |
3768 ImageBuffer* buffer = canvas->buffer(); | 3776 ImageBuffer* buffer = canvas->buffer(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3890 } | 3898 } |
3891 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, for
mat, type, pixels); | 3899 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, for
mat, type, pixels); |
3892 cleanupAfterGraphicsCall(false); | 3900 cleanupAfterGraphicsCall(false); |
3893 } | 3901 } |
3894 | 3902 |
3895 void WebGLRenderingContext::texSubImage2DImpl(GC3Denum target, GC3Dint level, GC
3Dint xoffset, GC3Dint yoffset, GC3Denum format, GC3Denum type, Image* image, Gr
aphicsContext3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha
, ExceptionCode& ec) | 3903 void WebGLRenderingContext::texSubImage2DImpl(GC3Denum target, GC3Dint level, GC
3Dint xoffset, GC3Dint yoffset, GC3Denum format, GC3Denum type, Image* image, Gr
aphicsContext3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha
, ExceptionCode& ec) |
3896 { | 3904 { |
3897 ec = 0; | 3905 ec = 0; |
3898 if (isContextLost()) | 3906 if (isContextLost()) |
3899 return; | 3907 return; |
| 3908 if (!validateTexFuncFormatAndType("texSubImage2D", format, type, level)) |
| 3909 return; |
| 3910 if (!validateSettableTexFormat("texSubImage2D", format)) |
| 3911 return; |
3900 Vector<uint8_t> data; | 3912 Vector<uint8_t> data; |
3901 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip
lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE); | 3913 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip
lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE); |
3902 if (!imageExtractor.extractSucceeded()) { | 3914 if (!imageExtractor.extractSucceeded()) { |
3903 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "ba
d image"); | 3915 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "ba
d image"); |
3904 return; | 3916 return; |
3905 } | 3917 } |
3906 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF
ormat(); | 3918 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF
ormat(); |
3907 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); | 3919 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); |
3908 const void* imagePixelData = imageExtractor.imagePixelData(); | 3920 const void* imagePixelData = imageExtractor.imagePixelData(); |
3909 | 3921 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3951 } | 3963 } |
3952 | 3964 |
3953 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 3965 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
3954 GC3Denum format, GC3Denum type, ImageD
ata* pixels, ExceptionCode& ec) | 3966 GC3Denum format, GC3Denum type, ImageD
ata* pixels, ExceptionCode& ec) |
3955 { | 3967 { |
3956 ec = 0; | 3968 ec = 0; |
3957 if (isContextLost()) | 3969 if (isContextLost()) |
3958 return; | 3970 return; |
3959 if (!pixels) | 3971 if (!pixels) |
3960 return; | 3972 return; |
| 3973 if (!validateTexFuncFormatAndType("texSubImage2D", format, type, level)) |
| 3974 return; |
| 3975 if (!validateSettableTexFormat("texSubImage2D", format)) |
| 3976 return; |
3961 Vector<uint8_t> data; | 3977 Vector<uint8_t> data; |
3962 bool needConversion = true; | 3978 bool needConversion = true; |
3963 // The data from ImageData is always of format RGBA8. | 3979 // The data from ImageData is always of format RGBA8. |
3964 // No conversion is needed if destination format is RGBA and type is USIGNED
_BYTE and no Flip or Premultiply operation is required. | 3980 // No conversion is needed if destination format is RGBA and type is USIGNED
_BYTE and no Flip or Premultiply operation is required. |
3965 if (format == GraphicsContext3D::RGBA && type == GraphicsContext3D::UNSIGNED
_BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha) | 3981 if (format == GraphicsContext3D::RGBA && type == GraphicsContext3D::UNSIGNED
_BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha) |
3966 needConversion = false; | 3982 needConversion = false; |
3967 else { | 3983 else { |
3968 if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_
unpackPremultiplyAlpha, data)) { | 3984 if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_
unpackPremultiplyAlpha, data)) { |
3969 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D",
"bad image data"); | 3985 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D",
"bad image data"); |
3970 return; | 3986 return; |
(...skipping 28 matching lines...) Expand all Loading... |
3999 if (isContextLost()) | 4015 if (isContextLost()) |
4000 return; | 4016 return; |
4001 if (!canvas || !canvas->buffer()) { | 4017 if (!canvas || !canvas->buffer()) { |
4002 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "no
canvas"); | 4018 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "no
canvas"); |
4003 return; | 4019 return; |
4004 } | 4020 } |
4005 if (wouldTaintOrigin(canvas)) { | 4021 if (wouldTaintOrigin(canvas)) { |
4006 ec = SECURITY_ERR; | 4022 ec = SECURITY_ERR; |
4007 return; | 4023 return; |
4008 } | 4024 } |
| 4025 if (!validateTexFuncFormatAndType("texSubImage2D", format, type, level)) |
| 4026 return; |
| 4027 if (!validateSettableTexFormat("texSubImage2D", format)) |
| 4028 return; |
4009 RefPtr<ImageData> imageData = canvas->getImageData(); | 4029 RefPtr<ImageData> imageData = canvas->getImageData(); |
4010 if (imageData) | 4030 if (imageData) |
4011 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g
et(), ec); | 4031 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g
et(), ec); |
4012 else | 4032 else |
4013 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas-
>copiedImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremult
iplyAlpha, ec); | 4033 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas-
>copiedImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremult
iplyAlpha, ec); |
4014 } | 4034 } |
4015 | 4035 |
4016 #if ENABLE(VIDEO) | 4036 #if ENABLE(VIDEO) |
4017 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 4037 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
4018 GC3Denum format, GC3Denum type, HTMLVi
deoElement* video, ExceptionCode& ec) | 4038 GC3Denum format, GC3Denum type, HTMLVi
deoElement* video, ExceptionCode& ec) |
(...skipping 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5835 | 5855 |
5836 IntSize WebGLRenderingContext::clampedCanvasSize() | 5856 IntSize WebGLRenderingContext::clampedCanvasSize() |
5837 { | 5857 { |
5838 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), | 5858 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), |
5839 clamp(canvas()->height(), 1, m_maxViewportDims[1])); | 5859 clamp(canvas()->height(), 1, m_maxViewportDims[1])); |
5840 } | 5860 } |
5841 | 5861 |
5842 } // namespace WebCore | 5862 } // namespace WebCore |
5843 | 5863 |
5844 #endif // ENABLE(WEBGL) | 5864 #endif // ENABLE(WEBGL) |
OLD | NEW |