diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/webgl/webgl_video_texture.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/modules/webgl/webgl_video_texture.cc | 83 |
1 files changed, 52 insertions, 31 deletions
diff --git a/chromium/third_party/blink/renderer/modules/webgl/webgl_video_texture.cc b/chromium/third_party/blink/renderer/modules/webgl/webgl_video_texture.cc index 494ea9d4078..d8eeff653b0 100644 --- a/chromium/third_party/blink/renderer/modules/webgl/webgl_video_texture.cc +++ b/chromium/third_party/blink/renderer/modules/webgl/webgl_video_texture.cc @@ -5,9 +5,9 @@ #include "third_party/blink/renderer/modules/webgl/webgl_video_texture.h" #include "build/build_config.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_video_frame_metadata.h" #include "third_party/blink/renderer/core/html/media/html_video_element.h" #include "third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h" -#include "third_party/blink/renderer/modules/webgl/webgl_video_frame_metadata.h" #include "third_party/blink/renderer/modules/webgl/webgl_video_texture_enum.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" @@ -15,23 +15,17 @@ namespace blink { WebGLVideoTexture::WebGLVideoTexture(WebGLRenderingContextBase* context) : WebGLExtension(context) { - context->ExtensionsUtil()->EnsureExtensionEnabled("WEBGL_video_texture"); + context->ExtensionsUtil()->EnsureExtensionEnabled("GL_WEBGL_video_texture"); } WebGLExtensionName WebGLVideoTexture::GetName() const { return kWebGLVideoTextureName; } -WebGLVideoTexture* WebGLVideoTexture::Create( - WebGLRenderingContextBase* context) { - return MakeGarbageCollected<WebGLVideoTexture>(context); -} - -// We only need GL_OES_EGL_image_external extension on Android. bool WebGLVideoTexture::Supported(WebGLRenderingContextBase* context) { #if defined(OS_ANDROID) - return context->ExtensionsUtil()->SupportsExtension( - "GL_OES_EGL_image_external"); + // TODO(crbug.com/776222): support extension on Android + return false; #else // defined OS_ANDROID return true; #endif @@ -41,16 +35,16 @@ const char* WebGLVideoTexture::ExtensionName() { return "WEBGL_video_texture"; } -void WebGLVideoTexture::Trace(blink::Visitor* visitor) { +void WebGLVideoTexture::Trace(Visitor* visitor) { visitor->Trace(current_frame_metadata_); WebGLExtension::Trace(visitor); } -WebGLVideoFrameMetadata* WebGLVideoTexture::VideoElementTargetVideoTexture( +VideoFrameMetadata* WebGLVideoTexture::VideoElementTargetVideoTexture( ExecutionContext* execution_context, unsigned target, HTMLVideoElement* video, - ExceptionState& exceptionState) { + ExceptionState& exception_state) { WebGLExtensionScopedContext scoped(this); if (!video || scoped.IsLost()) return nullptr; @@ -62,46 +56,73 @@ WebGLVideoFrameMetadata* WebGLVideoTexture::VideoElementTargetVideoTexture( if (!scoped.Context()->ValidateHTMLVideoElement( execution_context->GetSecurityOrigin(), "WEBGLVideoTexture", video, - exceptionState) || - !scoped.Context()->ValidateTexFuncDimensions( + exception_state)) { + return nullptr; + } + + if (!scoped.Context()->ValidateTexFuncDimensions( "WEBGLVideoTexture", WebGLRenderingContextBase::kTexImage, target, 0, - video->videoWidth(), video->videoHeight(), 1)) + video->videoWidth(), video->videoHeight(), 1)) { return nullptr; + } WebGLTexture* texture = scoped.Context()->ValidateTextureBinding("WEBGLVideoTexture", target); - if (!texture) + if (!texture) { + exception_state.ThrowTypeError( + "Failed to get correct binding texture for WEBGL_video_texture"); return nullptr; + } +#if defined(OS_ANDROID) + // TODO(crbug.com/776222): support extension on Android + NOTIMPLEMENTED(); + return nullptr; +#else // For WebGL last-uploaded-frame-metadata API. WebMediaPlayer::VideoFrameUploadMetadata frame_metadata = {}; + auto* frame_metadata_ptr = &frame_metadata; int already_uploaded_id = HTMLVideoElement::kNoAlreadyUploadedFrame; - WebMediaPlayer::VideoFrameUploadMetadata* frame_metadata_ptr = - &frame_metadata; - if (RuntimeEnabledFeatures::ExtraWebGLVideoTextureMetadataEnabled()) { + if (RuntimeEnabledFeatures::ExtraWebGLVideoTextureMetadataEnabled()) already_uploaded_id = texture->GetLastUploadedVideoFrameId(); - } -#if defined(OS_ANDROID) - target = GL_TEXTURE_EXTERNAL_OES; -#else // defined OS_ANDROID target = GL_TEXTURE_2D; -#endif // defined OS_ANDROID - + // TODO(shaobo.yan@intel.com) : A fallback path or exception needs to be + // added when video is not using gpu decoder. video->PrepareVideoFrameForWebGL(scoped.Context()->ContextGL(), target, texture->Object(), already_uploaded_id, frame_metadata_ptr); if (!frame_metadata_ptr) { + exception_state.ThrowTypeError("Failed to share video to texture."); return nullptr; } - if (frame_metadata_ptr) { - current_frame_metadata_ = - WebGLVideoFrameMetadata::Create(frame_metadata_ptr); - } - + if (RuntimeEnabledFeatures::ExtraWebGLVideoTextureMetadataEnabled()) + texture->UpdateLastUploadedFrame(frame_metadata); + + if (!current_frame_metadata_) + current_frame_metadata_ = VideoFrameMetadata::Create(); + + // TODO(crbug.com/776222): These should be read from the VideoFrameCompositor + // when the VideoFrame is retrieved in WebMediaPlayerImpl. These fields are + // not currently saved in VideoFrameCompositor, so VFC::ProcessNewFrame() + // would need to save the current time as well as the presentation time. + current_frame_metadata_->setPresentationTime( + frame_metadata_ptr->timestamp.InMicrosecondsF()); + current_frame_metadata_->setExpectedDisplayTime( + frame_metadata_ptr->expected_timestamp.InMicrosecondsF()); + + current_frame_metadata_->setWidth(frame_metadata_ptr->visible_rect.width()); + current_frame_metadata_->setHeight(frame_metadata_ptr->visible_rect.height()); + current_frame_metadata_->setMediaTime( + frame_metadata_ptr->timestamp.InSecondsF()); + + // This is a required field. It is supposed to be monotonically increasing for + // video.requestAnimationFrame, but it isn't used yet for WebGLVideoTexture. + current_frame_metadata_->setPresentedFrames(0); return current_frame_metadata_; +#endif // defined OS_ANDROID } } // namespace blink |