[chromium] Clean up culling tests and templatize to test impl constructs
[WebKit-https.git] / Source / WebKit / chromium / tests / CCOcclusionTrackerTest.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/CCOcclusionTracker.h"
28
29 #include "FilterOperations.h"
30 #include "LayerChromium.h"
31 #include "Region.h"
32 #include "TransformationMatrix.h"
33 #include "cc/CCLayerImpl.h"
34 #include "cc/CCLayerTreeHostCommon.h"
35 #include "cc/CCSingleThreadProxy.h"
36
37 #include <gmock/gmock.h>
38 #include <gtest/gtest.h>
39
40 using namespace WebCore;
41
42 #define EXPECT_EQ_RECT(a, b) \
43     EXPECT_EQ(a.x(), b.x()); \
44     EXPECT_EQ(a.y(), b.y()); \
45     EXPECT_EQ(a.width(), b.width()); \
46     EXPECT_EQ(a.height(), b.height());
47
48 namespace {
49
50 class TestContentLayerChromium : public LayerChromium {
51 public:
52     TestContentLayerChromium() : LayerChromium() { }
53
54     virtual bool drawsContent() const { return true; }
55     virtual Region opaqueContentsRegion() const { return intersection(m_opaqueContentsRect, visibleLayerRect()); }
56     void setOpaqueContentsRect(const IntRect& opaqueContentsRect) { m_opaqueContentsRect = opaqueContentsRect; }
57
58 private:
59     IntRect m_opaqueContentsRect;
60 };
61
62 class TestContentLayerImpl : public CCLayerImpl {
63 public:
64     TestContentLayerImpl(int id) : CCLayerImpl(id) { setDrawsContent(true); }
65
66     virtual Region opaqueContentsRegion() const { return intersection(m_opaqueContentsRect, visibleLayerRect()); }
67     void setOpaqueContentsRect(const IntRect& opaqueContentsRect) { m_opaqueContentsRect = opaqueContentsRect; }
68 private:
69     IntRect m_opaqueContentsRect;
70 };
71
72 // A subclass to expose the total current occlusion.
73 template<typename LayerType, typename RenderSurfaceType>
74 class TestCCOcclusionTrackerBase : public CCOcclusionTrackerBase<LayerType, RenderSurfaceType> {
75 public:
76     TestCCOcclusionTrackerBase(IntRect screenScissorRect)
77         : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>(screenScissorRect)
78         , m_overrideLayerScissorRect(false)
79     {
80     }
81
82     TestCCOcclusionTrackerBase(IntRect screenScissorRect, const CCOcclusionTrackerDamageClientBase<RenderSurfaceType>* damageClient)
83         : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>(screenScissorRect, damageClient)
84         , m_overrideLayerScissorRect(false)
85     {
86     }
87
88     Region occlusionInScreenSpace() const { return CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInScreen; }
89     Region occlusionInTargetSurface() const { return CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInTarget; }
90
91     void setOcclusionInScreenSpace(const Region& region) { CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInScreen = region; }
92     void setOcclusionInTargetSurface(const Region& region) { CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInTarget = region; }
93
94     void setLayerScissorRect(const IntRect& rect) { m_overrideLayerScissorRect = true; m_layerScissorRect = rect;}
95     void useDefaultLayerScissorRect() { m_overrideLayerScissorRect = false; }
96
97 protected:
98     virtual IntRect layerScissorRectInTargetSurface(const LayerType* layer) const { return m_overrideLayerScissorRect ? m_layerScissorRect : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::layerScissorRectInTargetSurface(layer); }
99
100 private:
101     bool m_overrideLayerScissorRect;
102     IntRect m_layerScissorRect;
103 };
104
105 template<typename RenderSurfaceType>
106 class TestDamageClient : public CCOcclusionTrackerDamageClientBase<RenderSurfaceType> {
107 public:
108     // The interface
109     virtual FloatRect damageRect(const RenderSurfaceType*) const { return m_damageRect; }
110
111     // Testing stuff
112     TestDamageClient(const FloatRect& damageRect) : m_damageRect(damageRect) { }
113     void setDamageRect(const FloatRect& damageRect) { m_damageRect = damageRect; }
114
115 private:
116     FloatRect m_damageRect;
117 };
118
119 struct CCOcclusionTrackerTestMainThreadTypes {
120     typedef LayerChromium LayerType;
121     typedef RenderSurfaceChromium RenderSurfaceType;
122     typedef TestContentLayerChromium ContentLayerType;
123     typedef RefPtr<LayerChromium> LayerPtrType;
124     typedef PassRefPtr<LayerChromium> PassLayerPtrType;
125     typedef RefPtr<ContentLayerType> ContentLayerPtrType;
126     typedef PassRefPtr<ContentLayerType> PassContentLayerPtrType;
127
128     static PassLayerPtrType createLayer() { return LayerChromium::create(); }
129     static PassContentLayerPtrType createContentLayer() { return adoptRef(new ContentLayerType()); }
130 };
131
132 struct CCOcclusionTrackerTestImplThreadTypes {
133     typedef CCLayerImpl LayerType;
134     typedef CCRenderSurface RenderSurfaceType;
135     typedef TestContentLayerImpl ContentLayerType;
136     typedef OwnPtr<CCLayerImpl> LayerPtrType;
137     typedef PassOwnPtr<CCLayerImpl> PassLayerPtrType;
138     typedef OwnPtr<ContentLayerType> ContentLayerPtrType;
139     typedef PassOwnPtr<ContentLayerType> PassContentLayerPtrType;
140
141     static PassLayerPtrType createLayer() { return CCLayerImpl::create(nextCCLayerImplId++); }
142     static PassContentLayerPtrType createContentLayer() { return adoptPtr(new ContentLayerType(nextCCLayerImplId++)); }
143     static int nextCCLayerImplId;
144 };
145
146 int CCOcclusionTrackerTestImplThreadTypes::nextCCLayerImplId = 0;
147
148 template<typename Types, bool opaqueLayers>
149 class CCOcclusionTrackerTest : public testing::Test {
150 protected:
151     virtual void runMyTest() = 0;
152
153     virtual void TearDown()
154     {
155         m_root.clear();
156         m_renderSurfaceLayerListChromium.clear();
157         m_renderSurfaceLayerListImpl.clear();
158     }
159
160     typename Types::ContentLayerType* createRoot(const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
161     {
162         typename Types::ContentLayerPtrType layer = Types::createContentLayer();
163         typename Types::ContentLayerType* layerPtr = layer.get();
164         setProperties(layerPtr, transform, position, bounds);
165
166         ASSERT(!m_root);
167         m_root = layer.release();
168         return layerPtr;
169     }
170
171     typename Types::LayerType* createLayer(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
172     {
173         typename Types::LayerPtrType layer = Types::createLayer();
174         typename Types::LayerType* layerPtr = layer.get();
175         setProperties(layerPtr, transform, position, bounds);
176         parent->addChild(layer.release());
177         return layerPtr;
178     }
179
180     typename Types::LayerType* createSurface(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
181     {
182         typename Types::LayerType* layer = createLayer(parent, transform, position, bounds);
183         FilterOperations filters;
184         filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
185         layer->setFilters(filters);
186         return layer;
187     }
188
189     typename Types::ContentLayerType* createDrawingLayer(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque)
190     {
191         typename Types::ContentLayerPtrType layer = Types::createContentLayer();
192         typename Types::ContentLayerType* layerPtr = layer.get();
193         setProperties(layerPtr, transform, position, bounds);
194
195         if (opaqueLayers)
196             layerPtr->setOpaque(opaque);
197         else {
198             layerPtr->setOpaque(false);
199             if (opaque)
200                 layerPtr->setOpaqueContentsRect(IntRect(IntPoint(), bounds));
201             else
202                 layerPtr->setOpaqueContentsRect(IntRect());
203         }
204
205         parent->addChild(layer.release());
206         return layerPtr;
207     }
208
209     typename Types::ContentLayerType* createDrawingSurface(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque)
210     {
211         typename Types::ContentLayerType* layer = createDrawingLayer(parent, transform, position, bounds, opaque);
212         FilterOperations filters;
213         filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
214         layer->setFilters(filters);
215         return layer;
216     }
217
218
219     TestContentLayerImpl* calcDrawEtc(TestContentLayerImpl* root)
220     {
221         ASSERT(root == m_root.get());
222         Vector<CCLayerImpl*> dummyLayerList;
223         int dummyMaxTextureSize = 512;
224
225         ASSERT(!root->renderSurface());
226         root->createRenderSurface();
227         root->renderSurface()->setContentRect(IntRect(IntPoint::zero(), root->bounds()));
228         root->setClipRect(IntRect(IntPoint::zero(), root->bounds()));
229         m_renderSurfaceLayerListImpl.append(m_root.get());
230
231         CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(root, root, identityMatrix, identityMatrix, m_renderSurfaceLayerListImpl, dummyLayerList, 0, dummyMaxTextureSize);
232         return root;
233     }
234
235     TestContentLayerChromium* calcDrawEtc(TestContentLayerChromium* root)
236     {
237         ASSERT(root == m_root.get());
238         Vector<RefPtr<LayerChromium> > dummyLayerList;
239         int dummyMaxTextureSize = 512;
240
241         ASSERT(!root->renderSurface());
242         root->createRenderSurface();
243         root->renderSurface()->setContentRect(IntRect(IntPoint::zero(), root->bounds()));
244         root->setClipRect(IntRect(IntPoint::zero(), root->bounds()));
245         m_renderSurfaceLayerListChromium.append(m_root);
246
247         CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(root, root, identityMatrix, identityMatrix, m_renderSurfaceLayerListChromium, dummyLayerList, dummyMaxTextureSize);
248         return root;
249     }
250
251     const TransformationMatrix identityMatrix;
252
253 private:
254     void setBaseProperties(typename Types::LayerType* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
255     {
256         layer->setTransform(transform);
257         layer->setSublayerTransform(TransformationMatrix());
258         layer->setAnchorPoint(FloatPoint(0, 0));
259         layer->setPosition(position);
260         layer->setBounds(bounds);
261     }
262
263     void setProperties(LayerChromium* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
264     {
265         setBaseProperties(layer, transform, position, bounds);
266     }
267
268     void setProperties(CCLayerImpl* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
269     {
270         setBaseProperties(layer, transform, position, bounds);
271
272         layer->setContentBounds(layer->bounds());
273     }
274
275     // These hold ownership of the layers for the duration of the test.
276     typename Types::LayerPtrType m_root;
277     Vector<RefPtr<LayerChromium> > m_renderSurfaceLayerListChromium;
278     Vector<CCLayerImpl*> m_renderSurfaceLayerListImpl;
279 };
280
281 #define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
282     class ClassName##MainThreadOpaqueLayers : public ClassName<CCOcclusionTrackerTestMainThreadTypes, true> { }; \
283     TEST_F(ClassName##MainThreadOpaqueLayers, runTest) { runMyTest(); }
284 #define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
285     class ClassName##MainThreadOpaquePaints : public ClassName<CCOcclusionTrackerTestMainThreadTypes, false> { }; \
286     TEST_F(ClassName##MainThreadOpaquePaints, runTest) { runMyTest(); }
287
288 #define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
289     class ClassName##ImplThreadOpaqueLayers : public ClassName<CCOcclusionTrackerTestImplThreadTypes, true> { \
290         DebugScopedSetImplThread impl; \
291     }; \
292     TEST_F(ClassName##ImplThreadOpaqueLayers, runTest) { runMyTest(); }
293 #define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
294     class ClassName##ImplThreadOpaquePaints : public ClassName<CCOcclusionTrackerTestImplThreadTypes, false> { \
295         DebugScopedSetImplThread impl; \
296     }; \
297     TEST_F(ClassName##ImplThreadOpaquePaints, runTest) { runMyTest(); }
298
299 #define ALL_CCOCCLUSIONTRACKER_TEST(ClassName) \
300     RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
301     RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
302     RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
303     RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
304
305 #define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
306     RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
307     RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
308
309 template<class Types, bool opaqueLayers>
310 class CCOcclusionTrackerTestIdentityTransforms : public CCOcclusionTrackerTest<Types, opaqueLayers> {
311 protected:
312     void runMyTest()
313     {
314         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
315         typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(30, 30), IntSize(500, 500), true);
316         calcDrawEtc(parent);
317
318         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
319         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
320
321         occlusion.enterTargetRenderSurface(parent->renderSurface());
322         occlusion.markOccludedBehindLayer(layer);
323         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
324         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
325         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
326         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
327
328         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
329         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
330         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
331         EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
332         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
333
334         occlusion.useDefaultLayerScissorRect();
335         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
336         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
337         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
338         EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
339         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
340         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
341
342         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)).isEmpty());
343         EXPECT_EQ_RECT(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 70, 70)));
344         EXPECT_EQ_RECT(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 29, 70, 70)));
345         EXPECT_EQ_RECT(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
346         EXPECT_EQ_RECT(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 29, 70, 70)));
347         EXPECT_EQ_RECT(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 70, 70)));
348         EXPECT_EQ_RECT(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 31, 70, 70)));
349         EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 31, 70, 70)));
350         EXPECT_EQ_RECT(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 31, 70, 70)));
351     }
352 };
353
354 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestIdentityTransforms);
355
356 template<class Types, bool opaqueLayers>
357 class CCOcclusionTrackerTestRotatedChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
358 protected:
359     void runMyTest()
360     {
361         TransformationMatrix layerTransform;
362         layerTransform.translate(250, 250);
363         layerTransform.rotate(90);
364         layerTransform.translate(-250, -250);
365
366         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
367         typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
368         calcDrawEtc(parent);
369
370         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
371         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
372
373         occlusion.enterTargetRenderSurface(parent->renderSurface());
374         occlusion.markOccludedBehindLayer(layer);
375         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
376         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
377         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
378         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
379
380         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
381         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
382         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
383         EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
384         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
385
386         occlusion.useDefaultLayerScissorRect();
387         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
388         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
389         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
390         EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
391         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
392         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
393
394         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)).isEmpty());
395         EXPECT_EQ_RECT(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 70, 70)));
396         EXPECT_EQ_RECT(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 29, 70, 70)));
397         EXPECT_EQ_RECT(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
398         EXPECT_EQ_RECT(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 29, 70, 70)));
399         EXPECT_EQ_RECT(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 70, 70)));
400         EXPECT_EQ_RECT(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 31, 70, 70)));
401         EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 31, 70, 70)));
402         EXPECT_EQ_RECT(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 31, 70, 70)));
403     }
404 };
405
406 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestRotatedChild);
407
408 template<class Types, bool opaqueLayers>
409 class CCOcclusionTrackerTestTranslatedChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
410 protected:
411     void runMyTest()
412     {
413         TransformationMatrix layerTransform;
414         layerTransform.translate(20, 20);
415
416         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
417         typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
418         calcDrawEtc(parent);
419
420         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
421         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
422
423         occlusion.enterTargetRenderSurface(parent->renderSurface());
424         occlusion.markOccludedBehindLayer(layer);
425         EXPECT_EQ_RECT(IntRect(50, 50, 50, 50), occlusion.occlusionInScreenSpace().bounds());
426         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
427         EXPECT_EQ_RECT(IntRect(50, 50, 50, 50), occlusion.occlusionInTargetSurface().bounds());
428         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
429
430         EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 50, 50, 50)));
431         EXPECT_FALSE(occlusion.occluded(parent, IntRect(49, 50, 50, 50)));
432         EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 49, 50, 50)));
433         EXPECT_FALSE(occlusion.occluded(parent, IntRect(51, 50, 50, 50)));
434         EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 51, 50, 50)));
435
436         occlusion.useDefaultLayerScissorRect();
437         EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 50, 50, 50)));
438         EXPECT_FALSE(occlusion.occluded(parent, IntRect(49, 50, 50, 50)));
439         EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 49, 50, 50)));
440         EXPECT_TRUE(occlusion.occluded(parent, IntRect(51, 50, 50, 50)));
441         EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 51, 50, 50)));
442         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
443
444         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 50, 50, 50)).isEmpty());
445         EXPECT_EQ_RECT(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 50, 50, 50)));
446         EXPECT_EQ_RECT(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 49, 50, 50)));
447         EXPECT_EQ_RECT(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 49, 50, 50)));
448         EXPECT_EQ_RECT(IntRect(51, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 49, 50, 50)));
449         EXPECT_EQ_RECT(IntRect(100, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 50, 50, 50)));
450         EXPECT_EQ_RECT(IntRect(51, 51, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 51, 50, 50)));
451         EXPECT_EQ_RECT(IntRect(50, 100, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 51, 50, 50)));
452         EXPECT_EQ_RECT(IntRect(49, 51, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 51, 50, 50)));
453
454         occlusion.useDefaultLayerScissorRect();
455         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 50, 50, 50)).isEmpty());
456         EXPECT_EQ_RECT(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 50, 50, 50)));
457         EXPECT_EQ_RECT(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 49, 50, 50)));
458         EXPECT_EQ_RECT(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 49, 50, 50)));
459         EXPECT_EQ_RECT(IntRect(51, 49, 49, 1), occlusion.unoccludedContentRect(parent, IntRect(51, 49, 50, 50)));
460         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(51, 50, 50, 50)).isEmpty());
461         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(51, 51, 50, 50)).isEmpty());
462         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 51, 50, 50)).isEmpty());
463         EXPECT_EQ_RECT(IntRect(49, 51, 1, 49), occlusion.unoccludedContentRect(parent, IntRect(49, 51, 50, 50)));
464         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
465     }
466 };
467
468 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestTranslatedChild);
469
470 template<class Types, bool opaqueLayers>
471 class CCOcclusionTrackerTestChildInRotatedChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
472 protected:
473     void runMyTest()
474     {
475         TransformationMatrix childTransform;
476         childTransform.translate(250, 250);
477         childTransform.rotate(90);
478         childTransform.translate(-250, -250);
479
480         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
481         typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
482         child->setMasksToBounds(true);
483         typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
484         calcDrawEtc(parent);
485
486         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
487         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
488
489         occlusion.enterTargetRenderSurface(child->renderSurface());
490         occlusion.markOccludedBehindLayer(layer);
491
492         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
493         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
494         EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
495         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
496
497         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
498         EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
499         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
500         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 430, 61, 70)));
501         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 430, 60, 71)));
502
503         occlusion.useDefaultLayerScissorRect();
504         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
505         EXPECT_TRUE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
506         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
507         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 61, 70)));
508         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 71)));
509         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
510
511         occlusion.markOccludedBehindLayer(child);
512         occlusion.finishedTargetRenderSurface(child, child->renderSurface());
513         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
514
515         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
516         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
517         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
518         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
519
520         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
521         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
522         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
523         EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 40, 70, 60)));
524         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 41, 70, 60)));
525
526         occlusion.useDefaultLayerScissorRect();
527         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
528         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
529         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
530         EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 40, 70, 60)));
531         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 41, 70, 60)));
532         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
533
534
535         /* Justification for the above occlusion from |layer|:
536                    100
537           +---------------------+                                      +---------------------+
538           |                     |                                      |                     |30  Visible region of |layer|: /////
539           |    30               |           rotate(90)                 |                     |
540           | 30 + ---------------------------------+                    |     +---------------------------------+
541       100 |    |  10            |                 |            ==>     |     |               |10               |
542           |    |10+---------------------------------+                  |  +---------------------------------+  |
543           |    |  |             |                 | |                  |  |  |///////////////|     420      |  |
544           |    |  |             |                 | |                  |  |  |///////////////|60            |  |
545           |    |  |             |                 | |                  |  |  |///////////////|              |  |
546           +----|--|-------------+                 | |                  +--|--|---------------+              |  |
547                |  |                               | |                   20|10|     70                       |  |
548                |  |                               | |                     |  |                              |  |
549                |  |                               | |500                  |  |                              |  |
550                |  |                               | |                     |  |                              |  |
551                |  |                               | |                     |  |                              |  |
552                |  |                               | |                     |  |                              |  |
553                |  |                               | |                     |  |                              |10|
554                +--|-------------------------------+ |                     |  +------------------------------|--+
555                   |                                 |                     |                 490             |
556                   +---------------------------------+                     +---------------------------------+
557                                  500                                                     500
558          */
559     }
560 };
561
562 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestChildInRotatedChild);
563
564 template<class Types, bool opaqueLayers>
565 class CCOcclusionTrackerTestVisitTargetTwoTimes : public CCOcclusionTrackerTest<Types, opaqueLayers> {
566 protected:
567     void runMyTest()
568     {
569         TransformationMatrix childTransform;
570         childTransform.translate(250, 250);
571         childTransform.rotate(90);
572         childTransform.translate(-250, -250);
573
574         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
575         typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
576         child->setMasksToBounds(true);
577         typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
578         // |child2| makes |parent|'s surface get considered by CCOcclusionTracker first, instead of |child|'s. This exercises different code in
579         // leaveToTargetRenderSurface, as the target surface has already been seen.
580         typename Types::ContentLayerType* child2 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(30, 30), IntSize(60, 20), true);
581         calcDrawEtc(parent);
582
583         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
584         occlusion.setLayerScissorRect(IntRect(-10, -10, 1000, 1000));
585
586         occlusion.enterTargetRenderSurface(parent->renderSurface());
587         occlusion.markOccludedBehindLayer(child2);
588
589         EXPECT_EQ_RECT(IntRect(30, 30, 60, 20), occlusion.occlusionInScreenSpace().bounds());
590         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
591         EXPECT_EQ_RECT(IntRect(30, 30, 60, 20), occlusion.occlusionInTargetSurface().bounds());
592         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
593
594         occlusion.enterTargetRenderSurface(child->renderSurface());
595         occlusion.markOccludedBehindLayer(layer);
596
597         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
598         EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
599         EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
600         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
601
602         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
603         EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
604         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
605         EXPECT_FALSE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
606         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
607
608         occlusion.useDefaultLayerScissorRect();
609         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
610         EXPECT_TRUE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
611         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
612         EXPECT_TRUE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
613         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
614         occlusion.setLayerScissorRect(IntRect(-10, -10, 1000, 1000));
615
616         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
617         // This is the little piece not occluded by child2
618         EXPECT_EQ_RECT(IntRect(9, 430, 1, 10), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)));
619         // This extends past both sides of child2, so it will be the original rect.
620         EXPECT_EQ_RECT(IntRect(9, 430, 60, 80), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 80)));
621         // This extends past two adjacent sides of child2, and should included the unoccluded parts of each side.
622         // This also demonstrates that the rect can be arbitrary and does not get clipped to the layer's visibleLayerRect().
623         EXPECT_EQ_RECT(IntRect(-10, 430, 20, 70), occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 70)));
624         // This extends past three adjacent sides of child2, so it should contain the unoccluded parts of each side. The left
625         // and bottom edges are completely unoccluded for some row/column so we get back the original query rect.
626         EXPECT_EQ_RECT(IntRect(-10, 430, 60, 80), occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 80)));
627         EXPECT_EQ_RECT(IntRect(10, 429, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)));
628         EXPECT_EQ_RECT(IntRect(70, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)));
629         EXPECT_EQ_RECT(IntRect(10, 500, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)));
630
631         occlusion.useDefaultLayerScissorRect();
632         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
633         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)).isEmpty());
634         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 80)).isEmpty());
635         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 70)).isEmpty());
636         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 80)).isEmpty());
637         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)).isEmpty());
638         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)).isEmpty());
639         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)).isEmpty());
640         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
641
642         occlusion.markOccludedBehindLayer(child);
643         // |child2| should get merged with the surface we are leaving now
644         occlusion.finishedTargetRenderSurface(child, child->renderSurface());
645         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
646
647         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
648         EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
649         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
650         EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
651
652         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
653         EXPECT_EQ_RECT(IntRect(90, 30, 10, 10), occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)));
654
655         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 60, 10)));
656         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 60, 10)));
657         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 60, 10)));
658         EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 60, 10)));
659         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 60, 10)));
660
661         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
662         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
663         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
664
665         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 60, 10)).isEmpty());
666         EXPECT_EQ_RECT(IntRect(29, 30, 1, 10), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 60, 10)));
667         EXPECT_EQ_RECT(IntRect(30, 29, 60, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 60, 10)));
668         EXPECT_EQ_RECT(IntRect(90, 30, 1, 10), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 60, 10)));
669         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 31, 60, 10)).isEmpty());
670
671         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 40, 70, 60)).isEmpty());
672         EXPECT_EQ_RECT(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(29, 40, 70, 60)));
673         // This rect is mostly occluded by |child2|.
674         EXPECT_EQ_RECT(IntRect(90, 39, 10, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 39, 70, 60)));
675         // This rect extends past top/right ends of |child2|.
676         EXPECT_EQ_RECT(IntRect(30, 29, 70, 11), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
677         // This rect extends past left/right ends of |child2|.
678         EXPECT_EQ_RECT(IntRect(20, 39, 80, 60), occlusion.unoccludedContentRect(parent, IntRect(20, 39, 80, 60)));
679         EXPECT_EQ_RECT(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(31, 40, 70, 60)));
680         EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 41, 70, 60)));
681
682         /* Justification for the above occlusion from |layer|:
683                    100
684           +---------------------+                                      +---------------------+
685           |                     |                                      |                     |30  Visible region of |layer|: /////
686           |    30               |           rotate(90)                 |     30   60         |    |child2|: \\\\\
687           | 30 + ------------+--------------------+                    |  30 +------------+--------------------+
688       100 |    |  10         |  |                 |            ==>     |     |\\\\\\\\\\\\|  |10               |
689           |    |10+----------|----------------------+                  |  +--|\\\\\\\\\\\\|-----------------+  |
690           |    + ------------+  |                 | |                  |  |  +------------+//|     420      |  |
691           |    |  |             |                 | |                  |  |  |///////////////|60            |  |
692           |    |  |             |                 | |                  |  |  |///////////////|              |  |
693           +----|--|-------------+                 | |                  +--|--|---------------+              |  |
694                |  |                               | |                   20|10|     70                       |  |
695                |  |                               | |                     |  |                              |  |
696                |  |                               | |500                  |  |                              |  |
697                |  |                               | |                     |  |                              |  |
698                |  |                               | |                     |  |                              |  |
699                |  |                               | |                     |  |                              |  |
700                |  |                               | |                     |  |                              |10|
701                +--|-------------------------------+ |                     |  +------------------------------|--+
702                   |                                 |                     |                 490             |
703                   +---------------------------------+                     +---------------------------------+
704                                  500                                                     500
705          */
706     }
707 };
708
709 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestVisitTargetTwoTimes);
710
711 template<class Types, bool opaqueLayers>
712 class CCOcclusionTrackerTestSurfaceRotatedOffAxis : public CCOcclusionTrackerTest<Types, opaqueLayers> {
713 protected:
714     void runMyTest()
715     {
716         TransformationMatrix childTransform;
717         childTransform.translate(250, 250);
718         childTransform.rotate(95);
719         childTransform.translate(-250, -250);
720
721         TransformationMatrix layerTransform;
722         layerTransform.translate(10, 10);
723
724         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
725         typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
726         child->setMasksToBounds(true);
727         typename Types::ContentLayerType* layer = this->createDrawingLayer(child, layerTransform, FloatPoint(0, 0), IntSize(500, 500), true);
728         calcDrawEtc(parent);
729
730         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
731         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
732
733         IntRect clippedLayerInChild = layerTransform.mapRect(layer->visibleLayerRect());
734
735         occlusion.enterTargetRenderSurface(child->renderSurface());
736         occlusion.markOccludedBehindLayer(layer);
737
738         EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInScreenSpace().bounds());
739         EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
740         EXPECT_EQ_RECT(clippedLayerInChild, occlusion.occlusionInTargetSurface().bounds());
741         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
742
743         EXPECT_TRUE(occlusion.occluded(child, clippedLayerInChild));
744         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
745         clippedLayerInChild.move(-1, 0);
746         EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
747         EXPECT_FALSE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
748         clippedLayerInChild.move(1, 0);
749         clippedLayerInChild.move(1, 0);
750         EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
751         EXPECT_FALSE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
752         clippedLayerInChild.move(-1, 0);
753         clippedLayerInChild.move(0, -1);
754         EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
755         EXPECT_FALSE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
756         clippedLayerInChild.move(0, 1);
757         clippedLayerInChild.move(0, 1);
758         EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
759         EXPECT_FALSE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
760         clippedLayerInChild.move(0, -1);
761
762         occlusion.markOccludedBehindLayer(child);
763         occlusion.finishedTargetRenderSurface(child, child->renderSurface());
764         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
765
766         EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInScreenSpace().bounds());
767         EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
768         EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInTargetSurface().bounds());
769         EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
770
771         EXPECT_FALSE(occlusion.occluded(parent, IntRect(75, 55, 1, 1)));
772         EXPECT_EQ_RECT(IntRect(75, 55, 1, 1), occlusion.unoccludedContentRect(parent, IntRect(75, 55, 1, 1)));
773     }
774 };
775
776 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestSurfaceRotatedOffAxis);
777
778 template<class Types, bool opaqueLayers>
779 class CCOcclusionTrackerTestSurfaceWithTwoOpaqueChildren : public CCOcclusionTrackerTest<Types, opaqueLayers> {
780 protected:
781     void runMyTest()
782     {
783         TransformationMatrix childTransform;
784         childTransform.translate(250, 250);
785         childTransform.rotate(90);
786         childTransform.translate(-250, -250);
787
788         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
789         typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
790         child->setMasksToBounds(true);
791         typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
792         typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 450), IntSize(500, 60), true);
793         calcDrawEtc(parent);
794
795         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
796         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
797
798         occlusion.enterTargetRenderSurface(child->renderSurface());
799         occlusion.markOccludedBehindLayer(layer2);
800         occlusion.markOccludedBehindLayer(layer1);
801
802         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
803         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
804         EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
805         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
806
807         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
808         EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
809         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
810         EXPECT_FALSE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
811         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
812
813         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
814         EXPECT_EQ_RECT(IntRect(9, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)));
815         EXPECT_EQ_RECT(IntRect(10, 429, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)));
816         EXPECT_EQ_RECT(IntRect(70, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)));
817         EXPECT_EQ_RECT(IntRect(10, 500, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)));
818
819         occlusion.markOccludedBehindLayer(child);
820         occlusion.finishedTargetRenderSurface(child, child->renderSurface());
821         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
822
823         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
824         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
825         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
826         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
827
828         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
829         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
830         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
831
832         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 40, 70, 60)).isEmpty());
833         EXPECT_EQ_RECT(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(29, 40, 70, 60)));
834         EXPECT_EQ_RECT(IntRect(30, 39, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 39, 70, 60)));
835         EXPECT_EQ_RECT(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(31, 40, 70, 60)));
836         EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 41, 70, 60)));
837
838         /* Justification for the above occlusion from |layer1| and |layer2|:
839
840            +---------------------+
841            |                     |30  Visible region of |layer1|: /////
842            |                     |    Visible region of |layer2|: \\\\\
843            |     +---------------------------------+
844            |     |               |10               |
845            |  +---------------+-----------------+  |
846            |  |  |\\\\\\\\\\\\|//|     420      |  |
847            |  |  |\\\\\\\\\\\\|//|60            |  |
848            |  |  |\\\\\\\\\\\\|//|              |  |
849            +--|--|------------|--+              |  |
850             20|10|     70     |                 |  |
851               |  |            |                 |  |
852               |  |            |                 |  |
853               |  |            |                 |  |
854               |  |            |                 |  |
855               |  |            |                 |  |
856               |  |            |                 |10|
857               |  +------------|-----------------|--+
858               |               | 490             |
859               +---------------+-----------------+
860                      60               440
861          */
862     }
863 };
864
865 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
866
867 template<class Types, bool opaqueLayers>
868 class CCOcclusionTrackerTestOverlappingSurfaceSiblings : public CCOcclusionTrackerTest<Types, opaqueLayers> {
869 protected:
870     void runMyTest()
871     {
872         TransformationMatrix childTransform;
873         childTransform.translate(250, 250);
874         childTransform.rotate(90);
875         childTransform.translate(-250, -250);
876
877         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
878         typename Types::LayerType* child1 = this->createSurface(parent, childTransform, FloatPoint(30, 30), IntSize(10, 10));
879         typename Types::LayerType* child2 = this->createSurface(parent, childTransform, FloatPoint(20, 40), IntSize(10, 10));
880         typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
881         typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
882         calcDrawEtc(parent);
883
884         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
885         occlusion.setLayerScissorRect(IntRect(-20, -20, 1000, 1000));
886
887         occlusion.enterTargetRenderSurface(child2->renderSurface());
888         occlusion.markOccludedBehindLayer(layer2);
889
890         EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
891         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
892         EXPECT_EQ_RECT(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
893         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
894
895         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
896         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
897         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
898         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
899         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
900
901         occlusion.useDefaultLayerScissorRect();
902         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
903         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
904         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
905         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
906         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
907         occlusion.setLayerScissorRect(IntRect(-20, -20, 1000, 1000));
908
909         occlusion.markOccludedBehindLayer(child2);
910         occlusion.finishedTargetRenderSurface(child2, child2->renderSurface());
911         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
912         occlusion.enterTargetRenderSurface(child1->renderSurface());
913         occlusion.markOccludedBehindLayer(layer1);
914
915         EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
916         EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
917         EXPECT_EQ_RECT(IntRect(-10, 430, 80, 70), occlusion.occlusionInTargetSurface().bounds());
918         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
919
920         EXPECT_TRUE(occlusion.occluded(child1, IntRect(-10, 430, 80, 70)));
921         EXPECT_FALSE(occlusion.occluded(child1, IntRect(-11, 430, 80, 70)));
922         EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 429, 80, 70)));
923         EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 430, 81, 70)));
924         EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 430, 80, 71)));
925
926         occlusion.markOccludedBehindLayer(child1);
927         occlusion.finishedTargetRenderSurface(child1, child1->renderSurface());
928         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
929
930         EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
931         EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
932         EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInTargetSurface().bounds());
933         EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
934
935         EXPECT_FALSE(occlusion.occluded(parent, IntRect(20, 20, 80, 80)));
936
937         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 20, 70, 80)));
938         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 20, 70, 80)));
939         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 19, 70, 80)));
940
941         EXPECT_TRUE(occlusion.occluded(parent, IntRect(20, 30, 80, 70)));
942         EXPECT_FALSE(occlusion.occluded(parent, IntRect(19, 30, 80, 70)));
943         EXPECT_FALSE(occlusion.occluded(parent, IntRect(20, 29, 80, 70)));
944
945         /* Justification for the above occlusion:
946                    100
947           +---------------------+
948           |    20               |       layer1
949           |  30+ ---------------------------------+
950       100 |  30|                |     layer2      |
951           |20+----------------------------------+ |
952           |  | |                |               | |
953           |  | |                |               | |
954           |  | |                |               | |
955           +--|-|----------------+               | |
956              | |                                | | 510
957              | |                                | |
958              | |                                | |
959              | |                                | |
960              | |                                | |
961              | |                                | |
962              | |                                | |
963              | +--------------------------------|-+
964              |                                  |
965              +----------------------------------+
966                              510
967          */
968     }
969 };
970
971 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestOverlappingSurfaceSiblings);
972
973 template<class Types, bool opaqueLayers>
974 class CCOcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms : public CCOcclusionTrackerTest<Types, opaqueLayers> {
975 protected:
976     void runMyTest()
977     {
978         TransformationMatrix child1Transform;
979         child1Transform.translate(250, 250);
980         child1Transform.rotate(-90);
981         child1Transform.translate(-250, -250);
982
983         TransformationMatrix child2Transform;
984         child2Transform.translate(250, 250);
985         child2Transform.rotate(90);
986         child2Transform.translate(-250, -250);
987
988         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
989         typename Types::LayerType* child1 = this->createSurface(parent, child1Transform, FloatPoint(30, 20), IntSize(10, 10));
990         typename Types::LayerType* child2 = this->createSurface(parent, child2Transform, FloatPoint(20, 40), IntSize(10, 10));
991         typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, FloatPoint(-10, -20), IntSize(510, 510), true);
992         typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
993         calcDrawEtc(parent);
994
995         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
996         occlusion.setLayerScissorRect(IntRect(-30, -30, 1000, 1000));
997
998         occlusion.enterTargetRenderSurface(child2->renderSurface());
999         occlusion.markOccludedBehindLayer(layer2);
1000
1001         EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
1002         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1003         EXPECT_EQ_RECT(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
1004         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1005
1006         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
1007         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
1008         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
1009         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
1010         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
1011
1012         occlusion.markOccludedBehindLayer(child2);
1013         occlusion.finishedTargetRenderSurface(child2, child2->renderSurface());
1014         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1015         occlusion.enterTargetRenderSurface(child1->renderSurface());
1016         occlusion.markOccludedBehindLayer(layer1);
1017
1018         EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
1019         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1020         EXPECT_EQ_RECT(IntRect(420, -20, 80, 90), occlusion.occlusionInTargetSurface().bounds());
1021         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1022
1023         EXPECT_TRUE(occlusion.occluded(child1, IntRect(420, -20, 80, 90)));
1024         EXPECT_FALSE(occlusion.occluded(child1, IntRect(419, -20, 80, 90)));
1025         EXPECT_FALSE(occlusion.occluded(child1, IntRect(420, -21, 80, 90)));
1026         EXPECT_FALSE(occlusion.occluded(child1, IntRect(420, -19, 80, 90)));
1027         EXPECT_FALSE(occlusion.occluded(child1, IntRect(421, -20, 80, 90)));
1028
1029         occlusion.markOccludedBehindLayer(child1);
1030         occlusion.finishedTargetRenderSurface(child1, child1->renderSurface());
1031         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1032
1033         EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
1034         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1035         EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInTargetSurface().bounds());
1036         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1037
1038         EXPECT_TRUE(occlusion.occluded(parent, IntRect(10, 20, 90, 80)));
1039         EXPECT_FALSE(occlusion.occluded(parent, IntRect(9, 20, 90, 80)));
1040         EXPECT_FALSE(occlusion.occluded(parent, IntRect(10, 19, 90, 80)));
1041         EXPECT_FALSE(occlusion.occluded(parent, IntRect(11, 20, 90, 80)));
1042         EXPECT_FALSE(occlusion.occluded(parent, IntRect(10, 21, 90, 80)));
1043
1044         /* Justification for the above occlusion:
1045                       100
1046             +---------------------+
1047             |20                   |       layer1
1048            10+----------------------------------+
1049         100 || 30                 |     layer2  |
1050             |20+----------------------------------+
1051             || |                  |             | |
1052             || |                  |             | |
1053             || |                  |             | |
1054             +|-|------------------+             | |
1055              | |                                | | 510
1056              | |                            510 | |
1057              | |                                | |
1058              | |                                | |
1059              | |                                | |
1060              | |                                | |
1061              | |                520             | |
1062              +----------------------------------+ |
1063                |                                  |
1064                +----------------------------------+
1065                                510
1066          */
1067     }
1068 };
1069
1070 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
1071
1072 template<class Types, bool opaqueLayers>
1073 class CCOcclusionTrackerTestFilters : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1074 protected:
1075     void runMyTest()
1076     {
1077         TransformationMatrix layerTransform;
1078         layerTransform.translate(250, 250);
1079         layerTransform.rotate(90);
1080         layerTransform.translate(-250, -250);
1081
1082         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
1083         typename Types::ContentLayerType* blurLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
1084         typename Types::ContentLayerType* opacityLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
1085         typename Types::ContentLayerType* opaqueLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
1086
1087         FilterOperations filters;
1088         filters.operations().append(BlurFilterOperation::create(Length(10, WebCore::Percent), FilterOperation::BLUR));
1089         blurLayer->setFilters(filters);
1090
1091         filters.operations().clear();
1092         filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
1093         opaqueLayer->setFilters(filters);
1094
1095         filters.operations().clear();
1096         filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::OPACITY));
1097         opacityLayer->setFilters(filters);
1098
1099         calcDrawEtc(parent);
1100
1101         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1102         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1103
1104         // Opacity layer won't contribute to occlusion.
1105         occlusion.enterTargetRenderSurface(opacityLayer->renderSurface());
1106         occlusion.markOccludedBehindLayer(opacityLayer);
1107         occlusion.finishedTargetRenderSurface(opacityLayer, opacityLayer->renderSurface());
1108
1109         EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1110         EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1111
1112         // And has nothing to contribute to its parent surface.
1113         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1114         EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1115         EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1116
1117         // Opaque layer will contribute to occlusion.
1118         occlusion.enterTargetRenderSurface(opaqueLayer->renderSurface());
1119         occlusion.markOccludedBehindLayer(opaqueLayer);
1120         occlusion.finishedTargetRenderSurface(opaqueLayer, opaqueLayer->renderSurface());
1121
1122         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
1123         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1124         EXPECT_EQ_RECT(IntRect(0, 430, 70, 70), occlusion.occlusionInTargetSurface().bounds());
1125         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1126
1127         // And it gets translated to the parent surface.
1128         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1129         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
1130         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1131         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
1132         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1133
1134         // The blur layer needs to throw away any occlusion from outside its subtree.
1135         occlusion.enterTargetRenderSurface(blurLayer->renderSurface());
1136         EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1137         EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1138
1139         // And it won't contribute to occlusion.
1140         occlusion.markOccludedBehindLayer(blurLayer);
1141         occlusion.finishedTargetRenderSurface(blurLayer, blurLayer->renderSurface());
1142         EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1143         EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1144
1145         // But the opaque layer's occlusion is preserved on the parent.
1146         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1147         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
1148         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1149         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
1150         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1151     }
1152 };
1153
1154 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestFilters);
1155
1156 template<class Types, bool opaqueLayers>
1157 class CCOcclusionTrackerTestLayerScissorRectOutsideChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1158 protected:
1159     void runMyTest()
1160     {
1161         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1162         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1163         calcDrawEtc(parent);
1164
1165         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1166         occlusion.setLayerScissorRect(IntRect(200, 100, 100, 100));
1167
1168         occlusion.enterTargetRenderSurface(layer->renderSurface());
1169
1170         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1171         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1172         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1173         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1174         EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1175
1176         occlusion.useDefaultLayerScissorRect();
1177         EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1178         occlusion.setLayerScissorRect(IntRect(200, 100, 100, 100));
1179
1180         occlusion.markOccludedBehindLayer(layer);
1181         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1182
1183         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1184         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1185         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1186         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1187         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1188         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1189         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1190         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1191         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1192
1193         EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1194     }
1195 };
1196
1197 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectOutsideChild);
1198
1199 template<class Types, bool opaqueLayers>
1200 class CCOcclusionTrackerTestScreenScissorRectOutsideChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1201 protected:
1202     void runMyTest()
1203     {
1204         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1205         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1206         calcDrawEtc(parent);
1207
1208         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(200, 100, 100, 100));
1209         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1210
1211         occlusion.enterTargetRenderSurface(layer->renderSurface());
1212
1213         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1214         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1215         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1216         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1217         EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1218
1219         occlusion.useDefaultLayerScissorRect();
1220         EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1221         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1222
1223         occlusion.markOccludedBehindLayer(layer);
1224         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1225
1226         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1227         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1228         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1229         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1230         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1231         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1232         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1233         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1234         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1235
1236         EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1237     }
1238 };
1239
1240 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectOutsideChild);
1241
1242 template<class Types, bool opaqueLayers>
1243 class CCOcclusionTrackerTestDamageRectOutsideChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1244 protected:
1245     void runMyTest()
1246     {
1247         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1248         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1249         calcDrawEtc(parent);
1250
1251         TestDamageClient<typename Types::RenderSurfaceType> damage(FloatRect(200, 100, 100, 100));
1252         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000), &damage);
1253
1254         occlusion.enterTargetRenderSurface(layer->renderSurface());
1255
1256         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 200, 200)).isEmpty());
1257
1258         occlusion.markOccludedBehindLayer(layer);
1259         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1260
1261         EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1262     }
1263 };
1264
1265 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestDamageRectOutsideChild);
1266
1267 template<class Types, bool opaqueLayers>
1268 class CCOcclusionTrackerTestLayerScissorRectOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1269 protected:
1270     void runMyTest()
1271     {
1272         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1273         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1274         calcDrawEtc(parent);
1275
1276         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1277         occlusion.setLayerScissorRect(IntRect(100, 100, 100, 100));
1278
1279         occlusion.enterTargetRenderSurface(layer->renderSurface());
1280
1281         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1282         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1283         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1284         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1285
1286         occlusion.markOccludedBehindLayer(layer);
1287         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1288
1289         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1290         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1291         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1292         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1293         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1294         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1295         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1296         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1297         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1298
1299         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1300     }
1301 };
1302
1303 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectOverChild);
1304
1305 template<class Types, bool opaqueLayers>
1306 class CCOcclusionTrackerTestScreenScissorRectOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1307 protected:
1308     void runMyTest()
1309     {
1310         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1311         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1312         calcDrawEtc(parent);
1313
1314         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(100, 100, 100, 100));
1315         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1316
1317         occlusion.enterTargetRenderSurface(layer->renderSurface());
1318
1319         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1320         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1321         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1322         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1323
1324         occlusion.markOccludedBehindLayer(layer);
1325         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1326
1327         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1328         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1329         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1330         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1331         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1332         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1333         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1334         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1335         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1336
1337         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1338     }
1339 };
1340
1341 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectOverChild);
1342
1343 template<class Types, bool opaqueLayers>
1344 class CCOcclusionTrackerTestDamageRectOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1345 protected:
1346     void runMyTest()
1347     {
1348         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1349         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1350         calcDrawEtc(parent);
1351
1352         TestDamageClient<typename Types::RenderSurfaceType> damage(FloatRect(100, 100, 100, 100));
1353         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000), &damage);
1354
1355         occlusion.enterTargetRenderSurface(layer->renderSurface());
1356
1357         EXPECT_EQ_RECT(IntRect(100, 100, 100, 100), occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)));
1358
1359         occlusion.markOccludedBehindLayer(layer);
1360         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1361
1362         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1363     }
1364 };
1365
1366 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestDamageRectOverChild);
1367
1368 template<class Types, bool opaqueLayers>
1369 class CCOcclusionTrackerTestLayerScissorRectPartlyOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1370 protected:
1371     void runMyTest()
1372     {
1373         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1374         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1375         calcDrawEtc(parent);
1376
1377         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1378         occlusion.setLayerScissorRect(IntRect(50, 50, 200, 200));
1379
1380         occlusion.enterTargetRenderSurface(layer->renderSurface());
1381
1382         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1383         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1384         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1385         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1386
1387         occlusion.markOccludedBehindLayer(layer);
1388         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1389
1390         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1391         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1392         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1393         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1394         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1395         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1396         EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1397         EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1398         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1399
1400         EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1401         EXPECT_EQ_RECT(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)));
1402         EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)));
1403         EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)));
1404         EXPECT_EQ_RECT(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)));
1405     }
1406 };
1407
1408 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectPartlyOverChild);
1409
1410 template<class Types, bool opaqueLayers>
1411 class CCOcclusionTrackerTestScreenScissorRectPartlyOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1412 protected:
1413     void runMyTest()
1414     {
1415         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1416         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1417         calcDrawEtc(parent);
1418
1419         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(50, 50, 200, 200));
1420         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1421
1422         occlusion.enterTargetRenderSurface(layer->renderSurface());
1423
1424         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1425         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1426         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1427         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1428
1429         occlusion.markOccludedBehindLayer(layer);
1430         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1431
1432         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1433         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1434         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1435         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1436         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1437         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1438         EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1439         EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1440         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1441
1442         EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1443         EXPECT_EQ_RECT(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)));
1444         EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)));
1445         EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)));
1446         EXPECT_EQ_RECT(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)));
1447     }
1448 };
1449
1450 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectPartlyOverChild);
1451
1452 template<class Types, bool opaqueLayers>
1453 class CCOcclusionTrackerTestDamageRectPartlyOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1454 protected:
1455     void runMyTest()
1456     {
1457         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1458         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1459         calcDrawEtc(parent);
1460
1461         TestDamageClient<typename Types::RenderSurfaceType> damage(FloatRect(50, 50, 200, 200));
1462         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000), &damage);
1463
1464         occlusion.enterTargetRenderSurface(layer->renderSurface());
1465
1466         EXPECT_EQ_RECT(IntRect(50, 50, 150, 150), occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)));
1467
1468         occlusion.markOccludedBehindLayer(layer);
1469         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1470
1471         EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1472     }
1473 };
1474
1475 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestDamageRectPartlyOverChild);
1476
1477 template<class Types, bool opaqueLayers>
1478 class CCOcclusionTrackerTestLayerScissorRectOverNothing : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1479 protected:
1480     void runMyTest()
1481     {
1482         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1483         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1484         calcDrawEtc(parent);
1485
1486         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1487         occlusion.setLayerScissorRect(IntRect(500, 500, 100, 100));
1488
1489         occlusion.enterTargetRenderSurface(layer->renderSurface());
1490
1491         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1492         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1493         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1494         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1495
1496         occlusion.markOccludedBehindLayer(layer);
1497         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1498
1499         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1500         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1501         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1502         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1503         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1504         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1505         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1506         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1507         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1508
1509         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1510         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)).isEmpty());
1511         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)).isEmpty());
1512         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)).isEmpty());
1513         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)).isEmpty());
1514     }
1515 };
1516
1517 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectOverNothing);
1518
1519 template<class Types, bool opaqueLayers>
1520 class CCOcclusionTrackerTestScreenScissorRectOverNothing : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1521 protected:
1522     void runMyTest()
1523     {
1524         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1525         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1526         calcDrawEtc(parent);
1527
1528         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(500, 500, 100, 100));
1529         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1530
1531         occlusion.enterTargetRenderSurface(layer->renderSurface());
1532
1533         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1534         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1535         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1536         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1537
1538         occlusion.markOccludedBehindLayer(layer);
1539         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1540
1541         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1542         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1543         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1544         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1545         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1546         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1547         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1548         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1549         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1550
1551         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1552         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)).isEmpty());
1553         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)).isEmpty());
1554         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)).isEmpty());
1555         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)).isEmpty());
1556     }
1557 };
1558
1559 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectOverNothing);
1560
1561 template<class Types, bool opaqueLayers>
1562 class CCOcclusionTrackerTestDamageRectOverNothing : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1563 protected:
1564     void runMyTest()
1565     {
1566         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1567         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1568         calcDrawEtc(parent);
1569
1570         TestDamageClient<typename Types::RenderSurfaceType> damage(FloatRect(500, 500, 100, 100));
1571         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000), &damage);
1572
1573         occlusion.enterTargetRenderSurface(layer->renderSurface());
1574
1575         EXPECT_TRUE(occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)).isEmpty());
1576
1577         occlusion.markOccludedBehindLayer(layer);
1578         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1579
1580         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1581     }
1582 };
1583
1584 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestDamageRectOverNothing);
1585
1586 template<class Types, bool opaqueLayers>
1587 class CCOcclusionTrackerTestLayerScissorRectForLayerOffOrigin : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1588 protected:
1589     void runMyTest()
1590     {
1591         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1592         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1593         calcDrawEtc(parent);
1594
1595         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1596         occlusion.enterTargetRenderSurface(layer->renderSurface());
1597
1598         // This layer is translated when drawn into its target. So if the scissor rect given from the target surface
1599         // is not in that target space, then after translating these query rects into the target, they will fall outside
1600         // the scissor and be considered occluded.
1601         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1602         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1603         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1604         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1605     }
1606 };
1607
1608 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectForLayerOffOrigin);
1609
1610 template<class Types, bool opaqueLayers>
1611 class CCOcclusionTrackerTestOpaqueContentsRegionEmpty : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1612 protected:
1613     void runMyTest()
1614     {
1615         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1616         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), false);
1617         calcDrawEtc(parent);
1618
1619         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1620         occlusion.enterTargetRenderSurface(layer->renderSurface());
1621
1622         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1623         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1624         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1625         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1626
1627         // Occluded since its outside the surface bounds.
1628         EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1629
1630         // Test without any scissors.
1631         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1632         EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1633         occlusion.useDefaultLayerScissorRect();
1634
1635         occlusion.markOccludedBehindLayer(layer);
1636         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1637
1638         EXPECT_TRUE(occlusion.occlusionInScreenSpace().bounds().isEmpty());
1639         EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
1640     }
1641 };
1642
1643 MAIN_AND_IMPL_THREAD_TEST(CCOcclusionTrackerTestOpaqueContentsRegionEmpty);
1644
1645 template<class Types, bool opaqueLayers>
1646 class CCOcclusionTrackerTestOpaqueContentsRegionNonEmpty : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1647 protected:
1648     void runMyTest()
1649     {
1650         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1651         typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(100, 100), IntSize(200, 200), false);
1652         calcDrawEtc(parent);
1653
1654         {
1655             TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1656             layer->setOpaqueContentsRect(IntRect(0, 0, 100, 100));
1657
1658             occlusion.enterTargetRenderSurface(parent->renderSurface());
1659             occlusion.markOccludedBehindLayer(layer);
1660
1661             EXPECT_EQ_RECT(IntRect(100, 100, 100, 100), occlusion.occlusionInScreenSpace().bounds());
1662             EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1663
1664             EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1665             EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1666             EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1667         }
1668
1669         {
1670             TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1671             layer->setOpaqueContentsRect(IntRect(20, 20, 180, 180));
1672
1673             occlusion.enterTargetRenderSurface(parent->renderSurface());
1674             occlusion.markOccludedBehindLayer(layer);
1675
1676             EXPECT_EQ_RECT(IntRect(120, 120, 180, 180), occlusion.occlusionInScreenSpace().bounds());
1677             EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1678
1679             EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1680             EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1681             EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1682         }
1683
1684         {
1685             TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1686             layer->setOpaqueContentsRect(IntRect(150, 150, 100, 100));
1687
1688             occlusion.enterTargetRenderSurface(parent->renderSurface());
1689             occlusion.markOccludedBehindLayer(layer);
1690
1691             EXPECT_EQ_RECT(IntRect(250, 250, 50, 50), occlusion.occlusionInScreenSpace().bounds());
1692             EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1693
1694             EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1695             EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1696             EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1697         }
1698     }
1699 };
1700
1701 MAIN_AND_IMPL_THREAD_TEST(CCOcclusionTrackerTestOpaqueContentsRegionNonEmpty);
1702
1703 } // namespace