blob: 889ce4b89025b882a3877470e1d220bda4d8f719 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "config.h"
6
[email protected]55a124d02012-10-22 03:07:137#include "cc/occlusion_tracker.h"
[email protected]94f206c12012-08-25 00:09:148
[email protected]94f206c12012-08-25 00:09:149#include "CCLayerAnimationController.h"
[email protected]f3922f22012-10-12 09:20:3810#include "CCLayerImpl.h"
[email protected]94f206c12012-08-25 00:09:1411#include "CCLayerTreeHostCommon.h"
[email protected]94f206c12012-08-25 00:09:1412#include "Region.h"
[email protected]a8461d82012-10-16 21:11:1413#include "cc/layer.h"
[email protected]55a124d02012-10-22 03:07:1314#include "cc/math_util.h"
15#include "cc/overdraw_metrics.h"
[email protected]4456eee22012-10-19 18:16:3816#include "cc/single_thread_proxy.h"
[email protected]101441ce2012-10-16 01:45:0317#include "cc/test/animation_test_common.h"
18#include "cc/test/geometry_test_utils.h"
19#include "cc/test/occlusion_tracker_test_common.h"
[email protected]7f0c53db2012-10-02 00:23:1820#include "testing/gmock/include/gmock/gmock.h"
21#include "testing/gtest/include/gtest/gtest.h"
[email protected]94f206c12012-08-25 00:09:1422#include <public/WebFilterOperation.h>
23#include <public/WebFilterOperations.h>
24#include <public/WebTransformationMatrix.h>
25
[email protected]9c88e562012-09-14 22:21:3026using namespace cc;
[email protected]94f206c12012-08-25 00:09:1427using namespace WebKit;
28using namespace WebKitTests;
29
30namespace {
31
[email protected]96baf3e2012-10-22 23:09:5532class TestContentLayer : public Layer {
[email protected]94f206c12012-08-25 00:09:1433public:
[email protected]96baf3e2012-10-22 23:09:5534 TestContentLayer()
35 : Layer()
[email protected]94f206c12012-08-25 00:09:1436 , m_overrideOpaqueContentsRect(false)
37 {
38 }
39
40 virtual bool drawsContent() const OVERRIDE { return true; }
41 virtual Region visibleContentOpaqueRegion() const OVERRIDE
42 {
43 if (m_overrideOpaqueContentsRect)
44 return intersection(m_opaqueContentsRect, visibleContentRect());
[email protected]96baf3e2012-10-22 23:09:5545 return Layer::visibleContentOpaqueRegion();
[email protected]94f206c12012-08-25 00:09:1446 }
47 void setOpaqueContentsRect(const IntRect& opaqueContentsRect)
48 {
49 m_overrideOpaqueContentsRect = true;
50 m_opaqueContentsRect = opaqueContentsRect;
51 }
52
53private:
[email protected]96baf3e2012-10-22 23:09:5554 virtual ~TestContentLayer()
[email protected]d58499a2012-10-09 22:27:4755 {
56 }
57
[email protected]94f206c12012-08-25 00:09:1458 bool m_overrideOpaqueContentsRect;
59 IntRect m_opaqueContentsRect;
60};
61
[email protected]96baf3e2012-10-22 23:09:5562class TestContentLayerImpl : public LayerImpl {
[email protected]94f206c12012-08-25 00:09:1463public:
64 TestContentLayerImpl(int id)
[email protected]96baf3e2012-10-22 23:09:5565 : LayerImpl(id)
[email protected]94f206c12012-08-25 00:09:1466 , m_overrideOpaqueContentsRect(false)
67 {
68 setDrawsContent(true);
69 }
70
71 virtual Region visibleContentOpaqueRegion() const OVERRIDE
72 {
73 if (m_overrideOpaqueContentsRect)
74 return intersection(m_opaqueContentsRect, visibleContentRect());
[email protected]96baf3e2012-10-22 23:09:5575 return LayerImpl::visibleContentOpaqueRegion();
[email protected]94f206c12012-08-25 00:09:1476 }
77 void setOpaqueContentsRect(const IntRect& opaqueContentsRect)
78 {
79 m_overrideOpaqueContentsRect = true;
80 m_opaqueContentsRect = opaqueContentsRect;
81 }
82
83private:
84 bool m_overrideOpaqueContentsRect;
85 IntRect m_opaqueContentsRect;
86};
87
88template<typename LayerType, typename RenderSurfaceType>
[email protected]96baf3e2012-10-22 23:09:5589class TestOcclusionTrackerWithClip : public TestOcclusionTrackerBase<LayerType, RenderSurfaceType> {
[email protected]94f206c12012-08-25 00:09:1490public:
[email protected]96baf3e2012-10-22 23:09:5591 TestOcclusionTrackerWithClip(IntRect viewportRect, bool recordMetricsForFrame = false)
92 : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(viewportRect, recordMetricsForFrame)
[email protected]94f206c12012-08-25 00:09:1493 , m_overrideLayerClipRect(false)
94 {
95 }
96
97 void setLayerClipRect(const IntRect& rect) { m_overrideLayerClipRect = true; m_layerClipRect = rect;}
98 void useDefaultLayerClipRect() { m_overrideLayerClipRect = false; }
99
100protected:
[email protected]96baf3e2012-10-22 23:09:55101 virtual IntRect layerClipRectInTarget(const LayerType* layer) const { return m_overrideLayerClipRect ? m_layerClipRect : OcclusionTrackerBase<LayerType, RenderSurfaceType>::layerClipRectInTarget(layer); }
[email protected]94f206c12012-08-25 00:09:14102
103private:
104 bool m_overrideLayerClipRect;
105 IntRect m_layerClipRect;
106};
107
[email protected]96baf3e2012-10-22 23:09:55108struct OcclusionTrackerTestMainThreadTypes {
109 typedef Layer LayerType;
110 typedef RenderSurface RenderSurfaceType;
111 typedef TestContentLayer ContentLayerType;
112 typedef scoped_refptr<Layer> LayerPtrType;
[email protected]d58499a2012-10-09 22:27:47113 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
[email protected]96baf3e2012-10-22 23:09:55114 typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::FrontToBack> TestLayerIterator;
115 typedef OcclusionTracker OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14116
[email protected]e0bd43a2012-10-12 16:54:21117 static LayerPtrType createLayer()
[email protected]94f206c12012-08-25 00:09:14118 {
[email protected]96baf3e2012-10-22 23:09:55119 return Layer::create();
[email protected]94f206c12012-08-25 00:09:14120 }
[email protected]e0bd43a2012-10-12 16:54:21121 static ContentLayerPtrType createContentLayer() { return make_scoped_refptr(new ContentLayerType()); }
122
123 static LayerPtrType passLayerPtr(ContentLayerPtrType& layer)
124 {
125 return layer.release();
126 }
127
128 static LayerPtrType passLayerPtr(LayerPtrType& layer)
129 {
130 return layer.release();
131 }
[email protected]d58499a2012-10-09 22:27:47132
133 static void destroyLayer(LayerPtrType& layer)
134 {
135 layer = NULL;
136 }
[email protected]94f206c12012-08-25 00:09:14137};
138
[email protected]96baf3e2012-10-22 23:09:55139struct OcclusionTrackerTestImplThreadTypes {
140 typedef LayerImpl LayerType;
141 typedef RenderSurfaceImpl RenderSurfaceType;
[email protected]94f206c12012-08-25 00:09:14142 typedef TestContentLayerImpl ContentLayerType;
[email protected]96baf3e2012-10-22 23:09:55143 typedef scoped_ptr<LayerImpl> LayerPtrType;
[email protected]e0bd43a2012-10-12 16:54:21144 typedef scoped_ptr<ContentLayerType> ContentLayerPtrType;
[email protected]96baf3e2012-10-22 23:09:55145 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> TestLayerIterator;
146 typedef OcclusionTrackerImpl OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14147
[email protected]96baf3e2012-10-22 23:09:55148 static LayerPtrType createLayer() { return LayerImpl::create(nextLayerImplId++); }
149 static ContentLayerPtrType createContentLayer() { return make_scoped_ptr(new ContentLayerType(nextLayerImplId++)); }
150 static int nextLayerImplId;
[email protected]d58499a2012-10-09 22:27:47151
[email protected]e0bd43a2012-10-12 16:54:21152 static LayerPtrType passLayerPtr(LayerPtrType& layer)
153 {
154 return layer.Pass();
155 }
156
157 static LayerPtrType passLayerPtr(ContentLayerPtrType& layer)
158 {
159 return layer.PassAs<LayerType>();
160 }
161
[email protected]d58499a2012-10-09 22:27:47162 static void destroyLayer(LayerPtrType& layer)
163 {
[email protected]e0bd43a2012-10-12 16:54:21164 layer.reset();
[email protected]d58499a2012-10-09 22:27:47165 }
[email protected]94f206c12012-08-25 00:09:14166};
167
[email protected]96baf3e2012-10-22 23:09:55168int OcclusionTrackerTestImplThreadTypes::nextLayerImplId = 1;
[email protected]94f206c12012-08-25 00:09:14169
[email protected]ece1d952012-10-18 21:26:07170template<typename Types>
[email protected]96baf3e2012-10-22 23:09:55171class OcclusionTrackerTest : public testing::Test {
[email protected]94f206c12012-08-25 00:09:14172protected:
[email protected]96baf3e2012-10-22 23:09:55173 OcclusionTrackerTest(bool opaqueLayers)
[email protected]ece1d952012-10-18 21:26:07174 : m_opaqueLayers(opaqueLayers)
[email protected]94f206c12012-08-25 00:09:14175 { }
176
177 virtual void runMyTest() = 0;
178
179 virtual void TearDown()
180 {
[email protected]d58499a2012-10-09 22:27:47181 Types::destroyLayer(m_root);
[email protected]96baf3e2012-10-22 23:09:55182 m_renderSurfaceLayerList.clear();
[email protected]94f206c12012-08-25 00:09:14183 m_renderSurfaceLayerListImpl.clear();
184 m_replicaLayers.clear();
185 m_maskLayers.clear();
[email protected]96baf3e2012-10-22 23:09:55186 LayerTreeHost::setNeedsFilterContext(false);
[email protected]94f206c12012-08-25 00:09:14187 }
188
189 typename Types::ContentLayerType* createRoot(const WebTransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
190 {
191 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
192 typename Types::ContentLayerType* layerPtr = layer.get();
193 setProperties(layerPtr, transform, position, bounds);
194
[email protected]1d993172012-10-18 18:15:04195 DCHECK(!m_root);
[email protected]e0bd43a2012-10-12 16:54:21196 m_root = Types::passLayerPtr(layer);
[email protected]94f206c12012-08-25 00:09:14197 return layerPtr;
198 }
199
200 typename Types::LayerType* createLayer(typename Types::LayerType* parent, const WebTransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
201 {
202 typename Types::LayerPtrType layer(Types::createLayer());
203 typename Types::LayerType* layerPtr = layer.get();
204 setProperties(layerPtr, transform, position, bounds);
[email protected]e0bd43a2012-10-12 16:54:21205 parent->addChild(Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14206 return layerPtr;
207 }
208
209 typename Types::LayerType* createSurface(typename Types::LayerType* parent, const WebTransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
210 {
211 typename Types::LayerType* layer = createLayer(parent, transform, position, bounds);
212 WebFilterOperations filters;
213 filters.append(WebFilterOperation::createGrayscaleFilter(0.5));
214 layer->setFilters(filters);
215 return layer;
216 }
217
218 typename Types::ContentLayerType* createDrawingLayer(typename Types::LayerType* parent, const WebTransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque)
219 {
220 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
221 typename Types::ContentLayerType* layerPtr = layer.get();
222 setProperties(layerPtr, transform, position, bounds);
223
[email protected]ece1d952012-10-18 21:26:07224 if (m_opaqueLayers)
[email protected]048634c2012-10-02 22:33:14225 layerPtr->setContentsOpaque(opaque);
[email protected]94f206c12012-08-25 00:09:14226 else {
[email protected]048634c2012-10-02 22:33:14227 layerPtr->setContentsOpaque(false);
[email protected]94f206c12012-08-25 00:09:14228 if (opaque)
229 layerPtr->setOpaqueContentsRect(IntRect(IntPoint(), bounds));
230 else
231 layerPtr->setOpaqueContentsRect(IntRect());
232 }
233
[email protected]e0bd43a2012-10-12 16:54:21234 parent->addChild(Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14235 return layerPtr;
236 }
237
238 typename Types::LayerType* createReplicaLayer(typename Types::LayerType* owningLayer, const WebTransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
239 {
240 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
241 typename Types::ContentLayerType* layerPtr = layer.get();
242 setProperties(layerPtr, transform, position, bounds);
[email protected]e0bd43a2012-10-12 16:54:21243 setReplica(owningLayer, Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14244 return layerPtr;
245 }
246
247 typename Types::LayerType* createMaskLayer(typename Types::LayerType* owningLayer, const IntSize& bounds)
248 {
249 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
250 typename Types::ContentLayerType* layerPtr = layer.get();
251 setProperties(layerPtr, identityMatrix, FloatPoint(), bounds);
[email protected]e0bd43a2012-10-12 16:54:21252 setMask(owningLayer, Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14253 return layerPtr;
254 }
255
256 typename Types::ContentLayerType* createDrawingSurface(typename Types::LayerType* parent, const WebTransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque)
257 {
258 typename Types::ContentLayerType* layer = createDrawingLayer(parent, transform, position, bounds, opaque);
259 WebFilterOperations filters;
260 filters.append(WebFilterOperation::createGrayscaleFilter(0.5));
261 layer->setFilters(filters);
262 return layer;
263 }
264
265 void calcDrawEtc(TestContentLayerImpl* root)
266 {
[email protected]1d993172012-10-18 18:15:04267 DCHECK(root == m_root.get());
[email protected]94f206c12012-08-25 00:09:14268 int dummyMaxTextureSize = 512;
[email protected]96baf3e2012-10-22 23:09:55269 LayerSorter layerSorter;
[email protected]94f206c12012-08-25 00:09:14270
[email protected]1d993172012-10-18 18:15:04271 DCHECK(!root->renderSurface());
[email protected]94f206c12012-08-25 00:09:14272
[email protected]96baf3e2012-10-22 23:09:55273 LayerTreeHostCommon::calculateDrawTransforms(root, root->bounds(), 1, &layerSorter, dummyMaxTextureSize, m_renderSurfaceLayerListImpl);
[email protected]94f206c12012-08-25 00:09:14274
[email protected]96baf3e2012-10-22 23:09:55275 m_layerIterator = m_layerIteratorBegin = Types::TestLayerIterator::begin(&m_renderSurfaceLayerListImpl);
[email protected]94f206c12012-08-25 00:09:14276 }
277
[email protected]96baf3e2012-10-22 23:09:55278 void calcDrawEtc(TestContentLayer* root)
[email protected]94f206c12012-08-25 00:09:14279 {
[email protected]1d993172012-10-18 18:15:04280 DCHECK(root == m_root.get());
[email protected]94f206c12012-08-25 00:09:14281 int dummyMaxTextureSize = 512;
282
[email protected]1d993172012-10-18 18:15:04283 DCHECK(!root->renderSurface());
[email protected]94f206c12012-08-25 00:09:14284
[email protected]96baf3e2012-10-22 23:09:55285 LayerTreeHostCommon::calculateDrawTransforms(root, root->bounds(), 1, dummyMaxTextureSize, m_renderSurfaceLayerList);
[email protected]94f206c12012-08-25 00:09:14286
[email protected]96baf3e2012-10-22 23:09:55287 m_layerIterator = m_layerIteratorBegin = Types::TestLayerIterator::begin(&m_renderSurfaceLayerList);
[email protected]94f206c12012-08-25 00:09:14288 }
289
290 void enterLayer(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
291 {
292 ASSERT_EQ(layer, *m_layerIterator);
293 ASSERT_TRUE(m_layerIterator.representsItself());
294 occlusion.enterLayer(m_layerIterator);
295 }
296
297 void leaveLayer(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
298 {
299 ASSERT_EQ(layer, *m_layerIterator);
300 ASSERT_TRUE(m_layerIterator.representsItself());
301 occlusion.leaveLayer(m_layerIterator);
302 ++m_layerIterator;
303 }
304
305 void visitLayer(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
306 {
307 enterLayer(layer, occlusion);
308 leaveLayer(layer, occlusion);
309 }
310
311 void enterContributingSurface(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
312 {
313 ASSERT_EQ(layer, *m_layerIterator);
314 ASSERT_TRUE(m_layerIterator.representsTargetRenderSurface());
315 occlusion.enterLayer(m_layerIterator);
316 occlusion.leaveLayer(m_layerIterator);
317 ++m_layerIterator;
318 ASSERT_TRUE(m_layerIterator.representsContributingRenderSurface());
319 occlusion.enterLayer(m_layerIterator);
320 }
321
322 void leaveContributingSurface(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
323 {
324 ASSERT_EQ(layer, *m_layerIterator);
325 ASSERT_TRUE(m_layerIterator.representsContributingRenderSurface());
326 occlusion.leaveLayer(m_layerIterator);
327 ++m_layerIterator;
328 }
329
330 void visitContributingSurface(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
331 {
332 enterContributingSurface(layer, occlusion);
333 leaveContributingSurface(layer, occlusion);
334 }
335
336 void resetLayerIterator()
337 {
338 m_layerIterator = m_layerIteratorBegin;
339 }
340
341 const WebTransformationMatrix identityMatrix;
342
343private:
344 void setBaseProperties(typename Types::LayerType* layer, const WebTransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
345 {
346 layer->setTransform(transform);
347 layer->setSublayerTransform(WebTransformationMatrix());
348 layer->setAnchorPoint(FloatPoint(0, 0));
349 layer->setPosition(position);
350 layer->setBounds(bounds);
351 }
352
[email protected]96baf3e2012-10-22 23:09:55353 void setProperties(Layer* layer, const WebTransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
[email protected]94f206c12012-08-25 00:09:14354 {
355 setBaseProperties(layer, transform, position, bounds);
356 }
357
[email protected]96baf3e2012-10-22 23:09:55358 void setProperties(LayerImpl* layer, const WebTransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
[email protected]94f206c12012-08-25 00:09:14359 {
360 setBaseProperties(layer, transform, position, bounds);
361
362 layer->setContentBounds(layer->bounds());
363 }
364
[email protected]96baf3e2012-10-22 23:09:55365 void setReplica(Layer* owningLayer, scoped_refptr<Layer> layer)
[email protected]94f206c12012-08-25 00:09:14366 {
367 owningLayer->setReplicaLayer(layer.get());
[email protected]d58499a2012-10-09 22:27:47368 m_replicaLayers.push_back(layer);
[email protected]94f206c12012-08-25 00:09:14369 }
370
[email protected]96baf3e2012-10-22 23:09:55371 void setReplica(LayerImpl* owningLayer, scoped_ptr<LayerImpl> layer)
[email protected]94f206c12012-08-25 00:09:14372 {
[email protected]e0bd43a2012-10-12 16:54:21373 owningLayer->setReplicaLayer(layer.Pass());
[email protected]94f206c12012-08-25 00:09:14374 }
375
[email protected]96baf3e2012-10-22 23:09:55376 void setMask(Layer* owningLayer, scoped_refptr<Layer> layer)
[email protected]94f206c12012-08-25 00:09:14377 {
378 owningLayer->setMaskLayer(layer.get());
[email protected]d58499a2012-10-09 22:27:47379 m_maskLayers.push_back(layer);
[email protected]94f206c12012-08-25 00:09:14380 }
381
[email protected]96baf3e2012-10-22 23:09:55382 void setMask(LayerImpl* owningLayer, scoped_ptr<LayerImpl> layer)
[email protected]94f206c12012-08-25 00:09:14383 {
[email protected]e0bd43a2012-10-12 16:54:21384 owningLayer->setMaskLayer(layer.Pass());
[email protected]94f206c12012-08-25 00:09:14385 }
386
[email protected]ece1d952012-10-18 21:26:07387 bool m_opaqueLayers;
[email protected]94f206c12012-08-25 00:09:14388 // These hold ownership of the layers for the duration of the test.
389 typename Types::LayerPtrType m_root;
[email protected]96baf3e2012-10-22 23:09:55390 std::vector<scoped_refptr<Layer> > m_renderSurfaceLayerList;
391 std::vector<LayerImpl*> m_renderSurfaceLayerListImpl;
392 typename Types::TestLayerIterator m_layerIteratorBegin;
393 typename Types::TestLayerIterator m_layerIterator;
[email protected]94f206c12012-08-25 00:09:14394 typename Types::LayerType* m_lastLayerVisited;
[email protected]96baf3e2012-10-22 23:09:55395 std::vector<scoped_refptr<Layer> > m_replicaLayers;
396 std::vector<scoped_refptr<Layer> > m_maskLayers;
[email protected]94f206c12012-08-25 00:09:14397};
398
399#define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55400 class ClassName##MainThreadOpaqueLayers : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14401 public: \
[email protected]96baf3e2012-10-22 23:09:55402 ClassName##MainThreadOpaqueLayers() : ClassName<OcclusionTrackerTestMainThreadTypes>(true) { } \
[email protected]94f206c12012-08-25 00:09:14403 }; \
404 TEST_F(ClassName##MainThreadOpaqueLayers, runTest) { runMyTest(); }
405#define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55406 class ClassName##MainThreadOpaquePaints : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14407 public: \
[email protected]96baf3e2012-10-22 23:09:55408 ClassName##MainThreadOpaquePaints() : ClassName<OcclusionTrackerTestMainThreadTypes>(false) { } \
[email protected]94f206c12012-08-25 00:09:14409 }; \
410 TEST_F(ClassName##MainThreadOpaquePaints, runTest) { runMyTest(); }
411
412#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55413 class ClassName##ImplThreadOpaqueLayers : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14414 DebugScopedSetImplThread impl; \
415 public: \
[email protected]96baf3e2012-10-22 23:09:55416 ClassName##ImplThreadOpaqueLayers() : ClassName<OcclusionTrackerTestImplThreadTypes>(true) { } \
[email protected]94f206c12012-08-25 00:09:14417 }; \
418 TEST_F(ClassName##ImplThreadOpaqueLayers, runTest) { runMyTest(); }
419#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55420 class ClassName##ImplThreadOpaquePaints : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14421 DebugScopedSetImplThread impl; \
422 public: \
[email protected]96baf3e2012-10-22 23:09:55423 ClassName##ImplThreadOpaquePaints() : ClassName<OcclusionTrackerTestImplThreadTypes>(false) { } \
[email protected]94f206c12012-08-25 00:09:14424 }; \
425 TEST_F(ClassName##ImplThreadOpaquePaints, runTest) { runMyTest(); }
426
[email protected]96baf3e2012-10-22 23:09:55427#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
[email protected]94f206c12012-08-25 00:09:14428 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
429 RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
430 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
431 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
432
433#define MAIN_THREAD_TEST(ClassName) \
[email protected]f3922f22012-10-12 09:20:38434 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14435
436#define IMPL_THREAD_TEST(ClassName) \
[email protected]f3922f22012-10-12 09:20:38437 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14438
439#define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
440 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]f3922f22012-10-12 09:20:38441 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14442
[email protected]ece1d952012-10-18 21:26:07443template<class Types>
[email protected]96baf3e2012-10-22 23:09:55444class OcclusionTrackerTestIdentityTransforms : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14445protected:
[email protected]96baf3e2012-10-22 23:09:55446 OcclusionTrackerTestIdentityTransforms(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]ece1d952012-10-18 21:26:07447
[email protected]94f206c12012-08-25 00:09:14448 void runMyTest()
449 {
450 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
451 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(30, 30), IntSize(500, 500), true);
452 this->calcDrawEtc(parent);
453
[email protected]96baf3e2012-10-22 23:09:55454 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14455 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
456
457 this->visitLayer(layer, occlusion);
458 this->enterLayer(parent, occlusion);
459
[email protected]022cbf162012-09-01 01:15:17460 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14461 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17462 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14463 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
464
465 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
466 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
467 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
468 EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
469 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
470
471 occlusion.useDefaultLayerClipRect();
472 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
473 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
474 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
475 EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
476 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
477 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
478
479 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)).isEmpty());
[email protected]022cbf162012-09-01 01:15:17480 EXPECT_RECT_EQ(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 70, 70)));
481 EXPECT_RECT_EQ(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 29, 70, 70)));
482 EXPECT_RECT_EQ(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
483 EXPECT_RECT_EQ(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 29, 70, 70)));
484 EXPECT_RECT_EQ(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 70, 70)));
485 EXPECT_RECT_EQ(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 31, 70, 70)));
486 EXPECT_RECT_EQ(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 31, 70, 70)));
487 EXPECT_RECT_EQ(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14488 }
489};
490
[email protected]96baf3e2012-10-22 23:09:55491ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14492
[email protected]ece1d952012-10-18 21:26:07493template<class Types>
[email protected]96baf3e2012-10-22 23:09:55494class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14495protected:
[email protected]96baf3e2012-10-22 23:09:55496 OcclusionTrackerTestRotatedChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14497 void runMyTest()
498 {
499 WebTransformationMatrix layerTransform;
500 layerTransform.translate(250, 250);
501 layerTransform.rotate(90);
502 layerTransform.translate(-250, -250);
503
504 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
505 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
506 this->calcDrawEtc(parent);
507
[email protected]96baf3e2012-10-22 23:09:55508 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14509 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
510
511 this->visitLayer(layer, occlusion);
512 this->enterLayer(parent, occlusion);
513
[email protected]022cbf162012-09-01 01:15:17514 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14515 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17516 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14517 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
518
519 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
520 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
521 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
522 EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
523 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
524
525 occlusion.useDefaultLayerClipRect();
526 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
527 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
528 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
529 EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
530 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
531 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
532
533 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)).isEmpty());
[email protected]022cbf162012-09-01 01:15:17534 EXPECT_RECT_EQ(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 70, 70)));
535 EXPECT_RECT_EQ(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 29, 70, 70)));
536 EXPECT_RECT_EQ(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
537 EXPECT_RECT_EQ(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 29, 70, 70)));
538 EXPECT_RECT_EQ(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 70, 70)));
539 EXPECT_RECT_EQ(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 31, 70, 70)));
540 EXPECT_RECT_EQ(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 31, 70, 70)));
541 EXPECT_RECT_EQ(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14542 }
543};
544
[email protected]96baf3e2012-10-22 23:09:55545ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14546
[email protected]ece1d952012-10-18 21:26:07547template<class Types>
[email protected]96baf3e2012-10-22 23:09:55548class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14549protected:
[email protected]96baf3e2012-10-22 23:09:55550 OcclusionTrackerTestTranslatedChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14551 void runMyTest()
552 {
553 WebTransformationMatrix layerTransform;
554 layerTransform.translate(20, 20);
555
556 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
557 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
558 this->calcDrawEtc(parent);
559
[email protected]96baf3e2012-10-22 23:09:55560 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14561 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
562
563 this->visitLayer(layer, occlusion);
564 this->enterLayer(parent, occlusion);
565
[email protected]022cbf162012-09-01 01:15:17566 EXPECT_RECT_EQ(IntRect(50, 50, 50, 50), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14567 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17568 EXPECT_RECT_EQ(IntRect(50, 50, 50, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14569 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
570
571 EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 50, 50, 50)));
572 EXPECT_FALSE(occlusion.occluded(parent, IntRect(49, 50, 50, 50)));
573 EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 49, 50, 50)));
574 EXPECT_FALSE(occlusion.occluded(parent, IntRect(51, 50, 50, 50)));
575 EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 51, 50, 50)));
576
577 occlusion.useDefaultLayerClipRect();
578 EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 50, 50, 50)));
579 EXPECT_FALSE(occlusion.occluded(parent, IntRect(49, 50, 50, 50)));
580 EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 49, 50, 50)));
581 EXPECT_TRUE(occlusion.occluded(parent, IntRect(51, 50, 50, 50)));
582 EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 51, 50, 50)));
583 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
584
585 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 50, 50, 50)).isEmpty());
[email protected]022cbf162012-09-01 01:15:17586 EXPECT_RECT_EQ(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 50, 50, 50)));
587 EXPECT_RECT_EQ(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 49, 50, 50)));
588 EXPECT_RECT_EQ(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 49, 50, 50)));
589 EXPECT_RECT_EQ(IntRect(51, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 49, 50, 50)));
590 EXPECT_RECT_EQ(IntRect(100, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 50, 50, 50)));
591 EXPECT_RECT_EQ(IntRect(51, 51, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 51, 50, 50)));
592 EXPECT_RECT_EQ(IntRect(50, 100, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 51, 50, 50)));
593 EXPECT_RECT_EQ(IntRect(49, 51, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 51, 50, 50)));
[email protected]94f206c12012-08-25 00:09:14594
595 occlusion.useDefaultLayerClipRect();
596 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 50, 50, 50)).isEmpty());
[email protected]022cbf162012-09-01 01:15:17597 EXPECT_RECT_EQ(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 50, 50, 50)));
598 EXPECT_RECT_EQ(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 49, 50, 50)));
599 EXPECT_RECT_EQ(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 49, 50, 50)));
600 EXPECT_RECT_EQ(IntRect(51, 49, 49, 1), occlusion.unoccludedContentRect(parent, IntRect(51, 49, 50, 50)));
[email protected]94f206c12012-08-25 00:09:14601 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(51, 50, 50, 50)).isEmpty());
602 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(51, 51, 50, 50)).isEmpty());
603 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 51, 50, 50)).isEmpty());
[email protected]022cbf162012-09-01 01:15:17604 EXPECT_RECT_EQ(IntRect(49, 51, 1, 49), occlusion.unoccludedContentRect(parent, IntRect(49, 51, 50, 50)));
[email protected]94f206c12012-08-25 00:09:14605 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
606 }
607};
608
[email protected]96baf3e2012-10-22 23:09:55609ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14610
[email protected]ece1d952012-10-18 21:26:07611template<class Types>
[email protected]96baf3e2012-10-22 23:09:55612class OcclusionTrackerTestChildInRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14613protected:
[email protected]96baf3e2012-10-22 23:09:55614 OcclusionTrackerTestChildInRotatedChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14615 void runMyTest()
616 {
617 WebTransformationMatrix childTransform;
618 childTransform.translate(250, 250);
619 childTransform.rotate(90);
620 childTransform.translate(-250, -250);
621
622 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
[email protected]23bbb412012-08-30 20:03:38623 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:14624 typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
625 child->setMasksToBounds(true);
626 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
627 this->calcDrawEtc(parent);
628
[email protected]96baf3e2012-10-22 23:09:55629 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14630 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
631
632 this->visitLayer(layer, occlusion);
633 this->enterContributingSurface(child, occlusion);
634
[email protected]022cbf162012-09-01 01:15:17635 EXPECT_RECT_EQ(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14636 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17637 EXPECT_RECT_EQ(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14638 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
639
640 this->leaveContributingSurface(child, occlusion);
641 this->enterLayer(parent, occlusion);
642
[email protected]022cbf162012-09-01 01:15:17643 EXPECT_RECT_EQ(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14644 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17645 EXPECT_RECT_EQ(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14646 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
647
648 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
649 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
650 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
651 EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 40, 70, 60)));
652 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 41, 70, 60)));
653
654 occlusion.useDefaultLayerClipRect();
655 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
656 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
657 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
658 EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 40, 70, 60)));
659 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 41, 70, 60)));
660 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
661
662
663 /* Justification for the above occlusion from |layer|:
664 100
665 +---------------------+ +---------------------+
666 | | | |30 Visible region of |layer|: /////
667 | 30 | rotate(90) | |
668 | 30 + ---------------------------------+ | +---------------------------------+
669 100 | | 10 | | ==> | | |10 |
670 | |10+---------------------------------+ | +---------------------------------+ |
671 | | | | | | | | |///////////////| 420 | |
672 | | | | | | | | |///////////////|60 | |
673 | | | | | | | | |///////////////| | |
674 +----|--|-------------+ | | +--|--|---------------+ | |
675 | | | | 20|10| 70 | |
676 | | | | | | | |
677 | | | |500 | | | |
678 | | | | | | | |
679 | | | | | | | |
680 | | | | | | | |
681 | | | | | | |10|
682 +--|-------------------------------+ | | +------------------------------|--+
683 | | | 490 |
684 +---------------------------------+ +---------------------------------+
685 500 500
686 */
687 }
688};
689
[email protected]96baf3e2012-10-22 23:09:55690ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14691
[email protected]ece1d952012-10-18 21:26:07692template<class Types>
[email protected]96baf3e2012-10-22 23:09:55693class OcclusionTrackerTestVisitTargetTwoTimes : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14694protected:
[email protected]96baf3e2012-10-22 23:09:55695 OcclusionTrackerTestVisitTargetTwoTimes(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14696 void runMyTest()
697 {
698 WebTransformationMatrix childTransform;
699 childTransform.translate(250, 250);
700 childTransform.rotate(90);
701 childTransform.translate(-250, -250);
702
703 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
[email protected]23bbb412012-08-30 20:03:38704 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:14705 typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
706 child->setMasksToBounds(true);
707 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
[email protected]96baf3e2012-10-22 23:09:55708 // |child2| makes |parent|'s surface get considered by OcclusionTracker first, instead of |child|'s. This exercises different code in
[email protected]94f206c12012-08-25 00:09:14709 // leaveToTargetRenderSurface, as the target surface has already been seen.
710 typename Types::ContentLayerType* child2 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(30, 30), IntSize(60, 20), true);
711 this->calcDrawEtc(parent);
712
[email protected]96baf3e2012-10-22 23:09:55713 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14714 occlusion.setLayerClipRect(IntRect(-10, -10, 1000, 1000));
715
716 this->visitLayer(child2, occlusion);
717
[email protected]022cbf162012-09-01 01:15:17718 EXPECT_RECT_EQ(IntRect(30, 30, 60, 20), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14719 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17720 EXPECT_RECT_EQ(IntRect(30, 30, 60, 20), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14721 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
722
723 this->visitLayer(layer, occlusion);
724
[email protected]022cbf162012-09-01 01:15:17725 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14726 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17727 EXPECT_RECT_EQ(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14728 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
729
730 this->enterContributingSurface(child, occlusion);
731
[email protected]022cbf162012-09-01 01:15:17732 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14733 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17734 EXPECT_RECT_EQ(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14735 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
736
737 // Occlusion in |child2| should get merged with the |child| surface we are leaving now.
738 this->leaveContributingSurface(child, occlusion);
739 this->enterLayer(parent, occlusion);
740
[email protected]022cbf162012-09-01 01:15:17741 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14742 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17743 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14744 EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
745
746 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
[email protected]022cbf162012-09-01 01:15:17747 EXPECT_RECT_EQ(IntRect(90, 30, 10, 10), occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14748
749 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 60, 10)));
750 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 60, 10)));
751 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 60, 10)));
752 EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 60, 10)));
753 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 60, 10)));
754
755 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
756 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
757 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
758
759 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 60, 10)).isEmpty());
[email protected]022cbf162012-09-01 01:15:17760 EXPECT_RECT_EQ(IntRect(29, 30, 1, 10), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 60, 10)));
761 EXPECT_RECT_EQ(IntRect(30, 29, 60, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 60, 10)));
762 EXPECT_RECT_EQ(IntRect(90, 30, 1, 10), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 60, 10)));
[email protected]94f206c12012-08-25 00:09:14763 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 31, 60, 10)).isEmpty());
764
765 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 40, 70, 60)).isEmpty());
[email protected]022cbf162012-09-01 01:15:17766 EXPECT_RECT_EQ(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(29, 40, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14767 // This rect is mostly occluded by |child2|.
[email protected]022cbf162012-09-01 01:15:17768 EXPECT_RECT_EQ(IntRect(90, 39, 10, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14769 // This rect extends past top/right ends of |child2|.
[email protected]022cbf162012-09-01 01:15:17770 EXPECT_RECT_EQ(IntRect(30, 29, 70, 11), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14771 // This rect extends past left/right ends of |child2|.
[email protected]022cbf162012-09-01 01:15:17772 EXPECT_RECT_EQ(IntRect(20, 39, 80, 60), occlusion.unoccludedContentRect(parent, IntRect(20, 39, 80, 60)));
773 EXPECT_RECT_EQ(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(31, 40, 70, 60)));
774 EXPECT_RECT_EQ(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 41, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14775
776 /* Justification for the above occlusion from |layer|:
777 100
778 +---------------------+ +---------------------+
779 | | | |30 Visible region of |layer|: /////
780 | 30 | rotate(90) | 30 60 | |child2|: \\\\\
781 | 30 + ------------+--------------------+ | 30 +------------+--------------------+
782 100 | | 10 | | | ==> | |\\\\\\\\\\\\| |10 |
783 | |10+----------|----------------------+ | +--|\\\\\\\\\\\\|-----------------+ |
784 | + ------------+ | | | | | +------------+//| 420 | |
785 | | | | | | | | |///////////////|60 | |
786 | | | | | | | | |///////////////| | |
787 +----|--|-------------+ | | +--|--|---------------+ | |
788 | | | | 20|10| 70 | |
789 | | | | | | | |
790 | | | |500 | | | |
791 | | | | | | | |
792 | | | | | | | |
793 | | | | | | | |
794 | | | | | | |10|
795 +--|-------------------------------+ | | +------------------------------|--+
796 | | | 490 |
797 +---------------------------------+ +---------------------------------+
798 500 500
799 */
800 }
801};
802
[email protected]96baf3e2012-10-22 23:09:55803ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:14804
[email protected]ece1d952012-10-18 21:26:07805template<class Types>
[email protected]96baf3e2012-10-22 23:09:55806class OcclusionTrackerTestSurfaceRotatedOffAxis : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14807protected:
[email protected]96baf3e2012-10-22 23:09:55808 OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14809 void runMyTest()
810 {
811 WebTransformationMatrix childTransform;
812 childTransform.translate(250, 250);
813 childTransform.rotate(95);
814 childTransform.translate(-250, -250);
815
816 WebTransformationMatrix layerTransform;
817 layerTransform.translate(10, 10);
818
819 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
820 typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
821 child->setMasksToBounds(true);
822 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, layerTransform, FloatPoint(0, 0), IntSize(500, 500), true);
823 this->calcDrawEtc(parent);
824
[email protected]96baf3e2012-10-22 23:09:55825 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14826 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
827
[email protected]96baf3e2012-10-22 23:09:55828 IntRect clippedLayerInChild = MathUtil::mapClippedRect(layerTransform, layer->visibleContentRect());
[email protected]94f206c12012-08-25 00:09:14829
830 this->visitLayer(layer, occlusion);
831 this->enterContributingSurface(child, occlusion);
832
[email protected]022cbf162012-09-01 01:15:17833 EXPECT_RECT_EQ(IntRect(), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14834 EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17835 EXPECT_RECT_EQ(clippedLayerInChild, occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14836 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
837
838 EXPECT_TRUE(occlusion.occluded(child, clippedLayerInChild));
839 EXPECT_TRUE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
840 clippedLayerInChild.move(-1, 0);
841 EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
842 EXPECT_FALSE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
843 clippedLayerInChild.move(1, 0);
844 clippedLayerInChild.move(1, 0);
845 EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
846 EXPECT_FALSE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
847 clippedLayerInChild.move(-1, 0);
848 clippedLayerInChild.move(0, -1);
849 EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
850 EXPECT_FALSE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
851 clippedLayerInChild.move(0, 1);
852 clippedLayerInChild.move(0, 1);
853 EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
854 EXPECT_FALSE(occlusion.unoccludedContentRect(child, clippedLayerInChild).isEmpty());
855 clippedLayerInChild.move(0, -1);
856
857 this->leaveContributingSurface(child, occlusion);
858 this->enterLayer(parent, occlusion);
859
[email protected]022cbf162012-09-01 01:15:17860 EXPECT_RECT_EQ(IntRect(), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14861 EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17862 EXPECT_RECT_EQ(IntRect(), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14863 EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
864
865 EXPECT_FALSE(occlusion.occluded(parent, IntRect(75, 55, 1, 1)));
[email protected]022cbf162012-09-01 01:15:17866 EXPECT_RECT_EQ(IntRect(75, 55, 1, 1), occlusion.unoccludedContentRect(parent, IntRect(75, 55, 1, 1)));
[email protected]94f206c12012-08-25 00:09:14867 }
868};
869
[email protected]96baf3e2012-10-22 23:09:55870ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:14871
[email protected]ece1d952012-10-18 21:26:07872template<class Types>
[email protected]96baf3e2012-10-22 23:09:55873class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14874protected:
[email protected]96baf3e2012-10-22 23:09:55875 OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14876 void runMyTest()
877 {
878 WebTransformationMatrix childTransform;
879 childTransform.translate(250, 250);
880 childTransform.rotate(90);
881 childTransform.translate(-250, -250);
882
883 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
[email protected]23bbb412012-08-30 20:03:38884 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:14885 typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
886 child->setMasksToBounds(true);
887 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
888 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 450), IntSize(500, 60), true);
889 this->calcDrawEtc(parent);
890
[email protected]96baf3e2012-10-22 23:09:55891 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14892 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
893
894 this->visitLayer(layer2, occlusion);
895 this->visitLayer(layer1, occlusion);
896 this->enterContributingSurface(child, occlusion);
897
[email protected]022cbf162012-09-01 01:15:17898 EXPECT_RECT_EQ(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14899 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17900 EXPECT_RECT_EQ(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14901 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
902
903 EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
904 EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
905 EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
906 EXPECT_FALSE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
907 EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
908
909 EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
[email protected]022cbf162012-09-01 01:15:17910 EXPECT_RECT_EQ(IntRect(9, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)));
911 EXPECT_RECT_EQ(IntRect(10, 429, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)));
912 EXPECT_RECT_EQ(IntRect(70, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)));
913 EXPECT_RECT_EQ(IntRect(10, 500, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)));
[email protected]94f206c12012-08-25 00:09:14914
915 this->leaveContributingSurface(child, occlusion);
916 this->enterLayer(parent, occlusion);
917
[email protected]022cbf162012-09-01 01:15:17918 EXPECT_RECT_EQ(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14919 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17920 EXPECT_RECT_EQ(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14921 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
922
923 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
924 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
925 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
926
927 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 40, 70, 60)).isEmpty());
[email protected]022cbf162012-09-01 01:15:17928 EXPECT_RECT_EQ(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(29, 40, 70, 60)));
929 EXPECT_RECT_EQ(IntRect(30, 39, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 39, 70, 60)));
930 EXPECT_RECT_EQ(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(31, 40, 70, 60)));
931 EXPECT_RECT_EQ(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 41, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14932
933 /* Justification for the above occlusion from |layer1| and |layer2|:
934
935 +---------------------+
936 | |30 Visible region of |layer1|: /////
937 | | Visible region of |layer2|: \\\\\
938 | +---------------------------------+
939 | | |10 |
940 | +---------------+-----------------+ |
941 | | |\\\\\\\\\\\\|//| 420 | |
942 | | |\\\\\\\\\\\\|//|60 | |
943 | | |\\\\\\\\\\\\|//| | |
944 +--|--|------------|--+ | |
945 20|10| 70 | | |
946 | | | | |
947 | | | | |
948 | | | | |
949 | | | | |
950 | | | | |
951 | | | |10|
952 | +------------|-----------------|--+
953 | | 490 |
954 +---------------+-----------------+
955 60 440
956 */
957 }
958};
959
[email protected]96baf3e2012-10-22 23:09:55960ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:14961
[email protected]ece1d952012-10-18 21:26:07962template<class Types>
[email protected]96baf3e2012-10-22 23:09:55963class OcclusionTrackerTestOverlappingSurfaceSiblings : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14964protected:
[email protected]96baf3e2012-10-22 23:09:55965 OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14966 void runMyTest()
967 {
968 WebTransformationMatrix childTransform;
969 childTransform.translate(250, 250);
970 childTransform.rotate(90);
971 childTransform.translate(-250, -250);
972
973 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
[email protected]23bbb412012-08-30 20:03:38974 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:14975 typename Types::LayerType* child1 = this->createSurface(parent, childTransform, FloatPoint(30, 30), IntSize(10, 10));
976 typename Types::LayerType* child2 = this->createSurface(parent, childTransform, FloatPoint(20, 40), IntSize(10, 10));
977 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
978 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
979 this->calcDrawEtc(parent);
980
[email protected]96baf3e2012-10-22 23:09:55981 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14982 occlusion.setLayerClipRect(IntRect(-20, -20, 1000, 1000));
983
984 this->visitLayer(layer2, occlusion);
985 this->enterContributingSurface(child2, occlusion);
986
[email protected]022cbf162012-09-01 01:15:17987 EXPECT_RECT_EQ(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:14988 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:17989 EXPECT_RECT_EQ(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:14990 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
991
992 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
993 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
994 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
995 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
996 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
997
998 occlusion.useDefaultLayerClipRect();
999 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
1000 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
1001 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
1002 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
1003 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
1004 occlusion.setLayerClipRect(IntRect(-20, -20, 1000, 1000));
1005
1006 // There is nothing above child2's surface in the z-order.
[email protected]022cbf162012-09-01 01:15:171007 EXPECT_RECT_EQ(IntRect(-10, 420, 70, 80), occlusion.unoccludedContributingSurfaceContentRect(child2, false, IntRect(-10, 420, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141008
1009 this->leaveContributingSurface(child2, occlusion);
1010 this->visitLayer(layer1, occlusion);
1011 this->enterContributingSurface(child1, occlusion);
1012
[email protected]022cbf162012-09-01 01:15:171013 EXPECT_RECT_EQ(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141014 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171015 EXPECT_RECT_EQ(IntRect(-10, 430, 80, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141016 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1017
1018 EXPECT_TRUE(occlusion.occluded(child1, IntRect(-10, 430, 80, 70)));
1019 EXPECT_FALSE(occlusion.occluded(child1, IntRect(-11, 430, 80, 70)));
1020 EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 429, 80, 70)));
1021 EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 430, 81, 70)));
1022 EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 430, 80, 71)));
1023
1024 // child2's contents will occlude child1 below it.
[email protected]022cbf162012-09-01 01:15:171025 EXPECT_RECT_EQ(IntRect(-10, 430, 10, 70), occlusion.unoccludedContributingSurfaceContentRect(child1, false, IntRect(-10, 430, 80, 70)));
[email protected]94f206c12012-08-25 00:09:141026
1027 this->leaveContributingSurface(child1, occlusion);
1028 this->enterLayer(parent, occlusion);
1029
[email protected]022cbf162012-09-01 01:15:171030 EXPECT_RECT_EQ(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141031 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171032 EXPECT_RECT_EQ(IntRect(20, 20, 80, 80), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141033 EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
1034
1035 EXPECT_FALSE(occlusion.occluded(parent, IntRect(20, 20, 80, 80)));
1036
1037 EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 20, 70, 80)));
1038 EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 20, 70, 80)));
1039 EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 19, 70, 80)));
1040
1041 EXPECT_TRUE(occlusion.occluded(parent, IntRect(20, 30, 80, 70)));
1042 EXPECT_FALSE(occlusion.occluded(parent, IntRect(19, 30, 80, 70)));
1043 EXPECT_FALSE(occlusion.occluded(parent, IntRect(20, 29, 80, 70)));
1044
1045 /* Justification for the above occlusion:
1046 100
1047 +---------------------+
1048 | 20 | layer1
1049 | 30+ ---------------------------------+
1050 100 | 30| | layer2 |
1051 |20+----------------------------------+ |
1052 | | | | | |
1053 | | | | | |
1054 | | | | | |
1055 +--|-|----------------+ | |
1056 | | | | 510
1057 | | | |
1058 | | | |
1059 | | | |
1060 | | | |
1061 | | | |
1062 | | | |
1063 | +--------------------------------|-+
1064 | |
1065 +----------------------------------+
1066 510
1067 */
1068 }
1069};
1070
[email protected]96baf3e2012-10-22 23:09:551071ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:141072
[email protected]ece1d952012-10-18 21:26:071073template<class Types>
[email protected]96baf3e2012-10-22 23:09:551074class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141075protected:
[email protected]96baf3e2012-10-22 23:09:551076 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141077 void runMyTest()
1078 {
1079 WebTransformationMatrix child1Transform;
1080 child1Transform.translate(250, 250);
1081 child1Transform.rotate(-90);
1082 child1Transform.translate(-250, -250);
1083
1084 WebTransformationMatrix child2Transform;
1085 child2Transform.translate(250, 250);
1086 child2Transform.rotate(90);
1087 child2Transform.translate(-250, -250);
1088
1089 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
[email protected]23bbb412012-08-30 20:03:381090 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:141091 typename Types::LayerType* child1 = this->createSurface(parent, child1Transform, FloatPoint(30, 20), IntSize(10, 10));
1092 typename Types::LayerType* child2 = this->createDrawingSurface(parent, child2Transform, FloatPoint(20, 40), IntSize(10, 10), false);
1093 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, FloatPoint(-10, -20), IntSize(510, 510), true);
1094 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
1095 this->calcDrawEtc(parent);
1096
[email protected]96baf3e2012-10-22 23:09:551097 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141098 occlusion.setLayerClipRect(IntRect(-30, -30, 1000, 1000));
1099
1100 this->visitLayer(layer2, occlusion);
1101 this->enterLayer(child2, occlusion);
1102
[email protected]022cbf162012-09-01 01:15:171103 EXPECT_RECT_EQ(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141104 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171105 EXPECT_RECT_EQ(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141106 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1107
1108 EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
1109 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
1110 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
1111 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
1112 EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
1113
1114 this->leaveLayer(child2, occlusion);
1115 this->enterContributingSurface(child2, occlusion);
1116
1117 // There is nothing above child2's surface in the z-order.
[email protected]022cbf162012-09-01 01:15:171118 EXPECT_RECT_EQ(IntRect(-10, 420, 70, 80), occlusion.unoccludedContributingSurfaceContentRect(child2, false, IntRect(-10, 420, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141119
1120 this->leaveContributingSurface(child2, occlusion);
1121 this->visitLayer(layer1, occlusion);
1122 this->enterContributingSurface(child1, occlusion);
1123
[email protected]022cbf162012-09-01 01:15:171124 EXPECT_RECT_EQ(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141125 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171126 EXPECT_RECT_EQ(IntRect(420, -20, 80, 90), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141127 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1128
1129 EXPECT_TRUE(occlusion.occluded(child1, IntRect(420, -20, 80, 90)));
1130 EXPECT_FALSE(occlusion.occluded(child1, IntRect(419, -20, 80, 90)));
1131 EXPECT_FALSE(occlusion.occluded(child1, IntRect(420, -21, 80, 90)));
1132 EXPECT_FALSE(occlusion.occluded(child1, IntRect(420, -19, 80, 90)));
1133 EXPECT_FALSE(occlusion.occluded(child1, IntRect(421, -20, 80, 90)));
1134
1135 // child2's contents will occlude child1 below it.
[email protected]022cbf162012-09-01 01:15:171136 EXPECT_RECT_EQ(IntRect(420, -20, 80, 90), occlusion.unoccludedContributingSurfaceContentRect(child1, false, IntRect(420, -20, 80, 90)));
1137 EXPECT_RECT_EQ(IntRect(490, -10, 10, 80), occlusion.unoccludedContributingSurfaceContentRect(child1, false, IntRect(420, -10, 80, 90)));
1138 EXPECT_RECT_EQ(IntRect(420, -20, 70, 10), occlusion.unoccludedContributingSurfaceContentRect(child1, false, IntRect(420, -20, 70, 90)));
[email protected]94f206c12012-08-25 00:09:141139
1140 this->leaveContributingSurface(child1, occlusion);
1141 this->enterLayer(parent, occlusion);
1142
[email protected]022cbf162012-09-01 01:15:171143 EXPECT_RECT_EQ(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141144 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171145 EXPECT_RECT_EQ(IntRect(10, 20, 90, 80), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141146 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1147
1148 EXPECT_TRUE(occlusion.occluded(parent, IntRect(10, 20, 90, 80)));
1149 EXPECT_FALSE(occlusion.occluded(parent, IntRect(9, 20, 90, 80)));
1150 EXPECT_FALSE(occlusion.occluded(parent, IntRect(10, 19, 90, 80)));
1151 EXPECT_FALSE(occlusion.occluded(parent, IntRect(11, 20, 90, 80)));
1152 EXPECT_FALSE(occlusion.occluded(parent, IntRect(10, 21, 90, 80)));
1153
1154 /* Justification for the above occlusion:
1155 100
1156 +---------------------+
1157 |20 | layer1
1158 10+----------------------------------+
1159 100 || 30 | layer2 |
1160 |20+----------------------------------+
1161 || | | | |
1162 || | | | |
1163 || | | | |
1164 +|-|------------------+ | |
1165 | | | | 510
1166 | | 510 | |
1167 | | | |
1168 | | | |
1169 | | | |
1170 | | | |
1171 | | 520 | |
1172 +----------------------------------+ |
1173 | |
1174 +----------------------------------+
1175 510
1176 */
1177 }
1178};
1179
[email protected]96baf3e2012-10-22 23:09:551180ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:141181
[email protected]ece1d952012-10-18 21:26:071182template<class Types>
[email protected]96baf3e2012-10-22 23:09:551183class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141184protected:
[email protected]96baf3e2012-10-22 23:09:551185 OcclusionTrackerTestFilters(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141186 void runMyTest()
1187 {
1188 WebTransformationMatrix layerTransform;
1189 layerTransform.translate(250, 250);
1190 layerTransform.rotate(90);
1191 layerTransform.translate(-250, -250);
1192
1193 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
[email protected]23bbb412012-08-30 20:03:381194 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:141195 typename Types::ContentLayerType* blurLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
1196 typename Types::ContentLayerType* opaqueLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
1197 typename Types::ContentLayerType* opacityLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
1198
1199 WebFilterOperations filters;
1200 filters.append(WebFilterOperation::createBlurFilter(10));
1201 blurLayer->setFilters(filters);
1202
1203 filters.clear();
1204 filters.append(WebFilterOperation::createGrayscaleFilter(0.5));
1205 opaqueLayer->setFilters(filters);
1206
1207 filters.clear();
1208 filters.append(WebFilterOperation::createOpacityFilter(0.5));
1209 opacityLayer->setFilters(filters);
1210
1211 this->calcDrawEtc(parent);
1212
[email protected]96baf3e2012-10-22 23:09:551213 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141214 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1215
1216 // Opacity layer won't contribute to occlusion.
1217 this->visitLayer(opacityLayer, occlusion);
1218 this->enterContributingSurface(opacityLayer, occlusion);
1219
1220 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1221 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1222
1223 // And has nothing to contribute to its parent surface.
1224 this->leaveContributingSurface(opacityLayer, occlusion);
1225 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1226 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1227
1228 // Opaque layer will contribute to occlusion.
1229 this->visitLayer(opaqueLayer, occlusion);
1230 this->enterContributingSurface(opaqueLayer, occlusion);
1231
[email protected]022cbf162012-09-01 01:15:171232 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141233 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171234 EXPECT_RECT_EQ(IntRect(0, 430, 70, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141235 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1236
1237 // And it gets translated to the parent surface.
1238 this->leaveContributingSurface(opaqueLayer, occlusion);
[email protected]022cbf162012-09-01 01:15:171239 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141240 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171241 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141242 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1243
1244 // The blur layer needs to throw away any occlusion from outside its subtree.
1245 this->enterLayer(blurLayer, occlusion);
1246 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1247 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1248
1249 // And it won't contribute to occlusion.
1250 this->leaveLayer(blurLayer, occlusion);
1251 this->enterContributingSurface(blurLayer, occlusion);
1252 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1253 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1254
1255 // But the opaque layer's occlusion is preserved on the parent.
1256 this->leaveContributingSurface(blurLayer, occlusion);
1257 this->enterLayer(parent, occlusion);
[email protected]022cbf162012-09-01 01:15:171258 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141259 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171260 EXPECT_RECT_EQ(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141261 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1262 }
1263};
1264
[email protected]96baf3e2012-10-22 23:09:551265ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:141266
[email protected]ece1d952012-10-18 21:26:071267template<class Types>
[email protected]96baf3e2012-10-22 23:09:551268class OcclusionTrackerTestReplicaDoesOcclude : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141269protected:
[email protected]96baf3e2012-10-22 23:09:551270 OcclusionTrackerTestReplicaDoesOcclude(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141271 void runMyTest()
1272 {
1273 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 200));
1274 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 100), IntSize(50, 50), true);
1275 this->createReplicaLayer(surface, this->identityMatrix, FloatPoint(50, 50), IntSize());
1276 this->calcDrawEtc(parent);
1277
[email protected]96baf3e2012-10-22 23:09:551278 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141279 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1280
1281 this->visitLayer(surface, occlusion);
1282
[email protected]022cbf162012-09-01 01:15:171283 EXPECT_RECT_EQ(IntRect(0, 100, 50, 50), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141284 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171285 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141286 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1287
1288 this->visitContributingSurface(surface, occlusion);
1289 this->enterLayer(parent, occlusion);
1290
1291 // The surface and replica should both be occluding the parent.
[email protected]022cbf162012-09-01 01:15:171292 EXPECT_RECT_EQ(IntRect(0, 100, 100, 100), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141293 EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
1294 }
1295};
1296
[email protected]96baf3e2012-10-22 23:09:551297ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude);
[email protected]94f206c12012-08-25 00:09:141298
[email protected]ece1d952012-10-18 21:26:071299template<class Types>
[email protected]96baf3e2012-10-22 23:09:551300class OcclusionTrackerTestReplicaWithClipping : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141301protected:
[email protected]96baf3e2012-10-22 23:09:551302 OcclusionTrackerTestReplicaWithClipping(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141303 void runMyTest()
1304 {
1305 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 170));
[email protected]23bbb412012-08-30 20:03:381306 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:141307 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 100), IntSize(50, 50), true);
1308 this->createReplicaLayer(surface, this->identityMatrix, FloatPoint(50, 50), IntSize());
1309 this->calcDrawEtc(parent);
1310
[email protected]96baf3e2012-10-22 23:09:551311 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141312 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1313
1314 this->visitLayer(surface, occlusion);
1315
[email protected]022cbf162012-09-01 01:15:171316 EXPECT_RECT_EQ(IntRect(0, 100, 50, 50), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141317 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171318 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141319 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1320
1321 this->visitContributingSurface(surface, occlusion);
1322 this->enterLayer(parent, occlusion);
1323
1324 // The surface and replica should both be occluding the parent.
[email protected]022cbf162012-09-01 01:15:171325 EXPECT_RECT_EQ(IntRect(0, 100, 100, 70), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141326 EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
1327 }
1328};
1329
[email protected]96baf3e2012-10-22 23:09:551330ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping);
[email protected]94f206c12012-08-25 00:09:141331
[email protected]ece1d952012-10-18 21:26:071332template<class Types>
[email protected]96baf3e2012-10-22 23:09:551333class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141334protected:
[email protected]96baf3e2012-10-22 23:09:551335 OcclusionTrackerTestReplicaWithMask(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141336 void runMyTest()
1337 {
1338 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 200));
1339 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 100), IntSize(50, 50), true);
1340 typename Types::LayerType* replica = this->createReplicaLayer(surface, this->identityMatrix, FloatPoint(50, 50), IntSize());
1341 this->createMaskLayer(replica, IntSize(10, 10));
1342 this->calcDrawEtc(parent);
1343
[email protected]96baf3e2012-10-22 23:09:551344 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141345 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1346
1347 this->visitLayer(surface, occlusion);
1348
[email protected]022cbf162012-09-01 01:15:171349 EXPECT_RECT_EQ(IntRect(0, 100, 50, 50), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141350 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:171351 EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141352 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1353
1354 this->visitContributingSurface(surface, occlusion);
1355 this->enterLayer(parent, occlusion);
1356
1357 // The replica should not be occluding the parent, since it has a mask applied to it.
[email protected]022cbf162012-09-01 01:15:171358 EXPECT_RECT_EQ(IntRect(0, 100, 50, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:141359 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
1360 }
1361};
1362
[email protected]96baf3e2012-10-22 23:09:551363ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask);
[email protected]94f206c12012-08-25 00:09:141364
[email protected]ece1d952012-10-18 21:26:071365template<class Types>
[email protected]96baf3e2012-10-22 23:09:551366class OcclusionTrackerTestLayerClipRectOutsideChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141367protected:
[email protected]96baf3e2012-10-22 23:09:551368 OcclusionTrackerTestLayerClipRectOutsideChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141369 void runMyTest()
1370 {
1371 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1372 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1373 this->calcDrawEtc(parent);
1374
[email protected]96baf3e2012-10-22 23:09:551375 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141376 occlusion.setLayerClipRect(IntRect(200, 100, 100, 100));
1377
1378 this->enterLayer(layer, occlusion);
1379
1380 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1381 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1382 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1383 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1384 EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1385
1386 occlusion.useDefaultLayerClipRect();
1387 EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1388 occlusion.setLayerClipRect(IntRect(200, 100, 100, 100));
1389
1390 this->leaveLayer(layer, occlusion);
1391 this->visitContributingSurface(layer, occlusion);
1392 this->enterLayer(parent, occlusion);
1393
1394 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1395 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1396 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1397 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1398 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1399 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1400 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1401 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1402 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1403
[email protected]022cbf162012-09-01 01:15:171404 EXPECT_RECT_EQ(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:141405 }
1406};
1407
[email protected]96baf3e2012-10-22 23:09:551408ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOutsideChild);
[email protected]94f206c12012-08-25 00:09:141409
[email protected]ece1d952012-10-18 21:26:071410template<class Types>
[email protected]96baf3e2012-10-22 23:09:551411class OcclusionTrackerTestViewportRectOutsideChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141412protected:
[email protected]96baf3e2012-10-22 23:09:551413 OcclusionTrackerTestViewportRectOutsideChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141414 void runMyTest()
1415 {
1416 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1417 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1418 this->calcDrawEtc(parent);
1419
[email protected]96baf3e2012-10-22 23:09:551420 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(200, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:141421 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1422
1423 this->enterLayer(layer, occlusion);
1424
1425 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1426 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1427 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1428 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1429 EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1430
1431 occlusion.useDefaultLayerClipRect();
1432 EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1433 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1434
1435 this->leaveLayer(layer, occlusion);
1436 this->visitContributingSurface(layer, occlusion);
1437 this->enterLayer(parent, occlusion);
1438
1439 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1440 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1441 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1442 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1443 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1444 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1445 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1446 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1447 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1448
[email protected]022cbf162012-09-01 01:15:171449 EXPECT_RECT_EQ(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:141450 }
1451};
1452
[email protected]96baf3e2012-10-22 23:09:551453ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOutsideChild);
[email protected]94f206c12012-08-25 00:09:141454
[email protected]ece1d952012-10-18 21:26:071455template<class Types>
[email protected]96baf3e2012-10-22 23:09:551456class OcclusionTrackerTestLayerClipRectOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141457protected:
[email protected]96baf3e2012-10-22 23:09:551458 OcclusionTrackerTestLayerClipRectOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141459 void runMyTest()
1460 {
1461 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1462 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1463 this->calcDrawEtc(parent);
1464
[email protected]96baf3e2012-10-22 23:09:551465 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141466 occlusion.setLayerClipRect(IntRect(100, 100, 100, 100));
1467
1468 this->enterLayer(layer, occlusion);
1469
1470 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1471 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1472 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1473 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1474
1475 this->leaveLayer(layer, occlusion);
1476 this->visitContributingSurface(layer, occlusion);
1477 this->enterLayer(parent, occlusion);
1478
1479 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1480 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1481 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1482 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1483 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1484 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1485 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1486 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1487 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1488
1489 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1490 }
1491};
1492
[email protected]96baf3e2012-10-22 23:09:551493ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOverChild);
[email protected]94f206c12012-08-25 00:09:141494
[email protected]ece1d952012-10-18 21:26:071495template<class Types>
[email protected]96baf3e2012-10-22 23:09:551496class OcclusionTrackerTestViewportRectOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141497protected:
[email protected]96baf3e2012-10-22 23:09:551498 OcclusionTrackerTestViewportRectOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141499 void runMyTest()
1500 {
1501 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1502 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1503 this->calcDrawEtc(parent);
1504
[email protected]96baf3e2012-10-22 23:09:551505 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(100, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:141506 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1507
1508 this->enterLayer(layer, occlusion);
1509
1510 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1511 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1512 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1513 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1514
1515 this->leaveLayer(layer, occlusion);
1516 this->visitContributingSurface(layer, occlusion);
1517 this->enterLayer(parent, occlusion);
1518
1519 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1520 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1521 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1522 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1523 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1524 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1525 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1526 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1527 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1528
1529 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1530 }
1531};
1532
[email protected]96baf3e2012-10-22 23:09:551533ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverChild);
[email protected]94f206c12012-08-25 00:09:141534
[email protected]ece1d952012-10-18 21:26:071535template<class Types>
[email protected]96baf3e2012-10-22 23:09:551536class OcclusionTrackerTestLayerClipRectPartlyOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141537protected:
[email protected]96baf3e2012-10-22 23:09:551538 OcclusionTrackerTestLayerClipRectPartlyOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141539 void runMyTest()
1540 {
1541 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1542 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1543 this->calcDrawEtc(parent);
1544
[email protected]96baf3e2012-10-22 23:09:551545 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141546 occlusion.setLayerClipRect(IntRect(50, 50, 200, 200));
1547
1548 this->enterLayer(layer, occlusion);
1549
1550 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1551 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1552 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1553 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1554
1555 this->leaveLayer(layer, occlusion);
1556 this->visitContributingSurface(layer, occlusion);
1557 this->enterLayer(parent, occlusion);
1558
1559 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1560 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1561 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1562 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1563 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1564 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1565 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1566 EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1567 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1568
[email protected]022cbf162012-09-01 01:15:171569 EXPECT_RECT_EQ(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1570 EXPECT_RECT_EQ(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)));
1571 EXPECT_RECT_EQ(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)));
1572 EXPECT_RECT_EQ(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)));
1573 EXPECT_RECT_EQ(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141574 }
1575};
1576
[email protected]96baf3e2012-10-22 23:09:551577ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectPartlyOverChild);
[email protected]94f206c12012-08-25 00:09:141578
[email protected]ece1d952012-10-18 21:26:071579template<class Types>
[email protected]96baf3e2012-10-22 23:09:551580class OcclusionTrackerTestViewportRectPartlyOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141581protected:
[email protected]96baf3e2012-10-22 23:09:551582 OcclusionTrackerTestViewportRectPartlyOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141583 void runMyTest()
1584 {
1585 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1586 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1587 this->calcDrawEtc(parent);
1588
[email protected]96baf3e2012-10-22 23:09:551589 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(50, 50, 200, 200));
[email protected]94f206c12012-08-25 00:09:141590 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1591
1592 this->enterLayer(layer, occlusion);
1593
1594 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1595 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1596 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1597 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1598
1599 this->leaveLayer(layer, occlusion);
1600 this->visitContributingSurface(layer, occlusion);
1601 this->enterLayer(parent, occlusion);
1602
1603 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1604 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1605 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1606 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1607 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1608 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1609 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1610 EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1611 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1612
[email protected]022cbf162012-09-01 01:15:171613 EXPECT_RECT_EQ(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
1614 EXPECT_RECT_EQ(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)));
1615 EXPECT_RECT_EQ(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)));
1616 EXPECT_RECT_EQ(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)));
1617 EXPECT_RECT_EQ(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141618 }
1619};
1620
[email protected]96baf3e2012-10-22 23:09:551621ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectPartlyOverChild);
[email protected]94f206c12012-08-25 00:09:141622
[email protected]ece1d952012-10-18 21:26:071623template<class Types>
[email protected]96baf3e2012-10-22 23:09:551624class OcclusionTrackerTestLayerClipRectOverNothing : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141625protected:
[email protected]96baf3e2012-10-22 23:09:551626 OcclusionTrackerTestLayerClipRectOverNothing(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141627 void runMyTest()
1628 {
1629 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1630 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1631 this->calcDrawEtc(parent);
1632
[email protected]96baf3e2012-10-22 23:09:551633 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141634 occlusion.setLayerClipRect(IntRect(500, 500, 100, 100));
1635
1636 this->enterLayer(layer, occlusion);
1637
1638 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1639 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1640 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1641 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1642
1643 this->leaveLayer(layer, occlusion);
1644 this->visitContributingSurface(layer, occlusion);
1645 this->enterLayer(parent, occlusion);
1646
1647 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1648 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1649 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1650 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1651 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1652 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1653 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1654 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1655 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1656
1657 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1658 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)).isEmpty());
1659 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)).isEmpty());
1660 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)).isEmpty());
1661 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)).isEmpty());
1662 }
1663};
1664
[email protected]96baf3e2012-10-22 23:09:551665ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOverNothing);
[email protected]94f206c12012-08-25 00:09:141666
[email protected]ece1d952012-10-18 21:26:071667template<class Types>
[email protected]96baf3e2012-10-22 23:09:551668class OcclusionTrackerTestViewportRectOverNothing : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141669protected:
[email protected]96baf3e2012-10-22 23:09:551670 OcclusionTrackerTestViewportRectOverNothing(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141671 void runMyTest()
1672 {
1673 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1674 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1675 this->calcDrawEtc(parent);
1676
[email protected]96baf3e2012-10-22 23:09:551677 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(500, 500, 100, 100));
[email protected]94f206c12012-08-25 00:09:141678 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1679
1680 this->enterLayer(layer, occlusion);
1681
1682 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1683 EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1684 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1685 EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1686
1687 this->leaveLayer(layer, occlusion);
1688 this->visitContributingSurface(layer, occlusion);
1689 this->enterLayer(parent, occlusion);
1690
1691 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
1692 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1693 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
1694 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1695 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
1696 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
1697 EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
1698 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
1699 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1700
1701 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
1702 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)).isEmpty());
1703 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)).isEmpty());
1704 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)).isEmpty());
1705 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)).isEmpty());
1706 }
1707};
1708
[email protected]96baf3e2012-10-22 23:09:551709ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverNothing);
[email protected]94f206c12012-08-25 00:09:141710
[email protected]ece1d952012-10-18 21:26:071711template<class Types>
[email protected]96baf3e2012-10-22 23:09:551712class OcclusionTrackerTestLayerClipRectForLayerOffOrigin : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141713protected:
[email protected]96baf3e2012-10-22 23:09:551714 OcclusionTrackerTestLayerClipRectForLayerOffOrigin(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141715 void runMyTest()
1716 {
1717 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1718 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
1719 this->calcDrawEtc(parent);
1720
[email protected]96baf3e2012-10-22 23:09:551721 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141722 this->enterLayer(layer, occlusion);
1723
1724 // This layer is translated when drawn into its target. So if the clip rect given from the target surface
1725 // is not in that target space, then after translating these query rects into the target, they will fall outside
1726 // the clip and be considered occluded.
1727 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1728 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1729 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1730 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1731 }
1732};
1733
[email protected]96baf3e2012-10-22 23:09:551734ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectForLayerOffOrigin);
[email protected]94f206c12012-08-25 00:09:141735
[email protected]ece1d952012-10-18 21:26:071736template<class Types>
[email protected]96baf3e2012-10-22 23:09:551737class OcclusionTrackerTestOpaqueContentsRegionEmpty : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141738protected:
[email protected]96baf3e2012-10-22 23:09:551739 OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141740 void runMyTest()
1741 {
1742 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1743 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), false);
1744 this->calcDrawEtc(parent);
1745
[email protected]96baf3e2012-10-22 23:09:551746 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141747 this->enterLayer(layer, occlusion);
1748
1749 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
1750 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
1751 EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
1752 EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
1753
1754 // Occluded since its outside the surface bounds.
1755 EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1756
1757 // Test without any clip rect.
1758 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
1759 EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
1760 occlusion.useDefaultLayerClipRect();
1761
1762 this->leaveLayer(layer, occlusion);
1763 this->visitContributingSurface(layer, occlusion);
1764 this->enterLayer(parent, occlusion);
1765
1766 EXPECT_TRUE(occlusion.occlusionInScreenSpace().bounds().isEmpty());
1767 EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
1768 }
1769};
1770
[email protected]96baf3e2012-10-22 23:09:551771MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141772
[email protected]ece1d952012-10-18 21:26:071773template<class Types>
[email protected]96baf3e2012-10-22 23:09:551774class OcclusionTrackerTestOpaqueContentsRegionNonEmpty : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141775protected:
[email protected]96baf3e2012-10-22 23:09:551776 OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141777 void runMyTest()
1778 {
1779 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1780 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(100, 100), IntSize(200, 200), false);
1781 this->calcDrawEtc(parent);
1782
1783 {
[email protected]96baf3e2012-10-22 23:09:551784 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141785 layer->setOpaqueContentsRect(IntRect(0, 0, 100, 100));
1786
1787 this->resetLayerIterator();
1788 this->visitLayer(layer, occlusion);
1789 this->enterLayer(parent, occlusion);
1790
[email protected]022cbf162012-09-01 01:15:171791 EXPECT_RECT_EQ(IntRect(100, 100, 100, 100), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141792 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1793
1794 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1795 EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1796 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1797 }
1798
1799 {
[email protected]96baf3e2012-10-22 23:09:551800 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141801 layer->setOpaqueContentsRect(IntRect(20, 20, 180, 180));
1802
1803 this->resetLayerIterator();
1804 this->visitLayer(layer, occlusion);
1805 this->enterLayer(parent, occlusion);
1806
[email protected]022cbf162012-09-01 01:15:171807 EXPECT_RECT_EQ(IntRect(120, 120, 180, 180), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141808 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1809
1810 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1811 EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1812 EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1813 }
1814
1815 {
[email protected]96baf3e2012-10-22 23:09:551816 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141817 layer->setOpaqueContentsRect(IntRect(150, 150, 100, 100));
1818
1819 this->resetLayerIterator();
1820 this->visitLayer(layer, occlusion);
1821 this->enterLayer(parent, occlusion);
1822
[email protected]022cbf162012-09-01 01:15:171823 EXPECT_RECT_EQ(IntRect(250, 250, 50, 50), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:141824 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
1825
1826 EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
1827 EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
1828 EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
1829 }
1830 }
1831};
1832
[email protected]96baf3e2012-10-22 23:09:551833MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141834
[email protected]ece1d952012-10-18 21:26:071835template<class Types>
[email protected]96baf3e2012-10-22 23:09:551836class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141837protected:
[email protected]96baf3e2012-10-22 23:09:551838 OcclusionTrackerTest3dTransform(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141839 void runMyTest()
1840 {
1841 WebTransformationMatrix transform;
1842 transform.rotate3d(0, 30, 0);
1843
1844 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1845 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1846 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, FloatPoint(100, 100), IntSize(200, 200), true);
1847 this->calcDrawEtc(parent);
1848
[email protected]96baf3e2012-10-22 23:09:551849 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141850 this->enterLayer(layer, occlusion);
1851
1852 // The layer is rotated in 3d but without preserving 3d, so it only gets resized.
[email protected]022cbf162012-09-01 01:15:171853 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)));
[email protected]94f206c12012-08-25 00:09:141854 }
1855};
1856
[email protected]96baf3e2012-10-22 23:09:551857MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform);
[email protected]94f206c12012-08-25 00:09:141858
[email protected]ece1d952012-10-18 21:26:071859template<class Types>
[email protected]96baf3e2012-10-22 23:09:551860class OcclusionTrackerTestUnsorted3dLayers : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141861protected:
[email protected]96baf3e2012-10-22 23:09:551862 OcclusionTrackerTestUnsorted3dLayers(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141863 void runMyTest()
1864 {
1865 // Currently, the main thread layer iterator does not iterate over 3d items in
1866 // sorted order, because layer sorting is not performed on the main thread.
1867 // Because of this, the occlusion tracker cannot assume that a 3d layer occludes
1868 // other layers that have not yet been iterated over. For now, the expected
1869 // behavior is that a 3d layer simply does not add any occlusion to the occlusion
1870 // tracker.
1871
1872 WebTransformationMatrix translationToFront;
1873 translationToFront.translate3d(0, 0, -10);
1874 WebTransformationMatrix translationToBack;
1875 translationToFront.translate3d(0, 0, -100);
1876
1877 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1878 typename Types::ContentLayerType* child1 = this->createDrawingLayer(parent, translationToBack, FloatPoint(0, 0), IntSize(100, 100), true);
1879 typename Types::ContentLayerType* child2 = this->createDrawingLayer(parent, translationToFront, FloatPoint(50, 50), IntSize(100, 100), true);
1880 parent->setPreserves3D(true);
1881
1882 this->calcDrawEtc(parent);
1883
[email protected]96baf3e2012-10-22 23:09:551884 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141885 this->visitLayer(child2, occlusion);
1886 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1887 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1888
1889 this->visitLayer(child1, occlusion);
1890 EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
1891 EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
1892 }
1893};
1894
1895// This test will have different layer ordering on the impl thread; the test will only work on the main thread.
[email protected]96baf3e2012-10-22 23:09:551896MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
[email protected]94f206c12012-08-25 00:09:141897
[email protected]ece1d952012-10-18 21:26:071898template<class Types>
[email protected]96baf3e2012-10-22 23:09:551899class OcclusionTrackerTestPerspectiveTransform : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141900protected:
[email protected]96baf3e2012-10-22 23:09:551901 OcclusionTrackerTestPerspectiveTransform(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141902 void runMyTest()
1903 {
1904 WebTransformationMatrix transform;
1905 transform.translate(150, 150);
1906 transform.applyPerspective(400);
1907 transform.rotate3d(1, 0, 0, -30);
1908 transform.translate(-150, -150);
1909
1910 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1911 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
1912 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, FloatPoint(100, 100), IntSize(200, 200), true);
1913 container->setPreserves3D(true);
1914 layer->setPreserves3D(true);
1915 this->calcDrawEtc(parent);
1916
[email protected]96baf3e2012-10-22 23:09:551917 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141918 this->enterLayer(layer, occlusion);
1919
[email protected]022cbf162012-09-01 01:15:171920 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)));
[email protected]94f206c12012-08-25 00:09:141921 }
1922};
1923
1924// This test requires accumulating occlusion of 3d layers, which are skipped by the occlusion tracker on the main thread. So this test should run on the impl thread.
[email protected]96baf3e2012-10-22 23:09:551925IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransform);
[email protected]94f206c12012-08-25 00:09:141926
[email protected]ece1d952012-10-18 21:26:071927template<class Types>
[email protected]96baf3e2012-10-22 23:09:551928class OcclusionTrackerTestPerspectiveTransformBehindCamera : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141929protected:
[email protected]96baf3e2012-10-22 23:09:551930 OcclusionTrackerTestPerspectiveTransformBehindCamera(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141931 void runMyTest()
1932 {
1933 // This test is based on the platform/chromium/compositing/3d-corners.html layout test.
1934 WebTransformationMatrix transform;
1935 transform.translate(250, 50);
1936 transform.applyPerspective(10);
1937 transform.translate(-250, -50);
1938 transform.translate(250, 50);
1939 transform.rotate3d(1, 0, 0, -167);
1940 transform.translate(-250, -50);
1941
1942 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(500, 100));
1943 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(500, 500));
1944 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, FloatPoint(0, 0), IntSize(500, 500), true);
1945 container->setPreserves3D(true);
1946 layer->setPreserves3D(true);
1947 this->calcDrawEtc(parent);
1948
[email protected]96baf3e2012-10-22 23:09:551949 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141950 this->enterLayer(layer, occlusion);
1951
1952 // The bottom 11 pixel rows of this layer remain visible inside the container, after translation to the target surface. When translated back,
1953 // this will include many more pixels but must include at least the bottom 11 rows.
1954 EXPECT_TRUE(occlusion.unoccludedContentRect(layer, IntRect(0, 0, 500, 500)).contains(IntRect(0, 489, 500, 11)));
1955 }
1956};
1957
1958// This test requires accumulating occlusion of 3d layers, which are skipped by the occlusion tracker on the main thread. So this test should run on the impl thread.
[email protected]96baf3e2012-10-22 23:09:551959IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransformBehindCamera);
[email protected]94f206c12012-08-25 00:09:141960
[email protected]ece1d952012-10-18 21:26:071961template<class Types>
[email protected]96baf3e2012-10-22 23:09:551962class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141963protected:
[email protected]96baf3e2012-10-22 23:09:551964 OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141965 void runMyTest()
1966 {
1967 WebTransformationMatrix transform;
1968 transform.translate(50, 50);
1969 transform.applyPerspective(100);
1970 transform.translate3d(0, 0, 110);
1971 transform.translate(-50, -50);
1972
1973 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
1974 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, transform, FloatPoint(0, 0), IntSize(100, 100), true);
1975 parent->setPreserves3D(true);
1976 layer->setPreserves3D(true);
1977 this->calcDrawEtc(parent);
1978
[email protected]96baf3e2012-10-22 23:09:551979 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141980
1981 // The |layer| is entirely behind the camera and should not occlude.
1982 this->visitLayer(layer, occlusion);
1983 this->enterLayer(parent, occlusion);
1984 EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
1985 EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
1986 }
1987};
1988
1989// This test requires accumulating occlusion of 3d layers, which are skipped by the occlusion tracker on the main thread. So this test should run on the impl thread.
[email protected]96baf3e2012-10-22 23:09:551990IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude);
[email protected]94f206c12012-08-25 00:09:141991
[email protected]ece1d952012-10-18 21:26:071992template<class Types>
[email protected]96baf3e2012-10-22 23:09:551993class OcclusionTrackerTestLargePixelsOccludeInsideClipRect : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141994protected:
[email protected]96baf3e2012-10-22 23:09:551995 OcclusionTrackerTestLargePixelsOccludeInsideClipRect(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141996 void runMyTest()
1997 {
1998 WebTransformationMatrix transform;
1999 transform.translate(50, 50);
2000 transform.applyPerspective(100);
2001 transform.translate3d(0, 0, 99);
2002 transform.translate(-50, -50);
2003
2004 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
[email protected]23bbb412012-08-30 20:03:382005 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:142006 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, transform, FloatPoint(0, 0), IntSize(100, 100), true);
2007 parent->setPreserves3D(true);
2008 layer->setPreserves3D(true);
2009 this->calcDrawEtc(parent);
2010
[email protected]96baf3e2012-10-22 23:09:552011 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142012
2013 // This is very close to the camera, so pixels in its visibleContentRect will actually go outside of the layer's clipRect.
2014 // Ensure that those pixels don't occlude things outside the clipRect.
2015 this->visitLayer(layer, occlusion);
2016 this->enterLayer(parent, occlusion);
[email protected]022cbf162012-09-01 01:15:172017 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142018 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
[email protected]022cbf162012-09-01 01:15:172019 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142020 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
2021 }
2022};
2023
2024// This test requires accumulating occlusion of 3d layers, which are skipped by the occlusion tracker on the main thread. So this test should run on the impl thread.
[email protected]96baf3e2012-10-22 23:09:552025IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect);
[email protected]94f206c12012-08-25 00:09:142026
[email protected]ece1d952012-10-18 21:26:072027template<class Types>
[email protected]96baf3e2012-10-22 23:09:552028class OcclusionTrackerTestAnimationOpacity1OnMainThread : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142029protected:
[email protected]96baf3e2012-10-22 23:09:552030 OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142031 void runMyTest()
2032 {
2033 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
2034 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300), true);
2035 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300), true);
2036 typename Types::ContentLayerType* surfaceChild = this->createDrawingLayer(surface, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 300), true);
2037 typename Types::ContentLayerType* surfaceChild2 = this->createDrawingLayer(surface, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 300), true);
2038 typename Types::ContentLayerType* parent2 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false);
2039 typename Types::ContentLayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(250, 0), IntSize(50, 300), true);
2040
2041 addOpacityTransitionToController(*layer->layerAnimationController(), 10, 0, 1, false);
2042 addOpacityTransitionToController(*surface->layerAnimationController(), 10, 0, 1, false);
2043 this->calcDrawEtc(parent);
2044
2045 EXPECT_TRUE(layer->drawOpacityIsAnimating());
2046 EXPECT_FALSE(surface->drawOpacityIsAnimating());
2047 EXPECT_TRUE(surface->renderSurface()->drawOpacityIsAnimating());
2048
[email protected]96baf3e2012-10-22 23:09:552049 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142050
2051 this->visitLayer(topmost, occlusion);
2052 this->enterLayer(parent2, occlusion);
2053 // This occlusion will affect all surfaces.
[email protected]022cbf162012-09-01 01:15:172054 EXPECT_RECT_EQ(IntRect(0, 0, 250, 300), occlusion.unoccludedContentRect(parent2, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142055 this->leaveLayer(parent2, occlusion);
2056
2057 this->visitLayer(surfaceChild2, occlusion);
2058 this->enterLayer(surfaceChild, occlusion);
[email protected]022cbf162012-09-01 01:15:172059 EXPECT_RECT_EQ(IntRect(100, 0, 100, 300), occlusion.unoccludedContentRect(surfaceChild, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142060 this->leaveLayer(surfaceChild, occlusion);
2061 this->enterLayer(surface, occlusion);
[email protected]022cbf162012-09-01 01:15:172062 EXPECT_RECT_EQ(IntRect(200, 0, 50, 300), occlusion.unoccludedContentRect(surface, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142063 this->leaveLayer(surface, occlusion);
2064
2065 this->enterContributingSurface(surface, occlusion);
2066 // Occlusion within the surface is lost when leaving the animating surface.
[email protected]022cbf162012-09-01 01:15:172067 EXPECT_RECT_EQ(IntRect(0, 0, 250, 300), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142068 this->leaveContributingSurface(surface, occlusion);
2069
2070 this->visitLayer(layer, occlusion);
2071 this->enterLayer(parent, occlusion);
2072
2073 // Occlusion is not added for the animating |layer|.
[email protected]022cbf162012-09-01 01:15:172074 EXPECT_RECT_EQ(IntRect(0, 0, 250, 300), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142075 }
2076};
2077
[email protected]96baf3e2012-10-22 23:09:552078MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread);
[email protected]94f206c12012-08-25 00:09:142079
[email protected]ece1d952012-10-18 21:26:072080template<class Types>
[email protected]96baf3e2012-10-22 23:09:552081class OcclusionTrackerTestAnimationOpacity0OnMainThread : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142082protected:
[email protected]96baf3e2012-10-22 23:09:552083 OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142084 void runMyTest()
2085 {
2086 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
2087 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300), true);
2088 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300), true);
2089 typename Types::ContentLayerType* surfaceChild = this->createDrawingLayer(surface, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 300), true);
2090 typename Types::ContentLayerType* surfaceChild2 = this->createDrawingLayer(surface, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 300), true);
2091 typename Types::ContentLayerType* parent2 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false);
2092 typename Types::ContentLayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(250, 0), IntSize(50, 300), true);
2093
2094 addOpacityTransitionToController(*layer->layerAnimationController(), 10, 1, 0, false);
2095 addOpacityTransitionToController(*surface->layerAnimationController(), 10, 1, 0, false);
2096 this->calcDrawEtc(parent);
2097
2098 EXPECT_TRUE(layer->drawOpacityIsAnimating());
2099 EXPECT_FALSE(surface->drawOpacityIsAnimating());
2100 EXPECT_TRUE(surface->renderSurface()->drawOpacityIsAnimating());
2101
[email protected]96baf3e2012-10-22 23:09:552102 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142103
2104 this->visitLayer(topmost, occlusion);
2105 this->enterLayer(parent2, occlusion);
2106 // This occlusion will affect all surfaces.
[email protected]022cbf162012-09-01 01:15:172107 EXPECT_RECT_EQ(IntRect(0, 0, 250, 300), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142108 this->leaveLayer(parent2, occlusion);
2109
2110 this->visitLayer(surfaceChild2, occlusion);
2111 this->enterLayer(surfaceChild, occlusion);
[email protected]022cbf162012-09-01 01:15:172112 EXPECT_RECT_EQ(IntRect(100, 0, 100, 300), occlusion.unoccludedContentRect(surfaceChild, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142113 this->leaveLayer(surfaceChild, occlusion);
2114 this->enterLayer(surface, occlusion);
[email protected]022cbf162012-09-01 01:15:172115 EXPECT_RECT_EQ(IntRect(200, 0, 50, 300), occlusion.unoccludedContentRect(surface, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142116 this->leaveLayer(surface, occlusion);
2117
2118 this->enterContributingSurface(surface, occlusion);
2119 // Occlusion within the surface is lost when leaving the animating surface.
[email protected]022cbf162012-09-01 01:15:172120 EXPECT_RECT_EQ(IntRect(0, 0, 250, 300), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142121 this->leaveContributingSurface(surface, occlusion);
2122
2123 this->visitLayer(layer, occlusion);
2124 this->enterLayer(parent, occlusion);
2125
2126 // Occlusion is not added for the animating |layer|.
[email protected]022cbf162012-09-01 01:15:172127 EXPECT_RECT_EQ(IntRect(0, 0, 250, 300), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142128 }
2129};
2130
[email protected]96baf3e2012-10-22 23:09:552131MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread);
[email protected]94f206c12012-08-25 00:09:142132
[email protected]ece1d952012-10-18 21:26:072133template<class Types>
[email protected]96baf3e2012-10-22 23:09:552134class OcclusionTrackerTestAnimationTranslateOnMainThread : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142135protected:
[email protected]96baf3e2012-10-22 23:09:552136 OcclusionTrackerTestAnimationTranslateOnMainThread(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142137 void runMyTest()
2138 {
2139 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
2140 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300), true);
2141 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300), true);
2142 typename Types::ContentLayerType* surfaceChild = this->createDrawingLayer(surface, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 300), true);
2143 typename Types::ContentLayerType* surfaceChild2 = this->createDrawingLayer(surface, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 300), true);
2144 typename Types::ContentLayerType* surface2 = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(50, 300), true);
2145
2146 addAnimatedTransformToController(*layer->layerAnimationController(), 10, 30, 0);
2147 addAnimatedTransformToController(*surface->layerAnimationController(), 10, 30, 0);
2148 addAnimatedTransformToController(*surfaceChild->layerAnimationController(), 10, 30, 0);
2149 this->calcDrawEtc(parent);
2150
2151 EXPECT_TRUE(layer->drawTransformIsAnimating());
2152 EXPECT_TRUE(layer->screenSpaceTransformIsAnimating());
2153 EXPECT_TRUE(surface->renderSurface()->targetSurfaceTransformsAreAnimating());
2154 EXPECT_TRUE(surface->renderSurface()->screenSpaceTransformsAreAnimating());
2155 // The surface owning layer doesn't animate against its own surface.
2156 EXPECT_FALSE(surface->drawTransformIsAnimating());
2157 EXPECT_TRUE(surface->screenSpaceTransformIsAnimating());
2158 EXPECT_TRUE(surfaceChild->drawTransformIsAnimating());
2159 EXPECT_TRUE(surfaceChild->screenSpaceTransformIsAnimating());
2160
[email protected]96baf3e2012-10-22 23:09:552161 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142162
2163 this->visitLayer(surface2, occlusion);
2164 this->enterContributingSurface(surface2, occlusion);
2165
[email protected]022cbf162012-09-01 01:15:172166 EXPECT_RECT_EQ(IntRect(0, 0, 50, 300), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142167 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
2168
2169 this->leaveContributingSurface(surface2, occlusion);
2170 this->enterLayer(surfaceChild2, occlusion);
2171
2172 // surfaceChild2 is moving in screen space but not relative to its target, so occlusion should happen in its target space only.
2173 // It also means that things occluding in screen space (e.g. surface2) cannot occlude this layer.
[email protected]022cbf162012-09-01 01:15:172174 EXPECT_RECT_EQ(IntRect(0, 0, 100, 300), occlusion.unoccludedContentRect(surfaceChild2, IntRect(0, 0, 100, 300)));
[email protected]94f206c12012-08-25 00:09:142175 EXPECT_FALSE(occlusion.occluded(surfaceChild, IntRect(0, 0, 50, 300)));
2176
2177 this->leaveLayer(surfaceChild2, occlusion);
2178 this->enterLayer(surfaceChild, occlusion);
2179 EXPECT_FALSE(occlusion.occluded(surfaceChild, IntRect(0, 0, 100, 300)));
[email protected]022cbf162012-09-01 01:15:172180 EXPECT_RECT_EQ(IntRect(0, 0, 50, 300), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142181 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172182 EXPECT_RECT_EQ(IntRect(0, 0, 100, 300), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142183 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
[email protected]022cbf162012-09-01 01:15:172184 EXPECT_RECT_EQ(IntRect(100, 0, 200, 300), occlusion.unoccludedContentRect(surface, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142185
2186 // The surfaceChild is occluded by the surfaceChild2, but is moving relative its target and the screen, so it
2187 // can't be occluded.
[email protected]022cbf162012-09-01 01:15:172188 EXPECT_RECT_EQ(IntRect(0, 0, 200, 300), occlusion.unoccludedContentRect(surfaceChild, IntRect(0, 0, 200, 300)));
[email protected]94f206c12012-08-25 00:09:142189 EXPECT_FALSE(occlusion.occluded(surfaceChild, IntRect(0, 0, 50, 300)));
2190
2191 this->leaveLayer(surfaceChild, occlusion);
2192 this->enterLayer(surface, occlusion);
2193 // The surfaceChild is moving in screen space but not relative to its target, so occlusion should happen in its target space only.
[email protected]022cbf162012-09-01 01:15:172194 EXPECT_RECT_EQ(IntRect(0, 0, 50, 300), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142195 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172196 EXPECT_RECT_EQ(IntRect(0, 0, 100, 300), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142197 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
[email protected]022cbf162012-09-01 01:15:172198 EXPECT_RECT_EQ(IntRect(100, 0, 200, 300), occlusion.unoccludedContentRect(surface, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142199
2200 this->leaveLayer(surface, occlusion);
2201 // The surface's owning layer is moving in screen space but not relative to its target, so occlusion should happen in its target space only.
[email protected]022cbf162012-09-01 01:15:172202 EXPECT_RECT_EQ(IntRect(0, 0, 50, 300), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142203 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172204 EXPECT_RECT_EQ(IntRect(0, 0, 300, 300), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142205 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
[email protected]022cbf162012-09-01 01:15:172206 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), occlusion.unoccludedContentRect(surface, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142207
2208 this->enterContributingSurface(surface, occlusion);
2209 // The contributing |surface| is animating so it can't be occluded.
[email protected]022cbf162012-09-01 01:15:172210 EXPECT_RECT_EQ(IntRect(0, 0, 300, 300), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142211 this->leaveContributingSurface(surface, occlusion);
2212
2213 this->enterLayer(layer, occlusion);
2214 // The |surface| is moving in the screen and in its target, so all occlusion within the surface is lost when leaving it.
[email protected]022cbf162012-09-01 01:15:172215 EXPECT_RECT_EQ(IntRect(50, 0, 250, 300), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142216 this->leaveLayer(layer, occlusion);
2217
2218 this->enterLayer(parent, occlusion);
2219 // The |layer| is animating in the screen and in its target, so no occlusion is added.
[email protected]022cbf162012-09-01 01:15:172220 EXPECT_RECT_EQ(IntRect(50, 0, 250, 300), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142221 }
2222};
2223
[email protected]96baf3e2012-10-22 23:09:552224MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread);
[email protected]94f206c12012-08-25 00:09:142225
[email protected]ece1d952012-10-18 21:26:072226template<class Types>
[email protected]96baf3e2012-10-22 23:09:552227class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142228protected:
[email protected]96baf3e2012-10-22 23:09:552229 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142230 void runMyTest()
2231 {
2232 WebTransformationMatrix surfaceTransform;
2233 surfaceTransform.translate(300, 300);
2234 surfaceTransform.scale(2);
2235 surfaceTransform.translate(-150, -150);
2236
2237 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(500, 500));
2238 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, surfaceTransform, FloatPoint(0, 0), IntSize(300, 300), false);
2239 typename Types::ContentLayerType* surface2 = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(50, 50), IntSize(300, 300), false);
[email protected]f3922f22012-10-12 09:20:382240 surface->setOpaqueContentsRect(IntRect(0, 0, 200, 200));
[email protected]94f206c12012-08-25 00:09:142241 surface2->setOpaqueContentsRect(IntRect(0, 0, 200, 200));
2242 this->calcDrawEtc(parent);
2243
[email protected]96baf3e2012-10-22 23:09:552244 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142245
2246 this->visitLayer(surface2, occlusion);
2247 this->visitContributingSurface(surface2, occlusion);
2248
[email protected]022cbf162012-09-01 01:15:172249 EXPECT_RECT_EQ(IntRect(50, 50, 200, 200), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142250 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172251 EXPECT_RECT_EQ(IntRect(50, 50, 200, 200), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142252 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2253
2254 // Clear any stored occlusion.
2255 occlusion.setOcclusionInScreenSpace(Region());
2256 occlusion.setOcclusionInTargetSurface(Region());
2257
2258 this->visitLayer(surface, occlusion);
2259 this->visitContributingSurface(surface, occlusion);
2260
[email protected]022cbf162012-09-01 01:15:172261 EXPECT_RECT_EQ(IntRect(0, 0, 400, 400), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142262 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172263 EXPECT_RECT_EQ(IntRect(0, 0, 400, 400), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142264 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2265 }
2266};
2267
[email protected]96baf3e2012-10-22 23:09:552268MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:142269
[email protected]ece1d952012-10-18 21:26:072270template<class Types>
[email protected]96baf3e2012-10-22 23:09:552271class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142272protected:
[email protected]96baf3e2012-10-22 23:09:552273 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142274 void runMyTest()
2275 {
2276 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
[email protected]23bbb412012-08-30 20:03:382277 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:142278 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(500, 300), false);
2279 surface->setOpaqueContentsRect(IntRect(0, 0, 400, 200));
2280 this->calcDrawEtc(parent);
2281
[email protected]96baf3e2012-10-22 23:09:552282 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142283
2284 this->visitLayer(surface, occlusion);
2285 this->visitContributingSurface(surface, occlusion);
2286
[email protected]022cbf162012-09-01 01:15:172287 EXPECT_RECT_EQ(IntRect(0, 0, 300, 200), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142288 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172289 EXPECT_RECT_EQ(IntRect(0, 0, 300, 200), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142290 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2291 }
2292};
2293
[email protected]96baf3e2012-10-22 23:09:552294MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:142295
[email protected]ece1d952012-10-18 21:26:072296template<class Types>
[email protected]96baf3e2012-10-22 23:09:552297class OcclusionTrackerTestReplicaOccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142298protected:
[email protected]96baf3e2012-10-22 23:09:552299 OcclusionTrackerTestReplicaOccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142300 void runMyTest()
2301 {
2302 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 200));
2303 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100), true);
2304 this->createReplicaLayer(surface, this->identityMatrix, FloatPoint(0, 100), IntSize(100, 100));
2305 typename Types::LayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 100), IntSize(100, 100), true);
2306 this->calcDrawEtc(parent);
2307
[email protected]96baf3e2012-10-22 23:09:552308 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142309 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
2310
2311 // |topmost| occludes the replica, but not the surface itself.
2312 this->visitLayer(topmost, occlusion);
2313
[email protected]022cbf162012-09-01 01:15:172314 EXPECT_RECT_EQ(IntRect(0, 100, 100, 100), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142315 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172316 EXPECT_RECT_EQ(IntRect(0, 100, 100, 100), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142317 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2318
2319 this->visitLayer(surface, occlusion);
2320
[email protected]022cbf162012-09-01 01:15:172321 EXPECT_RECT_EQ(IntRect(0, 0, 100, 200), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142322 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172323 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142324 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2325
2326 this->enterContributingSurface(surface, occlusion);
2327
2328 // Surface is not occluded so it shouldn't think it is.
[email protected]022cbf162012-09-01 01:15:172329 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142330 }
2331};
2332
[email protected]96baf3e2012-10-22 23:09:552333ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaOccluded);
[email protected]94f206c12012-08-25 00:09:142334
[email protected]ece1d952012-10-18 21:26:072335template<class Types>
[email protected]96baf3e2012-10-22 23:09:552336class OcclusionTrackerTestSurfaceWithReplicaUnoccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142337protected:
[email protected]96baf3e2012-10-22 23:09:552338 OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142339 void runMyTest()
2340 {
2341 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 200));
2342 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100), true);
2343 this->createReplicaLayer(surface, this->identityMatrix, FloatPoint(0, 100), IntSize(100, 100));
2344 typename Types::LayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 110), true);
2345 this->calcDrawEtc(parent);
2346
[email protected]96baf3e2012-10-22 23:09:552347 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142348 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
2349
2350 // |topmost| occludes the surface, but not the entire surface's replica.
2351 this->visitLayer(topmost, occlusion);
2352
[email protected]022cbf162012-09-01 01:15:172353 EXPECT_RECT_EQ(IntRect(0, 0, 100, 110), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142354 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172355 EXPECT_RECT_EQ(IntRect(0, 0, 100, 110), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142356 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2357
2358 this->visitLayer(surface, occlusion);
2359
[email protected]022cbf162012-09-01 01:15:172360 EXPECT_RECT_EQ(IntRect(0, 0, 100, 110), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142361 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172362 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142363 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2364
2365 this->enterContributingSurface(surface, occlusion);
2366
2367 // Surface is occluded, but only the top 10px of the replica.
[email protected]022cbf162012-09-01 01:15:172368 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 100, 100)));
2369 EXPECT_RECT_EQ(IntRect(0, 10, 100, 90), occlusion.unoccludedContributingSurfaceContentRect(surface, true, IntRect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142370 }
2371};
2372
[email protected]96baf3e2012-10-22 23:09:552373ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded);
[email protected]94f206c12012-08-25 00:09:142374
[email protected]ece1d952012-10-18 21:26:072375template<class Types>
[email protected]96baf3e2012-10-22 23:09:552376class OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142377protected:
[email protected]96baf3e2012-10-22 23:09:552378 OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142379 void runMyTest()
2380 {
2381 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 200));
2382 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100), true);
2383 this->createReplicaLayer(surface, this->identityMatrix, FloatPoint(0, 100), IntSize(100, 100));
2384 typename Types::LayerType* overSurface = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(40, 100), true);
2385 typename Types::LayerType* overReplica = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 100), IntSize(50, 100), true);
2386 this->calcDrawEtc(parent);
2387
[email protected]96baf3e2012-10-22 23:09:552388 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142389 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
2390
2391 // These occlude the surface and replica differently, so we can test each one.
2392 this->visitLayer(overReplica, occlusion);
2393 this->visitLayer(overSurface, occlusion);
2394
[email protected]022cbf162012-09-01 01:15:172395 EXPECT_RECT_EQ(IntRect(0, 0, 50, 200), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142396 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172397 EXPECT_RECT_EQ(IntRect(0, 0, 50, 200), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142398 EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
2399
2400 this->visitLayer(surface, occlusion);
2401
[email protected]022cbf162012-09-01 01:15:172402 EXPECT_RECT_EQ(IntRect(0, 0, 100, 200), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142403 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172404 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142405 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2406
2407 this->enterContributingSurface(surface, occlusion);
2408
2409 // Surface and replica are occluded different amounts.
[email protected]022cbf162012-09-01 01:15:172410 EXPECT_RECT_EQ(IntRect(40, 0, 60, 100), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 100, 100)));
2411 EXPECT_RECT_EQ(IntRect(50, 0, 50, 100), occlusion.unoccludedContributingSurfaceContentRect(surface, true, IntRect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142412 }
2413};
2414
[email protected]96baf3e2012-10-22 23:09:552415ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently);
[email protected]94f206c12012-08-25 00:09:142416
[email protected]ece1d952012-10-18 21:26:072417template<class Types>
[email protected]96baf3e2012-10-22 23:09:552418class OcclusionTrackerTestSurfaceChildOfSurface : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142419protected:
[email protected]96baf3e2012-10-22 23:09:552420 OcclusionTrackerTestSurfaceChildOfSurface(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142421 void runMyTest()
2422 {
2423 // This test verifies that the surface cliprect does not end up empty and clip away the entire unoccluded rect.
2424
2425 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 200));
2426 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100), true);
2427 typename Types::LayerType* surfaceChild = this->createDrawingSurface(surface, this->identityMatrix, FloatPoint(0, 10), IntSize(100, 50), true);
2428 typename Types::LayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 50), true);
2429 this->calcDrawEtc(parent);
2430
[email protected]96baf3e2012-10-22 23:09:552431 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142432
2433 // |topmost| occludes everything partially so we know occlusion is happening at all.
2434 this->visitLayer(topmost, occlusion);
2435
[email protected]022cbf162012-09-01 01:15:172436 EXPECT_RECT_EQ(IntRect(0, 0, 100, 50), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142437 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172438 EXPECT_RECT_EQ(IntRect(0, 0, 100, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142439 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2440
2441 this->visitLayer(surfaceChild, occlusion);
2442
2443 // surfaceChild increases the occlusion in the screen by a narrow sliver.
[email protected]022cbf162012-09-01 01:15:172444 EXPECT_RECT_EQ(IntRect(0, 0, 100, 60), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142445 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
2446 // In its own surface, surfaceChild is at 0,0 as is its occlusion.
[email protected]022cbf162012-09-01 01:15:172447 EXPECT_RECT_EQ(IntRect(0, 0, 100, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142448 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2449
2450 // The root layer always has a clipRect. So the parent of |surface| has a clipRect. However, the owning layer for |surface| does not
2451 // mask to bounds, so it doesn't have a clipRect of its own. Thus the parent of |surfaceChild| exercises different code paths
2452 // as its parent does not have a clipRect.
2453
2454 this->enterContributingSurface(surfaceChild, occlusion);
2455 // The surfaceChild's parent does not have a clipRect as it owns a render surface. Make sure the unoccluded rect
2456 // does not get clipped away inappropriately.
[email protected]022cbf162012-09-01 01:15:172457 EXPECT_RECT_EQ(IntRect(0, 40, 100, 10), occlusion.unoccludedContributingSurfaceContentRect(surfaceChild, false, IntRect(0, 0, 100, 50)));
[email protected]94f206c12012-08-25 00:09:142458 this->leaveContributingSurface(surfaceChild, occlusion);
2459
2460 // When the surfaceChild's occlusion is transformed up to its parent, make sure it is not clipped away inappropriately also.
2461 this->enterLayer(surface, occlusion);
[email protected]022cbf162012-09-01 01:15:172462 EXPECT_RECT_EQ(IntRect(0, 0, 100, 60), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142463 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172464 EXPECT_RECT_EQ(IntRect(0, 10, 100, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142465 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2466 this->leaveLayer(surface, occlusion);
2467
2468 this->enterContributingSurface(surface, occlusion);
2469 // The surface's parent does have a clipRect as it is the root layer.
[email protected]022cbf162012-09-01 01:15:172470 EXPECT_RECT_EQ(IntRect(0, 50, 100, 50), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142471 }
2472};
2473
[email protected]96baf3e2012-10-22 23:09:552474ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:142475
[email protected]ece1d952012-10-18 21:26:072476template<class Types>
[email protected]96baf3e2012-10-22 23:09:552477class OcclusionTrackerTestTopmostSurfaceIsClippedToViewport : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142478protected:
[email protected]96baf3e2012-10-22 23:09:552479 OcclusionTrackerTestTopmostSurfaceIsClippedToViewport(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142480 void runMyTest()
2481 {
2482 // This test verifies that the top-most surface is considered occluded outside of its target's clipRect and outside the viewport rect.
2483
2484 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 200));
2485 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 300), true);
2486 this->calcDrawEtc(parent);
2487
2488 {
2489 // Make a viewport rect that is larger than the root layer.
[email protected]96baf3e2012-10-22 23:09:552490 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142491
2492 this->visitLayer(surface, occlusion);
2493
2494 // The root layer always has a clipRect. So the parent of |surface| has a clipRect giving the surface itself a clipRect.
2495 this->enterContributingSurface(surface, occlusion);
2496 // Make sure the parent's clipRect clips the unoccluded region of the child surface.
[email protected]022cbf162012-09-01 01:15:172497 EXPECT_RECT_EQ(IntRect(0, 0, 100, 200), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 100, 300)));
[email protected]94f206c12012-08-25 00:09:142498 }
2499 this->resetLayerIterator();
2500 {
2501 // Make a viewport rect that is smaller than the root layer.
[email protected]96baf3e2012-10-22 23:09:552502 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:142503
2504 this->visitLayer(surface, occlusion);
2505
2506 // The root layer always has a clipRect. So the parent of |surface| has a clipRect giving the surface itself a clipRect.
2507 this->enterContributingSurface(surface, occlusion);
2508 // Make sure the viewport rect clips the unoccluded region of the child surface.
[email protected]022cbf162012-09-01 01:15:172509 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 100, 300)));
[email protected]94f206c12012-08-25 00:09:142510 }
2511 }
2512};
2513
[email protected]96baf3e2012-10-22 23:09:552514ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTopmostSurfaceIsClippedToViewport);
[email protected]94f206c12012-08-25 00:09:142515
[email protected]ece1d952012-10-18 21:26:072516template<class Types>
[email protected]96baf3e2012-10-22 23:09:552517class OcclusionTrackerTestSurfaceChildOfClippingSurface : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142518protected:
[email protected]96baf3e2012-10-22 23:09:552519 OcclusionTrackerTestSurfaceChildOfClippingSurface(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142520 void runMyTest()
2521 {
2522 // This test verifies that the surface cliprect does not end up empty and clip away the entire unoccluded rect.
2523
2524 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(80, 200));
[email protected]23bbb412012-08-30 20:03:382525 parent->setMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:142526 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100), true);
2527 typename Types::LayerType* surfaceChild = this->createDrawingSurface(surface, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100), false);
2528 typename Types::LayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(100, 50), true);
2529 this->calcDrawEtc(parent);
2530
[email protected]96baf3e2012-10-22 23:09:552531 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142532 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
2533
2534 // |topmost| occludes everything partially so we know occlusion is happening at all.
2535 this->visitLayer(topmost, occlusion);
2536
[email protected]022cbf162012-09-01 01:15:172537 EXPECT_RECT_EQ(IntRect(0, 0, 80, 50), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142538 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172539 EXPECT_RECT_EQ(IntRect(0, 0, 80, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142540 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2541
2542 // surfaceChild is not opaque and does not occlude, so we have a non-empty unoccluded area on surface.
2543 this->visitLayer(surfaceChild, occlusion);
2544
[email protected]022cbf162012-09-01 01:15:172545 EXPECT_RECT_EQ(IntRect(0, 0, 80, 50), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142546 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172547 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142548 EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
2549
2550 // The root layer always has a clipRect. So the parent of |surface| has a clipRect. However, the owning layer for |surface| does not
2551 // mask to bounds, so it doesn't have a clipRect of its own. Thus the parent of |surfaceChild| exercises different code paths
2552 // as its parent does not have a clipRect.
2553
2554 this->enterContributingSurface(surfaceChild, occlusion);
2555 // The surfaceChild's parent does not have a clipRect as it owns a render surface.
[email protected]022cbf162012-09-01 01:15:172556 EXPECT_RECT_EQ(IntRect(0, 50, 80, 50), occlusion.unoccludedContributingSurfaceContentRect(surfaceChild, false, IntRect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142557 this->leaveContributingSurface(surfaceChild, occlusion);
2558
2559 this->visitLayer(surface, occlusion);
2560 this->enterContributingSurface(surface, occlusion);
2561 // The surface's parent does have a clipRect as it is the root layer.
[email protected]022cbf162012-09-01 01:15:172562 EXPECT_RECT_EQ(IntRect(0, 50, 80, 50), occlusion.unoccludedContributingSurfaceContentRect(surface, false, IntRect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142563 }
2564};
2565
[email protected]96baf3e2012-10-22 23:09:552566ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfClippingSurface);
[email protected]94f206c12012-08-25 00:09:142567
[email protected]ece1d952012-10-18 21:26:072568template<class Types>
[email protected]96baf3e2012-10-22 23:09:552569class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142570protected:
[email protected]96baf3e2012-10-22 23:09:552571 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142572 void runMyTest()
2573 {
2574 WebTransformationMatrix scaleByHalf;
2575 scaleByHalf.scale(0.5);
2576
2577 // Make a surface and its replica, each 50x50, that are completely surrounded by opaque layers which are above them in the z-order.
2578 // The surface is scaled to test that the pixel moving is done in the target space, where the background filter is applied, but the surface
2579 // appears at 50, 50 and the replica at 200, 50.
2580 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 150));
2581 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, FloatPoint(50, 50), IntSize(100, 100), false);
2582 this->createReplicaLayer(filteredSurface, this->identityMatrix, FloatPoint(300, 0), IntSize());
2583 typename Types::LayerType* occludingLayer1 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 50), true);
2584 typename Types::LayerType* occludingLayer2 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 100), IntSize(300, 50), true);
2585 typename Types::LayerType* occludingLayer3 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 50), IntSize(50, 50), true);
2586 typename Types::LayerType* occludingLayer4 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(100, 50), IntSize(100, 50), true);
2587 typename Types::LayerType* occludingLayer5 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(250, 50), IntSize(50, 50), true);
2588
2589 // Filters make the layer own a surface.
2590 WebFilterOperations filters;
2591 filters.append(WebFilterOperation::createBlurFilter(10));
2592 filteredSurface->setBackgroundFilters(filters);
2593
2594 // Save the distance of influence for the blur effect.
2595 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2596 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2597
2598 this->calcDrawEtc(parent);
2599
[email protected]96baf3e2012-10-22 23:09:552600 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142601 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
2602
2603 // These layers occlude pixels directly beside the filteredSurface. Because filtered surface blends pixels in a radius, it will
2604 // need to see some of the pixels (up to radius far) underneath the occludingLayers.
2605 this->visitLayer(occludingLayer5, occlusion);
2606 this->visitLayer(occludingLayer4, occlusion);
2607 this->visitLayer(occludingLayer3, occlusion);
2608 this->visitLayer(occludingLayer2, occlusion);
2609 this->visitLayer(occludingLayer1, occlusion);
2610
[email protected]022cbf162012-09-01 01:15:172611 EXPECT_RECT_EQ(IntRect(0, 0, 300, 150), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142612 EXPECT_EQ(5u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172613 EXPECT_RECT_EQ(IntRect(0, 0, 300, 150), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142614 EXPECT_EQ(5u, occlusion.occlusionInTargetSurface().rects().size());
2615
2616 // Everything outside the surface/replica is occluded but the surface/replica itself is not.
2617 this->enterLayer(filteredSurface, occlusion);
[email protected]f3922f22012-10-12 09:20:382618 EXPECT_RECT_EQ(IntRect(1, 0, 99, 100), occlusion.unoccludedContentRect(filteredSurface, IntRect(1, 0, 100, 100)));
2619 EXPECT_RECT_EQ(IntRect(0, 1, 100, 99), occlusion.unoccludedContentRect(filteredSurface, IntRect(0, 1, 100, 100)));
2620 EXPECT_RECT_EQ(IntRect(0, 0, 99, 100), occlusion.unoccludedContentRect(filteredSurface, IntRect(-1, 0, 100, 100)));
2621 EXPECT_RECT_EQ(IntRect(0, 0, 100, 99), occlusion.unoccludedContentRect(filteredSurface, IntRect(0, -1, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142622
[email protected]f3922f22012-10-12 09:20:382623 EXPECT_RECT_EQ(IntRect(300 + 1, 0, 99, 100), occlusion.unoccludedContentRect(filteredSurface, IntRect(300 + 1, 0, 100, 100)));
2624 EXPECT_RECT_EQ(IntRect(300 + 0, 1, 100, 99), occlusion.unoccludedContentRect(filteredSurface, IntRect(300 + 0, 1, 100, 100)));
2625 EXPECT_RECT_EQ(IntRect(300 + 0, 0, 99, 100), occlusion.unoccludedContentRect(filteredSurface, IntRect(300 - 1, 0, 100, 100)));
2626 EXPECT_RECT_EQ(IntRect(300 + 0, 0, 100, 99), occlusion.unoccludedContentRect(filteredSurface, IntRect(300 + 0, -1, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142627 this->leaveLayer(filteredSurface, occlusion);
2628
2629 // The filtered layer/replica does not occlude.
[email protected]022cbf162012-09-01 01:15:172630 EXPECT_RECT_EQ(IntRect(0, 0, 300, 150), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142631 EXPECT_EQ(5u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172632 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142633 EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
2634
2635 // The surface has a background blur, so it needs pixels that are currently considered occluded in order to be drawn. So the pixels
[email protected]f3922f22012-10-12 09:20:382636 // it needs should be removed some the occluded area so that when we get to the parent they are drawn.
[email protected]94f206c12012-08-25 00:09:142637 this->visitContributingSurface(filteredSurface, occlusion);
2638
2639 this->enterLayer(parent, occlusion);
[email protected]022cbf162012-09-01 01:15:172640 EXPECT_RECT_EQ(IntRect(0, 0, 300, 150), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142641 EXPECT_EQ(5u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172642 EXPECT_RECT_EQ(IntRect(0, 0, 300, 150), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142643 EXPECT_EQ(5u, occlusion.occlusionInTargetSurface().rects().size());
2644
2645 IntRect outsetRect;
2646 IntRect testRect;
2647
2648 // Nothing in the blur outsets for the filteredSurface is occluded.
2649 outsetRect = IntRect(50 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
2650 testRect = outsetRect;
[email protected]022cbf162012-09-01 01:15:172651 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142652
2653 // Stuff outside the blur outsets is still occluded though.
2654 testRect = outsetRect;
2655 testRect.expand(1, 0);
[email protected]022cbf162012-09-01 01:15:172656 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142657 testRect = outsetRect;
2658 testRect.expand(0, 1);
[email protected]022cbf162012-09-01 01:15:172659 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142660 testRect = outsetRect;
2661 testRect.move(-1, 0);
2662 testRect.expand(1, 0);
[email protected]022cbf162012-09-01 01:15:172663 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142664 testRect = outsetRect;
2665 testRect.move(0, -1);
2666 testRect.expand(0, 1);
[email protected]022cbf162012-09-01 01:15:172667 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142668
2669 // Nothing in the blur outsets for the filteredSurface's replica is occluded.
2670 outsetRect = IntRect(200 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
2671 testRect = outsetRect;
[email protected]022cbf162012-09-01 01:15:172672 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142673
2674 // Stuff outside the blur outsets is still occluded though.
2675 testRect = outsetRect;
2676 testRect.expand(1, 0);
[email protected]022cbf162012-09-01 01:15:172677 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142678 testRect = outsetRect;
2679 testRect.expand(0, 1);
[email protected]022cbf162012-09-01 01:15:172680 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142681 testRect = outsetRect;
2682 testRect.move(-1, 0);
2683 testRect.expand(1, 0);
[email protected]022cbf162012-09-01 01:15:172684 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142685 testRect = outsetRect;
2686 testRect.move(0, -1);
2687 testRect.expand(0, 1);
[email protected]022cbf162012-09-01 01:15:172688 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142689 }
2690};
2691
[email protected]96baf3e2012-10-22 23:09:552692ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142693
[email protected]ece1d952012-10-18 21:26:072694template<class Types>
[email protected]96baf3e2012-10-22 23:09:552695class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142696protected:
[email protected]96baf3e2012-10-22 23:09:552697 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142698 void runMyTest()
2699 {
2700 WebTransformationMatrix scaleByHalf;
2701 scaleByHalf.scale(0.5);
2702
2703 // Makes two surfaces that completely cover |parent|. The occlusion both above and below the filters will be reduced by each of them.
[email protected]f3922f22012-10-12 09:20:382704 typename Types::ContentLayerType* root = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(75, 75));
2705 typename Types::LayerType* parent = this->createSurface(root, scaleByHalf, FloatPoint(0, 0), IntSize(150, 150));
[email protected]94f206c12012-08-25 00:09:142706 parent->setMasksToBounds(true);
[email protected]f3922f22012-10-12 09:20:382707 typename Types::LayerType* filteredSurface1 = this->createDrawingLayer(parent, scaleByHalf, FloatPoint(0, 0), IntSize(300, 300), false);
2708 typename Types::LayerType* filteredSurface2 = this->createDrawingLayer(parent, scaleByHalf, FloatPoint(0, 0), IntSize(300, 300), false);
2709 typename Types::LayerType* occludingLayerAbove = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(100, 100), IntSize(50, 50), true);
[email protected]94f206c12012-08-25 00:09:142710
2711 // Filters make the layers own surfaces.
2712 WebFilterOperations filters;
2713 filters.append(WebFilterOperation::createBlurFilter(3));
2714 filteredSurface1->setBackgroundFilters(filters);
2715 filteredSurface2->setBackgroundFilters(filters);
2716
2717 // Save the distance of influence for the blur effect.
2718 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2719 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2720
2721 this->calcDrawEtc(root);
2722
[email protected]96baf3e2012-10-22 23:09:552723 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142724 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
2725
2726 this->visitLayer(occludingLayerAbove, occlusion);
[email protected]f3922f22012-10-12 09:20:382727 EXPECT_RECT_EQ(IntRect(100 / 2, 100 / 2, 50 / 2, 50 / 2), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142728 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]f3922f22012-10-12 09:20:382729 EXPECT_RECT_EQ(IntRect(100, 100, 50, 50), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142730 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2731
2732 this->visitLayer(filteredSurface2, occlusion);
2733 this->visitContributingSurface(filteredSurface2, occlusion);
2734 this->visitLayer(filteredSurface1, occlusion);
2735 this->visitContributingSurface(filteredSurface1, occlusion);
2736
2737 ASSERT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
2738 ASSERT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
2739
[email protected]f3922f22012-10-12 09:20:382740 // Test expectations in the target.
2741 IntRect expectedOcclusion = IntRect(100 + outsetRight * 2, 100 + outsetBottom * 2, 50 - (outsetLeft + outsetRight) * 2, 50 - (outsetTop + outsetBottom) * 2);
[email protected]022cbf162012-09-01 01:15:172742 EXPECT_RECT_EQ(expectedOcclusion, occlusion.occlusionInTargetSurface().rects()[0]);
[email protected]94f206c12012-08-25 00:09:142743
[email protected]f3922f22012-10-12 09:20:382744 // Test expectations in the screen. Take the ceiling of half of the outsets.
2745 outsetTop = (outsetTop + 1) / 2;
2746 outsetRight = (outsetRight + 1) / 2;
2747 outsetBottom = (outsetBottom + 1) / 2;
2748 outsetLeft = (outsetLeft + 1) / 2;
2749 expectedOcclusion = IntRect(100 / 2 + outsetRight * 2, 100 / 2 + outsetBottom * 2, 50 / 2 - (outsetLeft + outsetRight) * 2, 50 /2 - (outsetTop + outsetBottom) * 2);
2750
[email protected]022cbf162012-09-01 01:15:172751 EXPECT_RECT_EQ(expectedOcclusion, occlusion.occlusionInScreenSpace().rects()[0]);
[email protected]94f206c12012-08-25 00:09:142752 }
2753};
2754
[email protected]96baf3e2012-10-22 23:09:552755ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:142756
[email protected]ece1d952012-10-18 21:26:072757template<class Types>
[email protected]96baf3e2012-10-22 23:09:552758class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142759protected:
[email protected]96baf3e2012-10-22 23:09:552760 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142761 void runMyTest()
2762 {
2763 // Make a surface and its replica, each 50x50, that are completely surrounded by opaque layers which are above them in the z-order.
2764 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 150));
2765 // We stick the filtered surface inside a clipping surface so that we can make sure the clip is honored when exposing pixels for
2766 // the background filter.
2767 typename Types::LayerType* clippingSurface = this->createSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 70));
2768 clippingSurface->setMasksToBounds(true);
2769 typename Types::LayerType* filteredSurface = this->createDrawingLayer(clippingSurface, this->identityMatrix, FloatPoint(50, 50), IntSize(50, 50), false);
2770 this->createReplicaLayer(filteredSurface, this->identityMatrix, FloatPoint(150, 0), IntSize());
2771 typename Types::LayerType* occludingLayer1 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(300, 50), true);
2772 typename Types::LayerType* occludingLayer2 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 100), IntSize(300, 50), true);
2773 typename Types::LayerType* occludingLayer3 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 50), IntSize(50, 50), true);
2774 typename Types::LayerType* occludingLayer4 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(100, 50), IntSize(100, 50), true);
2775 typename Types::LayerType* occludingLayer5 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(250, 50), IntSize(50, 50), true);
2776
2777 // Filters make the layer own a surface. This filter is large enough that it goes outside the bottom of the clippingSurface.
2778 WebFilterOperations filters;
2779 filters.append(WebFilterOperation::createBlurFilter(12));
2780 filteredSurface->setBackgroundFilters(filters);
2781
2782 // Save the distance of influence for the blur effect.
2783 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2784 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2785
2786 this->calcDrawEtc(parent);
2787
[email protected]96baf3e2012-10-22 23:09:552788 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142789 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
2790
2791 // These layers occlude pixels directly beside the filteredSurface. Because filtered surface blends pixels in a radius, it will
2792 // need to see some of the pixels (up to radius far) underneath the occludingLayers.
2793 this->visitLayer(occludingLayer5, occlusion);
2794 this->visitLayer(occludingLayer4, occlusion);
2795 this->visitLayer(occludingLayer3, occlusion);
2796 this->visitLayer(occludingLayer2, occlusion);
2797 this->visitLayer(occludingLayer1, occlusion);
2798
[email protected]022cbf162012-09-01 01:15:172799 EXPECT_RECT_EQ(IntRect(0, 0, 300, 150), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142800 EXPECT_EQ(5u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172801 EXPECT_RECT_EQ(IntRect(0, 0, 300, 150), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142802 EXPECT_EQ(5u, occlusion.occlusionInTargetSurface().rects().size());
2803
2804 // Everything outside the surface/replica is occluded but the surface/replica itself is not.
2805 this->enterLayer(filteredSurface, occlusion);
[email protected]022cbf162012-09-01 01:15:172806 EXPECT_RECT_EQ(IntRect(1, 0, 49, 50), occlusion.unoccludedContentRect(filteredSurface, IntRect(1, 0, 50, 50)));
2807 EXPECT_RECT_EQ(IntRect(0, 1, 50, 49), occlusion.unoccludedContentRect(filteredSurface, IntRect(0, 1, 50, 50)));
2808 EXPECT_RECT_EQ(IntRect(0, 0, 49, 50), occlusion.unoccludedContentRect(filteredSurface, IntRect(-1, 0, 50, 50)));
2809 EXPECT_RECT_EQ(IntRect(0, 0, 50, 49), occlusion.unoccludedContentRect(filteredSurface, IntRect(0, -1, 50, 50)));
[email protected]94f206c12012-08-25 00:09:142810
[email protected]022cbf162012-09-01 01:15:172811 EXPECT_RECT_EQ(IntRect(150 + 1, 0, 49, 50), occlusion.unoccludedContentRect(filteredSurface, IntRect(150 + 1, 0, 50, 50)));
2812 EXPECT_RECT_EQ(IntRect(150 + 0, 1, 50, 49), occlusion.unoccludedContentRect(filteredSurface, IntRect(150 + 0, 1, 50, 50)));
2813 EXPECT_RECT_EQ(IntRect(150 + 0, 0, 49, 50), occlusion.unoccludedContentRect(filteredSurface, IntRect(150 - 1, 0, 50, 50)));
2814 EXPECT_RECT_EQ(IntRect(150 + 0, 0, 50, 49), occlusion.unoccludedContentRect(filteredSurface, IntRect(150 + 0, -1, 50, 50)));
[email protected]94f206c12012-08-25 00:09:142815 this->leaveLayer(filteredSurface, occlusion);
2816
2817 // The filtered layer/replica does not occlude.
[email protected]022cbf162012-09-01 01:15:172818 EXPECT_RECT_EQ(IntRect(0, 0, 300, 150), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142819 EXPECT_EQ(5u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172820 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142821 EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
2822
2823 // The surface has a background blur, so it needs pixels that are currently considered occluded in order to be drawn. So the pixels
2824 // it needs should be removed some the occluded area so that when we get to the parent they are drawn.
2825 this->visitContributingSurface(filteredSurface, occlusion);
2826
2827 this->enterContributingSurface(clippingSurface, occlusion);
[email protected]022cbf162012-09-01 01:15:172828 EXPECT_RECT_EQ(IntRect(0, 0, 300, 150), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142829 EXPECT_EQ(5u, occlusion.occlusionInScreenSpace().rects().size());
2830
2831 IntRect outsetRect;
2832 IntRect clippedOutsetRect;
2833 IntRect testRect;
2834
2835 // Nothing in the (clipped) blur outsets for the filteredSurface is occluded.
2836 outsetRect = IntRect(50 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
2837 clippedOutsetRect = intersection(outsetRect, IntRect(0 - outsetLeft, 0 - outsetTop, 300 + outsetLeft + outsetRight, 70 + outsetTop + outsetBottom));
2838 testRect = outsetRect;
[email protected]022cbf162012-09-01 01:15:172839 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142840
2841 // Stuff outside the (clipped) blur outsets is still occluded though.
2842 testRect = outsetRect;
2843 testRect.expand(1, 0);
[email protected]022cbf162012-09-01 01:15:172844 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142845 testRect = outsetRect;
2846 testRect.expand(0, 1);
[email protected]022cbf162012-09-01 01:15:172847 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142848 testRect = outsetRect;
2849 testRect.move(-1, 0);
2850 testRect.expand(1, 0);
[email protected]022cbf162012-09-01 01:15:172851 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142852 testRect = outsetRect;
2853 testRect.move(0, -1);
2854 testRect.expand(0, 1);
[email protected]022cbf162012-09-01 01:15:172855 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142856
2857 // Nothing in the (clipped) blur outsets for the filteredSurface's replica is occluded.
2858 outsetRect = IntRect(200 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
2859 clippedOutsetRect = intersection(outsetRect, IntRect(0 - outsetLeft, 0 - outsetTop, 300 + outsetLeft + outsetRight, 70 + outsetTop + outsetBottom));
2860 testRect = outsetRect;
[email protected]022cbf162012-09-01 01:15:172861 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142862
2863 // Stuff outside the (clipped) blur outsets is still occluded though.
2864 testRect = outsetRect;
2865 testRect.expand(1, 0);
[email protected]022cbf162012-09-01 01:15:172866 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142867 testRect = outsetRect;
2868 testRect.expand(0, 1);
[email protected]022cbf162012-09-01 01:15:172869 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142870 testRect = outsetRect;
2871 testRect.move(-1, 0);
2872 testRect.expand(1, 0);
[email protected]022cbf162012-09-01 01:15:172873 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142874 testRect = outsetRect;
2875 testRect.move(0, -1);
2876 testRect.expand(0, 1);
[email protected]022cbf162012-09-01 01:15:172877 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142878 }
2879};
2880
[email protected]96baf3e2012-10-22 23:09:552881ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip);
[email protected]94f206c12012-08-25 00:09:142882
[email protected]ece1d952012-10-18 21:26:072883template<class Types>
[email protected]96baf3e2012-10-22 23:09:552884class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142885protected:
[email protected]96baf3e2012-10-22 23:09:552886 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142887 void runMyTest()
2888 {
2889 WebTransformationMatrix scaleByHalf;
2890 scaleByHalf.scale(0.5);
2891
2892 // Make a surface and its replica, each 50x50, with a smaller 30x30 layer centered below each.
2893 // The surface is scaled to test that the pixel moving is done in the target space, where the background filter is applied, but the surface
2894 // appears at 50, 50 and the replica at 200, 50.
2895 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 150));
2896 typename Types::LayerType* behindSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(60, 60), IntSize(30, 30), true);
2897 typename Types::LayerType* behindReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(210, 60), IntSize(30, 30), true);
2898 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, FloatPoint(50, 50), IntSize(100, 100), false);
2899 this->createReplicaLayer(filteredSurface, this->identityMatrix, FloatPoint(300, 0), IntSize());
2900
2901 // Filters make the layer own a surface.
2902 WebFilterOperations filters;
2903 filters.append(WebFilterOperation::createBlurFilter(3));
2904 filteredSurface->setBackgroundFilters(filters);
2905
2906 this->calcDrawEtc(parent);
2907
[email protected]96baf3e2012-10-22 23:09:552908 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142909 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
2910
2911 // The surface has a background blur, so it blurs non-opaque pixels below it.
2912 this->visitLayer(filteredSurface, occlusion);
2913 this->visitContributingSurface(filteredSurface, occlusion);
2914
2915 this->visitLayer(behindReplicaLayer, occlusion);
2916 this->visitLayer(behindSurfaceLayer, occlusion);
2917
2918 // The layers behind the surface are not blurred, and their occlusion does not change, until we leave the surface.
2919 // So it should not be modified by the filter here.
2920 IntRect occlusionBehindSurface = IntRect(60, 60, 30, 30);
2921 IntRect occlusionBehindReplica = IntRect(210, 60, 30, 30);
2922
2923 IntRect expectedOpaqueBounds = unionRect(occlusionBehindSurface, occlusionBehindReplica);
[email protected]022cbf162012-09-01 01:15:172924 EXPECT_RECT_EQ(expectedOpaqueBounds, occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142925 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172926 EXPECT_RECT_EQ(expectedOpaqueBounds, occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142927 EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
2928 }
2929};
2930
[email protected]96baf3e2012-10-22 23:09:552931ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142932
[email protected]ece1d952012-10-18 21:26:072933template<class Types>
[email protected]96baf3e2012-10-22 23:09:552934class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142935protected:
[email protected]96baf3e2012-10-22 23:09:552936 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142937 void runMyTest()
2938 {
2939 WebTransformationMatrix scaleByHalf;
2940 scaleByHalf.scale(0.5);
2941
2942 // Make a surface and its replica, each 50x50, that are completely occluded by opaque layers which are above them in the z-order.
2943 // The surface is scaled to test that the pixel moving is done in the target space, where the background filter is applied, but the surface
2944 // appears at 50, 50 and the replica at 200, 50.
2945 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 150));
2946 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, FloatPoint(50, 50), IntSize(100, 100), false);
2947 this->createReplicaLayer(filteredSurface, this->identityMatrix, FloatPoint(300, 0), IntSize());
2948 typename Types::LayerType* aboveSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(50, 50), IntSize(50, 50), true);
2949 typename Types::LayerType* aboveReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(200, 50), IntSize(50, 50), true);
2950
2951 // Filters make the layer own a surface.
2952 WebFilterOperations filters;
2953 filters.append(WebFilterOperation::createBlurFilter(3));
2954 filteredSurface->setBackgroundFilters(filters);
2955
2956 this->calcDrawEtc(parent);
2957
[email protected]96baf3e2012-10-22 23:09:552958 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142959 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
2960
2961 this->visitLayer(aboveReplicaLayer, occlusion);
2962 this->visitLayer(aboveSurfaceLayer, occlusion);
2963
2964 // The surface has a background blur, so it blurs non-opaque pixels below it.
2965 this->visitLayer(filteredSurface, occlusion);
2966 this->visitContributingSurface(filteredSurface, occlusion);
2967
2968 // The filter is completely occluded, so it should not blur anything and reduce any occlusion.
2969 IntRect occlusionAboveSurface = IntRect(50, 50, 50, 50);
2970 IntRect occlusionAboveReplica = IntRect(200, 50, 50, 50);
2971
2972 IntRect expectedOpaqueBounds = unionRect(occlusionAboveSurface, occlusionAboveReplica);
[email protected]022cbf162012-09-01 01:15:172973 EXPECT_RECT_EQ(expectedOpaqueBounds, occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:142974 EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:172975 EXPECT_RECT_EQ(expectedOpaqueBounds, occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:142976 EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
2977 }
2978};
2979
[email protected]96baf3e2012-10-22 23:09:552980ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:142981
[email protected]ece1d952012-10-18 21:26:072982template<class Types>
[email protected]96baf3e2012-10-22 23:09:552983class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142984protected:
[email protected]96baf3e2012-10-22 23:09:552985 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142986 void runMyTest()
2987 {
2988 WebTransformationMatrix scaleByHalf;
2989 scaleByHalf.scale(0.5);
2990
2991 // Make a surface and its replica, each 50x50, that are partially occluded by opaque layers which are above them in the z-order.
2992 // The surface is scaled to test that the pixel moving is done in the target space, where the background filter is applied, but the surface
2993 // appears at 50, 50 and the replica at 200, 50.
2994 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 150));
2995 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, FloatPoint(50, 50), IntSize(100, 100), false);
2996 this->createReplicaLayer(filteredSurface, this->identityMatrix, FloatPoint(300, 0), IntSize());
2997 typename Types::LayerType* aboveSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(70, 50), IntSize(30, 50), true);
2998 typename Types::LayerType* aboveReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(200, 50), IntSize(30, 50), true);
2999 typename Types::LayerType* besideSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(90, 40), IntSize(10, 10), true);
3000 typename Types::LayerType* besideReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(200, 40), IntSize(10, 10), true);
3001
3002 // Filters make the layer own a surface.
3003 WebFilterOperations filters;
3004 filters.append(WebFilterOperation::createBlurFilter(3));
3005 filteredSurface->setBackgroundFilters(filters);
3006
3007 // Save the distance of influence for the blur effect.
3008 int outsetTop, outsetRight, outsetBottom, outsetLeft;
3009 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
3010
3011 this->calcDrawEtc(parent);
3012
[email protected]96baf3e2012-10-22 23:09:553013 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143014 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
3015
3016 this->visitLayer(besideReplicaLayer, occlusion);
3017 this->visitLayer(besideSurfaceLayer, occlusion);
3018 this->visitLayer(aboveReplicaLayer, occlusion);
3019 this->visitLayer(aboveSurfaceLayer, occlusion);
3020
3021 // The surface has a background blur, so it blurs non-opaque pixels below it.
3022 this->visitLayer(filteredSurface, occlusion);
3023 this->visitContributingSurface(filteredSurface, occlusion);
3024
3025 // The filter in the surface and replica are partially unoccluded. Only the unoccluded parts should reduce occlusion.
3026 // This means it will push back the occlusion that touches the unoccluded part (occlusionAbove___), but it will not
3027 // touch occlusionBeside____ since that is not beside the unoccluded part of the surface, even though it is beside
3028 // the occluded part of the surface.
3029 IntRect occlusionAboveSurface = IntRect(70 + outsetRight, 50, 30 - outsetRight, 50);
3030 IntRect occlusionAboveReplica = IntRect(200, 50, 30 - outsetLeft, 50);
3031 IntRect occlusionBesideSurface = IntRect(90, 40, 10, 10);
3032 IntRect occlusionBesideReplica = IntRect(200, 40, 10, 10);
3033
3034 Region expectedOcclusion;
3035 expectedOcclusion.unite(occlusionAboveSurface);
3036 expectedOcclusion.unite(occlusionAboveReplica);
3037 expectedOcclusion.unite(occlusionBesideSurface);
3038 expectedOcclusion.unite(occlusionBesideReplica);
3039
3040 ASSERT_EQ(expectedOcclusion.rects().size(), occlusion.occlusionInTargetSurface().rects().size());
3041 ASSERT_EQ(expectedOcclusion.rects().size(), occlusion.occlusionInScreenSpace().rects().size());
3042
3043 for (size_t i = 0; i < expectedOcclusion.rects().size(); ++i) {
3044 IntRect expectedRect = expectedOcclusion.rects()[i];
3045 IntRect screenRect = occlusion.occlusionInScreenSpace().rects()[i];
3046 IntRect targetRect = occlusion.occlusionInTargetSurface().rects()[i];
3047 EXPECT_EQ(expectedRect, screenRect);
3048 EXPECT_EQ(expectedRect, targetRect);
3049 }
3050 }
3051};
3052
[email protected]96baf3e2012-10-22 23:09:553053ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:143054
[email protected]ece1d952012-10-18 21:26:073055template<class Types>
[email protected]96baf3e2012-10-22 23:09:553056class OcclusionTrackerTestMinimumTrackingSize : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:143057protected:
[email protected]96baf3e2012-10-22 23:09:553058 OcclusionTrackerTestMinimumTrackingSize(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:143059 void runMyTest()
3060 {
3061 IntSize trackingSize(100, 100);
3062 IntSize belowTrackingSize(99, 99);
3063
3064 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(400, 400));
3065 typename Types::LayerType* large = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), trackingSize, true);
3066 typename Types::LayerType* small = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(0, 0), belowTrackingSize, true);
3067 this->calcDrawEtc(parent);
3068
[email protected]96baf3e2012-10-22 23:09:553069 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143070 occlusion.setLayerClipRect(IntRect(0, 0, 1000, 1000));
3071 occlusion.setMinimumTrackingSize(trackingSize);
3072
3073 // The small layer is not tracked because it is too small.
3074 this->visitLayer(small, occlusion);
3075
[email protected]022cbf162012-09-01 01:15:173076 EXPECT_RECT_EQ(IntRect(), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:143077 EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:173078 EXPECT_RECT_EQ(IntRect(), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:143079 EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
3080
3081 // The large layer is tracked as it is large enough.
3082 this->visitLayer(large, occlusion);
3083
[email protected]022cbf162012-09-01 01:15:173084 EXPECT_RECT_EQ(IntRect(IntPoint(), trackingSize), occlusion.occlusionInScreenSpace().bounds());
[email protected]94f206c12012-08-25 00:09:143085 EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
[email protected]022cbf162012-09-01 01:15:173086 EXPECT_RECT_EQ(IntRect(IntPoint(), trackingSize), occlusion.occlusionInTargetSurface().bounds());
[email protected]94f206c12012-08-25 00:09:143087 EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
3088 }
3089};
3090
[email protected]96baf3e2012-10-22 23:09:553091ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:143092
3093} // namespace