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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/webgl/WebGL2RenderingContextBase.h" 6 #include "modules/webgl/WebGL2RenderingContextBase.h"
7 7
8 #include "bindings/modules/v8/WebGLAny.h" 8 #include "bindings/modules/v8/WebGLAny.h"
9 #include "core/html/HTMLCanvasElement.h" 9 #include "core/html/HTMLCanvasElement.h"
10 #include "core/html/HTMLImageElement.h" 10 #include "core/html/HTMLImageElement.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 webContext()->getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &maxTr ansformFeedbackSeparateAttribs); 161 webContext()->getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &maxTr ansformFeedbackSeparateAttribs);
162 m_boundIndexedTransformFeedbackBuffers.clear(); 162 m_boundIndexedTransformFeedbackBuffers.clear();
163 m_boundIndexedTransformFeedbackBuffers.resize(maxTransformFeedbackSeparateAt tribs); 163 m_boundIndexedTransformFeedbackBuffers.resize(maxTransformFeedbackSeparateAt tribs);
164 164
165 GLint maxUniformBufferBindings = 0; 165 GLint maxUniformBufferBindings = 0;
166 webContext()->getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferB indings); 166 webContext()->getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferB indings);
167 m_boundIndexedUniformBuffers.clear(); 167 m_boundIndexedUniformBuffers.clear();
168 m_boundIndexedUniformBuffers.resize(maxUniformBufferBindings); 168 m_boundIndexedUniformBuffers.resize(maxUniformBufferBindings);
169 m_maxBoundUniformBufferIndex = 0; 169 m_maxBoundUniformBufferIndex = 0;
170 170
171 m_packRowLength = 0;
172 m_packSkipPixels = 0;
173 m_packSkipRows = 0;
174 m_unpackRowLength = 0;
175 m_unpackImageHeight = 0;
176 m_unpackSkipPixels = 0;
177 m_unpackSkipRows = 0;
178 m_unpackSkipImages = 0;
179
180 WebGLRenderingContextBase::initializeNewContext(); 171 WebGLRenderingContextBase::initializeNewContext();
181 } 172 }
182 173
183 void WebGL2RenderingContextBase::copyBufferSubData(GLenum readTarget, GLenum wri teTarget, long long readOffset, long long writeOffset, long long size) 174 void WebGL2RenderingContextBase::copyBufferSubData(GLenum readTarget, GLenum wri teTarget, long long readOffset, long long writeOffset, long long size)
184 { 175 {
185 if (isContextLost()) 176 if (isContextLost())
186 return; 177 return;
187 178
188 if (!validateValueFitNonNegInt32("copyBufferSubData", "readOffset", readOffs et) 179 if (!validateValueFitNonNegInt32("copyBufferSubData", "readOffset", readOffs et)
189 || !validateValueFitNonNegInt32("copyBufferSubData", "writeOffset", writ eOffset) 180 || !validateValueFitNonNegInt32("copyBufferSubData", "writeOffset", writ eOffset)
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } else { 520 } else {
530 if (mode == GL_BACK) { 521 if (mode == GL_BACK) {
531 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer"); 522 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer");
532 return; 523 return;
533 } 524 }
534 readFramebufferBinding->readBuffer(mode); 525 readFramebufferBinding->readBuffer(mode);
535 } 526 }
536 webContext()->readBuffer(mode); 527 webContext()->readBuffer(mode);
537 } 528 }
538 529
539 void WebGL2RenderingContextBase::pixelStorei(GLenum pname, GLint param)
540 {
541 if (isContextLost())
542 return;
543 switch (pname) {
544 case GL_PACK_ROW_LENGTH:
545 m_packRowLength = param;
546 break;
547 case GL_PACK_SKIP_PIXELS:
548 m_packSkipPixels = param;
549 break;
550 case GL_PACK_SKIP_ROWS:
551 m_packSkipRows = param;
552 break;
553 case GL_UNPACK_ROW_LENGTH:
554 m_unpackRowLength = param;
555 break;
556 case GL_UNPACK_IMAGE_HEIGHT:
557 m_unpackImageHeight = param;
558 break;
559 case GL_UNPACK_SKIP_PIXELS:
560 m_unpackSkipPixels = param;
561 break;
562 case GL_UNPACK_SKIP_ROWS:
563 m_unpackSkipRows = param;
564 break;
565 case GL_UNPACK_SKIP_IMAGES:
566 m_unpackSkipImages = param;
567 break;
568 default:
569 WebGLRenderingContextBase::pixelStorei(pname, param);
570 return;
571 }
572 webContext()->pixelStorei(pname, param);
573 }
574
575 void WebGL2RenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLs izei height, GLenum format, GLenum type, DOMArrayBufferView* pixels) 530 void WebGL2RenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLs izei height, GLenum format, GLenum type, DOMArrayBufferView* pixels)
576 { 531 {
577 if (isContextLost()) 532 if (isContextLost())
578 return; 533 return;
579 if (m_boundPixelPackBuffer.get()) { 534 if (m_boundPixelPackBuffer.get()) {
580 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "PIXEL_PACK buffer should not be bound"); 535 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "PIXEL_PACK buffer should not be bound");
581 return; 536 return;
582 } 537 }
583 538
584 WebGLRenderingContextBase::readPixels(x, y, width, height, format, type, pix els); 539 WebGLRenderingContextBase::readPixels(x, y, width, height, format, type, pix els);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 if (!validateSize("renderbufferStorage", width, height)) 676 if (!validateSize("renderbufferStorage", width, height))
722 return; 677 return;
723 if (samples < 0) { 678 if (samples < 0) {
724 synthesizeGLError(GL_INVALID_VALUE, functionName, "samples < 0"); 679 synthesizeGLError(GL_INVALID_VALUE, functionName, "samples < 0");
725 return; 680 return;
726 } 681 }
727 renderbufferStorageImpl(target, samples, internalformat, width, height, func tionName); 682 renderbufferStorageImpl(target, samples, internalformat, width, height, func tionName);
728 applyStencilTest(); 683 applyStencilTest();
729 } 684 }
730 685
731 void WebGL2RenderingContextBase::resetUnpackParameters()
732 {
733 WebGLRenderingContextBase::resetUnpackParameters();
734
735 if (!m_unpackRowLength)
736 webContext()->pixelStorei(GL_UNPACK_ROW_LENGTH, 0);
737 if (!m_unpackImageHeight)
738 webContext()->pixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
739 if (!m_unpackSkipPixels)
740 webContext()->pixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
741 if (!m_unpackSkipRows)
742 webContext()->pixelStorei(GL_UNPACK_SKIP_ROWS, 0);
743 if (!m_unpackSkipImages)
744 webContext()->pixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
745 }
746
747 void WebGL2RenderingContextBase::restoreUnpackParameters()
748 {
749 WebGLRenderingContextBase::restoreUnpackParameters();
750
751 if (!m_unpackRowLength)
752 webContext()->pixelStorei(GL_UNPACK_ROW_LENGTH, m_unpackRowLength);
753 if (!m_unpackImageHeight)
754 webContext()->pixelStorei(GL_UNPACK_IMAGE_HEIGHT, m_unpackImageHeight);
755 if (!m_unpackSkipPixels)
756 webContext()->pixelStorei(GL_UNPACK_SKIP_PIXELS, m_unpackSkipPixels);
757 if (!m_unpackSkipRows)
758 webContext()->pixelStorei(GL_UNPACK_SKIP_ROWS, m_unpackSkipRows);
759 if (!m_unpackSkipImages)
760 webContext()->pixelStorei(GL_UNPACK_SKIP_IMAGES, m_unpackSkipImages);
761 }
762
763 /* Texture objects */ 686 /* Texture objects */
764 bool WebGL2RenderingContextBase::validateTexStorage(const char* functionName, GL enum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei heigh t, GLsizei depth, TexStorageType functionType) 687 bool WebGL2RenderingContextBase::validateTexStorage(const char* functionName, GL enum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei heigh t, GLsizei depth, TexStorageType functionType)
765 { 688 {
766 if (functionType == TexStorageType2D) { 689 if (functionType == TexStorageType2D) {
767 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP) { 690 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP) {
768 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid 2D target" ); 691 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid 2D target" );
769 return false; 692 return false;
770 } 693 }
771 } else { 694 } else {
772 if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) { 695 if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 bool needConversion = true; 876 bool needConversion = true;
954 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) { 877 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) {
955 needConversion = false; 878 needConversion = false;
956 } else { 879 } else {
957 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 880 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
958 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data "); 881 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data ");
959 return; 882 return;
960 } 883 }
961 } 884 }
962 885
963 resetUnpackParameters(); 886 if (m_unpackAlignment != 1)
887 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
964 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, imageE xtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needConver sion ? data.data() : imagePixelData); 888 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, imageE xtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needConver sion ? data.data() : imagePixelData);
965 restoreUnpackParameters(); 889 if (m_unpackAlignment != 1)
890 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
966 } 891 }
967 892
968 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei d epth, GLenum format, GLenum type, DOMArrayBufferView* pixels) 893 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei d epth, GLenum format, GLenum type, DOMArrayBufferView* pixels)
969 { 894 {
970 if (isContextLost() || !pixels || !validateTexSubImage3D("texSubImage3D", ta rget, level, xoffset, yoffset, zoffset, format, type, width, height, depth) 895 if (isContextLost() || !pixels || !validateTexSubImage3D("texSubImage3D", ta rget, level, xoffset, yoffset, zoffset, format, type, width, height, depth)
971 || !validateTexFuncData("texSubImage3D", level, width, height, depth, fo rmat, type, pixels, NullAllowed)) 896 || !validateTexFuncData("texSubImage3D", level, width, height, depth, fo rmat, type, pixels, NullAllowed))
972 return; 897 return;
973 898
974 // FIXME: Ensure pixels is large enough to contain the desired texture dimen sions. 899 // FIXME: Ensure pixels is large enough to contain the desired texture dimen sions.
975 900
976 void* data = pixels->baseAddress(); 901 void* data = pixels->baseAddress();
977 Vector<uint8_t> tempData; 902 Vector<uint8_t> tempData;
978 bool changeUnpackParameters = false; 903 bool changeUnpackAlignment = false;
979 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 904 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
980 // FIXME: WebGLImageConversion needs to be updated to accept image depth . 905 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e,
981 notImplemented(); 906 m_unpackAlignment,
982 changeUnpackParameters = true; 907 m_unpackFlipY, m_unpackPremultiplyAlpha,
908 data,
909 tempData))
910 return;
911 data = tempData.data();
912 changeUnpackAlignment = true;
983 } 913 }
984 if (changeUnpackParameters) 914 if (changeUnpackAlignment)
985 resetUnpackParameters(); 915 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
986 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data); 916 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
987 if (changeUnpackParameters) 917 if (changeUnpackAlignment)
988 restoreUnpackParameters(); 918 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
989 } 919 }
990 920
991 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, ImageData* p ixels) 921 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, ImageData* p ixels)
992 { 922 {
993 if (isContextLost() || !pixels || !validateTexSubImage3D("texSubImage3D", ta rget, level, xoffset, yoffset, zoffset, format, type, pixels->width(), pixels->h eight(), 1)) 923 if (isContextLost() || !pixels || !validateTexSubImage3D("texSubImage3D", ta rget, level, xoffset, yoffset, zoffset, format, type, pixels->width(), pixels->h eight(), 1))
994 return; 924 return;
995 925
996 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 926 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
997 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 927 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
998 type = GL_FLOAT; 928 type = GL_FLOAT;
999 } 929 }
1000 Vector<uint8_t> data; 930 Vector<uint8_t> data;
1001 bool needConversion = true; 931 bool needConversion = true;
1002 // The data from ImageData is always of format RGBA8. 932 // The data from ImageData is always of format RGBA8.
1003 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 933 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
1004 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) { 934 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) {
1005 needConversion = false; 935 needConversion = false;
1006 } else { 936 } else {
1007 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 937 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
1008 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data "); 938 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data ");
1009 return; 939 return;
1010 } 940 }
1011 } 941 }
1012 resetUnpackParameters(); 942 if (m_unpackAlignment != 1)
943 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
1013 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, pixels ->width(), pixels->height(), 1, format, type, needConversion ? data.data() : pix els->data()->data()); 944 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, pixels ->width(), pixels->height(), 1, format, type, needConversion ? data.data() : pix els->data()->data());
1014 restoreUnpackParameters(); 945 if (m_unpackAlignment != 1)
946 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
1015 } 947 }
1016 948
1017 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, HTMLImageEle ment* image, ExceptionState& exceptionState) 949 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, HTMLImageEle ment* image, ExceptionState& exceptionState)
1018 { 950 {
1019 if (isContextLost() || !image || !validateHTMLImageElement("texSubImage3D", image, exceptionState)) 951 if (isContextLost() || !image || !validateHTMLImageElement("texSubImage3D", image, exceptionState))
1020 return; 952 return;
1021 953
1022 RefPtr<Image> imageForRender = image->cachedImage()->image(); 954 RefPtr<Image> imageForRender = image->cachedImage()->image();
1023 if (imageForRender->isSVGImage()) 955 if (imageForRender->isSVGImage())
1024 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width( ), image->height(), "texSubImage3D"); 956 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width( ), image->height(), "texSubImage3D");
(...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 return getBooleanParameter(scriptState, pname); 2534 return getBooleanParameter(scriptState, pname);
2603 case GL_UNIFORM_BUFFER_BINDING: 2535 case GL_UNIFORM_BUFFER_BINDING:
2604 return WebGLAny(scriptState, m_boundUniformBuffer.get()); 2536 return WebGLAny(scriptState, m_boundUniformBuffer.get());
2605 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: 2537 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
2606 return getIntParameter(scriptState, pname); 2538 return getIntParameter(scriptState, pname);
2607 case GL_UNPACK_IMAGE_HEIGHT: 2539 case GL_UNPACK_IMAGE_HEIGHT:
2608 return getIntParameter(scriptState, pname); 2540 return getIntParameter(scriptState, pname);
2609 case GL_UNPACK_ROW_LENGTH: 2541 case GL_UNPACK_ROW_LENGTH:
2610 return getIntParameter(scriptState, pname); 2542 return getIntParameter(scriptState, pname);
2611 case GL_UNPACK_SKIP_IMAGES: 2543 case GL_UNPACK_SKIP_IMAGES:
2612 return getIntParameter(scriptState, pname); 2544 return getBooleanParameter(scriptState, pname);
2613 case GL_UNPACK_SKIP_PIXELS: 2545 case GL_UNPACK_SKIP_PIXELS:
2614 return getIntParameter(scriptState, pname); 2546 return getBooleanParameter(scriptState, pname);
2615 case GL_UNPACK_SKIP_ROWS: 2547 case GL_UNPACK_SKIP_ROWS:
2616 return getIntParameter(scriptState, pname); 2548 return getBooleanParameter(scriptState, pname);
2617 2549
2618 default: 2550 default:
2619 return WebGLRenderingContextBase::getParameter(scriptState, pname); 2551 return WebGLRenderingContextBase::getParameter(scriptState, pname);
2620 } 2552 }
2621 } 2553 }
2622 2554
2623 ScriptValue WebGL2RenderingContextBase::getInt64Parameter(ScriptState* scriptSta te, GLenum pname) 2555 ScriptValue WebGL2RenderingContextBase::getInt64Parameter(ScriptState* scriptSta te, GLenum pname)
2624 { 2556 {
2625 GLint64 value = 0; 2557 GLint64 value = 0;
2626 if (!isContextLost()) 2558 if (!isContextLost())
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
3279 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() 3211 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat()
3280 { 3212 {
3281 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) 3213 if (m_readFramebufferBinding && m_readFramebufferBinding->object())
3282 return m_readFramebufferBinding->colorBufferFormat(); 3214 return m_readFramebufferBinding->colorBufferFormat();
3283 if (m_requestedAttributes.alpha()) 3215 if (m_requestedAttributes.alpha())
3284 return GL_RGBA; 3216 return GL_RGBA;
3285 return GL_RGB; 3217 return GL_RGB;
3286 } 3218 }
3287 3219
3288 } // namespace blink 3220 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698