Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "cc/layers/append_quads_data.h" | 7 #include "cc/layers/append_quads_data.h" |
| 8 #include "cc/layers/nine_patch_layer_impl.h" | 8 #include "cc/layers/nine_patch_layer_impl.h" |
| 9 #include "cc/quads/texture_draw_quad.h" | 9 #include "cc/quads/texture_draw_quad.h" |
| 10 #include "cc/resources/ui_resource_bitmap.h" | 10 #include "cc/resources/ui_resource_bitmap.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 namespace cc { | 24 namespace cc { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 gfx::Rect ToRoundedIntRect(const gfx::RectF& rect_f) { | 27 gfx::Rect ToRoundedIntRect(const gfx::RectF& rect_f) { |
| 28 return gfx::Rect(gfx::ToRoundedInt(rect_f.x()), | 28 return gfx::Rect(gfx::ToRoundedInt(rect_f.x()), |
| 29 gfx::ToRoundedInt(rect_f.y()), | 29 gfx::ToRoundedInt(rect_f.y()), |
| 30 gfx::ToRoundedInt(rect_f.width()), | 30 gfx::ToRoundedInt(rect_f.width()), |
| 31 gfx::ToRoundedInt(rect_f.height())); | 31 gfx::ToRoundedInt(rect_f.height())); |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool ShouldUseOcclusion(const gfx::Size& bitmap_size, | |
|
aelias_OOO_until_Jul13
2016/05/05 04:17:57
It's a bad practice to copy-paste production code
llandwerlin-old
2016/05/06 16:26:48
Done.
| |
| 35 const gfx::Rect& aperture_rect, | |
| 36 const gfx::Size& layer_size, | |
| 37 const gfx::Rect& border, | |
| 38 const gfx::Rect& occlusion, | |
| 39 bool fill_center) { | |
| 40 if (occlusion.IsEmpty()) | |
| 41 return false; | |
| 42 | |
| 43 if (fill_center) | |
| 44 return false; | |
| 45 | |
| 46 if (border.x() == 0 || border.y() == 0 || | |
| 47 (border.width() - border.x()) == 0 || (border.height() - border.y()) == 0) | |
| 48 return false; | |
| 49 | |
| 50 if (occlusion.x() == 0 || occlusion.y() == 0 || | |
| 51 occlusion.right() == layer_size.width() || | |
| 52 occlusion.bottom() == layer_size.height()) | |
| 53 return false; | |
| 54 | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 34 void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, | 58 void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, |
| 35 const gfx::Rect& aperture_rect, | 59 const gfx::Rect& aperture_rect, |
| 36 const gfx::Size& layer_size, | 60 const gfx::Size& layer_size, |
| 37 const gfx::Rect& border, | 61 const gfx::Rect& border, |
| 38 const gfx::Rect& occlusion, | 62 const gfx::Rect& occlusion, |
| 39 bool fill_center, | 63 bool fill_center, |
| 40 size_t expected_quad_size) { | 64 size_t expected_quad_size) { |
| 41 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); | 65 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 42 gfx::Rect visible_layer_rect(layer_size); | 66 gfx::Rect visible_layer_rect(layer_size); |
| 43 gfx::Rect expected_layer_remaining; | 67 gfx::Rect expected_layer_remaining; |
| 44 gfx::Rect expected_tex_remaining; | 68 gfx::Rect expected_tex_remaining; |
| 45 | 69 |
| 46 if (!occlusion.IsEmpty()) { | 70 if (ShouldUseOcclusion(bitmap_size, aperture_rect, layer_size, border, |
| 47 expected_layer_remaining = occlusion; | 71 occlusion, fill_center)) { |
| 72 expected_layer_remaining.SetRect( | |
|
aelias_OOO_until_Jul13
2016/05/05 04:17:57
All this is too much logic for a test, this makes
llandwerlin-old
2016/05/06 16:26:48
Done.
| |
| 73 std::min(border.x(), occlusion.x()), | |
| 74 std::min(border.y(), occlusion.y()), | |
| 75 std::max(layer_size.width() - border.width(), occlusion.width()), | |
| 76 std::max(layer_size.height() - border.height(), occlusion.height())); | |
| 77 float ratio_left = aperture_rect.x() / border.x(), | |
| 78 ratio_top = aperture_rect.y() / border.y(), | |
| 79 ratio_right = (bitmap_size.width() - aperture_rect.right()) / | |
| 80 (border.width() - border.x()), | |
| 81 ratio_bottom = (bitmap_size.height() - aperture_rect.bottom()) / | |
| 82 (border.height() - border.y()); | |
| 83 int image_remaining_left = expected_layer_remaining.x() * ratio_left, | |
| 84 image_remaining_top = expected_layer_remaining.y() * ratio_top, | |
| 85 image_remaining_right = | |
| 86 (layer_size.width() - expected_layer_remaining.right()) * | |
| 87 ratio_right, | |
| 88 image_remaining_bottom = | |
| 89 (layer_size.height() - expected_layer_remaining.bottom()) * | |
| 90 ratio_bottom; | |
| 48 expected_tex_remaining.SetRect( | 91 expected_tex_remaining.SetRect( |
| 49 occlusion.x(), occlusion.y(), | 92 image_remaining_left, image_remaining_top, |
| 50 (bitmap_size.width() - occlusion.x()) - | 93 bitmap_size.width() - image_remaining_right - image_remaining_left, |
| 51 (layer_size.width() - occlusion.right()), | 94 bitmap_size.height() - image_remaining_bottom - image_remaining_top); |
| 52 (bitmap_size.height() - occlusion.y()) - | |
| 53 (layer_size.height() - occlusion.bottom())); | |
| 54 } else { | 95 } else { |
| 55 expected_layer_remaining.SetRect(border.x(), border.y(), | 96 expected_layer_remaining.SetRect(border.x(), border.y(), |
| 56 layer_size.width() - border.width(), | 97 layer_size.width() - border.width(), |
| 57 layer_size.height() - border.height()); | 98 layer_size.height() - border.height()); |
| 58 expected_tex_remaining = aperture_rect; | 99 expected_tex_remaining = aperture_rect; |
| 59 } | 100 } |
| 60 | 101 |
| 61 FakeImplTaskRunnerProvider task_runner_provider; | 102 FakeImplTaskRunnerProvider task_runner_provider; |
| 62 TestSharedBitmapManager shared_bitmap_manager; | 103 TestSharedBitmapManager shared_bitmap_manager; |
| 63 TestTaskGraphRunner task_graph_runner; | 104 TestTaskGraphRunner task_graph_runner; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 layer_size = gfx::Size(100, 100); | 193 layer_size = gfx::Size(100, 100); |
| 153 aperture_rect = gfx::Rect(20, 30, 40, 50); | 194 aperture_rect = gfx::Rect(20, 30, 40, 50); |
| 154 border = gfx::Rect(20, 30, 40, 50); | 195 border = gfx::Rect(20, 30, 40, 50); |
| 155 fill_center = true; | 196 fill_center = true; |
| 156 expected_quad_size = 9; | 197 expected_quad_size = 9; |
| 157 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, | 198 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
| 158 gfx::Rect(), fill_center, expected_quad_size); | 199 gfx::Rect(), fill_center, expected_quad_size); |
| 159 } | 200 } |
| 160 | 201 |
| 161 TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithOcclusion) { | 202 TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithOcclusion) { |
| 162 // Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30. | 203 // Input is a 100x100 bitmap with a 40x40 aperture at x=30, y=30. |
| 163 // The bounds of the layer are set to 400x400. | 204 // The bounds of the layer are set to 400x400. |
| 164 gfx::Size bitmap_size(100, 100); | 205 gfx::Size bitmap_size(100, 100); |
| 165 gfx::Rect aperture_rect(30, 30, 40, 40); | 206 gfx::Rect aperture_rect(30, 30, 40, 40); |
| 166 gfx::Size layer_size(400, 400); | 207 gfx::Size layer_size(400, 400); |
| 167 gfx::Rect occlusion(20, 20, 360, 360); | 208 gfx::Rect occlusion(20, 20, 360, 360); |
| 209 gfx::Rect border(30, 30, 60, 60); | |
| 168 bool fill_center = false; | 210 bool fill_center = false; |
| 169 size_t expected_quad_size = 12; | 211 size_t expected_quad_size = 12; |
| 170 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, gfx::Rect(), | 212 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
| 213 occlusion, fill_center, expected_quad_size); | |
| 214 | |
| 215 bitmap_size = gfx::Size(100, 100); | |
| 216 aperture_rect = gfx::Rect(0, 0, 100, 100); | |
| 217 layer_size = gfx::Size(400, 400); | |
| 218 occlusion = gfx::Rect(20, 20, 360, 360); | |
| 219 border = gfx::Rect(0, 0, 0, 0); | |
| 220 fill_center = false; | |
| 221 expected_quad_size = 0; | |
| 222 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, | |
| 223 occlusion, fill_center, expected_quad_size); | |
| 224 | |
| 225 bitmap_size = gfx::Size(100, 100); | |
| 226 aperture_rect = gfx::Rect(20, 30, 60, 40); | |
| 227 layer_size = gfx::Size(400, 400); | |
| 228 occlusion = gfx::Rect(10, 10, 380, 380); | |
| 229 border = gfx::Rect(20, 30, 360, 340); | |
| 230 fill_center = false; | |
| 231 expected_quad_size = 12; | |
| 232 NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, | |
| 171 occlusion, fill_center, expected_quad_size); | 233 occlusion, fill_center, expected_quad_size); |
| 172 } | 234 } |
| 173 | 235 |
| 174 TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) { | 236 TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithEmptyPatches) { |
| 175 // The top component of the 9-patch is empty, so there should be no quads for | 237 // The top component of the 9-patch is empty, so there should be no quads for |
| 176 // the top three components. | 238 // the top three components. |
| 177 gfx::Size bitmap_size(100, 100); | 239 gfx::Size bitmap_size(100, 100); |
| 178 gfx::Size layer_size(100, 100); | 240 gfx::Size layer_size(100, 100); |
| 179 gfx::Rect aperture_rect(10, 0, 80, 90); | 241 gfx::Rect aperture_rect(10, 0, 80, 90); |
| 180 gfx::Rect border(10, 0, 20, 10); | 242 gfx::Rect border(10, 0, 20, 10); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 | 397 |
| 336 const QuadList &quad_list = impl.quad_list(); | 398 const QuadList &quad_list = impl.quad_list(); |
| 337 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); | 399 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); |
| 338 it != quad_list.BackToFrontEnd(); ++it) | 400 it != quad_list.BackToFrontEnd(); ++it) |
| 339 EXPECT_TRUE(it->ShouldDrawWithBlending()); | 401 EXPECT_TRUE(it->ShouldDrawWithBlending()); |
| 340 } | 402 } |
| 341 } | 403 } |
| 342 | 404 |
| 343 } // namespace | 405 } // namespace |
| 344 } // namespace cc | 406 } // namespace cc |
| OLD | NEW |