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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 | 508 |
509 ~ScopedFramebufferRestorer() | 509 ~ScopedFramebufferRestorer() |
510 { | 510 { |
511 m_context->restoreCurrentFramebuffer(); | 511 m_context->restoreCurrentFramebuffer(); |
512 } | 512 } |
513 | 513 |
514 private: | 514 private: |
515 Member<WebGLRenderingContextBase> m_context; | 515 Member<WebGLRenderingContextBase> m_context; |
516 }; | 516 }; |
517 | 517 |
| 518 class ScopedUnpackParametersResetRestore { |
| 519 STACK_ALLOCATED(); |
| 520 |
| 521 public: |
| 522 explicit ScopedUnpackParametersResetRestore(WebGLRenderingContextBase* conte
xt, bool enabled = true) |
| 523 : m_context(context) |
| 524 , m_enabled(enabled) |
| 525 { |
| 526 if (enabled) |
| 527 m_context->resetUnpackParameters(); |
| 528 } |
| 529 |
| 530 ~ScopedUnpackParametersResetRestore() |
| 531 { |
| 532 if (m_enabled) |
| 533 m_context->restoreUnpackParameters(); |
| 534 } |
| 535 |
| 536 private: |
| 537 Member<WebGLRenderingContextBase> m_context; |
| 538 bool m_enabled; |
| 539 }; |
| 540 |
518 static void formatWebGLStatusString(const StringView& glInfo, const StringView&
infoString, StringBuilder& builder) | 541 static void formatWebGLStatusString(const StringView& glInfo, const StringView&
infoString, StringBuilder& builder) |
519 { | 542 { |
520 if (infoString.isEmpty()) | 543 if (infoString.isEmpty()) |
521 return; | 544 return; |
522 builder.append(", "); | 545 builder.append(", "); |
523 builder.append(glInfo); | 546 builder.append(glInfo); |
524 builder.append(" = "); | 547 builder.append(" = "); |
525 builder.append(infoString); | 548 builder.append(infoString); |
526 } | 549 } |
527 | 550 |
(...skipping 3503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4031 bool needConversion = true; | 4054 bool needConversion = true; |
4032 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da
taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo
thing && !flipY) { | 4055 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da
taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo
thing && !flipY) { |
4033 needConversion = false; | 4056 needConversion = false; |
4034 } else { | 4057 } else { |
4035 if (!WebGLImageConversion::packImageData(image, imagePixelData, format,
type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac
tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { | 4058 if (!WebGLImageConversion::packImageData(image, imagePixelData, format,
type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac
tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { |
4036 synthesizeGLError(GL_INVALID_VALUE, funcName, "packImage error"); | 4059 synthesizeGLError(GL_INVALID_VALUE, funcName, "packImage error"); |
4037 return; | 4060 return; |
4038 } | 4061 } |
4039 } | 4062 } |
4040 | 4063 |
4041 resetUnpackParameters(); | 4064 ScopedUnpackParametersResetRestore temporaryResetUnpack(this); |
4042 if (functionID == TexImage2D) { | 4065 if (functionID == TexImage2D) { |
4043 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(
), imageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() :
imagePixelData); | 4066 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(
), imageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() :
imagePixelData); |
4044 } else if (functionID == TexSubImage2D) { | 4067 } else if (functionID == TexSubImage2D) { |
4045 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, imageExtract
or.imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? d
ata.data() : imagePixelData); | 4068 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, imageExtract
or.imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? d
ata.data() : imagePixelData); |
4046 } else { | 4069 } else { |
4047 DCHECK_EQ(functionID, TexSubImage3D); | 4070 DCHECK_EQ(functionID, TexSubImage3D); |
4048 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, ima
geExtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needCon
version ? data.data() : imagePixelData); | 4071 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, ima
geExtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needCon
version ? data.data() : imagePixelData); |
4049 } | 4072 } |
4050 restoreUnpackParameters(); | |
4051 } | 4073 } |
4052 | 4074 |
4053 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma
geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ
et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d
epth, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset, GL
int zoffset) | 4075 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma
geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ
et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d
epth, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset, GL
int zoffset) |
4054 { | 4076 { |
4055 if (!validateTexFuncLevel(functionName, target, level)) | 4077 if (!validateTexFuncLevel(functionName, target, level)) |
4056 return false; | 4078 return false; |
4057 | 4079 |
4058 if (!validateTexFuncParameters(functionName, functionType, target, level, in
ternalformat, width, height, depth, border, format, type)) | 4080 if (!validateTexFuncParameters(functionName, functionType, target, level, in
ternalformat, width, height, depth, border, format, type)) |
4059 return false; | 4081 return false; |
4060 | 4082 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4182 // FIXME: implement flipY and premultiplyAlpha for tex(Sub)3D. | 4204 // FIXME: implement flipY and premultiplyAlpha for tex(Sub)3D. |
4183 if (functionID == TexImage3D) { | 4205 if (functionID == TexImage3D) { |
4184 contextGL()->TexImage3D(target, level, convertTexInternalFormat(internal
format, type), width, height, depth, border, format, type, data); | 4206 contextGL()->TexImage3D(target, level, convertTexInternalFormat(internal
format, type), width, height, depth, border, format, type, data); |
4185 return; | 4207 return; |
4186 } | 4208 } |
4187 if (functionID == TexSubImage3D) { | 4209 if (functionID == TexSubImage3D) { |
4188 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, wid
th, height, depth, format, type, data); | 4210 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, wid
th, height, depth, format, type, data); |
4189 return; | 4211 return; |
4190 } | 4212 } |
4191 | 4213 |
4192 if (changeUnpackAlignment) | 4214 ScopedUnpackParametersResetRestore temporaryResetUnpack(this, changeUnpackAl
ignment); |
4193 resetUnpackParameters(); | |
4194 if (functionID == TexImage2D) | 4215 if (functionID == TexImage2D) |
4195 texImage2DBase(target, level, internalformat, width, height, border, for
mat, type, data); | 4216 texImage2DBase(target, level, internalformat, width, height, border, for
mat, type, data); |
4196 else if (functionID == TexSubImage2D) | 4217 else if (functionID == TexSubImage2D) |
4197 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, heigh
t, format, type, data); | 4218 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, heigh
t, format, type, data); |
4198 if (changeUnpackAlignment) | |
4199 restoreUnpackParameters(); | |
4200 } | 4219 } |
4201 | 4220 |
4202 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4221 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
4203 GLsizei width, GLsizei height, GLint border, | 4222 GLsizei width, GLsizei height, GLint border, |
4204 GLenum format, GLenum type, DOMArrayBufferView* pixels) | 4223 GLenum format, GLenum type, DOMArrayBufferView* pixels) |
4205 { | 4224 { |
4206 texImageHelperDOMArrayBufferView(TexImage2D, target, level, internalformat,
width, height, border, format, type, 1, 0, 0, 0, pixels); | 4225 texImageHelperDOMArrayBufferView(TexImage2D, target, level, internalformat,
width, height, border, format, type, 1, 0, 0, 0, pixels); |
4207 } | 4226 } |
4208 | 4227 |
4209 void WebGLRenderingContextBase::texImageHelperImageData(TexImageFunctionID funct
ionID, | 4228 void WebGLRenderingContextBase::texImageHelperImageData(TexImageFunctionID funct
ionID, |
(...skipping 29 matching lines...) Expand all Loading... |
4239 } else { | 4258 } else { |
4240 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | 4259 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { |
4241 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement
ed. | 4260 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement
ed. |
4242 type = GL_FLOAT; | 4261 type = GL_FLOAT; |
4243 } | 4262 } |
4244 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG
LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u
npackFlipY, m_unpackPremultiplyAlpha, data)) { | 4263 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG
LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u
npackFlipY, m_unpackPremultiplyAlpha, data)) { |
4245 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); | 4264 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); |
4246 return; | 4265 return; |
4247 } | 4266 } |
4248 } | 4267 } |
4249 resetUnpackParameters(); | 4268 ScopedUnpackParametersResetRestore temporaryResetUnpack(this); |
4250 if (functionID == TexImage2D) { | 4269 if (functionID == TexImage2D) { |
4251 texImage2DBase(target, level, internalformat, pixels->width(), pixels->h
eight(), border, format, type, needConversion ? data.data() : pixels->data()->da
ta()); | 4270 texImage2DBase(target, level, internalformat, pixels->width(), pixels->h
eight(), border, format, type, needConversion ? data.data() : pixels->data()->da
ta()); |
4252 } else if (functionID == TexSubImage2D) { | 4271 } else if (functionID == TexSubImage2D) { |
4253 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, pixels->widt
h(), pixels->height(), format, type, needConversion ? data.data() : pixels->data
()->data()); | 4272 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, pixels->widt
h(), pixels->height(), format, type, needConversion ? data.data() : pixels->data
()->data()); |
4254 } else { | 4273 } else { |
4255 DCHECK_EQ(functionID, TexSubImage3D); | 4274 DCHECK_EQ(functionID, TexSubImage3D); |
4256 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, pix
els->width(), pixels->height(), depth, format, type, needConversion ? data.data(
) : pixels->data()->data()); | 4275 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, pix
els->width(), pixels->height(), depth, format, type, needConversion ? data.data(
) : pixels->data()->data()); |
4257 } | 4276 } |
4258 restoreUnpackParameters(); | |
4259 } | 4277 } |
4260 | 4278 |
4261 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4279 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
4262 GLenum format, GLenum type, ImageData* pixels) | 4280 GLenum format, GLenum type, ImageData* pixels) |
4263 { | 4281 { |
4264 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format
, type, 1, 0, 0, 0, pixels); | 4282 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format
, type, 1, 0, 0, 0, pixels); |
4265 } | 4283 } |
4266 | 4284 |
4267 void WebGLRenderingContextBase::texImageHelperHTMLImageElement(TexImageFunctionI
D functionID, | 4285 void WebGLRenderingContextBase::texImageHelperHTMLImageElement(TexImageFunctionI
D functionID, |
4268 GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type
, GLint xoffset, | 4286 GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type
, GLint xoffset, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4304 // TODO(crbug.com/622958): Implement GPU-to-GPU path for WebGL 2 and more in
ternal formats. | 4322 // TODO(crbug.com/622958): Implement GPU-to-GPU path for WebGL 2 and more in
ternal formats. |
4305 if (functionID == TexSubImage2D && (isWebGL2OrHigher() || extensionEnabled(O
ESTextureFloatName) || extensionEnabled(OESTextureHalfFloatName) || extensionEna
bled(EXTsRGBName))) | 4323 if (functionID == TexSubImage2D && (isWebGL2OrHigher() || extensionEnabled(O
ESTextureFloatName) || extensionEnabled(OESTextureHalfFloatName) || extensionEna
bled(EXTsRGBName))) |
4306 return false; | 4324 return false; |
4307 return true; | 4325 return true; |
4308 } | 4326 } |
4309 | 4327 |
4310 void WebGLRenderingContextBase::texImageCanvasByGPU(HTMLCanvasElement* canvas, G
Luint targetTexture, GLenum targetInternalformat, GLenum targetType, GLint targe
tLevel) | 4328 void WebGLRenderingContextBase::texImageCanvasByGPU(HTMLCanvasElement* canvas, G
Luint targetTexture, GLenum targetInternalformat, GLenum targetType, GLint targe
tLevel) |
4311 { | 4329 { |
4312 if (!canvas->is3D()) { | 4330 if (!canvas->is3D()) { |
4313 ImageBuffer* buffer = canvas->buffer(); | 4331 ImageBuffer* buffer = canvas->buffer(); |
4314 if (!buffer->copyToPlatformTexture(contextGL(), targetTexture, targetInt
ernalformat, targetType, | 4332 if (extensionsUtil()->canUseCopyTextureCHROMIUM(targetTexture, targetInt
ernalformat, targetType, targetLevel) && !buffer->copyToPlatformTexture(contextG
L(), targetTexture, targetInternalformat, targetType, targetLevel, m_unpackPremu
ltiplyAlpha, m_unpackFlipY)) { |
4315 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | |
4316 NOTREACHED(); | 4333 NOTREACHED(); |
4317 } | 4334 } |
4318 } else { | 4335 } else { |
4319 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); | 4336 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); |
4320 ScopedTexture2DRestorer restorer(gl); | 4337 ScopedTexture2DRestorer restorer(gl); |
4321 if (!gl->drawingBuffer()->copyToPlatformTexture(contextGL(), targetTextu
re, targetInternalformat, targetType, | 4338 if (!gl->drawingBuffer()->copyToPlatformTexture(contextGL(), targetTextu
re, targetInternalformat, targetType, |
4322 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ | 4339 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ |
4323 NOTREACHED(); | 4340 NOTREACHED(); |
4324 } | 4341 } |
4325 } | 4342 } |
4326 } | 4343 } |
4327 | 4344 |
4328 void WebGLRenderingContextBase::texImageByGPU(TexImageByGPUType functionType, We
bGLTexture* texture, GLenum target, | 4345 void WebGLRenderingContextBase::texImageByGPU(TexImageByGPUType functionType, We
bGLTexture* texture, GLenum target, |
4329 GLint level, GLint internalformat, GLenum type, GLint xoffset, GLint yoffset
, GLint zoffset, CanvasImageSource* image) | 4346 GLint level, GLint internalformat, GLenum type, GLint xoffset, GLint yoffset
, GLint zoffset, CanvasImageSource* image) |
4330 { | 4347 { |
4331 DCHECK(image->isCanvasElement() || image->isImageBitmap()); | 4348 DCHECK(image->isCanvasElement() || image->isImageBitmap()); |
4332 int width = image->sourceWidth(); | 4349 int width = image->sourceWidth(); |
4333 int height = image->sourceHeight(); | 4350 int height = image->sourceHeight(); |
4334 | 4351 |
4335 ScopedTexture2DRestorer restorer(this); | 4352 ScopedTexture2DRestorer restorer(this); |
4336 | 4353 |
4337 GLuint targetTexture = texture->object(); | 4354 GLuint targetTexture = texture->object(); |
4338 GLenum targetType = type; | 4355 GLenum targetType = type; |
4339 GLenum targetInternalformat = internalformat; | 4356 GLenum targetInternalformat = internalformat; |
4340 GLint targetLevel = level; | 4357 GLint targetLevel = level; |
4341 bool possibleDirectCopy = false; | 4358 bool possibleDirectCopy = false; |
4342 if (functionType == TexImage2DByGPU) { | 4359 if (functionType == TexImage2DByGPU) { |
4343 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(target,
internalformat, type, level); | 4360 possibleDirectCopy = extensionsUtil()->canUseCopyTextureCHROMIUM(target,
internalformat, type, level); |
4344 } | 4361 } |
4345 | 4362 |
4346 // if direct copy is not possible, create a temporary texture and then copy
from canvas to temporary texture to target texture. | 4363 // if direct copy is not possible, create a temporary texture and then copy
from canvas to temporary texture to target texture. |
4347 if (!possibleDirectCopy) { | 4364 if (!possibleDirectCopy) { |
4348 targetLevel = 0; | 4365 targetLevel = 0; |
4349 targetInternalformat = GL_RGBA; | 4366 targetInternalformat = GL_RGBA; |
4350 targetType = GL_UNSIGNED_BYTE; | 4367 targetType = GL_UNSIGNED_BYTE; |
4351 contextGL()->GenTextures(1, &targetTexture); | 4368 contextGL()->GenTextures(1, &targetTexture); |
4352 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); | 4369 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); |
4353 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAR
EST); | 4370 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAR
EST); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4457 if (!texture) | 4474 if (!texture) |
4458 return; | 4475 return; |
4459 TexImageFunctionType functionType; | 4476 TexImageFunctionType functionType; |
4460 if (functionID == TexImage2D) | 4477 if (functionID == TexImage2D) |
4461 functionType = TexImage; | 4478 functionType = TexImage; |
4462 else | 4479 else |
4463 functionType = TexSubImage; | 4480 functionType = TexSubImage; |
4464 if (!validateTexFunc(funcName, functionType, SourceHTMLVideoElement, target,
level, internalformat, video->videoWidth(), video->videoHeight(), 1, 0, format,
type, xoffset, yoffset, zoffset)) | 4481 if (!validateTexFunc(funcName, functionType, SourceHTMLVideoElement, target,
level, internalformat, video->videoWidth(), video->videoHeight(), 1, 0, format,
type, xoffset, yoffset, zoffset)) |
4465 return; | 4482 return; |
4466 | 4483 |
4467 if (functionID == TexImage2D) { | 4484 if (functionID == TexImage2D && GL_TEXTURE_2D == target && extensionsUtil()-
>canUseCopyTextureCHROMIUM(target, internalformat, type, level)) { |
4468 // Go through the fast path doing a GPU-GPU textures copy without a read
back to system memory if possible. | 4485 // Go through the fast path doing a GPU-GPU textures copy without a read
back to system memory if possible. |
4469 // Otherwise, it will fall back to the normal SW path. | 4486 // Otherwise, it will fall back to the normal SW path. |
4470 if (GL_TEXTURE_2D == target) { | 4487 if (video->copyVideoTextureToPlatformTexture(contextGL(), texture->objec
t(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
4471 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalform
at, type, level) | 4488 return; |
4472 && video->copyVideoTextureToPlatformTexture(contextGL(), texture
->object(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4489 } |
4473 return; | 4490 } |
4474 } | |
4475 | 4491 |
4476 // Try using an accelerated image buffer, this allows YUV conversion
to be done on the GPU. | 4492 { |
4477 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Acceler
atedImageBufferSurface(IntSize(video->videoWidth(), video->videoHeight()))); | 4493 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. I
t leaves early for other formats or if frame is stored on GPU. |
4478 if (surface->isValid()) { | 4494 ScopedUnpackParametersResetRestore(this, m_unpackFlipY || m_unpackPremul
tiplyAlpha); |
4479 std::unique_ptr<ImageBuffer> imageBuffer(ImageBuffer::create(std
::move(surface))); | 4495 if (video->texImageImpl(getTexImageFunctionName(functionID), target, con
textGL(), level, internalformat, format, type, xoffset, yoffset, zoffset, |
4480 if (imageBuffer) { | 4496 m_unpackFlipY, m_unpackPremultiplyAlpha && m_unpackColorspaceConvers
ion == GL_NONE)) |
4481 // The video element paints an RGBA frame into our surface h
ere. By using an AcceleratedImageBufferSurface, | 4497 return; |
4482 // we enable the WebMediaPlayer implementation to do any nec
essary color space conversion on the GPU (though it | 4498 } |
4483 // may still do a CPU conversion and upload the results). | |
4484 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0
, video->videoWidth(), video->videoHeight()), nullptr); | |
4485 | 4499 |
4486 // This is a straight GPU-GPU copy, any necessary color spac
e conversion was handled in the paintCurrentFrameInContext() call. | 4500 if (functionID == TexImage2D && GL_TEXTURE_2D == target && extensionsUtil()-
>canUseCopyTextureCHROMIUM(target, internalformat, type, level)) { |
4487 if (imageBuffer->copyToPlatformTexture(contextGL(), texture-
>object(), internalformat, type, | 4501 // Try using an accelerated image buffer, this allows YUV conversion to
be done on the GPU. |
| 4502 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Accelerated
ImageBufferSurface(IntSize(video->videoWidth(), video->videoHeight()))); |
| 4503 if (surface->isValid()) { |
| 4504 std::unique_ptr<ImageBuffer> imageBuffer(ImageBuffer::create(std::mo
ve(surface))); |
| 4505 if (imageBuffer) { |
| 4506 // The video element paints an RGBA frame into our surface here.
By using an AcceleratedImageBufferSurface, |
| 4507 // we enable the WebMediaPlayer implementation to do any necessa
ry color space conversion on the GPU (though it |
| 4508 // may still do a CPU conversion and upload the results). |
| 4509 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, vi
deo->videoWidth(), video->videoHeight()), nullptr); |
| 4510 |
| 4511 // This is a straight GPU-GPU copy, any necessary color space co
nversion was handled in the paintCurrentFrameInContext() call. |
| 4512 if (imageBuffer->copyToPlatformTexture(contextGL(), texture->obj
ect(), internalformat, type, |
4488 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4513 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
4489 return; | 4514 return; |
4490 } | |
4491 } | 4515 } |
4492 } | 4516 } |
4493 } | 4517 } |
4494 } | 4518 } |
4495 | 4519 |
4496 RefPtr<Image> image = videoFrameToImage(video); | 4520 RefPtr<Image> image = videoFrameToImage(video); |
4497 if (!image) | 4521 if (!image) |
4498 return; | 4522 return; |
4499 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zo
ffset, format, type, image.get(), WebGLImageConversion::HtmlDomVideo, m_unpackFl
ipY, m_unpackPremultiplyAlpha); | 4523 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zo
ffset, format, type, image.get(), WebGLImageConversion::HtmlDomVideo, m_unpackFl
ipY, m_unpackPremultiplyAlpha); |
4500 } | 4524 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4565 type = GL_FLOAT; | 4589 type = GL_FLOAT; |
4566 } | 4590 } |
4567 // In the case of ImageBitmap, we do not need to apply flipY or premulti
plyAlpha. | 4591 // In the case of ImageBitmap, we do not need to apply flipY or premulti
plyAlpha. |
4568 bool isPixelDataBGRA = pixmap.colorType() == SkColorType::kBGRA_8888_SkC
olorType; | 4592 bool isPixelDataBGRA = pixmap.colorType() == SkColorType::kBGRA_8888_SkC
olorType; |
4569 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat
aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format,
type, false, false, data)) | 4593 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat
aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format,
type, false, false, data)) |
4570 || (isPixelDataRGBA && !WebGLImageConversion::extractImageData(pixel
DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form
at, type, false, false, data))) { | 4594 || (isPixelDataRGBA && !WebGLImageConversion::extractImageData(pixel
DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form
at, type, false, false, data))) { |
4571 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); | 4595 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); |
4572 return; | 4596 return; |
4573 } | 4597 } |
4574 } | 4598 } |
4575 resetUnpackParameters(); | 4599 ScopedUnpackParametersResetRestore temporaryResetUnpack(this); |
4576 if (functionID == TexImage2D) { | 4600 if (functionID == TexImage2D) { |
4577 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->h
eight(), 0, format, type, needConversion ? data.data() : pixelDataPtr); | 4601 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->h
eight(), 0, format, type, needConversion ? data.data() : pixelDataPtr); |
4578 } else if (functionID == TexSubImage2D) { | 4602 } else if (functionID == TexSubImage2D) { |
4579 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->widt
h(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr
); | 4603 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->widt
h(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr
); |
4580 } else { | 4604 } else { |
4581 DCHECK_EQ(functionID, TexSubImage3D); | 4605 DCHECK_EQ(functionID, TexSubImage3D); |
4582 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bit
map->width(), bitmap->height(), 1, format, type, needConversion ? data.data() :
pixelDataPtr); | 4606 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bit
map->width(), bitmap->height(), 1, format, type, needConversion ? data.data() :
pixelDataPtr); |
4583 } | 4607 } |
4584 restoreUnpackParameters(); | |
4585 } | 4608 } |
4586 | 4609 |
4587 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4610 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
4588 GLenum format, GLenum type, ImageBitmap* bitmap, ExceptionState& exceptionSt
ate) | 4611 GLenum format, GLenum type, ImageBitmap* bitmap, ExceptionState& exceptionSt
ate) |
4589 { | 4612 { |
4590 texImageHelperImageBitmap(TexImage2D, target, level, internalformat, format,
type, 0, 0, 0, bitmap, exceptionState); | 4613 texImageHelperImageBitmap(TexImage2D, target, level, internalformat, format,
type, 0, 0, 0, bitmap, exceptionState); |
4591 } | 4614 } |
4592 | 4615 |
4593 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa
t paramf, GLint parami, bool isFloat) | 4616 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa
t paramf, GLint parami, bool isFloat) |
4594 { | 4617 { |
(...skipping 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6504 | 6527 |
6505 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs
creenCanvas& result) const | 6528 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs
creenCanvas& result) const |
6506 { | 6529 { |
6507 if (canvas()) | 6530 if (canvas()) |
6508 result.setHTMLCanvasElement(canvas()); | 6531 result.setHTMLCanvasElement(canvas()); |
6509 else | 6532 else |
6510 result.setOffscreenCanvas(getOffscreenCanvas()); | 6533 result.setOffscreenCanvas(getOffscreenCanvas()); |
6511 } | 6534 } |
6512 | 6535 |
6513 } // namespace blink | 6536 } // namespace blink |
OLD | NEW |