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 Occlusion all_occluded_outside( |
| 167 gfx::Transform(), SimpleEnclosedRegion(10, 10), SimpleEnclosedRegion()); |
| 168 Occlusion all_occluded_outside_half = |
| 169 all_occluded_outside.GetOcclusionWithScaledDrawTransform(0.5, 0.5); |
| 170 |
| 171 all_occluded_outside = Occlusion( |
| 172 gfx::Transform(), SimpleEnclosedRegion(40, 40), SimpleEnclosedRegion()); |
| 173 Occlusion all_occluded_outside_double = |
| 174 all_occluded_outside.GetOcclusionWithScaledDrawTransform(2, 2); |
| 175 |
| 176 EXPECT_OCCLUSION(all_occluded_outside_half, rects, true, true, true, true); |
| 177 EXPECT_OCCLUSION(all_occluded_outside_double, rects, true, true, true, true); |
| 178 |
| 179 Occlusion some_occluded(gfx::Transform(), |
| 180 SimpleEnclosedRegion(5, 5), |
| 181 SimpleEnclosedRegion(5, 5, 5, 5)); |
| 182 Occlusion some_occluded_half = |
| 183 some_occluded.GetOcclusionWithScaledDrawTransform(0.5, 0.5); |
| 184 |
| 185 some_occluded = Occlusion(gfx::Transform(), |
| 186 SimpleEnclosedRegion(20, 20), |
| 187 SimpleEnclosedRegion(20, 20, 20, 20)); |
| 188 Occlusion some_occluded_double = |
| 189 some_occluded.GetOcclusionWithScaledDrawTransform(2, 2); |
| 190 |
| 191 EXPECT_OCCLUSION(some_occluded_half, rects, true, false, false, true); |
| 192 EXPECT_OCCLUSION(some_occluded_double, rects, true, false, false, true); |
| 193 } |
| 194 |
| 195 TEST(OcclusionTest, GetUnoccludedContentRectNoTransform) { |
| 196 Occlusion some_occluded(gfx::Transform(), |
| 197 SimpleEnclosedRegion(10, 10), |
| 198 SimpleEnclosedRegion(10, 10, 10, 10)); |
| 199 |
| 200 gfx::Rect full_query_result = |
| 201 some_occluded.GetUnoccludedContentRect(gfx::Rect(20, 20)); |
| 202 EXPECT_EQ(gfx::Rect(20, 20), full_query_result); |
| 203 |
| 204 gfx::Rect half_query_result = |
| 205 some_occluded.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); |
| 206 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result); |
| 207 } |
| 208 |
| 209 TEST(OcclusionTest, GetUnoccludedContentRectScaled) { |
| 210 gfx::Transform half_scale; |
| 211 half_scale.Scale(0.5, 0.5); |
| 212 |
| 213 gfx::Transform double_scale; |
| 214 double_scale.Scale(2, 2); |
| 215 |
| 216 Occlusion some_occluded_half( |
| 217 half_scale, SimpleEnclosedRegion(5, 5), SimpleEnclosedRegion(5, 5, 5, 5)); |
| 218 Occlusion some_occluded_double(double_scale, |
| 219 SimpleEnclosedRegion(20, 20), |
| 220 SimpleEnclosedRegion(20, 20, 20, 20)); |
| 221 gfx::Rect full_query_result_half = |
| 222 some_occluded_half.GetUnoccludedContentRect(gfx::Rect(20, 20)); |
| 223 gfx::Rect full_query_result_double = |
| 224 some_occluded_double.GetUnoccludedContentRect(gfx::Rect(20, 20)); |
| 225 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_half); |
| 226 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_double); |
| 227 |
| 228 gfx::Rect half_query_result_half = |
| 229 some_occluded_half.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); |
| 230 gfx::Rect half_query_result_double = |
| 231 some_occluded_half.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); |
| 232 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_half); |
| 233 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_double); |
| 234 } |
| 235 |
| 236 TEST(OcclusionTest, GetUnoccludedContentRectTranslated) { |
| 237 gfx::Transform move_left; |
| 238 move_left.Translate(-100, 0); |
| 239 |
| 240 gfx::Transform move_down; |
| 241 move_down.Translate(0, 100); |
| 242 |
| 243 Occlusion some_occluded_left(move_left, |
| 244 SimpleEnclosedRegion(-100, 0, 10, 10), |
| 245 SimpleEnclosedRegion(-90, 10, 10, 10)); |
| 246 Occlusion some_occluded_down(move_down, |
| 247 SimpleEnclosedRegion(0, 100, 0, 10), |
| 248 SimpleEnclosedRegion(10, 110, 10, 10)); |
| 249 |
| 250 gfx::Rect full_query_result_left = |
| 251 some_occluded_left.GetUnoccludedContentRect(gfx::Rect(20, 20)); |
| 252 gfx::Rect full_query_result_down = |
| 253 some_occluded_down.GetUnoccludedContentRect(gfx::Rect(20, 20)); |
| 254 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_left); |
| 255 EXPECT_EQ(gfx::Rect(20, 20), full_query_result_down); |
| 256 |
| 257 gfx::Rect half_query_result_left = |
| 258 some_occluded_left.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); |
| 259 gfx::Rect half_query_result_down = |
| 260 some_occluded_down.GetUnoccludedContentRect(gfx::Rect(10, 0, 10, 20)); |
| 261 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_left); |
| 262 EXPECT_EQ(gfx::Rect(10, 0, 10, 10), half_query_result_down); |
| 263 } |
| 264 |
| 265 } // namespace |
| 266 } // namespace cc |
OLD | NEW |