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 4366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4377 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEA REST); | 4377 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEA REST); |
4378 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEA REST); | 4378 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEA REST); |
4379 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_T O_EDGE); | 4379 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_T O_EDGE); |
4380 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_T O_EDGE); | 4380 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_T O_EDGE); |
4381 webContext()->texImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas- >width(), | 4381 webContext()->texImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas- >width(), |
4382 canvas->height(), 0, GL_RGBA, targetType, 0); | 4382 canvas->height(), 0, GL_RGBA, targetType, 0); |
4383 } | 4383 } |
4384 | 4384 |
4385 if (!canvas->is3D()) { | 4385 if (!canvas->is3D()) { |
4386 ImageBuffer* buffer = canvas->buffer(); | 4386 ImageBuffer* buffer = canvas->buffer(); |
4387 if (!buffer->copyToPlatformTexture(webContext(), targetTexture, targetIn ternalformat, targetType, | 4387 if (!buffer->copyToPlatformTexture(webContext(), GL_TEXTURE_2D, targetTe xture, targetInternalformat, targetType, |
4388 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4388 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
4389 ASSERT_NOT_REACHED(); | 4389 ASSERT_NOT_REACHED(); |
4390 } | 4390 } |
4391 } else { | 4391 } else { |
4392 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend eringContext()); | 4392 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend eringContext()); |
4393 ScopedTexture2DRestorer restorer(gl); | 4393 ScopedTexture2DRestorer restorer(gl); |
4394 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), targetText ure, targetInternalformat, targetType, | 4394 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), targetText ure, targetInternalformat, targetType, |
4395 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer)) { | 4395 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer)) { |
4396 ASSERT_NOT_REACHED(); | 4396 ASSERT_NOT_REACHED(); |
4397 } | 4397 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4453 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) | 4453 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) |
4454 { | 4454 { |
4455 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) | 4455 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) |
4456 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) | 4456 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) |
4457 return; | 4457 return; |
4458 | 4458 |
4459 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. | 4459 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. |
4460 // Otherwise, it will fall back to the normal SW path. | 4460 // Otherwise, it will fall back to the normal SW path. |
4461 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); | 4461 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); |
4462 ASSERT(texture); | 4462 ASSERT(texture); |
4463 if (GL_TEXTURE_2D == target) { | 4463 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type , level)) { |
4464 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level) | 4464 if (video->copyVideoTextureToPlatformTexture(webContext(), |
4465 && video->copyVideoTextureToPlatformTexture(webContext(), texture->o bject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4465 WebMediaPlayer::CopyVideoTextureParams( |
4466 WebMediaPlayer::CopyVideoTextureParams::FullCopy, target, textur e->object(), | |
4467 internalformat, type, level, 0, 0, m_unpackPremultiplyAlpha, m_u npackFlipY))) { | |
4466 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), 1, type); | 4468 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), 1, type); |
4467 return; | 4469 return; |
4468 } | 4470 } |
4469 | 4471 |
4470 // Try using an accelerated image buffer, this allows YUV conversion to be done on the GPU. | 4472 // Try using an accelerated image buffer, this allows YUV conversion to be done on the GPU. |
4471 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBuffer Surface(IntSize(video->videoWidth(), video->videoHeight()))); | 4473 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBuffer Surface(IntSize(video->videoWidth(), video->videoHeight()))); |
4472 if (surface->isValid()) { | 4474 if (surface->isValid()) { |
4473 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release( ))); | 4475 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release( ))); |
4474 if (imageBuffer) { | 4476 if (imageBuffer) { |
4475 // The video element paints an RGBA frame into our surface here. By using an AcceleratedImageBufferSurface, | 4477 // The video element paints an RGBA frame into our surface here. By using an AcceleratedImageBufferSurface, |
4476 // we enable the WebMediaPlayer implementation to do any necessa ry color space conversion on the GPU (though it | 4478 // we enable the WebMediaPlayer implementation to do any necessa ry color space conversion on the GPU (though it |
4477 // may still do a CPU conversion and upload the results). | 4479 // may still do a CPU conversion and upload the results). |
4478 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, vi deo->videoWidth(), video->videoHeight()), nullptr); | 4480 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, vi deo->videoWidth(), video->videoHeight()), nullptr); |
4479 imageBuffer->canvas()->flush(); | 4481 imageBuffer->canvas()->flush(); |
4480 | 4482 |
4481 // This is a straight GPU-GPU copy, any necessary color space co nversion was handled in the paintCurrentFrameInContext() call. | 4483 // This is a straight GPU-GPU copy, any necessary color space co nversion was handled in the paintCurrentFrameInContext() call. |
4482 if (imageBuffer->copyToPlatformTexture(webContext(), texture->ob ject(), internalformat, type, | 4484 if (imageBuffer->copyToPlatformTexture(webContext(), target, tex ture->object(), internalformat, type, |
4483 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4485 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
4484 texture->setLevelInfo(target, level, internalformat, video-> videoWidth(), video->videoHeight(), 1, type); | 4486 texture->setLevelInfo(target, level, internalformat, video-> videoWidth(), video->videoHeight(), 1, type); |
4485 return; | 4487 return; |
4486 } | 4488 } |
4487 } | 4489 } |
4488 } | 4490 } |
4489 } | 4491 } |
4490 | 4492 |
4491 // Normal pure SW path. | 4493 // Normal pure SW path. |
4492 RefPtr<Image> image = videoFrameToImage(video); | 4494 RefPtr<Image> image = videoFrameToImage(video); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4694 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas); | 4696 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas); |
4695 } | 4697 } |
4696 | 4698 |
4697 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, | 4699 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, |
4698 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) | 4700 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) |
4699 { | 4701 { |
4700 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState) | 4702 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState) |
4701 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, 0, video->videoWidth(), video->videoHeight(), 0, format, type , xoffset, yoffset)) | 4703 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, 0, video->videoWidth(), video->videoHeight(), 0, format, type , xoffset, yoffset)) |
4702 return; | 4704 return; |
4703 | 4705 |
4706 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. | |
4707 // Otherwise, it will fall back to the normal SW path. | |
4708 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true ); | |
4709 ASSERT(texture); | |
4710 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, GL_RGBA, type, level )) { | |
Ken Russell (switch to Gerrit)
2015/10/25 01:08:40
It would be great if more code could be shared bet
dshwang
2015/10/26 14:17:32
I'll merge soon.
dshwang
2015/10/26 17:45:15
Done.
| |
4711 if (video->copyVideoTextureToPlatformTexture(webContext(), | |
4712 WebMediaPlayer::CopyVideoTextureParams( | |
4713 WebMediaPlayer::CopyVideoTextureParams::SubCopy, target, texture ->object(), | |
4714 GL_FALSE, GL_FALSE, level, xoffset, yoffset, m_unpackPremultiply Alpha, m_unpackFlipY))) { | |
4715 return; | |
4716 } | |
4717 | |
4718 // Try using an accelerated image buffer, this allows YUV conversion to be done on the GPU. | |
4719 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBuffer Surface(IntSize(video->videoWidth(), video->videoHeight()))); | |
4720 if (surface->isValid()) { | |
4721 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release( ))); | |
4722 if (imageBuffer) { | |
4723 // The video element paints an RGBA frame into our surface here. By using an AcceleratedImageBufferSurface, | |
4724 // we enable the WebMediaPlayer implementation to do any necessa ry color space conversion on the GPU (though it | |
4725 // may still do a CPU conversion and upload the results). | |
4726 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, vi deo->videoWidth(), video->videoHeight()), nullptr); | |
4727 imageBuffer->canvas()->flush(); | |
4728 | |
4729 // This is a straight GPU-GPU copy, any necessary color space co nversion was handled in the paintCurrentFrameInContext() call. | |
4730 if (imageBuffer->copySubToPlatformTexture(webContext(), target, texture->object(), level, | |
4731 xoffset, yoffset, video->videoWidth(), video->videoHeight(), m_unpackPremultiplyAlpha, m_unpackFlipY)) { | |
4732 return; | |
4733 } | |
4734 } | |
4735 } | |
4736 } | |
4737 | |
4704 RefPtr<Image> image = videoFrameToImage(video); | 4738 RefPtr<Image> image = videoFrameToImage(video); |
4705 if (!image) | 4739 if (!image) |
4706 return; | 4740 return; |
4707 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); | 4741 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); |
4708 } | 4742 } |
4709 | 4743 |
4710 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) | 4744 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) |
4711 { | 4745 { |
4712 if (isContextLost() || !location) | 4746 if (isContextLost() || !location) |
4713 return; | 4747 return; |
(...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6904 | 6938 |
6905 return totalBytesPerPixel; | 6939 return totalBytesPerPixel; |
6906 } | 6940 } |
6907 | 6941 |
6908 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const | 6942 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const |
6909 { | 6943 { |
6910 return m_drawingBuffer.get(); | 6944 return m_drawingBuffer.get(); |
6911 } | 6945 } |
6912 | 6946 |
6913 } // namespace blink | 6947 } // namespace blink |
OLD | NEW |