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