[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] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 13 | #include "cc/test/fake_impl_proxy.h" |
| 14 | #include "cc/test/fake_layer_tree_host_impl.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] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 19 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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) \ |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 25 | renderSurface->ResetPropertyChangedFlag(); \ |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 26 | codeToTest; \ |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 27 | EXPECT_TRUE(renderSurface->SurfacePropertyChanged()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 28 | |
| 29 | #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \ |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 30 | renderSurface->ResetPropertyChangedFlag(); \ |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 31 | codeToTest; \ |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 32 | EXPECT_FALSE(renderSurface->SurfacePropertyChanged()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 | // |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 37 | // This test checks that SurfacePropertyChanged() has the correct behavior. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 38 | // |
| 39 | |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 40 | FakeImplProxy proxy; |
| 41 | FakeLayerTreeHostImpl hostImpl(&proxy); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 42 | scoped_ptr<LayerImpl> owningLayer = LayerImpl::Create(hostImpl.active_tree(), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 43 | owningLayer->CreateRenderSurface(); |
| 44 | ASSERT_TRUE(owningLayer->render_surface()); |
| 45 | RenderSurfaceImpl* renderSurface = owningLayer->render_surface(); |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 46 | gfx::Rect testRect = gfx::Rect(gfx::Point(3, 4), gfx::Size(5, 6)); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 47 | owningLayer->ResetAllChangeTrackingForSubtree(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | |
| 49 | // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChanged() are |
| 50 | // the only sources of change. |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 51 | EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->SetClipRect(testRect)); |
| 52 | EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->SetContentRect(testRect)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 53 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 54 | owningLayer->SetOpacity(0.5f); |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 55 | EXPECT_TRUE(renderSurface->SurfacePropertyChanged()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 56 | owningLayer->ResetAllChangeTrackingForSubtree(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 57 | |
| 58 | // Setting the surface properties to the same values again should not be considered "change". |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 59 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetClipRect(testRect)); |
| 60 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetContentRect(testRect)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 61 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 62 | scoped_ptr<LayerImpl> dummyMask = LayerImpl::Create(hostImpl.active_tree(), 2); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 63 | gfx::Transform dummyMatrix; |
| 64 | dummyMatrix.Translate(1.0, 2.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 65 | |
| 66 | // The rest of the surface properties are either internal and should not cause change, |
| 67 | // or they are already accounted for by the owninglayer->layerPropertyChanged(). |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 68 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetDrawOpacity(0.5f)); |
| 69 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetDrawTransform(dummyMatrix)); |
| 70 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetReplicaDrawTransform(dummyMatrix)); |
| 71 | EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->ClearLayerLists()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 72 | } |
| 73 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 74 | TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 75 | { |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 76 | FakeImplProxy proxy; |
| 77 | FakeLayerTreeHostImpl hostImpl(&proxy); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 78 | scoped_ptr<LayerImpl> rootLayer = LayerImpl::Create(hostImpl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 79 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 80 | scoped_ptr<LayerImpl> owningLayer = LayerImpl::Create(hostImpl.active_tree(), 2); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 81 | owningLayer->CreateRenderSurface(); |
| 82 | ASSERT_TRUE(owningLayer->render_surface()); |
| 83 | owningLayer->draw_properties().render_target = owningLayer.get(); |
| 84 | RenderSurfaceImpl* renderSurface = owningLayer->render_surface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 85 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 86 | rootLayer->AddChild(owningLayer.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 87 | |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 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)); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 90 | gfx::Transform origin; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 91 | |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 92 | origin.Translate(30, 40); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 93 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 94 | renderSurface->SetDrawTransform(origin); |
| 95 | renderSurface->SetContentRect(contentRect); |
| 96 | renderSurface->SetClipRect(clipRect); |
| 97 | renderSurface->SetDrawOpacity(1.f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 98 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 99 | QuadList quadList; |
| 100 | SharedQuadStateList sharedStateList; |
| 101 | MockQuadCuller mockQuadCuller(quadList, sharedStateList); |
| 102 | AppendQuadsData appendQuadsData; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | |
| 104 | bool forReplica = false; |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 105 | renderSurface->AppendQuads(&mockQuadCuller, &appendQuadsData, forReplica, RenderPass::Id(2, 0)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 106 | |
| 107 | ASSERT_EQ(1u, sharedStateList.size()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 108 | SharedQuadState* sharedQuadState = sharedStateList[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 109 | |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 110 | EXPECT_EQ(30, sharedQuadState->content_to_target_transform.matrix().getDouble(0, 3)); |
| 111 | EXPECT_EQ(40, sharedQuadState->content_to_target_transform.matrix().getDouble(1, 3)); |
[email protected] | cb7af74 | 2012-11-21 04:02:24 | [diff] [blame] | 112 | EXPECT_RECT_EQ(contentRect, gfx::Rect(sharedQuadState->visible_content_rect)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 113 | EXPECT_EQ(1, sharedQuadState->opacity); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 114 | } |
| 115 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 116 | class TestRenderPassSink : public RenderPassSink { |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 117 | public: |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 118 | virtual void AppendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE { m_renderPasses.push_back(renderPass.Pass()); } |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 119 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 120 | const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPasses; } |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 121 | |
| 122 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 123 | ScopedPtrVector<RenderPass> m_renderPasses; |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 124 | }; |
| 125 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 126 | TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass) |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 127 | { |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 128 | FakeImplProxy proxy; |
| 129 | FakeLayerTreeHostImpl hostImpl(&proxy); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 130 | scoped_ptr<LayerImpl> rootLayer = LayerImpl::Create(hostImpl.active_tree(), 1); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 131 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 132 | scoped_ptr<LayerImpl> owningLayer = LayerImpl::Create(hostImpl.active_tree(), 2); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 133 | owningLayer->CreateRenderSurface(); |
| 134 | ASSERT_TRUE(owningLayer->render_surface()); |
| 135 | owningLayer->draw_properties().render_target = owningLayer.get(); |
| 136 | RenderSurfaceImpl* renderSurface = owningLayer->render_surface(); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 137 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 138 | rootLayer->AddChild(owningLayer.Pass()); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 139 | |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 140 | gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 141 | gfx::Transform origin; |
| 142 | origin.Translate(30, 40); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 143 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 144 | renderSurface->SetScreenSpaceTransform(origin); |
| 145 | renderSurface->SetContentRect(contentRect); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 146 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 147 | TestRenderPassSink passSink; |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 148 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 149 | renderSurface->AppendRenderPasses(&passSink); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 150 | |
| 151 | ASSERT_EQ(1u, passSink.renderPasses().size()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 152 | RenderPass* pass = passSink.renderPasses()[0]; |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 153 | |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 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); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 157 | } |
| 158 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 159 | } // namespace |
| 160 | } // namespace cc |