blob: db0a8214e795eacc9e7fa57c15c30d3b1e469dc9 [file] [log] [blame]
[email protected]2b74e882012-05-11 18:04:151/*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
thakis11b4bbc2016-10-04 17:35:3513 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
23 * DAMAGE.
[email protected]2b74e882012-05-11 18:04:1524 */
25
[email protected]49f8882b2013-12-06 12:31:1126#include "platform/graphics/GraphicsLayer.h"
[email protected]407b51d2013-05-30 22:16:0427
yutakcad69d6c2017-04-06 09:06:0328#include <memory>
loyso2c1247e22015-11-08 01:26:5829#include "platform/RuntimeEnabledFeatures.h"
loyso8247b0d2016-06-14 11:35:3330#include "platform/animation/CompositorAnimation.h"
loysoffcf86c2016-12-19 07:14:3931#include "platform/animation/CompositorAnimationHost.h"
loyso26f3c552016-02-10 23:54:3432#include "platform/animation/CompositorAnimationPlayer.h"
33#include "platform/animation/CompositorAnimationPlayerClient.h"
34#include "platform/animation/CompositorAnimationTimeline.h"
35#include "platform/animation/CompositorFloatAnimationCurve.h"
loyso8247b0d2016-06-14 11:35:3336#include "platform/animation/CompositorTargetProperty.h"
vollickef2ae922016-06-29 17:54:2737#include "platform/graphics/CompositorElementId.h"
Walter Kormana167bd82017-08-09 15:24:2938#include "platform/graphics/test/FakeScrollableArea.h"
skyostild80c41e2017-04-25 18:35:3639#include "platform/scheduler/child/web_scheduler.h"
[email protected]49f8882b2013-12-06 12:31:1140#include "platform/scroll/ScrollableArea.h"
wkorman070bb4a2016-04-01 19:58:4741#include "platform/testing/FakeGraphicsLayer.h"
wkorman098f4a82016-04-06 01:22:3942#include "platform/testing/FakeGraphicsLayerClient.h"
loysocde779072016-03-31 06:44:2843#include "platform/testing/WebLayerTreeViewImplForTesting.h"
[email protected]e72ce8b2013-10-27 14:41:1044#include "platform/transforms/Matrix3DTransformOperation.h"
45#include "platform/transforms/RotateTransformOperation.h"
46#include "platform/transforms/TranslateTransformOperation.h"
yutakcad69d6c2017-04-06 09:06:0347#include "platform/wtf/PtrUtil.h"
[email protected]8555b532013-06-01 08:11:5348#include "public/platform/Platform.h"
49#include "public/platform/WebCompositorSupport.h"
[email protected]8555b532013-06-01 08:11:5350#include "public/platform/WebLayer.h"
51#include "public/platform/WebLayerTreeView.h"
jbromancd5c59c2017-01-20 17:27:3352#include "public/platform/WebThread.h"
tkentce24c282015-11-18 15:52:1753#include "testing/gtest/include/gtest/gtest.h"
[email protected]2b74e882012-05-11 18:04:1554
[email protected]247956b2015-06-12 05:51:0655namespace blink {
[email protected]2b74e882012-05-11 18:04:1556
bratellc04dbb72017-07-07 17:37:3657class GraphicsLayerTest : public ::testing::Test {
Blink Reformat1c8e1a772016-10-01 00:25:3258 public:
59 GraphicsLayerTest() {
Blink Reformat1c4d759e2017-04-09 16:34:5460 clip_layer_ = WTF::WrapUnique(new FakeGraphicsLayer(&client_));
61 scroll_elasticity_layer_ = WTF::WrapUnique(new FakeGraphicsLayer(&client_));
Philip Rogersd9e5ffd2017-06-16 00:10:5362 page_scale_layer_ = WTF::WrapUnique(new FakeGraphicsLayer(&client_));
Blink Reformat1c4d759e2017-04-09 16:34:5463 graphics_layer_ = WTF::WrapUnique(new FakeGraphicsLayer(&client_));
64 clip_layer_->AddChild(scroll_elasticity_layer_.get());
Philip Rogersd9e5ffd2017-06-16 00:10:5365 scroll_elasticity_layer_->AddChild(page_scale_layer_.get());
66 page_scale_layer_->AddChild(graphics_layer_.get());
pdrbbfd8822017-06-27 22:44:5267 graphics_layer_->PlatformLayer()->SetScrollable(
68 clip_layer_->PlatformLayer()->Bounds());
Blink Reformat1c4d759e2017-04-09 16:34:5469 platform_layer_ = graphics_layer_->PlatformLayer();
70 layer_tree_view_ = WTF::WrapUnique(new WebLayerTreeViewImplForTesting);
hs1217.lee94e9d9c2017-04-12 02:26:2171 DCHECK(layer_tree_view_);
Blink Reformat1c4d759e2017-04-09 16:34:5472 layer_tree_view_->SetRootLayer(*clip_layer_->PlatformLayer());
Chandan Padhi198800bd12017-07-07 08:15:0773 WebLayerTreeView::ViewportLayers viewport_layers;
74 viewport_layers.overscroll_elasticity =
75 scroll_elasticity_layer_->PlatformLayer();
76 viewport_layers.page_scale = page_scale_layer_->PlatformLayer();
77 viewport_layers.inner_viewport_container = clip_layer_->PlatformLayer();
78 viewport_layers.inner_viewport_scroll = graphics_layer_->PlatformLayer();
79 layer_tree_view_->RegisterViewportLayers(viewport_layers);
Blink Reformat1c4d759e2017-04-09 16:34:5480 layer_tree_view_->SetViewportSize(WebSize(1, 1));
Blink Reformat1c8e1a772016-10-01 00:25:3281 }
[email protected]b3f4f962012-06-08 18:41:4782
Blink Reformat1c8e1a772016-10-01 00:25:3283 ~GraphicsLayerTest() override {
Blink Reformat1c4d759e2017-04-09 16:34:5484 graphics_layer_.reset();
85 layer_tree_view_.reset();
Blink Reformat1c8e1a772016-10-01 00:25:3286 }
[email protected]b3f4f962012-06-08 18:41:4787
Blink Reformat1c4d759e2017-04-09 16:34:5488 WebLayerTreeView* LayerTreeView() { return layer_tree_view_.get(); }
loyso2c1247e22015-11-08 01:26:5889
Blink Reformat1c8e1a772016-10-01 00:25:3290 protected:
Blink Reformat1c4d759e2017-04-09 16:34:5491 WebLayer* platform_layer_;
92 std::unique_ptr<FakeGraphicsLayer> graphics_layer_;
Philip Rogersd9e5ffd2017-06-16 00:10:5393 std::unique_ptr<FakeGraphicsLayer> page_scale_layer_;
Blink Reformat1c4d759e2017-04-09 16:34:5494 std::unique_ptr<FakeGraphicsLayer> scroll_elasticity_layer_;
95 std::unique_ptr<FakeGraphicsLayer> clip_layer_;
[email protected]b3f4f962012-06-08 18:41:4796
Blink Reformat1c8e1a772016-10-01 00:25:3297 private:
Blink Reformat1c4d759e2017-04-09 16:34:5498 std::unique_ptr<WebLayerTreeView> layer_tree_view_;
99 FakeGraphicsLayerClient client_;
[email protected]b3f4f962012-06-08 18:41:47100};
101
loyso26f3c552016-02-10 23:54:34102class AnimationPlayerForTesting : public CompositorAnimationPlayerClient {
Blink Reformat1c8e1a772016-10-01 00:25:32103 public:
104 AnimationPlayerForTesting() {
Blink Reformat1c4d759e2017-04-09 16:34:54105 compositor_player_ = CompositorAnimationPlayer::Create();
Blink Reformat1c8e1a772016-10-01 00:25:32106 }
loyso2c1247e22015-11-08 01:26:58107
Blink Reformat1c4d759e2017-04-09 16:34:54108 CompositorAnimationPlayer* CompositorPlayer() const override {
109 return compositor_player_.get();
Blink Reformat1c8e1a772016-10-01 00:25:32110 }
loyso2c1247e22015-11-08 01:26:58111
Blink Reformat1c4d759e2017-04-09 16:34:54112 std::unique_ptr<CompositorAnimationPlayer> compositor_player_;
loyso2c1247e22015-11-08 01:26:58113};
114
Blink Reformat1c8e1a772016-10-01 00:25:32115TEST_F(GraphicsLayerTest, updateLayerShouldFlattenTransformWithAnimations) {
Blink Reformat1c4d759e2017-04-09 16:34:54116 ASSERT_FALSE(platform_layer_->HasTickingAnimationForTesting());
[email protected]2b74e882012-05-11 18:04:15117
Blink Reformat1c8e1a772016-10-01 00:25:32118 std::unique_ptr<CompositorFloatAnimationCurve> curve =
Blink Reformat1c4d759e2017-04-09 16:34:54119 CompositorFloatAnimationCurve::Create();
120 curve->AddKeyframe(
121 CompositorFloatKeyframe(0.0, 0.0,
122 *CubicBezierTimingFunction::Preset(
123 CubicBezierTimingFunction::EaseType::EASE)));
124 std::unique_ptr<CompositorAnimation> float_animation(
125 CompositorAnimation::Create(*curve, CompositorTargetProperty::OPACITY, 0,
Blink Reformat1c8e1a772016-10-01 00:25:32126 0));
Blink Reformat1c4d759e2017-04-09 16:34:54127 int animation_id = float_animation->Id();
[email protected]2b74e882012-05-11 18:04:15128
Blink Reformat1c4d759e2017-04-09 16:34:54129 std::unique_ptr<CompositorAnimationTimeline> compositor_timeline =
130 CompositorAnimationTimeline::Create();
Blink Reformat1c8e1a772016-10-01 00:25:32131 AnimationPlayerForTesting player;
[email protected]2b74e882012-05-11 18:04:15132
Blink Reformat1c4d759e2017-04-09 16:34:54133 CompositorAnimationHost host(LayerTreeView()->CompositorAnimationHost());
loysoffcf86c2016-12-19 07:14:39134
Blink Reformat1c4d759e2017-04-09 16:34:54135 host.AddTimeline(*compositor_timeline);
136 compositor_timeline->PlayerAttached(player);
[email protected]2b74e882012-05-11 18:04:15137
chrishtrc3daf272017-05-11 11:08:02138 platform_layer_->SetElementId(CompositorElementId(platform_layer_->Id()));
vollickef2ae922016-06-29 17:54:27139
Blink Reformat1c4d759e2017-04-09 16:34:54140 player.CompositorPlayer()->AttachElement(platform_layer_->GetElementId());
141 ASSERT_TRUE(player.CompositorPlayer()->IsElementAttached());
[email protected]2b74e882012-05-11 18:04:15142
Blink Reformat1c4d759e2017-04-09 16:34:54143 player.CompositorPlayer()->AddAnimation(std::move(float_animation));
[email protected]2b74e882012-05-11 18:04:15144
Blink Reformat1c4d759e2017-04-09 16:34:54145 ASSERT_TRUE(platform_layer_->HasTickingAnimationForTesting());
[email protected]2b74e882012-05-11 18:04:15146
Blink Reformat1c4d759e2017-04-09 16:34:54147 graphics_layer_->SetShouldFlattenTransform(false);
[email protected]2b74e882012-05-11 18:04:15148
Blink Reformat1c4d759e2017-04-09 16:34:54149 platform_layer_ = graphics_layer_->PlatformLayer();
150 ASSERT_TRUE(platform_layer_);
loyso2c1247e22015-11-08 01:26:58151
Blink Reformat1c4d759e2017-04-09 16:34:54152 ASSERT_TRUE(platform_layer_->HasTickingAnimationForTesting());
153 player.CompositorPlayer()->RemoveAnimation(animation_id);
154 ASSERT_FALSE(platform_layer_->HasTickingAnimationForTesting());
loyso2c1247e22015-11-08 01:26:58155
Blink Reformat1c4d759e2017-04-09 16:34:54156 graphics_layer_->SetShouldFlattenTransform(true);
loyso2c1247e22015-11-08 01:26:58157
Blink Reformat1c4d759e2017-04-09 16:34:54158 platform_layer_ = graphics_layer_->PlatformLayer();
159 ASSERT_TRUE(platform_layer_);
loyso2c1247e22015-11-08 01:26:58160
Blink Reformat1c4d759e2017-04-09 16:34:54161 ASSERT_FALSE(platform_layer_->HasTickingAnimationForTesting());
loyso2c1247e22015-11-08 01:26:58162
Blink Reformat1c4d759e2017-04-09 16:34:54163 player.CompositorPlayer()->DetachElement();
164 ASSERT_FALSE(player.CompositorPlayer()->IsElementAttached());
loyso2c1247e22015-11-08 01:26:58165
Blink Reformat1c4d759e2017-04-09 16:34:54166 compositor_timeline->PlayerDestroyed(player);
167 host.RemoveTimeline(*compositor_timeline.get());
[email protected]b3f4f962012-06-08 18:41:47168}
169
Blink Reformat1c8e1a772016-10-01 00:25:32170} // namespace blink