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