| 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 4236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4247 | 4247 |
| 4248 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zo
ffset, format, type, imageForRender.get(), WebGLImageConversion::HtmlDomImage, m
_unpackFlipY, m_unpackPremultiplyAlpha); | 4248 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zo
ffset, format, type, imageForRender.get(), WebGLImageConversion::HtmlDomImage, m
_unpackFlipY, m_unpackPremultiplyAlpha); |
| 4249 } | 4249 } |
| 4250 | 4250 |
| 4251 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4251 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
| 4252 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti
onState) | 4252 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti
onState) |
| 4253 { | 4253 { |
| 4254 texImageHelperHTMLImageElement(TexImage2D, target, level, internalformat, fo
rmat, type, 0, 0, 0, image, exceptionState); | 4254 texImageHelperHTMLImageElement(TexImage2D, target, level, internalformat, fo
rmat, type, 0, 0, 0, image, exceptionState); |
| 4255 } | 4255 } |
| 4256 | 4256 |
| 4257 bool WebGLRenderingContextBase::canUseTexImageCanvasByGPU(GLint internalformat,
GLenum type) | 4257 bool WebGLRenderingContextBase::canUseTexImageByGPU(GLint internalformat, GLenum
type) |
| 4258 { | 4258 { |
| 4259 if (isFloatType(type) || isIntegerFormat(internalformat) || isSRGBFormat(int
ernalformat)) | 4259 if (isFloatType(type) || isIntegerFormat(internalformat) || isSRGBFormat(int
ernalformat)) |
| 4260 return false; | 4260 return false; |
| 4261 return true; | 4261 return true; |
| 4262 } | 4262 } |
| 4263 | 4263 |
| 4264 void WebGLRenderingContextBase::texImageCanvasByGPU(TexImageByGPUType functionTy
pe, WebGLTexture* texture, GLenum target, | 4264 void WebGLRenderingContextBase::texImageCanvasByGPU(HTMLCanvasElement* canvas, G
Luint targetTexture, GLenum targetInternalformat, GLenum targetType, GLint targe
tLevel) |
| 4265 GLint level, GLint internalformat, GLenum type, GLint xoffset, GLint yoffset
, GLint zoffset, HTMLCanvasElement* canvas) | |
| 4266 { | 4265 { |
| 4266 if (!canvas->is3D()) { |
| 4267 ImageBuffer* buffer = canvas->buffer(); |
| 4268 if (!buffer->copyToPlatformTexture(contextGL(), targetTexture, targetInt
ernalformat, targetType, |
| 4269 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 4270 NOTREACHED(); |
| 4271 } |
| 4272 } else { |
| 4273 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); |
| 4274 ScopedTexture2DRestorer restorer(gl); |
| 4275 if (!gl->drawingBuffer()->copyToPlatformTexture(contextGL(), targetTextu
re, targetInternalformat, targetType, |
| 4276 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ |
| 4277 NOTREACHED(); |
| 4278 } |
| 4279 } |
| 4280 } |
| 4281 |
| 4282 void WebGLRenderingContextBase::texImageByGPU(TexImageByGPUType functionType, We
bGLTexture* texture, GLenum target, |
| 4283 GLint level, GLint internalformat, GLenum type, GLint xoffset, GLint yoffset
, GLint zoffset, HTMLCanvasElement* canvas, ImageBitmap* bitmap) |
| 4284 { |
| 4285 DCHECK((!canvas || !bitmap) && (canvas || bitmap)); |
| 4267 ScopedTexture2DRestorer restorer(this); | 4286 ScopedTexture2DRestorer restorer(this); |
| 4268 | 4287 |
| 4269 GLuint targetTexture = texture->object(); | 4288 GLuint targetTexture = texture->object(); |
| 4270 GLenum targetType = type; | 4289 GLenum targetType = type; |
| 4271 GLenum targetInternalformat = internalformat; | 4290 GLenum targetInternalformat = internalformat; |
| 4272 GLint targetLevel = level; | 4291 GLint targetLevel = level; |
| 4273 bool possibleDirectCopy = false; | 4292 bool possibleDirectCopy = false; |
| 4293 // TODO: Make this function support more cases in texSubImage calls. |
| 4274 if (functionType == TexImage2DByGPU) { | 4294 if (functionType == TexImage2DByGPU) { |
| 4275 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(target,
internalformat, type, level); | 4295 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(target,
internalformat, type, level); |
| 4276 } | 4296 } |
| 4277 | 4297 |
| 4278 // if direct copy is not possible, create a temporary texture and then copy
from canvas to temporary texture to target texture. | 4298 // if direct copy is not possible, create a temporary texture and then copy
from canvas to temporary texture to target texture. |
| 4279 if (!possibleDirectCopy) { | 4299 if (!possibleDirectCopy) { |
| 4280 targetLevel = 0; | 4300 targetLevel = 0; |
| 4281 targetInternalformat = GL_RGBA; | 4301 targetInternalformat = GL_RGBA; |
| 4282 targetType = GL_UNSIGNED_BYTE; | 4302 targetType = GL_UNSIGNED_BYTE; |
| 4283 contextGL()->GenTextures(1, &targetTexture); | 4303 contextGL()->GenTextures(1, &targetTexture); |
| 4284 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); | 4304 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); |
| 4285 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAR
EST); | 4305 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAR
EST); |
| 4286 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAR
EST); | 4306 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAR
EST); |
| 4287 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO
_EDGE); | 4307 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO
_EDGE); |
| 4288 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO
_EDGE); | 4308 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO
_EDGE); |
| 4289 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas->
width(), | 4309 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas->
width(), |
| 4290 canvas->height(), 0, GL_RGBA, targetType, 0); | 4310 canvas->height(), 0, GL_RGBA, targetType, 0); |
| 4291 } | 4311 } |
| 4292 | 4312 |
| 4293 if (!canvas->is3D()) { | 4313 if (canvas) |
| 4294 ImageBuffer* buffer = canvas->buffer(); | 4314 texImageCanvasByGPU(canvas, targetTexture, targetInternalformat, targetT
ype, targetLevel); |
| 4295 if (!buffer->copyToPlatformTexture(contextGL(), targetTexture, targetInt
ernalformat, targetType, | 4315 else |
| 4296 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4316 texImageBitmapByGPU(bitmap, targetTexture, targetInternalformat, targetT
ype, targetLevel); |
| 4297 ASSERT_NOT_REACHED(); | |
| 4298 } | |
| 4299 } else { | |
| 4300 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); | |
| 4301 ScopedTexture2DRestorer restorer(gl); | |
| 4302 if (!gl->drawingBuffer()->copyToPlatformTexture(contextGL(), targetTextu
re, targetInternalformat, targetType, | |
| 4303 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ | |
| 4304 ASSERT_NOT_REACHED(); | |
| 4305 } | |
| 4306 } | |
| 4307 | 4317 |
| 4308 if (!possibleDirectCopy) { | 4318 if (!possibleDirectCopy) { |
| 4309 GLuint tmpFBO; | 4319 GLuint tmpFBO; |
| 4310 contextGL()->GenFramebuffers(1, &tmpFBO); | 4320 contextGL()->GenFramebuffers(1, &tmpFBO); |
| 4311 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO); | 4321 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO); |
| 4312 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, targetTexture, 0); | 4322 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, targetTexture, 0); |
| 4313 contextGL()->BindTexture(texture->getTarget(), texture->object()); | 4323 contextGL()->BindTexture(texture->getTarget(), texture->object()); |
| 4314 if (functionType == TexImage2DByGPU) { | 4324 if (functionType == TexImage2DByGPU) { |
| 4315 contextGL()->CopyTexSubImage2D(target, level, 0, 0, 0, 0, canvas->wi
dth(), canvas->height()); | 4325 contextGL()->CopyTexSubImage2D(target, level, 0, 0, 0, 0, canvas->wi
dth(), canvas->height()); |
| 4316 } else if (functionType == TexSubImage2DByGPU) { | 4326 } else if (functionType == TexSubImage2DByGPU) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4338 if (!texture) | 4348 if (!texture) |
| 4339 return; | 4349 return; |
| 4340 TexImageFunctionType functionType; | 4350 TexImageFunctionType functionType; |
| 4341 if (functionID == TexImage2D) | 4351 if (functionID == TexImage2D) |
| 4342 functionType = TexImage; | 4352 functionType = TexImage; |
| 4343 else | 4353 else |
| 4344 functionType = TexSubImage; | 4354 functionType = TexSubImage; |
| 4345 if (!validateTexFunc(funcName, functionType, SourceHTMLCanvasElement, target
, level, internalformat, canvas->width(), canvas->height(), 1, 0, format, type,
xoffset, yoffset, zoffset)) | 4355 if (!validateTexFunc(funcName, functionType, SourceHTMLCanvasElement, target
, level, internalformat, canvas->width(), canvas->height(), 1, 0, format, type,
xoffset, yoffset, zoffset)) |
| 4346 return; | 4356 return; |
| 4347 if (functionID == TexImage2D) { | 4357 if (functionID == TexImage2D) { |
| 4348 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't suppo
rt float/integer/sRGB internal format. | 4358 // texImageByGPU relies on copyTextureCHROMIUM which doesn't support flo
at/integer/sRGB internal format. |
| 4349 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to han
dle more formats. | 4359 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to han
dle more formats. |
| 4350 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccele
rated() || !canUseTexImageCanvasByGPU(internalformat, type)) { | 4360 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccele
rated() || !canUseTexImageByGPU(internalformat, type)) { |
| 4351 // 2D canvas has only FrontBuffer. | 4361 // 2D canvas has only FrontBuffer. |
| 4352 texImageImpl(TexImage2D, target, level, internalformat, xoffset, yof
fset, zoffset, format, type, canvas->copiedImage(FrontBuffer, PreferAcceleration
).get(), | 4362 texImageImpl(TexImage2D, target, level, internalformat, xoffset, yof
fset, zoffset, format, type, canvas->copiedImage(FrontBuffer, PreferAcceleration
).get(), |
| 4353 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPrem
ultiplyAlpha); | 4363 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPrem
ultiplyAlpha); |
| 4354 return; | 4364 return; |
| 4355 } | 4365 } |
| 4356 | 4366 |
| 4357 texImage2DBase(target, level, internalformat, canvas->width(), canvas->h
eight(), 0, format, type, 0); | 4367 texImage2DBase(target, level, internalformat, canvas->width(), canvas->h
eight(), 0, format, type, 0); |
| 4358 texImageCanvasByGPU(TexImage2DByGPU, texture, target, level, internalfor
mat, type, 0, 0, 0, canvas); | 4368 texImageByGPU(TexImage2DByGPU, texture, target, level, internalformat, t
ype, 0, 0, 0, canvas, nullptr); |
| 4359 } else if (functionID == TexSubImage2D) { | 4369 } else if (functionID == TexSubImage2D) { |
| 4360 // FIXME: Implement GPU-to-GPU path for WebGL 2 and more internal format
s. | 4370 // FIXME: Implement GPU-to-GPU path for WebGL 2 and more internal format
s. |
| 4361 bool useReadBackPath = isWebGL2OrHigher() | 4371 bool useReadBackPath = isWebGL2OrHigher() |
| 4362 || extensionEnabled(OESTextureFloatName) | 4372 || extensionEnabled(OESTextureFloatName) |
| 4363 || extensionEnabled(OESTextureHalfFloatName) | 4373 || extensionEnabled(OESTextureHalfFloatName) |
| 4364 || extensionEnabled(EXTsRGBName); | 4374 || extensionEnabled(EXTsRGBName); |
| 4365 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't suppo
rt float/integer/sRGB internal format. | 4375 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't suppo
rt float/integer/sRGB internal format. |
| 4366 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to han
dle more formats. | 4376 // FIXME: relax the constrains if copyTextureCHROMIUM is upgraded to han
dle more formats. |
| 4367 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccele
rated() || useReadBackPath) { | 4377 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccele
rated() || useReadBackPath) { |
| 4368 // 2D canvas has only FrontBuffer. | 4378 // 2D canvas has only FrontBuffer. |
| 4369 texImageImpl(TexSubImage2D, target, level, 0, xoffset, yoffset, 0, f
ormat, type, canvas->copiedImage(FrontBuffer, PreferAcceleration).get(), | 4379 texImageImpl(TexSubImage2D, target, level, 0, xoffset, yoffset, 0, f
ormat, type, canvas->copiedImage(FrontBuffer, PreferAcceleration).get(), |
| 4370 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPrem
ultiplyAlpha); | 4380 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPrem
ultiplyAlpha); |
| 4371 return; | 4381 return; |
| 4372 } | 4382 } |
| 4373 | 4383 |
| 4374 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA,
type, xoffset, yoffset, 0, canvas); | 4384 texImageByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, type,
xoffset, yoffset, 0, canvas, nullptr); |
| 4375 } else { | 4385 } else { |
| 4376 DCHECK_EQ(functionID, TexSubImage3D); | 4386 DCHECK_EQ(functionID, TexSubImage3D); |
| 4377 // FIXME: Implement GPU-to-GPU copy path (crbug.com/586269). | 4387 // FIXME: Implement GPU-to-GPU copy path (crbug.com/586269). |
| 4378 texImageImpl(TexSubImage3D, target, level, 0, xoffset, yoffset, zoffset,
format, type, canvas->copiedImage(FrontBuffer, PreferAcceleration).get(), | 4388 texImageImpl(TexSubImage3D, target, level, 0, xoffset, yoffset, zoffset,
format, type, canvas->copiedImage(FrontBuffer, PreferAcceleration).get(), |
| 4379 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti
plyAlpha); | 4389 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti
plyAlpha); |
| 4380 } | 4390 } |
| 4381 } | 4391 } |
| 4382 | 4392 |
| 4383 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4393 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
| 4384 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) | 4394 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4447 } | 4457 } |
| 4448 } | 4458 } |
| 4449 } | 4459 } |
| 4450 | 4460 |
| 4451 RefPtr<Image> image = videoFrameToImage(video); | 4461 RefPtr<Image> image = videoFrameToImage(video); |
| 4452 if (!image) | 4462 if (!image) |
| 4453 return; | 4463 return; |
| 4454 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zo
ffset, format, type, image.get(), WebGLImageConversion::HtmlDomVideo, m_unpackFl
ipY, m_unpackPremultiplyAlpha); | 4464 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zo
ffset, format, type, image.get(), WebGLImageConversion::HtmlDomVideo, m_unpackFl
ipY, m_unpackPremultiplyAlpha); |
| 4455 } | 4465 } |
| 4456 | 4466 |
| 4467 void WebGLRenderingContextBase::texImageBitmapByGPU(ImageBitmap* bitmap, GLuint
targetTexture, GLenum targetInternalformat, GLenum targetType, GLint targetLevel
) |
| 4468 { |
| 4469 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(drawin
gBuffer()->contextProvider()); |
| 4470 bitmap->bitmapImage()->copyTexture(drawingBuffer()->contextProvider(), targe
tTexture, targetInternalformat, targetType); |
| 4471 } |
| 4472 |
| 4457 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4473 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
| 4458 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) | 4474 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) |
| 4459 { | 4475 { |
| 4460 texImageHelperHTMLVideoElement(TexImage2D, target, level, internalformat, fo
rmat, type, 0, 0, 0, video, exceptionState); | 4476 texImageHelperHTMLVideoElement(TexImage2D, target, level, internalformat, fo
rmat, type, 0, 0, 0, video, exceptionState); |
| 4461 } | 4477 } |
| 4462 | 4478 |
| 4463 void WebGLRenderingContextBase::texImageHelperImageBitmap(TexImageFunctionID fun
ctionID, | 4479 void WebGLRenderingContextBase::texImageHelperImageBitmap(TexImageFunctionID fun
ctionID, |
| 4464 GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type
, GLint xoffset, | 4480 GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type
, GLint xoffset, |
| 4465 GLint yoffset, GLint zoffset, ImageBitmap* bitmap, ExceptionState& exception
State) | 4481 GLint yoffset, GLint zoffset, ImageBitmap* bitmap, ExceptionState& exception
State) |
| 4466 { | 4482 { |
| 4467 const char* funcName = getTexImageFunctionName(functionID); | 4483 const char* funcName = getTexImageFunctionName(functionID); |
| 4468 if (isContextLost()) | 4484 if (isContextLost()) |
| 4469 return; | 4485 return; |
| 4470 if (!validateImageBitmap(funcName, bitmap, exceptionState)) | 4486 if (!validateImageBitmap(funcName, bitmap, exceptionState)) |
| 4471 return; | 4487 return; |
| 4472 if (!validateTexImageBinding(funcName, functionID, target)) | 4488 WebGLTexture* texture = validateTexImageBinding(funcName, functionID, target
); |
| 4489 if (!texture) |
| 4473 return; | 4490 return; |
| 4474 TexImageFunctionType functionType; | 4491 TexImageFunctionType functionType; |
| 4475 if (functionID == TexImage2D) | 4492 if (functionID == TexImage2D) |
| 4476 functionType = TexImage; | 4493 functionType = TexImage; |
| 4477 else | 4494 else |
| 4478 functionType = TexSubImage; | 4495 functionType = TexSubImage; |
| 4479 if (!validateTexFunc(funcName, functionType, SourceImageBitmap, target, leve
l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, xoffse
t, yoffset, zoffset)) | 4496 if (!validateTexFunc(funcName, functionType, SourceImageBitmap, target, leve
l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, xoffse
t, yoffset, zoffset)) |
| 4480 return; | 4497 return; |
| 4481 ASSERT(bitmap->bitmapImage()); | 4498 ASSERT(bitmap->bitmapImage()); |
| 4499 if (bitmap->isTextureBacked() && canUseTexImageByGPU(internalformat, type))
{ |
| 4500 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->h
eight(), 0, format, type, 0); |
| 4501 texImageByGPU(TexImage2DByGPU, texture, target, level, internalformat, t
ype, 0, 0, 0, nullptr, bitmap); |
| 4502 return; |
| 4503 } |
| 4482 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); | 4504 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); |
| 4483 SkPixmap pixmap; | 4505 SkPixmap pixmap; |
| 4484 OwnPtr<uint8_t[]> pixelData; | 4506 OwnPtr<uint8_t[]> pixelData; |
| 4485 uint8_t* pixelDataPtr = nullptr; | 4507 uint8_t* pixelDataPtr = nullptr; |
| 4486 // TODO(crbug.com/613411): peekPixels fails if the SkImage is texture-backed | 4508 // In the case where an ImageBitmap is not texture backed, peekPixels() alwa
ys succeed. |
| 4487 // Use texture mailbox in that case. | 4509 // However, when it is texture backed and !canUseTexImageByGPU, we do a GPU
read back. |
| 4488 bool peekSucceed = skImage->peekPixels(&pixmap); | 4510 bool peekSucceed = skImage->peekPixels(&pixmap); |
| 4489 if (peekSucceed) { | 4511 if (peekSucceed) { |
| 4490 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); | 4512 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); |
| 4491 } else if (skImage->isTextureBacked()) { | 4513 } else { |
| 4492 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip
lyAlpha : DontPremultiplyAlpha); | 4514 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip
lyAlpha : DontPremultiplyAlpha); |
| 4493 pixelDataPtr = pixelData.get(); | 4515 pixelDataPtr = pixelData.get(); |
| 4494 } | 4516 } |
| 4495 Vector<uint8_t> data; | 4517 Vector<uint8_t> data; |
| 4496 bool needConversion = true; | 4518 bool needConversion = true; |
| 4497 bool havePeekableRGBA = (peekSucceed && pixmap.colorType() == SkColorType::k
RGBA_8888_SkColorType); | 4519 bool havePeekableRGBA = (peekSucceed && pixmap.colorType() == SkColorType::k
RGBA_8888_SkColorType); |
| 4498 bool isPixelDataRBGA = (havePeekableRGBA || !peekSucceed); | 4520 bool isPixelDataRGBA = (havePeekableRGBA || !peekSucceed); |
| 4499 if (isPixelDataRBGA && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { | 4521 if (isPixelDataRGBA && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { |
| 4500 needConversion = false; | 4522 needConversion = false; |
| 4501 } else { | 4523 } else { |
| 4502 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | 4524 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { |
| 4503 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement
ed. | 4525 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement
ed. |
| 4504 type = GL_FLOAT; | 4526 type = GL_FLOAT; |
| 4505 } | 4527 } |
| 4506 // In the case of ImageBitmap, we do not need to apply flipY or premulti
plyAlpha. | 4528 // In the case of ImageBitmap, we do not need to apply flipY or premulti
plyAlpha. |
| 4507 bool isPixelDataBGRA = (peekSucceed && pixmap.colorType() == SkColorType
::kBGRA_8888_SkColorType); | 4529 bool isPixelDataBGRA = pixmap.colorType() == SkColorType::kBGRA_8888_SkC
olorType; |
| 4508 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat
aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format,
type, false, false, data)) | 4530 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat
aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format,
type, false, false, data)) |
| 4509 || (isPixelDataRBGA && !WebGLImageConversion::extractImageData(pixel
DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form
at, type, false, false, data))) { | 4531 || (isPixelDataRGBA && !WebGLImageConversion::extractImageData(pixel
DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form
at, type, false, false, data))) { |
| 4510 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); | 4532 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); |
| 4511 return; | 4533 return; |
| 4512 } | 4534 } |
| 4513 } | 4535 } |
| 4514 resetUnpackParameters(); | 4536 resetUnpackParameters(); |
| 4515 if (functionID == TexImage2D) { | 4537 if (functionID == TexImage2D) { |
| 4516 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->h
eight(), 0, format, type, needConversion ? data.data() : pixelDataPtr); | 4538 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->h
eight(), 0, format, type, needConversion ? data.data() : pixelDataPtr); |
| 4517 } else if (functionID == TexSubImage2D) { | 4539 } else if (functionID == TexSubImage2D) { |
| 4518 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->widt
h(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr
); | 4540 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->widt
h(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr
); |
| 4519 } else { | 4541 } else { |
| (...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6425 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6447 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6426 } | 6448 } |
| 6427 | 6449 |
| 6428 void WebGLRenderingContextBase::restoreUnpackParameters() | 6450 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6429 { | 6451 { |
| 6430 if (m_unpackAlignment != 1) | 6452 if (m_unpackAlignment != 1) |
| 6431 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6453 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6432 } | 6454 } |
| 6433 | 6455 |
| 6434 } // namespace blink | 6456 } // namespace blink |
| OLD | NEW |