| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 #include "platform/graphics/GraphicsLayer.h" | 26 #include "platform/graphics/GraphicsLayer.h" |
| 27 | 27 |
| 28 #include "platform/RuntimeEnabledFeatures.h" |
| 28 #include "platform/scroll/ScrollableArea.h" | 29 #include "platform/scroll/ScrollableArea.h" |
| 29 #include "platform/transforms/Matrix3DTransformOperation.h" | 30 #include "platform/transforms/Matrix3DTransformOperation.h" |
| 30 #include "platform/transforms/RotateTransformOperation.h" | 31 #include "platform/transforms/RotateTransformOperation.h" |
| 31 #include "platform/transforms/TranslateTransformOperation.h" | 32 #include "platform/transforms/TranslateTransformOperation.h" |
| 32 #include "public/platform/Platform.h" | 33 #include "public/platform/Platform.h" |
| 34 #include "public/platform/WebCompositorAnimationPlayer.h" |
| 35 #include "public/platform/WebCompositorAnimationPlayerClient.h" |
| 36 #include "public/platform/WebCompositorAnimationTimeline.h" |
| 33 #include "public/platform/WebCompositorSupport.h" | 37 #include "public/platform/WebCompositorSupport.h" |
| 34 #include "public/platform/WebFloatAnimationCurve.h" | 38 #include "public/platform/WebFloatAnimationCurve.h" |
| 35 #include "public/platform/WebGraphicsContext3D.h" | 39 #include "public/platform/WebGraphicsContext3D.h" |
| 36 #include "public/platform/WebLayer.h" | 40 #include "public/platform/WebLayer.h" |
| 37 #include "public/platform/WebLayerTreeView.h" | 41 #include "public/platform/WebLayerTreeView.h" |
| 38 #include "public/platform/WebUnitTestSupport.h" | 42 #include "public/platform/WebUnitTestSupport.h" |
| 39 #include "wtf/PassOwnPtr.h" | 43 #include "wtf/PassOwnPtr.h" |
| 40 #include <gtest/gtest.h> | 44 #include <gtest/gtest.h> |
| 41 | 45 |
| 42 namespace blink { | 46 namespace blink { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 m_scrollElasticityLayer->platformLayer(), m_clipLayer->platformLayer
(), m_graphicsLayer->platformLayer(), 0); | 80 m_scrollElasticityLayer->platformLayer(), m_clipLayer->platformLayer
(), m_graphicsLayer->platformLayer(), 0); |
| 77 m_layerTreeView->setViewportSize(WebSize(1, 1)); | 81 m_layerTreeView->setViewportSize(WebSize(1, 1)); |
| 78 } | 82 } |
| 79 | 83 |
| 80 ~GraphicsLayerTest() override | 84 ~GraphicsLayerTest() override |
| 81 { | 85 { |
| 82 m_graphicsLayer.clear(); | 86 m_graphicsLayer.clear(); |
| 83 m_layerTreeView.clear(); | 87 m_layerTreeView.clear(); |
| 84 } | 88 } |
| 85 | 89 |
| 90 WebLayerTreeView* layerTreeView() { return m_layerTreeView.get(); } |
| 91 |
| 86 protected: | 92 protected: |
| 87 WebLayer* m_platformLayer; | 93 WebLayer* m_platformLayer; |
| 88 OwnPtr<GraphicsLayerForTesting> m_graphicsLayer; | 94 OwnPtr<GraphicsLayerForTesting> m_graphicsLayer; |
| 89 OwnPtr<GraphicsLayerForTesting> m_scrollElasticityLayer; | 95 OwnPtr<GraphicsLayerForTesting> m_scrollElasticityLayer; |
| 90 OwnPtr<GraphicsLayerForTesting> m_clipLayer; | 96 OwnPtr<GraphicsLayerForTesting> m_clipLayer; |
| 91 | 97 |
| 92 private: | 98 private: |
| 93 OwnPtr<WebLayerTreeView> m_layerTreeView; | 99 OwnPtr<WebLayerTreeView> m_layerTreeView; |
| 94 MockGraphicsLayerClient m_client; | 100 MockGraphicsLayerClient m_client; |
| 95 }; | 101 }; |
| 96 | 102 |
| 103 class AnimationPlayerForTesting : public WebCompositorAnimationPlayerClient { |
| 104 public: |
| 105 AnimationPlayerForTesting() |
| 106 { |
| 107 m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()->
createAnimationPlayer()); |
| 108 } |
| 109 |
| 110 WebCompositorAnimationPlayer* compositorPlayer() const override |
| 111 { |
| 112 return m_compositorPlayer.get(); |
| 113 } |
| 114 |
| 115 OwnPtr<WebCompositorAnimationPlayer> m_compositorPlayer; |
| 116 }; |
| 117 |
| 97 TEST_F(GraphicsLayerTest, updateLayerShouldFlattenTransformWithAnimations) | 118 TEST_F(GraphicsLayerTest, updateLayerShouldFlattenTransformWithAnimations) |
| 98 { | 119 { |
| 99 ASSERT_FALSE(m_platformLayer->hasActiveAnimation()); | 120 ASSERT_FALSE(m_platformLayer->hasActiveAnimation()); |
| 100 | 121 |
| 101 OwnPtr<WebFloatAnimationCurve> curve = adoptPtr(Platform::current()->composi
torSupport()->createFloatAnimationCurve()); | 122 OwnPtr<WebFloatAnimationCurve> curve = adoptPtr(Platform::current()->composi
torSupport()->createFloatAnimationCurve()); |
| 102 curve->add(WebFloatKeyframe(0.0, 0.0)); | 123 curve->add(WebFloatKeyframe(0.0, 0.0)); |
| 103 OwnPtr<WebCompositorAnimation> floatAnimation(adoptPtr(Platform::current()->
compositorSupport()->createAnimation(*curve, WebCompositorAnimation::TargetPrope
rtyOpacity))); | 124 OwnPtr<WebCompositorAnimation> floatAnimation(adoptPtr(Platform::current()->
compositorSupport()->createAnimation(*curve, WebCompositorAnimation::TargetPrope
rtyOpacity))); |
| 104 int animationId = floatAnimation->id(); | 125 int animationId = floatAnimation->id(); |
| 105 ASSERT_TRUE(m_platformLayer->addAnimation(floatAnimation.leakPtr())); | |
| 106 | 126 |
| 107 ASSERT_TRUE(m_platformLayer->hasActiveAnimation()); | 127 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled()) { |
| 128 OwnPtr<WebCompositorAnimationTimeline> compositorTimeline = adoptPtr(Pla
tform::current()->compositorSupport()->createAnimationTimeline()); |
| 129 AnimationPlayerForTesting player; |
| 108 | 130 |
| 109 m_graphicsLayer->setShouldFlattenTransform(false); | 131 layerTreeView()->attachCompositorAnimationTimeline(compositorTimeline.ge
t()); |
| 132 compositorTimeline->playerAttached(player); |
| 110 | 133 |
| 111 m_platformLayer = m_graphicsLayer->platformLayer(); | 134 player.compositorPlayer()->attachLayer(m_platformLayer); |
| 112 ASSERT_TRUE(m_platformLayer); | 135 ASSERT_TRUE(player.compositorPlayer()->isLayerAttached()); |
| 113 | 136 |
| 114 ASSERT_TRUE(m_platformLayer->hasActiveAnimation()); | 137 player.compositorPlayer()->addAnimation(floatAnimation.leakPtr()); |
| 115 m_platformLayer->removeAnimation(animationId); | |
| 116 ASSERT_FALSE(m_platformLayer->hasActiveAnimation()); | |
| 117 | 138 |
| 118 m_graphicsLayer->setShouldFlattenTransform(true); | 139 ASSERT_TRUE(m_platformLayer->hasActiveAnimation()); |
| 119 | 140 |
| 120 m_platformLayer = m_graphicsLayer->platformLayer(); | 141 m_graphicsLayer->setShouldFlattenTransform(false); |
| 121 ASSERT_TRUE(m_platformLayer); | |
| 122 | 142 |
| 123 ASSERT_FALSE(m_platformLayer->hasActiveAnimation()); | 143 m_platformLayer = m_graphicsLayer->platformLayer(); |
| 144 ASSERT_TRUE(m_platformLayer); |
| 145 |
| 146 ASSERT_TRUE(m_platformLayer->hasActiveAnimation()); |
| 147 player.compositorPlayer()->removeAnimation(animationId); |
| 148 ASSERT_FALSE(m_platformLayer->hasActiveAnimation()); |
| 149 |
| 150 m_graphicsLayer->setShouldFlattenTransform(true); |
| 151 |
| 152 m_platformLayer = m_graphicsLayer->platformLayer(); |
| 153 ASSERT_TRUE(m_platformLayer); |
| 154 |
| 155 ASSERT_FALSE(m_platformLayer->hasActiveAnimation()); |
| 156 |
| 157 player.compositorPlayer()->detachLayer(); |
| 158 ASSERT_FALSE(player.compositorPlayer()->isLayerAttached()); |
| 159 |
| 160 compositorTimeline->playerDestroyed(player); |
| 161 layerTreeView()->detachCompositorAnimationTimeline(compositorTimeline.ge
t()); |
| 162 } else { |
| 163 ASSERT_TRUE(m_platformLayer->addAnimation(floatAnimation.leakPtr())); |
| 164 |
| 165 ASSERT_TRUE(m_platformLayer->hasActiveAnimation()); |
| 166 |
| 167 m_graphicsLayer->setShouldFlattenTransform(false); |
| 168 |
| 169 m_platformLayer = m_graphicsLayer->platformLayer(); |
| 170 ASSERT_TRUE(m_platformLayer); |
| 171 |
| 172 ASSERT_TRUE(m_platformLayer->hasActiveAnimation()); |
| 173 m_platformLayer->removeAnimation(animationId); |
| 174 ASSERT_FALSE(m_platformLayer->hasActiveAnimation()); |
| 175 |
| 176 m_graphicsLayer->setShouldFlattenTransform(true); |
| 177 |
| 178 m_platformLayer = m_graphicsLayer->platformLayer(); |
| 179 ASSERT_TRUE(m_platformLayer); |
| 180 |
| 181 ASSERT_FALSE(m_platformLayer->hasActiveAnimation()); |
| 182 } |
| 124 } | 183 } |
| 125 | 184 |
| 126 class FakeScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<FakeScro
llableArea>, public ScrollableArea { | 185 class FakeScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<FakeScro
llableArea>, public ScrollableArea { |
| 127 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(FakeScrollableArea); | 186 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(FakeScrollableArea); |
| 128 public: | 187 public: |
| 129 static PassOwnPtrWillBeRawPtr<FakeScrollableArea> create() | 188 static PassOwnPtrWillBeRawPtr<FakeScrollableArea> create() |
| 130 { | 189 { |
| 131 return adoptPtrWillBeNoop(new FakeScrollableArea); | 190 return adoptPtrWillBeNoop(new FakeScrollableArea); |
| 132 } | 191 } |
| 133 | 192 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 231 |
| 173 WebDoublePoint scrollPosition(7, 9); | 232 WebDoublePoint scrollPosition(7, 9); |
| 174 m_platformLayer->setScrollPositionDouble(scrollPosition); | 233 m_platformLayer->setScrollPositionDouble(scrollPosition); |
| 175 m_graphicsLayer->didScroll(); | 234 m_graphicsLayer->didScroll(); |
| 176 | 235 |
| 177 EXPECT_FLOAT_EQ(scrollPosition.x, scrollableArea->scrollPositionDouble().x()
); | 236 EXPECT_FLOAT_EQ(scrollPosition.x, scrollableArea->scrollPositionDouble().x()
); |
| 178 EXPECT_FLOAT_EQ(scrollPosition.y, scrollableArea->scrollPositionDouble().y()
); | 237 EXPECT_FLOAT_EQ(scrollPosition.y, scrollableArea->scrollPositionDouble().y()
); |
| 179 } | 238 } |
| 180 | 239 |
| 181 } // namespace blink | 240 } // namespace blink |
| OLD | NEW |