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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/PaintControllerTest.cpp

Issue 1497873002: Make DisplayItemClient an interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years 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
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 "config.h" 5 #include "config.h"
6 #include "platform/graphics/paint/PaintController.h" 6 #include "platform/graphics/paint/PaintController.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"
(...skipping 25 matching lines...) Expand all
36 36
37 OwnPtr<PaintController> m_paintController; 37 OwnPtr<PaintController> m_paintController;
38 bool m_originalSlimmingPaintSynchronizedPaintingEnabled; 38 bool m_originalSlimmingPaintSynchronizedPaintingEnabled;
39 bool m_originalSlimmingPaintV2Enabled; 39 bool m_originalSlimmingPaintV2Enabled;
40 }; 40 };
41 41
42 const DisplayItem::Type foregroundDrawingType = static_cast<DisplayItem::Type>(D isplayItem::DrawingPaintPhaseFirst + 4); 42 const DisplayItem::Type foregroundDrawingType = static_cast<DisplayItem::Type>(D isplayItem::DrawingPaintPhaseFirst + 4);
43 const DisplayItem::Type backgroundDrawingType = DisplayItem::DrawingPaintPhaseFi rst; 43 const DisplayItem::Type backgroundDrawingType = DisplayItem::DrawingPaintPhaseFi rst;
44 const DisplayItem::Type clipType = DisplayItem::ClipFirst; 44 const DisplayItem::Type clipType = DisplayItem::ClipFirst;
45 45
46 class TestDisplayItemClient { 46 class TestDisplayItemClient : public DisplayItemClient {
47 public: 47 public:
48 TestDisplayItemClient(const String& name) 48 TestDisplayItemClient(const String& name)
49 : m_name(name) 49 : m_name(name)
50 { } 50 { }
51 51
52 DisplayItemClient displayItemClient() const { return toDisplayItemClient(thi s); } 52 String debugName() const final { return m_name; }
53 String debugName() const { return m_name; }
54 53
55 private: 54 private:
56 String m_name; 55 String m_name;
57 }; 56 };
58 57
59 class TestDisplayItem final : public DisplayItem { 58 class TestDisplayItem final : public DisplayItem {
60 public: 59 public:
61 TestDisplayItem(const TestDisplayItemClient& client, Type type) : DisplayIte m(client, type, sizeof(*this)) { } 60 TestDisplayItem(const TestDisplayItemClient& client, Type type) : DisplayIte m(client, type, sizeof(*this)) { }
62 61
63 void replay(GraphicsContext&) const final { ASSERT_NOT_REACHED(); } 62 void replay(GraphicsContext&) const final { ASSERT_NOT_REACHED(); }
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 TestDisplayItemClient second("second"); 362 TestDisplayItemClient second("second");
364 GraphicsContext context(paintController()); 363 GraphicsContext context(paintController());
365 364
366 drawRect(context, first, backgroundDrawingType, FloatRect(100, 100, 150, 150 )); 365 drawRect(context, first, backgroundDrawingType, FloatRect(100, 100, 150, 150 ));
367 drawRect(context, second, backgroundDrawingType, FloatRect(100, 100, 150, 15 0)); 366 drawRect(context, second, backgroundDrawingType, FloatRect(100, 100, 150, 15 0));
368 paintController().commitNewDisplayItems(); 367 paintController().commitNewDisplayItems();
369 368
370 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 2, 369 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 2,
371 TestDisplayItem(first, backgroundDrawingType), 370 TestDisplayItem(first, backgroundDrawingType),
372 TestDisplayItem(second, backgroundDrawingType)); 371 TestDisplayItem(second, backgroundDrawingType));
373 EXPECT_TRUE(paintController().clientCacheIsValid(first.displayItemClient())) ; 372 EXPECT_TRUE(paintController().clientCacheIsValid(first));
374 EXPECT_TRUE(paintController().clientCacheIsValid(second.displayItemClient()) ); 373 EXPECT_TRUE(paintController().clientCacheIsValid(second));
375 const SkPicture* firstPicture = static_cast<const DrawingDisplayItem&>(paint Controller().displayItemList()[0]).picture(); 374 const SkPicture* firstPicture = static_cast<const DrawingDisplayItem&>(paint Controller().displayItemList()[0]).picture();
376 const SkPicture* secondPicture = static_cast<const DrawingDisplayItem&>(pain tController().displayItemList()[1]).picture(); 375 const SkPicture* secondPicture = static_cast<const DrawingDisplayItem&>(pain tController().displayItemList()[1]).picture();
377 376
378 paintController().invalidate(first, PaintInvalidationFull, nullptr); 377 paintController().invalidate(first, PaintInvalidationFull, nullptr);
379 EXPECT_FALSE(paintController().clientCacheIsValid(first.displayItemClient()) ); 378 EXPECT_FALSE(paintController().clientCacheIsValid(first));
380 EXPECT_TRUE(paintController().clientCacheIsValid(second.displayItemClient()) ); 379 EXPECT_TRUE(paintController().clientCacheIsValid(second));
381 380
382 drawRect(context, first, backgroundDrawingType, FloatRect(100, 100, 150, 150 )); 381 drawRect(context, first, backgroundDrawingType, FloatRect(100, 100, 150, 150 ));
383 drawRect(context, second, backgroundDrawingType, FloatRect(100, 100, 150, 15 0)); 382 drawRect(context, second, backgroundDrawingType, FloatRect(100, 100, 150, 15 0));
384 paintController().commitNewDisplayItems(); 383 paintController().commitNewDisplayItems();
385 384
386 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 2, 385 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 2,
387 TestDisplayItem(first, backgroundDrawingType), 386 TestDisplayItem(first, backgroundDrawingType),
388 TestDisplayItem(second, backgroundDrawingType)); 387 TestDisplayItem(second, backgroundDrawingType));
389 // The first display item should be updated. 388 // The first display item should be updated.
390 EXPECT_NE(firstPicture, static_cast<const DrawingDisplayItem&>(paintControll er().displayItemList()[0]).picture()); 389 EXPECT_NE(firstPicture, static_cast<const DrawingDisplayItem&>(paintControll er().displayItemList()[0]).picture());
391 // The second display item should be cached. 390 // The second display item should be cached.
392 EXPECT_EQ(secondPicture, static_cast<const DrawingDisplayItem&>(paintControl ler().displayItemList()[1]).picture()); 391 EXPECT_EQ(secondPicture, static_cast<const DrawingDisplayItem&>(paintControl ler().displayItemList()[1]).picture());
393 EXPECT_TRUE(paintController().clientCacheIsValid(first.displayItemClient())) ; 392 EXPECT_TRUE(paintController().clientCacheIsValid(first));
394 EXPECT_TRUE(paintController().clientCacheIsValid(second.displayItemClient()) ); 393 EXPECT_TRUE(paintController().clientCacheIsValid(second));
395 394
396 paintController().invalidateAll(); 395 paintController().invalidateAll();
397 EXPECT_FALSE(paintController().clientCacheIsValid(first.displayItemClient()) ); 396 EXPECT_FALSE(paintController().clientCacheIsValid(first));
398 EXPECT_FALSE(paintController().clientCacheIsValid(second.displayItemClient() )); 397 EXPECT_FALSE(paintController().clientCacheIsValid(second));
399 } 398 }
400 399
401 TEST_F(PaintControllerTest, ComplexUpdateSwapOrder) 400 TEST_F(PaintControllerTest, ComplexUpdateSwapOrder)
402 { 401 {
403 TestDisplayItemClient container1("container1"); 402 TestDisplayItemClient container1("container1");
404 TestDisplayItemClient content1("content1"); 403 TestDisplayItemClient content1("content1");
405 TestDisplayItemClient container2("container2"); 404 TestDisplayItemClient container2("container2");
406 TestDisplayItemClient content2("content2"); 405 TestDisplayItemClient content2("content2");
407 GraphicsContext context(paintController()); 406 GraphicsContext context(paintController());
408 407
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 658
660 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 3, 659 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 3,
661 TestDisplayItem(multicol, backgroundDrawingType), 660 TestDisplayItem(multicol, backgroundDrawingType),
662 TestDisplayItem(content, foregroundDrawingType), 661 TestDisplayItem(content, foregroundDrawingType),
663 TestDisplayItem(content, foregroundDrawingType)); 662 TestDisplayItem(content, foregroundDrawingType));
664 RefPtr<const SkPicture> picture1 = static_cast<const DrawingDisplayItem&>(pa intController().displayItemList()[1]).picture(); 663 RefPtr<const SkPicture> picture1 = static_cast<const DrawingDisplayItem&>(pa intController().displayItemList()[1]).picture();
665 RefPtr<const SkPicture> picture2 = static_cast<const DrawingDisplayItem&>(pa intController().displayItemList()[2]).picture(); 664 RefPtr<const SkPicture> picture2 = static_cast<const DrawingDisplayItem&>(pa intController().displayItemList()[2]).picture();
666 EXPECT_NE(picture1, picture2); 665 EXPECT_NE(picture1, picture2);
667 666
668 // Draw again with nothing invalidated. 667 // Draw again with nothing invalidated.
669 EXPECT_TRUE(paintController().clientCacheIsValid(multicol.displayItemClient( ))); 668 EXPECT_TRUE(paintController().clientCacheIsValid(multicol));
670 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 200, 100, 100)); 669 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 200, 100, 100));
671 paintController().beginScope(); 670 paintController().beginScope();
672 drawRect(context, content, foregroundDrawingType, rect1); 671 drawRect(context, content, foregroundDrawingType, rect1);
673 paintController().endScope(); 672 paintController().endScope();
674 673
675 paintController().beginScope(); 674 paintController().beginScope();
676 drawRect(context, content, foregroundDrawingType, rect2); 675 drawRect(context, content, foregroundDrawingType, rect2);
677 paintController().endScope(); 676 paintController().endScope();
678 677
679 EXPECT_DISPLAY_LIST(paintController().newDisplayItemList(), 3, 678 EXPECT_DISPLAY_LIST(paintController().newDisplayItemList(), 3,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 drawRect(context, client, backgroundDrawingType, FloatRect(0, 0, 100, 100)); 780 drawRect(context, client, backgroundDrawingType, FloatRect(0, 0, 100, 100));
782 781
783 paintController().commitNewDisplayItems(); 782 paintController().commitNewDisplayItems();
784 const auto& paintChunks = paintController().paintChunks(); 783 const auto& paintChunks = paintController().paintChunks();
785 ASSERT_EQ(1u, paintChunks.size()); 784 ASSERT_EQ(1u, paintChunks.size());
786 EXPECT_EQ(0u, paintChunks[0].beginIndex); 785 EXPECT_EQ(0u, paintChunks[0].beginIndex);
787 EXPECT_EQ(1u, paintChunks[0].endIndex); 786 EXPECT_EQ(1u, paintChunks[0].endIndex);
788 } 787 }
789 788
790 } // namespace blink 789 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698