[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 | |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 7 | #include "cc/render_surface_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 8 | |
[email protected] | aa0a9d3 | 2012-10-24 01:58:10 | [diff] [blame] | 9 | #include "cc/append_quads_data.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 10 | #include "cc/layer_impl.h" |
[email protected] | 55a124d0 | 2012-10-22 03:07:13 | [diff] [blame] | 11 | #include "cc/render_pass_sink.h" |
[email protected] | 87cea537 | 2012-09-26 18:59:56 | [diff] [blame] | 12 | #include "cc/scoped_ptr_vector.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 13 | #include "cc/shared_quad_state.h" |
| 14 | #include "cc/single_thread_proxy.h" |
[email protected] | 1fea814 | 2012-10-20 04:12:41 | [diff] [blame] | 15 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 16 | #include "cc/test/mock_quad_culler.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 17 | #include "testing/gmock/include/gmock/gmock.h" |
| 18 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 19 | #include <public/WebTransformationMatrix.h> |
| 20 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 21 | using namespace cc; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 36 | TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 37 | { |
| 38 | // |
| 39 | // This test checks that surfacePropertyChanged() has the correct behavior. |
| 40 | // |
| 41 | |
[email protected] | 5bc29a2 | 2012-11-01 21:21:59 | [diff] [blame] | 42 | // This will fake that we are on the correct thread for testing purposes. |
| 43 | DebugScopedSetImplThread setImplThread; |
| 44 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 45 | scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 46 | owningLayer->createRenderSurface(); |
| 47 | ASSERT_TRUE(owningLayer->renderSurface()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 48 | RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame^] | 49 | gfx::Rect testRect = gfx::Rect(gfx::Point(3, 4), gfx::Size(5, 6)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 50 | owningLayer->resetAllChangeTrackingForSubtree(); |
| 51 | |
| 52 | // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChanged() 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 considered "change". |
| 62 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRect)); |
| 63 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(testRect)); |
| 64 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 65 | scoped_ptr<LayerImpl> dummyMask = LayerImpl::create(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 66 | WebTransformationMatrix dummyMatrix; |
| 67 | dummyMatrix.translate(1.0, 2.0); |
| 68 | |
| 69 | // The rest of the surface properties are either internal and should not cause change, |
| 70 | // or they are already accounted for by the owninglayer->layerPropertyChanged(). |
| 71 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawOpacity(0.5)); |
| 72 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawTransform(dummyMatrix)); |
| 73 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setReplicaDrawTransform(dummyMatrix)); |
[email protected] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 74 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerLists()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 75 | } |
| 76 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 77 | TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 78 | { |
[email protected] | 5bc29a2 | 2012-11-01 21:21:59 | [diff] [blame] | 79 | // This will fake that we are on the correct thread for testing purposes. |
| 80 | DebugScopedSetImplThread setImplThread; |
| 81 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 82 | scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 83 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 84 | scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 85 | owningLayer->createRenderSurface(); |
| 86 | ASSERT_TRUE(owningLayer->renderSurface()); |
| 87 | owningLayer->setRenderTarget(owningLayer.get()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 88 | RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 89 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 90 | rootLayer->addChild(owningLayer.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 91 | |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame^] | 92 | gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); |
| 93 | gfx::Rect clipRect = gfx::Rect(gfx::Point(5, 5), gfx::Size(40, 40)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 103 | QuadList quadList; |
| 104 | SharedQuadStateList sharedStateList; |
| 105 | MockQuadCuller mockQuadCuller(quadList, sharedStateList); |
| 106 | AppendQuadsData appendQuadsData; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 107 | |
| 108 | bool forReplica = false; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 109 | renderSurface->appendQuads(mockQuadCuller, appendQuadsData, forReplica, RenderPass::Id(2, 0)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 110 | |
| 111 | ASSERT_EQ(1u, sharedStateList.size()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 112 | SharedQuadState* sharedQuadState = sharedStateList[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 113 | |
| 114 | EXPECT_EQ(30, sharedQuadState->quadTransform.m41()); |
| 115 | EXPECT_EQ(40, sharedQuadState->quadTransform.m42()); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame^] | 116 | EXPECT_RECT_EQ(contentRect, gfx::Rect(sharedQuadState->visibleContentRect)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 117 | EXPECT_EQ(1, sharedQuadState->opacity); |
| 118 | EXPECT_FALSE(sharedQuadState->opaque); |
| 119 | } |
| 120 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 121 | class TestRenderPassSink : public RenderPassSink { |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 122 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 123 | virtual void appendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE { m_renderPasses.append(renderPass.Pass()); } |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 124 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 125 | const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPasses; } |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 126 | |
| 127 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 128 | ScopedPtrVector<RenderPass> m_renderPasses; |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 129 | }; |
| 130 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 131 | TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass) |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 132 | { |
[email protected] | 5bc29a2 | 2012-11-01 21:21:59 | [diff] [blame] | 133 | // This will fake that we are on the correct thread for testing purposes. |
| 134 | DebugScopedSetImplThread setImplThread; |
| 135 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 136 | scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 137 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 138 | scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 139 | owningLayer->createRenderSurface(); |
| 140 | ASSERT_TRUE(owningLayer->renderSurface()); |
| 141 | owningLayer->setRenderTarget(owningLayer.get()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 142 | RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 143 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 144 | rootLayer->addChild(owningLayer.Pass()); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 145 | |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame^] | 146 | gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 147 | WebTransformationMatrix origin; |
| 148 | origin.translate(30, 40); |
| 149 | |
| 150 | renderSurface->setScreenSpaceTransform(origin); |
| 151 | renderSurface->setContentRect(contentRect); |
| 152 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 153 | TestRenderPassSink passSink; |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 154 | |
| 155 | renderSurface->appendRenderPasses(passSink); |
| 156 | |
| 157 | ASSERT_EQ(1u, passSink.renderPasses().size()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 158 | RenderPass* pass = passSink.renderPasses()[0]; |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 159 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 160 | EXPECT_EQ(RenderPass::Id(2, 0), pass->id()); |
[email protected] | 1fea814 | 2012-10-20 04:12:41 | [diff] [blame] | 161 | EXPECT_RECT_EQ(contentRect, pass->outputRect()); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 162 | EXPECT_EQ(origin, pass->transformToRootTarget()); |
| 163 | } |
| 164 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 165 | } // namespace |