OLD | NEW |
---|---|
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 "config.h" | 5 #include "config.h" |
6 #include "platform/graphics/paint/DisplayItemList.h" | 6 #include "platform/graphics/paint/DisplayItemList.h" |
7 | 7 |
8 #include "platform/RuntimeEnabledFeatures.h" | 8 #include "platform/RuntimeEnabledFeatures.h" |
9 #include "platform/graphics/GraphicsContext.h" | 9 #include "platform/graphics/GraphicsContext.h" |
10 #include "platform/graphics/paint/CachedDisplayItem.h" | 10 #include "platform/graphics/paint/CachedDisplayItem.h" |
11 #include "platform/graphics/paint/ClipPathRecorder.h" | 11 #include "platform/graphics/paint/ClipPathRecorder.h" |
12 #include "platform/graphics/paint/ClipRecorder.h" | 12 #include "platform/graphics/paint/ClipRecorder.h" |
13 #include "platform/graphics/paint/DrawingDisplayItem.h" | 13 #include "platform/graphics/paint/DrawingDisplayItem.h" |
14 #include "platform/graphics/paint/DrawingRecorder.h" | 14 #include "platform/graphics/paint/DrawingRecorder.h" |
15 #include "platform/graphics/paint/SubtreeRecorder.h" | |
16 #include <gtest/gtest.h> | 15 #include <gtest/gtest.h> |
17 | 16 |
18 namespace blink { | 17 namespace blink { |
19 | 18 |
19 class SimpleSubtreeRecorder { | |
20 public: | |
21 SimpleSubtreeRecorder(DisplayItemList& displayItemList, const DisplayItemCli entWrapper& client, int paintPhase) | |
22 : m_displayItemList(displayItemList) | |
23 , m_client(client) | |
24 , m_paintPhase(paintPhase) | |
25 { | |
26 displayItemList.createAndAppend<BeginSubtreeDisplayItem>(client, Display Item::paintPhaseToBeginSubtreeType(paintPhase)); | |
27 } | |
28 ~SimpleSubtreeRecorder() | |
29 { | |
30 m_displayItemList.createAndAppend<EndSubtreeDisplayItem>(m_client, Displ ayItem::paintPhaseToEndSubtreeType(m_paintPhase)); | |
31 } | |
32 | |
33 private: | |
pdr.
2015/08/24 20:30:10
Should these be const?
Xianzhu
2015/08/24 23:03:21
Done.
| |
34 DisplayItemList& m_displayItemList; | |
35 DisplayItemClientWrapper m_client; | |
36 int m_paintPhase; | |
37 }; | |
38 | |
20 class DisplayItemListTest : public ::testing::Test { | 39 class DisplayItemListTest : public ::testing::Test { |
21 public: | 40 public: |
22 DisplayItemListTest() | 41 DisplayItemListTest() |
23 : m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint V2Enabled()) { } | 42 : m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint V2Enabled()) { } |
24 | 43 |
25 protected: | 44 protected: |
26 DisplayItemList& displayItemList() { return m_displayItemList; } | 45 DisplayItemList& displayItemList() { return m_displayItemList; } |
27 const DisplayItems& newPaintListBeforeUpdate() { return displayItemList().m_ newDisplayItems; } | 46 const DisplayItems& newPaintListBeforeUpdate() { return displayItemList().m_ newDisplayItems; } |
28 | 47 |
29 private: | 48 private: |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 { | 474 { |
456 TestDisplayItemClient container1("container1"); | 475 TestDisplayItemClient container1("container1"); |
457 TestDisplayItemClient content1("content1"); | 476 TestDisplayItemClient content1("content1"); |
458 TestDisplayItemClient container2("container2"); | 477 TestDisplayItemClient container2("container2"); |
459 TestDisplayItemClient content2("content2"); | 478 TestDisplayItemClient content2("content2"); |
460 GraphicsContext context(&displayItemList()); | 479 GraphicsContext context(&displayItemList()); |
461 const int backgroundPaintPhase = backgroundDrawingType - DisplayItem::Drawin gPaintPhaseFirst; | 480 const int backgroundPaintPhase = backgroundDrawingType - DisplayItem::Drawin gPaintPhaseFirst; |
462 const int foregroundPaintPhase = foregroundDrawingType - DisplayItem::Drawin gPaintPhaseFirst; | 481 const int foregroundPaintPhase = foregroundDrawingType - DisplayItem::Drawin gPaintPhaseFirst; |
463 | 482 |
464 { | 483 { |
465 SubtreeRecorder r(context, container1, backgroundPaintPhase); | 484 SimpleSubtreeRecorder r(context, container1, backgroundPaintPhase); |
466 EXPECT_FALSE(r.canUseCache()); | |
467 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); | 485 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); |
468 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 100, 5 0, 200)); | 486 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 100, 5 0, 200)); |
469 } | 487 } |
470 { | 488 { |
471 SubtreeRecorder r(context, container1, foregroundPaintPhase); | 489 SimpleSubtreeRecorder r(context, container1, foregroundPaintPhase); |
472 EXPECT_FALSE(r.canUseCache()); | |
473 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 5 0, 200)); | 490 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 5 0, 200)); |
474 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); | 491 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); |
475 } | 492 } |
476 { | 493 { |
477 SubtreeRecorder r(context, container2, backgroundPaintPhase); | 494 SimpleSubtreeRecorder r(context, container2, backgroundPaintPhase); |
478 EXPECT_FALSE(r.canUseCache()); | |
479 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); | 495 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); |
480 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 5 0, 200)); | 496 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 5 0, 200)); |
481 } | 497 } |
482 { | 498 { |
483 SubtreeRecorder r(context, container2, foregroundPaintPhase); | 499 SimpleSubtreeRecorder r(context, container2, foregroundPaintPhase); |
484 EXPECT_FALSE(r.canUseCache()); | |
485 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); | 500 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); |
486 drawRect(context, container2, foregroundDrawingType, FloatRect(100, 200, 100, 100)); | 501 drawRect(context, container2, foregroundDrawingType, FloatRect(100, 200, 100, 100)); |
487 } | 502 } |
488 displayItemList().commitNewDisplayItems(); | 503 displayItemList().commitNewDisplayItems(); |
489 | 504 |
490 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 16, | 505 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 16, |
491 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundPaintPhase)), | 506 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundPaintPhase)), |
492 TestDisplayItem(container1, backgroundDrawingType), | 507 TestDisplayItem(container1, backgroundDrawingType), |
493 TestDisplayItem(content1, backgroundDrawingType), | 508 TestDisplayItem(content1, backgroundDrawingType), |
494 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(back groundPaintPhase)), | 509 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(back groundPaintPhase)), |
495 | 510 |
496 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(fo regroundPaintPhase)), | 511 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(fo regroundPaintPhase)), |
497 TestDisplayItem(content1, foregroundDrawingType), | 512 TestDisplayItem(content1, foregroundDrawingType), |
498 TestDisplayItem(container1, foregroundDrawingType), | 513 TestDisplayItem(container1, foregroundDrawingType), |
499 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(fore groundPaintPhase)), | 514 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(fore groundPaintPhase)), |
500 | 515 |
501 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundPaintPhase)), | 516 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundPaintPhase)), |
502 TestDisplayItem(container2, backgroundDrawingType), | 517 TestDisplayItem(container2, backgroundDrawingType), |
503 TestDisplayItem(content2, backgroundDrawingType), | 518 TestDisplayItem(content2, backgroundDrawingType), |
504 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(back groundPaintPhase)), | 519 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(back groundPaintPhase)), |
505 | 520 |
506 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(fo regroundPaintPhase)), | 521 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(fo regroundPaintPhase)), |
507 TestDisplayItem(content2, foregroundDrawingType), | 522 TestDisplayItem(content2, foregroundDrawingType), |
508 TestDisplayItem(container2, foregroundDrawingType), | 523 TestDisplayItem(container2, foregroundDrawingType), |
509 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(fore groundPaintPhase))); | 524 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(fore groundPaintPhase))); |
510 | 525 |
511 // Simulate the situation when container1 e.g. gets a z-index that is now gr eater than container2. | 526 // Simulate the situation when container1 e.g. gets a z-index that is now gr eater than container2. |
512 displayItemList().createAndAppend<CachedDisplayItem>(container2, DisplayItem ::paintPhaseToCachedSubtreeType(backgroundPaintPhase)); | 527 EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container2, backgroundPaintPhase)); |
513 EXPECT_EQ((size_t)1, newPaintListBeforeUpdate().size()); | 528 EXPECT_EQ((size_t)1, newPaintListBeforeUpdate().size()); |
514 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); | 529 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); |
515 displayItemList().createAndAppend<CachedDisplayItem>(container2, DisplayItem ::paintPhaseToCachedSubtreeType(foregroundPaintPhase)); | 530 EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container2, foregroundPaintPhase)); |
516 EXPECT_EQ((size_t)2, newPaintListBeforeUpdate().size()); | 531 EXPECT_EQ((size_t)2, newPaintListBeforeUpdate().size()); |
517 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); | 532 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); |
518 | 533 |
519 displayItemList().createAndAppend<CachedDisplayItem>(container1, DisplayItem ::paintPhaseToCachedSubtreeType(backgroundPaintPhase)); | 534 EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container1, backgroundPaintPhase)); |
520 EXPECT_EQ((size_t)3, newPaintListBeforeUpdate().size()); | 535 EXPECT_EQ((size_t)3, newPaintListBeforeUpdate().size()); |
521 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); | 536 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); |
522 displayItemList().createAndAppend<CachedDisplayItem>(container1, DisplayItem ::paintPhaseToCachedSubtreeType(foregroundPaintPhase)); | 537 EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container1, foregroundPaintPhase)); |
523 EXPECT_EQ((size_t)4, newPaintListBeforeUpdate().size()); | 538 EXPECT_EQ((size_t)4, newPaintListBeforeUpdate().size()); |
524 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); | 539 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); |
525 displayItemList().commitNewDisplayItems(); | 540 displayItemList().commitNewDisplayItems(); |
526 | 541 |
527 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 16, | 542 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 16, |
528 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundDrawingType)), | 543 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundDrawingType)), |
529 TestDisplayItem(container2, backgroundDrawingType), | 544 TestDisplayItem(container2, backgroundDrawingType), |
530 TestDisplayItem(content2, backgroundDrawingType), | 545 TestDisplayItem(content2, backgroundDrawingType), |
531 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(back groundDrawingType)), | 546 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(back groundDrawingType)), |
532 | 547 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 drawRect(context, third, backgroundDrawingType, FloatRect(0, 0, 100, 100)); | 693 drawRect(context, third, backgroundDrawingType, FloatRect(0, 0, 100, 100)); |
679 displayItemList().commitNewDisplayItems(); | 694 displayItemList().commitNewDisplayItems(); |
680 | 695 |
681 // Empty clips should have been optimized out. | 696 // Empty clips should have been optimized out. |
682 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, | 697 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, |
683 TestDisplayItem(first, backgroundDrawingType), | 698 TestDisplayItem(first, backgroundDrawingType), |
684 TestDisplayItem(third, backgroundDrawingType)); | 699 TestDisplayItem(third, backgroundDrawingType)); |
685 } | 700 } |
686 | 701 |
687 } // namespace blink | 702 } // namespace blink |
OLD | NEW |