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

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: fix comments#3 Created 4 years, 11 months 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
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4187 matching lines...) Expand 10 before | Expand all | Expand 10 after
4198 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ; 4198 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ;
4199 return; 4199 return;
4200 } 4200 }
4201 } 4201 }
4202 4202
4203 resetUnpackParameters(); 4203 resetUnpackParameters();
4204 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData); 4204 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData);
4205 restoreUnpackParameters(); 4205 restoreUnpackParameters();
4206 } 4206 }
4207 4207
4208 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) 4208 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, GL int zoffset)
4209 { 4209 {
4210 if (!validateTexFuncLevel(functionName, target, level)) 4210 if (!validateTexFuncLevel(functionName, target, level))
4211 return false; 4211 return false;
4212 WebGLTexture* texture = validateTextureBinding(functionName, target, true); 4212 WebGLTexture* texture = validateTextureBinding(functionName, target, true);
4213 if (!texture) 4213 if (!texture)
4214 return false; 4214 return false;
4215 4215
4216 if (functionType == TexSubImage2D) { 4216 if (functionType == TexSubImage2D) {
4217 if (!texture->isValid(target, level)) { 4217 if (!texture->isValid(target, level)) {
4218 synthesizeGLError(GL_INVALID_OPERATION, "texSubImage2D", "no previou sly defined texture image"); 4218 synthesizeGLError(GL_INVALID_OPERATION, "texSubImage2D", "no previou sly defined texture image");
4219 return false; 4219 return false;
4220 } 4220 }
4221 } 4221 }
4222 4222
4223 if (internalformat == 0) 4223 if (internalformat == 0)
4224 internalformat = texture->getInternalFormat(target, level); 4224 internalformat = texture->getInternalFormat(target, level);
4225 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, 1, border, format, type)) 4225 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, depth, border, format, type))
4226 return false; 4226 return false;
4227 4227
4228 if (functionType == NotTexSubImage2D) { 4228 if (functionType == NotTexSubImage2D) {
4229 if (texture->isImmutable()) { 4229 if (texture->isImmutable()) {
4230 synthesizeGLError(GL_INVALID_OPERATION, "texImage2D", "attempted to modify immutable texture"); 4230 synthesizeGLError(GL_INVALID_OPERATION, functionName, "attempted to modify immutable texture");
4231 return false; 4231 return false;
4232 } 4232 }
4233 4233
4234 // Depth is for WebGL 2.0 only where iSNPOTStrict() is always false.
4234 if (isNPOTStrict() && level && WebGLTexture::isNPOT(width, height)) { 4235 if (isNPOTStrict() && level && WebGLTexture::isNPOT(width, height)) {
4235 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");
4236 return false; 4237 return false;
4237 } 4238 }
4238 // 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
4239 // by checking if the ArrayBufferView is null or not. 4240 // by checking if the ArrayBufferView is null or not.
4240 if (sourceType != SourceArrayBufferView) { 4241 if (sourceType != SourceArrayBufferView) {
4241 if (!validateSettableTexFormat(functionName, format)) 4242 if (!validateSettableTexFormat(functionName, format))
4242 return false; 4243 return false;
4243 } 4244 }
4244 } else { 4245 } else {
4245 if (!validateSettableTexFormat(functionName, format)) 4246 if (!validateSettableTexFormat(functionName, format))
4246 return false; 4247 return false;
4247 if (!validateSize(functionName, xoffset, yoffset)) 4248 if (!validateSize(functionName, xoffset, yoffset, zoffset))
4248 return false; 4249 return false;
4249 // Before checking if it is in the range, check if overflow happens firs t. 4250 // Before checking if it is in the range, check if overflow happens firs t.
4250 if (xoffset + width < 0 || yoffset + height < 0) { 4251 CheckedInt<GLint> maxX = xoffset, maxY = yoffset, maxZ = zoffset;
4251 synthesizeGLError(GL_INVALID_VALUE, functionName, "bad dimensions"); 4252 maxX += width;
4252 return false; 4253 maxY += height;
4253 } 4254 maxZ += depth;
4254 if (xoffset + width > texture->getWidth(target, level) || yoffset + heig ht > texture->getHeight(target, level)) { 4255 if (!maxX.isValid() || !maxY.isValid() || !maxZ.isValid()
4256 || maxX.value() > texture->getWidth(target, level)
4257 || maxY.value() > texture->getHeight(target, level)
4258 || maxZ.value() > texture->getDepth(target, level)) {
4255 synthesizeGLError(GL_INVALID_VALUE, functionName, "dimensions out of range"); 4259 synthesizeGLError(GL_INVALID_VALUE, functionName, "dimensions out of range");
4256 return false; 4260 return false;
4257 } 4261 }
4258 if (!isWebGL2OrHigher() && texture->getType(target, level) != type) { 4262 if (!isWebGL2OrHigher() && texture->getType(target, level) != type) {
4259 synthesizeGLError(GL_INVALID_OPERATION, functionName, "type of incom ing data does not match that used to define the texture"); 4263 synthesizeGLError(GL_INVALID_OPERATION, functionName, "type of incom ing data does not match that used to define the texture");
4260 return false; 4264 return false;
4261 } 4265 }
4262 } 4266 }
4263 4267
4264 return true; 4268 return true;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4301 IntRect destRect(0, 0, size.width(), size.height()); 4305 IntRect destRect(0, 0, size.width(), size.height());
4302 SkPaint paint; 4306 SkPaint paint;
4303 image->draw(buf->canvas(), paint, destRect, srcRect, DoNotRespectImageOrient ation, Image::DoNotClampImageToSourceRect); 4307 image->draw(buf->canvas(), paint, destRect, srcRect, DoNotRespectImageOrient ation, Image::DoNotClampImageToSourceRect);
4304 return buf->newImageSnapshot(); 4308 return buf->newImageSnapshot();
4305 } 4309 }
4306 4310
4307 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4311 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4308 GLsizei width, GLsizei height, GLint border, 4312 GLsizei width, GLsizei height, GLint border,
4309 GLenum format, GLenum type, DOMArrayBufferView* pixels) 4313 GLenum format, GLenum type, DOMArrayBufferView* pixels)
4310 { 4314 {
4311 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceArrayBufferView, target, level, internalformat, width, height, border, format, type, 0, 0) 4315 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceArrayBufferView, target, level, internalformat, width, height, 1, border, form at, type, 0, 0, 0)
4312 || !validateTexFuncData("texImage2D", level, width, height, 1, format, t ype, pixels, NullAllowed)) 4316 || !validateTexFuncData("texImage2D", level, width, height, 1, format, t ype, pixels, NullAllowed))
4313 return; 4317 return;
4314 void* data = pixels ? pixels->baseAddress() : 0; 4318 void* data = pixels ? pixels->baseAddress() : 0;
4315 Vector<uint8_t> tempData; 4319 Vector<uint8_t> tempData;
4316 bool changeUnpackAlignment = false; 4320 bool changeUnpackAlignment = false;
4317 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 4321 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
4318 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData)) 4322 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData))
4319 return; 4323 return;
4320 data = tempData.data(); 4324 data = tempData.data();
4321 changeUnpackAlignment = true; 4325 changeUnpackAlignment = true;
4322 } 4326 }
4323 if (changeUnpackAlignment) 4327 if (changeUnpackAlignment)
4324 resetUnpackParameters(); 4328 resetUnpackParameters();
4325 texImage2DBase(target, level, internalformat, width, height, border, format, type, data); 4329 texImage2DBase(target, level, internalformat, width, height, border, format, type, data);
4326 if (changeUnpackAlignment) 4330 if (changeUnpackAlignment)
4327 restoreUnpackParameters(); 4331 restoreUnpackParameters();
4328 } 4332 }
4329 4333
4330 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4334 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4331 GLenum format, GLenum type, ImageData* pixels) 4335 GLenum format, GLenum type, ImageData* pixels)
4332 { 4336 {
4333 if (!pixels) { 4337 if (!pixels) {
4334 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "no image data"); 4338 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "no image data");
4335 return; 4339 return;
4336 } 4340 }
4337 if (pixels->data()->bufferBase()->isNeutered()) { 4341 if (pixels->data()->bufferBase()->isNeutered()) {
4338 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "The source data has b een neutered."); 4342 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "The source data has b een neutered.");
4339 return; 4343 return;
4340 } 4344 }
4341 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 0 , format, type, 0, 0)) 4345 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 1 , 0, format, type, 0, 0, 0))
4342 return; 4346 return;
4343 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4347 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4344 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4348 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4345 type = GL_FLOAT; 4349 type = GL_FLOAT;
4346 } 4350 }
4347 Vector<uint8_t> data; 4351 Vector<uint8_t> data;
4348 bool needConversion = true; 4352 bool needConversion = true;
4349 // The data from ImageData is always of format RGBA8. 4353 // The data from ImageData is always of format RGBA8.
4350 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4354 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4351 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { 4355 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
(...skipping 16 matching lines...) Expand all
4368 return; 4372 return;
4369 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4373 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4370 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4374 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4371 type = GL_FLOAT; 4375 type = GL_FLOAT;
4372 } 4376 }
4373 4377
4374 RefPtr<Image> imageForRender = image->cachedImage()->image(); 4378 RefPtr<Image> imageForRender = image->cachedImage()->image();
4375 if (imageForRender && imageForRender->isSVGImage()) 4379 if (imageForRender && imageForRender->isSVGImage())
4376 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texImage2D"); 4380 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texImage2D");
4377 4381
4378 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag eForRender->height(), 0, format, type, 0, 0)) 4382 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag eForRender->height(), 1, 0, format, type, 0, 0, 0))
4379 return; 4383 return;
4380 4384
4381 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g et(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlph a); 4385 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g et(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlph a);
4382 } 4386 }
4383 4387
4384 bool WebGLRenderingContextBase::canUseTexImageCanvasByGPU(GLenum internalformat, GLenum type) 4388 bool WebGLRenderingContextBase::canUseTexImageCanvasByGPU(GLenum internalformat, GLenum type)
4385 { 4389 {
4386 if (isFloatType(type) || isIntegerFormat(internalformat) || isSRGBFormat(int ernalformat)) 4390 if (isFloatType(type) || isIntegerFormat(internalformat) || isSRGBFormat(int ernalformat))
4387 return false; 4391 return false;
4388 return true; 4392 return true;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4447 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); 4451 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
4448 restoreCurrentFramebuffer(); 4452 restoreCurrentFramebuffer();
4449 webContext()->deleteFramebuffer(tmpFBO); 4453 webContext()->deleteFramebuffer(tmpFBO);
4450 webContext()->deleteTexture(targetTexture); 4454 webContext()->deleteTexture(targetTexture);
4451 } 4455 }
4452 } 4456 }
4453 4457
4454 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4458 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4455 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 4459 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
4456 { 4460 {
4457 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)) 4461 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, 0))
4458 return; 4462 return;
4459 4463
4460 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4464 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4461 ASSERT(texture); 4465 ASSERT(texture);
4462 4466
4463 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format. 4467 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format.
4464 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats. 4468 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats.
4465 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) { 4469 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) {
4466 // 2D canvas has only FrontBuffer. 4470 // 2D canvas has only FrontBuffer.
4467 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(), 4471 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(),
(...skipping 15 matching lines...) Expand all
4483 } 4487 }
4484 IntRect destRect(0, 0, size.width(), size.height()); 4488 IntRect destRect(0, 0, size.width(), size.height());
4485 video->paintCurrentFrame(buf->canvas(), destRect, nullptr); 4489 video->paintCurrentFrame(buf->canvas(), destRect, nullptr);
4486 return buf->newImageSnapshot(); 4490 return buf->newImageSnapshot();
4487 } 4491 }
4488 4492
4489 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4493 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4490 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4494 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4491 { 4495 {
4492 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) 4496 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState)
4493 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) 4497 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 1, 0, format, type, 0, 0, 0))
4494 return; 4498 return;
4495 4499
4496 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 4500 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
4497 // Otherwise, it will fall back to the normal SW path. 4501 // Otherwise, it will fall back to the normal SW path.
4498 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4502 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4499 ASSERT(texture); 4503 ASSERT(texture);
4500 if (GL_TEXTURE_2D == target) { 4504 if (GL_TEXTURE_2D == target) {
4501 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level) 4505 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level)
4502 && video->copyVideoTextureToPlatformTexture(webContext(), texture->o bject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 4506 && video->copyVideoTextureToPlatformTexture(webContext(), texture->o bject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4503 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), 1, type); 4507 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), 1, type);
(...skipping 28 matching lines...) Expand all
4532 } 4536 }
4533 4537
4534 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4538 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4535 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap) 4539 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap)
4536 { 4540 {
4537 ASSERT(bitmap->bitmapImage()); 4541 ASSERT(bitmap->bitmapImage());
4538 if (bitmap->isNeutered()) { 4542 if (bitmap->isNeutered()) {
4539 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "The source data has b een neutered."); 4543 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "The source data has b een neutered.");
4540 return; 4544 return;
4541 } 4545 }
4542 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageBitmap, target, level, 0, bitmap->width(), bitmap->height(), 0, format, t ype, 0, 0)) 4546 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageBitmap, target, level, 0, bitmap->width(), bitmap->height(), 1, 0, format , type, 0, 0, 0))
4543 return; 4547 return;
4544 StaticBitmapImage* imageForRender = bitmap->bitmapImage(); 4548 StaticBitmapImage* imageForRender = bitmap->bitmapImage();
4545 texImage2DImpl(target, level, internalformat, format, type, imageForRender, WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha); 4549 texImage2DImpl(target, level, internalformat, format, type, imageForRender, WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha);
4546 } 4550 }
4547 4551
4548 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat) 4552 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat)
4549 { 4553 {
4550 if (isContextLost()) 4554 if (isContextLost())
4551 return; 4555 return;
4552 WebGLTexture* tex = validateTextureBinding("texParameter", target, false); 4556 WebGLTexture* tex = validateTextureBinding("texParameter", target, false);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
4639 4643
4640 resetUnpackParameters(); 4644 resetUnpackParameters();
4641 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData); 4645 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData);
4642 restoreUnpackParameters(); 4646 restoreUnpackParameters();
4643 } 4647 }
4644 4648
4645 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4649 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4646 GLsizei width, GLsizei height, 4650 GLsizei width, GLsizei height,
4647 GLenum format, GLenum type, DOMArrayBufferView* pixels) 4651 GLenum format, GLenum type, DOMArrayBufferView* pixels)
4648 { 4652 {
4649 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset) 4653 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 1, 0, format, type, xoffset, yoffset, 0)
4650 || !validateTexFuncData("texSubImage2D", level, width, height, 1, format , type, pixels, NullNotAllowed)) 4654 || !validateTexFuncData("texSubImage2D", level, width, height, 1, format , type, pixels, NullNotAllowed))
4651 return; 4655 return;
4652 void* data = pixels->baseAddress(); 4656 void* data = pixels->baseAddress();
4653 Vector<uint8_t> tempData; 4657 Vector<uint8_t> tempData;
4654 bool changeUnpackAlignment = false; 4658 bool changeUnpackAlignment = false;
4655 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 4659 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
4656 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, 4660 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e,
4657 m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, te mpData)) 4661 m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, te mpData))
4658 return; 4662 return;
4659 data = tempData.data(); 4663 data = tempData.data();
(...skipping 10 matching lines...) Expand all
4670 GLenum format, GLenum type, ImageData* pixels) 4674 GLenum format, GLenum type, ImageData* pixels)
4671 { 4675 {
4672 if (!pixels) { 4676 if (!pixels) {
4673 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data"); 4677 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data");
4674 return; 4678 return;
4675 } 4679 }
4676 if (pixels->data()->bufferBase()->isNeutered()) { 4680 if (pixels->data()->bufferBase()->isNeutered()) {
4677 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "The source data ha s been neutered."); 4681 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "The source data ha s been neutered.");
4678 return; 4682 return;
4679 } 4683 }
4680 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 0, format, ty pe, xoffset, yoffset)) 4684 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 1, 0, format, type, xoffset, yoffset, 0))
4681 return; 4685 return;
4682 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4686 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4683 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4687 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4684 type = GL_FLOAT; 4688 type = GL_FLOAT;
4685 } 4689 }
4686 Vector<uint8_t> data; 4690 Vector<uint8_t> data;
4687 bool needConversion = true; 4691 bool needConversion = true;
4688 // The data from ImageData is always of format RGBA8. 4692 // The data from ImageData is always of format RGBA8.
4689 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4693 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4690 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) { 4694 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) {
(...skipping 17 matching lines...) Expand all
4708 4712
4709 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4713 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4710 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4714 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4711 type = GL_FLOAT; 4715 type = GL_FLOAT;
4712 } 4716 }
4713 4717
4714 RefPtr<Image> imageForRender = image->cachedImage()->image(); 4718 RefPtr<Image> imageForRender = image->cachedImage()->image();
4715 if (imageForRender && imageForRender->isSVGImage()) 4719 if (imageForRender && imageForRender->isSVGImage())
4716 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texSubImage2D"); 4720 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texSubImage2D");
4717 4721
4718 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceHTMLImageElement, target, level, 0, imageForRender->width(), imageForRender->h eight(), 0, format, type, xoffset, yoffset)) 4722 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceHTMLImageElement, target, level, 0, imageForRender->width(), imageForRender->h eight(), 1, 0, format, type, xoffset, yoffset, 0))
4719 return; 4723 return;
4720 4724
4721 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl yAlpha); 4725 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl yAlpha);
4722 } 4726 }
4723 4727
4724 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4728 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4725 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 4729 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
4726 { 4730 {
4727 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState) 4731 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState)
4728 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 0, format, type, xoffs et, yoffset)) 4732 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 1, 0, format, type, xo ffset, yoffset, 0))
4729 return; 4733 return;
4730 4734
4731 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true ); 4735 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true );
4732 ASSERT(texture); 4736 ASSERT(texture);
4733 4737
4734 GLenum internalformat = texture->getInternalFormat(target, level); 4738 GLenum internalformat = texture->getInternalFormat(target, level);
4735 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format. 4739 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format.
4736 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats. 4740 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats.
4737 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) { 4741 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) {
4738 // 2D canvas has only FrontBuffer. 4742 // 2D canvas has only FrontBuffer.
4739 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(), 4743 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(),
4740 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); 4744 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha);
4741 return; 4745 return;
4742 } 4746 }
4743 4747
4744 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ e, xoffset, yoffset, 0, canvas); 4748 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ e, xoffset, yoffset, 0, canvas);
4745 } 4749 }
4746 4750
4747 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4751 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4748 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4752 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4749 { 4753 {
4750 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState) 4754 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState)
4751 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, 0, video->videoWidth(), video->videoHeight(), 0, format, type , xoffset, yoffset)) 4755 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, 0, video->videoWidth(), video->videoHeight(), 1, 0, format, t ype, xoffset, yoffset, 0))
4752 return; 4756 return;
4753 4757
4754 RefPtr<Image> image = videoFrameToImage(video); 4758 RefPtr<Image> image = videoFrameToImage(video);
4755 if (!image) 4759 if (!image)
4756 return; 4760 return;
4757 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); 4761 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha);
4758 } 4762 }
4759 4763
4760 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4764 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4761 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap) 4765 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap)
4762 { 4766 {
4763 ASSERT(bitmap->bitmapImage()); 4767 ASSERT(bitmap->bitmapImage());
4764 if (bitmap->isNeutered()) { 4768 if (bitmap->isNeutered()) {
4765 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "The source data ha s been neutered."); 4769 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "The source data ha s been neutered.");
4766 return; 4770 return;
4767 } 4771 }
4768 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageBitmap, target, level, 0, bitmap->width(), bitmap->height(), 0, format, t ype, 0, 0)) 4772 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageBitmap, target, level, 0, bitmap->width(), bitmap->height(), 1, 0, format , type, 0, 0, 0))
4769 return; 4773 return;
4770 StaticBitmapImage* imageForRender = bitmap->bitmapImage(); 4774 StaticBitmapImage* imageForRender = bitmap->bitmapImage();
4771 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der, WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha ); 4775 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der, WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha );
4772 } 4776 }
4773 4777
4774 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) 4778 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x)
4775 { 4779 {
4776 if (isContextLost() || !location) 4780 if (isContextLost() || !location)
4777 return; 4781 return;
4778 4782
(...skipping 2282 matching lines...) Expand 10 before | Expand all | Expand 10 after
7061 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 7065 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
7062 } 7066 }
7063 7067
7064 void WebGLRenderingContextBase::restoreUnpackParameters() 7068 void WebGLRenderingContextBase::restoreUnpackParameters()
7065 { 7069 {
7066 if (m_unpackAlignment != 1) 7070 if (m_unpackAlignment != 1)
7067 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 7071 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
7068 } 7072 }
7069 7073
7070 } // namespace blink 7074 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698