Chromium Code Reviews| 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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 layer->InvalidateContentRect(gfx::Rect(0, 0, 50, 50)); | 877 layer->InvalidateContentRect(gfx::Rect(0, 0, 50, 50)); |
| 857 UpdateAndPush(layer, layer_impl); | 878 UpdateAndPush(layer, layer_impl); |
| 858 EXPECT_EQ(1, layer->fake_layer_updater()->prepare_count()); | 879 EXPECT_EQ(1, layer->fake_layer_updater()->prepare_count()); |
| 859 layer->fake_layer_updater()->ClearPrepareCount(); | 880 layer->fake_layer_updater()->ClearPrepareCount(); |
| 860 | 881 |
| 861 // The layer should still be invalid as update invoked invalidate. | 882 // The layer should still be invalid as update invoked invalidate. |
| 862 UpdateAndPush(layer, layer_impl); // visible | 883 UpdateAndPush(layer, layer_impl); // visible |
| 863 EXPECT_EQ(1, layer->fake_layer_updater()->prepare_count()); | 884 EXPECT_EQ(1, layer->fake_layer_updater()->prepare_count()); |
| 864 } | 885 } |
| 865 | 886 |
| 866 TEST_F(TiledLayerTest, VerifyUpdateRectWhenContentBoundsAreScaled) { | |
|
sky
2014/09/22 18:00:00
This test didn't seem worth keeping around.
danakj
2014/09/22 19:21:18
This is testing the Layer::update_rect_ is in laye
sky
2014/09/22 21:23:55
Yes, because it didn't update the scales explicitl
| |
| 867 // The update rect (that indicates what was actually painted) should be in | |
| 868 // layer space, not the content space. | |
| 869 scoped_refptr<FakeTiledLayerWithScaledBounds> layer = make_scoped_refptr( | |
| 870 new FakeTiledLayerWithScaledBounds(resource_manager_.get())); | |
| 871 | |
| 872 layer_tree_host_->root_layer()->AddChild(layer); | |
| 873 | |
| 874 gfx::Rect layer_bounds(0, 0, 300, 200); | |
| 875 gfx::Rect content_bounds(0, 0, 200, 250); | |
| 876 | |
| 877 layer->SetBounds(layer_bounds.size()); | |
| 878 layer->SetContentBounds(content_bounds.size()); | |
| 879 layer->draw_properties().visible_content_rect = content_bounds; | |
| 880 | |
| 881 // On first update, the update_rect includes all tiles, even beyond the | |
| 882 // boundaries of the layer. | |
| 883 // However, it should still be in layer space, not content space. | |
| 884 layer->InvalidateContentRect(content_bounds); | |
| 885 | |
| 886 layer->SetTexturePriorities(priority_calculator_); | |
| 887 resource_manager_->PrioritizeTextures(); | |
| 888 layer->SavePaintProperties(); | |
| 889 layer->Update(queue_.get(), NULL); | |
| 890 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 300, 300 * 0.8), layer->update_rect()); | |
| 891 UpdateTextures(); | |
| 892 | |
| 893 // After the tiles are updated once, another invalidate only needs to update | |
| 894 // the bounds of the layer. | |
| 895 layer->SetTexturePriorities(priority_calculator_); | |
| 896 resource_manager_->PrioritizeTextures(); | |
| 897 layer->InvalidateContentRect(content_bounds); | |
| 898 layer->SavePaintProperties(); | |
| 899 layer->Update(queue_.get(), NULL); | |
| 900 EXPECT_FLOAT_RECT_EQ(gfx::RectF(layer_bounds), layer->update_rect()); | |
| 901 UpdateTextures(); | |
| 902 | |
| 903 // Partial re-paint should also be represented by the update rect in layer | |
| 904 // space, not content space. | |
| 905 gfx::Rect partial_damage(30, 100, 10, 10); | |
| 906 layer->InvalidateContentRect(partial_damage); | |
| 907 layer->SetTexturePriorities(priority_calculator_); | |
| 908 resource_manager_->PrioritizeTextures(); | |
| 909 layer->SavePaintProperties(); | |
| 910 layer->Update(queue_.get(), NULL); | |
| 911 EXPECT_FLOAT_RECT_EQ(gfx::RectF(45, 80, 15, 8), layer->update_rect()); | |
| 912 } | |
| 913 | |
| 914 TEST_F(TiledLayerTest, VerifyInvalidationWhenContentsScaleChanges) { | 887 TEST_F(TiledLayerTest, VerifyInvalidationWhenContentsScaleChanges) { |
| 915 scoped_refptr<FakeTiledLayer> layer = | 888 scoped_refptr<FakeTiledLayer> layer = |
| 916 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); | 889 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); |
| 917 scoped_ptr<FakeTiledLayerImpl> layer_impl = | 890 scoped_ptr<FakeTiledLayerImpl> layer_impl = |
| 918 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); | 891 make_scoped_ptr(new FakeTiledLayerImpl(host_impl_->active_tree(), 1)); |
| 919 RenderSurfaceLayerList render_surface_layer_list; | 892 RenderSurfaceLayerList render_surface_layer_list; |
| 920 | 893 |
| 921 layer_tree_host_->root_layer()->AddChild(layer); | 894 layer_tree_host_->root_layer()->AddChild(layer); |
| 922 | 895 |
| 923 // Create a layer with one tile. | 896 // Create a layer with one tile. |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1685 layer->tracking_layer_painter()->ResetPaintedRect(); | 1658 layer->tracking_layer_painter()->ResetPaintedRect(); |
| 1686 | 1659 |
| 1687 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); | 1660 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); |
| 1688 UpdateTextures(); | 1661 UpdateTextures(); |
| 1689 | 1662 |
| 1690 // Invalidate the entire layer in content space. When painting, the rect given | 1663 // Invalidate the entire layer in content space. When painting, the rect given |
| 1691 // to webkit should match the layer's bounds. | 1664 // to webkit should match the layer's bounds. |
| 1692 layer->InvalidateContentRect(content_rect); | 1665 layer->InvalidateContentRect(content_rect); |
| 1693 layer->Update(queue_.get(), NULL); | 1666 layer->Update(queue_.get(), NULL); |
| 1694 | 1667 |
| 1695 EXPECT_RECT_EQ(layer_rect, layer->tracking_layer_painter()->PaintedRect()); | 1668 // Rounding errors may lead to an extra dip. |
| 1669 EXPECT_RECT_NEAR( | |
|
danakj
2014/09/22 19:21:18
Can you instead EXPECT_EQ and just explain in a co
sky
2014/09/22 21:23:55
It's the 1.5 scale. Previously we calculated the s
| |
| 1670 layer_rect, layer->tracking_layer_painter()->PaintedRect(), 1); | |
| 1696 } | 1671 } |
| 1697 | 1672 |
| 1698 TEST_F(TiledLayerTest, | 1673 TEST_F(TiledLayerTest, |
| 1699 NonIntegerContentsScaleIsNotDistortedDuringInvalidation) { | 1674 NonIntegerContentsScaleIsNotDistortedDuringInvalidation) { |
| 1700 scoped_refptr<UpdateTrackingTiledLayer> layer = | 1675 scoped_refptr<UpdateTrackingTiledLayer> layer = |
| 1701 make_scoped_refptr(new UpdateTrackingTiledLayer(resource_manager_.get())); | 1676 make_scoped_refptr(new UpdateTrackingTiledLayer(resource_manager_.get())); |
| 1702 | 1677 |
| 1703 layer_tree_host_->root_layer()->AddChild(layer); | 1678 layer_tree_host_->root_layer()->AddChild(layer); |
| 1704 | 1679 |
| 1705 gfx::Rect layer_rect(0, 0, 30, 31); | 1680 gfx::Rect layer_rect(0, 0, 30, 31); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1720 layer->tracking_layer_painter()->ResetPaintedRect(); | 1695 layer->tracking_layer_painter()->ResetPaintedRect(); |
| 1721 | 1696 |
| 1722 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); | 1697 EXPECT_RECT_EQ(gfx::Rect(), layer->tracking_layer_painter()->PaintedRect()); |
| 1723 UpdateTextures(); | 1698 UpdateTextures(); |
| 1724 | 1699 |
| 1725 // Invalidate the entire layer in layer space. When painting, the rect given | 1700 // Invalidate the entire layer in layer space. When painting, the rect given |
| 1726 // to webkit should match the layer's bounds. | 1701 // to webkit should match the layer's bounds. |
| 1727 layer->SetNeedsDisplayRect(layer_rect); | 1702 layer->SetNeedsDisplayRect(layer_rect); |
| 1728 layer->Update(queue_.get(), NULL); | 1703 layer->Update(queue_.get(), NULL); |
| 1729 | 1704 |
| 1730 EXPECT_RECT_EQ(layer_rect, layer->tracking_layer_painter()->PaintedRect()); | 1705 // Rounding errors may lead to an extra dip. |
| 1706 EXPECT_RECT_NEAR( | |
|
danakj
2014/09/22 19:21:18
Same comment.
| |
| 1707 layer_rect, layer->tracking_layer_painter()->PaintedRect(), 1); | |
| 1731 } | 1708 } |
| 1732 | 1709 |
| 1733 } // namespace | 1710 } // namespace |
| 1734 } // namespace cc | 1711 } // namespace cc |
| OLD | NEW |