expected_quad_size);
}
+TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) {
+ // The top component of the 9-patch is empty, so there should be no quads for
+ // the top three components.
+ gfx::Size bitmap_size(100, 100);
+ gfx::Size layer_size(100, 100);
+ gfx::Rect aperture_rect(10, 0, 80, 90);
+ gfx::Rect border(10, 0, 20, 10);
+ bool fill_center = false;
+ size_t expected_quad_size = 5;
+ NinePatchLayerLayoutTest(bitmap_size,
+ aperture_rect,
+ layer_size,
+ border,
+ fill_center,
+ expected_quad_size);
+
+ // The top and left components of the 9-patch are empty, so there should be no
+ // quads for the left and top components.
+ bitmap_size = gfx::Size(100, 100);
+ layer_size = gfx::Size(100, 100);
+ aperture_rect = gfx::Rect(0, 0, 90, 90);
+ border = gfx::Rect(0, 0, 10, 10);
+ fill_center = false;
+ expected_quad_size = 3;
+ NinePatchLayerLayoutTest(bitmap_size,
+ aperture_rect,
+ layer_size,
+ border,
+ fill_center,
+ expected_quad_size);
+
+ // The aperture is the size of the bitmap and the center doesn't draw.
+ bitmap_size = gfx::Size(100, 100);
+ layer_size = gfx::Size(100, 100);
+ aperture_rect = gfx::Rect(0, 0, 100, 100);
+ border = gfx::Rect(0, 0, 0, 0);
+ fill_center = false;
+ expected_quad_size = 0;
+ NinePatchLayerLayoutTest(bitmap_size,
+ aperture_rect,
+ layer_size,
+ border,
+ fill_center,
+ expected_quad_size);
+
+ // The aperture is the size of the bitmap and the center does draw.
+ bitmap_size = gfx::Size(100, 100);
+ layer_size = gfx::Size(100, 100);
+ aperture_rect = gfx::Rect(0, 0, 100, 100);
+ border = gfx::Rect(0, 0, 0, 0);
+ fill_center = true;
+ expected_quad_size = 1;
+ NinePatchLayerLayoutTest(bitmap_size,
+ aperture_rect,
+ layer_size,
+ border,
+ fill_center,
+ expected_quad_size);
+}
+
+TEST(NinePatchLayerImplTest, Occlusion) {
+ gfx::Size layer_size(1000, 1000);
+ gfx::Size viewport_size(1000, 1000);
+
+ LayerTestCommon::LayerImplTest impl;
+
+ SkBitmap sk_bitmap;
+ sk_bitmap.allocN32Pixels(10, 10);
+ sk_bitmap.setImmutable();
+ UIResourceId uid = 5;
+ UIResourceBitmap bitmap(sk_bitmap);
+ impl.host_impl()->CreateUIResource(uid, bitmap);
+
+ NinePatchLayerImpl* nine_patch_layer_impl =
+ impl.AddChildToRoot<NinePatchLayerImpl>();
+ nine_patch_layer_impl->SetAnchorPoint(gfx::PointF());
+ nine_patch_layer_impl->SetBounds(layer_size);
+ nine_patch_layer_impl->SetContentBounds(layer_size);
+ nine_patch_layer_impl->SetDrawsContent(true);
+ nine_patch_layer_impl->SetUIResourceId(uid);
+ nine_patch_layer_impl->SetImageBounds(gfx::Size(10, 10));
+
+ gfx::Rect aperture = gfx::Rect(3, 3, 4, 4);
+ gfx::Rect border = gfx::Rect(300, 300, 400, 400);
+ nine_patch_layer_impl->SetLayout(aperture, border, true);
+
+ impl.CalcDrawProps(viewport_size);
+
+ {
+ SCOPED_TRACE("No occlusion");
+ gfx::Rect occluded;
+ impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded);
+
+ LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
+ gfx::Rect(layer_size));
+ EXPECT_EQ(9u, impl.quad_list().size());
+ }
+
+ {
+ SCOPED_TRACE("Full occlusion");
+ gfx::Rect occluded(nine_patch_layer_impl->visible_content_rect());
+ impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded);
+
+ LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
+ EXPECT_EQ(impl.quad_list().size(), 0u);
+ }
+
+ {
+ SCOPED_TRACE("Partial occlusion");
+ gfx::Rect occluded(0, 0, 500, 1000);
+ impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded);
+
+ size_t partially_occluded_count = 0;
+ LayerTestCommon::VerifyQuadsCoverRectWithOcclusion(
+ impl.quad_list(),
+ gfx::Rect(layer_size),
+ occluded,
+ &partially_occluded_count);
+ // The layer outputs nine quads, three of which are partially occluded, and
+ // three fully occluded.
+ EXPECT_EQ(6u, impl.quad_list().size());
+ EXPECT_EQ(3u, partially_occluded_count);
+ }
+}
+
} // namespace
} // namespace cc