blob: bc5b78f175780f48171031ea5aa6c38e2822f310 [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
[email protected]d50c6862012-10-23 02:08:315#include "cc/render_surface_impl.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]aa0a9d32012-10-24 01:58:107#include "cc/append_quads_data.h"
[email protected]d50c6862012-10-23 02:08:318#include "cc/layer_impl.h"
[email protected]55a124d02012-10-22 03:07:139#include "cc/render_pass_sink.h"
[email protected]87cea5372012-09-26 18:59:5610#include "cc/scoped_ptr_vector.h"
[email protected]4456eee22012-10-19 18:16:3811#include "cc/shared_quad_state.h"
12#include "cc/single_thread_proxy.h"
[email protected]1fea8142012-10-20 04:12:4113#include "cc/test/geometry_test_utils.h"
[email protected]101441ce2012-10-16 01:45:0314#include "cc/test/mock_quad_culler.h"
[email protected]7f0c53db2012-10-02 00:23:1815#include "testing/gmock/include/gmock/gmock.h"
16#include "testing/gtest/include/gtest/gtest.h"
[email protected]94f206c12012-08-25 00:09:1417#include <public/WebTransformationMatrix.h>
18
[email protected]94f206c12012-08-25 00:09:1419using WebKit::WebTransformationMatrix;
20
[email protected]ba565742012-11-10 09:29:4821namespace cc {
[email protected]94f206c12012-08-25 00:09:1422namespace {
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]96baf3e2012-10-22 23:09:5534TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly)
[email protected]94f206c12012-08-25 00:09:1435{
36 //
37 // This test checks that surfacePropertyChanged() has the correct behavior.
38 //
39
[email protected]96baf3e2012-10-22 23:09:5540 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(1);
[email protected]94f206c12012-08-25 00:09:1441 owningLayer->createRenderSurface();
42 ASSERT_TRUE(owningLayer->renderSurface());
[email protected]96baf3e2012-10-22 23:09:5543 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
[email protected]d0f98362012-11-01 23:02:3844 gfx::Rect testRect = gfx::Rect(gfx::Point(3, 4), gfx::Size(5, 6));
[email protected]94f206c12012-08-25 00:09:1445 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]96baf3e2012-10-22 23:09:5560 scoped_ptr<LayerImpl> dummyMask = LayerImpl::create(1);
[email protected]94f206c12012-08-25 00:09:1461 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]7d929c02012-09-20 17:26:5769 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerLists());
[email protected]94f206c12012-08-25 00:09:1470}
71
[email protected]96baf3e2012-10-22 23:09:5572TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState)
[email protected]94f206c12012-08-25 00:09:1473{
[email protected]96baf3e2012-10-22 23:09:5574 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1);
[email protected]94f206c12012-08-25 00:09:1475
[email protected]96baf3e2012-10-22 23:09:5576 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2);
[email protected]94f206c12012-08-25 00:09:1477 owningLayer->createRenderSurface();
78 ASSERT_TRUE(owningLayer->renderSurface());
79 owningLayer->setRenderTarget(owningLayer.get());
[email protected]96baf3e2012-10-22 23:09:5580 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
[email protected]94f206c12012-08-25 00:09:1481
[email protected]e0bd43a2012-10-12 16:54:2182 rootLayer->addChild(owningLayer.Pass());
[email protected]94f206c12012-08-25 00:09:1483
[email protected]d0f98362012-11-01 23:02:3884 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]94f206c12012-08-25 00:09:1486 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]96baf3e2012-10-22 23:09:5595 QuadList quadList;
96 SharedQuadStateList sharedStateList;
97 MockQuadCuller mockQuadCuller(quadList, sharedStateList);
98 AppendQuadsData appendQuadsData;
[email protected]94f206c12012-08-25 00:09:1499
100 bool forReplica = false;
[email protected]96baf3e2012-10-22 23:09:55101 renderSurface->appendQuads(mockQuadCuller, appendQuadsData, forReplica, RenderPass::Id(2, 0));
[email protected]94f206c12012-08-25 00:09:14102
103 ASSERT_EQ(1u, sharedStateList.size());
[email protected]96baf3e2012-10-22 23:09:55104 SharedQuadState* sharedQuadState = sharedStateList[0];
[email protected]94f206c12012-08-25 00:09:14105
[email protected]cb7af742012-11-21 04:02:24106 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]94f206c12012-08-25 00:09:14109 EXPECT_EQ(1, sharedQuadState->opacity);
[email protected]94f206c12012-08-25 00:09:14110}
111
[email protected]96baf3e2012-10-22 23:09:55112class TestRenderPassSink : public RenderPassSink {
[email protected]467b3612012-08-28 07:41:16113public:
[email protected]96baf3e2012-10-22 23:09:55114 virtual void appendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE { m_renderPasses.append(renderPass.Pass()); }
[email protected]467b3612012-08-28 07:41:16115
[email protected]96baf3e2012-10-22 23:09:55116 const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPasses; }
[email protected]467b3612012-08-28 07:41:16117
118private:
[email protected]96baf3e2012-10-22 23:09:55119 ScopedPtrVector<RenderPass> m_renderPasses;
[email protected]467b3612012-08-28 07:41:16120};
121
[email protected]96baf3e2012-10-22 23:09:55122TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass)
[email protected]467b3612012-08-28 07:41:16123{
[email protected]96baf3e2012-10-22 23:09:55124 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1);
[email protected]467b3612012-08-28 07:41:16125
[email protected]96baf3e2012-10-22 23:09:55126 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2);
[email protected]467b3612012-08-28 07:41:16127 owningLayer->createRenderSurface();
128 ASSERT_TRUE(owningLayer->renderSurface());
129 owningLayer->setRenderTarget(owningLayer.get());
[email protected]96baf3e2012-10-22 23:09:55130 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
[email protected]467b3612012-08-28 07:41:16131
[email protected]e0bd43a2012-10-12 16:54:21132 rootLayer->addChild(owningLayer.Pass());
[email protected]467b3612012-08-28 07:41:16133
[email protected]d0f98362012-11-01 23:02:38134 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50));
[email protected]467b3612012-08-28 07:41:16135 WebTransformationMatrix origin;
136 origin.translate(30, 40);
137
138 renderSurface->setScreenSpaceTransform(origin);
139 renderSurface->setContentRect(contentRect);
140
[email protected]96baf3e2012-10-22 23:09:55141 TestRenderPassSink passSink;
[email protected]467b3612012-08-28 07:41:16142
143 renderSurface->appendRenderPasses(passSink);
144
145 ASSERT_EQ(1u, passSink.renderPasses().size());
[email protected]96baf3e2012-10-22 23:09:55146 RenderPass* pass = passSink.renderPasses()[0];
[email protected]467b3612012-08-28 07:41:16147
[email protected]96baf3e2012-10-22 23:09:55148 EXPECT_EQ(RenderPass::Id(2, 0), pass->id());
[email protected]1fea8142012-10-20 04:12:41149 EXPECT_RECT_EQ(contentRect, pass->outputRect());
[email protected]467b3612012-08-28 07:41:16150 EXPECT_EQ(origin, pass->transformToRootTarget());
151}
152
[email protected]ba565742012-11-10 09:29:48153} // namespace
154} // namespace cc