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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGL2RenderingContextBase.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
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
171 WebGLRenderingContextBase::initializeNewContext(); 180 WebGLRenderingContextBase::initializeNewContext();
172 } 181 }
173 182
174 void WebGL2RenderingContextBase::copyBufferSubData(GLenum readTarget, GLenum wri teTarget, long long readOffset, long long writeOffset, long long size) 183 void WebGL2RenderingContextBase::copyBufferSubData(GLenum readTarget, GLenum wri teTarget, long long readOffset, long long writeOffset, long long size)
175 { 184 {
176 if (isContextLost()) 185 if (isContextLost())
177 return; 186 return;
178 187
179 if (!validateValueFitNonNegInt32("copyBufferSubData", "readOffset", readOffs et) 188 if (!validateValueFitNonNegInt32("copyBufferSubData", "readOffset", readOffs et)
180 || !validateValueFitNonNegInt32("copyBufferSubData", "writeOffset", writ eOffset) 189 || !validateValueFitNonNegInt32("copyBufferSubData", "writeOffset", writ eOffset)
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 } else { 529 } else {
521 if (mode == GL_BACK) { 530 if (mode == GL_BACK) {
522 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer"); 531 synthesizeGLError(GL_INVALID_OPERATION, "readBuffer", "invalid read buffer");
523 return; 532 return;
524 } 533 }
525 readFramebufferBinding->readBuffer(mode); 534 readFramebufferBinding->readBuffer(mode);
526 } 535 }
527 webContext()->readBuffer(mode); 536 webContext()->readBuffer(mode);
528 } 537 }
529 538
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
530 void WebGL2RenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLs izei height, GLenum format, GLenum type, DOMArrayBufferView* pixels) 575 void WebGL2RenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLs izei height, GLenum format, GLenum type, DOMArrayBufferView* pixels)
531 { 576 {
532 if (isContextLost()) 577 if (isContextLost())
533 return; 578 return;
534 if (m_boundPixelPackBuffer.get()) { 579 if (m_boundPixelPackBuffer.get()) {
535 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "PIXEL_PACK buffer should not be bound"); 580 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "PIXEL_PACK buffer should not be bound");
536 return; 581 return;
537 } 582 }
538 583
539 WebGLRenderingContextBase::readPixels(x, y, width, height, format, type, pix els); 584 WebGLRenderingContextBase::readPixels(x, y, width, height, format, type, pix els);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 if (!validateSize("renderbufferStorage", width, height)) 721 if (!validateSize("renderbufferStorage", width, height))
677 return; 722 return;
678 if (samples < 0) { 723 if (samples < 0) {
679 synthesizeGLError(GL_INVALID_VALUE, functionName, "samples < 0"); 724 synthesizeGLError(GL_INVALID_VALUE, functionName, "samples < 0");
680 return; 725 return;
681 } 726 }
682 renderbufferStorageImpl(target, samples, internalformat, width, height, func tionName); 727 renderbufferStorageImpl(target, samples, internalformat, width, height, func tionName);
683 applyStencilTest(); 728 applyStencilTest();
684 } 729 }
685 730
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
686 /* Texture objects */ 763 /* Texture objects */
687 bool WebGL2RenderingContextBase::validateTexStorage(const char* functionName, GL enum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei heigh t, GLsizei depth, TexStorageType functionType) 764 bool WebGL2RenderingContextBase::validateTexStorage(const char* functionName, GL enum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei heigh t, GLsizei depth, TexStorageType functionType)
688 { 765 {
689 if (functionType == TexStorageType2D) { 766 if (functionType == TexStorageType2D) {
690 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP) { 767 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP) {
691 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid 2D target" ); 768 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid 2D target" );
692 return false; 769 return false;
693 } 770 }
694 } else { 771 } else {
695 if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) { 772 if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 bool needConversion = true; 953 bool needConversion = true;
877 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) { 954 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) {
878 needConversion = false; 955 needConversion = false;
879 } else { 956 } else {
880 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 957 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
881 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data "); 958 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data ");
882 return; 959 return;
883 } 960 }
884 } 961 }
885 962
886 if (m_unpackAlignment != 1) 963 resetUnpackParameters();
887 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
888 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, imageE xtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needConver sion ? data.data() : imagePixelData); 964 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, imageE xtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needConver sion ? data.data() : imagePixelData);
889 if (m_unpackAlignment != 1) 965 restoreUnpackParameters();
890 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
891 } 966 }
892 967
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) 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)
894 { 969 {
895 if (isContextLost() || !pixels || !validateTexSubImage3D("texSubImage3D", ta rget, level, xoffset, yoffset, zoffset, format, type, width, height, depth) 970 if (isContextLost() || !pixels || !validateTexSubImage3D("texSubImage3D", ta rget, level, xoffset, yoffset, zoffset, format, type, width, height, depth)
896 || !validateTexFuncData("texSubImage3D", level, width, height, depth, fo rmat, type, pixels, NullAllowed)) 971 || !validateTexFuncData("texSubImage3D", level, width, height, depth, fo rmat, type, pixels, NullAllowed))
897 return; 972 return;
898 973
899 // FIXME: Ensure pixels is large enough to contain the desired texture dimen sions. 974 // FIXME: Ensure pixels is large enough to contain the desired texture dimen sions.
900 975
901 void* data = pixels->baseAddress(); 976 void* data = pixels->baseAddress();
902 Vector<uint8_t> tempData; 977 Vector<uint8_t> tempData;
903 bool changeUnpackAlignment = false; 978 bool changeUnpackParameters = false;
904 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 979 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
905 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, 980 // FIXME: WebGLImageConversion needs to be updated to accept image depth .
906 m_unpackAlignment, 981 notImplemented();
907 m_unpackFlipY, m_unpackPremultiplyAlpha, 982 changeUnpackParameters = true;
908 data,
909 tempData))
910 return;
911 data = tempData.data();
912 changeUnpackAlignment = true;
913 } 983 }
914 if (changeUnpackAlignment) 984 if (changeUnpackParameters)
915 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 985 resetUnpackParameters();
916 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data); 986 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
917 if (changeUnpackAlignment) 987 if (changeUnpackParameters)
918 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 988 restoreUnpackParameters();
919 } 989 }
920 990
921 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, ImageData* p ixels) 991 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, ImageData* p ixels)
922 { 992 {
923 if (isContextLost() || !pixels || !validateTexSubImage3D("texSubImage3D", ta rget, level, xoffset, yoffset, zoffset, format, type, pixels->width(), pixels->h eight(), 1)) 993 if (isContextLost() || !pixels || !validateTexSubImage3D("texSubImage3D", ta rget, level, xoffset, yoffset, zoffset, format, type, pixels->width(), pixels->h eight(), 1))
924 return; 994 return;
925 995
926 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 996 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
927 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 997 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
928 type = GL_FLOAT; 998 type = GL_FLOAT;
929 } 999 }
930 Vector<uint8_t> data; 1000 Vector<uint8_t> data;
931 bool needConversion = true; 1001 bool needConversion = true;
932 // The data from ImageData is always of format RGBA8. 1002 // The data from ImageData is always of format RGBA8.
933 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 1003 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
934 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) { 1004 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) {
935 needConversion = false; 1005 needConversion = false;
936 } else { 1006 } else {
937 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 1007 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
938 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data "); 1008 synthesizeGLError(GL_INVALID_VALUE, "texSubImage3D", "bad image data ");
939 return; 1009 return;
940 } 1010 }
941 } 1011 }
942 if (m_unpackAlignment != 1) 1012 resetUnpackParameters();
943 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
944 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, pixels ->width(), pixels->height(), 1, format, type, needConversion ? data.data() : pix els->data()->data()); 1013 webContext()->texSubImage3D(target, level, xoffset, yoffset, zoffset, pixels ->width(), pixels->height(), 1, format, type, needConversion ? data.data() : pix els->data()->data());
945 if (m_unpackAlignment != 1) 1014 restoreUnpackParameters();
946 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
947 } 1015 }
948 1016
949 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, HTMLImageEle ment* image, ExceptionState& exceptionState) 1017 void WebGL2RenderingContextBase::texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLenum format, GLenum type, HTMLImageEle ment* image, ExceptionState& exceptionState)
950 { 1018 {
951 if (isContextLost() || !image || !validateHTMLImageElement("texSubImage3D", image, exceptionState)) 1019 if (isContextLost() || !image || !validateHTMLImageElement("texSubImage3D", image, exceptionState))
952 return; 1020 return;
953 1021
954 RefPtr<Image> imageForRender = image->cachedImage()->image(); 1022 RefPtr<Image> imageForRender = image->cachedImage()->image();
955 if (imageForRender->isSVGImage()) 1023 if (imageForRender->isSVGImage())
956 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width( ), image->height(), "texSubImage3D"); 1024 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width( ), image->height(), "texSubImage3D");
(...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 return getBooleanParameter(scriptState, pname); 2602 return getBooleanParameter(scriptState, pname);
2535 case GL_UNIFORM_BUFFER_BINDING: 2603 case GL_UNIFORM_BUFFER_BINDING:
2536 return WebGLAny(scriptState, m_boundUniformBuffer.get()); 2604 return WebGLAny(scriptState, m_boundUniformBuffer.get());
2537 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: 2605 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
2538 return getIntParameter(scriptState, pname); 2606 return getIntParameter(scriptState, pname);
2539 case GL_UNPACK_IMAGE_HEIGHT: 2607 case GL_UNPACK_IMAGE_HEIGHT:
2540 return getIntParameter(scriptState, pname); 2608 return getIntParameter(scriptState, pname);
2541 case GL_UNPACK_ROW_LENGTH: 2609 case GL_UNPACK_ROW_LENGTH:
2542 return getIntParameter(scriptState, pname); 2610 return getIntParameter(scriptState, pname);
2543 case GL_UNPACK_SKIP_IMAGES: 2611 case GL_UNPACK_SKIP_IMAGES:
2544 return getBooleanParameter(scriptState, pname); 2612 return getIntParameter(scriptState, pname);
2545 case GL_UNPACK_SKIP_PIXELS: 2613 case GL_UNPACK_SKIP_PIXELS:
2546 return getBooleanParameter(scriptState, pname); 2614 return getIntParameter(scriptState, pname);
2547 case GL_UNPACK_SKIP_ROWS: 2615 case GL_UNPACK_SKIP_ROWS:
2548 return getBooleanParameter(scriptState, pname); 2616 return getIntParameter(scriptState, pname);
2549 2617
2550 default: 2618 default:
2551 return WebGLRenderingContextBase::getParameter(scriptState, pname); 2619 return WebGLRenderingContextBase::getParameter(scriptState, pname);
2552 } 2620 }
2553 } 2621 }
2554 2622
2555 ScriptValue WebGL2RenderingContextBase::getInt64Parameter(ScriptState* scriptSta te, GLenum pname) 2623 ScriptValue WebGL2RenderingContextBase::getInt64Parameter(ScriptState* scriptSta te, GLenum pname)
2556 { 2624 {
2557 GLint64 value = 0; 2625 GLint64 value = 0;
2558 if (!isContextLost()) 2626 if (!isContextLost())
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
3211 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() 3279 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat()
3212 { 3280 {
3213 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) 3281 if (m_readFramebufferBinding && m_readFramebufferBinding->object())
3214 return m_readFramebufferBinding->colorBufferFormat(); 3282 return m_readFramebufferBinding->colorBufferFormat();
3215 if (m_requestedAttributes.alpha()) 3283 if (m_requestedAttributes.alpha())
3216 return GL_RGBA; 3284 return GL_RGBA;
3217 return GL_RGB; 3285 return GL_RGB;
3218 } 3286 }
3219 3287
3220 } // namespace blink 3288 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698