diff options
author | boliu <boliu@chromium.org> | 2016-02-11 12:09:42 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-11 20:10:58 +0000 |
commit | f8753bf6f81cb53b498c498620cb0047911060fd (patch) | |
tree | c89fa156cdde31c2fd3b730a48d3319aa8ad09c1 | |
parent | 206812e6725389b7168e7a240c0856436ca6fa70 (diff) | |
download | chromium_src-f8753bf6f81cb53b498c498620cb0047911060fd.zip chromium_src-f8753bf6f81cb53b498c498620cb0047911060fd.tar.gz chromium_src-f8753bf6f81cb53b498c498620cb0047911060fd.tar.bz2 |
sync compositor: Allow sync stream texture over ipc compositing
The one-copy inline video path is not fully working yet on
all GPUs. This patch makes the existing code path that uses
the in-process command buffer keep working, even with
--ipc-sync-compositing.
Separate stream texture part of SynchronousCompositorFactory
into SynchronousCompositorStreamTextureFactory. Then also set
it in the IPC-sync compositing path when running in single
process.
BUG=583455
Previous Committed: https://crrev.com/28a28af2a5488703659d4cada9c2da7c736407cb
Cr-Commit-Position: refs/heads/master@{#374304}
Review URL: https://codereview.chromium.org/1657093002
Cr-Commit-Position: refs/heads/master@{#374958}
14 files changed, 170 insertions, 130 deletions
diff --git a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc index 628bfcc..385bb4f 100644 --- a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc +++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc @@ -86,12 +86,52 @@ ContextHolder CreateContextHolder( } // namespace -class SynchronousCompositorFactoryImpl::VideoContextProvider +SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() { + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kSingleProcess)) { + // TODO(boliu): Figure out how to deal with this more nicely. + SynchronousCompositorFactory::SetInstance(this); + } +} + +SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} + +scoped_refptr<base::SingleThreadTaskRunner> +SynchronousCompositorFactoryImpl::GetCompositorTaskRunner() { + return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); +} + +scoped_ptr<cc::OutputSurface> +SynchronousCompositorFactoryImpl::CreateOutputSurface( + int routing_id, + const scoped_refptr<FrameSwapMessageQueue>& frame_swap_message_queue, + const scoped_refptr<cc::ContextProvider>& onscreen_context, + const scoped_refptr<cc::ContextProvider>& worker_context) { + return make_scoped_ptr(new SynchronousCompositorOutputSurface( + onscreen_context, worker_context, routing_id, + SynchronousCompositorRegistryInProc::GetInstance(), + frame_swap_message_queue)); +} + +InputHandlerManagerClient* +SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() { + return synchronous_input_event_filter(); +} + +scoped_ptr<cc::BeginFrameSource> +SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( + int routing_id) { + return make_scoped_ptr(new SynchronousCompositorExternalBeginFrameSource( + routing_id, SynchronousCompositorRegistryInProc::GetInstance())); +} + +// SynchronousCompositorStreamTextureFactoryImpl. + +class SynchronousCompositorStreamTextureFactoryImpl::VideoContextProvider : public StreamTextureFactorySynchronousImpl::ContextProvider { public: - VideoContextProvider( - scoped_refptr<cc::ContextProvider> context_provider, - gpu::GLInProcessContext* gl_in_process_context) + VideoContextProvider(scoped_refptr<cc::ContextProvider> context_provider, + gpu::GLInProcessContext* gl_in_process_context) : context_provider_(context_provider), gl_in_process_context_(gl_in_process_context) { context_provider_->BindToCurrentThread(); @@ -119,8 +159,7 @@ class SynchronousCompositorFactoryImpl::VideoContextProvider } void RestoreContext() { - FOR_EACH_OBSERVER(StreamTextureFactoryContextObserver, - observer_list_, + FOR_EACH_OBSERVER(StreamTextureFactoryContextObserver, observer_list_, ResetStreamTextureProxy()); } @@ -135,87 +174,62 @@ class SynchronousCompositorFactoryImpl::VideoContextProvider DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); }; -SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() - : num_hardware_compositors_(0) { - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kSingleProcess)) { - // TODO(boliu): Figure out how to deal with this more nicely. - SynchronousCompositorFactory::SetInstance(this); - } -} - -SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} - -scoped_refptr<base::SingleThreadTaskRunner> -SynchronousCompositorFactoryImpl::GetCompositorTaskRunner() { - return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); -} - -scoped_ptr<cc::OutputSurface> -SynchronousCompositorFactoryImpl::CreateOutputSurface( - int routing_id, - const scoped_refptr<FrameSwapMessageQueue>& frame_swap_message_queue, - const scoped_refptr<cc::ContextProvider>& onscreen_context, - const scoped_refptr<cc::ContextProvider>& worker_context) { - return make_scoped_ptr(new SynchronousCompositorOutputSurface( - onscreen_context, worker_context, routing_id, - SynchronousCompositorRegistryInProc::GetInstance(), - frame_swap_message_queue)); -} +namespace { +base::LazyInstance<SynchronousCompositorStreamTextureFactoryImpl>::Leaky + g_stream_texture_factory = LAZY_INSTANCE_INITIALIZER; +} // namespace -InputHandlerManagerClient* -SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() { - return synchronous_input_event_filter(); +// static +SynchronousCompositorStreamTextureFactoryImpl* +SynchronousCompositorStreamTextureFactoryImpl::GetInstance() { + return g_stream_texture_factory.Pointer(); } -scoped_ptr<cc::BeginFrameSource> -SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( - int routing_id) { - return make_scoped_ptr(new SynchronousCompositorExternalBeginFrameSource( - routing_id, SynchronousCompositorRegistryInProc::GetInstance())); -} +SynchronousCompositorStreamTextureFactoryImpl:: + SynchronousCompositorStreamTextureFactoryImpl() + : num_hardware_compositors_(0) {} scoped_refptr<StreamTextureFactory> -SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { - scoped_refptr<StreamTextureFactorySynchronousImpl> factory( - StreamTextureFactorySynchronousImpl::Create( - base::Bind( - &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, - base::Unretained(this)), - frame_id)); - return factory; +SynchronousCompositorStreamTextureFactoryImpl::CreateStreamTextureFactory() { + return StreamTextureFactorySynchronousImpl::Create( + base::Bind(&SynchronousCompositorStreamTextureFactoryImpl:: + TryCreateStreamTextureFactory, + base::Unretained(this))); } -void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { +void SynchronousCompositorStreamTextureFactoryImpl:: + CompositorInitializedHardwareDraw() { base::AutoLock lock(num_hardware_compositor_lock_); num_hardware_compositors_++; if (num_hardware_compositors_ == 1 && main_thread_task_runner_.get()) { main_thread_task_runner_->PostTask( - FROM_HERE, - base::Bind( - &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread, - base::Unretained(this))); + FROM_HERE, base::Bind(&SynchronousCompositorStreamTextureFactoryImpl:: + RestoreContextOnMainThread, + base::Unretained(this))); } } -void SynchronousCompositorFactoryImpl::CompositorReleasedHardwareDraw() { +void SynchronousCompositorStreamTextureFactoryImpl:: + CompositorReleasedHardwareDraw() { base::AutoLock lock(num_hardware_compositor_lock_); DCHECK_GT(num_hardware_compositors_, 0u); num_hardware_compositors_--; } -void SynchronousCompositorFactoryImpl::RestoreContextOnMainThread() { +void SynchronousCompositorStreamTextureFactoryImpl:: + RestoreContextOnMainThread() { if (CanCreateMainThreadContext() && video_context_provider_.get()) video_context_provider_->RestoreContext(); } -bool SynchronousCompositorFactoryImpl::CanCreateMainThreadContext() { +bool SynchronousCompositorStreamTextureFactoryImpl:: + CanCreateMainThreadContext() { base::AutoLock lock(num_hardware_compositor_lock_); return num_hardware_compositors_ > 0; } scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> -SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { +SynchronousCompositorStreamTextureFactoryImpl::TryCreateStreamTextureFactory() { { base::AutoLock lock(num_hardware_compositor_lock_); main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); @@ -226,8 +240,8 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { // |video_context_provider_| to null is also not safe since it makes // synchronous destruction uncontrolled and possibly deadlock. if (!CanCreateMainThreadContext()) { - return - scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); + return scoped_refptr< + StreamTextureFactorySynchronousImpl::ContextProvider>(); } if (!video_context_provider_.get()) { @@ -248,10 +262,15 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { return video_context_provider_; } -void SynchronousCompositorFactoryImpl::SetDeferredGpuService( +void SynchronousCompositorStreamTextureFactoryImpl::SetDeferredGpuService( scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { DCHECK(!android_view_service_.get()); android_view_service_ = service; + + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kSingleProcess)) { + RenderThreadImpl::SetStreamTextureFactory(CreateStreamTextureFactory()); + } } } // namespace content diff --git a/content/browser/android/in_process/synchronous_compositor_factory_impl.h b/content/browser/android/in_process/synchronous_compositor_factory_impl.h index 0353344..be0d978 100644 --- a/content/browser/android/in_process/synchronous_compositor_factory_impl.h +++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.h @@ -5,6 +5,7 @@ #ifndef CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_FACTORY_IMPL_H_ #define CONTENT_BROWSER_ANDROID_IN_PROCESS_SYNCHRONOUS_COMPOSITOR_FACTORY_IMPL_H_ +#include "base/lazy_instance.h" #include "base/synchronization/lock.h" #include "cc/blink/context_provider_web_context.h" #include "content/browser/android/in_process/synchronous_input_event_filter.h" @@ -46,28 +47,37 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { InputHandlerManagerClient* GetInputHandlerManagerClient() override; scoped_ptr<cc::BeginFrameSource> CreateExternalBeginFrameSource( int routing_id) override; - scoped_refptr<StreamTextureFactory> CreateStreamTextureFactory( - int frame_id) override; SynchronousInputEventFilter* synchronous_input_event_filter() { return &synchronous_input_event_filter_; } + private: + SynchronousInputEventFilter synchronous_input_event_filter_; +}; + +class SynchronousCompositorStreamTextureFactoryImpl { + public: + static SynchronousCompositorStreamTextureFactoryImpl* GetInstance(); + + scoped_refptr<StreamTextureFactory> CreateStreamTextureFactory(); void SetDeferredGpuService( scoped_refptr<gpu::InProcessCommandBuffer::Service> service); void CompositorInitializedHardwareDraw(); void CompositorReleasedHardwareDraw(); - private: - scoped_refptr<cc::ContextProvider> GetSharedWorkerContextProvider(); + friend struct base::DefaultLazyInstanceTraits< + SynchronousCompositorStreamTextureFactoryImpl>; + + SynchronousCompositorStreamTextureFactoryImpl(); + ~SynchronousCompositorStreamTextureFactoryImpl(); + bool CanCreateMainThreadContext(); scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> TryCreateStreamTextureFactory(); void RestoreContextOnMainThread(); - SynchronousInputEventFilter synchronous_input_event_filter_; - scoped_refptr<gpu::InProcessCommandBuffer::Service> android_view_service_; class VideoContextProvider; diff --git a/content/browser/android/in_process/synchronous_compositor_impl.cc b/content/browser/android/in_process/synchronous_compositor_impl.cc index e179137..a10e608 100644 --- a/content/browser/android/in_process/synchronous_compositor_impl.cc +++ b/content/browser/android/in_process/synchronous_compositor_impl.cc @@ -108,12 +108,6 @@ void SynchronousCompositorImpl::RegisterWithClient() { synchronous_input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(this); } -// static -void SynchronousCompositorImpl::SetGpuServiceInProc( - scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { - g_factory.Get().SetDeferredGpuService(service); -} - void SynchronousCompositorImpl::DidInitializeRendererObjects( SynchronousCompositorOutputSurface* output_surface, SynchronousCompositorExternalBeginFrameSource* begin_frame_source, @@ -221,9 +215,11 @@ void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { output_surface_->SetMemoryPolicy(bytes_limit); if (bytes_limit && !current_bytes_limit) { - g_factory.Get().CompositorInitializedHardwareDraw(); + SynchronousCompositorStreamTextureFactoryImpl::GetInstance() + ->CompositorInitializedHardwareDraw(); } else if (!bytes_limit && current_bytes_limit) { - g_factory.Get().CompositorReleasedHardwareDraw(); + SynchronousCompositorStreamTextureFactoryImpl::GetInstance() + ->CompositorReleasedHardwareDraw(); } } diff --git a/content/browser/android/in_process/synchronous_compositor_impl.h b/content/browser/android/in_process/synchronous_compositor_impl.h index e5a1461..b788405 100644 --- a/content/browser/android/in_process/synchronous_compositor_impl.h +++ b/content/browser/android/in_process/synchronous_compositor_impl.h @@ -43,9 +43,6 @@ class SynchronousCompositorImpl // is implicitly that of the in-process renderer. static SynchronousCompositorImpl* FromRoutingID(int routing_id); - static void SetGpuServiceInProc( - scoped_refptr<gpu::InProcessCommandBuffer::Service> service); - ~SynchronousCompositorImpl() override; // Called by SynchronousCompositorRegistry. diff --git a/content/browser/android/synchronous_compositor_base.cc b/content/browser/android/synchronous_compositor_base.cc index acc5e34..47ceda3 100644 --- a/content/browser/android/synchronous_compositor_base.cc +++ b/content/browser/android/synchronous_compositor_base.cc @@ -6,6 +6,7 @@ #include "base/command_line.h" #include "base/supports_user_data.h" +#include "content/browser/android/in_process/synchronous_compositor_factory_impl.h" #include "content/browser/android/in_process/synchronous_compositor_impl.h" #include "content/browser/android/synchronous_compositor_host.h" #include "content/browser/gpu/gpu_process_host.h" @@ -36,11 +37,8 @@ void SynchronousCompositor::SetGpuService( g_sync_point_manager = service->sync_point_manager(); GpuProcessHost::RegisterGpuMainThreadFactory( CreateInProcessGpuThreadForSynchronousCompositor); - - if (!base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kIPCSyncCompositing)) { - SynchronousCompositorImpl::SetGpuServiceInProc(service); - } + SynchronousCompositorStreamTextureFactoryImpl::GetInstance() + ->SetDeferredGpuService(service); } // static diff --git a/content/browser/android/synchronous_compositor_base.h b/content/browser/android/synchronous_compositor_base.h index 6bd41bb..c269ed4 100644 --- a/content/browser/android/synchronous_compositor_base.h +++ b/content/browser/android/synchronous_compositor_base.h @@ -24,6 +24,7 @@ struct BeginFrameArgs; namespace content { class RenderWidgetHostViewAndroid; +class SynchronousCompositorStreamTextureFactoryImpl; class WebContents; class SynchronousCompositorBase : public SynchronousCompositor { diff --git a/content/browser/android/synchronous_compositor_host.cc b/content/browser/android/synchronous_compositor_host.cc index c4292ec..daff4b4 100644 --- a/content/browser/android/synchronous_compositor_host.cc +++ b/content/browser/android/synchronous_compositor_host.cc @@ -10,6 +10,7 @@ #include "base/memory/shared_memory.h" #include "base/trace_event/trace_event_argument.h" #include "cc/output/compositor_frame_ack.h" +#include "content/browser/android/in_process/synchronous_compositor_factory_impl.h" #include "content/browser/renderer_host/render_widget_host_view_android.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/common/android/sync_compositor_messages.h" @@ -231,8 +232,17 @@ void SynchronousCompositorHost::ReturnResources( void SynchronousCompositorHost::SetMemoryPolicy(size_t bytes_limit) { if (bytes_limit_ == bytes_limit) return; + size_t current_bytes_limit = bytes_limit_; bytes_limit_ = bytes_limit; SendAsyncCompositorStateIfNeeded(); + + if (bytes_limit && !current_bytes_limit) { + SynchronousCompositorStreamTextureFactoryImpl::GetInstance() + ->CompositorInitializedHardwareDraw(); + } else if (!bytes_limit && current_bytes_limit) { + SynchronousCompositorStreamTextureFactoryImpl::GetInstance() + ->CompositorReleasedHardwareDraw(); + } } void SynchronousCompositorHost::DidChangeRootLayerScrollOffset( diff --git a/content/renderer/android/synchronous_compositor_factory.cc b/content/renderer/android/synchronous_compositor_factory.cc index 550b76b..e2724be 100644 --- a/content/renderer/android/synchronous_compositor_factory.cc +++ b/content/renderer/android/synchronous_compositor_factory.cc @@ -9,13 +9,13 @@ namespace content { namespace { -SynchronousCompositorFactory* g_instance = NULL; +SynchronousCompositorFactory* g_instance = nullptr; } // namespace // static void SynchronousCompositorFactory::SetInstance( SynchronousCompositorFactory* instance) { - DCHECK(g_instance == NULL); + DCHECK(g_instance == nullptr); g_instance = instance; } diff --git a/content/renderer/android/synchronous_compositor_factory.h b/content/renderer/android/synchronous_compositor_factory.h index 0f001fb..c8fece9 100644 --- a/content/renderer/android/synchronous_compositor_factory.h +++ b/content/renderer/android/synchronous_compositor_factory.h @@ -58,14 +58,12 @@ class SynchronousCompositorFactory { virtual scoped_ptr<cc::BeginFrameSource> CreateExternalBeginFrameSource( int routing_id) = 0; - virtual scoped_refptr<StreamTextureFactory> CreateStreamTextureFactory( - int frame_id) = 0; protected: SynchronousCompositorFactory() {} virtual ~SynchronousCompositorFactory() {} }; -} +} // namespace content #endif // CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_FACTORY_H_ diff --git a/content/renderer/media/android/stream_texture_factory_synchronous_impl.cc b/content/renderer/media/android/stream_texture_factory_synchronous_impl.cc index 44ae072..137dc98 100644 --- a/content/renderer/media/android/stream_texture_factory_synchronous_impl.cc +++ b/content/renderer/media/android/stream_texture_factory_synchronous_impl.cc @@ -151,18 +151,13 @@ void StreamTextureProxyImpl::OnFrameAvailable() { // static scoped_refptr<StreamTextureFactorySynchronousImpl> StreamTextureFactorySynchronousImpl::Create( - const CreateContextProviderCallback& try_create_callback, - int frame_id) { - return new StreamTextureFactorySynchronousImpl(try_create_callback, frame_id); + const CreateContextProviderCallback& try_create_callback) { + return new StreamTextureFactorySynchronousImpl(try_create_callback); } StreamTextureFactorySynchronousImpl::StreamTextureFactorySynchronousImpl( - const CreateContextProviderCallback& try_create_callback, - int frame_id) - : create_context_provider_callback_(try_create_callback), - context_provider_(create_context_provider_callback_.Run()), - frame_id_(frame_id), - observer_(NULL) {} + const CreateContextProviderCallback& try_create_callback) + : create_context_provider_callback_(try_create_callback) {} StreamTextureFactorySynchronousImpl::~StreamTextureFactorySynchronousImpl() {} @@ -174,8 +169,10 @@ StreamTextureProxy* StreamTextureFactorySynchronousImpl::CreateProxy() { if (!context_provider_.get()) return NULL; - if (observer_ && !had_proxy) - context_provider_->AddObserver(observer_); + if (!observers_.empty() && !had_proxy) { + for (auto& observer : observers_) + context_provider_->AddObserver(observer); + } return new StreamTextureProxyImpl(context_provider_.get()); } @@ -189,7 +186,7 @@ void StreamTextureFactorySynchronousImpl::EstablishPeer(int32_t stream_id, SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( base::GetCurrentProcessHandle(), surface_texture, - frame_id_, + frame_id, player_id); } } @@ -221,16 +218,16 @@ gpu::gles2::GLES2Interface* StreamTextureFactorySynchronousImpl::ContextGL() { void StreamTextureFactorySynchronousImpl::AddObserver( StreamTextureFactoryContextObserver* obs) { - DCHECK(!observer_); - observer_ = obs; + DCHECK(observers_.find(obs) == observers_.end()); + observers_.insert(obs); if (context_provider_.get()) context_provider_->AddObserver(obs); } void StreamTextureFactorySynchronousImpl::RemoveObserver( StreamTextureFactoryContextObserver* obs) { - DCHECK_EQ(observer_, obs); - observer_ = NULL; + DCHECK(observers_.find(obs) != observers_.end()); + observers_.erase(obs); if (context_provider_.get()) context_provider_->RemoveObserver(obs); } diff --git a/content/renderer/media/android/stream_texture_factory_synchronous_impl.h b/content/renderer/media/android/stream_texture_factory_synchronous_impl.h index cca38a8..a8b759a 100644 --- a/content/renderer/media/android/stream_texture_factory_synchronous_impl.h +++ b/content/renderer/media/android/stream_texture_factory_synchronous_impl.h @@ -7,6 +7,8 @@ #include <stdint.h> +#include <set> + #include "base/callback.h" #include "base/macros.h" #include "base/memory/ref_counted.h" @@ -49,8 +51,7 @@ class StreamTextureFactorySynchronousImpl : public StreamTextureFactory { CreateContextProviderCallback; static scoped_refptr<StreamTextureFactorySynchronousImpl> Create( - const CreateContextProviderCallback& try_create_callback, - int frame_id); + const CreateContextProviderCallback& try_create_callback); StreamTextureProxy* CreateProxy() override; void EstablishPeer(int32_t stream_id, int player_id, int frame_id) override; @@ -65,14 +66,12 @@ class StreamTextureFactorySynchronousImpl : public StreamTextureFactory { private: friend class base::RefCounted<StreamTextureFactorySynchronousImpl>; StreamTextureFactorySynchronousImpl( - const CreateContextProviderCallback& try_create_callback, - int frame_id); + const CreateContextProviderCallback& try_create_callback); ~StreamTextureFactorySynchronousImpl() override; CreateContextProviderCallback create_context_provider_callback_; scoped_refptr<ContextProvider> context_provider_; - int frame_id_; - StreamTextureFactoryContextObserver* observer_; + std::set<StreamTextureFactoryContextObserver*> observers_; DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureFactorySynchronousImpl); }; diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index 6bbc484..622a4576 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -198,7 +198,6 @@ #include <cpu-features.h> #include "content/common/gpu/client/context_provider_command_buffer.h" -#include "content/renderer/android/synchronous_compositor_factory.h" #include "content/renderer/java/gin_java_bridge_dispatcher.h" #include "content/renderer/media/android/renderer_media_player_manager.h" #include "content/renderer/media/android/renderer_media_session_manager.h" @@ -5956,23 +5955,15 @@ WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer( WebMediaPlayerClient* client, WebMediaPlayerEncryptedMediaClient* encrypted_client, const media::WebMediaPlayerParams& params) { - scoped_refptr<StreamTextureFactory> stream_texture_factory; - bool enable_texture_copy = false; - if (SynchronousCompositorFactory* factory = - SynchronousCompositorFactory::GetInstance()) { - stream_texture_factory = factory->CreateStreamTextureFactory(routing_id_); - } else { - stream_texture_factory = - RenderThreadImpl::current()->GetStreamTexureFactory(); - enable_texture_copy = - RenderThreadImpl::current()->sync_compositor_message_filter() != - nullptr; - if (!stream_texture_factory.get()) { - LOG(ERROR) << "Failed to get stream texture factory!"; - return NULL; - } + scoped_refptr<StreamTextureFactory> stream_texture_factory = + RenderThreadImpl::current()->GetStreamTexureFactory(); + if (!stream_texture_factory.get()) { + LOG(ERROR) << "Failed to get stream texture factory!"; + return NULL; } + bool enable_texture_copy = + RenderThreadImpl::current()->EnableStreamTextureCopy(); return new WebMediaPlayerAndroid(frame_, client, encrypted_client, GetWebMediaPlayerDelegate()->AsWeakPtr(), GetMediaPlayerManager(), GetCdmFactory(), diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index dfa3b6f3..11d5682 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -1544,11 +1544,25 @@ RenderThreadImpl::SharedMainThreadContextProvider() { } #if defined(OS_ANDROID) + +namespace { +base::LazyInstance<scoped_refptr<StreamTextureFactory>> + g_stream_texture_factory_override; +} + +// static +void RenderThreadImpl::SetStreamTextureFactory( + scoped_refptr<StreamTextureFactory> factory) { + g_stream_texture_factory_override.Get() = factory; +} + scoped_refptr<StreamTextureFactory> RenderThreadImpl::GetStreamTexureFactory() { DCHECK(IsMainThread()); - if (!stream_texture_factory_.get() || - stream_texture_factory_->ContextGL()->GetGraphicsResetStatusKHR() != - GL_NO_ERROR) { + if (g_stream_texture_factory_override.Get()) { + stream_texture_factory_ = g_stream_texture_factory_override.Get(); + } else if (!stream_texture_factory_.get() || + stream_texture_factory_->ContextGL() + ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { if (!SharedMainThreadContextProvider().get()) { stream_texture_factory_ = NULL; return NULL; @@ -1565,6 +1579,12 @@ scoped_refptr<StreamTextureFactory> RenderThreadImpl::GetStreamTexureFactory() { } return stream_texture_factory_; } + +bool RenderThreadImpl::EnableStreamTextureCopy() { + return !g_stream_texture_factory_override.Get() && + sync_compositor_message_filter_.get(); +} + #endif AudioRendererMixerManager* RenderThreadImpl::GetAudioRendererMixerManager() { diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h index 5bd84a6..6d0fd73 100644 --- a/content/renderer/render_thread_impl.h +++ b/content/renderer/render_thread_impl.h @@ -294,7 +294,11 @@ class CONTENT_EXPORT RenderThreadImpl return sync_compositor_message_filter_.get(); } + static void SetStreamTextureFactory( + scoped_refptr<StreamTextureFactory> factory); + scoped_refptr<StreamTextureFactory> GetStreamTexureFactory(); + bool EnableStreamTextureCopy(); #endif // Creates the embedder implementation of WebMediaStreamCenter. |