OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/render_surface_impl.h" | 5 #include "cc/render_surface_impl.h" |
6 | 6 |
7 #include "cc/append_quads_data.h" | 7 #include "cc/append_quads_data.h" |
8 #include "cc/layer_impl.h" | 8 #include "cc/layer_impl.h" |
9 #include "cc/render_pass_sink.h" | 9 #include "cc/render_pass_sink.h" |
10 #include "cc/scoped_ptr_vector.h" | 10 #include "cc/scoped_ptr_vector.h" |
11 #include "cc/shared_quad_state.h" | 11 #include "cc/shared_quad_state.h" |
12 #include "cc/single_thread_proxy.h" | 12 #include "cc/single_thread_proxy.h" |
13 #include "cc/test/geometry_test_utils.h" | 13 #include "cc/test/geometry_test_utils.h" |
14 #include "cc/test/mock_quad_culler.h" | 14 #include "cc/test/mock_quad_culler.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include <public/WebTransformationMatrix.h> | 17 #include "ui/gfx/transform.h" |
18 | 18 |
19 using WebKit::WebTransformationMatrix; | 19 using gfx::Transform; |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 namespace { | 22 namespace { |
23 | 23 |
24 #define EXECUTE_AND_VERIFY_SURFACE_CHANGED(codeToTest) \ | 24 #define EXECUTE_AND_VERIFY_SURFACE_CHANGED(codeToTest) \ |
25 renderSurface->resetPropertyChangedFlag(); \ | 25 renderSurface->resetPropertyChangedFlag(); \ |
26 codeToTest; \ | 26 codeToTest; \ |
27 EXPECT_TRUE(renderSurface->surfacePropertyChanged()) | 27 EXPECT_TRUE(renderSurface->surfacePropertyChanged()) |
28 | 28 |
29 #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \ | 29 #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \ |
(...skipping 21 matching lines...) Expand all Loading... |
51 | 51 |
52 owningLayer->setOpacity(0.5f); | 52 owningLayer->setOpacity(0.5f); |
53 EXPECT_TRUE(renderSurface->surfacePropertyChanged()); | 53 EXPECT_TRUE(renderSurface->surfacePropertyChanged()); |
54 owningLayer->resetAllChangeTrackingForSubtree(); | 54 owningLayer->resetAllChangeTrackingForSubtree(); |
55 | 55 |
56 // Setting the surface properties to the same values again should not be con
sidered "change". | 56 // Setting the surface properties to the same values again should not be con
sidered "change". |
57 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRec
t)); | 57 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRec
t)); |
58 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(test
Rect)); | 58 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(test
Rect)); |
59 | 59 |
60 scoped_ptr<LayerImpl> dummyMask = LayerImpl::create(1); | 60 scoped_ptr<LayerImpl> dummyMask = LayerImpl::create(1); |
61 WebTransformationMatrix dummyMatrix; | 61 Transform dummyMatrix; |
62 dummyMatrix.translate(1.0, 2.0); | 62 dummyMatrix.PreconcatTranslate(1.0, 2.0); |
63 | 63 |
64 // The rest of the surface properties are either internal and should not cau
se change, | 64 // The rest of the surface properties are either internal and should not cau
se change, |
65 // or they are already accounted for by the owninglayer->layerPropertyChange
d(). | 65 // or they are already accounted for by the owninglayer->layerPropertyChange
d(). |
66 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawOpacity(0.5)
); | 66 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawOpacity(0.5)
); |
67 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawTransform(du
mmyMatrix)); | 67 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawTransform(du
mmyMatrix)); |
68 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setReplicaDrawTrans
form(dummyMatrix)); | 68 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setReplicaDrawTrans
form(dummyMatrix)); |
69 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerLists()); | 69 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerLists()); |
70 } | 70 } |
71 | 71 |
72 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState) | 72 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState) |
73 { | 73 { |
74 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); | 74 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); |
75 | 75 |
76 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); | 76 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); |
77 owningLayer->createRenderSurface(); | 77 owningLayer->createRenderSurface(); |
78 ASSERT_TRUE(owningLayer->renderSurface()); | 78 ASSERT_TRUE(owningLayer->renderSurface()); |
79 owningLayer->setRenderTarget(owningLayer.get()); | 79 owningLayer->setRenderTarget(owningLayer.get()); |
80 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); | 80 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); |
81 | 81 |
82 rootLayer->addChild(owningLayer.Pass()); | 82 rootLayer->addChild(owningLayer.Pass()); |
83 | 83 |
84 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); | 84 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); |
85 gfx::Rect clipRect = gfx::Rect(gfx::Point(5, 5), gfx::Size(40, 40)); | 85 gfx::Rect clipRect = gfx::Rect(gfx::Point(5, 5), gfx::Size(40, 40)); |
86 WebTransformationMatrix origin; | 86 Transform origin; |
87 | 87 |
88 origin.translate(30, 40); | 88 origin.PreconcatTranslate(30, 40); |
89 | 89 |
90 renderSurface->setDrawTransform(origin); | 90 renderSurface->setDrawTransform(origin); |
91 renderSurface->setContentRect(contentRect); | 91 renderSurface->setContentRect(contentRect); |
92 renderSurface->setClipRect(clipRect); | 92 renderSurface->setClipRect(clipRect); |
93 renderSurface->setDrawOpacity(1); | 93 renderSurface->setDrawOpacity(1); |
94 | 94 |
95 QuadList quadList; | 95 QuadList quadList; |
96 SharedQuadStateList sharedStateList; | 96 SharedQuadStateList sharedStateList; |
97 MockQuadCuller mockQuadCuller(quadList, sharedStateList); | 97 MockQuadCuller mockQuadCuller(quadList, sharedStateList); |
98 AppendQuadsData appendQuadsData; | 98 AppendQuadsData appendQuadsData; |
99 | 99 |
100 bool forReplica = false; | 100 bool forReplica = false; |
101 renderSurface->appendQuads(mockQuadCuller, appendQuadsData, forReplica, Rend
erPass::Id(2, 0)); | 101 renderSurface->appendQuads(mockQuadCuller, appendQuadsData, forReplica, Rend
erPass::Id(2, 0)); |
102 | 102 |
103 ASSERT_EQ(1u, sharedStateList.size()); | 103 ASSERT_EQ(1u, sharedStateList.size()); |
104 SharedQuadState* sharedQuadState = sharedStateList[0]; | 104 SharedQuadState* sharedQuadState = sharedStateList[0]; |
105 | 105 |
106 EXPECT_EQ(30, sharedQuadState->content_to_target_transform.m41()); | 106 EXPECT_EQ(30, sharedQuadState->content_to_target_transform.matrix().getDoubl
e(0, 3)); |
107 EXPECT_EQ(40, sharedQuadState->content_to_target_transform.m42()); | 107 EXPECT_EQ(40, sharedQuadState->content_to_target_transform.matrix().getDoubl
e(1, 3)); |
108 EXPECT_RECT_EQ(contentRect, gfx::Rect(sharedQuadState->visible_content_rect)
); | 108 EXPECT_RECT_EQ(contentRect, gfx::Rect(sharedQuadState->visible_content_rect)
); |
109 EXPECT_EQ(1, sharedQuadState->opacity); | 109 EXPECT_EQ(1, sharedQuadState->opacity); |
110 } | 110 } |
111 | 111 |
112 class TestRenderPassSink : public RenderPassSink { | 112 class TestRenderPassSink : public RenderPassSink { |
113 public: | 113 public: |
114 virtual void appendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE {
m_renderPasses.append(renderPass.Pass()); } | 114 virtual void appendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE {
m_renderPasses.append(renderPass.Pass()); } |
115 | 115 |
116 const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPas
ses; } | 116 const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPas
ses; } |
117 | 117 |
118 private: | 118 private: |
119 ScopedPtrVector<RenderPass> m_renderPasses; | 119 ScopedPtrVector<RenderPass> m_renderPasses; |
120 }; | 120 }; |
121 | 121 |
122 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass) | 122 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass) |
123 { | 123 { |
124 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); | 124 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); |
125 | 125 |
126 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); | 126 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); |
127 owningLayer->createRenderSurface(); | 127 owningLayer->createRenderSurface(); |
128 ASSERT_TRUE(owningLayer->renderSurface()); | 128 ASSERT_TRUE(owningLayer->renderSurface()); |
129 owningLayer->setRenderTarget(owningLayer.get()); | 129 owningLayer->setRenderTarget(owningLayer.get()); |
130 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); | 130 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); |
131 | 131 |
132 rootLayer->addChild(owningLayer.Pass()); | 132 rootLayer->addChild(owningLayer.Pass()); |
133 | 133 |
134 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); | 134 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); |
135 WebTransformationMatrix origin; | 135 Transform origin; |
136 origin.translate(30, 40); | 136 origin.PreconcatTranslate(30, 40); |
137 | 137 |
138 renderSurface->setScreenSpaceTransform(origin); | 138 renderSurface->setScreenSpaceTransform(origin); |
139 renderSurface->setContentRect(contentRect); | 139 renderSurface->setContentRect(contentRect); |
140 | 140 |
141 TestRenderPassSink passSink; | 141 TestRenderPassSink passSink; |
142 | 142 |
143 renderSurface->appendRenderPasses(passSink); | 143 renderSurface->appendRenderPasses(passSink); |
144 | 144 |
145 ASSERT_EQ(1u, passSink.renderPasses().size()); | 145 ASSERT_EQ(1u, passSink.renderPasses().size()); |
146 RenderPass* pass = passSink.renderPasses()[0]; | 146 RenderPass* pass = passSink.renderPasses()[0]; |
147 | 147 |
148 EXPECT_EQ(RenderPass::Id(2, 0), pass->id); | 148 EXPECT_EQ(RenderPass::Id(2, 0), pass->id); |
149 EXPECT_RECT_EQ(contentRect, pass->output_rect); | 149 EXPECT_RECT_EQ(contentRect, pass->output_rect); |
150 EXPECT_EQ(origin, pass->transform_to_root_target); | 150 EXPECT_EQ(origin, pass->transform_to_root_target); |
151 } | 151 } |
152 | 152 |
153 } // namespace | 153 } // namespace |
154 } // namespace cc | 154 } // namespace cc |
OLD | NEW |