Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1094)

Side by Side Diff: cc/render_surface_unittest.cc

Issue 11472021: cc: Pass LayerTreeHostImpl to LayerImpl constructor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/quad_culler_unittest.cc ('k') | cc/scrollbar_animation_controller_linear_fade_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/render_surface_impl.h" 5 #include "cc/render_surface_impl.h"
6 6
7 #include "cc/append_quads_data.h" 7 #include "cc/append_quads_data.h"
8 #include "cc/layer_impl.h" 8 #include "cc/layer_impl.h"
9 #include "cc/render_pass_sink.h" 9 #include "cc/render_pass_sink.h"
10 #include "cc/scoped_ptr_vector.h" 10 #include "cc/scoped_ptr_vector.h"
11 #include "cc/shared_quad_state.h" 11 #include "cc/shared_quad_state.h"
12 #include "cc/single_thread_proxy.h" 12 #include "cc/single_thread_proxy.h"
13 #include "cc/test/fake_impl_proxy.h"
14 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/geometry_test_utils.h" 15 #include "cc/test/geometry_test_utils.h"
14 #include "cc/test/mock_quad_culler.h" 16 #include "cc/test/mock_quad_culler.h"
15 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/gfx/transform.h" 19 #include "ui/gfx/transform.h"
18 20
19 namespace cc { 21 namespace cc {
20 namespace { 22 namespace {
21 23
22 #define EXECUTE_AND_VERIFY_SURFACE_CHANGED(codeToTest) \ 24 #define EXECUTE_AND_VERIFY_SURFACE_CHANGED(codeToTest) \
23 renderSurface->resetPropertyChangedFlag(); \ 25 renderSurface->resetPropertyChangedFlag(); \
24 codeToTest; \ 26 codeToTest; \
25 EXPECT_TRUE(renderSurface->surfacePropertyChanged()) 27 EXPECT_TRUE(renderSurface->surfacePropertyChanged())
26 28
27 #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \ 29 #define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest) \
28 renderSurface->resetPropertyChangedFlag(); \ 30 renderSurface->resetPropertyChangedFlag(); \
29 codeToTest; \ 31 codeToTest; \
30 EXPECT_FALSE(renderSurface->surfacePropertyChanged()) 32 EXPECT_FALSE(renderSurface->surfacePropertyChanged())
31 33
32 TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly) 34 TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly)
33 { 35 {
34 // 36 //
35 // This test checks that surfacePropertyChanged() has the correct behavior. 37 // This test checks that surfacePropertyChanged() has the correct behavior.
36 // 38 //
37 39
38 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(1); 40 FakeImplProxy proxy;
41 FakeLayerTreeHostImpl hostImpl(&proxy);
42 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(&hostImpl, 1);
39 owningLayer->createRenderSurface(); 43 owningLayer->createRenderSurface();
40 ASSERT_TRUE(owningLayer->renderSurface()); 44 ASSERT_TRUE(owningLayer->renderSurface());
41 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); 45 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
42 gfx::Rect testRect = gfx::Rect(gfx::Point(3, 4), gfx::Size(5, 6)); 46 gfx::Rect testRect = gfx::Rect(gfx::Point(3, 4), gfx::Size(5, 6));
43 owningLayer->resetAllChangeTrackingForSubtree(); 47 owningLayer->resetAllChangeTrackingForSubtree();
44 48
45 // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChang ed() are 49 // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChang ed() are
46 // the only sources of change. 50 // the only sources of change.
47 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setClipRect(testRect)); 51 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setClipRect(testRect));
48 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setContentRect(testRect)); 52 EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setContentRect(testRect));
49 53
50 owningLayer->setOpacity(0.5f); 54 owningLayer->setOpacity(0.5f);
51 EXPECT_TRUE(renderSurface->surfacePropertyChanged()); 55 EXPECT_TRUE(renderSurface->surfacePropertyChanged());
52 owningLayer->resetAllChangeTrackingForSubtree(); 56 owningLayer->resetAllChangeTrackingForSubtree();
53 57
54 // Setting the surface properties to the same values again should not be con sidered "change". 58 // Setting the surface properties to the same values again should not be con sidered "change".
55 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRec t)); 59 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRec t));
56 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(test Rect)); 60 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(test Rect));
57 61
58 scoped_ptr<LayerImpl> dummyMask = LayerImpl::create(1); 62 scoped_ptr<LayerImpl> dummyMask = LayerImpl::create(&hostImpl, 1);
59 gfx::Transform dummyMatrix; 63 gfx::Transform dummyMatrix;
60 dummyMatrix.Translate(1.0, 2.0); 64 dummyMatrix.Translate(1.0, 2.0);
61 65
62 // The rest of the surface properties are either internal and should not cau se change, 66 // The rest of the surface properties are either internal and should not cau se change,
63 // or they are already accounted for by the owninglayer->layerPropertyChange d(). 67 // or they are already accounted for by the owninglayer->layerPropertyChange d().
64 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawOpacity(0.5) ); 68 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawOpacity(0.5) );
65 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawTransform(du mmyMatrix)); 69 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawTransform(du mmyMatrix));
66 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setReplicaDrawTrans form(dummyMatrix)); 70 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setReplicaDrawTrans form(dummyMatrix));
67 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerLists()); 71 EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerLists());
68 } 72 }
69 73
70 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState) 74 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState)
71 { 75 {
72 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); 76 FakeImplProxy proxy;
77 FakeLayerTreeHostImpl hostImpl(&proxy);
78 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(&hostImpl, 1);
73 79
74 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); 80 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(&hostImpl, 2);
75 owningLayer->createRenderSurface(); 81 owningLayer->createRenderSurface();
76 ASSERT_TRUE(owningLayer->renderSurface()); 82 ASSERT_TRUE(owningLayer->renderSurface());
77 owningLayer->drawProperties().render_target = owningLayer.get(); 83 owningLayer->drawProperties().render_target = owningLayer.get();
78 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); 84 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
79 85
80 rootLayer->addChild(owningLayer.Pass()); 86 rootLayer->addChild(owningLayer.Pass());
81 87
82 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); 88 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50));
83 gfx::Rect clipRect = gfx::Rect(gfx::Point(5, 5), gfx::Size(40, 40)); 89 gfx::Rect clipRect = gfx::Rect(gfx::Point(5, 5), gfx::Size(40, 40));
84 gfx::Transform origin; 90 gfx::Transform origin;
(...skipping 27 matching lines...) Expand all
112 virtual void appendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE { m_renderPasses.append(renderPass.Pass()); } 118 virtual void appendRenderPass(scoped_ptr<RenderPass> renderPass) OVERRIDE { m_renderPasses.append(renderPass.Pass()); }
113 119
114 const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPas ses; } 120 const ScopedPtrVector<RenderPass>& renderPasses() const { return m_renderPas ses; }
115 121
116 private: 122 private:
117 ScopedPtrVector<RenderPass> m_renderPasses; 123 ScopedPtrVector<RenderPass> m_renderPasses;
118 }; 124 };
119 125
120 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass) 126 TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass)
121 { 127 {
122 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); 128 FakeImplProxy proxy;
129 FakeLayerTreeHostImpl hostImpl(&proxy);
130 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(&hostImpl, 1);
123 131
124 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); 132 scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(&hostImpl, 2);
125 owningLayer->createRenderSurface(); 133 owningLayer->createRenderSurface();
126 ASSERT_TRUE(owningLayer->renderSurface()); 134 ASSERT_TRUE(owningLayer->renderSurface());
127 owningLayer->drawProperties().render_target = owningLayer.get(); 135 owningLayer->drawProperties().render_target = owningLayer.get();
128 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); 136 RenderSurfaceImpl* renderSurface = owningLayer->renderSurface();
129 137
130 rootLayer->addChild(owningLayer.Pass()); 138 rootLayer->addChild(owningLayer.Pass());
131 139
132 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50)); 140 gfx::Rect contentRect = gfx::Rect(gfx::Point(), gfx::Size(50, 50));
133 gfx::Transform origin; 141 gfx::Transform origin;
134 origin.Translate(30, 40); 142 origin.Translate(30, 40);
135 143
136 renderSurface->setScreenSpaceTransform(origin); 144 renderSurface->setScreenSpaceTransform(origin);
137 renderSurface->setContentRect(contentRect); 145 renderSurface->setContentRect(contentRect);
138 146
139 TestRenderPassSink passSink; 147 TestRenderPassSink passSink;
140 148
141 renderSurface->appendRenderPasses(passSink); 149 renderSurface->appendRenderPasses(passSink);
142 150
143 ASSERT_EQ(1u, passSink.renderPasses().size()); 151 ASSERT_EQ(1u, passSink.renderPasses().size());
144 RenderPass* pass = passSink.renderPasses()[0]; 152 RenderPass* pass = passSink.renderPasses()[0];
145 153
146 EXPECT_EQ(RenderPass::Id(2, 0), pass->id); 154 EXPECT_EQ(RenderPass::Id(2, 0), pass->id);
147 EXPECT_RECT_EQ(contentRect, pass->output_rect); 155 EXPECT_RECT_EQ(contentRect, pass->output_rect);
148 EXPECT_EQ(origin, pass->transform_to_root_target); 156 EXPECT_EQ(origin, pass->transform_to_root_target);
149 } 157 }
150 158
151 } // namespace 159 } // namespace
152 } // namespace cc 160 } // namespace cc
OLDNEW
« no previous file with comments | « cc/quad_culler_unittest.cc ('k') | cc/scrollbar_animation_controller_linear_fade_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698