Commit 4e256bfc authored by Yuta Kitamura's avatar Yuta Kitamura Committed by Commit Bot

Move compositor thread to Platform.

This CL moves the ownership of the compositor thread from RenderThread-
Impl to Platform in order to reduce //content's dependency to
WebThread.

Now Platform::CompositorThread() is a concrete member function, and
the compositor thread is initialized by Platform::Initialize-
CompositorThread(). Some components of //content require the task
runner of the compositor thread, so RenderThreadImpl::
compositor_task_runner() is still available.

Bug: 826203
Change-Id: I6fe71835d7b7671d8781744ec62561242c6be29f
Reviewed-on: https://chromium-review.googlesource.com/1245039
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594611}
parent 8618df06
...@@ -149,7 +149,6 @@ ...@@ -149,7 +149,6 @@
#include "services/ws/public/cpp/gpu/gpu.h" #include "services/ws/public/cpp/gpu/gpu.h"
#include "services/ws/public/mojom/constants.mojom.h" #include "services/ws/public/mojom/constants.mojom.h"
#include "skia/ext/skia_memory_dump_provider.h" #include "skia/ext/skia_memory_dump_provider.h"
#include "third_party/blink/public/platform/scheduler/child/webthread_base.h"
#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h" #include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
#include "third_party/blink/public/platform/web_cache.h" #include "third_party/blink/public/platform/web_cache.h"
#include "third_party/blink/public/platform/web_image_generator.h" #include "third_party/blink/public/platform/web_image_generator.h"
...@@ -1172,10 +1171,10 @@ void RenderThreadImpl::InitializeCompositorThread() { ...@@ -1172,10 +1171,10 @@ void RenderThreadImpl::InitializeCompositorThread() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
params.thread_options.priority = base::ThreadPriority::DISPLAY; params.thread_options.priority = base::ThreadPriority::DISPLAY;
#endif #endif
compositor_thread_ = blink_platform_impl_->InitializeCompositorThread(params);
blink::scheduler::WebThreadBase::CreateCompositorThread(params); blink::WebThread* compositor_thread =
blink_platform_impl_->SetCompositorThread(compositor_thread_.get()); blink_platform_impl_->CompositorThread();
compositor_task_runner_ = compositor_thread_->GetTaskRunner(); compositor_task_runner_ = compositor_thread->GetTaskRunner();
compositor_task_runner_->PostTask( compositor_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed), base::BindOnce(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed),
...@@ -1183,7 +1182,7 @@ void RenderThreadImpl::InitializeCompositorThread() { ...@@ -1183,7 +1182,7 @@ void RenderThreadImpl::InitializeCompositorThread() {
GetContentClient()->renderer()->PostCompositorThreadCreated( GetContentClient()->renderer()->PostCompositorThreadCreated(
compositor_task_runner_.get()); compositor_task_runner_.get());
#if defined(OS_LINUX) #if defined(OS_LINUX)
render_message_filter()->SetThreadPriority(compositor_thread_->ThreadId(), render_message_filter()->SetThreadPriority(compositor_thread->ThreadId(),
base::ThreadPriority::DISPLAY); base::ThreadPriority::DISPLAY);
#endif #endif
} }
......
...@@ -71,9 +71,6 @@ ...@@ -71,9 +71,6 @@
class SkBitmap; class SkBitmap;
namespace blink { namespace blink {
namespace scheduler {
class WebThreadBase;
}
class WebMediaStreamCenter; class WebMediaStreamCenter;
} }
...@@ -316,6 +313,8 @@ class CONTENT_EXPORT RenderThreadImpl ...@@ -316,6 +313,8 @@ class CONTENT_EXPORT RenderThreadImpl
return blink_platform_impl_.get(); return blink_platform_impl_.get();
} }
// Returns the task runner on the compositor thread.
//
// Will be null if threaded compositing has not been enabled. // Will be null if threaded compositing has not been enabled.
scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner() const { scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner() const {
return compositor_task_runner_; return compositor_task_runner_;
...@@ -651,9 +650,6 @@ class CONTENT_EXPORT RenderThreadImpl ...@@ -651,9 +650,6 @@ class CONTENT_EXPORT RenderThreadImpl
// software-based. // software-based.
bool is_gpu_compositing_disabled_ = false; bool is_gpu_compositing_disabled_ = false;
// May be null if overridden by ContentRendererClient.
std::unique_ptr<blink::scheduler::WebThreadBase> compositor_thread_;
// Utility class to provide GPU functionalities to media. // Utility class to provide GPU functionalities to media.
// TODO(dcastagna): This should be just one scoped_ptr once // TODO(dcastagna): This should be just one scoped_ptr once
// http://crbug.com/580386 is fixed. // http://crbug.com/580386 is fixed.
......
...@@ -248,8 +248,6 @@ RendererBlinkPlatformImpl::RendererBlinkPlatformImpl( ...@@ -248,8 +248,6 @@ RendererBlinkPlatformImpl::RendererBlinkPlatformImpl(
RenderThreadImpl::current() RenderThreadImpl::current()
? RenderThreadImpl::current()->GetIOTaskRunner() ? RenderThreadImpl::current()->GetIOTaskRunner()
: nullptr), : nullptr),
compositor_thread_(nullptr),
main_thread_(main_thread_scheduler->CreateMainThread()),
sudden_termination_disables_(0), sudden_termination_disables_(0),
is_locked_to_site_(false), is_locked_to_site_(false),
default_task_runner_(main_thread_scheduler->DefaultTaskRunner()), default_task_runner_(main_thread_scheduler->DefaultTaskRunner()),
...@@ -382,16 +380,6 @@ RendererBlinkPlatformImpl::CreateNetworkURLLoaderFactory() { ...@@ -382,16 +380,6 @@ RendererBlinkPlatformImpl::CreateNetworkURLLoaderFactory() {
return url_loader_factory; return url_loader_factory;
} }
void RendererBlinkPlatformImpl::SetCompositorThread(
blink::scheduler::WebThreadBase* compositor_thread) {
// TODO(yutak): Compositor thread is currently owned by RenderThreadImpl,
// but should probably be owned by Platform so this wouldn't depend on
// WebThread.
compositor_thread_ = compositor_thread;
if (compositor_thread_)
RegisterExtraThreadToTLS(compositor_thread_);
}
blink::BlameContext* RendererBlinkPlatformImpl::GetTopLevelBlameContext() { blink::BlameContext* RendererBlinkPlatformImpl::GetTopLevelBlameContext() {
return &top_level_blame_context_; return &top_level_blame_context_;
} }
...@@ -515,10 +503,6 @@ void RendererBlinkPlatformImpl::SuddenTerminationChanged(bool enabled) { ...@@ -515,10 +503,6 @@ void RendererBlinkPlatformImpl::SuddenTerminationChanged(bool enabled) {
thread->GetRendererHost()->SuddenTerminationChanged(enabled); thread->GetRendererHost()->SuddenTerminationChanged(enabled);
} }
blink::WebThread* RendererBlinkPlatformImpl::CompositorThread() const {
return compositor_thread_;
}
std::unique_ptr<WebStorageNamespace> std::unique_ptr<WebStorageNamespace>
RendererBlinkPlatformImpl::CreateLocalStorageNamespace() { RendererBlinkPlatformImpl::CreateLocalStorageNamespace() {
if (!local_storage_cached_areas_) { if (!local_storage_cached_areas_) {
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
namespace blink { namespace blink {
namespace scheduler { namespace scheduler {
class WebThreadScheduler; class WebThreadScheduler;
class WebThreadBase;
} }
class WebCanvasCaptureHandler; class WebCanvasCaptureHandler;
class WebGraphicsContext3DProvider; class WebGraphicsContext3DProvider;
...@@ -102,7 +101,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { ...@@ -102,7 +101,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
const blink::WebString& cacheStorageCacheName) override; const blink::WebString& cacheStorageCacheName) override;
blink::WebString DefaultLocale() override; blink::WebString DefaultLocale() override;
void SuddenTerminationChanged(bool enabled) override; void SuddenTerminationChanged(bool enabled) override;
blink::WebThread* CompositorThread() const override;
std::unique_ptr<blink::WebStorageNamespace> CreateLocalStorageNamespace() std::unique_ptr<blink::WebStorageNamespace> CreateLocalStorageNamespace()
override; override;
std::unique_ptr<blink::WebStorageNamespace> CreateSessionStorageNamespace( std::unique_ptr<blink::WebStorageNamespace> CreateSessionStorageNamespace(
...@@ -239,11 +237,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { ...@@ -239,11 +237,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
scoped_refptr<ChildURLLoaderFactoryBundle> scoped_refptr<ChildURLLoaderFactoryBundle>
CreateDefaultURLLoaderFactoryBundle(); CreateDefaultURLLoaderFactoryBundle();
// This class does *not* own the compositor thread. It is the responsibility
// of the caller to ensure that the compositor thread is cleared before it is
// destructed.
void SetCompositorThread(blink::scheduler::WebThreadBase* compositor_thread);
PossiblyAssociatedInterfacePtr<network::mojom::URLLoaderFactory> PossiblyAssociatedInterfacePtr<network::mojom::URLLoaderFactory>
CreateNetworkURLLoaderFactory(); CreateNetworkURLLoaderFactory();
...@@ -267,9 +260,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { ...@@ -267,9 +260,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
// Return the mojo interface for making CodeCache calls. // Return the mojo interface for making CodeCache calls.
blink::mojom::CodeCacheHost& GetCodeCacheHost(); blink::mojom::CodeCacheHost& GetCodeCacheHost();
blink::scheduler::WebThreadBase* compositor_thread_;
std::unique_ptr<blink::WebThread> main_thread_;
std::unique_ptr<service_manager::Connector> connector_; std::unique_ptr<service_manager::Connector> connector_;
scoped_refptr<base::SingleThreadTaskRunner> io_runner_; scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/threading/thread.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/viz/common/surfaces/frame_sink_id.h" #include "components/viz/common/surfaces/frame_sink_id.h"
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
...@@ -444,9 +445,20 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -444,9 +445,20 @@ class BLINK_PLATFORM_EXPORT Platform {
// for any other purpose. // for any other purpose.
std::unique_ptr<WebThread> CreateWebAudioThread(); std::unique_ptr<WebThread> CreateWebAudioThread();
// Create and initialize the compositor thread. The thread is saved in
// Platform, and will be accessible through CompositorThread().
void InitializeCompositorThread(const WebThreadCreationParams&);
// Returns an interface to the current thread. // Returns an interface to the current thread.
WebThread* CurrentThread(); WebThread* CurrentThread();
// Returns an interface to the main thread.
WebThread* MainThread();
// Returns an interface to the compositor thread. This can be null if the
// renderer was created with threaded rendering disabled.
WebThread* CompositorThread();
// Returns a blame context for attributing top-level work which does not // Returns a blame context for attributing top-level work which does not
// belong to a particular frame scope. // belong to a particular frame scope.
virtual BlameContext* GetTopLevelBlameContext() { return nullptr; } virtual BlameContext* GetTopLevelBlameContext() { return nullptr; }
...@@ -478,15 +490,6 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -478,15 +490,6 @@ class BLINK_PLATFORM_EXPORT Platform {
// Returns a value such as "en-US". // Returns a value such as "en-US".
virtual WebString DefaultLocale() { return WebString(); } virtual WebString DefaultLocale() { return WebString(); }
// Returns an interface to the main thread. Can be null if blink was
// initialized on a thread without a message loop.
WebThread* MainThread() const;
// Returns an interface to the compositor thread. This can be null if the
// renderer was created with threaded rendering desabled.
virtual WebThread* CompositorThread() const { return 0; }
// Returns an interface to the IO task runner. // Returns an interface to the IO task runner.
virtual scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() const { virtual scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() const {
return nullptr; return nullptr;
...@@ -754,8 +757,6 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -754,8 +757,6 @@ class BLINK_PLATFORM_EXPORT Platform {
virtual bool IsTakingV8ContextSnapshot() { return false; } virtual bool IsTakingV8ContextSnapshot() { return false; }
protected: protected:
void RegisterExtraThreadToTLS(WebThread*);
WebThread* main_thread_; WebThread* main_thread_;
private: private:
...@@ -772,10 +773,11 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -772,10 +773,11 @@ class BLINK_PLATFORM_EXPORT Platform {
// Platform's main thread. See testing_platform_support.h for this. // Platform's main thread. See testing_platform_support.h for this.
std::unique_ptr<WebThread> owned_main_thread_; std::unique_ptr<WebThread> owned_main_thread_;
std::unique_ptr<WebThread> compositor_thread_;
// We can't use WTF stuff here. Ultimately these should go away (see comments // We can't use WTF stuff here. Ultimately these should go away (see comments
// near CreateThread()), though. // near CreateThread()), though.
base::ThreadLocalStorage::Slot current_thread_slot_; base::ThreadLocalStorage::Slot current_thread_slot_;
base::Lock create_thread_lock_;
}; };
} // namespace blink } // namespace blink
......
...@@ -274,7 +274,7 @@ Platform* Platform::Current() { ...@@ -274,7 +274,7 @@ Platform* Platform::Current() {
return g_platform; return g_platform;
} }
WebThread* Platform::MainThread() const { WebThread* Platform::MainThread() {
return main_thread_; return main_thread_;
} }
...@@ -342,8 +342,18 @@ void Platform::UpdateWebThreadTLS(WebThread* thread, ...@@ -342,8 +342,18 @@ void Platform::UpdateWebThreadTLS(WebThread* thread,
event->Signal(); event->Signal();
} }
void Platform::RegisterExtraThreadToTLS(WebThread* thread) { void Platform::InitializeCompositorThread(
WaitUntilWebThreadTLSUpdate(thread); const WebThreadCreationParams& params) {
DCHECK(!compositor_thread_);
std::unique_ptr<scheduler::WebThreadBase> compositor_thread =
scheduler::WebThreadBase::CreateCompositorThread(params);
compositor_thread->Init();
WaitUntilWebThreadTLSUpdate(compositor_thread.get());
compositor_thread_ = std::move(compositor_thread);
}
WebThread* Platform::CompositorThread() {
return compositor_thread_.get();
} }
std::unique_ptr<WebGraphicsContext3DProvider> std::unique_ptr<WebGraphicsContext3DProvider>
......
...@@ -96,7 +96,6 @@ class WebThreadForCompositor : public WebThreadImplForWorkerScheduler { ...@@ -96,7 +96,6 @@ class WebThreadForCompositor : public WebThreadImplForWorkerScheduler {
public: public:
explicit WebThreadForCompositor(const WebThreadCreationParams& params) explicit WebThreadForCompositor(const WebThreadCreationParams& params)
: WebThreadImplForWorkerScheduler(params) { : WebThreadImplForWorkerScheduler(params) {
Init();
} }
~WebThreadForCompositor() override = default; ~WebThreadForCompositor() override = default;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment