Commit 83186398 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

Remove platform/graphics -> platform/animation dependency

The dependency was test-only. Extracted ViewportLayersSetup
helper class to platform/testing to be reused both in animation
and graphics.

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Icf6b0578ceb99c1f7630e6ef5db1f0c6082cb13a
Reviewed-on: https://chromium-review.googlesource.com/1155750
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579518}
parent 20bf1c3f
......@@ -1655,6 +1655,8 @@ jumbo_static_library("test_support") {
"testing/url_test_helpers.cc",
"testing/url_test_helpers.h",
"testing/use_mock_scrollbar_settings.h",
"testing/viewport_layers_setup.cc",
"testing/viewport_layers_setup.h",
"testing/weburl_loader_mock.cc",
"testing/weburl_loader_mock.h",
"testing/weburl_loader_mock_factory_impl.cc",
......@@ -2209,6 +2211,7 @@ jumbo_source_set("unit_tests") {
visibility = []
visibility = [ "//third_party/blink/renderer/*" ]
sources = [
"animation/animated_layers_test.cc",
"graphics/canvas_2d_layer_bridge_test.cc",
"graphics/canvas_color_params_test.cc",
"graphics/canvas_resource_test.cc",
......
// 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.
#include <memory>
#include "cc/layers/picture_layer.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/mutator_host.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_client.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_host.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_timeline.h"
#include "third_party/blink/renderer/platform/animation/compositor_float_animation_curve.h"
#include "third_party/blink/renderer/platform/animation/compositor_keyframe_model.h"
#include "third_party/blink/renderer/platform/animation/compositor_target_property.h"
#include "third_party/blink/renderer/platform/graphics/compositor_element_id.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/paint_test_configurations.h"
#include "third_party/blink/renderer/platform/testing/viewport_layers_setup.h"
namespace blink {
class AnimatedLayersTest : public testing::Test,
public PaintTestConfigurations {
public:
AnimatedLayersTest() = default;
~AnimatedLayersTest() = default;
protected:
ViewportLayersSetup layers_;
};
INSTANTIATE_TEST_CASE_P(All,
AnimatedLayersTest,
testing::Values(0, kBlinkGenPropertyTrees));
class AnimationForTesting : public CompositorAnimationClient {
public:
AnimationForTesting() {
compositor_animation_ = CompositorAnimation::Create();
}
CompositorAnimation* GetCompositorAnimation() const override {
return compositor_animation_.get();
}
std::unique_ptr<CompositorAnimation> compositor_animation_;
};
TEST_P(AnimatedLayersTest, updateLayerShouldFlattenTransformWithAnimations) {
// TODO(bokan): This test doesn't yet work in blink-gen-property-trees
// because cc::Layers can't set an element id in that mode. We fail at
// AttachElement since the element id is invalid. https://crbug.com/836897.
if (RuntimeEnabledFeatures::BlinkGenPropertyTreesEnabled())
return;
cc::Layer* cc_layer = layers_.graphics_layer().CcLayer();
cc::MutatorHost* mutator = layers_.layer_tree_host()->mutator_host();
EXPECT_FALSE(
mutator->HasTickingKeyframeModelForTesting(cc_layer->element_id()));
std::unique_ptr<CompositorFloatAnimationCurve> curve =
CompositorFloatAnimationCurve::Create();
curve->AddKeyframe(
CompositorFloatKeyframe(0.0, 0.0,
*CubicBezierTimingFunction::Preset(
CubicBezierTimingFunction::EaseType::EASE)));
std::unique_ptr<CompositorKeyframeModel> float_keyframe_model(
CompositorKeyframeModel::Create(*curve, CompositorTargetProperty::OPACITY,
0, 0));
int keyframe_model_id = float_keyframe_model->Id();
std::unique_ptr<CompositorAnimationTimeline> compositor_timeline =
CompositorAnimationTimeline::Create();
AnimationForTesting animation;
CompositorAnimationHost host(layers_.animation_host());
host.AddTimeline(*compositor_timeline);
compositor_timeline->AnimationAttached(animation);
cc_layer->SetElementId(CompositorElementId(cc_layer->id()));
animation.GetCompositorAnimation()->AttachElement(cc_layer->element_id());
ASSERT_TRUE(animation.GetCompositorAnimation()->IsElementAttached());
animation.GetCompositorAnimation()->AddKeyframeModel(
std::move(float_keyframe_model));
EXPECT_TRUE(
mutator->HasTickingKeyframeModelForTesting(cc_layer->element_id()));
layers_.graphics_layer().SetShouldFlattenTransform(false);
cc_layer = layers_.graphics_layer().CcLayer();
ASSERT_TRUE(cc_layer);
EXPECT_TRUE(
mutator->HasTickingKeyframeModelForTesting(cc_layer->element_id()));
animation.GetCompositorAnimation()->RemoveKeyframeModel(keyframe_model_id);
EXPECT_FALSE(
mutator->HasTickingKeyframeModelForTesting(cc_layer->element_id()));
layers_.graphics_layer().SetShouldFlattenTransform(true);
cc_layer = layers_.graphics_layer().CcLayer();
ASSERT_TRUE(cc_layer);
EXPECT_FALSE(
mutator->HasTickingKeyframeModelForTesting(cc_layer->element_id()));
animation.GetCompositorAnimation()->DetachElement();
ASSERT_FALSE(animation.GetCompositorAnimation()->IsElementAttached());
compositor_timeline->AnimationDestroyed(animation);
host.RemoveTimeline(*compositor_timeline.get());
}
} // namespace blink
......@@ -23,7 +23,6 @@ include_rules = [
"+media/renderers/video_resource_updater.h",
"+services/ui/public/cpp/gpu/context_provider_command_buffer.h",
"+services/viz/public/interfaces",
"+third_party/blink/renderer/platform/animation",
"+third_party/blink/renderer/platform/cpu/mips/common_macros_msa.h",
"+third_party/blink/renderer/platform/cross_thread_functional.h",
"+third_party/blink/renderer/platform/drag_image.h",
......
......@@ -26,7 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_COLOR_BLEND_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_COLOR_BLEND_H_
#include "third_party/blink/renderer/platform/animation/animation_utilities.h"
#include "third_party/blink/renderer/platform/geometry/blend.h"
#include "third_party/blink/renderer/platform/graphics/color.h"
namespace blink {
......
......@@ -5,6 +5,8 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_FAKE_GRAPHICS_LAYER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_FAKE_GRAPHICS_LAYER_H_
#include "third_party/blink/renderer/platform/graphics/graphics_layer.h"
namespace blink {
// A simple GraphicsLayer implementation suitable for use in unit tests.
......
......@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_FAKE_GRAPHICS_LAYER_CLIENT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_FAKE_GRAPHICS_LAYER_CLIENT_H_
#include "third_party/blink/renderer/platform/geometry/int_rect.h"
#include "third_party/blink/renderer/platform/graphics/graphics_layer_client.h"
namespace blink {
......
// 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.
#include "third_party/blink/renderer/platform/testing/viewport_layers_setup.h"
#include <memory>
#include "cc/layers/picture_layer.h"
#include "cc/trees/layer_tree_host.h"
#include "third_party/blink/renderer/platform/graphics/graphics_layer.h"
#include "third_party/blink/renderer/platform/graphics/paint/property_tree_state.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"
namespace blink {
ViewportLayersSetup::ViewportLayersSetup() {
clip_layer_ = std::make_unique<FakeGraphicsLayer>(client_);
scroll_elasticity_layer_ = std::make_unique<FakeGraphicsLayer>(client_);
page_scale_layer_ = std::make_unique<FakeGraphicsLayer>(client_);
graphics_layer_ = std::make_unique<FakeGraphicsLayer>(client_);
graphics_layer_->SetDrawsContent(true);
clip_layer_->AddChild(scroll_elasticity_layer_.get());
scroll_elasticity_layer_->AddChild(page_scale_layer_.get());
page_scale_layer_->AddChild(graphics_layer_.get());
graphics_layer_->CcLayer()->SetScrollable(clip_layer_->CcLayer()->bounds());
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_->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());
}
ViewportLayersSetup::~ViewportLayersSetup() = default;
cc::LayerTreeHost* ViewportLayersSetup::layer_tree_host() {
return layer_tree_->layer_tree_host();
}
cc::AnimationHost* ViewportLayersSetup::animation_host() {
return layer_tree_->animation_host();
}
} // namespace blink
// 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_VIEWPORT_LAYERS_SETUP_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_VIEWPORT_LAYERS_SETUP_H_
#include <memory>
#include "third_party/blink/renderer/platform/testing/fake_graphics_layer_client.h"
namespace cc {
class AnimationHost;
class LayerTreeHost;
} // namespace cc
namespace blink {
class FakeGraphicsLayer;
class LayerTreeHostEmbedder;
class ViewportLayersSetup {
public:
ViewportLayersSetup();
~ViewportLayersSetup();
FakeGraphicsLayer& graphics_layer() { return *graphics_layer_; }
FakeGraphicsLayerClient& graphics_layer_client() { return client_; }
cc::LayerTreeHost* layer_tree_host();
cc::AnimationHost* animation_host();
private:
std::unique_ptr<FakeGraphicsLayer> graphics_layer_;
std::unique_ptr<FakeGraphicsLayer> page_scale_layer_;
std::unique_ptr<FakeGraphicsLayer> scroll_elasticity_layer_;
std::unique_ptr<FakeGraphicsLayer> clip_layer_;
FakeGraphicsLayerClient client_;
std::unique_ptr<LayerTreeHostEmbedder> layer_tree_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_VIEWPORT_LAYERS_SETUP_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