Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 1543233002: Unify validation for TexImage{2D|3D} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 4188 matching lines...) Expand 10 before | Expand all | Expand 10 after
4199 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ; 4199 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ;
4200 return; 4200 return;
4201 } 4201 }
4202 } 4202 }
4203 4203
4204 resetUnpackParameters(); 4204 resetUnpackParameters();
4205 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData); 4205 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData);
4206 restoreUnpackParameters(); 4206 restoreUnpackParameters();
4207 } 4207 }
4208 4208
4209 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint bor der, GLenum format, GLenum type, GLint xoffset, GLint yoffset) 4209 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d epth, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset)
Zhenyao Mo 2015/12/28 19:30:27 It is weird that you upgrade to depth but didn't d
qiankun 2015/12/29 16:16:58 Added depth now. It will be used when validating t
4210 { 4210 {
4211 if (!validateTexFuncLevel(functionName, target, level)) 4211 if (!validateTexFuncLevel(functionName, target, level))
4212 return false; 4212 return false;
4213 WebGLTexture* texture = validateTextureBinding(functionName, target, true); 4213 WebGLTexture* texture = validateTextureBinding(functionName, target, true);
4214 if (!texture) 4214 if (!texture)
4215 return false; 4215 return false;
4216 4216
4217 if (functionType == TexSubImage2D) { 4217 if (functionType == TexSubImage2D) {
4218 if (!texture->isValid(target, level)) { 4218 if (!texture->isValid(target, level)) {
4219 synthesizeGLError(GL_INVALID_OPERATION, "texSubImage2D", "no previou sly defined texture image"); 4219 synthesizeGLError(GL_INVALID_OPERATION, "texSubImage2D", "no previou sly defined texture image");
4220 return false; 4220 return false;
4221 } 4221 }
4222 } 4222 }
4223 4223
4224 if (internalformat == 0) 4224 if (internalformat == 0)
4225 internalformat = texture->getInternalFormat(target, level); 4225 internalformat = texture->getInternalFormat(target, level);
4226 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, 1, border, format, type)) 4226 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, depth, border, format, type))
4227 return false; 4227 return false;
4228 4228
4229 if (functionType == NotTexSubImage2D) { 4229 if (functionType == NotTexSubImage2D) {
4230 if (texture->isImmutable()) { 4230 if (texture->isImmutable()) {
4231 synthesizeGLError(GL_INVALID_OPERATION, "texImage2D", "attempted to modify immutable texture"); 4231 synthesizeGLError(GL_INVALID_OPERATION, "texImage2D", "attempted to modify immutable texture");
Zhenyao Mo 2015/12/28 19:30:27 use functionName here.
qiankun 2015/12/29 16:16:58 Done.
4232 return false; 4232 return false;
4233 } 4233 }
4234 4234
4235 if (isNPOTStrict() && level && WebGLTexture::isNPOT(width, height)) { 4235 if (isNPOTStrict() && level && WebGLTexture::isNPOT(width, height)) {
Zhenyao Mo 2015/12/28 19:30:27 Worth add a comment that depth is for WebGL 2 only
qiankun 2015/12/29 16:16:58 Done.
4236 synthesizeGLError(GL_INVALID_VALUE, functionName, "level > 0 not pow er of 2"); 4236 synthesizeGLError(GL_INVALID_VALUE, functionName, "level > 0 not pow er of 2");
4237 return false; 4237 return false;
4238 } 4238 }
4239 // For SourceArrayBufferView, function validateTexFuncData() would handl e whether to validate the SettableTexFormat 4239 // For SourceArrayBufferView, function validateTexFuncData() would handl e whether to validate the SettableTexFormat
4240 // by checking if the ArrayBufferView is null or not. 4240 // by checking if the ArrayBufferView is null or not.
4241 if (sourceType != SourceArrayBufferView) { 4241 if (sourceType != SourceArrayBufferView) {
4242 if (!validateSettableTexFormat(functionName, format)) 4242 if (!validateSettableTexFormat(functionName, format))
4243 return false; 4243 return false;
4244 } 4244 }
4245 } else { 4245 } else {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4302 IntRect destRect(0, 0, size.width(), size.height()); 4302 IntRect destRect(0, 0, size.width(), size.height());
4303 SkPaint paint; 4303 SkPaint paint;
4304 image->draw(buf->canvas(), paint, destRect, srcRect, DoNotRespectImageOrient ation, Image::DoNotClampImageToSourceRect); 4304 image->draw(buf->canvas(), paint, destRect, srcRect, DoNotRespectImageOrient ation, Image::DoNotClampImageToSourceRect);
4305 return buf->newImageSnapshot(); 4305 return buf->newImageSnapshot();
4306 } 4306 }
4307 4307
4308 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4308 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4309 GLsizei width, GLsizei height, GLint border, 4309 GLsizei width, GLsizei height, GLint border,
4310 GLenum format, GLenum type, DOMArrayBufferView* pixels) 4310 GLenum format, GLenum type, DOMArrayBufferView* pixels)
4311 { 4311 {
4312 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceArrayBufferView, target, level, internalformat, width, height, border, format, type, 0, 0) 4312 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceArrayBufferView, target, level, internalformat, width, height, 1, border, form at, type, 0, 0)
4313 || !validateTexFuncData("texImage2D", level, width, height, 1, format, t ype, pixels, NullAllowed)) 4313 || !validateTexFuncData("texImage2D", level, width, height, 1, format, t ype, pixels, NullAllowed))
4314 return; 4314 return;
4315 void* data = pixels ? pixels->baseAddress() : 0; 4315 void* data = pixels ? pixels->baseAddress() : 0;
4316 Vector<uint8_t> tempData; 4316 Vector<uint8_t> tempData;
4317 bool changeUnpackAlignment = false; 4317 bool changeUnpackAlignment = false;
4318 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 4318 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
4319 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData)) 4319 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData))
4320 return; 4320 return;
4321 data = tempData.data(); 4321 data = tempData.data();
4322 changeUnpackAlignment = true; 4322 changeUnpackAlignment = true;
4323 } 4323 }
4324 if (changeUnpackAlignment) 4324 if (changeUnpackAlignment)
4325 resetUnpackParameters(); 4325 resetUnpackParameters();
4326 texImage2DBase(target, level, internalformat, width, height, border, format, type, data); 4326 texImage2DBase(target, level, internalformat, width, height, border, format, type, data);
4327 if (changeUnpackAlignment) 4327 if (changeUnpackAlignment)
4328 restoreUnpackParameters(); 4328 restoreUnpackParameters();
4329 } 4329 }
4330 4330
4331 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4331 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4332 GLenum format, GLenum type, ImageData* pixels) 4332 GLenum format, GLenum type, ImageData* pixels)
4333 { 4333 {
4334 if (!pixels) { 4334 if (!pixels) {
4335 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "no image data"); 4335 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "no image data");
4336 return; 4336 return;
4337 } 4337 }
4338 if (pixels->data()->bufferBase()->isNeutered()) { 4338 if (pixels->data()->bufferBase()->isNeutered()) {
4339 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "The source data has b een neutered."); 4339 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "The source data has b een neutered.");
4340 return; 4340 return;
4341 } 4341 }
4342 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 0 , format, type, 0, 0)) 4342 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 1 , 0, format, type, 0, 0))
4343 return; 4343 return;
4344 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4344 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4345 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4345 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4346 type = GL_FLOAT; 4346 type = GL_FLOAT;
4347 } 4347 }
4348 Vector<uint8_t> data; 4348 Vector<uint8_t> data;
4349 bool needConversion = true; 4349 bool needConversion = true;
4350 // The data from ImageData is always of format RGBA8. 4350 // The data from ImageData is always of format RGBA8.
4351 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4351 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4352 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { 4352 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
(...skipping 16 matching lines...) Expand all
4369 return; 4369 return;
4370 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4370 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4371 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4371 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4372 type = GL_FLOAT; 4372 type = GL_FLOAT;
4373 } 4373 }
4374 4374
4375 RefPtr<Image> imageForRender = image->cachedImage()->image(); 4375 RefPtr<Image> imageForRender = image->cachedImage()->image();
4376 if (imageForRender && imageForRender->isSVGImage()) 4376 if (imageForRender && imageForRender->isSVGImage())
4377 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texImage2D"); 4377 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texImage2D");
4378 4378
4379 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag eForRender->height(), 0, format, type, 0, 0)) 4379 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag eForRender->height(), 1, 0, format, type, 0, 0))
4380 return; 4380 return;
4381 4381
4382 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g et(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlph a); 4382 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g et(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlph a);
4383 } 4383 }
4384 4384
4385 bool WebGLRenderingContextBase::canUseTexImageCanvasByGPU(GLenum internalformat, GLenum type) 4385 bool WebGLRenderingContextBase::canUseTexImageCanvasByGPU(GLenum internalformat, GLenum type)
4386 { 4386 {
4387 if (isFloatType(type) || isIntegerFormat(internalformat) || isSRGBFormat(int ernalformat)) 4387 if (isFloatType(type) || isIntegerFormat(internalformat) || isSRGBFormat(int ernalformat))
4388 return false; 4388 return false;
4389 return true; 4389 return true;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4448 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); 4448 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
4449 restoreCurrentFramebuffer(); 4449 restoreCurrentFramebuffer();
4450 webContext()->deleteFramebuffer(tmpFBO); 4450 webContext()->deleteFramebuffer(tmpFBO);
4451 webContext()->deleteTexture(targetTexture); 4451 webContext()->deleteTexture(targetTexture);
4452 } 4452 }
4453 } 4453 }
4454 4454
4455 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4455 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4456 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 4456 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
4457 { 4457 {
4458 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)) 4458 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas Element, target, level, internalformat, canvas->width(), canvas->height(), 1, 0, format, type, 0, 0))
4459 return; 4459 return;
4460 4460
4461 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4461 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4462 ASSERT(texture); 4462 ASSERT(texture);
4463 4463
4464 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format. 4464 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format.
4465 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats. 4465 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats.
4466 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) { 4466 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) {
4467 // 2D canvas has only FrontBuffer. 4467 // 2D canvas has only FrontBuffer.
4468 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(), 4468 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(),
(...skipping 15 matching lines...) Expand all
4484 } 4484 }
4485 IntRect destRect(0, 0, size.width(), size.height()); 4485 IntRect destRect(0, 0, size.width(), size.height());
4486 video->paintCurrentFrame(buf->canvas(), destRect, nullptr); 4486 video->paintCurrentFrame(buf->canvas(), destRect, nullptr);
4487 return buf->newImageSnapshot(); 4487 return buf->newImageSnapshot();
4488 } 4488 }
4489 4489
4490 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4490 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4491 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4491 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4492 { 4492 {
4493 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) 4493 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState)
4494 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) 4494 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 1, 0, format, type, 0, 0))
4495 return; 4495 return;
4496 4496
4497 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 4497 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
4498 // Otherwise, it will fall back to the normal SW path. 4498 // Otherwise, it will fall back to the normal SW path.
4499 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4499 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4500 ASSERT(texture); 4500 ASSERT(texture);
4501 if (GL_TEXTURE_2D == target) { 4501 if (GL_TEXTURE_2D == target) {
4502 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level) 4502 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level)
4503 && video->copyVideoTextureToPlatformTexture(webContext(), texture->o bject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 4503 && video->copyVideoTextureToPlatformTexture(webContext(), texture->o bject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4504 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), 1, type); 4504 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), 1, type);
(...skipping 28 matching lines...) Expand all
4533 } 4533 }
4534 4534
4535 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4535 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4536 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap) 4536 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap)
4537 { 4537 {
4538 ASSERT(bitmap->bitmapImage()); 4538 ASSERT(bitmap->bitmapImage());
4539 if (bitmap->isNeutered()) { 4539 if (bitmap->isNeutered()) {
4540 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "The source data has b een neutered."); 4540 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "The source data has b een neutered.");
4541 return; 4541 return;
4542 } 4542 }
4543 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageBitmap, target, level, 0, bitmap->width(), bitmap->height(), 0, format, t ype, 0, 0)) 4543 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageBitmap, target, level, 0, bitmap->width(), bitmap->height(), 1, 0, format , type, 0, 0))
4544 return; 4544 return;
4545 StaticBitmapImage* imageForRender = bitmap->bitmapImage(); 4545 StaticBitmapImage* imageForRender = bitmap->bitmapImage();
4546 texImage2DImpl(target, level, internalformat, format, type, imageForRender, WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha); 4546 texImage2DImpl(target, level, internalformat, format, type, imageForRender, WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha);
4547 } 4547 }
4548 4548
4549 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat) 4549 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat)
4550 { 4550 {
4551 if (isContextLost()) 4551 if (isContextLost())
4552 return; 4552 return;
4553 WebGLTexture* tex = validateTextureBinding("texParameter", target, false); 4553 WebGLTexture* tex = validateTextureBinding("texParameter", target, false);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
4640 4640
4641 resetUnpackParameters(); 4641 resetUnpackParameters();
4642 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData); 4642 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData);
4643 restoreUnpackParameters(); 4643 restoreUnpackParameters();
4644 } 4644 }
4645 4645
4646 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4646 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4647 GLsizei width, GLsizei height, 4647 GLsizei width, GLsizei height,
4648 GLenum format, GLenum type, DOMArrayBufferView* pixels) 4648 GLenum format, GLenum type, DOMArrayBufferView* pixels)
4649 { 4649 {
4650 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset) 4650 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 1, 0, format, type, xoffset, yoffset)
4651 || !validateTexFuncData("texSubImage2D", level, width, height, 1, format , type, pixels, NullNotAllowed)) 4651 || !validateTexFuncData("texSubImage2D", level, width, height, 1, format , type, pixels, NullNotAllowed))
4652 return; 4652 return;
4653 void* data = pixels->baseAddress(); 4653 void* data = pixels->baseAddress();
4654 Vector<uint8_t> tempData; 4654 Vector<uint8_t> tempData;
4655 bool changeUnpackAlignment = false; 4655 bool changeUnpackAlignment = false;
4656 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 4656 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
4657 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, 4657 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e,
4658 m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, te mpData)) 4658 m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, te mpData))
4659 return; 4659 return;
4660 data = tempData.data(); 4660 data = tempData.data();
(...skipping 10 matching lines...) Expand all
4671 GLenum format, GLenum type, ImageData* pixels) 4671 GLenum format, GLenum type, ImageData* pixels)
4672 { 4672 {
4673 if (!pixels) { 4673 if (!pixels) {
4674 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data"); 4674 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data");
4675 return; 4675 return;
4676 } 4676 }
4677 if (pixels->data()->bufferBase()->isNeutered()) { 4677 if (pixels->data()->bufferBase()->isNeutered()) {
4678 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "The source data ha s been neutered."); 4678 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "The source data ha s been neutered.");
4679 return; 4679 return;
4680 } 4680 }
4681 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 0, format, ty pe, xoffset, yoffset)) 4681 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 1, 0, format, type, xoffset, yoffset))
4682 return; 4682 return;
4683 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4683 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4684 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4684 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4685 type = GL_FLOAT; 4685 type = GL_FLOAT;
4686 } 4686 }
4687 Vector<uint8_t> data; 4687 Vector<uint8_t> data;
4688 bool needConversion = true; 4688 bool needConversion = true;
4689 // The data from ImageData is always of format RGBA8. 4689 // The data from ImageData is always of format RGBA8.
4690 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4690 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4691 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) { 4691 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) {
(...skipping 17 matching lines...) Expand all
4709 4709
4710 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4710 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4711 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4711 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4712 type = GL_FLOAT; 4712 type = GL_FLOAT;
4713 } 4713 }
4714 4714
4715 RefPtr<Image> imageForRender = image->cachedImage()->image(); 4715 RefPtr<Image> imageForRender = image->cachedImage()->image();
4716 if (imageForRender && imageForRender->isSVGImage()) 4716 if (imageForRender && imageForRender->isSVGImage())
4717 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texSubImage2D"); 4717 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texSubImage2D");
4718 4718
4719 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceHTMLImageElement, target, level, 0, imageForRender->width(), imageForRender->h eight(), 0, format, type, xoffset, yoffset)) 4719 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceHTMLImageElement, target, level, 0, imageForRender->width(), imageForRender->h eight(), 1, 0, format, type, xoffset, yoffset))
4720 return; 4720 return;
4721 4721
4722 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl yAlpha); 4722 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl yAlpha);
4723 } 4723 }
4724 4724
4725 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4725 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4726 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 4726 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
4727 { 4727 {
4728 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState) 4728 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState)
4729 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 0, format, type, xoffs et, yoffset)) 4729 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 1, 0, format, type, xo ffset, yoffset))
4730 return; 4730 return;
4731 4731
4732 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true ); 4732 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true );
4733 ASSERT(texture); 4733 ASSERT(texture);
4734 4734
4735 GLenum internalformat = texture->getInternalFormat(target, level); 4735 GLenum internalformat = texture->getInternalFormat(target, level);
4736 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format. 4736 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format.
4737 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats. 4737 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats.
4738 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) { 4738 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) {
4739 // 2D canvas has only FrontBuffer. 4739 // 2D canvas has only FrontBuffer.
4740 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(), 4740 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(),
4741 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); 4741 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha);
4742 return; 4742 return;
4743 } 4743 }
4744 4744
4745 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ e, xoffset, yoffset, 0, canvas); 4745 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ e, xoffset, yoffset, 0, canvas);
4746 } 4746 }
4747 4747
4748 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4748 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4749 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4749 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4750 { 4750 {
4751 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState) 4751 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState)
4752 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, 0, video->videoWidth(), video->videoHeight(), 0, format, type , xoffset, yoffset)) 4752 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, 0, video->videoWidth(), video->videoHeight(), 1, 0, format, t ype, xoffset, yoffset))
4753 return; 4753 return;
4754 4754
4755 RefPtr<Image> image = videoFrameToImage(video); 4755 RefPtr<Image> image = videoFrameToImage(video);
4756 if (!image) 4756 if (!image)
4757 return; 4757 return;
4758 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); 4758 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha);
4759 } 4759 }
4760 4760
4761 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4761 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4762 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap) 4762 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap)
4763 { 4763 {
4764 ASSERT(bitmap->bitmapImage()); 4764 ASSERT(bitmap->bitmapImage());
4765 if (bitmap->isNeutered()) { 4765 if (bitmap->isNeutered()) {
4766 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "The source data ha s been neutered."); 4766 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "The source data ha s been neutered.");
4767 return; 4767 return;
4768 } 4768 }
4769 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageBitmap, target, level, 0, bitmap->width(), bitmap->height(), 0, format, t ype, 0, 0)) 4769 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageBitmap, target, level, 0, bitmap->width(), bitmap->height(), 1, 0, format , type, 0, 0))
4770 return; 4770 return;
4771 StaticBitmapImage* imageForRender = bitmap->bitmapImage(); 4771 StaticBitmapImage* imageForRender = bitmap->bitmapImage();
4772 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der, WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha ); 4772 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der, WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha );
4773 } 4773 }
4774 4774
4775 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) 4775 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x)
4776 { 4776 {
4777 if (isContextLost() || !location) 4777 if (isContextLost() || !location)
4778 return; 4778 return;
4779 4779
(...skipping 2277 matching lines...) Expand 10 before | Expand all | Expand 10 after
7057 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 7057 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
7058 } 7058 }
7059 7059
7060 void WebGLRenderingContextBase::restoreUnpackParameters() 7060 void WebGLRenderingContextBase::restoreUnpackParameters()
7061 { 7061 {
7062 if (m_unpackAlignment != 1) 7062 if (m_unpackAlignment != 1)
7063 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 7063 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
7064 } 7064 }
7065 7065
7066 } // namespace blink 7066 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698