| 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 |
| 292 TEST_F(TiledLayerTest, PushOccludedDirtyTiles) { | 313 TEST_F(TiledLayerTest, PushOccludedDirtyTiles) { |
| 293 scoped_refptr<FakeTiledLayer> layer = | 314 scoped_refptr<FakeTiledLayer> layer = |
| 294 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); | 315 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); |
| 295 scoped_ptr<FakeTiledLayerImpl> layer_impl = | 316 scoped_ptr<FakeTiledLayerImpl> layer_impl = |
| 296 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); | 317 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); |
| 297 TestOcclusionTracker occluded; | 318 TestOcclusionTracker occluded; |
| 298 occlusion_ = &occluded; | 319 occlusion_ = &occluded; |
| 299 layer_tree_host_->SetViewportSize(gfx::Size(1000, 1000)); | 320 layer_tree_host_->SetViewportSize(gfx::Size(1000, 1000)); |
| 300 | 321 |
| 301 layer_tree_host_->root_layer()->AddChild(layer); | 322 layer_tree_host_->root_layer()->AddChild(layer); |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 | 886 |
| 866 TEST_F(TiledLayerTest, VerifyUpdateRectWhenContentBoundsAreScaled) { | 887 TEST_F(TiledLayerTest, VerifyUpdateRectWhenContentBoundsAreScaled) { |
| 867 // The update rect (that indicates what was actually painted) should be in | 888 // The update rect (that indicates what was actually painted) should be in |
| 868 // layer space, not the content space. | 889 // layer space, not the content space. |
| 869 scoped_refptr<FakeTiledLayerWithScaledBounds> layer = make_scoped_refptr( | 890 scoped_refptr<FakeTiledLayerWithScaledBounds> layer = make_scoped_refptr( |
| 870 new FakeTiledLayerWithScaledBounds(resource_manager_.get())); | 891 new FakeTiledLayerWithScaledBounds(resource_manager_.get())); |
| 871 | 892 |
| 872 layer_tree_host_->root_layer()->AddChild(layer); | 893 layer_tree_host_->root_layer()->AddChild(layer); |
| 873 | 894 |
| 874 gfx::Rect layer_bounds(0, 0, 300, 200); | 895 gfx::Rect layer_bounds(0, 0, 300, 200); |
| 875 gfx::Rect content_bounds(0, 0, 200, 250); | 896 gfx::Rect content_bounds(0, 0, 150, 250); |
| 876 | 897 |
| 877 layer->SetBounds(layer_bounds.size()); | 898 layer->SetBounds(layer_bounds.size()); |
| 878 layer->SetContentBounds(content_bounds.size()); | 899 layer->SetContentBounds(content_bounds.size()); |
| 879 layer->draw_properties().visible_content_rect = content_bounds; | 900 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; |
| 880 | 903 |
| 881 // On first update, the update_rect includes all tiles, even beyond the | 904 // On first update, the update_rect includes all tiles, even beyond the |
| 882 // boundaries of the layer. | 905 // boundaries of the layer. |
| 883 // However, it should still be in layer space, not content space. | 906 // However, it should still be in layer space, not content space. |
| 884 layer->InvalidateContentRect(content_bounds); | 907 layer->InvalidateContentRect(content_bounds); |
| 885 | 908 |
| 886 layer->SetTexturePriorities(priority_calculator_); | 909 layer->SetTexturePriorities(priority_calculator_); |
| 887 resource_manager_->PrioritizeTextures(); | 910 resource_manager_->PrioritizeTextures(); |
| 888 layer->SavePaintProperties(); | 911 layer->SavePaintProperties(); |
| 889 layer->Update(queue_.get(), NULL); | 912 layer->Update(queue_.get(), NULL); |
| 890 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 300, 300 * 0.8), layer->update_rect()); | 913 |
| 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()); |
| 891 UpdateTextures(); | 916 UpdateTextures(); |
| 892 | 917 |
| 893 // After the tiles are updated once, another invalidate only needs to update | 918 // After the tiles are updated once, another invalidate only needs to update |
| 894 // the bounds of the layer. | 919 // the bounds of the layer. |
| 895 layer->SetTexturePriorities(priority_calculator_); | 920 layer->SetTexturePriorities(priority_calculator_); |
| 896 resource_manager_->PrioritizeTextures(); | 921 resource_manager_->PrioritizeTextures(); |
| 897 layer->InvalidateContentRect(content_bounds); | 922 layer->InvalidateContentRect(content_bounds); |
| 898 layer->SavePaintProperties(); | 923 layer->SavePaintProperties(); |
| 899 layer->Update(queue_.get(), NULL); | 924 layer->Update(queue_.get(), NULL); |
| 900 EXPECT_FLOAT_RECT_EQ(gfx::RectF(layer_bounds), layer->update_rect()); | 925 EXPECT_FLOAT_RECT_EQ(gfx::RectF(layer_bounds), layer->update_rect()); |
| 901 UpdateTextures(); | 926 UpdateTextures(); |
| 902 | 927 |
| 903 // Partial re-paint should also be represented by the update rect in layer | 928 // Partial re-paint should also be represented by the update rect in layer |
| 904 // space, not content space. | 929 // space, not content space. |
| 905 gfx::Rect partial_damage(30, 100, 10, 10); | 930 gfx::Rect partial_damage(30, 100, 10, 10); |
| 906 layer->InvalidateContentRect(partial_damage); | 931 layer->InvalidateContentRect(partial_damage); |
| 907 layer->SetTexturePriorities(priority_calculator_); | 932 layer->SetTexturePriorities(priority_calculator_); |
| 908 resource_manager_->PrioritizeTextures(); | 933 resource_manager_->PrioritizeTextures(); |
| 909 layer->SavePaintProperties(); | 934 layer->SavePaintProperties(); |
| 910 layer->Update(queue_.get(), NULL); | 935 layer->Update(queue_.get(), NULL); |
| 911 EXPECT_FLOAT_RECT_EQ(gfx::RectF(45, 80, 15, 8), layer->update_rect()); | 936 EXPECT_FLOAT_RECT_EQ(gfx::RectF(60, 80, 20, 8), layer->update_rect()); |
| 912 } | 937 } |
| 913 | 938 |
| 914 TEST_F(TiledLayerTest, VerifyInvalidationWhenContentsScaleChanges) { | 939 TEST_F(TiledLayerTest, VerifyInvalidationWhenContentsScaleChanges) { |
| 915 scoped_refptr<FakeTiledLayer> layer = | 940 scoped_refptr<FakeTiledLayer> layer = |
| 916 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); | 941 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); |
| 917 scoped_ptr<FakeTiledLayerImpl> layer_impl = | 942 scoped_ptr<FakeTiledLayerImpl> layer_impl = |
| 918 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); | 943 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); |
| 919 RenderSurfaceLayerList render_surface_layer_list; | 944 RenderSurfaceLayerList render_surface_layer_list; |
| 920 | 945 |
| 921 layer_tree_host_->root_layer()->AddChild(layer); | 946 layer_tree_host_->root_layer()->AddChild(layer); |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1685 layer->tracking_layer_painter()->ResetPaintedRect(); | 1710 layer->tracking_layer_painter()->ResetPaintedRect(); |
| 1686 | 1711 |
| 1687 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); | 1712 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); |
| 1688 UpdateTextures(); | 1713 UpdateTextures(); |
| 1689 | 1714 |
| 1690 // Invalidate the entire layer in content space. When painting, the rect given | 1715 // Invalidate the entire layer in content space. When painting, the rect given |
| 1691 // to webkit should match the layer's bounds. | 1716 // to webkit should match the layer's bounds. |
| 1692 layer->InvalidateContentRect(content_rect); | 1717 layer->InvalidateContentRect(content_rect); |
| 1693 layer->Update(queue_.get(), NULL); | 1718 layer->Update(queue_.get(), NULL); |
| 1694 | 1719 |
| 1695 EXPECT_RECT_EQ(layer_rect, layer->tracking_layer_painter()->PaintedRect()); | 1720 // Rounding leads to an extra pixel. |
| 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()); |
| 1696 } | 1725 } |
| 1697 | 1726 |
| 1698 TEST_F(TiledLayerTest, | 1727 TEST_F(TiledLayerTest, |
| 1699 NonIntegerContentsScaleIsNotDistortedDuringInvalidation) { | 1728 NonIntegerContentsScaleIsNotDistortedDuringInvalidation) { |
| 1700 scoped_refptr<UpdateTrackingTiledLayer> layer = | 1729 scoped_refptr<UpdateTrackingTiledLayer> layer = |
| 1701 make_scoped_refptr(new UpdateTrackingTiledLayer(resource_manager_.get())); | 1730 make_scoped_refptr(new UpdateTrackingTiledLayer(resource_manager_.get())); |
| 1702 | 1731 |
| 1703 layer_tree_host_->root_layer()->AddChild(layer); | 1732 layer_tree_host_->root_layer()->AddChild(layer); |
| 1704 | 1733 |
| 1705 gfx::Rect layer_rect(0, 0, 30, 31); | 1734 gfx::Rect layer_rect(0, 0, 30, 31); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1720 layer->tracking_layer_painter()->ResetPaintedRect(); | 1749 layer->tracking_layer_painter()->ResetPaintedRect(); |
| 1721 | 1750 |
| 1722 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); | 1751 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); |
| 1723 UpdateTextures(); | 1752 UpdateTextures(); |
| 1724 | 1753 |
| 1725 // Invalidate the entire layer in layer space. When painting, the rect given | 1754 // Invalidate the entire layer in layer space. When painting, the rect given |
| 1726 // to webkit should match the layer's bounds. | 1755 // to webkit should match the layer's bounds. |
| 1727 layer->SetNeedsDisplayRect(layer_rect); | 1756 layer->SetNeedsDisplayRect(layer_rect); |
| 1728 layer->Update(queue_.get(), NULL); | 1757 layer->Update(queue_.get(), NULL); |
| 1729 | 1758 |
| 1730 EXPECT_RECT_EQ(layer_rect, layer->tracking_layer_painter()->PaintedRect()); | 1759 // Rounding leads to an extra pixel. |
| 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()); |
| 1731 } | 1764 } |
| 1732 | 1765 |
| 1733 } // namespace | 1766 } // namespace |
| 1734 } // namespace cc | 1767 } // namespace cc |
| OLD | NEW |