| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/paint_aggregator.h" | 5 #include "chrome/renderer/paint_aggregator.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 TEST(PaintAggregator, InitialState) { | 8 TEST(PaintAggregator, InitialState) { |
| 9 PaintAggregator greg; | 9 PaintAggregator greg; |
| 10 EXPECT_FALSE(greg.HasPendingUpdate()); | 10 EXPECT_FALSE(greg.HasPendingUpdate()); |
| 11 } | 11 } |
| 12 | 12 |
| 13 TEST(PaintAggregator, SingleInvalidation) { | 13 TEST(PaintAggregator, SingleInvalidation) { |
| 14 PaintAggregator greg; | 14 PaintAggregator greg; |
| 15 | 15 |
| 16 gfx::Rect rect(2, 4, 10, 16); | 16 gfx::Rect rect(2, 4, 10, 16); |
| 17 greg.InvalidateRect(rect); | 17 greg.InvalidateRect(rect); |
| 18 | 18 |
| 19 EXPECT_TRUE(greg.HasPendingUpdate()); | 19 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 20 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 20 PaintAggregator::PendingUpdate update; |
| 21 ASSERT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 21 greg.PopPendingUpdate(&update); |
| 22 | 22 |
| 23 EXPECT_EQ(rect, greg.GetPendingUpdate().paint_rects[0]); | 23 EXPECT_TRUE(update.scroll_rect.IsEmpty()); |
| 24 ASSERT_EQ(1U, update.paint_rects.size()); |
| 25 |
| 26 EXPECT_EQ(rect, update.paint_rects[0]); |
| 24 } | 27 } |
| 25 | 28 |
| 26 TEST(PaintAggregator, DoubleDisjointInvalidation) { | 29 TEST(PaintAggregator, DoubleDisjointInvalidation) { |
| 27 PaintAggregator greg; | 30 PaintAggregator greg; |
| 28 | 31 |
| 29 gfx::Rect r1(2, 4, 2, 4); | 32 gfx::Rect r1(2, 4, 2, 40); |
| 30 gfx::Rect r2(4, 2, 4, 2); | 33 gfx::Rect r2(4, 2, 40, 2); |
| 31 | 34 |
| 32 greg.InvalidateRect(r1); | 35 greg.InvalidateRect(r1); |
| 33 greg.InvalidateRect(r2); | 36 greg.InvalidateRect(r2); |
| 34 | 37 |
| 35 gfx::Rect expected_bounds = r1.Union(r2); | 38 gfx::Rect expected_bounds = r1.Union(r2); |
| 36 | 39 |
| 37 EXPECT_TRUE(greg.HasPendingUpdate()); | 40 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 38 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 41 PaintAggregator::PendingUpdate update; |
| 39 ASSERT_EQ(2U, greg.GetPendingUpdate().paint_rects.size()); | 42 greg.PopPendingUpdate(&update); |
| 40 | 43 |
| 41 EXPECT_EQ(expected_bounds, greg.GetPendingUpdate().GetPaintBounds()); | 44 EXPECT_TRUE(update.scroll_rect.IsEmpty()); |
| 45 EXPECT_EQ(2U, update.paint_rects.size()); |
| 46 |
| 47 EXPECT_EQ(expected_bounds, update.GetPaintBounds()); |
| 48 } |
| 49 |
| 50 TEST(PaintAggregator, DisjointInvalidationsCombined) { |
| 51 PaintAggregator greg; |
| 52 |
| 53 gfx::Rect r1(2, 4, 2, 2); |
| 54 gfx::Rect r2(4, 2, 2, 2); |
| 55 |
| 56 greg.InvalidateRect(r1); |
| 57 greg.InvalidateRect(r2); |
| 58 |
| 59 gfx::Rect expected_bounds = r1.Union(r2); |
| 60 |
| 61 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 62 PaintAggregator::PendingUpdate update; |
| 63 greg.PopPendingUpdate(&update); |
| 64 |
| 65 EXPECT_TRUE(update.scroll_rect.IsEmpty()); |
| 66 ASSERT_EQ(1U, update.paint_rects.size()); |
| 67 |
| 68 EXPECT_EQ(expected_bounds, update.paint_rects[0]); |
| 42 } | 69 } |
| 43 | 70 |
| 44 TEST(PaintAggregator, SingleScroll) { | 71 TEST(PaintAggregator, SingleScroll) { |
| 45 PaintAggregator greg; | 72 PaintAggregator greg; |
| 46 | 73 |
| 47 gfx::Rect rect(1, 2, 3, 4); | 74 gfx::Rect rect(1, 2, 3, 4); |
| 48 gfx::Point delta(1, 0); | 75 gfx::Point delta(1, 0); |
| 49 greg.ScrollRect(delta.x(), delta.y(), rect); | 76 greg.ScrollRect(delta.x(), delta.y(), rect); |
| 50 | 77 |
| 51 EXPECT_TRUE(greg.HasPendingUpdate()); | 78 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 52 EXPECT_TRUE(greg.GetPendingUpdate().paint_rects.empty()); | 79 PaintAggregator::PendingUpdate update; |
| 53 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 80 greg.PopPendingUpdate(&update); |
| 54 | 81 |
| 55 EXPECT_EQ(rect, greg.GetPendingUpdate().scroll_rect); | 82 EXPECT_TRUE(update.paint_rects.empty()); |
| 83 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 56 | 84 |
| 57 EXPECT_EQ(delta.x(), greg.GetPendingUpdate().scroll_delta.x()); | 85 EXPECT_EQ(rect, update.scroll_rect); |
| 58 EXPECT_EQ(delta.y(), greg.GetPendingUpdate().scroll_delta.y()); | |
| 59 | 86 |
| 60 gfx::Rect resulting_damage = greg.GetPendingUpdate().GetScrollDamage(); | 87 EXPECT_EQ(delta.x(), update.scroll_delta.x()); |
| 88 EXPECT_EQ(delta.y(), update.scroll_delta.y()); |
| 89 |
| 90 gfx::Rect resulting_damage = update.GetScrollDamage(); |
| 61 gfx::Rect expected_damage(1, 2, 1, 4); | 91 gfx::Rect expected_damage(1, 2, 1, 4); |
| 62 EXPECT_EQ(expected_damage, resulting_damage); | 92 EXPECT_EQ(expected_damage, resulting_damage); |
| 63 } | 93 } |
| 64 | 94 |
| 65 TEST(PaintAggregator, DoubleOverlappingScroll) { | 95 TEST(PaintAggregator, DoubleOverlappingScroll) { |
| 66 PaintAggregator greg; | 96 PaintAggregator greg; |
| 67 | 97 |
| 68 gfx::Rect rect(1, 2, 3, 4); | 98 gfx::Rect rect(1, 2, 3, 4); |
| 69 gfx::Point delta1(1, 0); | 99 gfx::Point delta1(1, 0); |
| 70 gfx::Point delta2(1, 0); | 100 gfx::Point delta2(1, 0); |
| 71 greg.ScrollRect(delta1.x(), delta1.y(), rect); | 101 greg.ScrollRect(delta1.x(), delta1.y(), rect); |
| 72 greg.ScrollRect(delta2.x(), delta2.y(), rect); | 102 greg.ScrollRect(delta2.x(), delta2.y(), rect); |
| 73 | 103 |
| 74 EXPECT_TRUE(greg.HasPendingUpdate()); | 104 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 75 EXPECT_TRUE(greg.GetPendingUpdate().paint_rects.empty()); | 105 PaintAggregator::PendingUpdate update; |
| 76 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 106 greg.PopPendingUpdate(&update); |
| 77 | 107 |
| 78 EXPECT_EQ(rect, greg.GetPendingUpdate().scroll_rect); | 108 EXPECT_TRUE(update.paint_rects.empty()); |
| 109 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 110 |
| 111 EXPECT_EQ(rect, update.scroll_rect); |
| 79 | 112 |
| 80 gfx::Point expected_delta(delta1.x() + delta2.x(), | 113 gfx::Point expected_delta(delta1.x() + delta2.x(), |
| 81 delta1.y() + delta2.y()); | 114 delta1.y() + delta2.y()); |
| 82 EXPECT_EQ(expected_delta.x(), greg.GetPendingUpdate().scroll_delta.x()); | 115 EXPECT_EQ(expected_delta.x(), update.scroll_delta.x()); |
| 83 EXPECT_EQ(expected_delta.y(), greg.GetPendingUpdate().scroll_delta.y()); | 116 EXPECT_EQ(expected_delta.y(), update.scroll_delta.y()); |
| 84 | 117 |
| 85 gfx::Rect resulting_damage = greg.GetPendingUpdate().GetScrollDamage(); | 118 gfx::Rect resulting_damage = update.GetScrollDamage(); |
| 86 gfx::Rect expected_damage(1, 2, 2, 4); | 119 gfx::Rect expected_damage(1, 2, 2, 4); |
| 87 EXPECT_EQ(expected_damage, resulting_damage); | 120 EXPECT_EQ(expected_damage, resulting_damage); |
| 88 } | 121 } |
| 89 | 122 |
| 90 TEST(PaintAggregator, NegatingScroll) { | 123 TEST(PaintAggregator, NegatingScroll) { |
| 91 PaintAggregator greg; | 124 PaintAggregator greg; |
| 92 | 125 |
| 93 // Scroll twice in opposite directions by equal amounts. The result | 126 // Scroll twice in opposite directions by equal amounts. The result |
| 94 // should be no scrolling. | 127 // should be no scrolling. |
| 95 | 128 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 106 PaintAggregator greg; | 139 PaintAggregator greg; |
| 107 | 140 |
| 108 // We don't support optimized diagonal scrolling, so this should result in | 141 // We don't support optimized diagonal scrolling, so this should result in |
| 109 // repainting. | 142 // repainting. |
| 110 | 143 |
| 111 gfx::Rect rect(1, 2, 3, 4); | 144 gfx::Rect rect(1, 2, 3, 4); |
| 112 gfx::Point delta(1, 1); | 145 gfx::Point delta(1, 1); |
| 113 greg.ScrollRect(delta.x(), delta.y(), rect); | 146 greg.ScrollRect(delta.x(), delta.y(), rect); |
| 114 | 147 |
| 115 EXPECT_TRUE(greg.HasPendingUpdate()); | 148 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 116 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 149 PaintAggregator::PendingUpdate update; |
| 117 ASSERT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 150 greg.PopPendingUpdate(&update); |
| 118 | 151 |
| 119 EXPECT_EQ(rect, greg.GetPendingUpdate().paint_rects[0]); | 152 EXPECT_TRUE(update.scroll_rect.IsEmpty()); |
| 153 ASSERT_EQ(1U, update.paint_rects.size()); |
| 154 |
| 155 EXPECT_EQ(rect, update.paint_rects[0]); |
| 120 } | 156 } |
| 121 | 157 |
| 122 TEST(PaintAggregator, ContainedPaintAfterScroll) { | 158 TEST(PaintAggregator, ContainedPaintAfterScroll) { |
| 123 PaintAggregator greg; | 159 PaintAggregator greg; |
| 124 | 160 |
| 125 gfx::Rect scroll_rect(0, 0, 10, 10); | 161 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 126 greg.ScrollRect(2, 0, scroll_rect); | 162 greg.ScrollRect(2, 0, scroll_rect); |
| 127 | 163 |
| 128 gfx::Rect paint_rect(4, 4, 2, 2); | 164 gfx::Rect paint_rect(4, 4, 2, 2); |
| 129 greg.InvalidateRect(paint_rect); | 165 greg.InvalidateRect(paint_rect); |
| 130 | 166 |
| 131 EXPECT_TRUE(greg.HasPendingUpdate()); | 167 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 168 PaintAggregator::PendingUpdate update; |
| 169 greg.PopPendingUpdate(&update); |
| 132 | 170 |
| 133 // expecting a paint rect inside the scroll rect | 171 // expecting a paint rect inside the scroll rect |
| 134 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 172 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 135 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 173 EXPECT_EQ(1U, update.paint_rects.size()); |
| 136 | 174 |
| 137 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().scroll_rect); | 175 EXPECT_EQ(scroll_rect, update.scroll_rect); |
| 138 EXPECT_EQ(paint_rect, greg.GetPendingUpdate().paint_rects[0]); | 176 EXPECT_EQ(paint_rect, update.paint_rects[0]); |
| 139 } | 177 } |
| 140 | 178 |
| 141 TEST(PaintAggregator, ContainedPaintBeforeScroll) { | 179 TEST(PaintAggregator, ContainedPaintBeforeScroll) { |
| 142 PaintAggregator greg; | 180 PaintAggregator greg; |
| 143 | 181 |
| 144 gfx::Rect paint_rect(4, 4, 2, 2); | 182 gfx::Rect paint_rect(4, 4, 2, 2); |
| 145 greg.InvalidateRect(paint_rect); | 183 greg.InvalidateRect(paint_rect); |
| 146 | 184 |
| 147 gfx::Rect scroll_rect(0, 0, 10, 10); | 185 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 148 greg.ScrollRect(2, 0, scroll_rect); | 186 greg.ScrollRect(2, 0, scroll_rect); |
| 149 | 187 |
| 150 EXPECT_TRUE(greg.HasPendingUpdate()); | 188 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 189 PaintAggregator::PendingUpdate update; |
| 190 greg.PopPendingUpdate(&update); |
| 151 | 191 |
| 152 // Expecting a paint rect inside the scroll rect | 192 // Expecting a paint rect inside the scroll rect |
| 153 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 193 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 154 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 194 EXPECT_EQ(1U, update.paint_rects.size()); |
| 155 | 195 |
| 156 paint_rect.Offset(2, 0); | 196 paint_rect.Offset(2, 0); |
| 157 | 197 |
| 158 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().scroll_rect); | 198 EXPECT_EQ(scroll_rect, update.scroll_rect); |
| 159 EXPECT_EQ(paint_rect, greg.GetPendingUpdate().paint_rects[0]); | 199 EXPECT_EQ(paint_rect, update.paint_rects[0]); |
| 160 } | 200 } |
| 161 | 201 |
| 162 TEST(PaintAggregator, ContainedPaintsBeforeAndAfterScroll) { | 202 TEST(PaintAggregator, ContainedPaintsBeforeAndAfterScroll) { |
| 163 PaintAggregator greg; | 203 PaintAggregator greg; |
| 164 | 204 |
| 165 gfx::Rect paint_rect1(4, 4, 2, 2); | 205 gfx::Rect paint_rect1(4, 4, 2, 2); |
| 166 greg.InvalidateRect(paint_rect1); | 206 greg.InvalidateRect(paint_rect1); |
| 167 | 207 |
| 168 gfx::Rect scroll_rect(0, 0, 10, 10); | 208 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 169 greg.ScrollRect(2, 0, scroll_rect); | 209 greg.ScrollRect(2, 0, scroll_rect); |
| 170 | 210 |
| 171 gfx::Rect paint_rect2(6, 4, 2, 2); | 211 gfx::Rect paint_rect2(6, 4, 2, 2); |
| 172 greg.InvalidateRect(paint_rect2); | 212 greg.InvalidateRect(paint_rect2); |
| 173 | 213 |
| 174 gfx::Rect expected_paint_rect = paint_rect2; | 214 gfx::Rect expected_paint_rect = paint_rect2; |
| 175 | 215 |
| 176 EXPECT_TRUE(greg.HasPendingUpdate()); | 216 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 217 PaintAggregator::PendingUpdate update; |
| 218 greg.PopPendingUpdate(&update); |
| 177 | 219 |
| 178 // Expecting a paint rect inside the scroll rect | 220 // Expecting a paint rect inside the scroll rect |
| 179 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 221 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 180 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 222 EXPECT_EQ(1U, update.paint_rects.size()); |
| 181 | 223 |
| 182 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().scroll_rect); | 224 EXPECT_EQ(scroll_rect, update.scroll_rect); |
| 183 EXPECT_EQ(expected_paint_rect, greg.GetPendingUpdate().paint_rects[0]); | 225 EXPECT_EQ(expected_paint_rect, update.paint_rects[0]); |
| 184 } | 226 } |
| 185 | 227 |
| 186 TEST(PaintAggregator, LargeContainedPaintAfterScroll) { | 228 TEST(PaintAggregator, LargeContainedPaintAfterScroll) { |
| 187 PaintAggregator greg; | 229 PaintAggregator greg; |
| 188 | 230 |
| 189 gfx::Rect scroll_rect(0, 0, 10, 10); | 231 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 190 greg.ScrollRect(0, 1, scroll_rect); | 232 greg.ScrollRect(0, 1, scroll_rect); |
| 191 | 233 |
| 192 gfx::Rect paint_rect(0, 0, 10, 9); // Repaint 90% | 234 gfx::Rect paint_rect(0, 0, 10, 9); // Repaint 90% |
| 193 greg.InvalidateRect(paint_rect); | 235 greg.InvalidateRect(paint_rect); |
| 194 | 236 |
| 195 EXPECT_TRUE(greg.HasPendingUpdate()); | 237 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 238 PaintAggregator::PendingUpdate update; |
| 239 greg.PopPendingUpdate(&update); |
| 196 | 240 |
| 197 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 241 EXPECT_TRUE(update.scroll_rect.IsEmpty()); |
| 198 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 242 EXPECT_EQ(1U, update.paint_rects.size()); |
| 199 | 243 |
| 200 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().paint_rects[0]); | 244 EXPECT_EQ(scroll_rect, update.paint_rects[0]); |
| 201 } | 245 } |
| 202 | 246 |
| 203 TEST(PaintAggregator, LargeContainedPaintBeforeScroll) { | 247 TEST(PaintAggregator, LargeContainedPaintBeforeScroll) { |
| 204 PaintAggregator greg; | 248 PaintAggregator greg; |
| 205 | 249 |
| 206 gfx::Rect paint_rect(0, 0, 10, 9); // Repaint 90% | 250 gfx::Rect paint_rect(0, 0, 10, 9); // Repaint 90% |
| 207 greg.InvalidateRect(paint_rect); | 251 greg.InvalidateRect(paint_rect); |
| 208 | 252 |
| 209 gfx::Rect scroll_rect(0, 0, 10, 10); | 253 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 210 greg.ScrollRect(0, 1, scroll_rect); | 254 greg.ScrollRect(0, 1, scroll_rect); |
| 211 | 255 |
| 212 EXPECT_TRUE(greg.HasPendingUpdate()); | 256 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 257 PaintAggregator::PendingUpdate update; |
| 258 greg.PopPendingUpdate(&update); |
| 213 | 259 |
| 214 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 260 EXPECT_TRUE(update.scroll_rect.IsEmpty()); |
| 215 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 261 EXPECT_EQ(1U, update.paint_rects.size()); |
| 216 | 262 |
| 217 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().paint_rects[0]); | 263 EXPECT_EQ(scroll_rect, update.paint_rects[0]); |
| 218 } | 264 } |
| 219 | 265 |
| 220 TEST(PaintAggregator, OverlappingPaintBeforeScroll) { | 266 TEST(PaintAggregator, OverlappingPaintBeforeScroll) { |
| 221 PaintAggregator greg; | 267 PaintAggregator greg; |
| 222 | 268 |
| 223 gfx::Rect paint_rect(4, 4, 10, 2); | 269 gfx::Rect paint_rect(4, 4, 10, 2); |
| 224 greg.InvalidateRect(paint_rect); | 270 greg.InvalidateRect(paint_rect); |
| 225 | 271 |
| 226 gfx::Rect scroll_rect(0, 0, 10, 10); | 272 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 227 greg.ScrollRect(2, 0, scroll_rect); | 273 greg.ScrollRect(2, 0, scroll_rect); |
| 228 | 274 |
| 229 gfx::Rect expected_paint_rect = scroll_rect.Union(paint_rect); | 275 gfx::Rect expected_paint_rect = scroll_rect.Union(paint_rect); |
| 230 | 276 |
| 231 EXPECT_TRUE(greg.HasPendingUpdate()); | 277 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 278 PaintAggregator::PendingUpdate update; |
| 279 greg.PopPendingUpdate(&update); |
| 232 | 280 |
| 233 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 281 EXPECT_TRUE(update.scroll_rect.IsEmpty()); |
| 234 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 282 EXPECT_EQ(1U, update.paint_rects.size()); |
| 235 | 283 |
| 236 EXPECT_EQ(expected_paint_rect, greg.GetPendingUpdate().paint_rects[0]); | 284 EXPECT_EQ(expected_paint_rect, update.paint_rects[0]); |
| 237 } | 285 } |
| 238 | 286 |
| 239 TEST(PaintAggregator, OverlappingPaintAfterScroll) { | 287 TEST(PaintAggregator, OverlappingPaintAfterScroll) { |
| 240 PaintAggregator greg; | 288 PaintAggregator greg; |
| 241 | 289 |
| 242 gfx::Rect scroll_rect(0, 0, 10, 10); | 290 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 243 greg.ScrollRect(2, 0, scroll_rect); | 291 greg.ScrollRect(2, 0, scroll_rect); |
| 244 | 292 |
| 245 gfx::Rect paint_rect(4, 4, 10, 2); | 293 gfx::Rect paint_rect(4, 4, 10, 2); |
| 246 greg.InvalidateRect(paint_rect); | 294 greg.InvalidateRect(paint_rect); |
| 247 | 295 |
| 248 gfx::Rect expected_paint_rect = scroll_rect.Union(paint_rect); | 296 gfx::Rect expected_paint_rect = scroll_rect.Union(paint_rect); |
| 249 | 297 |
| 250 EXPECT_TRUE(greg.HasPendingUpdate()); | 298 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 299 PaintAggregator::PendingUpdate update; |
| 300 greg.PopPendingUpdate(&update); |
| 251 | 301 |
| 252 EXPECT_TRUE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 302 EXPECT_TRUE(update.scroll_rect.IsEmpty()); |
| 253 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 303 EXPECT_EQ(1U, update.paint_rects.size()); |
| 254 | 304 |
| 255 EXPECT_EQ(expected_paint_rect, greg.GetPendingUpdate().paint_rects[0]); | 305 EXPECT_EQ(expected_paint_rect, update.paint_rects[0]); |
| 256 } | 306 } |
| 257 | 307 |
| 258 TEST(PaintAggregator, DisjointPaintBeforeScroll) { | 308 TEST(PaintAggregator, DisjointPaintBeforeScroll) { |
| 259 PaintAggregator greg; | 309 PaintAggregator greg; |
| 260 | 310 |
| 261 gfx::Rect paint_rect(4, 4, 10, 2); | 311 gfx::Rect paint_rect(4, 4, 10, 2); |
| 262 greg.InvalidateRect(paint_rect); | 312 greg.InvalidateRect(paint_rect); |
| 263 | 313 |
| 264 gfx::Rect scroll_rect(0, 0, 2, 10); | 314 gfx::Rect scroll_rect(0, 0, 2, 10); |
| 265 greg.ScrollRect(2, 0, scroll_rect); | 315 greg.ScrollRect(2, 0, scroll_rect); |
| 266 | 316 |
| 267 EXPECT_TRUE(greg.HasPendingUpdate()); | 317 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 318 PaintAggregator::PendingUpdate update; |
| 319 greg.PopPendingUpdate(&update); |
| 268 | 320 |
| 269 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 321 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 270 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 322 EXPECT_EQ(1U, update.paint_rects.size()); |
| 271 | 323 |
| 272 EXPECT_EQ(paint_rect, greg.GetPendingUpdate().paint_rects[0]); | 324 EXPECT_EQ(paint_rect, update.paint_rects[0]); |
| 273 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().scroll_rect); | 325 EXPECT_EQ(scroll_rect, update.scroll_rect); |
| 274 } | 326 } |
| 275 | 327 |
| 276 TEST(PaintAggregator, DisjointPaintAfterScroll) { | 328 TEST(PaintAggregator, DisjointPaintAfterScroll) { |
| 277 PaintAggregator greg; | 329 PaintAggregator greg; |
| 278 | 330 |
| 279 gfx::Rect scroll_rect(0, 0, 2, 10); | 331 gfx::Rect scroll_rect(0, 0, 2, 10); |
| 280 greg.ScrollRect(2, 0, scroll_rect); | 332 greg.ScrollRect(2, 0, scroll_rect); |
| 281 | 333 |
| 282 gfx::Rect paint_rect(4, 4, 10, 2); | 334 gfx::Rect paint_rect(4, 4, 10, 2); |
| 283 greg.InvalidateRect(paint_rect); | 335 greg.InvalidateRect(paint_rect); |
| 284 | 336 |
| 285 EXPECT_TRUE(greg.HasPendingUpdate()); | 337 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 338 PaintAggregator::PendingUpdate update; |
| 339 greg.PopPendingUpdate(&update); |
| 286 | 340 |
| 287 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 341 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 288 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 342 EXPECT_EQ(1U, update.paint_rects.size()); |
| 289 | 343 |
| 290 EXPECT_EQ(paint_rect, greg.GetPendingUpdate().paint_rects[0]); | 344 EXPECT_EQ(paint_rect, update.paint_rects[0]); |
| 291 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().scroll_rect); | 345 EXPECT_EQ(scroll_rect, update.scroll_rect); |
| 292 } | 346 } |
| 293 | 347 |
| 294 TEST(PaintAggregator, ContainedPaintTrimmedByScroll) { | 348 TEST(PaintAggregator, ContainedPaintTrimmedByScroll) { |
| 295 PaintAggregator greg; | 349 PaintAggregator greg; |
| 296 | 350 |
| 297 gfx::Rect paint_rect(4, 4, 6, 6); | 351 gfx::Rect paint_rect(4, 4, 6, 6); |
| 298 greg.InvalidateRect(paint_rect); | 352 greg.InvalidateRect(paint_rect); |
| 299 | 353 |
| 300 gfx::Rect scroll_rect(0, 0, 10, 10); | 354 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 301 greg.ScrollRect(2, 0, scroll_rect); | 355 greg.ScrollRect(2, 0, scroll_rect); |
| 302 | 356 |
| 303 // The paint rect should have become narrower. | 357 // The paint rect should have become narrower. |
| 304 gfx::Rect expected_paint_rect(6, 4, 4, 6); | 358 gfx::Rect expected_paint_rect(6, 4, 4, 6); |
| 305 | 359 |
| 306 EXPECT_TRUE(greg.HasPendingUpdate()); | 360 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 361 PaintAggregator::PendingUpdate update; |
| 362 greg.PopPendingUpdate(&update); |
| 307 | 363 |
| 308 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 364 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 309 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 365 EXPECT_EQ(1U, update.paint_rects.size()); |
| 310 | 366 |
| 311 EXPECT_EQ(expected_paint_rect, greg.GetPendingUpdate().paint_rects[0]); | 367 EXPECT_EQ(expected_paint_rect, update.paint_rects[0]); |
| 312 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().scroll_rect); | 368 EXPECT_EQ(scroll_rect, update.scroll_rect); |
| 313 } | 369 } |
| 314 | 370 |
| 315 TEST(PaintAggregator, ContainedPaintEliminatedByScroll) { | 371 TEST(PaintAggregator, ContainedPaintEliminatedByScroll) { |
| 316 PaintAggregator greg; | 372 PaintAggregator greg; |
| 317 | 373 |
| 318 gfx::Rect paint_rect(4, 4, 6, 6); | 374 gfx::Rect paint_rect(4, 4, 6, 6); |
| 319 greg.InvalidateRect(paint_rect); | 375 greg.InvalidateRect(paint_rect); |
| 320 | 376 |
| 321 gfx::Rect scroll_rect(0, 0, 10, 10); | 377 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 322 greg.ScrollRect(6, 0, scroll_rect); | 378 greg.ScrollRect(6, 0, scroll_rect); |
| 323 | 379 |
| 324 EXPECT_TRUE(greg.HasPendingUpdate()); | 380 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 381 PaintAggregator::PendingUpdate update; |
| 382 greg.PopPendingUpdate(&update); |
| 325 | 383 |
| 326 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 384 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 327 EXPECT_TRUE(greg.GetPendingUpdate().paint_rects.empty()); | 385 EXPECT_TRUE(update.paint_rects.empty()); |
| 328 | 386 |
| 329 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().scroll_rect); | 387 EXPECT_EQ(scroll_rect, update.scroll_rect); |
| 330 } | 388 } |
| 331 | 389 |
| 332 TEST(PaintAggregator, ContainedPaintAfterScrollTrimmedByScrollDamage) { | 390 TEST(PaintAggregator, ContainedPaintAfterScrollTrimmedByScrollDamage) { |
| 333 PaintAggregator greg; | 391 PaintAggregator greg; |
| 334 | 392 |
| 335 gfx::Rect scroll_rect(0, 0, 10, 10); | 393 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 336 greg.ScrollRect(4, 0, scroll_rect); | 394 greg.ScrollRect(4, 0, scroll_rect); |
| 337 | 395 |
| 338 gfx::Rect paint_rect(2, 0, 4, 10); | 396 gfx::Rect paint_rect(2, 0, 4, 10); |
| 339 greg.InvalidateRect(paint_rect); | 397 greg.InvalidateRect(paint_rect); |
| 340 | 398 |
| 341 gfx::Rect expected_scroll_damage(0, 0, 4, 10); | 399 gfx::Rect expected_scroll_damage(0, 0, 4, 10); |
| 342 gfx::Rect expected_paint_rect(4, 0, 2, 10); | 400 gfx::Rect expected_paint_rect(4, 0, 2, 10); |
| 343 | 401 |
| 344 EXPECT_TRUE(greg.HasPendingUpdate()); | 402 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 403 PaintAggregator::PendingUpdate update; |
| 404 greg.PopPendingUpdate(&update); |
| 345 | 405 |
| 346 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 406 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 347 EXPECT_EQ(1U, greg.GetPendingUpdate().paint_rects.size()); | 407 EXPECT_EQ(1U, update.paint_rects.size()); |
| 348 | 408 |
| 349 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().scroll_rect); | 409 EXPECT_EQ(scroll_rect, update.scroll_rect); |
| 350 EXPECT_EQ(expected_scroll_damage, greg.GetPendingUpdate().GetScrollDamage()); | 410 EXPECT_EQ(expected_scroll_damage, update.GetScrollDamage()); |
| 351 EXPECT_EQ(expected_paint_rect, greg.GetPendingUpdate().paint_rects[0]); | 411 EXPECT_EQ(expected_paint_rect, update.paint_rects[0]); |
| 352 } | 412 } |
| 353 | 413 |
| 354 TEST(PaintAggregator, ContainedPaintAfterScrollEliminatedByScrollDamage) { | 414 TEST(PaintAggregator, ContainedPaintAfterScrollEliminatedByScrollDamage) { |
| 355 PaintAggregator greg; | 415 PaintAggregator greg; |
| 356 | 416 |
| 357 gfx::Rect scroll_rect(0, 0, 10, 10); | 417 gfx::Rect scroll_rect(0, 0, 10, 10); |
| 358 greg.ScrollRect(4, 0, scroll_rect); | 418 greg.ScrollRect(4, 0, scroll_rect); |
| 359 | 419 |
| 360 gfx::Rect paint_rect(2, 0, 2, 10); | 420 gfx::Rect paint_rect(2, 0, 2, 10); |
| 361 greg.InvalidateRect(paint_rect); | 421 greg.InvalidateRect(paint_rect); |
| 362 | 422 |
| 363 gfx::Rect expected_scroll_damage(0, 0, 4, 10); | 423 gfx::Rect expected_scroll_damage(0, 0, 4, 10); |
| 364 | 424 |
| 365 EXPECT_TRUE(greg.HasPendingUpdate()); | 425 EXPECT_TRUE(greg.HasPendingUpdate()); |
| 426 PaintAggregator::PendingUpdate update; |
| 427 greg.PopPendingUpdate(&update); |
| 366 | 428 |
| 367 EXPECT_FALSE(greg.GetPendingUpdate().scroll_rect.IsEmpty()); | 429 EXPECT_FALSE(update.scroll_rect.IsEmpty()); |
| 368 EXPECT_TRUE(greg.GetPendingUpdate().paint_rects.empty()); | 430 EXPECT_TRUE(update.paint_rects.empty()); |
| 369 | 431 |
| 370 EXPECT_EQ(scroll_rect, greg.GetPendingUpdate().scroll_rect); | 432 EXPECT_EQ(scroll_rect, update.scroll_rect); |
| 371 EXPECT_EQ(expected_scroll_damage, greg.GetPendingUpdate().GetScrollDamage()); | 433 EXPECT_EQ(expected_scroll_damage, update.GetScrollDamage()); |
| 372 } | 434 } |
| OLD | NEW |