Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3544)

Unified Diff: cc/layers/nine_patch_layer_impl_unittest.cc

Issue 2083083004: cc: nine patch: add occlusion support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on ToT before commit Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/layers/nine_patch_layer_impl.cc ('k') | ui/compositor/layer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/nine_patch_layer_impl_unittest.cc
diff --git a/cc/layers/nine_patch_layer_impl_unittest.cc b/cc/layers/nine_patch_layer_impl_unittest.cc
index 5919299a95c44799f531bbd0ee0b55288ad7a50f..c31094cd2725c2f89631cb65325556a225d9656c 100644
--- a/cc/layers/nine_patch_layer_impl_unittest.cc
+++ b/cc/layers/nine_patch_layer_impl_unittest.cc
@@ -39,8 +39,7 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
size_t expected_quad_size) {
std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
gfx::Rect visible_layer_rect(layer_size);
- gfx::Rect expected_remaining(border.x(),
- border.y(),
+ gfx::Rect expected_remaining(border.x(), border.y(),
layer_size.width() - border.width(),
layer_size.height() - border.height());
@@ -67,7 +66,7 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
host_impl.CreateUIResource(uid, bitmap);
layer->SetUIResourceId(uid);
layer->SetImageBounds(bitmap_size);
- layer->SetLayout(aperture_rect, border, fill_center, false);
+ layer->SetLayout(aperture_rect, border, gfx::Rect(), fill_center, false);
AppendQuadsData data;
layer->AppendQuads(render_pass.get(), &data);
@@ -75,21 +74,21 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
const QuadList& quads = render_pass->quad_list;
EXPECT_EQ(expected_quad_size, quads.size());
- Region remaining(visible_layer_rect);
+ Region layer_remaining(visible_layer_rect);
for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) {
gfx::Rect quad_rect = iter->rect;
EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index();
- EXPECT_TRUE(remaining.Contains(quad_rect)) << iter.index();
- remaining.Subtract(Region(quad_rect));
+ EXPECT_TRUE(layer_remaining.Contains(quad_rect)) << iter.index();
+ layer_remaining.Subtract(Region(quad_rect));
}
// Check if the left-over quad is the same size as the mapped aperture quad in
// layer space.
if (!fill_center) {
- EXPECT_EQ(expected_remaining, remaining.bounds());
+ EXPECT_EQ(expected_remaining, layer_remaining.bounds());
} else {
- EXPECT_TRUE(remaining.bounds().IsEmpty());
+ EXPECT_TRUE(layer_remaining.bounds().IsEmpty());
}
// Verify UV rects
@@ -108,10 +107,106 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
Region aperture_region(aperture_rect);
EXPECT_EQ(aperture_region, tex_remaining);
} else {
- EXPECT_TRUE(remaining.bounds().IsEmpty());
+ EXPECT_TRUE(layer_remaining.bounds().IsEmpty());
}
}
+void NinePatchLayerLayoutTestWithOcclusion(const gfx::Size& bitmap_size,
+ const gfx::Rect& aperture_rect,
+ const gfx::Size& layer_size,
+ const gfx::Rect& border,
+ const gfx::Rect& occlusion,
+ bool fill_center,
+ size_t expected_quad_size) {
+ std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ gfx::Rect visible_layer_rect(layer_size);
+ int border_left = std::min(border.x(), occlusion.x()),
+ border_top = std::min(border.y(), occlusion.y()),
+ border_right = std::min(border.width() - border.x(),
+ layer_size.width() - occlusion.right()),
+ border_bottom = std::min(border.height() - border.y(),
+ layer_size.height() - occlusion.bottom());
+ gfx::Rect expected_layer_remaining(
+ border_left, border_top, layer_size.width() - border_left - border_right,
+ layer_size.height() - border_top - border_bottom);
+ float ratio_left = border_left == 0 ? 0 : (aperture_rect.x() / border.x()),
+ ratio_top = border_top == 0 ? 0 : (aperture_rect.y() / border.y()),
+ ratio_right = border_right == 0
+ ? 0
+ : ((bitmap_size.width() - aperture_rect.right()) /
+ (border.width() - border.x())),
+ ratio_bottom = border_bottom == 0
+ ? 0
+ : ((bitmap_size.height() - aperture_rect.bottom()) /
+ (border.height() - border.y()));
+ int image_remaining_left = border_left * ratio_left,
+ image_remaining_top = border_top * ratio_top,
+ image_remaining_right = border_right * ratio_right,
+ image_remaining_bottom = border_bottom * ratio_bottom;
+ gfx::Rect expected_tex_remaining(
+ image_remaining_left, image_remaining_top,
+ bitmap_size.width() - image_remaining_right - image_remaining_left,
+ bitmap_size.height() - image_remaining_bottom - image_remaining_top);
+
+ FakeImplTaskRunnerProvider task_runner_provider;
+ TestSharedBitmapManager shared_bitmap_manager;
+ TestTaskGraphRunner task_graph_runner;
+ std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
+ FakeUIResourceLayerTreeHostImpl host_impl(
+ &task_runner_provider, &shared_bitmap_manager, &task_graph_runner);
+ host_impl.SetVisible(true);
+ host_impl.InitializeRenderer(output_surface.get());
+
+ std::unique_ptr<NinePatchLayerImpl> layer =
+ NinePatchLayerImpl::Create(host_impl.active_tree(), 1);
+ layer->draw_properties().visible_layer_rect = visible_layer_rect;
+ layer->SetBounds(layer_size);
+ layer->test_properties()->force_render_surface = true;
+
+ UIResourceId uid = 1;
+ bool is_opaque = false;
+ UIResourceBitmap bitmap(bitmap_size, is_opaque);
+
+ host_impl.CreateUIResource(uid, bitmap);
+ layer->SetUIResourceId(uid);
+ layer->SetImageBounds(bitmap_size);
+ layer->SetLayout(aperture_rect, border, occlusion, false, false);
+ AppendQuadsData data;
+ layer->AppendQuads(render_pass.get(), &data);
+
+ // Verify quad rects
+ const QuadList& quads = render_pass->quad_list;
+ EXPECT_EQ(expected_quad_size, quads.size());
+
+ Region layer_remaining(visible_layer_rect);
+ for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) {
+ gfx::Rect quad_rect = iter->rect;
+
+ EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index();
+ EXPECT_TRUE(layer_remaining.Contains(quad_rect)) << iter.index();
+ layer_remaining.Subtract(Region(quad_rect));
+ }
+
+ // Check if the left-over quad is the same size as the mapped aperture quad in
+ // layer space.
+ EXPECT_EQ(expected_layer_remaining, layer_remaining.bounds());
+
+ // Verify UV rects
+ gfx::Rect bitmap_rect(bitmap_size);
+ Region tex_remaining(bitmap_rect);
+ for (const auto& quad : quads) {
+ const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad);
+ gfx::RectF tex_rect =
+ gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right);
+ tex_rect.Scale(bitmap_size.width(), bitmap_size.height());
+ tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect)));
+ }
+
+ EXPECT_EQ(expected_tex_remaining, tex_remaining.bounds());
+ Region aperture_region(expected_tex_remaining);
+ EXPECT_EQ(aperture_region, tex_remaining);
+}
+
TEST(NinePatchLayerImplTest, VerifyDrawQuads) {
// Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30.
// The bounds of the layer are set to 400x400.
@@ -121,12 +216,8 @@ TEST(NinePatchLayerImplTest, VerifyDrawQuads) {
gfx::Rect border(40, 40, 80, 80);
bool fill_center = false;
size_t expected_quad_size = 8;
- NinePatchLayerLayoutTest(bitmap_size,
- aperture_rect,
- layer_size,
- border,
- fill_center,
- expected_quad_size);
+ NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
+ fill_center, expected_quad_size);
// The bounds of the layer are set to less than the bitmap size.
bitmap_size = gfx::Size(100, 100);
@@ -135,12 +226,8 @@ TEST(NinePatchLayerImplTest, VerifyDrawQuads) {
border = gfx::Rect(10, 10, 25, 15);
fill_center = true;
expected_quad_size = 9;
- NinePatchLayerLayoutTest(bitmap_size,
- aperture_rect,
- layer_size,
- border,
- fill_center,
- expected_quad_size);
+ NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
+ fill_center, expected_quad_size);
// Layer and image sizes are equal.
bitmap_size = gfx::Size(100, 100);
@@ -149,12 +236,53 @@ TEST(NinePatchLayerImplTest, VerifyDrawQuads) {
border = gfx::Rect(20, 30, 40, 50);
fill_center = true;
expected_quad_size = 9;
- NinePatchLayerLayoutTest(bitmap_size,
- aperture_rect,
- layer_size,
- border,
- fill_center,
- expected_quad_size);
+ NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
+ fill_center, expected_quad_size);
+}
+
+TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithOcclusion) {
+ // Occlusion removed part of the border and leaves us with 12 patches.
+ gfx::Size bitmap_size(100, 100);
+ gfx::Rect aperture_rect(30, 30, 40, 40);
+ gfx::Size layer_size(400, 400);
+ gfx::Rect occlusion(20, 20, 360, 360);
+ gfx::Rect border(30, 30, 60, 60);
+ size_t expected_quad_size = 12;
+ NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size,
+ border, occlusion, false,
+ expected_quad_size);
+
+ bitmap_size = gfx::Size(100, 100);
+ aperture_rect = gfx::Rect(20, 30, 60, 40);
+ layer_size = gfx::Size(400, 400);
+ occlusion = gfx::Rect(10, 10, 380, 380);
+ border = gfx::Rect(20, 30, 40, 60);
+ expected_quad_size = 12;
+ NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size,
+ border, occlusion, false,
+ expected_quad_size);
+
+ // All borders are empty, so nothing should be drawn.
+ bitmap_size = gfx::Size(100, 100);
+ aperture_rect = gfx::Rect(0, 0, 100, 100);
+ layer_size = gfx::Size(400, 400);
+ occlusion = gfx::Rect(0, 0, 400, 400);
+ border = gfx::Rect(0, 0, 0, 0);
+ expected_quad_size = 0;
+ NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size,
+ border, occlusion, false,
+ expected_quad_size);
+
+ // Right border is empty, we should have no quads on the right side.
+ bitmap_size = gfx::Size(100, 100);
+ aperture_rect = gfx::Rect(20, 30, 80, 40);
+ layer_size = gfx::Size(400, 400);
+ occlusion = gfx::Rect(10, 10, 390, 380);
+ border = gfx::Rect(20, 30, 20, 60);
+ expected_quad_size = 7;
+ NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size,
+ border, occlusion, false,
+ expected_quad_size);
}
TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) {
@@ -166,12 +294,8 @@ TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) {
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);
+ 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.
@@ -181,12 +305,8 @@ TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) {
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);
+ 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);
@@ -195,12 +315,8 @@ TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) {
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);
+ 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);
@@ -209,12 +325,8 @@ TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) {
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);
+ NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
+ fill_center, expected_quad_size);
}
TEST(NinePatchLayerImplTest, Occlusion) {
@@ -239,7 +351,7 @@ TEST(NinePatchLayerImplTest, Occlusion) {
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, false);
+ nine_patch_layer_impl->SetLayout(aperture, border, gfx::Rect(), true, false);
impl.CalcDrawProps(viewport_size);
@@ -317,7 +429,8 @@ TEST(NinePatchLayerImplTest, OpaqueRect) {
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, false);
+ nine_patch_layer_impl->SetLayout(aperture, border, gfx::Rect(), true,
+ false);
impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect());
« no previous file with comments | « cc/layers/nine_patch_layer_impl.cc ('k') | ui/compositor/layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698