| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/trees/occlusion.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace cc { | |
| 10 namespace { | |
| 11 | |
| 12 TEST(OcclusionTest, HasOcclusion) { | |
| 13 Occlusion empty; | |
| 14 EXPECT_FALSE(empty.HasOcclusion()); | |
| 15 | |
| 16 empty = Occlusion( | |
| 17 gfx::Transform(), SimpleEnclosedRegion(), SimpleEnclosedRegion()); | |
| 18 EXPECT_FALSE(empty.HasOcclusion()); | |
| 19 | |
| 20 Occlusion outside_nonempty( | |
| 21 gfx::Transform(), SimpleEnclosedRegion(10, 10), SimpleEnclosedRegion()); | |
| 22 EXPECT_TRUE(outside_nonempty.HasOcclusion()); | |
| 23 | |
| 24 Occlusion inside_nonempty( | |
| 25 gfx::Transform(), SimpleEnclosedRegion(), SimpleEnclosedRegion(10, 10)); | |
| 26 EXPECT_TRUE(inside_nonempty.HasOcclusion()); | |
| 27 | |
| 28 Occlusion both_nonempty(gfx::Transform(), | |
| 29 SimpleEnclosedRegion(10, 10), | |
| 30 SimpleEnclosedRegion(10, 10)); | |
| 31 EXPECT_TRUE(both_nonempty.HasOcclusion()); | |
| 32 } | |
| 33 | |
| 34 #define EXPECT_OCCLUSION(occlusion, rects, ...) \ | |
| 35 { \ | |
| 36 bool expected[] = {__VA_ARGS__}; \ | |
| 37 ASSERT_EQ(arraysize(rects), arraysize(expected)); \ | |
| 38 for (size_t i = 0; i < arraysize(rects); ++i) \ | |
| 39 EXPECT_EQ(expected[i], occlusion.IsOccluded(rects[i])) \ | |
| 40 << "Test failed for index " << i << "."; \ | |
| 41 } | |
| 42 | |
| 43 TEST(OcclusionTest, IsOccludedNoTransform) { | |
| 44 gfx::Rect rects[] = {gfx::Rect(10, 10), | |
| 45 gfx::Rect(10, 0, 10, 10), | |
| 46 gfx::Rect(0, 10, 10, 10), | |
| 47 gfx::Rect(10, 10, 10, 10)}; | |
| 48 | |
| 49 Occlusion no_occlusion; | |
| 50 EXPECT_OCCLUSION(no_occlusion, rects, false, false, false, false); | |
| 51 | |
| 52 Occlusion all_occluded_outside( | |
| 53 gfx::Transform(), SimpleEnclosedRegion(20, 20), SimpleEnclosedRegion()); | |
| 54 EXPECT_OCCLUSION(all_occluded_outside, rects, true, true, true, true); | |
| 55 | |
| 56 Occlusion all_occluded_inside( | |
| 57 gfx::Transform(), SimpleEnclosedRegion(), SimpleEnclosedRegion(20, 20)); | |
| 58 EXPECT_OCCLUSION(all_occluded_inside, rects, true, true, true, true); | |
| 59 | |
| 60 Occlusion all_occluded_mixed(gfx::Transform(), | |
| 61 SimpleEnclosedRegion(10, 20), | |
| 62 SimpleEnclosedRegion(10, 0, 10, 20)); | |
| 63 EXPECT_OCCLUSION(all_occluded_mixed, rects, true, true, true, true); | |
| 64 | |
| 65 Occlusion some_occluded(gfx::Transform(), | |
| 66 SimpleEnclosedRegion(10, 10), | |
| 67 SimpleEnclosedRegion(10, 10, 10, 10)); | |
| 68 EXPECT_OCCLUSION(some_occluded, rects, true, false, false, true); | |
| 69 } | |
| 70 | |
| 71 TEST(OcclusionTest, IsOccludedScaled) { | |
| 72 gfx::Rect rects[] = {gfx::Rect(10, 10), | |
| 73 gfx::Rect(10, 0, 10, 10), | |
| 74 gfx::Rect(0, 10, 10, 10), | |
| 75 gfx::Rect(10, 10, 10, 10)}; | |
| 76 | |
| 77 gfx::Transform half_scale; | |
| 78 half_scale.Scale(0.5, 0.5); | |
| 79 | |
| 80 gfx::Transform double_scale; | |
| 81 double_scale.Scale(2, 2); | |
| 82 | |
| 83 Occlusion all_occluded_outside_half( | |
| 84 half_scale, SimpleEnclosedRegion(10, 10), SimpleEnclosedRegion()); | |
| 85 Occlusion all_occluded_outside_double( | |
| 86 double_scale, SimpleEnclosedRegion(40, 40), SimpleEnclosedRegion()); | |
| 87 EXPECT_OCCLUSION(all_occluded_outside_half, rects, true, true, true, true); | |
| 88 EXPECT_OCCLUSION(all_occluded_outside_double, rects, true, true, true, true); | |
| 89 | |
| 90 Occlusion all_occluded_inside_half( | |
| 91 half_scale, SimpleEnclosedRegion(), SimpleEnclosedRegion(10, 10)); | |
| 92 Occlusion all_occluded_inside_double( | |
| 93 double_scale, SimpleEnclosedRegion(), SimpleEnclosedRegion(40, 40)); | |
| 94 EXPECT_OCCLUSION(all_occluded_inside_half, rects, true, true, true, true); | |
| 95 EXPECT_OCCLUSION(all_occluded_inside_double, rects, true, true, true, true); | |
| 96 | |
| 97 Occlusion all_occluded_mixed_half(half_scale, | |
| 98 SimpleEnclosedRegion(5, 10), | |
| 99 SimpleEnclosedRegion(5, 0, 5, 10)); | |
| 100 Occlusion all_occluded_mixed_double(double_scale, | |
| 101 SimpleEnclosedRegion(20, 40), | |
| 102 SimpleEnclosedRegion(20, 0, 20, 40)); | |
| 103 EXPECT_OCCLUSION(all_occluded_mixed_half, rects, true, true, true, true); | |
| 104 EXPECT_OCCLUSION(all_occluded_mixed_double, rects, true, true, true, true); | |
| 105 | |
| 106 Occlusion some_occluded_half( | |
| 107 half_scale, SimpleEnclosedRegion(5, 5), SimpleEnclosedRegion(5, 5, 5, 5)); | |
| 108 Occlusion some_occluded_double(double_scale, | |
| 109 SimpleEnclosedRegion(20, 20), | |
| 110 SimpleEnclosedRegion(20, 20, 20, 20)); | |
| 111 EXPECT_OCCLUSION(some_occluded_half, rects, true, false, false, true); | |
| 112 EXPECT_OCCLUSION(some_occluded_double, rects, true, false, false, true); | |
| 113 } | |
| 114 | |
| 115 TEST(OcclusionTest, IsOccludedTranslated) { | |
| 116 gfx::Rect rects[] = {gfx::Rect(10, 10), | |
| 117 gfx::Rect(10, 0, 10, 10), | |
| 118 gfx::Rect(0, 10, 10, 10), | |
| 119 gfx::Rect(10, 10, 10, 10)}; | |
| 120 | |
| 121 gfx::Transform move_left; | |
| 122 move_left.Translate(-100, 0); | |
| 123 | |
| 124 gfx::Transform move_down; | |
| 125 move_down.Translate(0, 100); | |
| 126 | |
| 127 Occlusion all_occluded_outside_left( | |
| 128 move_left, SimpleEnclosedRegion(-100, 0, 20, 20), SimpleEnclosedRegion()); | |
| 129 Occlusion all_occluded_outside_down( | |
| 130 move_down, SimpleEnclosedRegion(0, 100, 20, 20), SimpleEnclosedRegion()); | |
| 131 EXPECT_OCCLUSION(all_occluded_outside_left, rects, true, true, true, true); | |
| 132 EXPECT_OCCLUSION(all_occluded_outside_down, rects, true, true, true, true); | |
| 133 | |
| 134 Occlusion all_occluded_inside_left( | |
| 135 move_left, SimpleEnclosedRegion(), SimpleEnclosedRegion(-100, 0, 20, 20)); | |
| 136 Occlusion all_occluded_inside_down( | |
| 137 move_down, SimpleEnclosedRegion(), SimpleEnclosedRegion(0, 100, 20, 20)); | |
| 138 EXPECT_OCCLUSION(all_occluded_inside_left, rects, true, true, true, true); | |
| 139 EXPECT_OCCLUSION(all_occluded_inside_down, rects, true, true, true, true); | |
| 140 | |
| 141 Occlusion all_occluded_mixed_left(move_left, | |
| 142 SimpleEnclosedRegion(-100, 0, 10, 20), | |
| 143 SimpleEnclosedRegion(-90, 0, 10, 20)); | |
| 144 Occlusion all_occluded_mixed_down(move_down, | |
| 145 SimpleEnclosedRegion(0, 100, 10, 20), | |
| 146 SimpleEnclosedRegion(10, 100, 10, 20)); | |
| 147 EXPECT_OCCLUSION(all_occluded_mixed_left, rects, true, true, true, true); | |
| 148 EXPECT_OCCLUSION(all_occluded_mixed_down, rects, true, true, true, true); | |
| 149 | |
| 150 Occlusion some_occluded_left(move_left, | |
| 151 SimpleEnclosedRegion(-100, 0, 10, 10), | |
| 152 SimpleEnclosedRegion(-90, 10, 10, 10)); | |
| 153 Occlusion some_occluded_down(move_down, | |
| 154 SimpleEnclosedRegion(0, 100, 10, 10), | |
| 155 SimpleEnclosedRegion(10, 110, 10, 10)); | |
| 156 EXPECT_OCCLUSION(some_occluded_left, rects, true, false, false, true); | |
| 157 EXPECT_OCCLUSION(some_occluded_down, rects, true, false, false, true); | |
| 158 } | |
| 159 | |
| 160 TEST(OcclusionTest, IsOccludedScaledAfterConstruction) { | |
| 161 gfx::Rect rects[] = {gfx::Rect(10, 10), | |
| 162 gfx::Rect(10, 0, 10, 10), | |
| 163 gfx::Rect(0, 10, 10, 10), | |
| 164 gfx::Rect(10, 10, 10, 10)}; | |
| 165 | |
| 166 gfx::Transform half_transform; | |
| 167 half_transform.Scale(0.5, 0.5); | |
| 168 | |
| 169 gfx::Transform double_transform; | |
| 170 double_transform.Scale(2, 2); | |
| 171 | |
| 172 Occlusion all_occluded_outside( | |
| 173 gfx::Transform(), SimpleEnclosedRegion(10, 10), SimpleEnclosedRegion()); | |
| 174 Occlusion all_occluded_outside_half = | |
| 175 all_occluded_outside.GetOcclusionWithGivenDrawTransform(half_transform); | |
| 176 | |
| 177 all_occluded_outside = Occlusion( | |
| 178 gfx::Transform(), SimpleEnclosedRegion(40, 40), SimpleEnclosedRegion()); | |
| 179 Occlusion all_occluded_outside_double = | |
| 180 all_occluded_outside.GetOcclusionWithGivenDrawTransform(double_transform); | |
| 181 | |
| 182 EXPECT_OCCLUSION(all_occluded_outside_half, rects, true, true, true, true); | |
| 183 EXPECT_OCCLUSION(all_occluded_outside_double, rects, true, true, true, true); | |
| 184 | |
| 185 Occlusion some_occluded(gfx::Transform(), | |
| 186 SimpleEnclosedRegion(5, 5), | |
| 187 SimpleEnclosedRegion(5, 5, 5, 5)); | |
| 188 Occlusion some_occluded_half = | |
| 189 some_occluded.GetOcclusionWithGivenDrawTransform(half_transform); | |
| 190 | |
| 191 some_occluded = Occlusion(gfx::Transform(), | |
| 192 SimpleEnclosedRegion(20, 20), | |
| 193 SimpleEnclosedRegion(20, 20, 20, 20)); | |
| 194 Occlusion some_occluded_double = | |
| 195 some_occluded.GetOcclusionWithGivenDrawTransform(double_transform); | |
| 196 | |
| 197 EXPECT_OCCLUSION(some_occluded_half, rects, true, false, false, true); | |
| 198 EXPECT_OCCLUSION(some_occluded_double, rects, true, false, false, true); | |
| 199 } | |
| 200 | |
| 201 TEST(OcclusionTest, GetUnoccludedContentRectNoTransform) { | |
| 202 Occlusion some_occluded(gfx::Transform(), | |
| 203 SimpleEnclosedRegion(10, 10), | |
| 204 SimpleEnclosedRegion(10, 10, 10, 10)); | |
| 205 | |
| 206 gfx::Rect full_query_result = | |
| 207 some_occluded.GetUnoccludedContentRect(gfx::Rect(20, 20)); | |
| 208 EXPECT_EQ(gfx::Rect(20, 20), full_query_result); | |
| 209 | |
| 210 gfx::Rect half_query_result = | |
| 211 some_occluded.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); | |
| 212 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result); | |
| 213 } | |
| 214 | |
| 215 TEST(OcclusionTest, GetUnoccludedContentRectScaled) { | |
| 216 gfx::Transform half_scale; | |
| 217 half_scale.Scale(0.5, 0.5); | |
| 218 | |
| 219 gfx::Transform double_scale; | |
| 220 double_scale.Scale(2, 2); | |
| 221 | |
| 222 Occlusion some_occluded_half( | |
| 223 half_scale, SimpleEnclosedRegion(5, 5), SimpleEnclosedRegion(5, 5, 5, 5)); | |
| 224 Occlusion some_occluded_double(double_scale, | |
| 225 SimpleEnclosedRegion(20, 20), | |
| 226 SimpleEnclosedRegion(20, 20, 20, 20)); | |
| 227 gfx::Rect full_query_result_half = | |
| 228 some_occluded_half.GetUnoccludedContentRect(gfx::Rect(20, 20)); | |
| 229 gfx::Rect full_query_result_double = | |
| 230 some_occluded_double.GetUnoccludedContentRect(gfx::Rect(20, 20)); | |
| 231 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_half); | |
| 232 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_double); | |
| 233 | |
| 234 gfx::Rect half_query_result_half = | |
| 235 some_occluded_half.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); | |
| 236 gfx::Rect half_query_result_double = | |
| 237 some_occluded_half.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); | |
| 238 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_half); | |
| 239 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_double); | |
| 240 } | |
| 241 | |
| 242 TEST(OcclusionTest, GetUnoccludedContentRectTranslated) { | |
| 243 gfx::Transform move_left; | |
| 244 move_left.Translate(-100, 0); | |
| 245 | |
| 246 gfx::Transform move_down; | |
| 247 move_down.Translate(0, 100); | |
| 248 | |
| 249 Occlusion some_occluded_left(move_left, | |
| 250 SimpleEnclosedRegion(-100, 0, 10, 10), | |
| 251 SimpleEnclosedRegion(-90, 10, 10, 10)); | |
| 252 Occlusion some_occluded_down(move_down, | |
| 253 SimpleEnclosedRegion(0, 100, 0, 10), | |
| 254 SimpleEnclosedRegion(10, 110, 10, 10)); | |
| 255 | |
| 256 gfx::Rect full_query_result_left = | |
| 257 some_occluded_left.GetUnoccludedContentRect(gfx::Rect(20, 20)); | |
| 258 gfx::Rect full_query_result_down = | |
| 259 some_occluded_down.GetUnoccludedContentRect(gfx::Rect(20, 20)); | |
| 260 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_left); | |
| 261 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_down); | |
| 262 | |
| 263 gfx::Rect half_query_result_left = | |
| 264 some_occluded_left.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); | |
| 265 gfx::Rect half_query_result_down = | |
| 266 some_occluded_down.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); | |
| 267 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_left); | |
| 268 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_down); | |
| 269 } | |
| 270 | |
| 271 } // namespace | |
| 272 } // namespace cc | |
| OLD | NEW |