| 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 3254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3265 m_context->stencilOp(fail, zfail, zpass); | 3265 m_context->stencilOp(fail, zfail, zpass); |
| 3266 } | 3266 } |
| 3267 | 3267 |
| 3268 void WebGLRenderingContext::stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3D
enum zfail, GC3Denum zpass) | 3268 void WebGLRenderingContext::stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3D
enum zfail, GC3Denum zpass) |
| 3269 { | 3269 { |
| 3270 if (isContextLost()) | 3270 if (isContextLost()) |
| 3271 return; | 3271 return; |
| 3272 m_context->stencilOpSeparate(face, fail, zfail, zpass); | 3272 m_context->stencilOpSeparate(face, fail, zfail, zpass); |
| 3273 } | 3273 } |
| 3274 | 3274 |
| 3275 void WebGLRenderingContext::texImage2DBase(GC3Denum target, GC3Dint level, GC3De
num internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum
format, GC3Denum type, const void* pixels, ExceptionState& es) | 3275 void WebGLRenderingContext::texImage2DBase(GC3Denum target, GC3Dint level, GC3De
num internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum
format, GC3Denum type, const void* pixels, ExceptionState& exceptionState) |
| 3276 { | 3276 { |
| 3277 // All calling functions check isContextLost, so a duplicate check is not ne
eded here. | 3277 // All calling functions check isContextLost, so a duplicate check is not ne
eded here. |
| 3278 // FIXME: Handle errors. | 3278 // FIXME: Handle errors. |
| 3279 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true); | 3279 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true); |
| 3280 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev
el, internalformat, width, height, border, format, type)); | 3280 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev
el, internalformat, width, height, border, format, type)); |
| 3281 ASSERT(tex); | 3281 ASSERT(tex); |
| 3282 ASSERT(!level || !WebGLTexture::isNPOT(width, height)); | 3282 ASSERT(!level || !WebGLTexture::isNPOT(width, height)); |
| 3283 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat)); | 3283 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat)); |
| 3284 m_context->texImage2D(target, level, internalformat, width, height, | 3284 m_context->texImage2D(target, level, internalformat, width, height, |
| 3285 border, format, type, pixels); | 3285 border, format, type, pixels); |
| 3286 tex->setLevelInfo(target, level, internalformat, width, height, type); | 3286 tex->setLevelInfo(target, level, internalformat, width, height, type); |
| 3287 } | 3287 } |
| 3288 | 3288 |
| 3289 void WebGLRenderingContext::texImage2DImpl(GC3Denum target, GC3Dint level, GC3De
num internalformat, GC3Denum format, GC3Denum type, Image* image, GraphicsContex
t3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, ExceptionS
tate& es) | 3289 void WebGLRenderingContext::texImage2DImpl(GC3Denum target, GC3Dint level, GC3De
num internalformat, GC3Denum format, GC3Denum type, Image* image, GraphicsContex
t3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, ExceptionS
tate& exceptionState) |
| 3290 { | 3290 { |
| 3291 // All calling functions check isContextLost, so a duplicate check is not ne
eded here. | 3291 // All calling functions check isContextLost, so a duplicate check is not ne
eded here. |
| 3292 Vector<uint8_t> data; | 3292 Vector<uint8_t> data; |
| 3293 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip
lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE); | 3293 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip
lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE); |
| 3294 if (!imageExtractor.extractSucceeded()) { | 3294 if (!imageExtractor.extractSucceeded()) { |
| 3295 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "bad i
mage data"); | 3295 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "bad i
mage data"); |
| 3296 return; | 3296 return; |
| 3297 } | 3297 } |
| 3298 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF
ormat(); | 3298 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF
ormat(); |
| 3299 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); | 3299 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); |
| 3300 const void* imagePixelData = imageExtractor.imagePixelData(); | 3300 const void* imagePixelData = imageExtractor.imagePixelData(); |
| 3301 | 3301 |
| 3302 bool needConversion = true; | 3302 bool needConversion = true; |
| 3303 if (type == GraphicsContext3D::UNSIGNED_BYTE && sourceDataFormat == Graphics
Context3D::DataFormatRGBA8 && format == GraphicsContext3D::RGBA && alphaOp == Gr
aphicsContext3D::AlphaDoNothing && !flipY) | 3303 if (type == GraphicsContext3D::UNSIGNED_BYTE && sourceDataFormat == Graphics
Context3D::DataFormatRGBA8 && format == GraphicsContext3D::RGBA && alphaOp == Gr
aphicsContext3D::AlphaDoNothing && !flipY) |
| 3304 needConversion = false; | 3304 needConversion = false; |
| 3305 else { | 3305 else { |
| 3306 if (!m_context->packImageData(image, imagePixelData, format, type, flipY
, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHe
ight(), imageExtractor.imageSourceUnpackAlignment(), data)) { | 3306 if (!m_context->packImageData(image, imagePixelData, format, type, flipY
, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHe
ight(), imageExtractor.imageSourceUnpackAlignment(), data)) { |
| 3307 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "p
ackImage error"); | 3307 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "p
ackImage error"); |
| 3308 return; | 3308 return; |
| 3309 } | 3309 } |
| 3310 } | 3310 } |
| 3311 | 3311 |
| 3312 if (m_unpackAlignment != 1) | 3312 if (m_unpackAlignment != 1) |
| 3313 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); | 3313 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); |
| 3314 texImage2DBase(target, level, internalformat, image->width(), image->height(
), 0, format, type, needConversion ? data.data() : imagePixelData, es); | 3314 texImage2DBase(target, level, internalformat, image->width(), image->height(
), 0, format, type, needConversion ? data.data() : imagePixelData, exceptionStat
e); |
| 3315 if (m_unpackAlignment != 1) | 3315 if (m_unpackAlignment != 1) |
| 3316 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); | 3316 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); |
| 3317 } | 3317 } |
| 3318 | 3318 |
| 3319 bool WebGLRenderingContext::validateTexFunc(const char* functionName, TexFuncVal
idationFunctionType functionType, TexFuncValidationSourceType sourceType, GC3Den
um target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei he
ight, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint xoffset, GC3Dint y
offset) | 3319 bool WebGLRenderingContext::validateTexFunc(const char* functionName, TexFuncVal
idationFunctionType functionType, TexFuncValidationSourceType sourceType, GC3Den
um target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei he
ight, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint xoffset, GC3Dint y
offset) |
| 3320 { | 3320 { |
| 3321 if (!validateTexFuncParameters(functionName, functionType, target, level, in
ternalformat, width, height, border, format, type)) | 3321 if (!validateTexFuncParameters(functionName, functionType, target, level, in
ternalformat, width, height, border, format, type)) |
| 3322 return false; | 3322 return false; |
| 3323 | 3323 |
| 3324 WebGLTexture* texture = validateTextureBinding(functionName, target, true); | 3324 WebGLTexture* texture = validateTextureBinding(functionName, target, true); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3370 } | 3370 } |
| 3371 | 3371 |
| 3372 IntRect srcRect(IntPoint(), image->size()); | 3372 IntRect srcRect(IntPoint(), image->size()); |
| 3373 IntRect destRect(0, 0, size.width(), size.height()); | 3373 IntRect destRect(0, 0, size.width(), size.height()); |
| 3374 buf->context()->drawImage(image, destRect, srcRect); | 3374 buf->context()->drawImage(image, destRect, srcRect); |
| 3375 return buf->copyImage(ImageBuffer::fastCopyImageMode()); | 3375 return buf->copyImage(ImageBuffer::fastCopyImageMode()); |
| 3376 } | 3376 } |
| 3377 | 3377 |
| 3378 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, | 3378 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, |
| 3379 GC3Dsizei width, GC3Dsizei height, GC3Dint border, | 3379 GC3Dsizei width, GC3Dsizei height, GC3Dint border, |
| 3380 GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionState& es) | 3380 GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionState& exc
eptionState) |
| 3381 { | 3381 { |
| 3382 if (isContextLost() || !validateTexFuncData("texImage2D", level, width, heig
ht, format, type, pixels, NullAllowed) | 3382 if (isContextLost() || !validateTexFuncData("texImage2D", level, width, heig
ht, format, type, pixels, NullAllowed) |
| 3383 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceArrayBufferVie
w, target, level, internalformat, width, height, border, format, type, 0, 0)) | 3383 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceArrayBufferVie
w, target, level, internalformat, width, height, border, format, type, 0, 0)) |
| 3384 return; | 3384 return; |
| 3385 void* data = pixels ? pixels->baseAddress() : 0; | 3385 void* data = pixels ? pixels->baseAddress() : 0; |
| 3386 Vector<uint8_t> tempData; | 3386 Vector<uint8_t> tempData; |
| 3387 bool changeUnpackAlignment = false; | 3387 bool changeUnpackAlignment = false; |
| 3388 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { | 3388 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { |
| 3389 if (!m_context->extractTextureData(width, height, format, type, | 3389 if (!m_context->extractTextureData(width, height, format, type, |
| 3390 m_unpackAlignment, | 3390 m_unpackAlignment, |
| 3391 m_unpackFlipY, m_unpackPremultiplyAlp
ha, | 3391 m_unpackFlipY, m_unpackPremultiplyAlp
ha, |
| 3392 data, | 3392 data, |
| 3393 tempData)) | 3393 tempData)) |
| 3394 return; | 3394 return; |
| 3395 data = tempData.data(); | 3395 data = tempData.data(); |
| 3396 changeUnpackAlignment = true; | 3396 changeUnpackAlignment = true; |
| 3397 } | 3397 } |
| 3398 if (changeUnpackAlignment) | 3398 if (changeUnpackAlignment) |
| 3399 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); | 3399 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); |
| 3400 texImage2DBase(target, level, internalformat, width, height, border, format,
type, data, es); | 3400 texImage2DBase(target, level, internalformat, width, height, border, format,
type, data, exceptionState); |
| 3401 if (changeUnpackAlignment) | 3401 if (changeUnpackAlignment) |
| 3402 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); | 3402 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); |
| 3403 } | 3403 } |
| 3404 | 3404 |
| 3405 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, | 3405 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, |
| 3406 GC3Denum format, GC3Denum type, ImageData* pixels, ExceptionState& es) | 3406 GC3Denum format, GC3Denum type, ImageData* pixels, ExceptionState& exception
State) |
| 3407 { | 3407 { |
| 3408 if (isContextLost() || !pixels || !validateTexFunc("texImage2D", NotTexSubIm
age2D, SourceImageData, target, level, internalformat, pixels->width(), pixels->
height(), 0, format, type, 0, 0)) | 3408 if (isContextLost() || !pixels || !validateTexFunc("texImage2D", NotTexSubIm
age2D, SourceImageData, target, level, internalformat, pixels->width(), pixels->
height(), 0, format, type, 0, 0)) |
| 3409 return; | 3409 return; |
| 3410 Vector<uint8_t> data; | 3410 Vector<uint8_t> data; |
| 3411 bool needConversion = true; | 3411 bool needConversion = true; |
| 3412 // The data from ImageData is always of format RGBA8. | 3412 // The data from ImageData is always of format RGBA8. |
| 3413 // No conversion is needed if destination format is RGBA and type is USIGNED
_BYTE and no Flip or Premultiply operation is required. | 3413 // No conversion is needed if destination format is RGBA and type is USIGNED
_BYTE and no Flip or Premultiply operation is required. |
| 3414 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GraphicsContext
3D::RGBA && type == GraphicsContext3D::UNSIGNED_BYTE) | 3414 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GraphicsContext
3D::RGBA && type == GraphicsContext3D::UNSIGNED_BYTE) |
| 3415 needConversion = false; | 3415 needConversion = false; |
| 3416 else { | 3416 else { |
| 3417 if (!m_context->extractImageData(pixels->data()->data(), pixels->size(),
format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { | 3417 if (!m_context->extractImageData(pixels->data()->data(), pixels->size(),
format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { |
| 3418 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b
ad image data"); | 3418 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b
ad image data"); |
| 3419 return; | 3419 return; |
| 3420 } | 3420 } |
| 3421 } | 3421 } |
| 3422 if (m_unpackAlignment != 1) | 3422 if (m_unpackAlignment != 1) |
| 3423 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); | 3423 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); |
| 3424 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh
t(), 0, format, type, needConversion ? data.data() : pixels->data()->data(), es)
; | 3424 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh
t(), 0, format, type, needConversion ? data.data() : pixels->data()->data(), exc
eptionState); |
| 3425 if (m_unpackAlignment != 1) | 3425 if (m_unpackAlignment != 1) |
| 3426 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); | 3426 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); |
| 3427 } | 3427 } |
| 3428 | 3428 |
| 3429 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, | 3429 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, |
| 3430 GC3Denum format, GC3Denum type, HTMLImageElement* image, ExceptionState& es) | 3430 GC3Denum format, GC3Denum type, HTMLImageElement* image, ExceptionState& exc
eptionState) |
| 3431 { | 3431 { |
| 3432 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, es)) | 3432 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, except
ionState)) |
| 3433 return; | 3433 return; |
| 3434 | 3434 |
| 3435 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image-
>renderer()); | 3435 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image-
>renderer()); |
| 3436 if (imageForRender->isSVGImage()) | 3436 if (imageForRender->isSVGImage()) |
| 3437 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width(
), image->height(), canvas()->deviceScaleFactor()); | 3437 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width(
), image->height(), canvas()->deviceScaleFactor()); |
| 3438 | 3438 |
| 3439 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour
ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag
eForRender->height(), 0, format, type, 0, 0)) | 3439 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour
ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag
eForRender->height(), 0, format, type, 0, 0)) |
| 3440 return; | 3440 return; |
| 3441 | 3441 |
| 3442 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g
et(), GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha,
es); | 3442 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g
et(), GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha,
exceptionState); |
| 3443 } | 3443 } |
| 3444 | 3444 |
| 3445 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, | 3445 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, |
| 3446 GC3Denum format, GC3Denum type, HTMLCanvasElement* canvas, ExceptionState& e
s) | 3446 GC3Denum format, GC3Denum type, HTMLCanvasElement* canvas, ExceptionState& e
xceptionState) |
| 3447 { | 3447 { |
| 3448 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, es)
|| !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvasElement, tar
get, level, internalformat, canvas->width(), canvas->height(), 0, format, type,
0, 0)) | 3448 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)) |
| 3449 return; | 3449 return; |
| 3450 | 3450 |
| 3451 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); | 3451 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); |
| 3452 // If possible, copy from the canvas element directly to the texture | 3452 // If possible, copy from the canvas element directly to the texture |
| 3453 // via the GPU, without a read-back to system memory. | 3453 // via the GPU, without a read-back to system memory. |
| 3454 if (GraphicsContext3D::TEXTURE_2D == target && texture) { | 3454 if (GraphicsContext3D::TEXTURE_2D == target && texture) { |
| 3455 if (!canvas->is3D()) { | 3455 if (!canvas->is3D()) { |
| 3456 ImageBuffer* buffer = canvas->buffer(); | 3456 ImageBuffer* buffer = canvas->buffer(); |
| 3457 if (buffer && buffer->copyToPlatformTexture(*m_context.get(), textur
e->object(), internalformat, type, | 3457 if (buffer && buffer->copyToPlatformTexture(*m_context.get(), textur
e->object(), internalformat, type, |
| 3458 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 3458 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 3459 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); | 3459 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); |
| 3460 return; | 3460 return; |
| 3461 } | 3461 } |
| 3462 } else { | 3462 } else { |
| 3463 WebGLRenderingContext* gl = static_cast<WebGLRenderingContext*>(canv
as->renderingContext()); | 3463 WebGLRenderingContext* gl = static_cast<WebGLRenderingContext*>(canv
as->renderingContext()); |
| 3464 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(*m_context.get(
), texture->object(), internalformat, type, | 3464 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(*m_context.get(
), texture->object(), internalformat, type, |
| 3465 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 3465 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 3466 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); | 3466 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); |
| 3467 return; | 3467 return; |
| 3468 } | 3468 } |
| 3469 } | 3469 } |
| 3470 } | 3470 } |
| 3471 | 3471 |
| 3472 RefPtr<ImageData> imageData = canvas->getImageData(); | 3472 RefPtr<ImageData> imageData = canvas->getImageData(); |
| 3473 if (imageData) | 3473 if (imageData) |
| 3474 texImage2D(target, level, internalformat, format, type, imageData.get(),
es); | 3474 texImage2D(target, level, internalformat, format, type, imageData.get(),
exceptionState); |
| 3475 else | 3475 else |
| 3476 texImage2DImpl(target, level, internalformat, format, type, canvas->copi
edImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultiplyA
lpha, es); | 3476 texImage2DImpl(target, level, internalformat, format, type, canvas->copi
edImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultiplyA
lpha, exceptionState); |
| 3477 } | 3477 } |
| 3478 | 3478 |
| 3479 PassRefPtr<Image> WebGLRenderingContext::videoFrameToImage(HTMLVideoElement* vid
eo, BackingStoreCopy backingStoreCopy) | 3479 PassRefPtr<Image> WebGLRenderingContext::videoFrameToImage(HTMLVideoElement* vid
eo, BackingStoreCopy backingStoreCopy) |
| 3480 { | 3480 { |
| 3481 IntSize size(video->videoWidth(), video->videoHeight()); | 3481 IntSize size(video->videoWidth(), video->videoHeight()); |
| 3482 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); | 3482 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); |
| 3483 if (!buf) { | 3483 if (!buf) { |
| 3484 synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "texImage2D", "out o
f memory"); | 3484 synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "texImage2D", "out o
f memory"); |
| 3485 return 0; | 3485 return 0; |
| 3486 } | 3486 } |
| 3487 IntRect destRect(0, 0, size.width(), size.height()); | 3487 IntRect destRect(0, 0, size.width(), size.height()); |
| 3488 // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback. | 3488 // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback. |
| 3489 video->paintCurrentFrameInContext(buf->context(), destRect); | 3489 video->paintCurrentFrameInContext(buf->context(), destRect); |
| 3490 return buf->copyImage(backingStoreCopy); | 3490 return buf->copyImage(backingStoreCopy); |
| 3491 } | 3491 } |
| 3492 | 3492 |
| 3493 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, | 3493 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum
internalformat, |
| 3494 GC3Denum format, GC3Denum type, HTMLVideoElement* video, ExceptionState& es) | 3494 GC3Denum format, GC3Denum type, HTMLVideoElement* video, ExceptionState& exc
eptionState) |
| 3495 { | 3495 { |
| 3496 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, es) | 3496 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except
ionState) |
| 3497 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme
nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0,
format, type, 0, 0)) | 3497 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme
nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0,
format, type, 0, 0)) |
| 3498 return; | 3498 return; |
| 3499 | 3499 |
| 3500 // Go through the fast path doing a GPU-GPU textures copy without a readback
to system memory if possible. | 3500 // Go through the fast path doing a GPU-GPU textures copy without a readback
to system memory if possible. |
| 3501 // Otherwise, it will fall back to the normal SW path. | 3501 // Otherwise, it will fall back to the normal SW path. |
| 3502 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); | 3502 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); |
| 3503 if (GraphicsContext3D::TEXTURE_2D == target && texture) { | 3503 if (GraphicsContext3D::TEXTURE_2D == target && texture) { |
| 3504 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o
bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY))
{ | 3504 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o
bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY))
{ |
| 3505 texture->setLevelInfo(target, level, internalformat, video->videoWid
th(), video->videoHeight(), type); | 3505 texture->setLevelInfo(target, level, internalformat, video->videoWid
th(), video->videoHeight(), type); |
| 3506 return; | 3506 return; |
| 3507 } | 3507 } |
| 3508 } | 3508 } |
| 3509 | 3509 |
| 3510 // Normal pure SW path. | 3510 // Normal pure SW path. |
| 3511 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod
e()); | 3511 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod
e()); |
| 3512 if (!image) | 3512 if (!image) |
| 3513 return; | 3513 return; |
| 3514 texImage2DImpl(target, level, internalformat, format, type, image.get(), Gra
phicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, es); | 3514 texImage2DImpl(target, level, internalformat, format, type, image.get(), Gra
phicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, exception
State); |
| 3515 } | 3515 } |
| 3516 | 3516 |
| 3517 void WebGLRenderingContext::texParameter(GC3Denum target, GC3Denum pname, GC3Dfl
oat paramf, GC3Dint parami, bool isFloat) | 3517 void WebGLRenderingContext::texParameter(GC3Denum target, GC3Denum pname, GC3Dfl
oat paramf, GC3Dint parami, bool isFloat) |
| 3518 { | 3518 { |
| 3519 if (isContextLost()) | 3519 if (isContextLost()) |
| 3520 return; | 3520 return; |
| 3521 WebGLTexture* tex = validateTextureBinding("texParameter", target, false); | 3521 WebGLTexture* tex = validateTextureBinding("texParameter", target, false); |
| 3522 if (!tex) | 3522 if (!tex) |
| 3523 return; | 3523 return; |
| 3524 switch (pname) { | 3524 switch (pname) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3555 void WebGLRenderingContext::texParameterf(GC3Denum target, GC3Denum pname, GC3Df
loat param) | 3555 void WebGLRenderingContext::texParameterf(GC3Denum target, GC3Denum pname, GC3Df
loat param) |
| 3556 { | 3556 { |
| 3557 texParameter(target, pname, param, 0, true); | 3557 texParameter(target, pname, param, 0, true); |
| 3558 } | 3558 } |
| 3559 | 3559 |
| 3560 void WebGLRenderingContext::texParameteri(GC3Denum target, GC3Denum pname, GC3Di
nt param) | 3560 void WebGLRenderingContext::texParameteri(GC3Denum target, GC3Denum pname, GC3Di
nt param) |
| 3561 { | 3561 { |
| 3562 texParameter(target, pname, 0, param, false); | 3562 texParameter(target, pname, 0, param, false); |
| 3563 } | 3563 } |
| 3564 | 3564 |
| 3565 void WebGLRenderingContext::texSubImage2DBase(GC3Denum target, GC3Dint level, GC
3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum form
at, GC3Denum type, const void* pixels, ExceptionState& es) | 3565 void WebGLRenderingContext::texSubImage2DBase(GC3Denum target, GC3Dint level, GC
3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum form
at, GC3Denum type, const void* pixels, ExceptionState& exceptionState) |
| 3566 { | 3566 { |
| 3567 // FIXME: Handle errors. | 3567 // FIXME: Handle errors. |
| 3568 ASSERT(!isContextLost()); | 3568 ASSERT(!isContextLost()); |
| 3569 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev
el, format, width, height, 0, format, type)); | 3569 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev
el, format, width, height, 0, format, type)); |
| 3570 ASSERT(validateSize("texSubImage2D", xoffset, yoffset)); | 3570 ASSERT(validateSize("texSubImage2D", xoffset, yoffset)); |
| 3571 ASSERT(validateSettableTexFormat("texSubImage2D", format)); | 3571 ASSERT(validateSettableTexFormat("texSubImage2D", format)); |
| 3572 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true); | 3572 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true); |
| 3573 if (!tex) { | 3573 if (!tex) { |
| 3574 ASSERT_NOT_REACHED(); | 3574 ASSERT_NOT_REACHED(); |
| 3575 return; | 3575 return; |
| 3576 } | 3576 } |
| 3577 ASSERT((xoffset + width) >= 0); | 3577 ASSERT((xoffset + width) >= 0); |
| 3578 ASSERT((yoffset + height) >= 0); | 3578 ASSERT((yoffset + height) >= 0); |
| 3579 ASSERT(tex->getWidth(target, level) >= (xoffset + width)); | 3579 ASSERT(tex->getWidth(target, level) >= (xoffset + width)); |
| 3580 ASSERT(tex->getHeight(target, level) >= (yoffset + height)); | 3580 ASSERT(tex->getHeight(target, level) >= (yoffset + height)); |
| 3581 ASSERT(tex->getInternalFormat(target, level) == format); | 3581 ASSERT(tex->getInternalFormat(target, level) == format); |
| 3582 ASSERT(tex->getType(target, level) == type); | 3582 ASSERT(tex->getType(target, level) == type); |
| 3583 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, for
mat, type, pixels); | 3583 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, for
mat, type, pixels); |
| 3584 } | 3584 } |
| 3585 | 3585 |
| 3586 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
, ExceptionState& es) | 3586 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
, ExceptionState& exceptionState) |
| 3587 { | 3587 { |
| 3588 // All calling functions check isContextLost, so a duplicate check is not ne
eded here. | 3588 // All calling functions check isContextLost, so a duplicate check is not ne
eded here. |
| 3589 Vector<uint8_t> data; | 3589 Vector<uint8_t> data; |
| 3590 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip
lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE); | 3590 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip
lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE); |
| 3591 if (!imageExtractor.extractSucceeded()) { | 3591 if (!imageExtractor.extractSucceeded()) { |
| 3592 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "ba
d image"); | 3592 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "ba
d image"); |
| 3593 return; | 3593 return; |
| 3594 } | 3594 } |
| 3595 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF
ormat(); | 3595 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF
ormat(); |
| 3596 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); | 3596 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); |
| 3597 const void* imagePixelData = imageExtractor.imagePixelData(); | 3597 const void* imagePixelData = imageExtractor.imagePixelData(); |
| 3598 | 3598 |
| 3599 bool needConversion = true; | 3599 bool needConversion = true; |
| 3600 if (type == GraphicsContext3D::UNSIGNED_BYTE && sourceDataFormat == Graphics
Context3D::DataFormatRGBA8 && format == GraphicsContext3D::RGBA && alphaOp == Gr
aphicsContext3D::AlphaDoNothing && !flipY) | 3600 if (type == GraphicsContext3D::UNSIGNED_BYTE && sourceDataFormat == Graphics
Context3D::DataFormatRGBA8 && format == GraphicsContext3D::RGBA && alphaOp == Gr
aphicsContext3D::AlphaDoNothing && !flipY) |
| 3601 needConversion = false; | 3601 needConversion = false; |
| 3602 else { | 3602 else { |
| 3603 if (!m_context->packImageData(image, imagePixelData, format, type, flipY
, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHe
ight(), imageExtractor.imageSourceUnpackAlignment(), data)) { | 3603 if (!m_context->packImageData(image, imagePixelData, format, type, flipY
, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHe
ight(), imageExtractor.imageSourceUnpackAlignment(), data)) { |
| 3604 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b
ad image data"); | 3604 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b
ad image data"); |
| 3605 return; | 3605 return; |
| 3606 } | 3606 } |
| 3607 } | 3607 } |
| 3608 | 3608 |
| 3609 if (m_unpackAlignment != 1) | 3609 if (m_unpackAlignment != 1) |
| 3610 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); | 3610 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); |
| 3611 texSubImage2DBase(target, level, xoffset, yoffset, image->width(), image->he
ight(), format, type, needConversion ? data.data() : imagePixelData, es); | 3611 texSubImage2DBase(target, level, xoffset, yoffset, image->width(), image->he
ight(), format, type, needConversion ? data.data() : imagePixelData, exceptionS
tate); |
| 3612 if (m_unpackAlignment != 1) | 3612 if (m_unpackAlignment != 1) |
| 3613 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); | 3613 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); |
| 3614 } | 3614 } |
| 3615 | 3615 |
| 3616 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 3616 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
| 3617 GC3Dsizei width, GC3Dsizei height, | 3617 GC3Dsizei width, GC3Dsizei height, |
| 3618 GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionState& es) | 3618 GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionState& exc
eptionState) |
| 3619 { | 3619 { |
| 3620 if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, h
eight, format, type, pixels, NullNotAllowed) | 3620 if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, h
eight, format, type, pixels, NullNotAllowed) |
| 3621 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceArrayBufferVie
w, target, level, format, width, height, 0, format, type, xoffset, yoffset)) | 3621 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceArrayBufferVie
w, target, level, format, width, height, 0, format, type, xoffset, yoffset)) |
| 3622 return; | 3622 return; |
| 3623 void* data = pixels->baseAddress(); | 3623 void* data = pixels->baseAddress(); |
| 3624 Vector<uint8_t> tempData; | 3624 Vector<uint8_t> tempData; |
| 3625 bool changeUnpackAlignment = false; | 3625 bool changeUnpackAlignment = false; |
| 3626 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { | 3626 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { |
| 3627 if (!m_context->extractTextureData(width, height, format, type, | 3627 if (!m_context->extractTextureData(width, height, format, type, |
| 3628 m_unpackAlignment, | 3628 m_unpackAlignment, |
| 3629 m_unpackFlipY, m_unpackPremultiplyAlp
ha, | 3629 m_unpackFlipY, m_unpackPremultiplyAlp
ha, |
| 3630 data, | 3630 data, |
| 3631 tempData)) | 3631 tempData)) |
| 3632 return; | 3632 return; |
| 3633 data = tempData.data(); | 3633 data = tempData.data(); |
| 3634 changeUnpackAlignment = true; | 3634 changeUnpackAlignment = true; |
| 3635 } | 3635 } |
| 3636 if (changeUnpackAlignment) | 3636 if (changeUnpackAlignment) |
| 3637 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); | 3637 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); |
| 3638 texSubImage2DBase(target, level, xoffset, yoffset, width, height, format, ty
pe, data, es); | 3638 texSubImage2DBase(target, level, xoffset, yoffset, width, height, format, ty
pe, data, exceptionState); |
| 3639 if (changeUnpackAlignment) | 3639 if (changeUnpackAlignment) |
| 3640 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); | 3640 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); |
| 3641 } | 3641 } |
| 3642 | 3642 |
| 3643 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 3643 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
| 3644 GC3Denum format, GC3Denum type, ImageData* pixels, ExceptionState& es) | 3644 GC3Denum format, GC3Denum type, ImageData* pixels, ExceptionState& exception
State) |
| 3645 { | 3645 { |
| 3646 if (isContextLost() || !pixels || !validateTexFunc("texSubImage2D", TexSubIm
age2D, SourceImageData, target, level, format, pixels->width(), pixels->height(
), 0, format, type, xoffset, yoffset)) | 3646 if (isContextLost() || !pixels || !validateTexFunc("texSubImage2D", TexSubIm
age2D, SourceImageData, target, level, format, pixels->width(), pixels->height(
), 0, format, type, xoffset, yoffset)) |
| 3647 return; | 3647 return; |
| 3648 | 3648 |
| 3649 Vector<uint8_t> data; | 3649 Vector<uint8_t> data; |
| 3650 bool needConversion = true; | 3650 bool needConversion = true; |
| 3651 // The data from ImageData is always of format RGBA8. | 3651 // The data from ImageData is always of format RGBA8. |
| 3652 // No conversion is needed if destination format is RGBA and type is USIGNED
_BYTE and no Flip or Premultiply operation is required. | 3652 // No conversion is needed if destination format is RGBA and type is USIGNED
_BYTE and no Flip or Premultiply operation is required. |
| 3653 if (format == GraphicsContext3D::RGBA && type == GraphicsContext3D::UNSIGNED
_BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha) | 3653 if (format == GraphicsContext3D::RGBA && type == GraphicsContext3D::UNSIGNED
_BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha) |
| 3654 needConversion = false; | 3654 needConversion = false; |
| 3655 else { | 3655 else { |
| 3656 if (!m_context->extractImageData(pixels->data()->data(), pixels->size(),
format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { | 3656 if (!m_context->extractImageData(pixels->data()->data(), pixels->size(),
format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { |
| 3657 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D",
"bad image data"); | 3657 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D",
"bad image data"); |
| 3658 return; | 3658 return; |
| 3659 } | 3659 } |
| 3660 } | 3660 } |
| 3661 if (m_unpackAlignment != 1) | 3661 if (m_unpackAlignment != 1) |
| 3662 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); | 3662 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); |
| 3663 texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels->
height(), format, type, needConversion ? data.data() : pixels->data()->data(), e
s); | 3663 texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels->
height(), format, type, needConversion ? data.data() : pixels->data()->data(), e
xceptionState); |
| 3664 if (m_unpackAlignment != 1) | 3664 if (m_unpackAlignment != 1) |
| 3665 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); | 3665 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig
nment); |
| 3666 } | 3666 } |
| 3667 | 3667 |
| 3668 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 3668 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
| 3669 GC3Denum format, GC3Denum type, HTMLImageElement* image, ExceptionState& es) | 3669 GC3Denum format, GC3Denum type, HTMLImageElement* image, ExceptionState& exc
eptionState) |
| 3670 { | 3670 { |
| 3671 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, es)
) | 3671 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, exc
eptionState)) |
| 3672 return; | 3672 return; |
| 3673 | 3673 |
| 3674 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image-
>renderer()); | 3674 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image-
>renderer()); |
| 3675 if (imageForRender->isSVGImage()) | 3675 if (imageForRender->isSVGImage()) |
| 3676 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width(
), image->height(), canvas()->deviceScaleFactor()); | 3676 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width(
), image->height(), canvas()->deviceScaleFactor()); |
| 3677 | 3677 |
| 3678 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour
ceHTMLImageElement, target, level, format, imageForRender->width(), imageForRend
er->height(), 0, format, type, xoffset, yoffset)) | 3678 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour
ceHTMLImageElement, target, level, format, imageForRender->width(), imageForRend
er->height(), 0, format, type, xoffset, yoffset)) |
| 3679 return; | 3679 return; |
| 3680 | 3680 |
| 3681 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen
der.get(), GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAl
pha, es); | 3681 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen
der.get(), GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAl
pha, exceptionState); |
| 3682 } | 3682 } |
| 3683 | 3683 |
| 3684 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 3684 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
| 3685 GC3Denum format, GC3Denum type, HTMLCanvasElement* canvas, ExceptionState& e
s) | 3685 GC3Denum format, GC3Denum type, HTMLCanvasElement* canvas, ExceptionState& e
xceptionState) |
| 3686 { | 3686 { |
| 3687 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e
s) | 3687 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e
xceptionState) |
| 3688 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem
ent, target, level, format, canvas->width(), canvas->height(), 0, format, type,
xoffset, yoffset)) | 3688 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem
ent, target, level, format, canvas->width(), canvas->height(), 0, format, type,
xoffset, yoffset)) |
| 3689 return; | 3689 return; |
| 3690 | 3690 |
| 3691 RefPtr<ImageData> imageData = canvas->getImageData(); | 3691 RefPtr<ImageData> imageData = canvas->getImageData(); |
| 3692 if (imageData) | 3692 if (imageData) |
| 3693 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g
et(), es); | 3693 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g
et(), exceptionState); |
| 3694 else | 3694 else |
| 3695 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas-
>copiedImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremult
iplyAlpha, es); | 3695 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas-
>copiedImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremult
iplyAlpha, exceptionState); |
| 3696 } | 3696 } |
| 3697 | 3697 |
| 3698 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, | 3698 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din
t xoffset, GC3Dint yoffset, |
| 3699 GC3Denum format, GC3Denum type, HTMLVideoElement* video, ExceptionState& es) | 3699 GC3Denum format, GC3Denum type, HTMLVideoElement* video, ExceptionState& exc
eptionState) |
| 3700 { | 3700 { |
| 3701 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, es) | 3701 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc
eptionState) |
| 3702 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme
nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format,
type, xoffset, yoffset)) | 3702 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme
nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format,
type, xoffset, yoffset)) |
| 3703 return; | 3703 return; |
| 3704 | 3704 |
| 3705 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod
e()); | 3705 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod
e()); |
| 3706 if (!image) | 3706 if (!image) |
| 3707 return; | 3707 return; |
| 3708 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get()
, GraphicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, es); | 3708 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get()
, GraphicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, exce
ptionState); |
| 3709 } | 3709 } |
| 3710 | 3710 |
| 3711 void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, GC3D
float x) | 3711 void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, GC3D
float x) |
| 3712 { | 3712 { |
| 3713 if (isContextLost() || !location) | 3713 if (isContextLost() || !location) |
| 3714 return; | 3714 return; |
| 3715 | 3715 |
| 3716 if (location->program() != m_currentProgram) { | 3716 if (location->program() != m_currentProgram) { |
| 3717 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1f", "lo
cation not for current program"); | 3717 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1f", "lo
cation not for current program"); |
| 3718 return; | 3718 return; |
| (...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5130 switch (usage) { | 5130 switch (usage) { |
| 5131 case GraphicsContext3D::STREAM_DRAW: | 5131 case GraphicsContext3D::STREAM_DRAW: |
| 5132 case GraphicsContext3D::STATIC_DRAW: | 5132 case GraphicsContext3D::STATIC_DRAW: |
| 5133 case GraphicsContext3D::DYNAMIC_DRAW: | 5133 case GraphicsContext3D::DYNAMIC_DRAW: |
| 5134 return buffer; | 5134 return buffer; |
| 5135 } | 5135 } |
| 5136 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invalid us
age"); | 5136 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invalid us
age"); |
| 5137 return 0; | 5137 return 0; |
| 5138 } | 5138 } |
| 5139 | 5139 |
| 5140 bool WebGLRenderingContext::validateHTMLImageElement(const char* functionName, H
TMLImageElement* image, ExceptionState& es) | 5140 bool WebGLRenderingContext::validateHTMLImageElement(const char* functionName, H
TMLImageElement* image, ExceptionState& exceptionState) |
| 5141 { | 5141 { |
| 5142 if (!image || !image->cachedImage()) { | 5142 if (!image || !image->cachedImage()) { |
| 5143 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no im
age"); | 5143 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no im
age"); |
| 5144 return false; | 5144 return false; |
| 5145 } | 5145 } |
| 5146 const KURL& url = image->cachedImage()->response().url(); | 5146 const KURL& url = image->cachedImage()->response().url(); |
| 5147 if (url.isNull() || url.isEmpty() || !url.isValid()) { | 5147 if (url.isNull() || url.isEmpty() || !url.isValid()) { |
| 5148 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval
id image"); | 5148 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval
id image"); |
| 5149 return false; | 5149 return false; |
| 5150 } | 5150 } |
| 5151 if (wouldTaintOrigin(image)) { | 5151 if (wouldTaintOrigin(image)) { |
| 5152 es.throwSecurityError(ExceptionMessages::failedToExecute(functionName, "
WebGLRenderingContext", "the cross-origin image at " + url.elidedString() + " ma
y not be loaded.")); | 5152 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute(fun
ctionName, "WebGLRenderingContext", "the cross-origin image at " + url.elidedStr
ing() + " may not be loaded.")); |
| 5153 return false; | 5153 return false; |
| 5154 } | 5154 } |
| 5155 return true; | 5155 return true; |
| 5156 } | 5156 } |
| 5157 | 5157 |
| 5158 bool WebGLRenderingContext::validateHTMLCanvasElement(const char* functionName,
HTMLCanvasElement* canvas, ExceptionState& es) | 5158 bool WebGLRenderingContext::validateHTMLCanvasElement(const char* functionName,
HTMLCanvasElement* canvas, ExceptionState& exceptionState) |
| 5159 { | 5159 { |
| 5160 if (!canvas || !canvas->buffer()) { | 5160 if (!canvas || !canvas->buffer()) { |
| 5161 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ca
nvas"); | 5161 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ca
nvas"); |
| 5162 return false; | 5162 return false; |
| 5163 } | 5163 } |
| 5164 if (wouldTaintOrigin(canvas)) { | 5164 if (wouldTaintOrigin(canvas)) { |
| 5165 es.throwSecurityError(ExceptionMessages::failedToExecute(functionName, "
WebGLRenderingContext", "tainted canvases may not be loded.")); | 5165 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute(fun
ctionName, "WebGLRenderingContext", "tainted canvases may not be loded.")); |
| 5166 return false; | 5166 return false; |
| 5167 } | 5167 } |
| 5168 return true; | 5168 return true; |
| 5169 } | 5169 } |
| 5170 | 5170 |
| 5171 bool WebGLRenderingContext::validateHTMLVideoElement(const char* functionName, H
TMLVideoElement* video, ExceptionState& es) | 5171 bool WebGLRenderingContext::validateHTMLVideoElement(const char* functionName, H
TMLVideoElement* video, ExceptionState& exceptionState) |
| 5172 { | 5172 { |
| 5173 if (!video || !video->videoWidth() || !video->videoHeight()) { | 5173 if (!video || !video->videoWidth() || !video->videoHeight()) { |
| 5174 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no vi
deo"); | 5174 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no vi
deo"); |
| 5175 return false; | 5175 return false; |
| 5176 } | 5176 } |
| 5177 if (wouldTaintOrigin(video)) { | 5177 if (wouldTaintOrigin(video)) { |
| 5178 es.throwSecurityError(ExceptionMessages::failedToExecute(functionName, "
WebGLRenderingContext", "the video element contains cross-origin data, and may n
ot be loaded.")); | 5178 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute(fun
ctionName, "WebGLRenderingContext", "the video element contains cross-origin dat
a, and may not be loaded.")); |
| 5179 return false; | 5179 return false; |
| 5180 } | 5180 } |
| 5181 return true; | 5181 return true; |
| 5182 } | 5182 } |
| 5183 | 5183 |
| 5184 bool WebGLRenderingContext::validateDrawArrays(const char* functionName, GC3Denu
m mode, GC3Dint first, GC3Dsizei count) | 5184 bool WebGLRenderingContext::validateDrawArrays(const char* functionName, GC3Denu
m mode, GC3Dint first, GC3Dsizei count) |
| 5185 { | 5185 { |
| 5186 if (isContextLost() || !validateDrawMode(functionName, mode)) | 5186 if (isContextLost() || !validateDrawMode(functionName, mode)) |
| 5187 return false; | 5187 return false; |
| 5188 | 5188 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5616 if (m_textureUnits[i].m_texture2DBinding | 5616 if (m_textureUnits[i].m_texture2DBinding |
| 5617 || m_textureUnits[i].m_textureCubeMapBinding) { | 5617 || m_textureUnits[i].m_textureCubeMapBinding) { |
| 5618 m_onePlusMaxNonDefaultTextureUnit = i + 1; | 5618 m_onePlusMaxNonDefaultTextureUnit = i + 1; |
| 5619 return; | 5619 return; |
| 5620 } | 5620 } |
| 5621 } | 5621 } |
| 5622 m_onePlusMaxNonDefaultTextureUnit = 0; | 5622 m_onePlusMaxNonDefaultTextureUnit = 0; |
| 5623 } | 5623 } |
| 5624 | 5624 |
| 5625 } // namespace WebCore | 5625 } // namespace WebCore |
| OLD | NEW |