Commit a7b2ce6d authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

Add VizCompositorThreadRunnerWebView

Make VizCompositorThreadRunner into an abstract interface and move the
existing implementation to VizCompositorThreadRunnerImpl. Then add
VizCompositorThreadRunnerWebView which will be webview's entry point
into creating and establishing viz objects.

Add code paths to ContentGpuClient so that webview can optionally
override the default instance.

Currently VizCompositorThreadRunnerWebView doesn't do much, except it
uses TaskQueueViz and exposes a simple API to run and block for work on
viz while allowing viz to schedule tasks on the render thread.

Bug: 805739
Change-Id: Ic5d2c45666ebc1fc9381c8cd5c71b0de57dd0136
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1731135Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683768}
parent e30dc321
......@@ -50,6 +50,8 @@ source_set("gfx") {
"task_forwarding_sequence.h",
"task_queue_web_view.cc",
"task_queue_web_view.h",
"viz_compositor_thread_runner_webview.cc",
"viz_compositor_thread_runner_webview.h",
]
deps = [
......@@ -63,6 +65,7 @@ source_set("gfx") {
"//gpu/skia_bindings",
"//gpu/vulkan:vulkan",
"//gpu/vulkan/init",
"//services/viz/privileged/mojom",
"//services/viz/public/mojom",
"//skia",
"//ui/gfx",
......
......@@ -6,5 +6,6 @@ include_rules = [
"+android_webview/browser/aw_feature_list.h",
"+android_webview/common/aw_switches.h",
"+android_webview/public/browser",
"+components/viz/service/main",
]
// Copyright 2019 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 "android_webview/browser/gfx/viz_compositor_thread_runner_webview.h"
#include <utility>
#include "android_webview/browser/gfx/task_queue_web_view.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
namespace android_webview {
namespace {
void RunAndDone(base::OnceClosure viz_task, base::OnceClosure done_task) {
std::move(viz_task).Run();
// |done_task| is provided by TaskQueueWebView unblocks the gpu service.
std::move(done_task).Run();
}
} // namespace
// static
VizCompositorThreadRunnerWebView*
VizCompositorThreadRunnerWebView::GetInstance() {
static base::NoDestructor<VizCompositorThreadRunnerWebView> instance;
return instance.get();
}
VizCompositorThreadRunnerWebView::VizCompositorThreadRunnerWebView()
: viz_thread_("VizWebView") {
base::Thread::Options options;
options.priority = base::ThreadPriority::DISPLAY;
CHECK(viz_thread_.StartWithOptions(options));
viz_task_runner_ = viz_thread_.task_runner();
TaskQueueWebView::GetInstance()->InitializeVizThread(viz_task_runner_);
DETACH_FROM_THREAD(viz_thread_checker_);
viz_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&VizCompositorThreadRunnerWebView::InitFrameSinkManagerOnViz,
base::Unretained(this)));
}
void VizCompositorThreadRunnerWebView::InitFrameSinkManagerOnViz() {
DCHECK_CALLED_ON_VALID_THREAD(viz_thread_checker_);
// The SharedBitmapManager is null as we do not support or use software
// compositing on Android.
frame_sink_manager_ = std::make_unique<viz::FrameSinkManagerImpl>(
/*shared_bitmap_manager=*/nullptr);
}
viz::FrameSinkManagerImpl*
VizCompositorThreadRunnerWebView::GetFrameSinkManager() {
DCHECK_CALLED_ON_VALID_THREAD(viz_thread_checker_);
DCHECK(frame_sink_manager_);
return frame_sink_manager_.get();
}
void VizCompositorThreadRunnerWebView::ScheduleOnVizAndBlock(
base::OnceClosure task) {
TaskQueueWebView::GetInstance()->ScheduleOnVizAndBlock(
base::BindOnce(&RunAndDone, std::move(task)));
}
VizCompositorThreadRunnerWebView::~VizCompositorThreadRunnerWebView() = default;
base::SingleThreadTaskRunner* VizCompositorThreadRunnerWebView::task_runner() {
return viz_task_runner_.get();
}
void VizCompositorThreadRunnerWebView::CreateFrameSinkManager(
viz::mojom::FrameSinkManagerParamsPtr params) {
// Does not support software compositing.
NOTREACHED();
}
void VizCompositorThreadRunnerWebView::CreateFrameSinkManager(
viz::mojom::FrameSinkManagerParamsPtr params,
gpu::CommandBufferTaskExecutor* task_executor,
viz::GpuServiceImpl* gpu_service) {
viz_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&VizCompositorThreadRunnerWebView::BindFrameSinkManagerOnViz,
base::Unretained(this), std::move(params)));
}
void VizCompositorThreadRunnerWebView::BindFrameSinkManagerOnViz(
viz::mojom::FrameSinkManagerParamsPtr params) {
DCHECK_CALLED_ON_VALID_THREAD(viz_thread_checker_);
DCHECK(frame_sink_manager_);
frame_sink_manager_->BindAndSetClient(
std::move(params->frame_sink_manager), viz_task_runner_,
viz::mojom::FrameSinkManagerClientPtr(
std::move(params->frame_sink_manager_client)));
}
#if defined(USE_VIZ_DEVTOOLS)
void VizCompositorThreadRunnerWebView::CreateVizDevTools(
viz::mojom::VizDevToolsParamsPtr params) {
NOTIMPLEMENTED();
}
#endif
void VizCompositorThreadRunnerWebView::CleanupForShutdown(
base::OnceClosure cleanup_finished_callback) {
// In-process gpu is not supposed to shutdown.
// Plus viz thread in webview architecture is not owned by the gpu thread.
NOTREACHED();
}
} // namespace android_webview
// Copyright 2019 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.
#ifndef ANDROID_WEBVIEW_BROWSER_GFX_VIZ_COMPOSITOR_THREAD_RUNNER_WEBVIEW_H_
#define ANDROID_WEBVIEW_BROWSER_GFX_VIZ_COMPOSITOR_THREAD_RUNNER_WEBVIEW_H_
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
#include "components/viz/service/main/viz_compositor_thread_runner.h"
namespace viz {
class FrameSinkManagerImpl;
} // namespace viz
namespace android_webview {
// This class overrides VizCompositorThreadRunner largely so that
// FrameSinkManagerImpl and other viz classes are connected to their mojo end
// points using the same code path (through VizMainImpl) as other chromium
// platforms. The benefit of this include:
// * code path sharing
// * keep illusion in content and below that webview does not assume
// in-process gpu
// * no need to introduce more "if webview" conditions in shared code
// However these viz classes actually do not talk to the gpu service
// in VizMainImpl, which may cause confusion for developers. If this proves to
// be common, then an alternative is assume viz runs in the browser process
// and directly connect viz classes to mojo end points in the browser.
class VizCompositorThreadRunnerWebView : public viz::VizCompositorThreadRunner {
public:
static VizCompositorThreadRunnerWebView* GetInstance();
viz::FrameSinkManagerImpl* GetFrameSinkManager();
void ScheduleOnVizAndBlock(base::OnceClosure task);
// viz::VizCompositorThreadRunner overrides.
base::SingleThreadTaskRunner* task_runner() override;
void CreateFrameSinkManager(
viz::mojom::FrameSinkManagerParamsPtr params) override;
void CreateFrameSinkManager(viz::mojom::FrameSinkManagerParamsPtr params,
gpu::CommandBufferTaskExecutor* task_executor,
viz::GpuServiceImpl* gpu_service) override;
#if defined(USE_VIZ_DEVTOOLS)
void CreateVizDevTools(viz::mojom::VizDevToolsParamsPtr params) override;
#endif
void CleanupForShutdown(base::OnceClosure cleanup_finished_callback) override;
private:
friend class base::NoDestructor<VizCompositorThreadRunnerWebView>;
VizCompositorThreadRunnerWebView();
~VizCompositorThreadRunnerWebView() override;
void InitFrameSinkManagerOnViz();
void BindFrameSinkManagerOnViz(viz::mojom::FrameSinkManagerParamsPtr params);
base::Thread viz_thread_;
scoped_refptr<base::SingleThreadTaskRunner> viz_task_runner_;
// Only accessed on |viz_task_runner_|.
THREAD_CHECKER(viz_thread_checker_);
std::unique_ptr<viz::FrameSinkManagerImpl> frame_sink_manager_;
DISALLOW_COPY_AND_ASSIGN(VizCompositorThreadRunnerWebView);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_GFX_VIZ_COMPOSITOR_THREAD_RUNNER_WEBVIEW_H_
......@@ -8,9 +8,13 @@ namespace android_webview {
AwContentGpuClient::AwContentGpuClient(
const GetSyncPointManagerCallback& sync_point_manager_callback,
const GetSharedImageManagerCallback& shared_image_manager_callback)
const GetSharedImageManagerCallback& shared_image_manager_callback,
const GetVizCompositorThreadRunnerCallback&
viz_compositor_thread_runner_callback)
: sync_point_manager_callback_(sync_point_manager_callback),
shared_image_manager_callback_(shared_image_manager_callback) {}
shared_image_manager_callback_(shared_image_manager_callback),
viz_compositor_thread_runner_callback_(
viz_compositor_thread_runner_callback) {}
AwContentGpuClient::~AwContentGpuClient() {}
......@@ -22,4 +26,9 @@ gpu::SharedImageManager* AwContentGpuClient::GetSharedImageManager() {
return shared_image_manager_callback_.Run();
}
viz::VizCompositorThreadRunner*
AwContentGpuClient::GetVizCompositorThreadRunner() {
return viz_compositor_thread_runner_callback_.Run();
}
} // namespace android_webview
......@@ -17,19 +17,25 @@ class AwContentGpuClient : public content::ContentGpuClient {
base::RepeatingCallback<gpu::SyncPointManager*()>;
using GetSharedImageManagerCallback =
base::RepeatingCallback<gpu::SharedImageManager*()>;
using GetVizCompositorThreadRunnerCallback =
base::RepeatingCallback<viz::VizCompositorThreadRunner*()>;
AwContentGpuClient(
const GetSyncPointManagerCallback& sync_point_manager_callback,
const GetSharedImageManagerCallback& shared_image_manager_callback);
const GetSharedImageManagerCallback& shared_image_manager_callback,
const GetVizCompositorThreadRunnerCallback&
viz_compositor_thread_runner_callback);
~AwContentGpuClient() override;
// content::ContentGpuClient implementation.
gpu::SyncPointManager* GetSyncPointManager() override;
gpu::SharedImageManager* GetSharedImageManager() override;
viz::VizCompositorThreadRunner* GetVizCompositorThreadRunner() override;
private:
GetSyncPointManagerCallback sync_point_manager_callback_;
GetSharedImageManagerCallback shared_image_manager_callback_;
GetVizCompositorThreadRunnerCallback viz_compositor_thread_runner_callback_;
DISALLOW_COPY_AND_ASSIGN(AwContentGpuClient);
};
......
......@@ -7,9 +7,11 @@
#include <memory>
#include "android_webview/browser/aw_content_browser_client.h"
#include "android_webview/browser/aw_feature_list.h"
#include "android_webview/browser/aw_media_url_interceptor.h"
#include "android_webview/browser/gfx/browser_view_renderer.h"
#include "android_webview/browser/gfx/gpu_service_web_view.h"
#include "android_webview/browser/gfx/viz_compositor_thread_runner_webview.h"
#include "android_webview/browser/scoped_add_feature_flags.h"
#include "android_webview/browser/tracing/aw_trace_event_args_whitelist.h"
#include "android_webview/common/aw_descriptors.h"
......@@ -319,6 +321,7 @@ gpu::SyncPointManager* GetSyncPointManager() {
DCHECK(GpuServiceWebView::GetInstance());
return GpuServiceWebView::GetInstance()->sync_point_manager();
}
gpu::SharedImageManager* GetSharedImageManager() {
DCHECK(GpuServiceWebView::GetInstance());
const bool enable_shared_image =
......@@ -328,12 +331,20 @@ gpu::SharedImageManager* GetSharedImageManager() {
? GpuServiceWebView::GetInstance()->shared_image_manager()
: nullptr;
}
viz::VizCompositorThreadRunner* GetVizCompositorThreadRunner() {
return base::FeatureList::IsEnabled(features::kVizForWebView)
? VizCompositorThreadRunnerWebView::GetInstance()
: nullptr;
}
} // namespace
content::ContentGpuClient* AwMainDelegate::CreateContentGpuClient() {
content_gpu_client_ = std::make_unique<AwContentGpuClient>(
base::BindRepeating(&GetSyncPointManager),
base::BindRepeating(&GetSharedImageManager));
base::BindRepeating(&GetSharedImageManager),
base::BindRepeating(&GetVizCompositorThreadRunner));
return content_gpu_client_.get();
}
......
......@@ -8,7 +8,7 @@
#include <utility>
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/service/main/viz_compositor_thread_runner.h"
#include "components/viz/service/main/viz_compositor_thread_runner_impl.h"
namespace demo {
......@@ -20,7 +20,7 @@ DemoService::DemoService(viz::mojom::FrameSinkManagerRequest request,
params->activation_deadline_in_frames = 0u;
params->frame_sink_manager = std::move(request);
params->frame_sink_manager_client = client.PassInterface();
runner_ = std::make_unique<viz::VizCompositorThreadRunner>();
runner_ = std::make_unique<viz::VizCompositorThreadRunnerImpl>();
runner_->CreateFrameSinkManager(std::move(params));
}
......
......@@ -11,7 +11,7 @@
#include "services/viz/privileged/mojom/compositing/frame_sink_manager.mojom.h"
namespace viz {
class VizCompositorThreadRunner;
class VizCompositorThreadRunnerImpl;
} // namespace viz
namespace demo {
......@@ -27,7 +27,7 @@ class DemoService {
~DemoService();
private:
std::unique_ptr<viz::VizCompositorThreadRunner> runner_;
std::unique_ptr<viz::VizCompositorThreadRunnerImpl> runner_;
DISALLOW_COPY_AND_ASSIGN(DemoService);
};
......
......@@ -12,8 +12,9 @@ source_set("main") {
defines = []
sources = [
"viz_compositor_thread_runner.cc",
"viz_compositor_thread_runner.h",
"viz_compositor_thread_runner_impl.cc",
"viz_compositor_thread_runner_impl.h",
"viz_main_impl.cc",
"viz_main_impl.h",
]
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Copyright 2019 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.
#ifndef COMPONENTS_VIZ_SERVICE_MAIN_VIZ_COMPOSITOR_THREAD_RUNNER_H_
#define COMPONENTS_VIZ_SERVICE_MAIN_VIZ_COMPOSITOR_THREAD_RUNNER_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "build/build_config.h"
#include "services/network/public/mojom/tcp_socket.mojom.h"
#include "base/callback.h"
#include "services/viz/privileged/mojom/viz_main.mojom.h"
#if defined(OS_ANDROID)
#include "base/android/java_handler_thread.h"
#endif
namespace base {
class SingleThreadTaskRunner;
class Thread;
} // namespace base
}
namespace gpu {
class CommandBufferTaskExecutor;
} // namespace gpu
namespace ui_devtools {
class UiDevToolsServer;
} // namespace ui_devtools
namespace viz {
class OutputSurfaceProvider;
class FrameSinkManagerImpl;
class GpuServiceImpl;
class ServerSharedBitmapManager;
#if defined(OS_ANDROID)
using VizCompositorThreadType = base::android::JavaHandlerThread;
#else
using VizCompositorThreadType = base::Thread;
#endif
class GpuServiceImpl;
// Starts and runs the VizCompositorThread. The thread will be started when this
// object is constructed. Objects on the thread will be initialized after
......@@ -48,24 +26,24 @@ using VizCompositorThreadType = base::Thread;
// and then stop the thread.
class VizCompositorThreadRunner {
public:
VizCompositorThreadRunner();
// Performs teardown on thread and then stops thread.
~VizCompositorThreadRunner();
virtual ~VizCompositorThreadRunner() = default;
// Returns the TaskRunner for VizCompositorThread.
base::SingleThreadTaskRunner* task_runner() { return task_runner_.get(); }
virtual base::SingleThreadTaskRunner* task_runner() = 0;
// Creates FrameSinkManager from |params|. The version with |gpu_service| and
// |task_executor| supports both GPU and software compositing, while the
// version without supports only software compositing. Should be called from
// the thread that owns |this| to initialize state on VizCompositorThread.
void CreateFrameSinkManager(mojom::FrameSinkManagerParamsPtr params);
void CreateFrameSinkManager(mojom::FrameSinkManagerParamsPtr params,
gpu::CommandBufferTaskExecutor* task_executor,
GpuServiceImpl* gpu_service);
virtual void CreateFrameSinkManager(
mojom::FrameSinkManagerParamsPtr params) = 0;
virtual void CreateFrameSinkManager(
mojom::FrameSinkManagerParamsPtr params,
gpu::CommandBufferTaskExecutor* task_executor,
GpuServiceImpl* gpu_service) = 0;
#if defined(USE_VIZ_DEVTOOLS)
void CreateVizDevTools(mojom::VizDevToolsParamsPtr params);
virtual void CreateVizDevTools(mojom::VizDevToolsParamsPtr params) = 0;
#endif
// Performs cleanup on VizCompositorThread needed before forcing thread to
......@@ -77,37 +55,8 @@ class VizCompositorThreadRunner {
// This is intended to be used when the GPU thread wants to force restart. The
// cleanup is normally handled by the browser process before GPU process
// shutdown, except if the GPU thread is forcing restart.
void CleanupForShutdown(base::OnceClosure cleanup_finished_callback);
private:
void CreateFrameSinkManagerOnCompositorThread(
mojom::FrameSinkManagerParamsPtr params,
gpu::CommandBufferTaskExecutor* task_executor,
GpuServiceImpl* gpu_service);
#if defined(USE_VIZ_DEVTOOLS)
void CreateVizDevToolsOnCompositorThread(mojom::VizDevToolsParamsPtr params);
void InitVizDevToolsOnCompositorThread(mojom::VizDevToolsParamsPtr params);
#endif
void CleanupForShutdownOnCompositorThread();
void TearDownOnCompositorThread();
// Start variables to be accessed only on |task_runner_|.
std::unique_ptr<ServerSharedBitmapManager> server_shared_bitmap_manager_;
std::unique_ptr<OutputSurfaceProvider> output_surface_provider_;
std::unique_ptr<FrameSinkManagerImpl> frame_sink_manager_;
#if defined(USE_VIZ_DEVTOOLS)
std::unique_ptr<ui_devtools::UiDevToolsServer> devtools_server_;
// If the FrameSinkManager is not ready yet, then we stash the pending
// VizDevToolsParams.
mojom::VizDevToolsParamsPtr pending_viz_dev_tools_params_;
#endif
// End variables to be accessed only on |task_runner_|.
std::unique_ptr<VizCompositorThreadType> thread_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
DISALLOW_COPY_AND_ASSIGN(VizCompositorThreadRunner);
virtual void CleanupForShutdown(
base::OnceClosure cleanup_finished_callback) = 0;
};
} // namespace viz
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/viz/service/main/viz_compositor_thread_runner.h"
#include "components/viz/service/main/viz_compositor_thread_runner_impl.h"
#include <utility>
......@@ -80,65 +80,69 @@ std::unique_ptr<VizCompositorThreadType> CreateAndStartCompositorThread() {
} // namespace
VizCompositorThreadRunner::VizCompositorThreadRunner()
VizCompositorThreadRunnerImpl::VizCompositorThreadRunnerImpl()
: thread_(CreateAndStartCompositorThread()),
task_runner_(thread_->task_runner()) {}
VizCompositorThreadRunner::~VizCompositorThreadRunner() {
VizCompositorThreadRunnerImpl::~VizCompositorThreadRunnerImpl() {
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&VizCompositorThreadRunner::TearDownOnCompositorThread,
base::BindOnce(&VizCompositorThreadRunnerImpl::TearDownOnCompositorThread,
base::Unretained(this)));
thread_->Stop();
}
void VizCompositorThreadRunner::CreateFrameSinkManager(
base::SingleThreadTaskRunner* VizCompositorThreadRunnerImpl::task_runner() {
return task_runner_.get();
}
void VizCompositorThreadRunnerImpl::CreateFrameSinkManager(
mojom::FrameSinkManagerParamsPtr params) {
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&VizCompositorThreadRunner::CreateFrameSinkManagerOnCompositorThread,
base::Unretained(this), std::move(params), nullptr, nullptr));
FROM_HERE, base::BindOnce(&VizCompositorThreadRunnerImpl::
CreateFrameSinkManagerOnCompositorThread,
base::Unretained(this), std::move(params),
nullptr, nullptr));
}
void VizCompositorThreadRunner::CreateFrameSinkManager(
void VizCompositorThreadRunnerImpl::CreateFrameSinkManager(
mojom::FrameSinkManagerParamsPtr params,
gpu::CommandBufferTaskExecutor* task_executor,
GpuServiceImpl* gpu_service) {
// All of the unretained objects are owned on the GPU thread and destroyed
// after VizCompositorThread has been shutdown.
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&VizCompositorThreadRunner::CreateFrameSinkManagerOnCompositorThread,
base::Unretained(this), std::move(params),
base::Unretained(task_executor), base::Unretained(gpu_service)));
FROM_HERE, base::BindOnce(&VizCompositorThreadRunnerImpl::
CreateFrameSinkManagerOnCompositorThread,
base::Unretained(this), std::move(params),
base::Unretained(task_executor),
base::Unretained(gpu_service)));
}
#if defined(USE_VIZ_DEVTOOLS)
void VizCompositorThreadRunner::CreateVizDevTools(
void VizCompositorThreadRunnerImpl::CreateVizDevTools(
mojom::VizDevToolsParamsPtr params) {
// It is safe to use Unretained(this) because |this| owns the |task_runner_|,
// and will outlive it.
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&VizCompositorThreadRunner::CreateVizDevToolsOnCompositorThread,
&VizCompositorThreadRunnerImpl::CreateVizDevToolsOnCompositorThread,
base::Unretained(this), std::move(params)));
}
#endif
void VizCompositorThreadRunner::CleanupForShutdown(
void VizCompositorThreadRunnerImpl::CleanupForShutdown(
base::OnceClosure cleanup_finished_callback) {
task_runner_->PostTaskAndReply(
FROM_HERE,
base::BindOnce(
&VizCompositorThreadRunner::CleanupForShutdownOnCompositorThread,
&VizCompositorThreadRunnerImpl::CleanupForShutdownOnCompositorThread,
base::Unretained(this)),
std::move(cleanup_finished_callback));
}
void VizCompositorThreadRunner::CreateFrameSinkManagerOnCompositorThread(
void VizCompositorThreadRunnerImpl::CreateFrameSinkManagerOnCompositorThread(
mojom::FrameSinkManagerParamsPtr params,
gpu::CommandBufferTaskExecutor* task_executor,
GpuServiceImpl* gpu_service) {
......@@ -201,7 +205,7 @@ void VizCompositorThreadRunner::CreateFrameSinkManagerOnCompositorThread(
}
#if defined(USE_VIZ_DEVTOOLS)
void VizCompositorThreadRunner::CreateVizDevToolsOnCompositorThread(
void VizCompositorThreadRunnerImpl::CreateVizDevToolsOnCompositorThread(
mojom::VizDevToolsParamsPtr params) {
if (!frame_sink_manager_) {
DCHECK(!pending_viz_dev_tools_params_);
......@@ -211,7 +215,7 @@ void VizCompositorThreadRunner::CreateVizDevToolsOnCompositorThread(
InitVizDevToolsOnCompositorThread(std::move(params));
}
void VizCompositorThreadRunner::InitVizDevToolsOnCompositorThread(
void VizCompositorThreadRunnerImpl::InitVizDevToolsOnCompositorThread(
mojom::VizDevToolsParamsPtr params) {
DCHECK(frame_sink_manager_);
devtools_server_ = ui_devtools::UiDevToolsServer::CreateForViz(
......@@ -231,14 +235,14 @@ void VizCompositorThreadRunner::InitVizDevToolsOnCompositorThread(
}
#endif
void VizCompositorThreadRunner::CleanupForShutdownOnCompositorThread() {
void VizCompositorThreadRunnerImpl::CleanupForShutdownOnCompositorThread() {
DCHECK(task_runner_->BelongsToCurrentThread());
if (frame_sink_manager_)
frame_sink_manager_->ForceShutdown();
}
void VizCompositorThreadRunner::TearDownOnCompositorThread() {
void VizCompositorThreadRunnerImpl::TearDownOnCompositorThread() {
DCHECK(task_runner_->BelongsToCurrentThread());
if (server_shared_bitmap_manager_) {
......
// Copyright 2018 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.
#ifndef COMPONENTS_VIZ_SERVICE_MAIN_VIZ_COMPOSITOR_THREAD_RUNNER_IMPL_H_
#define COMPONENTS_VIZ_SERVICE_MAIN_VIZ_COMPOSITOR_THREAD_RUNNER_IMPL_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/message_loop/message_loop.h"
#include "build/build_config.h"
#include "components/viz/service/main/viz_compositor_thread_runner.h"
#include "services/network/public/mojom/tcp_socket.mojom.h"
#if defined(OS_ANDROID)
#include "base/android/java_handler_thread.h"
#endif
namespace base {
class Thread;
} // namespace base
namespace ui_devtools {
class UiDevToolsServer;
} // namespace ui_devtools
namespace viz {
class OutputSurfaceProvider;
class FrameSinkManagerImpl;
class ServerSharedBitmapManager;
#if defined(OS_ANDROID)
using VizCompositorThreadType = base::android::JavaHandlerThread;
#else
using VizCompositorThreadType = base::Thread;
#endif
class VizCompositorThreadRunnerImpl : public VizCompositorThreadRunner {
public:
VizCompositorThreadRunnerImpl();
// Performs teardown on thread and then stops thread.
~VizCompositorThreadRunnerImpl() override;
// VizCompositorThreadRunner overrides.
base::SingleThreadTaskRunner* task_runner() override;
void CreateFrameSinkManager(mojom::FrameSinkManagerParamsPtr params) override;
void CreateFrameSinkManager(mojom::FrameSinkManagerParamsPtr params,
gpu::CommandBufferTaskExecutor* task_executor,
GpuServiceImpl* gpu_service) override;
#if defined(USE_VIZ_DEVTOOLS)
void CreateVizDevTools(mojom::VizDevToolsParamsPtr params) override;
#endif
void CleanupForShutdown(base::OnceClosure cleanup_finished_callback) override;
private:
void CreateFrameSinkManagerOnCompositorThread(
mojom::FrameSinkManagerParamsPtr params,
gpu::CommandBufferTaskExecutor* task_executor,
GpuServiceImpl* gpu_service);
#if defined(USE_VIZ_DEVTOOLS)
void CreateVizDevToolsOnCompositorThread(mojom::VizDevToolsParamsPtr params);
void InitVizDevToolsOnCompositorThread(mojom::VizDevToolsParamsPtr params);
#endif
void CleanupForShutdownOnCompositorThread();
void TearDownOnCompositorThread();
// Start variables to be accessed only on |task_runner_|.
std::unique_ptr<ServerSharedBitmapManager> server_shared_bitmap_manager_;
std::unique_ptr<OutputSurfaceProvider> output_surface_provider_;
std::unique_ptr<FrameSinkManagerImpl> frame_sink_manager_;
#if defined(USE_VIZ_DEVTOOLS)
std::unique_ptr<ui_devtools::UiDevToolsServer> devtools_server_;
// If the FrameSinkManager is not ready yet, then we stash the pending
// VizDevToolsParams.
mojom::VizDevToolsParamsPtr pending_viz_dev_tools_params_;
#endif
// End variables to be accessed only on |task_runner_|.
std::unique_ptr<VizCompositorThreadType> thread_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
DISALLOW_COPY_AND_ASSIGN(VizCompositorThreadRunnerImpl);
};
} // namespace viz
#endif // COMPONENTS_VIZ_SERVICE_MAIN_VIZ_COMPOSITOR_THREAD_RUNNER_IMPL_H_
......@@ -81,8 +81,13 @@ VizMainImpl::VizMainImpl(Delegate* delegate,
if (!dependencies_.io_thread_task_runner)
io_thread_ = CreateAndStartIOThread();
if (dependencies_.create_display_compositor) {
viz_compositor_thread_runner_ =
std::make_unique<VizCompositorThreadRunner>();
if (dependencies.viz_compositor_thread_runner) {
viz_compositor_thread_runner_ = dependencies.viz_compositor_thread_runner;
} else {
viz_compositor_thread_runner_impl_ =
std::make_unique<VizCompositorThreadRunnerImpl>();
viz_compositor_thread_runner_ = viz_compositor_thread_runner_impl_.get();
}
if (delegate_) {
delegate_->PostCompositorThreadCreated(
viz_compositor_thread_runner_->task_runner());
......@@ -115,11 +120,14 @@ VizMainImpl::~VizMainImpl() {
// need to process commands from the host as it is shutting down.
receiver_.reset();
// If the VizCompositorThread was started then this will block until the
// thread has been shutdown. All RootCompositorFrameSinks must be destroyed
// before now, otherwise the compositor thread will deadlock waiting for a
// response from the blocked GPU thread.
viz_compositor_thread_runner_.reset();
// If the VizCompositorThread was started and owned by VizMainImpl, then this
// will block until the thread has been shutdown. All RootCompositorFrameSinks
// must be destroyed before now, otherwise the compositor thread will deadlock
// waiting for a response from the blocked GPU thread.
// For the non-owned case for Android WebView, Viz does not communicate with
// this thread so there is no need to shutdown viz first.
viz_compositor_thread_runner_ = nullptr;
viz_compositor_thread_runner_impl_.reset();
if (ukm_recorder_)
ukm::DelegatingUkmRecorder::Get()->RemoveDelegate(ukm_recorder_.get());
......
......@@ -11,7 +11,7 @@
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "components/discardable_memory/client/client_discardable_shared_memory_manager.h"
#include "components/viz/service/main/viz_compositor_thread_runner.h"
#include "components/viz/service/main/viz_compositor_thread_runner_impl.h"
#include "gpu/ipc/in_process_command_buffer.h"
#include "mojo/public/cpp/bindings/associated_receiver_set.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
......@@ -84,6 +84,7 @@ class VizMainImpl : public mojom::VizMain {
base::WaitableEvent* shutdown_event = nullptr;
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner;
service_manager::Connector* connector = nullptr;
VizCompositorThreadRunner* viz_compositor_thread_runner = nullptr;
private:
DISALLOW_COPY_AND_ASSIGN(ExternalDependencies);
......@@ -165,7 +166,13 @@ class VizMainImpl : public mojom::VizMain {
mojom::FrameSinkManagerParamsPtr pending_frame_sink_manager_params_;
// Runs the VizCompositorThread for the display compositor with OOP-D.
std::unique_ptr<VizCompositorThreadRunner> viz_compositor_thread_runner_;
std::unique_ptr<VizCompositorThreadRunnerImpl>
viz_compositor_thread_runner_impl_;
// Note under Android WebView where VizCompositorThreadRunner is not created
// and owned by this, Viz does not interact with other objects in this class,
// such as GpuServiceImpl or CommandBufferTaskExecutor. Code should take care
// to avoid introducing such assumptions.
VizCompositorThreadRunner* viz_compositor_thread_runner_ = nullptr;
const scoped_refptr<base::SingleThreadTaskRunner> gpu_thread_task_runner_;
......
......@@ -188,7 +188,8 @@ void VizProcessTransportFactory::ConnectHostFrameSinkManager() {
// GPU process access is disabled. Start a new thread to run the display
// compositor in-process and connect HostFrameSinkManager to it.
viz_compositor_thread_ = std::make_unique<viz::VizCompositorThreadRunner>();
viz_compositor_thread_ =
std::make_unique<viz::VizCompositorThreadRunnerImpl>();
viz::mojom::FrameSinkManagerParamsPtr params =
viz::mojom::FrameSinkManagerParams::New();
......
......@@ -10,7 +10,7 @@
#include "base/macros.h"
#include "build/build_config.h"
#include "components/viz/common/gpu/context_lost_observer.h"
#include "components/viz/service/main/viz_compositor_thread_runner.h"
#include "components/viz/service/main/viz_compositor_thread_runner_impl.h"
#include "content/browser/compositor/image_transport_factory.h"
#include "gpu/command_buffer/common/context_result.h"
#include "mojo/public/cpp/bindings/binding.h"
......@@ -131,7 +131,7 @@ class VizProcessTransportFactory : public ui::ContextFactory,
// Will start and run the VizCompositorThread for using an in-process display
// compositor.
std::unique_ptr<viz::VizCompositorThreadRunner> viz_compositor_thread_;
std::unique_ptr<viz::VizCompositorThreadRunnerImpl> viz_compositor_thread_;
ui::HostContextFactoryPrivate context_factory_private_;
base::WeakPtrFactory<VizProcessTransportFactory> weak_ptr_factory_{this};
......
......@@ -170,6 +170,8 @@ viz::VizMainImpl::ExternalDependencies CreateVizMainDependencies(
deps.sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager();
deps.shared_image_manager =
GetContentClient()->gpu()->GetSharedImageManager();
deps.viz_compositor_thread_runner =
GetContentClient()->gpu()->GetVizCompositorThreadRunner();
}
auto* process = ChildProcess::current();
deps.shutdown_event = process->GetShutDownEvent();
......
......@@ -18,6 +18,11 @@ gpu::SharedImageManager* ContentGpuClient::GetSharedImageManager() {
return nullptr;
}
viz::VizCompositorThreadRunner*
ContentGpuClient::GetVizCompositorThreadRunner() {
return nullptr;
}
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
std::unique_ptr<media::CdmProxy> ContentGpuClient::CreateCdmProxy(
const base::Token& cdm_guid) {
......
......@@ -28,6 +28,10 @@ namespace media {
class CdmProxy;
}
namespace viz {
class VizCompositorThreadRunner;
}
namespace content {
// Embedder API for participating in gpu logic.
......@@ -53,10 +57,11 @@ class CONTENT_EXPORT ContentGpuClient {
virtual void PostCompositorThreadCreated(
base::SingleThreadTaskRunner* task_runner) {}
// Allows client to supply SyncPointManager and SharedImageManager instance
// instead of having content internally create one.
// Allows client to supply these object instances instead of having content
// internally create one.
virtual gpu::SyncPointManager* GetSyncPointManager();
virtual gpu::SharedImageManager* GetSharedImageManager();
virtual viz::VizCompositorThreadRunner* GetVizCompositorThreadRunner();
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
// Creates a media::CdmProxy for the type of Content Decryption Module (CDM)
......
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