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