OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <map> | 5 #include <map> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "cc/resources/picture_pile.h" | 8 #include "cc/resources/picture_pile.h" |
9 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
10 #include "cc/test/fake_picture_pile.h" | 10 #include "cc/test/fake_picture_pile.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/gfx/geometry/rect_conversions.h" | 12 #include "ui/gfx/geometry/rect_conversions.h" |
13 #include "ui/gfx/geometry/size_conversions.h" | 13 #include "ui/gfx/geometry/size_conversions.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 namespace { | 16 namespace { |
17 | 17 |
18 class PicturePileTestBase { | 18 class PicturePileTestBase { |
19 public: | 19 public: |
20 PicturePileTestBase() | 20 PicturePileTestBase() : min_scale_(0.125), frame_number_(0) {} |
21 : background_color_(SK_ColorBLUE), | |
22 min_scale_(0.125), | |
23 frame_number_(0), | |
24 contents_opaque_(false) {} | |
25 | 21 |
26 void InitializeData() { | 22 void InitializeData() { |
27 pile_.SetTileGridSize(gfx::Size(1000, 1000)); | 23 pile_.SetTileGridSize(gfx::Size(1000, 1000)); |
28 pile_.SetMinContentsScale(min_scale_); | 24 pile_.SetMinContentsScale(min_scale_); |
29 client_ = FakeContentLayerClient(); | 25 client_ = FakeContentLayerClient(); |
30 SetTilingSize(pile_.tiling().max_texture_size()); | 26 SetTilingSize(pile_.tiling().max_texture_size()); |
31 } | 27 } |
32 | 28 |
33 void SetTilingSize(const gfx::Size& tiling_size) { | 29 void SetTilingSize(const gfx::Size& tiling_size) { |
34 Region invalidation; | 30 Region invalidation; |
35 gfx::Rect viewport_rect(tiling_size); | 31 gfx::Rect viewport_rect(tiling_size); |
36 UpdateAndExpandInvalidation(&invalidation, tiling_size, viewport_rect); | 32 UpdateAndExpandInvalidation(&invalidation, tiling_size, viewport_rect); |
37 } | 33 } |
38 | 34 |
39 gfx::Size tiling_size() const { return pile_.GetSize(); } | 35 gfx::Size tiling_size() const { return pile_.GetSize(); } |
40 gfx::Rect tiling_rect() const { return gfx::Rect(pile_.GetSize()); } | 36 gfx::Rect tiling_rect() const { return gfx::Rect(pile_.GetSize()); } |
41 | 37 |
42 bool UpdateAndExpandInvalidation(Region* invalidation, | 38 bool UpdateAndExpandInvalidation(Region* invalidation, |
43 const gfx::Size& layer_size, | 39 const gfx::Size& layer_size, |
44 const gfx::Rect& visible_layer_rect) { | 40 const gfx::Rect& visible_layer_rect) { |
45 frame_number_++; | 41 frame_number_++; |
46 return pile_.UpdateAndExpandInvalidation( | 42 return pile_.UpdateAndExpandInvalidation(&client_, invalidation, layer_size, |
47 &client_, invalidation, background_color_, contents_opaque_, false, | 43 visible_layer_rect, frame_number_, |
48 layer_size, visible_layer_rect, frame_number_, | 44 Picture::RECORD_NORMALLY); |
49 Picture::RECORD_NORMALLY); | |
50 } | 45 } |
51 | 46 |
52 bool UpdateWholePile() { | 47 bool UpdateWholePile() { |
53 Region invalidation = tiling_rect(); | 48 Region invalidation = tiling_rect(); |
54 bool result = UpdateAndExpandInvalidation(&invalidation, tiling_size(), | 49 bool result = UpdateAndExpandInvalidation(&invalidation, tiling_size(), |
55 tiling_rect()); | 50 tiling_rect()); |
56 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 51 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
57 return result; | 52 return result; |
58 } | 53 } |
59 | 54 |
60 FakeContentLayerClient client_; | 55 FakeContentLayerClient client_; |
61 FakePicturePile pile_; | 56 FakePicturePile pile_; |
62 SkColor background_color_; | |
63 float min_scale_; | 57 float min_scale_; |
64 int frame_number_; | 58 int frame_number_; |
65 bool contents_opaque_; | |
66 }; | 59 }; |
67 | 60 |
68 class PicturePileTest : public PicturePileTestBase, public testing::Test { | 61 class PicturePileTest : public PicturePileTestBase, public testing::Test { |
69 public: | 62 public: |
70 virtual void SetUp() override { InitializeData(); } | 63 void SetUp() override { InitializeData(); } |
71 }; | 64 }; |
72 | 65 |
73 TEST_F(PicturePileTest, InvalidationOnTileBorderOutsideInterestRect) { | 66 TEST_F(PicturePileTest, InvalidationOnTileBorderOutsideInterestRect) { |
74 // Don't expand the interest rect past what we invalidate. | 67 // Don't expand the interest rect past what we invalidate. |
75 pile_.SetPixelRecordDistance(0); | 68 pile_.SetPixelRecordDistance(0); |
76 | 69 |
77 gfx::Size tile_size(100, 100); | 70 gfx::Size tile_size(100, 100); |
78 pile_.tiling().SetMaxTextureSize(tile_size); | 71 pile_.tiling().SetMaxTextureSize(tile_size); |
79 | 72 |
80 gfx::Size pile_size(400, 400); | 73 gfx::Size pile_size(400, 400); |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 enum Corner { | 517 enum Corner { |
525 TOP_LEFT, | 518 TOP_LEFT, |
526 TOP_RIGHT, | 519 TOP_RIGHT, |
527 BOTTOM_LEFT, | 520 BOTTOM_LEFT, |
528 BOTTOM_RIGHT, | 521 BOTTOM_RIGHT, |
529 }; | 522 }; |
530 | 523 |
531 class PicturePileResizeCornerTest : public PicturePileTestBase, | 524 class PicturePileResizeCornerTest : public PicturePileTestBase, |
532 public testing::TestWithParam<Corner> { | 525 public testing::TestWithParam<Corner> { |
533 protected: | 526 protected: |
534 virtual void SetUp() override { InitializeData(); } | 527 void SetUp() override { InitializeData(); } |
535 | 528 |
536 static gfx::Rect CornerSinglePixelRect(Corner corner, const gfx::Size& s) { | 529 static gfx::Rect CornerSinglePixelRect(Corner corner, const gfx::Size& s) { |
537 switch (corner) { | 530 switch (corner) { |
538 case TOP_LEFT: | 531 case TOP_LEFT: |
539 return gfx::Rect(0, 0, 1, 1); | 532 return gfx::Rect(0, 0, 1, 1); |
540 case TOP_RIGHT: | 533 case TOP_RIGHT: |
541 return gfx::Rect(s.width() - 1, 0, 1, 1); | 534 return gfx::Rect(s.width() - 1, 0, 1, 1); |
542 case BOTTOM_LEFT: | 535 case BOTTOM_LEFT: |
543 return gfx::Rect(0, s.height() - 1, 1, 1); | 536 return gfx::Rect(0, s.height() - 1, 1, 1); |
544 case BOTTOM_RIGHT: | 537 case BOTTOM_RIGHT: |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 EXPECT_TRUE(pile_.HasRecordings()); | 1535 EXPECT_TRUE(pile_.HasRecordings()); |
1543 pile_.SetEmptyBounds(); | 1536 pile_.SetEmptyBounds(); |
1544 EXPECT_FALSE(pile_.is_solid_color()); | 1537 EXPECT_FALSE(pile_.is_solid_color()); |
1545 EXPECT_TRUE(pile_.GetSize().IsEmpty()); | 1538 EXPECT_TRUE(pile_.GetSize().IsEmpty()); |
1546 EXPECT_TRUE(pile_.picture_map().empty()); | 1539 EXPECT_TRUE(pile_.picture_map().empty()); |
1547 EXPECT_FALSE(pile_.HasRecordings()); | 1540 EXPECT_FALSE(pile_.HasRecordings()); |
1548 } | 1541 } |
1549 | 1542 |
1550 } // namespace | 1543 } // namespace |
1551 } // namespace cc | 1544 } // namespace cc |
OLD | NEW |