Chromium Code Reviews| Index: content/renderer/media/android/surface_texture_frame_provider_impl.cc |
| diff --git a/content/renderer/media/android/surface_texture_frame_provider_impl.cc b/content/renderer/media/android/surface_texture_frame_provider_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c1b3257b32a26ffaf4ee9da726cf5650af8c2d43 |
| --- /dev/null |
| +++ b/content/renderer/media/android/surface_texture_frame_provider_impl.cc |
| @@ -0,0 +1,183 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/media/android/surface_texture_frame_provider_impl.h" |
| + |
| +#include "base/callback.h" |
| +#include "cc/layers/video_frame_provider.h" |
| +#include "gpu/GLES2/gl2extchromium.h" |
| +#include "gpu/command_buffer/client/gles2_interface.h" |
| +#include "media/base/bind_to_current_loop.h" |
| + |
| +using gpu::gles2::GLES2Interface; |
| + |
| +static const uint32_t kGLTextureExternalOES = 0x8D65; |
| + |
| +namespace { |
| +// File-static function is to allow it to run even after this class is deleted. |
| +void OnReleaseTexture( |
|
liberato (no reviews please)
2016/07/13 16:42:50
static void
tguilbert
2016/07/14 02:47:02
Done.
|
| + const scoped_refptr<content::StreamTextureFactory>& factories, |
| + uint32_t texture_id, |
| + const gpu::SyncToken& sync_token) { |
| + GLES2Interface* gl = factories->ContextGL(); |
| + gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| + gl->DeleteTextures(1, &texture_id); |
| + // Flush to ensure that the stream texture gets deleted in a timely fashion. |
| + gl->ShallowFlushCHROMIUM(); |
| +} |
| +} |
| + |
| +namespace content { |
| + |
| +SurfaceTextureFrameProviderImpl::SurfaceTextureFrameProviderImpl( |
| + scoped_refptr<StreamTextureFactory> factory) |
| + : texture_id_(0), stream_id_(0), client_(nullptr), factory_(factory) {} |
| + |
| +SurfaceTextureFrameProviderImpl::~SurfaceTextureFrameProviderImpl() { |
| + if (stream_id_) { |
| + GLES2Interface* gl = factory_->ContextGL(); |
|
liberato (no reviews please)
2016/07/13 16:42:50
can call OnReleaseTexture() to avoid duplication.
tguilbert
2016/07/14 02:47:02
In order to call OnReleaseTexture(), I need a sync
liberato (no reviews please)
2016/07/14 16:41:30
i think that SyncToken() creates a token that retu
|
| + gl->DeleteTextures(1, &texture_id_); |
| + // Flush to ensure that the stream texture gets deleted in a timely fashion. |
| + gl->ShallowFlushCHROMIUM(); |
| + texture_id_ = 0; |
| + texture_mailbox_ = gpu::Mailbox(); |
| + stream_id_ = 0; |
| + } |
| + |
| + { |
|
liberato (no reviews please)
2016/07/13 16:42:50
nit: don't need {} here.
actually, can just SetCu
tguilbert
2016/07/14 02:47:02
Done.
|
| + base::AutoLock auto_lock(current_frame_lock_); |
| + current_frame_ = NULL; |
| + } |
| +} |
| + |
| +void SurfaceTextureFrameProviderImpl::SetVideoFrameProviderClient( |
| + cc::VideoFrameProvider::Client* client) { |
| + DVLOG(3) << __FUNCTION__; |
| + |
| + // Set the callback target when a frame is produced. Need to do this before |
| + // StopUsingProvider to ensure we really stop using the client. |
| + if (stream_texture_proxy_) { |
| + stream_texture_proxy_->BindToLoop(stream_id_, client, |
| + compositor_task_runner_); |
| + } |
| + |
| + if (client_ && client_ != client) |
| + client_->StopUsingProvider(); |
| + |
| + client_ = client; |
| +} |
| + |
| +bool SurfaceTextureFrameProviderImpl::UpdateCurrentFrame( |
| + base::TimeTicks deadline_min, |
| + base::TimeTicks deadline_max) { |
| + NOTIMPLEMENTED(); |
| + return false; |
| +} |
| + |
| +bool SurfaceTextureFrameProviderImpl::HasCurrentFrame() { |
| + base::AutoLock auto_lock(current_frame_lock_); |
| + return static_cast<bool>(current_frame_); |
| +} |
| + |
| +scoped_refptr<media::VideoFrame> |
| +SurfaceTextureFrameProviderImpl::GetCurrentFrame() { |
| + scoped_refptr<media::VideoFrame> frame; |
| + { |
|
liberato (no reviews please)
2016/07/13 16:42:50
nit: don't need {}
tguilbert
2016/07/14 02:47:02
Done.
|
| + base::AutoLock auto_lock(current_frame_lock_); |
| + frame = current_frame_; |
| + } |
| + |
| + return frame; |
| +} |
| + |
| +void SurfaceTextureFrameProviderImpl::PutCurrentFrame() {} |
| + |
| +void SurfaceTextureFrameProviderImpl::ReallocateVideoFrame( |
| + const gfx::Size& natural_size) { |
| + GLES2Interface* gl = factory_->ContextGL(); |
| + GLuint texture_target = kGLTextureExternalOES; |
| + GLuint texture_id_ref = gl->CreateAndConsumeTextureCHROMIUM( |
| + texture_target, texture_mailbox_.name); |
| + const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| + gl->Flush(); |
| + |
| + gpu::SyncToken texture_mailbox_sync_token; |
| + gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, |
| + texture_mailbox_sync_token.GetData()); |
| + if (texture_mailbox_sync_token.namespace_id() == |
| + gpu::CommandBufferNamespace::IN_PROCESS) { |
| + // TODO(boliu): Remove this once Android WebView switches to IPC-based |
| + // command buffer for video. |
| + GLbyte* sync_tokens[] = {texture_mailbox_sync_token.GetData()}; |
| + gl->VerifySyncTokensCHROMIUM(sync_tokens, arraysize(sync_tokens)); |
| + } |
| + |
| + gpu::MailboxHolder holders[media::VideoFrame::kMaxPlanes] = { |
| + gpu::MailboxHolder(texture_mailbox_, texture_mailbox_sync_token, |
| + texture_target)}; |
| + |
| + scoped_refptr<media::VideoFrame> new_frame = |
| + media::VideoFrame::WrapNativeTextures( |
| + media::PIXEL_FORMAT_ARGB, holders, |
| + media::BindToCurrentLoop( |
| + base::Bind(&OnReleaseTexture, factory_, texture_id_ref)), |
| + natural_size, gfx::Rect(natural_size), natural_size, |
| + base::TimeDelta()); |
| + |
| + // TODO(tguilbert): For reviewers -- what was the purpose of |
| + // |enable_texture_copy_| in WMPA? Should it be added here? WPMA had the |
|
liberato (no reviews please)
2016/07/13 16:42:50
it's needed for webview. COPY_REQUIRED tells the
tguilbert
2016/07/14 02:47:02
Ok! Thanks for the background.
Opened 628066.
|
| + // following code: |
| + // |
| + // if (new_frame.get()) { |
| + // new_frame->metadata()->SetBoolean( |
| + // media::VideoFrameMetadata::COPY_REQUIRED, enable_texture_copy_); |
| + // } |
| + |
| + SetCurrentFrameInternal(new_frame); |
| +} |
| + |
| +void SurfaceTextureFrameProviderImpl::SetCurrentFrameInternal( |
| + scoped_refptr<media::VideoFrame>& video_frame) { |
| + base::AutoLock auto_lock(current_frame_lock_); |
| + current_frame_ = video_frame; |
| +} |
| + |
| +void SurfaceTextureFrameProviderImpl::UpdateTextureSize( |
| + const gfx::Size& new_size) { |
| + if (natural_size_ == new_size) |
| + return; |
| + |
| + natural_size_ = new_size; |
| + |
| + ReallocateVideoFrame(new_size); |
| + factory_->SetStreamTextureSize(stream_id_, new_size); |
| +} |
| + |
| +void SurfaceTextureFrameProviderImpl::Initialize( |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| + const gfx::Size& natural_size) { |
| + DVLOG(2) << __FUNCTION__; |
| + |
| + compositor_task_runner_ = task_runner; |
| + natural_size_ = natural_size; |
| + |
| + stream_texture_proxy_.reset(factory_->CreateProxy()); |
| + |
| + stream_id_ = factory_->CreateStreamTexture(kGLTextureExternalOES, |
| + &texture_id_, &texture_mailbox_); |
| + ReallocateVideoFrame(natural_size_); |
| + |
| + if (client_) { |
| + stream_texture_proxy_->BindToLoop(stream_id_, client_, |
| + compositor_task_runner_); |
| + } |
| +} |
| + |
| +int SurfaceTextureFrameProviderImpl::GetSurfaceTextureIdentifier() { |
| + // TODO(tguilbert): Return meaningful value and send it to the |
| + // MediaPlayerRenderer living in the Browser process. |
| + return 0; |
| +} |
| + |
| +} // namespace content |