2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "cc/CCOcclusionTracker.h"
29 #include "FilterOperations.h"
30 #include "LayerChromium.h"
32 #include "TransformationMatrix.h"
33 #include "cc/CCLayerImpl.h"
34 #include "cc/CCLayerTreeHostCommon.h"
35 #include "cc/CCSingleThreadProxy.h"
37 #include <gmock/gmock.h>
38 #include <gtest/gtest.h>
40 using namespace WebCore;
42 #define EXPECT_EQ_RECT(a, b) \
43 EXPECT_EQ(a.x(), b.x()); \
44 EXPECT_EQ(a.y(), b.y()); \
45 EXPECT_EQ(a.width(), b.width()); \
46 EXPECT_EQ(a.height(), b.height());
50 class TestContentLayerChromium : public LayerChromium {
52 TestContentLayerChromium() : LayerChromium() { }
54 virtual bool drawsContent() const { return true; }
55 virtual Region opaqueContentsRegion() const { return intersection(m_opaqueContentsRect, visibleLayerRect()); }
56 void setOpaqueContentsRect(const IntRect& opaqueContentsRect) { m_opaqueContentsRect = opaqueContentsRect; }
59 IntRect m_opaqueContentsRect;
62 class TestContentLayerImpl : public CCLayerImpl {
64 TestContentLayerImpl(int id) : CCLayerImpl(id) { setDrawsContent(true); }
66 virtual Region opaqueContentsRegion() const { return intersection(m_opaqueContentsRect, visibleLayerRect()); }
67 void setOpaqueContentsRect(const IntRect& opaqueContentsRect) { m_opaqueContentsRect = opaqueContentsRect; }
69 IntRect m_opaqueContentsRect;
72 // A subclass to expose the total current occlusion.
73 template<typename LayerType, typename RenderSurfaceType>
74 class TestCCOcclusionTrackerBase : public CCOcclusionTrackerBase<LayerType, RenderSurfaceType> {
76 TestCCOcclusionTrackerBase(IntRect screenScissorRect)
77 : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>(screenScissorRect)
78 , m_overrideLayerScissorRect(false)
82 Region occlusionInScreenSpace() const { return CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInScreen; }
83 Region occlusionInTargetSurface() const { return CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInTarget; }
85 void setOcclusionInScreenSpace(const Region& region) { CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInScreen = region; }
86 void setOcclusionInTargetSurface(const Region& region) { CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInTarget = region; }
88 void setLayerScissorRect(const IntRect& rect) { m_overrideLayerScissorRect = true; m_layerScissorRect = rect;}
89 void useDefaultLayerScissorRect() { m_overrideLayerScissorRect = false; }
92 virtual IntRect layerScissorRectInTargetSurface(const LayerType* layer) const { return m_overrideLayerScissorRect ? m_layerScissorRect : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::layerScissorRectInTargetSurface(layer); }
95 bool m_overrideLayerScissorRect;
96 IntRect m_layerScissorRect;
99 struct CCOcclusionTrackerTestMainThreadTypes {
100 typedef LayerChromium LayerType;
101 typedef RenderSurfaceChromium RenderSurfaceType;
102 typedef TestContentLayerChromium ContentLayerType;
103 typedef RefPtr<LayerChromium> LayerPtrType;
104 typedef PassRefPtr<LayerChromium> PassLayerPtrType;
105 typedef RefPtr<ContentLayerType> ContentLayerPtrType;
106 typedef PassRefPtr<ContentLayerType> PassContentLayerPtrType;
108 static PassLayerPtrType createLayer() { return LayerChromium::create(); }
109 static PassContentLayerPtrType createContentLayer() { return adoptRef(new ContentLayerType()); }
112 struct CCOcclusionTrackerTestImplThreadTypes {
113 typedef CCLayerImpl LayerType;
114 typedef CCRenderSurface RenderSurfaceType;
115 typedef TestContentLayerImpl ContentLayerType;
116 typedef OwnPtr<CCLayerImpl> LayerPtrType;
117 typedef PassOwnPtr<CCLayerImpl> PassLayerPtrType;
118 typedef OwnPtr<ContentLayerType> ContentLayerPtrType;
119 typedef PassOwnPtr<ContentLayerType> PassContentLayerPtrType;
121 static PassLayerPtrType createLayer() { return CCLayerImpl::create(nextCCLayerImplId++); }
122 static PassContentLayerPtrType createContentLayer() { return adoptPtr(new ContentLayerType(nextCCLayerImplId++)); }
123 static int nextCCLayerImplId;
126 int CCOcclusionTrackerTestImplThreadTypes::nextCCLayerImplId = 0;
128 template<typename Types, bool opaqueLayers>
129 class CCOcclusionTrackerTest : public testing::Test {
131 CCOcclusionTrackerTest() : testing::Test() { }
133 virtual void runMyTest() = 0;
135 virtual void TearDown()
138 m_renderSurfaceLayerListChromium.clear();
139 m_renderSurfaceLayerListImpl.clear();
142 typename Types::ContentLayerType* createRoot(const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
144 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
145 typename Types::ContentLayerType* layerPtr = layer.get();
146 setProperties(layerPtr, transform, position, bounds);
149 m_root = layer.release();
153 typename Types::LayerType* createLayer(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
155 typename Types::LayerPtrType layer(Types::createLayer());
156 typename Types::LayerType* layerPtr = layer.get();
157 setProperties(layerPtr, transform, position, bounds);
158 parent->addChild(layer.release());
162 typename Types::LayerType* createSurface(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
164 typename Types::LayerType* layer = createLayer(parent, transform, position, bounds);
165 FilterOperations filters;
166 filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
167 layer->setFilters(filters);
171 typename Types::ContentLayerType* createDrawingLayer(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque)
173 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
174 typename Types::ContentLayerType* layerPtr = layer.get();
175 setProperties(layerPtr, transform, position, bounds);
178 layerPtr->setOpaque(opaque);
180 layerPtr->setOpaque(false);
182 layerPtr->setOpaqueContentsRect(IntRect(IntPoint(), bounds));
184 layerPtr->setOpaqueContentsRect(IntRect());
187 parent->addChild(layer.release());
191 typename Types::ContentLayerType* createDrawingSurface(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque)
193 typename Types::ContentLayerType* layer = createDrawingLayer(parent, transform, position, bounds, opaque);
194 FilterOperations filters;
195 filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
196 layer->setFilters(filters);
201 TestContentLayerImpl* calcDrawEtc(TestContentLayerImpl* root)
203 ASSERT(root == m_root.get());
204 Vector<CCLayerImpl*> dummyLayerList;
205 int dummyMaxTextureSize = 512;
207 ASSERT(!root->renderSurface());
208 root->createRenderSurface();
209 root->renderSurface()->setContentRect(IntRect(IntPoint::zero(), root->bounds()));
210 root->setClipRect(IntRect(IntPoint::zero(), root->bounds()));
211 m_renderSurfaceLayerListImpl.append(m_root.get());
213 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(root, root, identityMatrix, identityMatrix, m_renderSurfaceLayerListImpl, dummyLayerList, 0, dummyMaxTextureSize);
217 TestContentLayerChromium* calcDrawEtc(TestContentLayerChromium* root)
219 ASSERT(root == m_root.get());
220 Vector<RefPtr<LayerChromium> > dummyLayerList;
221 int dummyMaxTextureSize = 512;
223 ASSERT(!root->renderSurface());
224 root->createRenderSurface();
225 root->renderSurface()->setContentRect(IntRect(IntPoint::zero(), root->bounds()));
226 root->setClipRect(IntRect(IntPoint::zero(), root->bounds()));
227 m_renderSurfaceLayerListChromium.append(m_root);
229 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(root, root, identityMatrix, identityMatrix, m_renderSurfaceLayerListChromium, dummyLayerList, dummyMaxTextureSize);
233 const TransformationMatrix identityMatrix;
236 void setBaseProperties(typename Types::LayerType* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
238 layer->setTransform(transform);
239 layer->setSublayerTransform(TransformationMatrix());
240 layer->setAnchorPoint(FloatPoint(0, 0));
241 layer->setPosition(position);
242 layer->setBounds(bounds);
245 void setProperties(LayerChromium* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
247 setBaseProperties(layer, transform, position, bounds);
250 void setProperties(CCLayerImpl* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
252 setBaseProperties(layer, transform, position, bounds);
254 layer->setContentBounds(layer->bounds());
257 // These hold ownership of the layers for the duration of the test.
258 typename Types::LayerPtrType m_root;
259 Vector<RefPtr<LayerChromium> > m_renderSurfaceLayerListChromium;
260 Vector<CCLayerImpl*> m_renderSurfaceLayerListImpl;
263 #define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
264 class ClassName##MainThreadOpaqueLayers : public ClassName<CCOcclusionTrackerTestMainThreadTypes, true> { \
266 ClassName##MainThreadOpaqueLayers() : ClassName<CCOcclusionTrackerTestMainThreadTypes, true>() { } \
268 TEST_F(ClassName##MainThreadOpaqueLayers, runTest) { runMyTest(); }
269 #define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
270 class ClassName##MainThreadOpaquePaints : public ClassName<CCOcclusionTrackerTestMainThreadTypes, false> { \
272 ClassName##MainThreadOpaquePaints() : ClassName<CCOcclusionTrackerTestMainThreadTypes, false>() { } \
274 TEST_F(ClassName##MainThreadOpaquePaints, runTest) { runMyTest(); }
276 #define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
277 class ClassName##ImplThreadOpaqueLayers : public ClassName<CCOcclusionTrackerTestImplThreadTypes, true> { \
278 DebugScopedSetImplThread impl; \
280 ClassName##ImplThreadOpaqueLayers() : ClassName<CCOcclusionTrackerTestImplThreadTypes, true>() { } \
282 TEST_F(ClassName##ImplThreadOpaqueLayers, runTest) { runMyTest(); }
283 #define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
284 class ClassName##ImplThreadOpaquePaints : public ClassName<CCOcclusionTrackerTestImplThreadTypes, false> { \
285 DebugScopedSetImplThread impl; \
287 ClassName##ImplThreadOpaquePaints() : ClassName<CCOcclusionTrackerTestImplThreadTypes, false>() { } \
289 TEST_F(ClassName##ImplThreadOpaquePaints, runTest) { runMyTest(); }
291 #define ALL_CCOCCLUSIONTRACKER_TEST(ClassName) \
292 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
293 RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
294 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
295 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
297 #define MAIN_THREAD_TEST(ClassName) \
298 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName)
300 #define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
301 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
302 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
304 template<class Types, bool opaqueLayers>
305 class CCOcclusionTrackerTestIdentityTransforms : public CCOcclusionTrackerTest<Types, opaqueLayers> {
309 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
310 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(30, 30), IntSize(500, 500), true);
311 this->calcDrawEtc(parent);
313 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
314 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
316 occlusion.enterTargetRenderSurface(parent->renderSurface());
317 occlusion.markOccludedBehindLayer(layer);
318 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
319 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
320 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
321 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
323 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
324 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
325 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
326 EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
327 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
329 occlusion.useDefaultLayerScissorRect();
330 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
331 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
332 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
333 EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
334 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
335 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
337 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)).isEmpty());
338 EXPECT_EQ_RECT(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 70, 70)));
339 EXPECT_EQ_RECT(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 29, 70, 70)));
340 EXPECT_EQ_RECT(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
341 EXPECT_EQ_RECT(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 29, 70, 70)));
342 EXPECT_EQ_RECT(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 70, 70)));
343 EXPECT_EQ_RECT(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 31, 70, 70)));
344 EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 31, 70, 70)));
345 EXPECT_EQ_RECT(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 31, 70, 70)));
349 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestIdentityTransforms);
351 template<class Types, bool opaqueLayers>
352 class CCOcclusionTrackerTestRotatedChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
356 TransformationMatrix layerTransform;
357 layerTransform.translate(250, 250);
358 layerTransform.rotate(90);
359 layerTransform.translate(-250, -250);
361 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
362 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
363 this->calcDrawEtc(parent);
365 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
366 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
368 occlusion.enterTargetRenderSurface(parent->renderSurface());
369 occlusion.markOccludedBehindLayer(layer);
370 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
371 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
372 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
373 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
375 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
376 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
377 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
378 EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
379 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
381 occlusion.useDefaultLayerScissorRect();
382 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
383 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
384 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
385 EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
386 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
387 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
389 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)).isEmpty());
390 EXPECT_EQ_RECT(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 70, 70)));
391 EXPECT_EQ_RECT(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 29, 70, 70)));
392 EXPECT_EQ_RECT(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
393 EXPECT_EQ_RECT(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 29, 70, 70)));
394 EXPECT_EQ_RECT(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 70, 70)));
395 EXPECT_EQ_RECT(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 31, 70, 70)));
396 EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 31, 70, 70)));
397 EXPECT_EQ_RECT(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 31, 70, 70)));
401 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestRotatedChild);
403 template<class Types, bool opaqueLayers>
404 class CCOcclusionTrackerTestTranslatedChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
408 TransformationMatrix layerTransform;
409 layerTransform.translate(20, 20);
411 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
412 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
413 this->calcDrawEtc(parent);
415 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
416 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
418 occlusion.enterTargetRenderSurface(parent->renderSurface());
419 occlusion.markOccludedBehindLayer(layer);
420 EXPECT_EQ_RECT(IntRect(50, 50, 50, 50), occlusion.occlusionInScreenSpace().bounds());
421 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
422 EXPECT_EQ_RECT(IntRect(50, 50, 50, 50), occlusion.occlusionInTargetSurface().bounds());
423 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
425 EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 50, 50, 50)));
426 EXPECT_FALSE(occlusion.occluded(parent, IntRect(49, 50, 50, 50)));
427 EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 49, 50, 50)));
428 EXPECT_FALSE(occlusion.occluded(parent, IntRect(51, 50, 50, 50)));
429 EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 51, 50, 50)));
431 occlusion.useDefaultLayerScissorRect();
432 EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 50, 50, 50)));
433 EXPECT_FALSE(occlusion.occluded(parent, IntRect(49, 50, 50, 50)));
434 EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 49, 50, 50)));
435 EXPECT_TRUE(occlusion.occluded(parent, IntRect(51, 50, 50, 50)));
436 EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 51, 50, 50)));
437 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
439 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 50, 50, 50)).isEmpty());
440 EXPECT_EQ_RECT(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 50, 50, 50)));
441 EXPECT_EQ_RECT(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 49, 50, 50)));
442 EXPECT_EQ_RECT(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 49, 50, 50)));
443 EXPECT_EQ_RECT(IntRect(51, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 49, 50, 50)));
444 EXPECT_EQ_RECT(IntRect(100, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 50, 50, 50)));
445 EXPECT_EQ_RECT(IntRect(51, 51, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 51, 50, 50)));
446 EXPECT_EQ_RECT(IntRect(50, 100, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 51, 50, 50)));
447 EXPECT_EQ_RECT(IntRect(49, 51, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 51, 50, 50)));
449 occlusion.useDefaultLayerScissorRect();
450 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 50, 50, 50)).isEmpty());
451 EXPECT_EQ_RECT(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 50, 50, 50)));
452 EXPECT_EQ_RECT(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 49, 50, 50)));
453 EXPECT_EQ_RECT(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 49, 50, 50)));
454 EXPECT_EQ_RECT(IntRect(51, 49, 49, 1), occlusion.unoccludedContentRect(parent, IntRect(51, 49, 50, 50)));
455 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(51, 50, 50, 50)).isEmpty());
456 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(51, 51, 50, 50)).isEmpty());
457 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 51, 50, 50)).isEmpty());
458 EXPECT_EQ_RECT(IntRect(49, 51, 1, 49), occlusion.unoccludedContentRect(parent, IntRect(49, 51, 50, 50)));
459 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
463 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestTranslatedChild);
465 template<class Types, bool opaqueLayers>
466 class CCOcclusionTrackerTestChildInRotatedChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
470 TransformationMatrix childTransform;
471 childTransform.translate(250, 250);
472 childTransform.rotate(90);
473 childTransform.translate(-250, -250);
475 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
476 typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
477 child->setMasksToBounds(true);
478 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
479 this->calcDrawEtc(parent);
481 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
482 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
484 occlusion.enterTargetRenderSurface(child->renderSurface());
485 occlusion.markOccludedBehindLayer(layer);
487 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
488 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
489 EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
490 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
492 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
493 EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
494 EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
495 EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 430, 61, 70)));
496 EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 430, 60, 71)));
498 occlusion.useDefaultLayerScissorRect();
499 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
500 EXPECT_TRUE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
501 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
502 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 61, 70)));
503 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 71)));
504 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
506 occlusion.markOccludedBehindLayer(child);
507 occlusion.finishedTargetRenderSurface(child, child->renderSurface());
508 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
510 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
511 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
512 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
513 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
515 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
516 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
517 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
518 EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 40, 70, 60)));
519 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 41, 70, 60)));
521 occlusion.useDefaultLayerScissorRect();
522 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
523 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
524 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
525 EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 40, 70, 60)));
526 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 41, 70, 60)));
527 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
530 /* Justification for the above occlusion from |layer|:
532 +---------------------+ +---------------------+
533 | | | |30 Visible region of |layer|: /////
534 | 30 | rotate(90) | |
535 | 30 + ---------------------------------+ | +---------------------------------+
536 100 | | 10 | | ==> | | |10 |
537 | |10+---------------------------------+ | +---------------------------------+ |
538 | | | | | | | | |///////////////| 420 | |
539 | | | | | | | | |///////////////|60 | |
540 | | | | | | | | |///////////////| | |
541 +----|--|-------------+ | | +--|--|---------------+ | |
542 | | | | 20|10| 70 | |
549 +--|-------------------------------+ | | +------------------------------|--+
551 +---------------------------------+ +---------------------------------+
557 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestChildInRotatedChild);
559 template<class Types, bool opaqueLayers>
560 class CCOcclusionTrackerTestVisitTargetTwoTimes : public CCOcclusionTrackerTest<Types, opaqueLayers> {
564 TransformationMatrix childTransform;
565 childTransform.translate(250, 250);
566 childTransform.rotate(90);
567 childTransform.translate(-250, -250);
569 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
570 typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
571 child->setMasksToBounds(true);
572 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
573 // |child2| makes |parent|'s surface get considered by CCOcclusionTracker first, instead of |child|'s. This exercises different code in
574 // leaveToTargetRenderSurface, as the target surface has already been seen.
575 typename Types::ContentLayerType* child2 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(30, 30), IntSize(60, 20), true);
576 this->calcDrawEtc(parent);
578 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
579 occlusion.setLayerScissorRect(IntRect(-10, -10, 1000, 1000));
581 occlusion.enterTargetRenderSurface(parent->renderSurface());
582 occlusion.markOccludedBehindLayer(child2);
584 EXPECT_EQ_RECT(IntRect(30, 30, 60, 20), occlusion.occlusionInScreenSpace().bounds());
585 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
586 EXPECT_EQ_RECT(IntRect(30, 30, 60, 20), occlusion.occlusionInTargetSurface().bounds());
587 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
589 occlusion.enterTargetRenderSurface(child->renderSurface());
590 occlusion.markOccludedBehindLayer(layer);
592 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
593 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
594 EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
595 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
597 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
598 EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
599 EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
600 EXPECT_FALSE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
601 EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
603 occlusion.useDefaultLayerScissorRect();
604 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
605 EXPECT_TRUE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
606 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
607 EXPECT_TRUE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
608 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
609 occlusion.setLayerScissorRect(IntRect(-10, -10, 1000, 1000));
611 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
612 // This is the little piece not occluded by child2
613 EXPECT_EQ_RECT(IntRect(9, 430, 1, 10), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)));
614 // This extends past both sides of child2, so it will be the original rect.
615 EXPECT_EQ_RECT(IntRect(9, 430, 60, 80), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 80)));
616 // This extends past two adjacent sides of child2, and should included the unoccluded parts of each side.
617 // This also demonstrates that the rect can be arbitrary and does not get clipped to the layer's visibleLayerRect().
618 EXPECT_EQ_RECT(IntRect(-10, 430, 20, 70), occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 70)));
619 // This extends past three adjacent sides of child2, so it should contain the unoccluded parts of each side. The left
620 // and bottom edges are completely unoccluded for some row/column so we get back the original query rect.
621 EXPECT_EQ_RECT(IntRect(-10, 430, 60, 80), occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 80)));
622 EXPECT_EQ_RECT(IntRect(10, 429, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)));
623 EXPECT_EQ_RECT(IntRect(70, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)));
624 EXPECT_EQ_RECT(IntRect(10, 500, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)));
626 occlusion.useDefaultLayerScissorRect();
627 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
628 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)).isEmpty());
629 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 80)).isEmpty());
630 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 70)).isEmpty());
631 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 80)).isEmpty());
632 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)).isEmpty());
633 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)).isEmpty());
634 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)).isEmpty());
635 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
637 occlusion.markOccludedBehindLayer(child);
638 // |child2| should get merged with the surface we are leaving now
639 occlusion.finishedTargetRenderSurface(child, child->renderSurface());
640 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
642 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
643 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
644 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
645 EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
647 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
648 EXPECT_EQ_RECT(IntRect(90, 30, 10, 10), occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)));
650 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 60, 10)));
651 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 60, 10)));
652 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 60, 10)));
653 EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 60, 10)));
654 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 60, 10)));
656 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
657 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
658 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
660 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 60, 10)).isEmpty());
661 EXPECT_EQ_RECT(IntRect(29, 30, 1, 10), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 60, 10)));
662 EXPECT_EQ_RECT(IntRect(30, 29, 60, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 60, 10)));
663 EXPECT_EQ_RECT(IntRect(90, 30, 1, 10), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 60, 10)));
664 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 31, 60, 10)).isEmpty());
666 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 40, 70, 60)).isEmpty());
667 EXPECT_EQ_RECT(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(29, 40, 70, 60)));
668 // This rect is mostly occluded by |child2|.
669 EXPECT_EQ_RECT(IntRect(90, 39, 10, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 39, 70, 60)));
670 // This rect extends past top/right ends of |child2|.
671 EXPECT_EQ_RECT(IntRect(30, 29, 70, 11), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
672 // This rect extends past left/right ends of |child2|.
673 EXPECT_EQ_RECT(IntRect(20, 39, 80, 60), occlusion.unoccludedContentRect(parent, IntRect(20, 39, 80, 60)));
674 EXPECT_EQ_RECT(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(31, 40, 70, 60)));
675 EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 41, 70, 60)));
677 /* Justification for the above occlusion from |layer|:
679 +---------------------+ +---------------------+
680 | | | |30 Visible region of |layer|: /////
681 | 30 | rotate(90) | 30 60 | |child2|: \\\\\
682 | 30 + ------------+--------------------+ | 30 +------------+--------------------+
683 100 | | 10 | | | ==> | |\\\\\\\\\\\\| |10 |
684 | |10+----------|----------------------+ | +--|\\\\\\\\\\\\|-----------------+ |
685 | + ------------+ | | | | | +------------+//| 420 | |
686 | | | | | | | | |///////////////|60 | |
687 | | | | | | | | |///////////////| | |
688 +----|--|-------------+ | | +--|--|---------------+ | |
689 | | | | 20|10| 70 | |
696 +--|-------------------------------+ | | +------------------------------|--+
698 +---------------------------------+ +---------------------------------+
704 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestVisitTargetTwoTimes);
706 template<class Types, bool opaqueLayers>
707 class CCOcclusionTrackerTestSurfaceRotatedOffAxis : public CCOcclusionTrackerTest<Types, opaqueLayers> {
711 TransformationMatrix childTransform;
712 childTransform.translate(250, 250);
713 childTransform.rotate(95);
714 childTransform.translate(-250, -250);
716 TransformationMatrix layerTransform;
717 layerTransform.translate(10, 10);
719 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
720 typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
721 child->setMasksToBounds(true);
722 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, layerTransform, FloatPoint(0, 0), IntSize(500, 500), true);
723 this->calcDrawEtc(parent);
725 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
726 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
728 IntRect clippedLayerInChild = layerTransform.mapRect(layer->visibleLayerRect());
730 occlusion.enterTargetRenderSurface(child->renderSurface());
731 occlusion.markOccludedBehindLayer(layer);
733 EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInScreenSpace().bounds());
734 EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
735 EXPECT_EQ_RECT(clippedLayerInChild, occlusion.occlusionInTargetSurface().bounds());
736 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
738 EXPECT_TRUE(occlusion.occluded(child, clippedLayerInChild));
739 EXPECT_TRUE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
740 clippedLayerInChild.move(-1, 0);
741 EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
742 EXPECT_FALSE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
743 clippedLayerInChild.move(1, 0);
744 clippedLayerInChild.move(1, 0);
745 EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
746 EXPECT_FALSE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
747 clippedLayerInChild.move(-1, 0);
748 clippedLayerInChild.move(0, -1);
749 EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
750 EXPECT_FALSE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
751 clippedLayerInChild.move(0, 1);
752 clippedLayerInChild.move(0, 1);
753 EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
754 EXPECT_FALSE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
755 clippedLayerInChild.move(0, -1);
757 occlusion.markOccludedBehindLayer(child);
758 occlusion.finishedTargetRenderSurface(child, child->renderSurface());
759 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
761 EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInScreenSpace().bounds());
762 EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
763 EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInTargetSurface().bounds());
764 EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
766 EXPECT_FALSE(occlusion.occluded(parent, IntRect(75, 55, 1, 1)));
767 EXPECT_EQ_RECT(IntRect(75, 55, 1, 1), occlusion.unoccludedContentRect(parent, IntRect(75, 55, 1, 1)));
771 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestSurfaceRotatedOffAxis);
773 template<class Types, bool opaqueLayers>
774 class CCOcclusionTrackerTestSurfaceWithTwoOpaqueChildren : public CCOcclusionTrackerTest<Types, opaqueLayers> {
778 TransformationMatrix childTransform;
779 childTransform.translate(250, 250);
780 childTransform.rotate(90);
781 childTransform.translate(-250, -250);
783 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
784 typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
785 child->setMasksToBounds(true);
786 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
787 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 450), IntSize(500, 60), true);
788 this->calcDrawEtc(parent);
790 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
791 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
793 occlusion.enterTargetRenderSurface(child->renderSurface());
794 occlusion.markOccludedBehindLayer(layer2);
795 occlusion.markOccludedBehindLayer(layer1);
797 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
798 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
799 EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
800 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
802 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
803 EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
804 EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
805 EXPECT_FALSE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
806 EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
808 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
809 EXPECT_EQ_RECT(IntRect(9, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)));
810 EXPECT_EQ_RECT(IntRect(10, 429, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)));
811 EXPECT_EQ_RECT(IntRect(70, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)));
812 EXPECT_EQ_RECT(IntRect(10, 500, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)));
814 occlusion.markOccludedBehindLayer(child);
815 occlusion.finishedTargetRenderSurface(child, child->renderSurface());
816 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
818 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
819 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
820 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
821 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
823 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
824 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
825 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
827 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 40, 70, 60)).isEmpty());
828 EXPECT_EQ_RECT(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(29, 40, 70, 60)));
829 EXPECT_EQ_RECT(IntRect(30, 39, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 39, 70, 60)));
830 EXPECT_EQ_RECT(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(31, 40, 70, 60)));
831 EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 41, 70, 60)));
833 /* Justification for the above occlusion from |layer1| and |layer2|:
835 +---------------------+
836 | |30 Visible region of |layer1|: /////
837 | | Visible region of |layer2|: \\\\\
838 | +---------------------------------+
840 | +---------------+-----------------+ |
841 | | |\\\\\\\\\\\\|//| 420 | |
842 | | |\\\\\\\\\\\\|//|60 | |
843 | | |\\\\\\\\\\\\|//| | |
844 +--|--|------------|--+ | |
852 | +------------|-----------------|--+
854 +---------------+-----------------+
860 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
862 template<class Types, bool opaqueLayers>
863 class CCOcclusionTrackerTestOverlappingSurfaceSiblings : public CCOcclusionTrackerTest<Types, opaqueLayers> {
867 TransformationMatrix childTransform;
868 childTransform.translate(250, 250);
869 childTransform.rotate(90);
870 childTransform.translate(-250, -250);
872 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
873 typename Types::LayerType* child1 = this->createSurface(parent, childTransform, FloatPoint(30, 30), IntSize(10, 10));
874 typename Types::LayerType* child2 = this->createSurface(parent, childTransform, FloatPoint(20, 40), IntSize(10, 10));
875 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
876 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
877 this->calcDrawEtc(parent);
879 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
880 occlusion.setLayerScissorRect(IntRect(-20, -20, 1000, 1000));
882 occlusion.enterTargetRenderSurface(child2->renderSurface());
883 occlusion.markOccludedBehindLayer(layer2);
885 EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
886 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
887 EXPECT_EQ_RECT(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
888 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
890 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
891 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
892 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
893 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
894 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
896 occlusion.useDefaultLayerScissorRect();
897 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
898 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
899 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
900 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
901 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
902 occlusion.setLayerScissorRect(IntRect(-20, -20, 1000, 1000));
904 occlusion.markOccludedBehindLayer(child2);
905 occlusion.finishedTargetRenderSurface(child2, child2->renderSurface());
906 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
907 occlusion.enterTargetRenderSurface(child1->renderSurface());
908 occlusion.markOccludedBehindLayer(layer1);
910 EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
911 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
912 EXPECT_EQ_RECT(IntRect(-10, 430, 80, 70), occlusion.occlusionInTargetSurface().bounds());
913 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
915 EXPECT_TRUE(occlusion.occluded(child1, IntRect(-10, 430, 80, 70)));
916 EXPECT_FALSE(occlusion.occluded(child1, IntRect(-11, 430, 80, 70)));
917 EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 429, 80, 70)));
918 EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 430, 81, 70)));
919 EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 430, 80, 71)));
921 occlusion.markOccludedBehindLayer(child1);
922 occlusion.finishedTargetRenderSurface(child1, child1->renderSurface());
923 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
925 EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
926 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
927 EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInTargetSurface().bounds());
928 EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
930 EXPECT_FALSE(occlusion.occluded(parent, IntRect(20, 20, 80, 80)));
932 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 20, 70, 80)));
933 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 20, 70, 80)));
934 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 19, 70, 80)));
936 EXPECT_TRUE(occlusion.occluded(parent, IntRect(20, 30, 80, 70)));
937 EXPECT_FALSE(occlusion.occluded(parent, IntRect(19, 30, 80, 70)));
938 EXPECT_FALSE(occlusion.occluded(parent, IntRect(20, 29, 80, 70)));
940 /* Justification for the above occlusion:
942 +---------------------+
944 | 30+ ---------------------------------+
946 |20+----------------------------------+ |
950 +--|-|----------------+ | |
958 | +--------------------------------|-+
960 +----------------------------------+
966 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestOverlappingSurfaceSiblings);
968 template<class Types, bool opaqueLayers>
969 class CCOcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms : public CCOcclusionTrackerTest<Types, opaqueLayers> {
973 TransformationMatrix child1Transform;
974 child1Transform.translate(250, 250);
975 child1Transform.rotate(-90);
976 child1Transform.translate(-250, -250);
978 TransformationMatrix child2Transform;
979 child2Transform.translate(250, 250);
980 child2Transform.rotate(90);
981 child2Transform.translate(-250, -250);
983 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
984 typename Types::LayerType* child1 = this->createSurface(parent, child1Transform, FloatPoint(30, 20), IntSize(10, 10));
985 typename Types::LayerType* child2 = this->createSurface(parent, child2Transform, FloatPoint(20, 40), IntSize(10, 10));
986 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, FloatPoint(-10, -20), IntSize(510, 510), true);
987 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
988 this->calcDrawEtc(parent);
990 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
991 occlusion.setLayerScissorRect(IntRect(-30, -30, 1000, 1000));
993 occlusion.enterTargetRenderSurface(child2->renderSurface());
994 occlusion.markOccludedBehindLayer(layer2);
996 EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
997 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
998 EXPECT_EQ_RECT(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
999 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1001 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
1002 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
1003 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
1004 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
1005 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
1007 occlusion.markOccludedBehindLayer(child2);
1008 occlusion.finishedTargetRenderSurface(child2, child2->renderSurface());
1009 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1010 occlusion.enterTargetRenderSurface(child1->renderSurface());
1011 occlusion.markOccludedBehindLayer(layer1);
1013 EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
1014 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1015 EXPECT_EQ_RECT(IntRect(420, -20, 80, 90), occlusion.occlusionInTargetSurface().bounds());
1016 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1018 EXPECT_TRUE(occlusion.occluded(child1, IntRect(420, -20, 80, 90)));
1019 EXPECT_FALSE(occlusion.occluded(child1, IntRect(419, -20, 80, 90)));
1020 EXPECT_FALSE(occlusion.occluded(child1, IntRect(420, -21, 80, 90)));
1021 EXPECT_FALSE(occlusion.occluded(child1, IntRect(420, -19, 80, 90)));
1022 EXPECT_FALSE(occlusion.occluded(child1, IntRect(421, -20, 80, 90)));
1024 occlusion.markOccludedBehindLayer(child1);
1025 occlusion.finishedTargetRenderSurface(child1, child1->renderSurface());
1026 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1028 EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
1029 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1030 EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInTargetSurface().bounds());
1031 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1033 EXPECT_TRUE(occlusion.occluded(parent, IntRect(10, 20, 90, 80)));
1034 EXPECT_FALSE(occlusion.occluded(parent, IntRect(9, 20, 90, 80)));
1035 EXPECT_FALSE(occlusion.occluded(parent, IntRect(10, 19, 90, 80)));
1036 EXPECT_FALSE(occlusion.occluded(parent, IntRect(11, 20, 90, 80)));
1037 EXPECT_FALSE(occlusion.occluded(parent, IntRect(10, 21, 90, 80)));
1039 /* Justification for the above occlusion:
1041 +---------------------+
1043 10+----------------------------------+
1044 100 || 30 | layer2 |
1045 |20+----------------------------------+
1049 +|-|------------------+ | |
1057 +----------------------------------+ |
1059 +----------------------------------+
1065 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
1067 template<class Types, bool opaqueLayers>
1068 class CCOcclusionTrackerTestFilters : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1072 TransformationMatrix layerTransform;
1073 layerTransform.translate(250, 250);
1074 layerTransform.rotate(90);
1075 layerTransform.translate(-250, -250);
1077 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
1078 typename Types::ContentLayerType* blurLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
1079 typename Types::ContentLayerType* opacityLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
1080 typename Types::ContentLayerType* opaqueLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
1082 FilterOperations filters;
1083 filters.operations().append(BlurFilterOperation::create(Length(10, WebCore::Percent), FilterOperation::BLUR));
1084 blurLayer->setFilters(filters);
1086 filters.operations().clear();
1087 filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
1088 opaqueLayer->setFilters(filters);
1090 filters.operations().clear();
1091 filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::OPACITY));
1092 opacityLayer->setFilters(filters);
1094 this->calcDrawEtc(parent);
1096 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1097 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1099 // Opacity layer won't contribute to occlusion.
1100 occlusion.enterTargetRenderSurface(opacityLayer->renderSurface());
1101 occlusion.markOccludedBehindLayer(opacityLayer);
1102 occlusion.finishedTargetRenderSurface(opacityLayer, opacityLayer->renderSurface());
1104 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1105 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1107 // And has nothing to contribute to its parent surface.
1108 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1109 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1110 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1112 // Opaque layer will contribute to occlusion.
1113 occlusion.enterTargetRenderSurface(opaqueLayer->renderSurface());
1114 occlusion.markOccludedBehindLayer(opaqueLayer);
1115 occlusion.finishedTargetRenderSurface(opaqueLayer, opaqueLayer->renderSurface());
1117 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
1118 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1119 EXPECT_EQ_RECT(IntRect(0, 430, 70, 70), occlusion.occlusionInTargetSurface().bounds());
1120 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1122 // And it gets translated to the parent surface.
1123 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1124 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
1125 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1126 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
1127 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1129 // The blur layer needs to throw away any occlusion from outside its subtree.
1130 occlusion.enterTargetRenderSurface(blurLayer->renderSurface());
1131 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1132 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1134 // And it won't contribute to occlusion.
1135 occlusion.markOccludedBehindLayer(blurLayer);
1136 occlusion.finishedTargetRenderSurface(blurLayer, blurLayer->renderSurface());
1137 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1138 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1140 // But the opaque layer's occlusion is preserved on the parent.
1141 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1142 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
1143 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1144 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
1145 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1149 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestFilters);
1151 template<class Types, bool opaqueLayers>
1152 class CCOcclusionTrackerTestLayerScissorRectOutsideChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1156 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1157 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1158 this->calcDrawEtc(parent);
1160 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1161 occlusion.setLayerScissorRect(IntRect(200, 100, 100, 100));
1163 occlusion.enterTargetRenderSurface(layer->renderSurface());
1165 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1166 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1167 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1168 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1169 EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1171 occlusion.useDefaultLayerScissorRect();
1172 EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1173 occlusion.setLayerScissorRect(IntRect(200, 100, 100, 100));
1175 occlusion.markOccludedBehindLayer(layer);
1176 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1178 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1179 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1180 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1181 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1182 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1183 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1184 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1185 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1186 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1188 EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1192 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectOutsideChild);
1194 template<class Types, bool opaqueLayers>
1195 class CCOcclusionTrackerTestScreenScissorRectOutsideChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1199 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1200 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1201 this->calcDrawEtc(parent);
1203 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(200, 100, 100, 100));
1204 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1206 occlusion.enterTargetRenderSurface(layer->renderSurface());
1208 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1209 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1210 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1211 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1212 EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1214 occlusion.useDefaultLayerScissorRect();
1215 EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1216 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1218 occlusion.markOccludedBehindLayer(layer);
1219 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1221 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1222 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1223 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1224 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1225 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1226 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1227 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1228 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1229 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1231 EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1235 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectOutsideChild);
1237 template<class Types, bool opaqueLayers>
1238 class CCOcclusionTrackerTestLayerScissorRectOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1242 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1243 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1244 this->calcDrawEtc(parent);
1246 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1247 occlusion.setLayerScissorRect(IntRect(100, 100, 100, 100));
1249 occlusion.enterTargetRenderSurface(layer->renderSurface());
1251 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1252 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1253 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1254 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1256 occlusion.markOccludedBehindLayer(layer);
1257 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1259 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1260 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1261 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1262 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1263 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1264 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1265 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1266 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1267 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1269 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1273 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectOverChild);
1275 template<class Types, bool opaqueLayers>
1276 class CCOcclusionTrackerTestScreenScissorRectOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1280 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1281 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1282 this->calcDrawEtc(parent);
1284 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(100, 100, 100, 100));
1285 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1287 occlusion.enterTargetRenderSurface(layer->renderSurface());
1289 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1290 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1291 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1292 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1294 occlusion.markOccludedBehindLayer(layer);
1295 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1297 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1298 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1299 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1300 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1301 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1302 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1303 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1304 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1305 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1307 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1311 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectOverChild);
1313 template<class Types, bool opaqueLayers>
1314 class CCOcclusionTrackerTestLayerScissorRectPartlyOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1318 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1319 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1320 this->calcDrawEtc(parent);
1322 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1323 occlusion.setLayerScissorRect(IntRect(50, 50, 200, 200));
1325 occlusion.enterTargetRenderSurface(layer->renderSurface());
1327 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1328 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1329 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1330 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1332 occlusion.markOccludedBehindLayer(layer);
1333 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1335 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1336 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1337 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1338 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1339 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1340 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1341 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1342 EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1343 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1345 EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1346 EXPECT_EQ_RECT(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)));
1347 EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)));
1348 EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)));
1349 EXPECT_EQ_RECT(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)));
1353 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectPartlyOverChild);
1355 template<class Types, bool opaqueLayers>
1356 class CCOcclusionTrackerTestScreenScissorRectPartlyOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1360 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1361 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1362 this->calcDrawEtc(parent);
1364 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(50, 50, 200, 200));
1365 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1367 occlusion.enterTargetRenderSurface(layer->renderSurface());
1369 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1370 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1371 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1372 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1374 occlusion.markOccludedBehindLayer(layer);
1375 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1377 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1378 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1379 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1380 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1381 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1382 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1383 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1384 EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1385 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1387 EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1388 EXPECT_EQ_RECT(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)));
1389 EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)));
1390 EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)));
1391 EXPECT_EQ_RECT(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)));
1395 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectPartlyOverChild);
1397 template<class Types, bool opaqueLayers>
1398 class CCOcclusionTrackerTestLayerScissorRectOverNothing : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1402 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1403 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1404 this->calcDrawEtc(parent);
1406 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1407 occlusion.setLayerScissorRect(IntRect(500, 500, 100, 100));
1409 occlusion.enterTargetRenderSurface(layer->renderSurface());
1411 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1412 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1413 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1414 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1416 occlusion.markOccludedBehindLayer(layer);
1417 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1419 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1420 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1421 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1422 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1423 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1424 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1425 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1426 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1427 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1429 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1430 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)).isEmpty());
1431 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)).isEmpty());
1432 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)).isEmpty());
1433 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)).isEmpty());
1437 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectOverNothing);
1439 template<class Types, bool opaqueLayers>
1440 class CCOcclusionTrackerTestScreenScissorRectOverNothing : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1444 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1445 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1446 this->calcDrawEtc(parent);
1448 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(500, 500, 100, 100));
1449 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1451 occlusion.enterTargetRenderSurface(layer->renderSurface());
1453 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1454 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1455 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1456 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1458 occlusion.markOccludedBehindLayer(layer);
1459 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1461 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1462 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1463 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1464 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1465 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1466 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1467 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1468 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1469 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1471 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1472 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)).isEmpty());
1473 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)).isEmpty());
1474 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)).isEmpty());
1475 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)).isEmpty());
1479 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectOverNothing);
1481 template<class Types, bool opaqueLayers>
1482 class CCOcclusionTrackerTestLayerScissorRectForLayerOffOrigin : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1486 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1487 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1488 this->calcDrawEtc(parent);
1490 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1491 occlusion.enterTargetRenderSurface(layer->renderSurface());
1493 // This layer is translated when drawn into its target. So if the scissor rect given from the target surface
1494 // is not in that target space, then after translating these query rects into the target, they will fall outside
1495 // the scissor and be considered occluded.
1496 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1497 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1498 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1499 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1503 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectForLayerOffOrigin);
1505 template<class Types, bool opaqueLayers>
1506 class CCOcclusionTrackerTestOpaqueContentsRegionEmpty : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1510 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1511 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), false);
1512 this->calcDrawEtc(parent);
1514 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1515 occlusion.enterTargetRenderSurface(layer->renderSurface());
1517 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1518 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1519 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1520 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1522 // Occluded since its outside the surface bounds.
1523 EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1525 // Test without any scissors.
1526 occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
1527 EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1528 occlusion.useDefaultLayerScissorRect();
1530 occlusion.markOccludedBehindLayer(layer);
1531 occlusion.leaveToTargetRenderSurface(parent->renderSurface());
1533 EXPECT_TRUE(occlusion.occlusionInScreenSpace().bounds().isEmpty());
1534 EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
1538 MAIN_AND_IMPL_THREAD_TEST(CCOcclusionTrackerTestOpaqueContentsRegionEmpty);
1540 template<class Types, bool opaqueLayers>
1541 class CCOcclusionTrackerTestOpaqueContentsRegionNonEmpty : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1545 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1546 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(100, 100), IntSize(200, 200), false);
1547 this->calcDrawEtc(parent);
1550 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1551 layer->setOpaqueContentsRect(IntRect(0, 0, 100, 100));
1553 occlusion.enterTargetRenderSurface(parent->renderSurface());
1554 occlusion.markOccludedBehindLayer(layer);
1556 EXPECT_EQ_RECT(IntRect(100, 100, 100, 100), occlusion.occlusionInScreenSpace().bounds());
1557 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1559 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1560 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1561 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1565 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1566 layer->setOpaqueContentsRect(IntRect(20, 20, 180, 180));
1568 occlusion.enterTargetRenderSurface(parent->renderSurface());
1569 occlusion.markOccludedBehindLayer(layer);
1571 EXPECT_EQ_RECT(IntRect(120, 120, 180, 180), occlusion.occlusionInScreenSpace().bounds());
1572 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1574 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1575 EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1576 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1580 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1581 layer->setOpaqueContentsRect(IntRect(150, 150, 100, 100));
1583 occlusion.enterTargetRenderSurface(parent->renderSurface());
1584 occlusion.markOccludedBehindLayer(layer);
1586 EXPECT_EQ_RECT(IntRect(250, 250, 50, 50), occlusion.occlusionInScreenSpace().bounds());
1587 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1589 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1590 EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1591 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1596 MAIN_AND_IMPL_THREAD_TEST(CCOcclusionTrackerTestOpaqueContentsRegionNonEmpty);
1598 template<class Types, bool opaqueLayers>
1599 class CCOcclusionTrackerTest3dTransform : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1603 TransformationMatrix transform;
1604 transform.rotate3d(0, 30, 0);
1606 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1607 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1608 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, FloatPoint(100, 100), IntSize(200, 200), true);
1609 this->calcDrawEtc(parent);
1611 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1612 occlusion.enterTargetRenderSurface(parent->renderSurface());
1614 EXPECT_EQ_RECT(IntRect(0, 0, 200, 200), occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)));
1618 MAIN_AND_IMPL_THREAD_TEST(CCOcclusionTrackerTest3dTransform);
1620 template<class Types, bool opaqueLayers>
1621 class CCOcclusionTrackerTestPerspectiveTransform : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1625 TransformationMatrix transform;
1626 transform.translate(150, 150);
1627 transform.applyPerspective(400);
1628 transform.rotate3d(1, 0, 0, -30);
1629 transform.translate(-150, -150);
1631 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1632 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1633 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, FloatPoint(100, 100), IntSize(200, 200), true);
1634 container->setPreserves3D(true);
1635 this->calcDrawEtc(parent);
1637 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1638 occlusion.enterTargetRenderSurface(parent->renderSurface());
1640 EXPECT_EQ_RECT(IntRect(0, 0, 200, 200), occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)));
1644 MAIN_THREAD_TEST(CCOcclusionTrackerTestPerspectiveTransform);
1646 template<class Types, bool opaqueLayers>
1647 class CCOcclusionTrackerTestPerspectiveTransformBehindCamera : public CCOcclusionTrackerTest<Types, opaqueLayers> {
1651 // This test is based on the platform/chromium/compositing/3d-corners.html layout test.
1652 TransformationMatrix transform;
1653 transform.translate(250, 50);
1654 transform.applyPerspective(10);
1655 transform.translate(-250, -50);
1656 transform.translate(250, 50);
1657 transform.rotate3d(1, 0, 0, -167);
1658 transform.translate(-250, -50);
1660 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(500, 100));
1661 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(500, 500));
1662 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, FloatPoint(0, 0), IntSize(500, 500), true);
1663 container->setPreserves3D(true);
1664 this->calcDrawEtc(parent);
1666 TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
1667 occlusion.enterTargetRenderSurface(parent->renderSurface());
1669 // The bottom 11 pixel rows of this layer remain visible inside the container, after translation to the target surface. When translated back,
1670 // this will include many more pixels but must include at least the bottom 11 rows.
1671 EXPECT_TRUE(occlusion.unoccludedContentRect(layer, IntRect(0, 0, 500, 500)).contains(IntRect(0, 489, 500, 11)));
1675 MAIN_THREAD_TEST(CCOcclusionTrackerTestPerspectiveTransformBehindCamera);