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 "base/containers/hash_tables.h" | 5 #include "base/containers/hash_tables.h" |
6 #include "cc/layers/append_quads_data.h" | 6 #include "cc/layers/append_quads_data.h" |
7 #include "cc/layers/nine_patch_layer_impl.h" | 7 #include "cc/layers/nine_patch_layer_impl.h" |
8 #include "cc/quads/texture_draw_quad.h" | 8 #include "cc/quads/texture_draw_quad.h" |
9 #include "cc/resources/ui_resource_bitmap.h" | 9 #include "cc/resources/ui_resource_bitmap.h" |
10 #include "cc/resources/ui_resource_client.h" | 10 #include "cc/resources/ui_resource_client.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 size_t partially_occluded_count = 0; | 264 size_t partially_occluded_count = 0; |
265 LayerTestCommon::VerifyQuadsAreOccluded( | 265 LayerTestCommon::VerifyQuadsAreOccluded( |
266 impl.quad_list(), occluded, &partially_occluded_count); | 266 impl.quad_list(), occluded, &partially_occluded_count); |
267 // The layer outputs nine quads, three of which are partially occluded, and | 267 // The layer outputs nine quads, three of which are partially occluded, and |
268 // three fully occluded. | 268 // three fully occluded. |
269 EXPECT_EQ(6u, impl.quad_list().size()); | 269 EXPECT_EQ(6u, impl.quad_list().size()); |
270 EXPECT_EQ(3u, partially_occluded_count); | 270 EXPECT_EQ(3u, partially_occluded_count); |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 TEST(NinePatchLayerImplTest, VerifyOpaqueRect) { | |
danakj
2014/11/12 16:34:08
Verify is redundant, all tests verify something
| |
275 gfx::Size layer_size(1000, 1000); | |
276 gfx::Size viewport_size(1000, 1000); | |
277 | |
278 LayerTestCommon::LayerImplTest impl; | |
279 | |
280 SkBitmap sk_bitmap_opaque; | |
281 sk_bitmap_opaque.allocN32Pixels(10, 10); | |
282 sk_bitmap_opaque.setImmutable(); | |
283 sk_bitmap_opaque.setAlphaType(kOpaque_SkAlphaType); | |
284 | |
285 UIResourceId uid_opaque = 1; | |
286 UIResourceBitmap bitmap_opaque(sk_bitmap_opaque); | |
287 impl.host_impl()->CreateUIResource(uid_opaque, bitmap_opaque); | |
288 | |
289 SkBitmap sk_bitmap_alpha; | |
290 sk_bitmap_alpha.allocN32Pixels(10, 10); | |
291 sk_bitmap_alpha.setImmutable(); | |
292 sk_bitmap_alpha.setAlphaType(kUnpremul_SkAlphaType); | |
293 | |
294 UIResourceId uid_alpha = 2; | |
295 UIResourceBitmap bitmap_alpha(sk_bitmap_alpha); | |
296 | |
297 impl.host_impl()->CreateUIResource(uid_alpha, bitmap_alpha); | |
298 | |
299 NinePatchLayerImpl *nine_patch_layer_impl = | |
300 impl.AddChildToRoot<NinePatchLayerImpl>(); | |
301 nine_patch_layer_impl->SetBounds(layer_size); | |
302 nine_patch_layer_impl->SetContentBounds(layer_size); | |
303 nine_patch_layer_impl->SetDrawsContent(true); | |
304 nine_patch_layer_impl->SetImageBounds(gfx::Size(10, 10)); | |
305 | |
306 gfx::Rect aperture = gfx::Rect(3, 3, 4, 4); | |
307 gfx::Rect border = gfx::Rect(300, 300, 400, 400); | |
308 nine_patch_layer_impl->SetLayout(aperture, border, true); | |
309 | |
310 impl.CalcDrawProps(viewport_size); | |
311 | |
312 { | |
313 SCOPED_TRACE("Use opaque image"); | |
314 | |
315 nine_patch_layer_impl->SetUIResourceId(uid_opaque); | |
316 | |
317 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect()); | |
318 | |
319 const QuadList &quad_list = impl.quad_list(); | |
320 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); | |
321 it != quad_list.BackToFrontEnd(); ++it) | |
322 EXPECT_EQ(false, it->ShouldDrawWithBlending()); | |
323 } | |
324 | |
325 { | |
326 SCOPED_TRACE("Use tranparent image"); | |
327 | |
328 nine_patch_layer_impl->SetUIResourceId(uid_alpha); | |
329 | |
330 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect()); | |
331 | |
332 const QuadList &quad_list = impl.quad_list(); | |
333 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); | |
334 it != quad_list.BackToFrontEnd(); ++it) | |
335 EXPECT_EQ(true, it->ShouldDrawWithBlending()); | |
336 } | |
337 } | |
338 | |
274 } // namespace | 339 } // namespace |
275 } // namespace cc | 340 } // namespace cc |
OLD | NEW |