Commit 88c84377 authored by Yuta Kitamura's avatar Yuta Kitamura Committed by Commit Bot

Move most of compositor thread's initialization to Platform.

This CL moves most of the actual work of initializing compositor thread
from RenderThreadImpl to Platform. This further reduces //content's
dependency to WebThread.

A new virtual function is introduced to Platform so we can change the
thread priority of the created compositor thread on Linux, where we need
to talk to the browser process to change the thread priority.

Additionally, a new function Platform::CompositorThreadTaskRunner() is
introduced, because RenderThreadImpl needs to post tasks to the
compositor thread after the thread is initialized.

Bug: 826203
Change-Id: Ic80e6452cdfe8af25ae2b277125687854859d106
Reviewed-on: https://chromium-review.googlesource.com/1249424
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@{#595063}
parent c465ab40
......@@ -1167,25 +1167,14 @@ void RenderThreadImpl::SetResourceDispatcherDelegate(
}
void RenderThreadImpl::InitializeCompositorThread() {
blink::WebThreadCreationParams params(
blink::WebThreadType::kCompositorThread);
#if defined(OS_ANDROID)
params.thread_options.priority = base::ThreadPriority::DISPLAY;
#endif
blink_platform_impl_->InitializeCompositorThread(params);
blink::WebThread* compositor_thread =
blink_platform_impl_->CompositorThread();
compositor_task_runner_ = compositor_thread->GetTaskRunner();
blink_platform_impl_->InitializeCompositorThread();
compositor_task_runner_ = blink_platform_impl_->CompositorThreadTaskRunner();
compositor_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed),
false));
GetContentClient()->renderer()->PostCompositorThreadCreated(
compositor_task_runner_.get());
#if defined(OS_LINUX)
render_message_filter()->SetThreadPriority(compositor_thread->ThreadId(),
base::ThreadPriority::DISPLAY);
#endif
}
scoped_refptr<base::SingleThreadTaskRunner>
......
......@@ -380,6 +380,16 @@ RendererBlinkPlatformImpl::CreateNetworkURLLoaderFactory() {
return url_loader_factory;
}
void RendererBlinkPlatformImpl::SetDisplayThreadPriority(
base::PlatformThreadId thread_id) {
#if defined(OS_LINUX)
if (RenderThreadImpl* render_thread = RenderThreadImpl::current()) {
render_thread->render_message_filter()->SetThreadPriority(
thread_id, base::ThreadPriority::DISPLAY);
}
#endif
}
blink::BlameContext* RendererBlinkPlatformImpl::GetTopLevelBlameContext() {
return &top_level_blame_context_;
}
......
......@@ -196,6 +196,7 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
blink::WebString ConvertIDNToUnicode(const blink::WebString& host) override;
service_manager::Connector* GetConnector() override;
blink::InterfaceProvider* GetInterfaceProvider() override;
void SetDisplayThreadPriority(base::PlatformThreadId thread_id) override;
blink::BlameContext* GetTopLevelBlameContext() override;
void RecordRappor(const char* metric,
const blink::WebString& sample) override;
......
......@@ -447,7 +447,7 @@ class BLINK_PLATFORM_EXPORT Platform {
// Create and initialize the compositor thread. The thread is saved in
// Platform, and will be accessible through CompositorThread().
void InitializeCompositorThread(const WebThreadCreationParams&);
void InitializeCompositorThread();
// Returns an interface to the current thread.
WebThread* CurrentThread();
......@@ -459,6 +459,17 @@ class BLINK_PLATFORM_EXPORT Platform {
// renderer was created with threaded rendering disabled.
WebThread* CompositorThread();
// Returns the task runner of the compositor thread. This is available
// once InitializeCompositorThread() is called.
scoped_refptr<base::SingleThreadTaskRunner> CompositorThreadTaskRunner();
// This is called after the compositor thread is created, so the embedder
// can initiate an IPC to change its thread priority (on Linux we can't
// increase the nice value, so we need to ask the browser process). This
// function is only called from the main thread (where InitializeCompositor-
// Thread() is called).
virtual void SetDisplayThreadPriority(base::PlatformThreadId) {}
// Returns a blame context for attributing top-level work which does not
// belong to a particular frame scope.
virtual BlameContext* GetTopLevelBlameContext() { return nullptr; }
......
......@@ -36,6 +36,7 @@
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/memory_dump_manager.h"
#include "build/build_config.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/platform/interface_provider.h"
......@@ -341,20 +342,32 @@ void Platform::UpdateWebThreadTLS(WebThread* thread,
event->Signal();
}
void Platform::InitializeCompositorThread(
const WebThreadCreationParams& params) {
void Platform::InitializeCompositorThread() {
DCHECK(!compositor_thread_);
WebThreadCreationParams params(WebThreadType::kCompositorThread);
#if defined(OS_ANDROID)
params.thread_options.priority = base::ThreadPriority::DISPLAY;
#endif
std::unique_ptr<scheduler::WebThreadBase> compositor_thread =
scheduler::WebThreadBase::CreateCompositorThread(params);
compositor_thread->Init();
WaitUntilWebThreadTLSUpdate(compositor_thread.get());
compositor_thread_ = std::move(compositor_thread);
SetDisplayThreadPriority(compositor_thread_->ThreadId());
}
WebThread* Platform::CompositorThread() {
return compositor_thread_.get();
}
scoped_refptr<base::SingleThreadTaskRunner>
Platform::CompositorThreadTaskRunner() {
if (WebThread* compositor_thread = CompositorThread())
return compositor_thread->GetTaskRunner();
return nullptr;
}
std::unique_ptr<WebGraphicsContext3DProvider>
Platform::CreateOffscreenGraphicsContext3DProvider(
const Platform::ContextAttributes&,
......
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