blob: be35ac129fea2a6601377c430c2d174262860b2e [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
[email protected]d50c6862012-10-23 02:08:317#include "cc/render_surface_impl.h"
[email protected]94f206c12012-08-25 00:09:148
[email protected]aa0a9d32012-10-24 01:58:109#include "cc/append_quads_data.h"
[email protected]d50c6862012-10-23 02:08:3110#include "cc/layer_impl.h"
[email protected]55a124d02012-10-22 03:07:1311#include "cc/render_pass_sink.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]96baf3e2012-10-22 23:09:5536TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly)
[email protected]94f206c12012-08-25 00:09:1437{
38 //
39 // This test checks that surfacePropertyChanged() has the correct behavior.
40 //
41
[email protected]5bc29a22012-11-01 21:21:5942 // This will fake that we are on the correct thread for testing purposes.
43 DebugScopedSetImplThread setImplThread;
44
[email protected]96baf3e2012-10-22 23:09:5545 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(1);
[email protected]94f206c12012-08-25 00:09:1446 owningLayer->createRenderSurface();
47 ASSERT_TRUE(owningLayer->renderSurface());
[email protected]96baf3e2012-10-22 23:09:5548 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
[email protected]d0f98362012-11-01 23:02:3849 gfx::Rect testRect = gfx::Rect(gfx::Point(3, 4), gfx::Size(5, 6));
[email protected]94f206c12012-08-25 00:09:1450 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]96baf3e2012-10-22 23:09:5565 scoped_ptr<LayerImpl> dummyMask = LayerImpl::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]96baf3e2012-10-22 23:09:5577TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState)
[email protected]94f206c12012-08-25 00:09:1478{
[email protected]5bc29a22012-11-01 21:21:5979 // This will fake that we are on the correct thread for testing purposes.
80 DebugScopedSetImplThread setImplThread;
81
[email protected]96baf3e2012-10-22 23:09:5582 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1);
[email protected]94f206c12012-08-25 00:09:1483
[email protected]96baf3e2012-10-22 23:09:5584 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2);
[email protected]94f206c12012-08-25 00:09:1485 owningLayer->createRenderSurface();
86 ASSERT_TRUE(owningLayer->renderSurface());
87 owningLayer->setRenderTarget(owningLayer.get());
[email protected]96baf3e2012-10-22 23:09:5588 RenderSurfaceImpl* 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
[email protected]d0f98362012-11-01 23:02:3892 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]94f206c12012-08-25 00:09:1494 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]96baf3e2012-10-22 23:09:55103 QuadList quadList;
104 SharedQuadStateList sharedStateList;
105 MockQuadCuller mockQuadCuller(quadList, sharedStateList);
106 AppendQuadsData appendQuadsData;
[email protected]94f206c12012-08-25 00:09:14107
108 bool forReplica = false;
[email protected]96baf3e2012-10-22 23:09:55109 renderSurface->appendQuads(mockQuadCuller, appendQuadsData, forReplica, RenderPass::Id(2, 0));
[email protected]94f206c12012-08-25 00:09:14110
111 ASSERT_EQ(1u, sharedStateList.size());
[email protected]96baf3e2012-10-22 23:09:55112 SharedQuadState* 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]d0f98362012-11-01 23:02:38116 EXPECT_RECT_EQ(contentRect, gfx::Rect(sharedQuadState->visibleContentRect));
[email protected]94f206c12012-08-25 00:09:14117 EXPECT_EQ(1, sharedQuadState->opacity);
118 EXPECT_FALSE(sharedQuadState->opaque);
119}
120
[email protected]96baf3e2012-10-22 23:09:55121class TestRenderPassSink : public RenderPassSink {
[email protected]467b3612012-08-28 07:41:16122public:
[email protected]96baf3e2012-10-22 23:09:55123 virtual void appendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE { m_renderPasses.append(renderPass.Pass()); }
[email protected]467b3612012-08-28 07:41:16124
[email protected]96baf3e2012-10-22 23:09:55125 const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPasses; }
[email protected]467b3612012-08-28 07:41:16126
127private:
[email protected]96baf3e2012-10-22 23:09:55128 ScopedPtrVector<RenderPass> m_renderPasses;
[email protected]467b3612012-08-28 07:41:16129};
130
[email protected]96baf3e2012-10-22 23:09:55131TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass)
[email protected]467b3612012-08-28 07:41:16132{
[email protected]5bc29a22012-11-01 21:21:59133 // This will fake that we are on the correct thread for testing purposes.
134 DebugScopedSetImplThread setImplThread;
135
[email protected]96baf3e2012-10-22 23:09:55136 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1);
[email protected]467b3612012-08-28 07:41:16137
[email protected]96baf3e2012-10-22 23:09:55138 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2);
[email protected]467b3612012-08-28 07:41:16139 owningLayer->createRenderSurface();
140 ASSERT_TRUE(owningLayer->renderSurface());
141 owningLayer->setRenderTarget(owningLayer.get());
[email protected]96baf3e2012-10-22 23:09:55142 RenderSurfaceImpl* 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
[email protected]d0f98362012-11-01 23:02:38146 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50));
[email protected]467b3612012-08-28 07:41:16147 WebTransformationMatrix origin;
148 origin.translate(30, 40);
149
150 renderSurface->setScreenSpaceTransform(origin);
151 renderSurface->setContentRect(contentRect);
152
[email protected]96baf3e2012-10-22 23:09:55153 TestRenderPassSink passSink;
[email protected]467b3612012-08-28 07:41:16154
155 renderSurface->appendRenderPasses(passSink);
156
157 ASSERT_EQ(1u, passSink.renderPasses().size());
[email protected]96baf3e2012-10-22 23:09:55158 RenderPass* pass = passSink.renderPasses()[0];
[email protected]467b3612012-08-28 07:41:16159
[email protected]96baf3e2012-10-22 23:09:55160 EXPECT_EQ(RenderPass::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