OLD | NEW |
| (Empty) |
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 | |
5 #include "config.h" | |
6 | |
7 #include "CCRenderSurface.h" | |
8 | |
9 #include "CCAppendQuadsData.h" | |
10 #include "CCLayerImpl.h" | |
11 #include "CCRenderPassSink.h" | |
12 #include "CCSharedQuadState.h" | |
13 #include "CCSingleThreadProxy.h" | |
14 #include "MockCCQuadCuller.h" | |
15 #include "cc/own_ptr_vector.h" | |
16 #include "cc/scoped_ptr_vector.h" | |
17 #include "testing/gmock/include/gmock/gmock.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 #include <public/WebTransformationMatrix.h> | |
20 | |
21 using namespace cc; | |
22 using WebKit::WebTransformationMatrix; | |
23 | |
24 namespace { | |
25 | |
26 #define EXECUTE_AND_VERIFY_SURFACE_CHANGED(codeToTest) \ | |
27 renderSurface->resetPropertyChangedFlag(); \ | |
28 codeToTest; \ | |
29 EXPECT_TRUE(renderSurface->surfacePropertyChanged()) | |
30 | |
31 #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \ | |
32 renderSurface->resetPropertyChangedFlag(); \ | |
33 codeToTest; \ | |
34 EXPECT_FALSE(renderSurface->surfacePropertyChanged()) | |
35 | |
36 TEST(CCRenderSurfaceTest, verifySurfaceChangesAreTrackedProperly) | |
37 { | |
38 // | |
39 // This test checks that surfacePropertyChanged() has the correct behavior. | |
40 // | |
41 | |
42 // This will fake that we are on the correct thread for testing purposes. | |
43 DebugScopedSetImplThread setImplThread; | |
44 | |
45 scoped_ptr<CCLayerImpl> owningLayer = CCLayerImpl::create(1); | |
46 owningLayer->createRenderSurface(); | |
47 ASSERT_TRUE(owningLayer->renderSurface()); | |
48 CCRenderSurface* renderSurface = owningLayer->renderSurface(); | |
49 IntRect testRect = IntRect(IntPoint(3, 4), IntSize(5, 6)); | |
50 owningLayer->resetAllChangeTrackingForSubtree(); | |
51 | |
52 // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChang
ed() are | |
53 // the only sources of change. | |
54 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setClipRect(testRect)); | |
55 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setContentRect(testRect)); | |
56 | |
57 owningLayer->setOpacity(0.5f); | |
58 EXPECT_TRUE(renderSurface->surfacePropertyChanged()); | |
59 owningLayer->resetAllChangeTrackingForSubtree(); | |
60 | |
61 // Setting the surface properties to the same values again should not be con
sidered "change". | |
62 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRec
t)); | |
63 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(test
Rect)); | |
64 | |
65 scoped_ptr<CCLayerImpl> dummyMask = CCLayerImpl::create(1); | |
66 WebTransformationMatrix dummyMatrix; | |
67 dummyMatrix.translate(1.0, 2.0); | |
68 | |
69 // The rest of the surface properties are either internal and should not cau
se change, | |
70 // or they are already accounted for by the owninglayer->layerPropertyChange
d(). | |
71 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawOpacity(0.5)
); | |
72 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawTransform(du
mmyMatrix)); | |
73 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setReplicaDrawTrans
form(dummyMatrix)); | |
74 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerLists()); | |
75 } | |
76 | |
77 TEST(CCRenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState) | |
78 { | |
79 // This will fake that we are on the correct thread for testing purposes. | |
80 DebugScopedSetImplThread setImplThread; | |
81 | |
82 scoped_ptr<CCLayerImpl> rootLayer = CCLayerImpl::create(1); | |
83 | |
84 scoped_ptr<CCLayerImpl> owningLayer = CCLayerImpl::create(2); | |
85 owningLayer->createRenderSurface(); | |
86 ASSERT_TRUE(owningLayer->renderSurface()); | |
87 owningLayer->setRenderTarget(owningLayer.get()); | |
88 CCRenderSurface* renderSurface = owningLayer->renderSurface(); | |
89 | |
90 rootLayer->addChild(owningLayer.Pass()); | |
91 | |
92 IntRect contentRect = IntRect(IntPoint::zero(), IntSize(50, 50)); | |
93 IntRect clipRect = IntRect(IntPoint(5, 5), IntSize(40, 40)); | |
94 WebTransformationMatrix origin; | |
95 | |
96 origin.translate(30, 40); | |
97 | |
98 renderSurface->setDrawTransform(origin); | |
99 renderSurface->setContentRect(contentRect); | |
100 renderSurface->setClipRect(clipRect); | |
101 renderSurface->setDrawOpacity(1); | |
102 | |
103 CCQuadList quadList; | |
104 CCSharedQuadStateList sharedStateList; | |
105 MockCCQuadCuller mockQuadCuller(quadList, sharedStateList); | |
106 CCAppendQuadsData appendQuadsData; | |
107 | |
108 bool forReplica = false; | |
109 renderSurface->appendQuads(mockQuadCuller, appendQuadsData, forReplica, CCRe
nderPass::Id(2, 0)); | |
110 | |
111 ASSERT_EQ(1u, sharedStateList.size()); | |
112 CCSharedQuadState* sharedQuadState = sharedStateList[0]; | |
113 | |
114 EXPECT_EQ(30, sharedQuadState->quadTransform.m41()); | |
115 EXPECT_EQ(40, sharedQuadState->quadTransform.m42()); | |
116 EXPECT_EQ(contentRect, IntRect(sharedQuadState->visibleContentRect)); | |
117 EXPECT_EQ(1, sharedQuadState->opacity); | |
118 EXPECT_FALSE(sharedQuadState->opaque); | |
119 } | |
120 | |
121 class TestCCRenderPassSink : public CCRenderPassSink { | |
122 public: | |
123 virtual void appendRenderPass(scoped_ptr<CCRenderPass> renderPass) OVERRIDE
{ m_renderPasses.append(renderPass.Pass()); } | |
124 | |
125 const ScopedPtrVector<CCRenderPass>& renderPasses() const { return m_renderP
asses; } | |
126 | |
127 private: | |
128 ScopedPtrVector<CCRenderPass> m_renderPasses; | |
129 }; | |
130 | |
131 TEST(CCRenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass) | |
132 { | |
133 // This will fake that we are on the correct thread for testing purposes. | |
134 DebugScopedSetImplThread setImplThread; | |
135 | |
136 scoped_ptr<CCLayerImpl> rootLayer = CCLayerImpl::create(1); | |
137 | |
138 scoped_ptr<CCLayerImpl> owningLayer = CCLayerImpl::create(2); | |
139 owningLayer->createRenderSurface(); | |
140 ASSERT_TRUE(owningLayer->renderSurface()); | |
141 owningLayer->setRenderTarget(owningLayer.get()); | |
142 CCRenderSurface* renderSurface = owningLayer->renderSurface(); | |
143 | |
144 rootLayer->addChild(owningLayer.Pass()); | |
145 | |
146 IntRect contentRect = IntRect(IntPoint::zero(), IntSize(50, 50)); | |
147 WebTransformationMatrix origin; | |
148 origin.translate(30, 40); | |
149 | |
150 renderSurface->setScreenSpaceTransform(origin); | |
151 renderSurface->setContentRect(contentRect); | |
152 | |
153 TestCCRenderPassSink passSink; | |
154 | |
155 renderSurface->appendRenderPasses(passSink); | |
156 | |
157 ASSERT_EQ(1u, passSink.renderPasses().size()); | |
158 CCRenderPass* pass = passSink.renderPasses()[0]; | |
159 | |
160 EXPECT_EQ(CCRenderPass::Id(2, 0), pass->id()); | |
161 EXPECT_EQ(contentRect, pass->outputRect()); | |
162 EXPECT_EQ(origin, pass->transformToRootTarget()); | |
163 } | |
164 | |
165 } // namespace | |
OLD | NEW |