Chromium Code Reviews| 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 4033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4044 if (!image->currentFrameKnownToBeOpaque()) | 4044 if (!image->currentFrameKnownToBeOpaque()) |
| 4045 buf->canvas()->clear(SK_ColorTRANSPARENT); | 4045 buf->canvas()->clear(SK_ColorTRANSPARENT); |
| 4046 | 4046 |
| 4047 IntRect srcRect(IntPoint(), image->size()); | 4047 IntRect srcRect(IntPoint(), image->size()); |
| 4048 IntRect destRect(0, 0, size.width(), size.height()); | 4048 IntRect destRect(0, 0, size.width(), size.height()); |
| 4049 SkPaint paint; | 4049 SkPaint paint; |
| 4050 image->draw(buf->canvas(), paint, destRect, srcRect, DoNotRespectImageOrient ation, Image::DoNotClampImageToSourceRect); | 4050 image->draw(buf->canvas(), paint, destRect, srcRect, DoNotRespectImageOrient ation, Image::DoNotClampImageToSourceRect); |
| 4051 return buf->newImageSnapshot(); | 4051 return buf->newImageSnapshot(); |
| 4052 } | 4052 } |
| 4053 | 4053 |
| 4054 void WebGLRenderingContextBase::texImageHelperDOMArrayBufferView(const char* fun cType, GLenum target, GLint level, GLint internalformat, | |
| 4055 GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLs izei depth, | |
| 4056 GLint xoffset, GLint yoffset, GLint zoffset, DOMArrayBufferView* pixels) | |
| 4057 { | |
| 4058 if (isContextLost()) | |
| 4059 return; | |
| 4060 if ((!strcmp(funcType, "texImage2D") || !strcmp(funcType, "texSubImage2D")) && !validateTexture2DBinding(funcType, target)) | |
| 4061 return; | |
| 4062 if ((!strcmp(funcType, "texImage3D") || !strcmp(funcType, "texSubImage3D")) && !validateTexture3DBinding(funcType, target)) | |
|
xidachen
2016/05/31 02:11:41
Yes, the error is because validateTexture3DBinding
| |
| 4063 return; | |
| 4064 TexImageFunctionType functionType; | |
| 4065 if (!strcmp(funcType, "texImage2D") || !strcmp(funcType, "texImage3D")) | |
| 4066 functionType = TexImage; | |
| 4067 else | |
| 4068 functionType = TexSubImage; | |
| 4069 if (!validateTexFunc(funcType, functionType, SourceArrayBufferView, target, level, internalformat, width, height, depth, border, format, type, xoffset, yoff set, zoffset)) | |
| 4070 return; | |
| 4071 TexImageDimension sourceType; | |
| 4072 if (!strcmp(funcType, "texImage2D") || !strcmp(funcType, "texSubImage2D")) | |
| 4073 sourceType = Tex2D; | |
| 4074 else | |
| 4075 sourceType = Tex3D; | |
| 4076 if (!validateTexFuncData(funcType, sourceType, level, width, height, depth, format, type, pixels, NullAllowed)) | |
| 4077 return; | |
| 4078 void* data = pixels ? pixels->baseAddress() : 0; | |
| 4079 Vector<uint8_t> tempData; | |
| 4080 bool changeUnpackAlignment = false; | |
| 4081 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { | |
| 4082 if (!strcmp(funcType, "texImage2D") || !strcmp(funcType, "texSubImage2D" )) { | |
| 4083 if (!WebGLImageConversion::extractTextureData(width, height, format, type, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempDat a)) | |
| 4084 return; | |
| 4085 data = tempData.data(); | |
| 4086 } else { | |
| 4087 NOTIMPLEMENTED(); | |
| 4088 if (!strcmp(funcType, "texImage3D")) | |
| 4089 return; | |
| 4090 } | |
| 4091 changeUnpackAlignment = true; | |
| 4092 } | |
| 4093 if (!strcmp(funcType, "texImage3D")) { | |
| 4094 contextGL()->TexImage3D(target, level, convertTexInternalFormat(internal format, type), width, height, depth, border, format, type, data); | |
| 4095 return; | |
| 4096 } | |
| 4097 | |
| 4098 if (changeUnpackAlignment) | |
| 4099 resetUnpackParameters(); | |
| 4100 if (!strcmp(funcType, "texImage2D")) | |
| 4101 texImage2DBase(target, level, internalformat, width, height, border, for mat, type, data); | |
| 4102 else if (!strcmp(funcType, "texSubImage2D")) | |
| 4103 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, heigh t, format, type, data); | |
| 4104 else | |
| 4105 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, wid th, height, depth, format, type, data); | |
| 4106 if (changeUnpackAlignment) | |
| 4107 restoreUnpackParameters(); | |
| 4108 } | |
| 4109 | |
| 4054 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, | 4110 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, |
| 4055 GLsizei width, GLsizei height, GLint border, | 4111 GLsizei width, GLsizei height, GLint border, |
| 4056 GLenum format, GLenum type, DOMArrayBufferView* pixels) | 4112 GLenum format, GLenum type, DOMArrayBufferView* pixels) |
| 4057 { | 4113 { |
| 4058 if (isContextLost()) | 4114 texImageHelperDOMArrayBufferView("texImage2D", target, level, internalformat , width, height, border, format, type, 1, 0, 0, 0, pixels); |
| 4059 return; | |
| 4060 if (!validateTexture2DBinding("texImage2D", target)) | |
| 4061 return; | |
| 4062 if (!validateTexFunc("texImage2D", TexImage, SourceArrayBufferView, target, level, internalformat, width, height, 1, border, format, type, 0, 0, 0)) | |
| 4063 return; | |
| 4064 if (!validateTexFuncData("texImage2D", Tex2D, level, width, height, 1, forma t, type, pixels, NullAllowed)) | |
| 4065 return; | |
| 4066 void* data = pixels ? pixels->baseAddress() : 0; | |
| 4067 Vector<uint8_t> tempData; | |
| 4068 bool changeUnpackAlignment = false; | |
| 4069 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { | |
| 4070 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData)) | |
| 4071 return; | |
| 4072 data = tempData.data(); | |
| 4073 changeUnpackAlignment = true; | |
| 4074 } | |
| 4075 if (changeUnpackAlignment) | |
| 4076 resetUnpackParameters(); | |
| 4077 texImage2DBase(target, level, internalformat, width, height, border, format, type, data); | |
| 4078 if (changeUnpackAlignment) | |
| 4079 restoreUnpackParameters(); | |
| 4080 } | 4115 } |
| 4081 | 4116 |
| 4082 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, | 4117 void WebGLRenderingContextBase::texImageHelperImageData(const char* funcType, GL enum target, GLint level, GLint internalformat, |
| 4083 GLenum format, GLenum type, ImageData* pixels) | 4118 GLint border, GLenum format, GLenum type, GLsizei depth, |
| 4119 GLint xoffset, GLint yoffset, GLint zoffset, ImageData* pixels) | |
| 4084 { | 4120 { |
| 4085 if (isContextLost()) | 4121 if (isContextLost()) |
| 4086 return; | 4122 return; |
| 4087 if (!pixels) { | 4123 if (!pixels) { |
| 4088 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "no image data"); | 4124 synthesizeGLError(GL_INVALID_VALUE, funcType, "no image data"); |
| 4089 return; | 4125 return; |
| 4090 } | 4126 } |
| 4091 if (pixels->data()->bufferBase()->isNeutered()) { | 4127 if (pixels->data()->bufferBase()->isNeutered()) { |
| 4092 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "The source data has b een neutered."); | 4128 synthesizeGLError(GL_INVALID_VALUE, funcType, "The source data has been neutered."); |
| 4093 return; | 4129 return; |
| 4094 } | 4130 } |
| 4095 if (!validateTexture2DBinding("texImage2D", target)) | 4131 if ((!strcmp(funcType, "texImage2D") || !strcmp(funcType, "texSubImage2D")) && !validateTexture2DBinding(funcType, target)) |
| 4096 return; | 4132 return; |
| 4097 if (!validateTexFunc("texImage2D", TexImage, SourceImageData, target, level, internalformat, pixels->width(), pixels->height(), 1, 0, format, type, 0, 0, 0) ) | 4133 if (!strcmp(funcType, "texSubImage3D") && !validateTexture3DBinding(funcType , target)) |
| 4134 return; | |
| 4135 TexImageFunctionType functionType; | |
| 4136 if (!strcmp(funcType, "texImage2D")) | |
| 4137 functionType = TexImage; | |
| 4138 else | |
| 4139 functionType = TexSubImage; | |
| 4140 if (!validateTexFunc(funcType, functionType, SourceImageData, target, level, internalformat, pixels->width(), pixels->height(), depth, border, format, type, xoffset, yoffset, zoffset)) | |
| 4098 return; | 4141 return; |
| 4099 Vector<uint8_t> data; | 4142 Vector<uint8_t> data; |
| 4100 bool needConversion = true; | 4143 bool needConversion = true; |
| 4101 // The data from ImageData is always of format RGBA8. | 4144 // The data from ImageData is always of format RGBA8. |
| 4102 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. | 4145 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. |
| 4103 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { | 4146 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { |
| 4104 needConversion = false; | 4147 needConversion = false; |
| 4105 } else { | 4148 } else { |
| 4106 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | 4149 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { |
| 4107 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement ed. | 4150 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement ed. |
| 4108 type = GL_FLOAT; | 4151 type = GL_FLOAT; |
| 4109 } | 4152 } |
| 4110 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u npackFlipY, m_unpackPremultiplyAlpha, data)) { | 4153 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u npackFlipY, m_unpackPremultiplyAlpha, data)) { |
| 4111 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); | 4154 synthesizeGLError(GL_INVALID_VALUE, funcType, "bad image data"); |
| 4112 return; | 4155 return; |
| 4113 } | 4156 } |
| 4114 } | 4157 } |
| 4115 resetUnpackParameters(); | 4158 resetUnpackParameters(); |
| 4116 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data()); | 4159 if (!strcmp(funcType, "texImage2D")) |
| 4160 texImage2DBase(target, level, internalformat, pixels->width(), pixels->h eight(), border, format, type, needConversion ? data.data() : pixels->data()->da ta()); | |
| 4161 else if (!strcmp(funcType, "texSubImage2D")) | |
| 4162 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, pixels->widt h(), pixels->height(), format, type, needConversion ? data.data() : pixels->data ()->data()); | |
| 4163 else // must be "texSubImage3D" | |
| 4164 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, pix els->width(), pixels->height(), depth, format, type, needConversion ? data.data( ) : pixels->data()->data()); | |
| 4117 restoreUnpackParameters(); | 4165 restoreUnpackParameters(); |
| 4118 } | 4166 } |
| 4119 | 4167 |
| 4120 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, | 4168 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, |
| 4169 GLenum format, GLenum type, ImageData* pixels) | |
| 4170 { | |
| 4171 texImageHelperImageData("texImage2D", target, level, internalformat, 0, form at, type, 1, 0, 0, 0, pixels); | |
| 4172 } | |
| 4173 | |
| 4174 bool WebGLRenderingContextBase::texImageHelperHTMLImageElement(const char* funcT ype, GLenum target, GLint level, GLint internalformat, | |
| 4175 GLenum format, GLenum type, GLint xoffset, GLint yoffset, GLint zoffset, HTM LImageElement* image, ExceptionState& exceptionState) | |
| 4176 { | |
| 4177 if (isContextLost()) | |
| 4178 return false; | |
| 4179 if (!validateHTMLImageElement(funcType, image, exceptionState)) | |
| 4180 return false; | |
| 4181 if ((!strcmp(funcType, "texImage2D") || !strcmp(funcType, "texSubImage2D")) && !validateTexture2DBinding(funcType, target)) | |
| 4182 return false; | |
| 4183 if (!strcmp(funcType, "texSubImage3D") && !validateTexture3DBinding(funcType , target)) | |
| 4184 return false; | |
| 4185 if (!strcmp(funcType, "texSubImage3D")) | |
| 4186 return true; | |
| 4187 | |
| 4188 RefPtr<Image> imageForRender = image->cachedImage()->getImage(); | |
| 4189 if (imageForRender && imageForRender->isSVGImage()) | |
| 4190 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), funcType); | |
| 4191 | |
| 4192 TexImageFunctionType functionType; | |
| 4193 if (!strcmp(funcType, "texImage2D")) | |
| 4194 functionType = TexImage; | |
| 4195 else | |
| 4196 functionType = TexSubImage; | |
| 4197 if (!imageForRender || !validateTexFunc(funcType, functionType, SourceHTMLIm ageElement, target, level, internalformat, imageForRender->width(), imageForRend er->height(), 1, 0, format, type, xoffset, yoffset, zoffset)) | |
| 4198 return false; | |
| 4199 | |
| 4200 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | |
| 4201 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. | |
| 4202 type = GL_FLOAT; | |
| 4203 } | |
| 4204 if (!strcmp(funcType, "texImage2D")) | |
| 4205 texImage2DImpl(target, level, internalformat, format, type, imageForRend er.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiply Alpha); | |
| 4206 else if (!strcmp(funcType, "texSubImage2D")) | |
| 4207 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageFo rRender.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremul tiplyAlpha); | |
| 4208 return true; | |
| 4209 } | |
| 4210 | |
| 4211 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, | |
| 4121 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) | 4212 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) |
| 4122 { | 4213 { |
| 4123 if (isContextLost()) | 4214 texImageHelperHTMLImageElement("texImage2D", target, level, internalformat, format, type, 0, 0, 0, image, exceptionState); |
| 4124 return; | |
| 4125 if (!validateHTMLImageElement("texImage2D", image, exceptionState)) | |
| 4126 return; | |
| 4127 if (!validateTexture2DBinding("texImage2D", target)) | |
| 4128 return; | |
| 4129 | |
| 4130 RefPtr<Image> imageForRender = image->cachedImage()->getImage(); | |
| 4131 if (imageForRender && imageForRender->isSVGImage()) | |
| 4132 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texImage2D"); | |
| 4133 | |
| 4134 if (!imageForRender || !validateTexFunc("texImage2D", TexImage, SourceHTMLIm ageElement, target, level, internalformat, imageForRender->width(), imageForRend er->height(), 1, 0, format, type, 0, 0, 0)) | |
| 4135 return; | |
| 4136 | |
| 4137 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | |
| 4138 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. | |
| 4139 type = GL_FLOAT; | |
| 4140 } | |
| 4141 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g et(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlph a); | |
| 4142 } | 4215 } |
| 4143 | 4216 |
| 4144 bool WebGLRenderingContextBase::canUseTexImageCanvasByGPU(GLint internalformat, GLenum type) | 4217 bool WebGLRenderingContextBase::canUseTexImageCanvasByGPU(GLint internalformat, GLenum type) |
| 4145 { | 4218 { |
| 4146 if (isFloatType(type) || isIntegerFormat(internalformat) || isSRGBFormat(int ernalformat)) | 4219 if (isFloatType(type) || isIntegerFormat(internalformat) || isSRGBFormat(int ernalformat)) |
| 4147 return false; | 4220 return false; |
| 4148 return true; | 4221 return true; |
| 4149 } | 4222 } |
| 4150 | 4223 |
| 4151 void WebGLRenderingContextBase::texImageCanvasByGPU(TexImageByGPUType functionTy pe, WebGLTexture* texture, GLenum target, | 4224 void WebGLRenderingContextBase::texImageCanvasByGPU(TexImageByGPUType functionTy pe, WebGLTexture* texture, GLenum target, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4205 } else if (functionType == TexSubImage3DByGPU) { | 4278 } else if (functionType == TexSubImage3DByGPU) { |
| 4206 contextGL()->CopyTexSubImage3D(target, level, xoffset, yoffset, zoff set, 0, 0, canvas->width(), canvas->height()); | 4279 contextGL()->CopyTexSubImage3D(target, level, xoffset, yoffset, zoff set, 0, 0, canvas->width(), canvas->height()); |
| 4207 } | 4280 } |
| 4208 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); | 4281 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); |
| 4209 restoreCurrentFramebuffer(); | 4282 restoreCurrentFramebuffer(); |
| 4210 contextGL()->DeleteFramebuffers(1, &tmpFBO); | 4283 contextGL()->DeleteFramebuffers(1, &tmpFBO); |
| 4211 contextGL()->DeleteTextures(1, &targetTexture); | 4284 contextGL()->DeleteTextures(1, &targetTexture); |
| 4212 } | 4285 } |
| 4213 } | 4286 } |
| 4214 | 4287 |
| 4288 WebGLTexture* WebGLRenderingContextBase::texImageHelperHTMLCanvasElement(const c har* funcType, GLenum target, GLint level, GLint internalformat, | |
| 4289 GLenum format, GLenum type, GLint xoffset, GLint yoffset, GLint zoffset, HTM LCanvasElement* canvas, ExceptionState& exceptionState) | |
| 4290 { | |
| 4291 if (isContextLost()) | |
| 4292 return nullptr; | |
| 4293 if (!validateHTMLCanvasElement(funcType, canvas, exceptionState)) | |
| 4294 return nullptr; | |
| 4295 WebGLTexture* texture = nullptr; | |
| 4296 if (!strcmp(funcType, "texImage2D") || !strcmp(funcType, "texSubImage2D") | |
| 4297 texture = validateTexture2DBinding(funcType, target); | |
| 4298 else | |
| 4299 texture = validateTexture3DBinding(funcType, target); | |
| 4300 if (!texture) | |
| 4301 return nullptr; | |
| 4302 TexImageFunctionType functionType; | |
| 4303 if (!strcmp(funcType, "texImage2D")) | |
| 4304 functionType = TexImage; | |
| 4305 else | |
| 4306 functionType = TexSubImage; | |
| 4307 if (!validateTexFunc(funcType, functionType, SourceHTMLCanvasElement, target , level, internalformat, canvas->width(), canvas->height(), 1, 0, format, type, xoffset, yoffset, zoffset)) | |
| 4308 return nullptr; | |
| 4309 return texture; | |
| 4310 } | |
| 4311 | |
| 4215 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, | 4312 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, |
| 4216 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) | 4313 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) |
| 4217 { | 4314 { |
| 4218 if (isContextLost()) | 4315 WebGLTexture* texture = texImageHelperHTMLCanvasElement("texImage2D", target , level, internalformat, format, type, 0, 0, 0, canvas, exceptionState); |
| 4219 return; | |
| 4220 if (!validateHTMLCanvasElement("texImage2D", canvas, exceptionState)) | |
| 4221 return; | |
| 4222 WebGLTexture* texture = validateTexture2DBinding("texImage2D", target); | |
| 4223 if (!texture) | 4316 if (!texture) |
| 4224 return; | 4317 return; |
| 4225 if (!validateTexFunc("texImage2D", TexImage, SourceHTMLCanvasElement, target , level, internalformat, canvas->width(), canvas->height(), 1, 0, format, type, 0, 0, 0)) | |
| 4226 return; | |
| 4227 | |
| 4228 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format. | 4318 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format. |
| 4229 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats. | 4319 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats. |
| 4230 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) { | 4320 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || !canUseTexImageCanvasByGPU(internalformat, type)) { |
| 4231 // 2D canvas has only FrontBuffer. | 4321 // 2D canvas has only FrontBuffer. |
| 4232 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(), | 4322 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(), |
| 4233 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); | 4323 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); |
| 4234 return; | 4324 return; |
| 4235 } | 4325 } |
| 4236 | 4326 |
| 4237 texImage2DBase(target, level, internalformat, canvas->width(), canvas->heigh t(), 0, format, type, 0); | 4327 texImage2DBase(target, level, internalformat, canvas->width(), canvas->heigh t(), 0, format, type, 0); |
| 4238 texImageCanvasByGPU(TexImage2DByGPU, texture, target, level, internalformat, type, 0, 0, 0, canvas); | 4328 texImageCanvasByGPU(TexImage2DByGPU, texture, target, level, internalformat, type, 0, 0, 0, canvas); |
| 4239 } | 4329 } |
| 4240 | 4330 |
| 4241 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video) | 4331 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video) |
| 4242 { | 4332 { |
| 4243 IntSize size(video->videoWidth(), video->videoHeight()); | 4333 IntSize size(video->videoWidth(), video->videoHeight()); |
| 4244 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); | 4334 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); |
| 4245 if (!buf) { | 4335 if (!buf) { |
| 4246 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); | 4336 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); |
| 4247 return nullptr; | 4337 return nullptr; |
| 4248 } | 4338 } |
| 4249 IntRect destRect(0, 0, size.width(), size.height()); | 4339 IntRect destRect(0, 0, size.width(), size.height()); |
| 4250 video->paintCurrentFrame(buf->canvas(), destRect, nullptr); | 4340 video->paintCurrentFrame(buf->canvas(), destRect, nullptr); |
| 4251 return buf->newImageSnapshot(); | 4341 return buf->newImageSnapshot(); |
| 4252 } | 4342 } |
| 4253 | 4343 |
| 4344 WebGLTexture* WebGLRenderingContextBase::texImageHelperHTMLVideoElement(const ch ar* funcType, GLenum target, GLint level, GLint internalformat, | |
| 4345 GLenum format, GLenum type, GLint xoffset, GLint yoffset, GLint zoffset, HTM LVideoElement* video, ExceptionState& exceptionState) | |
| 4346 { | |
| 4347 if (isContextLost()) | |
| 4348 return nullptr; | |
| 4349 if (!validateHTMLVideoElement(funcType, video, exceptionState)) | |
| 4350 return nullptr; | |
| 4351 WebGLTexture* texture = nullptr; | |
| 4352 if (!strcmp(funcType, "texImage2D") || !strcmp(funcType, "texSubImage2D") | |
| 4353 texture = validateTexture2DBinding(funcType, target); | |
| 4354 else | |
| 4355 texture = validateTexture3DBinding(funcType, target); | |
| 4356 if (!texture) | |
| 4357 return nullptr; | |
| 4358 TexImageFunctionType functionType; | |
| 4359 if (!strcmp(funcType, "texImage2D")) | |
| 4360 functionType = TexImage; | |
| 4361 else | |
| 4362 functionType = TexSubImage; | |
| 4363 if (!validateTexFunc(funcType, functionType, SourceHTMLVideoElement, target, level, internalformat, video->videoWidth(), video->videoHeight(), 1, 0, format, type, xoffset, yoffset, zoffset)) | |
| 4364 return nullptr; | |
| 4365 return texture; | |
| 4366 } | |
| 4367 | |
| 4254 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, | 4368 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, |
| 4255 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) | 4369 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) |
| 4256 { | 4370 { |
| 4257 if (isContextLost()) | 4371 WebGLTexture* texture = texImageHelperHTMLVideoElement("texImage2D", target, level, internalformat, format, type, 0, 0, 0, video, exceptionState); |
| 4258 return; | |
| 4259 if (!validateHTMLVideoElement("texImage2D", video, exceptionState)) | |
| 4260 return; | |
| 4261 WebGLTexture* texture = validateTexture2DBinding("texImage2D", target); | |
| 4262 if (!texture) | 4372 if (!texture) |
| 4263 return; | 4373 return; |
| 4264 if (!validateTexFunc("texImage2D", TexImage, SourceHTMLVideoElement, target, level, internalformat, video->videoWidth(), video->videoHeight(), 1, 0, format, type, 0, 0, 0)) | |
| 4265 return; | |
| 4266 | |
| 4267 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. | 4374 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. |
| 4268 // Otherwise, it will fall back to the normal SW path. | 4375 // Otherwise, it will fall back to the normal SW path. |
| 4269 if (GL_TEXTURE_2D == target) { | 4376 if (GL_TEXTURE_2D == target) { |
| 4270 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level) | 4377 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level) |
| 4271 && video->copyVideoTextureToPlatformTexture(contextGL(), texture->ob ject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4378 && video->copyVideoTextureToPlatformTexture(contextGL(), texture->ob ject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 4272 return; | 4379 return; |
| 4273 } | 4380 } |
| 4274 | 4381 |
| 4275 // Try using an accelerated image buffer, this allows YUV conversion to be done on the GPU. | 4382 // Try using an accelerated image buffer, this allows YUV conversion to be done on the GPU. |
| 4276 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBuffer Surface(IntSize(video->videoWidth(), video->videoHeight()))); | 4383 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBuffer Surface(IntSize(video->videoWidth(), video->videoHeight()))); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 4291 } | 4398 } |
| 4292 } | 4399 } |
| 4293 | 4400 |
| 4294 // Normal pure SW path. | 4401 // Normal pure SW path. |
| 4295 RefPtr<Image> image = videoFrameToImage(video); | 4402 RefPtr<Image> image = videoFrameToImage(video); |
| 4296 if (!image) | 4403 if (!image) |
| 4297 return; | 4404 return; |
| 4298 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); | 4405 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); |
| 4299 } | 4406 } |
| 4300 | 4407 |
| 4301 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, | 4408 void WebGLRenderingContextBase::texImageHelperImageBitmap(const char* funcType, GLenum target, GLint level, GLint internalformat, |
| 4302 GLenum format, GLenum type, ImageBitmap* bitmap, ExceptionState& exceptionSt ate) | 4409 GLenum format, GLenum type, GLint xoffset, GLint yoffset, GLint zoffset, Ima geBitmap* bitmap, ExceptionState& exceptionState) |
| 4303 { | 4410 { |
| 4304 if (isContextLost()) | 4411 if (isContextLost()) |
| 4305 return; | 4412 return; |
| 4306 if (!validateImageBitmap("texImage2D", bitmap, exceptionState)) | 4413 if (!validateImageBitmap(funcType, bitmap, exceptionState)) |
| 4307 return; | 4414 return; |
| 4308 if (!validateTexture2DBinding("texImage2D", target)) | 4415 if ((!strcmp(funcType, "texImage2D") || !strcmp(funcType, "texSubImage2D")) && !validateTexture2DBinding(funcType, target)) |
| 4309 return; | 4416 return; |
| 4310 if (!validateTexFunc("texImage2D", TexImage, SourceImageBitmap, target, leve l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0, 0)) | 4417 if (!strcmp(funcType, "texSubImage3D") && !validateTexture3DBinding(funcType , target)) |
| 4418 return; | |
| 4419 TexImageFunctionType functionType; | |
| 4420 if (!strcmp(funcType, "texImage2D")) | |
| 4421 functionType = TexImage; | |
| 4422 else | |
| 4423 functionType = TexSubImage; | |
| 4424 if (!validateTexFunc(funcType, functionType, SourceImageBitmap, target, leve l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, xoffse t, yoffset, zoffset)) | |
| 4311 return; | 4425 return; |
| 4312 ASSERT(bitmap->bitmapImage()); | 4426 ASSERT(bitmap->bitmapImage()); |
| 4313 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); | 4427 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); |
| 4314 SkPixmap pixmap; | 4428 SkPixmap pixmap; |
| 4315 OwnPtr<uint8_t[]> pixelData; | 4429 OwnPtr<uint8_t[]> pixelData; |
| 4316 uint8_t* pixelDataPtr = nullptr; | 4430 uint8_t* pixelDataPtr = nullptr; |
| 4317 // TODO(crbug.com/613411): peekPixels fails if the SkImage is texture-backed | 4431 // TODO(crbug.com/613411): peekPixels fails if the SkImage is texture-backed |
| 4318 // Use texture mailbox in that case. | 4432 // Use texture mailbox in that case. |
| 4319 bool peekSucceed = skImage->peekPixels(&pixmap); | 4433 bool peekSucceed = skImage->peekPixels(&pixmap); |
| 4320 if (peekSucceed) { | 4434 if (peekSucceed) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 4331 needConversion = false; | 4445 needConversion = false; |
| 4332 } else { | 4446 } else { |
| 4333 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | 4447 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { |
| 4334 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement ed. | 4448 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement ed. |
| 4335 type = GL_FLOAT; | 4449 type = GL_FLOAT; |
| 4336 } | 4450 } |
| 4337 // In the case of ImageBitmap, we do not need to apply flipY or premulti plyAlpha. | 4451 // In the case of ImageBitmap, we do not need to apply flipY or premulti plyAlpha. |
| 4338 bool isPixelDataBGRA = (peekSucceed && pixmap.colorType() == SkColorType ::kBGRA_8888_SkColorType); | 4452 bool isPixelDataBGRA = (peekSucceed && pixmap.colorType() == SkColorType ::kBGRA_8888_SkColorType); |
| 4339 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format, type, false, false, data)) | 4453 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format, type, false, false, data)) |
| 4340 || (isPixelDataRBGA && !WebGLImageConversion::extractImageData(pixel DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form at, type, false, false, data))) { | 4454 || (isPixelDataRBGA && !WebGLImageConversion::extractImageData(pixel DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form at, type, false, false, data))) { |
| 4341 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); | 4455 synthesizeGLError(GL_INVALID_VALUE, funcType, "bad image data"); |
| 4342 return; | 4456 return; |
| 4343 } | 4457 } |
| 4344 } | 4458 } |
| 4345 resetUnpackParameters(); | 4459 resetUnpackParameters(); |
| 4346 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->heigh t(), 0, format, type, needConversion ? data.data() : pixelDataPtr); | 4460 if (!strcmp(funcType, "texImage2D")) |
| 4461 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->h eight(), 0, format, type, needConversion ? data.data() : pixelDataPtr); | |
| 4462 else if (!strcmp(funcType, "texSubImage2D")) | |
| 4463 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->widt h(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr ); | |
| 4464 else // must be "texSubImage3D" | |
| 4465 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bit map->width(), bitmap->height(), 1, format, type, needConversion ? data.data() : pixelDataPtr); | |
| 4347 restoreUnpackParameters(); | 4466 restoreUnpackParameters(); |
| 4348 } | 4467 } |
| 4349 | 4468 |
| 4469 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int ernalformat, | |
| 4470 GLenum format, GLenum type, ImageBitmap* bitmap, ExceptionState& exceptionSt ate) | |
| 4471 { | |
| 4472 texImageHelperImageBitmap("texImage2D", target, level, internalformat, forma t, type, 0, 0, 0, bitmap, exceptionState); | |
| 4473 } | |
| 4474 | |
| 4350 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat) | 4475 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat) |
| 4351 { | 4476 { |
| 4352 if (isContextLost()) | 4477 if (isContextLost()) |
| 4353 return; | 4478 return; |
| 4354 if (!validateTextureBinding("texParameter", target)) | 4479 if (!validateTextureBinding("texParameter", target)) |
| 4355 return; | 4480 return; |
| 4356 switch (pname) { | 4481 switch (pname) { |
| 4357 case GL_TEXTURE_MIN_FILTER: | 4482 case GL_TEXTURE_MIN_FILTER: |
| 4358 case GL_TEXTURE_MAG_FILTER: | 4483 case GL_TEXTURE_MAG_FILTER: |
| 4359 break; | 4484 break; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4438 | 4563 |
| 4439 resetUnpackParameters(); | 4564 resetUnpackParameters(); |
| 4440 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, imageExtractor.i mageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data. data() : imagePixelData); | 4565 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, imageExtractor.i mageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data. data() : imagePixelData); |
| 4441 restoreUnpackParameters(); | 4566 restoreUnpackParameters(); |
| 4442 } | 4567 } |
| 4443 | 4568 |
| 4444 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | 4569 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 4445 GLsizei width, GLsizei height, | 4570 GLsizei width, GLsizei height, |
| 4446 GLenum format, GLenum type, DOMArrayBufferView* pixels) | 4571 GLenum format, GLenum type, DOMArrayBufferView* pixels) |
| 4447 { | 4572 { |
| 4448 if (isContextLost()) | 4573 texImageHelperDOMArrayBufferView("texSubImage2D", target, level, 0, width, h eight, 0, format, type, 1, xoffset, yoffset, 0, pixels); |
| 4449 return; | |
| 4450 if (!validateTexture2DBinding("texSubImage2D", target)) | |
| 4451 return; | |
| 4452 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceArrayBufferView, ta rget, level, 0, width, height, 1, 0, format, type, xoffset, yoffset, 0)) | |
| 4453 return; | |
| 4454 if (!validateTexFuncData("texSubImage2D", Tex2D, level, width, height, 1, fo rmat, type, pixels, NullNotAllowed)) | |
| 4455 return; | |
| 4456 void* data = pixels->baseAddress(); | |
| 4457 Vector<uint8_t> tempData; | |
| 4458 bool changeUnpackAlignment = false; | |
| 4459 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { | |
| 4460 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, | |
| 4461 m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, te mpData)) | |
| 4462 return; | |
| 4463 data = tempData.data(); | |
| 4464 changeUnpackAlignment = true; | |
| 4465 } | |
| 4466 if (changeUnpackAlignment) | |
| 4467 resetUnpackParameters(); | |
| 4468 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, height, f ormat, type, data); | |
| 4469 if (changeUnpackAlignment) | |
| 4470 restoreUnpackParameters(); | |
| 4471 } | 4574 } |
| 4472 | 4575 |
| 4473 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | 4576 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 4474 GLenum format, GLenum type, ImageData* pixels) | 4577 GLenum format, GLenum type, ImageData* pixels) |
| 4475 { | 4578 { |
| 4476 if (isContextLost()) | 4579 texImageHelperImageData("texSubImage2D", target, level, 0, 0, format, type, 1, xoffset, yoffset, 0, pixels); |
| 4477 return; | |
| 4478 if (!pixels) { | |
| 4479 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data"); | |
| 4480 return; | |
| 4481 } | |
| 4482 if (pixels->data()->bufferBase()->isNeutered()) { | |
| 4483 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "The source data ha s been neutered."); | |
| 4484 return; | |
| 4485 } | |
| 4486 if (!validateTexture2DBinding("texSubImage2D", target)) | |
| 4487 return; | |
| 4488 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceImageData, target, level, 0, pixels->width(), pixels->height(), 1, 0, format, type, xoffset, yoffs et, 0)) | |
| 4489 return; | |
| 4490 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | |
| 4491 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. | |
| 4492 type = GL_FLOAT; | |
| 4493 } | |
| 4494 Vector<uint8_t> data; | |
| 4495 bool needConversion = true; | |
| 4496 // The data from ImageData is always of format RGBA8. | |
| 4497 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. | |
| 4498 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) { | |
| 4499 needConversion = false; | |
| 4500 } else { | |
| 4501 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u npackFlipY, m_unpackPremultiplyAlpha, data)) { | |
| 4502 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); | |
| 4503 return; | |
| 4504 } | |
| 4505 } | |
| 4506 resetUnpackParameters(); | |
| 4507 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, pixels->width(), pixels->height(), format, type, needConversion ? data.data() : pixels->data()-> data()); | |
| 4508 restoreUnpackParameters(); | |
| 4509 } | 4580 } |
| 4510 | 4581 |
| 4511 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | 4582 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 4512 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) | 4583 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) |
| 4513 { | 4584 { |
| 4514 if (isContextLost()) | 4585 texImageHelperHTMLImageElement("texSubImage2D", target, level, 0, format, ty pe, xoffset, yoffset, 0, image, exceptionState); |
| 4515 return; | |
| 4516 if (!validateHTMLImageElement("texSubImage2D", image, exceptionState)) | |
| 4517 return; | |
| 4518 if (!validateTexture2DBinding("texSubImage2D", target)) | |
| 4519 return; | |
| 4520 | |
| 4521 RefPtr<Image> imageForRender = image->cachedImage()->getImage(); | |
| 4522 if (imageForRender && imageForRender->isSVGImage()) | |
| 4523 imageForRender = drawImageIntoBuffer(imageForRender.release(), image->wi dth(), image->height(), "texSubImage2D"); | |
| 4524 | |
| 4525 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage, Source HTMLImageElement, target, level, 0, imageForRender->width(), imageForRender->hei ght(), 1, 0, format, type, xoffset, yoffset, 0)) | |
| 4526 return; | |
| 4527 | |
| 4528 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | |
| 4529 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. | |
| 4530 type = GL_FLOAT; | |
| 4531 } | |
| 4532 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl yAlpha); | |
| 4533 } | 4586 } |
| 4534 | 4587 |
| 4535 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | 4588 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 4536 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) | 4589 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) |
| 4537 { | 4590 { |
| 4538 if (isContextLost()) | 4591 WebGLTexture* texture = texImageHelperHTMLCanvasElement("texSubImage2D", tar get, level, 0, format, type, xoffset, yoffset, 0, canvas, exceptionState); |
| 4539 return; | |
| 4540 if (!validateHTMLCanvasElement("texSubImage2D", canvas, exceptionState)) | |
| 4541 return; | |
| 4542 WebGLTexture* texture = validateTexture2DBinding("texSubImage2D", target); | |
| 4543 if (!texture) | 4592 if (!texture) |
| 4544 return; | 4593 return; |
| 4545 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceHTMLCanvasElement, target, level, 0, canvas->width(), canvas->height(), 1, 0, format, type, xoffset , yoffset, 0)) | |
| 4546 return; | |
| 4547 | 4594 |
| 4548 // FIXME: Implement GPU-to-GPU path for WebGL 2 and more internal formats. | 4595 // FIXME: Implement GPU-to-GPU path for WebGL 2 and more internal formats. |
| 4549 bool useReadBackPath = isWebGL2OrHigher() | 4596 bool useReadBackPath = isWebGL2OrHigher() |
| 4550 || extensionEnabled(OESTextureFloatName) | 4597 || extensionEnabled(OESTextureFloatName) |
| 4551 || extensionEnabled(OESTextureHalfFloatName) | 4598 || extensionEnabled(OESTextureHalfFloatName) |
| 4552 || extensionEnabled(EXTsRGBName); | 4599 || extensionEnabled(EXTsRGBName); |
| 4553 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format. | 4600 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format. |
| 4554 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats. | 4601 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to handle more formats. |
| 4555 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || useReadBackPath) { | 4602 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || useReadBackPath) { |
| 4556 // 2D canvas has only FrontBuffer. | 4603 // 2D canvas has only FrontBuffer. |
| 4557 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(), | 4604 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(), |
| 4558 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); | 4605 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); |
| 4559 return; | 4606 return; |
| 4560 } | 4607 } |
| 4561 | 4608 |
| 4562 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ e, xoffset, yoffset, 0, canvas); | 4609 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ e, xoffset, yoffset, 0, canvas); |
| 4563 } | 4610 } |
| 4564 | 4611 |
| 4565 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | 4612 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 4566 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) | 4613 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) |
| 4567 { | 4614 { |
| 4568 if (isContextLost()) | 4615 WebGLTexture* texture = texImageHelperHTMLVideoElement("texSubImage2D", targ et, level, 0, format, type, xoffset, yoffset, 0, video, exceptionState); |
| 4569 return; | 4616 if (!texture) |
| 4570 if (!validateHTMLVideoElement("texSubImage2D", video, exceptionState)) | |
| 4571 return; | |
| 4572 if (!validateTexture2DBinding("texSubImage2D", target)) | |
| 4573 return; | |
| 4574 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceHTMLVideoElement, t arget, level, 0, video->videoWidth(), video->videoHeight(), 1, 0, format, type, xoffset, yoffset, 0)) | |
| 4575 return; | 4617 return; |
| 4576 | 4618 |
| 4577 RefPtr<Image> image = videoFrameToImage(video); | 4619 RefPtr<Image> image = videoFrameToImage(video); |
| 4578 if (!image) | 4620 if (!image) |
| 4579 return; | 4621 return; |
| 4580 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); | 4622 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); |
| 4581 } | 4623 } |
| 4582 | 4624 |
| 4583 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | 4625 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 4584 GLenum format, GLenum type, ImageBitmap* bitmap, ExceptionState& exceptionSt ate) | 4626 GLenum format, GLenum type, ImageBitmap* bitmap, ExceptionState& exceptionSt ate) |
| 4585 { | 4627 { |
| 4586 if (isContextLost()) | 4628 texImageHelperImageBitmap("texSubImage2D", target, level, 0, format, type, x offset, yoffset, 0, bitmap, exceptionState); |
| 4587 return; | |
| 4588 if (!validateImageBitmap("texSubImage2D", bitmap, exceptionState)) | |
| 4589 return; | |
| 4590 if (!validateTexture2DBinding("texSubImage2D", target)) | |
| 4591 return; | |
| 4592 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceImageBitmap, target , level, 0, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0, 0)) | |
| 4593 return; | |
| 4594 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | |
| 4595 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. | |
| 4596 type = GL_FLOAT; | |
| 4597 } | |
| 4598 ASSERT(bitmap->bitmapImage()); | |
| 4599 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); | |
| 4600 SkPixmap pixmap; | |
| 4601 OwnPtr<uint8_t[]> pixelData; | |
| 4602 uint8_t* pixelDataPtr = nullptr; | |
| 4603 bool peekSucceed = skImage->peekPixels(&pixmap); | |
| 4604 if (peekSucceed) { | |
| 4605 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); | |
| 4606 } else if (skImage->isTextureBacked()) { | |
| 4607 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip lyAlpha : DontPremultiplyAlpha); | |
| 4608 pixelDataPtr = pixelData.get(); | |
| 4609 } | |
| 4610 Vector<uint8_t> data; | |
| 4611 bool needConversion = true; | |
| 4612 bool havePeekableRGBA = (peekSucceed && pixmap.colorType() == SkColorType::k RGBA_8888_SkColorType); | |
| 4613 bool isPixelDataRBGA = (havePeekableRGBA || !peekSucceed); | |
| 4614 if (isPixelDataRBGA && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { | |
| 4615 needConversion = false; | |
| 4616 } else { | |
| 4617 // In the case of ImageBitmap, we do not need to apply flipY or premulti plyAlpha. | |
| 4618 bool isPixelDataBGRA = (peekSucceed && pixmap.colorType() == SkColorType ::kBGRA_8888_SkColorType); | |
| 4619 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format, type, false, false, data)) | |
| 4620 || (isPixelDataRBGA && !WebGLImageConversion::extractImageData(pixel DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form at, type, false, false, data))) { | |
| 4621 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); | |
| 4622 return; | |
| 4623 } | |
| 4624 } | |
| 4625 resetUnpackParameters(); | |
| 4626 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->width(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr); | |
| 4627 restoreUnpackParameters(); | |
| 4628 } | 4629 } |
| 4629 | 4630 |
| 4630 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) | 4631 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) |
| 4631 { | 4632 { |
| 4632 if (isContextLost() || !location) | 4633 if (isContextLost() || !location) |
| 4633 return; | 4634 return; |
| 4634 | 4635 |
| 4635 if (location->program() != m_currentProgram) { | 4636 if (location->program() != m_currentProgram) { |
| 4636 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", "location not for c urrent program"); | 4637 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", "location not for c urrent program"); |
| 4637 return; | 4638 return; |
| (...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6424 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6425 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6425 } | 6426 } |
| 6426 | 6427 |
| 6427 void WebGLRenderingContextBase::restoreUnpackParameters() | 6428 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6428 { | 6429 { |
| 6429 if (m_unpackAlignment != 1) | 6430 if (m_unpackAlignment != 1) |
| 6430 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6431 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6431 } | 6432 } |
| 6432 | 6433 |
| 6433 } // namespace blink | 6434 } // namespace blink |
| OLD | NEW |