Commit b9985819 authored by danakj's avatar danakj Committed by Commit Bot

Remove use of WebLayerTreeViewImplForTesting in platform tests.

Migrate the LayerTreeHostForPaintArtifactTest to platform/testing/
as LayerTreeHostEmbedder, and use it in platform/graphics/ tests
that want to construct a cc::LayerTreeHost but currently do so through
WebLayerTreeViewImplForTesting.

Also construct and use a cc::AnimationHost directly in the
platform/animation/ tests instead of a WebLayerTreeViewImplForTesting.

As the last user of it, we also remove the WebLayerTreeViewImplForTesting
class, bringing us closer to being able to remove the WebLayerTreeView
interface.

R=chrishtr@chromium.org

Bug: 838693
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ia92b0d6227575d1c8733a336c80e4a3aebb75001
Reviewed-on: https://chromium-review.googlesource.com/1117610Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571284}
parent 4c2ee1dc
......@@ -2041,8 +2041,6 @@ jumbo_source_set("unit_tests") {
"paint/first_meaningful_paint_detector_test.cc",
"paint/fragment_data_test.cc",
"paint/html_canvas_painter_test.cc",
"paint/layer_tree_host_for_paint_artifact_test.cc",
"paint/layer_tree_host_for_paint_artifact_test.h",
"paint/link_highlight_impl_test.cc",
"paint/ng/ng_paint_fragment_test.cc",
"paint/ng/ng_paint_fragment_traversal_test.cc",
......
......@@ -6,10 +6,10 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_PAINT_AND_RASTER_INVALIDATION_TEST_H_
#include "cc/layers/picture_layer.h"
#include "third_party/blink/renderer/core/paint/layer_tree_host_for_paint_artifact_test.h"
#include "third_party/blink/renderer/core/paint/paint_controller_paint_test.h"
#include "third_party/blink/renderer/platform/graphics/compositing/content_layer_client_impl.h"
#include "third_party/blink/renderer/platform/graphics/compositing/paint_artifact_compositor.h"
#include "third_party/blink/renderer/platform/testing/layer_tree_host_embedder.h"
namespace blink {
......@@ -51,7 +51,7 @@ class PaintAndRasterInvalidationTest : public PaintControllerPaintTest {
PaintControllerPaintTest::SetUp();
if (RuntimeEnabledFeatures::SlimmingPaintV2Enabled()) {
layer_tree_ = std::make_unique<LayerTreeHostForPaintArtifactTest>();
layer_tree_ = std::make_unique<LayerTreeHostEmbedder>();
layer_tree_->layer_tree_host()->SetRootLayer(
GetDocument()
.View()
......@@ -65,7 +65,7 @@ class PaintAndRasterInvalidationTest : public PaintControllerPaintTest {
}
private:
std::unique_ptr<LayerTreeHostForPaintArtifactTest> layer_tree_;
std::unique_ptr<LayerTreeHostEmbedder> layer_tree_;
};
} // namespace blink
......
......@@ -6,8 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_STUB_CHROME_CLIENT_FOR_SPV2_H_
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/paint/layer_tree_host_for_paint_artifact_test.h"
#include "third_party/blink/renderer/platform/testing/web_layer_tree_view_impl_for_testing.h"
#include "third_party/blink/renderer/platform/testing/layer_tree_host_embedder.h"
namespace cc {
class Layer;
......@@ -30,7 +29,7 @@ class StubChromeClientForSPv2 : public EmptyChromeClient {
}
private:
LayerTreeHostForPaintArtifactTest layer_tree_;
LayerTreeHostEmbedder layer_tree_;
};
} // namespace blink
......
......@@ -1640,6 +1640,8 @@ jumbo_static_library("test_support") {
"testing/fuzzed_data_provider.h",
"testing/histogram_tester.cc",
"testing/histogram_tester.h",
"testing/layer_tree_host_embedder.cc",
"testing/layer_tree_host_embedder.h",
"testing/message_loop_for_mojo.h",
"testing/mock_web_crypto.cc",
"testing/mock_web_crypto.h",
......@@ -1664,8 +1666,6 @@ jumbo_static_library("test_support") {
"testing/url_test_helpers.cc",
"testing/url_test_helpers.h",
"testing/use_mock_scrollbar_settings.h",
"testing/web_layer_tree_view_impl_for_testing.cc",
"testing/web_layer_tree_view_impl_for_testing.h",
"testing/weburl_loader_mock.cc",
"testing/weburl_loader_mock.h",
"testing/weburl_loader_mock_factory_impl.cc",
......
......@@ -5,10 +5,11 @@
#include "third_party/blink/renderer/platform/animation/compositor_animation_host.h"
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "cc/animation/animation_host.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_timeline.h"
#include "third_party/blink/renderer/platform/testing/compositor_test.h"
#include "third_party/blink/renderer/platform/testing/web_layer_tree_view_impl_for_testing.h"
namespace blink {
......@@ -22,9 +23,9 @@ TEST_F(CompositorAnimationHostTest, AnimationHostNullWhenTimelineDetached) {
timeline->GetAnimationTimeline();
EXPECT_FALSE(cc_timeline->animation_host());
WebLayerTreeViewImplForTesting layer_tree_view;
CompositorAnimationHost compositor_animation_host(
layer_tree_view.CompositorAnimationHost());
std::unique_ptr<cc::AnimationHost> animation_host =
cc::AnimationHost::CreateMainInstance();
CompositorAnimationHost compositor_animation_host(animation_host.get());
compositor_animation_host.AddTimeline(*timeline);
EXPECT_TRUE(cc_timeline->animation_host());
......
......@@ -5,12 +5,12 @@
#include "third_party/blink/renderer/platform/animation/compositor_animation_timeline.h"
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "cc/animation/animation_host.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_host.h"
#include "third_party/blink/renderer/platform/testing/compositor_test.h"
#include "third_party/blink/renderer/platform/testing/web_layer_tree_view_impl_for_testing.h"
namespace blink {
......@@ -25,19 +25,18 @@ TEST_F(CompositorAnimationTimelineTest,
timeline->GetAnimationTimeline();
EXPECT_FALSE(cc_timeline->animation_host());
WebLayerTreeViewImplForTesting layer_tree_view;
CompositorAnimationHost compositor_animation_host(
layer_tree_view.CompositorAnimationHost());
std::unique_ptr<cc::AnimationHost> animation_host =
cc::AnimationHost::CreateMainInstance();
CompositorAnimationHost compositor_animation_host(animation_host.get());
compositor_animation_host.AddTimeline(*timeline);
cc::AnimationHost* animation_host = cc_timeline->animation_host();
EXPECT_TRUE(animation_host);
EXPECT_EQ(cc_timeline->animation_host(), animation_host.get());
EXPECT_TRUE(animation_host->GetTimelineById(cc_timeline->id()));
// Delete CompositorAnimationTimeline while attached to host.
timeline = nullptr;
EXPECT_FALSE(cc_timeline->animation_host());
EXPECT_EQ(cc_timeline->animation_host(), nullptr);
EXPECT_FALSE(animation_host->GetTimelineById(cc_timeline->id()));
}
......
......@@ -6,11 +6,13 @@
#include <memory>
#include "base/memory/ptr_util.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "cc/layers/layer.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_frame_sink.h"
#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/trees/clip_node.h"
......@@ -25,11 +27,11 @@
#include "third_party/blink/renderer/platform/graphics/paint/paint_artifact.h"
#include "third_party/blink/renderer/platform/graphics/paint/scroll_paint_property_node.h"
#include "third_party/blink/renderer/platform/testing/fake_display_item_client.h"
#include "third_party/blink/renderer/platform/testing/layer_tree_host_embedder.h"
#include "third_party/blink/renderer/platform/testing/paint_property_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/picture_matchers.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/test_paint_artifact.h"
#include "third_party/blink/renderer/platform/testing/web_layer_tree_view_impl_for_testing.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
......@@ -51,19 +53,6 @@ gfx::Transform Translation(SkMScalar x, SkMScalar y) {
return transform;
}
class WebLayerTreeViewWithLayerTreeFrameSink
: public WebLayerTreeViewImplForTesting {
public:
WebLayerTreeViewWithLayerTreeFrameSink(const cc::LayerTreeSettings& settings)
: WebLayerTreeViewImplForTesting(settings) {}
// cc::LayerTreeHostClient
void RequestNewLayerTreeFrameSink() override {
GetLayerTreeHost()->SetLayerTreeFrameSink(
cc::FakeLayerTreeFrameSink::Create3d());
}
};
class FakeScrollClient {
public:
FakeScrollClient() : did_scroll_count(0) {}
......@@ -82,7 +71,7 @@ class PaintArtifactCompositorTest : public testing::Test,
protected:
PaintArtifactCompositorTest()
: ScopedSlimmingPaintV2ForTest(true),
task_runner_(new base::TestSimpleTaskRunner),
task_runner_(base::MakeRefCounted<base::TestSimpleTaskRunner>()),
task_runner_handle_(task_runner_) {}
void SetUp() override {
......@@ -92,13 +81,15 @@ class PaintArtifactCompositorTest : public testing::Test,
&FakeScrollClient::DidScroll, WTF::Unretained(&scroll_client_)));
paint_artifact_compositor_->EnableExtraDataForTesting();
cc::LayerTreeSettings settings =
WebLayerTreeViewImplForTesting::DefaultLayerTreeSettings();
settings.single_thread_proxy_scheduler = false;
settings.use_layer_lists = true;
web_layer_tree_view_ =
std::make_unique<WebLayerTreeViewWithLayerTreeFrameSink>(settings);
web_layer_tree_view_->SetRootLayer(paint_artifact_compositor_->RootLayer());
// Uses a LayerTreeHostClient that will make a LayerTreeFrameSink to allow
// the compositor to run and submit frames.
layer_tree_ = std::make_unique<LayerTreeHostEmbedder>(
&layer_tree_host_client_,
/*single_thread_client=*/nullptr,
/*use_layer_lists=*/true);
layer_tree_host_client_.SetLayerTreeHost(layer_tree_->layer_tree_host());
layer_tree_->layer_tree_host()->SetRootLayer(
paint_artifact_compositor_->RootLayer());
}
void TearDown() override {
......@@ -108,34 +99,31 @@ class PaintArtifactCompositorTest : public testing::Test,
}
cc::PropertyTrees& GetPropertyTrees() {
return *web_layer_tree_view_->GetLayerTreeHost()->property_trees();
return *layer_tree_->layer_tree_host()->property_trees();
}
const cc::TransformNode& GetTransformNode(const cc::Layer* layer) {
auto* property_trees = layer_tree_->layer_tree_host()->property_trees();
return *property_trees->transform_tree.Node(layer->transform_tree_index());
}
const cc::LayerTreeHost& GetLayerTreeHost() {
return *web_layer_tree_view_->GetLayerTreeHost();
return *layer_tree_->layer_tree_host();
}
int ElementIdToEffectNodeIndex(CompositorElementId element_id) {
return web_layer_tree_view_->GetLayerTreeHost()
->property_trees()
->element_id_to_effect_node_index[element_id];
auto* property_trees = layer_tree_->layer_tree_host()->property_trees();
return property_trees->element_id_to_effect_node_index[element_id];
}
int ElementIdToTransformNodeIndex(CompositorElementId element_id) {
return web_layer_tree_view_->GetLayerTreeHost()
->property_trees()
->element_id_to_transform_node_index[element_id];
auto* property_trees = layer_tree_->layer_tree_host()->property_trees();
return property_trees->element_id_to_transform_node_index[element_id];
}
int ElementIdToScrollNodeIndex(CompositorElementId element_id) {
return web_layer_tree_view_->GetLayerTreeHost()
->property_trees()
->element_id_to_scroll_node_index[element_id];
}
const cc::TransformNode& GetTransformNode(const cc::Layer* layer) {
return *GetPropertyTrees().transform_tree.Node(
layer->transform_tree_index());
auto* property_trees = layer_tree_->layer_tree_host()->property_trees();
return property_trees->element_id_to_scroll_node_index[element_id];
}
void Update(const PaintArtifact& artifact) {
......@@ -155,7 +143,7 @@ class PaintArtifactCompositorTest : public testing::Test,
TransformPaintPropertyNode* viewport_scale_transform_node) {
paint_artifact_compositor_->Update(artifact, element_ids,
viewport_scale_transform_node);
web_layer_tree_view_->GetLayerTreeHost()->LayoutAndUpdateLayers();
layer_tree_->layer_tree_host()->LayoutAndUpdateLayers();
}
void WillBeRemovedFromFrame() {
......@@ -238,7 +226,8 @@ class PaintArtifactCompositorTest : public testing::Test,
std::unique_ptr<PaintArtifactCompositor> paint_artifact_compositor_;
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
base::ThreadTaskRunnerHandle task_runner_handle_;
std::unique_ptr<WebLayerTreeViewWithLayerTreeFrameSink> web_layer_tree_view_;
cc::FakeLayerTreeHostClient layer_tree_host_client_;
std::unique_ptr<LayerTreeHostEmbedder> layer_tree_;
};
const auto kNotScrollingOnMain = MainThreadScrollingReason::kNotScrollingOnMain;
......
......@@ -33,7 +33,6 @@
#include "cc/trees/mutator_host.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_layer_tree_view.h"
#include "third_party/blink/public/platform/web_thread.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_client.h"
......@@ -51,9 +50,9 @@
#include "third_party/blink/renderer/platform/scroll/scrollable_area.h"
#include "third_party/blink/renderer/platform/testing/fake_graphics_layer.h"
#include "third_party/blink/renderer/platform/testing/fake_graphics_layer_client.h"
#include "third_party/blink/renderer/platform/testing/layer_tree_host_embedder.h"
#include "third_party/blink/renderer/platform/testing/paint_property_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/paint_test_configurations.h"
#include "third_party/blink/renderer/platform/testing/web_layer_tree_view_impl_for_testing.h"
#include "third_party/blink/renderer/platform/transforms/matrix_3d_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/rotate_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/translate_transform_operation.h"
......@@ -73,27 +72,27 @@ class GraphicsLayerTest : public testing::Test, public PaintTestConfigurations {
page_scale_layer_->AddChild(graphics_layer_.get());
graphics_layer_->CcLayer()->SetScrollable(clip_layer_->CcLayer()->bounds());
cc_layer_ = graphics_layer_->CcLayer();
layer_tree_view_ = std::make_unique<WebLayerTreeViewImplForTesting>();
DCHECK(layer_tree_view_);
layer_tree_view_->SetRootLayer(clip_layer_->CcLayer());
WebLayerTreeView::ViewportLayers viewport_layers;
layer_tree_ = std::make_unique<LayerTreeHostEmbedder>();
layer_tree_->layer_tree_host()->SetRootLayer(clip_layer_->CcLayer());
cc::LayerTreeHost::ViewportLayers viewport_layers;
viewport_layers.overscroll_elasticity = scroll_elasticity_layer_->CcLayer();
viewport_layers.page_scale = page_scale_layer_->CcLayer();
viewport_layers.inner_viewport_container = clip_layer_->CcLayer();
viewport_layers.inner_viewport_scroll = graphics_layer_->CcLayer();
layer_tree_view_->RegisterViewportLayers(viewport_layers);
layer_tree_view_->SetViewportSize(WebSize(1, 1));
layer_tree_->layer_tree_host()->RegisterViewportLayers(viewport_layers);
layer_tree_->layer_tree_host()->SetViewportSizeAndScale(
gfx::Size(1, 1), /*device_scale_factor=*/1.f, viz::LocalSurfaceId());
graphics_layer_->SetLayerState(
PropertyTreeState(PropertyTreeState::Root()), IntPoint());
graphics_layer_->SetLayerState(PropertyTreeState(PropertyTreeState::Root()),
IntPoint());
}
~GraphicsLayerTest() override {
graphics_layer_.reset();
layer_tree_view_.reset();
}
~GraphicsLayerTest() = default;
WebLayerTreeView* LayerTreeView() { return layer_tree_view_.get(); }
cc::LayerTreeHost* layer_tree_host() {
return layer_tree_->layer_tree_host();
}
cc::AnimationHost* animation_host() { return layer_tree_->animation_host(); }
protected:
bool PaintWithoutCommit(GraphicsLayer& layer, const IntRect* interest_rect) {
......@@ -114,10 +113,6 @@ class GraphicsLayerTest : public testing::Test, public PaintTestConfigurations {
return layer.paint_controller_.get();
}
cc::LayerTreeHost* layer_tree_host() {
return layer_tree_view_->GetLayerTreeHost();
}
cc::Layer* cc_layer_;
std::unique_ptr<FakeGraphicsLayer> graphics_layer_;
std::unique_ptr<FakeGraphicsLayer> page_scale_layer_;
......@@ -126,7 +121,7 @@ class GraphicsLayerTest : public testing::Test, public PaintTestConfigurations {
FakeGraphicsLayerClient client_;
private:
std::unique_ptr<WebLayerTreeViewImplForTesting> layer_tree_view_;
std::unique_ptr<LayerTreeHostEmbedder> layer_tree_;
};
INSTANTIATE_TEST_CASE_P(All,
......@@ -173,7 +168,7 @@ TEST_P(GraphicsLayerTest, updateLayerShouldFlattenTransformWithAnimations) {
CompositorAnimationTimeline::Create();
AnimationForTesting animation;
CompositorAnimationHost host(LayerTreeView()->CompositorAnimationHost());
CompositorAnimationHost host(animation_host());
host.AddTimeline(*compositor_timeline);
compositor_timeline->AnimationAttached(animation);
......
......@@ -21,8 +21,8 @@ class CompositorTest : public testing::Test {
~CompositorTest() override;
protected:
// Mock task runner is initialized here because tests create
// WebLayerTreeViewImplForTesting which needs the current task runner handle.
// cc::LayerTreeHost requires a task runner, so we use a mock task runner
// and bind it as the current ThreadTaskRunnerHandle for this thread.
scoped_refptr<base::TestMockTimeTaskRunner> runner_;
base::ThreadTaskRunnerHandle runner_handle_;
};
......
......@@ -2,28 +2,38 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/paint/layer_tree_host_for_paint_artifact_test.h"
#include "third_party/blink/renderer/platform/testing/layer_tree_host_embedder.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_thread.h"
#include "base/threading/thread_task_runner_handle.h"
namespace blink {
LayerTreeHostForPaintArtifactTest::LayerTreeHostForPaintArtifactTest() {
LayerTreeHostEmbedder::LayerTreeHostEmbedder()
: LayerTreeHostEmbedder(/*client=*/nullptr,
/*single_thread_client=*/nullptr,
/*use_layer_lists=*/false) {}
LayerTreeHostEmbedder::LayerTreeHostEmbedder(
cc::LayerTreeHostClient* client,
cc::LayerTreeHostSingleThreadClient* single_thread_client,
bool use_layer_lists) {
cc::LayerTreeSettings settings;
settings.layer_transforms_should_scale_layer_contents = true;
settings.single_thread_proxy_scheduler = false;
settings.use_layer_lists = use_layer_lists;
animation_host_ = cc::AnimationHost::CreateMainInstance();
cc::LayerTreeHost::InitParams params;
params.client = &layer_tree_host_client_;
params.client = client ? client : &layer_tree_host_client_;
params.settings = &settings;
params.main_task_runner =
Platform::Current()->CurrentThread()->GetTaskRunner();
params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
params.task_graph_runner = &task_graph_runner_;
params.mutator_host = animation_host_.get();
layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(
&layer_tree_host_single_thread_client_, &params);
single_thread_client ? single_thread_client
: &layer_tree_host_single_thread_client_,
&params);
}
} // namespace blink
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_LAYER_TREE_HOST_FOR_PAINT_ARTIFACT_TEST_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_LAYER_TREE_HOST_FOR_PAINT_ARTIFACT_TEST_H_
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_LAYER_TREE_HOST_EMBEDDER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_LAYER_TREE_HOST_EMBEDDER_H_
#include "cc/animation/animation_host.h"
#include "cc/test/stub_layer_tree_host_client.h"
......@@ -14,11 +14,23 @@
namespace blink {
class LayerTreeHostForPaintArtifactTest {
// A class that owns the lifetime of a cc::LayerTreeHost and its dependencies
// for unit tests that need to instantiate only a cc::LayerTreeHost and not the
// full blink APIs that normally own and embed it.
class LayerTreeHostEmbedder {
public:
LayerTreeHostForPaintArtifactTest();
// Default constructor uses stub clients, and default LayerTreeSettings
// appropriate for blink unit tests.
LayerTreeHostEmbedder();
// Constructor to specify the clients, or null to use stubs. Also specify
// overrides of LayerTreeSettings.
LayerTreeHostEmbedder(
cc::LayerTreeHostClient* client,
cc::LayerTreeHostSingleThreadClient* single_thread_client,
bool use_layer_lists);
cc::LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); }
cc::AnimationHost* animation_host() { return animation_host_.get(); }
private:
cc::StubLayerTreeHostSingleThreadClient layer_tree_host_single_thread_client_;
......@@ -30,4 +42,4 @@ class LayerTreeHostForPaintArtifactTest {
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_LAYER_TREE_HOST_FOR_PAINT_ARTIFACT_TEST_H_
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_LAYER_TREE_HOST_EMBEDDER_H_
// Copyright 2013 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 "third_party/blink/renderer/platform/testing/web_layer_tree_view_impl_for_testing.h"
#include "base/threading/thread_task_runner_handle.h"
#include "cc/animation/animation_host.h"
#include "cc/animation/animation_timeline.h"
#include "cc/layers/layer.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_settings.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_layer_tree_view.h"
#include "third_party/blink/public/platform/web_size.h"
namespace blink {
WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting()
: WebLayerTreeViewImplForTesting(DefaultLayerTreeSettings()) {}
WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting(
const cc::LayerTreeSettings& settings) {
animation_host_ = cc::AnimationHost::CreateMainInstance();
cc::LayerTreeHost::InitParams params;
params.client = this;
params.settings = &settings;
params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
params.task_graph_runner = &task_graph_runner_;
params.mutator_host = animation_host_.get();
layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params);
DCHECK(layer_tree_host_);
}
WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() = default;
// static
cc::LayerTreeSettings
WebLayerTreeViewImplForTesting::DefaultLayerTreeSettings() {
cc::LayerTreeSettings settings;
// For web contents, layer transforms should scale up the contents of layers
// to keep content always crisp when possible.
settings.layer_transforms_should_scale_layer_contents = true;
return settings;
}
bool WebLayerTreeViewImplForTesting::HasLayer(const cc::Layer& layer) {
return layer.layer_tree_host() == layer_tree_host_.get();
}
void WebLayerTreeViewImplForTesting::SetViewportSize(
const WebSize& device_viewport_size) {
gfx::Size gfx_size(std::max(0, device_viewport_size.width),
std::max(0, device_viewport_size.height));
// TODO(ccameron): This likely causes surface invariant violations.
layer_tree_host_->SetViewportSizeAndScale(
gfx_size, layer_tree_host_->device_scale_factor(),
layer_tree_host_->local_surface_id_from_parent());
}
void WebLayerTreeViewImplForTesting::SetRootLayer(
scoped_refptr<cc::Layer> root) {
layer_tree_host_->SetRootLayer(root);
}
void WebLayerTreeViewImplForTesting::ClearRootLayer() {
layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>());
}
cc::AnimationHost* WebLayerTreeViewImplForTesting::CompositorAnimationHost() {
return animation_host_.get();
}
WebSize WebLayerTreeViewImplForTesting::GetViewportSize() const {
return WebSize(layer_tree_host_->device_viewport_size().width(),
layer_tree_host_->device_viewport_size().height());
}
void WebLayerTreeViewImplForTesting::SetBackgroundColor(SkColor color) {
layer_tree_host_->set_background_color(color);
}
void WebLayerTreeViewImplForTesting::SetVisible(bool visible) {
layer_tree_host_->SetVisible(visible);
}
void WebLayerTreeViewImplForTesting::SetPageScaleFactorAndLimits(
float page_scale_factor,
float minimum,
float maximum) {
layer_tree_host_->SetPageScaleFactorAndLimits(page_scale_factor, minimum,
maximum);
}
void WebLayerTreeViewImplForTesting::StartPageScaleAnimation(
const blink::WebPoint& scroll,
bool use_anchor,
float new_page_scale,
double duration_sec) {}
void WebLayerTreeViewImplForTesting::SetNeedsBeginFrame() {
layer_tree_host_->SetNeedsAnimate();
}
void WebLayerTreeViewImplForTesting::DidStopFlinging() {}
void WebLayerTreeViewImplForTesting::SetDeferCommits(bool defer_commits) {
layer_tree_host_->SetDeferCommits(defer_commits);
}
void WebLayerTreeViewImplForTesting::UpdateLayerTreeHost(
VisualStateUpdate requested_update) {}
void WebLayerTreeViewImplForTesting::ApplyViewportDeltas(
const gfx::Vector2dF& inner_delta,
const gfx::Vector2dF& outer_delta,
const gfx::Vector2dF& elastic_overscroll_delta,
float page_scale,
float browser_controls_delta) {}
void WebLayerTreeViewImplForTesting::RecordWheelAndTouchScrollingCount(
bool has_scrolled_by_wheel,
bool has_scrolled_by_touch) {}
void WebLayerTreeViewImplForTesting::RequestNewLayerTreeFrameSink() {
// Intentionally do not create and set a LayerTreeFrameSink.
}
void WebLayerTreeViewImplForTesting::DidFailToInitializeLayerTreeFrameSink() {
NOTREACHED();
}
void WebLayerTreeViewImplForTesting::RegisterViewportLayers(
const WebLayerTreeView::ViewportLayers& layers) {
cc::LayerTreeHost::ViewportLayers viewport_layers;
if (layers.overscroll_elasticity) {
viewport_layers.overscroll_elasticity = layers.overscroll_elasticity;
}
viewport_layers.page_scale = layers.page_scale;
if (layers.inner_viewport_container) {
viewport_layers.inner_viewport_container = layers.inner_viewport_container;
}
if (layers.outer_viewport_container) {
viewport_layers.outer_viewport_container = layers.outer_viewport_container;
}
viewport_layers.inner_viewport_scroll = layers.inner_viewport_scroll;
if (layers.outer_viewport_scroll) {
viewport_layers.outer_viewport_scroll = layers.outer_viewport_scroll;
}
layer_tree_host_->RegisterViewportLayers(viewport_layers);
}
void WebLayerTreeViewImplForTesting::ClearViewportLayers() {
layer_tree_host_->RegisterViewportLayers(cc::LayerTreeHost::ViewportLayers());
}
void WebLayerTreeViewImplForTesting::RegisterSelection(
const blink::WebSelection& selection) {}
void WebLayerTreeViewImplForTesting::ClearSelection() {}
void WebLayerTreeViewImplForTesting::SetEventListenerProperties(
blink::WebEventListenerClass event_class,
blink::WebEventListenerProperties properties) {
// Equality of static_cast is checked in render_widget_compositor.cc.
layer_tree_host_->SetEventListenerProperties(
static_cast<cc::EventListenerClass>(event_class),
static_cast<cc::EventListenerProperties>(properties));
}
blink::WebEventListenerProperties
WebLayerTreeViewImplForTesting::EventListenerProperties(
blink::WebEventListenerClass event_class) const {
// Equality of static_cast is checked in render_widget_compositor.cc.
return static_cast<blink::WebEventListenerProperties>(
layer_tree_host_->event_listener_properties(
static_cast<cc::EventListenerClass>(event_class)));
}
void WebLayerTreeViewImplForTesting::SetHaveScrollEventHandlers(
bool have_eent_handlers) {
layer_tree_host_->SetHaveScrollEventHandlers(have_eent_handlers);
}
bool WebLayerTreeViewImplForTesting::HaveScrollEventHandlers() const {
return layer_tree_host_->have_scroll_event_handlers();
}
} // namespace blink
// Copyright 2013 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_WEB_LAYER_TREE_VIEW_IMPL_FOR_TESTING_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_WEB_LAYER_TREE_VIEW_IMPL_FOR_TESTING_H_
#include <memory>
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_host_client.h"
#include "cc/trees/layer_tree_host_single_thread_client.h"
#include "third_party/blink/public/platform/web_layer_tree_view.h"
#include "third_party/blink/renderer/platform/wtf/noncopyable.h"
namespace cc {
class AnimationHost;
class Layer;
class LayerTreeHost;
class LayerTreeSettings;
}
namespace blink {
// Dummy WeblayerTeeView that does not support any actual compositing.
class WebLayerTreeViewImplForTesting
: public blink::WebLayerTreeView,
public cc::LayerTreeHostClient,
public cc::LayerTreeHostSingleThreadClient {
WTF_MAKE_NONCOPYABLE(WebLayerTreeViewImplForTesting);
public:
WebLayerTreeViewImplForTesting();
explicit WebLayerTreeViewImplForTesting(const cc::LayerTreeSettings&);
~WebLayerTreeViewImplForTesting() override;
static cc::LayerTreeSettings DefaultLayerTreeSettings();
cc::LayerTreeHost* GetLayerTreeHost() { return layer_tree_host_.get(); }
bool HasLayer(const cc::Layer&);
void SetViewportSize(const blink::WebSize&);
// blink::WebLayerTreeView implementation.
void SetRootLayer(scoped_refptr<cc::Layer>) override;
void ClearRootLayer() override;
cc::AnimationHost* CompositorAnimationHost() override;
WebSize GetViewportSize() const override;
void SetBackgroundColor(SkColor) override;
void SetVisible(bool) override;
void SetPageScaleFactorAndLimits(float page_scale_factor,
float minimum,
float maximum) override;
void StartPageScaleAnimation(const blink::WebPoint& destination,
bool use_anchor,
float new_page_scale,
double duration_sec) override;
void SetNeedsBeginFrame() override;
void DidStopFlinging() override;
void SetDeferCommits(bool) override;
void RegisterViewportLayers(const WebLayerTreeView::ViewportLayers&) override;
void ClearViewportLayers() override;
void RegisterSelection(const blink::WebSelection&) override;
void ClearSelection() override;
void SetEventListenerProperties(blink::WebEventListenerClass event_class,
blink::WebEventListenerProperties) override;
blink::WebEventListenerProperties EventListenerProperties(
blink::WebEventListenerClass event_class) const override;
void SetHaveScrollEventHandlers(bool) override;
bool HaveScrollEventHandlers() const override;
// cc::LayerTreeHostClient implementation.
void WillBeginMainFrame() override {}
void DidBeginMainFrame() override {}
void BeginMainFrame(const viz::BeginFrameArgs& args) override {}
void BeginMainFrameNotExpectedSoon() override {}
void BeginMainFrameNotExpectedUntil(base::TimeTicks) override {}
void UpdateLayerTreeHost(VisualStateUpdate requested_update) override;
void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
const gfx::Vector2dF& outer_delta,
const gfx::Vector2dF& elastic_overscroll_delta,
float page_scale,
float browser_controls_delta) override;
void RecordWheelAndTouchScrollingCount(bool has_scrolled_by_wheel,
bool has_scrolled_by_touch) override;
void RequestNewLayerTreeFrameSink() override;
void DidInitializeLayerTreeFrameSink() override {}
void DidFailToInitializeLayerTreeFrameSink() override;
void WillCommit() override {}
void DidCommit() override {}
void DidCommitAndDrawFrame() override {}
void DidReceiveCompositorFrameAck() override {}
void DidCompletePageScaleAnimation() override {}
void DidPresentCompositorFrame(
uint32_t frame_token,
const gfx::PresentationFeedback& feedback) override {}
// cc::LayerTreeHostSingleThreadClient implementation.
void DidSubmitCompositorFrame() override {}
void DidLoseLayerTreeFrameSink() override {}
private:
cc::TestTaskGraphRunner task_graph_runner_;
std::unique_ptr<cc::AnimationHost> animation_host_;
std::unique_ptr<cc::LayerTreeHost> layer_tree_host_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_WEB_LAYER_TREE_VIEW_IMPL_FOR_TESTING_H_
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