blob: 5f366fb0a694f869a6cdc24d7ead272b67936c65 [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
[email protected]55a124d02012-10-22 03:07:135#include "cc/occlusion_tracker.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]c8686a02012-11-27 08:29:007#include <public/WebFilterOperation.h>
8#include <public/WebFilterOperations.h>
9
[email protected]a8461d82012-10-16 21:11:1410#include "cc/layer.h"
[email protected]d50c6862012-10-23 02:08:3111#include "cc/layer_animation_controller.h"
12#include "cc/layer_impl.h"
13#include "cc/layer_tree_host_common.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"
[email protected]586d51ed2012-12-07 20:31:4518#include "cc/test/fake_impl_proxy.h"
19#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0320#include "cc/test/geometry_test_utils.h"
21#include "cc/test/occlusion_tracker_test_common.h"
[email protected]7f0c53db2012-10-02 00:23:1822#include "testing/gmock/include/gmock/gmock.h"
23#include "testing/gtest/include/gtest/gtest.h"
[email protected]c8686a02012-11-27 08:29:0024#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1425
[email protected]94f206c12012-08-25 00:09:1426using namespace WebKit;
27using namespace WebKitTests;
28
[email protected]ba565742012-11-10 09:29:4829namespace cc {
[email protected]94f206c12012-08-25 00:09:1430namespace {
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)
[email protected]d0f98362012-11-01 23:02:3844 return gfx::IntersectRects(m_opaqueContentsRect, visibleContentRect());
[email protected]96baf3e2012-10-22 23:09:5545 return Layer::visibleContentOpaqueRegion();
[email protected]94f206c12012-08-25 00:09:1446 }
[email protected]aad0a0072012-11-01 18:15:5847 void setOpaqueContentsRect(const gfx::Rect& opaqueContentsRect)
[email protected]94f206c12012-08-25 00:09:1448 {
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;
[email protected]aad0a0072012-11-01 18:15:5859 gfx::Rect m_opaqueContentsRect;
[email protected]94f206c12012-08-25 00:09:1460};
61
[email protected]96baf3e2012-10-22 23:09:5562class TestContentLayerImpl : public LayerImpl {
[email protected]94f206c12012-08-25 00:09:1463public:
[email protected]586d51ed2012-12-07 20:31:4564 TestContentLayerImpl(LayerTreeHostImpl* hostImpl, int id)
65 : LayerImpl(hostImpl, 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)
[email protected]d0f98362012-11-01 23:02:3874 return gfx::IntersectRects(m_opaqueContentsRect, visibleContentRect());
[email protected]96baf3e2012-10-22 23:09:5575 return LayerImpl::visibleContentOpaqueRegion();
[email protected]94f206c12012-08-25 00:09:1476 }
[email protected]aad0a0072012-11-01 18:15:5877 void setOpaqueContentsRect(const gfx::Rect& opaqueContentsRect)
[email protected]94f206c12012-08-25 00:09:1478 {
79 m_overrideOpaqueContentsRect = true;
80 m_opaqueContentsRect = opaqueContentsRect;
81 }
82
83private:
84 bool m_overrideOpaqueContentsRect;
[email protected]aad0a0072012-11-01 18:15:5885 gfx::Rect m_opaqueContentsRect;
[email protected]94f206c12012-08-25 00:09:1486};
87
[email protected]710ffc02012-10-30 21:42:0288static inline bool layerImplDrawTransformIsUnknown(const Layer* layer) { return layer->drawTransformIsAnimating(); }
89static inline bool layerImplDrawTransformIsUnknown(const LayerImpl*) { return false; }
90
[email protected]94f206c12012-08-25 00:09:1491template<typename LayerType, typename RenderSurfaceType>
[email protected]96baf3e2012-10-22 23:09:5592class TestOcclusionTrackerWithClip : public TestOcclusionTrackerBase<LayerType, RenderSurfaceType> {
[email protected]94f206c12012-08-25 00:09:1493public:
[email protected]167ed9d52012-10-31 20:47:5894 TestOcclusionTrackerWithClip(gfx::Rect viewportRect, bool recordMetricsForFrame = false)
[email protected]96baf3e2012-10-22 23:09:5595 : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(viewportRect, recordMetricsForFrame)
[email protected]94f206c12012-08-25 00:09:1496 , m_overrideLayerClipRect(false)
97 {
98 }
99
[email protected]167ed9d52012-10-31 20:47:58100 void setLayerClipRect(const gfx::Rect& rect) { m_overrideLayerClipRect = true; m_layerClipRect = rect;}
[email protected]94f206c12012-08-25 00:09:14101 void useDefaultLayerClipRect() { m_overrideLayerClipRect = false; }
[email protected]710ffc02012-10-30 21:42:02102 // Returns true if the given rect in content space for the layer is fully occluded in either screen space or the layer's target surface.
[email protected]167ed9d52012-10-31 20:47:58103 bool occludedLayer(const LayerType* layer, const gfx::Rect& contentRect, bool* hasOcclusionFromOutsideTargetSurface = 0) const
[email protected]710ffc02012-10-30 21:42:02104 {
105 return this->occluded(layer->renderTarget(), contentRect, layer->drawTransform(), layerImplDrawTransformIsUnknown(layer), layerClipRectInTarget(layer), hasOcclusionFromOutsideTargetSurface);
106 }
107 // Gives an unoccluded sub-rect of |contentRect| in the content space of the layer. Simple wrapper around unoccludedContentRect.
[email protected]167ed9d52012-10-31 20:47:58108 gfx::Rect unoccludedLayerContentRect(const LayerType* layer, const gfx::Rect& contentRect, bool* hasOcclusionFromOutsideTargetSurface = 0) const
[email protected]710ffc02012-10-30 21:42:02109 {
110 return this->unoccludedContentRect(layer->renderTarget(), contentRect, layer->drawTransform(), layerImplDrawTransformIsUnknown(layer), layerClipRectInTarget(layer), hasOcclusionFromOutsideTargetSurface);
111 }
112
[email protected]94f206c12012-08-25 00:09:14113
114protected:
[email protected]167ed9d52012-10-31 20:47:58115 virtual gfx::Rect layerClipRectInTarget(const LayerType* layer) const { return m_overrideLayerClipRect ? m_layerClipRect : OcclusionTrackerBase<LayerType, RenderSurfaceType>::layerClipRectInTarget(layer); }
[email protected]94f206c12012-08-25 00:09:14116
117private:
118 bool m_overrideLayerClipRect;
[email protected]167ed9d52012-10-31 20:47:58119 gfx::Rect m_layerClipRect;
[email protected]94f206c12012-08-25 00:09:14120};
121
[email protected]96baf3e2012-10-22 23:09:55122struct OcclusionTrackerTestMainThreadTypes {
123 typedef Layer LayerType;
[email protected]586d51ed2012-12-07 20:31:45124 typedef LayerTreeHost HostType;
[email protected]96baf3e2012-10-22 23:09:55125 typedef RenderSurface RenderSurfaceType;
126 typedef TestContentLayer ContentLayerType;
127 typedef scoped_refptr<Layer> LayerPtrType;
[email protected]d58499a2012-10-09 22:27:47128 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
[email protected]96baf3e2012-10-22 23:09:55129 typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::FrontToBack> TestLayerIterator;
130 typedef OcclusionTracker OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14131
[email protected]586d51ed2012-12-07 20:31:45132 static LayerPtrType createLayer(HostType*)
[email protected]94f206c12012-08-25 00:09:14133 {
[email protected]96baf3e2012-10-22 23:09:55134 return Layer::create();
[email protected]94f206c12012-08-25 00:09:14135 }
[email protected]586d51ed2012-12-07 20:31:45136 static ContentLayerPtrType createContentLayer(HostType*) { return make_scoped_refptr(new ContentLayerType()); }
[email protected]e0bd43a2012-10-12 16:54:21137
138 static LayerPtrType passLayerPtr(ContentLayerPtrType& layer)
139 {
[email protected]1b8660f2012-12-07 00:50:21140 LayerPtrType ref(layer);
141 layer = NULL;
142 return ref;
[email protected]e0bd43a2012-10-12 16:54:21143 }
144
145 static LayerPtrType passLayerPtr(LayerPtrType& layer)
146 {
[email protected]1b8660f2012-12-07 00:50:21147 LayerPtrType ref(layer);
148 layer = NULL;
149 return ref;
[email protected]e0bd43a2012-10-12 16:54:21150 }
[email protected]d58499a2012-10-09 22:27:47151
152 static void destroyLayer(LayerPtrType& layer)
153 {
154 layer = NULL;
155 }
[email protected]94f206c12012-08-25 00:09:14156};
157
[email protected]96baf3e2012-10-22 23:09:55158struct OcclusionTrackerTestImplThreadTypes {
159 typedef LayerImpl LayerType;
[email protected]586d51ed2012-12-07 20:31:45160 typedef LayerTreeHostImpl HostType;
[email protected]96baf3e2012-10-22 23:09:55161 typedef RenderSurfaceImpl RenderSurfaceType;
[email protected]94f206c12012-08-25 00:09:14162 typedef TestContentLayerImpl ContentLayerType;
[email protected]96baf3e2012-10-22 23:09:55163 typedef scoped_ptr<LayerImpl> LayerPtrType;
[email protected]e0bd43a2012-10-12 16:54:21164 typedef scoped_ptr<ContentLayerType> ContentLayerPtrType;
[email protected]96baf3e2012-10-22 23:09:55165 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> TestLayerIterator;
166 typedef OcclusionTrackerImpl OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14167
[email protected]586d51ed2012-12-07 20:31:45168 static LayerPtrType createLayer(HostType* host) { return LayerImpl::create(host, nextLayerImplId++); }
169 static ContentLayerPtrType createContentLayer(HostType* host) { return make_scoped_ptr(new ContentLayerType(host, nextLayerImplId++)); }
[email protected]96baf3e2012-10-22 23:09:55170 static int nextLayerImplId;
[email protected]d58499a2012-10-09 22:27:47171
[email protected]e0bd43a2012-10-12 16:54:21172 static LayerPtrType passLayerPtr(LayerPtrType& layer)
173 {
174 return layer.Pass();
175 }
176
177 static LayerPtrType passLayerPtr(ContentLayerPtrType& layer)
178 {
179 return layer.PassAs<LayerType>();
180 }
181
[email protected]d58499a2012-10-09 22:27:47182 static void destroyLayer(LayerPtrType& layer)
183 {
[email protected]e0bd43a2012-10-12 16:54:21184 layer.reset();
[email protected]d58499a2012-10-09 22:27:47185 }
[email protected]94f206c12012-08-25 00:09:14186};
187
[email protected]96baf3e2012-10-22 23:09:55188int OcclusionTrackerTestImplThreadTypes::nextLayerImplId = 1;
[email protected]94f206c12012-08-25 00:09:14189
[email protected]ece1d952012-10-18 21:26:07190template<typename Types>
[email protected]96baf3e2012-10-22 23:09:55191class OcclusionTrackerTest : public testing::Test {
[email protected]94f206c12012-08-25 00:09:14192protected:
[email protected]96baf3e2012-10-22 23:09:55193 OcclusionTrackerTest(bool opaqueLayers)
[email protected]586d51ed2012-12-07 20:31:45194 : m_hostImpl(&m_proxy)
195 , m_opaqueLayers(opaqueLayers)
196 {
197 }
[email protected]94f206c12012-08-25 00:09:14198
199 virtual void runMyTest() = 0;
200
201 virtual void TearDown()
202 {
[email protected]d58499a2012-10-09 22:27:47203 Types::destroyLayer(m_root);
[email protected]96baf3e2012-10-22 23:09:55204 m_renderSurfaceLayerList.clear();
[email protected]94f206c12012-08-25 00:09:14205 m_renderSurfaceLayerListImpl.clear();
206 m_replicaLayers.clear();
207 m_maskLayers.clear();
[email protected]96baf3e2012-10-22 23:09:55208 LayerTreeHost::setNeedsFilterContext(false);
[email protected]94f206c12012-08-25 00:09:14209 }
210
[email protected]586d51ed2012-12-07 20:31:45211 typename Types::HostType* getHost();
212
[email protected]c8686a02012-11-27 08:29:00213 typename Types::ContentLayerType* createRoot(const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14214 {
[email protected]586d51ed2012-12-07 20:31:45215 typename Types::ContentLayerPtrType layer(Types::createContentLayer(getHost()));
[email protected]94f206c12012-08-25 00:09:14216 typename Types::ContentLayerType* layerPtr = layer.get();
217 setProperties(layerPtr, transform, position, bounds);
218
[email protected]1d993172012-10-18 18:15:04219 DCHECK(!m_root);
[email protected]e0bd43a2012-10-12 16:54:21220 m_root = Types::passLayerPtr(layer);
[email protected]94f206c12012-08-25 00:09:14221 return layerPtr;
222 }
223
[email protected]c8686a02012-11-27 08:29:00224 typename Types::LayerType* createLayer(typename Types::LayerType* parent, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14225 {
[email protected]586d51ed2012-12-07 20:31:45226 typename Types::LayerPtrType layer(Types::createLayer(getHost()));
[email protected]94f206c12012-08-25 00:09:14227 typename Types::LayerType* layerPtr = layer.get();
228 setProperties(layerPtr, transform, position, bounds);
[email protected]e0bd43a2012-10-12 16:54:21229 parent->addChild(Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14230 return layerPtr;
231 }
232
[email protected]c8686a02012-11-27 08:29:00233 typename Types::LayerType* createSurface(typename Types::LayerType* parent, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14234 {
235 typename Types::LayerType* layer = createLayer(parent, transform, position, bounds);
236 WebFilterOperations filters;
237 filters.append(WebFilterOperation::createGrayscaleFilter(0.5));
238 layer->setFilters(filters);
239 return layer;
240 }
241
[email protected]c8686a02012-11-27 08:29:00242 typename Types::ContentLayerType* createDrawingLayer(typename Types::LayerType* parent, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds, bool opaque)
[email protected]94f206c12012-08-25 00:09:14243 {
[email protected]586d51ed2012-12-07 20:31:45244 typename Types::ContentLayerPtrType layer(Types::createContentLayer(getHost()));
[email protected]94f206c12012-08-25 00:09:14245 typename Types::ContentLayerType* layerPtr = layer.get();
246 setProperties(layerPtr, transform, position, bounds);
247
[email protected]ece1d952012-10-18 21:26:07248 if (m_opaqueLayers)
[email protected]048634c2012-10-02 22:33:14249 layerPtr->setContentsOpaque(opaque);
[email protected]94f206c12012-08-25 00:09:14250 else {
[email protected]048634c2012-10-02 22:33:14251 layerPtr->setContentsOpaque(false);
[email protected]94f206c12012-08-25 00:09:14252 if (opaque)
[email protected]aad0a0072012-11-01 18:15:58253 layerPtr->setOpaqueContentsRect(gfx::Rect(gfx::Point(), bounds));
[email protected]94f206c12012-08-25 00:09:14254 else
[email protected]aad0a0072012-11-01 18:15:58255 layerPtr->setOpaqueContentsRect(gfx::Rect());
[email protected]94f206c12012-08-25 00:09:14256 }
257
[email protected]e0bd43a2012-10-12 16:54:21258 parent->addChild(Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14259 return layerPtr;
260 }
261
[email protected]c8686a02012-11-27 08:29:00262 typename Types::LayerType* createReplicaLayer(typename Types::LayerType* owningLayer, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14263 {
[email protected]586d51ed2012-12-07 20:31:45264 typename Types::ContentLayerPtrType layer(Types::createContentLayer(getHost()));
[email protected]94f206c12012-08-25 00:09:14265 typename Types::ContentLayerType* layerPtr = layer.get();
266 setProperties(layerPtr, transform, position, bounds);
[email protected]e0bd43a2012-10-12 16:54:21267 setReplica(owningLayer, Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14268 return layerPtr;
269 }
270
[email protected]aad0a0072012-11-01 18:15:58271 typename Types::LayerType* createMaskLayer(typename Types::LayerType* owningLayer, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14272 {
[email protected]586d51ed2012-12-07 20:31:45273 typename Types::ContentLayerPtrType layer(Types::createContentLayer(getHost()));
[email protected]94f206c12012-08-25 00:09:14274 typename Types::ContentLayerType* layerPtr = layer.get();
[email protected]d0f98362012-11-01 23:02:38275 setProperties(layerPtr, identityMatrix, gfx::PointF(), bounds);
[email protected]e0bd43a2012-10-12 16:54:21276 setMask(owningLayer, Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14277 return layerPtr;
278 }
279
[email protected]c8686a02012-11-27 08:29:00280 typename Types::ContentLayerType* createDrawingSurface(typename Types::LayerType* parent, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds, bool opaque)
[email protected]94f206c12012-08-25 00:09:14281 {
282 typename Types::ContentLayerType* layer = createDrawingLayer(parent, transform, position, bounds, opaque);
283 WebFilterOperations filters;
284 filters.append(WebFilterOperation::createGrayscaleFilter(0.5));
285 layer->setFilters(filters);
286 return layer;
287 }
288
289 void calcDrawEtc(TestContentLayerImpl* root)
290 {
[email protected]1d993172012-10-18 18:15:04291 DCHECK(root == m_root.get());
[email protected]94f206c12012-08-25 00:09:14292 int dummyMaxTextureSize = 512;
[email protected]94f206c12012-08-25 00:09:14293
[email protected]1d993172012-10-18 18:15:04294 DCHECK(!root->renderSurface());
[email protected]94f206c12012-08-25 00:09:14295
[email protected]93698c12012-12-07 00:43:56296 LayerTreeHostCommon::calculateDrawProperties(root, root->bounds(), 1, 1, dummyMaxTextureSize, m_renderSurfaceLayerListImpl);
[email protected]94f206c12012-08-25 00:09:14297
[email protected]96baf3e2012-10-22 23:09:55298 m_layerIterator = m_layerIteratorBegin = Types::TestLayerIterator::begin(&m_renderSurfaceLayerListImpl);
[email protected]94f206c12012-08-25 00:09:14299 }
300
[email protected]96baf3e2012-10-22 23:09:55301 void calcDrawEtc(TestContentLayer* root)
[email protected]94f206c12012-08-25 00:09:14302 {
[email protected]1d993172012-10-18 18:15:04303 DCHECK(root == m_root.get());
[email protected]94f206c12012-08-25 00:09:14304 int dummyMaxTextureSize = 512;
305
[email protected]1d993172012-10-18 18:15:04306 DCHECK(!root->renderSurface());
[email protected]94f206c12012-08-25 00:09:14307
[email protected]d76806f82012-12-05 21:41:50308 LayerTreeHostCommon::calculateDrawProperties(root, root->bounds(), 1, 1, dummyMaxTextureSize, m_renderSurfaceLayerList);
[email protected]94f206c12012-08-25 00:09:14309
[email protected]96baf3e2012-10-22 23:09:55310 m_layerIterator = m_layerIteratorBegin = Types::TestLayerIterator::begin(&m_renderSurfaceLayerList);
[email protected]94f206c12012-08-25 00:09:14311 }
312
313 void enterLayer(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
314 {
315 ASSERT_EQ(layer, *m_layerIterator);
316 ASSERT_TRUE(m_layerIterator.representsItself());
317 occlusion.enterLayer(m_layerIterator);
318 }
319
320 void leaveLayer(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
321 {
322 ASSERT_EQ(layer, *m_layerIterator);
323 ASSERT_TRUE(m_layerIterator.representsItself());
324 occlusion.leaveLayer(m_layerIterator);
325 ++m_layerIterator;
326 }
327
328 void visitLayer(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
329 {
330 enterLayer(layer, occlusion);
331 leaveLayer(layer, occlusion);
332 }
333
334 void enterContributingSurface(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
335 {
336 ASSERT_EQ(layer, *m_layerIterator);
337 ASSERT_TRUE(m_layerIterator.representsTargetRenderSurface());
338 occlusion.enterLayer(m_layerIterator);
339 occlusion.leaveLayer(m_layerIterator);
340 ++m_layerIterator;
341 ASSERT_TRUE(m_layerIterator.representsContributingRenderSurface());
342 occlusion.enterLayer(m_layerIterator);
343 }
344
345 void leaveContributingSurface(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
346 {
347 ASSERT_EQ(layer, *m_layerIterator);
348 ASSERT_TRUE(m_layerIterator.representsContributingRenderSurface());
349 occlusion.leaveLayer(m_layerIterator);
350 ++m_layerIterator;
351 }
352
353 void visitContributingSurface(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
354 {
355 enterContributingSurface(layer, occlusion);
356 leaveContributingSurface(layer, occlusion);
357 }
358
359 void resetLayerIterator()
360 {
361 m_layerIterator = m_layerIteratorBegin;
362 }
363
[email protected]c8686a02012-11-27 08:29:00364 const gfx::Transform identityMatrix;
[email protected]94f206c12012-08-25 00:09:14365
366private:
[email protected]c8686a02012-11-27 08:29:00367 void setBaseProperties(typename Types::LayerType* layer, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14368 {
369 layer->setTransform(transform);
[email protected]c8686a02012-11-27 08:29:00370 layer->setSublayerTransform(gfx::Transform());
[email protected]d0f98362012-11-01 23:02:38371 layer->setAnchorPoint(gfx::PointF(0, 0));
[email protected]94f206c12012-08-25 00:09:14372 layer->setPosition(position);
373 layer->setBounds(bounds);
374 }
375
[email protected]c8686a02012-11-27 08:29:00376 void setProperties(Layer* layer, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14377 {
378 setBaseProperties(layer, transform, position, bounds);
379 }
380
[email protected]c8686a02012-11-27 08:29:00381 void setProperties(LayerImpl* layer, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14382 {
383 setBaseProperties(layer, transform, position, bounds);
384
385 layer->setContentBounds(layer->bounds());
386 }
387
[email protected]96baf3e2012-10-22 23:09:55388 void setReplica(Layer* owningLayer, scoped_refptr<Layer> layer)
[email protected]94f206c12012-08-25 00:09:14389 {
390 owningLayer->setReplicaLayer(layer.get());
[email protected]d58499a2012-10-09 22:27:47391 m_replicaLayers.push_back(layer);
[email protected]94f206c12012-08-25 00:09:14392 }
393
[email protected]96baf3e2012-10-22 23:09:55394 void setReplica(LayerImpl* owningLayer, scoped_ptr<LayerImpl> layer)
[email protected]94f206c12012-08-25 00:09:14395 {
[email protected]e0bd43a2012-10-12 16:54:21396 owningLayer->setReplicaLayer(layer.Pass());
[email protected]94f206c12012-08-25 00:09:14397 }
398
[email protected]96baf3e2012-10-22 23:09:55399 void setMask(Layer* owningLayer, scoped_refptr<Layer> layer)
[email protected]94f206c12012-08-25 00:09:14400 {
401 owningLayer->setMaskLayer(layer.get());
[email protected]d58499a2012-10-09 22:27:47402 m_maskLayers.push_back(layer);
[email protected]94f206c12012-08-25 00:09:14403 }
404
[email protected]96baf3e2012-10-22 23:09:55405 void setMask(LayerImpl* owningLayer, scoped_ptr<LayerImpl> layer)
[email protected]94f206c12012-08-25 00:09:14406 {
[email protected]e0bd43a2012-10-12 16:54:21407 owningLayer->setMaskLayer(layer.Pass());
[email protected]94f206c12012-08-25 00:09:14408 }
409
[email protected]586d51ed2012-12-07 20:31:45410 FakeImplProxy m_proxy;
411 FakeLayerTreeHostImpl m_hostImpl;
[email protected]ece1d952012-10-18 21:26:07412 bool m_opaqueLayers;
[email protected]94f206c12012-08-25 00:09:14413 // These hold ownership of the layers for the duration of the test.
414 typename Types::LayerPtrType m_root;
[email protected]96baf3e2012-10-22 23:09:55415 std::vector<scoped_refptr<Layer> > m_renderSurfaceLayerList;
416 std::vector<LayerImpl*> m_renderSurfaceLayerListImpl;
417 typename Types::TestLayerIterator m_layerIteratorBegin;
418 typename Types::TestLayerIterator m_layerIterator;
[email protected]94f206c12012-08-25 00:09:14419 typename Types::LayerType* m_lastLayerVisited;
[email protected]96baf3e2012-10-22 23:09:55420 std::vector<scoped_refptr<Layer> > m_replicaLayers;
421 std::vector<scoped_refptr<Layer> > m_maskLayers;
[email protected]94f206c12012-08-25 00:09:14422};
423
[email protected]586d51ed2012-12-07 20:31:45424template<>
425LayerTreeHost* OcclusionTrackerTest<OcclusionTrackerTestMainThreadTypes>::getHost()
426{
427 return 0;
428}
429
430template<>
431LayerTreeHostImpl* OcclusionTrackerTest<OcclusionTrackerTestImplThreadTypes>::getHost()
432{
433 return &m_hostImpl;
434}
435
[email protected]94f206c12012-08-25 00:09:14436#define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55437 class ClassName##MainThreadOpaqueLayers : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14438 public: \
[email protected]96baf3e2012-10-22 23:09:55439 ClassName##MainThreadOpaqueLayers() : ClassName<OcclusionTrackerTestMainThreadTypes>(true) { } \
[email protected]94f206c12012-08-25 00:09:14440 }; \
441 TEST_F(ClassName##MainThreadOpaqueLayers, runTest) { runMyTest(); }
442#define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55443 class ClassName##MainThreadOpaquePaints : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14444 public: \
[email protected]96baf3e2012-10-22 23:09:55445 ClassName##MainThreadOpaquePaints() : ClassName<OcclusionTrackerTestMainThreadTypes>(false) { } \
[email protected]94f206c12012-08-25 00:09:14446 }; \
447 TEST_F(ClassName##MainThreadOpaquePaints, runTest) { runMyTest(); }
448
449#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55450 class ClassName##ImplThreadOpaqueLayers : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14451 public: \
[email protected]96baf3e2012-10-22 23:09:55452 ClassName##ImplThreadOpaqueLayers() : ClassName<OcclusionTrackerTestImplThreadTypes>(true) { } \
[email protected]94f206c12012-08-25 00:09:14453 }; \
454 TEST_F(ClassName##ImplThreadOpaqueLayers, runTest) { runMyTest(); }
455#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55456 class ClassName##ImplThreadOpaquePaints : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14457 public: \
[email protected]96baf3e2012-10-22 23:09:55458 ClassName##ImplThreadOpaquePaints() : ClassName<OcclusionTrackerTestImplThreadTypes>(false) { } \
[email protected]94f206c12012-08-25 00:09:14459 }; \
460 TEST_F(ClassName##ImplThreadOpaquePaints, runTest) { runMyTest(); }
461
[email protected]96baf3e2012-10-22 23:09:55462#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
[email protected]94f206c12012-08-25 00:09:14463 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
464 RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
465 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
466 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
467
468#define MAIN_THREAD_TEST(ClassName) \
[email protected]f3922f22012-10-12 09:20:38469 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14470
471#define IMPL_THREAD_TEST(ClassName) \
[email protected]f3922f22012-10-12 09:20:38472 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14473
474#define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
475 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]f3922f22012-10-12 09:20:38476 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14477
[email protected]ece1d952012-10-18 21:26:07478template<class Types>
[email protected]96baf3e2012-10-22 23:09:55479class OcclusionTrackerTestIdentityTransforms : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14480protected:
[email protected]96baf3e2012-10-22 23:09:55481 OcclusionTrackerTestIdentityTransforms(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]ece1d952012-10-18 21:26:07482
[email protected]94f206c12012-08-25 00:09:14483 void runMyTest()
484 {
[email protected]d0f98362012-11-01 23:02:38485 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
486 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(30, 30), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:14487 this->calcDrawEtc(parent);
488
[email protected]167ed9d52012-10-31 20:47:58489 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
490 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14491
492 this->visitLayer(layer, occlusion);
493 this->enterLayer(parent, occlusion);
494
[email protected]ac7c7f52012-11-08 06:26:50495 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
496 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14497
[email protected]167ed9d52012-10-31 20:47:58498 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
499 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
500 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
501 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
502 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14503
504 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58505 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
506 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
507 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
508 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
509 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
510 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14511
[email protected]167ed9d52012-10-31 20:47:58512 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
513 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 30, 70, 70)));
514 EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 29, 70, 70)));
515 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 29, 70, 70)));
516 EXPECT_RECT_EQ(gfx::Rect(31, 29, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 29, 70, 70)));
517 EXPECT_RECT_EQ(gfx::Rect(100, 30, 1, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 30, 70, 70)));
518 EXPECT_RECT_EQ(gfx::Rect(31, 31, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 31, 70, 70)));
519 EXPECT_RECT_EQ(gfx::Rect(30, 100, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 31, 70, 70)));
520 EXPECT_RECT_EQ(gfx::Rect(29, 31, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14521 }
522};
523
[email protected]96baf3e2012-10-22 23:09:55524ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14525
[email protected]ece1d952012-10-18 21:26:07526template<class Types>
[email protected]710ffc02012-10-30 21:42:02527class OcclusionTrackerTestQuadsMismatchLayer : public OcclusionTrackerTest<Types> {
528protected:
529 OcclusionTrackerTestQuadsMismatchLayer(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
530 void runMyTest()
531 {
[email protected]c8686a02012-11-27 08:29:00532 gfx::Transform layerTransform;
533 layerTransform.Translate(10, 10);
[email protected]710ffc02012-10-30 21:42:02534
[email protected]d0f98362012-11-01 23:02:38535 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::Point(0, 0), gfx::Size(100, 100));
536 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(parent, layerTransform, gfx::PointF(0, 0), gfx::Size(90, 90), true);
537 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(layer1, layerTransform, gfx::PointF(0, 0), gfx::Size(50, 50), true);
[email protected]710ffc02012-10-30 21:42:02538 this->calcDrawEtc(parent);
539
[email protected]167ed9d52012-10-31 20:47:58540 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02541
542 this->visitLayer(layer2, occlusion);
543 this->enterLayer(layer1, occlusion);
544
[email protected]ac7c7f52012-11-08 06:26:50545 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
546 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]710ffc02012-10-30 21:42:02547
548 // This checks cases where the quads don't match their "containing"
549 // layers, e.g. in terms of transforms or clip rect. This is typical for
550 // DelegatedRendererLayer.
551
[email protected]c8686a02012-11-27 08:29:00552 gfx::Transform quadTransform;
553 quadTransform.Translate(30, 30);
[email protected]167ed9d52012-10-31 20:47:58554 gfx::Rect clipRectInTarget(0, 0, 100, 100);
[email protected]710ffc02012-10-30 21:42:02555
[email protected]167ed9d52012-10-31 20:47:58556 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, gfx::Rect(0, 0, 10, 10), quadTransform, false, clipRectInTarget).IsEmpty());
557 EXPECT_RECT_EQ(gfx::Rect(0, 0, 10, 10), occlusion.unoccludedContentRect(parent, gfx::Rect(0, 0, 10, 10), quadTransform, true, clipRectInTarget));
558 EXPECT_RECT_EQ(gfx::Rect(40, 40, 10, 10), occlusion.unoccludedContentRect(parent, gfx::Rect(40, 40, 10, 10), quadTransform, false, clipRectInTarget));
559 EXPECT_RECT_EQ(gfx::Rect(40, 30, 5, 10), occlusion.unoccludedContentRect(parent, gfx::Rect(35, 30, 10, 10), quadTransform, false, clipRectInTarget));
560 EXPECT_RECT_EQ(gfx::Rect(40, 40, 5, 5), occlusion.unoccludedContentRect(parent, gfx::Rect(40, 40, 10, 10), quadTransform, false, gfx::Rect(0, 0, 75, 75)));
[email protected]710ffc02012-10-30 21:42:02561 }
562};
563
564ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestQuadsMismatchLayer);
565
566template<class Types>
[email protected]96baf3e2012-10-22 23:09:55567class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14568protected:
[email protected]96baf3e2012-10-22 23:09:55569 OcclusionTrackerTestRotatedChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14570 void runMyTest()
571 {
[email protected]c8686a02012-11-27 08:29:00572 gfx::Transform layerTransform;
573 layerTransform.Translate(250, 250);
574 layerTransform.Rotate(90);
575 layerTransform.Translate(-250, -250);
[email protected]94f206c12012-08-25 00:09:14576
[email protected]d0f98362012-11-01 23:02:38577 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
578 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:14579 this->calcDrawEtc(parent);
580
[email protected]167ed9d52012-10-31 20:47:58581 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
582 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14583
584 this->visitLayer(layer, occlusion);
585 this->enterLayer(parent, occlusion);
586
[email protected]ac7c7f52012-11-08 06:26:50587 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
588 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14589
[email protected]167ed9d52012-10-31 20:47:58590 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
591 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
592 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
593 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
594 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14595
596 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58597 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
598 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
599 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
600 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
601 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
602 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14603
[email protected]167ed9d52012-10-31 20:47:58604 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
605 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 30, 70, 70)));
606 EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 29, 70, 70)));
607 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 29, 70, 70)));
608 EXPECT_RECT_EQ(gfx::Rect(31, 29, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 29, 70, 70)));
609 EXPECT_RECT_EQ(gfx::Rect(100, 30, 1, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 30, 70, 70)));
610 EXPECT_RECT_EQ(gfx::Rect(31, 31, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 31, 70, 70)));
611 EXPECT_RECT_EQ(gfx::Rect(30, 100, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 31, 70, 70)));
612 EXPECT_RECT_EQ(gfx::Rect(29, 31, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14613 }
614};
615
[email protected]96baf3e2012-10-22 23:09:55616ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14617
[email protected]ece1d952012-10-18 21:26:07618template<class Types>
[email protected]96baf3e2012-10-22 23:09:55619class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14620protected:
[email protected]96baf3e2012-10-22 23:09:55621 OcclusionTrackerTestTranslatedChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14622 void runMyTest()
623 {
[email protected]c8686a02012-11-27 08:29:00624 gfx::Transform layerTransform;
625 layerTransform.Translate(20, 20);
[email protected]94f206c12012-08-25 00:09:14626
[email protected]d0f98362012-11-01 23:02:38627 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
628 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:14629 this->calcDrawEtc(parent);
630
[email protected]167ed9d52012-10-31 20:47:58631 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
632 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14633
634 this->visitLayer(layer, occlusion);
635 this->enterLayer(parent, occlusion);
636
[email protected]ac7c7f52012-11-08 06:26:50637 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
638 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14639
[email protected]167ed9d52012-10-31 20:47:58640 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(50, 50, 50, 50)));
641 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(49, 50, 50, 50)));
642 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(50, 49, 50, 50)));
643 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(51, 50, 50, 50)));
644 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(50, 51, 50, 50)));
[email protected]94f206c12012-08-25 00:09:14645
646 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58647 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(50, 50, 50, 50)));
648 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(49, 50, 50, 50)));
649 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(50, 49, 50, 50)));
650 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(51, 50, 50, 50)));
651 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(50, 51, 50, 50)));
652 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14653
[email protected]167ed9d52012-10-31 20:47:58654 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 50, 50, 50)).IsEmpty());
655 EXPECT_RECT_EQ(gfx::Rect(49, 50, 1, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 50, 50, 50)));
656 EXPECT_RECT_EQ(gfx::Rect(49, 49, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 49, 50, 50)));
657 EXPECT_RECT_EQ(gfx::Rect(50, 49, 50, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 49, 50, 50)));
658 EXPECT_RECT_EQ(gfx::Rect(51, 49, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 49, 50, 50)));
659 EXPECT_RECT_EQ(gfx::Rect(100, 50, 1, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 50, 50, 50)));
660 EXPECT_RECT_EQ(gfx::Rect(51, 51, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 51, 50, 50)));
661 EXPECT_RECT_EQ(gfx::Rect(50, 100, 50, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 51, 50, 50)));
662 EXPECT_RECT_EQ(gfx::Rect(49, 51, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 51, 50, 50)));
[email protected]94f206c12012-08-25 00:09:14663
664 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58665 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 50, 50, 50)).IsEmpty());
666 EXPECT_RECT_EQ(gfx::Rect(49, 50, 1, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 50, 50, 50)));
667 EXPECT_RECT_EQ(gfx::Rect(49, 49, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 49, 50, 50)));
668 EXPECT_RECT_EQ(gfx::Rect(50, 49, 50, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 49, 50, 50)));
669 EXPECT_RECT_EQ(gfx::Rect(51, 49, 49, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 49, 50, 50)));
670 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 50, 50, 50)).IsEmpty());
671 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 51, 50, 50)).IsEmpty());
672 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 51, 50, 50)).IsEmpty());
673 EXPECT_RECT_EQ(gfx::Rect(49, 51, 1, 49), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 51, 50, 50)));
674 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14675 }
676};
677
[email protected]96baf3e2012-10-22 23:09:55678ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14679
[email protected]ece1d952012-10-18 21:26:07680template<class Types>
[email protected]96baf3e2012-10-22 23:09:55681class OcclusionTrackerTestChildInRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14682protected:
[email protected]96baf3e2012-10-22 23:09:55683 OcclusionTrackerTestChildInRotatedChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14684 void runMyTest()
685 {
[email protected]c8686a02012-11-27 08:29:00686 gfx::Transform childTransform;
687 childTransform.Translate(250, 250);
688 childTransform.Rotate(90);
689 childTransform.Translate(-250, -250);
[email protected]94f206c12012-08-25 00:09:14690
[email protected]d0f98362012-11-01 23:02:38691 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:38692 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38693 typename Types::LayerType* child = this->createLayer(parent, childTransform, gfx::PointF(30, 30), gfx::Size(500, 500));
[email protected]94f206c12012-08-25 00:09:14694 child->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38695 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, gfx::PointF(10, 10), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:14696 this->calcDrawEtc(parent);
697
[email protected]167ed9d52012-10-31 20:47:58698 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
699 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14700
701 this->visitLayer(layer, occlusion);
702 this->enterContributingSurface(child, occlusion);
703
[email protected]ac7c7f52012-11-08 06:26:50704 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
705 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14706
707 this->leaveContributingSurface(child, occlusion);
708 this->enterLayer(parent, occlusion);
709
[email protected]ac7c7f52012-11-08 06:26:50710 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
711 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14712
[email protected]167ed9d52012-10-31 20:47:58713 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
714 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
715 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
716 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(31, 40, 70, 60)));
717 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 41, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14718
719 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58720 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
721 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
722 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
723 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(31, 40, 70, 60)));
724 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 41, 70, 60)));
725 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14726
727
728 /* Justification for the above occlusion from |layer|:
729 100
730 +---------------------+ +---------------------+
731 | | | |30 Visible region of |layer|: /////
732 | 30 | rotate(90) | |
733 | 30 + ---------------------------------+ | +---------------------------------+
734 100 | | 10 | | ==> | | |10 |
735 | |10+---------------------------------+ | +---------------------------------+ |
736 | | | | | | | | |///////////////| 420 | |
737 | | | | | | | | |///////////////|60 | |
738 | | | | | | | | |///////////////| | |
739 +----|--|-------------+ | | +--|--|---------------+ | |
740 | | | | 20|10| 70 | |
741 | | | | | | | |
742 | | | |500 | | | |
743 | | | | | | | |
744 | | | | | | | |
745 | | | | | | | |
746 | | | | | | |10|
747 +--|-------------------------------+ | | +------------------------------|--+
748 | | | 490 |
749 +---------------------------------+ +---------------------------------+
750 500 500
751 */
752 }
753};
754
[email protected]96baf3e2012-10-22 23:09:55755ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14756
[email protected]ece1d952012-10-18 21:26:07757template<class Types>
[email protected]710ffc02012-10-30 21:42:02758class OcclusionTrackerTestScaledRenderSurface : public OcclusionTrackerTest<Types> {
759protected:
760 OcclusionTrackerTestScaledRenderSurface(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
761
762 void runMyTest()
763 {
[email protected]d0f98362012-11-01 23:02:38764 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02765
[email protected]c8686a02012-11-27 08:29:00766 gfx::Transform layer1Matrix;
767 layer1Matrix.Scale(2, 2);
[email protected]d0f98362012-11-01 23:02:38768 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(parent, layer1Matrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
[email protected]710ffc02012-10-30 21:42:02769 layer1->setForceRenderSurface(true);
770
[email protected]c8686a02012-11-27 08:29:00771 gfx::Transform layer2Matrix;
772 layer2Matrix.Translate(25, 25);
[email protected]d0f98362012-11-01 23:02:38773 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(layer1, layer2Matrix, gfx::PointF(0, 0), gfx::Size(50, 50), true);
774 typename Types::ContentLayerType* occluder = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(100, 100), gfx::Size(500, 500), true);
[email protected]710ffc02012-10-30 21:42:02775 this->calcDrawEtc(parent);
776
[email protected]167ed9d52012-10-31 20:47:58777 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02778
779 this->visitLayer(occluder, occlusion);
780 this->enterLayer(layer2, occlusion);
781
[email protected]ac7c7f52012-11-08 06:26:50782 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), occlusion.occlusionInScreenSpace().ToString());
783 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]710ffc02012-10-30 21:42:02784
[email protected]167ed9d52012-10-31 20:47:58785 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), occlusion.unoccludedLayerContentRect(layer2, gfx::Rect(0, 0, 25, 25)));
786 EXPECT_RECT_EQ(gfx::Rect(10, 25, 15, 25), occlusion.unoccludedLayerContentRect(layer2, gfx::Rect(10, 25, 25, 25)));
787 EXPECT_RECT_EQ(gfx::Rect(25, 10, 25, 15), occlusion.unoccludedLayerContentRect(layer2, gfx::Rect(25, 10, 25, 25)));
788 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(layer2, gfx::Rect(25, 25, 25, 25)).IsEmpty());
[email protected]710ffc02012-10-30 21:42:02789 }
790};
791
792ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
793
794template<class Types>
[email protected]96baf3e2012-10-22 23:09:55795class OcclusionTrackerTestVisitTargetTwoTimes : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14796protected:
[email protected]96baf3e2012-10-22 23:09:55797 OcclusionTrackerTestVisitTargetTwoTimes(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14798 void runMyTest()
799 {
[email protected]c8686a02012-11-27 08:29:00800 gfx::Transform childTransform;
801 childTransform.Translate(250, 250);
802 childTransform.Rotate(90);
803 childTransform.Translate(-250, -250);
[email protected]94f206c12012-08-25 00:09:14804
[email protected]d0f98362012-11-01 23:02:38805 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:38806 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38807 typename Types::LayerType* child = this->createLayer(parent, childTransform, gfx::PointF(30, 30), gfx::Size(500, 500));
[email protected]94f206c12012-08-25 00:09:14808 child->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38809 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, gfx::PointF(10, 10), gfx::Size(500, 500), true);
[email protected]96baf3e2012-10-22 23:09:55810 // |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:14811 // leaveToTargetRenderSurface, as the target surface has already been seen.
[email protected]d0f98362012-11-01 23:02:38812 typename Types::ContentLayerType* child2 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(30, 30), gfx::Size(60, 20), true);
[email protected]94f206c12012-08-25 00:09:14813 this->calcDrawEtc(parent);
814
[email protected]167ed9d52012-10-31 20:47:58815 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
816 occlusion.setLayerClipRect(gfx::Rect(-10, -10, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14817
818 this->visitLayer(child2, occlusion);
819
[email protected]ac7c7f52012-11-08 06:26:50820 EXPECT_EQ(gfx::Rect(30, 30, 60, 20).ToString(), occlusion.occlusionInScreenSpace().ToString());
821 EXPECT_EQ(gfx::Rect(30, 30, 60, 20).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14822
823 this->visitLayer(layer, occlusion);
824
[email protected]ac7c7f52012-11-08 06:26:50825 EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60)).ToString(), occlusion.occlusionInScreenSpace().ToString());
826 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14827
828 this->enterContributingSurface(child, occlusion);
829
[email protected]ac7c7f52012-11-08 06:26:50830 EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60)).ToString(), occlusion.occlusionInScreenSpace().ToString());
831 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14832
833 // Occlusion in |child2| should get merged with the |child| surface we are leaving now.
834 this->leaveContributingSurface(child, occlusion);
835 this->enterLayer(parent, occlusion);
836
[email protected]ac7c7f52012-11-08 06:26:50837 EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60)).ToString(), occlusion.occlusionInScreenSpace().ToString());
838 EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60)).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14839
[email protected]167ed9d52012-10-31 20:47:58840 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
841 EXPECT_RECT_EQ(gfx::Rect(90, 30, 10, 10), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 30, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14842
[email protected]167ed9d52012-10-31 20:47:58843 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 60, 10)));
844 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 60, 10)));
845 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 60, 10)));
846 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 60, 10)));
847 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 60, 10)));
[email protected]94f206c12012-08-25 00:09:14848
[email protected]167ed9d52012-10-31 20:47:58849 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
850 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
851 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14852
[email protected]167ed9d52012-10-31 20:47:58853 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 30, 60, 10)).IsEmpty());
854 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 10), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 30, 60, 10)));
855 EXPECT_RECT_EQ(gfx::Rect(30, 29, 60, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 29, 60, 10)));
856 EXPECT_RECT_EQ(gfx::Rect(90, 30, 1, 10), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 30, 60, 10)));
857 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 31, 60, 10)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:14858
[email protected]167ed9d52012-10-31 20:47:58859 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
860 EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 40, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14861 // This rect is mostly occluded by |child2|.
[email protected]167ed9d52012-10-31 20:47:58862 EXPECT_RECT_EQ(gfx::Rect(90, 39, 10, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14863 // This rect extends past top/right ends of |child2|.
[email protected]167ed9d52012-10-31 20:47:58864 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 11), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 29, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14865 // This rect extends past left/right ends of |child2|.
[email protected]167ed9d52012-10-31 20:47:58866 EXPECT_RECT_EQ(gfx::Rect(20, 39, 80, 60), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(20, 39, 80, 60)));
867 EXPECT_RECT_EQ(gfx::Rect(100, 40, 1, 60), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 40, 70, 60)));
868 EXPECT_RECT_EQ(gfx::Rect(30, 100, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 41, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14869
870 /* Justification for the above occlusion from |layer|:
871 100
872 +---------------------+ +---------------------+
873 | | | |30 Visible region of |layer|: /////
874 | 30 | rotate(90) | 30 60 | |child2|: \\\\\
875 | 30 + ------------+--------------------+ | 30 +------------+--------------------+
876 100 | | 10 | | | ==> | |\\\\\\\\\\\\| |10 |
877 | |10+----------|----------------------+ | +--|\\\\\\\\\\\\|-----------------+ |
878 | + ------------+ | | | | | +------------+//| 420 | |
879 | | | | | | | | |///////////////|60 | |
880 | | | | | | | | |///////////////| | |
881 +----|--|-------------+ | | +--|--|---------------+ | |
882 | | | | 20|10| 70 | |
883 | | | | | | | |
884 | | | |500 | | | |
885 | | | | | | | |
886 | | | | | | | |
887 | | | | | | | |
888 | | | | | | |10|
889 +--|-------------------------------+ | | +------------------------------|--+
890 | | | 490 |
891 +---------------------------------+ +---------------------------------+
892 500 500
893 */
894 }
895};
896
[email protected]96baf3e2012-10-22 23:09:55897ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:14898
[email protected]ece1d952012-10-18 21:26:07899template<class Types>
[email protected]96baf3e2012-10-22 23:09:55900class OcclusionTrackerTestSurfaceRotatedOffAxis : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14901protected:
[email protected]96baf3e2012-10-22 23:09:55902 OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14903 void runMyTest()
904 {
[email protected]c8686a02012-11-27 08:29:00905 gfx::Transform childTransform;
906 childTransform.Translate(250, 250);
907 childTransform.Rotate(95);
908 childTransform.Translate(-250, -250);
[email protected]94f206c12012-08-25 00:09:14909
[email protected]c8686a02012-11-27 08:29:00910 gfx::Transform layerTransform;
911 layerTransform.Translate(10, 10);
[email protected]94f206c12012-08-25 00:09:14912
[email protected]d0f98362012-11-01 23:02:38913 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
914 typename Types::LayerType* child = this->createLayer(parent, childTransform, gfx::PointF(30, 30), gfx::Size(500, 500));
[email protected]94f206c12012-08-25 00:09:14915 child->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38916 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, layerTransform, gfx::PointF(0, 0), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:14917 this->calcDrawEtc(parent);
918
[email protected]167ed9d52012-10-31 20:47:58919 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
920 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14921
[email protected]167ed9d52012-10-31 20:47:58922 gfx::Rect clippedLayerInChild = MathUtil::mapClippedRect(layerTransform, layer->visibleContentRect());
[email protected]94f206c12012-08-25 00:09:14923
924 this->visitLayer(layer, occlusion);
925 this->enterContributingSurface(child, occlusion);
926
[email protected]ac7c7f52012-11-08 06:26:50927 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInScreenSpace().ToString());
928 EXPECT_EQ(clippedLayerInChild.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14929
[email protected]710ffc02012-10-30 21:42:02930 EXPECT_TRUE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58931 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19932 clippedLayerInChild += gfx::Vector2d(-1, 0);
[email protected]710ffc02012-10-30 21:42:02933 EXPECT_FALSE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58934 EXPECT_FALSE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19935 clippedLayerInChild += gfx::Vector2d(1, 0);
936 clippedLayerInChild += gfx::Vector2d(1, 0);
[email protected]710ffc02012-10-30 21:42:02937 EXPECT_FALSE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58938 EXPECT_FALSE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19939 clippedLayerInChild += gfx::Vector2d(-1, 0);
940 clippedLayerInChild += gfx::Vector2d(0, -1);
[email protected]710ffc02012-10-30 21:42:02941 EXPECT_FALSE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58942 EXPECT_FALSE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19943 clippedLayerInChild += gfx::Vector2d(0, 1);
944 clippedLayerInChild += gfx::Vector2d(0, 1);
[email protected]710ffc02012-10-30 21:42:02945 EXPECT_FALSE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58946 EXPECT_FALSE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19947 clippedLayerInChild += gfx::Vector2d(0, -1);
[email protected]94f206c12012-08-25 00:09:14948
949 this->leaveContributingSurface(child, occlusion);
950 this->enterLayer(parent, occlusion);
951
[email protected]ac7c7f52012-11-08 06:26:50952 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInScreenSpace().ToString());
953 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14954
[email protected]167ed9d52012-10-31 20:47:58955 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(75, 55, 1, 1)));
956 EXPECT_RECT_EQ(gfx::Rect(75, 55, 1, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(75, 55, 1, 1)));
[email protected]94f206c12012-08-25 00:09:14957 }
958};
959
[email protected]96baf3e2012-10-22 23:09:55960ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[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 OcclusionTrackerTestSurfaceWithTwoOpaqueChildren : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14964protected:
[email protected]96baf3e2012-10-22 23:09:55965 OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14966 void runMyTest()
967 {
[email protected]c8686a02012-11-27 08:29:00968 gfx::Transform childTransform;
969 childTransform.Translate(250, 250);
970 childTransform.Rotate(90);
971 childTransform.Translate(-250, -250);
[email protected]94f206c12012-08-25 00:09:14972
[email protected]d0f98362012-11-01 23:02:38973 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:38974 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38975 typename Types::LayerType* child = this->createLayer(parent, childTransform, gfx::PointF(30, 30), gfx::Size(500, 500));
[email protected]94f206c12012-08-25 00:09:14976 child->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38977 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child, this->identityMatrix, gfx::PointF(10, 10), gfx::Size(500, 500), true);
978 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child, this->identityMatrix, gfx::PointF(10, 450), gfx::Size(500, 60), true);
[email protected]94f206c12012-08-25 00:09:14979 this->calcDrawEtc(parent);
980
[email protected]167ed9d52012-10-31 20:47:58981 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
982 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14983
984 this->visitLayer(layer2, occlusion);
985 this->visitLayer(layer1, occlusion);
986 this->enterContributingSurface(child, occlusion);
987
[email protected]ac7c7f52012-11-08 06:26:50988 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
989 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14990
[email protected]167ed9d52012-10-31 20:47:58991 EXPECT_TRUE(occlusion.occludedLayer(child, gfx::Rect(10, 430, 60, 70)));
992 EXPECT_FALSE(occlusion.occludedLayer(child, gfx::Rect(9, 430, 60, 70)));
993 EXPECT_FALSE(occlusion.occludedLayer(child, gfx::Rect(10, 429, 60, 70)));
994 EXPECT_FALSE(occlusion.occludedLayer(child, gfx::Rect(11, 430, 60, 70)));
995 EXPECT_FALSE(occlusion.occludedLayer(child, gfx::Rect(10, 431, 60, 70)));
[email protected]94f206c12012-08-25 00:09:14996
[email protected]167ed9d52012-10-31 20:47:58997 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(child, gfx::Rect(10, 430, 60, 70)).IsEmpty());
998 EXPECT_RECT_EQ(gfx::Rect(9, 430, 1, 70), occlusion.unoccludedLayerContentRect(child, gfx::Rect(9, 430, 60, 70)));
999 EXPECT_RECT_EQ(gfx::Rect(10, 429, 60, 1), occlusion.unoccludedLayerContentRect(child, gfx::Rect(10, 429, 60, 70)));
1000 EXPECT_RECT_EQ(gfx::Rect(70, 430, 1, 70), occlusion.unoccludedLayerContentRect(child, gfx::Rect(11, 430, 60, 70)));
1001 EXPECT_RECT_EQ(gfx::Rect(10, 500, 60, 1), occlusion.unoccludedLayerContentRect(child, gfx::Rect(10, 431, 60, 70)));
[email protected]94f206c12012-08-25 00:09:141002
1003 this->leaveContributingSurface(child, occlusion);
1004 this->enterLayer(parent, occlusion);
1005
[email protected]ac7c7f52012-11-08 06:26:501006 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
1007 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141008
[email protected]167ed9d52012-10-31 20:47:581009 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
1010 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
1011 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:141012
[email protected]167ed9d52012-10-31 20:47:581013 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
1014 EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 40, 70, 60)));
1015 EXPECT_RECT_EQ(gfx::Rect(30, 39, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 39, 70, 60)));
1016 EXPECT_RECT_EQ(gfx::Rect(100, 40, 1, 60), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 40, 70, 60)));
1017 EXPECT_RECT_EQ(gfx::Rect(30, 100, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 41, 70, 60)));
[email protected]94f206c12012-08-25 00:09:141018
1019 /* Justification for the above occlusion from |layer1| and |layer2|:
1020
1021 +---------------------+
1022 | |30 Visible region of |layer1|: /////
1023 | | Visible region of |layer2|: \\\\\
1024 | +---------------------------------+
1025 | | |10 |
1026 | +---------------+-----------------+ |
1027 | | |\\\\\\\\\\\\|//| 420 | |
1028 | | |\\\\\\\\\\\\|//|60 | |
1029 | | |\\\\\\\\\\\\|//| | |
1030 +--|--|------------|--+ | |
1031 20|10| 70 | | |
1032 | | | | |
1033 | | | | |
1034 | | | | |
1035 | | | | |
1036 | | | | |
1037 | | | |10|
1038 | +------------|-----------------|--+
1039 | | 490 |
1040 +---------------+-----------------+
1041 60 440
1042 */
1043 }
1044};
1045
[email protected]96baf3e2012-10-22 23:09:551046ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:141047
[email protected]ece1d952012-10-18 21:26:071048template<class Types>
[email protected]96baf3e2012-10-22 23:09:551049class OcclusionTrackerTestOverlappingSurfaceSiblings : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141050protected:
[email protected]96baf3e2012-10-22 23:09:551051 OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141052 void runMyTest()
1053 {
[email protected]c8686a02012-11-27 08:29:001054 gfx::Transform childTransform;
1055 childTransform.Translate(250, 250);
1056 childTransform.Rotate(90);
1057 childTransform.Translate(-250, -250);
[email protected]94f206c12012-08-25 00:09:141058
[email protected]d0f98362012-11-01 23:02:381059 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:381060 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:381061 typename Types::LayerType* child1 = this->createSurface(parent, childTransform, gfx::PointF(30, 30), gfx::Size(10, 10));
1062 typename Types::LayerType* child2 = this->createSurface(parent, childTransform, gfx::PointF(20, 40), gfx::Size(10, 10));
1063 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, gfx::PointF(-10, -10), gfx::Size(510, 510), true);
1064 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, gfx::PointF(-10, -10), gfx::Size(510, 510), true);
[email protected]94f206c12012-08-25 00:09:141065 this->calcDrawEtc(parent);
1066
[email protected]167ed9d52012-10-31 20:47:581067 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1068 occlusion.setLayerClipRect(gfx::Rect(-20, -20, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141069
1070 this->visitLayer(layer2, occlusion);
1071 this->enterContributingSurface(child2, occlusion);
1072
[email protected]ac7c7f52012-11-08 06:26:501073 EXPECT_EQ(gfx::Rect(20, 30, 80, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1074 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141075
[email protected]167ed9d52012-10-31 20:47:581076 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 80)));
1077 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-11, 420, 70, 80)));
1078 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 419, 70, 80)));
1079 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 71, 80)));
1080 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 81)));
[email protected]94f206c12012-08-25 00:09:141081
1082 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:581083 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 80)));
1084 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-11, 420, 70, 80)));
1085 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 419, 70, 80)));
1086 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 71, 80)));
1087 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 81)));
1088 occlusion.setLayerClipRect(gfx::Rect(-20, -20, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141089
1090 // There is nothing above child2's surface in the z-order.
[email protected]167ed9d52012-10-31 20:47:581091 EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80), occlusion.unoccludedContributingSurfaceContentRect(child2, false, gfx::Rect(-10, 420, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141092
1093 this->leaveContributingSurface(child2, occlusion);
1094 this->visitLayer(layer1, occlusion);
1095 this->enterContributingSurface(child1, occlusion);
1096
[email protected]ac7c7f52012-11-08 06:26:501097 EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70)).ToString(), occlusion.occlusionInScreenSpace().ToString());
1098 EXPECT_EQ(gfx::Rect(-10, 430, 80, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141099
[email protected]167ed9d52012-10-31 20:47:581100 EXPECT_TRUE(occlusion.occludedLayer(child1, gfx::Rect(-10, 430, 80, 70)));
1101 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(-11, 430, 80, 70)));
1102 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(-10, 429, 80, 70)));
1103 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(-10, 430, 81, 70)));
1104 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(-10, 430, 80, 71)));
[email protected]94f206c12012-08-25 00:09:141105
1106 // child2's contents will occlude child1 below it.
[email protected]167ed9d52012-10-31 20:47:581107 EXPECT_RECT_EQ(gfx::Rect(-10, 430, 10, 70), occlusion.unoccludedContributingSurfaceContentRect(child1, false, gfx::Rect(-10, 430, 80, 70)));
[email protected]94f206c12012-08-25 00:09:141108
1109 this->leaveContributingSurface(child1, occlusion);
1110 this->enterLayer(parent, occlusion);
1111
[email protected]ac7c7f52012-11-08 06:26:501112 EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70)).ToString(), occlusion.occlusionInScreenSpace().ToString());
1113 EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70)).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141114
[email protected]167ed9d52012-10-31 20:47:581115 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(20, 20, 80, 80)));
[email protected]94f206c12012-08-25 00:09:141116
[email protected]167ed9d52012-10-31 20:47:581117 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 20, 70, 80)));
1118 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 20, 70, 80)));
1119 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 19, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141120
[email protected]167ed9d52012-10-31 20:47:581121 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(20, 30, 80, 70)));
1122 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(19, 30, 80, 70)));
1123 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(20, 29, 80, 70)));
[email protected]94f206c12012-08-25 00:09:141124
1125 /* Justification for the above occlusion:
1126 100
1127 +---------------------+
1128 | 20 | layer1
1129 | 30+ ---------------------------------+
1130 100 | 30| | layer2 |
1131 |20+----------------------------------+ |
1132 | | | | | |
1133 | | | | | |
1134 | | | | | |
1135 +--|-|----------------+ | |
1136 | | | | 510
1137 | | | |
1138 | | | |
1139 | | | |
1140 | | | |
1141 | | | |
1142 | | | |
1143 | +--------------------------------|-+
1144 | |
1145 +----------------------------------+
1146 510
1147 */
1148 }
1149};
1150
[email protected]96baf3e2012-10-22 23:09:551151ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:141152
[email protected]ece1d952012-10-18 21:26:071153template<class Types>
[email protected]96baf3e2012-10-22 23:09:551154class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141155protected:
[email protected]96baf3e2012-10-22 23:09:551156 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141157 void runMyTest()
1158 {
[email protected]c8686a02012-11-27 08:29:001159 gfx::Transform child1Transform;
1160 child1Transform.Translate(250, 250);
1161 child1Transform.Rotate(-90);
1162 child1Transform.Translate(-250, -250);
[email protected]94f206c12012-08-25 00:09:141163
[email protected]c8686a02012-11-27 08:29:001164 gfx::Transform child2Transform;
1165 child2Transform.Translate(250, 250);
1166 child2Transform.Rotate(90);
1167 child2Transform.Translate(-250, -250);
[email protected]94f206c12012-08-25 00:09:141168
[email protected]d0f98362012-11-01 23:02:381169 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:381170 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:381171 typename Types::LayerType* child1 = this->createSurface(parent, child1Transform, gfx::PointF(30, 20), gfx::Size(10, 10));
1172 typename Types::LayerType* child2 = this->createDrawingSurface(parent, child2Transform, gfx::PointF(20, 40), gfx::Size(10, 10), false);
1173 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, gfx::PointF(-10, -20), gfx::Size(510, 510), true);
1174 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, gfx::PointF(-10, -10), gfx::Size(510, 510), true);
[email protected]94f206c12012-08-25 00:09:141175 this->calcDrawEtc(parent);
1176
[email protected]167ed9d52012-10-31 20:47:581177 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1178 occlusion.setLayerClipRect(gfx::Rect(-30, -30, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141179
1180 this->visitLayer(layer2, occlusion);
1181 this->enterLayer(child2, occlusion);
1182
[email protected]ac7c7f52012-11-08 06:26:501183 EXPECT_EQ(gfx::Rect(20, 30, 80, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1184 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141185
[email protected]167ed9d52012-10-31 20:47:581186 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 80)));
1187 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-11, 420, 70, 80)));
1188 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 419, 70, 80)));
1189 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 71, 80)));
1190 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 81)));
[email protected]94f206c12012-08-25 00:09:141191
1192 this->leaveLayer(child2, occlusion);
1193 this->enterContributingSurface(child2, occlusion);
1194
1195 // There is nothing above child2's surface in the z-order.
[email protected]167ed9d52012-10-31 20:47:581196 EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80), occlusion.unoccludedContributingSurfaceContentRect(child2, false, gfx::Rect(-10, 420, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141197
1198 this->leaveContributingSurface(child2, occlusion);
1199 this->visitLayer(layer1, occlusion);
1200 this->enterContributingSurface(child1, occlusion);
1201
[email protected]ac7c7f52012-11-08 06:26:501202 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), occlusion.occlusionInScreenSpace().ToString());
1203 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141204
[email protected]167ed9d52012-10-31 20:47:581205 EXPECT_TRUE(occlusion.occludedLayer(child1, gfx::Rect(420, -20, 80, 90)));
1206 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(419, -20, 80, 90)));
1207 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(420, -21, 80, 90)));
1208 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(420, -19, 80, 90)));
1209 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(421, -20, 80, 90)));
[email protected]94f206c12012-08-25 00:09:141210
1211 // child2's contents will occlude child1 below it.
[email protected]167ed9d52012-10-31 20:47:581212 EXPECT_RECT_EQ(gfx::Rect(420, -20, 80, 90), occlusion.unoccludedContributingSurfaceContentRect(child1, false, gfx::Rect(420, -20, 80, 90)));
1213 EXPECT_RECT_EQ(gfx::Rect(490, -10, 10, 80), occlusion.unoccludedContributingSurfaceContentRect(child1, false, gfx::Rect(420, -10, 80, 90)));
1214 EXPECT_RECT_EQ(gfx::Rect(420, -20, 70, 10), occlusion.unoccludedContributingSurfaceContentRect(child1, false, gfx::Rect(420, -20, 70, 90)));
[email protected]94f206c12012-08-25 00:09:141215
1216 this->leaveContributingSurface(child1, occlusion);
1217 this->enterLayer(parent, occlusion);
1218
[email protected]ac7c7f52012-11-08 06:26:501219 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), occlusion.occlusionInScreenSpace().ToString());
1220 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141221
[email protected]167ed9d52012-10-31 20:47:581222 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(10, 20, 90, 80)));
1223 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(9, 20, 90, 80)));
1224 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(10, 19, 90, 80)));
1225 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(11, 20, 90, 80)));
1226 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(10, 21, 90, 80)));
[email protected]94f206c12012-08-25 00:09:141227
1228 /* Justification for the above occlusion:
1229 100
1230 +---------------------+
1231 |20 | layer1
1232 10+----------------------------------+
1233 100 || 30 | layer2 |
1234 |20+----------------------------------+
1235 || | | | |
1236 || | | | |
1237 || | | | |
1238 +|-|------------------+ | |
1239 | | | | 510
1240 | | 510 | |
1241 | | | |
1242 | | | |
1243 | | | |
1244 | | | |
1245 | | 520 | |
1246 +----------------------------------+ |
1247 | |
1248 +----------------------------------+
1249 510
1250 */
1251 }
1252};
1253
[email protected]96baf3e2012-10-22 23:09:551254ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:141255
[email protected]ece1d952012-10-18 21:26:071256template<class Types>
[email protected]96baf3e2012-10-22 23:09:551257class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141258protected:
[email protected]96baf3e2012-10-22 23:09:551259 OcclusionTrackerTestFilters(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141260 void runMyTest()
1261 {
[email protected]c8686a02012-11-27 08:29:001262 gfx::Transform layerTransform;
1263 layerTransform.Translate(250, 250);
1264 layerTransform.Rotate(90);
1265 layerTransform.Translate(-250, -250);
[email protected]94f206c12012-08-25 00:09:141266
[email protected]d0f98362012-11-01 23:02:381267 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:381268 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:381269 typename Types::ContentLayerType* blurLayer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
1270 typename Types::ContentLayerType* opaqueLayer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
1271 typename Types::ContentLayerType* opacityLayer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:141272
1273 WebFilterOperations filters;
1274 filters.append(WebFilterOperation::createBlurFilter(10));
1275 blurLayer->setFilters(filters);
1276
1277 filters.clear();
1278 filters.append(WebFilterOperation::createGrayscaleFilter(0.5));
1279 opaqueLayer->setFilters(filters);
1280
1281 filters.clear();
1282 filters.append(WebFilterOperation::createOpacityFilter(0.5));
1283 opacityLayer->setFilters(filters);
1284
1285 this->calcDrawEtc(parent);
1286
[email protected]167ed9d52012-10-31 20:47:581287 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1288 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141289
1290 // Opacity layer won't contribute to occlusion.
1291 this->visitLayer(opacityLayer, occlusion);
1292 this->enterContributingSurface(opacityLayer, occlusion);
1293
[email protected]d0f98362012-11-01 23:02:381294 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1295 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141296
1297 // And has nothing to contribute to its parent surface.
1298 this->leaveContributingSurface(opacityLayer, occlusion);
[email protected]d0f98362012-11-01 23:02:381299 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1300 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141301
1302 // Opaque layer will contribute to occlusion.
1303 this->visitLayer(opaqueLayer, occlusion);
1304 this->enterContributingSurface(opaqueLayer, occlusion);
1305
[email protected]ac7c7f52012-11-08 06:26:501306 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1307 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141308
1309 // And it gets translated to the parent surface.
1310 this->leaveContributingSurface(opaqueLayer, occlusion);
[email protected]ac7c7f52012-11-08 06:26:501311 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1312 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141313
1314 // The blur layer needs to throw away any occlusion from outside its subtree.
1315 this->enterLayer(blurLayer, occlusion);
[email protected]d0f98362012-11-01 23:02:381316 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1317 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141318
1319 // And it won't contribute to occlusion.
1320 this->leaveLayer(blurLayer, occlusion);
1321 this->enterContributingSurface(blurLayer, occlusion);
[email protected]d0f98362012-11-01 23:02:381322 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1323 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141324
1325 // But the opaque layer's occlusion is preserved on the parent.
1326 this->leaveContributingSurface(blurLayer, occlusion);
1327 this->enterLayer(parent, occlusion);
[email protected]ac7c7f52012-11-08 06:26:501328 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1329 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141330 }
1331};
1332
[email protected]96baf3e2012-10-22 23:09:551333ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:141334
[email protected]ece1d952012-10-18 21:26:071335template<class Types>
[email protected]96baf3e2012-10-22 23:09:551336class OcclusionTrackerTestReplicaDoesOcclude : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141337protected:
[email protected]96baf3e2012-10-22 23:09:551338 OcclusionTrackerTestReplicaDoesOcclude(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141339 void runMyTest()
1340 {
[email protected]d0f98362012-11-01 23:02:381341 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
1342 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(50, 50), true);
1343 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(50, 50), gfx::Size());
[email protected]94f206c12012-08-25 00:09:141344 this->calcDrawEtc(parent);
1345
[email protected]167ed9d52012-10-31 20:47:581346 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1347 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141348
1349 this->visitLayer(surface, occlusion);
1350
[email protected]ac7c7f52012-11-08 06:26:501351 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
1352 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141353
1354 this->visitContributingSurface(surface, occlusion);
1355 this->enterLayer(parent, occlusion);
1356
1357 // The surface and replica should both be occluding the parent.
[email protected]ac7c7f52012-11-08 06:26:501358 EXPECT_EQ(UnionRegions(gfx::Rect(0, 100, 50, 50), gfx::Rect(50, 150, 50, 50)).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141359 }
1360};
1361
[email protected]96baf3e2012-10-22 23:09:551362ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude);
[email protected]94f206c12012-08-25 00:09:141363
[email protected]ece1d952012-10-18 21:26:071364template<class Types>
[email protected]96baf3e2012-10-22 23:09:551365class OcclusionTrackerTestReplicaWithClipping : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141366protected:
[email protected]96baf3e2012-10-22 23:09:551367 OcclusionTrackerTestReplicaWithClipping(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141368 void runMyTest()
1369 {
[email protected]d0f98362012-11-01 23:02:381370 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 170));
[email protected]23bbb412012-08-30 20:03:381371 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:381372 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(50, 50), true);
1373 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(50, 50), gfx::Size());
[email protected]94f206c12012-08-25 00:09:141374 this->calcDrawEtc(parent);
1375
[email protected]167ed9d52012-10-31 20:47:581376 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1377 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141378
1379 this->visitLayer(surface, occlusion);
1380
[email protected]ac7c7f52012-11-08 06:26:501381 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
1382 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141383
1384 this->visitContributingSurface(surface, occlusion);
1385 this->enterLayer(parent, occlusion);
1386
1387 // The surface and replica should both be occluding the parent.
[email protected]ac7c7f52012-11-08 06:26:501388 EXPECT_EQ(UnionRegions(gfx::Rect(0, 100, 50, 50), gfx::Rect(50, 150, 50, 20)).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141389 }
1390};
1391
[email protected]96baf3e2012-10-22 23:09:551392ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping);
[email protected]94f206c12012-08-25 00:09:141393
[email protected]ece1d952012-10-18 21:26:071394template<class Types>
[email protected]96baf3e2012-10-22 23:09:551395class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141396protected:
[email protected]96baf3e2012-10-22 23:09:551397 OcclusionTrackerTestReplicaWithMask(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141398 void runMyTest()
1399 {
[email protected]d0f98362012-11-01 23:02:381400 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
1401 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(50, 50), true);
1402 typename Types::LayerType* replica = this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(50, 50), gfx::Size());
[email protected]aad0a0072012-11-01 18:15:581403 this->createMaskLayer(replica, gfx::Size(10, 10));
[email protected]94f206c12012-08-25 00:09:141404 this->calcDrawEtc(parent);
1405
[email protected]167ed9d52012-10-31 20:47:581406 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1407 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141408
1409 this->visitLayer(surface, occlusion);
1410
[email protected]ac7c7f52012-11-08 06:26:501411 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
1412 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141413
1414 this->visitContributingSurface(surface, occlusion);
1415 this->enterLayer(parent, occlusion);
1416
1417 // The replica should not be occluding the parent, since it has a mask applied to it.
[email protected]ac7c7f52012-11-08 06:26:501418 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141419 }
1420};
1421
[email protected]96baf3e2012-10-22 23:09:551422ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask);
[email protected]94f206c12012-08-25 00:09:141423
[email protected]ece1d952012-10-18 21:26:071424template<class Types>
[email protected]96baf3e2012-10-22 23:09:551425class OcclusionTrackerTestLayerClipRectOutsideChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141426protected:
[email protected]96baf3e2012-10-22 23:09:551427 OcclusionTrackerTestLayerClipRectOutsideChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141428 void runMyTest()
1429 {
[email protected]d0f98362012-11-01 23:02:381430 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1431 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141432 this->calcDrawEtc(parent);
1433
[email protected]167ed9d52012-10-31 20:47:581434 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1435 occlusion.setLayerClipRect(gfx::Rect(200, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:141436
1437 this->enterLayer(layer, occlusion);
1438
[email protected]167ed9d52012-10-31 20:47:581439 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1440 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1441 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1442 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
1443 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141444
1445 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:581446 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
1447 occlusion.setLayerClipRect(gfx::Rect(200, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:141448
1449 this->leaveLayer(layer, occlusion);
1450 this->visitContributingSurface(layer, occlusion);
1451 this->enterLayer(parent, occlusion);
1452
[email protected]167ed9d52012-10-31 20:47:581453 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1454 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1455 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1456 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1457 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1458 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1459 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1460 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1461 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141462
[email protected]167ed9d52012-10-31 20:47:581463 EXPECT_RECT_EQ(gfx::Rect(200, 100, 100, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:141464 }
1465};
1466
[email protected]96baf3e2012-10-22 23:09:551467ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOutsideChild);
[email protected]94f206c12012-08-25 00:09:141468
[email protected]ece1d952012-10-18 21:26:071469template<class Types>
[email protected]96baf3e2012-10-22 23:09:551470class OcclusionTrackerTestViewportRectOutsideChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141471protected:
[email protected]96baf3e2012-10-22 23:09:551472 OcclusionTrackerTestViewportRectOutsideChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141473 void runMyTest()
1474 {
[email protected]d0f98362012-11-01 23:02:381475 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1476 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141477 this->calcDrawEtc(parent);
1478
[email protected]167ed9d52012-10-31 20:47:581479 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(200, 100, 100, 100));
1480 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141481
1482 this->enterLayer(layer, occlusion);
1483
[email protected]167ed9d52012-10-31 20:47:581484 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1485 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1486 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1487 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
1488 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141489
1490 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:581491 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
1492 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141493
1494 this->leaveLayer(layer, occlusion);
1495 this->visitContributingSurface(layer, occlusion);
1496 this->enterLayer(parent, occlusion);
1497
[email protected]167ed9d52012-10-31 20:47:581498 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1499 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1500 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1501 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1502 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1503 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1504 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1505 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1506 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141507
[email protected]167ed9d52012-10-31 20:47:581508 EXPECT_RECT_EQ(gfx::Rect(200, 100, 100, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:141509 }
1510};
1511
[email protected]96baf3e2012-10-22 23:09:551512ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOutsideChild);
[email protected]94f206c12012-08-25 00:09:141513
[email protected]ece1d952012-10-18 21:26:071514template<class Types>
[email protected]96baf3e2012-10-22 23:09:551515class OcclusionTrackerTestLayerClipRectOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141516protected:
[email protected]96baf3e2012-10-22 23:09:551517 OcclusionTrackerTestLayerClipRectOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141518 void runMyTest()
1519 {
[email protected]d0f98362012-11-01 23:02:381520 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1521 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141522 this->calcDrawEtc(parent);
1523
[email protected]167ed9d52012-10-31 20:47:581524 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1525 occlusion.setLayerClipRect(gfx::Rect(100, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:141526
1527 this->enterLayer(layer, occlusion);
1528
[email protected]167ed9d52012-10-31 20:47:581529 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1530 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1531 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1532 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141533
1534 this->leaveLayer(layer, occlusion);
1535 this->visitContributingSurface(layer, occlusion);
1536 this->enterLayer(parent, occlusion);
1537
[email protected]167ed9d52012-10-31 20:47:581538 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1539 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1540 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1541 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1542 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1543 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1544 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1545 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1546 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141547
[email protected]167ed9d52012-10-31 20:47:581548 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141549 }
1550};
1551
[email protected]96baf3e2012-10-22 23:09:551552ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOverChild);
[email protected]94f206c12012-08-25 00:09:141553
[email protected]ece1d952012-10-18 21:26:071554template<class Types>
[email protected]96baf3e2012-10-22 23:09:551555class OcclusionTrackerTestViewportRectOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141556protected:
[email protected]96baf3e2012-10-22 23:09:551557 OcclusionTrackerTestViewportRectOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141558 void runMyTest()
1559 {
[email protected]d0f98362012-11-01 23:02:381560 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1561 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141562 this->calcDrawEtc(parent);
1563
[email protected]167ed9d52012-10-31 20:47:581564 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(100, 100, 100, 100));
1565 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141566
1567 this->enterLayer(layer, occlusion);
1568
[email protected]167ed9d52012-10-31 20:47:581569 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1570 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1571 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1572 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141573
1574 this->leaveLayer(layer, occlusion);
1575 this->visitContributingSurface(layer, occlusion);
1576 this->enterLayer(parent, occlusion);
1577
[email protected]167ed9d52012-10-31 20:47:581578 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1579 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1580 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1581 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1582 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1583 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1584 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1585 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1586 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141587
[email protected]167ed9d52012-10-31 20:47:581588 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141589 }
1590};
1591
[email protected]96baf3e2012-10-22 23:09:551592ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverChild);
[email protected]94f206c12012-08-25 00:09:141593
[email protected]ece1d952012-10-18 21:26:071594template<class Types>
[email protected]96baf3e2012-10-22 23:09:551595class OcclusionTrackerTestLayerClipRectPartlyOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141596protected:
[email protected]96baf3e2012-10-22 23:09:551597 OcclusionTrackerTestLayerClipRectPartlyOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141598 void runMyTest()
1599 {
[email protected]d0f98362012-11-01 23:02:381600 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1601 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141602 this->calcDrawEtc(parent);
1603
[email protected]167ed9d52012-10-31 20:47:581604 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1605 occlusion.setLayerClipRect(gfx::Rect(50, 50, 200, 200));
[email protected]94f206c12012-08-25 00:09:141606
1607 this->enterLayer(layer, occlusion);
1608
[email protected]167ed9d52012-10-31 20:47:581609 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1610 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1611 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1612 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141613
1614 this->leaveLayer(layer, occlusion);
1615 this->visitContributingSurface(layer, occlusion);
1616 this->enterLayer(parent, occlusion);
1617
[email protected]167ed9d52012-10-31 20:47:581618 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1619 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1620 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1621 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1622 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1623 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1624 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1625 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1626 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141627
[email protected]167ed9d52012-10-31 20:47:581628 EXPECT_RECT_EQ(gfx::Rect(50, 50, 200, 200), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
1629 EXPECT_RECT_EQ(gfx::Rect(200, 50, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 100)));
1630 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 100, 300, 100)));
1631 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(200, 100, 100, 100)));
1632 EXPECT_RECT_EQ(gfx::Rect(100, 200, 100, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(100, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141633 }
1634};
1635
[email protected]96baf3e2012-10-22 23:09:551636ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectPartlyOverChild);
[email protected]94f206c12012-08-25 00:09:141637
[email protected]ece1d952012-10-18 21:26:071638template<class Types>
[email protected]96baf3e2012-10-22 23:09:551639class OcclusionTrackerTestViewportRectPartlyOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141640protected:
[email protected]96baf3e2012-10-22 23:09:551641 OcclusionTrackerTestViewportRectPartlyOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141642 void runMyTest()
1643 {
[email protected]d0f98362012-11-01 23:02:381644 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1645 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141646 this->calcDrawEtc(parent);
1647
[email protected]167ed9d52012-10-31 20:47:581648 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(50, 50, 200, 200));
1649 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141650
1651 this->enterLayer(layer, occlusion);
1652
[email protected]167ed9d52012-10-31 20:47:581653 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1654 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1655 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1656 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141657
1658 this->leaveLayer(layer, occlusion);
1659 this->visitContributingSurface(layer, occlusion);
1660 this->enterLayer(parent, occlusion);
1661
[email protected]167ed9d52012-10-31 20:47:581662 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1663 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1664 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1665 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1666 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1667 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1668 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1669 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1670 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141671
[email protected]167ed9d52012-10-31 20:47:581672 EXPECT_RECT_EQ(gfx::Rect(50, 50, 200, 200), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
1673 EXPECT_RECT_EQ(gfx::Rect(200, 50, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 100)));
1674 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 100, 300, 100)));
1675 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(200, 100, 100, 100)));
1676 EXPECT_RECT_EQ(gfx::Rect(100, 200, 100, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(100, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141677 }
1678};
1679
[email protected]96baf3e2012-10-22 23:09:551680ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectPartlyOverChild);
[email protected]94f206c12012-08-25 00:09:141681
[email protected]ece1d952012-10-18 21:26:071682template<class Types>
[email protected]96baf3e2012-10-22 23:09:551683class OcclusionTrackerTestLayerClipRectOverNothing : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141684protected:
[email protected]96baf3e2012-10-22 23:09:551685 OcclusionTrackerTestLayerClipRectOverNothing(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141686 void runMyTest()
1687 {
[email protected]d0f98362012-11-01 23:02:381688 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1689 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141690 this->calcDrawEtc(parent);
1691
[email protected]167ed9d52012-10-31 20:47:581692 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1693 occlusion.setLayerClipRect(gfx::Rect(500, 500, 100, 100));
[email protected]94f206c12012-08-25 00:09:141694
1695 this->enterLayer(layer, occlusion);
1696
[email protected]167ed9d52012-10-31 20:47:581697 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1698 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1699 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1700 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141701
1702 this->leaveLayer(layer, occlusion);
1703 this->visitContributingSurface(layer, occlusion);
1704 this->enterLayer(parent, occlusion);
1705
[email protected]167ed9d52012-10-31 20:47:581706 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1707 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1708 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1709 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1710 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1711 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1712 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1713 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1714 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141715
[email protected]167ed9d52012-10-31 20:47:581716 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
1717 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 100)).IsEmpty());
1718 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 100, 300, 100)).IsEmpty());
1719 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(200, 100, 100, 100)).IsEmpty());
1720 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(100, 200, 100, 100)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141721 }
1722};
1723
[email protected]96baf3e2012-10-22 23:09:551724ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOverNothing);
[email protected]94f206c12012-08-25 00:09:141725
[email protected]ece1d952012-10-18 21:26:071726template<class Types>
[email protected]96baf3e2012-10-22 23:09:551727class OcclusionTrackerTestViewportRectOverNothing : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141728protected:
[email protected]96baf3e2012-10-22 23:09:551729 OcclusionTrackerTestViewportRectOverNothing(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141730 void runMyTest()
1731 {
[email protected]d0f98362012-11-01 23:02:381732 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1733 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141734 this->calcDrawEtc(parent);
1735
[email protected]167ed9d52012-10-31 20:47:581736 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(500, 500, 100, 100));
1737 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141738
1739 this->enterLayer(layer, occlusion);
1740
[email protected]167ed9d52012-10-31 20:47:581741 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1742 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1743 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1744 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141745
1746 this->leaveLayer(layer, occlusion);
1747 this->visitContributingSurface(layer, occlusion);
1748 this->enterLayer(parent, occlusion);
1749
[email protected]167ed9d52012-10-31 20:47:581750 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1751 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1752 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1753 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1754 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1755 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1756 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1757 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1758 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141759
[email protected]167ed9d52012-10-31 20:47:581760 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
1761 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 100)).IsEmpty());
1762 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 100, 300, 100)).IsEmpty());
1763 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(200, 100, 100, 100)).IsEmpty());
1764 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(100, 200, 100, 100)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141765 }
1766};
1767
[email protected]96baf3e2012-10-22 23:09:551768ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverNothing);
[email protected]94f206c12012-08-25 00:09:141769
[email protected]ece1d952012-10-18 21:26:071770template<class Types>
[email protected]96baf3e2012-10-22 23:09:551771class OcclusionTrackerTestLayerClipRectForLayerOffOrigin : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141772protected:
[email protected]96baf3e2012-10-22 23:09:551773 OcclusionTrackerTestLayerClipRectForLayerOffOrigin(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141774 void runMyTest()
1775 {
[email protected]d0f98362012-11-01 23:02:381776 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1777 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141778 this->calcDrawEtc(parent);
1779
[email protected]167ed9d52012-10-31 20:47:581780 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141781 this->enterLayer(layer, occlusion);
1782
1783 // This layer is translated when drawn into its target. So if the clip rect given from the target surface
1784 // is not in that target space, then after translating these query rects into the target, they will fall outside
1785 // the clip and be considered occluded.
[email protected]167ed9d52012-10-31 20:47:581786 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1787 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1788 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1789 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141790 }
1791};
1792
[email protected]96baf3e2012-10-22 23:09:551793ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectForLayerOffOrigin);
[email protected]94f206c12012-08-25 00:09:141794
[email protected]ece1d952012-10-18 21:26:071795template<class Types>
[email protected]96baf3e2012-10-22 23:09:551796class OcclusionTrackerTestOpaqueContentsRegionEmpty : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141797protected:
[email protected]96baf3e2012-10-22 23:09:551798 OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141799 void runMyTest()
1800 {
[email protected]d0f98362012-11-01 23:02:381801 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1802 typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200), false);
[email protected]94f206c12012-08-25 00:09:141803 this->calcDrawEtc(parent);
1804
[email protected]167ed9d52012-10-31 20:47:581805 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141806 this->enterLayer(layer, occlusion);
1807
[email protected]167ed9d52012-10-31 20:47:581808 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1809 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1810 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1811 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141812
1813 // Occluded since its outside the surface bounds.
[email protected]167ed9d52012-10-31 20:47:581814 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141815
1816 // Test without any clip rect.
[email protected]167ed9d52012-10-31 20:47:581817 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
1818 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141819 occlusion.useDefaultLayerClipRect();
1820
1821 this->leaveLayer(layer, occlusion);
1822 this->visitContributingSurface(layer, occlusion);
1823 this->enterLayer(parent, occlusion);
1824
[email protected]ac7c7f52012-11-08 06:26:501825 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141826 }
1827};
1828
[email protected]96baf3e2012-10-22 23:09:551829MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141830
[email protected]ece1d952012-10-18 21:26:071831template<class Types>
[email protected]96baf3e2012-10-22 23:09:551832class OcclusionTrackerTestOpaqueContentsRegionNonEmpty : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141833protected:
[email protected]96baf3e2012-10-22 23:09:551834 OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141835 void runMyTest()
1836 {
[email protected]d0f98362012-11-01 23:02:381837 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1838 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(100, 100), gfx::Size(200, 200), false);
[email protected]94f206c12012-08-25 00:09:141839 this->calcDrawEtc(parent);
1840
1841 {
[email protected]167ed9d52012-10-31 20:47:581842 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]aad0a0072012-11-01 18:15:581843 layer->setOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:141844
1845 this->resetLayerIterator();
1846 this->visitLayer(layer, occlusion);
1847 this->enterLayer(parent, occlusion);
1848
[email protected]ac7c7f52012-11-08 06:26:501849 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:141850
[email protected]167ed9d52012-10-31 20:47:581851 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1852 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1853 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141854 }
1855
1856 {
[email protected]167ed9d52012-10-31 20:47:581857 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]aad0a0072012-11-01 18:15:581858 layer->setOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
[email protected]94f206c12012-08-25 00:09:141859
1860 this->resetLayerIterator();
1861 this->visitLayer(layer, occlusion);
1862 this->enterLayer(parent, occlusion);
1863
[email protected]ac7c7f52012-11-08 06:26:501864 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:141865
[email protected]167ed9d52012-10-31 20:47:581866 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1867 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1868 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141869 }
1870
1871 {
[email protected]167ed9d52012-10-31 20:47:581872 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]aad0a0072012-11-01 18:15:581873 layer->setOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
[email protected]94f206c12012-08-25 00:09:141874
1875 this->resetLayerIterator();
1876 this->visitLayer(layer, occlusion);
1877 this->enterLayer(parent, occlusion);
1878
[email protected]ac7c7f52012-11-08 06:26:501879 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:141880
[email protected]167ed9d52012-10-31 20:47:581881 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1882 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1883 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141884 }
1885 }
1886};
1887
[email protected]96baf3e2012-10-22 23:09:551888MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141889
[email protected]ece1d952012-10-18 21:26:071890template<class Types>
[email protected]96baf3e2012-10-22 23:09:551891class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141892protected:
[email protected]96baf3e2012-10-22 23:09:551893 OcclusionTrackerTest3dTransform(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141894 void runMyTest()
1895 {
[email protected]c8686a02012-11-27 08:29:001896 gfx::Transform transform;
1897 MathUtil::rotateEulerAngles(&transform, 0, 30, 0);
[email protected]94f206c12012-08-25 00:09:141898
[email protected]d0f98362012-11-01 23:02:381899 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1900 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1901 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, gfx::PointF(100, 100), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141902 this->calcDrawEtc(parent);
1903
[email protected]167ed9d52012-10-31 20:47:581904 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141905 this->enterLayer(layer, occlusion);
1906
1907 // The layer is rotated in 3d but without preserving 3d, so it only gets resized.
[email protected]167ed9d52012-10-31 20:47:581908 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), occlusion.unoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
[email protected]94f206c12012-08-25 00:09:141909 }
1910};
1911
[email protected]96baf3e2012-10-22 23:09:551912MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform);
[email protected]94f206c12012-08-25 00:09:141913
[email protected]ece1d952012-10-18 21:26:071914template<class Types>
[email protected]96baf3e2012-10-22 23:09:551915class OcclusionTrackerTestUnsorted3dLayers : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141916protected:
[email protected]96baf3e2012-10-22 23:09:551917 OcclusionTrackerTestUnsorted3dLayers(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141918 void runMyTest()
1919 {
1920 // Currently, the main thread layer iterator does not iterate over 3d items in
1921 // sorted order, because layer sorting is not performed on the main thread.
1922 // Because of this, the occlusion tracker cannot assume that a 3d layer occludes
1923 // other layers that have not yet been iterated over. For now, the expected
1924 // behavior is that a 3d layer simply does not add any occlusion to the occlusion
1925 // tracker.
1926
[email protected]c8686a02012-11-27 08:29:001927 gfx::Transform translationToFront;
1928 translationToFront.Translate3d(0, 0, -10);
1929 gfx::Transform translationToBack;
1930 translationToFront.Translate3d(0, 0, -100);
[email protected]94f206c12012-08-25 00:09:141931
[email protected]d0f98362012-11-01 23:02:381932 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1933 typename Types::ContentLayerType* child1 = this->createDrawingLayer(parent, translationToBack, gfx::PointF(0, 0), gfx::Size(100, 100), true);
1934 typename Types::ContentLayerType* child2 = this->createDrawingLayer(parent, translationToFront, gfx::PointF(50, 50), gfx::Size(100, 100), true);
[email protected]94f206c12012-08-25 00:09:141935 parent->setPreserves3D(true);
1936
1937 this->calcDrawEtc(parent);
1938
[email protected]167ed9d52012-10-31 20:47:581939 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141940 this->visitLayer(child2, occlusion);
[email protected]d0f98362012-11-01 23:02:381941 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1942 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141943
1944 this->visitLayer(child1, occlusion);
[email protected]d0f98362012-11-01 23:02:381945 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1946 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141947 }
1948};
1949
1950// 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:551951MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
[email protected]94f206c12012-08-25 00:09:141952
[email protected]ece1d952012-10-18 21:26:071953template<class Types>
[email protected]96baf3e2012-10-22 23:09:551954class OcclusionTrackerTestPerspectiveTransform : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141955protected:
[email protected]96baf3e2012-10-22 23:09:551956 OcclusionTrackerTestPerspectiveTransform(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141957 void runMyTest()
1958 {
[email protected]c8686a02012-11-27 08:29:001959 gfx::Transform transform;
1960 transform.Translate(150, 150);
1961 transform.ApplyPerspectiveDepth(400);
[email protected]2c7cd6d2012-11-28 23:49:261962 transform.RotateAboutXAxis(-30);
[email protected]c8686a02012-11-27 08:29:001963 transform.Translate(-150, -150);
[email protected]94f206c12012-08-25 00:09:141964
[email protected]d0f98362012-11-01 23:02:381965 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1966 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1967 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, gfx::PointF(100, 100), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141968 container->setPreserves3D(true);
1969 layer->setPreserves3D(true);
1970 this->calcDrawEtc(parent);
1971
[email protected]167ed9d52012-10-31 20:47:581972 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141973 this->enterLayer(layer, occlusion);
1974
[email protected]167ed9d52012-10-31 20:47:581975 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), occlusion.unoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
[email protected]94f206c12012-08-25 00:09:141976 }
1977};
1978
1979// 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:551980IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransform);
[email protected]94f206c12012-08-25 00:09:141981
[email protected]ece1d952012-10-18 21:26:071982template<class Types>
[email protected]96baf3e2012-10-22 23:09:551983class OcclusionTrackerTestPerspectiveTransformBehindCamera : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141984protected:
[email protected]96baf3e2012-10-22 23:09:551985 OcclusionTrackerTestPerspectiveTransformBehindCamera(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141986 void runMyTest()
1987 {
1988 // This test is based on the platform/chromium/compositing/3d-corners.html layout test.
[email protected]c8686a02012-11-27 08:29:001989 gfx::Transform transform;
1990 transform.Translate(250, 50);
1991 transform.ApplyPerspectiveDepth(10);
1992 transform.Translate(-250, -50);
1993 transform.Translate(250, 50);
[email protected]2c7cd6d2012-11-28 23:49:261994 transform.RotateAboutXAxis(-167);
[email protected]c8686a02012-11-27 08:29:001995 transform.Translate(-250, -50);
[email protected]94f206c12012-08-25 00:09:141996
[email protected]d0f98362012-11-01 23:02:381997 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(500, 100));
1998 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(500, 500));
1999 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, gfx::PointF(0, 0), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:142000 container->setPreserves3D(true);
2001 layer->setPreserves3D(true);
2002 this->calcDrawEtc(parent);
2003
[email protected]167ed9d52012-10-31 20:47:582004 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142005 this->enterLayer(layer, occlusion);
2006
2007 // The bottom 11 pixel rows of this layer remain visible inside the container, after translation to the target surface. When translated back,
2008 // this will include many more pixels but must include at least the bottom 11 rows.
[email protected]167ed9d52012-10-31 20:47:582009 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(layer, gfx::Rect(0, 0, 500, 500)).Contains(gfx::Rect(0, 489, 500, 11)));
[email protected]94f206c12012-08-25 00:09:142010 }
2011};
2012
2013// 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:552014IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransformBehindCamera);
[email protected]94f206c12012-08-25 00:09:142015
[email protected]ece1d952012-10-18 21:26:072016template<class Types>
[email protected]96baf3e2012-10-22 23:09:552017class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142018protected:
[email protected]96baf3e2012-10-22 23:09:552019 OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142020 void runMyTest()
2021 {
[email protected]c8686a02012-11-27 08:29:002022 gfx::Transform transform;
2023 transform.Translate(50, 50);
2024 transform.ApplyPerspectiveDepth(100);
2025 transform.Translate3d(0, 0, 110);
2026 transform.Translate(-50, -50);
[email protected]94f206c12012-08-25 00:09:142027
[email protected]d0f98362012-11-01 23:02:382028 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
2029 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, transform, gfx::PointF(0, 0), gfx::Size(100, 100), true);
[email protected]94f206c12012-08-25 00:09:142030 parent->setPreserves3D(true);
2031 layer->setPreserves3D(true);
2032 this->calcDrawEtc(parent);
2033
[email protected]167ed9d52012-10-31 20:47:582034 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142035
2036 // The |layer| is entirely behind the camera and should not occlude.
2037 this->visitLayer(layer, occlusion);
2038 this->enterLayer(parent, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502039 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
2040 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142041 }
2042};
2043
2044// 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:552045IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude);
[email protected]94f206c12012-08-25 00:09:142046
[email protected]ece1d952012-10-18 21:26:072047template<class Types>
[email protected]96baf3e2012-10-22 23:09:552048class OcclusionTrackerTestLargePixelsOccludeInsideClipRect : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142049protected:
[email protected]96baf3e2012-10-22 23:09:552050 OcclusionTrackerTestLargePixelsOccludeInsideClipRect(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142051 void runMyTest()
2052 {
[email protected]c8686a02012-11-27 08:29:002053 gfx::Transform transform;
2054 transform.Translate(50, 50);
2055 transform.ApplyPerspectiveDepth(100);
2056 transform.Translate3d(0, 0, 99);
2057 transform.Translate(-50, -50);
[email protected]94f206c12012-08-25 00:09:142058
[email protected]d0f98362012-11-01 23:02:382059 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:382060 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382061 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, transform, gfx::PointF(0, 0), gfx::Size(100, 100), true);
[email protected]94f206c12012-08-25 00:09:142062 parent->setPreserves3D(true);
2063 layer->setPreserves3D(true);
2064 this->calcDrawEtc(parent);
2065
[email protected]167ed9d52012-10-31 20:47:582066 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142067
2068 // This is very close to the camera, so pixels in its visibleContentRect will actually go outside of the layer's clipRect.
2069 // Ensure that those pixels don't occlude things outside the clipRect.
2070 this->visitLayer(layer, occlusion);
2071 this->enterLayer(parent, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502072 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
2073 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:142074 }
2075};
2076
2077// 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:552078IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect);
[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 OcclusionTrackerTestAnimationOpacity1OnMainThread : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142082protected:
[email protected]96baf3e2012-10-22 23:09:552083 OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142084 void runMyTest()
2085 {
[email protected]d0f98362012-11-01 23:02:382086 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
2087 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2088 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2089 typename Types::ContentLayerType* surfaceChild = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 300), true);
2090 typename Types::ContentLayerType* surfaceChild2 = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 300), true);
2091 typename Types::ContentLayerType* parent2 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2092 typename Types::ContentLayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(250, 0), gfx::Size(50, 300), true);
[email protected]94f206c12012-08-25 00:09:142093
2094 addOpacityTransitionToController(*layer->layerAnimationController(), 10, 0, 1, false);
2095 addOpacityTransitionToController(*surface->layerAnimationController(), 10, 0, 1, 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]167ed9d52012-10-31 20:47:582102 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(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]167ed9d52012-10-31 20:47:582107 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), occlusion.unoccludedLayerContentRect(parent2, gfx::Rect(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]167ed9d52012-10-31 20:47:582112 EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300), occlusion.unoccludedLayerContentRect(surfaceChild, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142113 this->leaveLayer(surfaceChild, occlusion);
2114 this->enterLayer(surface, occlusion);
[email protected]167ed9d52012-10-31 20:47:582115 EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300), occlusion.unoccludedLayerContentRect(surface, gfx::Rect(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]167ed9d52012-10-31 20:47:582120 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(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]167ed9d52012-10-31 20:47:582127 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142128 }
2129};
2130
[email protected]96baf3e2012-10-22 23:09:552131MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread);
[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 OcclusionTrackerTestAnimationOpacity0OnMainThread : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142135protected:
[email protected]96baf3e2012-10-22 23:09:552136 OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142137 void runMyTest()
2138 {
[email protected]d0f98362012-11-01 23:02:382139 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
2140 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2141 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2142 typename Types::ContentLayerType* surfaceChild = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 300), true);
2143 typename Types::ContentLayerType* surfaceChild2 = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 300), true);
2144 typename Types::ContentLayerType* parent2 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2145 typename Types::ContentLayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(250, 0), gfx::Size(50, 300), true);
[email protected]94f206c12012-08-25 00:09:142146
2147 addOpacityTransitionToController(*layer->layerAnimationController(), 10, 1, 0, false);
2148 addOpacityTransitionToController(*surface->layerAnimationController(), 10, 1, 0, false);
2149 this->calcDrawEtc(parent);
2150
2151 EXPECT_TRUE(layer->drawOpacityIsAnimating());
2152 EXPECT_FALSE(surface->drawOpacityIsAnimating());
2153 EXPECT_TRUE(surface->renderSurface()->drawOpacityIsAnimating());
2154
[email protected]167ed9d52012-10-31 20:47:582155 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142156
2157 this->visitLayer(topmost, occlusion);
2158 this->enterLayer(parent2, occlusion);
2159 // This occlusion will affect all surfaces.
[email protected]167ed9d52012-10-31 20:47:582160 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142161 this->leaveLayer(parent2, occlusion);
2162
2163 this->visitLayer(surfaceChild2, occlusion);
2164 this->enterLayer(surfaceChild, occlusion);
[email protected]167ed9d52012-10-31 20:47:582165 EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300), occlusion.unoccludedLayerContentRect(surfaceChild, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142166 this->leaveLayer(surfaceChild, occlusion);
2167 this->enterLayer(surface, occlusion);
[email protected]167ed9d52012-10-31 20:47:582168 EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300), occlusion.unoccludedLayerContentRect(surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142169 this->leaveLayer(surface, occlusion);
2170
2171 this->enterContributingSurface(surface, occlusion);
2172 // Occlusion within the surface is lost when leaving the animating surface.
[email protected]167ed9d52012-10-31 20:47:582173 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142174 this->leaveContributingSurface(surface, occlusion);
2175
2176 this->visitLayer(layer, occlusion);
2177 this->enterLayer(parent, occlusion);
2178
2179 // Occlusion is not added for the animating |layer|.
[email protected]167ed9d52012-10-31 20:47:582180 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142181 }
2182};
2183
[email protected]96baf3e2012-10-22 23:09:552184MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread);
[email protected]94f206c12012-08-25 00:09:142185
[email protected]ece1d952012-10-18 21:26:072186template<class Types>
[email protected]96baf3e2012-10-22 23:09:552187class OcclusionTrackerTestAnimationTranslateOnMainThread : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142188protected:
[email protected]96baf3e2012-10-22 23:09:552189 OcclusionTrackerTestAnimationTranslateOnMainThread(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142190 void runMyTest()
2191 {
[email protected]d0f98362012-11-01 23:02:382192 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
2193 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2194 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2195 typename Types::ContentLayerType* surfaceChild = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 300), true);
2196 typename Types::ContentLayerType* surfaceChild2 = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 300), true);
2197 typename Types::ContentLayerType* surface2 = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(50, 300), true);
[email protected]94f206c12012-08-25 00:09:142198
2199 addAnimatedTransformToController(*layer->layerAnimationController(), 10, 30, 0);
2200 addAnimatedTransformToController(*surface->layerAnimationController(), 10, 30, 0);
2201 addAnimatedTransformToController(*surfaceChild->layerAnimationController(), 10, 30, 0);
2202 this->calcDrawEtc(parent);
2203
2204 EXPECT_TRUE(layer->drawTransformIsAnimating());
2205 EXPECT_TRUE(layer->screenSpaceTransformIsAnimating());
2206 EXPECT_TRUE(surface->renderSurface()->targetSurfaceTransformsAreAnimating());
2207 EXPECT_TRUE(surface->renderSurface()->screenSpaceTransformsAreAnimating());
2208 // The surface owning layer doesn't animate against its own surface.
2209 EXPECT_FALSE(surface->drawTransformIsAnimating());
2210 EXPECT_TRUE(surface->screenSpaceTransformIsAnimating());
2211 EXPECT_TRUE(surfaceChild->drawTransformIsAnimating());
2212 EXPECT_TRUE(surfaceChild->screenSpaceTransformIsAnimating());
2213
[email protected]167ed9d52012-10-31 20:47:582214 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142215
2216 this->visitLayer(surface2, occlusion);
2217 this->enterContributingSurface(surface2, occlusion);
2218
[email protected]ac7c7f52012-11-08 06:26:502219 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:142220
2221 this->leaveContributingSurface(surface2, occlusion);
2222 this->enterLayer(surfaceChild2, occlusion);
2223
2224 // surfaceChild2 is moving in screen space but not relative to its target, so occlusion should happen in its target space only.
2225 // It also means that things occluding in screen space (e.g. surface2) cannot occlude this layer.
[email protected]167ed9d52012-10-31 20:47:582226 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 300), occlusion.unoccludedLayerContentRect(surfaceChild2, gfx::Rect(0, 0, 100, 300)));
2227 EXPECT_FALSE(occlusion.occludedLayer(surfaceChild, gfx::Rect(0, 0, 50, 300)));
[email protected]94f206c12012-08-25 00:09:142228
2229 this->leaveLayer(surfaceChild2, occlusion);
2230 this->enterLayer(surfaceChild, occlusion);
[email protected]167ed9d52012-10-31 20:47:582231 EXPECT_FALSE(occlusion.occludedLayer(surfaceChild, gfx::Rect(0, 0, 100, 300)));
[email protected]ac7c7f52012-11-08 06:26:502232 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), occlusion.occlusionInScreenSpace().ToString());
2233 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]167ed9d52012-10-31 20:47:582234 EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300), occlusion.unoccludedLayerContentRect(surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142235
2236 // The surfaceChild is occluded by the surfaceChild2, but is moving relative its target and the screen, so it
2237 // can't be occluded.
[email protected]167ed9d52012-10-31 20:47:582238 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 300), occlusion.unoccludedLayerContentRect(surfaceChild, gfx::Rect(0, 0, 200, 300)));
2239 EXPECT_FALSE(occlusion.occludedLayer(surfaceChild, gfx::Rect(0, 0, 50, 300)));
[email protected]94f206c12012-08-25 00:09:142240
2241 this->leaveLayer(surfaceChild, occlusion);
2242 this->enterLayer(surface, occlusion);
2243 // The surfaceChild is moving in screen space but not relative to its target, so occlusion should happen in its target space only.
[email protected]ac7c7f52012-11-08 06:26:502244 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), occlusion.occlusionInScreenSpace().ToString());
2245 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]167ed9d52012-10-31 20:47:582246 EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300), occlusion.unoccludedLayerContentRect(surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142247
2248 this->leaveLayer(surface, occlusion);
2249 // 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]ac7c7f52012-11-08 06:26:502250 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), occlusion.occlusionInScreenSpace().ToString());
2251 EXPECT_EQ(gfx::Rect(0, 0, 300, 300).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]167ed9d52012-10-31 20:47:582252 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), occlusion.unoccludedLayerContentRect(surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142253
2254 this->enterContributingSurface(surface, occlusion);
2255 // The contributing |surface| is animating so it can't be occluded.
[email protected]167ed9d52012-10-31 20:47:582256 EXPECT_RECT_EQ(gfx::Rect(0, 0, 300, 300), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142257 this->leaveContributingSurface(surface, occlusion);
2258
2259 this->enterLayer(layer, occlusion);
2260 // The |surface| is moving in the screen and in its target, so all occlusion within the surface is lost when leaving it.
[email protected]167ed9d52012-10-31 20:47:582261 EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142262 this->leaveLayer(layer, occlusion);
2263
2264 this->enterLayer(parent, occlusion);
2265 // The |layer| is animating in the screen and in its target, so no occlusion is added.
[email protected]167ed9d52012-10-31 20:47:582266 EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142267 }
2268};
2269
[email protected]96baf3e2012-10-22 23:09:552270MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread);
[email protected]94f206c12012-08-25 00:09:142271
[email protected]ece1d952012-10-18 21:26:072272template<class Types>
[email protected]96baf3e2012-10-22 23:09:552273class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142274protected:
[email protected]96baf3e2012-10-22 23:09:552275 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142276 void runMyTest()
2277 {
[email protected]c8686a02012-11-27 08:29:002278 gfx::Transform surfaceTransform;
2279 surfaceTransform.Translate(300, 300);
2280 surfaceTransform.Scale(2, 2);
2281 surfaceTransform.Translate(-150, -150);
[email protected]94f206c12012-08-25 00:09:142282
[email protected]d0f98362012-11-01 23:02:382283 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(500, 500));
2284 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, surfaceTransform, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2285 typename Types::ContentLayerType* surface2 = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(50, 50), gfx::Size(300, 300), false);
[email protected]aad0a0072012-11-01 18:15:582286 surface->setOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
2287 surface2->setOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
[email protected]94f206c12012-08-25 00:09:142288 this->calcDrawEtc(parent);
2289
[email protected]167ed9d52012-10-31 20:47:582290 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142291
2292 this->visitLayer(surface2, occlusion);
2293 this->visitContributingSurface(surface2, occlusion);
2294
[email protected]ac7c7f52012-11-08 06:26:502295 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(), occlusion.occlusionInScreenSpace().ToString());
2296 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142297
2298 // Clear any stored occlusion.
2299 occlusion.setOcclusionInScreenSpace(Region());
2300 occlusion.setOcclusionInTargetSurface(Region());
2301
2302 this->visitLayer(surface, occlusion);
2303 this->visitContributingSurface(surface, occlusion);
2304
[email protected]ac7c7f52012-11-08 06:26:502305 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(), occlusion.occlusionInScreenSpace().ToString());
2306 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142307 }
2308};
2309
[email protected]96baf3e2012-10-22 23:09:552310MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:142311
[email protected]ece1d952012-10-18 21:26:072312template<class Types>
[email protected]96baf3e2012-10-22 23:09:552313class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142314protected:
[email protected]96baf3e2012-10-22 23:09:552315 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142316 void runMyTest()
2317 {
[email protected]d0f98362012-11-01 23:02:382318 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
[email protected]23bbb412012-08-30 20:03:382319 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382320 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(500, 300), false);
[email protected]aad0a0072012-11-01 18:15:582321 surface->setOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
[email protected]94f206c12012-08-25 00:09:142322 this->calcDrawEtc(parent);
2323
[email protected]167ed9d52012-10-31 20:47:582324 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142325
2326 this->visitLayer(surface, occlusion);
2327 this->visitContributingSurface(surface, occlusion);
2328
[email protected]ac7c7f52012-11-08 06:26:502329 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(), occlusion.occlusionInScreenSpace().ToString());
2330 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142331 }
2332};
2333
[email protected]96baf3e2012-10-22 23:09:552334MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:142335
[email protected]ece1d952012-10-18 21:26:072336template<class Types>
[email protected]96baf3e2012-10-22 23:09:552337class OcclusionTrackerTestReplicaOccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142338protected:
[email protected]96baf3e2012-10-22 23:09:552339 OcclusionTrackerTestReplicaOccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142340 void runMyTest()
2341 {
[email protected]d0f98362012-11-01 23:02:382342 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2343 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2344 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(100, 100));
2345 typename Types::LayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(100, 100), true);
[email protected]94f206c12012-08-25 00:09:142346 this->calcDrawEtc(parent);
2347
[email protected]167ed9d52012-10-31 20:47:582348 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2349 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142350
2351 // |topmost| occludes the replica, but not the surface itself.
2352 this->visitLayer(topmost, occlusion);
2353
[email protected]ac7c7f52012-11-08 06:26:502354 EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(), occlusion.occlusionInScreenSpace().ToString());
2355 EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142356
2357 this->visitLayer(surface, occlusion);
2358
[email protected]ac7c7f52012-11-08 06:26:502359 EXPECT_EQ(gfx::Rect(0, 0, 100, 200).ToString(), occlusion.occlusionInScreenSpace().ToString());
2360 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142361
2362 this->enterContributingSurface(surface, occlusion);
2363
2364 // Surface is not occluded so it shouldn't think it is.
[email protected]167ed9d52012-10-31 20:47:582365 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142366 }
2367};
2368
[email protected]96baf3e2012-10-22 23:09:552369ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaOccluded);
[email protected]94f206c12012-08-25 00:09:142370
[email protected]ece1d952012-10-18 21:26:072371template<class Types>
[email protected]96baf3e2012-10-22 23:09:552372class OcclusionTrackerTestSurfaceWithReplicaUnoccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142373protected:
[email protected]96baf3e2012-10-22 23:09:552374 OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142375 void runMyTest()
2376 {
[email protected]d0f98362012-11-01 23:02:382377 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2378 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2379 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(100, 100));
2380 typename Types::LayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 110), true);
[email protected]94f206c12012-08-25 00:09:142381 this->calcDrawEtc(parent);
2382
[email protected]167ed9d52012-10-31 20:47:582383 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2384 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142385
2386 // |topmost| occludes the surface, but not the entire surface's replica.
2387 this->visitLayer(topmost, occlusion);
2388
[email protected]ac7c7f52012-11-08 06:26:502389 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(), occlusion.occlusionInScreenSpace().ToString());
2390 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142391
2392 this->visitLayer(surface, occlusion);
2393
[email protected]ac7c7f52012-11-08 06:26:502394 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(), occlusion.occlusionInScreenSpace().ToString());
2395 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142396
2397 this->enterContributingSurface(surface, occlusion);
2398
2399 // Surface is occluded, but only the top 10px of the replica.
[email protected]167ed9d52012-10-31 20:47:582400 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 100, 100)));
2401 EXPECT_RECT_EQ(gfx::Rect(0, 10, 100, 90), occlusion.unoccludedContributingSurfaceContentRect(surface, true, gfx::Rect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142402 }
2403};
2404
[email protected]96baf3e2012-10-22 23:09:552405ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded);
[email protected]94f206c12012-08-25 00:09:142406
[email protected]ece1d952012-10-18 21:26:072407template<class Types>
[email protected]96baf3e2012-10-22 23:09:552408class OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142409protected:
[email protected]96baf3e2012-10-22 23:09:552410 OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142411 void runMyTest()
2412 {
[email protected]d0f98362012-11-01 23:02:382413 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2414 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2415 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(100, 100));
2416 typename Types::LayerType* overSurface = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(40, 100), true);
2417 typename Types::LayerType* overReplica = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(50, 100), true);
[email protected]94f206c12012-08-25 00:09:142418 this->calcDrawEtc(parent);
2419
[email protected]167ed9d52012-10-31 20:47:582420 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2421 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142422
2423 // These occlude the surface and replica differently, so we can test each one.
2424 this->visitLayer(overReplica, occlusion);
2425 this->visitLayer(overSurface, occlusion);
2426
[email protected]ac7c7f52012-11-08 06:26:502427 EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 40, 100), gfx::Rect(0, 100, 50, 100)).ToString(), occlusion.occlusionInScreenSpace().ToString());
2428 EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 40, 100), gfx::Rect(0, 100, 50, 100)).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142429
2430 this->visitLayer(surface, occlusion);
2431
[email protected]ac7c7f52012-11-08 06:26:502432 EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 100, 50, 100)).ToString(), occlusion.occlusionInScreenSpace().ToString());
2433 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142434
2435 this->enterContributingSurface(surface, occlusion);
2436
2437 // Surface and replica are occluded different amounts.
[email protected]167ed9d52012-10-31 20:47:582438 EXPECT_RECT_EQ(gfx::Rect(40, 0, 60, 100), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 100, 100)));
2439 EXPECT_RECT_EQ(gfx::Rect(50, 0, 50, 100), occlusion.unoccludedContributingSurfaceContentRect(surface, true, gfx::Rect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142440 }
2441};
2442
[email protected]96baf3e2012-10-22 23:09:552443ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently);
[email protected]94f206c12012-08-25 00:09:142444
[email protected]ece1d952012-10-18 21:26:072445template<class Types>
[email protected]96baf3e2012-10-22 23:09:552446class OcclusionTrackerTestSurfaceChildOfSurface : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142447protected:
[email protected]96baf3e2012-10-22 23:09:552448 OcclusionTrackerTestSurfaceChildOfSurface(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142449 void runMyTest()
2450 {
2451 // This test verifies that the surface cliprect does not end up empty and clip away the entire unoccluded rect.
2452
[email protected]d0f98362012-11-01 23:02:382453 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2454 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2455 typename Types::LayerType* surfaceChild = this->createDrawingSurface(surface, this->identityMatrix, gfx::PointF(0, 10), gfx::Size(100, 50), true);
2456 typename Types::LayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 50), true);
[email protected]94f206c12012-08-25 00:09:142457 this->calcDrawEtc(parent);
2458
[email protected]167ed9d52012-10-31 20:47:582459 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142460
2461 // |topmost| occludes everything partially so we know occlusion is happening at all.
2462 this->visitLayer(topmost, occlusion);
2463
[email protected]ac7c7f52012-11-08 06:26:502464 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
2465 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142466
2467 this->visitLayer(surfaceChild, occlusion);
2468
2469 // surfaceChild increases the occlusion in the screen by a narrow sliver.
[email protected]ac7c7f52012-11-08 06:26:502470 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:142471 // In its own surface, surfaceChild is at 0,0 as is its occlusion.
[email protected]ac7c7f52012-11-08 06:26:502472 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142473
2474 // The root layer always has a clipRect. So the parent of |surface| has a clipRect. However, the owning layer for |surface| does not
2475 // mask to bounds, so it doesn't have a clipRect of its own. Thus the parent of |surfaceChild| exercises different code paths
2476 // as its parent does not have a clipRect.
2477
2478 this->enterContributingSurface(surfaceChild, occlusion);
2479 // The surfaceChild's parent does not have a clipRect as it owns a render surface. Make sure the unoccluded rect
2480 // does not get clipped away inappropriately.
[email protected]167ed9d52012-10-31 20:47:582481 EXPECT_RECT_EQ(gfx::Rect(0, 40, 100, 10), occlusion.unoccludedContributingSurfaceContentRect(surfaceChild, false, gfx::Rect(0, 0, 100, 50)));
[email protected]94f206c12012-08-25 00:09:142482 this->leaveContributingSurface(surfaceChild, occlusion);
2483
2484 // When the surfaceChild's occlusion is transformed up to its parent, make sure it is not clipped away inappropriately also.
2485 this->enterLayer(surface, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502486 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
2487 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142488 this->leaveLayer(surface, occlusion);
2489
2490 this->enterContributingSurface(surface, occlusion);
2491 // The surface's parent does have a clipRect as it is the root layer.
[email protected]167ed9d52012-10-31 20:47:582492 EXPECT_RECT_EQ(gfx::Rect(0, 50, 100, 50), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142493 }
2494};
2495
[email protected]96baf3e2012-10-22 23:09:552496ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:142497
[email protected]ece1d952012-10-18 21:26:072498template<class Types>
[email protected]96baf3e2012-10-22 23:09:552499class OcclusionTrackerTestTopmostSurfaceIsClippedToViewport : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142500protected:
[email protected]96baf3e2012-10-22 23:09:552501 OcclusionTrackerTestTopmostSurfaceIsClippedToViewport(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142502 void runMyTest()
2503 {
2504 // This test verifies that the top-most surface is considered occluded outside of its target's clipRect and outside the viewport rect.
2505
[email protected]d0f98362012-11-01 23:02:382506 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2507 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 300), true);
[email protected]94f206c12012-08-25 00:09:142508 this->calcDrawEtc(parent);
2509
2510 {
2511 // Make a viewport rect that is larger than the root layer.
[email protected]167ed9d52012-10-31 20:47:582512 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142513
2514 this->visitLayer(surface, occlusion);
2515
2516 // The root layer always has a clipRect. So the parent of |surface| has a clipRect giving the surface itself a clipRect.
2517 this->enterContributingSurface(surface, occlusion);
2518 // Make sure the parent's clipRect clips the unoccluded region of the child surface.
[email protected]167ed9d52012-10-31 20:47:582519 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 200), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 100, 300)));
[email protected]94f206c12012-08-25 00:09:142520 }
2521 this->resetLayerIterator();
2522 {
2523 // Make a viewport rect that is smaller than the root layer.
[email protected]167ed9d52012-10-31 20:47:582524 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:142525
2526 this->visitLayer(surface, occlusion);
2527
2528 // The root layer always has a clipRect. So the parent of |surface| has a clipRect giving the surface itself a clipRect.
2529 this->enterContributingSurface(surface, occlusion);
2530 // Make sure the viewport rect clips the unoccluded region of the child surface.
[email protected]167ed9d52012-10-31 20:47:582531 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 100, 300)));
[email protected]94f206c12012-08-25 00:09:142532 }
2533 }
2534};
2535
[email protected]96baf3e2012-10-22 23:09:552536ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTopmostSurfaceIsClippedToViewport);
[email protected]94f206c12012-08-25 00:09:142537
[email protected]ece1d952012-10-18 21:26:072538template<class Types>
[email protected]96baf3e2012-10-22 23:09:552539class OcclusionTrackerTestSurfaceChildOfClippingSurface : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142540protected:
[email protected]96baf3e2012-10-22 23:09:552541 OcclusionTrackerTestSurfaceChildOfClippingSurface(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142542 void runMyTest()
2543 {
2544 // This test verifies that the surface cliprect does not end up empty and clip away the entire unoccluded rect.
2545
[email protected]d0f98362012-11-01 23:02:382546 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(80, 200));
[email protected]23bbb412012-08-30 20:03:382547 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382548 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2549 typename Types::LayerType* surfaceChild = this->createDrawingSurface(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), false);
2550 typename Types::LayerType* topmost = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 50), true);
[email protected]94f206c12012-08-25 00:09:142551 this->calcDrawEtc(parent);
2552
[email protected]167ed9d52012-10-31 20:47:582553 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2554 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142555
2556 // |topmost| occludes everything partially so we know occlusion is happening at all.
2557 this->visitLayer(topmost, occlusion);
2558
[email protected]ac7c7f52012-11-08 06:26:502559 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
2560 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142561
2562 // surfaceChild is not opaque and does not occlude, so we have a non-empty unoccluded area on surface.
2563 this->visitLayer(surfaceChild, occlusion);
2564
[email protected]ac7c7f52012-11-08 06:26:502565 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
2566 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142567
2568 // The root layer always has a clipRect. So the parent of |surface| has a clipRect. However, the owning layer for |surface| does not
2569 // mask to bounds, so it doesn't have a clipRect of its own. Thus the parent of |surfaceChild| exercises different code paths
2570 // as its parent does not have a clipRect.
2571
2572 this->enterContributingSurface(surfaceChild, occlusion);
2573 // The surfaceChild's parent does not have a clipRect as it owns a render surface.
[email protected]167ed9d52012-10-31 20:47:582574 EXPECT_RECT_EQ(gfx::Rect(0, 50, 80, 50), occlusion.unoccludedContributingSurfaceContentRect(surfaceChild, false, gfx::Rect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142575 this->leaveContributingSurface(surfaceChild, occlusion);
2576
2577 this->visitLayer(surface, occlusion);
2578 this->enterContributingSurface(surface, occlusion);
2579 // The surface's parent does have a clipRect as it is the root layer.
[email protected]167ed9d52012-10-31 20:47:582580 EXPECT_RECT_EQ(gfx::Rect(0, 50, 80, 50), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142581 }
2582};
2583
[email protected]96baf3e2012-10-22 23:09:552584ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfClippingSurface);
[email protected]94f206c12012-08-25 00:09:142585
[email protected]ece1d952012-10-18 21:26:072586template<class Types>
[email protected]96baf3e2012-10-22 23:09:552587class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142588protected:
[email protected]96baf3e2012-10-22 23:09:552589 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142590 void runMyTest()
2591 {
[email protected]c8686a02012-11-27 08:29:002592 gfx::Transform scaleByHalf;
2593 scaleByHalf.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142594
2595 // Make a surface and its replica, each 50x50, that are completely surrounded by opaque layers which are above them in the z-order.
2596 // 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
2597 // appears at 50, 50 and the replica at 200, 50.
[email protected]d0f98362012-11-01 23:02:382598 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
2599 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(50, 50), gfx::Size(100, 100), false);
2600 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(300, 0), gfx::Size());
2601 typename Types::LayerType* occludingLayer1 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 50), true);
2602 typename Types::LayerType* occludingLayer2 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(300, 50), true);
2603 typename Types::LayerType* occludingLayer3 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 50), gfx::Size(50, 50), true);
2604 typename Types::LayerType* occludingLayer4 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(100, 50), gfx::Size(100, 50), true);
2605 typename Types::LayerType* occludingLayer5 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(250, 50), gfx::Size(50, 50), true);
[email protected]94f206c12012-08-25 00:09:142606
2607 // Filters make the layer own a surface.
2608 WebFilterOperations filters;
2609 filters.append(WebFilterOperation::createBlurFilter(10));
2610 filteredSurface->setBackgroundFilters(filters);
2611
2612 // Save the distance of influence for the blur effect.
2613 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2614 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2615
2616 this->calcDrawEtc(parent);
2617
[email protected]167ed9d52012-10-31 20:47:582618 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2619 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142620
2621 // These layers occlude pixels directly beside the filteredSurface. Because filtered surface blends pixels in a radius, it will
2622 // need to see some of the pixels (up to radius far) underneath the occludingLayers.
2623 this->visitLayer(occludingLayer5, occlusion);
2624 this->visitLayer(occludingLayer4, occlusion);
2625 this->visitLayer(occludingLayer3, occlusion);
2626 this->visitLayer(occludingLayer2, occlusion);
2627 this->visitLayer(occludingLayer1, occlusion);
2628
[email protected]ac7c7f52012-11-08 06:26:502629 Region expectedOcclusion;
2630 expectedOcclusion.Union(gfx::Rect(0, 0, 300, 50));
2631 expectedOcclusion.Union(gfx::Rect(0, 50, 50, 50));
2632 expectedOcclusion.Union(gfx::Rect(100, 50, 100, 50));
2633 expectedOcclusion.Union(gfx::Rect(250, 50, 50, 50));
2634 expectedOcclusion.Union(gfx::Rect(0, 100, 300, 50));
2635
2636 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2637 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142638
2639 // Everything outside the surface/replica is occluded but the surface/replica itself is not.
2640 this->enterLayer(filteredSurface, occlusion);
[email protected]167ed9d52012-10-31 20:47:582641 EXPECT_RECT_EQ(gfx::Rect(1, 0, 99, 100), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(1, 0, 100, 100)));
2642 EXPECT_RECT_EQ(gfx::Rect(0, 1, 100, 99), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(0, 1, 100, 100)));
2643 EXPECT_RECT_EQ(gfx::Rect(0, 0, 99, 100), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(-1, 0, 100, 100)));
2644 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 99), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(0, -1, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142645
[email protected]167ed9d52012-10-31 20:47:582646 EXPECT_RECT_EQ(gfx::Rect(300 + 1, 0, 99, 100), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(300 + 1, 0, 100, 100)));
2647 EXPECT_RECT_EQ(gfx::Rect(300 + 0, 1, 100, 99), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(300 + 0, 1, 100, 100)));
2648 EXPECT_RECT_EQ(gfx::Rect(300 + 0, 0, 99, 100), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(300 - 1, 0, 100, 100)));
2649 EXPECT_RECT_EQ(gfx::Rect(300 + 0, 0, 100, 99), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(300 + 0, -1, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142650 this->leaveLayer(filteredSurface, occlusion);
2651
2652 // The filtered layer/replica does not occlude.
[email protected]ac7c7f52012-11-08 06:26:502653 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2654 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142655
2656 // 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:382657 // 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:142658 this->visitContributingSurface(filteredSurface, occlusion);
2659
2660 this->enterLayer(parent, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502661
2662 Region expectedBlurredOcclusion;
2663 expectedBlurredOcclusion.Union(gfx::Rect(0, 0, 300, 50 - outsetTop));
2664 expectedBlurredOcclusion.Union(gfx::Rect(0, 50 - outsetTop, 50 - outsetLeft, 50 + outsetTop + outsetBottom));
2665 expectedBlurredOcclusion.Union(gfx::Rect(100 + outsetRight, 50 - outsetTop, 100 - outsetRight - outsetLeft, 50 + outsetTop + outsetBottom));
2666 expectedBlurredOcclusion.Union(gfx::Rect(250 + outsetRight, 50 - outsetTop, 50 - outsetRight, 50 + outsetTop + outsetBottom));
2667 expectedBlurredOcclusion.Union(gfx::Rect(0, 100 + outsetBottom, 300, 50 - outsetBottom));
2668
2669 EXPECT_EQ(expectedBlurredOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2670 EXPECT_EQ(expectedBlurredOcclusion.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142671
[email protected]167ed9d52012-10-31 20:47:582672 gfx::Rect outsetRect;
2673 gfx::Rect testRect;
[email protected]94f206c12012-08-25 00:09:142674
2675 // Nothing in the blur outsets for the filteredSurface is occluded.
[email protected]167ed9d52012-10-31 20:47:582676 outsetRect = gfx::Rect(50 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
[email protected]94f206c12012-08-25 00:09:142677 testRect = outsetRect;
[email protected]710ffc02012-10-30 21:42:022678 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142679
2680 // Stuff outside the blur outsets is still occluded though.
2681 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582682 testRect.Inset(0, 0, -1, 0);
[email protected]710ffc02012-10-30 21:42:022683 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142684 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582685 testRect.Inset(0, 0, 0, -1);
[email protected]710ffc02012-10-30 21:42:022686 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142687 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582688 testRect.Inset(-1, 0, 0, 0);
[email protected]710ffc02012-10-30 21:42:022689 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142690 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582691 testRect.Inset(0, -1, 0, 0);
[email protected]710ffc02012-10-30 21:42:022692 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142693
2694 // Nothing in the blur outsets for the filteredSurface's replica is occluded.
[email protected]167ed9d52012-10-31 20:47:582695 outsetRect = gfx::Rect(200 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
[email protected]94f206c12012-08-25 00:09:142696 testRect = outsetRect;
[email protected]710ffc02012-10-30 21:42:022697 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142698
2699 // Stuff outside the blur outsets is still occluded though.
2700 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582701 testRect.Inset(0, 0, -1, 0);
[email protected]710ffc02012-10-30 21:42:022702 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142703 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582704 testRect.Inset(0, 0, 0, -1);
[email protected]710ffc02012-10-30 21:42:022705 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142706 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582707 testRect.Inset(-1, 0, 0, 0);
[email protected]710ffc02012-10-30 21:42:022708 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142709 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582710 testRect.Inset(0, -1, 0, 0);
[email protected]710ffc02012-10-30 21:42:022711 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142712 }
2713};
2714
[email protected]96baf3e2012-10-22 23:09:552715ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142716
[email protected]ece1d952012-10-18 21:26:072717template<class Types>
[email protected]96baf3e2012-10-22 23:09:552718class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142719protected:
[email protected]96baf3e2012-10-22 23:09:552720 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142721 void runMyTest()
2722 {
[email protected]c8686a02012-11-27 08:29:002723 gfx::Transform scaleByHalf;
2724 scaleByHalf.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142725
2726 // Makes two surfaces that completely cover |parent|. The occlusion both above and below the filters will be reduced by each of them.
[email protected]d0f98362012-11-01 23:02:382727 typename Types::ContentLayerType* root = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(75, 75));
2728 typename Types::LayerType* parent = this->createSurface(root, scaleByHalf, gfx::PointF(0, 0), gfx::Size(150, 150));
[email protected]94f206c12012-08-25 00:09:142729 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382730 typename Types::LayerType* filteredSurface1 = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2731 typename Types::LayerType* filteredSurface2 = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2732 typename Types::LayerType* occludingLayerAbove = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(100, 100), gfx::Size(50, 50), true);
[email protected]94f206c12012-08-25 00:09:142733
2734 // Filters make the layers own surfaces.
2735 WebFilterOperations filters;
[email protected]518ee582012-10-24 18:29:442736 filters.append(WebFilterOperation::createBlurFilter(1));
[email protected]94f206c12012-08-25 00:09:142737 filteredSurface1->setBackgroundFilters(filters);
2738 filteredSurface2->setBackgroundFilters(filters);
2739
2740 // Save the distance of influence for the blur effect.
2741 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2742 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2743
2744 this->calcDrawEtc(root);
2745
[email protected]167ed9d52012-10-31 20:47:582746 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2747 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142748
2749 this->visitLayer(occludingLayerAbove, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502750 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(), occlusion.occlusionInScreenSpace().ToString());
2751 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142752
2753 this->visitLayer(filteredSurface2, occlusion);
2754 this->visitContributingSurface(filteredSurface2, occlusion);
2755 this->visitLayer(filteredSurface1, occlusion);
2756 this->visitContributingSurface(filteredSurface1, occlusion);
2757
[email protected]f3922f22012-10-12 09:20:382758 // Test expectations in the target.
[email protected]167ed9d52012-10-31 20:47:582759 gfx::Rect expectedOcclusion = gfx::Rect(100 / 2 + outsetRight * 2, 100 / 2 + outsetBottom * 2, 50 / 2 - (outsetLeft + outsetRight) * 2, 50 / 2 - (outsetTop + outsetBottom) * 2);
[email protected]ac7c7f52012-11-08 06:26:502760 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142761
[email protected]518ee582012-10-24 18:29:442762 // Test expectations in the screen are the same as in the target, as the render surface is 1:1 with the screen.
[email protected]ac7c7f52012-11-08 06:26:502763 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:142764 }
2765};
2766
[email protected]96baf3e2012-10-22 23:09:552767ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:142768
[email protected]ece1d952012-10-18 21:26:072769template<class Types>
[email protected]96baf3e2012-10-22 23:09:552770class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142771protected:
[email protected]96baf3e2012-10-22 23:09:552772 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142773 void runMyTest()
2774 {
2775 // Make a surface and its replica, each 50x50, that are completely surrounded by opaque layers which are above them in the z-order.
[email protected]d0f98362012-11-01 23:02:382776 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
[email protected]94f206c12012-08-25 00:09:142777 // We stick the filtered surface inside a clipping surface so that we can make sure the clip is honored when exposing pixels for
2778 // the background filter.
[email protected]d0f98362012-11-01 23:02:382779 typename Types::LayerType* clippingSurface = this->createSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 70));
[email protected]94f206c12012-08-25 00:09:142780 clippingSurface->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382781 typename Types::LayerType* filteredSurface = this->createDrawingLayer(clippingSurface, this->identityMatrix, gfx::PointF(50, 50), gfx::Size(50, 50), false);
2782 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(150, 0), gfx::Size());
2783 typename Types::LayerType* occludingLayer1 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 50), true);
2784 typename Types::LayerType* occludingLayer2 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(300, 50), true);
2785 typename Types::LayerType* occludingLayer3 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 50), gfx::Size(50, 50), true);
2786 typename Types::LayerType* occludingLayer4 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(100, 50), gfx::Size(100, 50), true);
2787 typename Types::LayerType* occludingLayer5 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(250, 50), gfx::Size(50, 50), true);
[email protected]94f206c12012-08-25 00:09:142788
2789 // Filters make the layer own a surface. This filter is large enough that it goes outside the bottom of the clippingSurface.
2790 WebFilterOperations filters;
2791 filters.append(WebFilterOperation::createBlurFilter(12));
2792 filteredSurface->setBackgroundFilters(filters);
2793
2794 // Save the distance of influence for the blur effect.
2795 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2796 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2797
2798 this->calcDrawEtc(parent);
2799
[email protected]167ed9d52012-10-31 20:47:582800 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2801 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142802
2803 // These layers occlude pixels directly beside the filteredSurface. Because filtered surface blends pixels in a radius, it will
2804 // need to see some of the pixels (up to radius far) underneath the occludingLayers.
2805 this->visitLayer(occludingLayer5, occlusion);
2806 this->visitLayer(occludingLayer4, occlusion);
2807 this->visitLayer(occludingLayer3, occlusion);
2808 this->visitLayer(occludingLayer2, occlusion);
2809 this->visitLayer(occludingLayer1, occlusion);
2810
[email protected]ac7c7f52012-11-08 06:26:502811 Region expectedOcclusion;
2812 expectedOcclusion.Union(gfx::Rect(0, 0, 300, 50));
2813 expectedOcclusion.Union(gfx::Rect(0, 50, 50, 50));
2814 expectedOcclusion.Union(gfx::Rect(100, 50, 100, 50));
2815 expectedOcclusion.Union(gfx::Rect(250, 50, 50, 50));
2816 expectedOcclusion.Union(gfx::Rect(0, 100, 300, 50));
2817
2818 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2819 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142820
2821 // Everything outside the surface/replica is occluded but the surface/replica itself is not.
2822 this->enterLayer(filteredSurface, occlusion);
[email protected]167ed9d52012-10-31 20:47:582823 EXPECT_RECT_EQ(gfx::Rect(1, 0, 49, 50), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(1, 0, 50, 50)));
2824 EXPECT_RECT_EQ(gfx::Rect(0, 1, 50, 49), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(0, 1, 50, 50)));
2825 EXPECT_RECT_EQ(gfx::Rect(0, 0, 49, 50), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(-1, 0, 50, 50)));
2826 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 49), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(0, -1, 50, 50)));
[email protected]94f206c12012-08-25 00:09:142827
[email protected]167ed9d52012-10-31 20:47:582828 EXPECT_RECT_EQ(gfx::Rect(150 + 1, 0, 49, 50), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(150 + 1, 0, 50, 50)));
2829 EXPECT_RECT_EQ(gfx::Rect(150 + 0, 1, 50, 49), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(150 + 0, 1, 50, 50)));
2830 EXPECT_RECT_EQ(gfx::Rect(150 + 0, 0, 49, 50), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(150 - 1, 0, 50, 50)));
2831 EXPECT_RECT_EQ(gfx::Rect(150 + 0, 0, 50, 49), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(150 + 0, -1, 50, 50)));
[email protected]94f206c12012-08-25 00:09:142832 this->leaveLayer(filteredSurface, occlusion);
2833
2834 // The filtered layer/replica does not occlude.
[email protected]ac7c7f52012-11-08 06:26:502835 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2836 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142837
2838 // The surface has a background blur, so it needs pixels that are currently considered occluded in order to be drawn. So the pixels
2839 // it needs should be removed some the occluded area so that when we get to the parent they are drawn.
2840 this->visitContributingSurface(filteredSurface, occlusion);
2841
2842 this->enterContributingSurface(clippingSurface, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502843
2844 Region expectedBlurredOcclusion;
2845 expectedBlurredOcclusion.Union(gfx::Rect(0, 0, 300, 50 - outsetTop));
2846 expectedBlurredOcclusion.Union(gfx::Rect(0, 50 - outsetTop, 50 - outsetLeft, 20 + outsetTop + outsetBottom));
2847 expectedBlurredOcclusion.Union(gfx::Rect(100 + outsetRight, 50 - outsetTop, 100 - outsetRight - outsetLeft, 20 + outsetTop + outsetBottom));
2848 expectedBlurredOcclusion.Union(gfx::Rect(250 + outsetRight, 50 - outsetTop, 50 - outsetRight, 20 + outsetTop + outsetBottom));
2849 expectedBlurredOcclusion.Union(gfx::Rect(0, 100 + 5, 300, 50 - 5));
2850
2851 EXPECT_EQ(expectedBlurredOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2852 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142853
[email protected]167ed9d52012-10-31 20:47:582854 gfx::Rect outsetRect;
2855 gfx::Rect clippedOutsetRect;
2856 gfx::Rect testRect;
[email protected]94f206c12012-08-25 00:09:142857
2858 // Nothing in the (clipped) blur outsets for the filteredSurface is occluded.
[email protected]167ed9d52012-10-31 20:47:582859 outsetRect = gfx::Rect(50 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
2860 clippedOutsetRect = gfx::IntersectRects(outsetRect, gfx::Rect(0 - outsetLeft, 0 - outsetTop, 300 + outsetLeft + outsetRight, 70 + outsetTop + outsetBottom));
[email protected]94f206c12012-08-25 00:09:142861 testRect = outsetRect;
[email protected]710ffc02012-10-30 21:42:022862 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142863
2864 // Stuff outside the (clipped) blur outsets is still occluded though.
2865 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582866 testRect.Inset(0, 0, -1, 0);
[email protected]710ffc02012-10-30 21:42:022867 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142868 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582869 testRect.Inset(0, 0, 0, -1);
[email protected]710ffc02012-10-30 21:42:022870 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142871 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582872 testRect.Inset(-1, 0, 0, 0);
[email protected]710ffc02012-10-30 21:42:022873 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142874 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582875 testRect.Inset(0, -1, 0, 0);
[email protected]710ffc02012-10-30 21:42:022876 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142877
2878 // Nothing in the (clipped) blur outsets for the filteredSurface's replica is occluded.
[email protected]167ed9d52012-10-31 20:47:582879 outsetRect = gfx::Rect(200 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
2880 clippedOutsetRect = gfx::IntersectRects(outsetRect, gfx::Rect(0 - outsetLeft, 0 - outsetTop, 300 + outsetLeft + outsetRight, 70 + outsetTop + outsetBottom));
[email protected]94f206c12012-08-25 00:09:142881 testRect = outsetRect;
[email protected]710ffc02012-10-30 21:42:022882 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142883
2884 // Stuff outside the (clipped) blur outsets is still occluded though.
2885 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582886 testRect.Inset(0, 0, -1, 0);
[email protected]710ffc02012-10-30 21:42:022887 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142888 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582889 testRect.Inset(0, 0, 0, -1);
[email protected]710ffc02012-10-30 21:42:022890 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142891 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582892 testRect.Inset(-1, 0, 0, 0);
[email protected]710ffc02012-10-30 21:42:022893 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142894 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582895 testRect.Inset(0, -1, 0, 0);
[email protected]710ffc02012-10-30 21:42:022896 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142897 }
2898};
2899
[email protected]96baf3e2012-10-22 23:09:552900ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip);
[email protected]94f206c12012-08-25 00:09:142901
[email protected]ece1d952012-10-18 21:26:072902template<class Types>
[email protected]96baf3e2012-10-22 23:09:552903class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142904protected:
[email protected]96baf3e2012-10-22 23:09:552905 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142906 void runMyTest()
2907 {
[email protected]c8686a02012-11-27 08:29:002908 gfx::Transform scaleByHalf;
2909 scaleByHalf.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142910
2911 // Make a surface and its replica, each 50x50, with a smaller 30x30 layer centered below each.
2912 // 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
2913 // appears at 50, 50 and the replica at 200, 50.
[email protected]d0f98362012-11-01 23:02:382914 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
2915 typename Types::LayerType* behindSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(60, 60), gfx::Size(30, 30), true);
2916 typename Types::LayerType* behindReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(210, 60), gfx::Size(30, 30), true);
2917 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(50, 50), gfx::Size(100, 100), false);
2918 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(300, 0), gfx::Size());
[email protected]94f206c12012-08-25 00:09:142919
2920 // Filters make the layer own a surface.
2921 WebFilterOperations filters;
2922 filters.append(WebFilterOperation::createBlurFilter(3));
2923 filteredSurface->setBackgroundFilters(filters);
2924
2925 this->calcDrawEtc(parent);
2926
[email protected]167ed9d52012-10-31 20:47:582927 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2928 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142929
2930 // The surface has a background blur, so it blurs non-opaque pixels below it.
2931 this->visitLayer(filteredSurface, occlusion);
2932 this->visitContributingSurface(filteredSurface, occlusion);
2933
2934 this->visitLayer(behindReplicaLayer, occlusion);
2935 this->visitLayer(behindSurfaceLayer, occlusion);
2936
2937 // The layers behind the surface are not blurred, and their occlusion does not change, until we leave the surface.
2938 // So it should not be modified by the filter here.
[email protected]167ed9d52012-10-31 20:47:582939 gfx::Rect occlusionBehindSurface = gfx::Rect(60, 60, 30, 30);
2940 gfx::Rect occlusionBehindReplica = gfx::Rect(210, 60, 30, 30);
[email protected]94f206c12012-08-25 00:09:142941
[email protected]ac7c7f52012-11-08 06:26:502942 Region expectedOpaqueBounds = UnionRegions(occlusionBehindSurface, occlusionBehindReplica);
2943 EXPECT_EQ(expectedOpaqueBounds.ToString(), occlusion.occlusionInScreenSpace().ToString());
2944 EXPECT_EQ(expectedOpaqueBounds.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142945 }
2946};
2947
[email protected]96baf3e2012-10-22 23:09:552948ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142949
[email protected]ece1d952012-10-18 21:26:072950template<class Types>
[email protected]96baf3e2012-10-22 23:09:552951class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142952protected:
[email protected]96baf3e2012-10-22 23:09:552953 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142954 void runMyTest()
2955 {
[email protected]c8686a02012-11-27 08:29:002956 gfx::Transform scaleByHalf;
2957 scaleByHalf.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142958
2959 // Make a surface and its replica, each 50x50, that are completely occluded by opaque layers which are above them in the z-order.
2960 // 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
2961 // appears at 50, 50 and the replica at 200, 50.
[email protected]d0f98362012-11-01 23:02:382962 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
2963 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(50, 50), gfx::Size(100, 100), false);
2964 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(300, 0), gfx::Size());
2965 typename Types::LayerType* aboveSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(50, 50), gfx::Size(50, 50), true);
2966 typename Types::LayerType* aboveReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(200, 50), gfx::Size(50, 50), true);
[email protected]94f206c12012-08-25 00:09:142967
2968 // Filters make the layer own a surface.
2969 WebFilterOperations filters;
2970 filters.append(WebFilterOperation::createBlurFilter(3));
2971 filteredSurface->setBackgroundFilters(filters);
2972
2973 this->calcDrawEtc(parent);
2974
[email protected]167ed9d52012-10-31 20:47:582975 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2976 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142977
2978 this->visitLayer(aboveReplicaLayer, occlusion);
2979 this->visitLayer(aboveSurfaceLayer, occlusion);
2980
2981 // The surface has a background blur, so it blurs non-opaque pixels below it.
2982 this->visitLayer(filteredSurface, occlusion);
2983 this->visitContributingSurface(filteredSurface, occlusion);
2984
2985 // The filter is completely occluded, so it should not blur anything and reduce any occlusion.
[email protected]167ed9d52012-10-31 20:47:582986 gfx::Rect occlusionAboveSurface = gfx::Rect(50, 50, 50, 50);
2987 gfx::Rect occlusionAboveReplica = gfx::Rect(200, 50, 50, 50);
[email protected]94f206c12012-08-25 00:09:142988
[email protected]ac7c7f52012-11-08 06:26:502989 Region expectedOpaqueRegion = UnionRegions(occlusionAboveSurface, occlusionAboveReplica);
2990 EXPECT_EQ(expectedOpaqueRegion, occlusion.occlusionInScreenSpace());
2991 EXPECT_EQ(expectedOpaqueRegion, occlusion.occlusionInTargetSurface());
[email protected]94f206c12012-08-25 00:09:142992 }
2993};
2994
[email protected]96baf3e2012-10-22 23:09:552995ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:142996
[email protected]ece1d952012-10-18 21:26:072997template<class Types>
[email protected]96baf3e2012-10-22 23:09:552998class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142999protected:
[email protected]96baf3e2012-10-22 23:09:553000 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:143001 void runMyTest()
3002 {
[email protected]c8686a02012-11-27 08:29:003003 gfx::Transform scaleByHalf;
3004 scaleByHalf.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:143005
3006 // Make a surface and its replica, each 50x50, that are partially occluded by opaque layers which are above them in the z-order.
3007 // 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
3008 // appears at 50, 50 and the replica at 200, 50.
[email protected]d0f98362012-11-01 23:02:383009 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
3010 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(50, 50), gfx::Size(100, 100), false);
3011 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(300, 0), gfx::Size());
3012 typename Types::LayerType* aboveSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(70, 50), gfx::Size(30, 50), true);
3013 typename Types::LayerType* aboveReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(200, 50), gfx::Size(30, 50), true);
3014 typename Types::LayerType* besideSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(90, 40), gfx::Size(10, 10), true);
3015 typename Types::LayerType* besideReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(200, 40), gfx::Size(10, 10), true);
[email protected]94f206c12012-08-25 00:09:143016
3017 // Filters make the layer own a surface.
3018 WebFilterOperations filters;
3019 filters.append(WebFilterOperation::createBlurFilter(3));
3020 filteredSurface->setBackgroundFilters(filters);
3021
3022 // Save the distance of influence for the blur effect.
3023 int outsetTop, outsetRight, outsetBottom, outsetLeft;
3024 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
3025
3026 this->calcDrawEtc(parent);
3027
[email protected]167ed9d52012-10-31 20:47:583028 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
3029 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143030
3031 this->visitLayer(besideReplicaLayer, occlusion);
3032 this->visitLayer(besideSurfaceLayer, occlusion);
3033 this->visitLayer(aboveReplicaLayer, occlusion);
3034 this->visitLayer(aboveSurfaceLayer, occlusion);
3035
3036 // The surface has a background blur, so it blurs non-opaque pixels below it.
3037 this->visitLayer(filteredSurface, occlusion);
3038 this->visitContributingSurface(filteredSurface, occlusion);
3039
3040 // The filter in the surface and replica are partially unoccluded. Only the unoccluded parts should reduce occlusion.
3041 // This means it will push back the occlusion that touches the unoccluded part (occlusionAbove___), but it will not
3042 // touch occlusionBeside____ since that is not beside the unoccluded part of the surface, even though it is beside
3043 // the occluded part of the surface.
[email protected]167ed9d52012-10-31 20:47:583044 gfx::Rect occlusionAboveSurface = gfx::Rect(70 + outsetRight, 50, 30 - outsetRight, 50);
3045 gfx::Rect occlusionAboveReplica = gfx::Rect(200, 50, 30 - outsetLeft, 50);
3046 gfx::Rect occlusionBesideSurface = gfx::Rect(90, 40, 10, 10);
3047 gfx::Rect occlusionBesideReplica = gfx::Rect(200, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:143048
3049 Region expectedOcclusion;
[email protected]d0f98362012-11-01 23:02:383050 expectedOcclusion.Union(occlusionAboveSurface);
3051 expectedOcclusion.Union(occlusionAboveReplica);
3052 expectedOcclusion.Union(occlusionBesideSurface);
3053 expectedOcclusion.Union(occlusionBesideReplica);
[email protected]94f206c12012-08-25 00:09:143054
[email protected]ac7c7f52012-11-08 06:26:503055 ASSERT_EQ(expectedOcclusion, occlusion.occlusionInTargetSurface());
3056 ASSERT_EQ(expectedOcclusion, occlusion.occlusionInScreenSpace());
[email protected]94f206c12012-08-25 00:09:143057
[email protected]0d8a30502012-11-03 02:59:153058 Region::Iterator expectedRects(expectedOcclusion);
3059 Region::Iterator screenSpaceRects(occlusion.occlusionInScreenSpace());
3060 Region::Iterator targetSurfaceRects(occlusion.occlusionInTargetSurface());
3061 for (; expectedRects.has_rect(); expectedRects.next(), screenSpaceRects.next(), targetSurfaceRects.next()) {
3062 ASSERT_TRUE(screenSpaceRects.has_rect());
3063 ASSERT_TRUE(targetSurfaceRects.has_rect());
3064 EXPECT_EQ(expectedRects.rect(), screenSpaceRects.rect());
3065 EXPECT_EQ(expectedRects.rect(), targetSurfaceRects.rect());
[email protected]94f206c12012-08-25 00:09:143066 }
3067 }
3068};
3069
[email protected]96baf3e2012-10-22 23:09:553070ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:143071
[email protected]ece1d952012-10-18 21:26:073072template<class Types>
[email protected]96baf3e2012-10-22 23:09:553073class OcclusionTrackerTestMinimumTrackingSize : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:143074protected:
[email protected]96baf3e2012-10-22 23:09:553075 OcclusionTrackerTestMinimumTrackingSize(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:143076 void runMyTest()
3077 {
[email protected]aad0a0072012-11-01 18:15:583078 gfx::Size trackingSize(100, 100);
3079 gfx::Size belowTrackingSize(99, 99);
[email protected]94f206c12012-08-25 00:09:143080
[email protected]d0f98362012-11-01 23:02:383081 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(400, 400));
3082 typename Types::LayerType* large = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), trackingSize, true);
3083 typename Types::LayerType* small = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), belowTrackingSize, true);
[email protected]94f206c12012-08-25 00:09:143084 this->calcDrawEtc(parent);
3085
[email protected]167ed9d52012-10-31 20:47:583086 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
3087 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143088 occlusion.setMinimumTrackingSize(trackingSize);
3089
3090 // The small layer is not tracked because it is too small.
3091 this->visitLayer(small, occlusion);
3092
[email protected]ac7c7f52012-11-08 06:26:503093 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInScreenSpace().ToString());
3094 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:143095
3096 // The large layer is tracked as it is large enough.
3097 this->visitLayer(large, occlusion);
3098
[email protected]ac7c7f52012-11-08 06:26:503099 EXPECT_EQ(gfx::Rect(gfx::Point(), trackingSize).ToString(), occlusion.occlusionInScreenSpace().ToString());
3100 EXPECT_EQ(gfx::Rect(gfx::Point(), trackingSize).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:143101 }
3102};
3103
[email protected]96baf3e2012-10-22 23:09:553104ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:143105
[email protected]ba565742012-11-10 09:29:483106} // namespace
3107} // namespace cc