| 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" |
| 11 #include "cc/test/fake_impl_proxy.h" | 11 #include "cc/test/fake_impl_proxy.h" |
| 12 #include "cc/test/fake_ui_resource_layer_tree_host_impl.h" | 12 #include "cc/test/fake_ui_resource_layer_tree_host_impl.h" |
| 13 #include "cc/test/geometry_test_utils.h" | 13 #include "cc/test/geometry_test_utils.h" |
| 14 #include "cc/test/layer_test_common.h" | 14 #include "cc/test/layer_test_common.h" |
| 15 #include "cc/test/mock_quad_culler.h" | |
| 16 #include "cc/trees/single_thread_proxy.h" | 15 #include "cc/trees/single_thread_proxy.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/gfx/rect_conversions.h" | 18 #include "ui/gfx/rect_conversions.h" |
| 20 #include "ui/gfx/safe_integer_conversions.h" | 19 #include "ui/gfx/safe_integer_conversions.h" |
| 21 #include "ui/gfx/transform.h" | 20 #include "ui/gfx/transform.h" |
| 22 | 21 |
| 23 namespace cc { | 22 namespace cc { |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 gfx::Rect ToRoundedIntRect(const gfx::RectF& rect_f) { | 25 gfx::Rect ToRoundedIntRect(const gfx::RectF& rect_f) { |
| 27 return gfx::Rect(gfx::ToRoundedInt(rect_f.x()), | 26 return gfx::Rect(gfx::ToRoundedInt(rect_f.x()), |
| 28 gfx::ToRoundedInt(rect_f.y()), | 27 gfx::ToRoundedInt(rect_f.y()), |
| 29 gfx::ToRoundedInt(rect_f.width()), | 28 gfx::ToRoundedInt(rect_f.width()), |
| 30 gfx::ToRoundedInt(rect_f.height())); | 29 gfx::ToRoundedInt(rect_f.height())); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, | 32 void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, |
| 34 const gfx::Rect& aperture_rect, | 33 const gfx::Rect& aperture_rect, |
| 35 const gfx::Size& layer_size, | 34 const gfx::Size& layer_size, |
| 36 const gfx::Rect& border, | 35 const gfx::Rect& border, |
| 37 bool fill_center, | 36 bool fill_center, |
| 38 size_t expected_quad_size) { | 37 size_t expected_quad_size) { |
| 39 MockOcclusionTracker<LayerImpl> occlusion_tracker; | 38 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 40 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 39 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 41 MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker); | |
| 42 gfx::Rect visible_content_rect(layer_size); | 40 gfx::Rect visible_content_rect(layer_size); |
| 43 gfx::Rect expected_remaining(border.x(), | 41 gfx::Rect expected_remaining(border.x(), |
| 44 border.y(), | 42 border.y(), |
| 45 layer_size.width() - border.width(), | 43 layer_size.width() - border.width(), |
| 46 layer_size.height() - border.height()); | 44 layer_size.height() - border.height()); |
| 47 | 45 |
| 48 FakeImplProxy proxy; | 46 FakeImplProxy proxy; |
| 49 TestSharedBitmapManager shared_bitmap_manager; | 47 TestSharedBitmapManager shared_bitmap_manager; |
| 50 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); | 48 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 51 scoped_ptr<NinePatchLayerImpl> layer = | 49 scoped_ptr<NinePatchLayerImpl> layer = |
| 52 NinePatchLayerImpl::Create(host_impl.active_tree(), 1); | 50 NinePatchLayerImpl::Create(host_impl.active_tree(), 1); |
| 53 layer->draw_properties().visible_content_rect = visible_content_rect; | 51 layer->draw_properties().visible_content_rect = visible_content_rect; |
| 54 layer->SetBounds(layer_size); | 52 layer->SetBounds(layer_size); |
| 55 layer->SetContentBounds(layer_size); | 53 layer->SetContentBounds(layer_size); |
| 56 layer->CreateRenderSurface(); | 54 layer->CreateRenderSurface(); |
| 57 layer->draw_properties().render_target = layer.get(); | 55 layer->draw_properties().render_target = layer.get(); |
| 58 | 56 |
| 59 UIResourceId uid = 1; | 57 UIResourceId uid = 1; |
| 60 bool is_opaque = false; | 58 bool is_opaque = false; |
| 61 UIResourceBitmap bitmap(bitmap_size, is_opaque); | 59 UIResourceBitmap bitmap(bitmap_size, is_opaque); |
| 62 | 60 |
| 63 host_impl.CreateUIResource(uid, bitmap); | 61 host_impl.CreateUIResource(uid, bitmap); |
| 64 layer->SetUIResourceId(uid); | 62 layer->SetUIResourceId(uid); |
| 65 layer->SetImageBounds(bitmap_size); | 63 layer->SetImageBounds(bitmap_size); |
| 66 layer->SetLayout(aperture_rect, border, fill_center); | 64 layer->SetLayout(aperture_rect, border, fill_center); |
| 67 AppendQuadsData data; | 65 AppendQuadsData data; |
| 68 layer->AppendQuads(&quad_culler, &data); | 66 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); |
| 69 | 67 |
| 70 // Verify quad rects | 68 // Verify quad rects |
| 71 const QuadList& quads = quad_culler.quad_list(); | 69 const QuadList& quads = render_pass->quad_list; |
| 72 EXPECT_EQ(expected_quad_size, quads.size()); | 70 EXPECT_EQ(expected_quad_size, quads.size()); |
| 73 | 71 |
| 74 Region remaining(visible_content_rect); | 72 Region remaining(visible_content_rect); |
| 75 for (size_t i = 0; i < quads.size(); ++i) { | 73 for (size_t i = 0; i < quads.size(); ++i) { |
| 76 DrawQuad* quad = quads[i]; | 74 DrawQuad* quad = quads[i]; |
| 77 gfx::Rect quad_rect = quad->rect; | 75 gfx::Rect quad_rect = quad->rect; |
| 78 | 76 |
| 79 EXPECT_TRUE(visible_content_rect.Contains(quad_rect)) << i; | 77 EXPECT_TRUE(visible_content_rect.Contains(quad_rect)) << i; |
| 80 EXPECT_TRUE(remaining.Contains(quad_rect)) << i; | 78 EXPECT_TRUE(remaining.Contains(quad_rect)) << i; |
| 81 remaining.Subtract(Region(quad_rect)); | 79 remaining.Subtract(Region(quad_rect)); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 &partially_occluded_count); | 273 &partially_occluded_count); |
| 276 // The layer outputs nine quads, three of which are partially occluded, and | 274 // The layer outputs nine quads, three of which are partially occluded, and |
| 277 // three fully occluded. | 275 // three fully occluded. |
| 278 EXPECT_EQ(6u, impl.quad_list().size()); | 276 EXPECT_EQ(6u, impl.quad_list().size()); |
| 279 EXPECT_EQ(3u, partially_occluded_count); | 277 EXPECT_EQ(3u, partially_occluded_count); |
| 280 } | 278 } |
| 281 } | 279 } |
| 282 | 280 |
| 283 } // namespace | 281 } // namespace |
| 284 } // namespace cc | 282 } // namespace cc |
| OLD | NEW |