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

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

Issue 1405013002: Update texImage2DCanvasByGPU path in texImage2D/texSubImage2D for WebGL 2.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add FIXME and wrap the checks in one function Created 5 years, 2 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 | « no previous file | 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 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 { GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT }, 857 { GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT },
858 { GL_RGBA32I, GL_RGBA_INTEGER, GL_INT }, 858 { GL_RGBA32I, GL_RGBA_INTEGER, GL_INT },
859 { GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT }, 859 { GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT },
860 { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT }, 860 { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT },
861 { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT }, 861 { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT },
862 { GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT }, 862 { GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT },
863 { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT }, 863 { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT },
864 { GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 }, 864 { GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 },
865 }; 865 };
866 866
867 bool isUnsignedIntegerFormat(GLenum internalformat)
868 {
869 switch (internalformat) {
870 case GL_R8UI:
871 case GL_R16UI:
872 case GL_R32UI:
873 case GL_RG8UI:
874 case GL_RG16UI:
875 case GL_RG32UI:
876 case GL_RGB8UI:
877 case GL_RGB16UI:
878 case GL_RGB32UI:
879 case GL_RGBA8UI:
880 case GL_RGB10_A2UI:
881 case GL_RGBA16UI:
882 case GL_RGBA32UI:
883 return true;
884 default:
885 return false;
886 }
887 }
888
889 bool isSignedIntegerFormat(GLenum internalformat)
890 {
891 switch (internalformat) {
892 case GL_R8I:
893 case GL_R16I:
894 case GL_R32I:
895 case GL_RG8I:
896 case GL_RG16I:
897 case GL_RG32I:
898 case GL_RGB8I:
899 case GL_RGB16I:
900 case GL_RGB32I:
901 case GL_RGBA8I:
902 case GL_RGBA16I:
903 case GL_RGBA32I:
904 return true;
905 default:
906 return false;
907 }
908 }
909
910 bool isIntegerFormat(GLenum internalformat)
911 {
912 return (isUnsignedIntegerFormat(internalformat) || isSignedIntegerFormat(int ernalformat));
913 }
914
915 bool isFloatType(GLenum type)
916 {
917 switch (type) {
918 case GL_FLOAT:
919 case GL_HALF_FLOAT:
920 case GL_HALF_FLOAT_OES:
921 case GL_UNSIGNED_INT_10F_11F_11F_REV:
922 return true;
923 default:
924 return false;
925 }
926 }
927
928 bool isSRGBFormat(GLenum internalformat)
929 {
930 switch (internalformat) {
931 case GL_SRGB_EXT:
932 case GL_SRGB_ALPHA_EXT:
933 case GL_SRGB8:
934 case GL_SRGB8_ALPHA8:
935 return true;
936 default:
937 return false;
938 }
939 }
940
941 bool canUseTexImage2DCanvasByGPU(GLenum internalformat, GLenum type)
942 {
943 if (isFloatType(type) || isIntegerFormat(internalformat) || isSRGBFormat(int ernalformat))
944 return false;
945 return true;
946 }
947
867 } // namespace anonymous 948 } // namespace anonymous
868 949
869 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3D> context, const WebGLContextAttributes& re questedAttributes) 950 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3D> context, const WebGLContextAttributes& re questedAttributes)
870 : CanvasRenderingContext(passedCanvas) 951 : CanvasRenderingContext(passedCanvas)
871 , m_contextLostMode(NotLostContext) 952 , m_contextLostMode(NotLostContext)
872 , m_autoRecoveryMethod(Manual) 953 , m_autoRecoveryMethod(Manual)
873 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) 954 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent)
874 , m_restoreAllowed(false) 955 , m_restoreAllowed(false)
875 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) 956 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
876 , m_preservedDefaultVAOObjectWrapper(false) 957 , m_preservedDefaultVAOObjectWrapper(false)
(...skipping 3469 matching lines...) Expand 10 before | Expand all | Expand 10 after
4346 4427
4347 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4428 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4348 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 4429 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
4349 { 4430 {
4350 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)) 4431 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))
4351 return; 4432 return;
4352 4433
4353 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4434 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4354 ASSERT(texture); 4435 ASSERT(texture);
4355 4436
4356 // texImage2DCanvasByGPU relies on copyTextureCHROMIUM which doesn't support float type. 4437 // texImage2DCanvasByGPU relies on copyTextureCHROMIUM which doesn't support float/integer/sRGB internal format.
4357 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES; 4438 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats.
4358 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) { 4439 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImage2DCanvasByGPU(internalformat, type)) {
4359 // 2D canvas has only FrontBuffer. 4440 // 2D canvas has only FrontBuffer.
4360 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(), 4441 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(),
4361 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); 4442 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha);
4362 return; 4443 return;
4363 } 4444 }
4364 4445
4365 texImage2DCanvasByGPU(NotTexSubImage2D, texture, target, level, internalform at, type, 0, 0, canvas); 4446 texImage2DCanvasByGPU(NotTexSubImage2D, texture, target, level, internalform at, type, 0, 0, canvas);
4366 texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas ->height(), 1, type); 4447 texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas ->height(), 1, type);
4367 } 4448 }
4368 4449
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
4604 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4685 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4605 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 4686 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
4606 { 4687 {
4607 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState) 4688 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState)
4608 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 0, format, type, xoffs et, yoffset)) 4689 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 0, format, type, xoffs et, yoffset))
4609 return; 4690 return;
4610 4691
4611 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true ); 4692 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true );
4612 ASSERT(texture); 4693 ASSERT(texture);
4613 4694
4614 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES; 4695 GLenum internalformat = texture->getInternalFormat(target, level);
4615 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) { 4696 // texImage2DCanvasByGPU relies on copyTextureCHROMIUM which doesn't support float/integer/sRGB internal format.
4697 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats.
4698 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImage2DCanvasByGPU(internalformat, type)) {
4616 // 2D canvas has only FrontBuffer. 4699 // 2D canvas has only FrontBuffer.
4617 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(), 4700 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(),
4618 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); 4701 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha);
4619 return; 4702 return;
4620 } 4703 }
4621 4704
4622 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas); 4705 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas);
4623 } 4706 }
4624 4707
4625 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4708 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
(...skipping 2206 matching lines...) Expand 10 before | Expand all | Expand 10 after
6832 6915
6833 return totalBytesPerPixel; 6916 return totalBytesPerPixel;
6834 } 6917 }
6835 6918
6836 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6919 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6837 { 6920 {
6838 return m_drawingBuffer.get(); 6921 return m_drawingBuffer.get();
6839 } 6922 }
6840 6923
6841 } // namespace blink 6924 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698