blob: 385b044e2f4fe99eba6724997e67206dd5f5b668 [file] [log] [blame]
[email protected]35680c02012-11-06 05:53:001// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avi02a4d172015-12-21 06:14:365#include <stddef.h>
6
[email protected]cc3cfaa2013-03-18 09:05:527#include "cc/layers/append_quads_data.h"
8#include "cc/layers/nine_patch_layer_impl.h"
[email protected]741fba422013-09-20 03:34:149#include "cc/resources/ui_resource_bitmap.h"
10#include "cc/resources/ui_resource_client.h"
khushalsagarb64b360d2015-10-21 19:25:1611#include "cc/test/fake_impl_task_runner_provider.h"
danakjc7afae52017-06-20 21:12:4112#include "cc/test/fake_layer_tree_frame_sink.h"
[email protected]efbdb3a2013-10-04 00:35:1313#include "cc/test/fake_ui_resource_layer_tree_host_impl.h"
[email protected]35680c02012-11-06 05:53:0014#include "cc/test/geometry_test_utils.h"
15#include "cc/test/layer_test_common.h"
[email protected]556fd292013-03-18 08:03:0416#include "cc/trees/single_thread_proxy.h"
danakje5805be2017-09-15 19:24:5517#include "components/viz/common/quads/texture_draw_quad.h"
[email protected]35680c02012-11-06 05:53:0018#include "testing/gmock/include/gmock/gmock.h"
19#include "testing/gtest/include/gtest/gtest.h"
heejin.r.chungd28506ba2014-10-23 16:36:2020#include "ui/gfx/geometry/rect_conversions.h"
21#include "ui/gfx/geometry/safe_integer_conversions.h"
[email protected]c8686a02012-11-27 08:29:0022#include "ui/gfx/transform.h"
[email protected]35680c02012-11-06 05:53:0023
[email protected]ba565742012-11-10 09:29:4824namespace cc {
[email protected]35680c02012-11-06 05:53:0025namespace {
26
[email protected]0023fc72014-01-10 20:05:0627gfx::Rect ToRoundedIntRect(const gfx::RectF& rect_f) {
[email protected]57115a42013-03-24 10:00:4928 return gfx::Rect(gfx::ToRoundedInt(rect_f.x()),
29 gfx::ToRoundedInt(rect_f.y()),
30 gfx::ToRoundedInt(rect_f.width()),
31 gfx::ToRoundedInt(rect_f.height()));
[email protected]35680c02012-11-06 05:53:0032}
33
[email protected]64348ea2014-01-29 22:58:2634void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
[email protected]0023fc72014-01-10 20:05:0635 const gfx::Rect& aperture_rect,
[email protected]64348ea2014-01-29 22:58:2636 const gfx::Size& layer_size,
[email protected]0023fc72014-01-10 20:05:0637 const gfx::Rect& border,
[email protected]741fba422013-09-20 03:34:1438 bool fill_center,
39 size_t expected_quad_size) {
danakje5805be2017-09-15 19:24:5540 std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
danakj64767d902015-06-19 00:10:4341 gfx::Rect visible_layer_rect(layer_size);
lionel.g.landwerlin258c7d32016-07-27 09:55:2442 gfx::Rect expected_remaining(border.x(), border.y(),
lionel.g.landwerlineec4f7b2016-05-16 18:46:4643 layer_size.width() - border.width(),
44 layer_size.height() - border.height());
[email protected]35680c02012-11-06 05:53:0045
khushalsagarb64b360d2015-10-21 19:25:1646 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:5647 TestTaskGraphRunner task_graph_runner;
danakjc7afae52017-06-20 21:12:4148 std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink =
49 FakeLayerTreeFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:2250 FakeUIResourceLayerTreeHostImpl host_impl(&task_runner_provider,
51 &task_graph_runner);
sievers71c62dd52015-10-07 01:44:3952 host_impl.SetVisible(true);
danakjc7afae52017-06-20 21:12:4153 host_impl.InitializeRenderer(layer_tree_frame_sink.get());
danakj26bcd452015-04-07 20:14:3954
danakj60bc3bc2016-04-09 00:24:4855 std::unique_ptr<NinePatchLayerImpl> layer =
[email protected]57115a42013-03-24 10:00:4956 NinePatchLayerImpl::Create(host_impl.active_tree(), 1);
danakj64767d902015-06-19 00:10:4357 layer->draw_properties().visible_layer_rect = visible_layer_rect;
[email protected]57115a42013-03-24 10:00:4958 layer->SetBounds(layer_size);
jaydasika6b5a32bf2016-04-22 21:56:3659 layer->test_properties()->force_render_surface = true;
[email protected]35680c02012-11-06 05:53:0060
[email protected]741fba422013-09-20 03:34:1461 UIResourceId uid = 1;
[email protected]0046982c2014-03-25 22:00:5162 bool is_opaque = false;
63 UIResourceBitmap bitmap(bitmap_size, is_opaque);
[email protected]35680c02012-11-06 05:53:0064
[email protected]741fba422013-09-20 03:34:1465 host_impl.CreateUIResource(uid, bitmap);
66 layer->SetUIResourceId(uid);
[email protected]efbdb3a2013-10-04 00:35:1367 layer->SetImageBounds(bitmap_size);
lionel.g.landwerlin258c7d32016-07-27 09:55:2468 layer->SetLayout(aperture_rect, border, gfx::Rect(), fill_center, false);
wkormanf09921d2017-01-07 01:01:2069 host_impl.active_tree()->SetRootLayerForTesting(std::move(layer));
70 host_impl.active_tree()->BuildPropertyTreesForTesting();
71
[email protected]57115a42013-03-24 10:00:4972 AppendQuadsData data;
wkormanf09921d2017-01-07 01:01:2073 host_impl.active_tree()->root_layer_for_testing()->AppendQuads(
74 render_pass.get(), &data);
[email protected]35680c02012-11-06 05:53:0075
[email protected]57115a42013-03-24 10:00:4976 // Verify quad rects
danakje5805be2017-09-15 19:24:5577 const auto& quads = render_pass->quad_list;
[email protected]741fba422013-09-20 03:34:1478 EXPECT_EQ(expected_quad_size, quads.size());
79
lionel.g.landwerlin258c7d32016-07-27 09:55:2480 Region layer_remaining(visible_layer_rect);
weiliangc7eb7ee62014-10-07 00:04:4081 for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) {
weiliangc032e929d2014-09-26 01:55:0182 gfx::Rect quad_rect = iter->rect;
[email protected]35680c02012-11-06 05:53:0083
danakj64767d902015-06-19 00:10:4384 EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index();
lionel.g.landwerlin258c7d32016-07-27 09:55:2485 EXPECT_TRUE(layer_remaining.Contains(quad_rect)) << iter.index();
yiyix10141eca2017-09-05 20:36:5286 EXPECT_EQ(iter->needs_blending,
87 !iter->shared_quad_state->are_contents_opaque);
lionel.g.landwerlin258c7d32016-07-27 09:55:2488 layer_remaining.Subtract(Region(quad_rect));
[email protected]57115a42013-03-24 10:00:4989 }
[email protected]741fba422013-09-20 03:34:1490
91 // Check if the left-over quad is the same size as the mapped aperture quad in
92 // layer space.
93 if (!fill_center) {
lionel.g.landwerlin258c7d32016-07-27 09:55:2494 EXPECT_EQ(expected_remaining, layer_remaining.bounds());
[email protected]741fba422013-09-20 03:34:1495 } else {
lionel.g.landwerlin258c7d32016-07-27 09:55:2496 EXPECT_TRUE(layer_remaining.bounds().IsEmpty());
[email protected]741fba422013-09-20 03:34:1497 }
[email protected]35680c02012-11-06 05:53:0098
[email protected]57115a42013-03-24 10:00:4999 // Verify UV rects
[email protected]2c7c6702013-03-26 03:14:05100 gfx::Rect bitmap_rect(bitmap_size);
[email protected]57115a42013-03-24 10:00:49101 Region tex_remaining(bitmap_rect);
vmpstra2e89432016-07-20 02:05:34102 for (auto* quad : quads) {
danakje5805be2017-09-15 19:24:55103 const viz::TextureDrawQuad* tex_quad =
104 viz::TextureDrawQuad::MaterialCast(quad);
[email protected]57115a42013-03-24 10:00:49105 gfx::RectF tex_rect =
106 gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right);
107 tex_rect.Scale(bitmap_size.width(), bitmap_size.height());
108 tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect)));
109 }
[email protected]741fba422013-09-20 03:34:14110
111 if (!fill_center) {
lionel.g.landwerlineec4f7b2016-05-16 18:46:46112 EXPECT_EQ(aperture_rect, tex_remaining.bounds());
113 Region aperture_region(aperture_rect);
[email protected]741fba422013-09-20 03:34:14114 EXPECT_EQ(aperture_region, tex_remaining);
115 } else {
lionel.g.landwerlin258c7d32016-07-27 09:55:24116 EXPECT_TRUE(layer_remaining.bounds().IsEmpty());
[email protected]741fba422013-09-20 03:34:14117 }
[email protected]411ccfc2012-11-21 22:14:12118}
119
lionel.g.landwerlin258c7d32016-07-27 09:55:24120void NinePatchLayerLayoutTestWithOcclusion(const gfx::Size& bitmap_size,
121 const gfx::Rect& aperture_rect,
122 const gfx::Size& layer_size,
123 const gfx::Rect& border,
124 const gfx::Rect& occlusion,
125 bool fill_center,
126 size_t expected_quad_size) {
danakje5805be2017-09-15 19:24:55127 std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
lionel.g.landwerlin258c7d32016-07-27 09:55:24128 gfx::Rect visible_layer_rect(layer_size);
129 int border_left = std::min(border.x(), occlusion.x()),
130 border_top = std::min(border.y(), occlusion.y()),
131 border_right = std::min(border.width() - border.x(),
132 layer_size.width() - occlusion.right()),
133 border_bottom = std::min(border.height() - border.y(),
134 layer_size.height() - occlusion.bottom());
135 gfx::Rect expected_layer_remaining(
136 border_left, border_top, layer_size.width() - border_left - border_right,
137 layer_size.height() - border_top - border_bottom);
138 float ratio_left = border_left == 0 ? 0 : (aperture_rect.x() / border.x()),
139 ratio_top = border_top == 0 ? 0 : (aperture_rect.y() / border.y()),
140 ratio_right = border_right == 0
141 ? 0
142 : ((bitmap_size.width() - aperture_rect.right()) /
143 (border.width() - border.x())),
144 ratio_bottom = border_bottom == 0
145 ? 0
146 : ((bitmap_size.height() - aperture_rect.bottom()) /
147 (border.height() - border.y()));
148 int image_remaining_left = border_left * ratio_left,
149 image_remaining_top = border_top * ratio_top,
150 image_remaining_right = border_right * ratio_right,
151 image_remaining_bottom = border_bottom * ratio_bottom;
152 gfx::Rect expected_tex_remaining(
153 image_remaining_left, image_remaining_top,
154 bitmap_size.width() - image_remaining_right - image_remaining_left,
155 bitmap_size.height() - image_remaining_bottom - image_remaining_top);
156
157 FakeImplTaskRunnerProvider task_runner_provider;
lionel.g.landwerlin258c7d32016-07-27 09:55:24158 TestTaskGraphRunner task_graph_runner;
danakjc7afae52017-06-20 21:12:41159 std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink =
160 FakeLayerTreeFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:22161 FakeUIResourceLayerTreeHostImpl host_impl(&task_runner_provider,
162 &task_graph_runner);
lionel.g.landwerlin258c7d32016-07-27 09:55:24163 host_impl.SetVisible(true);
danakjc7afae52017-06-20 21:12:41164 host_impl.InitializeRenderer(layer_tree_frame_sink.get());
lionel.g.landwerlin258c7d32016-07-27 09:55:24165
166 std::unique_ptr<NinePatchLayerImpl> layer =
167 NinePatchLayerImpl::Create(host_impl.active_tree(), 1);
168 layer->draw_properties().visible_layer_rect = visible_layer_rect;
169 layer->SetBounds(layer_size);
170 layer->test_properties()->force_render_surface = true;
171
172 UIResourceId uid = 1;
173 bool is_opaque = false;
174 UIResourceBitmap bitmap(bitmap_size, is_opaque);
175
176 host_impl.CreateUIResource(uid, bitmap);
177 layer->SetUIResourceId(uid);
178 layer->SetImageBounds(bitmap_size);
179 layer->SetLayout(aperture_rect, border, occlusion, false, false);
wkormanf09921d2017-01-07 01:01:20180 host_impl.active_tree()->SetRootLayerForTesting(std::move(layer));
181 host_impl.active_tree()->BuildPropertyTreesForTesting();
182
lionel.g.landwerlin258c7d32016-07-27 09:55:24183 AppendQuadsData data;
wkormanf09921d2017-01-07 01:01:20184 host_impl.active_tree()->root_layer_for_testing()->AppendQuads(
185 render_pass.get(), &data);
lionel.g.landwerlin258c7d32016-07-27 09:55:24186
187 // Verify quad rects
danakje5805be2017-09-15 19:24:55188 const auto& quads = render_pass->quad_list;
lionel.g.landwerlin258c7d32016-07-27 09:55:24189 EXPECT_EQ(expected_quad_size, quads.size());
190
191 Region layer_remaining(visible_layer_rect);
192 for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) {
193 gfx::Rect quad_rect = iter->rect;
194
195 EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index();
196 EXPECT_TRUE(layer_remaining.Contains(quad_rect)) << iter.index();
yiyix10141eca2017-09-05 20:36:52197 EXPECT_EQ(iter->needs_blending,
198 !iter->shared_quad_state->are_contents_opaque);
lionel.g.landwerlin258c7d32016-07-27 09:55:24199 layer_remaining.Subtract(Region(quad_rect));
200 }
201
202 // Check if the left-over quad is the same size as the mapped aperture quad in
203 // layer space.
204 EXPECT_EQ(expected_layer_remaining, layer_remaining.bounds());
205
206 // Verify UV rects
207 gfx::Rect bitmap_rect(bitmap_size);
208 Region tex_remaining(bitmap_rect);
vmpstr691539d2017-02-13 19:49:18209 for (auto* quad : quads) {
danakje5805be2017-09-15 19:24:55210 const viz::TextureDrawQuad* tex_quad =
211 viz::TextureDrawQuad::MaterialCast(quad);
lionel.g.landwerlin258c7d32016-07-27 09:55:24212 gfx::RectF tex_rect =
213 gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right);
214 tex_rect.Scale(bitmap_size.width(), bitmap_size.height());
215 tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect)));
216 }
217
218 EXPECT_EQ(expected_tex_remaining, tex_remaining.bounds());
219 Region aperture_region(expected_tex_remaining);
220 EXPECT_EQ(aperture_region, tex_remaining);
221}
222
[email protected]741fba422013-09-20 03:34:14223TEST(NinePatchLayerImplTest, VerifyDrawQuads) {
224 // Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30.
225 // The bounds of the layer are set to 400x400.
226 gfx::Size bitmap_size(100, 100);
227 gfx::Size layer_size(400, 500);
228 gfx::Rect aperture_rect(20, 30, 40, 50);
229 gfx::Rect border(40, 40, 80, 80);
230 bool fill_center = false;
231 size_t expected_quad_size = 8;
lionel.g.landwerlin258c7d32016-07-27 09:55:24232 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
233 fill_center, expected_quad_size);
[email protected]411ccfc2012-11-21 22:14:12234
[email protected]741fba422013-09-20 03:34:14235 // The bounds of the layer are set to less than the bitmap size.
236 bitmap_size = gfx::Size(100, 100);
237 layer_size = gfx::Size(40, 50);
238 aperture_rect = gfx::Rect(20, 30, 40, 50);
239 border = gfx::Rect(10, 10, 25, 15);
240 fill_center = true;
241 expected_quad_size = 9;
lionel.g.landwerlin258c7d32016-07-27 09:55:24242 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
243 fill_center, expected_quad_size);
[email protected]411ccfc2012-11-21 22:14:12244
[email protected]741fba422013-09-20 03:34:14245 // Layer and image sizes are equal.
246 bitmap_size = gfx::Size(100, 100);
247 layer_size = gfx::Size(100, 100);
248 aperture_rect = gfx::Rect(20, 30, 40, 50);
249 border = gfx::Rect(20, 30, 40, 50);
250 fill_center = true;
251 expected_quad_size = 9;
lionel.g.landwerlin258c7d32016-07-27 09:55:24252 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
253 fill_center, expected_quad_size);
254}
255
256TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithOcclusion) {
257 // Occlusion removed part of the border and leaves us with 12 patches.
258 gfx::Size bitmap_size(100, 100);
259 gfx::Rect aperture_rect(30, 30, 40, 40);
260 gfx::Size layer_size(400, 400);
261 gfx::Rect occlusion(20, 20, 360, 360);
262 gfx::Rect border(30, 30, 60, 60);
263 size_t expected_quad_size = 12;
264 NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size,
265 border, occlusion, false,
266 expected_quad_size);
267
268 bitmap_size = gfx::Size(100, 100);
269 aperture_rect = gfx::Rect(20, 30, 60, 40);
270 layer_size = gfx::Size(400, 400);
271 occlusion = gfx::Rect(10, 10, 380, 380);
272 border = gfx::Rect(20, 30, 40, 60);
273 expected_quad_size = 12;
274 NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size,
275 border, occlusion, false,
276 expected_quad_size);
277
278 // All borders are empty, so nothing should be drawn.
279 bitmap_size = gfx::Size(100, 100);
280 aperture_rect = gfx::Rect(0, 0, 100, 100);
281 layer_size = gfx::Size(400, 400);
282 occlusion = gfx::Rect(0, 0, 400, 400);
283 border = gfx::Rect(0, 0, 0, 0);
284 expected_quad_size = 0;
285 NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size,
286 border, occlusion, false,
287 expected_quad_size);
288
289 // Right border is empty, we should have no quads on the right side.
290 bitmap_size = gfx::Size(100, 100);
291 aperture_rect = gfx::Rect(20, 30, 80, 40);
292 layer_size = gfx::Size(400, 400);
293 occlusion = gfx::Rect(10, 10, 390, 380);
294 border = gfx::Rect(20, 30, 20, 60);
295 expected_quad_size = 7;
296 NinePatchLayerLayoutTestWithOcclusion(bitmap_size, aperture_rect, layer_size,
297 border, occlusion, false,
298 expected_quad_size);
[email protected]35680c02012-11-06 05:53:00299}
300
[email protected]e681b3d2014-05-09 01:43:00301TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) {
302 // The top component of the 9-patch is empty, so there should be no quads for
303 // the top three components.
304 gfx::Size bitmap_size(100, 100);
305 gfx::Size layer_size(100, 100);
306 gfx::Rect aperture_rect(10, 0, 80, 90);
307 gfx::Rect border(10, 0, 20, 10);
308 bool fill_center = false;
309 size_t expected_quad_size = 5;
lionel.g.landwerlin258c7d32016-07-27 09:55:24310 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
311 fill_center, expected_quad_size);
[email protected]e681b3d2014-05-09 01:43:00312
313 // The top and left components of the 9-patch are empty, so there should be no
314 // quads for the left and top components.
315 bitmap_size = gfx::Size(100, 100);
316 layer_size = gfx::Size(100, 100);
317 aperture_rect = gfx::Rect(0, 0, 90, 90);
318 border = gfx::Rect(0, 0, 10, 10);
319 fill_center = false;
320 expected_quad_size = 3;
lionel.g.landwerlin258c7d32016-07-27 09:55:24321 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
322 fill_center, expected_quad_size);
[email protected]e681b3d2014-05-09 01:43:00323
324 // The aperture is the size of the bitmap and the center doesn't draw.
325 bitmap_size = gfx::Size(100, 100);
326 layer_size = gfx::Size(100, 100);
327 aperture_rect = gfx::Rect(0, 0, 100, 100);
328 border = gfx::Rect(0, 0, 0, 0);
329 fill_center = false;
330 expected_quad_size = 0;
lionel.g.landwerlin258c7d32016-07-27 09:55:24331 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
332 fill_center, expected_quad_size);
[email protected]e681b3d2014-05-09 01:43:00333
334 // The aperture is the size of the bitmap and the center does draw.
335 bitmap_size = gfx::Size(100, 100);
336 layer_size = gfx::Size(100, 100);
337 aperture_rect = gfx::Rect(0, 0, 100, 100);
338 border = gfx::Rect(0, 0, 0, 0);
339 fill_center = true;
340 expected_quad_size = 1;
lionel.g.landwerlin258c7d32016-07-27 09:55:24341 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border,
342 fill_center, expected_quad_size);
[email protected]e681b3d2014-05-09 01:43:00343}
344
[email protected]ffe27342014-04-18 01:25:06345TEST(NinePatchLayerImplTest, Occlusion) {
346 gfx::Size layer_size(1000, 1000);
347 gfx::Size viewport_size(1000, 1000);
348
349 LayerTestCommon::LayerImplTest impl;
350
351 SkBitmap sk_bitmap;
352 sk_bitmap.allocN32Pixels(10, 10);
353 sk_bitmap.setImmutable();
354 UIResourceId uid = 5;
355 UIResourceBitmap bitmap(sk_bitmap);
356 impl.host_impl()->CreateUIResource(uid, bitmap);
357
358 NinePatchLayerImpl* nine_patch_layer_impl =
359 impl.AddChildToRoot<NinePatchLayerImpl>();
[email protected]ffe27342014-04-18 01:25:06360 nine_patch_layer_impl->SetBounds(layer_size);
[email protected]ffe27342014-04-18 01:25:06361 nine_patch_layer_impl->SetDrawsContent(true);
362 nine_patch_layer_impl->SetUIResourceId(uid);
363 nine_patch_layer_impl->SetImageBounds(gfx::Size(10, 10));
364
365 gfx::Rect aperture = gfx::Rect(3, 3, 4, 4);
366 gfx::Rect border = gfx::Rect(300, 300, 400, 400);
lionel.g.landwerlin258c7d32016-07-27 09:55:24367 nine_patch_layer_impl->SetLayout(aperture, border, gfx::Rect(), true, false);
[email protected]ffe27342014-04-18 01:25:06368
369 impl.CalcDrawProps(viewport_size);
370
371 {
372 SCOPED_TRACE("No occlusion");
373 gfx::Rect occluded;
374 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded);
375
376 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
377 gfx::Rect(layer_size));
378 EXPECT_EQ(9u, impl.quad_list().size());
379 }
380
381 {
382 SCOPED_TRACE("Full occlusion");
danakj64767d902015-06-19 00:10:43383 gfx::Rect occluded(nine_patch_layer_impl->visible_layer_rect());
[email protected]ffe27342014-04-18 01:25:06384 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded);
385
386 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
387 EXPECT_EQ(impl.quad_list().size(), 0u);
388 }
389
390 {
391 SCOPED_TRACE("Partial occlusion");
392 gfx::Rect occluded(0, 0, 500, 1000);
393 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded);
394
395 size_t partially_occluded_count = 0;
hartmanng53af0fe2014-09-22 20:26:11396 LayerTestCommon::VerifyQuadsAreOccluded(
397 impl.quad_list(), occluded, &partially_occluded_count);
[email protected]ffe27342014-04-18 01:25:06398 // The layer outputs nine quads, three of which are partially occluded, and
399 // three fully occluded.
400 EXPECT_EQ(6u, impl.quad_list().size());
401 EXPECT_EQ(3u, partially_occluded_count);
402 }
403}
404
jungjik.leec9ca7822014-11-14 01:10:27405TEST(NinePatchLayerImplTest, OpaqueRect) {
406 gfx::Size layer_size(1000, 1000);
407 gfx::Size viewport_size(1000, 1000);
408
409 LayerTestCommon::LayerImplTest impl;
410
411 SkBitmap sk_bitmap_opaque;
412 sk_bitmap_opaque.allocN32Pixels(10, 10);
413 sk_bitmap_opaque.setImmutable();
414 sk_bitmap_opaque.setAlphaType(kOpaque_SkAlphaType);
415
416 UIResourceId uid_opaque = 6;
417 UIResourceBitmap bitmap_opaque(sk_bitmap_opaque);
418 impl.host_impl()->CreateUIResource(uid_opaque, bitmap_opaque);
419
420 SkBitmap sk_bitmap_alpha;
421 sk_bitmap_alpha.allocN32Pixels(10, 10);
422 sk_bitmap_alpha.setImmutable();
423 sk_bitmap_alpha.setAlphaType(kUnpremul_SkAlphaType);
424
425 UIResourceId uid_alpha = 7;
426 UIResourceBitmap bitmap_alpha(sk_bitmap_alpha);
427
428 impl.host_impl()->CreateUIResource(uid_alpha, bitmap_alpha);
429
430 NinePatchLayerImpl *nine_patch_layer_impl =
431 impl.AddChildToRoot<NinePatchLayerImpl>();
432 nine_patch_layer_impl->SetBounds(layer_size);
jungjik.leec9ca7822014-11-14 01:10:27433 nine_patch_layer_impl->SetDrawsContent(true);
434
435 impl.CalcDrawProps(viewport_size);
436
437 {
438 SCOPED_TRACE("Use opaque image");
439
440 nine_patch_layer_impl->SetUIResourceId(uid_opaque);
441 nine_patch_layer_impl->SetImageBounds(gfx::Size(10, 10));
442
443 gfx::Rect aperture = gfx::Rect(3, 3, 4, 4);
444 gfx::Rect border = gfx::Rect(300, 300, 400, 400);
lionel.g.landwerlin258c7d32016-07-27 09:55:24445 nine_patch_layer_impl->SetLayout(aperture, border, gfx::Rect(), true,
446 false);
jungjik.leec9ca7822014-11-14 01:10:27447
448 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect());
449
danakje5805be2017-09-15 19:24:55450 const auto& quad_list = impl.quad_list();
451 for (auto it = quad_list.BackToFrontBegin();
jungjik.leec9ca7822014-11-14 01:10:27452 it != quad_list.BackToFrontEnd(); ++it)
453 EXPECT_FALSE(it->ShouldDrawWithBlending());
454 }
455
456 {
457 SCOPED_TRACE("Use tranparent image");
458
459 nine_patch_layer_impl->SetUIResourceId(uid_alpha);
460
461 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect());
462
danakje5805be2017-09-15 19:24:55463 const auto& quad_list = impl.quad_list();
464 for (auto it = quad_list.BackToFrontBegin();
jungjik.leec9ca7822014-11-14 01:10:27465 it != quad_list.BackToFrontEnd(); ++it)
466 EXPECT_TRUE(it->ShouldDrawWithBlending());
467 }
468}
469
[email protected]ba565742012-11-10 09:29:48470} // namespace
471} // namespace cc