| 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 4372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4383 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEA
REST); | 4383 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEA
REST); |
| 4384 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEA
REST); | 4384 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEA
REST); |
| 4385 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_T
O_EDGE); | 4385 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_T
O_EDGE); |
| 4386 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_T
O_EDGE); | 4386 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_T
O_EDGE); |
| 4387 webContext()->texImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas-
>width(), | 4387 webContext()->texImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas-
>width(), |
| 4388 canvas->height(), 0, GL_RGBA, targetType, 0); | 4388 canvas->height(), 0, GL_RGBA, targetType, 0); |
| 4389 } | 4389 } |
| 4390 | 4390 |
| 4391 if (!canvas->is3D()) { | 4391 if (!canvas->is3D()) { |
| 4392 ImageBuffer* buffer = canvas->buffer(); | 4392 ImageBuffer* buffer = canvas->buffer(); |
| 4393 if (!buffer->copyToPlatformTexture(webContext(), GL_TEXTURE_2D, targetTe
xture, targetInternalformat, targetType, | 4393 if (!buffer->copyToPlatformTexture(webContext(), targetTexture, targetIn
ternalformat, targetType, |
| 4394 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4394 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 4395 ASSERT_NOT_REACHED(); | 4395 ASSERT_NOT_REACHED(); |
| 4396 } | 4396 } |
| 4397 } else { | 4397 } else { |
| 4398 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); | 4398 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); |
| 4399 ScopedTexture2DRestorer restorer(gl); | 4399 ScopedTexture2DRestorer restorer(gl); |
| 4400 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), targetText
ure, targetInternalformat, targetType, | 4400 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), targetText
ure, targetInternalformat, targetType, |
| 4401 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ | 4401 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ |
| 4402 ASSERT_NOT_REACHED(); | 4402 ASSERT_NOT_REACHED(); |
| 4403 } | 4403 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4415 } else if (functionType == TexSubImage3DByGPU) { | 4415 } else if (functionType == TexSubImage3DByGPU) { |
| 4416 webContext()->copyTexSubImage3D(target, level, xoffset, yoffset, zof
fset, 0, 0, canvas->width(), canvas->height()); | 4416 webContext()->copyTexSubImage3D(target, level, xoffset, yoffset, zof
fset, 0, 0, canvas->width(), canvas->height()); |
| 4417 } | 4417 } |
| 4418 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, 0, 0); | 4418 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, 0, 0); |
| 4419 restoreCurrentFramebuffer(); | 4419 restoreCurrentFramebuffer(); |
| 4420 webContext()->deleteFramebuffer(tmpFBO); | 4420 webContext()->deleteFramebuffer(tmpFBO); |
| 4421 webContext()->deleteTexture(targetTexture); | 4421 webContext()->deleteTexture(targetTexture); |
| 4422 } | 4422 } |
| 4423 } | 4423 } |
| 4424 | 4424 |
| 4425 bool WebGLRenderingContextBase::texImage2DVideoByGPU(TexImageFunctionType functi
onType, WebGLTexture* texture, GLenum target, | |
| 4426 GLint level, GLenum internalformat, GLenum type, GLint xoffset, GLint yoffse
t, HTMLVideoElement* video) | |
| 4427 { | |
| 4428 typedef WebMediaPlayer::CopyVideoTextureParams CopyParams; | |
| 4429 if (video->copyVideoTextureToPlatformTexture(webContext(), | |
| 4430 CopyParams( | |
| 4431 functionType == NotTexSubImage2D ? CopyParams::FullCopy : CopyParams
::SubCopy, | |
| 4432 target, texture->object(), internalformat, type, level, xoffset, | |
| 4433 yoffset, m_unpackPremultiplyAlpha, m_unpackFlipY))) { | |
| 4434 if (functionType == NotTexSubImage2D) | |
| 4435 texture->setLevelInfo(target, level, internalformat, video->videoWid
th(), video->videoHeight(), 1, type); | |
| 4436 return true; | |
| 4437 } | |
| 4438 | |
| 4439 // Try using an accelerated image buffer, this allows YUV conversion to be d
one on the GPU. | |
| 4440 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBufferSurf
ace(IntSize(video->videoWidth(), video->videoHeight()))); | |
| 4441 if (surface->isValid()) { | |
| 4442 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release())); | |
| 4443 if (imageBuffer) { | |
| 4444 // The video element paints an RGBA frame into our surface here. By
using an AcceleratedImageBufferSurface, | |
| 4445 // we enable the WebMediaPlayer implementation to do any necessary c
olor space conversion on the GPU (though it | |
| 4446 // may still do a CPU conversion and upload the results). | |
| 4447 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, video-
>videoWidth(), video->videoHeight()), nullptr); | |
| 4448 | |
| 4449 // This is a straight GPU-GPU copy, any necessary color space conver
sion was handled in the paintCurrentFrameInContext() call. | |
| 4450 switch (functionType) { | |
| 4451 case NotTexSubImage2D: | |
| 4452 if (imageBuffer->copyToPlatformTexture(webContext(), target, tex
ture->object(), internalformat, type, | |
| 4453 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | |
| 4454 texture->setLevelInfo(target, level, internalformat, video->
videoWidth(), video->videoHeight(), 1, type); | |
| 4455 return true; | |
| 4456 } | |
| 4457 break; | |
| 4458 case TexSubImage2D: | |
| 4459 if (imageBuffer->copySubToPlatformTexture(webContext(), target,
texture->object(), level, | |
| 4460 xoffset, yoffset, video->videoWidth(), video->videoHeight(),
m_unpackPremultiplyAlpha, m_unpackFlipY)) { | |
| 4461 return true; | |
| 4462 } | |
| 4463 break; | |
| 4464 } | |
| 4465 } | |
| 4466 } | |
| 4467 return false; | |
| 4468 } | |
| 4469 | |
| 4470 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in
ternalformat, | 4425 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in
ternalformat, |
| 4471 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) | 4426 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) |
| 4472 { | 4427 { |
| 4473 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce
ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas
Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo
rmat, type, 0, 0)) | 4428 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce
ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas
Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo
rmat, type, 0, 0)) |
| 4474 return; | 4429 return; |
| 4475 | 4430 |
| 4476 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); | 4431 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); |
| 4477 ASSERT(texture); | 4432 ASSERT(texture); |
| 4478 | 4433 |
| 4479 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f
loat/integer/sRGB internal format. | 4434 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f
loat/integer/sRGB internal format. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 4506 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) | 4461 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) |
| 4507 { | 4462 { |
| 4508 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except
ionState) | 4463 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except
ionState) |
| 4509 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme
nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0,
format, type, 0, 0)) | 4464 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme
nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0,
format, type, 0, 0)) |
| 4510 return; | 4465 return; |
| 4511 | 4466 |
| 4512 // Go through the fast path doing a GPU-GPU textures copy without a readback
to system memory if possible. | 4467 // Go through the fast path doing a GPU-GPU textures copy without a readback
to system memory if possible. |
| 4513 // Otherwise, it will fall back to the normal SW path. | 4468 // Otherwise, it will fall back to the normal SW path. |
| 4514 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); | 4469 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); |
| 4515 ASSERT(texture); | 4470 ASSERT(texture); |
| 4516 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type
, level)) { | 4471 if (GL_TEXTURE_2D == target) { |
| 4517 if (texImage2DVideoByGPU(NotTexSubImage2D, texture, target, level, inter
nalformat, type, 0, 0, video)) | 4472 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat,
type, level) |
| 4473 && video->copyVideoTextureToPlatformTexture(webContext(), texture->o
bject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 4474 texture->setLevelInfo(target, level, internalformat, video->videoWid
th(), video->videoHeight(), 1, type); |
| 4518 return; | 4475 return; |
| 4476 } |
| 4477 |
| 4478 // Try using an accelerated image buffer, this allows YUV conversion to
be done on the GPU. |
| 4479 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBuffer
Surface(IntSize(video->videoWidth(), video->videoHeight()))); |
| 4480 if (surface->isValid()) { |
| 4481 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release(
))); |
| 4482 if (imageBuffer) { |
| 4483 // The video element paints an RGBA frame into our surface here.
By using an AcceleratedImageBufferSurface, |
| 4484 // we enable the WebMediaPlayer implementation to do any necessa
ry color space conversion on the GPU (though it |
| 4485 // may still do a CPU conversion and upload the results). |
| 4486 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, vi
deo->videoWidth(), video->videoHeight()), nullptr); |
| 4487 |
| 4488 // This is a straight GPU-GPU copy, any necessary color space co
nversion was handled in the paintCurrentFrameInContext() call. |
| 4489 if (imageBuffer->copyToPlatformTexture(webContext(), texture->ob
ject(), internalformat, type, |
| 4490 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 4491 texture->setLevelInfo(target, level, internalformat, video->
videoWidth(), video->videoHeight(), 1, type); |
| 4492 return; |
| 4493 } |
| 4494 } |
| 4495 } |
| 4519 } | 4496 } |
| 4520 | 4497 |
| 4521 // Normal pure SW path. | 4498 // Normal pure SW path. |
| 4522 RefPtr<Image> image = videoFrameToImage(video); | 4499 RefPtr<Image> image = videoFrameToImage(video); |
| 4523 if (!image) | 4500 if (!image) |
| 4524 return; | 4501 return; |
| 4525 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web
GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); | 4502 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web
GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); |
| 4526 } | 4503 } |
| 4527 | 4504 |
| 4528 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa
t paramf, GLint parami, bool isFloat) | 4505 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa
t paramf, GLint parami, bool isFloat) |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4724 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ
e, xoffset, yoffset, 0, canvas); | 4701 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ
e, xoffset, yoffset, 0, canvas); |
| 4725 } | 4702 } |
| 4726 | 4703 |
| 4727 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, | 4704 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, |
| 4728 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) | 4705 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti
onState) |
| 4729 { | 4706 { |
| 4730 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc
eptionState) | 4707 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc
eptionState) |
| 4731 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme
nt, target, level, 0, video->videoWidth(), video->videoHeight(), 0, format, type
, xoffset, yoffset)) | 4708 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme
nt, target, level, 0, video->videoWidth(), video->videoHeight(), 0, format, type
, xoffset, yoffset)) |
| 4732 return; | 4709 return; |
| 4733 | 4710 |
| 4734 // Go through the fast path doing a GPU-GPU textures copy without a readback
to system memory if possible. | |
| 4735 // Otherwise, it will fall back to the normal SW path. | |
| 4736 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true
); | |
| 4737 ASSERT(texture); | |
| 4738 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, GL_RGBA, type, level
)) { | |
| 4739 if (texImage2DVideoByGPU(TexSubImage2D, texture, target, level, GL_FALSE
, | |
| 4740 GL_FALSE, xoffset, yoffset, video)) | |
| 4741 return; | |
| 4742 } | |
| 4743 | |
| 4744 RefPtr<Image> image = videoFrameToImage(video); | 4711 RefPtr<Image> image = videoFrameToImage(video); |
| 4745 if (!image) | 4712 if (!image) |
| 4746 return; | 4713 return; |
| 4747 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get()
, WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); | 4714 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get()
, WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); |
| 4748 } | 4715 } |
| 4749 | 4716 |
| 4750 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location,
GLfloat x) | 4717 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location,
GLfloat x) |
| 4751 { | 4718 { |
| 4752 if (isContextLost() || !location) | 4719 if (isContextLost() || !location) |
| 4753 return; | 4720 return; |
| (...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6944 | 6911 |
| 6945 return totalBytesPerPixel; | 6912 return totalBytesPerPixel; |
| 6946 } | 6913 } |
| 6947 | 6914 |
| 6948 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 6915 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
| 6949 { | 6916 { |
| 6950 return m_drawingBuffer.get(); | 6917 return m_drawingBuffer.get(); |
| 6951 } | 6918 } |
| 6952 | 6919 |
| 6953 } // namespace blink | 6920 } // namespace blink |
| OLD | NEW |