[chromium] Allow us to disable overdraw metrics when tracing is off
[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/CCOverdrawMetrics.h"
31 #include "cc/CCSingleThreadProxy.h"
32 #include "cc/CCTiledLayerImpl.h"
33 #include "cc/CCTileDrawQuad.h"
34 #include <gmock/gmock.h>
35 #include <gtest/gtest.h>
36
37 using namespace WebCore;
38
39 namespace {
40
41 class TestCCOcclusionTrackerImpl : public CCOcclusionTrackerImpl {
42 public:
43     TestCCOcclusionTrackerImpl(const IntRect& scissorRectInScreen, bool recordMetricsForFrame = true)
44         : CCOcclusionTrackerImpl(scissorRectInScreen, recordMetricsForFrame)
45         , m_scissorRectInScreen(scissorRectInScreen)
46     {
47         // Pretend we have visited a render surface.
48         m_stack.append(StackObject());
49     }
50
51 protected:
52     virtual IntRect layerScissorRectInTargetSurface(const CCLayerImpl* layer) const { return m_scissorRectInScreen; }
53
54 private:
55     IntRect m_scissorRectInScreen;
56 };
57
58 static PassOwnPtr<CCTiledLayerImpl> makeLayer(const TransformationMatrix& drawTransform, const IntRect& layerRect, float opacity, bool opaque, const IntRect& layerOpaqueRect)
59 {
60     OwnPtr<CCTiledLayerImpl> layer = CCTiledLayerImpl::create(0);
61     OwnPtr<CCLayerTilingData> tiler = CCLayerTilingData::create(IntSize(100, 100), CCLayerTilingData::NoBorderTexels);
62     tiler->setBounds(layerRect.size());
63     layer->setTilingData(*tiler);
64     layer->setSkipsDraw(false);
65     layer->setDrawTransform(drawTransform);
66     layer->setScreenSpaceTransform(drawTransform);
67     layer->setVisibleLayerRect(layerRect);
68     layer->setDrawOpacity(opacity);
69     layer->setOpaque(opaque);
70
71     int textureId = 1;
72     for (int i = 0; i < tiler->numTilesX(); ++i)
73         for (int j = 0; j < tiler->numTilesY(); ++j) {
74             IntRect tileOpaqueRect = opaque ? tiler->tileBounds(i, j) : intersection(tiler->tileBounds(i, j), layerOpaqueRect);
75             layer->pushTileProperties(i, j, static_cast<Platform3DObject>(textureId++), tileOpaqueRect);
76         }
77
78     return layer.release();
79 }
80
81 static void appendQuads(CCQuadList& quadList, Vector<OwnPtr<CCSharedQuadState> >& sharedStateList, CCTiledLayerImpl* layer, CCOcclusionTrackerImpl& occlusionTracker)
82 {
83     CCQuadCuller quadCuller(quadList, layer, &occlusionTracker);
84     OwnPtr<CCSharedQuadState> sharedQuadState = layer->createSharedQuadState();
85     layer->appendQuads(quadCuller, sharedQuadState.get());
86     sharedStateList.append(sharedQuadState.release());
87 }
88
89 #define DECLARE_AND_INITIALIZE_TEST_QUADS               \
90     DebugScopedSetImplThread impl;                      \
91     CCQuadList quadList;                                \
92     Vector<OwnPtr<CCSharedQuadState> > sharedStateList; \
93     TransformationMatrix childTransform;                \
94     IntSize rootSize = IntSize(300, 300);               \
95     IntRect rootRect = IntRect(IntPoint(), rootSize);   \
96     IntSize childSize = IntSize(200, 200);              \
97     IntRect childRect = IntRect(IntPoint(), childSize);
98
99 TEST(CCQuadCullerTest, verifyNoCulling)
100 {
101     DECLARE_AND_INITIALIZE_TEST_QUADS
102
103     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
104     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
105     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
106
107     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
108     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
109     EXPECT_EQ(quadList.size(), 13u);
110     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 130000, 1);
111     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
112     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 0, 1);
113 }
114
115 TEST(CCQuadCullerTest, verifyCullChildLinesUpTopLeft)
116 {
117     DECLARE_AND_INITIALIZE_TEST_QUADS
118
119     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
120     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
121     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
122
123     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
124     occlusionTracker.markOccludedBehindLayer(childLayer.get());
125     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
126     EXPECT_EQ(quadList.size(), 9u);
127     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
128     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
129     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 40000, 1);
130 }
131
132 TEST(CCQuadCullerTest, verifyCullWhenChildOpacityNotOne)
133 {
134     DECLARE_AND_INITIALIZE_TEST_QUADS
135
136     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
137     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 0.9, true, IntRect());
138     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
139
140     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
141     occlusionTracker.markOccludedBehindLayer(childLayer.get());
142     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
143     EXPECT_EQ(quadList.size(), 13u);
144     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
145     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 40000, 1);
146     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 0, 1);
147 }
148
149 TEST(CCQuadCullerTest, verifyCullWhenChildOpaqueFlagFalse)
150 {
151     DECLARE_AND_INITIALIZE_TEST_QUADS
152
153     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
154     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, IntRect());
155     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
156
157     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
158     occlusionTracker.markOccludedBehindLayer(childLayer.get());
159     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
160     EXPECT_EQ(quadList.size(), 13u);
161     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
162     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 40000, 1);
163     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 0, 1);
164 }
165
166 TEST(CCQuadCullerTest, verifyCullCenterTileOnly)
167 {
168     DECLARE_AND_INITIALIZE_TEST_QUADS
169
170     childTransform.translate(50, 50);
171
172     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
173     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
174     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
175
176     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
177     occlusionTracker.markOccludedBehindLayer(childLayer.get());
178     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
179     EXPECT_EQ(quadList.size(), 12u);
180
181     IntRect quadVisibleRect1 = quadList[5].get()->quadVisibleRect();
182     EXPECT_EQ(quadVisibleRect1.height(), 50);
183
184     IntRect quadVisibleRect3 = quadList[7].get()->quadVisibleRect();
185     EXPECT_EQ(quadVisibleRect3.width(), 50);
186
187     // Next index is 8, not 9, since centre quad culled.
188     IntRect quadVisibleRect4 = quadList[8].get()->quadVisibleRect();
189     EXPECT_EQ(quadVisibleRect4.width(), 50);
190     EXPECT_EQ(quadVisibleRect4.x(), 250);
191
192     IntRect quadVisibleRect6 = quadList[10].get()->quadVisibleRect();
193     EXPECT_EQ(quadVisibleRect6.height(), 50);
194     EXPECT_EQ(quadVisibleRect6.y(), 250);
195
196     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 100000, 1);
197     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
198     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 30000, 1);
199 }
200
201 TEST(CCQuadCullerTest, verifyCullCenterTileNonIntegralSize1)
202 {
203     DECLARE_AND_INITIALIZE_TEST_QUADS
204
205     childTransform.translate(100, 100);
206
207     // Make the root layer's quad have extent (99.1, 99.1) -> (200.9, 200.9) to make
208     // sure it doesn't get culled due to transform rounding.
209     TransformationMatrix rootTransform;
210     rootTransform.translate(99.1, 99.1);
211     rootTransform.scale(1.018);
212
213     rootRect = childRect = IntRect(0, 0, 100, 100);
214
215     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(rootTransform, rootRect, 1.0, true, IntRect());
216     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
217     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
218
219     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
220     occlusionTracker.markOccludedBehindLayer(childLayer.get());
221     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
222     EXPECT_EQ(quadList.size(), 2u);
223
224     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 20363, 1);
225     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
226     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 0, 1);
227 }
228
229 TEST(CCQuadCullerTest, verifyCullCenterTileNonIntegralSize2)
230 {
231     DECLARE_AND_INITIALIZE_TEST_QUADS
232
233     // Make the child's quad slightly smaller than, and centred over, the root layer tile.
234     // Verify the child does not cause the quad below to be culled due to rounding.
235     childTransform.translate(100.1, 100.1);
236     childTransform.scale(0.982);
237
238     TransformationMatrix rootTransform;
239     rootTransform.translate(100, 100);
240
241     rootRect = childRect = IntRect(0, 0, 100, 100);
242
243     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(rootTransform, rootRect, 1.0, true, IntRect());
244     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
245     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
246
247     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
248     occlusionTracker.markOccludedBehindLayer(childLayer.get());
249     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
250     EXPECT_EQ(quadList.size(), 2u);
251
252     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 19643, 1);
253     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
254     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 0, 1);
255 }
256
257 TEST(CCQuadCullerTest, verifyCullChildLinesUpBottomRight)
258 {
259     DECLARE_AND_INITIALIZE_TEST_QUADS
260
261     childTransform.translate(100, 100);
262
263     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
264     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
265     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
266
267     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
268     occlusionTracker.markOccludedBehindLayer(childLayer.get());
269     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
270     EXPECT_EQ(quadList.size(), 9u);
271     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
272     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
273     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 40000, 1);
274 }
275
276 TEST(CCQuadCullerTest, verifyCullSubRegion)
277 {
278     DECLARE_AND_INITIALIZE_TEST_QUADS
279
280     childTransform.translate(50, 50);
281
282     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
283     IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() / 2);
284     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, childOpaqueRect);
285     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
286
287     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
288     occlusionTracker.markOccludedBehindLayer(childLayer.get());
289     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
290     EXPECT_EQ(quadList.size(), 12u);
291     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
292     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 30000, 1);
293     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 10000, 1);
294 }
295
296 TEST(CCQuadCullerTest, verifyCullSubRegion2)
297 {
298     DECLARE_AND_INITIALIZE_TEST_QUADS
299
300     childTransform.translate(50, 10);
301
302     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
303     IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() * 3 / 4);
304     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, childOpaqueRect);
305     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
306
307     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
308     occlusionTracker.markOccludedBehindLayer(childLayer.get());
309     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
310     EXPECT_EQ(quadList.size(), 12u);
311     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
312     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 25000, 1);
313     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 15000, 1);
314 }
315
316 TEST(CCQuadCullerTest, verifyCullSubRegionCheckOvercull)
317 {
318     DECLARE_AND_INITIALIZE_TEST_QUADS
319
320     childTransform.translate(50, 49);
321
322     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
323     IntRect childOpaqueRect(childRect.x() + childRect.width() / 4, childRect.y() + childRect.height() / 4, childRect.width() / 2, childRect.height() / 2);
324     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, false, childOpaqueRect);
325     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
326
327     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
328     occlusionTracker.markOccludedBehindLayer(childLayer.get());
329     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
330     EXPECT_EQ(quadList.size(), 13u);
331     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 90000, 1);
332     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 30000, 1);
333     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 10000, 1);
334 }
335
336 TEST(CCQuadCullerTest, verifyNonAxisAlignedQuadsDontOcclude)
337 {
338     DECLARE_AND_INITIALIZE_TEST_QUADS
339
340     // Use a small rotation so as to not disturb the geometry significantly.
341     childTransform.rotate(1);
342
343     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
344     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(childTransform, childRect, 1.0, true, IntRect());
345     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
346
347     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
348     occlusionTracker.markOccludedBehindLayer(childLayer.get());
349     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
350     EXPECT_EQ(quadList.size(), 13u);
351     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 130000, 1);
352     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
353     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 0, 1);
354 }
355
356 // This test requires some explanation: here we are rotating the quads to be culled.
357 // The 2x2 tile child layer remains in the top-left corner, unrotated, but the 3x3
358 // tile parent layer is rotated by 1 degree. Of the four tiles the child would
359 // normally occlude, three will move (slightly) out from under the child layer, and
360 // one moves further under the child. Only this last tile should be culled.
361 TEST(CCQuadCullerTest, verifyNonAxisAlignedQuadsSafelyCulled)
362 {
363     DECLARE_AND_INITIALIZE_TEST_QUADS
364
365     // Use a small rotation so as to not disturb the geometry significantly.
366     TransformationMatrix parentTransform;
367     parentTransform.rotate(1);
368
369     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(parentTransform, rootRect, 1.0, true, IntRect());
370     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
371     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(-100, -100, 1000, 1000));
372
373     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
374     occlusionTracker.markOccludedBehindLayer(childLayer.get());
375     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
376     EXPECT_EQ(quadList.size(), 12u);
377     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 100600, 1);
378     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
379     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 29400, 1);
380 }
381
382 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverTile)
383 {
384     DECLARE_AND_INITIALIZE_TEST_QUADS
385
386     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
387     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
388     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(200, 100, 100, 100));
389
390     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
391     occlusionTracker.markOccludedBehindLayer(childLayer.get());
392     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
393     EXPECT_EQ(quadList.size(), 1u);
394     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 10000, 1);
395     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
396     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 120000, 1);
397 }
398
399 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverCulledTile)
400 {
401     DECLARE_AND_INITIALIZE_TEST_QUADS
402
403     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
404     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
405     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(100, 100, 100, 100));
406
407     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
408     occlusionTracker.markOccludedBehindLayer(childLayer.get());
409     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
410     EXPECT_EQ(quadList.size(), 1u);
411     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 10000, 1);
412     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
413     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 120000, 1);
414 }
415
416 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverPartialTiles)
417 {
418     DECLARE_AND_INITIALIZE_TEST_QUADS
419
420     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
421     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
422     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(50, 50, 200, 200));
423
424     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
425     occlusionTracker.markOccludedBehindLayer(childLayer.get());
426     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
427     EXPECT_EQ(quadList.size(), 9u);
428     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 40000, 1);
429     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
430     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 90000, 1);
431 }
432
433 TEST(CCQuadCullerTest, verifyCullOutsideScissorOverNoTiles)
434 {
435     DECLARE_AND_INITIALIZE_TEST_QUADS
436
437     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
438     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
439     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(500, 500, 100, 100));
440
441     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
442     occlusionTracker.markOccludedBehindLayer(childLayer.get());
443     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
444     EXPECT_EQ(quadList.size(), 0u);
445     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 0, 1);
446     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
447     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 130000, 1);
448 }
449
450 TEST(CCQuadCullerTest, verifyWithoutMetrics)
451 {
452     DECLARE_AND_INITIALIZE_TEST_QUADS
453
454     OwnPtr<CCTiledLayerImpl> rootLayer = makeLayer(TransformationMatrix(), rootRect, 1.0, true, IntRect());
455     OwnPtr<CCTiledLayerImpl> childLayer = makeLayer(TransformationMatrix(), childRect, 1.0, true, IntRect());
456     TestCCOcclusionTrackerImpl occlusionTracker(IntRect(50, 50, 200, 200), false);
457
458     appendQuads(quadList, sharedStateList, childLayer.get(), occlusionTracker);
459     occlusionTracker.markOccludedBehindLayer(childLayer.get());
460     appendQuads(quadList, sharedStateList, rootLayer.get(), occlusionTracker);
461     EXPECT_EQ(quadList.size(), 9u);
462     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnOpaque(), 0, 1);
463     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsDrawnTranslucent(), 0, 1);
464     EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulled(), 0, 1);
465 }
466
467
468 } // namespace