| 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 3582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3593 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in
ternalformat, | 3593 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in
ternalformat, |
| 3594 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) | 3594 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) |
| 3595 { | 3595 { |
| 3596 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce
ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas
Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo
rmat, type, 0, 0)) | 3596 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce
ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas
Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo
rmat, type, 0, 0)) |
| 3597 return; | 3597 return; |
| 3598 | 3598 |
| 3599 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); | 3599 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); |
| 3600 | 3600 |
| 3601 // If possible, copy from the canvas element directly to the texture | 3601 // If possible, copy from the canvas element directly to the texture |
| 3602 // via the GPU, without a read-back to system memory. | 3602 // via the GPU, without a read-back to system memory. |
| 3603 if (GL_TEXTURE_2D == target && texture) { | 3603 if (canvas->renderingContext() && GL_TEXTURE_2D == target && texture) { |
| 3604 ScopedTexture2DRestorer restorer(this); | 3604 ScopedTexture2DRestorer restorer(this); |
| 3605 | 3605 |
| 3606 if (!canvas->is3D()) { | 3606 if (!canvas->is3D()) { |
| 3607 ImageBuffer* buffer = canvas->buffer(); | 3607 ImageBuffer* buffer = canvas->buffer(); |
| 3608 if (buffer && buffer->copyToPlatformTexture(webContext(), texture->o
bject(), internalformat, type, | 3608 if (buffer && buffer->copyToPlatformTexture(webContext(), texture->o
bject(), internalformat, type, |
| 3609 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 3609 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 3610 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); | 3610 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); |
| 3611 return; | 3611 return; |
| 3612 } | 3612 } |
| 3613 } else { | 3613 } else { |
| 3614 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->
renderingContext()); | 3614 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->
renderingContext()); |
| 3615 ScopedTexture2DRestorer restorer(gl); | 3615 ScopedTexture2DRestorer restorer(gl); |
| 3616 if (gl && gl->drawingBuffer()->copyToPlatformTexture(webContext(), t
exture->object(), internalformat, type, | 3616 if (gl->drawingBuffer()->copyToPlatformTexture(webContext(), texture
->object(), internalformat, type, |
| 3617 level, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer)) { | 3617 level, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer)) { |
| 3618 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); | 3618 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); |
| 3619 return; | 3619 return; |
| 3620 } | 3620 } |
| 3621 } | 3621 } |
| 3622 } | 3622 } |
| 3623 | 3623 |
| 3624 texImage2DImpl(target, level, internalformat, format, type, canvas->copiedIm
age(BackBuffer), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPre
multiplyAlpha, exceptionState); | 3624 texImage2DImpl(target, level, internalformat, format, type, canvas->copiedIm
age(BackBuffer).get(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unp
ackPremultiplyAlpha, exceptionState); |
| 3625 } | 3625 } |
| 3626 | 3626 |
| 3627 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement*
video, BackingStoreCopy backingStoreCopy) | 3627 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement*
video, BackingStoreCopy backingStoreCopy) |
| 3628 { | 3628 { |
| 3629 IntSize size(video->videoWidth(), video->videoHeight()); | 3629 IntSize size(video->videoWidth(), video->videoHeight()); |
| 3630 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); | 3630 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); |
| 3631 if (!buf) { | 3631 if (!buf) { |
| 3632 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); | 3632 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); |
| 3633 return nullptr; | 3633 return nullptr; |
| 3634 } | 3634 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3848 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen
der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl
yAlpha, exceptionState); | 3848 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen
der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl
yAlpha, exceptionState); |
| 3849 } | 3849 } |
| 3850 | 3850 |
| 3851 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, | 3851 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, |
| 3852 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) | 3852 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) |
| 3853 { | 3853 { |
| 3854 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e
xceptionState) | 3854 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e
xceptionState) |
| 3855 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem
ent, target, level, format, canvas->width(), canvas->height(), 0, format, type,
xoffset, yoffset)) | 3855 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem
ent, target, level, format, canvas->width(), canvas->height(), 0, format, type,
xoffset, yoffset)) |
| 3856 return; | 3856 return; |
| 3857 | 3857 |
| 3858 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas->cop
iedImage(BackBuffer), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpa
ckPremultiplyAlpha, exceptionState); | 3858 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas->cop
iedImage(BackBuffer).get(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY,
m_unpackPremultiplyAlpha, exceptionState); |
| 3859 } | 3859 } |
| 3860 | 3860 |
| 3861 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, | 3861 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, |
| 3862 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) | 3862 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) |
| 3863 { | 3863 { |
| 3864 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc
eptionState) | 3864 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc
eptionState) |
| 3865 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme
nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format,
type, xoffset, yoffset)) | 3865 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme
nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format,
type, xoffset, yoffset)) |
| 3866 return; | 3866 return; |
| 3867 | 3867 |
| 3868 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod
e()); | 3868 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod
e()); |
| (...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5356 | 5356 |
| 5357 if (wouldTaintOrigin(image)) { | 5357 if (wouldTaintOrigin(image)) { |
| 5358 exceptionState.throwSecurityError("The cross-origin image at " + url.eli
dedString() + " may not be loaded."); | 5358 exceptionState.throwSecurityError("The cross-origin image at " + url.eli
dedString() + " may not be loaded."); |
| 5359 return false; | 5359 return false; |
| 5360 } | 5360 } |
| 5361 return true; | 5361 return true; |
| 5362 } | 5362 } |
| 5363 | 5363 |
| 5364 bool WebGLRenderingContextBase::validateHTMLCanvasElement(const char* functionNa
me, HTMLCanvasElement* canvas, ExceptionState& exceptionState) | 5364 bool WebGLRenderingContextBase::validateHTMLCanvasElement(const char* functionNa
me, HTMLCanvasElement* canvas, ExceptionState& exceptionState) |
| 5365 { | 5365 { |
| 5366 if (!canvas || !canvas->buffer()) { | 5366 if (!canvas || !canvas->canCreateImageBuffer()) { |
| 5367 synthesizeGLError(GL_INVALID_VALUE, functionName, "no canvas"); | 5367 synthesizeGLError(GL_INVALID_VALUE, functionName, "no canvas"); |
| 5368 return false; | 5368 return false; |
| 5369 } | 5369 } |
| 5370 if (wouldTaintOrigin(canvas)) { | 5370 if (wouldTaintOrigin(canvas)) { |
| 5371 exceptionState.throwSecurityError("Tainted canvases may not be loaded.")
; | 5371 exceptionState.throwSecurityError("Tainted canvases may not be loaded.")
; |
| 5372 return false; | 5372 return false; |
| 5373 } | 5373 } |
| 5374 return true; | 5374 return true; |
| 5375 } | 5375 } |
| 5376 | 5376 |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5863 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB
uffer() : 0; | 5863 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB
uffer() : 0; |
| 5864 } | 5864 } |
| 5865 #else | 5865 #else |
| 5866 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 5866 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
| 5867 { | 5867 { |
| 5868 return m_drawingBuffer.get(); | 5868 return m_drawingBuffer.get(); |
| 5869 } | 5869 } |
| 5870 #endif | 5870 #endif |
| 5871 | 5871 |
| 5872 } // namespace blink | 5872 } // namespace blink |
| OLD | NEW |