blob: e59a2a1db7827e8caba7606994845c7e176938cd [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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
7#include "CCRenderSurface.h"
8
[email protected]89228202012-08-29 03:20:309#include "CCAppendQuadsData.h"
[email protected]94f206c12012-08-25 00:09:1410#include "CCLayerImpl.h"
[email protected]467b3612012-08-28 07:41:1611#include "CCRenderPassSink.h"
[email protected]87cea5372012-09-26 18:59:5612#include "cc/scoped_ptr_vector.h"
[email protected]4456eee22012-10-19 18:16:3813#include "cc/shared_quad_state.h"
14#include "cc/single_thread_proxy.h"
[email protected]1fea8142012-10-20 04:12:4115#include "cc/test/geometry_test_utils.h"
[email protected]101441ce2012-10-16 01:45:0316#include "cc/test/mock_quad_culler.h"
[email protected]7f0c53db2012-10-02 00:23:1817#include "testing/gmock/include/gmock/gmock.h"
18#include "testing/gtest/include/gtest/gtest.h"
[email protected]94f206c12012-08-25 00:09:1419#include <public/WebTransformationMatrix.h>
20
[email protected]9c88e562012-09-14 22:21:3021using namespace cc;
[email protected]94f206c12012-08-25 00:09:1422using WebKit::WebTransformationMatrix;
23
24namespace {
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]c753e25a2012-10-19 21:22:4236TEST(CCRenderSurfaceTest, verifySurfaceChangesAreTrackedProperly)
[email protected]94f206c12012-08-25 00:09:1437{
38 //
39 // This test checks that surfacePropertyChanged() has the correct behavior.
40 //
41
42 // This will fake that we are on the correct thread for testing purposes.
43 DebugScopedSetImplThread setImplThread;
44
[email protected]c753e25a2012-10-19 21:22:4245 scoped_ptr<CCLayerImpl> owningLayer = CCLayerImpl::create(1);
[email protected]94f206c12012-08-25 00:09:1446 owningLayer->createRenderSurface();
47 ASSERT_TRUE(owningLayer->renderSurface());
[email protected]c753e25a2012-10-19 21:22:4248 CCRenderSurface* renderSurface = owningLayer->renderSurface();
[email protected]94f206c12012-08-25 00:09:1449 IntRect testRect = IntRect(IntPoint(3, 4), IntSize(5, 6));
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]c753e25a2012-10-19 21:22:4265 scoped_ptr<CCLayerImpl> dummyMask = CCLayerImpl::create(1);
[email protected]94f206c12012-08-25 00:09:1466 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]7d929c02012-09-20 17:26:5774 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerLists());
[email protected]94f206c12012-08-25 00:09:1475}
76
[email protected]c753e25a2012-10-19 21:22:4277TEST(CCRenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState)
[email protected]94f206c12012-08-25 00:09:1478{
79 // This will fake that we are on the correct thread for testing purposes.
80 DebugScopedSetImplThread setImplThread;
81
[email protected]c753e25a2012-10-19 21:22:4282 scoped_ptr<CCLayerImpl> rootLayer = CCLayerImpl::create(1);
[email protected]94f206c12012-08-25 00:09:1483
[email protected]c753e25a2012-10-19 21:22:4284 scoped_ptr<CCLayerImpl> owningLayer = CCLayerImpl::create(2);
[email protected]94f206c12012-08-25 00:09:1485 owningLayer->createRenderSurface();
86 ASSERT_TRUE(owningLayer->renderSurface());
87 owningLayer->setRenderTarget(owningLayer.get());
[email protected]c753e25a2012-10-19 21:22:4288 CCRenderSurface* renderSurface = owningLayer->renderSurface();
[email protected]94f206c12012-08-25 00:09:1489
[email protected]e0bd43a2012-10-12 16:54:2190 rootLayer->addChild(owningLayer.Pass());
[email protected]94f206c12012-08-25 00:09:1491
92 IntRect contentRect = IntRect(IntPoint::zero(), IntSize(50, 50));
93 IntRect clipRect = IntRect(IntPoint(5, 5), IntSize(40, 40));
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]c753e25a2012-10-19 21:22:42103 CCQuadList quadList;
104 CCSharedQuadStateList sharedStateList;
105 MockCCQuadCuller mockQuadCuller(quadList, sharedStateList);
106 CCAppendQuadsData appendQuadsData;
[email protected]94f206c12012-08-25 00:09:14107
108 bool forReplica = false;
[email protected]c753e25a2012-10-19 21:22:42109 renderSurface->appendQuads(mockQuadCuller, appendQuadsData, forReplica, CCRenderPass::Id(2, 0));
[email protected]94f206c12012-08-25 00:09:14110
111 ASSERT_EQ(1u, sharedStateList.size());
[email protected]c753e25a2012-10-19 21:22:42112 CCSharedQuadState* sharedQuadState = sharedStateList[0];
[email protected]94f206c12012-08-25 00:09:14113
114 EXPECT_EQ(30, sharedQuadState->quadTransform.m41());
115 EXPECT_EQ(40, sharedQuadState->quadTransform.m42());
[email protected]1fea8142012-10-20 04:12:41116 EXPECT_RECT_EQ(contentRect, IntRect(sharedQuadState->visibleContentRect));
[email protected]94f206c12012-08-25 00:09:14117 EXPECT_EQ(1, sharedQuadState->opacity);
118 EXPECT_FALSE(sharedQuadState->opaque);
119}
120
[email protected]c753e25a2012-10-19 21:22:42121class TestCCRenderPassSink : public CCRenderPassSink {
[email protected]467b3612012-08-28 07:41:16122public:
[email protected]c753e25a2012-10-19 21:22:42123 virtual void appendRenderPass(scoped_ptr<CCRenderPass> renderPass) OVERRIDE { m_renderPasses.append(renderPass.Pass()); }
[email protected]467b3612012-08-28 07:41:16124
[email protected]c753e25a2012-10-19 21:22:42125 const ScopedPtrVector<CCRenderPass>& renderPasses() const { return m_renderPasses; }
[email protected]467b3612012-08-28 07:41:16126
127private:
[email protected]c753e25a2012-10-19 21:22:42128 ScopedPtrVector<CCRenderPass> m_renderPasses;
[email protected]467b3612012-08-28 07:41:16129};
130
[email protected]c753e25a2012-10-19 21:22:42131TEST(CCRenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass)
[email protected]467b3612012-08-28 07:41:16132{
133 // This will fake that we are on the correct thread for testing purposes.
134 DebugScopedSetImplThread setImplThread;
135
[email protected]c753e25a2012-10-19 21:22:42136 scoped_ptr<CCLayerImpl> rootLayer = CCLayerImpl::create(1);
[email protected]467b3612012-08-28 07:41:16137
[email protected]c753e25a2012-10-19 21:22:42138 scoped_ptr<CCLayerImpl> owningLayer = CCLayerImpl::create(2);
[email protected]467b3612012-08-28 07:41:16139 owningLayer->createRenderSurface();
140 ASSERT_TRUE(owningLayer->renderSurface());
141 owningLayer->setRenderTarget(owningLayer.get());
[email protected]c753e25a2012-10-19 21:22:42142 CCRenderSurface* renderSurface = owningLayer->renderSurface();
[email protected]467b3612012-08-28 07:41:16143
[email protected]e0bd43a2012-10-12 16:54:21144 rootLayer->addChild(owningLayer.Pass());
[email protected]467b3612012-08-28 07:41:16145
146 IntRect contentRect = IntRect(IntPoint::zero(), IntSize(50, 50));
147 WebTransformationMatrix origin;
148 origin.translate(30, 40);
149
150 renderSurface->setScreenSpaceTransform(origin);
151 renderSurface->setContentRect(contentRect);
152
[email protected]c753e25a2012-10-19 21:22:42153 TestCCRenderPassSink passSink;
[email protected]467b3612012-08-28 07:41:16154
155 renderSurface->appendRenderPasses(passSink);
156
157 ASSERT_EQ(1u, passSink.renderPasses().size());
[email protected]c753e25a2012-10-19 21:22:42158 CCRenderPass* pass = passSink.renderPasses()[0];
[email protected]467b3612012-08-28 07:41:16159
[email protected]c753e25a2012-10-19 21:22:42160 EXPECT_EQ(CCRenderPass::Id(2, 0), pass->id());
[email protected]1fea8142012-10-20 04:12:41161 EXPECT_RECT_EQ(contentRect, pass->outputRect());
[email protected]467b3612012-08-28 07:41:16162 EXPECT_EQ(origin, pass->transformToRootTarget());
163}
164
[email protected]94f206c12012-08-25 00:09:14165} // namespace