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 "cc/render_surface_impl.h" | |
6 | |
7 #include "cc/append_quads_data.h" | |
8 #include "cc/base/scoped_ptr_vector.h" | |
9 #include "cc/layer_impl.h" | |
10 #include "cc/quads/shared_quad_state.h" | |
11 #include "cc/render_pass_sink.h" | |
12 #include "cc/test/fake_impl_proxy.h" | |
13 #include "cc/test/fake_layer_tree_host_impl.h" | |
14 #include "cc/test/geometry_test_utils.h" | |
15 #include "cc/test/mock_quad_culler.h" | |
16 #include "cc/trees/single_thread_proxy.h" | |
17 #include "testing/gmock/include/gmock/gmock.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 #include "ui/gfx/transform.h" | |
20 | |
21 namespace cc { | |
22 namespace { | |
23 | |
24 #define EXECUTE_AND_VERIFY_SURFACE_CHANGED(codeToTest) \ | |
25 renderSurface->ResetPropertyChangedFlag(); \ | |
26 codeToTest; \ | |
27 EXPECT_TRUE(renderSurface->SurfacePropertyChanged()) | |
28 | |
29 #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \ | |
30 renderSurface->ResetPropertyChangedFlag(); \ | |
31 codeToTest; \ | |
32 EXPECT_FALSE(renderSurface->SurfacePropertyChanged()) | |
33 | |
34 TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly) | |
35 { | |
36 // | |
37 // This test checks that SurfacePropertyChanged() has the correct behavior. | |
38 // | |
39 | |
40 FakeImplProxy proxy; | |
41 FakeLayerTreeHostImpl hostImpl(&proxy); | |
42 scoped_ptr<LayerImpl> owningLayer = LayerImpl::Create(hostImpl.active_tree()
, 1); | |
43 owningLayer->CreateRenderSurface(); | |
44 ASSERT_TRUE(owningLayer->render_surface()); | |
45 RenderSurfaceImpl* renderSurface = owningLayer->render_surface(); | |
46 gfx::Rect testRect = gfx::Rect(gfx::Point(3, 4), gfx::Size(5, 6)); | |
47 owningLayer->ResetAllChangeTrackingForSubtree(); | |
48 | |
49 // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChang
ed() are | |
50 // the only sources of change. | |
51 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->SetClipRect(testRect)); | |
52 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->SetContentRect(testRect)); | |
53 | |
54 owningLayer->SetOpacity(0.5f); | |
55 EXPECT_TRUE(renderSurface->SurfacePropertyChanged()); | |
56 owningLayer->ResetAllChangeTrackingForSubtree(); | |
57 | |
58 // Setting the surface properties to the same values again should not be con
sidered "change". | |
59 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetClipRect(testRec
t)); | |
60 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetContentRect(test
Rect)); | |
61 | |
62 scoped_ptr<LayerImpl> dummyMask = LayerImpl::Create(hostImpl.active_tree(),
2); | |
63 gfx::Transform dummyMatrix; | |
64 dummyMatrix.Translate(1.0, 2.0); | |
65 | |
66 // The rest of the surface properties are either internal and should not cau
se change, | |
67 // or they are already accounted for by the owninglayer->layerPropertyChange
d(). | |
68 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetDrawOpacity(0.5f
)); | |
69 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetDrawTransform(du
mmyMatrix)); | |
70 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetReplicaDrawTrans
form(dummyMatrix)); | |
71 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->ClearLayerLists()); | |
72 } | |
73 | |
74 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState) | |
75 { | |
76 FakeImplProxy proxy; | |
77 FakeLayerTreeHostImpl hostImpl(&proxy); | |
78 scoped_ptr<LayerImpl> rootLayer = LayerImpl::Create(hostImpl.active_tree(),
1); | |
79 | |
80 scoped_ptr<LayerImpl> owningLayer = LayerImpl::Create(hostImpl.active_tree()
, 2); | |
81 owningLayer->CreateRenderSurface(); | |
82 ASSERT_TRUE(owningLayer->render_surface()); | |
83 owningLayer->draw_properties().render_target = owningLayer.get(); | |
84 RenderSurfaceImpl* renderSurface = owningLayer->render_surface(); | |
85 | |
86 rootLayer->AddChild(owningLayer.Pass()); | |
87 | |
88 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); | |
89 gfx::Rect clipRect = gfx::Rect(gfx::Point(5, 5), gfx::Size(40, 40)); | |
90 gfx::Transform origin; | |
91 | |
92 origin.Translate(30, 40); | |
93 | |
94 renderSurface->SetDrawTransform(origin); | |
95 renderSurface->SetContentRect(contentRect); | |
96 renderSurface->SetClipRect(clipRect); | |
97 renderSurface->SetDrawOpacity(1.f); | |
98 | |
99 QuadList quadList; | |
100 SharedQuadStateList sharedStateList; | |
101 MockQuadCuller mockQuadCuller(quadList, sharedStateList); | |
102 AppendQuadsData appendQuadsData; | |
103 | |
104 bool forReplica = false; | |
105 renderSurface->AppendQuads(&mockQuadCuller, &appendQuadsData, forReplica, Re
nderPass::Id(2, 0)); | |
106 | |
107 ASSERT_EQ(1u, sharedStateList.size()); | |
108 SharedQuadState* sharedQuadState = sharedStateList[0]; | |
109 | |
110 EXPECT_EQ(30, sharedQuadState->content_to_target_transform.matrix().getDoubl
e(0, 3)); | |
111 EXPECT_EQ(40, sharedQuadState->content_to_target_transform.matrix().getDoubl
e(1, 3)); | |
112 EXPECT_RECT_EQ(contentRect, gfx::Rect(sharedQuadState->visible_content_rect)
); | |
113 EXPECT_EQ(1, sharedQuadState->opacity); | |
114 } | |
115 | |
116 class TestRenderPassSink : public RenderPassSink { | |
117 public: | |
118 virtual void AppendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE {
m_renderPasses.push_back(renderPass.Pass()); } | |
119 | |
120 const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPas
ses; } | |
121 | |
122 private: | |
123 ScopedPtrVector<RenderPass> m_renderPasses; | |
124 }; | |
125 | |
126 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass) | |
127 { | |
128 FakeImplProxy proxy; | |
129 FakeLayerTreeHostImpl hostImpl(&proxy); | |
130 scoped_ptr<LayerImpl> rootLayer = LayerImpl::Create(hostImpl.active_tree(),
1); | |
131 | |
132 scoped_ptr<LayerImpl> owningLayer = LayerImpl::Create(hostImpl.active_tree()
, 2); | |
133 owningLayer->CreateRenderSurface(); | |
134 ASSERT_TRUE(owningLayer->render_surface()); | |
135 owningLayer->draw_properties().render_target = owningLayer.get(); | |
136 RenderSurfaceImpl* renderSurface = owningLayer->render_surface(); | |
137 | |
138 rootLayer->AddChild(owningLayer.Pass()); | |
139 | |
140 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); | |
141 gfx::Transform origin; | |
142 origin.Translate(30, 40); | |
143 | |
144 renderSurface->SetScreenSpaceTransform(origin); | |
145 renderSurface->SetContentRect(contentRect); | |
146 | |
147 TestRenderPassSink passSink; | |
148 | |
149 renderSurface->AppendRenderPasses(&passSink); | |
150 | |
151 ASSERT_EQ(1u, passSink.renderPasses().size()); | |
152 RenderPass* pass = passSink.renderPasses()[0]; | |
153 | |
154 EXPECT_EQ(RenderPass::Id(2, 0), pass->id); | |
155 EXPECT_RECT_EQ(contentRect, pass->output_rect); | |
156 EXPECT_EQ(origin, pass->transform_to_root_target); | |
157 } | |
158 | |
159 } // namespace | |
160 } // namespace cc | |
OLD | NEW |