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

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

Issue 1492013002: Reland of Upgrade PixelStorei to ES3/WebGL2. (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
« 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 4161 matching lines...) Expand 10 before | Expand all | Expand 10 after
4172 bool needConversion = true; 4172 bool needConversion = true;
4173 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) { 4173 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) {
4174 needConversion = false; 4174 needConversion = false;
4175 } else { 4175 } else {
4176 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 4176 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
4177 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ; 4177 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ;
4178 return; 4178 return;
4179 } 4179 }
4180 } 4180 }
4181 4181
4182 if (m_unpackAlignment != 1) 4182 resetUnpackParameters();
4183 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4184 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData); 4183 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData);
4185 if (m_unpackAlignment != 1) 4184 restoreUnpackParameters();
4186 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
4187 } 4185 }
4188 4186
4189 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) 4187 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)
4190 { 4188 {
4191 if (!validateTexFuncLevel(functionName, target, level)) 4189 if (!validateTexFuncLevel(functionName, target, level))
4192 return false; 4190 return false;
4193 WebGLTexture* texture = validateTextureBinding(functionName, target, true); 4191 WebGLTexture* texture = validateTextureBinding(functionName, target, true);
4194 if (!texture) 4192 if (!texture)
4195 return false; 4193 return false;
4196 4194
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
4295 void* data = pixels ? pixels->baseAddress() : 0; 4293 void* data = pixels ? pixels->baseAddress() : 0;
4296 Vector<uint8_t> tempData; 4294 Vector<uint8_t> tempData;
4297 bool changeUnpackAlignment = false; 4295 bool changeUnpackAlignment = false;
4298 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 4296 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
4299 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData)) 4297 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData))
4300 return; 4298 return;
4301 data = tempData.data(); 4299 data = tempData.data();
4302 changeUnpackAlignment = true; 4300 changeUnpackAlignment = true;
4303 } 4301 }
4304 if (changeUnpackAlignment) 4302 if (changeUnpackAlignment)
4305 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4303 resetUnpackParameters();
4306 texImage2DBase(target, level, internalformat, width, height, border, format, type, data); 4304 texImage2DBase(target, level, internalformat, width, height, border, format, type, data);
4307 if (changeUnpackAlignment) 4305 if (changeUnpackAlignment)
4308 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4306 restoreUnpackParameters();
4309 } 4307 }
4310 4308
4311 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4309 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4312 GLenum format, GLenum type, ImageData* pixels) 4310 GLenum format, GLenum type, ImageData* pixels)
4313 { 4311 {
4314 if (!pixels) { 4312 if (!pixels) {
4315 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "no image data"); 4313 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "no image data");
4316 return; 4314 return;
4317 } 4315 }
4318 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 0 , format, type, 0, 0)) 4316 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 0 , format, type, 0, 0))
4319 return; 4317 return;
4320 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4318 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4321 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4319 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4322 type = GL_FLOAT; 4320 type = GL_FLOAT;
4323 } 4321 }
4324 Vector<uint8_t> data; 4322 Vector<uint8_t> data;
4325 bool needConversion = true; 4323 bool needConversion = true;
4326 // The data from ImageData is always of format RGBA8. 4324 // The data from ImageData is always of format RGBA8.
4327 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4325 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4328 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { 4326 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
4329 needConversion = false; 4327 needConversion = false;
4330 } else { 4328 } else {
4331 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 4329 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
4332 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 4330 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
4333 return; 4331 return;
4334 } 4332 }
4335 } 4333 }
4336 if (m_unpackAlignment != 1) 4334 resetUnpackParameters();
4337 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4338 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data()); 4335 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data());
4339 if (m_unpackAlignment != 1) 4336 restoreUnpackParameters();
4340 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
4341 } 4337 }
4342 4338
4343 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4339 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4344 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) 4340 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState)
4345 { 4341 {
4346 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, except ionState)) 4342 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, except ionState))
4347 return; 4343 return;
4348 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4344 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4349 // 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.
4350 type = GL_FLOAT; 4346 type = GL_FLOAT;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
4595 bool needConversion = true; 4591 bool needConversion = true;
4596 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) { 4592 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) {
4597 needConversion = false; 4593 needConversion = false;
4598 } else { 4594 } else {
4599 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 4595 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
4600 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 4596 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
4601 return; 4597 return;
4602 } 4598 }
4603 } 4599 }
4604 4600
4605 if (m_unpackAlignment != 1) 4601 resetUnpackParameters();
4606 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4607 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData); 4602 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData);
4608 if (m_unpackAlignment != 1) 4603 restoreUnpackParameters();
4609 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
4610 } 4604 }
4611 4605
4612 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4606 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4613 GLsizei width, GLsizei height, 4607 GLsizei width, GLsizei height,
4614 GLenum format, GLenum type, DOMArrayBufferView* pixels) 4608 GLenum format, GLenum type, DOMArrayBufferView* pixels)
4615 { 4609 {
4616 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset) 4610 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset)
4617 || !validateTexFuncData("texSubImage2D", level, width, height, 1, format , type, pixels, NullNotAllowed)) 4611 || !validateTexFuncData("texSubImage2D", level, width, height, 1, format , type, pixels, NullNotAllowed))
4618 return; 4612 return;
4619 void* data = pixels->baseAddress(); 4613 void* data = pixels->baseAddress();
4620 Vector<uint8_t> tempData; 4614 Vector<uint8_t> tempData;
4621 bool changeUnpackAlignment = false; 4615 bool changeUnpackAlignment = false;
4622 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 4616 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
4623 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, 4617 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e,
4624 m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, te mpData)) 4618 m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, te mpData))
4625 return; 4619 return;
4626 data = tempData.data(); 4620 data = tempData.data();
4627 changeUnpackAlignment = true; 4621 changeUnpackAlignment = true;
4628 } 4622 }
4629 if (changeUnpackAlignment) 4623 if (changeUnpackAlignment)
4630 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4624 resetUnpackParameters();
4631 webContext()->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data); 4625 webContext()->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data);
4632 if (changeUnpackAlignment) 4626 if (changeUnpackAlignment)
4633 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4627 restoreUnpackParameters();
4634 } 4628 }
4635 4629
4636 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4630 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4637 GLenum format, GLenum type, ImageData* pixels) 4631 GLenum format, GLenum type, ImageData* pixels)
4638 { 4632 {
4639 if (!pixels) { 4633 if (!pixels) {
4640 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data"); 4634 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data");
4641 return; 4635 return;
4642 } 4636 }
4643 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 0, format, ty pe, xoffset, yoffset)) 4637 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 0, format, ty pe, xoffset, yoffset))
4644 return; 4638 return;
4645 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4639 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4646 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4640 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4647 type = GL_FLOAT; 4641 type = GL_FLOAT;
4648 } 4642 }
4649 Vector<uint8_t> data; 4643 Vector<uint8_t> data;
4650 bool needConversion = true; 4644 bool needConversion = true;
4651 // The data from ImageData is always of format RGBA8. 4645 // The data from ImageData is always of format RGBA8.
4652 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4646 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4653 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) { 4647 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) {
4654 needConversion = false; 4648 needConversion = false;
4655 } else { 4649 } else {
4656 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 4650 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
4657 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 4651 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
4658 return; 4652 return;
4659 } 4653 }
4660 } 4654 }
4661 if (m_unpackAlignment != 1) 4655 resetUnpackParameters();
4662 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4663 webContext()->texSubImage2D(target, level, xoffset, yoffset, pixels->width() , pixels->height(), format, type, needConversion ? data.data() : pixels->data()- >data()); 4656 webContext()->texSubImage2D(target, level, xoffset, yoffset, pixels->width() , pixels->height(), format, type, needConversion ? data.data() : pixels->data()- >data());
4664 if (m_unpackAlignment != 1) 4657 restoreUnpackParameters();
4665 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
4666 } 4658 }
4667 4659
4668 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4660 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4669 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) 4661 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState)
4670 { 4662 {
4671 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, exc eptionState)) 4663 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, exc eptionState))
4672 return; 4664 return;
4673 4665
4674 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4666 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4675 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4667 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
(...skipping 2251 matching lines...) Expand 10 before | Expand all | Expand 10 after
6927 } 6919 }
6928 6920
6929 return totalBytesPerPixel; 6921 return totalBytesPerPixel;
6930 } 6922 }
6931 6923
6932 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6924 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6933 { 6925 {
6934 return m_drawingBuffer.get(); 6926 return m_drawingBuffer.get();
6935 } 6927 }
6936 6928
6929 void WebGLRenderingContextBase::resetUnpackParameters()
6930 {
6931 if (m_unpackAlignment != 1)
6932 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
6933 }
6934
6935 void WebGLRenderingContextBase::restoreUnpackParameters()
6936 {
6937 if (m_unpackAlignment != 1)
6938 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6939 }
6940
6937 } // namespace blink 6941 } // 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