| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef PaintControllerPaintTest_h | 5 #ifndef PaintControllerPaintTest_h |
| 6 #define PaintControllerPaintTest_h | 6 #define PaintControllerPaintTest_h |
| 7 | 7 |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/layout/LayoutView.h" | 10 #include "core/layout/LayoutView.h" |
| 11 #include "core/paint/PaintLayer.h" | 11 #include "core/paint/PaintLayer.h" |
| 12 #include "platform/graphics/GraphicsContext.h" |
| 12 #include "platform/graphics/GraphicsLayer.h" | 13 #include "platform/graphics/GraphicsLayer.h" |
| 13 #include <gtest/gtest.h> | 14 #include <gtest/gtest.h> |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 class PaintControllerPaintTest : public RenderingTest { | 18 class PaintControllerPaintTestBase : public RenderingTest { |
| 18 public: | 19 public: |
| 19 PaintControllerPaintTest() | 20 PaintControllerPaintTestBase(bool enableSlimmingPaintV2) |
| 20 : m_originalSlimmingPaintSynchronizedPaintingEnabled(RuntimeEnabledFeatu
res::slimmingPaintSynchronizedPaintingEnabled()) | 21 : m_originalSlimmingPaintSynchronizedPaintingEnabled(RuntimeEnabledFeatu
res::slimmingPaintSynchronizedPaintingEnabled()) |
| 21 , m_originalSlimmingPaintOffsetCachingEnabled(RuntimeEnabledFeatures::sl
immingPaintOffsetCachingEnabled()) | 22 , m_originalSlimmingPaintOffsetCachingEnabled(RuntimeEnabledFeatures::sl
immingPaintOffsetCachingEnabled()) |
| 22 { } | 23 , m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint
V2Enabled()) |
| 24 , m_enableSlimmingPaintV2(enableSlimmingPaintV2) |
| 25 { } |
| 23 | 26 |
| 24 protected: | 27 protected: |
| 25 LayoutView& layoutView() { return *document().layoutView(); } | 28 LayoutView& layoutView() { return *document().layoutView(); } |
| 26 PaintController& rootPaintController() { return *layoutView().layer()->graph
icsLayerBacking()->paintController(); } | 29 PaintController& rootPaintController() { return *layoutView().layer()->graph
icsLayerBacking()->paintController(); } |
| 27 | 30 |
| 28 private: | |
| 29 void SetUp() override | 31 void SetUp() override |
| 30 { | 32 { |
| 31 RenderingTest::SetUp(); | 33 RenderingTest::SetUp(); |
| 32 enableCompositing(); | 34 enableCompositing(); |
| 33 GraphicsLayer::setDrawDebugRedFillForTesting(false); | 35 GraphicsLayer::setDrawDebugRedFillForTesting(false); |
| 36 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_enableSlimmingPaintV
2); |
| 34 } | 37 } |
| 35 void TearDown() override | 38 void TearDown() override |
| 36 { | 39 { |
| 37 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_or
iginalSlimmingPaintSynchronizedPaintingEnabled); | 40 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_or
iginalSlimmingPaintSynchronizedPaintingEnabled); |
| 38 RuntimeEnabledFeatures::setSlimmingPaintOffsetCachingEnabled(m_originalS
limmingPaintOffsetCachingEnabled); | 41 RuntimeEnabledFeatures::setSlimmingPaintOffsetCachingEnabled(m_originalS
limmingPaintOffsetCachingEnabled); |
| 42 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_originalSlimmingPain
tV2Enabled); |
| 39 GraphicsLayer::setDrawDebugRedFillForTesting(true); | 43 GraphicsLayer::setDrawDebugRedFillForTesting(true); |
| 40 } | 44 } |
| 41 | 45 |
| 46 // Expose some document lifecycle steps for checking new display items befor
e commiting. |
| 47 void updateLifecyclePhasesBeforePaint() |
| 48 { |
| 49 // This doesn't do all steps that FrameView does, but is enough for curr
ent tests. |
| 50 FrameView* frameView = document().view(); |
| 51 frameView->updateLifecyclePhasesInternal(FrameView::OnlyUpToCompositingC
leanPlusScrolling); |
| 52 frameView->invalidateTreeIfNeededRecursive(); |
| 53 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 54 document().view()->updatePaintProperties(); |
| 55 } |
| 56 |
| 57 void updateLifecyclePhasesToPaintClean() |
| 58 { |
| 59 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); |
| 60 updateLifecyclePhasesBeforePaint(); |
| 61 document().view()->synchronizedPaint(); |
| 62 } |
| 63 |
| 64 void paint(const IntRect* interestRect = nullptr) |
| 65 { |
| 66 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); |
| 67 // For v1, only root graphics layer is supported. |
| 68 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && !interestRect) { |
| 69 document().view()->synchronizedPaint(); |
| 70 } else { |
| 71 document().view()->lifecycle().advanceTo(DocumentLifecycle::InPaint)
; |
| 72 GraphicsContext context(rootPaintController()); |
| 73 layoutView().layer()->graphicsLayerBacking()->paint(context, interes
tRect); |
| 74 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 75 document().view()->lifecycle().advanceTo(DocumentLifecycle::Pain
tClean); |
| 76 } |
| 77 } |
| 78 |
| 79 // TODO(who removes pre-v2 code): rename to composite(). |
| 80 void commit() |
| 81 { |
| 82 // For v1, only root graphics layer is supported. |
| 83 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { |
| 84 document().view()->compositeForSlimmingPaintV2(); |
| 85 } else { |
| 86 rootPaintController().commitNewDisplayItems(); |
| 87 document().view()->lifecycle().advanceTo(DocumentLifecycle::PaintCle
an); |
| 88 } |
| 89 } |
| 90 |
| 91 private: |
| 42 bool m_originalSlimmingPaintSynchronizedPaintingEnabled; | 92 bool m_originalSlimmingPaintSynchronizedPaintingEnabled; |
| 43 bool m_originalSlimmingPaintOffsetCachingEnabled; | 93 bool m_originalSlimmingPaintOffsetCachingEnabled; |
| 94 bool m_originalSlimmingPaintV2Enabled; |
| 95 bool m_enableSlimmingPaintV2; |
| 44 }; | 96 }; |
| 45 | 97 |
| 46 // Slimming paint v2 has subtly different behavior on some paint tests. This | 98 class PaintControllerPaintTest : public PaintControllerPaintTestBase { |
| 47 // class is used to test only v2 behavior while maintaining v1 test coverage. | |
| 48 class PaintControllerPaintTestForSlimmingPaintV2 : public RenderingTest { | |
| 49 public: | 99 public: |
| 50 PaintControllerPaintTestForSlimmingPaintV2() | 100 PaintControllerPaintTest() : PaintControllerPaintTestBase(false) { } |
| 51 : m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint
V2Enabled()) { } | 101 }; |
| 52 | 102 |
| 53 protected: | 103 class PaintControllerPaintTestForSlimmingPaintV2 : public PaintControllerPaintTe
stBase { |
| 54 LayoutView& layoutView() { return *document().layoutView(); } | 104 public: |
| 55 PaintController& rootPaintController() { return *layoutView().layer()->graph
icsLayerBacking()->paintController(); } | 105 PaintControllerPaintTestForSlimmingPaintV2() : PaintControllerPaintTestBase(
true) { } |
| 106 }; |
| 56 | 107 |
| 57 // Expose some document lifecycle steps for checking new display items befor
e commiting. | 108 class PaintControllerPaintTestForSlimmingPaintV1AndV2 |
| 58 void updateLifecyclePhasesToPaintClean(const LayoutRect* interestRect = null
ptr) | 109 : public PaintControllerPaintTestBase |
| 59 { | 110 , public testing::WithParamInterface<bool> { |
| 60 document().view()->updateLifecyclePhasesInternal(FrameView::OnlyUpToComp
ositingCleanPlusScrolling, nullptr); | 111 public: |
| 61 document().view()->invalidateTreeIfNeededRecursive(); | 112 PaintControllerPaintTestForSlimmingPaintV1AndV2() : PaintControllerPaintTest
Base(GetParam()) { } |
| 62 document().view()->updatePaintProperties(); | |
| 63 document().view()->synchronizedPaint(interestRect); | |
| 64 } | |
| 65 void compositeForSlimmingPaintV2() { document().view()->compositeForSlimming
PaintV2(); } | |
| 66 | |
| 67 private: | |
| 68 void SetUp() override | |
| 69 { | |
| 70 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | |
| 71 | |
| 72 RenderingTest::SetUp(); | |
| 73 enableCompositing(); | |
| 74 GraphicsLayer::setDrawDebugRedFillForTesting(false); | |
| 75 } | |
| 76 | |
| 77 void TearDown() override | |
| 78 { | |
| 79 GraphicsLayer::setDrawDebugRedFillForTesting(true); | |
| 80 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_originalSlimmingPain
tV2Enabled); | |
| 81 } | |
| 82 | |
| 83 bool m_originalSlimmingPaintV2Enabled; | |
| 84 }; | 113 }; |
| 85 | 114 |
| 86 class TestDisplayItem final : public DisplayItem { | 115 class TestDisplayItem final : public DisplayItem { |
| 87 public: | 116 public: |
| 88 TestDisplayItem(const DisplayItemClientWrapper& client, Type type) : Display
Item(client, type, sizeof(*this)) { } | 117 TestDisplayItem(const DisplayItemClientWrapper& client, Type type) : Display
Item(client, type, sizeof(*this)) { } |
| 89 | 118 |
| 90 void replay(GraphicsContext&) const final { ASSERT_NOT_REACHED(); } | 119 void replay(GraphicsContext&) const final { ASSERT_NOT_REACHED(); } |
| 91 void appendToWebDisplayItemList(WebDisplayItemList*) const final { ASSERT_NO
T_REACHED(); } | 120 void appendToWebDisplayItemList(WebDisplayItemList*) const final { ASSERT_NO
T_REACHED(); } |
| 92 }; | 121 }; |
| 93 | 122 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 117 const DisplayItem::Type cachedBackgroundType = DisplayItem::drawingTypeToCachedD
rawingType(backgroundType); | 146 const DisplayItem::Type cachedBackgroundType = DisplayItem::drawingTypeToCachedD
rawingType(backgroundType); |
| 118 const DisplayItem::Type foregroundType = DisplayItem::paintPhaseToDrawingType(Pa
intPhaseForeground); | 147 const DisplayItem::Type foregroundType = DisplayItem::paintPhaseToDrawingType(Pa
intPhaseForeground); |
| 119 const DisplayItem::Type cachedForegroundType = DisplayItem::drawingTypeToCachedD
rawingType(foregroundType); | 148 const DisplayItem::Type cachedForegroundType = DisplayItem::drawingTypeToCachedD
rawingType(foregroundType); |
| 120 const DisplayItem::Type subsequenceType = DisplayItem::SubsequenceNormalFlowAndP
ositiveZOrder; | 149 const DisplayItem::Type subsequenceType = DisplayItem::SubsequenceNormalFlowAndP
ositiveZOrder; |
| 121 const DisplayItem::Type endSubsequenceType = DisplayItem::subsequenceTypeToEndSu
bsequenceType(subsequenceType); | 150 const DisplayItem::Type endSubsequenceType = DisplayItem::subsequenceTypeToEndSu
bsequenceType(subsequenceType); |
| 122 const DisplayItem::Type cachedSubsequenceType = DisplayItem::subsequenceTypeToCa
chedSubsequenceType(subsequenceType); | 151 const DisplayItem::Type cachedSubsequenceType = DisplayItem::subsequenceTypeToCa
chedSubsequenceType(subsequenceType); |
| 123 | 152 |
| 124 } // namespace blink | 153 } // namespace blink |
| 125 | 154 |
| 126 #endif // PaintControllerPaintTest_h | 155 #endif // PaintControllerPaintTest_h |
| OLD | NEW |