OLD | NEW |
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 "cc/test/fake_picture_layer_tiling_client.h" | 7 #include "cc/test/fake_picture_layer_tiling_client.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/rect_conversions.h" | 9 #include "ui/gfx/rect_conversions.h" |
10 #include "ui/gfx/size_conversions.h" | 10 #include "ui/gfx/size_conversions.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 EXPECT_TRUE(request_rect.Contains(expect_rect)); | 33 EXPECT_TRUE(request_rect.Contains(expect_rect)); |
34 | 34 |
35 // Iterators are not valid if this ratio is too large (i.e. the | 35 // Iterators are not valid if this ratio is too large (i.e. the |
36 // tiling is too high-res for a low-res destination rect.) This is an | 36 // tiling is too high-res for a low-res destination rect.) This is an |
37 // artifact of snapping geometry to integer coordinates and then mapping | 37 // artifact of snapping geometry to integer coordinates and then mapping |
38 // back to floating point texture coordinates. | 38 // back to floating point texture coordinates. |
39 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | 39 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; |
40 ASSERT_LE(dest_to_contents_scale, 2.0); | 40 ASSERT_LE(dest_to_contents_scale, 2.0); |
41 | 41 |
42 Region remaining = expect_rect; | 42 Region remaining = expect_rect; |
43 for (PictureLayerTiling::Iterator iter(tiling_.get(), | 43 for (PictureLayerTiling::CoverageIterator |
44 rect_scale, | 44 iter(tiling_.get(), rect_scale, request_rect); |
45 request_rect); | |
46 iter; | 45 iter; |
47 ++iter) { | 46 ++iter) { |
48 // Geometry cannot overlap previous geometry at all | 47 // Geometry cannot overlap previous geometry at all |
49 gfx::Rect geometry = iter.geometry_rect(); | 48 gfx::Rect geometry = iter.geometry_rect(); |
50 EXPECT_TRUE(expect_rect.Contains(geometry)); | 49 EXPECT_TRUE(expect_rect.Contains(geometry)); |
51 EXPECT_TRUE(remaining.Contains(geometry)); | 50 EXPECT_TRUE(remaining.Contains(geometry)); |
52 remaining.Subtract(geometry); | 51 remaining.Subtract(geometry); |
53 | 52 |
54 // Sanity check that texture coords are within the texture rect. | 53 // Sanity check that texture coords are within the texture rect. |
55 gfx::RectF texture_rect = iter.texture_rect(); | 54 gfx::RectF texture_rect = iter.texture_rect(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 gfx::Rect full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale))); | 134 gfx::Rect full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale))); |
136 Initialize(gfx::Size(256, 512), 5.2f, bounds); | 135 Initialize(gfx::Size(256, 512), 5.2f, bounds); |
137 VerifyTilesExactlyCoverRect(scale, full_rect); | 136 VerifyTilesExactlyCoverRect(scale, full_rect); |
138 VerifyTilesExactlyCoverRect(scale, gfx::Rect(2014, 1579, 867, 1033)); | 137 VerifyTilesExactlyCoverRect(scale, gfx::Rect(2014, 1579, 867, 1033)); |
139 } | 138 } |
140 | 139 |
141 TEST_F(PictureLayerTilingIteratorTest, IteratorEmptyRect) { | 140 TEST_F(PictureLayerTilingIteratorTest, IteratorEmptyRect) { |
142 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(800, 600)); | 141 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(800, 600)); |
143 | 142 |
144 gfx::Rect empty; | 143 gfx::Rect empty; |
145 PictureLayerTiling::Iterator iter(tiling_.get(), 1.0f, empty); | 144 PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1.0f, empty); |
146 EXPECT_FALSE(iter); | 145 EXPECT_FALSE(iter); |
147 } | 146 } |
148 | 147 |
149 TEST_F(PictureLayerTilingIteratorTest, NonIntersectingRect) { | 148 TEST_F(PictureLayerTilingIteratorTest, NonIntersectingRect) { |
150 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(800, 600)); | 149 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(800, 600)); |
151 gfx::Rect non_intersecting(1000, 1000, 50, 50); | 150 gfx::Rect non_intersecting(1000, 1000, 50, 50); |
152 PictureLayerTiling::Iterator iter(tiling_.get(), 1, non_intersecting); | 151 PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1, non_intersecting); |
153 EXPECT_FALSE(iter); | 152 EXPECT_FALSE(iter); |
154 } | 153 } |
155 | 154 |
156 TEST_F(PictureLayerTilingIteratorTest, LayerEdgeTextureCoordinates) { | 155 TEST_F(PictureLayerTilingIteratorTest, LayerEdgeTextureCoordinates) { |
157 Initialize(gfx::Size(300, 300), 1.0f, gfx::Size(256, 256)); | 156 Initialize(gfx::Size(300, 300), 1.0f, gfx::Size(256, 256)); |
158 // All of these sizes are 256x256, scaled and ceiled. | 157 // All of these sizes are 256x256, scaled and ceiled. |
159 VerifyTilesExactlyCoverRect(1.0f, gfx::Rect(0, 0, 256, 256)); | 158 VerifyTilesExactlyCoverRect(1.0f, gfx::Rect(0, 0, 256, 256)); |
160 VerifyTilesExactlyCoverRect(0.8f, gfx::Rect(0, 0, 205, 205)); | 159 VerifyTilesExactlyCoverRect(0.8f, gfx::Rect(0, 0, 205, 205)); |
161 VerifyTilesExactlyCoverRect(1.2f, gfx::Rect(0, 0, 308, 308)); | 160 VerifyTilesExactlyCoverRect(1.2f, gfx::Rect(0, 0, 308, 308)); |
162 } | 161 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 gfx::Rect in(40, 50, 100, 200); | 353 gfx::Rect in(40, 50, 100, 200); |
355 gfx::Rect bounds(0, 0, 10, 10); | 354 gfx::Rect bounds(0, 0, 10, 10); |
356 int64 target_area = 400 * 400; | 355 int64 target_area = 400 * 400; |
357 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 356 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
358 in, target_area, bounds); | 357 in, target_area, bounds); |
359 EXPECT_TRUE(out.IsEmpty()); | 358 EXPECT_TRUE(out.IsEmpty()); |
360 } | 359 } |
361 | 360 |
362 } // namespace | 361 } // namespace |
363 } // namespace cc | 362 } // namespace cc |
OLD | NEW |