1 // Copyright 2012 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.
7 #include "CCQuadCuller.h"
9 #include "CCAppendQuadsData.h"
10 #include "CCLayerTilingData.h"
11 #include "CCMathUtil.h"
12 #include "CCOcclusionTracker.h"
13 #include "CCOverdrawMetrics.h"
14 #include "CCSingleThreadProxy.h"
15 #include "CCTileDrawQuad.h"
16 #include "CCTiledLayerImpl.h"
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 #include <public/WebTransformationMatrix.h>
22 using WebKit::WebTransformationMatrix
;
26 class TestCCOcclusionTrackerImpl
: public CCOcclusionTrackerImpl
{
28 TestCCOcclusionTrackerImpl(const IntRect
& scissorRectInScreen
, bool recordMetricsForFrame
= true)
29 : CCOcclusionTrackerImpl(scissorRectInScreen
, recordMetricsForFrame
)
30 , m_scissorRectInScreen(scissorRectInScreen
)
35 virtual IntRect
layerScissorRectInTargetSurface(const CCLayerImpl
* layer
) const { return m_scissorRectInScreen
; }
38 IntRect m_scissorRectInScreen
;
41 typedef CCLayerIterator
<CCLayerImpl
, Vector
<CCLayerImpl
*>, CCRenderSurface
, CCLayerIteratorActions::FrontToBack
> CCLayerIteratorType
;
43 static PassOwnPtr
<CCTiledLayerImpl
> makeLayer(CCTiledLayerImpl
* parent
, const WebTransformationMatrix
& drawTransform
, const IntRect
& layerRect
, float opacity
, bool opaque
, const IntRect
& layerOpaqueRect
, Vector
<CCLayerImpl
*>& surfaceLayerList
)
45 OwnPtr
<CCTiledLayerImpl
> layer
= CCTiledLayerImpl::create(1);
46 OwnPtr
<CCLayerTilingData
> tiler
= CCLayerTilingData::create(IntSize(100, 100), CCLayerTilingData::NoBorderTexels
);
47 tiler
->setBounds(layerRect
.size());
48 layer
->setTilingData(*tiler
);
49 layer
->setSkipsDraw(false);
50 layer
->setDrawTransform(drawTransform
);
51 layer
->setScreenSpaceTransform(drawTransform
);
52 layer
->setVisibleContentRect(layerRect
);
53 layer
->setDrawOpacity(opacity
);
54 layer
->setOpaque(opaque
);
55 layer
->setBounds(layerRect
.size());
56 layer
->setContentBounds(layerRect
.size());
58 CCResourceProvider::ResourceId resourceId
= 1;
59 for (int i
= 0; i
< tiler
->numTilesX(); ++i
)
60 for (int j
= 0; j
< tiler
->numTilesY(); ++j
) {
61 IntRect tileOpaqueRect
= opaque
? tiler
->tileBounds(i
, j
) : intersection(tiler
->tileBounds(i
, j
), layerOpaqueRect
);
62 layer
->pushTileProperties(i
, j
, resourceId
++, tileOpaqueRect
);
65 IntRect rectInTarget
= CCMathUtil::mapClippedRect(layer
->drawTransform(), layer
->visibleContentRect());
67 layer
->createRenderSurface();
68 surfaceLayerList
.append(layer
.get());
69 layer
->renderSurface()->layerList().append(layer
.get());
71 layer
->setRenderTarget(parent
->renderTarget());
72 parent
->renderSurface()->layerList().append(layer
.get());
73 rectInTarget
.unite(CCMathUtil::mapClippedRect(parent
->drawTransform(), parent
->visibleContentRect()));
75 layer
->setDrawableContentRect(rectInTarget
);
77 return layer
.release();
80 static void appendQuads(CCQuadList
& quadList
, CCSharedQuadStateList
& sharedStateList
, CCTiledLayerImpl
* layer
, CCLayerIteratorType
& it
, CCOcclusionTrackerImpl
& occlusionTracker
)
82 occlusionTracker
.enterLayer(it
);
83 CCQuadCuller
quadCuller(quadList
, sharedStateList
, layer
, &occlusionTracker
, false, false);
84 CCAppendQuadsData data
;
85 layer
->appendQuads(quadCuller
, data
);
86 occlusionTracker
.leaveLayer(it
);
90 #define DECLARE_AND_INITIALIZE_TEST_QUADS \
91 DebugScopedSetImplThread impl; \
92 CCQuadList quadList; \
93 CCSharedQuadStateList sharedStateList; \
94 Vector<CCLayerImpl*> renderSurfaceLayerList; \
95 WebTransformationMatrix childTransform; \
96 IntSize rootSize = IntSize(300, 300); \
97 IntRect rootRect = IntRect(IntPoint(), rootSize); \
98 IntSize childSize = IntSize(200, 200); \
99 IntRect childRect = IntRect(IntPoint(), childSize);
101 TEST(CCQuadCullerTest
, verifyNoCulling
)
103 DECLARE_AND_INITIALIZE_TEST_QUADS
105 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
106 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), WebTransformationMatrix(), childRect
, 1, false, IntRect(), renderSurfaceLayerList
);
107 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
108 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
110 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
111 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
112 EXPECT_EQ(quadList
.size(), 13u);
113 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
114 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 40000, 1);
115 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 0, 1);
118 TEST(CCQuadCullerTest
, verifyCullChildLinesUpTopLeft
)
120 DECLARE_AND_INITIALIZE_TEST_QUADS
122 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
123 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), WebTransformationMatrix(), childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
124 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
125 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
127 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
128 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
129 EXPECT_EQ(quadList
.size(), 9u);
130 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
131 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
132 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 40000, 1);
135 TEST(CCQuadCullerTest
, verifyCullWhenChildOpacityNotOne
)
137 DECLARE_AND_INITIALIZE_TEST_QUADS
139 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
140 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 0.9f
, true, IntRect(), renderSurfaceLayerList
);
141 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
142 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
144 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
145 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
146 EXPECT_EQ(quadList
.size(), 13u);
147 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
148 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 40000, 1);
149 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 0, 1);
152 TEST(CCQuadCullerTest
, verifyCullWhenChildOpaqueFlagFalse
)
154 DECLARE_AND_INITIALIZE_TEST_QUADS
156 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
157 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 1, false, IntRect(), renderSurfaceLayerList
);
158 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
159 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
161 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
162 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
163 EXPECT_EQ(quadList
.size(), 13u);
164 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
165 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 40000, 1);
166 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 0, 1);
169 TEST(CCQuadCullerTest
, verifyCullCenterTileOnly
)
171 DECLARE_AND_INITIALIZE_TEST_QUADS
173 childTransform
.translate(50, 50);
175 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
176 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
177 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
178 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
180 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
181 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
182 ASSERT_EQ(quadList
.size(), 12u);
184 IntRect quadVisibleRect1
= quadList
[5].get()->quadVisibleRect();
185 EXPECT_EQ(quadVisibleRect1
.height(), 50);
187 IntRect quadVisibleRect3
= quadList
[7].get()->quadVisibleRect();
188 EXPECT_EQ(quadVisibleRect3
.width(), 50);
190 // Next index is 8, not 9, since centre quad culled.
191 IntRect quadVisibleRect4
= quadList
[8].get()->quadVisibleRect();
192 EXPECT_EQ(quadVisibleRect4
.width(), 50);
193 EXPECT_EQ(quadVisibleRect4
.x(), 250);
195 IntRect quadVisibleRect6
= quadList
[10].get()->quadVisibleRect();
196 EXPECT_EQ(quadVisibleRect6
.height(), 50);
197 EXPECT_EQ(quadVisibleRect6
.y(), 250);
199 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 100000, 1);
200 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
201 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 30000, 1);
204 TEST(CCQuadCullerTest
, verifyCullCenterTileNonIntegralSize1
)
206 DECLARE_AND_INITIALIZE_TEST_QUADS
208 childTransform
.translate(100, 100);
210 // Make the root layer's quad have extent (99.1, 99.1) -> (200.9, 200.9) to make
211 // sure it doesn't get culled due to transform rounding.
212 WebTransformationMatrix rootTransform
;
213 rootTransform
.translate(99.1, 99.1);
214 rootTransform
.scale(1.018);
216 rootRect
= childRect
= IntRect(0, 0, 100, 100);
218 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, rootTransform
, rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
219 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
220 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
221 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
223 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
224 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
225 EXPECT_EQ(quadList
.size(), 2u);
227 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 20363, 1);
228 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
229 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 0, 1);
232 TEST(CCQuadCullerTest
, verifyCullCenterTileNonIntegralSize2
)
234 DECLARE_AND_INITIALIZE_TEST_QUADS
236 // Make the child's quad slightly smaller than, and centred over, the root layer tile.
237 // Verify the child does not cause the quad below to be culled due to rounding.
238 childTransform
.translate(100.1, 100.1);
239 childTransform
.scale(0.982);
241 WebTransformationMatrix rootTransform
;
242 rootTransform
.translate(100, 100);
244 rootRect
= childRect
= IntRect(0, 0, 100, 100);
246 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, rootTransform
, rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
247 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
248 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
249 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
251 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
252 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
253 EXPECT_EQ(quadList
.size(), 2u);
255 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 19643, 1);
256 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
257 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 0, 1);
260 TEST(CCQuadCullerTest
, verifyCullChildLinesUpBottomRight
)
262 DECLARE_AND_INITIALIZE_TEST_QUADS
264 childTransform
.translate(100, 100);
266 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
267 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
268 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
269 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
271 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
272 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
273 EXPECT_EQ(quadList
.size(), 9u);
274 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
275 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
276 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 40000, 1);
279 TEST(CCQuadCullerTest
, verifyCullSubRegion
)
281 DECLARE_AND_INITIALIZE_TEST_QUADS
283 childTransform
.translate(50, 50);
285 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
286 IntRect
childOpaqueRect(childRect
.x() + childRect
.width() / 4, childRect
.y() + childRect
.height() / 4, childRect
.width() / 2, childRect
.height() / 2);
287 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 1, false, childOpaqueRect
, renderSurfaceLayerList
);
288 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
289 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
291 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
292 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
293 EXPECT_EQ(quadList
.size(), 12u);
294 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
295 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 30000, 1);
296 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 10000, 1);
299 TEST(CCQuadCullerTest
, verifyCullSubRegion2
)
301 DECLARE_AND_INITIALIZE_TEST_QUADS
303 childTransform
.translate(50, 10);
305 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
306 IntRect
childOpaqueRect(childRect
.x() + childRect
.width() / 4, childRect
.y() + childRect
.height() / 4, childRect
.width() / 2, childRect
.height() * 3 / 4);
307 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 1, false, childOpaqueRect
, renderSurfaceLayerList
);
308 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
309 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
311 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
312 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
313 EXPECT_EQ(quadList
.size(), 12u);
314 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
315 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 25000, 1);
316 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 15000, 1);
319 TEST(CCQuadCullerTest
, verifyCullSubRegionCheckOvercull
)
321 DECLARE_AND_INITIALIZE_TEST_QUADS
323 childTransform
.translate(50, 49);
325 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
326 IntRect
childOpaqueRect(childRect
.x() + childRect
.width() / 4, childRect
.y() + childRect
.height() / 4, childRect
.width() / 2, childRect
.height() / 2);
327 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 1, false, childOpaqueRect
, renderSurfaceLayerList
);
328 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
329 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
331 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
332 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
333 EXPECT_EQ(quadList
.size(), 13u);
334 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
335 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 30000, 1);
336 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 10000, 1);
339 TEST(CCQuadCullerTest
, verifyNonAxisAlignedQuadsDontOcclude
)
341 DECLARE_AND_INITIALIZE_TEST_QUADS
343 // Use a small rotation so as to not disturb the geometry significantly.
344 childTransform
.rotate(1);
346 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
347 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), childTransform
, childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
348 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
349 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
351 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
352 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
353 EXPECT_EQ(quadList
.size(), 13u);
354 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 130000, 1);
355 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
356 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 0, 1);
359 // This test requires some explanation: here we are rotating the quads to be culled.
360 // The 2x2 tile child layer remains in the top-left corner, unrotated, but the 3x3
361 // tile parent layer is rotated by 1 degree. Of the four tiles the child would
362 // normally occlude, three will move (slightly) out from under the child layer, and
363 // one moves further under the child. Only this last tile should be culled.
364 TEST(CCQuadCullerTest
, verifyNonAxisAlignedQuadsSafelyCulled
)
366 DECLARE_AND_INITIALIZE_TEST_QUADS
368 // Use a small rotation so as to not disturb the geometry significantly.
369 WebTransformationMatrix parentTransform
;
370 parentTransform
.rotate(1);
372 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, parentTransform
, rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
373 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), WebTransformationMatrix(), childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
374 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(-100, -100, 1000, 1000));
375 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
377 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
378 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
379 EXPECT_EQ(quadList
.size(), 12u);
380 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 100600, 1);
381 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
382 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 29400, 1);
385 TEST(CCQuadCullerTest
, verifyCullOutsideScissorOverTile
)
387 DECLARE_AND_INITIALIZE_TEST_QUADS
389 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
390 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), WebTransformationMatrix(), childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
391 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(200, 100, 100, 100));
392 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
394 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
395 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
396 EXPECT_EQ(quadList
.size(), 1u);
397 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 10000, 1);
398 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
399 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 120000, 1);
402 TEST(CCQuadCullerTest
, verifyCullOutsideScissorOverCulledTile
)
404 DECLARE_AND_INITIALIZE_TEST_QUADS
406 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
407 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), WebTransformationMatrix(), childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
408 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(100, 100, 100, 100));
409 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
411 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
412 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
413 EXPECT_EQ(quadList
.size(), 1u);
414 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 10000, 1);
415 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
416 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 120000, 1);
419 TEST(CCQuadCullerTest
, verifyCullOutsideScissorOverPartialTiles
)
421 DECLARE_AND_INITIALIZE_TEST_QUADS
423 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
424 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), WebTransformationMatrix(), childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
425 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(50, 50, 200, 200));
426 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
428 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
429 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
430 EXPECT_EQ(quadList
.size(), 9u);
431 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 40000, 1);
432 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
433 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 90000, 1);
436 TEST(CCQuadCullerTest
, verifyCullOutsideScissorOverNoTiles
)
438 DECLARE_AND_INITIALIZE_TEST_QUADS
440 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
441 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), WebTransformationMatrix(), childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
442 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(500, 500, 100, 100));
443 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
445 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
446 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
447 EXPECT_EQ(quadList
.size(), 0u);
448 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 0, 1);
449 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
450 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 130000, 1);
453 TEST(CCQuadCullerTest
, verifyWithoutMetrics
)
455 DECLARE_AND_INITIALIZE_TEST_QUADS
457 OwnPtr
<CCTiledLayerImpl
> rootLayer
= makeLayer(0, WebTransformationMatrix(), rootRect
, 1, true, IntRect(), renderSurfaceLayerList
);
458 OwnPtr
<CCTiledLayerImpl
> childLayer
= makeLayer(rootLayer
.get(), WebTransformationMatrix(), childRect
, 1, true, IntRect(), renderSurfaceLayerList
);
459 TestCCOcclusionTrackerImpl
occlusionTracker(IntRect(50, 50, 200, 200), false);
460 CCLayerIteratorType it
= CCLayerIteratorType::begin(&renderSurfaceLayerList
);
462 appendQuads(quadList
, sharedStateList
, childLayer
.get(), it
, occlusionTracker
);
463 appendQuads(quadList
, sharedStateList
, rootLayer
.get(), it
, occlusionTracker
);
464 EXPECT_EQ(quadList
.size(), 9u);
465 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnOpaque(), 0, 1);
466 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
467 EXPECT_NEAR(occlusionTracker
.overdrawMetrics().pixelsCulledForDrawing(), 0, 1);