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

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

Powered by Google App Engine
This is Rietveld 408576698