Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 1315323006: webgl: optimize webgl.texSubImage2D(video) path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix canvas2d-webgl failures Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 4377 matching lines...) Expand 10 before | Expand all | Expand 10 after
4388 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEA REST); 4388 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEA REST);
4389 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEA REST); 4389 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEA REST);
4390 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_T O_EDGE); 4390 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_T O_EDGE);
4391 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_T O_EDGE); 4391 webContext()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_T O_EDGE);
4392 webContext()->texImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas- >width(), 4392 webContext()->texImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas- >width(),
4393 canvas->height(), 0, GL_RGBA, targetType, 0); 4393 canvas->height(), 0, GL_RGBA, targetType, 0);
4394 } 4394 }
4395 4395
4396 if (!canvas->is3D()) { 4396 if (!canvas->is3D()) {
4397 ImageBuffer* buffer = canvas->buffer(); 4397 ImageBuffer* buffer = canvas->buffer();
4398 if (!buffer->copyToPlatformTexture(webContext(), targetTexture, targetIn ternalformat, targetType, 4398 if (!buffer->copyToPlatformTexture(webContext(), GL_TEXTURE_2D, targetTe xture, targetInternalformat, targetType,
4399 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 4399 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4400 ASSERT_NOT_REACHED(); 4400 ASSERT_NOT_REACHED();
4401 } 4401 }
4402 } else { 4402 } else {
4403 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend eringContext()); 4403 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend eringContext());
4404 ScopedTexture2DRestorer restorer(gl); 4404 ScopedTexture2DRestorer restorer(gl);
4405 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), targetText ure, targetInternalformat, targetType, 4405 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), targetText ure, targetInternalformat, targetType,
4406 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer)) { 4406 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer)) {
4407 ASSERT_NOT_REACHED(); 4407 ASSERT_NOT_REACHED();
4408 } 4408 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
4464 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4464 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4465 { 4465 {
4466 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) 4466 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState)
4467 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) 4467 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0))
4468 return; 4468 return;
4469 4469
4470 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 4470 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
4471 // Otherwise, it will fall back to the normal SW path. 4471 // Otherwise, it will fall back to the normal SW path.
4472 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4472 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4473 ASSERT(texture); 4473 ASSERT(texture);
4474 if (GL_TEXTURE_2D == target) { 4474 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type , level)
4475 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level) 4475 && video->copyVideoTextureToPlatformTexture(webContext(), {
4476 && video->copyVideoTextureToPlatformTexture(webContext(), texture->o bject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 4476 WebMediaPlayer::CopyVideoTextureParams::FullCopy, target, texture->o bject(),
4477 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), 1, type); 4477 internalformat, type, level, 0, 0, m_unpackPremultiplyAlpha, m_unpac kFlipY
4478 return; 4478 })) {
4479 } 4479 texture->setLevelInfo(target, level, internalformat, video->videoWidth() , video->videoHeight(), 1, type);
4480 return;
4481 }
4480 4482
4481 // Try using an accelerated image buffer, this allows YUV conversion to be done on the GPU. 4483 // Try using an accelerated image buffer, this allows YUV conversion to be d one on the GPU.
4482 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBuffer Surface(IntSize(video->videoWidth(), video->videoHeight()))); 4484 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBufferSurf ace(IntSize(video->videoWidth(), video->videoHeight())));
4483 if (surface->isValid()) { 4485 if (surface->isValid()) {
4484 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release( ))); 4486 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release()));
4485 if (imageBuffer) { 4487 if (imageBuffer) {
4486 // The video element paints an RGBA frame into our surface here. By using an AcceleratedImageBufferSurface, 4488 // The video element paints an RGBA frame into our surface here. By using an AcceleratedImageBufferSurface,
4487 // we enable the WebMediaPlayer implementation to do any necessa ry color space conversion on the GPU (though it 4489 // we enable the WebMediaPlayer implementation to do any necessary c olor space conversion on the GPU (though it
4488 // may still do a CPU conversion and upload the results). 4490 // may still do a CPU conversion and upload the results).
4489 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, vi deo->videoWidth(), video->videoHeight()), nullptr); 4491 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, video- >videoWidth(), video->videoHeight()), nullptr);
4490 imageBuffer->canvas()->flush(); 4492 imageBuffer->canvas()->flush();
4491 4493
4492 // This is a straight GPU-GPU copy, any necessary color space co nversion was handled in the paintCurrentFrameInContext() call. 4494 // This is a straight GPU-GPU copy, any necessary color space conver sion was handled in the paintCurrentFrameInContext() call.
4493 if (imageBuffer->copyToPlatformTexture(webContext(), texture->ob ject(), internalformat, type, 4495 if (imageBuffer->copyToPlatformTexture(webContext(), target, texture ->object(), internalformat, type,
4494 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 4496 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4495 texture->setLevelInfo(target, level, internalformat, video-> videoWidth(), video->videoHeight(), 1, type); 4497 texture->setLevelInfo(target, level, internalformat, video->vide oWidth(), video->videoHeight(), 1, type);
4496 return; 4498 return;
4497 }
4498 } 4499 }
4499 } 4500 }
4500 } 4501 }
4501 4502
4502 // Normal pure SW path. 4503 // Normal pure SW path.
4503 RefPtr<Image> image = videoFrameToImage(video); 4504 RefPtr<Image> image = videoFrameToImage(video);
4504 if (!image) 4505 if (!image)
4505 return; 4506 return;
4506 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); 4507 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha);
4507 } 4508 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
4705 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas); 4706 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas);
4706 } 4707 }
4707 4708
4708 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4709 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4709 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4710 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4710 { 4711 {
4711 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState) 4712 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState)
4712 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, 0, video->videoWidth(), video->videoHeight(), 0, format, type , xoffset, yoffset)) 4713 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, 0, video->videoWidth(), video->videoHeight(), 0, format, type , xoffset, yoffset))
4713 return; 4714 return;
4714 4715
4716 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
4717 // Otherwise, it will fall back to the normal SW path.
4718 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true );
4719 ASSERT(texture);
4720 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, GL_RGBA, type, level )
4721 && video->copyVideoTextureToPlatformTexture(webContext(), {
4722 WebMediaPlayer::CopyVideoTextureParams::SubCopy, target, texture->ob ject(),
4723 GL_FALSE, GL_FALSE, level, xoffset, yoffset, m_unpackPremultiplyAlph a, m_unpackFlipY
4724 })) {
4725 return;
4726 }
4727
4728 // Try using an accelerated image buffer, this allows YUV conversion to be d one on the GPU.
4729 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBufferSurf ace(IntSize(video->videoWidth(), video->videoHeight())));
4730 if (surface->isValid()) {
4731 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release()));
4732 if (imageBuffer) {
4733 // The video element paints an RGBA frame into our surface here. By using an AcceleratedImageBufferSurface,
4734 // we enable the WebMediaPlayer implementation to do any necessary c olor space conversion on the GPU (though it
4735 // may still do a CPU conversion and upload the results).
4736 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, video- >videoWidth(), video->videoHeight()), nullptr);
4737 imageBuffer->canvas()->flush();
4738
4739 // This is a straight GPU-GPU copy, any necessary color space conver sion was handled in the paintCurrentFrameInContext() call.
4740 if (imageBuffer->copySubToPlatformTexture(webContext(), target, text ure->object(), level,
4741 xoffset, yoffset, video->videoWidth(), video->videoHeight(), m_u npackPremultiplyAlpha, m_unpackFlipY)) {
4742 return;
4743 }
4744 }
4745 }
4746
4715 RefPtr<Image> image = videoFrameToImage(video); 4747 RefPtr<Image> image = videoFrameToImage(video);
4716 if (!image) 4748 if (!image)
4717 return; 4749 return;
4718 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); 4750 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha);
4719 } 4751 }
4720 4752
4721 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) 4753 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x)
4722 { 4754 {
4723 if (isContextLost() || !location) 4755 if (isContextLost() || !location)
4724 return; 4756 return;
(...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after
6915 6947
6916 return totalBytesPerPixel; 6948 return totalBytesPerPixel;
6917 } 6949 }
6918 6950
6919 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6951 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6920 { 6952 {
6921 return m_drawingBuffer.get(); 6953 return m_drawingBuffer.get();
6922 } 6954 }
6923 6955
6924 } // namespace blink 6956 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698