[Chromium] REGRESSION(r110596) CCQuadCullerTest.verifyCullChildLinesUpTopLeft fails...
[WebKit-https.git] / Source / WebKit / chromium / tests / CCQuadCullerTest.cpp
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1.  Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  * 2.  Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #include "config.h"
26
27 #include "cc/CCQuadCuller.h"
28
29 #include "cc/CCOcclusionTracker.h"
30 #include "cc/CCSingleThreadProxy.h"
31 #include "cc/CCTiledLayerImpl.h"
32 #include "cc/CCTileDrawQuad.h"
33 #include <gmock/gmock.h>
34 #include <gtest/gtest.h>
35
36 using namespace WebCore;
37
38 namespace {
39
40 class TestCCOcclusionTrackerImpl : public CCOcclusionTrackerImpl {
41 public:
42     TestCCOcclusionTrackerImpl(const IntRect& scissorRectInScreen)
43         : CCOcclusionTrackerImpl(scissorRectInScreen)
44         , m_scissorRectInScreen(scissorRectInScreen)
45     {
46         // Pretend we have visited a render surface.
47         m_stack.append(StackObject());
48     }
49
50 protected:
51     virtual IntRect layerScissorRectInTargetSurface(const CCLayerImpl* layer) const { return m_scissorRectInScreen; }
52
53 private:
54     IntRect m_scissorRectInScreen;
55 };
56
57 static PassOwnPtr<CCTiledLayerImpl> makeLayer(const TransformationMatrix& drawTransform, const IntRect& layerRect, float opacity, bool opaque, const IntRect& layerOpaqueRect)
58 {
59     OwnPtr<CCTiledLayerImpl> layer = CCTiledLayerImpl::create(0);
60     OwnPtr<CCLayerTilingData> tiler = CCLayerTilingData::create(IntSize(100, 100), CCLayerTilingData::NoBorderTexels);
61     tiler->setBounds(layerRect.size());
62     layer->setTilingData(*tiler);
63     layer->setSkipsDraw(false);
64     layer->setDrawTransform(drawTransform);
65     layer->setScreenSpaceTransform(drawTransform);
66     layer->setVisibleLayerRect(layerRect);
67     layer->setDrawOpacity(opacity);
68     layer->setOpaque(opaque);
69
70     int textureId = 1;
71     for (int i = 0; i < tiler->numTilesX(); ++i)
72         for (int j = 0; j < tiler->numTilesY(); ++j) {
73             IntRect tileOpaqueRect = opaque ? tiler->tileBounds(i, j) : intersection(tiler->tileBounds(i, j), layerOpaqueRect);
74             layer->pushTileProperties(i, j, static_cast<Platform3DObject>(textureId++), tileOpaqueRect);
75         }
76
77     return layer.release();
78 }
79
80 static void appendQuads(CCQuadList& quadList, CCTiledLayerImpl* layer, CCOcclusionTrackerImpl& occlusionTracker, CCOverdrawCounts& overdraw)
81 {
82     CCQuadCuller quadCuller(quadList, layer, &occlusionTracker, &overdraw);
83     OwnPtr<CCSharedQuadState> sharedQuadState = layer->createSharedQuadState();
84     layer->appendQuads(quadCuller, sharedQuadState.get());
85 }
86
87 #define DECLARE_AND_INITIALIZE_TEST_QUADS               \
88     DebugScopedSetImplThread impl;                      \
89     CCQuadList quadList;                                \
90     CCOverdrawCounts overdraw;                          \
91     TransformationMatrix childTransform;                \
92     IntSize rootSize = IntSize(300, 300);               \
93     IntRect rootRect = IntRect(IntPoint(), rootSize);   \
94     IntSize childSize = IntSize(200, 200);              \
95     IntRect childRect = IntRect(IntPoint(), childSize);
96
97 TEST(CCQuadCullerTest, verifyNoCulling)
98 {
99     DECLARE_AND_INITIALIZE_TEST_QUADS
100
101     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
102     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
103     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
104
105     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
106     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
107     EXPECT_EQ(quadList.size(), 13u);
108     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 130000, 1);
109     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
110     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
111 }
112
113 TEST(CCQuadCullerTest, verifyCullChildLinesUpTopLeft)
114 {
115     DECLARE_AND_INITIALIZE_TEST_QUADS
116
117     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
118     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
119     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
120
121     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
122     occlusionTracker.markOccludedBehindLayer(childLayer.get());
123     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
124     EXPECT_EQ(quadList.size(), 9u);
125     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
126     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
127     EXPECT_NEAR(overdraw.m_pixelsCulled, 40000, 1);
128 }
129
130 TEST(CCQuadCullerTest, verifyCullWhenChildOpacityNotOne)
131 {
132     DECLARE_AND_INITIALIZE_TEST_QUADS
133
134     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
135     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 0.9, true, IntRect());
136     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
137
138     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
139     occlusionTracker.markOccludedBehindLayer(childLayer.get());
140     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
141     EXPECT_EQ(quadList.size(), 13u);
142     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
143     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 40000, 1);
144     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
145 }
146
147 TEST(CCQuadCullerTest, verifyCullWhenChildOpaqueFlagFalse)
148 {
149     DECLARE_AND_INITIALIZE_TEST_QUADS
150
151     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
152     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, IntRect());
153     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
154
155     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
156     occlusionTracker.markOccludedBehindLayer(childLayer.get());
157     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
158     EXPECT_EQ(quadList.size(), 13u);
159     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
160     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 40000, 1);
161     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
162 }
163
164 TEST(CCQuadCullerTest, verifyCullCenterTileOnly)
165 {
166     DECLARE_AND_INITIALIZE_TEST_QUADS
167
168     childTransform.translate(50, 50);
169
170     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
171     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
172     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
173
174     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
175     occlusionTracker.markOccludedBehindLayer(childLayer.get());
176     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
177     EXPECT_EQ(quadList.size(), 12u);
178
179     IntRect quadVisibleRect1 = quadList[5].get()->quadVisibleRect();
180     EXPECT_EQ(quadVisibleRect1.height(), 50);
181
182     IntRect quadVisibleRect3 = quadList[7].get()->quadVisibleRect();
183     EXPECT_EQ(quadVisibleRect3.width(), 50);
184
185     // Next index is 8, not 9, since centre quad culled.
186     IntRect quadVisibleRect4 = quadList[8].get()->quadVisibleRect();
187     EXPECT_EQ(quadVisibleRect4.width(), 50);
188     EXPECT_EQ(quadVisibleRect4.x(), 250);
189
190     IntRect quadVisibleRect6 = quadList[10].get()->quadVisibleRect();
191     EXPECT_EQ(quadVisibleRect6.height(), 50);
192     EXPECT_EQ(quadVisibleRect6.y(), 250);
193
194     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 100000, 1);
195     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
196     EXPECT_NEAR(overdraw.m_pixelsCulled, 30000, 1);
197 }
198
199 TEST(CCQuadCullerTest, verifyCullCenterTileNonIntegralSize1)
200 {
201     DECLARE_AND_INITIALIZE_TEST_QUADS
202
203     childTransform.translate(100, 100);
204
205     // Make the root layer's quad have extent (99.1, 99.1) -> (200.9, 200.9) to make
206     // sure it doesn't get culled due to transform rounding.
207     TransformationMatrix rootTransform;
208     rootTransform.translate(99.1, 99.1);
209     rootTransform.scale(1.018);
210
211     rootRect = childRect = IntRect(0, 0, 100, 100);
212
213     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(rootTransform, rootRect, 1.0, true, IntRect());
214     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
215     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
216
217     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
218     occlusionTracker.markOccludedBehindLayer(childLayer.get());
219     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
220     EXPECT_EQ(quadList.size(), 2u);
221
222     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 20363, 1);
223     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
224     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
225 }
226
227 TEST(CCQuadCullerTest, verifyCullCenterTileNonIntegralSize2)
228 {
229     DECLARE_AND_INITIALIZE_TEST_QUADS
230
231     // Make the child's quad slightly smaller than, and centred over, the root layer tile.
232     // Verify the child does not cause the quad below to be culled due to rounding.
233     childTransform.translate(100.1, 100.1);
234     childTransform.scale(0.982);
235
236     TransformationMatrix rootTransform;
237     rootTransform.translate(100, 100);
238
239     rootRect = childRect = IntRect(0, 0, 100, 100);
240
241     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(rootTransform, rootRect, 1.0, true, IntRect());
242     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
243     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
244
245     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
246     occlusionTracker.markOccludedBehindLayer(childLayer.get());
247     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
248     EXPECT_EQ(quadList.size(), 2u);
249
250     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 19643, 1);
251     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
252     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
253 }
254
255 TEST(CCQuadCullerTest, verifyCullChildLinesUpBottomRight)
256 {
257     DECLARE_AND_INITIALIZE_TEST_QUADS
258
259     childTransform.translate(100, 100);
260
261     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
262     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
263     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
264
265     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
266     occlusionTracker.markOccludedBehindLayer(childLayer.get());
267     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
268     EXPECT_EQ(quadList.size(), 9u);
269     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
270     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
271     EXPECT_NEAR(overdraw.m_pixelsCulled, 40000, 1);
272 }
273
274 TEST(CCQuadCullerTest, verifyCullSubRegion)
275 {
276     DECLARE_AND_INITIALIZE_TEST_QUADS
277
278     childTransform.translate(50, 50);
279
280     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
281     IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() / 2);
282     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, childOpaqueRect);
283     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
284
285     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
286     occlusionTracker.markOccludedBehindLayer(childLayer.get());
287     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
288     EXPECT_EQ(quadList.size(), 12u);
289     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
290     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 30000, 1);
291     EXPECT_NEAR(overdraw.m_pixelsCulled, 10000, 1);
292 }
293
294 TEST(CCQuadCullerTest, verifyCullSubRegion2)
295 {
296     DECLARE_AND_INITIALIZE_TEST_QUADS
297
298     childTransform.translate(50, 10);
299
300     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
301     IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() * 3 / 4);
302     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, childOpaqueRect);
303     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
304
305     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
306     occlusionTracker.markOccludedBehindLayer(childLayer.get());
307     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
308     EXPECT_EQ(quadList.size(), 12u);
309     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
310     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 25000, 1);
311     EXPECT_NEAR(overdraw.m_pixelsCulled, 15000, 1);
312 }
313
314 TEST(CCQuadCullerTest, verifyCullSubRegionCheckOvercull)
315 {
316     DECLARE_AND_INITIALIZE_TEST_QUADS
317
318     childTransform.translate(50, 49);
319
320     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
321     IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() / 2);
322     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, childOpaqueRect);
323     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
324
325     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
326     occlusionTracker.markOccludedBehindLayer(childLayer.get());
327     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
328     EXPECT_EQ(quadList.size(), 13u);
329     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
330     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 30000, 1);
331     EXPECT_NEAR(overdraw.m_pixelsCulled, 10000, 1);
332 }
333
334 TEST(CCQuadCullerTest, verifyNonAxisAlignedQuadsDontOcclude)
335 {
336     DECLARE_AND_INITIALIZE_TEST_QUADS
337
338     // Use a small rotation so as to not disturb the geometry significantly.
339     childTransform.rotate(1);
340
341     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
342     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
343     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
344
345     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
346     occlusionTracker.markOccludedBehindLayer(childLayer.get());
347     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
348     EXPECT_EQ(quadList.size(), 13u);
349     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 130000, 1);
350     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
351     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
352 }
353
354 // This test requires some explanation: here we are rotating the quads to be culled.
355 // The 2x2 tile child layer remains in the top-left corner, unrotated, but the 3x3
356 // tile parent layer is rotated by 1 degree. Of the four tiles the child would
357 // normally occlude, three will move (slightly) out from under the child layer, and
358 // one moves further under the child. Only this last tile should be culled.
359 TEST(CCQuadCullerTest, verifyNonAxisAlignedQuadsSafelyCulled)
360 {
361     DECLARE_AND_INITIALIZE_TEST_QUADS
362
363     // Use a small rotation so as to not disturb the geometry significantly.
364     TransformationMatrix parentTransform;
365     parentTransform.rotate(1);
366
367     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(parentTransform, rootRect, 1.0, true, IntRect());
368     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
369     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
370
371     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
372     occlusionTracker.markOccludedBehindLayer(childLayer.get());
373     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
374     EXPECT_EQ(quadList.size(), 12u);
375     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 100600, 1);
376     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
377     EXPECT_NEAR(overdraw.m_pixelsCulled, 29400, 1);
378 }
379
380 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverTile)
381 {
382     DECLARE_AND_INITIALIZE_TEST_QUADS
383
384     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
385     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
386     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(200, 100, 100, 100));
387
388     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
389     occlusionTracker.markOccludedBehindLayer(childLayer.get());
390     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
391     EXPECT_EQ(quadList.size(), 1u);
392     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 10000, 1);
393     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
394     EXPECT_NEAR(overdraw.m_pixelsCulled, 120000, 1);
395 }
396
397 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverCulledTile)
398 {
399     DECLARE_AND_INITIALIZE_TEST_QUADS
400
401     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
402     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
403     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(100, 100, 100, 100));
404
405     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
406     occlusionTracker.markOccludedBehindLayer(childLayer.get());
407     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
408     EXPECT_EQ(quadList.size(), 1u);
409     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 10000, 1);
410     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
411     EXPECT_NEAR(overdraw.m_pixelsCulled, 120000, 1);
412 }
413
414 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverPartialTiles)
415 {
416     DECLARE_AND_INITIALIZE_TEST_QUADS
417
418     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
419     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
420     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(50, 50, 200, 200));
421
422     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
423     occlusionTracker.markOccludedBehindLayer(childLayer.get());
424     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
425     EXPECT_EQ(quadList.size(), 9u);
426     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 40000, 1);
427     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
428     EXPECT_NEAR(overdraw.m_pixelsCulled, 90000, 1);
429 }
430
431 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverNoTiles)
432 {
433     DECLARE_AND_INITIALIZE_TEST_QUADS
434
435     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
436     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
437     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(500, 500, 100, 100));
438
439     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
440     occlusionTracker.markOccludedBehindLayer(childLayer.get());
441     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
442     EXPECT_EQ(quadList.size(), 0u);
443     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 0, 1);
444     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
445     EXPECT_NEAR(overdraw.m_pixelsCulled, 130000, 1);
446 }
447
448 } // namespace