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 2789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2800 } | 2800 } |
2801 | 2801 |
2802 void WebGLRenderingContext::polygonOffset(GC3Dfloat factor, GC3Dfloat units) | 2802 void WebGLRenderingContext::polygonOffset(GC3Dfloat factor, GC3Dfloat units) |
2803 { | 2803 { |
2804 if (isContextLost()) | 2804 if (isContextLost()) |
2805 return; | 2805 return; |
2806 m_context->polygonOffset(factor, units); | 2806 m_context->polygonOffset(factor, units); |
2807 cleanupAfterGraphicsCall(false); | 2807 cleanupAfterGraphicsCall(false); |
2808 } | 2808 } |
2809 | 2809 |
2810 void WebGLRenderingContext::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC
3Dsizei height, GC3Denum format, GC3Denum type, ArrayBufferView* pixels, Excepti
onCode& ec) | 2810 void WebGLRenderingContext::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC
3Dsizei height, GC3Denum format, GC3Denum type, ArrayBufferView* pixels, Excepti
onCode&) |
2811 { | 2811 { |
2812 if (isContextLost()) | 2812 if (isContextLost()) |
2813 return; | 2813 return; |
2814 if (!canvas()->originClean()) { | 2814 // Due to WebGL's same-origin restrictions, it is not possible to |
2815 ec = SECURITY_ERR; | 2815 // taint the origin using the WebGL API. |
2816 return; | 2816 ASSERT(canvas()->originClean()); |
2817 } | |
2818 // Validate input parameters. | 2817 // Validate input parameters. |
2819 if (!pixels) { | 2818 if (!pixels) { |
2820 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); | 2819 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); |
2821 return; | 2820 return; |
2822 } | 2821 } |
2823 switch (format) { | 2822 switch (format) { |
2824 case GraphicsContext3D::ALPHA: | 2823 case GraphicsContext3D::ALPHA: |
2825 case GraphicsContext3D::RGB: | 2824 case GraphicsContext3D::RGB: |
2826 case GraphicsContext3D::RGBA: | 2825 case GraphicsContext3D::RGBA: |
2827 break; | 2826 break; |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3150 } | 3149 } |
3151 | 3150 |
3152 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, | 3151 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, |
3153 GC3Denum format, GC3Denum type, HTMLImage
Element* image, ExceptionCode& ec) | 3152 GC3Denum format, GC3Denum type, HTMLImage
Element* image, ExceptionCode& ec) |
3154 { | 3153 { |
3155 ec = 0; | 3154 ec = 0; |
3156 if (isContextLost()) | 3155 if (isContextLost()) |
3157 return; | 3156 return; |
3158 if (!validateHTMLImageElement(image)) | 3157 if (!validateHTMLImageElement(image)) |
3159 return; | 3158 return; |
3160 checkOrigin(image); | 3159 if (wouldTaintOrigin(image)) { |
| 3160 ec = SECURITY_ERR; |
| 3161 return; |
| 3162 } |
| 3163 |
3161 texImage2DImpl(target, level, internalformat, format, type, image->cachedIma
ge()->image(), | 3164 texImage2DImpl(target, level, internalformat, format, type, image->cachedIma
ge()->image(), |
3162 m_unpackFlipY, m_unpackPremultiplyAlpha, ec); | 3165 m_unpackFlipY, m_unpackPremultiplyAlpha, ec); |
3163 } | 3166 } |
3164 | 3167 |
3165 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, | 3168 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, |
3166 GC3Denum format, GC3Denum type, HTMLCanva
sElement* canvas, ExceptionCode& ec) | 3169 GC3Denum format, GC3Denum type, HTMLCanva
sElement* canvas, ExceptionCode& ec) |
3167 { | 3170 { |
3168 ec = 0; | 3171 ec = 0; |
3169 if (isContextLost()) | 3172 if (isContextLost()) |
3170 return; | 3173 return; |
3171 if (!canvas || !canvas->buffer()) { | 3174 if (!canvas || !canvas->buffer()) { |
3172 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); | 3175 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); |
3173 return; | 3176 return; |
3174 } | 3177 } |
3175 checkOrigin(canvas); | 3178 if (wouldTaintOrigin(canvas)) { |
| 3179 ec = SECURITY_ERR; |
| 3180 return; |
| 3181 } |
3176 RefPtr<ImageData> imageData = canvas->getImageData(); | 3182 RefPtr<ImageData> imageData = canvas->getImageData(); |
3177 if (imageData) | 3183 if (imageData) |
3178 texImage2D(target, level, internalformat, format, type, imageData.get(),
ec); | 3184 texImage2D(target, level, internalformat, format, type, imageData.get(),
ec); |
3179 else | 3185 else |
3180 texImage2DImpl(target, level, internalformat, format, type, canvas->copi
edImage(), | 3186 texImage2DImpl(target, level, internalformat, format, type, canvas->copi
edImage(), |
3181 m_unpackFlipY, m_unpackPremultiplyAlpha, ec); | 3187 m_unpackFlipY, m_unpackPremultiplyAlpha, ec); |
3182 } | 3188 } |
3183 | 3189 |
3184 #if ENABLE(VIDEO) | 3190 #if ENABLE(VIDEO) |
3185 PassRefPtr<Image> WebGLRenderingContext::videoFrameToImage(HTMLVideoElement* vid
eo) | 3191 PassRefPtr<Image> WebGLRenderingContext::videoFrameToImage(HTMLVideoElement* vid
eo, ExceptionCode& ec) |
3186 { | 3192 { |
3187 if (!video || !video->videoWidth() || !video->videoHeight()) { | 3193 if (!video || !video->videoWidth() || !video->videoHeight()) { |
3188 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); | 3194 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); |
3189 return 0; | 3195 return 0; |
3190 } | 3196 } |
3191 IntSize size(video->videoWidth(), video->videoHeight()); | 3197 IntSize size(video->videoWidth(), video->videoHeight()); |
3192 ImageBuffer* buf = m_videoCache.imageBuffer(size); | 3198 ImageBuffer* buf = m_videoCache.imageBuffer(size); |
3193 if (!buf) { | 3199 if (!buf) { |
3194 m_context->synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY); | 3200 m_context->synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY); |
3195 return 0; | 3201 return 0; |
3196 } | 3202 } |
3197 checkOrigin(video); | 3203 if (wouldTaintOrigin(video)) { |
| 3204 ec = SECURITY_ERR; |
| 3205 return 0; |
| 3206 } |
3198 IntRect destRect(0, 0, size.width(), size.height()); | 3207 IntRect destRect(0, 0, size.width(), size.height()); |
3199 // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback. | 3208 // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback. |
3200 video->paintCurrentFrameInContext(buf->context(), destRect); | 3209 video->paintCurrentFrameInContext(buf->context(), destRect); |
3201 return buf->copyImage(); | 3210 return buf->copyImage(); |
3202 } | 3211 } |
3203 | 3212 |
3204 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, | 3213 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, |
3205 GC3Denum format, GC3Denum type, HTMLVideo
Element* video, ExceptionCode& ec) | 3214 GC3Denum format, GC3Denum type, HTMLVideo
Element* video, ExceptionCode& ec) |
3206 { | 3215 { |
3207 ec = 0; | 3216 ec = 0; |
3208 if (isContextLost()) | 3217 if (isContextLost()) |
3209 return; | 3218 return; |
3210 RefPtr<Image> image = videoFrameToImage(video); | 3219 RefPtr<Image> image = videoFrameToImage(video, ec); |
3211 if (!video) | 3220 if (!image) |
3212 return; | 3221 return; |
3213 texImage2DImpl(target, level, internalformat, format, type, image.get(), m_u
npackFlipY, m_unpackPremultiplyAlpha, ec); | 3222 texImage2DImpl(target, level, internalformat, format, type, image.get(), m_u
npackFlipY, m_unpackPremultiplyAlpha, ec); |
3214 } | 3223 } |
3215 #endif | 3224 #endif |
3216 | 3225 |
3217 void WebGLRenderingContext::texParameter(GC3Denum target, GC3Denum pname, GC3Dfl
oat paramf, GC3Dint parami, bool isFloat) | 3226 void WebGLRenderingContext::texParameter(GC3Denum target, GC3Denum pname, GC3Dfl
oat paramf, GC3Dint parami, bool isFloat) |
3218 { | 3227 { |
3219 if (isContextLost()) | 3228 if (isContextLost()) |
3220 return; | 3229 return; |
3221 WebGLTexture* tex = validateTextureBinding(target, false); | 3230 WebGLTexture* tex = validateTextureBinding(target, false); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3342 } | 3351 } |
3343 | 3352 |
3344 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 3353 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
3345 GC3Denum format, GC3Denum type, HTMLIm
ageElement* image, ExceptionCode& ec) | 3354 GC3Denum format, GC3Denum type, HTMLIm
ageElement* image, ExceptionCode& ec) |
3346 { | 3355 { |
3347 ec = 0; | 3356 ec = 0; |
3348 if (isContextLost()) | 3357 if (isContextLost()) |
3349 return; | 3358 return; |
3350 if (!validateHTMLImageElement(image)) | 3359 if (!validateHTMLImageElement(image)) |
3351 return; | 3360 return; |
3352 checkOrigin(image); | 3361 if (wouldTaintOrigin(image)) { |
| 3362 ec = SECURITY_ERR; |
| 3363 return; |
| 3364 } |
3353 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image->cach
edImage()->image(), | 3365 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image->cach
edImage()->image(), |
3354 m_unpackFlipY, m_unpackPremultiplyAlpha, ec); | 3366 m_unpackFlipY, m_unpackPremultiplyAlpha, ec); |
3355 } | 3367 } |
3356 | 3368 |
3357 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 3369 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
3358 GC3Denum format, GC3Denum type, HTMLCa
nvasElement* canvas, ExceptionCode& ec) | 3370 GC3Denum format, GC3Denum type, HTMLCa
nvasElement* canvas, ExceptionCode& ec) |
3359 { | 3371 { |
3360 ec = 0; | 3372 ec = 0; |
3361 if (isContextLost()) | 3373 if (isContextLost()) |
3362 return; | 3374 return; |
3363 if (!canvas || !canvas->buffer()) { | 3375 if (!canvas || !canvas->buffer()) { |
3364 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); | 3376 m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); |
3365 return; | 3377 return; |
3366 } | 3378 } |
3367 checkOrigin(canvas); | 3379 if (wouldTaintOrigin(canvas)) { |
| 3380 ec = SECURITY_ERR; |
| 3381 return; |
| 3382 } |
3368 RefPtr<ImageData> imageData = canvas->getImageData(); | 3383 RefPtr<ImageData> imageData = canvas->getImageData(); |
3369 if (imageData) | 3384 if (imageData) |
3370 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g
et(), ec); | 3385 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g
et(), ec); |
3371 else | 3386 else |
3372 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas-
>copiedImage(), | 3387 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas-
>copiedImage(), |
3373 m_unpackFlipY, m_unpackPremultiplyAlpha, ec); | 3388 m_unpackFlipY, m_unpackPremultiplyAlpha, ec); |
3374 } | 3389 } |
3375 | 3390 |
3376 #if ENABLE(VIDEO) | 3391 #if ENABLE(VIDEO) |
3377 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 3392 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
3378 GC3Denum format, GC3Denum type, HTMLVi
deoElement* video, ExceptionCode& ec) | 3393 GC3Denum format, GC3Denum type, HTMLVi
deoElement* video, ExceptionCode& ec) |
3379 { | 3394 { |
3380 ec = 0; | 3395 ec = 0; |
3381 if (isContextLost()) | 3396 if (isContextLost()) |
3382 return; | 3397 return; |
3383 RefPtr<Image> image = videoFrameToImage(video); | 3398 RefPtr<Image> image = videoFrameToImage(video, ec); |
3384 if (!video) | 3399 if (!image) |
3385 return; | 3400 return; |
3386 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get()
, m_unpackFlipY, m_unpackPremultiplyAlpha, ec); | 3401 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get()
, m_unpackFlipY, m_unpackPremultiplyAlpha, ec); |
3387 } | 3402 } |
3388 #endif | 3403 #endif |
3389 | 3404 |
3390 void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, GC3D
float x, ExceptionCode& ec) | 3405 void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, GC3D
float x, ExceptionCode& ec) |
3391 { | 3406 { |
3392 UNUSED_PARAM(ec); | 3407 UNUSED_PARAM(ec); |
3393 if (isContextLost() || !location) | 3408 if (isContextLost() || !location) |
3394 return; | 3409 return; |
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4829 | 4844 |
4830 void WebGLRenderingContext::LRUImageBufferCache::bubbleToFront(int idx) | 4845 void WebGLRenderingContext::LRUImageBufferCache::bubbleToFront(int idx) |
4831 { | 4846 { |
4832 for (int i = idx; i > 0; --i) | 4847 for (int i = idx; i > 0; --i) |
4833 m_buffers[i].swap(m_buffers[i-1]); | 4848 m_buffers[i].swap(m_buffers[i-1]); |
4834 } | 4849 } |
4835 | 4850 |
4836 } // namespace WebCore | 4851 } // namespace WebCore |
4837 | 4852 |
4838 #endif // ENABLE(WEBGL) | 4853 #endif // ENABLE(WEBGL) |
OLD | NEW |