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

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

Issue 2738163002: Enable CopyTextureCHROMIUM in Blink for Tex{Sub}Image2D with more cases (Closed)
Patch Set: Created 3 years, 9 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
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 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 811
812 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); 812 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry);
813 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( 813 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(
814 SharedGpuContext::gr(), SkBudgeted::kYes, imageInfo, 0, 814 SharedGpuContext::gr(), SkBudgeted::kYes, imageInfo, 0,
815 imageInfo.alphaType() == kOpaque_SkAlphaType ? nullptr 815 imageInfo.alphaType() == kOpaque_SkAlphaType ? nullptr
816 : &disableLCDProps); 816 : &disableLCDProps);
817 GLuint textureId = skia::GrBackendObjectToGrGLTextureInfo( 817 GLuint textureId = skia::GrBackendObjectToGrGLTextureInfo(
818 surface->getTextureHandle( 818 surface->getTextureHandle(
819 SkSurface::kDiscardWrite_TextureHandleAccess)) 819 SkSurface::kDiscardWrite_TextureHandleAccess))
820 ->fID; 820 ->fID;
821 GLenum textureTarget = skia::GrBackendObjectToGrGLTextureInfo(
822 surface->getTextureHandle(
823 SkSurface::kDiscardWrite_TextureHandleAccess))
Zhenyao Mo 2017/03/10 00:10:24 Can we cache this and reuse it for both textureId
qiankun 2017/03/10 02:48:04 Done.
824 ->fTarget;
821 825
822 drawingBuffer()->copyToPlatformTexture( 826 drawingBuffer()->copyToPlatformTexture(
823 gl, textureId, GL_RGBA, GL_UNSIGNED_BYTE, 0, true, false, IntPoint(0, 0), 827 gl, textureTarget, textureId, true, false, IntPoint(0, 0),
824 IntRect(IntPoint(0, 0), drawingBuffer()->size()), BackBuffer); 828 IntRect(IntPoint(0, 0), drawingBuffer()->size()), BackBuffer);
825 return surface->makeImageSnapshot(); 829 return surface->makeImageSnapshot();
826 } 830 }
827 831
828 ImageData* WebGLRenderingContextBase::toImageData(SnapshotReason reason) { 832 ImageData* WebGLRenderingContextBase::toImageData(SnapshotReason reason) {
829 ImageData* imageData = nullptr; 833 ImageData* imageData = nullptr;
830 // TODO(ccameron): WebGL should produce sRGB images. 834 // TODO(ccameron): WebGL should produce sRGB images.
831 // https://crbug.com/672299 835 // https://crbug.com/672299
832 if (drawingBuffer()) { 836 if (drawingBuffer()) {
833 // For un-premultiplied data 837 // For un-premultiplied data
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 GL_UNSIGNED_INT_5_9_9_9_REV, 981 GL_UNSIGNED_INT_5_9_9_9_REV,
978 GL_UNSIGNED_INT_24_8, 982 GL_UNSIGNED_INT_24_8,
979 GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 983 GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
980 }; 984 };
981 985
982 // ES3 enums supported by TexImageSource 986 // ES3 enums supported by TexImageSource
983 static const GLenum kSupportedTypesTexImageSourceES3[] = { 987 static const GLenum kSupportedTypesTexImageSourceES3[] = {
984 GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_INT_10F_11F_11F_REV, 988 GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_INT_10F_11F_11F_REV,
985 }; 989 };
986 990
987 bool isUnsignedIntegerFormat(GLenum internalformat) {
988 switch (internalformat) {
989 case GL_R8UI:
990 case GL_R16UI:
991 case GL_R32UI:
992 case GL_RG8UI:
993 case GL_RG16UI:
994 case GL_RG32UI:
995 case GL_RGB8UI:
996 case GL_RGB16UI:
997 case GL_RGB32UI:
998 case GL_RGBA8UI:
999 case GL_RGB10_A2UI:
1000 case GL_RGBA16UI:
1001 case GL_RGBA32UI:
1002 return true;
1003 default:
1004 return false;
1005 }
1006 }
1007
1008 bool isSignedIntegerFormat(GLenum internalformat) {
1009 switch (internalformat) {
1010 case GL_R8I:
1011 case GL_R16I:
1012 case GL_R32I:
1013 case GL_RG8I:
1014 case GL_RG16I:
1015 case GL_RG32I:
1016 case GL_RGB8I:
1017 case GL_RGB16I:
1018 case GL_RGB32I:
1019 case GL_RGBA8I:
1020 case GL_RGBA16I:
1021 case GL_RGBA32I:
1022 return true;
1023 default:
1024 return false;
1025 }
1026 }
1027
1028 bool isIntegerFormat(GLenum internalformat) {
1029 return (isUnsignedIntegerFormat(internalformat) ||
1030 isSignedIntegerFormat(internalformat));
1031 }
1032
1033 bool isFloatType(GLenum type) {
1034 switch (type) {
1035 case GL_FLOAT:
1036 case GL_HALF_FLOAT:
1037 case GL_HALF_FLOAT_OES:
1038 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1039 return true;
1040 default:
1041 return false;
1042 }
1043 }
1044
1045 bool isSRGBFormat(GLenum internalformat) { 991 bool isSRGBFormat(GLenum internalformat) {
1046 switch (internalformat) { 992 switch (internalformat) {
1047 case GL_SRGB_EXT: 993 case GL_SRGB_EXT:
1048 case GL_SRGB_ALPHA_EXT: 994 case GL_SRGB_ALPHA_EXT:
1049 case GL_SRGB8: 995 case GL_SRGB8:
1050 case GL_SRGB8_ALPHA8: 996 case GL_SRGB8_ALPHA8:
1051 return true; 997 return true;
1052 default: 998 default:
1053 return false; 999 return false;
1054 } 1000 }
(...skipping 3891 matching lines...) Expand 10 before | Expand all | Expand 10 after
4946 ExceptionState& exceptionState) { 4892 ExceptionState& exceptionState) {
4947 texImageHelperHTMLImageElement(TexImage2D, target, level, internalformat, 4893 texImageHelperHTMLImageElement(TexImage2D, target, level, internalformat,
4948 format, type, 0, 0, 0, image, 4894 format, type, 0, 0, 0, image,
4949 sentinelEmptyRect(), 1, 0, exceptionState); 4895 sentinelEmptyRect(), 1, 0, exceptionState);
4950 } 4896 }
4951 4897
4952 bool WebGLRenderingContextBase::canUseTexImageByGPU( 4898 bool WebGLRenderingContextBase::canUseTexImageByGPU(
4953 TexImageFunctionID functionID, 4899 TexImageFunctionID functionID,
4954 GLint internalformat, 4900 GLint internalformat,
4955 GLenum type) { 4901 GLenum type) {
4956 if (functionID == TexImage2D && 4902 // SRGB format has color-space conversion issue, see
4957 (isFloatType(type) || isIntegerFormat(internalformat) || 4903 // https://github.com/KhronosGroup/WebGL/issues/2165.
4958 isSRGBFormat(internalformat))) 4904 if (isSRGBFormat(internalformat))
4959 return false; 4905 return false;
4960 // TODO(crbug.com/622958): Implement GPU-to-GPU path for WebGL 2 and more 4906 // Before we can detect internalformat in TexSubImage2D, we disable GPU path
4961 // internal formats. 4907 // if EXT_sRGB extension is enabled.
4962 if (functionID == TexSubImage2D && 4908 if (functionID == TexSubImage2D && extensionEnabled(EXTsRGBName))
Zhenyao Mo 2017/03/10 00:10:24 This is a big fallback. Can we look into lifting
qiankun 2017/03/10 02:48:04 When we get clear on how to handle sRGB texture, w
4963 (isWebGL2OrHigher() || extensionEnabled(OESTextureFloatName) ||
4964 extensionEnabled(OESTextureHalfFloatName) ||
4965 extensionEnabled(EXTsRGBName)))
4966 return false; 4909 return false;
4910 #if OS(MACOSX)
4911 // RGB5_A1 is not color-renderable on NVIDIA Mac, see crbug.com/676209.
4912 if (type == GL_UNSIGNED_SHORT_5_5_5_1)
4913 return false;
4914 #endif
4915 // OES_texture_half_float doesn't support HALF_FLOAT_OES type for
4916 // CopyTexImage/CopyTexSubImage. And OES_texture_half_float doesn't require
4917 // HALF_FLOAT_OES type texture to be renderable. So, HALF_FLOAT_OES type
4918 // texture cannot be copied to or drawn to by glCopyTextureCHROMIUM.
4919 if (type == GL_HALF_FLOAT_OES)
4920 return false;
4921
4967 return true; 4922 return true;
4968 } 4923 }
4969 4924
4970 SnapshotReason WebGLRenderingContextBase::functionIDToSnapshotReason( 4925 SnapshotReason WebGLRenderingContextBase::functionIDToSnapshotReason(
4971 TexImageFunctionID id) { 4926 TexImageFunctionID id) {
4972 switch (id) { 4927 switch (id) {
4973 case TexImage2D: 4928 case TexImage2D:
4974 return SnapshotReasonWebGLTexImage2D; 4929 return SnapshotReasonWebGLTexImage2D;
4975 case TexSubImage2D: 4930 case TexSubImage2D:
4976 return SnapshotReasonWebGLTexSubImage2D; 4931 return SnapshotReasonWebGLTexSubImage2D;
4977 case TexImage3D: 4932 case TexImage3D:
4978 return SnapshotReasonWebGLTexImage3D; 4933 return SnapshotReasonWebGLTexImage3D;
4979 case TexSubImage3D: 4934 case TexSubImage3D:
4980 return SnapshotReasonWebGLTexSubImage3D; 4935 return SnapshotReasonWebGLTexSubImage3D;
4981 } 4936 }
4982 NOTREACHED(); 4937 NOTREACHED();
4983 return SnapshotReasonUnknown; 4938 return SnapshotReasonUnknown;
4984 } 4939 }
4985 4940
4986 void WebGLRenderingContextBase::texImageCanvasByGPU( 4941 void WebGLRenderingContextBase::texImageCanvasByGPU(
4987 TexImageFunctionID functionID, 4942 TexImageFunctionID functionID,
4988 HTMLCanvasElement* canvas, 4943 HTMLCanvasElement* canvas,
4944 GLenum target,
4989 GLuint targetTexture, 4945 GLuint targetTexture,
4990 GLenum targetInternalformat,
4991 GLenum targetType,
4992 GLint targetLevel,
4993 GLint xoffset, 4946 GLint xoffset,
4994 GLint yoffset, 4947 GLint yoffset,
4995 const IntRect& sourceSubRectangle) { 4948 const IntRect& sourceSubRectangle) {
4996 if (!canvas->is3D()) { 4949 if (!canvas->is3D()) {
4997 ImageBuffer* buffer = canvas->buffer(); 4950 ImageBuffer* buffer = canvas->buffer();
4998 if (buffer && 4951 if (buffer &&
4999 !buffer->copyToPlatformTexture( 4952 !buffer->copyToPlatformTexture(
5000 functionIDToSnapshotReason(functionID), contextGL(), targetTexture, 4953 functionIDToSnapshotReason(functionID), contextGL(), target,
5001 targetInternalformat, targetType, targetLevel, 4954 targetTexture, m_unpackPremultiplyAlpha, m_unpackFlipY,
5002 m_unpackPremultiplyAlpha, m_unpackFlipY, IntPoint(xoffset, yoffset), 4955 IntPoint(xoffset, yoffset), sourceSubRectangle)) {
5003 sourceSubRectangle)) {
5004 NOTREACHED(); 4956 NOTREACHED();
5005 } 4957 }
5006 } else { 4958 } else {
5007 WebGLRenderingContextBase* gl = 4959 WebGLRenderingContextBase* gl =
5008 toWebGLRenderingContextBase(canvas->renderingContext()); 4960 toWebGLRenderingContextBase(canvas->renderingContext());
5009 ScopedTexture2DRestorer restorer(gl); 4961 ScopedTexture2DRestorer restorer(gl);
5010 if (!gl->drawingBuffer()->copyToPlatformTexture( 4962 if (!gl->drawingBuffer()->copyToPlatformTexture(
5011 contextGL(), targetTexture, targetInternalformat, targetType, 4963 contextGL(), target, targetTexture, m_unpackPremultiplyAlpha,
5012 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, 4964 !m_unpackFlipY, IntPoint(xoffset, yoffset), sourceSubRectangle,
5013 IntPoint(xoffset, yoffset), sourceSubRectangle, BackBuffer)) { 4965 BackBuffer)) {
5014 NOTREACHED(); 4966 NOTREACHED();
5015 } 4967 }
5016 } 4968 }
5017 } 4969 }
5018 4970
5019 void WebGLRenderingContextBase::texImageByGPU( 4971 void WebGLRenderingContextBase::texImageByGPU(
5020 TexImageFunctionID functionID, 4972 TexImageFunctionID functionID,
5021 WebGLTexture* texture, 4973 WebGLTexture* texture,
5022 GLenum target, 4974 GLenum target,
5023 GLint level, 4975 GLint level,
5024 GLint internalformat,
5025 GLenum type,
5026 GLint xoffset, 4976 GLint xoffset,
5027 GLint yoffset, 4977 GLint yoffset,
5028 GLint zoffset, 4978 GLint zoffset,
5029 CanvasImageSource* image, 4979 CanvasImageSource* image,
5030 const IntRect& sourceSubRectangle) { 4980 const IntRect& sourceSubRectangle) {
5031 DCHECK(image->isCanvasElement() || image->isImageBitmap()); 4981 DCHECK(image->isCanvasElement() || image->isImageBitmap());
5032 int width = sourceSubRectangle.width(); 4982 int width = sourceSubRectangle.width();
5033 int height = sourceSubRectangle.height(); 4983 int height = sourceSubRectangle.height();
5034 4984
5035 ScopedTexture2DRestorer restorer(this); 4985 ScopedTexture2DRestorer restorer(this);
5036 4986
5037 GLuint targetTexture = texture->object(); 4987 GLuint targetTexture = texture->object();
5038 GLenum targetType = type;
5039 GLenum targetInternalformat = internalformat;
5040 GLint targetLevel = level;
5041 bool possibleDirectCopy = false; 4988 bool possibleDirectCopy = false;
5042 if (functionID == TexImage2D) { 4989 if (functionID == TexImage2D || functionID == TexSubImage2D) {
5043 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM( 4990 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(target);
5044 target, internalformat, type, level);
5045 } 4991 }
5046 4992
5047 GLint copyXOffset = xoffset; 4993 GLint copyXOffset = xoffset;
5048 GLint copyYOffset = yoffset; 4994 GLint copyYOffset = yoffset;
4995 GLenum copyTarget = target;
5049 4996
5050 // if direct copy is not possible, create a temporary texture and then copy 4997 // if direct copy is not possible, create a temporary texture and then copy
5051 // from canvas to temporary texture to target texture. 4998 // from canvas to temporary texture to target texture.
5052 if (!possibleDirectCopy) { 4999 if (!possibleDirectCopy) {
5053 targetLevel = 0;
5054 targetInternalformat = GL_RGBA;
5055 targetType = GL_UNSIGNED_BYTE;
5056 contextGL()->GenTextures(1, &targetTexture); 5000 contextGL()->GenTextures(1, &targetTexture);
5057 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); 5001 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture);
5058 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 5002 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
5059 GL_NEAREST); 5003 GL_NEAREST);
5060 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 5004 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
5061 GL_NEAREST); 5005 GL_NEAREST);
5062 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 5006 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
5063 GL_CLAMP_TO_EDGE); 5007 GL_CLAMP_TO_EDGE);
5064 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 5008 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
5065 GL_CLAMP_TO_EDGE); 5009 GL_CLAMP_TO_EDGE);
5066 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, width, 5010 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
5067 height, 0, GL_RGBA, targetType, 0); 5011 GL_RGBA, GL_UNSIGNED_BYTE, 0);
5068 copyXOffset = 0; 5012 copyXOffset = 0;
5069 copyYOffset = 0; 5013 copyYOffset = 0;
5014 copyTarget = GL_TEXTURE_2D;
5070 } 5015 }
5071 5016
5072 if (image->isCanvasElement()) { 5017 if (image->isCanvasElement()) {
5073 texImageCanvasByGPU(functionID, static_cast<HTMLCanvasElement*>(image), 5018 texImageCanvasByGPU(functionID, static_cast<HTMLCanvasElement*>(image),
5074 targetTexture, targetInternalformat, targetType, 5019 copyTarget, targetTexture, copyXOffset, copyYOffset,
5075 targetLevel, copyXOffset, copyYOffset,
5076 sourceSubRectangle); 5020 sourceSubRectangle);
5077 } else { 5021 } else {
5078 texImageBitmapByGPU(static_cast<ImageBitmap*>(image), targetTexture, 5022 texImageBitmapByGPU(static_cast<ImageBitmap*>(image), copyTarget,
5079 targetInternalformat, targetType, targetLevel, 5023 targetTexture, !m_unpackFlipY, copyXOffset, copyYOffset,
5080 !m_unpackFlipY); 5024 sourceSubRectangle);
5081 } 5025 }
5082 5026
5083 if (!possibleDirectCopy) { 5027 if (!possibleDirectCopy) {
5084 GLuint tmpFBO; 5028 GLuint tmpFBO;
5085 contextGL()->GenFramebuffers(1, &tmpFBO); 5029 contextGL()->GenFramebuffers(1, &tmpFBO);
5086 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO); 5030 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO);
5087 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 5031 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
5088 GL_TEXTURE_2D, targetTexture, 0); 5032 GL_TEXTURE_2D, targetTexture, 0);
5089 contextGL()->BindTexture(texture->getTarget(), texture->object()); 5033 contextGL()->BindTexture(texture->getTarget(), texture->object());
5090 if (functionID == TexImage2D) { 5034 if (functionID == TexImage2D) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5170 // The GPU-GPU copy path uses the Y-up coordinate system. 5114 // The GPU-GPU copy path uses the Y-up coordinate system.
5171 IntRect adjustedSourceSubRectangle = sourceSubRectangle; 5115 IntRect adjustedSourceSubRectangle = sourceSubRectangle;
5172 if (!m_unpackFlipY) { 5116 if (!m_unpackFlipY) {
5173 adjustedSourceSubRectangle.setY(canvas->height() - 5117 adjustedSourceSubRectangle.setY(canvas->height() -
5174 adjustedSourceSubRectangle.maxY()); 5118 adjustedSourceSubRectangle.maxY());
5175 } 5119 }
5176 5120
5177 if (functionID == TexImage2D) { 5121 if (functionID == TexImage2D) {
5178 texImage2DBase(target, level, internalformat, sourceSubRectangle.width(), 5122 texImage2DBase(target, level, internalformat, sourceSubRectangle.width(),
5179 sourceSubRectangle.height(), 0, format, type, 0); 5123 sourceSubRectangle.height(), 0, format, type, 0);
5180 texImageByGPU(functionID, texture, target, level, internalformat, type, 0, 5124 texImageByGPU(functionID, texture, target, level, 0, 0, 0, canvas,
5181 0, 0, canvas, adjustedSourceSubRectangle); 5125 adjustedSourceSubRectangle);
5182 } else { 5126 } else {
5183 texImageByGPU(functionID, texture, target, level, GL_RGBA, type, xoffset, 5127 texImageByGPU(functionID, texture, target, level, xoffset, yoffset, 0,
5184 yoffset, 0, canvas, adjustedSourceSubRectangle); 5128 canvas, adjustedSourceSubRectangle);
5185 } 5129 }
5186 } else { 5130 } else {
5187 // 3D functions. 5131 // 3D functions.
5188 5132
5189 // TODO(zmo): Implement GPU-to-GPU copy path (crbug.com/612542). 5133 // TODO(zmo): Implement GPU-to-GPU copy path (crbug.com/612542).
5190 // Note that code will also be needed to copy to layers of 3D 5134 // Note that code will also be needed to copy to layers of 3D
5191 // textures, and elements of 2D texture arrays. 5135 // textures, and elements of 2D texture arrays.
5192 texImageImpl( 5136 texImageImpl(
5193 functionID, target, level, internalformat, xoffset, yoffset, zoffset, 5137 functionID, target, level, internalformat, xoffset, yoffset, zoffset,
5194 format, type, canvas 5138 format, type, canvas
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
5256 if (!validateTexFunc(funcName, functionType, SourceHTMLVideoElement, target, 5200 if (!validateTexFunc(funcName, functionType, SourceHTMLVideoElement, target,
5257 level, internalformat, video->videoWidth(), 5201 level, internalformat, video->videoWidth(),
5258 video->videoHeight(), 1, 0, format, type, xoffset, 5202 video->videoHeight(), 1, 0, format, type, xoffset,
5259 yoffset, zoffset)) 5203 yoffset, zoffset))
5260 return; 5204 return;
5261 5205
5262 bool sourceImageRectIsDefault = 5206 bool sourceImageRectIsDefault =
5263 sourceImageRect == sentinelEmptyRect() || 5207 sourceImageRect == sentinelEmptyRect() ||
5264 sourceImageRect == 5208 sourceImageRect ==
5265 IntRect(0, 0, video->videoWidth(), video->videoHeight()); 5209 IntRect(0, 0, video->videoWidth(), video->videoHeight());
5210 // Format of source video may be 16-bit format, e.g. Y16 format.
5211 // glCopyTextureCHROMIUM will cause precision lost when uploading such video
5212 // texture to half float or float texture.
Zhenyao Mo 2017/03/10 00:10:24 Well, the same can be said for RGBA8 formats, so I
qiankun 2017/03/10 02:48:04 Or we can increase the tolerance in the tests? I m
Zhenyao Mo 2017/03/10 22:45:43 What will be the tolerance to make it pass? I thin
qiankun 2017/03/10 23:54:19 When calling glCopy{Sub}TextureCHROMIUM, source_in
aleksandar.stojiljkovic 2017/03/14 13:43:46 Thanks. Yes, that would break the 16 bit video. An
qiankun 2017/03/31 09:54:05 Done as aleksandar suggested.
5266 if (functionID == TexImage2D && sourceImageRectIsDefault && depth == 1 && 5213 if (functionID == TexImage2D && sourceImageRectIsDefault && depth == 1 &&
5267 GL_TEXTURE_2D == target && Extensions3DUtil::canUseCopyTextureCHROMIUM( 5214 GL_TEXTURE_2D == target &&
5268 target, internalformat, type, level)) { 5215 canUseTexImageByGPU(functionID, internalformat, type) &&
5216 (type != GL_FLOAT && type != GL_HALF_FLOAT &&
5217 type != GL_UNSIGNED_INT_10F_11F_11F_REV)) {
5269 DCHECK_EQ(xoffset, 0); 5218 DCHECK_EQ(xoffset, 0);
5270 DCHECK_EQ(yoffset, 0); 5219 DCHECK_EQ(yoffset, 0);
5271 DCHECK_EQ(zoffset, 0); 5220 DCHECK_EQ(zoffset, 0);
5272 // Go through the fast path doing a GPU-GPU textures copy without a readback 5221 // Go through the fast path doing a GPU-GPU textures copy without a readback
5273 // to system memory if possible. Otherwise, it will fall back to the normal 5222 // to system memory if possible. Otherwise, it will fall back to the normal
5274 // SW path. 5223 // SW path.
5275 5224
5276 // Note that neither 5225 // Note that neither
5277 // HTMLVideoElement::copyVideoTextureToPlatformTexture nor 5226 // HTMLVideoElement::copyVideoTextureToPlatformTexture nor
5278 // ImageBuffer::copyToPlatformTexture allocate the destination texture 5227 // ImageBuffer::copyToPlatformTexture allocate the destination texture
(...skipping 21 matching lines...) Expand all
5300 // implementation to do any necessary color space conversion on the GPU 5249 // implementation to do any necessary color space conversion on the GPU
5301 // (though it may still do a CPU conversion and upload the results). 5250 // (though it may still do a CPU conversion and upload the results).
5302 video->paintCurrentFrame( 5251 video->paintCurrentFrame(
5303 imageBuffer->canvas(), 5252 imageBuffer->canvas(),
5304 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr); 5253 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr);
5305 5254
5306 // This is a straight GPU-GPU copy, any necessary color space conversion 5255 // This is a straight GPU-GPU copy, any necessary color space conversion
5307 // was handled in the paintCurrentFrameInContext() call. 5256 // was handled in the paintCurrentFrameInContext() call.
5308 5257
5309 if (imageBuffer->copyToPlatformTexture( 5258 if (imageBuffer->copyToPlatformTexture(
5310 functionIDToSnapshotReason(functionID), contextGL(), 5259 functionIDToSnapshotReason(functionID), contextGL(), target,
5311 texture->object(), internalformat, type, level, 5260 texture->object(), m_unpackPremultiplyAlpha, m_unpackFlipY,
5312 m_unpackPremultiplyAlpha, m_unpackFlipY, IntPoint(0, 0), 5261 IntPoint(0, 0),
5313 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) { 5262 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) {
5314 return; 5263 return;
5315 } 5264 }
5316 } 5265 }
5317 } 5266 }
5318 } 5267 }
5319 5268
5320 if (sourceImageRectIsDefault) { 5269 if (sourceImageRectIsDefault) {
5321 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. It 5270 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. It
5322 // leaves early for other formats or if frame is stored on GPU. 5271 // leaves early for other formats or if frame is stored on GPU.
(...skipping 11 matching lines...) Expand all
5334 RefPtr<Image> image = videoFrameToImage(video); 5283 RefPtr<Image> image = videoFrameToImage(video);
5335 if (!image) 5284 if (!image)
5336 return; 5285 return;
5337 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, 5286 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset,
5338 zoffset, format, type, image.get(), 5287 zoffset, format, type, image.get(),
5339 WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, 5288 WebGLImageConversion::HtmlDomVideo, m_unpackFlipY,
5340 m_unpackPremultiplyAlpha, sourceImageRect, depth, 5289 m_unpackPremultiplyAlpha, sourceImageRect, depth,
5341 unpackImageHeight); 5290 unpackImageHeight);
5342 } 5291 }
5343 5292
5344 void WebGLRenderingContextBase::texImageBitmapByGPU(ImageBitmap* bitmap, 5293 void WebGLRenderingContextBase::texImageBitmapByGPU(
5345 GLuint targetTexture, 5294 ImageBitmap* bitmap,
5346 GLenum targetInternalformat, 5295 GLenum target,
5347 GLenum targetType, 5296 GLuint targetTexture,
5348 GLint targetLevel, 5297 bool flipY,
5349 bool flipY) { 5298 GLint xoffset,
5350 bitmap->bitmapImage()->copyToTexture(drawingBuffer()->contextProvider(), 5299 GLint yoffset,
5351 targetTexture, targetInternalformat, 5300 const IntRect& sourceSubRectangle) {
5352 targetType, flipY); 5301 bitmap->bitmapImage()->copyToTexture(
5302 drawingBuffer()->contextProvider(), target, targetTexture, flipY,
5303 IntPoint(xoffset, yoffset), sourceSubRectangle);
5353 } 5304 }
5354 5305
5355 void WebGLRenderingContextBase::texImage2D(GLenum target, 5306 void WebGLRenderingContextBase::texImage2D(GLenum target,
5356 GLint level, 5307 GLint level,
5357 GLint internalformat, 5308 GLint internalformat,
5358 GLenum format, 5309 GLenum format,
5359 GLenum type, 5310 GLenum type,
5360 HTMLVideoElement* video, 5311 HTMLVideoElement* video,
5361 ExceptionState& exceptionState) { 5312 ExceptionState& exceptionState) {
5362 texImageHelperHTMLVideoElement(TexImage2D, target, level, internalformat, 5313 texImageHelperHTMLVideoElement(TexImage2D, target, level, internalformat,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
5410 ASSERT(bitmap->bitmapImage()); 5361 ASSERT(bitmap->bitmapImage());
5411 5362
5412 // TODO(kbr): make this work for sub-rectangles of ImageBitmaps. 5363 // TODO(kbr): make this work for sub-rectangles of ImageBitmaps.
5413 if (functionID != TexSubImage3D && functionID != TexImage3D && 5364 if (functionID != TexSubImage3D && functionID != TexImage3D &&
5414 bitmap->isAccelerated() && 5365 bitmap->isAccelerated() &&
5415 canUseTexImageByGPU(functionID, internalformat, type) && 5366 canUseTexImageByGPU(functionID, internalformat, type) &&
5416 !selectingSubRectangle) { 5367 !selectingSubRectangle) {
5417 if (functionID == TexImage2D) { 5368 if (functionID == TexImage2D) {
5418 texImage2DBase(target, level, internalformat, width, height, 0, format, 5369 texImage2DBase(target, level, internalformat, width, height, 0, format,
5419 type, 0); 5370 type, 0);
5420 texImageByGPU(functionID, texture, target, level, internalformat, type, 0, 5371 texImageByGPU(functionID, texture, target, level, 0, 0, 0, bitmap,
5421 0, 0, bitmap, sourceSubRect); 5372 sourceSubRect);
5422 } else if (functionID == TexSubImage2D) { 5373 } else if (functionID == TexSubImage2D) {
5423 texImageByGPU(functionID, texture, target, level, GL_RGBA, type, xoffset, 5374 texImageByGPU(functionID, texture, target, level, xoffset, yoffset, 0,
5424 yoffset, 0, bitmap, sourceSubRect); 5375 bitmap, sourceSubRect);
5425 } 5376 }
5426 return; 5377 return;
5427 } 5378 }
5428 sk_sp<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); 5379 sk_sp<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame();
5429 SkPixmap pixmap; 5380 SkPixmap pixmap;
5430 uint8_t* pixelDataPtr = nullptr; 5381 uint8_t* pixelDataPtr = nullptr;
5431 RefPtr<Uint8Array> pixelData; 5382 RefPtr<Uint8Array> pixelData;
5432 // In the case where an ImageBitmap is not texture backed, peekPixels() always 5383 // In the case where an ImageBitmap is not texture backed, peekPixels() always
5433 // succeed. However, when it is texture backed and !canUseTexImageByGPU, we 5384 // succeed. However, when it is texture backed and !canUseTexImageByGPU, we
5434 // do a GPU read back. 5385 // do a GPU read back.
(...skipping 2400 matching lines...) Expand 10 before | Expand all | Expand 10 after
7835 7786
7836 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( 7787 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(
7837 HTMLCanvasElementOrOffscreenCanvas& result) const { 7788 HTMLCanvasElementOrOffscreenCanvas& result) const {
7838 if (canvas()) 7789 if (canvas())
7839 result.setHTMLCanvasElement(canvas()); 7790 result.setHTMLCanvasElement(canvas());
7840 else 7791 else
7841 result.setOffscreenCanvas(offscreenCanvas()); 7792 result.setOffscreenCanvas(offscreenCanvas());
7842 } 7793 }
7843 7794
7844 } // namespace blink 7795 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698