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

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

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