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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "cc/layers/append_quads_data.h" | 7 #include "cc/layers/append_quads_data.h" |
8 #include "cc/layers/nine_patch_layer_impl.h" | 8 #include "cc/layers/nine_patch_layer_impl.h" |
9 #include "cc/quads/texture_draw_quad.h" | 9 #include "cc/quads/texture_draw_quad.h" |
10 #include "cc/resources/ui_resource_bitmap.h" | 10 #include "cc/resources/ui_resource_bitmap.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 | 33 |
34 void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, | 34 void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, |
35 const gfx::Rect& aperture_rect, | 35 const gfx::Rect& aperture_rect, |
36 const gfx::Size& layer_size, | 36 const gfx::Size& layer_size, |
37 const gfx::Rect& border, | 37 const gfx::Rect& border, |
38 bool fill_center, | 38 bool fill_center, |
39 size_t expected_quad_size) { | 39 size_t expected_quad_size) { |
40 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); | 40 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
41 gfx::Rect visible_layer_rect(layer_size); | 41 gfx::Rect visible_layer_rect(layer_size); |
42 gfx::Rect expected_remaining(border.x(), | 42 gfx::Rect expected_remaining(border.x(), border.y(), |
43 border.y(), | |
44 layer_size.width() - border.width(), | 43 layer_size.width() - border.width(), |
45 layer_size.height() - border.height()); | 44 layer_size.height() - border.height()); |
46 | 45 |
47 FakeImplTaskRunnerProvider task_runner_provider; | 46 FakeImplTaskRunnerProvider task_runner_provider; |
48 TestSharedBitmapManager shared_bitmap_manager; | 47 TestSharedBitmapManager shared_bitmap_manager; |
49 TestTaskGraphRunner task_graph_runner; | 48 TestTaskGraphRunner task_graph_runner; |
50 std::unique_ptr<OutputSurface> output_surface = | 49 std::unique_ptr<OutputSurface> output_surface = |
51 FakeOutputSurface::CreateDelegating3d(); | 50 FakeOutputSurface::CreateDelegating3d(); |
52 FakeUIResourceLayerTreeHostImpl host_impl( | 51 FakeUIResourceLayerTreeHostImpl host_impl( |
53 &task_runner_provider, &shared_bitmap_manager, &task_graph_runner); | 52 &task_runner_provider, &shared_bitmap_manager, &task_graph_runner); |
54 host_impl.SetVisible(true); | 53 host_impl.SetVisible(true); |
55 host_impl.InitializeRenderer(output_surface.get()); | 54 host_impl.InitializeRenderer(output_surface.get()); |
56 | 55 |
57 std::unique_ptr<NinePatchLayerImpl> layer = | 56 std::unique_ptr<NinePatchLayerImpl> layer = |
58 NinePatchLayerImpl::Create(host_impl.active_tree(), 1); | 57 NinePatchLayerImpl::Create(host_impl.active_tree(), 1); |
59 layer->draw_properties().visible_layer_rect = visible_layer_rect; | 58 layer->draw_properties().visible_layer_rect = visible_layer_rect; |
60 layer->SetBounds(layer_size); | 59 layer->SetBounds(layer_size); |
61 layer->test_properties()->force_render_surface = true; | 60 layer->test_properties()->force_render_surface = true; |
62 | 61 |
63 UIResourceId uid = 1; | 62 UIResourceId uid = 1; |
64 bool is_opaque = false; | 63 bool is_opaque = false; |
65 UIResourceBitmap bitmap(bitmap_size, is_opaque); | 64 UIResourceBitmap bitmap(bitmap_size, is_opaque); |
66 | 65 |
67 host_impl.CreateUIResource(uid, bitmap); | 66 host_impl.CreateUIResource(uid, bitmap); |
68 layer->SetUIResourceId(uid); | 67 layer->SetUIResourceId(uid); |
69 layer->SetImageBounds(bitmap_size); | 68 layer->SetImageBounds(bitmap_size); |
70 layer->SetLayout(aperture_rect, border, fill_center, false); | 69 layer->SetLayout(aperture_rect, border, gfx::Rect(), fill_center, false); |
71 AppendQuadsData data; | 70 AppendQuadsData data; |
72 layer->AppendQuads(render_pass.get(), &data); | 71 layer->AppendQuads(render_pass.get(), &data); |
73 | 72 |
74 // Verify quad rects | 73 // Verify quad rects |
75 const QuadList& quads = render_pass->quad_list; | 74 const QuadList& quads = render_pass->quad_list; |
76 EXPECT_EQ(expected_quad_size, quads.size()); | 75 EXPECT_EQ(expected_quad_size, quads.size()); |
77 | 76 |
78 Region remaining(visible_layer_rect); | 77 Region layer_remaining(visible_layer_rect); |
79 for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) { | 78 for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) { |
80 gfx::Rect quad_rect = iter->rect; | 79 gfx::Rect quad_rect = iter->rect; |
81 | 80 |
82 EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index(); | 81 EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index(); |
83 EXPECT_TRUE(remaining.Contains(quad_rect)) << iter.index(); | 82 EXPECT_TRUE(layer_remaining.Contains(quad_rect)) << iter.index(); |
84 remaining.Subtract(Region(quad_rect)); | 83 layer_remaining.Subtract(Region(quad_rect)); |
85 } | 84 } |
86 | 85 |
87 // Check if the left-over quad is the same size as the mapped aperture quad in | 86 // Check if the left-over quad is the same size as the mapped aperture quad in |
88 // layer space. | 87 // layer space. |
89 if (!fill_center) { | 88 if (!fill_center) { |
90 EXPECT_EQ(expected_remaining, remaining.bounds()); | 89 EXPECT_EQ(expected_remaining, layer_remaining.bounds()); |
91 } else { | 90 } else { |
92 EXPECT_TRUE(remaining.bounds().IsEmpty()); | 91 EXPECT_TRUE(layer_remaining.bounds().IsEmpty()); |
93 } | 92 } |
94 | 93 |
95 // Verify UV rects | 94 // Verify UV rects |
96 gfx::Rect bitmap_rect(bitmap_size); | 95 gfx::Rect bitmap_rect(bitmap_size); |
97 Region tex_remaining(bitmap_rect); | 96 Region tex_remaining(bitmap_rect); |
98 for (auto* quad : quads) { | 97 for (auto* quad : quads) { |
99 const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad); | 98 const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad); |
100 gfx::RectF tex_rect = | 99 gfx::RectF tex_rect = |
101 gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right); | 100 gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right); |
102 tex_rect.Scale(bitmap_size.width(), bitmap_size.height()); | 101 tex_rect.Scale(bitmap_size.width(), bitmap_size.height()); |
103 tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect))); | 102 tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect))); |
104 } | 103 } |
105 | 104 |
106 if (!fill_center) { | 105 if (!fill_center) { |
107 EXPECT_EQ(aperture_rect, tex_remaining.bounds()); | 106 EXPECT_EQ(aperture_rect, tex_remaining.bounds()); |
108 Region aperture_region(aperture_rect); | 107 Region aperture_region(aperture_rect); |
109 EXPECT_EQ(aperture_region, tex_remaining); | 108 EXPECT_EQ(aperture_region, tex_remaining); |
110 } else { | 109 } else { |
111 EXPECT_TRUE(remaining.bounds().IsEmpty()); | 110 EXPECT_TRUE(layer_remaining.bounds().IsEmpty()); |
112 } | 111 } |
113 } | 112 } |
114 | 113 |
| 114 void NinePatchLayerLayoutTestWithOcclusion(const gfx::Size& bitmap_size, |
| 115 const gfx::Rect& aperture_rect, |
| 116 const gfx::Size& layer_size, |
| 117 const gfx::Rect& border, |
| 118 const gfx::Rect& occlusion, |
| 119 bool fill_center, |
| 120 size_t expected_quad_size) { |
| 121 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 122 gfx::Rect visible_layer_rect(layer_size); |
| 123 int border_left = std::min(border.x(), occlusion.x()), |
| 124 border_top = std::min(border.y(), occlusion.y()), |
| 125 border_right = std::min(border.width() - border.x(), |
| 126 layer_size.width() - occlusion.right()), |
| 127 border_bottom = std::min(border.height() - border.y(), |
| 128 layer_size.height() - occlusion.bottom()); |
| 129 gfx::Rect expected_layer_remaining( |
| 130 border_left, border_top, layer_size.width() - border_left - border_right, |
| 131 layer_size.height() - border_top - border_bottom); |
| 132 float ratio_left = border_left == 0 ? 0 : (aperture_rect.x() / border.x()), |
| 133 ratio_top = border_top == 0 ? 0 : (aperture_rect.y() / border.y()), |
| 134 ratio_right = border_right == 0 |
| 135 ? 0 |
| 136 : ((bitmap_size.width() - aperture_rect.right()) / |
| 137 (border.width() - border.x())), |
| 138 ratio_bottom = border_bottom == 0 |
| 139 ? 0 |
| 140 : ((bitmap_size.height() - aperture_rect.bottom()) / |
| 141 (border.height() - border.y())); |
| 142 int image_remaining_left = border_left * ratio_left, |
| 143 image_remaining_top = border_top * ratio_top, |
| 144 image_remaining_right = border_right * ratio_right, |
| 145 image_remaining_bottom = border_bottom * ratio_bottom; |
| 146 gfx::Rect expected_tex_remaining( |
| 147 image_remaining_left, image_remaining_top, |
| 148 bitmap_size.width() - image_remaining_right - image_remaining_left, |
| 149 bitmap_size.height() - image_remaining_bottom - image_remaining_top); |
| 150 |
| 151 FakeImplTaskRunnerProvider task_runner_provider; |
| 152 TestSharedBitmapManager shared_bitmap_manager; |
| 153 TestTaskGraphRunner task_graph_runner; |
| 154 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 155 FakeUIResourceLayerTreeHostImpl host_impl( |
| 156 &task_runner_provider, &shared_bitmap_manager, &task_graph_runner); |
| 157 host_impl.SetVisible(true); |
| 158 host_impl.InitializeRenderer(output_surface.get()); |
| 159 |
| 160 std::unique_ptr<NinePatchLayerImpl> layer = |
| 161 NinePatchLayerImpl::Create(host_impl.active_tree(), 1); |
| 162 layer->draw_properties().visible_layer_rect = visible_layer_rect; |
| 163 layer->SetBounds(layer_size); |
| 164 layer->test_properties()->force_render_surface = true; |
| 165 |
| 166 UIResourceId uid = 1; |
| 167 bool is_opaque = false; |
| 168 UIResourceBitmap bitmap(bitmap_size, is_opaque); |
| 169 |
| 170 host_impl.CreateUIResource(uid, bitmap); |
| 171 layer->SetUIResourceId(uid); |
| 172 layer->SetImageBounds(bitmap_size); |
| 173 layer->SetLayout(aperture_rect, border, occlusion, false, false); |
| 174 AppendQuadsData data; |
| 175 layer->AppendQuads(render_pass.get(), &data); |
| 176 |
| 177 // Verify quad rects |
| 178 const QuadList& quads = render_pass->quad_list; |
| 179 EXPECT_EQ(expected_quad_size, quads.size()); |
| 180 |
| 181 Region layer_remaining(visible_layer_rect); |
| 182 for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) { |
| 183 gfx::Rect quad_rect = iter->rect; |
| 184 |
| 185 EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index(); |
| 186 EXPECT_TRUE(layer_remaining.Contains(quad_rect)) << iter.index(); |
| 187 layer_remaining.Subtract(Region(quad_rect)); |
| 188 } |
| 189 |
| 190 // Check if the left-over quad is the same size as the mapped aperture quad in |
| 191 // layer space. |
| 192 EXPECT_EQ(expected_layer_remaining, layer_remaining.bounds()); |
| 193 |
| 194 // Verify UV rects |
| 195 gfx::Rect bitmap_rect(bitmap_size); |
| 196 Region tex_remaining(bitmap_rect); |
| 197 for (const auto& quad : quads) { |
| 198 const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad); |
| 199 gfx::RectF tex_rect = |
| 200 gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right); |
| 201 tex_rect.Scale(bitmap_size.width(), bitmap_size.height()); |
| 202 tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect))); |
| 203 } |
| 204 |
| 205 EXPECT_EQ(expected_tex_remaining, tex_remaining.bounds()); |
| 206 Region aperture_region(expected_tex_remaining); |
| 207 EXPECT_EQ(aperture_region, tex_remaining); |
| 208 } |
| 209 |
115 TEST(NinePatchLayerImplTest, VerifyDrawQuads) { | 210 TEST(NinePatchLayerImplTest, VerifyDrawQuads) { |
116 // Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30. | 211 // Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30. |
117 // The bounds of the layer are set to 400x400. | 212 // The bounds of the layer are set to 400x400. |
118 gfx::Size bitmap_size(100, 100); | 213 gfx::Size bitmap_size(100, 100); |
119 gfx::Size layer_size(400, 500); | 214 gfx::Size layer_size(400, 500); |
120 gfx::Rect aperture_rect(20, 30, 40, 50); | 215 gfx::Rect aperture_rect(20, 30, 40, 50); |
121 gfx::Rect border(40, 40, 80, 80); | 216 gfx::Rect border(40, 40, 80, 80); |
122 bool fill_center = false; | 217 bool fill_center = false; |
123 size_t expected_quad_size = 8; | 218 size_t expected_quad_size = 8; |
124 NinePatchLayerLayoutTest(bitmap_size, | 219 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
125 aperture_rect, | 220 fill_center, expected_quad_size); |
126 layer_size, | |
127 border, | |
128 fill_center, | |
129 expected_quad_size); | |
130 | 221 |
131 // The bounds of the layer are set to less than the bitmap size. | 222 // The bounds of the layer are set to less than the bitmap size. |
132 bitmap_size = gfx::Size(100, 100); | 223 bitmap_size = gfx::Size(100, 100); |
133 layer_size = gfx::Size(40, 50); | 224 layer_size = gfx::Size(40, 50); |
134 aperture_rect = gfx::Rect(20, 30, 40, 50); | 225 aperture_rect = gfx::Rect(20, 30, 40, 50); |
135 border = gfx::Rect(10, 10, 25, 15); | 226 border = gfx::Rect(10, 10, 25, 15); |
136 fill_center = true; | 227 fill_center = true; |
137 expected_quad_size = 9; | 228 expected_quad_size = 9; |
138 NinePatchLayerLayoutTest(bitmap_size, | 229 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
139 aperture_rect, | 230 fill_center, expected_quad_size); |
140 layer_size, | |
141 border, | |
142 fill_center, | |
143 expected_quad_size); | |
144 | 231 |
145 // Layer and image sizes are equal. | 232 // Layer and image sizes are equal. |
146 bitmap_size = gfx::Size(100, 100); | 233 bitmap_size = gfx::Size(100, 100); |
147 layer_size = gfx::Size(100, 100); | 234 layer_size = gfx::Size(100, 100); |
148 aperture_rect = gfx::Rect(20, 30, 40, 50); | 235 aperture_rect = gfx::Rect(20, 30, 40, 50); |
149 border = gfx::Rect(20, 30, 40, 50); | 236 border = gfx::Rect(20, 30, 40, 50); |
150 fill_center = true; | 237 fill_center = true; |
151 expected_quad_size = 9; | 238 expected_quad_size = 9; |
152 NinePatchLayerLayoutTest(bitmap_size, | 239 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
153 aperture_rect, | 240 fill_center, expected_quad_size); |
154 layer_size, | 241 } |
155 border, | 242 |
156 fill_center, | 243 TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithOcclusion) { |
157 expected_quad_size); | 244 // Occlusion removed part of the border and leaves us with 12 patches. |
| 245 gfx::Size bitmap_size(100, 100); |
| 246 gfx::Rect aperture_rect(30, 30, 40, 40); |
| 247 gfx::Size layer_size(400, 400); |
| 248 gfx::Rect occlusion(20, 20, 360, 360); |
| 249 gfx::Rect border(30, 30, 60, 60); |
| 250 size_t expected_quad_size = 12; |
| 251 NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size, |
| 252 border, occlusion, false, |
| 253 expected_quad_size); |
| 254 |
| 255 bitmap_size = gfx::Size(100, 100); |
| 256 aperture_rect = gfx::Rect(20, 30, 60, 40); |
| 257 layer_size = gfx::Size(400, 400); |
| 258 occlusion = gfx::Rect(10, 10, 380, 380); |
| 259 border = gfx::Rect(20, 30, 40, 60); |
| 260 expected_quad_size = 12; |
| 261 NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size, |
| 262 border, occlusion, false, |
| 263 expected_quad_size); |
| 264 |
| 265 // All borders are empty, so nothing should be drawn. |
| 266 bitmap_size = gfx::Size(100, 100); |
| 267 aperture_rect = gfx::Rect(0, 0, 100, 100); |
| 268 layer_size = gfx::Size(400, 400); |
| 269 occlusion = gfx::Rect(0, 0, 400, 400); |
| 270 border = gfx::Rect(0, 0, 0, 0); |
| 271 expected_quad_size = 0; |
| 272 NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size, |
| 273 border, occlusion, false, |
| 274 expected_quad_size); |
| 275 |
| 276 // Right border is empty, we should have no quads on the right side. |
| 277 bitmap_size = gfx::Size(100, 100); |
| 278 aperture_rect = gfx::Rect(20, 30, 80, 40); |
| 279 layer_size = gfx::Size(400, 400); |
| 280 occlusion = gfx::Rect(10, 10, 390, 380); |
| 281 border = gfx::Rect(20, 30, 20, 60); |
| 282 expected_quad_size = 7; |
| 283 NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size, |
| 284 border, occlusion, false, |
| 285 expected_quad_size); |
158 } | 286 } |
159 | 287 |
160 TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) { | 288 TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) { |
161 // The top component of the 9-patch is empty, so there should be no quads for | 289 // The top component of the 9-patch is empty, so there should be no quads for |
162 // the top three components. | 290 // the top three components. |
163 gfx::Size bitmap_size(100, 100); | 291 gfx::Size bitmap_size(100, 100); |
164 gfx::Size layer_size(100, 100); | 292 gfx::Size layer_size(100, 100); |
165 gfx::Rect aperture_rect(10, 0, 80, 90); | 293 gfx::Rect aperture_rect(10, 0, 80, 90); |
166 gfx::Rect border(10, 0, 20, 10); | 294 gfx::Rect border(10, 0, 20, 10); |
167 bool fill_center = false; | 295 bool fill_center = false; |
168 size_t expected_quad_size = 5; | 296 size_t expected_quad_size = 5; |
169 NinePatchLayerLayoutTest(bitmap_size, | 297 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
170 aperture_rect, | 298 fill_center, expected_quad_size); |
171 layer_size, | |
172 border, | |
173 fill_center, | |
174 expected_quad_size); | |
175 | 299 |
176 // The top and left components of the 9-patch are empty, so there should be no | 300 // The top and left components of the 9-patch are empty, so there should be no |
177 // quads for the left and top components. | 301 // quads for the left and top components. |
178 bitmap_size = gfx::Size(100, 100); | 302 bitmap_size = gfx::Size(100, 100); |
179 layer_size = gfx::Size(100, 100); | 303 layer_size = gfx::Size(100, 100); |
180 aperture_rect = gfx::Rect(0, 0, 90, 90); | 304 aperture_rect = gfx::Rect(0, 0, 90, 90); |
181 border = gfx::Rect(0, 0, 10, 10); | 305 border = gfx::Rect(0, 0, 10, 10); |
182 fill_center = false; | 306 fill_center = false; |
183 expected_quad_size = 3; | 307 expected_quad_size = 3; |
184 NinePatchLayerLayoutTest(bitmap_size, | 308 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
185 aperture_rect, | 309 fill_center, expected_quad_size); |
186 layer_size, | |
187 border, | |
188 fill_center, | |
189 expected_quad_size); | |
190 | 310 |
191 // The aperture is the size of the bitmap and the center doesn't draw. | 311 // The aperture is the size of the bitmap and the center doesn't draw. |
192 bitmap_size = gfx::Size(100, 100); | 312 bitmap_size = gfx::Size(100, 100); |
193 layer_size = gfx::Size(100, 100); | 313 layer_size = gfx::Size(100, 100); |
194 aperture_rect = gfx::Rect(0, 0, 100, 100); | 314 aperture_rect = gfx::Rect(0, 0, 100, 100); |
195 border = gfx::Rect(0, 0, 0, 0); | 315 border = gfx::Rect(0, 0, 0, 0); |
196 fill_center = false; | 316 fill_center = false; |
197 expected_quad_size = 0; | 317 expected_quad_size = 0; |
198 NinePatchLayerLayoutTest(bitmap_size, | 318 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
199 aperture_rect, | 319 fill_center, expected_quad_size); |
200 layer_size, | |
201 border, | |
202 fill_center, | |
203 expected_quad_size); | |
204 | 320 |
205 // The aperture is the size of the bitmap and the center does draw. | 321 // The aperture is the size of the bitmap and the center does draw. |
206 bitmap_size = gfx::Size(100, 100); | 322 bitmap_size = gfx::Size(100, 100); |
207 layer_size = gfx::Size(100, 100); | 323 layer_size = gfx::Size(100, 100); |
208 aperture_rect = gfx::Rect(0, 0, 100, 100); | 324 aperture_rect = gfx::Rect(0, 0, 100, 100); |
209 border = gfx::Rect(0, 0, 0, 0); | 325 border = gfx::Rect(0, 0, 0, 0); |
210 fill_center = true; | 326 fill_center = true; |
211 expected_quad_size = 1; | 327 expected_quad_size = 1; |
212 NinePatchLayerLayoutTest(bitmap_size, | 328 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
213 aperture_rect, | 329 fill_center, expected_quad_size); |
214 layer_size, | |
215 border, | |
216 fill_center, | |
217 expected_quad_size); | |
218 } | 330 } |
219 | 331 |
220 TEST(NinePatchLayerImplTest, Occlusion) { | 332 TEST(NinePatchLayerImplTest, Occlusion) { |
221 gfx::Size layer_size(1000, 1000); | 333 gfx::Size layer_size(1000, 1000); |
222 gfx::Size viewport_size(1000, 1000); | 334 gfx::Size viewport_size(1000, 1000); |
223 | 335 |
224 LayerTestCommon::LayerImplTest impl; | 336 LayerTestCommon::LayerImplTest impl; |
225 | 337 |
226 SkBitmap sk_bitmap; | 338 SkBitmap sk_bitmap; |
227 sk_bitmap.allocN32Pixels(10, 10); | 339 sk_bitmap.allocN32Pixels(10, 10); |
228 sk_bitmap.setImmutable(); | 340 sk_bitmap.setImmutable(); |
229 UIResourceId uid = 5; | 341 UIResourceId uid = 5; |
230 UIResourceBitmap bitmap(sk_bitmap); | 342 UIResourceBitmap bitmap(sk_bitmap); |
231 impl.host_impl()->CreateUIResource(uid, bitmap); | 343 impl.host_impl()->CreateUIResource(uid, bitmap); |
232 | 344 |
233 NinePatchLayerImpl* nine_patch_layer_impl = | 345 NinePatchLayerImpl* nine_patch_layer_impl = |
234 impl.AddChildToRoot<NinePatchLayerImpl>(); | 346 impl.AddChildToRoot<NinePatchLayerImpl>(); |
235 nine_patch_layer_impl->SetBounds(layer_size); | 347 nine_patch_layer_impl->SetBounds(layer_size); |
236 nine_patch_layer_impl->SetDrawsContent(true); | 348 nine_patch_layer_impl->SetDrawsContent(true); |
237 nine_patch_layer_impl->SetUIResourceId(uid); | 349 nine_patch_layer_impl->SetUIResourceId(uid); |
238 nine_patch_layer_impl->SetImageBounds(gfx::Size(10, 10)); | 350 nine_patch_layer_impl->SetImageBounds(gfx::Size(10, 10)); |
239 | 351 |
240 gfx::Rect aperture = gfx::Rect(3, 3, 4, 4); | 352 gfx::Rect aperture = gfx::Rect(3, 3, 4, 4); |
241 gfx::Rect border = gfx::Rect(300, 300, 400, 400); | 353 gfx::Rect border = gfx::Rect(300, 300, 400, 400); |
242 nine_patch_layer_impl->SetLayout(aperture, border, true, false); | 354 nine_patch_layer_impl->SetLayout(aperture, border, gfx::Rect(), true, false); |
243 | 355 |
244 impl.CalcDrawProps(viewport_size); | 356 impl.CalcDrawProps(viewport_size); |
245 | 357 |
246 { | 358 { |
247 SCOPED_TRACE("No occlusion"); | 359 SCOPED_TRACE("No occlusion"); |
248 gfx::Rect occluded; | 360 gfx::Rect occluded; |
249 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded); | 361 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded); |
250 | 362 |
251 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), | 363 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), |
252 gfx::Rect(layer_size)); | 364 gfx::Rect(layer_size)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 impl.CalcDrawProps(viewport_size); | 422 impl.CalcDrawProps(viewport_size); |
311 | 423 |
312 { | 424 { |
313 SCOPED_TRACE("Use opaque image"); | 425 SCOPED_TRACE("Use opaque image"); |
314 | 426 |
315 nine_patch_layer_impl->SetUIResourceId(uid_opaque); | 427 nine_patch_layer_impl->SetUIResourceId(uid_opaque); |
316 nine_patch_layer_impl->SetImageBounds(gfx::Size(10, 10)); | 428 nine_patch_layer_impl->SetImageBounds(gfx::Size(10, 10)); |
317 | 429 |
318 gfx::Rect aperture = gfx::Rect(3, 3, 4, 4); | 430 gfx::Rect aperture = gfx::Rect(3, 3, 4, 4); |
319 gfx::Rect border = gfx::Rect(300, 300, 400, 400); | 431 gfx::Rect border = gfx::Rect(300, 300, 400, 400); |
320 nine_patch_layer_impl->SetLayout(aperture, border, true, false); | 432 nine_patch_layer_impl->SetLayout(aperture, border, gfx::Rect(), true, |
| 433 false); |
321 | 434 |
322 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect()); | 435 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect()); |
323 | 436 |
324 const QuadList &quad_list = impl.quad_list(); | 437 const QuadList &quad_list = impl.quad_list(); |
325 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); | 438 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); |
326 it != quad_list.BackToFrontEnd(); ++it) | 439 it != quad_list.BackToFrontEnd(); ++it) |
327 EXPECT_FALSE(it->ShouldDrawWithBlending()); | 440 EXPECT_FALSE(it->ShouldDrawWithBlending()); |
328 } | 441 } |
329 | 442 |
330 { | 443 { |
331 SCOPED_TRACE("Use tranparent image"); | 444 SCOPED_TRACE("Use tranparent image"); |
332 | 445 |
333 nine_patch_layer_impl->SetUIResourceId(uid_alpha); | 446 nine_patch_layer_impl->SetUIResourceId(uid_alpha); |
334 | 447 |
335 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect()); | 448 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect()); |
336 | 449 |
337 const QuadList &quad_list = impl.quad_list(); | 450 const QuadList &quad_list = impl.quad_list(); |
338 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); | 451 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); |
339 it != quad_list.BackToFrontEnd(); ++it) | 452 it != quad_list.BackToFrontEnd(); ++it) |
340 EXPECT_TRUE(it->ShouldDrawWithBlending()); | 453 EXPECT_TRUE(it->ShouldDrawWithBlending()); |
341 } | 454 } |
342 } | 455 } |
343 | 456 |
344 } // namespace | 457 } // namespace |
345 } // namespace cc | 458 } // namespace cc |
OLD | NEW |