summaryrefslogtreecommitdiffstats
path: root/chromium/cc/layers/nine_patch_layer_impl_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/cc/layers/nine_patch_layer_impl_unittest.cc')
-rw-r--r--chromium/cc/layers/nine_patch_layer_impl_unittest.cc149
1 files changed, 136 insertions, 13 deletions
diff --git a/chromium/cc/layers/nine_patch_layer_impl_unittest.cc b/chromium/cc/layers/nine_patch_layer_impl_unittest.cc
index 60201110a25..b1296769486 100644
--- a/chromium/cc/layers/nine_patch_layer_impl_unittest.cc
+++ b/chromium/cc/layers/nine_patch_layer_impl_unittest.cc
@@ -23,20 +23,22 @@
namespace cc {
namespace {
-gfx::Rect ToRoundedIntRect(gfx::RectF rect_f) {
+gfx::Rect ToRoundedIntRect(const gfx::RectF& rect_f) {
return gfx::Rect(gfx::ToRoundedInt(rect_f.x()),
gfx::ToRoundedInt(rect_f.y()),
gfx::ToRoundedInt(rect_f.width()),
gfx::ToRoundedInt(rect_f.height()));
}
-void NinePatchLayerLayoutTest(gfx::Size bitmap_size,
- gfx::Rect aperture_rect,
- gfx::Size layer_size,
- gfx::Rect border,
+void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
+ const gfx::Rect& aperture_rect,
+ const gfx::Size& layer_size,
+ const gfx::Rect& border,
bool fill_center,
size_t expected_quad_size) {
- MockQuadCuller quad_culler;
+ MockOcclusionTracker<LayerImpl> occlusion_tracker;
+ scoped_ptr<RenderPass> render_pass = RenderPass::Create();
+ MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker);
gfx::Rect visible_content_rect(layer_size);
gfx::Rect expected_remaining(border.x(),
border.y(),
@@ -44,7 +46,8 @@ void NinePatchLayerLayoutTest(gfx::Size bitmap_size,
layer_size.height() - border.height());
FakeImplProxy proxy;
- FakeUIResourceLayerTreeHostImpl host_impl(&proxy);
+ TestSharedBitmapManager shared_bitmap_manager;
+ FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<NinePatchLayerImpl> layer =
NinePatchLayerImpl::Create(host_impl.active_tree(), 1);
layer->draw_properties().visible_content_rect = visible_content_rect;
@@ -54,12 +57,8 @@ void NinePatchLayerLayoutTest(gfx::Size bitmap_size,
layer->draw_properties().render_target = layer.get();
UIResourceId uid = 1;
- SkBitmap skbitmap;
- skbitmap.setConfig(
- SkBitmap::kARGB_8888_Config, bitmap_size.width(), bitmap_size.height());
- skbitmap.allocPixels();
- skbitmap.setImmutable();
- UIResourceBitmap bitmap(skbitmap);
+ bool is_opaque = false;
+ UIResourceBitmap bitmap(bitmap_size, is_opaque);
host_impl.CreateUIResource(uid, bitmap);
layer->SetUIResourceId(uid);
@@ -156,5 +155,129 @@ 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);
+
+ 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->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