 Chromium Code Reviews
 Chromium Code Reviews Issue 1393083003:
  Implement interest rects for synchronized paint.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1393083003:
  Implement interest rects for synchronized paint.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/layout/compositing/CompositedLayerMapping.h" | |
| 7 | |
| 8 #include "core/frame/FrameView.h" | |
| 9 #include "core/layout/LayoutBoxModelObject.h" | |
| 10 #include "core/layout/LayoutTestHelper.h" | |
| 11 #include "core/paint/PaintLayer.h" | |
| 12 #include <gtest/gtest.h> | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 class CompositedLayerMappingTest : public RenderingTest { | |
| 17 public: | |
| 18 CompositedLayerMappingTest() | |
| 19 : m_originalSlimmingPaintSynchronizedPaintingEnabled(RuntimeEnabledFeatu res::slimmingPaintSynchronizedPaintingEnabled()) { } | |
| 20 | |
| 21 protected: | |
| 22 IntRect computeInterestRect(const GraphicsLayer* graphicsLayer, LayoutObject * owningLayoutObject) | |
| 23 { | |
| 24 return CompositedLayerMapping::computeInterestRect(graphicsLayer, owning LayoutObject); | |
| 25 } | |
| 26 | |
| 27 private: | |
| 28 void SetUp() override | |
| 29 { | |
| 30 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(true ); | |
| 31 | |
| 32 RenderingTest::SetUp(); | |
| 33 enableCompositing(); | |
| 34 GraphicsLayer::setDrawDebugRedFillForTesting(false); | |
| 35 } | |
| 36 | |
| 37 void TearDown() override | |
| 38 { | |
| 39 GraphicsLayer::setDrawDebugRedFillForTesting(true); | |
| 40 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_or iginalSlimmingPaintSynchronizedPaintingEnabled); | |
| 41 } | |
| 42 | |
| 43 bool m_originalSlimmingPaintSynchronizedPaintingEnabled; | |
| 44 }; | |
| 45 | |
| 46 static void printRect(IntRect rect) | |
| 47 { | |
| 48 fprintf(stderr, "[x=%d y=%d maxX=%d maxY=%d]\n", rect.x(), rect.y(), rect.ma xX(), rect.maxY()); | |
| 49 } | |
| 50 | |
| 51 static bool checkRectsEqual(const IntRect& expected, const IntRect& actual) | |
| 52 { | |
| 53 if (expected != actual) { | |
| 54 fprintf(stderr, "Expected: "); | |
| 55 printRect(expected); | |
| 56 fprintf(stderr, "Actual: "); | |
| 57 printRect(actual); | |
| 58 return false; | |
| 59 } | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 TEST_F(CompositedLayerMappingTest, SimpleInterestRect) | |
| 64 { | |
| 65 setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will- change: transform'></div>"); | |
| 66 | |
| 67 document().view()->updateAllLifecyclePhases(); | |
| 68 Element* element = document().getElementById("target"); | |
| 69 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la yer(); | |
| 70 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); | |
| 71 EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 200), computeInterestRect(pai ntLayer->graphicsLayerBacking(), paintLayer->layoutObject()))); | |
| 72 } | |
| 73 | |
| 74 TEST_F(CompositedLayerMappingTest, TallLayerInterestRect) | |
| 75 { | |
| 76 setBodyInnerHTML("<div id='target' style='width: 200px; height: 10000px; wil l-change: transform'></div>"); | |
| 77 | |
| 78 document().view()->updateAllLifecyclePhases(); | |
| 79 Element* element = document().getElementById("target"); | |
| 80 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la yer(); | |
| 81 ASSERT_TRUE(paintLayer->graphicsLayerBacking()); | |
| 82 // Screen-space visible content rect is [8, 8, 200, 600]. Mapping back to lo cal, adding 4000px in all directions, then | |
| 83 // clipping, yields this rect. | |
| 84 EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 4592), computeInterestRect(pa intLayer->graphicsLayerBacking(), paintLayer->layoutObject()))); | |
| 85 } | |
| 86 | |
| 87 TEST_F(CompositedLayerMappingTest, RotatedInterestRect) | |
| 88 { | |
| 89 setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will- change: transform; transform: rotateZ(45deg)'></div>"); | |
| 90 | |
| 91 document().view()->updateAllLifecyclePhases(); | |
| 92 Element* element = document().getElementById("target"); | |
| 93 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la yer(); | |
| 94 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); | |
| 95 EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 200), computeInterestRect(pai ntLayer->graphicsLayerBacking(), paintLayer->layoutObject()))); | |
| 96 } | |
| 97 | |
| 98 TEST_F(CompositedLayerMappingTest, RotatedTallInterestRect) | |
| 99 { | |
| 100 setBodyInnerHTML("<div id='target' style='width: 200px; height: 10000px; wil l-change: transform; transform: rotateZ(45deg)'></div>"); | |
| 101 | |
| 102 document().view()->updateAllLifecyclePhases(); | |
| 103 Element* element = document().getElementById("target"); | |
| 104 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la yer(); | |
| 105 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); | |
| 106 EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 5536), computeInterestRect(pa intLayer->graphicsLayerBacking(), paintLayer->layoutObject()))); | |
| 107 } | |
| 108 | |
| 109 TEST_F(CompositedLayerMappingTest, WideLayerInterestRect) | |
| 110 { | |
| 111 setBodyInnerHTML("<div id='target' style='width: 10000px; height: 200px; wil l-change: transform'></div>"); | |
| 112 | |
| 113 document().view()->updateAllLifecyclePhases(); | |
| 114 Element* element = document().getElementById("target"); | |
| 115 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la yer(); | |
| 116 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); | |
| 117 // Screen-space visible content rect is [8, 8, 800, 200] (the screen is 800x 600). | |
| 118 // Mapping back to local, adding 4000px in all directions, then clipping, yi elds this rect. | |
| 119 EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 4792, 200), computeInterestRect(pa intLayer->graphicsLayerBacking(), paintLayer->layoutObject()))); | |
| 120 } | |
| 121 | |
| 122 TEST_F(CompositedLayerMappingTest, FixedPositionInterestRect) | |
| 123 { | |
| 124 setBodyInnerHTML("<div id='target' style='width: 300px; height: 400px; will- change: transform; position: fixed; top: 100px; left: 200px;'></div>"); | |
| 125 | |
| 126 document().view()->updateAllLifecyclePhases(); | |
| 127 Element* element = document().getElementById("target"); | |
| 128 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la yer(); | |
| 129 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); | |
| 130 EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 300, 400), computeInterestRect(pai ntLayer->graphicsLayerBacking(), paintLayer->layoutObject()))); | |
| 131 } | |
| 132 | |
| 133 TEST_F(CompositedLayerMappingTest, LayerOffscreenInterestRect) | |
| 134 { | |
| 135 setBodyInnerHTML( | |
| 136 "<div id='target' style='width: 200px; height: 200px; will-change: trans form; position: absolute; top: 9000px; left: 0px;'>" | |
| 137 "</div>"); | |
| 138 | |
| 139 document().view()->updateAllLifecyclePhases(); | |
| 140 Element* element = document().getElementById("target"); | |
| 141 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la yer(); | |
| 142 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); | |
| 143 // Offscreen layers are painted as usual. | |
| 144 fprintf(stderr, "\nTest:\n"); | |
| 
wkorman
2015/10/09 19:46:32
Need this and others still?
 
