OLD | NEW |
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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCTiledLayerImpl.h" | 7 #include "CCTiledLayerImpl.h" |
8 | 8 |
9 #include "CCAppendQuadsData.h" | 9 #include "CCAppendQuadsData.h" |
10 #include "CCLayerTestCommon.h" | 10 #include "CCLayerTestCommon.h" |
11 #include "CCLayerTilingData.h" | 11 #include "CCLayerTilingData.h" |
12 #include "CCSingleThreadProxy.h" | 12 #include "CCSingleThreadProxy.h" |
13 #include "CCTileDrawQuad.h" | 13 #include "CCTileDrawQuad.h" |
14 #include "MockCCQuadCuller.h" | 14 #include "MockCCQuadCuller.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 using namespace cc; | 18 using namespace cc; |
19 using namespace CCLayerTestCommon; | 19 using namespace CCLayerTestCommon; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Create a default tiled layer with textures for all tiles and a default | 23 // Create a default tiled layer with textures for all tiles and a default |
24 // visibility of the entire layer size. | 24 // visibility of the entire layer size. |
25 static PassOwnPtr<CCTiledLayerImpl> createLayer(const IntSize& tileSize, const I
ntSize& layerSize, CCLayerTilingData::BorderTexelOption borderTexels) | 25 static scoped_ptr<CCTiledLayerImpl> createLayer(const IntSize& tileSize, const I
ntSize& layerSize, CCLayerTilingData::BorderTexelOption borderTexels) |
26 { | 26 { |
27 OwnPtr<CCTiledLayerImpl> layer = CCTiledLayerImpl::create(1); | 27 scoped_ptr<CCTiledLayerImpl> layer = CCTiledLayerImpl::create(1); |
28 OwnPtr<CCLayerTilingData> tiler = CCLayerTilingData::create(tileSize, border
Texels); | 28 OwnPtr<CCLayerTilingData> tiler = CCLayerTilingData::create(tileSize, border
Texels); |
29 tiler->setBounds(layerSize); | 29 tiler->setBounds(layerSize); |
30 layer->setTilingData(*tiler); | 30 layer->setTilingData(*tiler); |
31 layer->setSkipsDraw(false); | 31 layer->setSkipsDraw(false); |
32 layer->setVisibleContentRect(IntRect(IntPoint(), layerSize)); | 32 layer->setVisibleContentRect(IntRect(IntPoint(), layerSize)); |
33 layer->setDrawOpacity(1); | 33 layer->setDrawOpacity(1); |
34 layer->setBounds(layerSize); | 34 layer->setBounds(layerSize); |
35 layer->setContentBounds(layerSize); | 35 layer->setContentBounds(layerSize); |
36 layer->createRenderSurface(); | 36 layer->createRenderSurface(); |
37 layer->setRenderTarget(layer.get()); | 37 layer->setRenderTarget(layer.get()); |
38 | 38 |
39 CCResourceProvider::ResourceId resourceId = 1; | 39 CCResourceProvider::ResourceId resourceId = 1; |
40 for (int i = 0; i < tiler->numTilesX(); ++i) | 40 for (int i = 0; i < tiler->numTilesX(); ++i) |
41 for (int j = 0; j < tiler->numTilesY(); ++j) | 41 for (int j = 0; j < tiler->numTilesY(); ++j) |
42 layer->pushTileProperties(i, j, resourceId++, IntRect(0, 0, 1, 1)); | 42 layer->pushTileProperties(i, j, resourceId++, IntRect(0, 0, 1, 1)); |
43 | 43 |
44 return layer.release(); | 44 return layer.Pass(); |
45 } | 45 } |
46 | 46 |
47 TEST(CCTiledLayerImplTest, emptyQuadList) | 47 TEST(CCTiledLayerImplTest, emptyQuadList) |
48 { | 48 { |
49 DebugScopedSetImplThread scopedImplThread; | 49 DebugScopedSetImplThread scopedImplThread; |
50 | 50 |
51 const IntSize tileSize(90, 90); | 51 const IntSize tileSize(90, 90); |
52 const int numTilesX = 8; | 52 const int numTilesX = 8; |
53 const int numTilesY = 4; | 53 const int numTilesY = 4; |
54 const IntSize layerSize(tileSize.width() * numTilesX, tileSize.height() * nu
mTilesY); | 54 const IntSize layerSize(tileSize.width() * numTilesX, tileSize.height() * nu
mTilesY); |
55 | 55 |
56 // Verify default layer does creates quads | 56 // Verify default layer does creates quads |
57 { | 57 { |
58 OwnPtr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CCLaye
rTilingData::NoBorderTexels); | 58 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CC
LayerTilingData::NoBorderTexels); |
59 MockCCQuadCuller quadCuller; | 59 MockCCQuadCuller quadCuller; |
60 CCAppendQuadsData data; | 60 CCAppendQuadsData data; |
61 layer->appendQuads(quadCuller, data); | 61 layer->appendQuads(quadCuller, data); |
62 const unsigned numTiles = numTilesX * numTilesY; | 62 const unsigned numTiles = numTilesX * numTilesY; |
63 EXPECT_EQ(quadCuller.quadList().size(), numTiles); | 63 EXPECT_EQ(quadCuller.quadList().size(), numTiles); |
64 } | 64 } |
65 | 65 |
66 // Layer with empty visible layer rect produces no quads | 66 // Layer with empty visible layer rect produces no quads |
67 { | 67 { |
68 OwnPtr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CCLaye
rTilingData::NoBorderTexels); | 68 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CC
LayerTilingData::NoBorderTexels); |
69 layer->setVisibleContentRect(IntRect()); | 69 layer->setVisibleContentRect(IntRect()); |
70 | 70 |
71 MockCCQuadCuller quadCuller; | 71 MockCCQuadCuller quadCuller; |
72 CCAppendQuadsData data; | 72 CCAppendQuadsData data; |
73 layer->appendQuads(quadCuller, data); | 73 layer->appendQuads(quadCuller, data); |
74 EXPECT_EQ(quadCuller.quadList().size(), 0u); | 74 EXPECT_EQ(quadCuller.quadList().size(), 0u); |
75 } | 75 } |
76 | 76 |
77 // Layer with non-intersecting visible layer rect produces no quads | 77 // Layer with non-intersecting visible layer rect produces no quads |
78 { | 78 { |
79 OwnPtr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CCLaye
rTilingData::NoBorderTexels); | 79 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CC
LayerTilingData::NoBorderTexels); |
80 | 80 |
81 IntRect outsideBounds(IntPoint(-100, -100), IntSize(50, 50)); | 81 IntRect outsideBounds(IntPoint(-100, -100), IntSize(50, 50)); |
82 layer->setVisibleContentRect(outsideBounds); | 82 layer->setVisibleContentRect(outsideBounds); |
83 | 83 |
84 MockCCQuadCuller quadCuller; | 84 MockCCQuadCuller quadCuller; |
85 CCAppendQuadsData data; | 85 CCAppendQuadsData data; |
86 layer->appendQuads(quadCuller, data); | 86 layer->appendQuads(quadCuller, data); |
87 EXPECT_EQ(quadCuller.quadList().size(), 0u); | 87 EXPECT_EQ(quadCuller.quadList().size(), 0u); |
88 } | 88 } |
89 | 89 |
90 // Layer with skips draw produces no quads | 90 // Layer with skips draw produces no quads |
91 { | 91 { |
92 OwnPtr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CCLaye
rTilingData::NoBorderTexels); | 92 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CC
LayerTilingData::NoBorderTexels); |
93 layer->setSkipsDraw(true); | 93 layer->setSkipsDraw(true); |
94 | 94 |
95 MockCCQuadCuller quadCuller; | 95 MockCCQuadCuller quadCuller; |
96 CCAppendQuadsData data; | 96 CCAppendQuadsData data; |
97 layer->appendQuads(quadCuller, data); | 97 layer->appendQuads(quadCuller, data); |
98 EXPECT_EQ(quadCuller.quadList().size(), 0u); | 98 EXPECT_EQ(quadCuller.quadList().size(), 0u); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 TEST(CCTiledLayerImplTest, checkerboarding) | 102 TEST(CCTiledLayerImplTest, checkerboarding) |
103 { | 103 { |
104 DebugScopedSetImplThread scopedImplThread; | 104 DebugScopedSetImplThread scopedImplThread; |
105 | 105 |
106 const IntSize tileSize(10, 10); | 106 const IntSize tileSize(10, 10); |
107 const int numTilesX = 2; | 107 const int numTilesX = 2; |
108 const int numTilesY = 2; | 108 const int numTilesY = 2; |
109 const IntSize layerSize(tileSize.width() * numTilesX, tileSize.height() * nu
mTilesY); | 109 const IntSize layerSize(tileSize.width() * numTilesX, tileSize.height() * nu
mTilesY); |
110 | 110 |
111 OwnPtr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CCLayerTil
ingData::NoBorderTexels); | 111 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CCLaye
rTilingData::NoBorderTexels); |
112 | 112 |
113 // No checkerboarding | 113 // No checkerboarding |
114 { | 114 { |
115 MockCCQuadCuller quadCuller; | 115 MockCCQuadCuller quadCuller; |
116 CCAppendQuadsData data; | 116 CCAppendQuadsData data; |
117 layer->appendQuads(quadCuller, data); | 117 layer->appendQuads(quadCuller, data); |
118 EXPECT_EQ(quadCuller.quadList().size(), 4u); | 118 EXPECT_EQ(quadCuller.quadList().size(), 4u); |
119 EXPECT_FALSE(data.hadMissingTiles); | 119 EXPECT_FALSE(data.hadMissingTiles); |
120 | 120 |
121 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) | 121 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) |
(...skipping 11 matching lines...) Expand all Loading... |
133 layer->appendQuads(quadCuller, data); | 133 layer->appendQuads(quadCuller, data); |
134 EXPECT_TRUE(data.hadMissingTiles); | 134 EXPECT_TRUE(data.hadMissingTiles); |
135 EXPECT_EQ(quadCuller.quadList().size(), 4u); | 135 EXPECT_EQ(quadCuller.quadList().size(), 4u); |
136 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) | 136 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) |
137 EXPECT_NE(quadCuller.quadList()[i]->material(), CCDrawQuad::TiledCon
tent); | 137 EXPECT_NE(quadCuller.quadList()[i]->material(), CCDrawQuad::TiledCon
tent); |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 static void getQuads(CCQuadList& quads, CCSharedQuadStateList& sharedStates, Int
Size tileSize, const IntSize& layerSize, CCLayerTilingData::BorderTexelOption bo
rderTexelOption, const IntRect& visibleContentRect) | 141 static void getQuads(CCQuadList& quads, CCSharedQuadStateList& sharedStates, Int
Size tileSize, const IntSize& layerSize, CCLayerTilingData::BorderTexelOption bo
rderTexelOption, const IntRect& visibleContentRect) |
142 { | 142 { |
143 OwnPtr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, borderTexe
lOption); | 143 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, border
TexelOption); |
144 layer->setVisibleContentRect(visibleContentRect); | 144 layer->setVisibleContentRect(visibleContentRect); |
145 layer->setBounds(layerSize); | 145 layer->setBounds(layerSize); |
146 | 146 |
147 MockCCQuadCuller quadCuller(quads, sharedStates); | 147 MockCCQuadCuller quadCuller(quads, sharedStates); |
148 CCAppendQuadsData data; | 148 CCAppendQuadsData data; |
149 layer->appendQuads(quadCuller, data); | 149 layer->appendQuads(quadCuller, data); |
150 } | 150 } |
151 | 151 |
152 // Test with both border texels and without. | 152 // Test with both border texels and without. |
153 #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ | 153 #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 235 |
236 for (size_t i = 0; i < quads.size(); ++i) { | 236 for (size_t i = 0; i < quads.size(); ++i) { |
237 ASSERT_EQ(quads[i]->material(), CCDrawQuad::TiledContent) << quadString
<< i; | 237 ASSERT_EQ(quads[i]->material(), CCDrawQuad::TiledContent) << quadString
<< i; |
238 CCTileDrawQuad* quad = static_cast<CCTileDrawQuad*>(quads[i]); | 238 CCTileDrawQuad* quad = static_cast<CCTileDrawQuad*>(quads[i]); |
239 | 239 |
240 EXPECT_EQ(IntRect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i; | 240 EXPECT_EQ(IntRect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i; |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 } // namespace | 244 } // namespace |
OLD | NEW |