From e681b3dc58a974f2810d0009acf9b201699e4f21 Mon Sep 17 00:00:00 2001 From: "dtrainor@chromium.org" Date: Fri, 9 May 2014 01:43:00 +0000 Subject: NinePatchLayer should support aperture on edge It's possible (and happens often at least in Android assets) for the 9-patch aperture to touch the edge of the bitmap. This happens when you want to stretch an edge of the image and not have any 9-patch component there. BUG= Review URL: https://codereview.chromium.org/252323002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269139 0039d316-1c4b-4281-b951-d872f2087c98 --- cc/layers/nine_patch_layer_impl.cc | 17 +------- cc/layers/nine_patch_layer_impl_unittest.cc | 60 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 15 deletions(-) (limited to 'cc') diff --git a/cc/layers/nine_patch_layer_impl.cc b/cc/layers/nine_patch_layer_impl.cc index 990310b..d0596ba 100644 --- a/cc/layers/nine_patch_layer_impl.cc +++ b/cc/layers/nine_patch_layer_impl.cc @@ -63,19 +63,13 @@ void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture, } void NinePatchLayerImpl::CheckGeometryLimitations() { - // TODO(ccameron): the following "greater than or equal to" (GE) checks should - // be greater than (GT) to avoid degenerate nine-patches. The relaxed - // condition "equal to" is a workaround for the overhang shadow use case and - // should be investigated further. - // |border| is in layer space. It cannot exceed the bounds of the layer. - DCHECK(!border_.size().IsEmpty()); DCHECK_GE(bounds().width(), border_.width()); DCHECK_GE(bounds().height(), border_.height()); // Sanity Check on |border| - DCHECK_LT(border_.x(), border_.width()); - DCHECK_LT(border_.y(), border_.height()); + DCHECK_LE(border_.x(), border_.width()); + DCHECK_LE(border_.y(), border_.height()); DCHECK_GE(border_.x(), 0); DCHECK_GE(border_.y(), 0); @@ -84,13 +78,6 @@ void NinePatchLayerImpl::CheckGeometryLimitations() { DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_)) << "image_bounds_ " << gfx::Rect(image_bounds_).ToString() << " image_aperture_ " << image_aperture_.ToString(); - - // Avoid the degenerate cases where the aperture touches the edge of the - // image. - DCHECK_LT(image_aperture_.width(), image_bounds_.width() - 1); - DCHECK_LT(image_aperture_.height(), image_bounds_.height() - 1); - DCHECK_GT(image_aperture_.x(), 0); - DCHECK_GT(image_aperture_.y(), 0); } void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink, diff --git a/cc/layers/nine_patch_layer_impl_unittest.cc b/cc/layers/nine_patch_layer_impl_unittest.cc index c40d915..28d1775 100644 --- a/cc/layers/nine_patch_layer_impl_unittest.cc +++ b/cc/layers/nine_patch_layer_impl_unittest.cc @@ -153,6 +153,66 @@ TEST(NinePatchLayerImplTest, VerifyDrawQuads) { 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); -- cgit v1.1