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