Commit 150e09e1 authored by kylechar's avatar kylechar Committed by Commit Bot

Add VizProcessTransportFactory.

The VizProcessTransportFactory is a replacement for
GpuProcessTransportFactory for viz mode. In this mode the display
compositor runs in the viz process instead of browser process.

The --enable-viz flag won't work yet since there are changes required in
content/browser/renderer_host that still need to land.

TBR: mpearson@chromium.org
Bug: 770833, 732900
Change-Id: I0aaf9ef369366838e2335447358fd6dfaaa5bf0a
Reviewed-on: https://chromium-review.googlesource.com/703274
Commit-Queue: kylechar <kylechar@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510076}
parent 24062340
......@@ -15,4 +15,8 @@ const char kDisableSurfaceReferences[] = "disable-surface-references";
// by the parent compositor.
const char kEnableSurfaceSynchronization[] = "enable-surface-synchronization";
// Enables running viz. This basically entails running the display compositor
// in the viz process instead of the browser process.
const char kEnableViz[] = "enable-viz";
} // namespace switches
......@@ -12,6 +12,7 @@ namespace switches {
// Keep list in alphabetical order.
VIZ_COMMON_EXPORT extern const char kDisableSurfaceReferences[];
VIZ_COMMON_EXPORT extern const char kEnableSurfaceSynchronization[];
VIZ_COMMON_EXPORT extern const char kEnableViz[];
} // namespace switches
......
......@@ -2202,6 +2202,8 @@ source_set("browser") {
"compositor/software_output_device_win.h",
"compositor/software_output_device_x11.cc",
"compositor/software_output_device_x11.h",
"compositor/viz_process_transport_factory.cc",
"compositor/viz_process_transport_factory.h",
"context_factory.cc",
"renderer_host/browser_compositor_view_mac.h",
"renderer_host/browser_compositor_view_mac.mm",
......
......@@ -60,6 +60,7 @@
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/compositor/gpu_process_transport_factory.h"
#include "content/browser/compositor/surface_utils.h"
#include "content/browser/compositor/viz_process_transport_factory.h"
#include "content/browser/dom_storage/dom_storage_area.h"
#include "content/browser/download/download_resource_handler.h"
#include "content/browser/download/save_file_manager.h"
......@@ -1455,10 +1456,8 @@ int BrowserMainLoop::BrowserThreadsStarted() {
#endif
#if BUILDFLAG(ENABLE_VULKAN)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableVulkan)) {
if (parsed_command_line_.HasSwitch(switches::kEnableVulkan))
gpu::InitializeVulkan();
}
#endif
// Initialize the GPU shader cache. This needs to be initialized before
......@@ -1481,27 +1480,33 @@ int BrowserMainLoop::BrowserThreadsStarted() {
is_mus) {
established_gpu_channel = always_uses_gpu = false;
}
if (!is_mus) {
host_frame_sink_manager_ = base::MakeUnique<viz::HostFrameSinkManager>();
// TODO(crbug.com/676384): Remove flag along with surface sequences.
auto surface_lifetime_type =
parsed_command_line_.HasSwitch(switches::kDisableSurfaceReferences)
? viz::SurfaceManager::LifetimeType::SEQUENCES
: viz::SurfaceManager::LifetimeType::REFERENCES;
frame_sink_manager_impl_ =
std::make_unique<viz::FrameSinkManagerImpl>(surface_lifetime_type);
// TODO(danakj): Don't make a FrameSinkManagerImpl when display is in the
// Gpu process, instead get the mojo pointer from the Gpu process.
surface_utils::ConnectWithLocalFrameSinkManager(
host_frame_sink_manager_.get(), frame_sink_manager_impl_.get());
// Initialize GpuChannelHostFactory and ImageTransportFactory.
BrowserGpuChannelHostFactory::Initialize(established_gpu_channel);
ImageTransportFactory::SetFactory(
std::make_unique<GpuProcessTransportFactory>(
BrowserGpuChannelHostFactory::instance(), GetResizeTaskRunner()));
if (parsed_command_line_.HasSwitch(switches::kEnableViz)) {
auto transport_factory = std::make_unique<VizProcessTransportFactory>(
BrowserGpuChannelHostFactory::instance(), GetResizeTaskRunner());
transport_factory->ConnectHostFrameSinkManager();
ImageTransportFactory::SetFactory(std::move(transport_factory));
} else {
// TODO(crbug.com/676384): Remove flag along with surface sequences.
auto surface_lifetime_type =
parsed_command_line_.HasSwitch(switches::kDisableSurfaceReferences)
? viz::SurfaceManager::LifetimeType::SEQUENCES
: viz::SurfaceManager::LifetimeType::REFERENCES;
frame_sink_manager_impl_ =
std::make_unique<viz::FrameSinkManagerImpl>(surface_lifetime_type);
surface_utils::ConnectWithLocalFrameSinkManager(
host_frame_sink_manager_.get(), frame_sink_manager_impl_.get());
ImageTransportFactory::SetFactory(
std::make_unique<GpuProcessTransportFactory>(
BrowserGpuChannelHostFactory::instance(), GetResizeTaskRunner()));
}
}
#if defined(USE_AURA)
......
......@@ -5,4 +5,6 @@ per-file *mus*=fsamuel@chromium.org
per-file *mus*=sadrul@chromium.org
per-file *mus*=rjkroege@chromium.org
per-file *viz*=file://components/viz/OWNERS
# COMPONENT: Internals>Compositing
This diff is collapsed.
// Copyright 2017 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 CONTENT_BROWSER_COMPOSITOR_VIZ_PROCESS_TRANSPORT_FACTORY_H_
#define CONTENT_BROWSER_COMPOSITOR_VIZ_PROCESS_TRANSPORT_FACTORY_H_
#include <memory>
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "components/viz/common/display/renderer_settings.h"
#include "components/viz/common/surfaces/frame_sink_id_allocator.h"
#include "content/browser/compositor/image_transport_factory.h"
#include "services/viz/privileged/interfaces/compositing/frame_sink_manager.mojom.h"
#include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom.h"
#include "ui/compositor/compositor.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace cc {
class SingleThreadTaskGraphRunner;
}
namespace gpu {
class GpuChannelEstablishFactory;
}
namespace ui {
class ContextProviderCommandBuffer;
}
namespace content {
// A replacement for GpuProcessTransportFactory to be used when running viz. In
// this configuration the display compositor is located in the viz process
// instead of in the browser process. Any interaction with the display
// compositor must happen over IPC.
class VizProcessTransportFactory : public ui::ContextFactory,
public ui::ContextFactoryPrivate,
public ImageTransportFactory {
public:
VizProcessTransportFactory(
gpu::GpuChannelEstablishFactory* gpu_channel_establish_factory,
scoped_refptr<base::SingleThreadTaskRunner> resize_task_runner);
~VizProcessTransportFactory() override;
// Connects HostFrameSinkManager to FrameSinkManagerImpl in viz process.
void ConnectHostFrameSinkManager();
// ui::ContextFactory implementation.
void CreateLayerTreeFrameSink(
base::WeakPtr<ui::Compositor> compositor) override;
scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider()
override;
void RemoveCompositor(ui::Compositor* compositor) override;
double GetRefreshRate() const override;
gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
cc::TaskGraphRunner* GetTaskGraphRunner() override;
const viz::ResourceSettings& GetResourceSettings() const override;
void AddObserver(ui::ContextFactoryObserver* observer) override;
void RemoveObserver(ui::ContextFactoryObserver* observer) override;
// ui::ContextFactoryPrivate implementation.
std::unique_ptr<ui::Reflector> CreateReflector(ui::Compositor* source,
ui::Layer* target) override;
void RemoveReflector(ui::Reflector* reflector) override;
viz::FrameSinkId AllocateFrameSinkId() override;
viz::HostFrameSinkManager* GetHostFrameSinkManager() override;
void SetDisplayVisible(ui::Compositor* compositor, bool visible) override;
void ResizeDisplay(ui::Compositor* compositor,
const gfx::Size& size) override;
void SetDisplayColorSpace(ui::Compositor* compositor,
const gfx::ColorSpace& blending_color_space,
const gfx::ColorSpace& output_color_space) override;
void SetAuthoritativeVSyncInterval(ui::Compositor* compositor,
base::TimeDelta interval) override;
void SetDisplayVSyncParameters(ui::Compositor* compositor,
base::TimeTicks timebase,
base::TimeDelta interval) override;
void IssueExternalBeginFrame(ui::Compositor* compositor,
const viz::BeginFrameArgs& args) override;
void SetOutputIsSecure(ui::Compositor* compositor, bool secure) override;
viz::FrameSinkManagerImpl* GetFrameSinkManager() override;
// ImageTransportFactory implementation.
ui::ContextFactory* GetContextFactory() override;
ui::ContextFactoryPrivate* GetContextFactoryPrivate() override;
viz::GLHelper* GetGLHelper() override;
#if defined(OS_MACOSX)
void SetCompositorSuspendedForRecycle(ui::Compositor* compositor,
bool suspended) override;
#endif
private:
struct CompositorData {
CompositorData();
CompositorData(CompositorData&& other);
~CompositorData();
CompositorData& operator=(CompositorData&& other);
// Privileged interface that controls the display for a root
// CompositorFrameSink.
viz::mojom::DisplayPrivateAssociatedPtr display_private;
private:
DISALLOW_COPY_AND_ASSIGN(CompositorData);
};
// Finishes creation of LayerTreeFrameSink after GPU channel has been
// established.
void CreateLayerTreeFrameSinkForGpuChannel(
base::WeakPtr<ui::Compositor> compositor_weak_ptr,
scoped_refptr<gpu::GpuChannelHost> gpu_channel);
// Creates a ContextProvider for a compositor. Will also create
// |shared_worker_context_provider_| if it doesn't exist.
scoped_refptr<ui::ContextProviderCommandBuffer> CreateContextProvider(
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host);
gpu::GpuChannelEstablishFactory* const gpu_channel_establish_factory_;
scoped_refptr<base::SingleThreadTaskRunner> resize_task_runner_;
base::flat_map<ui::Compositor*, CompositorData> compositor_data_map_;
// TODO(kylechar): Call OnContextLost() on observers when GPU crashes.
base::ObserverList<ui::ContextFactoryObserver> observer_list_;
scoped_refptr<ui::ContextProviderCommandBuffer>
shared_worker_context_provider_;
viz::FrameSinkIdAllocator frame_sink_id_allocator_;
std::unique_ptr<cc::SingleThreadTaskGraphRunner> task_graph_runner_;
const viz::RendererSettings renderer_settings_;
base::WeakPtrFactory<VizProcessTransportFactory> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(VizProcessTransportFactory);
};
} // namespace content
#endif // CONTENT_BROWSER_COMPOSITOR_VIZ_PROCESS_TRANSPORT_FACTORY_H_
......@@ -27,6 +27,7 @@
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/tracing/common/tracing_switches.h"
#include "components/viz/common/switches.h"
#include "content/browser/browser_child_process_host_impl.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/field_trial_recorder.h"
......@@ -80,7 +81,6 @@
#if defined(OS_WIN)
#include "content/common/sandbox_win.h"
#include "sandbox/win/src/sandbox_policy.h"
#include "ui/gfx/switches.h"
#include "ui/gfx/win/rendering_window_manager.h"
#endif
......@@ -130,6 +130,7 @@ static const char* const kSwitchNames[] = {
switches::kEnableHeapProfiling,
switches::kEnableLogging,
switches::kEnableOOPRasterization,
switches::kEnableViz,
#if defined(OS_CHROMEOS)
switches::kDisableVaapiAcceleratedVideoEncode,
#endif
......@@ -739,6 +740,13 @@ void GpuProcessHost::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
gpu_service_ptr_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
}
void GpuProcessHost::ConnectFrameSinkManager(
viz::mojom::FrameSinkManagerRequest request,
viz::mojom::FrameSinkManagerClientPtr client) {
TRACE_EVENT0("gpu", "GpuProcessHost::ConnectFrameSinkManager");
gpu_main_ptr_->CreateFrameSinkManager(std::move(request), std::move(client));
}
void GpuProcessHost::RequestGPUInfo(RequestGPUInfoCallback request_cb) {
if (status_ == SUCCESS || status_ == FAILURE) {
std::move(request_cb).Run(GpuDataManagerImpl::GetInstance()->GetGPUInfo());
......
......@@ -32,6 +32,7 @@
#include "ipc/message_filter.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/ui/gpu/interfaces/gpu_main.mojom.h"
#include "services/viz/privileged/interfaces/compositing/frame_sink_manager.mojom.h"
#include "services/viz/privileged/interfaces/gl/gpu_host.mojom.h"
#include "services/viz/privileged/interfaces/gl/gpu_service.mojom.h"
#include "ui/gfx/geometry/size.h"
......@@ -149,6 +150,12 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
int client_id,
const gpu::SyncToken& sync_token);
// Connects to FrameSinkManager running in the viz process. In this
// configuration the display compositor runs in the viz process and the
// browser must submit CompositorFrames over IPC.
void ConnectFrameSinkManager(viz::mojom::FrameSinkManagerRequest request,
viz::mojom::FrameSinkManagerClientPtr client);
void RequestGPUInfo(RequestGPUInfoCallback request_cb);
void RequestHDRStatus(RequestHDRStatusCallback request_cb);
......
......@@ -9,12 +9,14 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/sequenced_task_runner.h"
#include "base/threading/thread_checker.h"
#include "build/build_config.h"
#include "components/viz/common/switches.h"
#include "content/child/child_process.h"
#include "content/gpu/gpu_service_factory.h"
#include "content/public/common/connection_filter.h"
......@@ -44,11 +46,6 @@
namespace content {
namespace {
bool IsVizEnabled() {
// TODO(crbug.com/770833): Look at the --enable-viz flag instead.
return false;
}
ChildThreadImpl::Options GetOptions() {
ChildThreadImpl::Options::Builder builder;
......@@ -136,7 +133,8 @@ class QueueingConnectionFilter : public ConnectionFilter {
ui::GpuMain::ExternalDependencies CreateGpuMainDependencies() {
ui::GpuMain::ExternalDependencies deps;
deps.create_display_compositor = IsVizEnabled();
deps.create_display_compositor =
base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableViz);
if (GetContentClient()->gpu())
deps.sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager();
auto* process = ChildProcess::current();
......
......@@ -121,6 +121,9 @@ void RecordContextLost(ContextType type,
UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.MusClient", reason,
CONTEXT_LOST_REASON_MAX_ENUM);
break;
case UI_COMPOSITOR_CONTEXT:
UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.UICompositor", reason,
CONTEXT_LOST_REASON_MAX_ENUM);
case CONTEXT_TYPE_UNKNOWN:
UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.Unknown", reason,
CONTEXT_LOST_REASON_MAX_ENUM);
......@@ -155,7 +158,9 @@ std::string ContextTypeToString(ContextType type) {
case MEDIA_CONTEXT:
return "Media";
case MUS_CLIENT_CONTEXT:
return "MusClientContext";
return "MusClient";
case UI_COMPOSITOR_CONTEXT:
return "UICompositor";
default:
NOTREACHED();
return "unknown";
......
......@@ -25,6 +25,7 @@ enum ContextType {
CONTEXT_TYPE_UNKNOWN,
MEDIA_CONTEXT,
MUS_CLIENT_CONTEXT,
UI_COMPOSITOR_CONTEXT,
OFFSCREEN_CONTEXT_FOR_TESTING = CONTEXT_TYPE_UNKNOWN,
};
......
......@@ -96888,6 +96888,8 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
label="A VideoCapture GPU command buffer context"/>
<suffix name="WebGL" label="A WebGL GPU command buffer context"/>
<suffix name="Media" label="The media worker command buffer context"/>
<suffix name="MusClient" label="A mus client command buffer context"/>
<suffix name="UICompositor" label="The UI compositor command buffer context"/>
<suffix name="BlimpRenderCompositor"
label="BlimpCompositor compositor command buffer context">
<obsolete>
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