| 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 "base/containers/hash_tables.h" | 5 #include "base/containers/hash_tables.h" |
| 6 #include "cc/layers/append_quads_data.h" | 6 #include "cc/layers/append_quads_data.h" |
| 7 #include "cc/layers/nine_patch_layer_impl.h" | 7 #include "cc/layers/nine_patch_layer_impl.h" |
| 8 #include "cc/quads/texture_draw_quad.h" | 8 #include "cc/quads/texture_draw_quad.h" |
| 9 #include "cc/resources/ui_resource_bitmap.h" | 9 #include "cc/resources/ui_resource_bitmap.h" |
| 10 #include "cc/resources/ui_resource_client.h" | 10 #include "cc/resources/ui_resource_client.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 gfx::ToRoundedInt(rect_f.height())); | 30 gfx::ToRoundedInt(rect_f.height())); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, | 33 void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, |
| 34 const gfx::Rect& aperture_rect, | 34 const gfx::Rect& aperture_rect, |
| 35 const gfx::Size& layer_size, | 35 const gfx::Size& layer_size, |
| 36 const gfx::Rect& border, | 36 const gfx::Rect& border, |
| 37 bool fill_center, | 37 bool fill_center, |
| 38 size_t expected_quad_size) { | 38 size_t expected_quad_size) { |
| 39 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 39 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 40 gfx::Rect visible_content_rect(layer_size); | 40 gfx::Rect visible_layer_rect(layer_size); |
| 41 gfx::Rect expected_remaining(border.x(), | 41 gfx::Rect expected_remaining(border.x(), |
| 42 border.y(), | 42 border.y(), |
| 43 layer_size.width() - border.width(), | 43 layer_size.width() - border.width(), |
| 44 layer_size.height() - border.height()); | 44 layer_size.height() - border.height()); |
| 45 | 45 |
| 46 FakeImplProxy proxy; | 46 FakeImplProxy proxy; |
| 47 TestSharedBitmapManager shared_bitmap_manager; | 47 TestSharedBitmapManager shared_bitmap_manager; |
| 48 TestTaskGraphRunner task_graph_runner; | 48 TestTaskGraphRunner task_graph_runner; |
| 49 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, | 49 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, |
| 50 &task_graph_runner); | 50 &task_graph_runner); |
| 51 host_impl.InitializeRenderer(FakeOutputSurface::Create3d()); | 51 host_impl.InitializeRenderer(FakeOutputSurface::Create3d()); |
| 52 | 52 |
| 53 scoped_ptr<NinePatchLayerImpl> layer = | 53 scoped_ptr<NinePatchLayerImpl> layer = |
| 54 NinePatchLayerImpl::Create(host_impl.active_tree(), 1); | 54 NinePatchLayerImpl::Create(host_impl.active_tree(), 1); |
| 55 layer->draw_properties().visible_content_rect = visible_content_rect; | 55 layer->draw_properties().visible_layer_rect = visible_layer_rect; |
| 56 layer->SetBounds(layer_size); | 56 layer->SetBounds(layer_size); |
| 57 layer->SetHasRenderSurface(true); | 57 layer->SetHasRenderSurface(true); |
| 58 layer->draw_properties().render_target = layer.get(); | 58 layer->draw_properties().render_target = layer.get(); |
| 59 | 59 |
| 60 UIResourceId uid = 1; | 60 UIResourceId uid = 1; |
| 61 bool is_opaque = false; | 61 bool is_opaque = false; |
| 62 UIResourceBitmap bitmap(bitmap_size, is_opaque); | 62 UIResourceBitmap bitmap(bitmap_size, is_opaque); |
| 63 | 63 |
| 64 host_impl.CreateUIResource(uid, bitmap); | 64 host_impl.CreateUIResource(uid, bitmap); |
| 65 layer->SetUIResourceId(uid); | 65 layer->SetUIResourceId(uid); |
| 66 layer->SetImageBounds(bitmap_size); | 66 layer->SetImageBounds(bitmap_size); |
| 67 layer->SetLayout(aperture_rect, border, fill_center); | 67 layer->SetLayout(aperture_rect, border, fill_center); |
| 68 AppendQuadsData data; | 68 AppendQuadsData data; |
| 69 layer->AppendQuads(render_pass.get(), &data); | 69 layer->AppendQuads(render_pass.get(), &data); |
| 70 | 70 |
| 71 // Verify quad rects | 71 // Verify quad rects |
| 72 const QuadList& quads = render_pass->quad_list; | 72 const QuadList& quads = render_pass->quad_list; |
| 73 EXPECT_EQ(expected_quad_size, quads.size()); | 73 EXPECT_EQ(expected_quad_size, quads.size()); |
| 74 | 74 |
| 75 Region remaining(visible_content_rect); | 75 Region remaining(visible_layer_rect); |
| 76 for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) { | 76 for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) { |
| 77 gfx::Rect quad_rect = iter->rect; | 77 gfx::Rect quad_rect = iter->rect; |
| 78 | 78 |
| 79 EXPECT_TRUE(visible_content_rect.Contains(quad_rect)) << iter.index(); | 79 EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index(); |
| 80 EXPECT_TRUE(remaining.Contains(quad_rect)) << iter.index(); | 80 EXPECT_TRUE(remaining.Contains(quad_rect)) << iter.index(); |
| 81 remaining.Subtract(Region(quad_rect)); | 81 remaining.Subtract(Region(quad_rect)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Check if the left-over quad is the same size as the mapped aperture quad in | 84 // Check if the left-over quad is the same size as the mapped aperture quad in |
| 85 // layer space. | 85 // layer space. |
| 86 if (!fill_center) { | 86 if (!fill_center) { |
| 87 EXPECT_EQ(expected_remaining, gfx::ToEnclosedRect(remaining.bounds())); | 87 EXPECT_EQ(expected_remaining, gfx::ToEnclosedRect(remaining.bounds())); |
| 88 } else { | 88 } else { |
| 89 EXPECT_TRUE(remaining.bounds().IsEmpty()); | 89 EXPECT_TRUE(remaining.bounds().IsEmpty()); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 gfx::Rect occluded; | 245 gfx::Rect occluded; |
| 246 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded); | 246 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded); |
| 247 | 247 |
| 248 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), | 248 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), |
| 249 gfx::Rect(layer_size)); | 249 gfx::Rect(layer_size)); |
| 250 EXPECT_EQ(9u, impl.quad_list().size()); | 250 EXPECT_EQ(9u, impl.quad_list().size()); |
| 251 } | 251 } |
| 252 | 252 |
| 253 { | 253 { |
| 254 SCOPED_TRACE("Full occlusion"); | 254 SCOPED_TRACE("Full occlusion"); |
| 255 gfx::Rect occluded(nine_patch_layer_impl->visible_content_rect()); | 255 gfx::Rect occluded(nine_patch_layer_impl->visible_layer_rect()); |
| 256 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded); | 256 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded); |
| 257 | 257 |
| 258 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); | 258 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); |
| 259 EXPECT_EQ(impl.quad_list().size(), 0u); | 259 EXPECT_EQ(impl.quad_list().size(), 0u); |
| 260 } | 260 } |
| 261 | 261 |
| 262 { | 262 { |
| 263 SCOPED_TRACE("Partial occlusion"); | 263 SCOPED_TRACE("Partial occlusion"); |
| 264 gfx::Rect occluded(0, 0, 500, 1000); | 264 gfx::Rect occluded(0, 0, 500, 1000); |
| 265 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded); | 265 impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, occluded); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 333 |
| 334 const QuadList &quad_list = impl.quad_list(); | 334 const QuadList &quad_list = impl.quad_list(); |
| 335 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); | 335 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); |
| 336 it != quad_list.BackToFrontEnd(); ++it) | 336 it != quad_list.BackToFrontEnd(); ++it) |
| 337 EXPECT_TRUE(it->ShouldDrawWithBlending()); | 337 EXPECT_TRUE(it->ShouldDrawWithBlending()); |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace | 341 } // namespace |
| 342 } // namespace cc | 342 } // namespace cc |
| OLD | NEW |