8a1041a87e44806b3c6c774ac002cef19a9646c3
[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 // Fails on Windows https://bugs.webkit.org/show_bug.cgi?id=81083
114 TEST(CCQuadCullerTest, FAILS_verifyCullChildLinesUpTopLeft)
115 {
116     DECLARE_AND_INITIALIZE_TEST_QUADS
117
118     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
119     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
120     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
121
122     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
123     occlusionTracker.markOccludedBehindLayer(childLayer.get());
124     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
125     EXPECT_EQ(quadList.size(), 9u);
126     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
127     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
128     EXPECT_NEAR(overdraw.m_pixelsCulled, 40000, 1);
129 }
130
131 TEST(CCQuadCullerTest, verifyCullWhenChildOpacityNotOne)
132 {
133     DECLARE_AND_INITIALIZE_TEST_QUADS
134
135     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
136     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 0.9, true, IntRect());
137     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
138
139     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
140     occlusionTracker.markOccludedBehindLayer(childLayer.get());
141     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
142     EXPECT_EQ(quadList.size(), 13u);
143     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
144     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 40000, 1);
145     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
146 }
147
148 TEST(CCQuadCullerTest, verifyCullWhenChildOpaqueFlagFalse)
149 {
150     DECLARE_AND_INITIALIZE_TEST_QUADS
151
152     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
153     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, IntRect());
154     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
155
156     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
157     occlusionTracker.markOccludedBehindLayer(childLayer.get());
158     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
159     EXPECT_EQ(quadList.size(), 13u);
160     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
161     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 40000, 1);
162     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
163 }
164
165 TEST(CCQuadCullerTest, verifyCullCenterTileOnly)
166 {
167     DECLARE_AND_INITIALIZE_TEST_QUADS
168
169     childTransform.translate(50, 50);
170
171     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
172     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
173     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
174
175     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
176     occlusionTracker.markOccludedBehindLayer(childLayer.get());
177     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
178     EXPECT_EQ(quadList.size(), 12u);
179
180     IntRect quadVisibleRect1 = quadList[5].get()->quadVisibleRect();
181     EXPECT_EQ(quadVisibleRect1.height(), 50);
182
183     IntRect quadVisibleRect3 = quadList[7].get()->quadVisibleRect();
184     EXPECT_EQ(quadVisibleRect3.width(), 50);
185
186     // Next index is 8, not 9, since centre quad culled.
187     IntRect quadVisibleRect4 = quadList[8].get()->quadVisibleRect();
188     EXPECT_EQ(quadVisibleRect4.width(), 50);
189     EXPECT_EQ(quadVisibleRect4.x(), 250);
190
191     IntRect quadVisibleRect6 = quadList[10].get()->quadVisibleRect();
192     EXPECT_EQ(quadVisibleRect6.height(), 50);
193     EXPECT_EQ(quadVisibleRect6.y(), 250);
194
195     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 100000, 1);
196     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
197     EXPECT_NEAR(overdraw.m_pixelsCulled, 30000, 1);
198 }
199
200 TEST(CCQuadCullerTest, verifyCullCenterTileNonIntegralSize1)
201 {
202     DECLARE_AND_INITIALIZE_TEST_QUADS
203
204     childTransform.translate(100, 100);
205
206     // Make the root layer's quad have extent (99.1, 99.1) -> (200.9, 200.9) to make
207     // sure it doesn't get culled due to transform rounding.
208     TransformationMatrix rootTransform;
209     rootTransform.translate(99.1, 99.1);
210     rootTransform.scale(1.018);
211
212     rootRect = childRect = IntRect(0, 0, 100, 100);
213
214     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(rootTransform, rootRect, 1.0, true, IntRect());
215     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
216     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
217
218     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
219     occlusionTracker.markOccludedBehindLayer(childLayer.get());
220     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
221     EXPECT_EQ(quadList.size(), 2u);
222
223     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 20363, 1);
224     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
225     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
226 }
227
228 TEST(CCQuadCullerTest, verifyCullCenterTileNonIntegralSize2)
229 {
230     DECLARE_AND_INITIALIZE_TEST_QUADS
231
232     // Make the child's quad slightly smaller than, and centred over, the root layer tile.
233     // Verify the child does not cause the quad below to be culled due to rounding.
234     childTransform.translate(100.1, 100.1);
235     childTransform.scale(0.982);
236
237     TransformationMatrix rootTransform;
238     rootTransform.translate(100, 100);
239
240     rootRect = childRect = IntRect(0, 0, 100, 100);
241
242     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(rootTransform, rootRect, 1.0, true, IntRect());
243     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
244     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
245
246     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
247     occlusionTracker.markOccludedBehindLayer(childLayer.get());
248     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
249     EXPECT_EQ(quadList.size(), 2u);
250
251     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 19643, 1);
252     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
253     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
254 }
255
256 TEST(CCQuadCullerTest, verifyCullChildLinesUpBottomRight)
257 {
258     DECLARE_AND_INITIALIZE_TEST_QUADS
259
260     childTransform.translate(100, 100);
261
262     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
263     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
264     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
265
266     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
267     occlusionTracker.markOccludedBehindLayer(childLayer.get());
268     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
269     EXPECT_EQ(quadList.size(), 9u);
270     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
271     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
272     EXPECT_NEAR(overdraw.m_pixelsCulled, 40000, 1);
273 }
274
275 TEST(CCQuadCullerTest, verifyCullSubRegion)
276 {
277     DECLARE_AND_INITIALIZE_TEST_QUADS
278
279     childTransform.translate(50, 50);
280
281     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
282     IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() / 2);
283     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, childOpaqueRect);
284     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
285
286     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
287     occlusionTracker.markOccludedBehindLayer(childLayer.get());
288     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
289     EXPECT_EQ(quadList.size(), 12u);
290     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
291     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 30000, 1);
292     EXPECT_NEAR(overdraw.m_pixelsCulled, 10000, 1);
293 }
294
295 TEST(CCQuadCullerTest, verifyCullSubRegion2)
296 {
297     DECLARE_AND_INITIALIZE_TEST_QUADS
298
299     childTransform.translate(50, 10);
300
301     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
302     IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() * 3 / 4);
303     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, childOpaqueRect);
304     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
305
306     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
307     occlusionTracker.markOccludedBehindLayer(childLayer.get());
308     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
309     EXPECT_EQ(quadList.size(), 12u);
310     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
311     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 25000, 1);
312     EXPECT_NEAR(overdraw.m_pixelsCulled, 15000, 1);
313 }
314
315 TEST(CCQuadCullerTest, verifyCullSubRegionCheckOvercull)
316 {
317     DECLARE_AND_INITIALIZE_TEST_QUADS
318
319     childTransform.translate(50, 49);
320
321     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
322     IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() / 2);
323     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, childOpaqueRect);
324     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
325
326     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
327     occlusionTracker.markOccludedBehindLayer(childLayer.get());
328     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
329     EXPECT_EQ(quadList.size(), 13u);
330     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 90000, 1);
331     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 30000, 1);
332     EXPECT_NEAR(overdraw.m_pixelsCulled, 10000, 1);
333 }
334
335 TEST(CCQuadCullerTest, verifyNonAxisAlignedQuadsDontOcclude)
336 {
337     DECLARE_AND_INITIALIZE_TEST_QUADS
338
339     // Use a small rotation so as to not disturb the geometry significantly.
340     childTransform.rotate(1);
341
342     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
343     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
344     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
345
346     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
347     occlusionTracker.markOccludedBehindLayer(childLayer.get());
348     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
349     EXPECT_EQ(quadList.size(), 13u);
350     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 130000, 1);
351     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
352     EXPECT_NEAR(overdraw.m_pixelsCulled, 0, 1);
353 }
354
355 // This test requires some explanation: here we are rotating the quads to be culled.
356 // The 2x2 tile child layer remains in the top-left corner, unrotated, but the 3x3
357 // tile parent layer is rotated by 1 degree. Of the four tiles the child would
358 // normally occlude, three will move (slightly) out from under the child layer, and
359 // one moves further under the child. Only this last tile should be culled.
360 TEST(CCQuadCullerTest, verifyNonAxisAlignedQuadsSafelyCulled)
361 {
362     DECLARE_AND_INITIALIZE_TEST_QUADS
363
364     // Use a small rotation so as to not disturb the geometry significantly.
365     TransformationMatrix parentTransform;
366     parentTransform.rotate(1);
367
368     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(parentTransform, rootRect, 1.0, true, IntRect());
369     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
370     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
371
372     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
373     occlusionTracker.markOccludedBehindLayer(childLayer.get());
374     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
375     EXPECT_EQ(quadList.size(), 12u);
376     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 100600, 1);
377     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
378     EXPECT_NEAR(overdraw.m_pixelsCulled, 29400, 1);
379 }
380
381 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverTile)
382 {
383     DECLARE_AND_INITIALIZE_TEST_QUADS
384
385     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
386     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
387     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(200, 100, 100, 100));
388
389     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
390     occlusionTracker.markOccludedBehindLayer(childLayer.get());
391     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
392     EXPECT_EQ(quadList.size(), 1u);
393     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 10000, 1);
394     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
395     EXPECT_NEAR(overdraw.m_pixelsCulled, 120000, 1);
396 }
397
398 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverCulledTile)
399 {
400     DECLARE_AND_INITIALIZE_TEST_QUADS
401
402     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
403     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
404     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(100, 100, 100, 100));
405
406     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
407     occlusionTracker.markOccludedBehindLayer(childLayer.get());
408     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
409     EXPECT_EQ(quadList.size(), 1u);
410     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 10000, 1);
411     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
412     EXPECT_NEAR(overdraw.m_pixelsCulled, 120000, 1);
413 }
414
415 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverPartialTiles)
416 {
417     DECLARE_AND_INITIALIZE_TEST_QUADS
418
419     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
420     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
421     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(50, 50, 200, 200));
422
423     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
424     occlusionTracker.markOccludedBehindLayer(childLayer.get());
425     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
426     EXPECT_EQ(quadList.size(), 9u);
427     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 40000, 1);
428     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
429     EXPECT_NEAR(overdraw.m_pixelsCulled, 90000, 1);
430 }
431
432 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverNoTiles)
433 {
434     DECLARE_AND_INITIALIZE_TEST_QUADS
435
436     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
437     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
438     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(500, 500, 100, 100));
439
440     appendQuads(quadList, childLayer.get(), occlusionTracker, overdraw);
441     occlusionTracker.markOccludedBehindLayer(childLayer.get());
442     appendQuads(quadList, rootLayer.get(), occlusionTracker, overdraw);
443     EXPECT_EQ(quadList.size(), 0u);
444     EXPECT_NEAR(overdraw.m_pixelsDrawnOpaque, 0, 1);
445     EXPECT_NEAR(overdraw.m_pixelsDrawnTransparent, 0, 1);
446     EXPECT_NEAR(overdraw.m_pixelsCulled, 130000, 1);
447 }
448
449 } // namespace