chrishtr
2015/10/09 20:54:52
Fixed. I think that's the only one.
 | |
| 145 EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 200), computeInterestRect(pai ntLayer->graphicsLayerBacking(), paintLayer->layoutObject()))); | |
| 146 } | |
| 147 | |
| 148 TEST_F(CompositedLayerMappingTest, ScrollingLayerInterestRect) | |
| 149 { | |
| 150 setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will- change: transform; overflow: scroll'>" | |
| 151 "<div style='width: 100px; height: 10000px'></div></div>"); | |
| 152 | |
| 153 document().view()->updateAllLifecyclePhases(); | |
| 154 Element* element = document().getElementById("target"); | |
| 155 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la yer(); | |
| 156 ASSERT_TRUE(paintLayer->graphicsLayerBacking()); | |
| 157 // Offscreen layers are painted as usual. | |
| 158 EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 200, 4592), computeInterestRect(pa intLayer->graphicsLayerBackingForScrolling(), paintLayer->layoutObject()))); | |
| 159 } | |
| 160 | |
| 161 TEST_F(CompositedLayerMappingTest, ClippedBigLayer) | |
| 162 { | |
| 163 setBodyInnerHTML("<div style='width: 1px; height: 1px; overflow: hidden'>" | |
| 164 "<div id='target' style='width: 10000px; height: 10000px; will-change: t ransform'></div></div>"); | |
| 165 | |
| 166 document().view()->updateAllLifecyclePhases(); | |
| 167 Element* element = document().getElementById("target"); | |
| 168 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la yer(); | |
| 169 ASSERT_TRUE(paintLayer->graphicsLayerBacking()); | |
| 170 // Offscreen layers are painted as usual. | |
| 171 EXPECT_TRUE(checkRectsEqual(IntRect(0, 0, 4001, 4001), computeInterestRect(p aintLayer->graphicsLayerBacking(), paintLayer->layoutObject()))); | |
| 172 } | |
| 
ajuma
2015/10/09 20:55:27
Please also add a test where the transform to/from
 
chrishtr
2015/10/09 21:35:46
Done.
 | |
| 173 | |
| 174 } // namespace blink | |
| OLD | NEW |