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

Side by Side Diff: cc/tiled_layer_impl_unittest.cc

Issue 12774006: cc: Chromify Layer and LayerImpl classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MoreAndroidCompilings Created 7 years, 9 months 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/tiled_layer_impl.cc ('k') | cc/tiled_layer_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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/tiled_layer_impl.h" 5 #include "cc/tiled_layer_impl.h"
6 6
7 #include "cc/append_quads_data.h" 7 #include "cc/append_quads_data.h"
8 #include "cc/layer_tiling_data.h" 8 #include "cc/layer_tiling_data.h"
9 #include "cc/single_thread_proxy.h" 9 #include "cc/single_thread_proxy.h"
10 #include "cc/test/fake_impl_proxy.h" 10 #include "cc/test/fake_impl_proxy.h"
(...skipping 12 matching lines...) Expand all
23 public: 23 public:
24 TiledLayerImplTest() 24 TiledLayerImplTest()
25 : m_hostImpl(&m_proxy) 25 : m_hostImpl(&m_proxy)
26 { 26 {
27 } 27 }
28 28
29 // Create a default tiled layer with textures for all tiles and a default 29 // Create a default tiled layer with textures for all tiles and a default
30 // visibility of the entire layer size. 30 // visibility of the entire layer size.
31 scoped_ptr<TiledLayerImpl> createLayer(const gfx::Size& tileSize, const gfx: :Size& layerSize, LayerTilingData::BorderTexelOption borderTexels) 31 scoped_ptr<TiledLayerImpl> createLayer(const gfx::Size& tileSize, const gfx: :Size& layerSize, LayerTilingData::BorderTexelOption borderTexels)
32 { 32 {
33 scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(m_hostImpl.act iveTree(), 1); 33 scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::Create(m_hostImpl.act iveTree(), 1);
34 scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, bo rderTexels); 34 scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, bo rderTexels);
35 tiler->setBounds(layerSize); 35 tiler->setBounds(layerSize);
36 layer->setTilingData(*tiler); 36 layer->setTilingData(*tiler);
37 layer->setSkipsDraw(false); 37 layer->setSkipsDraw(false);
38 layer->drawProperties().visible_content_rect = gfx::Rect(gfx::Point(), l ayerSize); 38 layer->draw_properties().visible_content_rect = gfx::Rect(gfx::Point(), layerSize);
39 layer->drawProperties().opacity = 1; 39 layer->draw_properties().opacity = 1;
40 layer->setBounds(layerSize); 40 layer->SetBounds(layerSize);
41 layer->setContentBounds(layerSize); 41 layer->SetContentBounds(layerSize);
42 layer->createRenderSurface(); 42 layer->CreateRenderSurface();
43 layer->drawProperties().render_target = layer.get(); 43 layer->draw_properties().render_target = layer.get();
44 44
45 ResourceProvider::ResourceId resourceId = 1; 45 ResourceProvider::ResourceId resourceId = 1;
46 for (int i = 0; i < tiler->numTilesX(); ++i) 46 for (int i = 0; i < tiler->numTilesX(); ++i)
47 for (int j = 0; j < tiler->numTilesY(); ++j) 47 for (int j = 0; j < tiler->numTilesY(); ++j)
48 layer->pushTileProperties(i, j, resourceId++, gfx::Rect(0, 0, 1, 1), false); 48 layer->pushTileProperties(i, j, resourceId++, gfx::Rect(0, 0, 1, 1), false);
49 49
50 return layer.Pass(); 50 return layer.Pass();
51 } 51 }
52 52
53 void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, gfx::Size tileSize, const gfx::Size& layerSize, LayerTilingData::BorderTexelOption borderT exelOption, const gfx::Rect& visibleContentRect) 53 void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, gfx::Size tileSize, const gfx::Size& layerSize, LayerTilingData::BorderTexelOption borderT exelOption, const gfx::Rect& visibleContentRect)
54 { 54 {
55 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, bord erTexelOption); 55 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, bord erTexelOption);
56 layer->drawProperties().visible_content_rect = visibleContentRect; 56 layer->draw_properties().visible_content_rect = visibleContentRect;
57 layer->setBounds(layerSize); 57 layer->SetBounds(layerSize);
58 58
59 MockQuadCuller quadCuller(quads, sharedStates); 59 MockQuadCuller quadCuller(quads, sharedStates);
60 AppendQuadsData data; 60 AppendQuadsData data;
61 layer->appendQuads(quadCuller, data); 61 layer->AppendQuads(&quadCuller, &data);
62 } 62 }
63 63
64 protected: 64 protected:
65 FakeImplProxy m_proxy; 65 FakeImplProxy m_proxy;
66 FakeLayerTreeHostImpl m_hostImpl; 66 FakeLayerTreeHostImpl m_hostImpl;
67 }; 67 };
68 68
69 TEST_F(TiledLayerImplTest, emptyQuadList) 69 TEST_F(TiledLayerImplTest, emptyQuadList)
70 { 70 {
71 const gfx::Size tileSize(90, 90); 71 const gfx::Size tileSize(90, 90);
72 const int numTilesX = 8; 72 const int numTilesX = 8;
73 const int numTilesY = 4; 73 const int numTilesY = 4;
74 const gfx::Size layerSize(tileSize.width() * numTilesX, tileSize.height() * numTilesY); 74 const gfx::Size layerSize(tileSize.width() * numTilesX, tileSize.height() * numTilesY);
75 75
76 // Verify default layer does creates quads 76 // Verify default layer does creates quads
77 { 77 {
78 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels); 78 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels);
79 MockQuadCuller quadCuller; 79 MockQuadCuller quadCuller;
80 AppendQuadsData data; 80 AppendQuadsData data;
81 layer->appendQuads(quadCuller, data); 81 layer->AppendQuads(&quadCuller, &data);
82 const unsigned numTiles = numTilesX * numTilesY; 82 const unsigned numTiles = numTilesX * numTilesY;
83 EXPECT_EQ(quadCuller.quadList().size(), numTiles); 83 EXPECT_EQ(quadCuller.quadList().size(), numTiles);
84 } 84 }
85 85
86 // Layer with empty visible layer rect produces no quads 86 // Layer with empty visible layer rect produces no quads
87 { 87 {
88 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels); 88 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels);
89 layer->drawProperties().visible_content_rect = gfx::Rect(); 89 layer->draw_properties().visible_content_rect = gfx::Rect();
90 90
91 MockQuadCuller quadCuller; 91 MockQuadCuller quadCuller;
92 AppendQuadsData data; 92 AppendQuadsData data;
93 layer->appendQuads(quadCuller, data); 93 layer->AppendQuads(&quadCuller, &data);
94 EXPECT_EQ(quadCuller.quadList().size(), 0u); 94 EXPECT_EQ(quadCuller.quadList().size(), 0u);
95 } 95 }
96 96
97 // Layer with non-intersecting visible layer rect produces no quads 97 // Layer with non-intersecting visible layer rect produces no quads
98 { 98 {
99 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels); 99 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels);
100 100
101 gfx::Rect outsideBounds(gfx::Point(-100, -100), gfx::Size(50, 50)); 101 gfx::Rect outsideBounds(gfx::Point(-100, -100), gfx::Size(50, 50));
102 layer->drawProperties().visible_content_rect = outsideBounds; 102 layer->draw_properties().visible_content_rect = outsideBounds;
103 103
104 MockQuadCuller quadCuller; 104 MockQuadCuller quadCuller;
105 AppendQuadsData data; 105 AppendQuadsData data;
106 layer->appendQuads(quadCuller, data); 106 layer->AppendQuads(&quadCuller, &data);
107 EXPECT_EQ(quadCuller.quadList().size(), 0u); 107 EXPECT_EQ(quadCuller.quadList().size(), 0u);
108 } 108 }
109 109
110 // Layer with skips draw produces no quads 110 // Layer with skips draw produces no quads
111 { 111 {
112 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels); 112 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels);
113 layer->setSkipsDraw(true); 113 layer->setSkipsDraw(true);
114 114
115 MockQuadCuller quadCuller; 115 MockQuadCuller quadCuller;
116 AppendQuadsData data; 116 AppendQuadsData data;
117 layer->appendQuads(quadCuller, data); 117 layer->AppendQuads(&quadCuller, &data);
118 EXPECT_EQ(quadCuller.quadList().size(), 0u); 118 EXPECT_EQ(quadCuller.quadList().size(), 0u);
119 } 119 }
120 } 120 }
121 121
122 TEST_F(TiledLayerImplTest, checkerboarding) 122 TEST_F(TiledLayerImplTest, checkerboarding)
123 { 123 {
124 const gfx::Size tileSize(10, 10); 124 const gfx::Size tileSize(10, 10);
125 const int numTilesX = 2; 125 const int numTilesX = 2;
126 const int numTilesY = 2; 126 const int numTilesY = 2;
127 const gfx::Size layerSize(tileSize.width() * numTilesX, tileSize.height() * numTilesY); 127 const gfx::Size layerSize(tileSize.width() * numTilesX, tileSize.height() * numTilesY);
128 128
129 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTil ingData::NoBorderTexels); 129 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTil ingData::NoBorderTexels);
130 130
131 // No checkerboarding 131 // No checkerboarding
132 { 132 {
133 MockQuadCuller quadCuller; 133 MockQuadCuller quadCuller;
134 AppendQuadsData data; 134 AppendQuadsData data;
135 layer->appendQuads(quadCuller, data); 135 layer->AppendQuads(&quadCuller, &data);
136 EXPECT_EQ(quadCuller.quadList().size(), 4u); 136 EXPECT_EQ(quadCuller.quadList().size(), 4u);
137 EXPECT_EQ(0u, data.numMissingTiles); 137 EXPECT_EQ(0u, data.numMissingTiles);
138 138
139 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) 139 for (size_t i = 0; i < quadCuller.quadList().size(); ++i)
140 EXPECT_EQ(quadCuller.quadList()[i]->material, DrawQuad::TILED_CONTEN T); 140 EXPECT_EQ(quadCuller.quadList()[i]->material, DrawQuad::TILED_CONTEN T);
141 } 141 }
142 142
143 for (int i = 0; i < numTilesX; ++i) 143 for (int i = 0; i < numTilesX; ++i)
144 for (int j = 0; j < numTilesY; ++j) 144 for (int j = 0; j < numTilesY; ++j)
145 layer->pushTileProperties(i, j, 0, gfx::Rect(), false); 145 layer->pushTileProperties(i, j, 0, gfx::Rect(), false);
146 146
147 // All checkerboarding 147 // All checkerboarding
148 { 148 {
149 MockQuadCuller quadCuller; 149 MockQuadCuller quadCuller;
150 AppendQuadsData data; 150 AppendQuadsData data;
151 layer->appendQuads(quadCuller, data); 151 layer->AppendQuads(&quadCuller, &data);
152 EXPECT_LT(0u, data.numMissingTiles); 152 EXPECT_LT(0u, data.numMissingTiles);
153 EXPECT_EQ(quadCuller.quadList().size(), 4u); 153 EXPECT_EQ(quadCuller.quadList().size(), 4u);
154 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) 154 for (size_t i = 0; i < quadCuller.quadList().size(); ++i)
155 EXPECT_NE(quadCuller.quadList()[i]->material, DrawQuad::TILED_CONTEN T); 155 EXPECT_NE(quadCuller.quadList()[i]->material, DrawQuad::TILED_CONTEN T);
156 } 156 }
157 } 157 }
158 158
159 // Test with both border texels and without. 159 // Test with both border texels and without.
160 #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ 160 #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \
161 TEST_F(TiledLayerImplBorderTest, testFixtureName##NoBorders) \ 161 TEST_F(TiledLayerImplBorderTest, testFixtureName##NoBorders) \
(...skipping 27 matching lines...) Expand all
189 gfx::Size layerSize(250, 250); 189 gfx::Size layerSize(250, 250);
190 QuadList quads; 190 QuadList quads;
191 SharedQuadStateList sharedStates; 191 SharedQuadStateList sharedStates;
192 getQuads(quads, sharedStates, gfx::Size(50, 50), gfx::Size(250, 250), La yerTilingData::NoBorderTexels, visibleContentRect); 192 getQuads(quads, sharedStates, gfx::Size(50, 50), gfx::Size(250, 250), La yerTilingData::NoBorderTexels, visibleContentRect);
193 LayerTestCommon::verifyQuadsExactlyCoverRect(quads, visibleContentRect); 193 LayerTestCommon::verifyQuadsExactlyCoverRect(quads, visibleContentRect);
194 } 194 }
195 195
196 void coverageVisibleRectIntersectsBounds(LayerTilingData::BorderTexelOption borders) 196 void coverageVisibleRectIntersectsBounds(LayerTilingData::BorderTexelOption borders)
197 { 197 {
198 gfx::Size layerSize(220, 210); 198 gfx::Size layerSize(220, 210);
199 gfx::Rect visibleContentRect(gfx::Point(), layerSize); 199 gfx::Rect visibleContentRect(layerSize);
200 QuadList quads; 200 QuadList quads;
201 SharedQuadStateList sharedStates; 201 SharedQuadStateList sharedStates;
202 getQuads(quads, sharedStates, gfx::Size(100, 100), layerSize, LayerTilin gData::NoBorderTexels, visibleContentRect); 202 getQuads(quads, sharedStates, gfx::Size(100, 100), layerSize, LayerTilin gData::NoBorderTexels, visibleContentRect);
203 LayerTestCommon::verifyQuadsExactlyCoverRect(quads, visibleContentRect); 203 LayerTestCommon::verifyQuadsExactlyCoverRect(quads, visibleContentRect);
204 } 204 }
205 }; 205 };
206 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectOnTileBoundaries); 206 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectOnTileBoundaries);
207 207
208 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsTiles); 208 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsTiles);
209 209
(...skipping 12 matching lines...) Expand all
222 222
223 EXPECT_NE(0u, quad->resource_id) << LayerTestCommon::quadString << i; 223 EXPECT_NE(0u, quad->resource_id) << LayerTestCommon::quadString << i;
224 EXPECT_EQ(gfx::RectF(gfx::PointF(), tileSize), quad->tex_coord_rect) << LayerTestCommon::quadString << i; 224 EXPECT_EQ(gfx::RectF(gfx::PointF(), tileSize), quad->tex_coord_rect) << LayerTestCommon::quadString << i;
225 EXPECT_EQ(tileSize, quad->texture_size) << LayerTestCommon::quadString < < i; 225 EXPECT_EQ(tileSize, quad->texture_size) << LayerTestCommon::quadString < < i;
226 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaque_rect) << LayerTestCommon:: quadString << i; 226 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaque_rect) << LayerTestCommon:: quadString << i;
227 } 227 }
228 } 228 }
229 229
230 } // namespace 230 } // namespace
231 } // namespace cc 231 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiled_layer_impl.cc ('k') | cc/tiled_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698