Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: cc/resources/picture_layer_tiling_unittest.cc

Issue 183663003: cc: Add tiling raster tile iterators. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "cc/resources/picture_layer_tiling.h" 5 #include "cc/resources/picture_layer_tiling.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <set>
8 9
9 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
10 #include "cc/resources/picture_layer_tiling_set.h" 11 #include "cc/resources/picture_layer_tiling_set.h"
12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_output_surface_client.h"
11 #include "cc/test/fake_picture_layer_tiling_client.h" 14 #include "cc/test/fake_picture_layer_tiling_client.h"
15 #include "cc/test/test_context_provider.h"
12 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/rect_conversions.h" 17 #include "ui/gfx/rect_conversions.h"
14 #include "ui/gfx/size_conversions.h" 18 #include "ui/gfx/size_conversions.h"
15 19
16 namespace cc { 20 namespace cc {
17 namespace { 21 namespace {
18 22
19 static gfx::Rect ViewportInLayerSpace( 23 static gfx::Rect ViewportInLayerSpace(
20 const gfx::Transform& transform, 24 const gfx::Transform& transform,
21 const gfx::Size& device_viewport) { 25 const gfx::Size& device_viewport) {
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 bool have_soon = false; 489 bool have_soon = false;
486 490
487 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and 491 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
488 // some EVENTUALLY tiles. 492 // some EVENTUALLY tiles.
489 for (int i = 0; i < 6; ++i) { 493 for (int i = 0; i < 6; ++i) {
490 for (int j = 0; j < 6; ++j) { 494 for (int j = 0; j < 6; ++j) {
491 Tile* tile = tiling->TileAt(i, j); 495 Tile* tile = tiling->TileAt(i, j);
492 TilePriority priority = tile->priority(ACTIVE_TREE); 496 TilePriority priority = tile->priority(ACTIVE_TREE);
493 497
494 if (viewport_in_content_space.Intersects(tile->content_rect())) { 498 if (viewport_in_content_space.Intersects(tile->content_rect())) {
495 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); 499 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i
496 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); 500 << " j: " << j;
501 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i
502 << " j: " << j;
497 have_now = true; 503 have_now = true;
498 } else if (skewport.Intersects(tile->content_rect())) { 504 } else if (skewport.Intersects(tile->content_rect())) {
499 EXPECT_EQ(TilePriority::SOON, priority.priority_bin); 505 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i
500 EXPECT_GT(priority.distance_to_visible, 0.f); 506 << " j: " << j;
507 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
508 << " j: " << j;
501 have_soon = true; 509 have_soon = true;
502 } else { 510 } else {
503 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); 511 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin)
504 EXPECT_GT(priority.distance_to_visible, 0.f); 512 << "i: " << i << " j: " << j;
513 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
514 << " j: " << j;
505 have_eventually = true; 515 have_eventually = true;
506 } 516 }
507 } 517 }
508 } 518 }
509 519
510 EXPECT_TRUE(have_now); 520 EXPECT_TRUE(have_now);
511 EXPECT_TRUE(have_soon); 521 EXPECT_TRUE(have_soon);
512 EXPECT_TRUE(have_eventually); 522 EXPECT_TRUE(have_eventually);
513 523
514 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); 524 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // If a layer has a non-invertible transform, then the starting rect 754 // If a layer has a non-invertible transform, then the starting rect
745 // for the layer would be empty. 755 // for the layer would be empty.
746 gfx::Rect in(40, 40, 0, 0); 756 gfx::Rect in(40, 40, 0, 0);
747 gfx::Rect bounds(0, 0, 10, 10); 757 gfx::Rect bounds(0, 0, 10, 10);
748 int64 target_area = 400 * 400; 758 int64 target_area = 400 * 400;
749 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( 759 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
750 in, target_area, bounds, NULL); 760 in, target_area, bounds, NULL);
751 EXPECT_TRUE(out.IsEmpty()); 761 EXPECT_TRUE(out.IsEmpty());
752 } 762 }
753 763
764 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) {
765 FakePictureLayerTilingClient client;
766 scoped_ptr<TestablePictureLayerTiling> tiling;
767
768 gfx::Rect viewport(50, 50, 100, 100);
769 gfx::Size layer_bounds(200, 200);
770
771 client.SetTileSize(gfx::Size(10, 10));
772
773 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client);
774 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0);
775
776 PictureLayerTiling::TilingRasterTileIterator empty_iterator;
777 EXPECT_FALSE(empty_iterator);
778
779 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting();
780
781 // Sanity check.
782 EXPECT_EQ(36u, all_tiles.size());
783
784 // The explanation of each iteration is as follows:
785 // 1. First iteration tests that we can get all of the tiles correctly.
786 // 2. Second iteration ensures that we can get all of the tiles again (first
787 // iteration didn't change any tiles), as well set all tiles to be ready to
788 // draw.
789 // 3. Third iteration ensures that no tiles are returned, since they were all
790 // marked as ready to draw.
791 for (int i = 0; i < 3; ++i) {
792 PictureLayerTiling::TilingRasterTileIterator it(tiling.get(), ACTIVE_TREE);
793
794 // There are 3 bins in TilePriority.
795 bool have_tiles[3] = {};
796
797 // On the third iteration, we should get no tiles since everything was
798 // marked as ready to draw.
799 if (i == 2) {
800 EXPECT_FALSE(it);
801 continue;
802 }
803
804 EXPECT_TRUE(it);
805 std::set<Tile*> unique_tiles;
806 unique_tiles.insert(*it);
807 Tile* last_tile = *it;
808 have_tiles[last_tile->priority(ACTIVE_TREE).priority_bin] = true;
809
810 // On the second iteration, mark everything as ready to draw (solid color).
811 if (i == 1) {
812 ManagedTileState::TileVersion& tile_version =
813 last_tile->GetTileVersionForTesting(
814 last_tile->DetermineRasterModeForTree(ACTIVE_TREE));
815 tile_version.SetSolidColorForTesting(SK_ColorRED);
816 }
817 ++it;
818 int eventually_bin_order_correct_count = 0;
819 int eventually_bin_order_incorrect_count = 0;
820 while (it) {
821 Tile* new_tile = *it;
822 ++it;
823 unique_tiles.insert(new_tile);
824
825 TilePriority last_priority = last_tile->priority(ACTIVE_TREE);
826 TilePriority new_priority = new_tile->priority(ACTIVE_TREE);
827 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin);
828 if (last_priority.priority_bin == new_priority.priority_bin) {
829 if (last_priority.priority_bin == TilePriority::EVENTUALLY) {
830 bool order_correct = last_priority.distance_to_visible <=
831 new_priority.distance_to_visible;
832 eventually_bin_order_correct_count += order_correct;
833 eventually_bin_order_incorrect_count += !order_correct;
834 } else {
835 EXPECT_LE(last_priority.distance_to_visible,
836 new_priority.distance_to_visible);
837 }
838 }
839 have_tiles[new_priority.priority_bin] = true;
840
841 last_tile = new_tile;
842
843 // On the second iteration, mark everything as ready to draw (solid
844 // color).
845 if (i == 1) {
846 ManagedTileState::TileVersion& tile_version =
847 last_tile->GetTileVersionForTesting(
848 last_tile->DetermineRasterModeForTree(ACTIVE_TREE));
849 tile_version.SetSolidColorForTesting(SK_ColorRED);
850 }
851 }
852
853 EXPECT_GT(eventually_bin_order_correct_count,
854 eventually_bin_order_incorrect_count);
855
856 // We should have now and eventually tiles, but not soon tiles because the
857 // viewport is static.
858 EXPECT_TRUE(have_tiles[TilePriority::NOW]);
859 EXPECT_FALSE(have_tiles[TilePriority::SOON]);
860 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]);
861
862 EXPECT_EQ(unique_tiles.size(), all_tiles.size());
863 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, i + 2);
864 }
865 }
866
867 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) {
868 FakePictureLayerTilingClient client;
869 scoped_ptr<TestablePictureLayerTiling> tiling;
870
871 gfx::Rect viewport(50, 0, 100, 100);
872 gfx::Size layer_bounds(500, 500);
873
874 client.SetTileSize(gfx::Size(30, 30));
875
876 tiling = TestablePictureLayerTiling::Create(1.f, layer_bounds, &client);
877 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0);
878
879 viewport = gfx::Rect(50, 50, 100, 100);
880 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.1);
881
882 // There are 3 bins in TilePriority.
883 bool have_tiles[3] = {};
884 Tile* last_tile = NULL;
885 int eventually_bin_order_correct_count = 0;
886 int eventually_bin_order_incorrect_count = 0;
887 for (PictureLayerTiling::TilingRasterTileIterator it(tiling.get(),
888 ACTIVE_TREE);
889 it;
890 ++it) {
891 if (!last_tile)
892 last_tile = *it;
893
894 Tile* new_tile = *it;
895
896 TilePriority last_priority = last_tile->priority(ACTIVE_TREE);
897 TilePriority new_priority = new_tile->priority(ACTIVE_TREE);
898
899 have_tiles[new_priority.priority_bin] = true;
900
901 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin);
902 if (last_priority.priority_bin == new_priority.priority_bin) {
903 if (last_priority.priority_bin == TilePriority::EVENTUALLY) {
904 bool order_correct = last_priority.distance_to_visible <=
905 new_priority.distance_to_visible;
906 eventually_bin_order_correct_count += order_correct;
907 eventually_bin_order_incorrect_count += !order_correct;
908 } else {
909 EXPECT_LE(last_priority.distance_to_visible,
910 new_priority.distance_to_visible);
911 }
912 }
913 last_tile = new_tile;
914 }
915
916 EXPECT_GT(eventually_bin_order_correct_count,
917 eventually_bin_order_incorrect_count);
918
919 EXPECT_TRUE(have_tiles[TilePriority::NOW]);
920 EXPECT_TRUE(have_tiles[TilePriority::SOON]);
921 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]);
922 }
923
754 static void TileExists(bool exists, Tile* tile, 924 static void TileExists(bool exists, Tile* tile,
755 const gfx::Rect& geometry_rect) { 925 const gfx::Rect& geometry_rect) {
756 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); 926 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString();
757 } 927 }
758 928
759 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { 929 TEST_F(PictureLayerTilingIteratorTest, TilesExist) {
760 gfx::Size layer_bounds(1099, 801); 930 gfx::Size layer_bounds(1099, 801);
761 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); 931 Initialize(gfx::Size(100, 100), 1.f, layer_bounds);
762 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); 932 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds));
763 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); 933 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false));
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); 1629 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1460 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); 1630 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
1461 1631
1462 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); 1632 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1463 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); 1633 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1464 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); 1634 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
1465 } 1635 }
1466 1636
1467 } // namespace 1637 } // namespace
1468 } // namespace cc 1638 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698