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

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

Issue 1418513016: Revert of webgl: optimize webgl.texSubImage2D(video) path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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(), GL_TEXTURE_2D, targetTe xture, targetInternalformat, targetType, 4388 if (!buffer->copyToPlatformTexture(webContext(), targetTexture, targetIn ternalformat, 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
4465 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 4420 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
4466 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 4421 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
4467 { 4422 {
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)) 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))
4469 return; 4424 return;
4470 4425
4471 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4426 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4472 ASSERT(texture); 4427 ASSERT(texture);
4473 4428
4474 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format. 4429 // texImageCanvasByGPU relies on copyTextureCHROMIUM which doesn't support f loat/integer/sRGB internal format.
(...skipping 26 matching lines...) Expand all
4501 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4456 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4502 { 4457 {
4503 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) 4458 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState)
4504 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) 4459 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0))
4505 return; 4460 return;
4506 4461
4507 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 4462 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
4508 // Otherwise, it will fall back to the normal SW path. 4463 // Otherwise, it will fall back to the normal SW path.
4509 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4464 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4510 ASSERT(texture); 4465 ASSERT(texture);
4511 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type , level)) { 4466 if (GL_TEXTURE_2D == target) {
4512 if (texImage2DVideoByGPU(NotTexSubImage2D, texture, target, level, inter nalformat, type, 0, 0, video)) 4467 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalformat, type, level)
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);
4513 return; 4470 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 }
4514 } 4491 }
4515 4492
4516 // Normal pure SW path. 4493 // Normal pure SW path.
4517 RefPtr<Image> image = videoFrameToImage(video); 4494 RefPtr<Image> image = videoFrameToImage(video);
4518 if (!image) 4495 if (!image)
4519 return; 4496 return;
4520 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); 4497 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha);
4521 } 4498 }
4522 4499
4523 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat) 4500 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
4719 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ e, xoffset, yoffset, 0, canvas); 4696 texImageCanvasByGPU(TexSubImage2DByGPU, texture, target, level, GL_RGBA, typ e, xoffset, yoffset, 0, canvas);
4720 } 4697 }
4721 4698
4722 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4699 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4723 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4700 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4724 { 4701 {
4725 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState) 4702 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState)
4726 || !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))
4727 return; 4704 return;
4728 4705
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
4739 RefPtr<Image> image = videoFrameToImage(video); 4706 RefPtr<Image> image = videoFrameToImage(video);
4740 if (!image) 4707 if (!image)
4741 return; 4708 return;
4742 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); 4709 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha);
4743 } 4710 }
4744 4711
4745 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) 4712 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x)
4746 { 4713 {
4747 if (isContextLost() || !location) 4714 if (isContextLost() || !location)
4748 return; 4715 return;
(...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after
6939 6906
6940 return totalBytesPerPixel; 6907 return totalBytesPerPixel;
6941 } 6908 }
6942 6909
6943 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6910 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6944 { 6911 {
6945 return m_drawingBuffer.get(); 6912 return m_drawingBuffer.get();
6946 } 6913 }
6947 6914
6948 } // namespace blink 6915 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698