blob: d848f11803c02f5f0b39820a6d806c44aadf8bcf [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]586d51ed2012-12-07 20:31:4513#include "cc/test/fake_impl_proxy.h"
14#include "cc/test/fake_layer_tree_host_impl.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]c8686a02012-11-27 08:29:0019#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1420
[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) \
[email protected]d2d915aa2013-03-08 20:18:1225 renderSurface->ResetPropertyChangedFlag(); \
[email protected]94f206c12012-08-25 00:09:1426 codeToTest; \
[email protected]d2d915aa2013-03-08 20:18:1227 EXPECT_TRUE(renderSurface->SurfacePropertyChanged())
[email protected]94f206c12012-08-25 00:09:1428
29#define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \
[email protected]d2d915aa2013-03-08 20:18:1230 renderSurface->ResetPropertyChangedFlag(); \
[email protected]94f206c12012-08-25 00:09:1431 codeToTest; \
[email protected]d2d915aa2013-03-08 20:18:1232 EXPECT_FALSE(renderSurface->SurfacePropertyChanged())
[email protected]94f206c12012-08-25 00:09:1433
[email protected]96baf3e2012-10-22 23:09:5534TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly)
[email protected]94f206c12012-08-25 00:09:1435{
36 //
[email protected]d2d915aa2013-03-08 20:18:1237 // This test checks that SurfacePropertyChanged() has the correct behavior.
[email protected]94f206c12012-08-25 00:09:1438 //
39
[email protected]586d51ed2012-12-07 20:31:4540 FakeImplProxy proxy;
41 FakeLayerTreeHostImpl hostImpl(&proxy);
[email protected]c1bb5af2013-03-13 19:06:2742 scoped_ptr<LayerImpl> owningLayer = LayerImpl::Create(hostImpl.active_tree(), 1);
[email protected]7aba6662013-03-12 10:17:3443 owningLayer->CreateRenderSurface();
44 ASSERT_TRUE(owningLayer->render_surface());
45 RenderSurfaceImpl* renderSurface = owningLayer->render_surface();
[email protected]d0f98362012-11-01 23:02:3846 gfx::Rect testRect = gfx::Rect(gfx::Point(3, 4), gfx::Size(5, 6));
[email protected]7aba6662013-03-12 10:17:3447 owningLayer->ResetAllChangeTrackingForSubtree();
[email protected]94f206c12012-08-25 00:09:1448
49 // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChanged() are
50 // the only sources of change.
[email protected]d2d915aa2013-03-08 20:18:1251 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->SetClipRect(testRect));
52 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->SetContentRect(testRect));
[email protected]94f206c12012-08-25 00:09:1453
[email protected]7aba6662013-03-12 10:17:3454 owningLayer->SetOpacity(0.5f);
[email protected]d2d915aa2013-03-08 20:18:1255 EXPECT_TRUE(renderSurface->SurfacePropertyChanged());
[email protected]7aba6662013-03-12 10:17:3456 owningLayer->ResetAllChangeTrackingForSubtree();
[email protected]94f206c12012-08-25 00:09:1457
58 // Setting the surface properties to the same values again should not be considered "change".
[email protected]d2d915aa2013-03-08 20:18:1259 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetClipRect(testRect));
60 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->SetContentRect(testRect));
[email protected]94f206c12012-08-25 00:09:1461
[email protected]c1bb5af2013-03-13 19:06:2762 scoped_ptr<LayerImpl> dummyMask = LayerImpl::Create(hostImpl.active_tree(), 2);
[email protected]c8686a02012-11-27 08:29:0063 gfx::Transform dummyMatrix;
64 dummyMatrix.Translate(1.0, 2.0);
[email protected]94f206c12012-08-25 00:09:1465
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]d2d915aa2013-03-08 20:18:1268 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]94f206c12012-08-25 00:09:1472}
73
[email protected]96baf3e2012-10-22 23:09:5574TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState)
[email protected]94f206c12012-08-25 00:09:1475{
[email protected]586d51ed2012-12-07 20:31:4576 FakeImplProxy proxy;
77 FakeLayerTreeHostImpl hostImpl(&proxy);
[email protected]c1bb5af2013-03-13 19:06:2778 scoped_ptr<LayerImpl> rootLayer = LayerImpl::Create(hostImpl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:1479
[email protected]c1bb5af2013-03-13 19:06:2780 scoped_ptr<LayerImpl> owningLayer = LayerImpl::Create(hostImpl.active_tree(), 2);
[email protected]7aba6662013-03-12 10:17:3481 owningLayer->CreateRenderSurface();
82 ASSERT_TRUE(owningLayer->render_surface());
83 owningLayer->draw_properties().render_target = owningLayer.get();
84 RenderSurfaceImpl* renderSurface = owningLayer->render_surface();
[email protected]94f206c12012-08-25 00:09:1485
[email protected]7aba6662013-03-12 10:17:3486 rootLayer->AddChild(owningLayer.Pass());
[email protected]94f206c12012-08-25 00:09:1487
[email protected]d0f98362012-11-01 23:02:3888 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]c8686a02012-11-27 08:29:0090 gfx::Transform origin;
[email protected]94f206c12012-08-25 00:09:1491
[email protected]c8686a02012-11-27 08:29:0092 origin.Translate(30, 40);
[email protected]94f206c12012-08-25 00:09:1493
[email protected]d2d915aa2013-03-08 20:18:1294 renderSurface->SetDrawTransform(origin);
95 renderSurface->SetContentRect(contentRect);
96 renderSurface->SetClipRect(clipRect);
97 renderSurface->SetDrawOpacity(1.f);
[email protected]94f206c12012-08-25 00:09:1498
[email protected]96baf3e2012-10-22 23:09:5599 QuadList quadList;
100 SharedQuadStateList sharedStateList;
101 MockQuadCuller mockQuadCuller(quadList, sharedStateList);
102 AppendQuadsData appendQuadsData;
[email protected]94f206c12012-08-25 00:09:14103
104 bool forReplica = false;
[email protected]d2d915aa2013-03-08 20:18:12105 renderSurface->AppendQuads(&mockQuadCuller, &appendQuadsData, forReplica, RenderPass::Id(2, 0));
[email protected]94f206c12012-08-25 00:09:14106
107 ASSERT_EQ(1u, sharedStateList.size());
[email protected]96baf3e2012-10-22 23:09:55108 SharedQuadState* sharedQuadState = sharedStateList[0];
[email protected]94f206c12012-08-25 00:09:14109
[email protected]c8686a02012-11-27 08:29:00110 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]cb7af742012-11-21 04:02:24112 EXPECT_RECT_EQ(contentRect, gfx::Rect(sharedQuadState->visible_content_rect));
[email protected]94f206c12012-08-25 00:09:14113 EXPECT_EQ(1, sharedQuadState->opacity);
[email protected]94f206c12012-08-25 00:09:14114}
115
[email protected]96baf3e2012-10-22 23:09:55116class TestRenderPassSink : public RenderPassSink {
[email protected]467b3612012-08-28 07:41:16117public:
[email protected]c1bb5af2013-03-13 19:06:27118 virtual void AppendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE { m_renderPasses.push_back(renderPass.Pass()); }
[email protected]467b3612012-08-28 07:41:16119
[email protected]96baf3e2012-10-22 23:09:55120 const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPasses; }
[email protected]467b3612012-08-28 07:41:16121
122private:
[email protected]96baf3e2012-10-22 23:09:55123 ScopedPtrVector<RenderPass> m_renderPasses;
[email protected]467b3612012-08-28 07:41:16124};
125
[email protected]96baf3e2012-10-22 23:09:55126TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass)
[email protected]467b3612012-08-28 07:41:16127{
[email protected]586d51ed2012-12-07 20:31:45128 FakeImplProxy proxy;
129 FakeLayerTreeHostImpl hostImpl(&proxy);
[email protected]c1bb5af2013-03-13 19:06:27130 scoped_ptr<LayerImpl> rootLayer = LayerImpl::Create(hostImpl.active_tree(), 1);
[email protected]467b3612012-08-28 07:41:16131
[email protected]c1bb5af2013-03-13 19:06:27132 scoped_ptr<LayerImpl> owningLayer = LayerImpl::Create(hostImpl.active_tree(), 2);
[email protected]7aba6662013-03-12 10:17:34133 owningLayer->CreateRenderSurface();
134 ASSERT_TRUE(owningLayer->render_surface());
135 owningLayer->draw_properties().render_target = owningLayer.get();
136 RenderSurfaceImpl* renderSurface = owningLayer->render_surface();
[email protected]467b3612012-08-28 07:41:16137
[email protected]7aba6662013-03-12 10:17:34138 rootLayer->AddChild(owningLayer.Pass());
[email protected]467b3612012-08-28 07:41:16139
[email protected]d0f98362012-11-01 23:02:38140 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50));
[email protected]c8686a02012-11-27 08:29:00141 gfx::Transform origin;
142 origin.Translate(30, 40);
[email protected]467b3612012-08-28 07:41:16143
[email protected]d2d915aa2013-03-08 20:18:12144 renderSurface->SetScreenSpaceTransform(origin);
145 renderSurface->SetContentRect(contentRect);
[email protected]467b3612012-08-28 07:41:16146
[email protected]96baf3e2012-10-22 23:09:55147 TestRenderPassSink passSink;
[email protected]467b3612012-08-28 07:41:16148
[email protected]d2d915aa2013-03-08 20:18:12149 renderSurface->AppendRenderPasses(&passSink);
[email protected]467b3612012-08-28 07:41:16150
151 ASSERT_EQ(1u, passSink.renderPasses().size());
[email protected]96baf3e2012-10-22 23:09:55152 RenderPass* pass = passSink.renderPasses()[0];
[email protected]467b3612012-08-28 07:41:16153
[email protected]f57bbc02012-11-21 07:02:15154 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]467b3612012-08-28 07:41:16157}
158
[email protected]ba565742012-11-10 09:29:48159} // namespace
160} // namespace cc