Commit a40dd448 authored by danakj's avatar danakj Committed by Commit bot
Browse files

Use a cc::Display for layout tests.

This gives a delegating OutputSurface to LayerTreeHost for layout tests,
which delegates to an in-process cc::Display instance. It does so using
the same code we now use for cc pixel tests, which is the
PixelTestDelegatingOutputSurface class.

This makes LayoutTests use the same code paths in the renderer
compositor that we ship to users! Hooray paying down 3-year-old
technical debt. After this, LayerTreeHostImpl will no longer need
to use a DirectRenderer ever (modulo WebView).

I wanted to keep the Display using a separate ContextProvider from cc,
to test texture transport mostly as it exists between the renderer and
the out-of-process Display that we ship to users. So the output surface
must take a ContextProvider from its creator to allow cc pixel tests
to use in-process GL, and layout tests to use out-of-process GL. So
the LayoutTestDependenciesImpl creates a ContextProviderCommandBuffer
for the cc::Display to use, keeping the smallest code footprint
possible inside RenderThreadImpl.

TODO(danakj): Delete GLFrameData, MailboxOutputSurface, mailbox support
in GLRenderer, etc.

R=piman@chromium.org, sievers
BUG=311404

Review-Url: https://codereview.chromium.org/2075343003
Cr-Commit-Position: refs/heads/master@{#402360}
parent 29259299
......@@ -46,18 +46,23 @@ void LayerTreePixelTest::InitializeSettings(LayerTreeSettings* settings) {
std::unique_ptr<OutputSurface> LayerTreePixelTest::CreateOutputSurface() {
scoped_refptr<TestInProcessContextProvider> compositor;
scoped_refptr<TestInProcessContextProvider> worker;
scoped_refptr<TestInProcessContextProvider> display;
if (test_type_ == PIXEL_TEST_GL) {
compositor = new TestInProcessContextProvider(nullptr);
worker = new TestInProcessContextProvider(compositor.get());
display = new TestInProcessContextProvider(nullptr);
}
const bool allow_force_reclaim_resources = !HasImplThread();
const bool synchronous_composite =
!layer_tree_host()->settings().single_thread_proxy_scheduler;
// Always test Webview shenanigans.
const gfx::Size surface_expansion_size(40, 60);
std::unique_ptr<PixelTestDelegatingOutputSurface> delegating_output_surface(
new PixelTestDelegatingOutputSurface(
std::move(compositor), std::move(worker), shared_bitmap_manager(),
gpu_memory_buffer_manager(), allow_force_reclaim_resources,
synchronous_composite));
std::move(compositor), std::move(worker), std::move(display),
RendererSettings(), shared_bitmap_manager(),
gpu_memory_buffer_manager(), surface_expansion_size,
allow_force_reclaim_resources, synchronous_composite));
delegating_output_surface->SetEnlargePassTextureAmount(
enlarge_texture_amount_);
return std::move(delegating_output_surface);
......
......@@ -28,8 +28,11 @@ namespace cc {
PixelTestDelegatingOutputSurface::PixelTestDelegatingOutputSurface(
scoped_refptr<ContextProvider> compositor_context_provider,
scoped_refptr<ContextProvider> worker_context_provider,
scoped_refptr<ContextProvider> display_context_provider,
const RendererSettings& renderer_settings,
SharedBitmapManager* shared_bitmap_manager,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
const gfx::Size& surface_expansion_size,
bool allow_force_reclaim_resources,
bool synchronous_composite)
: OutputSurface(std::move(compositor_context_provider),
......@@ -37,8 +40,11 @@ PixelTestDelegatingOutputSurface::PixelTestDelegatingOutputSurface(
nullptr),
shared_bitmap_manager_(shared_bitmap_manager),
gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
surface_expansion_size_(surface_expansion_size),
allow_force_reclaim_resources_(allow_force_reclaim_resources),
synchronous_composite_(synchronous_composite),
renderer_settings_(renderer_settings),
display_context_provider_(std::move(display_context_provider)),
surface_manager_(new SurfaceManager),
surface_id_allocator_(
new SurfaceIdAllocator(kCompositorSurfaceNamespace)),
......@@ -60,26 +66,21 @@ bool PixelTestDelegatingOutputSurface::BindToClient(
surface_manager_->RegisterSurfaceFactoryClient(
surface_id_allocator_->id_namespace(), this);
// Always test Webview shenanigans.
gfx::Size surface_expansion_size(40, 60);
// The PixelTestOutputSurface is owned by the Display.
std::unique_ptr<PixelTestOutputSurface> output_surface;
if (!context_provider()) {
std::unique_ptr<PixelTestSoftwareOutputDevice> software_output_device(
new PixelTestSoftwareOutputDevice);
software_output_device->set_surface_expansion_size(surface_expansion_size);
software_output_device->set_surface_expansion_size(surface_expansion_size_);
output_surface = base::MakeUnique<PixelTestOutputSurface>(
std::move(software_output_device));
} else {
scoped_refptr<TestInProcessContextProvider> context(
new TestInProcessContextProvider(nullptr));
bool flipped_output_surface = false;
output_surface = base::MakeUnique<PixelTestOutputSurface>(
std::move(context), nullptr, flipped_output_surface);
std::move(display_context_provider_), nullptr, flipped_output_surface);
}
output_surface->set_surface_expansion_size(surface_expansion_size);
output_surface->set_surface_expansion_size(surface_expansion_size_);
auto* task_runner = base::ThreadTaskRunnerHandle::Get().get();
CHECK(task_runner);
......@@ -87,7 +88,7 @@ bool PixelTestDelegatingOutputSurface::BindToClient(
std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source;
std::unique_ptr<DisplayScheduler> scheduler;
if (!synchronous_composite_) {
begin_frame_source.reset(new BackToBackBeginFrameSource(
begin_frame_source.reset(new DelayBasedBeginFrameSource(
base::MakeUnique<DelayBasedTimeSource>(task_runner)));
scheduler.reset(new DisplayScheduler(
begin_frame_source.get(), task_runner,
......@@ -96,7 +97,7 @@ bool PixelTestDelegatingOutputSurface::BindToClient(
display_.reset(new Display(
surface_manager_.get(), shared_bitmap_manager_,
gpu_memory_buffer_manager_, RendererSettings(),
gpu_memory_buffer_manager_, renderer_settings_,
surface_id_allocator_->id_namespace(), std::move(begin_frame_source),
std::move(output_surface), std::move(scheduler),
base::MakeUnique<TextureMailboxDeleter>(task_runner)));
......
......@@ -7,6 +7,7 @@
#include "base/memory/weak_ptr.h"
#include "cc/output/output_surface.h"
#include "cc/output/renderer_settings.h"
#include "cc/scheduler/begin_frame_source.h"
#include "cc/surfaces/display.h"
#include "cc/surfaces/display_client.h"
......@@ -23,8 +24,11 @@ class PixelTestDelegatingOutputSurface : public OutputSurface,
PixelTestDelegatingOutputSurface(
scoped_refptr<ContextProvider> compositor_context_provider,
scoped_refptr<ContextProvider> worker_context_provider,
scoped_refptr<ContextProvider> display_context_provider,
const RendererSettings& renderer_settings,
SharedBitmapManager* shared_bitmap_manager,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
const gfx::Size& surface_expansion_size,
bool allow_force_reclaim_resources,
bool synchronous_composite);
~PixelTestDelegatingOutputSurface() override;
......@@ -56,8 +60,13 @@ class PixelTestDelegatingOutputSurface : public OutputSurface,
SharedBitmapManager* const shared_bitmap_manager_;
gpu::GpuMemoryBufferManager* const gpu_memory_buffer_manager_;
const gfx::Size surface_expansion_size_;
const bool allow_force_reclaim_resources_;
const bool synchronous_composite_;
const RendererSettings renderer_settings_;
// Passed to the Display.
scoped_refptr<ContextProvider> display_context_provider_;
gfx::Size enlarge_pass_texture_amount_;
......
......@@ -115,6 +115,10 @@ ProxyImpl::~ProxyImpl() {
DCHECK(IsImplThread());
DCHECK(IsMainThreadBlocked());
// Take away the OutputSurface before destroying things so it doesn't try
// to call into its client mid-shutdown.
layer_tree_host_impl_->ReleaseOutputSurface();
scheduler_ = nullptr;
external_begin_frame_source_ = nullptr;
unthrottled_begin_frame_source_ = nullptr;
......
......@@ -358,6 +358,10 @@ void SingleThreadProxy::Stop() {
DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
DebugScopedSetImplThread impl(task_runner_provider_);
// Take away the OutputSurface before destroying things so it doesn't try
// to call into its client mid-shutdown.
layer_tree_host_impl_->ReleaseOutputSurface();
BlockingTaskRunner::CapturePostTasks blocked(
task_runner_provider_->blocking_main_thread_task_runner());
scheduler_on_impl_thread_ = nullptr;
......
......@@ -47,7 +47,9 @@ SynchronousCompositorProxy::SynchronousCompositorProxy(
}
SynchronousCompositorProxy::~SynchronousCompositorProxy() {
SetOutputSurface(nullptr);
// The OutputSurface is destroyed/removed by the compositor before shutting
// down everything.
DCHECK_EQ(output_surface_, nullptr);
input_handler_proxy_->SetOnlySynchronouslyAnimateRootFlings(nullptr);
}
......
......@@ -24,8 +24,8 @@
#include "third_party/WebKit/public/platform/WebLayerTreeView.h"
#include "ui/gfx/geometry/rect.h"
namespace ui {
class LatencyInfo;
namespace base {
class CommandLine;
}
namespace cc {
......@@ -33,11 +33,13 @@ class CopyOutputRequest;
class InputHandler;
class Layer;
class LayerTreeHost;
namespace proto {
class CompositorMessage;
}
}
namespace ui {
class LatencyInfo;
}
namespace content {
......@@ -59,6 +61,13 @@ class CONTENT_EXPORT RenderWidgetCompositor
~RenderWidgetCompositor() override;
static cc::LayerTreeSettings GenerateLayerTreeSettings(
const base::CommandLine& cmd,
CompositorDependencies* compositor_deps,
float device_scale_factor);
static cc::ManagedMemoryPolicy GetGpuMemoryPolicy(
const cc::ManagedMemoryPolicy& policy);
void SetNeverVisible();
const base::WeakPtr<cc::InputHandler>& GetInputHandler();
bool BeginMainFrameRequested() const;
......@@ -90,8 +99,6 @@ class CONTENT_EXPORT RenderWidgetCompositor
bool SendMessageToMicroBenchmark(int id, std::unique_ptr<base::Value> value);
void SetSurfaceIdNamespace(uint32_t surface_id_namespace);
void OnHandleCompositorProto(const std::vector<uint8_t>& proto);
cc::ManagedMemoryPolicy GetGpuMemoryPolicy(
const cc::ManagedMemoryPolicy& policy);
void SetPaintedDeviceScaleFactor(float device_scale);
// WebLayerTreeView implementation.
......@@ -207,6 +214,7 @@ class CONTENT_EXPORT RenderWidgetCompositor
int num_failed_recreate_attempts_;
RenderWidgetCompositorDelegate* const delegate_;
CompositorDependencies* const compositor_deps_;
const bool threaded_;
std::unique_ptr<cc::LayerTreeHost> layer_tree_host_;
bool never_visible_;
......
......@@ -15,16 +15,22 @@ class ContextProvider;
class OutputSurface;
}
namespace gpu {
class GpuChannelHost;
}
namespace content {
class CompositorDependencies;
// This class allows injection of LayoutTest-specific behaviour to the
// RenderThreadImpl.
class LayoutTestDependencies {
public:
virtual std::unique_ptr<cc::OutputSurface> CreateOutputSurface(
uint32_t output_surface_id,
scoped_refptr<cc::ContextProvider> context_provider,
scoped_refptr<cc::ContextProvider> worker_context_provider) = 0;
scoped_refptr<gpu::GpuChannelHost> gpu_channel,
scoped_refptr<cc::ContextProvider> compositor_context_provider,
scoped_refptr<cc::ContextProvider> worker_context_provider,
CompositorDependencies* deps) = 0;
};
} // namespace content
......
......@@ -1820,8 +1820,8 @@ RenderThreadImpl::CreateCompositorOutputSurface(
if (vulkan_context_provider) {
DCHECK(!layout_test_mode());
return base::WrapUnique(new CompositorOutputSurface(
routing_id, output_surface_id, vulkan_context_provider,
frame_swap_message_queue));
routing_id, output_surface_id, std::move(vulkan_context_provider),
std::move(frame_swap_message_queue)));
}
}
......@@ -1843,9 +1843,9 @@ RenderThreadImpl::CreateCompositorOutputSurface(
if (use_software) {
DCHECK(!layout_test_mode());
return base::WrapUnique(
new CompositorOutputSurface(routing_id, output_surface_id, nullptr,
nullptr, frame_swap_message_queue));
return base::WrapUnique(new CompositorOutputSurface(
routing_id, output_surface_id, nullptr, nullptr,
std::move(frame_swap_message_queue)));
}
scoped_refptr<ContextProviderCommandBuffer> worker_context_provider =
......@@ -1882,33 +1882,30 @@ RenderThreadImpl::CreateCompositorOutputSurface(
scoped_refptr<ContextProviderCommandBuffer> context_provider(
new ContextProviderCommandBuffer(
std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT,
gpu_channel_host, gpu::GPU_STREAM_DEFAULT,
gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, url,
gl::PreferIntegratedGpu, automatic_flushes, support_locking, limits,
attributes, share_context,
command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT));
// Composite-to-mailbox is currently used for layout tests in order to cause
// them to draw inside in the renderer to do the readback there. This should
// no longer be the case when crbug.com/311404 is fixed.
if (layout_test_deps_) {
return layout_test_deps_->CreateOutputSurface(
output_surface_id, std::move(context_provider),
std::move(worker_context_provider));
std::move(gpu_channel_host), std::move(context_provider),
std::move(worker_context_provider), this);
}
#if defined(OS_ANDROID)
if (sync_compositor_message_filter_) {
return base::WrapUnique(new SynchronousCompositorOutputSurface(
context_provider, worker_context_provider, routing_id,
output_surface_id, sync_compositor_message_filter_.get(),
frame_swap_message_queue));
std::move(context_provider), std::move(worker_context_provider),
routing_id, output_surface_id, sync_compositor_message_filter_.get(),
std::move(frame_swap_message_queue)));
}
#endif
return base::WrapUnique(new CompositorOutputSurface(
routing_id, output_surface_id, std::move(context_provider),
std::move(worker_context_provider), frame_swap_message_queue));
std::move(worker_context_provider), std::move(frame_swap_message_queue)));
}
blink::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter(
......
......@@ -12,6 +12,7 @@
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "cc/test/pixel_test_delegating_output_surface.h"
#include "components/scheduler/test/renderer_scheduler_test_support.h"
#include "components/test_runner/test_common.h"
#include "components/test_runner/web_frame_test_proxy.h"
......@@ -19,10 +20,12 @@
#include "content/browser/bluetooth/bluetooth_adapter_factory_wrapper.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
#include "content/common/site_isolation_policy.h"
#include "content/public/common/page_state.h"
#include "content/public/renderer/renderer_gamepad_provider.h"
#include "content/renderer/fetchers/manifest_fetcher.h"
#include "content/renderer/gpu/render_widget_compositor.h"
#include "content/renderer/history_entry.h"
#include "content/renderer/history_serialization.h"
#include "content/renderer/layout_test_dependencies.h"
......@@ -178,12 +181,43 @@ void SetMockDeviceOrientationData(const WebDeviceOrientationData& data) {
class LayoutTestDependenciesImpl : public LayoutTestDependencies {
public:
std::unique_ptr<cc::OutputSurface> CreateOutputSurface(
uint32_t output_surface_id,
scoped_refptr<cc::ContextProvider> context_provider,
scoped_refptr<cc::ContextProvider> worker_context_provider) override {
return base::MakeUnique<MailboxOutputSurface>(
output_surface_id, std::move(context_provider),
std::move(worker_context_provider));
scoped_refptr<gpu::GpuChannelHost> gpu_channel,
scoped_refptr<cc::ContextProvider> compositor_context_provider,
scoped_refptr<cc::ContextProvider> worker_context_provider,
CompositorDependencies* deps) override {
// This is for an offscreen context for the compositor. So the default
// framebuffer doesn't need alpha, depth, stencil, antialiasing.
gpu::gles2::ContextCreationAttribHelper attributes;
attributes.alpha_size = -1;
attributes.depth_size = 0;
attributes.stencil_size = 0;
attributes.samples = 0;
attributes.sample_buffers = 0;
attributes.bind_generates_resource = false;
attributes.lose_context_when_out_of_memory = true;
const bool automatic_flushes = false;
const bool support_locking = false;
scoped_refptr<cc::ContextProvider> display_context_provider(
new ContextProviderCommandBuffer(
std::move(gpu_channel), gpu::GPU_STREAM_DEFAULT,
gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle,
GURL(
"chrome://gpu/LayoutTestDependenciesImpl::CreateOutputSurface"),
gl::PreferIntegratedGpu, automatic_flushes, support_locking,
gpu::SharedMemoryLimits(), attributes, nullptr,
command_buffer_metrics::OFFSCREEN_CONTEXT_FOR_TESTING));
cc::LayerTreeSettings settings =
RenderWidgetCompositor::GenerateLayerTreeSettings(
*base::CommandLine::ForCurrentProcess(), deps, 1.f);
return base::MakeUnique<cc::PixelTestDelegatingOutputSurface>(
std::move(compositor_context_provider),
std::move(worker_context_provider), std::move(display_context_provider),
settings.renderer_settings, deps->GetSharedBitmapManager(),
deps->GetGpuMemoryBufferManager(), gfx::Size(), false,
!deps->GetCompositorImplThreadTaskRunner());
}
};
......
......@@ -111,6 +111,12 @@ fast/canvas/canvas-lost-gpu-context.html [ WontFix ]
virtual/threaded/printing/setPrinting.html [ WontFix ]
virtual/threaded/printing/width-overflow.html [ WontFix ]
# These tests are flaky/fail when threaded and add little value (they're just
# reading back Blink's current animation value).
virtual/threaded/animations/transition-and-animation-1.html [ WontFix ]
virtual/threaded/animations/transition-and-animation-2.html [ WontFix ]
virtual/threaded/transitions/transition-end-event-multiple-04.html [ WontFix ]
# This test only fails with an ASSERT in Debug build.
[ Release ] editing/input/orphan-set-selection-range.html [ WontFix ]
......
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