| OLD | NEW |
| 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 4549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4560 // it later and recalculate it based on the Image whose data we'll | 4560 // it later and recalculate it based on the Image whose data we'll |
| 4561 // upload. It's important that there be no possible differences in | 4561 // upload. It's important that there be no possible differences in |
| 4562 // the logic which computes the image's size. | 4562 // the logic which computes the image's size. |
| 4563 return IntRect(0, 0, -1, -1); | 4563 return IntRect(0, 0, -1, -1); |
| 4564 } | 4564 } |
| 4565 | 4565 |
| 4566 IntRect WebGLRenderingContextBase::safeGetImageSize(Image* image) { | 4566 IntRect WebGLRenderingContextBase::safeGetImageSize(Image* image) { |
| 4567 if (!image) | 4567 if (!image) |
| 4568 return IntRect(); | 4568 return IntRect(); |
| 4569 | 4569 |
| 4570 return IntRect(0, 0, image->width(), image->height()); | 4570 return getTextureSourceSize(image); |
| 4571 } | 4571 } |
| 4572 | 4572 |
| 4573 IntRect WebGLRenderingContextBase::getImageDataSize(ImageData* pixels) { | 4573 IntRect WebGLRenderingContextBase::getImageDataSize(ImageData* pixels) { |
| 4574 DCHECK(pixels); | 4574 DCHECK(pixels); |
| 4575 return IntRect(0, 0, pixels->width(), pixels->height()); | 4575 return getTextureSourceSize(pixels); |
| 4576 } | 4576 } |
| 4577 | 4577 |
| 4578 void WebGLRenderingContextBase::texImageHelperDOMArrayBufferView( | 4578 void WebGLRenderingContextBase::texImageHelperDOMArrayBufferView( |
| 4579 TexImageFunctionID functionID, | 4579 TexImageFunctionID functionID, |
| 4580 GLenum target, | 4580 GLenum target, |
| 4581 GLint level, | 4581 GLint level, |
| 4582 GLint internalformat, | 4582 GLint internalformat, |
| 4583 GLsizei width, | 4583 GLsizei width, |
| 4584 GLsizei height, | 4584 GLsizei height, |
| 4585 GLsizei depth, | 4585 GLsizei depth, |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4808 return; | 4808 return; |
| 4809 if (!validateTexImageBinding(funcName, functionID, target)) | 4809 if (!validateTexImageBinding(funcName, functionID, target)) |
| 4810 return; | 4810 return; |
| 4811 | 4811 |
| 4812 RefPtr<Image> imageForRender = image->cachedImage()->getImage(); | 4812 RefPtr<Image> imageForRender = image->cachedImage()->getImage(); |
| 4813 if (imageForRender && imageForRender->isSVGImage()) | 4813 if (imageForRender && imageForRender->isSVGImage()) |
| 4814 imageForRender = drawImageIntoBuffer( | 4814 imageForRender = drawImageIntoBuffer( |
| 4815 imageForRender.release(), image->width(), image->height(), funcName); | 4815 imageForRender.release(), image->width(), image->height(), funcName); |
| 4816 | 4816 |
| 4817 TexImageFunctionType functionType; | 4817 TexImageFunctionType functionType; |
| 4818 if (functionID == TexImage2D) | 4818 if (functionID == TexImage2D || functionID == TexImage3D) |
| 4819 functionType = TexImage; | 4819 functionType = TexImage; |
| 4820 else | 4820 else |
| 4821 functionType = TexSubImage; | 4821 functionType = TexSubImage; |
| 4822 if (!imageForRender || | 4822 if (!imageForRender || |
| 4823 !validateTexFunc(funcName, functionType, SourceHTMLImageElement, target, | 4823 !validateTexFunc(funcName, functionType, SourceHTMLImageElement, target, |
| 4824 level, internalformat, imageForRender->width(), | 4824 level, internalformat, imageForRender->width(), |
| 4825 imageForRender->height(), depth, 0, format, type, | 4825 imageForRender->height(), depth, 0, format, type, |
| 4826 xoffset, yoffset, zoffset)) | 4826 xoffset, yoffset, zoffset)) |
| 4827 return; | 4827 return; |
| 4828 | 4828 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4856 // TODO(crbug.com/622958): Implement GPU-to-GPU path for WebGL 2 and more | 4856 // TODO(crbug.com/622958): Implement GPU-to-GPU path for WebGL 2 and more |
| 4857 // internal formats. | 4857 // internal formats. |
| 4858 if (functionID == TexSubImage2D && | 4858 if (functionID == TexSubImage2D && |
| 4859 (isWebGL2OrHigher() || extensionEnabled(OESTextureFloatName) || | 4859 (isWebGL2OrHigher() || extensionEnabled(OESTextureFloatName) || |
| 4860 extensionEnabled(OESTextureHalfFloatName) || | 4860 extensionEnabled(OESTextureHalfFloatName) || |
| 4861 extensionEnabled(EXTsRGBName))) | 4861 extensionEnabled(EXTsRGBName))) |
| 4862 return false; | 4862 return false; |
| 4863 return true; | 4863 return true; |
| 4864 } | 4864 } |
| 4865 | 4865 |
| 4866 void WebGLRenderingContextBase::texImageCanvasByGPU(HTMLCanvasElement* canvas, | 4866 void WebGLRenderingContextBase::texImageCanvasByGPU( |
| 4867 GLuint targetTexture, | 4867 HTMLCanvasElement* canvas, |
| 4868 GLenum targetInternalformat, | 4868 GLuint targetTexture, |
| 4869 GLenum targetType, | 4869 GLenum targetInternalformat, |
| 4870 GLint targetLevel) { | 4870 GLenum targetType, |
| 4871 GLint targetLevel, |
| 4872 GLint xoffset, |
| 4873 GLint yoffset, |
| 4874 const IntRect& sourceSubRectangle) { |
| 4871 if (!canvas->is3D()) { | 4875 if (!canvas->is3D()) { |
| 4872 ImageBuffer* buffer = canvas->buffer(); | 4876 ImageBuffer* buffer = canvas->buffer(); |
| 4873 if (buffer && | 4877 if (buffer && |
| 4874 !buffer->copyToPlatformTexture( | 4878 !buffer->copyToPlatformTexture( |
| 4875 contextGL(), targetTexture, targetInternalformat, targetType, | 4879 contextGL(), targetTexture, targetInternalformat, targetType, |
| 4876 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4880 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY, |
| 4881 IntPoint(xoffset, yoffset), sourceSubRectangle)) { |
| 4877 NOTREACHED(); | 4882 NOTREACHED(); |
| 4878 } | 4883 } |
| 4879 } else { | 4884 } else { |
| 4880 WebGLRenderingContextBase* gl = | 4885 WebGLRenderingContextBase* gl = |
| 4881 toWebGLRenderingContextBase(canvas->renderingContext()); | 4886 toWebGLRenderingContextBase(canvas->renderingContext()); |
| 4882 ScopedTexture2DRestorer restorer(gl); | 4887 ScopedTexture2DRestorer restorer(gl); |
| 4883 if (!gl->drawingBuffer()->copyToPlatformTexture( | 4888 if (!gl->drawingBuffer()->copyToPlatformTexture( |
| 4884 contextGL(), targetTexture, targetInternalformat, targetType, | 4889 contextGL(), targetTexture, targetInternalformat, targetType, |
| 4885 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, | 4890 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, |
| 4886 BackBuffer)) { | 4891 IntPoint(xoffset, yoffset), sourceSubRectangle, BackBuffer)) { |
| 4887 NOTREACHED(); | 4892 NOTREACHED(); |
| 4888 } | 4893 } |
| 4889 } | 4894 } |
| 4890 } | 4895 } |
| 4891 | 4896 |
| 4892 void WebGLRenderingContextBase::texImageByGPU(TexImageByGPUType functionType, | 4897 void WebGLRenderingContextBase::texImageByGPU( |
| 4893 WebGLTexture* texture, | 4898 TexImageByGPUType functionType, |
| 4894 GLenum target, | 4899 WebGLTexture* texture, |
| 4895 GLint level, | 4900 GLenum target, |
| 4896 GLint internalformat, | 4901 GLint level, |
| 4897 GLenum type, | 4902 GLint internalformat, |
| 4898 GLint xoffset, | 4903 GLenum type, |
| 4899 GLint yoffset, | 4904 GLint xoffset, |
| 4900 GLint zoffset, | 4905 GLint yoffset, |
| 4901 CanvasImageSource* image) { | 4906 GLint zoffset, |
| 4907 CanvasImageSource* image, |
| 4908 const IntRect& sourceSubRectangle) { |
| 4902 DCHECK(image->isCanvasElement() || image->isImageBitmap()); | 4909 DCHECK(image->isCanvasElement() || image->isImageBitmap()); |
| 4903 int width = image->sourceWidth(); | 4910 int width = sourceSubRectangle.width(); |
| 4904 int height = image->sourceHeight(); | 4911 int height = sourceSubRectangle.height(); |
| 4905 | 4912 |
| 4906 ScopedTexture2DRestorer restorer(this); | 4913 ScopedTexture2DRestorer restorer(this); |
| 4907 | 4914 |
| 4908 GLuint targetTexture = texture->object(); | 4915 GLuint targetTexture = texture->object(); |
| 4909 GLenum targetType = type; | 4916 GLenum targetType = type; |
| 4910 GLenum targetInternalformat = internalformat; | 4917 GLenum targetInternalformat = internalformat; |
| 4911 GLint targetLevel = level; | 4918 GLint targetLevel = level; |
| 4912 bool possibleDirectCopy = false; | 4919 bool possibleDirectCopy = false; |
| 4913 if (functionType == TexImage2DByGPU) { | 4920 if (functionType == TexImage2DByGPU) { |
| 4914 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM( | 4921 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM( |
| 4915 target, internalformat, type, level); | 4922 target, internalformat, type, level); |
| 4916 } | 4923 } |
| 4917 | 4924 |
| 4925 GLint copyXOffset = xoffset; |
| 4926 GLint copyYOffset = yoffset; |
| 4927 |
| 4918 // if direct copy is not possible, create a temporary texture and then copy | 4928 // if direct copy is not possible, create a temporary texture and then copy |
| 4919 // from canvas to temporary texture to target texture. | 4929 // from canvas to temporary texture to target texture. |
| 4920 if (!possibleDirectCopy) { | 4930 if (!possibleDirectCopy) { |
| 4921 targetLevel = 0; | 4931 targetLevel = 0; |
| 4922 targetInternalformat = GL_RGBA; | 4932 targetInternalformat = GL_RGBA; |
| 4923 targetType = GL_UNSIGNED_BYTE; | 4933 targetType = GL_UNSIGNED_BYTE; |
| 4924 contextGL()->GenTextures(1, &targetTexture); | 4934 contextGL()->GenTextures(1, &targetTexture); |
| 4925 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); | 4935 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); |
| 4926 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, | 4936 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, |
| 4927 GL_NEAREST); | 4937 GL_NEAREST); |
| 4928 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, | 4938 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
| 4929 GL_NEAREST); | 4939 GL_NEAREST); |
| 4930 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, | 4940 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, |
| 4931 GL_CLAMP_TO_EDGE); | 4941 GL_CLAMP_TO_EDGE); |
| 4932 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, | 4942 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, |
| 4933 GL_CLAMP_TO_EDGE); | 4943 GL_CLAMP_TO_EDGE); |
| 4934 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, width, | 4944 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, width, |
| 4935 height, 0, GL_RGBA, targetType, 0); | 4945 height, 0, GL_RGBA, targetType, 0); |
| 4946 copyXOffset = 0; |
| 4947 copyYOffset = 0; |
| 4936 } | 4948 } |
| 4937 | 4949 |
| 4938 if (image->isCanvasElement()) | 4950 if (image->isCanvasElement()) { |
| 4939 texImageCanvasByGPU(static_cast<HTMLCanvasElement*>(image), targetTexture, | 4951 texImageCanvasByGPU(static_cast<HTMLCanvasElement*>(image), targetTexture, |
| 4940 targetInternalformat, targetType, targetLevel); | 4952 targetInternalformat, targetType, targetLevel, |
| 4941 else | 4953 copyXOffset, copyYOffset, sourceSubRectangle); |
| 4954 } else { |
| 4942 texImageBitmapByGPU(static_cast<ImageBitmap*>(image), targetTexture, | 4955 texImageBitmapByGPU(static_cast<ImageBitmap*>(image), targetTexture, |
| 4943 targetInternalformat, targetType, targetLevel, | 4956 targetInternalformat, targetType, targetLevel, |
| 4944 !m_unpackFlipY); | 4957 !m_unpackFlipY); |
| 4958 } |
| 4945 | 4959 |
| 4946 if (!possibleDirectCopy) { | 4960 if (!possibleDirectCopy) { |
| 4947 GLuint tmpFBO; | 4961 GLuint tmpFBO; |
| 4948 contextGL()->GenFramebuffers(1, &tmpFBO); | 4962 contextGL()->GenFramebuffers(1, &tmpFBO); |
| 4949 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO); | 4963 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO); |
| 4950 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 4964 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 4951 GL_TEXTURE_2D, targetTexture, 0); | 4965 GL_TEXTURE_2D, targetTexture, 0); |
| 4952 contextGL()->BindTexture(texture->getTarget(), texture->object()); | 4966 contextGL()->BindTexture(texture->getTarget(), texture->object()); |
| 4953 if (functionType == TexImage2DByGPU) { | 4967 if (functionType == TexImage2DByGPU) { |
| 4954 contextGL()->CopyTexSubImage2D(target, level, 0, 0, 0, 0, width, height); | 4968 contextGL()->CopyTexSubImage2D(target, level, 0, 0, 0, 0, width, height); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4971 TexImageFunctionID functionID, | 4985 TexImageFunctionID functionID, |
| 4972 GLenum target, | 4986 GLenum target, |
| 4973 GLint level, | 4987 GLint level, |
| 4974 GLint internalformat, | 4988 GLint internalformat, |
| 4975 GLenum format, | 4989 GLenum format, |
| 4976 GLenum type, | 4990 GLenum type, |
| 4977 GLint xoffset, | 4991 GLint xoffset, |
| 4978 GLint yoffset, | 4992 GLint yoffset, |
| 4979 GLint zoffset, | 4993 GLint zoffset, |
| 4980 HTMLCanvasElement* canvas, | 4994 HTMLCanvasElement* canvas, |
| 4995 const IntRect& sourceSubRectangle, |
| 4996 GLsizei depth, |
| 4997 GLint unpackImageHeight, |
| 4981 ExceptionState& exceptionState) { | 4998 ExceptionState& exceptionState) { |
| 4982 const char* funcName = getTexImageFunctionName(functionID); | 4999 const char* funcName = getTexImageFunctionName(functionID); |
| 4983 if (isContextLost()) | 5000 if (isContextLost()) |
| 4984 return; | 5001 return; |
| 4985 if (!validateHTMLCanvasElement(funcName, canvas, exceptionState)) | 5002 if (!validateHTMLCanvasElement(funcName, canvas, exceptionState)) |
| 4986 return; | 5003 return; |
| 4987 WebGLTexture* texture = validateTexImageBinding(funcName, functionID, target); | 5004 WebGLTexture* texture = validateTexImageBinding(funcName, functionID, target); |
| 4988 if (!texture) | 5005 if (!texture) |
| 4989 return; | 5006 return; |
| 4990 TexImageFunctionType functionType; | 5007 TexImageFunctionType functionType; |
| 4991 if (functionID == TexImage2D) | 5008 if (functionID == TexImage2D) |
| 4992 functionType = TexImage; | 5009 functionType = TexImage; |
| 4993 else | 5010 else |
| 4994 functionType = TexSubImage; | 5011 functionType = TexSubImage; |
| 4995 if (!validateTexFunc(funcName, functionType, SourceHTMLCanvasElement, target, | 5012 if (!validateTexFunc(funcName, functionType, SourceHTMLCanvasElement, target, |
| 4996 level, internalformat, canvas->width(), canvas->height(), | 5013 level, internalformat, canvas->width(), canvas->height(), |
| 4997 1, 0, format, type, xoffset, yoffset, zoffset)) | 5014 depth, 0, format, type, xoffset, yoffset, zoffset)) |
| 4998 return; | 5015 return; |
| 5016 |
| 5017 // Note that the sub-rectangle validation is needed for the GPU-GPU |
| 5018 // copy case, but is redundant for the software upload case |
| 5019 // (texImageImpl). |
| 5020 bool selectingSubRectangle = false; |
| 5021 if (!validateTexImageSubRectangle( |
| 5022 funcName, functionID, canvas, sourceSubRectangle, depth, |
| 5023 unpackImageHeight, &selectingSubRectangle)) { |
| 5024 return; |
| 5025 } |
| 5026 |
| 5027 if (functionID == TexImage3D || functionID == TexSubImage3D) { |
| 5028 DCHECK_GE(unpackImageHeight, 0); |
| 5029 |
| 5030 // Verify that the image data can cover the required depth. |
| 5031 CheckedNumeric<GLint> maxDepthSupported = 1; |
| 5032 if (unpackImageHeight) { |
| 5033 maxDepthSupported = sourceSubRectangle.height(); |
| 5034 maxDepthSupported /= unpackImageHeight; |
| 5035 } |
| 5036 |
| 5037 if (!maxDepthSupported.IsValid() || |
| 5038 maxDepthSupported.ValueOrDie() < depth) { |
| 5039 synthesizeGLError( |
| 5040 GL_INVALID_OPERATION, funcName, |
| 5041 "Not enough data supplied to upload to a 3D texture with depth > 1"); |
| 5042 return; |
| 5043 } |
| 5044 } else { |
| 5045 DCHECK_EQ(depth, 1); |
| 5046 DCHECK_EQ(unpackImageHeight, 0); |
| 5047 } |
| 5048 |
| 4999 if (functionID == TexImage2D || functionID == TexSubImage2D) { | 5049 if (functionID == TexImage2D || functionID == TexSubImage2D) { |
| 5000 // texImageByGPU relies on copyTextureCHROMIUM which doesn't support | 5050 // texImageByGPU relies on copyTextureCHROMIUM which doesn't support |
| 5001 // float/integer/sRGB internal format. | 5051 // float/integer/sRGB internal format. |
| 5002 // TODO(crbug.com/622958): relax the constrains if copyTextureCHROMIUM is | 5052 // TODO(crbug.com/622958): relax the constrains if copyTextureCHROMIUM is |
| 5003 // upgraded to handle more formats. | 5053 // upgraded to handle more formats. |
| 5004 if (!canvas->renderingContext() || | 5054 if (!canvas->renderingContext() || |
| 5005 !canvas->renderingContext()->isAccelerated() || | 5055 !canvas->renderingContext()->isAccelerated() || |
| 5006 !canUseTexImageByGPU(functionID, internalformat, type)) { | 5056 !canUseTexImageByGPU(functionID, internalformat, type)) { |
| 5007 // 2D canvas has only FrontBuffer. | 5057 // 2D canvas has only FrontBuffer. |
| 5008 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, | 5058 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, |
| 5009 zoffset, format, type, | 5059 zoffset, format, type, |
| 5010 canvas->copiedImage(FrontBuffer, PreferAcceleration).get(), | 5060 canvas->copiedImage(FrontBuffer, PreferAcceleration).get(), |
| 5011 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, | 5061 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, |
| 5012 m_unpackPremultiplyAlpha, | 5062 m_unpackPremultiplyAlpha, sourceSubRectangle, 1, 0); |
| 5013 IntRect(0, 0, canvas->width(), canvas->height()), 1, 0); | |
| 5014 return; | 5063 return; |
| 5015 } | 5064 } |
| 5016 | 5065 |
| 5066 // The GPU-GPU copy path uses the Y-up coordinate system. |
| 5067 IntRect adjustedSourceSubRectangle = sourceSubRectangle; |
| 5068 if (!m_unpackFlipY) { |
| 5069 adjustedSourceSubRectangle.setY(canvas->height() - |
| 5070 adjustedSourceSubRectangle.maxY()); |
| 5071 } |
| 5072 |
| 5017 if (functionID == TexImage2D) { | 5073 if (functionID == TexImage2D) { |
| 5018 texImage2DBase(target, level, internalformat, canvas->width(), | 5074 texImage2DBase(target, level, internalformat, sourceSubRectangle.width(), |
| 5019 canvas->height(), 0, format, type, 0); | 5075 sourceSubRectangle.height(), 0, format, type, 0); |
| 5020 texImageByGPU(TexImage2DByGPU, texture, target, level, internalformat, | 5076 texImageByGPU(TexImage2DByGPU, texture, target, level, internalformat, |
| 5021 type, 0, 0, 0, canvas); | 5077 type, 0, 0, 0, canvas, adjustedSourceSubRectangle); |
| 5022 } else { | 5078 } else { |
| 5023 texImageByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, type, | 5079 texImageByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, type, |
| 5024 xoffset, yoffset, 0, canvas); | 5080 xoffset, yoffset, 0, canvas, adjustedSourceSubRectangle); |
| 5025 } | 5081 } |
| 5026 } else { | 5082 } else { |
| 5027 DCHECK_EQ(functionID, TexSubImage3D); | 5083 // 3D functions. |
| 5028 // FIXME: Implement GPU-to-GPU copy path (crbug.com/586269). | 5084 |
| 5029 texImageImpl(TexSubImage3D, target, level, 0, xoffset, yoffset, zoffset, | 5085 // TODO(zmo): Implement GPU-to-GPU copy path (crbug.com/612542). |
| 5030 format, type, | 5086 // Note that code will also be needed to copy to layers of 3D |
| 5087 // textures, and elements of 2D texture arrays. |
| 5088 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, |
| 5089 zoffset, format, type, |
| 5031 canvas->copiedImage(FrontBuffer, PreferAcceleration).get(), | 5090 canvas->copiedImage(FrontBuffer, PreferAcceleration).get(), |
| 5032 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, | 5091 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, |
| 5033 m_unpackPremultiplyAlpha, | 5092 m_unpackPremultiplyAlpha, sourceSubRectangle, depth, |
| 5034 IntRect(0, 0, canvas->width(), canvas->height()), 1, 0); | 5093 unpackImageHeight); |
| 5035 } | 5094 } |
| 5036 } | 5095 } |
| 5037 | 5096 |
| 5038 void WebGLRenderingContextBase::texImage2D(GLenum target, | 5097 void WebGLRenderingContextBase::texImage2D(GLenum target, |
| 5039 GLint level, | 5098 GLint level, |
| 5040 GLint internalformat, | 5099 GLint internalformat, |
| 5041 GLenum format, | 5100 GLenum format, |
| 5042 GLenum type, | 5101 GLenum type, |
| 5043 HTMLCanvasElement* canvas, | 5102 HTMLCanvasElement* canvas, |
| 5044 ExceptionState& exceptionState) { | 5103 ExceptionState& exceptionState) { |
| 5045 texImageHelperHTMLCanvasElement(TexImage2D, target, level, internalformat, | 5104 texImageHelperHTMLCanvasElement( |
| 5046 format, type, 0, 0, 0, canvas, | 5105 TexImage2D, target, level, internalformat, format, type, 0, 0, 0, canvas, |
| 5047 exceptionState); | 5106 getTextureSourceSize(canvas), 1, 0, exceptionState); |
| 5048 } | 5107 } |
| 5049 | 5108 |
| 5050 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage( | 5109 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage( |
| 5051 HTMLVideoElement* video) { | 5110 HTMLVideoElement* video) { |
| 5052 IntSize size(video->videoWidth(), video->videoHeight()); | 5111 IntSize size(video->videoWidth(), video->videoHeight()); |
| 5053 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); | 5112 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); |
| 5054 if (!buf) { | 5113 if (!buf) { |
| 5055 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); | 5114 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); |
| 5056 return nullptr; | 5115 return nullptr; |
| 5057 } | 5116 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5118 // WebMediaPlayer implementation to do any necessary color space | 5177 // WebMediaPlayer implementation to do any necessary color space |
| 5119 // conversion on the GPU (though it | 5178 // conversion on the GPU (though it |
| 5120 // may still do a CPU conversion and upload the results). | 5179 // may still do a CPU conversion and upload the results). |
| 5121 video->paintCurrentFrame( | 5180 video->paintCurrentFrame( |
| 5122 imageBuffer->canvas(), | 5181 imageBuffer->canvas(), |
| 5123 IntRect(0, 0, video->videoWidth(), video->videoHeight()), | 5182 IntRect(0, 0, video->videoWidth(), video->videoHeight()), |
| 5124 nullptr); | 5183 nullptr); |
| 5125 | 5184 |
| 5126 // This is a straight GPU-GPU copy, any necessary color space | 5185 // This is a straight GPU-GPU copy, any necessary color space |
| 5127 // conversion was handled in the paintCurrentFrameInContext() call. | 5186 // conversion was handled in the paintCurrentFrameInContext() call. |
| 5187 |
| 5188 // Note that copyToPlatformTexture no longer allocates the |
| 5189 // destination texture. |
| 5190 texImage2DBase(target, level, internalformat, video->videoWidth(), |
| 5191 video->videoHeight(), 0, format, type, nullptr); |
| 5192 |
| 5128 if (imageBuffer->copyToPlatformTexture( | 5193 if (imageBuffer->copyToPlatformTexture( |
| 5129 contextGL(), texture->object(), internalformat, type, level, | 5194 contextGL(), texture->object(), internalformat, type, level, |
| 5130 m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 5195 m_unpackPremultiplyAlpha, m_unpackFlipY, IntPoint(0, 0), |
| 5196 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) { |
| 5131 return; | 5197 return; |
| 5132 } | 5198 } |
| 5133 } | 5199 } |
| 5134 } | 5200 } |
| 5135 } | 5201 } |
| 5136 } | 5202 } |
| 5137 | 5203 |
| 5138 RefPtr<Image> image = videoFrameToImage(video); | 5204 RefPtr<Image> image = videoFrameToImage(video); |
| 5139 if (!image) | 5205 if (!image) |
| 5140 return; | 5206 return; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5197 format, type, xoffset, yoffset, zoffset)) | 5263 format, type, xoffset, yoffset, zoffset)) |
| 5198 return; | 5264 return; |
| 5199 ASSERT(bitmap->bitmapImage()); | 5265 ASSERT(bitmap->bitmapImage()); |
| 5200 | 5266 |
| 5201 if (functionID != TexSubImage3D && bitmap->isAccelerated() && | 5267 if (functionID != TexSubImage3D && bitmap->isAccelerated() && |
| 5202 canUseTexImageByGPU(functionID, internalformat, type)) { | 5268 canUseTexImageByGPU(functionID, internalformat, type)) { |
| 5203 if (functionID == TexImage2D) { | 5269 if (functionID == TexImage2D) { |
| 5204 texImage2DBase(target, level, internalformat, bitmap->width(), | 5270 texImage2DBase(target, level, internalformat, bitmap->width(), |
| 5205 bitmap->height(), 0, format, type, 0); | 5271 bitmap->height(), 0, format, type, 0); |
| 5206 texImageByGPU(TexImage2DByGPU, texture, target, level, internalformat, | 5272 texImageByGPU(TexImage2DByGPU, texture, target, level, internalformat, |
| 5207 type, 0, 0, 0, bitmap); | 5273 type, 0, 0, 0, bitmap, getTextureSourceSize(bitmap)); |
| 5208 } else if (functionID == TexSubImage2D) { | 5274 } else if (functionID == TexSubImage2D) { |
| 5209 texImageByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, type, | 5275 texImageByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, type, |
| 5210 xoffset, yoffset, 0, bitmap); | 5276 xoffset, yoffset, 0, bitmap, getTextureSourceSize(bitmap)); |
| 5211 } | 5277 } |
| 5212 return; | 5278 return; |
| 5213 } | 5279 } |
| 5214 sk_sp<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); | 5280 sk_sp<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); |
| 5215 SkPixmap pixmap; | 5281 SkPixmap pixmap; |
| 5216 uint8_t* pixelDataPtr = nullptr; | 5282 uint8_t* pixelDataPtr = nullptr; |
| 5217 RefPtr<Uint8Array> pixelData; | 5283 RefPtr<Uint8Array> pixelData; |
| 5218 // In the case where an ImageBitmap is not texture backed, peekPixels() always | 5284 // In the case where an ImageBitmap is not texture backed, peekPixels() always |
| 5219 // succeed. However, when it is texture backed and !canUseTexImageByGPU, we | 5285 // succeed. However, when it is texture backed and !canUseTexImageByGPU, we |
| 5220 // do a GPU read back. | 5286 // do a GPU read back. |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5402 } | 5468 } |
| 5403 | 5469 |
| 5404 void WebGLRenderingContextBase::texSubImage2D(GLenum target, | 5470 void WebGLRenderingContextBase::texSubImage2D(GLenum target, |
| 5405 GLint level, | 5471 GLint level, |
| 5406 GLint xoffset, | 5472 GLint xoffset, |
| 5407 GLint yoffset, | 5473 GLint yoffset, |
| 5408 GLenum format, | 5474 GLenum format, |
| 5409 GLenum type, | 5475 GLenum type, |
| 5410 HTMLCanvasElement* canvas, | 5476 HTMLCanvasElement* canvas, |
| 5411 ExceptionState& exceptionState) { | 5477 ExceptionState& exceptionState) { |
| 5412 texImageHelperHTMLCanvasElement(TexSubImage2D, target, level, 0, format, type, | 5478 texImageHelperHTMLCanvasElement( |
| 5413 xoffset, yoffset, 0, canvas, exceptionState); | 5479 TexSubImage2D, target, level, 0, format, type, xoffset, yoffset, 0, |
| 5480 canvas, getTextureSourceSize(canvas), 1, 0, exceptionState); |
| 5414 } | 5481 } |
| 5415 | 5482 |
| 5416 void WebGLRenderingContextBase::texSubImage2D(GLenum target, | 5483 void WebGLRenderingContextBase::texSubImage2D(GLenum target, |
| 5417 GLint level, | 5484 GLint level, |
| 5418 GLint xoffset, | 5485 GLint xoffset, |
| 5419 GLint yoffset, | 5486 GLint yoffset, |
| 5420 GLenum format, | 5487 GLenum format, |
| 5421 GLenum type, | 5488 GLenum type, |
| 5422 HTMLVideoElement* video, | 5489 HTMLVideoElement* video, |
| 5423 ExceptionState& exceptionState) { | 5490 ExceptionState& exceptionState) { |
| (...skipping 2236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7660 | 7727 |
| 7661 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( | 7728 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( |
| 7662 HTMLCanvasElementOrOffscreenCanvas& result) const { | 7729 HTMLCanvasElementOrOffscreenCanvas& result) const { |
| 7663 if (canvas()) | 7730 if (canvas()) |
| 7664 result.setHTMLCanvasElement(canvas()); | 7731 result.setHTMLCanvasElement(canvas()); |
| 7665 else | 7732 else |
| 7666 result.setOffscreenCanvas(getOffscreenCanvas()); | 7733 result.setOffscreenCanvas(getOffscreenCanvas()); |
| 7667 } | 7734 } |
| 7668 | 7735 |
| 7669 } // namespace blink | 7736 } // namespace blink |
| OLD | NEW |