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 "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/layer_test_common.h" | 10 #include "cc/test/layer_test_common.h" |
11 #include "cc/test/mock_quad_culler.h" | 11 #include "cc/test/mock_quad_culler.h" |
12 #include "cc/tile_draw_quad.h" | 12 #include "cc/tile_draw_quad.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using namespace LayerTestCommon; | 16 using namespace LayerTestCommon; |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Create a default tiled layer with textures for all tiles and a default | 21 // Create a default tiled layer with textures for all tiles and a default |
22 // visibility of the entire layer size. | 22 // visibility of the entire layer size. |
23 static scoped_ptr<TiledLayerImpl> createLayer(const gfx::Size& tileSize, const g
fx::Size& layerSize, LayerTilingData::BorderTexelOption borderTexels) | 23 static scoped_ptr<TiledLayerImpl> createLayer(const gfx::Size& tileSize, const g
fx::Size& layerSize, LayerTilingData::BorderTexelOption borderTexels) |
24 { | 24 { |
25 scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(1); | 25 scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(1); |
26 scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, border
Texels); | 26 scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, border
Texels); |
27 tiler->setBounds(layerSize); | 27 tiler->setBounds(layerSize); |
28 layer->setTilingData(*tiler); | 28 layer->setTilingData(*tiler); |
29 layer->setSkipsDraw(false); | 29 layer->setSkipsDraw(false); |
30 layer->setVisibleContentRect(gfx::Rect(gfx::Point(), layerSize)); | 30 layer->drawProperties().visible_content_rect = gfx::Rect(gfx::Point(), layer
Size); |
31 layer->setDrawOpacity(1); | 31 layer->drawProperties().opacity = 1; |
32 layer->setBounds(layerSize); | 32 layer->setBounds(layerSize); |
33 layer->setContentBounds(layerSize); | 33 layer->setContentBounds(layerSize); |
34 layer->createRenderSurface(); | 34 layer->createRenderSurface(); |
35 layer->setRenderTarget(layer.get()); | 35 layer->drawProperties().render_target = layer.get(); |
36 | 36 |
37 ResourceProvider::ResourceId resourceId = 1; | 37 ResourceProvider::ResourceId resourceId = 1; |
38 for (int i = 0; i < tiler->numTilesX(); ++i) | 38 for (int i = 0; i < tiler->numTilesX(); ++i) |
39 for (int j = 0; j < tiler->numTilesY(); ++j) | 39 for (int j = 0; j < tiler->numTilesY(); ++j) |
40 layer->pushTileProperties(i, j, resourceId++, gfx::Rect(0, 0, 1, 1),
false); | 40 layer->pushTileProperties(i, j, resourceId++, gfx::Rect(0, 0, 1, 1),
false); |
41 | 41 |
42 return layer.Pass(); | 42 return layer.Pass(); |
43 } | 43 } |
44 | 44 |
45 TEST(TiledLayerImplTest, emptyQuadList) | 45 TEST(TiledLayerImplTest, emptyQuadList) |
46 { | 46 { |
47 const gfx::Size tileSize(90, 90); | 47 const gfx::Size tileSize(90, 90); |
48 const int numTilesX = 8; | 48 const int numTilesX = 8; |
49 const int numTilesY = 4; | 49 const int numTilesY = 4; |
50 const gfx::Size layerSize(tileSize.width() * numTilesX, tileSize.height() *
numTilesY); | 50 const gfx::Size layerSize(tileSize.width() * numTilesX, tileSize.height() *
numTilesY); |
51 | 51 |
52 // Verify default layer does creates quads | 52 // Verify default layer does creates quads |
53 { | 53 { |
54 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye
rTilingData::NoBorderTexels); | 54 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye
rTilingData::NoBorderTexels); |
55 MockQuadCuller quadCuller; | 55 MockQuadCuller quadCuller; |
56 AppendQuadsData data; | 56 AppendQuadsData data; |
57 layer->appendQuads(quadCuller, data); | 57 layer->appendQuads(quadCuller, data); |
58 const unsigned numTiles = numTilesX * numTilesY; | 58 const unsigned numTiles = numTilesX * numTilesY; |
59 EXPECT_EQ(quadCuller.quadList().size(), numTiles); | 59 EXPECT_EQ(quadCuller.quadList().size(), numTiles); |
60 } | 60 } |
61 | 61 |
62 // Layer with empty visible layer rect produces no quads | 62 // Layer with empty visible layer rect produces no quads |
63 { | 63 { |
64 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye
rTilingData::NoBorderTexels); | 64 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye
rTilingData::NoBorderTexels); |
65 layer->setVisibleContentRect(gfx::Rect()); | 65 layer->drawProperties().visible_content_rect = gfx::Rect(); |
66 | 66 |
67 MockQuadCuller quadCuller; | 67 MockQuadCuller quadCuller; |
68 AppendQuadsData data; | 68 AppendQuadsData data; |
69 layer->appendQuads(quadCuller, data); | 69 layer->appendQuads(quadCuller, data); |
70 EXPECT_EQ(quadCuller.quadList().size(), 0u); | 70 EXPECT_EQ(quadCuller.quadList().size(), 0u); |
71 } | 71 } |
72 | 72 |
73 // Layer with non-intersecting visible layer rect produces no quads | 73 // Layer with non-intersecting visible layer rect produces no quads |
74 { | 74 { |
75 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye
rTilingData::NoBorderTexels); | 75 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye
rTilingData::NoBorderTexels); |
76 | 76 |
77 gfx::Rect outsideBounds(gfx::Point(-100, -100), gfx::Size(50, 50)); | 77 gfx::Rect outsideBounds(gfx::Point(-100, -100), gfx::Size(50, 50)); |
78 layer->setVisibleContentRect(outsideBounds); | 78 layer->drawProperties().visible_content_rect = outsideBounds; |
79 | 79 |
80 MockQuadCuller quadCuller; | 80 MockQuadCuller quadCuller; |
81 AppendQuadsData data; | 81 AppendQuadsData data; |
82 layer->appendQuads(quadCuller, data); | 82 layer->appendQuads(quadCuller, data); |
83 EXPECT_EQ(quadCuller.quadList().size(), 0u); | 83 EXPECT_EQ(quadCuller.quadList().size(), 0u); |
84 } | 84 } |
85 | 85 |
86 // Layer with skips draw produces no quads | 86 // Layer with skips draw 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); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 EXPECT_TRUE(data.hadMissingTiles); | 128 EXPECT_TRUE(data.hadMissingTiles); |
129 EXPECT_EQ(quadCuller.quadList().size(), 4u); | 129 EXPECT_EQ(quadCuller.quadList().size(), 4u); |
130 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) | 130 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) |
131 EXPECT_NE(quadCuller.quadList()[i]->material, DrawQuad::TILED_CONTEN
T); | 131 EXPECT_NE(quadCuller.quadList()[i]->material, DrawQuad::TILED_CONTEN
T); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 static void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, gfx::Si
ze tileSize, const gfx::Size& layerSize, LayerTilingData::BorderTexelOption bord
erTexelOption, const gfx::Rect& visibleContentRect) | 135 static void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, gfx::Si
ze tileSize, const gfx::Size& layerSize, LayerTilingData::BorderTexelOption bord
erTexelOption, const gfx::Rect& visibleContentRect) |
136 { | 136 { |
137 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, borderTe
xelOption); | 137 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, borderTe
xelOption); |
138 layer->setVisibleContentRect(visibleContentRect); | 138 layer->drawProperties().visible_content_rect = visibleContentRect; |
139 layer->setBounds(layerSize); | 139 layer->setBounds(layerSize); |
140 | 140 |
141 MockQuadCuller quadCuller(quads, sharedStates); | 141 MockQuadCuller quadCuller(quads, sharedStates); |
142 AppendQuadsData data; | 142 AppendQuadsData data; |
143 layer->appendQuads(quadCuller, data); | 143 layer->appendQuads(quadCuller, data); |
144 } | 144 } |
145 | 145 |
146 // Test with both border texels and without. | 146 // Test with both border texels and without. |
147 #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ | 147 #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ |
148 TEST(TiledLayerImplTest, testFixtureName##NoBorders) \ | 148 TEST(TiledLayerImplTest, testFixtureName##NoBorders) \ |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 EXPECT_NE(0u, quad->resource_id) << quadString << i; | 204 EXPECT_NE(0u, quad->resource_id) << quadString << i; |
205 EXPECT_EQ(gfx::RectF(gfx::PointF(), tileSize), quad->tex_coord_rect) <<
quadString << i; | 205 EXPECT_EQ(gfx::RectF(gfx::PointF(), tileSize), quad->tex_coord_rect) <<
quadString << i; |
206 EXPECT_EQ(tileSize, quad->texture_size) << quadString << i; | 206 EXPECT_EQ(tileSize, quad->texture_size) << quadString << i; |
207 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaque_rect) << quadString << i; | 207 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaque_rect) << quadString << i; |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 } // namespace | 211 } // namespace |
212 } // namespace cc | 212 } // namespace cc |
OLD | NEW |