blob: f47dc1df54b198601aacf5c5bcdf277fc3ac6b3f [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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]d50c6862012-10-23 02:08:315#include "cc/layer_impl.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]4456eee22012-10-19 18:16:387#include "cc/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:188#include "testing/gmock/include/gmock/gmock.h"
9#include "testing/gtest/include/gtest/gtest.h"
[email protected]4000abf2012-10-23 04:45:4510#include "third_party/skia/include/effects/SkBlurImageFilter.h"
[email protected]94f206c12012-08-25 00:09:1411#include <public/WebFilterOperation.h>
12#include <public/WebFilterOperations.h>
13
14using namespace WebKit;
[email protected]94f206c12012-08-25 00:09:1415
[email protected]ba565742012-11-10 09:29:4816namespace cc {
[email protected]94f206c12012-08-25 00:09:1417namespace {
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]96baf3e2012-10-22 23:09:5552TEST(LayerImplTest, verifyLayerChangesAreTrackedProperly)
[email protected]94f206c12012-08-25 00:09:1453{
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]96baf3e2012-10-22 23:09:5559 // 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]94f206c12012-08-25 00:09:1465
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]d0f98362012-11-01 23:02:3871 gfx::PointF arbitraryPointF = gfx::PointF(0.125f, 0.25f);
[email protected]94f206c12012-08-25 00:09:1472 float arbitraryNumber = 0.352f;
[email protected]d0f98362012-11-01 23:02:3873 gfx::Size arbitrarySize = gfx::Size(111, 222);
74 gfx::Point arbitraryPoint = gfx::Point(333, 444);
[email protected]c9c1ebe2012-11-05 20:46:1375 gfx::Vector2d arbitraryVector2d = gfx::Vector2d(111, 222);
[email protected]d0f98362012-11-01 23:02:3876 gfx::Rect arbitraryRect = gfx::Rect(arbitraryPoint, arbitrarySize);
77 gfx::RectF arbitraryRectF = gfx::RectF(arbitraryPointF, gfx::SizeF(1.234f, 5.678f));
[email protected]94f206c12012-08-25 00:09:1478 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]4000abf2012-10-23 04:45:4583 SkAutoTUnref<SkImageFilter> arbitraryFilter(new SkBlurImageFilter(SK_Scalar1, SK_Scalar1));
[email protected]94f206c12012-08-25 00:09:1484
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]d0f98362012-11-01 23:02:3891 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]c9c1ebe2012-11-05 20:46:1394 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setMaxScrollOffset(arbitraryVector2d));
[email protected]94f206c12012-08-25 00:09:1495
96 // Changing these properties affects the entire subtree of layers.
[email protected]d0f98362012-11-01 23:02:3897 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setAnchorPoint(arbitraryPointF));
[email protected]94f206c12012-08-25 00:09:1498 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setAnchorPointZ(arbitraryNumber));
99 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setFilters(arbitraryFilters));
[email protected]4000abf2012-10-23 04:45:45100 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setFilters(WebFilterOperations()));
101 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setFilter(arbitraryFilter));
[email protected]96baf3e2012-10-22 23:09:55102 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setMaskLayer(LayerImpl::create(4)));
[email protected]94f206c12012-08-25 00:09:14103 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setMasksToBounds(true));
[email protected]048634c2012-10-02 22:33:14104 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setContentsOpaque(true));
[email protected]96baf3e2012-10-22 23:09:55105 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setReplicaLayer(LayerImpl::create(5)));
[email protected]d0f98362012-11-01 23:02:38106 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setPosition(arbitraryPointF));
[email protected]94f206c12012-08-25 00:09:14107 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setPreserves3D(true));
108 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setDoubleSided(false)); // constructor initializes it to "true".
[email protected]c9c1ebe2012-11-05 20:46:13109 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]1c0c9bc2012-10-08 22:41:48112 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setImplTransform(arbitraryTransform));
[email protected]94f206c12012-08-25 00:09:14113
114 // Changing these properties only affects the layer itself.
[email protected]d0f98362012-11-01 23:02:38115 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setContentBounds(arbitrarySize));
[email protected]904e9132012-11-01 00:12:47116 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setContentsScale(arbitraryNumber, arbitraryNumber));
[email protected]94f206c12012-08-25 00:09:14117 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]d0f98362012-11-01 23:02:38134 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setBounds(gfx::Size(135, 246)));
[email protected]94f206c12012-08-25 00:09:14135 root->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38136 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setBounds(arbitrarySize)); // should be a different size than previous call, to ensure it marks tree changed.
[email protected]94f206c12012-08-25 00:09:14137
138 // After setting all these properties already, setting to the exact same values again should
139 // not cause any change.
[email protected]d0f98362012-11-01 23:02:38140 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setAnchorPoint(arbitraryPointF));
[email protected]94f206c12012-08-25 00:09:14141 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setAnchorPointZ(arbitraryNumber));
142 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setMasksToBounds(true));
[email protected]d0f98362012-11-01 23:02:38143 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setPosition(arbitraryPointF));
[email protected]94f206c12012-08-25 00:09:14144 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]c9c1ebe2012-11-05 20:46:13147 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setScrollDelta(gfx::Vector2d()));
148 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setScrollOffset(arbitraryVector2d));
[email protected]1c0c9bc2012-10-08 22:41:48149 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setImplTransform(arbitraryTransform));
[email protected]d0f98362012-11-01 23:02:38150 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setContentBounds(arbitrarySize));
[email protected]904e9132012-11-01 00:12:47151 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setContentsScale(arbitraryNumber, arbitraryNumber));
[email protected]048634c2012-10-02 22:33:14152 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setContentsOpaque(true));
[email protected]94f206c12012-08-25 00:09:14153 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setOpacity(arbitraryNumber));
[email protected]94f206c12012-08-25 00:09:14154 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setDrawsContent(true));
155 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setSublayerTransform(arbitraryTransform));
[email protected]d0f98362012-11-01 23:02:38156 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->setBounds(arbitrarySize));
[email protected]94f206c12012-08-25 00:09:14157}
158
[email protected]ba565742012-11-10 09:29:48159} // namespace
160} // namespace cc