blob: fac2f02e4a8f160d330727b6fa39043c9dc73f01 [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]a8461d82012-10-16 21:11:147#include "cc/layer.h"
[email protected]d50c6862012-10-23 02:08:318#include "cc/layer_animation_controller.h"
9#include "cc/layer_impl.h"
10#include "cc/layer_tree_host_common.h"
[email protected]55a124d02012-10-22 03:07:1311#include "cc/math_util.h"
12#include "cc/overdraw_metrics.h"
[email protected]4456eee22012-10-19 18:16:3813#include "cc/single_thread_proxy.h"
[email protected]101441ce2012-10-16 01:45:0314#include "cc/test/animation_test_common.h"
15#include "cc/test/geometry_test_utils.h"
16#include "cc/test/occlusion_tracker_test_common.h"
[email protected]7f0c53db2012-10-02 00:23:1817#include "testing/gmock/include/gmock/gmock.h"
18#include "testing/gtest/include/gtest/gtest.h"
[email protected]94f206c12012-08-25 00:09:1419#include <public/WebFilterOperation.h>
20#include <public/WebFilterOperations.h>
21#include <public/WebTransformationMatrix.h>
22
[email protected]94f206c12012-08-25 00:09:1423using namespace WebKit;
24using namespace WebKitTests;
25
[email protected]ba565742012-11-10 09:29:4826namespace cc {
[email protected]94f206c12012-08-25 00:09:1427namespace {
28
[email protected]96baf3e2012-10-22 23:09:5529class TestContentLayer : public Layer {
[email protected]94f206c12012-08-25 00:09:1430public:
[email protected]96baf3e2012-10-22 23:09:5531 TestContentLayer()
32 : Layer()
[email protected]94f206c12012-08-25 00:09:1433 , m_overrideOpaqueContentsRect(false)
34 {
35 }
36
37 virtual bool drawsContent() const OVERRIDE { return true; }
38 virtual Region visibleContentOpaqueRegion() const OVERRIDE
39 {
40 if (m_overrideOpaqueContentsRect)
[email protected]d0f98362012-11-01 23:02:3841 return gfx::IntersectRects(m_opaqueContentsRect, visibleContentRect());
[email protected]96baf3e2012-10-22 23:09:5542 return Layer::visibleContentOpaqueRegion();
[email protected]94f206c12012-08-25 00:09:1443 }
[email protected]aad0a0072012-11-01 18:15:5844 void setOpaqueContentsRect(const gfx::Rect& opaqueContentsRect)
[email protected]94f206c12012-08-25 00:09:1445 {
46 m_overrideOpaqueContentsRect = true;
47 m_opaqueContentsRect = opaqueContentsRect;
48 }
49
50private:
[email protected]96baf3e2012-10-22 23:09:5551 virtual ~TestContentLayer()
[email protected]d58499a2012-10-09 22:27:4752 {
53 }
54
[email protected]94f206c12012-08-25 00:09:1455 bool m_overrideOpaqueContentsRect;
[email protected]aad0a0072012-11-01 18:15:5856 gfx::Rect m_opaqueContentsRect;
[email protected]94f206c12012-08-25 00:09:1457};
58
[email protected]96baf3e2012-10-22 23:09:5559class TestContentLayerImpl : public LayerImpl {
[email protected]94f206c12012-08-25 00:09:1460public:
61 TestContentLayerImpl(int id)
[email protected]96baf3e2012-10-22 23:09:5562 : LayerImpl(id)
[email protected]94f206c12012-08-25 00:09:1463 , m_overrideOpaqueContentsRect(false)
64 {
65 setDrawsContent(true);
66 }
67
68 virtual Region visibleContentOpaqueRegion() const OVERRIDE
69 {
70 if (m_overrideOpaqueContentsRect)
[email protected]d0f98362012-11-01 23:02:3871 return gfx::IntersectRects(m_opaqueContentsRect, visibleContentRect());
[email protected]96baf3e2012-10-22 23:09:5572 return LayerImpl::visibleContentOpaqueRegion();
[email protected]94f206c12012-08-25 00:09:1473 }
[email protected]aad0a0072012-11-01 18:15:5874 void setOpaqueContentsRect(const gfx::Rect& opaqueContentsRect)
[email protected]94f206c12012-08-25 00:09:1475 {
76 m_overrideOpaqueContentsRect = true;
77 m_opaqueContentsRect = opaqueContentsRect;
78 }
79
80private:
81 bool m_overrideOpaqueContentsRect;
[email protected]aad0a0072012-11-01 18:15:5882 gfx::Rect m_opaqueContentsRect;
[email protected]94f206c12012-08-25 00:09:1483};
84
[email protected]710ffc02012-10-30 21:42:0285static inline bool layerImplDrawTransformIsUnknown(const Layer* layer) { return layer->drawTransformIsAnimating(); }
86static inline bool layerImplDrawTransformIsUnknown(const LayerImpl*) { return false; }
87
[email protected]94f206c12012-08-25 00:09:1488template<typename LayerType, typename RenderSurfaceType>
[email protected]96baf3e2012-10-22 23:09:5589class TestOcclusionTrackerWithClip : public TestOcclusionTrackerBase<LayerType, RenderSurfaceType> {
[email protected]94f206c12012-08-25 00:09:1490public:
[email protected]167ed9d52012-10-31 20:47:5891 TestOcclusionTrackerWithClip(gfx::Rect viewportRect, bool recordMetricsForFrame = false)
[email protected]96baf3e2012-10-22 23:09:5592 : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(viewportRect, recordMetricsForFrame)
[email protected]94f206c12012-08-25 00:09:1493 , m_overrideLayerClipRect(false)
94 {
95 }
96
[email protected]167ed9d52012-10-31 20:47:5897 void setLayerClipRect(const gfx::Rect& rect) { m_overrideLayerClipRect = true; m_layerClipRect = rect;}
[email protected]94f206c12012-08-25 00:09:1498 void useDefaultLayerClipRect() { m_overrideLayerClipRect = false; }
[email protected]710ffc02012-10-30 21:42:0299 // 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:58100 bool occludedLayer(const LayerType* layer, const gfx::Rect& contentRect, bool* hasOcclusionFromOutsideTargetSurface = 0) const
[email protected]710ffc02012-10-30 21:42:02101 {
102 return this->occluded(layer->renderTarget(), contentRect, layer->drawTransform(), layerImplDrawTransformIsUnknown(layer), layerClipRectInTarget(layer), hasOcclusionFromOutsideTargetSurface);
103 }
104 // 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:58105 gfx::Rect unoccludedLayerContentRect(const LayerType* layer, const gfx::Rect& contentRect, bool* hasOcclusionFromOutsideTargetSurface = 0) const
[email protected]710ffc02012-10-30 21:42:02106 {
107 return this->unoccludedContentRect(layer->renderTarget(), contentRect, layer->drawTransform(), layerImplDrawTransformIsUnknown(layer), layerClipRectInTarget(layer), hasOcclusionFromOutsideTargetSurface);
108 }
109
[email protected]94f206c12012-08-25 00:09:14110
111protected:
[email protected]167ed9d52012-10-31 20:47:58112 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:14113
114private:
115 bool m_overrideLayerClipRect;
[email protected]167ed9d52012-10-31 20:47:58116 gfx::Rect m_layerClipRect;
[email protected]94f206c12012-08-25 00:09:14117};
118
[email protected]96baf3e2012-10-22 23:09:55119struct OcclusionTrackerTestMainThreadTypes {
120 typedef Layer LayerType;
121 typedef RenderSurface RenderSurfaceType;
122 typedef TestContentLayer ContentLayerType;
123 typedef scoped_refptr<Layer> LayerPtrType;
[email protected]d58499a2012-10-09 22:27:47124 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
[email protected]96baf3e2012-10-22 23:09:55125 typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::FrontToBack> TestLayerIterator;
126 typedef OcclusionTracker OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14127
[email protected]e0bd43a2012-10-12 16:54:21128 static LayerPtrType createLayer()
[email protected]94f206c12012-08-25 00:09:14129 {
[email protected]96baf3e2012-10-22 23:09:55130 return Layer::create();
[email protected]94f206c12012-08-25 00:09:14131 }
[email protected]e0bd43a2012-10-12 16:54:21132 static ContentLayerPtrType createContentLayer() { return make_scoped_refptr(new ContentLayerType()); }
133
134 static LayerPtrType passLayerPtr(ContentLayerPtrType& layer)
135 {
136 return layer.release();
137 }
138
139 static LayerPtrType passLayerPtr(LayerPtrType& layer)
140 {
141 return layer.release();
142 }
[email protected]d58499a2012-10-09 22:27:47143
144 static void destroyLayer(LayerPtrType& layer)
145 {
146 layer = NULL;
147 }
[email protected]94f206c12012-08-25 00:09:14148};
149
[email protected]96baf3e2012-10-22 23:09:55150struct OcclusionTrackerTestImplThreadTypes {
151 typedef LayerImpl LayerType;
152 typedef RenderSurfaceImpl RenderSurfaceType;
[email protected]94f206c12012-08-25 00:09:14153 typedef TestContentLayerImpl ContentLayerType;
[email protected]96baf3e2012-10-22 23:09:55154 typedef scoped_ptr<LayerImpl> LayerPtrType;
[email protected]e0bd43a2012-10-12 16:54:21155 typedef scoped_ptr<ContentLayerType> ContentLayerPtrType;
[email protected]96baf3e2012-10-22 23:09:55156 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> TestLayerIterator;
157 typedef OcclusionTrackerImpl OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14158
[email protected]96baf3e2012-10-22 23:09:55159 static LayerPtrType createLayer() { return LayerImpl::create(nextLayerImplId++); }
160 static ContentLayerPtrType createContentLayer() { return make_scoped_ptr(new ContentLayerType(nextLayerImplId++)); }
161 static int nextLayerImplId;
[email protected]d58499a2012-10-09 22:27:47162
[email protected]e0bd43a2012-10-12 16:54:21163 static LayerPtrType passLayerPtr(LayerPtrType& layer)
164 {
165 return layer.Pass();
166 }
167
168 static LayerPtrType passLayerPtr(ContentLayerPtrType& layer)
169 {
170 return layer.PassAs<LayerType>();
171 }
172
[email protected]d58499a2012-10-09 22:27:47173 static void destroyLayer(LayerPtrType& layer)
174 {
[email protected]e0bd43a2012-10-12 16:54:21175 layer.reset();
[email protected]d58499a2012-10-09 22:27:47176 }
[email protected]94f206c12012-08-25 00:09:14177};
178
[email protected]96baf3e2012-10-22 23:09:55179int OcclusionTrackerTestImplThreadTypes::nextLayerImplId = 1;
[email protected]94f206c12012-08-25 00:09:14180
[email protected]ece1d952012-10-18 21:26:07181template<typename Types>
[email protected]96baf3e2012-10-22 23:09:55182class OcclusionTrackerTest : public testing::Test {
[email protected]94f206c12012-08-25 00:09:14183protected:
[email protected]96baf3e2012-10-22 23:09:55184 OcclusionTrackerTest(bool opaqueLayers)
[email protected]ece1d952012-10-18 21:26:07185 : m_opaqueLayers(opaqueLayers)
[email protected]94f206c12012-08-25 00:09:14186 { }
187
188 virtual void runMyTest() = 0;
189
190 virtual void TearDown()
191 {
[email protected]d58499a2012-10-09 22:27:47192 Types::destroyLayer(m_root);
[email protected]96baf3e2012-10-22 23:09:55193 m_renderSurfaceLayerList.clear();
[email protected]94f206c12012-08-25 00:09:14194 m_renderSurfaceLayerListImpl.clear();
195 m_replicaLayers.clear();
196 m_maskLayers.clear();
[email protected]96baf3e2012-10-22 23:09:55197 LayerTreeHost::setNeedsFilterContext(false);
[email protected]94f206c12012-08-25 00:09:14198 }
199
[email protected]d0f98362012-11-01 23:02:38200 typename Types::ContentLayerType* createRoot(const WebTransformationMatrix& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14201 {
202 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
203 typename Types::ContentLayerType* layerPtr = layer.get();
204 setProperties(layerPtr, transform, position, bounds);
205
[email protected]1d993172012-10-18 18:15:04206 DCHECK(!m_root);
[email protected]e0bd43a2012-10-12 16:54:21207 m_root = Types::passLayerPtr(layer);
[email protected]94f206c12012-08-25 00:09:14208 return layerPtr;
209 }
210
[email protected]d0f98362012-11-01 23:02:38211 typename Types::LayerType* createLayer(typename Types::LayerType* parent, const WebTransformationMatrix& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14212 {
213 typename Types::LayerPtrType layer(Types::createLayer());
214 typename Types::LayerType* layerPtr = layer.get();
215 setProperties(layerPtr, transform, position, bounds);
[email protected]e0bd43a2012-10-12 16:54:21216 parent->addChild(Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14217 return layerPtr;
218 }
219
[email protected]d0f98362012-11-01 23:02:38220 typename Types::LayerType* createSurface(typename Types::LayerType* parent, const WebTransformationMatrix& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14221 {
222 typename Types::LayerType* layer = createLayer(parent, transform, position, bounds);
223 WebFilterOperations filters;
224 filters.append(WebFilterOperation::createGrayscaleFilter(0.5));
225 layer->setFilters(filters);
226 return layer;
227 }
228
[email protected]d0f98362012-11-01 23:02:38229 typename Types::ContentLayerType* createDrawingLayer(typename Types::LayerType* parent, const WebTransformationMatrix& transform, const gfx::PointF& position, const gfx::Size& bounds, bool opaque)
[email protected]94f206c12012-08-25 00:09:14230 {
231 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
232 typename Types::ContentLayerType* layerPtr = layer.get();
233 setProperties(layerPtr, transform, position, bounds);
234
[email protected]ece1d952012-10-18 21:26:07235 if (m_opaqueLayers)
[email protected]048634c2012-10-02 22:33:14236 layerPtr->setContentsOpaque(opaque);
[email protected]94f206c12012-08-25 00:09:14237 else {
[email protected]048634c2012-10-02 22:33:14238 layerPtr->setContentsOpaque(false);
[email protected]94f206c12012-08-25 00:09:14239 if (opaque)
[email protected]aad0a0072012-11-01 18:15:58240 layerPtr->setOpaqueContentsRect(gfx::Rect(gfx::Point(), bounds));
[email protected]94f206c12012-08-25 00:09:14241 else
[email protected]aad0a0072012-11-01 18:15:58242 layerPtr->setOpaqueContentsRect(gfx::Rect());
[email protected]94f206c12012-08-25 00:09:14243 }
244
[email protected]e0bd43a2012-10-12 16:54:21245 parent->addChild(Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14246 return layerPtr;
247 }
248
[email protected]d0f98362012-11-01 23:02:38249 typename Types::LayerType* createReplicaLayer(typename Types::LayerType* owningLayer, const WebTransformationMatrix& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14250 {
251 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
252 typename Types::ContentLayerType* layerPtr = layer.get();
253 setProperties(layerPtr, transform, position, bounds);
[email protected]e0bd43a2012-10-12 16:54:21254 setReplica(owningLayer, Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14255 return layerPtr;
256 }
257
[email protected]aad0a0072012-11-01 18:15:58258 typename Types::LayerType* createMaskLayer(typename Types::LayerType* owningLayer, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14259 {
260 typename Types::ContentLayerPtrType layer(Types::createContentLayer());
261 typename Types::ContentLayerType* layerPtr = layer.get();
[email protected]d0f98362012-11-01 23:02:38262 setProperties(layerPtr, identityMatrix, gfx::PointF(), bounds);
[email protected]e0bd43a2012-10-12 16:54:21263 setMask(owningLayer, Types::passLayerPtr(layer));
[email protected]94f206c12012-08-25 00:09:14264 return layerPtr;
265 }
266
[email protected]d0f98362012-11-01 23:02:38267 typename Types::ContentLayerType* createDrawingSurface(typename Types::LayerType* parent, const WebTransformationMatrix& transform, const gfx::PointF& position, const gfx::Size& bounds, bool opaque)
[email protected]94f206c12012-08-25 00:09:14268 {
269 typename Types::ContentLayerType* layer = createDrawingLayer(parent, transform, position, bounds, opaque);
270 WebFilterOperations filters;
271 filters.append(WebFilterOperation::createGrayscaleFilter(0.5));
272 layer->setFilters(filters);
273 return layer;
274 }
275
276 void calcDrawEtc(TestContentLayerImpl* root)
277 {
[email protected]1d993172012-10-18 18:15:04278 DCHECK(root == m_root.get());
[email protected]94f206c12012-08-25 00:09:14279 int dummyMaxTextureSize = 512;
[email protected]96baf3e2012-10-22 23:09:55280 LayerSorter layerSorter;
[email protected]94f206c12012-08-25 00:09:14281
[email protected]1d993172012-10-18 18:15:04282 DCHECK(!root->renderSurface());
[email protected]94f206c12012-08-25 00:09:14283
[email protected]518ee582012-10-24 18:29:44284 LayerTreeHostCommon::calculateDrawTransforms(root, root->bounds(), 1, 1, &layerSorter, dummyMaxTextureSize, m_renderSurfaceLayerListImpl);
[email protected]94f206c12012-08-25 00:09:14285
[email protected]96baf3e2012-10-22 23:09:55286 m_layerIterator = m_layerIteratorBegin = Types::TestLayerIterator::begin(&m_renderSurfaceLayerListImpl);
[email protected]94f206c12012-08-25 00:09:14287 }
288
[email protected]96baf3e2012-10-22 23:09:55289 void calcDrawEtc(TestContentLayer* root)
[email protected]94f206c12012-08-25 00:09:14290 {
[email protected]1d993172012-10-18 18:15:04291 DCHECK(root == m_root.get());
[email protected]94f206c12012-08-25 00:09:14292 int dummyMaxTextureSize = 512;
293
[email protected]1d993172012-10-18 18:15:04294 DCHECK(!root->renderSurface());
[email protected]94f206c12012-08-25 00:09:14295
[email protected]518ee582012-10-24 18:29:44296 LayerTreeHostCommon::calculateDrawTransforms(root, root->bounds(), 1, 1, dummyMaxTextureSize, m_renderSurfaceLayerList);
[email protected]94f206c12012-08-25 00:09:14297
[email protected]96baf3e2012-10-22 23:09:55298 m_layerIterator = m_layerIteratorBegin = Types::TestLayerIterator::begin(&m_renderSurfaceLayerList);
[email protected]94f206c12012-08-25 00:09:14299 }
300
301 void enterLayer(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
302 {
303 ASSERT_EQ(layer, *m_layerIterator);
304 ASSERT_TRUE(m_layerIterator.representsItself());
305 occlusion.enterLayer(m_layerIterator);
306 }
307
308 void leaveLayer(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
309 {
310 ASSERT_EQ(layer, *m_layerIterator);
311 ASSERT_TRUE(m_layerIterator.representsItself());
312 occlusion.leaveLayer(m_layerIterator);
313 ++m_layerIterator;
314 }
315
316 void visitLayer(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
317 {
318 enterLayer(layer, occlusion);
319 leaveLayer(layer, occlusion);
320 }
321
322 void enterContributingSurface(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
323 {
324 ASSERT_EQ(layer, *m_layerIterator);
325 ASSERT_TRUE(m_layerIterator.representsTargetRenderSurface());
326 occlusion.enterLayer(m_layerIterator);
327 occlusion.leaveLayer(m_layerIterator);
328 ++m_layerIterator;
329 ASSERT_TRUE(m_layerIterator.representsContributingRenderSurface());
330 occlusion.enterLayer(m_layerIterator);
331 }
332
333 void leaveContributingSurface(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
334 {
335 ASSERT_EQ(layer, *m_layerIterator);
336 ASSERT_TRUE(m_layerIterator.representsContributingRenderSurface());
337 occlusion.leaveLayer(m_layerIterator);
338 ++m_layerIterator;
339 }
340
341 void visitContributingSurface(typename Types::LayerType* layer, typename Types::OcclusionTrackerType& occlusion)
342 {
343 enterContributingSurface(layer, occlusion);
344 leaveContributingSurface(layer, occlusion);
345 }
346
347 void resetLayerIterator()
348 {
349 m_layerIterator = m_layerIteratorBegin;
350 }
351
352 const WebTransformationMatrix identityMatrix;
353
354private:
[email protected]d0f98362012-11-01 23:02:38355 void setBaseProperties(typename Types::LayerType* layer, const WebTransformationMatrix& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14356 {
357 layer->setTransform(transform);
358 layer->setSublayerTransform(WebTransformationMatrix());
[email protected]d0f98362012-11-01 23:02:38359 layer->setAnchorPoint(gfx::PointF(0, 0));
[email protected]94f206c12012-08-25 00:09:14360 layer->setPosition(position);
361 layer->setBounds(bounds);
362 }
363
[email protected]d0f98362012-11-01 23:02:38364 void setProperties(Layer* layer, const WebTransformationMatrix& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14365 {
366 setBaseProperties(layer, transform, position, bounds);
367 }
368
[email protected]d0f98362012-11-01 23:02:38369 void setProperties(LayerImpl* layer, const WebTransformationMatrix& transform, const gfx::PointF& position, const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14370 {
371 setBaseProperties(layer, transform, position, bounds);
372
373 layer->setContentBounds(layer->bounds());
374 }
375
[email protected]96baf3e2012-10-22 23:09:55376 void setReplica(Layer* owningLayer, scoped_refptr<Layer> layer)
[email protected]94f206c12012-08-25 00:09:14377 {
378 owningLayer->setReplicaLayer(layer.get());
[email protected]d58499a2012-10-09 22:27:47379 m_replicaLayers.push_back(layer);
[email protected]94f206c12012-08-25 00:09:14380 }
381
[email protected]96baf3e2012-10-22 23:09:55382 void setReplica(LayerImpl* owningLayer, scoped_ptr<LayerImpl> layer)
[email protected]94f206c12012-08-25 00:09:14383 {
[email protected]e0bd43a2012-10-12 16:54:21384 owningLayer->setReplicaLayer(layer.Pass());
[email protected]94f206c12012-08-25 00:09:14385 }
386
[email protected]96baf3e2012-10-22 23:09:55387 void setMask(Layer* owningLayer, scoped_refptr<Layer> layer)
[email protected]94f206c12012-08-25 00:09:14388 {
389 owningLayer->setMaskLayer(layer.get());
[email protected]d58499a2012-10-09 22:27:47390 m_maskLayers.push_back(layer);
[email protected]94f206c12012-08-25 00:09:14391 }
392
[email protected]96baf3e2012-10-22 23:09:55393 void setMask(LayerImpl* owningLayer, scoped_ptr<LayerImpl> layer)
[email protected]94f206c12012-08-25 00:09:14394 {
[email protected]e0bd43a2012-10-12 16:54:21395 owningLayer->setMaskLayer(layer.Pass());
[email protected]94f206c12012-08-25 00:09:14396 }
397
[email protected]ece1d952012-10-18 21:26:07398 bool m_opaqueLayers;
[email protected]94f206c12012-08-25 00:09:14399 // These hold ownership of the layers for the duration of the test.
400 typename Types::LayerPtrType m_root;
[email protected]96baf3e2012-10-22 23:09:55401 std::vector<scoped_refptr<Layer> > m_renderSurfaceLayerList;
402 std::vector<LayerImpl*> m_renderSurfaceLayerListImpl;
403 typename Types::TestLayerIterator m_layerIteratorBegin;
404 typename Types::TestLayerIterator m_layerIterator;
[email protected]94f206c12012-08-25 00:09:14405 typename Types::LayerType* m_lastLayerVisited;
[email protected]96baf3e2012-10-22 23:09:55406 std::vector<scoped_refptr<Layer> > m_replicaLayers;
407 std::vector<scoped_refptr<Layer> > m_maskLayers;
[email protected]94f206c12012-08-25 00:09:14408};
409
410#define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55411 class ClassName##MainThreadOpaqueLayers : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14412 public: \
[email protected]96baf3e2012-10-22 23:09:55413 ClassName##MainThreadOpaqueLayers() : ClassName<OcclusionTrackerTestMainThreadTypes>(true) { } \
[email protected]94f206c12012-08-25 00:09:14414 }; \
415 TEST_F(ClassName##MainThreadOpaqueLayers, runTest) { runMyTest(); }
416#define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55417 class ClassName##MainThreadOpaquePaints : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14418 public: \
[email protected]96baf3e2012-10-22 23:09:55419 ClassName##MainThreadOpaquePaints() : ClassName<OcclusionTrackerTestMainThreadTypes>(false) { } \
[email protected]94f206c12012-08-25 00:09:14420 }; \
421 TEST_F(ClassName##MainThreadOpaquePaints, runTest) { runMyTest(); }
422
423#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55424 class ClassName##ImplThreadOpaqueLayers : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14425 public: \
[email protected]96baf3e2012-10-22 23:09:55426 ClassName##ImplThreadOpaqueLayers() : ClassName<OcclusionTrackerTestImplThreadTypes>(true) { } \
[email protected]94f206c12012-08-25 00:09:14427 }; \
428 TEST_F(ClassName##ImplThreadOpaqueLayers, runTest) { runMyTest(); }
429#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]96baf3e2012-10-22 23:09:55430 class ClassName##ImplThreadOpaquePaints : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
[email protected]94f206c12012-08-25 00:09:14431 public: \
[email protected]96baf3e2012-10-22 23:09:55432 ClassName##ImplThreadOpaquePaints() : ClassName<OcclusionTrackerTestImplThreadTypes>(false) { } \
[email protected]94f206c12012-08-25 00:09:14433 }; \
434 TEST_F(ClassName##ImplThreadOpaquePaints, runTest) { runMyTest(); }
435
[email protected]96baf3e2012-10-22 23:09:55436#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
[email protected]94f206c12012-08-25 00:09:14437 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
438 RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
439 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
440 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
441
442#define MAIN_THREAD_TEST(ClassName) \
[email protected]f3922f22012-10-12 09:20:38443 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14444
445#define IMPL_THREAD_TEST(ClassName) \
[email protected]f3922f22012-10-12 09:20:38446 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14447
448#define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
449 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]f3922f22012-10-12 09:20:38450 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14451
[email protected]ece1d952012-10-18 21:26:07452template<class Types>
[email protected]96baf3e2012-10-22 23:09:55453class OcclusionTrackerTestIdentityTransforms : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14454protected:
[email protected]96baf3e2012-10-22 23:09:55455 OcclusionTrackerTestIdentityTransforms(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]ece1d952012-10-18 21:26:07456
[email protected]94f206c12012-08-25 00:09:14457 void runMyTest()
458 {
[email protected]d0f98362012-11-01 23:02:38459 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
460 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:14461 this->calcDrawEtc(parent);
462
[email protected]167ed9d52012-10-31 20:47:58463 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
464 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14465
466 this->visitLayer(layer, occlusion);
467 this->enterLayer(parent, occlusion);
468
[email protected]ac7c7f52012-11-08 06:26:50469 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
470 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14471
[email protected]167ed9d52012-10-31 20:47:58472 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
473 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
474 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
475 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
476 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14477
478 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58479 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
480 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
481 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
482 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
483 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
484 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14485
[email protected]167ed9d52012-10-31 20:47:58486 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
487 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 30, 70, 70)));
488 EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 29, 70, 70)));
489 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 29, 70, 70)));
490 EXPECT_RECT_EQ(gfx::Rect(31, 29, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 29, 70, 70)));
491 EXPECT_RECT_EQ(gfx::Rect(100, 30, 1, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 30, 70, 70)));
492 EXPECT_RECT_EQ(gfx::Rect(31, 31, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 31, 70, 70)));
493 EXPECT_RECT_EQ(gfx::Rect(30, 100, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 31, 70, 70)));
494 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:14495 }
496};
497
[email protected]96baf3e2012-10-22 23:09:55498ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14499
[email protected]ece1d952012-10-18 21:26:07500template<class Types>
[email protected]710ffc02012-10-30 21:42:02501class OcclusionTrackerTestQuadsMismatchLayer : public OcclusionTrackerTest<Types> {
502protected:
503 OcclusionTrackerTestQuadsMismatchLayer(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
504 void runMyTest()
505 {
506 WebTransformationMatrix layerTransform;
507 layerTransform.translate(10, 10);
508
[email protected]d0f98362012-11-01 23:02:38509 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::Point(0, 0), gfx::Size(100, 100));
510 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(parent, layerTransform, gfx::PointF(0, 0), gfx::Size(90, 90), true);
511 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(layer1, layerTransform, gfx::PointF(0, 0), gfx::Size(50, 50), true);
[email protected]710ffc02012-10-30 21:42:02512 this->calcDrawEtc(parent);
513
[email protected]167ed9d52012-10-31 20:47:58514 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02515
516 this->visitLayer(layer2, occlusion);
517 this->enterLayer(layer1, occlusion);
518
[email protected]ac7c7f52012-11-08 06:26:50519 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
520 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]710ffc02012-10-30 21:42:02521
522 // This checks cases where the quads don't match their "containing"
523 // layers, e.g. in terms of transforms or clip rect. This is typical for
524 // DelegatedRendererLayer.
525
526 WebTransformationMatrix quadTransform;
527 quadTransform.translate(30, 30);
[email protected]167ed9d52012-10-31 20:47:58528 gfx::Rect clipRectInTarget(0, 0, 100, 100);
[email protected]710ffc02012-10-30 21:42:02529
[email protected]167ed9d52012-10-31 20:47:58530 EXPECT_TRUE(occlusion.unoccludedContentRect(parent, gfx::Rect(0, 0, 10, 10), quadTransform, false, clipRectInTarget).IsEmpty());
531 EXPECT_RECT_EQ(gfx::Rect(0, 0, 10, 10), occlusion.unoccludedContentRect(parent, gfx::Rect(0, 0, 10, 10), quadTransform, true, clipRectInTarget));
532 EXPECT_RECT_EQ(gfx::Rect(40, 40, 10, 10), occlusion.unoccludedContentRect(parent, gfx::Rect(40, 40, 10, 10), quadTransform, false, clipRectInTarget));
533 EXPECT_RECT_EQ(gfx::Rect(40, 30, 5, 10), occlusion.unoccludedContentRect(parent, gfx::Rect(35, 30, 10, 10), quadTransform, false, clipRectInTarget));
534 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:02535 }
536};
537
538ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestQuadsMismatchLayer);
539
540template<class Types>
[email protected]96baf3e2012-10-22 23:09:55541class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14542protected:
[email protected]96baf3e2012-10-22 23:09:55543 OcclusionTrackerTestRotatedChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14544 void runMyTest()
545 {
546 WebTransformationMatrix layerTransform;
547 layerTransform.translate(250, 250);
548 layerTransform.rotate(90);
549 layerTransform.translate(-250, -250);
550
[email protected]d0f98362012-11-01 23:02:38551 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
552 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:14553 this->calcDrawEtc(parent);
554
[email protected]167ed9d52012-10-31 20:47:58555 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
556 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14557
558 this->visitLayer(layer, occlusion);
559 this->enterLayer(parent, occlusion);
560
[email protected]ac7c7f52012-11-08 06:26:50561 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
562 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14563
[email protected]167ed9d52012-10-31 20:47:58564 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
565 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
566 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
567 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
568 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14569
570 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58571 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
572 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
573 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
574 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
575 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
576 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14577
[email protected]167ed9d52012-10-31 20:47:58578 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
579 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 30, 70, 70)));
580 EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 29, 70, 70)));
581 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 29, 70, 70)));
582 EXPECT_RECT_EQ(gfx::Rect(31, 29, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 29, 70, 70)));
583 EXPECT_RECT_EQ(gfx::Rect(100, 30, 1, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 30, 70, 70)));
584 EXPECT_RECT_EQ(gfx::Rect(31, 31, 70, 70), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 31, 70, 70)));
585 EXPECT_RECT_EQ(gfx::Rect(30, 100, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 31, 70, 70)));
586 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:14587 }
588};
589
[email protected]96baf3e2012-10-22 23:09:55590ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14591
[email protected]ece1d952012-10-18 21:26:07592template<class Types>
[email protected]96baf3e2012-10-22 23:09:55593class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14594protected:
[email protected]96baf3e2012-10-22 23:09:55595 OcclusionTrackerTestTranslatedChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14596 void runMyTest()
597 {
598 WebTransformationMatrix layerTransform;
599 layerTransform.translate(20, 20);
600
[email protected]d0f98362012-11-01 23:02:38601 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
602 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:14603 this->calcDrawEtc(parent);
604
[email protected]167ed9d52012-10-31 20:47:58605 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
606 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14607
608 this->visitLayer(layer, occlusion);
609 this->enterLayer(parent, occlusion);
610
[email protected]ac7c7f52012-11-08 06:26:50611 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
612 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14613
[email protected]167ed9d52012-10-31 20:47:58614 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(50, 50, 50, 50)));
615 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(49, 50, 50, 50)));
616 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(50, 49, 50, 50)));
617 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(51, 50, 50, 50)));
618 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(50, 51, 50, 50)));
[email protected]94f206c12012-08-25 00:09:14619
620 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58621 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(50, 50, 50, 50)));
622 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(49, 50, 50, 50)));
623 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(50, 49, 50, 50)));
624 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(51, 50, 50, 50)));
625 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(50, 51, 50, 50)));
626 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14627
[email protected]167ed9d52012-10-31 20:47:58628 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 50, 50, 50)).IsEmpty());
629 EXPECT_RECT_EQ(gfx::Rect(49, 50, 1, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 50, 50, 50)));
630 EXPECT_RECT_EQ(gfx::Rect(49, 49, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 49, 50, 50)));
631 EXPECT_RECT_EQ(gfx::Rect(50, 49, 50, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 49, 50, 50)));
632 EXPECT_RECT_EQ(gfx::Rect(51, 49, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 49, 50, 50)));
633 EXPECT_RECT_EQ(gfx::Rect(100, 50, 1, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 50, 50, 50)));
634 EXPECT_RECT_EQ(gfx::Rect(51, 51, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 51, 50, 50)));
635 EXPECT_RECT_EQ(gfx::Rect(50, 100, 50, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 51, 50, 50)));
636 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:14637
638 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58639 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 50, 50, 50)).IsEmpty());
640 EXPECT_RECT_EQ(gfx::Rect(49, 50, 1, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 50, 50, 50)));
641 EXPECT_RECT_EQ(gfx::Rect(49, 49, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 49, 50, 50)));
642 EXPECT_RECT_EQ(gfx::Rect(50, 49, 50, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 49, 50, 50)));
643 EXPECT_RECT_EQ(gfx::Rect(51, 49, 49, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 49, 50, 50)));
644 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 50, 50, 50)).IsEmpty());
645 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(51, 51, 50, 50)).IsEmpty());
646 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(50, 51, 50, 50)).IsEmpty());
647 EXPECT_RECT_EQ(gfx::Rect(49, 51, 1, 49), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(49, 51, 50, 50)));
648 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14649 }
650};
651
[email protected]96baf3e2012-10-22 23:09:55652ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14653
[email protected]ece1d952012-10-18 21:26:07654template<class Types>
[email protected]96baf3e2012-10-22 23:09:55655class OcclusionTrackerTestChildInRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14656protected:
[email protected]96baf3e2012-10-22 23:09:55657 OcclusionTrackerTestChildInRotatedChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14658 void runMyTest()
659 {
660 WebTransformationMatrix childTransform;
661 childTransform.translate(250, 250);
662 childTransform.rotate(90);
663 childTransform.translate(-250, -250);
664
[email protected]d0f98362012-11-01 23:02:38665 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:38666 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38667 typename Types::LayerType* child = this->createLayer(parent, childTransform, gfx::PointF(30, 30), gfx::Size(500, 500));
[email protected]94f206c12012-08-25 00:09:14668 child->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38669 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:14670 this->calcDrawEtc(parent);
671
[email protected]167ed9d52012-10-31 20:47:58672 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
673 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14674
675 this->visitLayer(layer, occlusion);
676 this->enterContributingSurface(child, occlusion);
677
[email protected]ac7c7f52012-11-08 06:26:50678 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
679 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14680
681 this->leaveContributingSurface(child, occlusion);
682 this->enterLayer(parent, occlusion);
683
[email protected]ac7c7f52012-11-08 06:26:50684 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
685 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14686
[email protected]167ed9d52012-10-31 20:47:58687 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
688 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
689 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
690 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(31, 40, 70, 60)));
691 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 41, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14692
693 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:58694 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
695 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
696 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
697 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(31, 40, 70, 60)));
698 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 41, 70, 60)));
699 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14700
701
702 /* Justification for the above occlusion from |layer|:
703 100
704 +---------------------+ +---------------------+
705 | | | |30 Visible region of |layer|: /////
706 | 30 | rotate(90) | |
707 | 30 + ---------------------------------+ | +---------------------------------+
708 100 | | 10 | | ==> | | |10 |
709 | |10+---------------------------------+ | +---------------------------------+ |
710 | | | | | | | | |///////////////| 420 | |
711 | | | | | | | | |///////////////|60 | |
712 | | | | | | | | |///////////////| | |
713 +----|--|-------------+ | | +--|--|---------------+ | |
714 | | | | 20|10| 70 | |
715 | | | | | | | |
716 | | | |500 | | | |
717 | | | | | | | |
718 | | | | | | | |
719 | | | | | | | |
720 | | | | | | |10|
721 +--|-------------------------------+ | | +------------------------------|--+
722 | | | 490 |
723 +---------------------------------+ +---------------------------------+
724 500 500
725 */
726 }
727};
728
[email protected]96baf3e2012-10-22 23:09:55729ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14730
[email protected]ece1d952012-10-18 21:26:07731template<class Types>
[email protected]710ffc02012-10-30 21:42:02732class OcclusionTrackerTestScaledRenderSurface : public OcclusionTrackerTest<Types> {
733protected:
734 OcclusionTrackerTestScaledRenderSurface(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
735
736 void runMyTest()
737 {
[email protected]d0f98362012-11-01 23:02:38738 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02739
740 WebTransformationMatrix layer1Matrix;
741 layer1Matrix.scale(2);
[email protected]d0f98362012-11-01 23:02:38742 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(parent, layer1Matrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
[email protected]710ffc02012-10-30 21:42:02743 layer1->setForceRenderSurface(true);
744
745 WebTransformationMatrix layer2Matrix;
746 layer2Matrix.translate(25, 25);
[email protected]d0f98362012-11-01 23:02:38747 typename Types::ContentLayerType* layer2 = this->createDrawingLayer(layer1, layer2Matrix, gfx::PointF(0, 0), gfx::Size(50, 50), true);
748 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:02749 this->calcDrawEtc(parent);
750
[email protected]167ed9d52012-10-31 20:47:58751 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02752
753 this->visitLayer(occluder, occlusion);
754 this->enterLayer(layer2, occlusion);
755
[email protected]ac7c7f52012-11-08 06:26:50756 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), occlusion.occlusionInScreenSpace().ToString());
757 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]710ffc02012-10-30 21:42:02758
[email protected]167ed9d52012-10-31 20:47:58759 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), occlusion.unoccludedLayerContentRect(layer2, gfx::Rect(0, 0, 25, 25)));
760 EXPECT_RECT_EQ(gfx::Rect(10, 25, 15, 25), occlusion.unoccludedLayerContentRect(layer2, gfx::Rect(10, 25, 25, 25)));
761 EXPECT_RECT_EQ(gfx::Rect(25, 10, 25, 15), occlusion.unoccludedLayerContentRect(layer2, gfx::Rect(25, 10, 25, 25)));
762 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(layer2, gfx::Rect(25, 25, 25, 25)).IsEmpty());
[email protected]710ffc02012-10-30 21:42:02763 }
764};
765
766ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
767
768template<class Types>
[email protected]96baf3e2012-10-22 23:09:55769class OcclusionTrackerTestVisitTargetTwoTimes : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14770protected:
[email protected]96baf3e2012-10-22 23:09:55771 OcclusionTrackerTestVisitTargetTwoTimes(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14772 void runMyTest()
773 {
774 WebTransformationMatrix childTransform;
775 childTransform.translate(250, 250);
776 childTransform.rotate(90);
777 childTransform.translate(-250, -250);
778
[email protected]d0f98362012-11-01 23:02:38779 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:38780 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38781 typename Types::LayerType* child = this->createLayer(parent, childTransform, gfx::PointF(30, 30), gfx::Size(500, 500));
[email protected]94f206c12012-08-25 00:09:14782 child->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38783 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:55784 // |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:14785 // leaveToTargetRenderSurface, as the target surface has already been seen.
[email protected]d0f98362012-11-01 23:02:38786 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:14787 this->calcDrawEtc(parent);
788
[email protected]167ed9d52012-10-31 20:47:58789 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
790 occlusion.setLayerClipRect(gfx::Rect(-10, -10, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14791
792 this->visitLayer(child2, occlusion);
793
[email protected]ac7c7f52012-11-08 06:26:50794 EXPECT_EQ(gfx::Rect(30, 30, 60, 20).ToString(), occlusion.occlusionInScreenSpace().ToString());
795 EXPECT_EQ(gfx::Rect(30, 30, 60, 20).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14796
797 this->visitLayer(layer, occlusion);
798
[email protected]ac7c7f52012-11-08 06:26:50799 EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60)).ToString(), occlusion.occlusionInScreenSpace().ToString());
800 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14801
802 this->enterContributingSurface(child, occlusion);
803
[email protected]ac7c7f52012-11-08 06:26:50804 EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60)).ToString(), occlusion.occlusionInScreenSpace().ToString());
805 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14806
807 // Occlusion in |child2| should get merged with the |child| surface we are leaving now.
808 this->leaveContributingSurface(child, occlusion);
809 this->enterLayer(parent, occlusion);
810
[email protected]ac7c7f52012-11-08 06:26:50811 EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60)).ToString(), occlusion.occlusionInScreenSpace().ToString());
812 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:14813
[email protected]167ed9d52012-10-31 20:47:58814 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
815 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:14816
[email protected]167ed9d52012-10-31 20:47:58817 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 30, 60, 10)));
818 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 30, 60, 10)));
819 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 29, 60, 10)));
820 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(31, 30, 60, 10)));
821 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 31, 60, 10)));
[email protected]94f206c12012-08-25 00:09:14822
[email protected]167ed9d52012-10-31 20:47:58823 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
824 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
825 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14826
[email protected]167ed9d52012-10-31 20:47:58827 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 30, 60, 10)).IsEmpty());
828 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 10), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 30, 60, 10)));
829 EXPECT_RECT_EQ(gfx::Rect(30, 29, 60, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 29, 60, 10)));
830 EXPECT_RECT_EQ(gfx::Rect(90, 30, 1, 10), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 30, 60, 10)));
831 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 31, 60, 10)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:14832
[email protected]167ed9d52012-10-31 20:47:58833 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
834 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:14835 // This rect is mostly occluded by |child2|.
[email protected]167ed9d52012-10-31 20:47:58836 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:14837 // This rect extends past top/right ends of |child2|.
[email protected]167ed9d52012-10-31 20:47:58838 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:14839 // This rect extends past left/right ends of |child2|.
[email protected]167ed9d52012-10-31 20:47:58840 EXPECT_RECT_EQ(gfx::Rect(20, 39, 80, 60), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(20, 39, 80, 60)));
841 EXPECT_RECT_EQ(gfx::Rect(100, 40, 1, 60), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 40, 70, 60)));
842 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:14843
844 /* Justification for the above occlusion from |layer|:
845 100
846 +---------------------+ +---------------------+
847 | | | |30 Visible region of |layer|: /////
848 | 30 | rotate(90) | 30 60 | |child2|: \\\\\
849 | 30 + ------------+--------------------+ | 30 +------------+--------------------+
850 100 | | 10 | | | ==> | |\\\\\\\\\\\\| |10 |
851 | |10+----------|----------------------+ | +--|\\\\\\\\\\\\|-----------------+ |
852 | + ------------+ | | | | | +------------+//| 420 | |
853 | | | | | | | | |///////////////|60 | |
854 | | | | | | | | |///////////////| | |
855 +----|--|-------------+ | | +--|--|---------------+ | |
856 | | | | 20|10| 70 | |
857 | | | | | | | |
858 | | | |500 | | | |
859 | | | | | | | |
860 | | | | | | | |
861 | | | | | | | |
862 | | | | | | |10|
863 +--|-------------------------------+ | | +------------------------------|--+
864 | | | 490 |
865 +---------------------------------+ +---------------------------------+
866 500 500
867 */
868 }
869};
870
[email protected]96baf3e2012-10-22 23:09:55871ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:14872
[email protected]ece1d952012-10-18 21:26:07873template<class Types>
[email protected]96baf3e2012-10-22 23:09:55874class OcclusionTrackerTestSurfaceRotatedOffAxis : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14875protected:
[email protected]96baf3e2012-10-22 23:09:55876 OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14877 void runMyTest()
878 {
879 WebTransformationMatrix childTransform;
880 childTransform.translate(250, 250);
881 childTransform.rotate(95);
882 childTransform.translate(-250, -250);
883
884 WebTransformationMatrix layerTransform;
885 layerTransform.translate(10, 10);
886
[email protected]d0f98362012-11-01 23:02:38887 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
888 typename Types::LayerType* child = this->createLayer(parent, childTransform, gfx::PointF(30, 30), gfx::Size(500, 500));
[email protected]94f206c12012-08-25 00:09:14889 child->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38890 typename Types::ContentLayerType* layer = this->createDrawingLayer(child, layerTransform, gfx::PointF(0, 0), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:14891 this->calcDrawEtc(parent);
892
[email protected]167ed9d52012-10-31 20:47:58893 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
894 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14895
[email protected]167ed9d52012-10-31 20:47:58896 gfx::Rect clippedLayerInChild = MathUtil::mapClippedRect(layerTransform, layer->visibleContentRect());
[email protected]94f206c12012-08-25 00:09:14897
898 this->visitLayer(layer, occlusion);
899 this->enterContributingSurface(child, occlusion);
900
[email protected]ac7c7f52012-11-08 06:26:50901 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInScreenSpace().ToString());
902 EXPECT_EQ(clippedLayerInChild.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14903
[email protected]710ffc02012-10-30 21:42:02904 EXPECT_TRUE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58905 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19906 clippedLayerInChild += gfx::Vector2d(-1, 0);
[email protected]710ffc02012-10-30 21:42:02907 EXPECT_FALSE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58908 EXPECT_FALSE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19909 clippedLayerInChild += gfx::Vector2d(1, 0);
910 clippedLayerInChild += gfx::Vector2d(1, 0);
[email protected]710ffc02012-10-30 21:42:02911 EXPECT_FALSE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58912 EXPECT_FALSE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19913 clippedLayerInChild += gfx::Vector2d(-1, 0);
914 clippedLayerInChild += gfx::Vector2d(0, -1);
[email protected]710ffc02012-10-30 21:42:02915 EXPECT_FALSE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58916 EXPECT_FALSE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19917 clippedLayerInChild += gfx::Vector2d(0, 1);
918 clippedLayerInChild += gfx::Vector2d(0, 1);
[email protected]710ffc02012-10-30 21:42:02919 EXPECT_FALSE(occlusion.occludedLayer(child, clippedLayerInChild));
[email protected]167ed9d52012-10-31 20:47:58920 EXPECT_FALSE(occlusion.unoccludedLayerContentRect(child, clippedLayerInChild).IsEmpty());
[email protected]2e6486012012-11-10 00:03:19921 clippedLayerInChild += gfx::Vector2d(0, -1);
[email protected]94f206c12012-08-25 00:09:14922
923 this->leaveContributingSurface(child, occlusion);
924 this->enterLayer(parent, occlusion);
925
[email protected]ac7c7f52012-11-08 06:26:50926 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInScreenSpace().ToString());
927 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14928
[email protected]167ed9d52012-10-31 20:47:58929 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(75, 55, 1, 1)));
930 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:14931 }
932};
933
[email protected]96baf3e2012-10-22 23:09:55934ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:14935
[email protected]ece1d952012-10-18 21:26:07936template<class Types>
[email protected]96baf3e2012-10-22 23:09:55937class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:14938protected:
[email protected]96baf3e2012-10-22 23:09:55939 OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:14940 void runMyTest()
941 {
942 WebTransformationMatrix childTransform;
943 childTransform.translate(250, 250);
944 childTransform.rotate(90);
945 childTransform.translate(-250, -250);
946
[email protected]d0f98362012-11-01 23:02:38947 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:38948 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38949 typename Types::LayerType* child = this->createLayer(parent, childTransform, gfx::PointF(30, 30), gfx::Size(500, 500));
[email protected]94f206c12012-08-25 00:09:14950 child->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:38951 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child, this->identityMatrix, gfx::PointF(10, 10), gfx::Size(500, 500), true);
952 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:14953 this->calcDrawEtc(parent);
954
[email protected]167ed9d52012-10-31 20:47:58955 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
956 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14957
958 this->visitLayer(layer2, occlusion);
959 this->visitLayer(layer1, occlusion);
960 this->enterContributingSurface(child, occlusion);
961
[email protected]ac7c7f52012-11-08 06:26:50962 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
963 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14964
[email protected]167ed9d52012-10-31 20:47:58965 EXPECT_TRUE(occlusion.occludedLayer(child, gfx::Rect(10, 430, 60, 70)));
966 EXPECT_FALSE(occlusion.occludedLayer(child, gfx::Rect(9, 430, 60, 70)));
967 EXPECT_FALSE(occlusion.occludedLayer(child, gfx::Rect(10, 429, 60, 70)));
968 EXPECT_FALSE(occlusion.occludedLayer(child, gfx::Rect(11, 430, 60, 70)));
969 EXPECT_FALSE(occlusion.occludedLayer(child, gfx::Rect(10, 431, 60, 70)));
[email protected]94f206c12012-08-25 00:09:14970
[email protected]167ed9d52012-10-31 20:47:58971 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(child, gfx::Rect(10, 430, 60, 70)).IsEmpty());
972 EXPECT_RECT_EQ(gfx::Rect(9, 430, 1, 70), occlusion.unoccludedLayerContentRect(child, gfx::Rect(9, 430, 60, 70)));
973 EXPECT_RECT_EQ(gfx::Rect(10, 429, 60, 1), occlusion.unoccludedLayerContentRect(child, gfx::Rect(10, 429, 60, 70)));
974 EXPECT_RECT_EQ(gfx::Rect(70, 430, 1, 70), occlusion.unoccludedLayerContentRect(child, gfx::Rect(11, 430, 60, 70)));
975 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:14976
977 this->leaveContributingSurface(child, occlusion);
978 this->enterLayer(parent, occlusion);
979
[email protected]ac7c7f52012-11-08 06:26:50980 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
981 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:14982
[email protected]167ed9d52012-10-31 20:47:58983 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
984 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
985 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14986
[email protected]167ed9d52012-10-31 20:47:58987 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
988 EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(29, 40, 70, 60)));
989 EXPECT_RECT_EQ(gfx::Rect(30, 39, 70, 1), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(30, 39, 70, 60)));
990 EXPECT_RECT_EQ(gfx::Rect(100, 40, 1, 60), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(31, 40, 70, 60)));
991 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:14992
993 /* Justification for the above occlusion from |layer1| and |layer2|:
994
995 +---------------------+
996 | |30 Visible region of |layer1|: /////
997 | | Visible region of |layer2|: \\\\\
998 | +---------------------------------+
999 | | |10 |
1000 | +---------------+-----------------+ |
1001 | | |\\\\\\\\\\\\|//| 420 | |
1002 | | |\\\\\\\\\\\\|//|60 | |
1003 | | |\\\\\\\\\\\\|//| | |
1004 +--|--|------------|--+ | |
1005 20|10| 70 | | |
1006 | | | | |
1007 | | | | |
1008 | | | | |
1009 | | | | |
1010 | | | | |
1011 | | | |10|
1012 | +------------|-----------------|--+
1013 | | 490 |
1014 +---------------+-----------------+
1015 60 440
1016 */
1017 }
1018};
1019
[email protected]96baf3e2012-10-22 23:09:551020ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:141021
[email protected]ece1d952012-10-18 21:26:071022template<class Types>
[email protected]96baf3e2012-10-22 23:09:551023class OcclusionTrackerTestOverlappingSurfaceSiblings : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141024protected:
[email protected]96baf3e2012-10-22 23:09:551025 OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141026 void runMyTest()
1027 {
1028 WebTransformationMatrix childTransform;
1029 childTransform.translate(250, 250);
1030 childTransform.rotate(90);
1031 childTransform.translate(-250, -250);
1032
[email protected]d0f98362012-11-01 23:02:381033 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:381034 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:381035 typename Types::LayerType* child1 = this->createSurface(parent, childTransform, gfx::PointF(30, 30), gfx::Size(10, 10));
1036 typename Types::LayerType* child2 = this->createSurface(parent, childTransform, gfx::PointF(20, 40), gfx::Size(10, 10));
1037 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, gfx::PointF(-10, -10), gfx::Size(510, 510), true);
1038 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:141039 this->calcDrawEtc(parent);
1040
[email protected]167ed9d52012-10-31 20:47:581041 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1042 occlusion.setLayerClipRect(gfx::Rect(-20, -20, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141043
1044 this->visitLayer(layer2, occlusion);
1045 this->enterContributingSurface(child2, occlusion);
1046
[email protected]ac7c7f52012-11-08 06:26:501047 EXPECT_EQ(gfx::Rect(20, 30, 80, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1048 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141049
[email protected]167ed9d52012-10-31 20:47:581050 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 80)));
1051 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-11, 420, 70, 80)));
1052 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 419, 70, 80)));
1053 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 71, 80)));
1054 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 81)));
[email protected]94f206c12012-08-25 00:09:141055
1056 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:581057 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 80)));
1058 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-11, 420, 70, 80)));
1059 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 419, 70, 80)));
1060 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 71, 80)));
1061 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 81)));
1062 occlusion.setLayerClipRect(gfx::Rect(-20, -20, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141063
1064 // There is nothing above child2's surface in the z-order.
[email protected]167ed9d52012-10-31 20:47:581065 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:141066
1067 this->leaveContributingSurface(child2, occlusion);
1068 this->visitLayer(layer1, occlusion);
1069 this->enterContributingSurface(child1, occlusion);
1070
[email protected]ac7c7f52012-11-08 06:26:501071 EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70)).ToString(), occlusion.occlusionInScreenSpace().ToString());
1072 EXPECT_EQ(gfx::Rect(-10, 430, 80, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141073
[email protected]167ed9d52012-10-31 20:47:581074 EXPECT_TRUE(occlusion.occludedLayer(child1, gfx::Rect(-10, 430, 80, 70)));
1075 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(-11, 430, 80, 70)));
1076 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(-10, 429, 80, 70)));
1077 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(-10, 430, 81, 70)));
1078 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(-10, 430, 80, 71)));
[email protected]94f206c12012-08-25 00:09:141079
1080 // child2's contents will occlude child1 below it.
[email protected]167ed9d52012-10-31 20:47:581081 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:141082
1083 this->leaveContributingSurface(child1, occlusion);
1084 this->enterLayer(parent, occlusion);
1085
[email protected]ac7c7f52012-11-08 06:26:501086 EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70)).ToString(), occlusion.occlusionInScreenSpace().ToString());
1087 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:141088
[email protected]167ed9d52012-10-31 20:47:581089 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(20, 20, 80, 80)));
[email protected]94f206c12012-08-25 00:09:141090
[email protected]167ed9d52012-10-31 20:47:581091 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(30, 20, 70, 80)));
1092 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(29, 20, 70, 80)));
1093 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(30, 19, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141094
[email protected]167ed9d52012-10-31 20:47:581095 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(20, 30, 80, 70)));
1096 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(19, 30, 80, 70)));
1097 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(20, 29, 80, 70)));
[email protected]94f206c12012-08-25 00:09:141098
1099 /* Justification for the above occlusion:
1100 100
1101 +---------------------+
1102 | 20 | layer1
1103 | 30+ ---------------------------------+
1104 100 | 30| | layer2 |
1105 |20+----------------------------------+ |
1106 | | | | | |
1107 | | | | | |
1108 | | | | | |
1109 +--|-|----------------+ | |
1110 | | | | 510
1111 | | | |
1112 | | | |
1113 | | | |
1114 | | | |
1115 | | | |
1116 | | | |
1117 | +--------------------------------|-+
1118 | |
1119 +----------------------------------+
1120 510
1121 */
1122 }
1123};
1124
[email protected]96baf3e2012-10-22 23:09:551125ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:141126
[email protected]ece1d952012-10-18 21:26:071127template<class Types>
[email protected]96baf3e2012-10-22 23:09:551128class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141129protected:
[email protected]96baf3e2012-10-22 23:09:551130 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141131 void runMyTest()
1132 {
1133 WebTransformationMatrix child1Transform;
1134 child1Transform.translate(250, 250);
1135 child1Transform.rotate(-90);
1136 child1Transform.translate(-250, -250);
1137
1138 WebTransformationMatrix child2Transform;
1139 child2Transform.translate(250, 250);
1140 child2Transform.rotate(90);
1141 child2Transform.translate(-250, -250);
1142
[email protected]d0f98362012-11-01 23:02:381143 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:381144 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:381145 typename Types::LayerType* child1 = this->createSurface(parent, child1Transform, gfx::PointF(30, 20), gfx::Size(10, 10));
1146 typename Types::LayerType* child2 = this->createDrawingSurface(parent, child2Transform, gfx::PointF(20, 40), gfx::Size(10, 10), false);
1147 typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, gfx::PointF(-10, -20), gfx::Size(510, 510), true);
1148 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:141149 this->calcDrawEtc(parent);
1150
[email protected]167ed9d52012-10-31 20:47:581151 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1152 occlusion.setLayerClipRect(gfx::Rect(-30, -30, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141153
1154 this->visitLayer(layer2, occlusion);
1155 this->enterLayer(child2, occlusion);
1156
[email protected]ac7c7f52012-11-08 06:26:501157 EXPECT_EQ(gfx::Rect(20, 30, 80, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1158 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141159
[email protected]167ed9d52012-10-31 20:47:581160 EXPECT_TRUE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 80)));
1161 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-11, 420, 70, 80)));
1162 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 419, 70, 80)));
1163 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 71, 80)));
1164 EXPECT_FALSE(occlusion.occludedLayer(child2, gfx::Rect(-10, 420, 70, 81)));
[email protected]94f206c12012-08-25 00:09:141165
1166 this->leaveLayer(child2, occlusion);
1167 this->enterContributingSurface(child2, occlusion);
1168
1169 // There is nothing above child2's surface in the z-order.
[email protected]167ed9d52012-10-31 20:47:581170 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:141171
1172 this->leaveContributingSurface(child2, occlusion);
1173 this->visitLayer(layer1, occlusion);
1174 this->enterContributingSurface(child1, occlusion);
1175
[email protected]ac7c7f52012-11-08 06:26:501176 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), occlusion.occlusionInScreenSpace().ToString());
1177 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141178
[email protected]167ed9d52012-10-31 20:47:581179 EXPECT_TRUE(occlusion.occludedLayer(child1, gfx::Rect(420, -20, 80, 90)));
1180 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(419, -20, 80, 90)));
1181 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(420, -21, 80, 90)));
1182 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(420, -19, 80, 90)));
1183 EXPECT_FALSE(occlusion.occludedLayer(child1, gfx::Rect(421, -20, 80, 90)));
[email protected]94f206c12012-08-25 00:09:141184
1185 // child2's contents will occlude child1 below it.
[email protected]167ed9d52012-10-31 20:47:581186 EXPECT_RECT_EQ(gfx::Rect(420, -20, 80, 90), occlusion.unoccludedContributingSurfaceContentRect(child1, false, gfx::Rect(420, -20, 80, 90)));
1187 EXPECT_RECT_EQ(gfx::Rect(490, -10, 10, 80), occlusion.unoccludedContributingSurfaceContentRect(child1, false, gfx::Rect(420, -10, 80, 90)));
1188 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:141189
1190 this->leaveContributingSurface(child1, occlusion);
1191 this->enterLayer(parent, occlusion);
1192
[email protected]ac7c7f52012-11-08 06:26:501193 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), occlusion.occlusionInScreenSpace().ToString());
1194 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141195
[email protected]167ed9d52012-10-31 20:47:581196 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(10, 20, 90, 80)));
1197 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(9, 20, 90, 80)));
1198 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(10, 19, 90, 80)));
1199 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(11, 20, 90, 80)));
1200 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(10, 21, 90, 80)));
[email protected]94f206c12012-08-25 00:09:141201
1202 /* Justification for the above occlusion:
1203 100
1204 +---------------------+
1205 |20 | layer1
1206 10+----------------------------------+
1207 100 || 30 | layer2 |
1208 |20+----------------------------------+
1209 || | | | |
1210 || | | | |
1211 || | | | |
1212 +|-|------------------+ | |
1213 | | | | 510
1214 | | 510 | |
1215 | | | |
1216 | | | |
1217 | | | |
1218 | | | |
1219 | | 520 | |
1220 +----------------------------------+ |
1221 | |
1222 +----------------------------------+
1223 510
1224 */
1225 }
1226};
1227
[email protected]96baf3e2012-10-22 23:09:551228ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:141229
[email protected]ece1d952012-10-18 21:26:071230template<class Types>
[email protected]96baf3e2012-10-22 23:09:551231class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141232protected:
[email protected]96baf3e2012-10-22 23:09:551233 OcclusionTrackerTestFilters(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141234 void runMyTest()
1235 {
1236 WebTransformationMatrix layerTransform;
1237 layerTransform.translate(250, 250);
1238 layerTransform.rotate(90);
1239 layerTransform.translate(-250, -250);
1240
[email protected]d0f98362012-11-01 23:02:381241 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:381242 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:381243 typename Types::ContentLayerType* blurLayer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
1244 typename Types::ContentLayerType* opaqueLayer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
1245 typename Types::ContentLayerType* opacityLayer = this->createDrawingLayer(parent, layerTransform, gfx::PointF(30, 30), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:141246
1247 WebFilterOperations filters;
1248 filters.append(WebFilterOperation::createBlurFilter(10));
1249 blurLayer->setFilters(filters);
1250
1251 filters.clear();
1252 filters.append(WebFilterOperation::createGrayscaleFilter(0.5));
1253 opaqueLayer->setFilters(filters);
1254
1255 filters.clear();
1256 filters.append(WebFilterOperation::createOpacityFilter(0.5));
1257 opacityLayer->setFilters(filters);
1258
1259 this->calcDrawEtc(parent);
1260
[email protected]167ed9d52012-10-31 20:47:581261 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1262 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141263
1264 // Opacity layer won't contribute to occlusion.
1265 this->visitLayer(opacityLayer, occlusion);
1266 this->enterContributingSurface(opacityLayer, occlusion);
1267
[email protected]d0f98362012-11-01 23:02:381268 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1269 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141270
1271 // And has nothing to contribute to its parent surface.
1272 this->leaveContributingSurface(opacityLayer, occlusion);
[email protected]d0f98362012-11-01 23:02:381273 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1274 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141275
1276 // Opaque layer will contribute to occlusion.
1277 this->visitLayer(opaqueLayer, occlusion);
1278 this->enterContributingSurface(opaqueLayer, occlusion);
1279
[email protected]ac7c7f52012-11-08 06:26:501280 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1281 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141282
1283 // And it gets translated to the parent surface.
1284 this->leaveContributingSurface(opaqueLayer, occlusion);
[email protected]ac7c7f52012-11-08 06:26:501285 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1286 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141287
1288 // The blur layer needs to throw away any occlusion from outside its subtree.
1289 this->enterLayer(blurLayer, occlusion);
[email protected]d0f98362012-11-01 23:02:381290 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1291 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141292
1293 // And it won't contribute to occlusion.
1294 this->leaveLayer(blurLayer, occlusion);
1295 this->enterContributingSurface(blurLayer, occlusion);
[email protected]d0f98362012-11-01 23:02:381296 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1297 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141298
1299 // But the opaque layer's occlusion is preserved on the parent.
1300 this->leaveContributingSurface(blurLayer, occlusion);
1301 this->enterLayer(parent, occlusion);
[email protected]ac7c7f52012-11-08 06:26:501302 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInScreenSpace().ToString());
1303 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141304 }
1305};
1306
[email protected]96baf3e2012-10-22 23:09:551307ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:141308
[email protected]ece1d952012-10-18 21:26:071309template<class Types>
[email protected]96baf3e2012-10-22 23:09:551310class OcclusionTrackerTestReplicaDoesOcclude : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141311protected:
[email protected]96baf3e2012-10-22 23:09:551312 OcclusionTrackerTestReplicaDoesOcclude(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141313 void runMyTest()
1314 {
[email protected]d0f98362012-11-01 23:02:381315 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
1316 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(50, 50), true);
1317 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(50, 50), gfx::Size());
[email protected]94f206c12012-08-25 00:09:141318 this->calcDrawEtc(parent);
1319
[email protected]167ed9d52012-10-31 20:47:581320 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1321 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141322
1323 this->visitLayer(surface, occlusion);
1324
[email protected]ac7c7f52012-11-08 06:26:501325 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
1326 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141327
1328 this->visitContributingSurface(surface, occlusion);
1329 this->enterLayer(parent, occlusion);
1330
1331 // The surface and replica should both be occluding the parent.
[email protected]ac7c7f52012-11-08 06:26:501332 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:141333 }
1334};
1335
[email protected]96baf3e2012-10-22 23:09:551336ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude);
[email protected]94f206c12012-08-25 00:09:141337
[email protected]ece1d952012-10-18 21:26:071338template<class Types>
[email protected]96baf3e2012-10-22 23:09:551339class OcclusionTrackerTestReplicaWithClipping : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141340protected:
[email protected]96baf3e2012-10-22 23:09:551341 OcclusionTrackerTestReplicaWithClipping(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141342 void runMyTest()
1343 {
[email protected]d0f98362012-11-01 23:02:381344 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 170));
[email protected]23bbb412012-08-30 20:03:381345 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:381346 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(50, 50), true);
1347 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(50, 50), gfx::Size());
[email protected]94f206c12012-08-25 00:09:141348 this->calcDrawEtc(parent);
1349
[email protected]167ed9d52012-10-31 20:47:581350 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1351 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141352
1353 this->visitLayer(surface, occlusion);
1354
[email protected]ac7c7f52012-11-08 06:26:501355 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
1356 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141357
1358 this->visitContributingSurface(surface, occlusion);
1359 this->enterLayer(parent, occlusion);
1360
1361 // The surface and replica should both be occluding the parent.
[email protected]ac7c7f52012-11-08 06:26:501362 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:141363 }
1364};
1365
[email protected]96baf3e2012-10-22 23:09:551366ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping);
[email protected]94f206c12012-08-25 00:09:141367
[email protected]ece1d952012-10-18 21:26:071368template<class Types>
[email protected]96baf3e2012-10-22 23:09:551369class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141370protected:
[email protected]96baf3e2012-10-22 23:09:551371 OcclusionTrackerTestReplicaWithMask(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141372 void runMyTest()
1373 {
[email protected]d0f98362012-11-01 23:02:381374 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
1375 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(50, 50), true);
1376 typename Types::LayerType* replica = this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(50, 50), gfx::Size());
[email protected]aad0a0072012-11-01 18:15:581377 this->createMaskLayer(replica, gfx::Size(10, 10));
[email protected]94f206c12012-08-25 00:09:141378 this->calcDrawEtc(parent);
1379
[email protected]167ed9d52012-10-31 20:47:581380 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1381 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141382
1383 this->visitLayer(surface, occlusion);
1384
[email protected]ac7c7f52012-11-08 06:26:501385 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
1386 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141387
1388 this->visitContributingSurface(surface, occlusion);
1389 this->enterLayer(parent, occlusion);
1390
1391 // The replica should not be occluding the parent, since it has a mask applied to it.
[email protected]ac7c7f52012-11-08 06:26:501392 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:141393 }
1394};
1395
[email protected]96baf3e2012-10-22 23:09:551396ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask);
[email protected]94f206c12012-08-25 00:09:141397
[email protected]ece1d952012-10-18 21:26:071398template<class Types>
[email protected]96baf3e2012-10-22 23:09:551399class OcclusionTrackerTestLayerClipRectOutsideChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141400protected:
[email protected]96baf3e2012-10-22 23:09:551401 OcclusionTrackerTestLayerClipRectOutsideChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141402 void runMyTest()
1403 {
[email protected]d0f98362012-11-01 23:02:381404 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1405 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:141406 this->calcDrawEtc(parent);
1407
[email protected]167ed9d52012-10-31 20:47:581408 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1409 occlusion.setLayerClipRect(gfx::Rect(200, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:141410
1411 this->enterLayer(layer, occlusion);
1412
[email protected]167ed9d52012-10-31 20:47:581413 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1414 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1415 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1416 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
1417 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141418
1419 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:581420 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
1421 occlusion.setLayerClipRect(gfx::Rect(200, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:141422
1423 this->leaveLayer(layer, occlusion);
1424 this->visitContributingSurface(layer, occlusion);
1425 this->enterLayer(parent, occlusion);
1426
[email protected]167ed9d52012-10-31 20:47:581427 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1428 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1429 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1430 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1431 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1432 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1433 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1434 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1435 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141436
[email protected]167ed9d52012-10-31 20:47:581437 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:141438 }
1439};
1440
[email protected]96baf3e2012-10-22 23:09:551441ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOutsideChild);
[email protected]94f206c12012-08-25 00:09:141442
[email protected]ece1d952012-10-18 21:26:071443template<class Types>
[email protected]96baf3e2012-10-22 23:09:551444class OcclusionTrackerTestViewportRectOutsideChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141445protected:
[email protected]96baf3e2012-10-22 23:09:551446 OcclusionTrackerTestViewportRectOutsideChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141447 void runMyTest()
1448 {
[email protected]d0f98362012-11-01 23:02:381449 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1450 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:141451 this->calcDrawEtc(parent);
1452
[email protected]167ed9d52012-10-31 20:47:581453 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(200, 100, 100, 100));
1454 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141455
1456 this->enterLayer(layer, occlusion);
1457
[email protected]167ed9d52012-10-31 20:47:581458 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1459 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1460 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1461 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
1462 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141463
1464 occlusion.useDefaultLayerClipRect();
[email protected]167ed9d52012-10-31 20:47:581465 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
1466 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141467
1468 this->leaveLayer(layer, occlusion);
1469 this->visitContributingSurface(layer, occlusion);
1470 this->enterLayer(parent, occlusion);
1471
[email protected]167ed9d52012-10-31 20:47:581472 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1473 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1474 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1475 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1476 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1477 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1478 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1479 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1480 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141481
[email protected]167ed9d52012-10-31 20:47:581482 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:141483 }
1484};
1485
[email protected]96baf3e2012-10-22 23:09:551486ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOutsideChild);
[email protected]94f206c12012-08-25 00:09:141487
[email protected]ece1d952012-10-18 21:26:071488template<class Types>
[email protected]96baf3e2012-10-22 23:09:551489class OcclusionTrackerTestLayerClipRectOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141490protected:
[email protected]96baf3e2012-10-22 23:09:551491 OcclusionTrackerTestLayerClipRectOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141492 void runMyTest()
1493 {
[email protected]d0f98362012-11-01 23:02:381494 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1495 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:141496 this->calcDrawEtc(parent);
1497
[email protected]167ed9d52012-10-31 20:47:581498 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1499 occlusion.setLayerClipRect(gfx::Rect(100, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:141500
1501 this->enterLayer(layer, occlusion);
1502
[email protected]167ed9d52012-10-31 20:47:581503 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1504 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1505 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1506 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141507
1508 this->leaveLayer(layer, occlusion);
1509 this->visitContributingSurface(layer, occlusion);
1510 this->enterLayer(parent, occlusion);
1511
[email protected]167ed9d52012-10-31 20:47:581512 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1513 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1514 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1515 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1516 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1517 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1518 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1519 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1520 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141521
[email protected]167ed9d52012-10-31 20:47:581522 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141523 }
1524};
1525
[email protected]96baf3e2012-10-22 23:09:551526ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOverChild);
[email protected]94f206c12012-08-25 00:09:141527
[email protected]ece1d952012-10-18 21:26:071528template<class Types>
[email protected]96baf3e2012-10-22 23:09:551529class OcclusionTrackerTestViewportRectOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141530protected:
[email protected]96baf3e2012-10-22 23:09:551531 OcclusionTrackerTestViewportRectOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141532 void runMyTest()
1533 {
[email protected]d0f98362012-11-01 23:02:381534 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1535 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:141536 this->calcDrawEtc(parent);
1537
[email protected]167ed9d52012-10-31 20:47:581538 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(100, 100, 100, 100));
1539 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141540
1541 this->enterLayer(layer, occlusion);
1542
[email protected]167ed9d52012-10-31 20:47:581543 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1544 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1545 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1546 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141547
1548 this->leaveLayer(layer, occlusion);
1549 this->visitContributingSurface(layer, occlusion);
1550 this->enterLayer(parent, occlusion);
1551
[email protected]167ed9d52012-10-31 20:47:581552 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1553 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1554 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1555 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1556 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1557 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1558 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1559 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1560 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141561
[email protected]167ed9d52012-10-31 20:47:581562 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141563 }
1564};
1565
[email protected]96baf3e2012-10-22 23:09:551566ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverChild);
[email protected]94f206c12012-08-25 00:09:141567
[email protected]ece1d952012-10-18 21:26:071568template<class Types>
[email protected]96baf3e2012-10-22 23:09:551569class OcclusionTrackerTestLayerClipRectPartlyOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141570protected:
[email protected]96baf3e2012-10-22 23:09:551571 OcclusionTrackerTestLayerClipRectPartlyOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141572 void runMyTest()
1573 {
[email protected]d0f98362012-11-01 23:02:381574 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1575 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:141576 this->calcDrawEtc(parent);
1577
[email protected]167ed9d52012-10-31 20:47:581578 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1579 occlusion.setLayerClipRect(gfx::Rect(50, 50, 200, 200));
[email protected]94f206c12012-08-25 00:09:141580
1581 this->enterLayer(layer, occlusion);
1582
[email protected]167ed9d52012-10-31 20:47:581583 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1584 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1585 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1586 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141587
1588 this->leaveLayer(layer, occlusion);
1589 this->visitContributingSurface(layer, occlusion);
1590 this->enterLayer(parent, occlusion);
1591
[email protected]167ed9d52012-10-31 20:47:581592 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1593 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1594 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1595 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1596 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1597 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1598 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1599 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1600 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141601
[email protected]167ed9d52012-10-31 20:47:581602 EXPECT_RECT_EQ(gfx::Rect(50, 50, 200, 200), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
1603 EXPECT_RECT_EQ(gfx::Rect(200, 50, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 100)));
1604 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 100, 300, 100)));
1605 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(200, 100, 100, 100)));
1606 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:141607 }
1608};
1609
[email protected]96baf3e2012-10-22 23:09:551610ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectPartlyOverChild);
[email protected]94f206c12012-08-25 00:09:141611
[email protected]ece1d952012-10-18 21:26:071612template<class Types>
[email protected]96baf3e2012-10-22 23:09:551613class OcclusionTrackerTestViewportRectPartlyOverChild : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141614protected:
[email protected]96baf3e2012-10-22 23:09:551615 OcclusionTrackerTestViewportRectPartlyOverChild(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141616 void runMyTest()
1617 {
[email protected]d0f98362012-11-01 23:02:381618 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1619 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:141620 this->calcDrawEtc(parent);
1621
[email protected]167ed9d52012-10-31 20:47:581622 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(50, 50, 200, 200));
1623 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141624
1625 this->enterLayer(layer, occlusion);
1626
[email protected]167ed9d52012-10-31 20:47:581627 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1628 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1629 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1630 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141631
1632 this->leaveLayer(layer, occlusion);
1633 this->visitContributingSurface(layer, occlusion);
1634 this->enterLayer(parent, occlusion);
1635
[email protected]167ed9d52012-10-31 20:47:581636 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1637 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1638 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1639 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1640 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1641 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1642 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1643 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1644 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141645
[email protected]167ed9d52012-10-31 20:47:581646 EXPECT_RECT_EQ(gfx::Rect(50, 50, 200, 200), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)));
1647 EXPECT_RECT_EQ(gfx::Rect(200, 50, 50, 50), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 100)));
1648 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 100, 300, 100)));
1649 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), occlusion.unoccludedLayerContentRect(parent, gfx::Rect(200, 100, 100, 100)));
1650 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:141651 }
1652};
1653
[email protected]96baf3e2012-10-22 23:09:551654ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectPartlyOverChild);
[email protected]94f206c12012-08-25 00:09:141655
[email protected]ece1d952012-10-18 21:26:071656template<class Types>
[email protected]96baf3e2012-10-22 23:09:551657class OcclusionTrackerTestLayerClipRectOverNothing : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141658protected:
[email protected]96baf3e2012-10-22 23:09:551659 OcclusionTrackerTestLayerClipRectOverNothing(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141660 void runMyTest()
1661 {
[email protected]d0f98362012-11-01 23:02:381662 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1663 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:141664 this->calcDrawEtc(parent);
1665
[email protected]167ed9d52012-10-31 20:47:581666 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
1667 occlusion.setLayerClipRect(gfx::Rect(500, 500, 100, 100));
[email protected]94f206c12012-08-25 00:09:141668
1669 this->enterLayer(layer, occlusion);
1670
[email protected]167ed9d52012-10-31 20:47:581671 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1672 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1673 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1674 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141675
1676 this->leaveLayer(layer, occlusion);
1677 this->visitContributingSurface(layer, occlusion);
1678 this->enterLayer(parent, occlusion);
1679
[email protected]167ed9d52012-10-31 20:47:581680 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1681 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1682 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1683 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1684 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1685 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1686 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1687 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1688 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141689
[email protected]167ed9d52012-10-31 20:47:581690 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
1691 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 100)).IsEmpty());
1692 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 100, 300, 100)).IsEmpty());
1693 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(200, 100, 100, 100)).IsEmpty());
1694 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(100, 200, 100, 100)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141695 }
1696};
1697
[email protected]96baf3e2012-10-22 23:09:551698ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOverNothing);
[email protected]94f206c12012-08-25 00:09:141699
[email protected]ece1d952012-10-18 21:26:071700template<class Types>
[email protected]96baf3e2012-10-22 23:09:551701class OcclusionTrackerTestViewportRectOverNothing : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141702protected:
[email protected]96baf3e2012-10-22 23:09:551703 OcclusionTrackerTestViewportRectOverNothing(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141704 void runMyTest()
1705 {
[email protected]d0f98362012-11-01 23:02:381706 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1707 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:141708 this->calcDrawEtc(parent);
1709
[email protected]167ed9d52012-10-31 20:47:581710 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(500, 500, 100, 100));
1711 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141712
1713 this->enterLayer(layer, occlusion);
1714
[email protected]167ed9d52012-10-31 20:47:581715 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1716 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1717 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1718 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141719
1720 this->leaveLayer(layer, occlusion);
1721 this->visitContributingSurface(layer, occlusion);
1722 this->enterLayer(parent, occlusion);
1723
[email protected]167ed9d52012-10-31 20:47:581724 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1725 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1726 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1727 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1728 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1729 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1730 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1731 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1732 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141733
[email protected]167ed9d52012-10-31 20:47:581734 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
1735 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 0, 300, 100)).IsEmpty());
1736 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(0, 100, 300, 100)).IsEmpty());
1737 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(200, 100, 100, 100)).IsEmpty());
1738 EXPECT_TRUE(occlusion.unoccludedLayerContentRect(parent, gfx::Rect(100, 200, 100, 100)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141739 }
1740};
1741
[email protected]96baf3e2012-10-22 23:09:551742ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverNothing);
[email protected]94f206c12012-08-25 00:09:141743
[email protected]ece1d952012-10-18 21:26:071744template<class Types>
[email protected]96baf3e2012-10-22 23:09:551745class OcclusionTrackerTestLayerClipRectForLayerOffOrigin : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141746protected:
[email protected]96baf3e2012-10-22 23:09:551747 OcclusionTrackerTestLayerClipRectForLayerOffOrigin(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141748 void runMyTest()
1749 {
[email protected]d0f98362012-11-01 23:02:381750 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1751 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:141752 this->calcDrawEtc(parent);
1753
[email protected]167ed9d52012-10-31 20:47:581754 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141755 this->enterLayer(layer, occlusion);
1756
1757 // This layer is translated when drawn into its target. So if the clip rect given from the target surface
1758 // is not in that target space, then after translating these query rects into the target, they will fall outside
1759 // the clip and be considered occluded.
[email protected]167ed9d52012-10-31 20:47:581760 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1761 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1762 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1763 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141764 }
1765};
1766
[email protected]96baf3e2012-10-22 23:09:551767ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectForLayerOffOrigin);
[email protected]94f206c12012-08-25 00:09:141768
[email protected]ece1d952012-10-18 21:26:071769template<class Types>
[email protected]96baf3e2012-10-22 23:09:551770class OcclusionTrackerTestOpaqueContentsRegionEmpty : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141771protected:
[email protected]96baf3e2012-10-22 23:09:551772 OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141773 void runMyTest()
1774 {
[email protected]d0f98362012-11-01 23:02:381775 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1776 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:141777 this->calcDrawEtc(parent);
1778
[email protected]167ed9d52012-10-31 20:47:581779 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141780 this->enterLayer(layer, occlusion);
1781
[email protected]167ed9d52012-10-31 20:47:581782 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1783 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1784 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1785 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141786
1787 // Occluded since its outside the surface bounds.
[email protected]167ed9d52012-10-31 20:47:581788 EXPECT_TRUE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141789
1790 // Test without any clip rect.
[email protected]167ed9d52012-10-31 20:47:581791 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
1792 EXPECT_FALSE(occlusion.occludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141793 occlusion.useDefaultLayerClipRect();
1794
1795 this->leaveLayer(layer, occlusion);
1796 this->visitContributingSurface(layer, occlusion);
1797 this->enterLayer(parent, occlusion);
1798
[email protected]ac7c7f52012-11-08 06:26:501799 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141800 }
1801};
1802
[email protected]96baf3e2012-10-22 23:09:551803MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141804
[email protected]ece1d952012-10-18 21:26:071805template<class Types>
[email protected]96baf3e2012-10-22 23:09:551806class OcclusionTrackerTestOpaqueContentsRegionNonEmpty : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141807protected:
[email protected]96baf3e2012-10-22 23:09:551808 OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141809 void runMyTest()
1810 {
[email protected]d0f98362012-11-01 23:02:381811 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1812 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:141813 this->calcDrawEtc(parent);
1814
1815 {
[email protected]167ed9d52012-10-31 20:47:581816 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]aad0a0072012-11-01 18:15:581817 layer->setOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:141818
1819 this->resetLayerIterator();
1820 this->visitLayer(layer, occlusion);
1821 this->enterLayer(parent, occlusion);
1822
[email protected]ac7c7f52012-11-08 06:26:501823 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:141824
[email protected]167ed9d52012-10-31 20:47:581825 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1826 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1827 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141828 }
1829
1830 {
[email protected]167ed9d52012-10-31 20:47:581831 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]aad0a0072012-11-01 18:15:581832 layer->setOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
[email protected]94f206c12012-08-25 00:09:141833
1834 this->resetLayerIterator();
1835 this->visitLayer(layer, occlusion);
1836 this->enterLayer(parent, occlusion);
1837
[email protected]ac7c7f52012-11-08 06:26:501838 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:141839
[email protected]167ed9d52012-10-31 20:47:581840 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1841 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1842 EXPECT_TRUE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141843 }
1844
1845 {
[email protected]167ed9d52012-10-31 20:47:581846 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]aad0a0072012-11-01 18:15:581847 layer->setOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
[email protected]94f206c12012-08-25 00:09:141848
1849 this->resetLayerIterator();
1850 this->visitLayer(layer, occlusion);
1851 this->enterLayer(parent, occlusion);
1852
[email protected]ac7c7f52012-11-08 06:26:501853 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:141854
[email protected]167ed9d52012-10-31 20:47:581855 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1856 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1857 EXPECT_FALSE(occlusion.occludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141858 }
1859 }
1860};
1861
[email protected]96baf3e2012-10-22 23:09:551862MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141863
[email protected]ece1d952012-10-18 21:26:071864template<class Types>
[email protected]96baf3e2012-10-22 23:09:551865class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141866protected:
[email protected]96baf3e2012-10-22 23:09:551867 OcclusionTrackerTest3dTransform(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141868 void runMyTest()
1869 {
1870 WebTransformationMatrix transform;
1871 transform.rotate3d(0, 30, 0);
1872
[email protected]d0f98362012-11-01 23:02:381873 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1874 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1875 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, gfx::PointF(100, 100), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141876 this->calcDrawEtc(parent);
1877
[email protected]167ed9d52012-10-31 20:47:581878 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141879 this->enterLayer(layer, occlusion);
1880
1881 // The layer is rotated in 3d but without preserving 3d, so it only gets resized.
[email protected]167ed9d52012-10-31 20:47:581882 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:141883 }
1884};
1885
[email protected]96baf3e2012-10-22 23:09:551886MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform);
[email protected]94f206c12012-08-25 00:09:141887
[email protected]ece1d952012-10-18 21:26:071888template<class Types>
[email protected]96baf3e2012-10-22 23:09:551889class OcclusionTrackerTestUnsorted3dLayers : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141890protected:
[email protected]96baf3e2012-10-22 23:09:551891 OcclusionTrackerTestUnsorted3dLayers(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141892 void runMyTest()
1893 {
1894 // Currently, the main thread layer iterator does not iterate over 3d items in
1895 // sorted order, because layer sorting is not performed on the main thread.
1896 // Because of this, the occlusion tracker cannot assume that a 3d layer occludes
1897 // other layers that have not yet been iterated over. For now, the expected
1898 // behavior is that a 3d layer simply does not add any occlusion to the occlusion
1899 // tracker.
1900
1901 WebTransformationMatrix translationToFront;
1902 translationToFront.translate3d(0, 0, -10);
1903 WebTransformationMatrix translationToBack;
1904 translationToFront.translate3d(0, 0, -100);
1905
[email protected]d0f98362012-11-01 23:02:381906 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1907 typename Types::ContentLayerType* child1 = this->createDrawingLayer(parent, translationToBack, gfx::PointF(0, 0), gfx::Size(100, 100), true);
1908 typename Types::ContentLayerType* child2 = this->createDrawingLayer(parent, translationToFront, gfx::PointF(50, 50), gfx::Size(100, 100), true);
[email protected]94f206c12012-08-25 00:09:141909 parent->setPreserves3D(true);
1910
1911 this->calcDrawEtc(parent);
1912
[email protected]167ed9d52012-10-31 20:47:581913 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141914 this->visitLayer(child2, occlusion);
[email protected]d0f98362012-11-01 23:02:381915 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1916 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141917
1918 this->visitLayer(child1, occlusion);
[email protected]d0f98362012-11-01 23:02:381919 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
1920 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141921 }
1922};
1923
1924// 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:551925MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
[email protected]94f206c12012-08-25 00:09:141926
[email protected]ece1d952012-10-18 21:26:071927template<class Types>
[email protected]96baf3e2012-10-22 23:09:551928class OcclusionTrackerTestPerspectiveTransform : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141929protected:
[email protected]96baf3e2012-10-22 23:09:551930 OcclusionTrackerTestPerspectiveTransform(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141931 void runMyTest()
1932 {
1933 WebTransformationMatrix transform;
1934 transform.translate(150, 150);
1935 transform.applyPerspective(400);
1936 transform.rotate3d(1, 0, 0, -30);
1937 transform.translate(-150, -150);
1938
[email protected]d0f98362012-11-01 23:02:381939 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1940 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
1941 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, gfx::PointF(100, 100), gfx::Size(200, 200), true);
[email protected]94f206c12012-08-25 00:09:141942 container->setPreserves3D(true);
1943 layer->setPreserves3D(true);
1944 this->calcDrawEtc(parent);
1945
[email protected]167ed9d52012-10-31 20:47:581946 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141947 this->enterLayer(layer, occlusion);
1948
[email protected]167ed9d52012-10-31 20:47:581949 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:141950 }
1951};
1952
1953// 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:551954IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransform);
[email protected]94f206c12012-08-25 00:09:141955
[email protected]ece1d952012-10-18 21:26:071956template<class Types>
[email protected]96baf3e2012-10-22 23:09:551957class OcclusionTrackerTestPerspectiveTransformBehindCamera : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141958protected:
[email protected]96baf3e2012-10-22 23:09:551959 OcclusionTrackerTestPerspectiveTransformBehindCamera(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141960 void runMyTest()
1961 {
1962 // This test is based on the platform/chromium/compositing/3d-corners.html layout test.
1963 WebTransformationMatrix transform;
1964 transform.translate(250, 50);
1965 transform.applyPerspective(10);
1966 transform.translate(-250, -50);
1967 transform.translate(250, 50);
1968 transform.rotate3d(1, 0, 0, -167);
1969 transform.translate(-250, -50);
1970
[email protected]d0f98362012-11-01 23:02:381971 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(500, 100));
1972 typename Types::LayerType* container = this->createLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(500, 500));
1973 typename Types::ContentLayerType* layer = this->createDrawingLayer(container, transform, gfx::PointF(0, 0), gfx::Size(500, 500), true);
[email protected]94f206c12012-08-25 00:09:141974 container->setPreserves3D(true);
1975 layer->setPreserves3D(true);
1976 this->calcDrawEtc(parent);
1977
[email protected]167ed9d52012-10-31 20:47:581978 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141979 this->enterLayer(layer, occlusion);
1980
1981 // The bottom 11 pixel rows of this layer remain visible inside the container, after translation to the target surface. When translated back,
1982 // this will include many more pixels but must include at least the bottom 11 rows.
[email protected]167ed9d52012-10-31 20:47:581983 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:141984 }
1985};
1986
1987// 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:551988IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransformBehindCamera);
[email protected]94f206c12012-08-25 00:09:141989
[email protected]ece1d952012-10-18 21:26:071990template<class Types>
[email protected]96baf3e2012-10-22 23:09:551991class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:141992protected:
[email protected]96baf3e2012-10-22 23:09:551993 OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:141994 void runMyTest()
1995 {
1996 WebTransformationMatrix transform;
1997 transform.translate(50, 50);
1998 transform.applyPerspective(100);
1999 transform.translate3d(0, 0, 110);
2000 transform.translate(-50, -50);
2001
[email protected]d0f98362012-11-01 23:02:382002 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
2003 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, transform, gfx::PointF(0, 0), gfx::Size(100, 100), true);
[email protected]94f206c12012-08-25 00:09:142004 parent->setPreserves3D(true);
2005 layer->setPreserves3D(true);
2006 this->calcDrawEtc(parent);
2007
[email protected]167ed9d52012-10-31 20:47:582008 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142009
2010 // The |layer| is entirely behind the camera and should not occlude.
2011 this->visitLayer(layer, occlusion);
2012 this->enterLayer(parent, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502013 EXPECT_TRUE(occlusion.occlusionInTargetSurface().IsEmpty());
2014 EXPECT_TRUE(occlusion.occlusionInScreenSpace().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142015 }
2016};
2017
2018// 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:552019IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude);
[email protected]94f206c12012-08-25 00:09:142020
[email protected]ece1d952012-10-18 21:26:072021template<class Types>
[email protected]96baf3e2012-10-22 23:09:552022class OcclusionTrackerTestLargePixelsOccludeInsideClipRect : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142023protected:
[email protected]96baf3e2012-10-22 23:09:552024 OcclusionTrackerTestLargePixelsOccludeInsideClipRect(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142025 void runMyTest()
2026 {
2027 WebTransformationMatrix transform;
2028 transform.translate(50, 50);
2029 transform.applyPerspective(100);
2030 transform.translate3d(0, 0, 99);
2031 transform.translate(-50, -50);
2032
[email protected]d0f98362012-11-01 23:02:382033 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100));
[email protected]23bbb412012-08-30 20:03:382034 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382035 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, transform, gfx::PointF(0, 0), gfx::Size(100, 100), true);
[email protected]94f206c12012-08-25 00:09:142036 parent->setPreserves3D(true);
2037 layer->setPreserves3D(true);
2038 this->calcDrawEtc(parent);
2039
[email protected]167ed9d52012-10-31 20:47:582040 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142041
2042 // This is very close to the camera, so pixels in its visibleContentRect will actually go outside of the layer's clipRect.
2043 // Ensure that those pixels don't occlude things outside the clipRect.
2044 this->visitLayer(layer, occlusion);
2045 this->enterLayer(parent, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502046 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
2047 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:142048 }
2049};
2050
2051// 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:552052IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect);
[email protected]94f206c12012-08-25 00:09:142053
[email protected]ece1d952012-10-18 21:26:072054template<class Types>
[email protected]96baf3e2012-10-22 23:09:552055class OcclusionTrackerTestAnimationOpacity1OnMainThread : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142056protected:
[email protected]96baf3e2012-10-22 23:09:552057 OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142058 void runMyTest()
2059 {
[email protected]d0f98362012-11-01 23:02:382060 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
2061 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2062 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2063 typename Types::ContentLayerType* surfaceChild = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 300), true);
2064 typename Types::ContentLayerType* surfaceChild2 = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 300), true);
2065 typename Types::ContentLayerType* parent2 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2066 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:142067
2068 addOpacityTransitionToController(*layer->layerAnimationController(), 10, 0, 1, false);
2069 addOpacityTransitionToController(*surface->layerAnimationController(), 10, 0, 1, false);
2070 this->calcDrawEtc(parent);
2071
2072 EXPECT_TRUE(layer->drawOpacityIsAnimating());
2073 EXPECT_FALSE(surface->drawOpacityIsAnimating());
2074 EXPECT_TRUE(surface->renderSurface()->drawOpacityIsAnimating());
2075
[email protected]167ed9d52012-10-31 20:47:582076 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142077
2078 this->visitLayer(topmost, occlusion);
2079 this->enterLayer(parent2, occlusion);
2080 // This occlusion will affect all surfaces.
[email protected]167ed9d52012-10-31 20:47:582081 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:142082 this->leaveLayer(parent2, occlusion);
2083
2084 this->visitLayer(surfaceChild2, occlusion);
2085 this->enterLayer(surfaceChild, occlusion);
[email protected]167ed9d52012-10-31 20:47:582086 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:142087 this->leaveLayer(surfaceChild, occlusion);
2088 this->enterLayer(surface, occlusion);
[email protected]167ed9d52012-10-31 20:47:582089 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:142090 this->leaveLayer(surface, occlusion);
2091
2092 this->enterContributingSurface(surface, occlusion);
2093 // Occlusion within the surface is lost when leaving the animating surface.
[email protected]167ed9d52012-10-31 20:47:582094 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:142095 this->leaveContributingSurface(surface, occlusion);
2096
2097 this->visitLayer(layer, occlusion);
2098 this->enterLayer(parent, occlusion);
2099
2100 // Occlusion is not added for the animating |layer|.
[email protected]167ed9d52012-10-31 20:47:582101 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:142102 }
2103};
2104
[email protected]96baf3e2012-10-22 23:09:552105MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread);
[email protected]94f206c12012-08-25 00:09:142106
[email protected]ece1d952012-10-18 21:26:072107template<class Types>
[email protected]96baf3e2012-10-22 23:09:552108class OcclusionTrackerTestAnimationOpacity0OnMainThread : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142109protected:
[email protected]96baf3e2012-10-22 23:09:552110 OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142111 void runMyTest()
2112 {
[email protected]d0f98362012-11-01 23:02:382113 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
2114 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2115 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2116 typename Types::ContentLayerType* surfaceChild = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 300), true);
2117 typename Types::ContentLayerType* surfaceChild2 = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 300), true);
2118 typename Types::ContentLayerType* parent2 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2119 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:142120
2121 addOpacityTransitionToController(*layer->layerAnimationController(), 10, 1, 0, false);
2122 addOpacityTransitionToController(*surface->layerAnimationController(), 10, 1, 0, false);
2123 this->calcDrawEtc(parent);
2124
2125 EXPECT_TRUE(layer->drawOpacityIsAnimating());
2126 EXPECT_FALSE(surface->drawOpacityIsAnimating());
2127 EXPECT_TRUE(surface->renderSurface()->drawOpacityIsAnimating());
2128
[email protected]167ed9d52012-10-31 20:47:582129 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142130
2131 this->visitLayer(topmost, occlusion);
2132 this->enterLayer(parent2, occlusion);
2133 // This occlusion will affect all surfaces.
[email protected]167ed9d52012-10-31 20:47:582134 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:142135 this->leaveLayer(parent2, occlusion);
2136
2137 this->visitLayer(surfaceChild2, occlusion);
2138 this->enterLayer(surfaceChild, occlusion);
[email protected]167ed9d52012-10-31 20:47:582139 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:142140 this->leaveLayer(surfaceChild, occlusion);
2141 this->enterLayer(surface, occlusion);
[email protected]167ed9d52012-10-31 20:47:582142 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:142143 this->leaveLayer(surface, occlusion);
2144
2145 this->enterContributingSurface(surface, occlusion);
2146 // Occlusion within the surface is lost when leaving the animating surface.
[email protected]167ed9d52012-10-31 20:47:582147 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:142148 this->leaveContributingSurface(surface, occlusion);
2149
2150 this->visitLayer(layer, occlusion);
2151 this->enterLayer(parent, occlusion);
2152
2153 // Occlusion is not added for the animating |layer|.
[email protected]167ed9d52012-10-31 20:47:582154 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:142155 }
2156};
2157
[email protected]96baf3e2012-10-22 23:09:552158MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread);
[email protected]94f206c12012-08-25 00:09:142159
[email protected]ece1d952012-10-18 21:26:072160template<class Types>
[email protected]96baf3e2012-10-22 23:09:552161class OcclusionTrackerTestAnimationTranslateOnMainThread : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142162protected:
[email protected]96baf3e2012-10-22 23:09:552163 OcclusionTrackerTestAnimationTranslateOnMainThread(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142164 void runMyTest()
2165 {
[email protected]d0f98362012-11-01 23:02:382166 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
2167 typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2168 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300), true);
2169 typename Types::ContentLayerType* surfaceChild = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(200, 300), true);
2170 typename Types::ContentLayerType* surfaceChild2 = this->createDrawingLayer(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 300), true);
2171 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:142172
2173 addAnimatedTransformToController(*layer->layerAnimationController(), 10, 30, 0);
2174 addAnimatedTransformToController(*surface->layerAnimationController(), 10, 30, 0);
2175 addAnimatedTransformToController(*surfaceChild->layerAnimationController(), 10, 30, 0);
2176 this->calcDrawEtc(parent);
2177
2178 EXPECT_TRUE(layer->drawTransformIsAnimating());
2179 EXPECT_TRUE(layer->screenSpaceTransformIsAnimating());
2180 EXPECT_TRUE(surface->renderSurface()->targetSurfaceTransformsAreAnimating());
2181 EXPECT_TRUE(surface->renderSurface()->screenSpaceTransformsAreAnimating());
2182 // The surface owning layer doesn't animate against its own surface.
2183 EXPECT_FALSE(surface->drawTransformIsAnimating());
2184 EXPECT_TRUE(surface->screenSpaceTransformIsAnimating());
2185 EXPECT_TRUE(surfaceChild->drawTransformIsAnimating());
2186 EXPECT_TRUE(surfaceChild->screenSpaceTransformIsAnimating());
2187
[email protected]167ed9d52012-10-31 20:47:582188 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142189
2190 this->visitLayer(surface2, occlusion);
2191 this->enterContributingSurface(surface2, occlusion);
2192
[email protected]ac7c7f52012-11-08 06:26:502193 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:142194
2195 this->leaveContributingSurface(surface2, occlusion);
2196 this->enterLayer(surfaceChild2, occlusion);
2197
2198 // surfaceChild2 is moving in screen space but not relative to its target, so occlusion should happen in its target space only.
2199 // It also means that things occluding in screen space (e.g. surface2) cannot occlude this layer.
[email protected]167ed9d52012-10-31 20:47:582200 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 300), occlusion.unoccludedLayerContentRect(surfaceChild2, gfx::Rect(0, 0, 100, 300)));
2201 EXPECT_FALSE(occlusion.occludedLayer(surfaceChild, gfx::Rect(0, 0, 50, 300)));
[email protected]94f206c12012-08-25 00:09:142202
2203 this->leaveLayer(surfaceChild2, occlusion);
2204 this->enterLayer(surfaceChild, occlusion);
[email protected]167ed9d52012-10-31 20:47:582205 EXPECT_FALSE(occlusion.occludedLayer(surfaceChild, gfx::Rect(0, 0, 100, 300)));
[email protected]ac7c7f52012-11-08 06:26:502206 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), occlusion.occlusionInScreenSpace().ToString());
2207 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]167ed9d52012-10-31 20:47:582208 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:142209
2210 // The surfaceChild is occluded by the surfaceChild2, but is moving relative its target and the screen, so it
2211 // can't be occluded.
[email protected]167ed9d52012-10-31 20:47:582212 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 300), occlusion.unoccludedLayerContentRect(surfaceChild, gfx::Rect(0, 0, 200, 300)));
2213 EXPECT_FALSE(occlusion.occludedLayer(surfaceChild, gfx::Rect(0, 0, 50, 300)));
[email protected]94f206c12012-08-25 00:09:142214
2215 this->leaveLayer(surfaceChild, occlusion);
2216 this->enterLayer(surface, occlusion);
2217 // 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:502218 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), occlusion.occlusionInScreenSpace().ToString());
2219 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]167ed9d52012-10-31 20:47:582220 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:142221
2222 this->leaveLayer(surface, occlusion);
2223 // 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:502224 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), occlusion.occlusionInScreenSpace().ToString());
2225 EXPECT_EQ(gfx::Rect(0, 0, 300, 300).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]167ed9d52012-10-31 20:47:582226 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:142227
2228 this->enterContributingSurface(surface, occlusion);
2229 // The contributing |surface| is animating so it can't be occluded.
[email protected]167ed9d52012-10-31 20:47:582230 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:142231 this->leaveContributingSurface(surface, occlusion);
2232
2233 this->enterLayer(layer, occlusion);
2234 // 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:582235 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:142236 this->leaveLayer(layer, occlusion);
2237
2238 this->enterLayer(parent, occlusion);
2239 // The |layer| is animating in the screen and in its target, so no occlusion is added.
[email protected]167ed9d52012-10-31 20:47:582240 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:142241 }
2242};
2243
[email protected]96baf3e2012-10-22 23:09:552244MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread);
[email protected]94f206c12012-08-25 00:09:142245
[email protected]ece1d952012-10-18 21:26:072246template<class Types>
[email protected]96baf3e2012-10-22 23:09:552247class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142248protected:
[email protected]96baf3e2012-10-22 23:09:552249 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142250 void runMyTest()
2251 {
2252 WebTransformationMatrix surfaceTransform;
2253 surfaceTransform.translate(300, 300);
2254 surfaceTransform.scale(2);
2255 surfaceTransform.translate(-150, -150);
2256
[email protected]d0f98362012-11-01 23:02:382257 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(500, 500));
2258 typename Types::ContentLayerType* surface = this->createDrawingSurface(parent, surfaceTransform, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2259 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:582260 surface->setOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
2261 surface2->setOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
[email protected]94f206c12012-08-25 00:09:142262 this->calcDrawEtc(parent);
2263
[email protected]167ed9d52012-10-31 20:47:582264 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142265
2266 this->visitLayer(surface2, occlusion);
2267 this->visitContributingSurface(surface2, occlusion);
2268
[email protected]ac7c7f52012-11-08 06:26:502269 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(), occlusion.occlusionInScreenSpace().ToString());
2270 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142271
2272 // Clear any stored occlusion.
2273 occlusion.setOcclusionInScreenSpace(Region());
2274 occlusion.setOcclusionInTargetSurface(Region());
2275
2276 this->visitLayer(surface, occlusion);
2277 this->visitContributingSurface(surface, occlusion);
2278
[email protected]ac7c7f52012-11-08 06:26:502279 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(), occlusion.occlusionInScreenSpace().ToString());
2280 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142281 }
2282};
2283
[email protected]96baf3e2012-10-22 23:09:552284MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:142285
[email protected]ece1d952012-10-18 21:26:072286template<class Types>
[email protected]96baf3e2012-10-22 23:09:552287class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142288protected:
[email protected]96baf3e2012-10-22 23:09:552289 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142290 void runMyTest()
2291 {
[email protected]d0f98362012-11-01 23:02:382292 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 300));
[email protected]23bbb412012-08-30 20:03:382293 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382294 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:582295 surface->setOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
[email protected]94f206c12012-08-25 00:09:142296 this->calcDrawEtc(parent);
2297
[email protected]167ed9d52012-10-31 20:47:582298 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142299
2300 this->visitLayer(surface, occlusion);
2301 this->visitContributingSurface(surface, occlusion);
2302
[email protected]ac7c7f52012-11-08 06:26:502303 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(), occlusion.occlusionInScreenSpace().ToString());
2304 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142305 }
2306};
2307
[email protected]96baf3e2012-10-22 23:09:552308MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:142309
[email protected]ece1d952012-10-18 21:26:072310template<class Types>
[email protected]96baf3e2012-10-22 23:09:552311class OcclusionTrackerTestReplicaOccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142312protected:
[email protected]96baf3e2012-10-22 23:09:552313 OcclusionTrackerTestReplicaOccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142314 void runMyTest()
2315 {
[email protected]d0f98362012-11-01 23:02:382316 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2317 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2318 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(100, 100));
2319 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:142320 this->calcDrawEtc(parent);
2321
[email protected]167ed9d52012-10-31 20:47:582322 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2323 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142324
2325 // |topmost| occludes the replica, but not the surface itself.
2326 this->visitLayer(topmost, occlusion);
2327
[email protected]ac7c7f52012-11-08 06:26:502328 EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(), occlusion.occlusionInScreenSpace().ToString());
2329 EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142330
2331 this->visitLayer(surface, occlusion);
2332
[email protected]ac7c7f52012-11-08 06:26:502333 EXPECT_EQ(gfx::Rect(0, 0, 100, 200).ToString(), occlusion.occlusionInScreenSpace().ToString());
2334 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142335
2336 this->enterContributingSurface(surface, occlusion);
2337
2338 // Surface is not occluded so it shouldn't think it is.
[email protected]167ed9d52012-10-31 20:47:582339 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:142340 }
2341};
2342
[email protected]96baf3e2012-10-22 23:09:552343ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaOccluded);
[email protected]94f206c12012-08-25 00:09:142344
[email protected]ece1d952012-10-18 21:26:072345template<class Types>
[email protected]96baf3e2012-10-22 23:09:552346class OcclusionTrackerTestSurfaceWithReplicaUnoccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142347protected:
[email protected]96baf3e2012-10-22 23:09:552348 OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142349 void runMyTest()
2350 {
[email protected]d0f98362012-11-01 23:02:382351 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2352 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2353 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(100, 100));
2354 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:142355 this->calcDrawEtc(parent);
2356
[email protected]167ed9d52012-10-31 20:47:582357 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2358 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142359
2360 // |topmost| occludes the surface, but not the entire surface's replica.
2361 this->visitLayer(topmost, occlusion);
2362
[email protected]ac7c7f52012-11-08 06:26:502363 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(), occlusion.occlusionInScreenSpace().ToString());
2364 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142365
2366 this->visitLayer(surface, occlusion);
2367
[email protected]ac7c7f52012-11-08 06:26:502368 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(), occlusion.occlusionInScreenSpace().ToString());
2369 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142370
2371 this->enterContributingSurface(surface, occlusion);
2372
2373 // Surface is occluded, but only the top 10px of the replica.
[email protected]167ed9d52012-10-31 20:47:582374 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 100, 100)));
2375 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:142376 }
2377};
2378
[email protected]96baf3e2012-10-22 23:09:552379ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded);
[email protected]94f206c12012-08-25 00:09:142380
[email protected]ece1d952012-10-18 21:26:072381template<class Types>
[email protected]96baf3e2012-10-22 23:09:552382class OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142383protected:
[email protected]96baf3e2012-10-22 23:09:552384 OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142385 void runMyTest()
2386 {
[email protected]d0f98362012-11-01 23:02:382387 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2388 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2389 this->createReplicaLayer(surface, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(100, 100));
2390 typename Types::LayerType* overSurface = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(40, 100), true);
2391 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:142392 this->calcDrawEtc(parent);
2393
[email protected]167ed9d52012-10-31 20:47:582394 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2395 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142396
2397 // These occlude the surface and replica differently, so we can test each one.
2398 this->visitLayer(overReplica, occlusion);
2399 this->visitLayer(overSurface, occlusion);
2400
[email protected]ac7c7f52012-11-08 06:26:502401 EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 40, 100), gfx::Rect(0, 100, 50, 100)).ToString(), occlusion.occlusionInScreenSpace().ToString());
2402 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:142403
2404 this->visitLayer(surface, occlusion);
2405
[email protected]ac7c7f52012-11-08 06:26:502406 EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 100, 50, 100)).ToString(), occlusion.occlusionInScreenSpace().ToString());
2407 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142408
2409 this->enterContributingSurface(surface, occlusion);
2410
2411 // Surface and replica are occluded different amounts.
[email protected]167ed9d52012-10-31 20:47:582412 EXPECT_RECT_EQ(gfx::Rect(40, 0, 60, 100), occlusion.unoccludedContributingSurfaceContentRect(surface, false, gfx::Rect(0, 0, 100, 100)));
2413 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:142414 }
2415};
2416
[email protected]96baf3e2012-10-22 23:09:552417ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently);
[email protected]94f206c12012-08-25 00:09:142418
[email protected]ece1d952012-10-18 21:26:072419template<class Types>
[email protected]96baf3e2012-10-22 23:09:552420class OcclusionTrackerTestSurfaceChildOfSurface : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142421protected:
[email protected]96baf3e2012-10-22 23:09:552422 OcclusionTrackerTestSurfaceChildOfSurface(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142423 void runMyTest()
2424 {
2425 // This test verifies that the surface cliprect does not end up empty and clip away the entire unoccluded rect.
2426
[email protected]d0f98362012-11-01 23:02:382427 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2428 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2429 typename Types::LayerType* surfaceChild = this->createDrawingSurface(surface, this->identityMatrix, gfx::PointF(0, 10), gfx::Size(100, 50), true);
2430 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:142431 this->calcDrawEtc(parent);
2432
[email protected]167ed9d52012-10-31 20:47:582433 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142434
2435 // |topmost| occludes everything partially so we know occlusion is happening at all.
2436 this->visitLayer(topmost, occlusion);
2437
[email protected]ac7c7f52012-11-08 06:26:502438 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
2439 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142440
2441 this->visitLayer(surfaceChild, occlusion);
2442
2443 // surfaceChild increases the occlusion in the screen by a narrow sliver.
[email protected]ac7c7f52012-11-08 06:26:502444 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:142445 // In its own surface, surfaceChild is at 0,0 as is its occlusion.
[email protected]ac7c7f52012-11-08 06:26:502446 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142447
2448 // The root layer always has a clipRect. So the parent of |surface| has a clipRect. However, the owning layer for |surface| does not
2449 // mask to bounds, so it doesn't have a clipRect of its own. Thus the parent of |surfaceChild| exercises different code paths
2450 // as its parent does not have a clipRect.
2451
2452 this->enterContributingSurface(surfaceChild, occlusion);
2453 // The surfaceChild's parent does not have a clipRect as it owns a render surface. Make sure the unoccluded rect
2454 // does not get clipped away inappropriately.
[email protected]167ed9d52012-10-31 20:47:582455 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:142456 this->leaveContributingSurface(surfaceChild, occlusion);
2457
2458 // When the surfaceChild's occlusion is transformed up to its parent, make sure it is not clipped away inappropriately also.
2459 this->enterLayer(surface, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502460 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(), occlusion.occlusionInScreenSpace().ToString());
2461 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142462 this->leaveLayer(surface, occlusion);
2463
2464 this->enterContributingSurface(surface, occlusion);
2465 // The surface's parent does have a clipRect as it is the root layer.
[email protected]167ed9d52012-10-31 20:47:582466 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:142467 }
2468};
2469
[email protected]96baf3e2012-10-22 23:09:552470ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:142471
[email protected]ece1d952012-10-18 21:26:072472template<class Types>
[email protected]96baf3e2012-10-22 23:09:552473class OcclusionTrackerTestTopmostSurfaceIsClippedToViewport : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142474protected:
[email protected]96baf3e2012-10-22 23:09:552475 OcclusionTrackerTestTopmostSurfaceIsClippedToViewport(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142476 void runMyTest()
2477 {
2478 // This test verifies that the top-most surface is considered occluded outside of its target's clipRect and outside the viewport rect.
2479
[email protected]d0f98362012-11-01 23:02:382480 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 200));
2481 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:142482 this->calcDrawEtc(parent);
2483
2484 {
2485 // Make a viewport rect that is larger than the root layer.
[email protected]167ed9d52012-10-31 20:47:582486 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142487
2488 this->visitLayer(surface, occlusion);
2489
2490 // The root layer always has a clipRect. So the parent of |surface| has a clipRect giving the surface itself a clipRect.
2491 this->enterContributingSurface(surface, occlusion);
2492 // Make sure the parent's clipRect clips the unoccluded region of the child surface.
[email protected]167ed9d52012-10-31 20:47:582493 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:142494 }
2495 this->resetLayerIterator();
2496 {
2497 // Make a viewport rect that is smaller than the root layer.
[email protected]167ed9d52012-10-31 20:47:582498 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:142499
2500 this->visitLayer(surface, occlusion);
2501
2502 // The root layer always has a clipRect. So the parent of |surface| has a clipRect giving the surface itself a clipRect.
2503 this->enterContributingSurface(surface, occlusion);
2504 // Make sure the viewport rect clips the unoccluded region of the child surface.
[email protected]167ed9d52012-10-31 20:47:582505 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:142506 }
2507 }
2508};
2509
[email protected]96baf3e2012-10-22 23:09:552510ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTopmostSurfaceIsClippedToViewport);
[email protected]94f206c12012-08-25 00:09:142511
[email protected]ece1d952012-10-18 21:26:072512template<class Types>
[email protected]96baf3e2012-10-22 23:09:552513class OcclusionTrackerTestSurfaceChildOfClippingSurface : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142514protected:
[email protected]96baf3e2012-10-22 23:09:552515 OcclusionTrackerTestSurfaceChildOfClippingSurface(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142516 void runMyTest()
2517 {
2518 // This test verifies that the surface cliprect does not end up empty and clip away the entire unoccluded rect.
2519
[email protected]d0f98362012-11-01 23:02:382520 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(80, 200));
[email protected]23bbb412012-08-30 20:03:382521 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382522 typename Types::LayerType* surface = this->createDrawingSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), true);
2523 typename Types::LayerType* surfaceChild = this->createDrawingSurface(surface, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(100, 100), false);
2524 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:142525 this->calcDrawEtc(parent);
2526
[email protected]167ed9d52012-10-31 20:47:582527 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2528 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142529
2530 // |topmost| occludes everything partially so we know occlusion is happening at all.
2531 this->visitLayer(topmost, occlusion);
2532
[email protected]ac7c7f52012-11-08 06:26:502533 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
2534 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142535
2536 // surfaceChild is not opaque and does not occlude, so we have a non-empty unoccluded area on surface.
2537 this->visitLayer(surfaceChild, occlusion);
2538
[email protected]ac7c7f52012-11-08 06:26:502539 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), occlusion.occlusionInScreenSpace().ToString());
2540 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142541
2542 // The root layer always has a clipRect. So the parent of |surface| has a clipRect. However, the owning layer for |surface| does not
2543 // mask to bounds, so it doesn't have a clipRect of its own. Thus the parent of |surfaceChild| exercises different code paths
2544 // as its parent does not have a clipRect.
2545
2546 this->enterContributingSurface(surfaceChild, occlusion);
2547 // The surfaceChild's parent does not have a clipRect as it owns a render surface.
[email protected]167ed9d52012-10-31 20:47:582548 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:142549 this->leaveContributingSurface(surfaceChild, occlusion);
2550
2551 this->visitLayer(surface, occlusion);
2552 this->enterContributingSurface(surface, occlusion);
2553 // The surface's parent does have a clipRect as it is the root layer.
[email protected]167ed9d52012-10-31 20:47:582554 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:142555 }
2556};
2557
[email protected]96baf3e2012-10-22 23:09:552558ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfClippingSurface);
[email protected]94f206c12012-08-25 00:09:142559
[email protected]ece1d952012-10-18 21:26:072560template<class Types>
[email protected]96baf3e2012-10-22 23:09:552561class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142562protected:
[email protected]96baf3e2012-10-22 23:09:552563 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142564 void runMyTest()
2565 {
2566 WebTransformationMatrix scaleByHalf;
2567 scaleByHalf.scale(0.5);
2568
2569 // Make a surface and its replica, each 50x50, that are completely surrounded by opaque layers which are above them in the z-order.
2570 // 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
2571 // appears at 50, 50 and the replica at 200, 50.
[email protected]d0f98362012-11-01 23:02:382572 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
2573 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(50, 50), gfx::Size(100, 100), false);
2574 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(300, 0), gfx::Size());
2575 typename Types::LayerType* occludingLayer1 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 50), true);
2576 typename Types::LayerType* occludingLayer2 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(300, 50), true);
2577 typename Types::LayerType* occludingLayer3 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 50), gfx::Size(50, 50), true);
2578 typename Types::LayerType* occludingLayer4 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(100, 50), gfx::Size(100, 50), true);
2579 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:142580
2581 // Filters make the layer own a surface.
2582 WebFilterOperations filters;
2583 filters.append(WebFilterOperation::createBlurFilter(10));
2584 filteredSurface->setBackgroundFilters(filters);
2585
2586 // Save the distance of influence for the blur effect.
2587 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2588 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2589
2590 this->calcDrawEtc(parent);
2591
[email protected]167ed9d52012-10-31 20:47:582592 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2593 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142594
2595 // These layers occlude pixels directly beside the filteredSurface. Because filtered surface blends pixels in a radius, it will
2596 // need to see some of the pixels (up to radius far) underneath the occludingLayers.
2597 this->visitLayer(occludingLayer5, occlusion);
2598 this->visitLayer(occludingLayer4, occlusion);
2599 this->visitLayer(occludingLayer3, occlusion);
2600 this->visitLayer(occludingLayer2, occlusion);
2601 this->visitLayer(occludingLayer1, occlusion);
2602
[email protected]ac7c7f52012-11-08 06:26:502603 Region expectedOcclusion;
2604 expectedOcclusion.Union(gfx::Rect(0, 0, 300, 50));
2605 expectedOcclusion.Union(gfx::Rect(0, 50, 50, 50));
2606 expectedOcclusion.Union(gfx::Rect(100, 50, 100, 50));
2607 expectedOcclusion.Union(gfx::Rect(250, 50, 50, 50));
2608 expectedOcclusion.Union(gfx::Rect(0, 100, 300, 50));
2609
2610 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2611 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142612
2613 // Everything outside the surface/replica is occluded but the surface/replica itself is not.
2614 this->enterLayer(filteredSurface, occlusion);
[email protected]167ed9d52012-10-31 20:47:582615 EXPECT_RECT_EQ(gfx::Rect(1, 0, 99, 100), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(1, 0, 100, 100)));
2616 EXPECT_RECT_EQ(gfx::Rect(0, 1, 100, 99), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(0, 1, 100, 100)));
2617 EXPECT_RECT_EQ(gfx::Rect(0, 0, 99, 100), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(-1, 0, 100, 100)));
2618 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:142619
[email protected]167ed9d52012-10-31 20:47:582620 EXPECT_RECT_EQ(gfx::Rect(300 + 1, 0, 99, 100), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(300 + 1, 0, 100, 100)));
2621 EXPECT_RECT_EQ(gfx::Rect(300 + 0, 1, 100, 99), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(300 + 0, 1, 100, 100)));
2622 EXPECT_RECT_EQ(gfx::Rect(300 + 0, 0, 99, 100), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(300 - 1, 0, 100, 100)));
2623 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:142624 this->leaveLayer(filteredSurface, occlusion);
2625
2626 // The filtered layer/replica does not occlude.
[email protected]ac7c7f52012-11-08 06:26:502627 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2628 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142629
2630 // 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:382631 // 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:142632 this->visitContributingSurface(filteredSurface, occlusion);
2633
2634 this->enterLayer(parent, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502635
2636 Region expectedBlurredOcclusion;
2637 expectedBlurredOcclusion.Union(gfx::Rect(0, 0, 300, 50 - outsetTop));
2638 expectedBlurredOcclusion.Union(gfx::Rect(0, 50 - outsetTop, 50 - outsetLeft, 50 + outsetTop + outsetBottom));
2639 expectedBlurredOcclusion.Union(gfx::Rect(100 + outsetRight, 50 - outsetTop, 100 - outsetRight - outsetLeft, 50 + outsetTop + outsetBottom));
2640 expectedBlurredOcclusion.Union(gfx::Rect(250 + outsetRight, 50 - outsetTop, 50 - outsetRight, 50 + outsetTop + outsetBottom));
2641 expectedBlurredOcclusion.Union(gfx::Rect(0, 100 + outsetBottom, 300, 50 - outsetBottom));
2642
2643 EXPECT_EQ(expectedBlurredOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2644 EXPECT_EQ(expectedBlurredOcclusion.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142645
[email protected]167ed9d52012-10-31 20:47:582646 gfx::Rect outsetRect;
2647 gfx::Rect testRect;
[email protected]94f206c12012-08-25 00:09:142648
2649 // Nothing in the blur outsets for the filteredSurface is occluded.
[email protected]167ed9d52012-10-31 20:47:582650 outsetRect = gfx::Rect(50 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
[email protected]94f206c12012-08-25 00:09:142651 testRect = outsetRect;
[email protected]710ffc02012-10-30 21:42:022652 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142653
2654 // Stuff outside the blur outsets is still occluded though.
2655 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582656 testRect.Inset(0, 0, -1, 0);
[email protected]710ffc02012-10-30 21:42:022657 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142658 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582659 testRect.Inset(0, 0, 0, -1);
[email protected]710ffc02012-10-30 21:42:022660 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142661 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582662 testRect.Inset(-1, 0, 0, 0);
[email protected]710ffc02012-10-30 21:42:022663 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142664 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582665 testRect.Inset(0, -1, 0, 0);
[email protected]710ffc02012-10-30 21:42:022666 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142667
2668 // Nothing in the blur outsets for the filteredSurface's replica is occluded.
[email protected]167ed9d52012-10-31 20:47:582669 outsetRect = gfx::Rect(200 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
[email protected]94f206c12012-08-25 00:09:142670 testRect = outsetRect;
[email protected]710ffc02012-10-30 21:42:022671 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142672
2673 // Stuff outside the blur outsets is still occluded though.
2674 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582675 testRect.Inset(0, 0, -1, 0);
[email protected]710ffc02012-10-30 21:42:022676 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142677 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582678 testRect.Inset(0, 0, 0, -1);
[email protected]710ffc02012-10-30 21:42:022679 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142680 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582681 testRect.Inset(-1, 0, 0, 0);
[email protected]710ffc02012-10-30 21:42:022682 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142683 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582684 testRect.Inset(0, -1, 0, 0);
[email protected]710ffc02012-10-30 21:42:022685 EXPECT_RECT_EQ(outsetRect, occlusion.unoccludedLayerContentRect(parent, testRect));
[email protected]94f206c12012-08-25 00:09:142686 }
2687};
2688
[email protected]96baf3e2012-10-22 23:09:552689ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142690
[email protected]ece1d952012-10-18 21:26:072691template<class Types>
[email protected]96baf3e2012-10-22 23:09:552692class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142693protected:
[email protected]96baf3e2012-10-22 23:09:552694 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142695 void runMyTest()
2696 {
2697 WebTransformationMatrix scaleByHalf;
2698 scaleByHalf.scale(0.5);
2699
2700 // 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:382701 typename Types::ContentLayerType* root = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(75, 75));
2702 typename Types::LayerType* parent = this->createSurface(root, scaleByHalf, gfx::PointF(0, 0), gfx::Size(150, 150));
[email protected]94f206c12012-08-25 00:09:142703 parent->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382704 typename Types::LayerType* filteredSurface1 = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2705 typename Types::LayerType* filteredSurface2 = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(0, 0), gfx::Size(300, 300), false);
2706 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:142707
2708 // Filters make the layers own surfaces.
2709 WebFilterOperations filters;
[email protected]518ee582012-10-24 18:29:442710 filters.append(WebFilterOperation::createBlurFilter(1));
[email protected]94f206c12012-08-25 00:09:142711 filteredSurface1->setBackgroundFilters(filters);
2712 filteredSurface2->setBackgroundFilters(filters);
2713
2714 // Save the distance of influence for the blur effect.
2715 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2716 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2717
2718 this->calcDrawEtc(root);
2719
[email protected]167ed9d52012-10-31 20:47:582720 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2721 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142722
2723 this->visitLayer(occludingLayerAbove, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502724 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(), occlusion.occlusionInScreenSpace().ToString());
2725 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142726
2727 this->visitLayer(filteredSurface2, occlusion);
2728 this->visitContributingSurface(filteredSurface2, occlusion);
2729 this->visitLayer(filteredSurface1, occlusion);
2730 this->visitContributingSurface(filteredSurface1, occlusion);
2731
[email protected]f3922f22012-10-12 09:20:382732 // Test expectations in the target.
[email protected]167ed9d52012-10-31 20:47:582733 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:502734 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142735
[email protected]518ee582012-10-24 18:29:442736 // 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:502737 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
[email protected]94f206c12012-08-25 00:09:142738 }
2739};
2740
[email protected]96baf3e2012-10-22 23:09:552741ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:142742
[email protected]ece1d952012-10-18 21:26:072743template<class Types>
[email protected]96baf3e2012-10-22 23:09:552744class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142745protected:
[email protected]96baf3e2012-10-22 23:09:552746 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142747 void runMyTest()
2748 {
2749 // 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:382750 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
[email protected]94f206c12012-08-25 00:09:142751 // We stick the filtered surface inside a clipping surface so that we can make sure the clip is honored when exposing pixels for
2752 // the background filter.
[email protected]d0f98362012-11-01 23:02:382753 typename Types::LayerType* clippingSurface = this->createSurface(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 70));
[email protected]94f206c12012-08-25 00:09:142754 clippingSurface->setMasksToBounds(true);
[email protected]d0f98362012-11-01 23:02:382755 typename Types::LayerType* filteredSurface = this->createDrawingLayer(clippingSurface, this->identityMatrix, gfx::PointF(50, 50), gfx::Size(50, 50), false);
2756 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(150, 0), gfx::Size());
2757 typename Types::LayerType* occludingLayer1 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 50), true);
2758 typename Types::LayerType* occludingLayer2 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 100), gfx::Size(300, 50), true);
2759 typename Types::LayerType* occludingLayer3 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 50), gfx::Size(50, 50), true);
2760 typename Types::LayerType* occludingLayer4 = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(100, 50), gfx::Size(100, 50), true);
2761 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:142762
2763 // Filters make the layer own a surface. This filter is large enough that it goes outside the bottom of the clippingSurface.
2764 WebFilterOperations filters;
2765 filters.append(WebFilterOperation::createBlurFilter(12));
2766 filteredSurface->setBackgroundFilters(filters);
2767
2768 // Save the distance of influence for the blur effect.
2769 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2770 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2771
2772 this->calcDrawEtc(parent);
2773
[email protected]167ed9d52012-10-31 20:47:582774 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2775 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142776
2777 // These layers occlude pixels directly beside the filteredSurface. Because filtered surface blends pixels in a radius, it will
2778 // need to see some of the pixels (up to radius far) underneath the occludingLayers.
2779 this->visitLayer(occludingLayer5, occlusion);
2780 this->visitLayer(occludingLayer4, occlusion);
2781 this->visitLayer(occludingLayer3, occlusion);
2782 this->visitLayer(occludingLayer2, occlusion);
2783 this->visitLayer(occludingLayer1, occlusion);
2784
[email protected]ac7c7f52012-11-08 06:26:502785 Region expectedOcclusion;
2786 expectedOcclusion.Union(gfx::Rect(0, 0, 300, 50));
2787 expectedOcclusion.Union(gfx::Rect(0, 50, 50, 50));
2788 expectedOcclusion.Union(gfx::Rect(100, 50, 100, 50));
2789 expectedOcclusion.Union(gfx::Rect(250, 50, 50, 50));
2790 expectedOcclusion.Union(gfx::Rect(0, 100, 300, 50));
2791
2792 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2793 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142794
2795 // Everything outside the surface/replica is occluded but the surface/replica itself is not.
2796 this->enterLayer(filteredSurface, occlusion);
[email protected]167ed9d52012-10-31 20:47:582797 EXPECT_RECT_EQ(gfx::Rect(1, 0, 49, 50), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(1, 0, 50, 50)));
2798 EXPECT_RECT_EQ(gfx::Rect(0, 1, 50, 49), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(0, 1, 50, 50)));
2799 EXPECT_RECT_EQ(gfx::Rect(0, 0, 49, 50), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(-1, 0, 50, 50)));
2800 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:142801
[email protected]167ed9d52012-10-31 20:47:582802 EXPECT_RECT_EQ(gfx::Rect(150 + 1, 0, 49, 50), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(150 + 1, 0, 50, 50)));
2803 EXPECT_RECT_EQ(gfx::Rect(150 + 0, 1, 50, 49), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(150 + 0, 1, 50, 50)));
2804 EXPECT_RECT_EQ(gfx::Rect(150 + 0, 0, 49, 50), occlusion.unoccludedLayerContentRect(filteredSurface, gfx::Rect(150 - 1, 0, 50, 50)));
2805 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:142806 this->leaveLayer(filteredSurface, occlusion);
2807
2808 // The filtered layer/replica does not occlude.
[email protected]ac7c7f52012-11-08 06:26:502809 EXPECT_EQ(expectedOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2810 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142811
2812 // The surface has a background blur, so it needs pixels that are currently considered occluded in order to be drawn. So the pixels
2813 // it needs should be removed some the occluded area so that when we get to the parent they are drawn.
2814 this->visitContributingSurface(filteredSurface, occlusion);
2815
2816 this->enterContributingSurface(clippingSurface, occlusion);
[email protected]ac7c7f52012-11-08 06:26:502817
2818 Region expectedBlurredOcclusion;
2819 expectedBlurredOcclusion.Union(gfx::Rect(0, 0, 300, 50 - outsetTop));
2820 expectedBlurredOcclusion.Union(gfx::Rect(0, 50 - outsetTop, 50 - outsetLeft, 20 + outsetTop + outsetBottom));
2821 expectedBlurredOcclusion.Union(gfx::Rect(100 + outsetRight, 50 - outsetTop, 100 - outsetRight - outsetLeft, 20 + outsetTop + outsetBottom));
2822 expectedBlurredOcclusion.Union(gfx::Rect(250 + outsetRight, 50 - outsetTop, 50 - outsetRight, 20 + outsetTop + outsetBottom));
2823 expectedBlurredOcclusion.Union(gfx::Rect(0, 100 + 5, 300, 50 - 5));
2824
2825 EXPECT_EQ(expectedBlurredOcclusion.ToString(), occlusion.occlusionInScreenSpace().ToString());
2826 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142827
[email protected]167ed9d52012-10-31 20:47:582828 gfx::Rect outsetRect;
2829 gfx::Rect clippedOutsetRect;
2830 gfx::Rect testRect;
[email protected]94f206c12012-08-25 00:09:142831
2832 // Nothing in the (clipped) blur outsets for the filteredSurface is occluded.
[email protected]167ed9d52012-10-31 20:47:582833 outsetRect = gfx::Rect(50 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
2834 clippedOutsetRect = gfx::IntersectRects(outsetRect, gfx::Rect(0 - outsetLeft, 0 - outsetTop, 300 + outsetLeft + outsetRight, 70 + outsetTop + outsetBottom));
[email protected]94f206c12012-08-25 00:09:142835 testRect = outsetRect;
[email protected]710ffc02012-10-30 21:42:022836 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142837
2838 // Stuff outside the (clipped) blur outsets is still occluded though.
2839 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582840 testRect.Inset(0, 0, -1, 0);
[email protected]710ffc02012-10-30 21:42:022841 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142842 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582843 testRect.Inset(0, 0, 0, -1);
[email protected]710ffc02012-10-30 21:42:022844 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142845 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582846 testRect.Inset(-1, 0, 0, 0);
[email protected]710ffc02012-10-30 21:42:022847 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142848 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582849 testRect.Inset(0, -1, 0, 0);
[email protected]710ffc02012-10-30 21:42:022850 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142851
2852 // Nothing in the (clipped) blur outsets for the filteredSurface's replica is occluded.
[email protected]167ed9d52012-10-31 20:47:582853 outsetRect = gfx::Rect(200 - outsetLeft, 50 - outsetTop, 50 + outsetLeft + outsetRight, 50 + outsetTop + outsetBottom);
2854 clippedOutsetRect = gfx::IntersectRects(outsetRect, gfx::Rect(0 - outsetLeft, 0 - outsetTop, 300 + outsetLeft + outsetRight, 70 + outsetTop + outsetBottom));
[email protected]94f206c12012-08-25 00:09:142855 testRect = outsetRect;
[email protected]710ffc02012-10-30 21:42:022856 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142857
2858 // Stuff outside the (clipped) blur outsets is still occluded though.
2859 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582860 testRect.Inset(0, 0, -1, 0);
[email protected]710ffc02012-10-30 21:42:022861 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142862 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582863 testRect.Inset(0, 0, 0, -1);
[email protected]710ffc02012-10-30 21:42:022864 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142865 testRect = outsetRect;
[email protected]167ed9d52012-10-31 20:47:582866 testRect.Inset(-1, 0, 0, 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, -1, 0, 0);
[email protected]710ffc02012-10-30 21:42:022870 EXPECT_RECT_EQ(clippedOutsetRect, occlusion.unoccludedLayerContentRect(clippingSurface, testRect));
[email protected]94f206c12012-08-25 00:09:142871 }
2872};
2873
[email protected]96baf3e2012-10-22 23:09:552874ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip);
[email protected]94f206c12012-08-25 00:09:142875
[email protected]ece1d952012-10-18 21:26:072876template<class Types>
[email protected]96baf3e2012-10-22 23:09:552877class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142878protected:
[email protected]96baf3e2012-10-22 23:09:552879 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142880 void runMyTest()
2881 {
2882 WebTransformationMatrix scaleByHalf;
2883 scaleByHalf.scale(0.5);
2884
2885 // Make a surface and its replica, each 50x50, with a smaller 30x30 layer centered below each.
2886 // 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
2887 // appears at 50, 50 and the replica at 200, 50.
[email protected]d0f98362012-11-01 23:02:382888 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
2889 typename Types::LayerType* behindSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(60, 60), gfx::Size(30, 30), true);
2890 typename Types::LayerType* behindReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(210, 60), gfx::Size(30, 30), true);
2891 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(50, 50), gfx::Size(100, 100), false);
2892 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(300, 0), gfx::Size());
[email protected]94f206c12012-08-25 00:09:142893
2894 // Filters make the layer own a surface.
2895 WebFilterOperations filters;
2896 filters.append(WebFilterOperation::createBlurFilter(3));
2897 filteredSurface->setBackgroundFilters(filters);
2898
2899 this->calcDrawEtc(parent);
2900
[email protected]167ed9d52012-10-31 20:47:582901 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2902 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142903
2904 // The surface has a background blur, so it blurs non-opaque pixels below it.
2905 this->visitLayer(filteredSurface, occlusion);
2906 this->visitContributingSurface(filteredSurface, occlusion);
2907
2908 this->visitLayer(behindReplicaLayer, occlusion);
2909 this->visitLayer(behindSurfaceLayer, occlusion);
2910
2911 // The layers behind the surface are not blurred, and their occlusion does not change, until we leave the surface.
2912 // So it should not be modified by the filter here.
[email protected]167ed9d52012-10-31 20:47:582913 gfx::Rect occlusionBehindSurface = gfx::Rect(60, 60, 30, 30);
2914 gfx::Rect occlusionBehindReplica = gfx::Rect(210, 60, 30, 30);
[email protected]94f206c12012-08-25 00:09:142915
[email protected]ac7c7f52012-11-08 06:26:502916 Region expectedOpaqueBounds = UnionRegions(occlusionBehindSurface, occlusionBehindReplica);
2917 EXPECT_EQ(expectedOpaqueBounds.ToString(), occlusion.occlusionInScreenSpace().ToString());
2918 EXPECT_EQ(expectedOpaqueBounds.ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:142919 }
2920};
2921
[email protected]96baf3e2012-10-22 23:09:552922ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142923
[email protected]ece1d952012-10-18 21:26:072924template<class Types>
[email protected]96baf3e2012-10-22 23:09:552925class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142926protected:
[email protected]96baf3e2012-10-22 23:09:552927 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142928 void runMyTest()
2929 {
2930 WebTransformationMatrix scaleByHalf;
2931 scaleByHalf.scale(0.5);
2932
2933 // Make a surface and its replica, each 50x50, that are completely occluded by opaque layers which are above them in the z-order.
2934 // 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
2935 // appears at 50, 50 and the replica at 200, 50.
[email protected]d0f98362012-11-01 23:02:382936 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
2937 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(50, 50), gfx::Size(100, 100), false);
2938 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(300, 0), gfx::Size());
2939 typename Types::LayerType* aboveSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(50, 50), gfx::Size(50, 50), true);
2940 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:142941
2942 // Filters make the layer own a surface.
2943 WebFilterOperations filters;
2944 filters.append(WebFilterOperation::createBlurFilter(3));
2945 filteredSurface->setBackgroundFilters(filters);
2946
2947 this->calcDrawEtc(parent);
2948
[email protected]167ed9d52012-10-31 20:47:582949 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
2950 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142951
2952 this->visitLayer(aboveReplicaLayer, occlusion);
2953 this->visitLayer(aboveSurfaceLayer, occlusion);
2954
2955 // The surface has a background blur, so it blurs non-opaque pixels below it.
2956 this->visitLayer(filteredSurface, occlusion);
2957 this->visitContributingSurface(filteredSurface, occlusion);
2958
2959 // The filter is completely occluded, so it should not blur anything and reduce any occlusion.
[email protected]167ed9d52012-10-31 20:47:582960 gfx::Rect occlusionAboveSurface = gfx::Rect(50, 50, 50, 50);
2961 gfx::Rect occlusionAboveReplica = gfx::Rect(200, 50, 50, 50);
[email protected]94f206c12012-08-25 00:09:142962
[email protected]ac7c7f52012-11-08 06:26:502963 Region expectedOpaqueRegion = UnionRegions(occlusionAboveSurface, occlusionAboveReplica);
2964 EXPECT_EQ(expectedOpaqueRegion, occlusion.occlusionInScreenSpace());
2965 EXPECT_EQ(expectedOpaqueRegion, occlusion.occlusionInTargetSurface());
[email protected]94f206c12012-08-25 00:09:142966 }
2967};
2968
[email protected]96baf3e2012-10-22 23:09:552969ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:142970
[email protected]ece1d952012-10-18 21:26:072971template<class Types>
[email protected]96baf3e2012-10-22 23:09:552972class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:142973protected:
[email protected]96baf3e2012-10-22 23:09:552974 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:142975 void runMyTest()
2976 {
2977 WebTransformationMatrix scaleByHalf;
2978 scaleByHalf.scale(0.5);
2979
2980 // Make a surface and its replica, each 50x50, that are partially occluded by opaque layers which are above them in the z-order.
2981 // 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
2982 // appears at 50, 50 and the replica at 200, 50.
[email protected]d0f98362012-11-01 23:02:382983 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(300, 150));
2984 typename Types::LayerType* filteredSurface = this->createDrawingLayer(parent, scaleByHalf, gfx::PointF(50, 50), gfx::Size(100, 100), false);
2985 this->createReplicaLayer(filteredSurface, this->identityMatrix, gfx::PointF(300, 0), gfx::Size());
2986 typename Types::LayerType* aboveSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(70, 50), gfx::Size(30, 50), true);
2987 typename Types::LayerType* aboveReplicaLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(200, 50), gfx::Size(30, 50), true);
2988 typename Types::LayerType* besideSurfaceLayer = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(90, 40), gfx::Size(10, 10), true);
2989 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:142990
2991 // Filters make the layer own a surface.
2992 WebFilterOperations filters;
2993 filters.append(WebFilterOperation::createBlurFilter(3));
2994 filteredSurface->setBackgroundFilters(filters);
2995
2996 // Save the distance of influence for the blur effect.
2997 int outsetTop, outsetRight, outsetBottom, outsetLeft;
2998 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
2999
3000 this->calcDrawEtc(parent);
3001
[email protected]167ed9d52012-10-31 20:47:583002 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
3003 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143004
3005 this->visitLayer(besideReplicaLayer, occlusion);
3006 this->visitLayer(besideSurfaceLayer, occlusion);
3007 this->visitLayer(aboveReplicaLayer, occlusion);
3008 this->visitLayer(aboveSurfaceLayer, occlusion);
3009
3010 // The surface has a background blur, so it blurs non-opaque pixels below it.
3011 this->visitLayer(filteredSurface, occlusion);
3012 this->visitContributingSurface(filteredSurface, occlusion);
3013
3014 // The filter in the surface and replica are partially unoccluded. Only the unoccluded parts should reduce occlusion.
3015 // This means it will push back the occlusion that touches the unoccluded part (occlusionAbove___), but it will not
3016 // touch occlusionBeside____ since that is not beside the unoccluded part of the surface, even though it is beside
3017 // the occluded part of the surface.
[email protected]167ed9d52012-10-31 20:47:583018 gfx::Rect occlusionAboveSurface = gfx::Rect(70 + outsetRight, 50, 30 - outsetRight, 50);
3019 gfx::Rect occlusionAboveReplica = gfx::Rect(200, 50, 30 - outsetLeft, 50);
3020 gfx::Rect occlusionBesideSurface = gfx::Rect(90, 40, 10, 10);
3021 gfx::Rect occlusionBesideReplica = gfx::Rect(200, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:143022
3023 Region expectedOcclusion;
[email protected]d0f98362012-11-01 23:02:383024 expectedOcclusion.Union(occlusionAboveSurface);
3025 expectedOcclusion.Union(occlusionAboveReplica);
3026 expectedOcclusion.Union(occlusionBesideSurface);
3027 expectedOcclusion.Union(occlusionBesideReplica);
[email protected]94f206c12012-08-25 00:09:143028
[email protected]ac7c7f52012-11-08 06:26:503029 ASSERT_EQ(expectedOcclusion, occlusion.occlusionInTargetSurface());
3030 ASSERT_EQ(expectedOcclusion, occlusion.occlusionInScreenSpace());
[email protected]94f206c12012-08-25 00:09:143031
[email protected]0d8a30502012-11-03 02:59:153032 Region::Iterator expectedRects(expectedOcclusion);
3033 Region::Iterator screenSpaceRects(occlusion.occlusionInScreenSpace());
3034 Region::Iterator targetSurfaceRects(occlusion.occlusionInTargetSurface());
3035 for (; expectedRects.has_rect(); expectedRects.next(), screenSpaceRects.next(), targetSurfaceRects.next()) {
3036 ASSERT_TRUE(screenSpaceRects.has_rect());
3037 ASSERT_TRUE(targetSurfaceRects.has_rect());
3038 EXPECT_EQ(expectedRects.rect(), screenSpaceRects.rect());
3039 EXPECT_EQ(expectedRects.rect(), targetSurfaceRects.rect());
[email protected]94f206c12012-08-25 00:09:143040 }
3041 }
3042};
3043
[email protected]96baf3e2012-10-22 23:09:553044ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:143045
[email protected]ece1d952012-10-18 21:26:073046template<class Types>
[email protected]96baf3e2012-10-22 23:09:553047class OcclusionTrackerTestMinimumTrackingSize : public OcclusionTrackerTest<Types> {
[email protected]94f206c12012-08-25 00:09:143048protected:
[email protected]96baf3e2012-10-22 23:09:553049 OcclusionTrackerTestMinimumTrackingSize(bool opaqueLayers) : OcclusionTrackerTest<Types>(opaqueLayers) {}
[email protected]94f206c12012-08-25 00:09:143050 void runMyTest()
3051 {
[email protected]aad0a0072012-11-01 18:15:583052 gfx::Size trackingSize(100, 100);
3053 gfx::Size belowTrackingSize(99, 99);
[email protected]94f206c12012-08-25 00:09:143054
[email protected]d0f98362012-11-01 23:02:383055 typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, gfx::PointF(0, 0), gfx::Size(400, 400));
3056 typename Types::LayerType* large = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), trackingSize, true);
3057 typename Types::LayerType* small = this->createDrawingLayer(parent, this->identityMatrix, gfx::PointF(0, 0), belowTrackingSize, true);
[email protected]94f206c12012-08-25 00:09:143058 this->calcDrawEtc(parent);
3059
[email protected]167ed9d52012-10-31 20:47:583060 TestOcclusionTrackerWithClip<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(gfx::Rect(0, 0, 1000, 1000));
3061 occlusion.setLayerClipRect(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143062 occlusion.setMinimumTrackingSize(trackingSize);
3063
3064 // The small layer is not tracked because it is too small.
3065 this->visitLayer(small, occlusion);
3066
[email protected]ac7c7f52012-11-08 06:26:503067 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInScreenSpace().ToString());
3068 EXPECT_EQ(gfx::Rect().ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:143069
3070 // The large layer is tracked as it is large enough.
3071 this->visitLayer(large, occlusion);
3072
[email protected]ac7c7f52012-11-08 06:26:503073 EXPECT_EQ(gfx::Rect(gfx::Point(), trackingSize).ToString(), occlusion.occlusionInScreenSpace().ToString());
3074 EXPECT_EQ(gfx::Rect(gfx::Point(), trackingSize).ToString(), occlusion.occlusionInTargetSurface().ToString());
[email protected]94f206c12012-08-25 00:09:143075 }
3076};
3077
[email protected]96baf3e2012-10-22 23:09:553078ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:143079
[email protected]ba565742012-11-10 09:29:483080} // namespace
3081} // namespace cc