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

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: share code in texImage2D and texSubImage2D. fix win build failure 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 4366 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
4398 } 4398 }
4399 4399
4400 if (!possibleDirectCopy) { 4400 if (!possibleDirectCopy) {
4401 WebGLId tmpFBO = webContext()->createFramebuffer(); 4401 WebGLId tmpFBO = webContext()->createFramebuffer();
4402 webContext()->bindFramebuffer(GL_FRAMEBUFFER, tmpFBO); 4402 webContext()->bindFramebuffer(GL_FRAMEBUFFER, tmpFBO);
4403 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, targetTexture, 0); 4403 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, targetTexture, 0);
4404 webContext()->bindTexture(texture->getTarget(), texture->object()); 4404 webContext()->bindTexture(texture->getTarget(), texture->object());
4405 if (functionType == NotTexSubImage2D) { 4405 if (functionType == NotTexSubImage2D) {
4406 webContext()->copyTexImage2D(target, level, internalformat, 0, 0, ca nvas->width(), canvas->height(), 0); 4406 webContext()->copyTexImage2D(target, level, internalformat, 0, 0, ca nvas->width(), canvas->height(), 0);
4407 } else if (functionType == TexSubImage2D) { 4407 } else if (functionType == TexSubImage2D) {
4408 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, 0, 0, canvas->width(), canvas->height()); 4408 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, 0, 0, canvas->width(), canvas->height());
4409 } 4409 }
4410 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); 4410 webContext()->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
4411 restoreCurrentFramebuffer(); 4411 restoreCurrentFramebuffer();
4412 webContext()->deleteFramebuffer(tmpFBO); 4412 webContext()->deleteFramebuffer(tmpFBO);
4413 webContext()->deleteTexture(targetTexture); 4413 webContext()->deleteTexture(targetTexture);
4414 } 4414 }
4415 } 4415 }
4416 4416
4417 bool WebGLRenderingContextBase::texImage2DVideoByGPU(TexImageFunctionType functi onType, WebGLTexture* texture, GLenum target,
4418 GLint level, GLenum internalformat, GLenum type, GLint xoffset, GLint yoffse t, HTMLVideoElement* video)
4419 {
4420 typedef WebMediaPlayer::CopyVideoTextureParams CopyParams;
4421 if (video->copyVideoTextureToPlatformTexture(webContext(),
4422 CopyParams(
4423 functionType == NotTexSubImage2D ? CopyParams::FullCopy : CopyParams ::SubCopy,
4424 target, texture->object(), internalformat, type, level, xoffset,
4425 yoffset, m_unpackPremultiplyAlpha, m_unpackFlipY))) {
4426 if (functionType == NotTexSubImage2D)
4427 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), 1, type);
4428 return true;
4429 }
4430
4431 // Try using an accelerated image buffer, this allows YUV conversion to be d one on the GPU.
4432 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBufferSurf ace(IntSize(video->videoWidth(), video->videoHeight())));
4433 if (surface->isValid()) {
4434 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release()));
4435 if (imageBuffer) {
4436 // The video element paints an RGBA frame into our surface here. By using an AcceleratedImageBufferSurface,
4437 // we enable the WebMediaPlayer implementation to do any necessary c olor space conversion on the GPU (though it
4438 // may still do a CPU conversion and upload the results).
4439 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, video- >videoWidth(), video->videoHeight()), nullptr);
4440 imageBuffer->canvas()->flush();
4441
4442 // This is a straight GPU-GPU copy, any necessary color space conver sion was handled in the paintCurrentFrameInContext() call.
4443 switch (functionType) {
4444 case NotTexSubImage2D:
4445 if (imageBuffer->copyToPlatformTexture(webContext(), target, tex ture->object(), internalformat, type,
4446 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4447 texture->setLevelInfo(target, level, internalformat, video-> videoWidth(), video->videoHeight(), 1, type);
4448 return true;
4449 }
4450 break;
4451 case TexSubImage2D:
4452 if (imageBuffer->copySubToPlatformTexture(webContext(), target, texture->object(), level,
4453 xoffset, yoffset, video->videoWidth(), video->videoHeight(), m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4454 return true;
4455 }
4456 break;
4457 }
4458 }
4459 }
4460 return false;
4461 }
4462
4417 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4463 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4418 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 4464 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
4419 { 4465 {
4420 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)) 4466 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))
4421 return; 4467 return;
4422 4468
4423 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4469 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4424 ASSERT(texture); 4470 ASSERT(texture);
4425 4471
4426 // texImage2DCanvasByGPU relies on copyTextureCHROMIUM which doesn't support float/integer/sRGB internal format. 4472 // texImage2DCanvasByGPU relies on copyTextureCHROMIUM which doesn't support float/integer/sRGB internal format.
(...skipping 26 matching lines...) Expand all
4453 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4499 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4454 { 4500 {
4455 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) 4501 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)) 4502 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0))
4457 return; 4503 return;
4458 4504
4459 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 4505 // 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. 4506 // Otherwise, it will fall back to the normal SW path.
4461 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4507 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4462 ASSERT(texture); 4508 ASSERT(texture);
4463 if (GL_TEXTURE_2D == target) { 4509 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type , level)) {
4464 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level) 4510 if (texImage2DVideoByGPU(NotTexSubImage2D, texture, target, level, inter nalformat, type, 0, 0, video))
4465 && video->copyVideoTextureToPlatformTexture(webContext(), texture->o bject(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4466 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), 1, type);
4467 return; 4511 return;
4468 }
4469
4470 // 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())));
4472 if (surface->isValid()) {
4473 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(surface.release( )));
4474 if (imageBuffer) {
4475 // 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
4477 // may still do a CPU conversion and upload the results).
4478 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0, vi deo->videoWidth(), video->videoHeight()), nullptr);
4479 imageBuffer->canvas()->flush();
4480
4481 // 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,
4483 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4484 texture->setLevelInfo(target, level, internalformat, video-> videoWidth(), video->videoHeight(), 1, type);
4485 return;
4486 }
4487 }
4488 }
4489 } 4512 }
4490 4513
4491 // Normal pure SW path. 4514 // Normal pure SW path.
4492 RefPtr<Image> image = videoFrameToImage(video); 4515 RefPtr<Image> image = videoFrameToImage(video);
4493 if (!image) 4516 if (!image)
4494 return; 4517 return;
4495 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); 4518 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha);
4496 } 4519 }
4497 4520
4498 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat) 4521 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
4694 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas); 4717 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas);
4695 } 4718 }
4696 4719
4697 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4720 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4698 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4721 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4699 { 4722 {
4700 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState) 4723 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)) 4724 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, 0, video->videoWidth(), video->videoHeight(), 0, format, type , xoffset, yoffset))
4702 return; 4725 return;
4703 4726
4727 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
4728 // Otherwise, it will fall back to the normal SW path.
4729 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true );
4730 ASSERT(texture);
4731 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, GL_RGBA, type, level )) {
4732 if (texImage2DVideoByGPU(TexSubImage2D, texture, target, level, GL_FALSE ,
4733 GL_FALSE, xoffset, yoffset, video))
4734 return;
4735 }
4736
4704 RefPtr<Image> image = videoFrameToImage(video); 4737 RefPtr<Image> image = videoFrameToImage(video);
4705 if (!image) 4738 if (!image)
4706 return; 4739 return;
4707 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); 4740 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha);
4708 } 4741 }
4709 4742
4710 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) 4743 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x)
4711 { 4744 {
4712 if (isContextLost() || !location) 4745 if (isContextLost() || !location)
4713 return; 4746 return;
(...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after
6904 6937
6905 return totalBytesPerPixel; 6938 return totalBytesPerPixel;
6906 } 6939 }
6907 6940
6908 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6941 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6909 { 6942 {
6910 return m_drawingBuffer.get(); 6943 return m_drawingBuffer.get();
6911 } 6944 }
6912 6945
6913 } // namespace blink 6946 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698