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 @@
#include "services/ws/public/cpp/gpu/gpu.h"
#include "services/ws/public/mojom/constants.mojom.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/web_cache.h"
#include "third_party/blink/public/platform/web_image_generator.h"
......@@ -1172,10 +1171,10 @@ void RenderThreadImpl::InitializeCompositorThread() {
#if defined(OS_ANDROID)
params.thread_options.priority = base::ThreadPriority::DISPLAY;
#endif
compositor_thread_ =
blink::scheduler::WebThreadBase::CreateCompositorThread(params);
blink_platform_impl_->SetCompositorThread(compositor_thread_.get());
compositor_task_runner_ = compositor_thread_->GetTaskRunner();
blink_platform_impl_->InitializeCompositorThread(params);
blink::WebThread* compositor_thread =
blink_platform_impl_->CompositorThread();
compositor_task_runner_ = compositor_thread->GetTaskRunner();
compositor_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed),
......@@ -1183,7 +1182,7 @@ void RenderThreadImpl::InitializeCompositorThread() {
GetContentClient()->renderer()->PostCompositorThreadCreated(
compositor_task_runner_.get());
#if defined(OS_LINUX)
render_message_filter()->SetThreadPriority(compositor_thread_->ThreadId(),
render_message_filter()->SetThreadPriority(compositor_thread->ThreadId(),
base::ThreadPriority::DISPLAY);
#endif
}
......
......@@ -71,9 +71,6 @@
class SkBitmap;
namespace blink {
namespace scheduler {
class WebThreadBase;
}
class WebMediaStreamCenter;
}
......@@ -316,6 +313,8 @@ class CONTENT_EXPORT RenderThreadImpl
return blink_platform_impl_.get();
}
// Returns the task runner on the compositor thread.
//
// Will be null if threaded compositing has not been enabled.
scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner() const {
return compositor_task_runner_;
......@@ -651,9 +650,6 @@ class CONTENT_EXPORT RenderThreadImpl
// software-based.
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.
// TODO(dcastagna): This should be just one scoped_ptr once
// http://crbug.com/580386 is fixed.
......
......@@ -248,8 +248,6 @@ RendererBlinkPlatformImpl::RendererBlinkPlatformImpl(
RenderThreadImpl::current()
? RenderThreadImpl::current()->GetIOTaskRunner()
: nullptr),
compositor_thread_(nullptr),
main_thread_(main_thread_scheduler->CreateMainThread()),
sudden_termination_disables_(0),
is_locked_to_site_(false),
default_task_runner_(main_thread_scheduler->DefaultTaskRunner()),
......@@ -382,16 +380,6 @@ RendererBlinkPlatformImpl::CreateNetworkURLLoaderFactory() {
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() {
return &top_level_blame_context_;
}
......@@ -515,10 +503,6 @@ void RendererBlinkPlatformImpl::SuddenTerminationChanged(bool enabled) {
thread->GetRendererHost()->SuddenTerminationChanged(enabled);
}
blink::WebThread* RendererBlinkPlatformImpl::CompositorThread() const {
return compositor_thread_;
}
std::unique_ptr<WebStorageNamespace>
RendererBlinkPlatformImpl::CreateLocalStorageNamespace() {
if (!local_storage_cached_areas_) {
......
......@@ -38,7 +38,6 @@
namespace blink {
namespace scheduler {
class WebThreadScheduler;
class WebThreadBase;
}
class WebCanvasCaptureHandler;
class WebGraphicsContext3DProvider;
......@@ -102,7 +101,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
const blink::WebString& cacheStorageCacheName) override;
blink::WebString DefaultLocale() override;
void SuddenTerminationChanged(bool enabled) override;
blink::WebThread* CompositorThread() const override;
std::unique_ptr<blink::WebStorageNamespace> CreateLocalStorageNamespace()
override;
std::unique_ptr<blink::WebStorageNamespace> CreateSessionStorageNamespace(
......@@ -239,11 +237,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
scoped_refptr<ChildURLLoaderFactoryBundle>
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>
CreateNetworkURLLoaderFactory();
......@@ -267,9 +260,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
// Return the mojo interface for making CodeCache calls.
blink::mojom::CodeCacheHost& GetCodeCacheHost();
blink::scheduler::WebThreadBase* compositor_thread_;
std::unique_ptr<blink::WebThread> main_thread_;
std::unique_ptr<service_manager::Connector> connector_;
scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
......
......@@ -40,6 +40,7 @@
#include "base/memory/scoped_refptr.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/string_piece.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "mojo/public/cpp/system/data_pipe.h"
......@@ -444,9 +445,20 @@ class BLINK_PLATFORM_EXPORT Platform {
// for any other purpose.
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.
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
// belong to a particular frame scope.
virtual BlameContext* GetTopLevelBlameContext() { return nullptr; }
......@@ -478,15 +490,6 @@ class BLINK_PLATFORM_EXPORT Platform {
// Returns a value such as "en-US".
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.
virtual scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() const {
return nullptr;
......@@ -754,8 +757,6 @@ class BLINK_PLATFORM_EXPORT Platform {
virtual bool IsTakingV8ContextSnapshot() { return false; }
protected:
void RegisterExtraThreadToTLS(WebThread*);
WebThread* main_thread_;
private:
......@@ -772,10 +773,11 @@ class BLINK_PLATFORM_EXPORT Platform {
// Platform's main thread. See testing_platform_support.h for this.
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
// near CreateThread()), though.
base::ThreadLocalStorage::Slot current_thread_slot_;
base::Lock create_thread_lock_;
};
} // namespace blink
......
......@@ -274,7 +274,7 @@ Platform* Platform::Current() {
return g_platform;
}
WebThread* Platform::MainThread() const {
WebThread* Platform::MainThread() {
return main_thread_;
}
......@@ -342,8 +342,18 @@ void Platform::UpdateWebThreadTLS(WebThread* thread,
event->Signal();
}
void Platform::RegisterExtraThreadToTLS(WebThread* thread) {
WaitUntilWebThreadTLSUpdate(thread);
void Platform::InitializeCompositorThread(
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>
......
......@@ -96,7 +96,6 @@ class WebThreadForCompositor : public WebThreadImplForWorkerScheduler {
public:
explicit WebThreadForCompositor(const WebThreadCreationParams& params)
: WebThreadImplForWorkerScheduler(params) {
Init();
}
~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