[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 5 | #include "cc/layer_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 7 | #include "cc/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 8 | #include "testing/gmock/include/gmock/gmock.h" |
| 9 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 10 | #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 11 | #include <public/WebFilterOperation.h> |
| 12 | #include <public/WebFilterOperations.h> |
| 13 | |
| 14 | using namespace WebKit; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 15 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 16 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 17 | namespace { |
| 18 | |
| 19 | #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(codeToTest) \ |
| 20 | root->resetAllChangeTrackingForSubtree(); \ |
| 21 | codeToTest; \ |
| 22 | EXPECT_TRUE(root->layerPropertyChanged()); \ |
| 23 | EXPECT_TRUE(child->layerPropertyChanged()); \ |
| 24 | EXPECT_TRUE(grandChild->layerPropertyChanged()); \ |
| 25 | EXPECT_FALSE(root->layerSurfacePropertyChanged()) |
| 26 | |
| 27 | |
| 28 | #define EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(codeToTest) \ |
| 29 | root->resetAllChangeTrackingForSubtree(); \ |
| 30 | codeToTest; \ |
| 31 | EXPECT_FALSE(root->layerPropertyChanged()); \ |
| 32 | EXPECT_FALSE(child->layerPropertyChanged()); \ |
| 33 | EXPECT_FALSE(grandChild->layerPropertyChanged()); \ |
| 34 | EXPECT_FALSE(root->layerSurfacePropertyChanged()) |
| 35 | |
| 36 | #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(codeToTest) \ |
| 37 | root->resetAllChangeTrackingForSubtree(); \ |
| 38 | codeToTest; \ |
| 39 | EXPECT_TRUE(root->layerPropertyChanged()); \ |
| 40 | EXPECT_FALSE(child->layerPropertyChanged()); \ |
| 41 | EXPECT_FALSE(grandChild->layerPropertyChanged()); \ |
| 42 | EXPECT_FALSE(root->layerSurfacePropertyChanged()) |
| 43 | |
| 44 | #define EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(codeToTest) \ |
| 45 | root->resetAllChangeTrackingForSubtree(); \ |
| 46 | codeToTest; \ |
| 47 | EXPECT_FALSE(root->layerPropertyChanged()); \ |
| 48 | EXPECT_FALSE(child->layerPropertyChanged()); \ |
| 49 | EXPECT_FALSE(grandChild->layerPropertyChanged()); \ |
| 50 | EXPECT_TRUE(root->layerSurfacePropertyChanged()) |
| 51 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 52 | TEST(LayerImplTest, verifyLayerChangesAreTrackedProperly) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 53 | { |
| 54 | // |
| 55 | // This test checks that layerPropertyChanged() has the correct behavior. |
| 56 | // |
| 57 | |
| 58 | // The constructor on this will fake that we are on the correct thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 59 | // Create a simple LayerImpl tree: |
| 60 | scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 61 | root->addChild(LayerImpl::create(2)); |
| 62 | LayerImpl* child = root->children()[0]; |
| 63 | child->addChild(LayerImpl::create(3)); |
| 64 | LayerImpl* grandChild = child->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 65 | |
| 66 | // Adding children is an internal operation and should not mark layers as changed. |
| 67 | EXPECT_FALSE(root->layerPropertyChanged()); |
| 68 | EXPECT_FALSE(child->layerPropertyChanged()); |
| 69 | EXPECT_FALSE(grandChild->layerPropertyChanged()); |
| 70 | |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 71 | gfx::PointF arbitraryPointF = gfx::PointF(0.125f, 0.25f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 72 | float arbitraryNumber = 0.352f; |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 73 | gfx::Size arbitrarySize = gfx::Size(111, 222); |
| 74 | gfx::Point arbitraryPoint = gfx::Point(333, 444); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 75 | gfx::Vector2d arbitraryVector2d = gfx::Vector2d(111, 222); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 76 | gfx::Rect arbitraryRect = gfx::Rect(arbitraryPoint, arbitrarySize); |
| 77 | gfx::RectF arbitraryRectF = gfx::RectF(arbitraryPointF, gfx::SizeF(1.234f, 5.678f)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 78 | SkColor arbitraryColor = SkColorSetRGB(10, 20, 30); |
| 79 | WebTransformationMatrix arbitraryTransform; |
| 80 | arbitraryTransform.scale3d(0.1, 0.2, 0.3); |
| 81 | WebFilterOperations arbitraryFilters; |
| 82 | arbitraryFilters.append(WebFilterOperation::createOpacityFilter(0.5)); |
[email protected] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 83 | SkAutoTUnref<SkImageFilter> arbitraryFilter(new SkBlurImageFilter(SK_Scalar1, SK_Scalar1)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 84 | |
| 85 | // These properties are internal, and should not be considered "change" when they are used. |
| 86 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setUseLCDText(true)); |
| 87 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDrawOpacity(arbitraryNumber)); |
| 88 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setRenderTarget(0)); |
| 89 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDrawTransform(arbitraryTransform)); |
| 90 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setScreenSpaceTransform(arbitraryTransform)); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 91 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDrawableContentRect(arbitraryRect)); |
| 92 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setUpdateRect(arbitraryRectF)); |
| 93 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setVisibleContentRect(arbitraryRect)); |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 94 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setMaxScrollOffset(arbitraryVector2d)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 95 | |
| 96 | // Changing these properties affects the entire subtree of layers. |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 97 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setAnchorPoint(arbitraryPointF)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 98 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setAnchorPointZ(arbitraryNumber)); |
| 99 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setFilters(arbitraryFilters)); |
[email protected] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 100 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setFilters(WebFilterOperations())); |
| 101 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setFilter(arbitraryFilter)); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 102 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setMaskLayer(LayerImpl::create(4))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setMasksToBounds(true)); |
[email protected] | 048634c | 2012-10-02 22:33:14 | [diff] [blame] | 104 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setContentsOpaque(true)); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 105 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setReplicaLayer(LayerImpl::create(5))); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 106 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setPosition(arbitraryPointF)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 107 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setPreserves3D(true)); |
| 108 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setDoubleSided(false)); // constructor initializes it to "true". |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 109 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->scrollBy(arbitraryVector2d)); |
| 110 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setScrollDelta(gfx::Vector2d())); |
| 111 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setScrollOffset(arbitraryVector2d)); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 112 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setImplTransform(arbitraryTransform)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 113 | |
| 114 | // Changing these properties only affects the layer itself. |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 115 | EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setContentBounds(arbitrarySize)); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 116 | EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setContentsScale(arbitraryNumber, arbitraryNumber)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 117 | EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setDrawsContent(true)); |
| 118 | EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setBackgroundColor(SK_ColorGRAY)); |
| 119 | EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setBackgroundFilters(arbitraryFilters)); |
| 120 | |
| 121 | // Changing these properties only affects how render surface is drawn |
| 122 | EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(root->setOpacity(arbitraryNumber)); |
| 123 | EXECUTE_AND_VERIFY_ONLY_SURFACE_CHANGED(root->setTransform(arbitraryTransform)); |
| 124 | |
| 125 | // Special case: check that sublayer transform changes all layer's descendants, but not the layer itself. |
| 126 | root->resetAllChangeTrackingForSubtree(); |
| 127 | root->setSublayerTransform(arbitraryTransform); |
| 128 | EXPECT_FALSE(root->layerPropertyChanged()); |
| 129 | EXPECT_TRUE(child->layerPropertyChanged()); |
| 130 | EXPECT_TRUE(grandChild->layerPropertyChanged()); |
| 131 | |
| 132 | // Special case: check that setBounds changes behavior depending on masksToBounds. |
| 133 | root->setMasksToBounds(false); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 134 | EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setBounds(gfx::Size(135, 246))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 135 | root->setMasksToBounds(true); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 136 | EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setBounds(arbitrarySize)); // should be a different size than previous call, to ensure it marks tree changed. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 137 | |
| 138 | // After setting all these properties already, setting to the exact same values again should |
| 139 | // not cause any change. |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 140 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setAnchorPoint(arbitraryPointF)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 141 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setAnchorPointZ(arbitraryNumber)); |
| 142 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setMasksToBounds(true)); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 143 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setPosition(arbitraryPointF)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 144 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setPreserves3D(true)); |
| 145 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setTransform(arbitraryTransform)); |
| 146 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDoubleSided(false)); // constructor initializes it to "true". |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 147 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setScrollDelta(gfx::Vector2d())); |
| 148 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setScrollOffset(arbitraryVector2d)); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 149 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setImplTransform(arbitraryTransform)); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 150 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setContentBounds(arbitrarySize)); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 151 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setContentsScale(arbitraryNumber, arbitraryNumber)); |
[email protected] | 048634c | 2012-10-02 22:33:14 | [diff] [blame] | 152 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setContentsOpaque(true)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 153 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setOpacity(arbitraryNumber)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 154 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDrawsContent(true)); |
| 155 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setSublayerTransform(arbitraryTransform)); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 156 | EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setBounds(arbitrarySize)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 157 | } |
| 158 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 159 | } // namespace |
| 160 | } // namespace cc |