| 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 5275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5286 // Note that neither | 5286 // Note that neither |
| 5287 // HTMLVideoElement::copyVideoTextureToPlatformTexture nor | 5287 // HTMLVideoElement::copyVideoTextureToPlatformTexture nor |
| 5288 // ImageBuffer::copyToPlatformTexture allocate the destination texture | 5288 // ImageBuffer::copyToPlatformTexture allocate the destination texture |
| 5289 // any more. | 5289 // any more. |
| 5290 texImage2DBase(target, level, internalformat, video->videoWidth(), | 5290 texImage2DBase(target, level, internalformat, video->videoWidth(), |
| 5291 video->videoHeight(), 0, format, type, nullptr); | 5291 video->videoHeight(), 0, format, type, nullptr); |
| 5292 | 5292 |
| 5293 if (video->copyVideoTextureToPlatformTexture(contextGL(), texture->object(), | 5293 if (video->copyVideoTextureToPlatformTexture(contextGL(), texture->object(), |
| 5294 m_unpackPremultiplyAlpha, | 5294 m_unpackPremultiplyAlpha, |
| 5295 m_unpackFlipY)) { | 5295 m_unpackFlipY)) { |
| 5296 texture->updateLastUploadedVideo(video->webMediaPlayer()); |
| 5296 return; | 5297 return; |
| 5297 } | 5298 } |
| 5298 | 5299 |
| 5299 // Try using an accelerated image buffer, this allows YUV conversion to be | 5300 // Try using an accelerated image buffer, this allows YUV conversion to be |
| 5300 // done on the GPU. | 5301 // done on the GPU. |
| 5301 std::unique_ptr<ImageBufferSurface> surface = | 5302 std::unique_ptr<ImageBufferSurface> surface = |
| 5302 WTF::wrapUnique(new AcceleratedImageBufferSurface( | 5303 WTF::wrapUnique(new AcceleratedImageBufferSurface( |
| 5303 IntSize(video->videoWidth(), video->videoHeight()))); | 5304 IntSize(video->videoWidth(), video->videoHeight()))); |
| 5304 if (surface->isValid()) { | 5305 if (surface->isValid()) { |
| 5305 std::unique_ptr<ImageBuffer> imageBuffer( | 5306 std::unique_ptr<ImageBuffer> imageBuffer( |
| 5306 ImageBuffer::create(std::move(surface))); | 5307 ImageBuffer::create(std::move(surface))); |
| 5307 if (imageBuffer) { | 5308 if (imageBuffer) { |
| 5308 // The video element paints an RGBA frame into our surface here. By | 5309 // The video element paints an RGBA frame into our surface here. By |
| 5309 // using an AcceleratedImageBufferSurface, we enable the WebMediaPlayer | 5310 // using an AcceleratedImageBufferSurface, we enable the WebMediaPlayer |
| 5310 // implementation to do any necessary color space conversion on the GPU | 5311 // implementation to do any necessary color space conversion on the GPU |
| 5311 // (though it may still do a CPU conversion and upload the results). | 5312 // (though it may still do a CPU conversion and upload the results). |
| 5312 video->paintCurrentFrame( | 5313 video->paintCurrentFrame( |
| 5313 imageBuffer->canvas(), | 5314 imageBuffer->canvas(), |
| 5314 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr); | 5315 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr); |
| 5315 | 5316 |
| 5316 // This is a straight GPU-GPU copy, any necessary color space conversion | 5317 // This is a straight GPU-GPU copy, any necessary color space conversion |
| 5317 // was handled in the paintCurrentFrameInContext() call. | 5318 // was handled in the paintCurrentFrameInContext() call. |
| 5318 | 5319 |
| 5319 if (imageBuffer->copyToPlatformTexture( | 5320 if (imageBuffer->copyToPlatformTexture( |
| 5320 functionIDToSnapshotReason(functionID), contextGL(), | 5321 functionIDToSnapshotReason(functionID), contextGL(), |
| 5321 texture->object(), internalformat, type, level, | 5322 texture->object(), internalformat, type, level, |
| 5322 m_unpackPremultiplyAlpha, m_unpackFlipY, IntPoint(0, 0), | 5323 m_unpackPremultiplyAlpha, m_unpackFlipY, IntPoint(0, 0), |
| 5323 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) { | 5324 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) { |
| 5325 texture->updateLastUploadedVideo(video->webMediaPlayer()); |
| 5324 return; | 5326 return; |
| 5325 } | 5327 } |
| 5326 } | 5328 } |
| 5327 } | 5329 } |
| 5328 } | 5330 } |
| 5329 | 5331 |
| 5330 if (sourceImageRectIsDefault) { | 5332 if (sourceImageRectIsDefault) { |
| 5331 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. It | 5333 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. It |
| 5332 // leaves early for other formats or if frame is stored on GPU. | 5334 // leaves early for other formats or if frame is stored on GPU. |
| 5333 ScopedUnpackParametersResetRestore( | 5335 ScopedUnpackParametersResetRestore( |
| 5334 this, m_unpackFlipY || m_unpackPremultiplyAlpha); | 5336 this, m_unpackFlipY || m_unpackPremultiplyAlpha); |
| 5335 if (video->texImageImpl( | 5337 if (video->texImageImpl( |
| 5336 static_cast<WebMediaPlayer::TexImageFunctionID>(functionID), target, | 5338 static_cast<WebMediaPlayer::TexImageFunctionID>(functionID), target, |
| 5337 contextGL(), level, convertTexInternalFormat(internalformat, type), | 5339 contextGL(), level, convertTexInternalFormat(internalformat, type), |
| 5338 format, type, xoffset, yoffset, zoffset, m_unpackFlipY, | 5340 format, type, xoffset, yoffset, zoffset, m_unpackFlipY, |
| 5339 m_unpackPremultiplyAlpha && | 5341 m_unpackPremultiplyAlpha && |
| 5340 m_unpackColorspaceConversion == GL_NONE)) | 5342 m_unpackColorspaceConversion == GL_NONE)) { |
| 5343 texture->updateLastUploadedVideo(video->webMediaPlayer()); |
| 5341 return; | 5344 return; |
| 5345 } |
| 5342 } | 5346 } |
| 5343 | 5347 |
| 5344 RefPtr<Image> image = videoFrameToImage(video); | 5348 RefPtr<Image> image = videoFrameToImage(video); |
| 5345 if (!image) | 5349 if (!image) |
| 5346 return; | 5350 return; |
| 5347 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, | 5351 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, |
| 5348 zoffset, format, type, image.get(), | 5352 zoffset, format, type, image.get(), |
| 5349 WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, | 5353 WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, |
| 5350 m_unpackPremultiplyAlpha, sourceImageRect, depth, | 5354 m_unpackPremultiplyAlpha, sourceImageRect, depth, |
| 5351 unpackImageHeight); | 5355 unpackImageHeight); |
| 5356 texture->updateLastUploadedVideo(video->webMediaPlayer()); |
| 5352 } | 5357 } |
| 5353 | 5358 |
| 5354 void WebGLRenderingContextBase::texImageBitmapByGPU(ImageBitmap* bitmap, | 5359 void WebGLRenderingContextBase::texImageBitmapByGPU(ImageBitmap* bitmap, |
| 5355 GLuint targetTexture, | 5360 GLuint targetTexture, |
| 5356 GLenum targetInternalformat, | 5361 GLenum targetInternalformat, |
| 5357 GLenum targetType, | 5362 GLenum targetType, |
| 5358 GLint targetLevel, | 5363 GLint targetLevel, |
| 5359 bool flipY) { | 5364 bool flipY) { |
| 5360 bitmap->bitmapImage()->copyToTexture(drawingBuffer()->contextProvider(), | 5365 bitmap->bitmapImage()->copyToTexture(drawingBuffer()->contextProvider(), |
| 5361 targetTexture, targetInternalformat, | 5366 targetTexture, targetInternalformat, |
| (...skipping 2483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7845 | 7850 |
| 7846 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( | 7851 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( |
| 7847 HTMLCanvasElementOrOffscreenCanvas& result) const { | 7852 HTMLCanvasElementOrOffscreenCanvas& result) const { |
| 7848 if (canvas()) | 7853 if (canvas()) |
| 7849 result.setHTMLCanvasElement(canvas()); | 7854 result.setHTMLCanvasElement(canvas()); |
| 7850 else | 7855 else |
| 7851 result.setOffscreenCanvas(offscreenCanvas()); | 7856 result.setOffscreenCanvas(offscreenCanvas()); |
| 7852 } | 7857 } |
| 7853 | 7858 |
| 7854 } // namespace blink | 7859 } // namespace blink |
| OLD | NEW |