| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/layers/tiled_layer.h" | 5 #include "cc/layers/tiled_layer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 layer->InvalidateContentRect(gfx::Rect(0, 0, 100, 200)); | 282 layer->InvalidateContentRect(gfx::Rect(0, 0, 100, 200)); |
| 283 layer->draw_properties().visible_content_rect = gfx::Rect(0, 0, 100, 100); | 283 layer->draw_properties().visible_content_rect = gfx::Rect(0, 0, 100, 100); |
| 284 UpdateAndPush(layer, layer_impl); | 284 UpdateAndPush(layer, layer_impl); |
| 285 | 285 |
| 286 // We should only have the first tile since the other tile was invalidated but | 286 // We should only have the first tile since the other tile was invalidated but |
| 287 // not painted. | 287 // not painted. |
| 288 EXPECT_TRUE(layer_impl->HasResourceIdForTileAt(0, 0)); | 288 EXPECT_TRUE(layer_impl->HasResourceIdForTileAt(0, 0)); |
| 289 EXPECT_FALSE(layer_impl->HasResourceIdForTileAt(0, 1)); | 289 EXPECT_FALSE(layer_impl->HasResourceIdForTileAt(0, 1)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 TEST_F(TiledLayerTest, Scale) { | |
| 293 layer_tree_host_->SetDeviceScaleFactor(1.5); | |
| 294 | |
| 295 scoped_refptr<FakeTiledLayer> layer = | |
| 296 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); | |
| 297 scoped_ptr<FakeTiledLayerImpl> layer_impl = | |
| 298 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); | |
| 299 RenderSurfaceLayerList render_surface_layer_list; | |
| 300 | |
| 301 layer_tree_host_->root_layer()->AddChild(layer); | |
| 302 | |
| 303 layer->SetBounds(gfx::Size(100, 200)); | |
| 304 CalcDrawProps(&render_surface_layer_list); | |
| 305 | |
| 306 // Change the width so that it doesn't divide cleanly by the scale. | |
| 307 layer->SetBounds(gfx::Size(101, 200)); | |
| 308 UpdateAndPush(layer, layer_impl); | |
| 309 | |
| 310 EXPECT_EQ(1.5, layer->fake_layer_updater()->last_contents_width_scale()); | |
| 311 } | |
| 312 | |
| 313 TEST_F(TiledLayerTest, PushOccludedDirtyTiles) { | 292 TEST_F(TiledLayerTest, PushOccludedDirtyTiles) { |
| 314 scoped_refptr<FakeTiledLayer> layer = | 293 scoped_refptr<FakeTiledLayer> layer = |
| 315 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); | 294 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); |
| 316 scoped_ptr<FakeTiledLayerImpl> layer_impl = | 295 scoped_ptr<FakeTiledLayerImpl> layer_impl = |
| 317 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); | 296 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); |
| 318 TestOcclusionTracker occluded; | 297 TestOcclusionTracker occluded; |
| 319 occlusion_ = &occluded; | 298 occlusion_ = &occluded; |
| 320 layer_tree_host_->SetViewportSize(gfx::Size(1000, 1000)); | 299 layer_tree_host_->SetViewportSize(gfx::Size(1000, 1000)); |
| 321 | 300 |
| 322 layer_tree_host_->root_layer()->AddChild(layer); | 301 layer_tree_host_->root_layer()->AddChild(layer); |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 | 865 |
| 887 TEST_F(TiledLayerTest, VerifyUpdateRectWhenContentBoundsAreScaled) { | 866 TEST_F(TiledLayerTest, VerifyUpdateRectWhenContentBoundsAreScaled) { |
| 888 // The update rect (that indicates what was actually painted) should be in | 867 // The update rect (that indicates what was actually painted) should be in |
| 889 // layer space, not the content space. | 868 // layer space, not the content space. |
| 890 scoped_refptr<FakeTiledLayerWithScaledBounds> layer = make_scoped_refptr( | 869 scoped_refptr<FakeTiledLayerWithScaledBounds> layer = make_scoped_refptr( |
| 891 new FakeTiledLayerWithScaledBounds(resource_manager_.get())); | 870 new FakeTiledLayerWithScaledBounds(resource_manager_.get())); |
| 892 | 871 |
| 893 layer_tree_host_->root_layer()->AddChild(layer); | 872 layer_tree_host_->root_layer()->AddChild(layer); |
| 894 | 873 |
| 895 gfx::Rect layer_bounds(0, 0, 300, 200); | 874 gfx::Rect layer_bounds(0, 0, 300, 200); |
| 896 gfx::Rect content_bounds(0, 0, 150, 250); | 875 gfx::Rect content_bounds(0, 0, 200, 250); |
| 897 | 876 |
| 898 layer->SetBounds(layer_bounds.size()); | 877 layer->SetBounds(layer_bounds.size()); |
| 899 layer->SetContentBounds(content_bounds.size()); | 878 layer->SetContentBounds(content_bounds.size()); |
| 900 layer->draw_properties().visible_content_rect = content_bounds; | 879 layer->draw_properties().visible_content_rect = content_bounds; |
| 901 layer->draw_properties().contents_scale_x = .5f; | |
| 902 layer->draw_properties().contents_scale_y = 1.25f; | |
| 903 | 880 |
| 904 // On first update, the update_rect includes all tiles, even beyond the | 881 // On first update, the update_rect includes all tiles, even beyond the |
| 905 // boundaries of the layer. | 882 // boundaries of the layer. |
| 906 // However, it should still be in layer space, not content space. | 883 // However, it should still be in layer space, not content space. |
| 907 layer->InvalidateContentRect(content_bounds); | 884 layer->InvalidateContentRect(content_bounds); |
| 908 | 885 |
| 909 layer->SetTexturePriorities(priority_calculator_); | 886 layer->SetTexturePriorities(priority_calculator_); |
| 910 resource_manager_->PrioritizeTextures(); | 887 resource_manager_->PrioritizeTextures(); |
| 911 layer->SavePaintProperties(); | 888 layer->SavePaintProperties(); |
| 912 layer->Update(queue_.get(), NULL); | 889 layer->Update(queue_.get(), NULL); |
| 913 | 890 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 300, 300 * 0.8), layer->update_rect()); |
| 914 // Update rect is 200x300 (tile size of 100x100). Scaled this gives 400x240. | |
| 915 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 400, 240), layer->update_rect()); | |
| 916 UpdateTextures(); | 891 UpdateTextures(); |
| 917 | 892 |
| 918 // After the tiles are updated once, another invalidate only needs to update | 893 // After the tiles are updated once, another invalidate only needs to update |
| 919 // the bounds of the layer. | 894 // the bounds of the layer. |
| 920 layer->SetTexturePriorities(priority_calculator_); | 895 layer->SetTexturePriorities(priority_calculator_); |
| 921 resource_manager_->PrioritizeTextures(); | 896 resource_manager_->PrioritizeTextures(); |
| 922 layer->InvalidateContentRect(content_bounds); | 897 layer->InvalidateContentRect(content_bounds); |
| 923 layer->SavePaintProperties(); | 898 layer->SavePaintProperties(); |
| 924 layer->Update(queue_.get(), NULL); | 899 layer->Update(queue_.get(), NULL); |
| 925 EXPECT_FLOAT_RECT_EQ(gfx::RectF(layer_bounds), layer->update_rect()); | 900 EXPECT_FLOAT_RECT_EQ(gfx::RectF(layer_bounds), layer->update_rect()); |
| 926 UpdateTextures(); | 901 UpdateTextures(); |
| 927 | 902 |
| 928 // Partial re-paint should also be represented by the update rect in layer | 903 // Partial re-paint should also be represented by the update rect in layer |
| 929 // space, not content space. | 904 // space, not content space. |
| 930 gfx::Rect partial_damage(30, 100, 10, 10); | 905 gfx::Rect partial_damage(30, 100, 10, 10); |
| 931 layer->InvalidateContentRect(partial_damage); | 906 layer->InvalidateContentRect(partial_damage); |
| 932 layer->SetTexturePriorities(priority_calculator_); | 907 layer->SetTexturePriorities(priority_calculator_); |
| 933 resource_manager_->PrioritizeTextures(); | 908 resource_manager_->PrioritizeTextures(); |
| 934 layer->SavePaintProperties(); | 909 layer->SavePaintProperties(); |
| 935 layer->Update(queue_.get(), NULL); | 910 layer->Update(queue_.get(), NULL); |
| 936 EXPECT_FLOAT_RECT_EQ(gfx::RectF(60, 80, 20, 8), layer->update_rect()); | 911 EXPECT_FLOAT_RECT_EQ(gfx::RectF(45, 80, 15, 8), layer->update_rect()); |
| 937 } | 912 } |
| 938 | 913 |
| 939 TEST_F(TiledLayerTest, VerifyInvalidationWhenContentsScaleChanges) { | 914 TEST_F(TiledLayerTest, VerifyInvalidationWhenContentsScaleChanges) { |
| 940 scoped_refptr<FakeTiledLayer> layer = | 915 scoped_refptr<FakeTiledLayer> layer = |
| 941 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); | 916 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); |
| 942 scoped_ptr<FakeTiledLayerImpl> layer_impl = | 917 scoped_ptr<FakeTiledLayerImpl> layer_impl = |
| 943 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); | 918 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); |
| 944 RenderSurfaceLayerList render_surface_layer_list; | 919 RenderSurfaceLayerList render_surface_layer_list; |
| 945 | 920 |
| 946 layer_tree_host_->root_layer()->AddChild(layer); | 921 layer_tree_host_->root_layer()->AddChild(layer); |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1710 layer->tracking_layer_painter()->ResetPaintedRect(); | 1685 layer->tracking_layer_painter()->ResetPaintedRect(); |
| 1711 | 1686 |
| 1712 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); | 1687 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); |
| 1713 UpdateTextures(); | 1688 UpdateTextures(); |
| 1714 | 1689 |
| 1715 // Invalidate the entire layer in content space. When painting, the rect given | 1690 // Invalidate the entire layer in content space. When painting, the rect given |
| 1716 // to webkit should match the layer's bounds. | 1691 // to webkit should match the layer's bounds. |
| 1717 layer->InvalidateContentRect(content_rect); | 1692 layer->InvalidateContentRect(content_rect); |
| 1718 layer->Update(queue_.get(), NULL); | 1693 layer->Update(queue_.get(), NULL); |
| 1719 | 1694 |
| 1720 // Rounding leads to an extra pixel. | 1695 EXPECT_RECT_EQ(layer_rect, layer->tracking_layer_painter()->PaintedRect()); |
| 1721 gfx::Rect expanded_layer_rect(layer_rect); | |
| 1722 expanded_layer_rect.set_height(32); | |
| 1723 EXPECT_RECT_EQ(expanded_layer_rect, | |
| 1724 layer->tracking_layer_painter()->PaintedRect()); | |
| 1725 } | 1696 } |
| 1726 | 1697 |
| 1727 TEST_F(TiledLayerTest, | 1698 TEST_F(TiledLayerTest, |
| 1728 NonIntegerContentsScaleIsNotDistortedDuringInvalidation) { | 1699 NonIntegerContentsScaleIsNotDistortedDuringInvalidation) { |
| 1729 scoped_refptr<UpdateTrackingTiledLayer> layer = | 1700 scoped_refptr<UpdateTrackingTiledLayer> layer = |
| 1730 make_scoped_refptr(new UpdateTrackingTiledLayer(resource_manager_.get())); | 1701 make_scoped_refptr(new UpdateTrackingTiledLayer(resource_manager_.get())); |
| 1731 | 1702 |
| 1732 layer_tree_host_->root_layer()->AddChild(layer); | 1703 layer_tree_host_->root_layer()->AddChild(layer); |
| 1733 | 1704 |
| 1734 gfx::Rect layer_rect(0, 0, 30, 31); | 1705 gfx::Rect layer_rect(0, 0, 30, 31); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1749 layer->tracking_layer_painter()->ResetPaintedRect(); | 1720 layer->tracking_layer_painter()->ResetPaintedRect(); |
| 1750 | 1721 |
| 1751 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); | 1722 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); |
| 1752 UpdateTextures(); | 1723 UpdateTextures(); |
| 1753 | 1724 |
| 1754 // Invalidate the entire layer in layer space. When painting, the rect given | 1725 // Invalidate the entire layer in layer space. When painting, the rect given |
| 1755 // to webkit should match the layer's bounds. | 1726 // to webkit should match the layer's bounds. |
| 1756 layer->SetNeedsDisplayRect(layer_rect); | 1727 layer->SetNeedsDisplayRect(layer_rect); |
| 1757 layer->Update(queue_.get(), NULL); | 1728 layer->Update(queue_.get(), NULL); |
| 1758 | 1729 |
| 1759 // Rounding leads to an extra pixel. | 1730 EXPECT_RECT_EQ(layer_rect, layer->tracking_layer_painter()->PaintedRect()); |
| 1760 gfx::Rect expanded_layer_rect(layer_rect); | |
| 1761 expanded_layer_rect.set_height(32); | |
| 1762 EXPECT_RECT_EQ(expanded_layer_rect, | |
| 1763 layer->tracking_layer_painter()->PaintedRect()); | |
| 1764 } | 1731 } |
| 1765 | 1732 |
| 1766 } // namespace | 1733 } // namespace |
| 1767 } // namespace cc | 1734 } // namespace cc |
| OLD | NEW |