| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 1 | /* |
| 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 | * |
| thakis | 11b4bbc | 2016-10-04 17:35:35 | [diff] [blame] | 13 | * 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] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 24 | */ |
| 25 | |
| [email protected] | 49f8882b | 2013-12-06 12:31:11 | [diff] [blame] | 26 | #include "platform/graphics/GraphicsLayer.h" |
| [email protected] | 407b51d | 2013-05-30 22:16:04 | [diff] [blame] | 27 | |
| yutak | cad69d6c | 2017-04-06 09:06:03 | [diff] [blame] | 28 | #include <memory> |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 29 | #include "platform/RuntimeEnabledFeatures.h" |
| loyso | 8247b0d | 2016-06-14 11:35:33 | [diff] [blame] | 30 | #include "platform/animation/CompositorAnimation.h" |
| loyso | ffcf86c | 2016-12-19 07:14:39 | [diff] [blame] | 31 | #include "platform/animation/CompositorAnimationHost.h" |
| loyso | 26f3c55 | 2016-02-10 23:54:34 | [diff] [blame] | 32 | #include "platform/animation/CompositorAnimationPlayer.h" |
| 33 | #include "platform/animation/CompositorAnimationPlayerClient.h" |
| 34 | #include "platform/animation/CompositorAnimationTimeline.h" |
| 35 | #include "platform/animation/CompositorFloatAnimationCurve.h" |
| loyso | 8247b0d | 2016-06-14 11:35:33 | [diff] [blame] | 36 | #include "platform/animation/CompositorTargetProperty.h" |
| vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 37 | #include "platform/graphics/CompositorElementId.h" |
| Walter Korman | a167bd8 | 2017-08-09 15:24:29 | [diff] [blame^] | 38 | #include "platform/graphics/test/FakeScrollableArea.h" |
| skyostil | d80c41e | 2017-04-25 18:35:36 | [diff] [blame] | 39 | #include "platform/scheduler/child/web_scheduler.h" |
| [email protected] | 49f8882b | 2013-12-06 12:31:11 | [diff] [blame] | 40 | #include "platform/scroll/ScrollableArea.h" |
| wkorman | 070bb4a | 2016-04-01 19:58:47 | [diff] [blame] | 41 | #include "platform/testing/FakeGraphicsLayer.h" |
| wkorman | 098f4a8 | 2016-04-06 01:22:39 | [diff] [blame] | 42 | #include "platform/testing/FakeGraphicsLayerClient.h" |
| loyso | cde77907 | 2016-03-31 06:44:28 | [diff] [blame] | 43 | #include "platform/testing/WebLayerTreeViewImplForTesting.h" |
| [email protected] | e72ce8b | 2013-10-27 14:41:10 | [diff] [blame] | 44 | #include "platform/transforms/Matrix3DTransformOperation.h" |
| 45 | #include "platform/transforms/RotateTransformOperation.h" |
| 46 | #include "platform/transforms/TranslateTransformOperation.h" |
| yutak | cad69d6c | 2017-04-06 09:06:03 | [diff] [blame] | 47 | #include "platform/wtf/PtrUtil.h" |
| [email protected] | 8555b53 | 2013-06-01 08:11:53 | [diff] [blame] | 48 | #include "public/platform/Platform.h" |
| 49 | #include "public/platform/WebCompositorSupport.h" |
| [email protected] | 8555b53 | 2013-06-01 08:11:53 | [diff] [blame] | 50 | #include "public/platform/WebLayer.h" |
| 51 | #include "public/platform/WebLayerTreeView.h" |
| jbroman | cd5c59c | 2017-01-20 17:27:33 | [diff] [blame] | 52 | #include "public/platform/WebThread.h" |
| tkent | ce24c28 | 2015-11-18 15:52:17 | [diff] [blame] | 53 | #include "testing/gtest/include/gtest/gtest.h" |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 54 | |
| [email protected] | 247956b | 2015-06-12 05:51:06 | [diff] [blame] | 55 | namespace blink { |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 56 | |
| bratell | c04dbb7 | 2017-07-07 17:37:36 | [diff] [blame] | 57 | class GraphicsLayerTest : public ::testing::Test { |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 58 | public: |
| 59 | GraphicsLayerTest() { |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 60 | clip_layer_ = WTF::WrapUnique(new FakeGraphicsLayer(&client_)); |
| 61 | scroll_elasticity_layer_ = WTF::WrapUnique(new FakeGraphicsLayer(&client_)); |
| Philip Rogers | d9e5ffd | 2017-06-16 00:10:53 | [diff] [blame] | 62 | page_scale_layer_ = WTF::WrapUnique(new FakeGraphicsLayer(&client_)); |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 63 | graphics_layer_ = WTF::WrapUnique(new FakeGraphicsLayer(&client_)); |
| 64 | clip_layer_->AddChild(scroll_elasticity_layer_.get()); |
| Philip Rogers | d9e5ffd | 2017-06-16 00:10:53 | [diff] [blame] | 65 | scroll_elasticity_layer_->AddChild(page_scale_layer_.get()); |
| 66 | page_scale_layer_->AddChild(graphics_layer_.get()); |
| pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 67 | graphics_layer_->PlatformLayer()->SetScrollable( |
| 68 | clip_layer_->PlatformLayer()->Bounds()); |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 69 | platform_layer_ = graphics_layer_->PlatformLayer(); |
| 70 | layer_tree_view_ = WTF::WrapUnique(new WebLayerTreeViewImplForTesting); |
| hs1217.lee | 94e9d9c | 2017-04-12 02:26:21 | [diff] [blame] | 71 | DCHECK(layer_tree_view_); |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 72 | layer_tree_view_->SetRootLayer(*clip_layer_->PlatformLayer()); |
| Chandan Padhi | 198800bd1 | 2017-07-07 08:15:07 | [diff] [blame] | 73 | 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 Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 80 | layer_tree_view_->SetViewportSize(WebSize(1, 1)); |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 81 | } |
| [email protected] | b3f4f96 | 2012-06-08 18:41:47 | [diff] [blame] | 82 | |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 83 | ~GraphicsLayerTest() override { |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 84 | graphics_layer_.reset(); |
| 85 | layer_tree_view_.reset(); |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 86 | } |
| [email protected] | b3f4f96 | 2012-06-08 18:41:47 | [diff] [blame] | 87 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 88 | WebLayerTreeView* LayerTreeView() { return layer_tree_view_.get(); } |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 89 | |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 90 | protected: |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 91 | WebLayer* platform_layer_; |
| 92 | std::unique_ptr<FakeGraphicsLayer> graphics_layer_; |
| Philip Rogers | d9e5ffd | 2017-06-16 00:10:53 | [diff] [blame] | 93 | std::unique_ptr<FakeGraphicsLayer> page_scale_layer_; |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 94 | std::unique_ptr<FakeGraphicsLayer> scroll_elasticity_layer_; |
| 95 | std::unique_ptr<FakeGraphicsLayer> clip_layer_; |
| [email protected] | b3f4f96 | 2012-06-08 18:41:47 | [diff] [blame] | 96 | |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 97 | private: |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 98 | std::unique_ptr<WebLayerTreeView> layer_tree_view_; |
| 99 | FakeGraphicsLayerClient client_; |
| [email protected] | b3f4f96 | 2012-06-08 18:41:47 | [diff] [blame] | 100 | }; |
| 101 | |
| loyso | 26f3c55 | 2016-02-10 23:54:34 | [diff] [blame] | 102 | class AnimationPlayerForTesting : public CompositorAnimationPlayerClient { |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 103 | public: |
| 104 | AnimationPlayerForTesting() { |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 105 | compositor_player_ = CompositorAnimationPlayer::Create(); |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 106 | } |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 107 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 108 | CompositorAnimationPlayer* CompositorPlayer() const override { |
| 109 | return compositor_player_.get(); |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 110 | } |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 111 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 112 | std::unique_ptr<CompositorAnimationPlayer> compositor_player_; |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 113 | }; |
| 114 | |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 115 | TEST_F(GraphicsLayerTest, updateLayerShouldFlattenTransformWithAnimations) { |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 116 | ASSERT_FALSE(platform_layer_->HasTickingAnimationForTesting()); |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 117 | |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 118 | std::unique_ptr<CompositorFloatAnimationCurve> curve = |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 119 | 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 Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 126 | 0)); |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 127 | int animation_id = float_animation->Id(); |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 128 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 129 | std::unique_ptr<CompositorAnimationTimeline> compositor_timeline = |
| 130 | CompositorAnimationTimeline::Create(); |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 131 | AnimationPlayerForTesting player; |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 132 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 133 | CompositorAnimationHost host(LayerTreeView()->CompositorAnimationHost()); |
| loyso | ffcf86c | 2016-12-19 07:14:39 | [diff] [blame] | 134 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 135 | host.AddTimeline(*compositor_timeline); |
| 136 | compositor_timeline->PlayerAttached(player); |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 137 | |
| chrishtr | c3daf27 | 2017-05-11 11:08:02 | [diff] [blame] | 138 | platform_layer_->SetElementId(CompositorElementId(platform_layer_->Id())); |
| vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 139 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 140 | player.CompositorPlayer()->AttachElement(platform_layer_->GetElementId()); |
| 141 | ASSERT_TRUE(player.CompositorPlayer()->IsElementAttached()); |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 142 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 143 | player.CompositorPlayer()->AddAnimation(std::move(float_animation)); |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 144 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 145 | ASSERT_TRUE(platform_layer_->HasTickingAnimationForTesting()); |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 146 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 147 | graphics_layer_->SetShouldFlattenTransform(false); |
| [email protected] | 2b74e88 | 2012-05-11 18:04:15 | [diff] [blame] | 148 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 149 | platform_layer_ = graphics_layer_->PlatformLayer(); |
| 150 | ASSERT_TRUE(platform_layer_); |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 151 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 152 | ASSERT_TRUE(platform_layer_->HasTickingAnimationForTesting()); |
| 153 | player.CompositorPlayer()->RemoveAnimation(animation_id); |
| 154 | ASSERT_FALSE(platform_layer_->HasTickingAnimationForTesting()); |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 155 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 156 | graphics_layer_->SetShouldFlattenTransform(true); |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 157 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 158 | platform_layer_ = graphics_layer_->PlatformLayer(); |
| 159 | ASSERT_TRUE(platform_layer_); |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 160 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 161 | ASSERT_FALSE(platform_layer_->HasTickingAnimationForTesting()); |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 162 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 163 | player.CompositorPlayer()->DetachElement(); |
| 164 | ASSERT_FALSE(player.CompositorPlayer()->IsElementAttached()); |
| loyso | 2c1247e2 | 2015-11-08 01:26:58 | [diff] [blame] | 165 | |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 166 | compositor_timeline->PlayerDestroyed(player); |
| 167 | host.RemoveTimeline(*compositor_timeline.get()); |
| [email protected] | b3f4f96 | 2012-06-08 18:41:47 | [diff] [blame] | 168 | } |
| 169 | |
| Blink Reformat | 1c8e1a77 | 2016-10-01 00:25:32 | [diff] [blame] | 170 | } // namespace blink |