Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: cc/base/simple_enclosed_region_unittest.cc

Issue 2866063002: Improve overdraw with multiple windows (Closed)
Patch Set: remove occlusion_track_unittests and rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/base/simple_enclosed_region.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/base/simple_enclosed_region.h" 5 #include "cc/base/simple_enclosed_region.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // Anything Union contained rect = Anything. 330 // Anything Union contained rect = Anything.
331 r.Union(gfx::Rect(5, 6, 4, 5)); 331 r.Union(gfx::Rect(5, 6, 4, 5));
332 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(4, 5, 6, 7), r)); 332 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(4, 5, 6, 7), r));
333 333
334 // Anything Union containing rect = containing rect. 334 // Anything Union containing rect = containing rect.
335 r.Union(gfx::Rect(2, 3, 8, 9)); 335 r.Union(gfx::Rect(2, 3, 8, 9));
336 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(2, 3, 8, 9), r)); 336 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(2, 3, 8, 9), r));
337 r.Union(gfx::Rect(2, 3, 9, 10)); 337 r.Union(gfx::Rect(2, 3, 9, 10));
338 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(2, 3, 9, 10), r)); 338 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(2, 3, 9, 10), r));
339 339
340 // Union with a smaller disjoint rect is ignored. 340 // Union with a second disjoint rect with area larger than half of the first
341 r.Union(gfx::Rect(20, 21, 9, 9)); 341 // one.
342 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(2, 3, 9, 10), r)); 342 // +---+ +--+
343 // | | | |
344 // +---+ +--+
345 r.Union(gfx::Rect(20, 20, 6, 10));
346 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(20, 20, 6, 10), r));
343 347
344 // Union with a smaller overlapping rect is ignored. 348 // Union with a second disjoint rect with area smaller than half of the first
345 r.Union(gfx::Rect(3, 4, 9, 9)); 349 // one.
346 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(2, 3, 9, 10), r)); 350 // +----+ +--+
351 // | | +--+
352 // +----+
353 r.Union(gfx::Rect(2, 3, 3, 3));
354 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(20, 20, 6, 10), r));
347 355
348 // Union with an equal sized rect can be either one. 356 // Union with a second disjoint rect with area larger than the first one.
349 r.Union(gfx::Rect(4, 4, 9, 10)); 357 // +---+ +-------+
350 EXPECT_EQ(1u, r.GetRegionComplexity()); 358 // | | | |
351 EXPECT_TRUE(r.bounds() == gfx::Rect(2, 3, 9, 10) || 359 // +---+ +-------+
352 r.bounds() == gfx::Rect(4, 4, 9, 10)); 360 r.Union(gfx::Rect(2, 3, 15, 15));
361 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(2, 3, 15, 15), r));
353 362
354 // Union with a larger disjoint rect is taken. 363 // Union with rect which extends from the first one:
355 r.Union(gfx::Rect(20, 21, 12, 13)); 364 // +----------+
356 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(20, 21, 12, 13), r)); 365 // | 1 | 2 |
357 366 // +-----+----+
358 // Union with a larger overlapping rect is taken.
359 r.Union(gfx::Rect(19, 19, 12, 14));
360 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(19, 19, 12, 14), r));
361
362 // True also when the rect covers one edge of the existing region.
363 r = gfx::Rect(10, 10, 10, 10); 367 r = gfx::Rect(10, 10, 10, 10);
364 r.Union(gfx::Rect(12, 7, 9, 16)); 368 r.Union(gfx::Rect(20, 10, 5, 10));
365 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(12, 7, 9, 16), r)); 369 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 15, 10), r));
366 370
367 r = gfx::Rect(10, 10, 10, 10); 371 r = gfx::Rect(10, 10, 10, 10);
368 r.Union(gfx::Rect(9, 7, 9, 16)); 372 r.Union(gfx::Rect(10, 5, 10, 5));
369 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(9, 7, 9, 16), r)); 373 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 5, 10, 15), r));
370 374
371 r = gfx::Rect(10, 10, 10, 10); 375 r = gfx::Rect(10, 10, 10, 10);
372 r.Union(gfx::Rect(7, 12, 16, 9)); 376 r.Union(gfx::Rect(5, 10, 5, 10));
373 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(7, 12, 16, 9), r)); 377 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(5, 10, 15, 10), r));
374 378
375 r = gfx::Rect(10, 10, 10, 10); 379 r = gfx::Rect(10, 10, 10, 10);
376 r.Union(gfx::Rect(7, 9, 16, 9)); 380 r.Union(gfx::Rect(10, 20, 10, 5));
377 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(7, 9, 16, 9), r)); 381 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 15), r));
378 382
379 // But if the existing region can be expanded to make a larger rect, then it 383 // Union with rect which overlaps and extends from the first one:
380 // will. Union area is 9*12 = 108. By merging, we make a rect with an area of 384 // +----+--+---+
381 // 10*11 = 110. The resulting rect is expanded as far as possible while 385 // | 1 | |2 |
382 // remaining enclosed in the Union. 386 // | | | |
387 // +----+--+---+
383 r = gfx::Rect(10, 10, 10, 10); 388 r = gfx::Rect(10, 10, 10, 10);
384 r.Union(gfx::Rect(12, 9, 9, 12)); 389 r.Union(gfx::Rect(10, 2, 10, 10));
385 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 11, 10), r)); 390 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 2, 10, 18), r));
386 391
387 r = gfx::Rect(10, 10, 10, 10); 392 r = gfx::Rect(10, 10, 10, 10);
388 r.Union(gfx::Rect(9, 9, 9, 12)); 393 r.Union(gfx::Rect(2, 10, 10, 10));
389 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(9, 10, 11, 10), r)); 394 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(2, 10, 18, 10), r));
390 395
391 r = gfx::Rect(10, 10, 10, 10); 396 r = gfx::Rect(10, 10, 10, 10);
392 r.Union(gfx::Rect(9, 12, 12, 9)); 397 r.Union(gfx::Rect(10, 18, 10, 10));
393 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 11), r)); 398 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 18), r));
394 399
395 r = gfx::Rect(10, 10, 10, 10); 400 r = gfx::Rect(10, 10, 10, 10);
396 r.Union(gfx::Rect(9, 9, 12, 9)); 401 r.Union(gfx::Rect(18, 10, 10, 10));
397 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 9, 10, 11), r)); 402 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 18, 10), r));
398 403
399 r = gfx::Rect(12, 9, 9, 12); 404 // Union with a second rect which overlaps with the first one and
400 r.Union(gfx::Rect(10, 10, 10, 10)); 405 // area(rect 1) + area(overlap) > area(rect 2)*2 and
401 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 11, 10), r)); 406 // area(rect 1) < area(rect 2)*2.
407 // +---+
408 // +---|+ 2|
409 // | +---+
410 // | 1 |
411 // +----+ (same figure for next test case.)
412 r = gfx::Rect(10, 10, 10, 10);
413 r.Union(gfx::Rect(14, 12, 8, 7));
414 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 10), r));
402 415
403 r = gfx::Rect(9, 9, 9, 12); 416 r = gfx::Rect(10, 10, 10, 10);
404 r.Union(gfx::Rect(10, 10, 10, 10)); 417 r.Union(gfx::Rect(11, 9, 8, 7));
405 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(9, 10, 11, 10), r)); 418 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 10), r));
406 419
407 r = gfx::Rect(9, 12, 12, 9); 420 r = gfx::Rect(10, 10, 10, 10);
408 r.Union(gfx::Rect(10, 10, 10, 10)); 421 r.Union(gfx::Rect(9, 12, 8, 7));
409 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 11), r)); 422 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 10), r));
410 423
411 r = gfx::Rect(9, 9, 12, 9); 424 r = gfx::Rect(10, 10, 10, 10);
412 r.Union(gfx::Rect(10, 10, 10, 10)); 425 r.Union(gfx::Rect(13, 11, 8, 7));
413 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 9, 10, 11), r)); 426 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 10), r));
427
428 // Union with a second rect which overlaps with the first one and
429 // area(rect 1) + area(overlap) < area(rect 2)*2 and
430 // area(rect 1) > area(rect 2).
431 r = gfx::Rect(10, 10, 5, 5);
432 r.Union(gfx::Rect(7, 7, 4, 4));
433 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(7, 7, 4, 4), r));
434
435 r = gfx::Rect(10, 10, 5, 5);
436 r.Union(gfx::Rect(14, 7, 4, 4));
437 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(14, 7, 4, 4), r));
438
439 r = gfx::Rect(10, 10, 5, 5);
440 r.Union(gfx::Rect(7, 14, 4, 4));
441 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(7, 14, 4, 4), r));
442
443 r = gfx::Rect(10, 10, 5, 5);
444 r.Union(gfx::Rect(14, 14, 4, 4));
445 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(14, 14, 4, 4), r));
446
447 // Union with a second rect which overlaps with the first one and the new
448 // unioned rect should combine both rect.
449 // +---+-+-----------+
450 // | 1| | 2 |
451 // | +-|-----------+
452 // +-----+
453 r = gfx::Rect(10, 10, 5, 5);
454 r.Union(gfx::Rect(5, 11, 7, 4));
455 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(5, 11, 10, 4), r));
456
457 r = gfx::Rect(10, 10, 5, 5);
458 r.Union(gfx::Rect(13, 10, 7, 4));
459 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 4), r));
460
461 r = gfx::Rect(10, 10, 5, 5);
462 r.Union(gfx::Rect(10, 12, 4, 7));
463 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 4, 9), r));
464
465 r = gfx::Rect(10, 10, 5, 5);
466 r.Union(gfx::Rect(11, 11, 4, 7));
467 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(11, 10, 4, 8), r));
414 } 468 }
415 469
416 TEST(SimpleEnclosedRegionTest, Subtract) { 470 TEST(SimpleEnclosedRegionTest, Subtract) {
417 SimpleEnclosedRegion r; 471 SimpleEnclosedRegion r;
418 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(), r)); 472 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(), r));
419 473
420 // Empty Subtract anything = empty. 474 // Empty Subtract anything = empty.
421 r.Subtract(gfx::Rect(4, 5, 6, 7)); 475 r.Subtract(gfx::Rect(4, 5, 6, 7));
422 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(), r)); 476 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(), r));
423 477
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 r.Subtract(gfx::Rect(14, 13, 3, 7)); 684 r.Subtract(gfx::Rect(14, 13, 3, 7));
631 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 4, 10), r)); 685 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 4, 10), r));
632 686
633 r = gfx::Rect(10, 10, 10, 10); 687 r = gfx::Rect(10, 10, 10, 10);
634 r.Subtract(gfx::Rect(14, 15, 3, 5)); 688 r.Subtract(gfx::Rect(14, 15, 3, 5));
635 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 5), r)); 689 EXPECT_TRUE(ExpectRegionEq(gfx::Rect(10, 10, 10, 5), r));
636 } 690 }
637 691
638 } // namespace 692 } // namespace
639 } // namespace cc 693 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/simple_enclosed_region.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698