blob: 997d184138d96e2a94deece631988db283811cda [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]556fd292013-03-18 08:03:045#include "cc/trees/occlusion_tracker.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]95e4e1a02013-03-18 07:09:097#include "cc/animation/layer_animation_controller.h"
[email protected]681ccff2013-03-18 06:13:528#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:529#include "cc/layers/layer.h"
10#include "cc/layers/layer_impl.h"
[email protected]5b54b972013-07-26 13:25:4211#include "cc/output/copy_output_request.h"
12#include "cc/output/copy_output_result.h"
[email protected]ae6b1a72013-06-25 18:49:2913#include "cc/output/filter_operation.h"
14#include "cc/output/filter_operations.h"
[email protected]101441ce2012-10-16 01:45:0315#include "cc/test/animation_test_common.h"
[email protected]586d51ed2012-12-07 20:31:4516#include "cc/test/fake_impl_proxy.h"
[email protected]d600df7d2013-08-03 02:34:2817#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4518#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0319#include "cc/test/geometry_test_utils.h"
[email protected]34ba1ffb2014-03-05 06:55:0320#include "cc/test/test_occlusion_tracker.h"
[email protected]556fd292013-03-18 08:03:0421#include "cc/trees/layer_tree_host_common.h"
22#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1823#include "testing/gmock/include/gmock/gmock.h"
24#include "testing/gtest/include/gtest/gtest.h"
[email protected]c8686a02012-11-27 08:29:0025#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1426
[email protected]ba565742012-11-10 09:29:4827namespace cc {
[email protected]94f206c12012-08-25 00:09:1428namespace {
29
[email protected]96baf3e2012-10-22 23:09:5530class TestContentLayer : public Layer {
[email protected]a27cbde2013-03-23 22:01:4931 public:
[email protected]afc4f262013-10-05 01:14:1032 TestContentLayer() : Layer(), override_opaque_contents_rect_(false) {
33 SetIsDrawable(true);
34 }
[email protected]94f206c12012-08-25 00:09:1435
[email protected]d5467eb72014-08-22 01:16:4336 virtual SimpleEnclosedRegion VisibleContentOpaqueRegion() const OVERRIDE {
37 if (override_opaque_contents_rect_) {
38 return SimpleEnclosedRegion(
39 gfx::IntersectRects(opaque_contents_rect_, visible_content_rect()));
40 }
[email protected]a27cbde2013-03-23 22:01:4941 return Layer::VisibleContentOpaqueRegion();
42 }
[email protected]0023fc72014-01-10 20:05:0643 void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) {
[email protected]a27cbde2013-03-23 22:01:4944 override_opaque_contents_rect_ = true;
45 opaque_contents_rect_ = opaque_contents_rect;
46 }
[email protected]94f206c12012-08-25 00:09:1447
[email protected]a27cbde2013-03-23 22:01:4948 private:
49 virtual ~TestContentLayer() {}
[email protected]d58499a2012-10-09 22:27:4750
[email protected]a27cbde2013-03-23 22:01:4951 bool override_opaque_contents_rect_;
52 gfx::Rect opaque_contents_rect_;
[email protected]94f206c12012-08-25 00:09:1453};
54
[email protected]96baf3e2012-10-22 23:09:5555class TestContentLayerImpl : public LayerImpl {
[email protected]a27cbde2013-03-23 22:01:4956 public:
57 TestContentLayerImpl(LayerTreeImpl* tree_impl, int id)
58 : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) {
59 SetDrawsContent(true);
60 }
[email protected]94f206c12012-08-25 00:09:1461
[email protected]d5467eb72014-08-22 01:16:4362 virtual SimpleEnclosedRegion VisibleContentOpaqueRegion() const OVERRIDE {
63 if (override_opaque_contents_rect_) {
64 return SimpleEnclosedRegion(
65 gfx::IntersectRects(opaque_contents_rect_, visible_content_rect()));
66 }
[email protected]a27cbde2013-03-23 22:01:4967 return LayerImpl::VisibleContentOpaqueRegion();
68 }
[email protected]0023fc72014-01-10 20:05:0669 void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) {
[email protected]a27cbde2013-03-23 22:01:4970 override_opaque_contents_rect_ = true;
71 opaque_contents_rect_ = opaque_contents_rect;
72 }
[email protected]94f206c12012-08-25 00:09:1473
[email protected]a27cbde2013-03-23 22:01:4974 private:
75 bool override_opaque_contents_rect_;
76 gfx::Rect opaque_contents_rect_;
[email protected]94f206c12012-08-25 00:09:1477};
78
[email protected]34ba1ffb2014-03-05 06:55:0379template <typename LayerType>
80class TestOcclusionTrackerWithClip : public TestOcclusionTracker<LayerType> {
[email protected]a27cbde2013-03-23 22:01:4981 public:
[email protected]0023fc72014-01-10 20:05:0682 explicit TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect)
[email protected]97c6a7342014-03-12 20:36:4383 : TestOcclusionTracker<LayerType>(viewport_rect) {}
[email protected]94f206c12012-08-25 00:09:1484
[email protected]a27cbde2013-03-23 22:01:4985 bool OccludedLayer(const LayerType* layer,
[email protected]0023fc72014-01-10 20:05:0686 const gfx::Rect& content_rect) const {
[email protected]cfc2d2d2013-10-04 23:26:4587 DCHECK(layer->visible_content_rect().Contains(content_rect));
[email protected]7d6d6c92014-03-06 01:18:5088 return this->Occluded(
89 layer->render_target(), content_rect, layer->draw_transform());
[email protected]a27cbde2013-03-23 22:01:4990 }
[email protected]fbc293322013-10-01 05:07:1591
[email protected]a27cbde2013-03-23 22:01:4992 // Gives an unoccluded sub-rect of |content_rect| in the content space of the
[email protected]ed511b8d2013-03-25 03:29:2993 // layer. Simple wrapper around UnoccludedContentRect.
[email protected]a27cbde2013-03-23 22:01:4994 gfx::Rect UnoccludedLayerContentRect(const LayerType* layer,
[email protected]0023fc72014-01-10 20:05:0695 const gfx::Rect& content_rect) const {
[email protected]cfc2d2d2013-10-04 23:26:4596 DCHECK(layer->visible_content_rect().Contains(content_rect));
[email protected]ce4738e2014-06-13 14:54:0297 return this->UnoccludedContentRect(content_rect, layer->draw_transform());
[email protected]a27cbde2013-03-23 22:01:4998 }
[email protected]e312aca2014-03-20 22:11:5599
100 gfx::Rect UnoccludedSurfaceContentRect(const LayerType* layer,
101 bool for_replica,
102 const gfx::Rect& content_rect) const {
103 typename LayerType::RenderSurfaceType* surface = layer->render_surface();
104 gfx::Transform draw_transform = for_replica
105 ? surface->replica_draw_transform()
106 : surface->draw_transform();
[email protected]ce4738e2014-06-13 14:54:02107 return this->UnoccludedContributingSurfaceContentRect(content_rect,
108 draw_transform);
[email protected]e312aca2014-03-20 22:11:55109 }
[email protected]94f206c12012-08-25 00:09:14110};
111
[email protected]96baf3e2012-10-22 23:09:55112struct OcclusionTrackerTestMainThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49113 typedef Layer LayerType;
[email protected]d600df7d2013-08-03 02:34:28114 typedef FakeLayerTreeHost HostType;
[email protected]a27cbde2013-03-23 22:01:49115 typedef RenderSurface RenderSurfaceType;
116 typedef TestContentLayer ContentLayerType;
117 typedef scoped_refptr<Layer> LayerPtrType;
118 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
[email protected]ba1b33e2014-02-28 16:44:51119 typedef LayerIterator<Layer> TestLayerIterator;
[email protected]34ba1ffb2014-03-05 06:55:03120 typedef OcclusionTracker<Layer> OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14121
[email protected]a27cbde2013-03-23 22:01:49122 static LayerPtrType CreateLayer(HostType* host) { return Layer::Create(); }
123 static ContentLayerPtrType CreateContentLayer(HostType* host) {
124 return make_scoped_refptr(new ContentLayerType());
125 }
[email protected]e0bd43a2012-10-12 16:54:21126
[email protected]a27cbde2013-03-23 22:01:49127 static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) {
128 LayerPtrType ref(*layer);
129 *layer = NULL;
130 return ref;
131 }
[email protected]e0bd43a2012-10-12 16:54:21132
[email protected]a27cbde2013-03-23 22:01:49133 static LayerPtrType PassLayerPtr(LayerPtrType* layer) {
134 LayerPtrType ref(*layer);
135 *layer = NULL;
136 return ref;
137 }
[email protected]d58499a2012-10-09 22:27:47138
[email protected]a27cbde2013-03-23 22:01:49139 static void DestroyLayer(LayerPtrType* layer) { *layer = NULL; }
[email protected]ad63b2f2014-08-11 17:39:54140
141 static void RecursiveUpdateNumChildren(LayerType* layerType) {}
[email protected]94f206c12012-08-25 00:09:14142};
143
[email protected]96baf3e2012-10-22 23:09:55144struct OcclusionTrackerTestImplThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49145 typedef LayerImpl LayerType;
146 typedef LayerTreeImpl HostType;
147 typedef RenderSurfaceImpl RenderSurfaceType;
148 typedef TestContentLayerImpl ContentLayerType;
149 typedef scoped_ptr<LayerImpl> LayerPtrType;
150 typedef scoped_ptr<ContentLayerType> ContentLayerPtrType;
[email protected]ba1b33e2014-02-28 16:44:51151 typedef LayerIterator<LayerImpl> TestLayerIterator;
[email protected]34ba1ffb2014-03-05 06:55:03152 typedef OcclusionTracker<LayerImpl> OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14153
[email protected]a27cbde2013-03-23 22:01:49154 static LayerPtrType CreateLayer(HostType* host) {
155 return LayerImpl::Create(host, next_layer_impl_id++);
156 }
157 static ContentLayerPtrType CreateContentLayer(HostType* host) {
158 return make_scoped_ptr(new ContentLayerType(host, next_layer_impl_id++));
159 }
160 static int next_layer_impl_id;
[email protected]d58499a2012-10-09 22:27:47161
[email protected]a27cbde2013-03-23 22:01:49162 static LayerPtrType PassLayerPtr(LayerPtrType* layer) {
163 return layer->Pass();
164 }
[email protected]e0bd43a2012-10-12 16:54:21165
[email protected]a27cbde2013-03-23 22:01:49166 static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) {
167 return layer->PassAs<LayerType>();
168 }
[email protected]e0bd43a2012-10-12 16:54:21169
[email protected]a27cbde2013-03-23 22:01:49170 static void DestroyLayer(LayerPtrType* layer) { layer->reset(); }
[email protected]ad63b2f2014-08-11 17:39:54171
172 static void RecursiveUpdateNumChildren(LayerType* layer) {
173 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(layer);
174 }
[email protected]94f206c12012-08-25 00:09:14175};
176
[email protected]a27cbde2013-03-23 22:01:49177int OcclusionTrackerTestImplThreadTypes::next_layer_impl_id = 1;
[email protected]94f206c12012-08-25 00:09:14178
[email protected]a27cbde2013-03-23 22:01:49179template <typename Types> class OcclusionTrackerTest : public testing::Test {
180 protected:
[email protected]ca2902e92013-03-28 01:45:35181 explicit OcclusionTrackerTest(bool opaque_layers)
[email protected]d600df7d2013-08-03 02:34:28182 : opaque_layers_(opaque_layers), host_(FakeLayerTreeHost::Create()) {}
[email protected]a27cbde2013-03-23 22:01:49183
184 virtual void RunMyTest() = 0;
185
[email protected]d5467eb72014-08-22 01:16:43186 virtual void TearDown() { DestroyLayers(); }
[email protected]a27cbde2013-03-23 22:01:49187
188 typename Types::HostType* GetHost();
189
190 typename Types::ContentLayerType* CreateRoot(const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47191 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26192 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49193 typename Types::ContentLayerPtrType layer(
194 Types::CreateContentLayer(GetHost()));
195 typename Types::ContentLayerType* layer_ptr = layer.get();
196 SetProperties(layer_ptr, transform, position, bounds);
197
[email protected]22898ed2013-06-01 04:52:30198 DCHECK(!root_.get());
[email protected]a27cbde2013-03-23 22:01:49199 root_ = Types::PassLayerPtr(&layer);
[email protected]d600df7d2013-08-03 02:34:28200
201 SetRootLayerOnMainThread(layer_ptr);
202
[email protected]a27cbde2013-03-23 22:01:49203 return layer_ptr;
204 }
205
206 typename Types::LayerType* CreateLayer(typename Types::LayerType* parent,
207 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47208 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26209 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49210 typename Types::LayerPtrType layer(Types::CreateLayer(GetHost()));
211 typename Types::LayerType* layer_ptr = layer.get();
212 SetProperties(layer_ptr, transform, position, bounds);
213 parent->AddChild(Types::PassLayerPtr(&layer));
214 return layer_ptr;
215 }
216
217 typename Types::LayerType* CreateSurface(typename Types::LayerType* parent,
218 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47219 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26220 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49221 typename Types::LayerType* layer =
222 CreateLayer(parent, transform, position, bounds);
223 layer->SetForceRenderSurface(true);
224 return layer;
225 }
226
227 typename Types::ContentLayerType* CreateDrawingLayer(
228 typename Types::LayerType* parent,
229 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47230 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26231 const gfx::Size& bounds,
[email protected]a27cbde2013-03-23 22:01:49232 bool opaque) {
233 typename Types::ContentLayerPtrType layer(
234 Types::CreateContentLayer(GetHost()));
235 typename Types::ContentLayerType* layer_ptr = layer.get();
236 SetProperties(layer_ptr, transform, position, bounds);
237
238 if (opaque_layers_) {
239 layer_ptr->SetContentsOpaque(opaque);
240 } else {
241 layer_ptr->SetContentsOpaque(false);
242 if (opaque)
[email protected]2c7c6702013-03-26 03:14:05243 layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds));
[email protected]a27cbde2013-03-23 22:01:49244 else
245 layer_ptr->SetOpaqueContentsRect(gfx::Rect());
[email protected]586d51ed2012-12-07 20:31:45246 }
[email protected]94f206c12012-08-25 00:09:14247
[email protected]a27cbde2013-03-23 22:01:49248 parent->AddChild(Types::PassLayerPtr(&layer));
249 return layer_ptr;
250 }
[email protected]94f206c12012-08-25 00:09:14251
[email protected]a27cbde2013-03-23 22:01:49252 typename Types::LayerType* CreateReplicaLayer(
253 typename Types::LayerType* owning_layer,
254 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47255 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26256 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49257 typename Types::ContentLayerPtrType layer(
258 Types::CreateContentLayer(GetHost()));
259 typename Types::ContentLayerType* layer_ptr = layer.get();
260 SetProperties(layer_ptr, transform, position, bounds);
261 SetReplica(owning_layer, Types::PassLayerPtr(&layer));
262 return layer_ptr;
263 }
[email protected]94f206c12012-08-25 00:09:14264
[email protected]a27cbde2013-03-23 22:01:49265 typename Types::LayerType* CreateMaskLayer(
266 typename Types::LayerType* owning_layer,
[email protected]64348ea2014-01-29 22:58:26267 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49268 typename Types::ContentLayerPtrType layer(
269 Types::CreateContentLayer(GetHost()));
270 typename Types::ContentLayerType* layer_ptr = layer.get();
271 SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds);
272 SetMask(owning_layer, Types::PassLayerPtr(&layer));
273 return layer_ptr;
274 }
[email protected]586d51ed2012-12-07 20:31:45275
[email protected]a27cbde2013-03-23 22:01:49276 typename Types::ContentLayerType* CreateDrawingSurface(
277 typename Types::LayerType* parent,
278 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47279 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26280 const gfx::Size& bounds,
[email protected]a27cbde2013-03-23 22:01:49281 bool opaque) {
282 typename Types::ContentLayerType* layer =
283 CreateDrawingLayer(parent, transform, position, bounds, opaque);
284 layer->SetForceRenderSurface(true);
285 return layer;
286 }
[email protected]94f206c12012-08-25 00:09:14287
[email protected]d5467eb72014-08-22 01:16:43288 void DestroyLayers() {
289 Types::DestroyLayer(&root_);
290 render_surface_layer_list_.reset();
291 render_surface_layer_list_impl_.clear();
292 replica_layers_.clear();
293 mask_layers_.clear();
294 ResetLayerIterator();
295 }
[email protected]5b54b972013-07-26 13:25:42296
297 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
298
299 void AddCopyRequest(Layer* layer) {
300 layer->RequestCopyOfOutput(
301 CopyOutputRequest::CreateBitmapRequest(base::Bind(
302 &OcclusionTrackerTest<Types>::CopyOutputCallback,
303 base::Unretained(this))));
304 }
305
306 void AddCopyRequest(LayerImpl* layer) {
307 ScopedPtrVector<CopyOutputRequest> requests;
308 requests.push_back(
309 CopyOutputRequest::CreateBitmapRequest(base::Bind(
310 &OcclusionTrackerTest<Types>::CopyOutputCallback,
311 base::Unretained(this))));
312 layer->PassCopyRequests(&requests);
313 }
314
[email protected]a27cbde2013-03-23 22:01:49315 void CalcDrawEtc(TestContentLayerImpl* root) {
316 DCHECK(root == root_.get());
[email protected]a27cbde2013-03-23 22:01:49317 DCHECK(!root->render_surface());
[email protected]94f206c12012-08-25 00:09:14318
[email protected]ad63b2f2014-08-11 17:39:54319 Types::RecursiveUpdateNumChildren(root);
[email protected]7aad55f2013-07-26 11:25:53320 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
321 root, root->bounds(), &render_surface_layer_list_impl_);
322 inputs.can_adjust_raster_scales = true;
323 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14324
[email protected]a27cbde2013-03-23 22:01:49325 layer_iterator_ = layer_iterator_begin_ =
326 Types::TestLayerIterator::Begin(&render_surface_layer_list_impl_);
327 }
[email protected]94f206c12012-08-25 00:09:14328
[email protected]a27cbde2013-03-23 22:01:49329 void CalcDrawEtc(TestContentLayer* root) {
330 DCHECK(root == root_.get());
[email protected]a27cbde2013-03-23 22:01:49331 DCHECK(!root->render_surface());
[email protected]94f206c12012-08-25 00:09:14332
[email protected]989386c2013-07-18 21:37:23333 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
[email protected]7aad55f2013-07-26 11:25:53334 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
335 root, root->bounds(), render_surface_layer_list_.get());
336 inputs.can_adjust_raster_scales = true;
337 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14338
[email protected]a27cbde2013-03-23 22:01:49339 layer_iterator_ = layer_iterator_begin_ =
[email protected]989386c2013-07-18 21:37:23340 Types::TestLayerIterator::Begin(render_surface_layer_list_.get());
[email protected]a27cbde2013-03-23 22:01:49341 }
[email protected]94f206c12012-08-25 00:09:14342
[email protected]a27cbde2013-03-23 22:01:49343 void EnterLayer(typename Types::LayerType* layer,
[email protected]e47b0a0a2013-11-18 23:26:22344 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43345 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49346 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]e47b0a0a2013-11-18 23:26:22347 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49348 }
[email protected]94f206c12012-08-25 00:09:14349
[email protected]a27cbde2013-03-23 22:01:49350 void LeaveLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40351 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43352 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49353 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]d002dd02013-03-27 07:40:40354 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49355 ++layer_iterator_;
356 }
[email protected]94f206c12012-08-25 00:09:14357
[email protected]a27cbde2013-03-23 22:01:49358 void VisitLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40359 typename Types::OcclusionTrackerType* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22360 EnterLayer(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49361 LeaveLayer(layer, occlusion);
362 }
[email protected]94f206c12012-08-25 00:09:14363
[email protected]a27cbde2013-03-23 22:01:49364 void EnterContributingSurface(
365 typename Types::LayerType* layer,
[email protected]e47b0a0a2013-11-18 23:26:22366 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43367 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49368 ASSERT_TRUE(layer_iterator_.represents_target_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22369 occlusion->EnterLayer(layer_iterator_);
[email protected]d002dd02013-03-27 07:40:40370 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49371 ++layer_iterator_;
372 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22373 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49374 }
[email protected]94f206c12012-08-25 00:09:14375
[email protected]a27cbde2013-03-23 22:01:49376 void LeaveContributingSurface(
377 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40378 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43379 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49380 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]d002dd02013-03-27 07:40:40381 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49382 ++layer_iterator_;
383 }
[email protected]94f206c12012-08-25 00:09:14384
[email protected]a27cbde2013-03-23 22:01:49385 void VisitContributingSurface(
386 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40387 typename Types::OcclusionTrackerType* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22388 EnterContributingSurface(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49389 LeaveContributingSurface(layer, occlusion);
390 }
[email protected]94f206c12012-08-25 00:09:14391
[email protected]a27cbde2013-03-23 22:01:49392 void ResetLayerIterator() { layer_iterator_ = layer_iterator_begin_; }
[email protected]94f206c12012-08-25 00:09:14393
[email protected]a27cbde2013-03-23 22:01:49394 const gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:14395
[email protected]a27cbde2013-03-23 22:01:49396 private:
[email protected]d600df7d2013-08-03 02:34:28397 void SetRootLayerOnMainThread(Layer* root) {
398 host_->SetRootLayer(scoped_refptr<Layer>(root));
399 }
400
401 void SetRootLayerOnMainThread(LayerImpl* root) {}
402
[email protected]a27cbde2013-03-23 22:01:49403 void SetBaseProperties(typename Types::LayerType* layer,
404 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47405 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26406 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49407 layer->SetTransform(transform);
[email protected]a27cbde2013-03-23 22:01:49408 layer->SetPosition(position);
409 layer->SetBounds(bounds);
410 }
[email protected]94f206c12012-08-25 00:09:14411
[email protected]a27cbde2013-03-23 22:01:49412 void SetProperties(Layer* layer,
413 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47414 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26415 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49416 SetBaseProperties(layer, transform, position, bounds);
417 }
[email protected]94f206c12012-08-25 00:09:14418
[email protected]a27cbde2013-03-23 22:01:49419 void SetProperties(LayerImpl* layer,
420 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47421 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26422 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49423 SetBaseProperties(layer, transform, position, bounds);
[email protected]94f206c12012-08-25 00:09:14424
[email protected]a27cbde2013-03-23 22:01:49425 layer->SetContentBounds(layer->bounds());
426 }
[email protected]94f206c12012-08-25 00:09:14427
[email protected]a27cbde2013-03-23 22:01:49428 void SetReplica(Layer* owning_layer, scoped_refptr<Layer> layer) {
429 owning_layer->SetReplicaLayer(layer.get());
430 replica_layers_.push_back(layer);
431 }
[email protected]94f206c12012-08-25 00:09:14432
[email protected]a27cbde2013-03-23 22:01:49433 void SetReplica(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
434 owning_layer->SetReplicaLayer(layer.Pass());
435 }
[email protected]94f206c12012-08-25 00:09:14436
[email protected]a27cbde2013-03-23 22:01:49437 void SetMask(Layer* owning_layer, scoped_refptr<Layer> layer) {
438 owning_layer->SetMaskLayer(layer.get());
439 mask_layers_.push_back(layer);
440 }
[email protected]94f206c12012-08-25 00:09:14441
[email protected]a27cbde2013-03-23 22:01:49442 void SetMask(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
443 owning_layer->SetMaskLayer(layer.Pass());
444 }
[email protected]94f206c12012-08-25 00:09:14445
[email protected]a27cbde2013-03-23 22:01:49446 bool opaque_layers_;
[email protected]d600df7d2013-08-03 02:34:28447 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]a27cbde2013-03-23 22:01:49448 // These hold ownership of the layers for the duration of the test.
449 typename Types::LayerPtrType root_;
[email protected]989386c2013-07-18 21:37:23450 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
[email protected]50761e92013-03-29 20:51:28451 LayerImplList render_surface_layer_list_impl_;
[email protected]a27cbde2013-03-23 22:01:49452 typename Types::TestLayerIterator layer_iterator_begin_;
453 typename Types::TestLayerIterator layer_iterator_;
454 typename Types::LayerType* last_layer_visited_;
[email protected]50761e92013-03-29 20:51:28455 LayerList replica_layers_;
456 LayerList mask_layers_;
[email protected]94f206c12012-08-25 00:09:14457};
458
[email protected]a27cbde2013-03-23 22:01:49459template <>
[email protected]d600df7d2013-08-03 02:34:28460FakeLayerTreeHost*
[email protected]a27cbde2013-03-23 22:01:49461OcclusionTrackerTest<OcclusionTrackerTestMainThreadTypes>::GetHost() {
[email protected]d600df7d2013-08-03 02:34:28462 return host_.get();
[email protected]586d51ed2012-12-07 20:31:45463}
464
[email protected]a27cbde2013-03-23 22:01:49465template <>
466LayerTreeImpl*
467OcclusionTrackerTest<OcclusionTrackerTestImplThreadTypes>::GetHost() {
[email protected]d600df7d2013-08-03 02:34:28468 return host_->host_impl()->active_tree();
[email protected]586d51ed2012-12-07 20:31:45469}
470
[email protected]a27cbde2013-03-23 22:01:49471#define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35472 class ClassName##MainThreadOpaqueLayers \
473 : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
474 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49475 ClassName##MainThreadOpaqueLayers() \
476 : ClassName<OcclusionTrackerTestMainThreadTypes>(true) {} \
477 }; \
478 TEST_F(ClassName##MainThreadOpaqueLayers, RunTest) { RunMyTest(); }
479#define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35480 class ClassName##MainThreadOpaquePaints \
481 : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
482 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49483 ClassName##MainThreadOpaquePaints() \
484 : ClassName<OcclusionTrackerTestMainThreadTypes>(false) {} \
485 }; \
486 TEST_F(ClassName##MainThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14487
[email protected]a27cbde2013-03-23 22:01:49488#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35489 class ClassName##ImplThreadOpaqueLayers \
490 : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
491 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49492 ClassName##ImplThreadOpaqueLayers() \
493 : ClassName<OcclusionTrackerTestImplThreadTypes>(true) {} \
494 }; \
495 TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); }
496#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35497 class ClassName##ImplThreadOpaquePaints \
498 : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
499 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49500 ClassName##ImplThreadOpaquePaints() \
501 : ClassName<OcclusionTrackerTestImplThreadTypes>(false) {} \
502 }; \
503 TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14504
[email protected]a27cbde2013-03-23 22:01:49505#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
506 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
507 RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
508 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
509 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
[email protected]94f206c12012-08-25 00:09:14510
[email protected]a27cbde2013-03-23 22:01:49511#define MAIN_THREAD_TEST(ClassName) \
512 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14513
[email protected]a27cbde2013-03-23 22:01:49514#define IMPL_THREAD_TEST(ClassName) \
515 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14516
[email protected]a27cbde2013-03-23 22:01:49517#define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
518 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
519 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14520
[email protected]a27cbde2013-03-23 22:01:49521template <class Types>
[email protected]ca2902e92013-03-28 01:45:35522class OcclusionTrackerTestIdentityTransforms
523 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49524 protected:
[email protected]ca2902e92013-03-28 01:45:35525 explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49526 : OcclusionTrackerTest<Types>(opaque_layers) {}
[email protected]ece1d952012-10-18 21:26:07527
[email protected]a27cbde2013-03-23 22:01:49528 void RunMyTest() {
529 typename Types::ContentLayerType* root = this->CreateRoot(
530 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
531 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
532 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
533 typename Types::ContentLayerType* layer =
534 this->CreateDrawingLayer(parent,
535 this->identity_matrix,
536 gfx::PointF(30.f, 30.f),
537 gfx::Size(500, 500),
538 true);
539 parent->SetMasksToBounds(true);
540 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14541
[email protected]34ba1ffb2014-03-05 06:55:03542 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]97c6a7342014-03-12 20:36:43543 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14544
[email protected]d002dd02013-03-27 07:40:40545 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22546 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14547
[email protected]a27cbde2013-03-23 22:01:49548 EXPECT_EQ(gfx::Rect().ToString(),
549 occlusion.occlusion_from_outside_target().ToString());
550 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
551 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14552
[email protected]a27cbde2013-03-23 22:01:49553 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
554 parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
[email protected]d5467eb72014-08-22 01:16:43555 EXPECT_EQ(gfx::Rect(29, 30, 1, 70),
556 occlusion.UnoccludedLayerContentRect(parent,
557 gfx::Rect(29, 30, 70, 70)));
558 EXPECT_EQ(gfx::Rect(29, 29, 70, 70),
559 occlusion.UnoccludedLayerContentRect(parent,
560 gfx::Rect(29, 29, 70, 70)));
561 EXPECT_EQ(gfx::Rect(30, 29, 70, 1),
562 occlusion.UnoccludedLayerContentRect(parent,
563 gfx::Rect(30, 29, 70, 70)));
564 EXPECT_EQ(gfx::Rect(31, 29, 69, 1),
565 occlusion.UnoccludedLayerContentRect(parent,
566 gfx::Rect(31, 29, 69, 70)));
567 EXPECT_EQ(gfx::Rect(),
568 occlusion.UnoccludedLayerContentRect(parent,
569 gfx::Rect(31, 30, 69, 70)));
570 EXPECT_EQ(gfx::Rect(),
571 occlusion.UnoccludedLayerContentRect(parent,
572 gfx::Rect(31, 31, 69, 69)));
573 EXPECT_EQ(gfx::Rect(),
574 occlusion.UnoccludedLayerContentRect(parent,
575 gfx::Rect(30, 31, 70, 69)));
576 EXPECT_EQ(gfx::Rect(29, 31, 1, 69),
577 occlusion.UnoccludedLayerContentRect(parent,
578 gfx::Rect(29, 31, 70, 69)));
[email protected]a27cbde2013-03-23 22:01:49579 }
[email protected]94f206c12012-08-25 00:09:14580};
581
[email protected]96baf3e2012-10-22 23:09:55582ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14583
[email protected]a27cbde2013-03-23 22:01:49584template <class Types>
[email protected]ca2902e92013-03-28 01:45:35585class OcclusionTrackerTestQuadsMismatchLayer
586 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49587 protected:
[email protected]ca2902e92013-03-28 01:45:35588 explicit OcclusionTrackerTestQuadsMismatchLayer(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49589 : OcclusionTrackerTest<Types>(opaque_layers) {}
590 void RunMyTest() {
591 gfx::Transform layer_transform;
592 layer_transform.Translate(10.0, 10.0);
[email protected]710ffc02012-10-30 21:42:02593
[email protected]a27cbde2013-03-23 22:01:49594 typename Types::ContentLayerType* parent = this->CreateRoot(
595 this->identity_matrix, gfx::Point(0, 0), gfx::Size(100, 100));
596 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
597 parent, layer_transform, gfx::PointF(), gfx::Size(90, 90), true);
598 typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
599 layer1, layer_transform, gfx::PointF(), gfx::Size(50, 50), true);
600 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02601
[email protected]34ba1ffb2014-03-05 06:55:03602 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49603 gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02604
[email protected]d002dd02013-03-27 07:40:40605 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22606 this->EnterLayer(layer1, &occlusion);
[email protected]710ffc02012-10-30 21:42:02607
[email protected]a27cbde2013-03-23 22:01:49608 EXPECT_EQ(gfx::Rect().ToString(),
609 occlusion.occlusion_from_outside_target().ToString());
610 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
611 occlusion.occlusion_from_inside_target().ToString());
[email protected]710ffc02012-10-30 21:42:02612
[email protected]a27cbde2013-03-23 22:01:49613 // This checks cases where the quads don't match their "containing"
614 // layers, e.g. in terms of transforms or clip rect. This is typical for
615 // DelegatedRendererLayer.
[email protected]710ffc02012-10-30 21:42:02616
[email protected]a27cbde2013-03-23 22:01:49617 gfx::Transform quad_transform;
618 quad_transform.Translate(30.0, 30.0);
[email protected]710ffc02012-10-30 21:42:02619
[email protected]ce4738e2014-06-13 14:54:02620 EXPECT_TRUE(occlusion.UnoccludedContentRect(gfx::Rect(0, 0, 10, 10),
[email protected]7d6d6c92014-03-06 01:18:50621 quad_transform).IsEmpty());
[email protected]d5467eb72014-08-22 01:16:43622 EXPECT_EQ(gfx::Rect(40, 40, 10, 10),
623 occlusion.UnoccludedContentRect(gfx::Rect(40, 40, 10, 10),
624 quad_transform));
625 EXPECT_EQ(gfx::Rect(40, 30, 5, 10),
626 occlusion.UnoccludedContentRect(gfx::Rect(35, 30, 10, 10),
627 quad_transform));
[email protected]a27cbde2013-03-23 22:01:49628 }
[email protected]710ffc02012-10-30 21:42:02629};
630
631ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestQuadsMismatchLayer);
632
[email protected]a27cbde2013-03-23 22:01:49633template <class Types>
[email protected]96baf3e2012-10-22 23:09:55634class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49635 protected:
[email protected]ca2902e92013-03-28 01:45:35636 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49637 : OcclusionTrackerTest<Types>(opaque_layers) {}
638 void RunMyTest() {
639 gfx::Transform layer_transform;
640 layer_transform.Translate(250.0, 250.0);
641 layer_transform.Rotate(90.0);
642 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14643
[email protected]a27cbde2013-03-23 22:01:49644 typename Types::ContentLayerType* root = this->CreateRoot(
645 this->identity_matrix, gfx::Point(0, 0), gfx::Size(200, 200));
646 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
647 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
648 typename Types::ContentLayerType* layer =
649 this->CreateDrawingLayer(parent,
650 layer_transform,
651 gfx::PointF(30.f, 30.f),
652 gfx::Size(500, 500),
653 true);
654 parent->SetMasksToBounds(true);
655 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14656
[email protected]34ba1ffb2014-03-05 06:55:03657 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49658 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14659
[email protected]d002dd02013-03-27 07:40:40660 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22661 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14662
[email protected]a27cbde2013-03-23 22:01:49663 EXPECT_EQ(gfx::Rect().ToString(),
664 occlusion.occlusion_from_outside_target().ToString());
665 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
666 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14667
[email protected]a27cbde2013-03-23 22:01:49668 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
669 parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
[email protected]d5467eb72014-08-22 01:16:43670 EXPECT_EQ(gfx::Rect(29, 30, 1, 70),
671 occlusion.UnoccludedLayerContentRect(parent,
672 gfx::Rect(29, 30, 69, 70)));
673 EXPECT_EQ(gfx::Rect(29, 29, 70, 70),
674 occlusion.UnoccludedLayerContentRect(parent,
675 gfx::Rect(29, 29, 70, 70)));
676 EXPECT_EQ(gfx::Rect(30, 29, 70, 1),
677 occlusion.UnoccludedLayerContentRect(parent,
678 gfx::Rect(30, 29, 70, 70)));
679 EXPECT_EQ(gfx::Rect(31, 29, 69, 1),
680 occlusion.UnoccludedLayerContentRect(parent,
681 gfx::Rect(31, 29, 69, 70)));
682 EXPECT_EQ(gfx::Rect(),
683 occlusion.UnoccludedLayerContentRect(parent,
684 gfx::Rect(31, 30, 69, 70)));
685 EXPECT_EQ(gfx::Rect(),
686 occlusion.UnoccludedLayerContentRect(parent,
687 gfx::Rect(31, 31, 69, 69)));
688 EXPECT_EQ(gfx::Rect(),
689 occlusion.UnoccludedLayerContentRect(parent,
690 gfx::Rect(30, 31, 70, 69)));
691 EXPECT_EQ(gfx::Rect(29, 31, 1, 69),
692 occlusion.UnoccludedLayerContentRect(parent,
693 gfx::Rect(29, 31, 70, 69)));
[email protected]a27cbde2013-03-23 22:01:49694 }
[email protected]94f206c12012-08-25 00:09:14695};
696
[email protected]96baf3e2012-10-22 23:09:55697ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14698
[email protected]a27cbde2013-03-23 22:01:49699template <class Types>
[email protected]96baf3e2012-10-22 23:09:55700class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49701 protected:
[email protected]ca2902e92013-03-28 01:45:35702 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49703 : OcclusionTrackerTest<Types>(opaque_layers) {}
704 void RunMyTest() {
705 gfx::Transform layer_transform;
706 layer_transform.Translate(20.0, 20.0);
[email protected]94f206c12012-08-25 00:09:14707
[email protected]a27cbde2013-03-23 22:01:49708 typename Types::ContentLayerType* root = this->CreateRoot(
709 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
710 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
711 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
712 typename Types::ContentLayerType* layer =
713 this->CreateDrawingLayer(parent,
714 layer_transform,
715 gfx::PointF(30.f, 30.f),
716 gfx::Size(500, 500),
717 true);
718 parent->SetMasksToBounds(true);
719 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14720
[email protected]34ba1ffb2014-03-05 06:55:03721 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49722 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14723
[email protected]d002dd02013-03-27 07:40:40724 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22725 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14726
[email protected]a27cbde2013-03-23 22:01:49727 EXPECT_EQ(gfx::Rect().ToString(),
728 occlusion.occlusion_from_outside_target().ToString());
729 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
730 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14731
[email protected]a27cbde2013-03-23 22:01:49732 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
733 parent, gfx::Rect(50, 50, 50, 50)).IsEmpty());
[email protected]d5467eb72014-08-22 01:16:43734 EXPECT_EQ(gfx::Rect(49, 50, 1, 50),
735 occlusion.UnoccludedLayerContentRect(parent,
736 gfx::Rect(49, 50, 50, 50)));
737 EXPECT_EQ(gfx::Rect(49, 49, 50, 50),
738 occlusion.UnoccludedLayerContentRect(parent,
739 gfx::Rect(49, 49, 50, 50)));
740 EXPECT_EQ(gfx::Rect(50, 49, 50, 1),
741 occlusion.UnoccludedLayerContentRect(parent,
742 gfx::Rect(50, 49, 50, 50)));
743 EXPECT_EQ(gfx::Rect(51, 49, 49, 1),
744 occlusion.UnoccludedLayerContentRect(parent,
745 gfx::Rect(51, 49, 49, 50)));
[email protected]a27cbde2013-03-23 22:01:49746 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45747 parent, gfx::Rect(51, 50, 49, 50)).IsEmpty());
[email protected]a27cbde2013-03-23 22:01:49748 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45749 parent, gfx::Rect(51, 51, 49, 49)).IsEmpty());
[email protected]a27cbde2013-03-23 22:01:49750 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45751 parent, gfx::Rect(50, 51, 50, 49)).IsEmpty());
[email protected]d5467eb72014-08-22 01:16:43752 EXPECT_EQ(gfx::Rect(49, 51, 1, 49),
753 occlusion.UnoccludedLayerContentRect(parent,
754 gfx::Rect(49, 51, 50, 49)));
[email protected]a27cbde2013-03-23 22:01:49755 }
[email protected]94f206c12012-08-25 00:09:14756};
757
[email protected]96baf3e2012-10-22 23:09:55758ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14759
[email protected]a27cbde2013-03-23 22:01:49760template <class Types>
[email protected]ca2902e92013-03-28 01:45:35761class OcclusionTrackerTestChildInRotatedChild
762 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49763 protected:
[email protected]ca2902e92013-03-28 01:45:35764 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49765 : OcclusionTrackerTest<Types>(opaque_layers) {}
766 void RunMyTest() {
767 gfx::Transform child_transform;
768 child_transform.Translate(250.0, 250.0);
769 child_transform.Rotate(90.0);
770 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14771
[email protected]a27cbde2013-03-23 22:01:49772 typename Types::ContentLayerType* parent = this->CreateRoot(
773 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
774 parent->SetMasksToBounds(true);
[email protected]3a9a92d2013-07-11 04:37:00775 typename Types::LayerType* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49776 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
777 child->SetMasksToBounds(true);
778 typename Types::ContentLayerType* layer =
779 this->CreateDrawingLayer(child,
780 this->identity_matrix,
781 gfx::PointF(10.f, 10.f),
782 gfx::Size(500, 500),
783 true);
784 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14785
[email protected]34ba1ffb2014-03-05 06:55:03786 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49787 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14788
[email protected]d002dd02013-03-27 07:40:40789 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22790 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14791
[email protected]a27cbde2013-03-23 22:01:49792 EXPECT_EQ(gfx::Rect().ToString(),
793 occlusion.occlusion_from_outside_target().ToString());
794 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
795 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14796
[email protected]d002dd02013-03-27 07:40:40797 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22798 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14799
[email protected]a27cbde2013-03-23 22:01:49800 EXPECT_EQ(gfx::Rect().ToString(),
801 occlusion.occlusion_from_outside_target().ToString());
802 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
803 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14804
[email protected]a27cbde2013-03-23 22:01:49805 /* Justification for the above occlusion from |layer|:
806 100
807 +---------------------+
808 | |
809 | 30 | rotate(90)
810 | 30 + ---------------------------------+
811 100 | | 10 | | ==>
812 | |10+---------------------------------+
813 | | | | | |
814 | | | | | |
815 | | | | | |
816 +----|--|-------------+ | |
817 | | | |
818 | | | |
819 | | | |500
820 | | | |
821 | | | |
822 | | | |
823 | | | |
824 +--|-------------------------------+ |
825 | |
826 +---------------------------------+
827 500
828
829 +---------------------+
830 | |30 Visible region of |layer|: /////
831 | |
832 | +---------------------------------+
833 100| | |10 |
834 | +---------------------------------+ |
835 | | |///////////////| 420 | |
836 | | |///////////////|60 | |
837 | | |///////////////| | |
838 +--|--|---------------+ | |
839 20|10| 70 | |
840 | | | |
841 | | | |
842 | | | |
843 | | | |
844 | | | |
845 | | |10|
846 | +------------------------------|--+
847 | 490 |
848 +---------------------------------+
849 500
850
851 */
852 }
[email protected]94f206c12012-08-25 00:09:14853};
854
[email protected]96baf3e2012-10-22 23:09:55855ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14856
[email protected]a27cbde2013-03-23 22:01:49857template <class Types>
[email protected]ca2902e92013-03-28 01:45:35858class OcclusionTrackerTestScaledRenderSurface
859 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49860 protected:
[email protected]ca2902e92013-03-28 01:45:35861 explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49862 : OcclusionTrackerTest<Types>(opaque_layers) {}
[email protected]710ffc02012-10-30 21:42:02863
[email protected]a27cbde2013-03-23 22:01:49864 void RunMyTest() {
865 typename Types::ContentLayerType* parent = this->CreateRoot(
866 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02867
[email protected]a27cbde2013-03-23 22:01:49868 gfx::Transform layer1_matrix;
869 layer1_matrix.Scale(2.0, 2.0);
870 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
871 parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true);
872 layer1->SetForceRenderSurface(true);
[email protected]710ffc02012-10-30 21:42:02873
[email protected]a27cbde2013-03-23 22:01:49874 gfx::Transform layer2_matrix;
875 layer2_matrix.Translate(25.0, 25.0);
876 typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
877 layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true);
878 typename Types::ContentLayerType* occluder =
879 this->CreateDrawingLayer(parent,
880 this->identity_matrix,
881 gfx::PointF(100.f, 100.f),
882 gfx::Size(500, 500),
883 true);
884 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02885
[email protected]34ba1ffb2014-03-05 06:55:03886 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49887 gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02888
[email protected]d002dd02013-03-27 07:40:40889 this->VisitLayer(occluder, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22890 this->EnterLayer(layer2, &occlusion);
[email protected]710ffc02012-10-30 21:42:02891
[email protected]a27cbde2013-03-23 22:01:49892 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
893 occlusion.occlusion_from_outside_target().ToString());
894 EXPECT_EQ(gfx::Rect().ToString(),
895 occlusion.occlusion_from_inside_target().ToString());
[email protected]710ffc02012-10-30 21:42:02896
[email protected]d5467eb72014-08-22 01:16:43897 EXPECT_EQ(
[email protected]a27cbde2013-03-23 22:01:49898 gfx::Rect(0, 0, 25, 25),
899 occlusion.UnoccludedLayerContentRect(layer2, gfx::Rect(0, 0, 25, 25)));
[email protected]d5467eb72014-08-22 01:16:43900 EXPECT_EQ(gfx::Rect(10, 25, 15, 25),
901 occlusion.UnoccludedLayerContentRect(layer2,
902 gfx::Rect(10, 25, 25, 25)));
903 EXPECT_EQ(gfx::Rect(25, 10, 25, 15),
904 occlusion.UnoccludedLayerContentRect(layer2,
905 gfx::Rect(25, 10, 25, 25)));
[email protected]a27cbde2013-03-23 22:01:49906 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
907 layer2, gfx::Rect(25, 25, 25, 25)).IsEmpty());
908 }
[email protected]710ffc02012-10-30 21:42:02909};
910
911ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
912
[email protected]a27cbde2013-03-23 22:01:49913template <class Types>
[email protected]ca2902e92013-03-28 01:45:35914class OcclusionTrackerTestVisitTargetTwoTimes
915 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49916 protected:
[email protected]ca2902e92013-03-28 01:45:35917 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49918 : OcclusionTrackerTest<Types>(opaque_layers) {}
919 void RunMyTest() {
[email protected]a27cbde2013-03-23 22:01:49920 typename Types::ContentLayerType* root = this->CreateRoot(
921 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]d5467eb72014-08-22 01:16:43922 typename Types::LayerType* surface = this->CreateSurface(
923 root, this->identity_matrix, gfx::PointF(30.f, 30.f), gfx::Size());
924 typename Types::ContentLayerType* surface_child =
925 this->CreateDrawingLayer(surface,
[email protected]a27cbde2013-03-23 22:01:49926 this->identity_matrix,
927 gfx::PointF(10.f, 10.f),
[email protected]d5467eb72014-08-22 01:16:43928 gfx::Size(50, 50),
[email protected]a27cbde2013-03-23 22:01:49929 true);
[email protected]d5467eb72014-08-22 01:16:43930 // |top_layer| makes |root|'s surface get considered by OcclusionTracker
931 // first, instead of |surface|'s. This exercises different code in
932 // LeaveToRenderTarget, as the target surface has already been seen when
933 // leaving |surface| later.
934 typename Types::ContentLayerType* top_layer =
935 this->CreateDrawingLayer(root,
[email protected]a27cbde2013-03-23 22:01:49936 this->identity_matrix,
[email protected]d5467eb72014-08-22 01:16:43937 gfx::PointF(40.f, 90.f),
938 gfx::Size(50, 20),
[email protected]a27cbde2013-03-23 22:01:49939 true);
940 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14941
[email protected]34ba1ffb2014-03-05 06:55:03942 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49943 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14944
[email protected]d5467eb72014-08-22 01:16:43945 this->VisitLayer(top_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14946
[email protected]a27cbde2013-03-23 22:01:49947 EXPECT_EQ(gfx::Rect().ToString(),
948 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43949 EXPECT_EQ(gfx::Rect(40, 90, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49950 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14951
[email protected]d5467eb72014-08-22 01:16:43952 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14953
[email protected]d5467eb72014-08-22 01:16:43954 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49955 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43956 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49957 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14958
[email protected]d5467eb72014-08-22 01:16:43959 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:14960
[email protected]d5467eb72014-08-22 01:16:43961 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49962 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43963 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49964 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14965
[email protected]d5467eb72014-08-22 01:16:43966 // Occlusion from |top_layer| already in the root target should get merged
967 // with the occlusion from the |surface| we are leaving now.
968 this->LeaveContributingSurface(surface, &occlusion);
969 this->EnterLayer(root, &occlusion);
[email protected]94f206c12012-08-25 00:09:14970
[email protected]d5467eb72014-08-22 01:16:43971 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
972 EXPECT_EQ(gfx::Rect(40, 40, 50, 70).ToString(),
[email protected]a27cbde2013-03-23 22:01:49973 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49974 }
[email protected]94f206c12012-08-25 00:09:14975};
976
[email protected]96baf3e2012-10-22 23:09:55977ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:14978
[email protected]a27cbde2013-03-23 22:01:49979template <class Types>
[email protected]ca2902e92013-03-28 01:45:35980class OcclusionTrackerTestSurfaceRotatedOffAxis
981 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49982 protected:
[email protected]ca2902e92013-03-28 01:45:35983 explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49984 : OcclusionTrackerTest<Types>(opaque_layers) {}
985 void RunMyTest() {
986 gfx::Transform child_transform;
987 child_transform.Translate(250.0, 250.0);
988 child_transform.Rotate(95.0);
989 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14990
[email protected]a27cbde2013-03-23 22:01:49991 gfx::Transform layer_transform;
992 layer_transform.Translate(10.0, 10.0);
[email protected]94f206c12012-08-25 00:09:14993
[email protected]a27cbde2013-03-23 22:01:49994 typename Types::ContentLayerType* root = this->CreateRoot(
995 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
996 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
997 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
998 typename Types::LayerType* child = this->CreateLayer(
999 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
1000 child->SetMasksToBounds(true);
1001 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1002 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true);
1003 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141004
[email protected]34ba1ffb2014-03-05 06:55:031005 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491006 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141007
[email protected]8a822692014-02-12 17:30:551008 gfx::Rect clipped_layer_in_child = MathUtil::MapEnclosingClippedRect(
[email protected]a27cbde2013-03-23 22:01:491009 layer_transform, layer->visible_content_rect());
[email protected]94f206c12012-08-25 00:09:141010
[email protected]d002dd02013-03-27 07:40:401011 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221012 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141013
[email protected]a27cbde2013-03-23 22:01:491014 EXPECT_EQ(gfx::Rect().ToString(),
1015 occlusion.occlusion_from_outside_target().ToString());
1016 EXPECT_EQ(clipped_layer_in_child.ToString(),
1017 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141018
[email protected]d002dd02013-03-27 07:40:401019 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221020 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141021
[email protected]a27cbde2013-03-23 22:01:491022 EXPECT_EQ(gfx::Rect().ToString(),
1023 occlusion.occlusion_from_outside_target().ToString());
1024 EXPECT_EQ(gfx::Rect().ToString(),
1025 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141026
[email protected]d5467eb72014-08-22 01:16:431027 EXPECT_EQ(
[email protected]a27cbde2013-03-23 22:01:491028 gfx::Rect(75, 55, 1, 1),
1029 occlusion.UnoccludedLayerContentRect(parent, gfx::Rect(75, 55, 1, 1)));
1030 }
[email protected]94f206c12012-08-25 00:09:141031};
1032
[email protected]96baf3e2012-10-22 23:09:551033ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:141034
[email protected]a27cbde2013-03-23 22:01:491035template <class Types>
[email protected]ca2902e92013-03-28 01:45:351036class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
1037 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491038 protected:
[email protected]ca2902e92013-03-28 01:45:351039 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491040 : OcclusionTrackerTest<Types>(opaque_layers) {}
1041 void RunMyTest() {
1042 gfx::Transform child_transform;
1043 child_transform.Translate(250.0, 250.0);
1044 child_transform.Rotate(90.0);
1045 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141046
[email protected]a27cbde2013-03-23 22:01:491047 typename Types::ContentLayerType* root = this->CreateRoot(
1048 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
1049 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
1050 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
1051 parent->SetMasksToBounds(true);
1052 typename Types::ContentLayerType* child =
[email protected]3a9a92d2013-07-11 04:37:001053 this->CreateDrawingSurface(parent,
[email protected]a27cbde2013-03-23 22:01:491054 child_transform,
1055 gfx::PointF(30.f, 30.f),
1056 gfx::Size(500, 500),
1057 false);
1058 child->SetMasksToBounds(true);
1059 typename Types::ContentLayerType* layer1 =
1060 this->CreateDrawingLayer(child,
1061 this->identity_matrix,
1062 gfx::PointF(10.f, 10.f),
1063 gfx::Size(500, 500),
1064 true);
1065 typename Types::ContentLayerType* layer2 =
1066 this->CreateDrawingLayer(child,
1067 this->identity_matrix,
1068 gfx::PointF(10.f, 450.f),
1069 gfx::Size(500, 60),
1070 true);
1071 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141072
[email protected]34ba1ffb2014-03-05 06:55:031073 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491074 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141075
[email protected]d002dd02013-03-27 07:40:401076 this->VisitLayer(layer2, &occlusion);
1077 this->VisitLayer(layer1, &occlusion);
1078 this->VisitLayer(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221079 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141080
[email protected]a27cbde2013-03-23 22:01:491081 EXPECT_EQ(gfx::Rect().ToString(),
1082 occlusion.occlusion_from_outside_target().ToString());
1083 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
1084 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141085
[email protected]a27cbde2013-03-23 22:01:491086 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1087 child, gfx::Rect(10, 430, 60, 70)).IsEmpty());
[email protected]d5467eb72014-08-22 01:16:431088 EXPECT_EQ(
[email protected]a27cbde2013-03-23 22:01:491089 gfx::Rect(9, 430, 1, 70),
1090 occlusion.UnoccludedLayerContentRect(child, gfx::Rect(9, 430, 60, 70)));
[email protected]d5467eb72014-08-22 01:16:431091 EXPECT_EQ(gfx::Rect(),
1092 occlusion.UnoccludedLayerContentRect(child,
1093 gfx::Rect(11, 430, 59, 70)));
1094 EXPECT_EQ(gfx::Rect(),
1095 occlusion.UnoccludedLayerContentRect(child,
1096 gfx::Rect(10, 431, 60, 69)));
[email protected]94f206c12012-08-25 00:09:141097
[email protected]d002dd02013-03-27 07:40:401098 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221099 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141100
[email protected]a27cbde2013-03-23 22:01:491101 EXPECT_EQ(gfx::Rect().ToString(),
1102 occlusion.occlusion_from_outside_target().ToString());
1103 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
1104 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141105
[email protected]a27cbde2013-03-23 22:01:491106 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1107 parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
[email protected]d5467eb72014-08-22 01:16:431108 EXPECT_EQ(gfx::Rect(29, 40, 1, 60),
1109 occlusion.UnoccludedLayerContentRect(parent,
1110 gfx::Rect(29, 40, 70, 60)));
1111 EXPECT_EQ(gfx::Rect(30, 39, 70, 1),
1112 occlusion.UnoccludedLayerContentRect(parent,
1113 gfx::Rect(30, 39, 70, 60)));
1114 EXPECT_EQ(gfx::Rect(),
1115 occlusion.UnoccludedLayerContentRect(parent,
1116 gfx::Rect(31, 40, 69, 60)));
1117 EXPECT_EQ(gfx::Rect(),
1118 occlusion.UnoccludedLayerContentRect(parent,
1119 gfx::Rect(30, 41, 70, 59)));
[email protected]94f206c12012-08-25 00:09:141120
[email protected]a27cbde2013-03-23 22:01:491121 /* Justification for the above occlusion from |layer1| and |layer2|:
[email protected]94f206c12012-08-25 00:09:141122
1123 +---------------------+
1124 | |30 Visible region of |layer1|: /////
1125 | | Visible region of |layer2|: \\\\\
1126 | +---------------------------------+
1127 | | |10 |
1128 | +---------------+-----------------+ |
1129 | | |\\\\\\\\\\\\|//| 420 | |
1130 | | |\\\\\\\\\\\\|//|60 | |
1131 | | |\\\\\\\\\\\\|//| | |
1132 +--|--|------------|--+ | |
1133 20|10| 70 | | |
1134 | | | | |
1135 | | | | |
1136 | | | | |
1137 | | | | |
1138 | | | | |
1139 | | | |10|
1140 | +------------|-----------------|--+
1141 | | 490 |
1142 +---------------+-----------------+
1143 60 440
1144 */
[email protected]a27cbde2013-03-23 22:01:491145 }
[email protected]94f206c12012-08-25 00:09:141146};
1147
[email protected]96baf3e2012-10-22 23:09:551148ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:141149
[email protected]a27cbde2013-03-23 22:01:491150template <class Types>
[email protected]ca2902e92013-03-28 01:45:351151class OcclusionTrackerTestOverlappingSurfaceSiblings
1152 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491153 protected:
[email protected]ca2902e92013-03-28 01:45:351154 explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491155 : OcclusionTrackerTest<Types>(opaque_layers) {}
1156 void RunMyTest() {
[email protected]a27cbde2013-03-23 22:01:491157 typename Types::ContentLayerType* parent = this->CreateRoot(
1158 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1159 parent->SetMasksToBounds(true);
1160 typename Types::LayerType* child1 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:431161 parent, this->identity_matrix, gfx::PointF(10.f, 0.f), gfx::Size());
[email protected]a27cbde2013-03-23 22:01:491162 typename Types::LayerType* child2 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:431163 parent, this->identity_matrix, gfx::PointF(30.f, 0.f), gfx::Size());
1164 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
1165 child1, this->identity_matrix, gfx::PointF(), gfx::Size(40, 50), true);
[email protected]a27cbde2013-03-23 22:01:491166 typename Types::ContentLayerType* layer2 =
1167 this->CreateDrawingLayer(child2,
1168 this->identity_matrix,
[email protected]d5467eb72014-08-22 01:16:431169 gfx::PointF(10.f, 0.f),
1170 gfx::Size(40, 50),
[email protected]a27cbde2013-03-23 22:01:491171 true);
1172 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141173
[email protected]34ba1ffb2014-03-05 06:55:031174 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491175 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141176
[email protected]d002dd02013-03-27 07:40:401177 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221178 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141179
[email protected]d5467eb72014-08-22 01:16:431180 // layer2's occlusion.
[email protected]a27cbde2013-03-23 22:01:491181 EXPECT_EQ(gfx::Rect().ToString(),
1182 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431183 EXPECT_EQ(gfx::Rect(10, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491184 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141185
[email protected]d002dd02013-03-27 07:40:401186 this->LeaveContributingSurface(child2, &occlusion);
1187 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221188 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141189
[email protected]d5467eb72014-08-22 01:16:431190 // layer2's occlusion in the target space of layer1.
1191 EXPECT_EQ(gfx::Rect(30, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491192 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431193 // layer1's occlusion.
1194 EXPECT_EQ(gfx::Rect(0, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491195 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141196
[email protected]d002dd02013-03-27 07:40:401197 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221198 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141199
[email protected]d5467eb72014-08-22 01:16:431200 // The occlusion from from layer1 and layer2 is merged.
1201 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1202 EXPECT_EQ(gfx::Rect(10, 0, 70, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491203 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491204 }
[email protected]94f206c12012-08-25 00:09:141205};
1206
[email protected]96baf3e2012-10-22 23:09:551207ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:141208
[email protected]a27cbde2013-03-23 22:01:491209template <class Types>
[email protected]ca2902e92013-03-28 01:45:351210class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms
1211 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491212 protected:
[email protected]ca2902e92013-03-28 01:45:351213 explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(
[email protected]a27cbde2013-03-23 22:01:491214 bool opaque_layers)
1215 : OcclusionTrackerTest<Types>(opaque_layers) {}
1216 void RunMyTest() {
1217 gfx::Transform child1_transform;
1218 child1_transform.Translate(250.0, 250.0);
1219 child1_transform.Rotate(-90.0);
1220 child1_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141221
[email protected]a27cbde2013-03-23 22:01:491222 gfx::Transform child2_transform;
1223 child2_transform.Translate(250.0, 250.0);
1224 child2_transform.Rotate(90.0);
1225 child2_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141226
[email protected]a27cbde2013-03-23 22:01:491227 typename Types::ContentLayerType* parent = this->CreateRoot(
1228 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1229 parent->SetMasksToBounds(true);
1230 typename Types::LayerType* child1 = this->CreateSurface(
1231 parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10));
1232 typename Types::LayerType* child2 =
1233 this->CreateDrawingSurface(parent,
1234 child2_transform,
1235 gfx::PointF(20.f, 40.f),
1236 gfx::Size(10, 10),
1237 false);
1238 typename Types::ContentLayerType* layer1 =
1239 this->CreateDrawingLayer(child1,
1240 this->identity_matrix,
1241 gfx::PointF(-10.f, -20.f),
1242 gfx::Size(510, 510),
1243 true);
1244 typename Types::ContentLayerType* layer2 =
1245 this->CreateDrawingLayer(child2,
1246 this->identity_matrix,
1247 gfx::PointF(-10.f, -10.f),
1248 gfx::Size(510, 510),
1249 true);
1250 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141251
[email protected]34ba1ffb2014-03-05 06:55:031252 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491253 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141254
[email protected]d002dd02013-03-27 07:40:401255 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221256 this->EnterLayer(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141257
[email protected]a27cbde2013-03-23 22:01:491258 EXPECT_EQ(gfx::Rect().ToString(),
1259 occlusion.occlusion_from_outside_target().ToString());
1260 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1261 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141262
[email protected]d002dd02013-03-27 07:40:401263 this->LeaveLayer(child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221264 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141265
[email protected]a27cbde2013-03-23 22:01:491266 // There is nothing above child2's surface in the z-order.
[email protected]d5467eb72014-08-22 01:16:431267 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80),
1268 occlusion.UnoccludedSurfaceContentRect(
1269 child2, false, gfx::Rect(-10, 420, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141270
[email protected]d002dd02013-03-27 07:40:401271 this->LeaveContributingSurface(child2, &occlusion);
1272 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221273 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141274
[email protected]a27cbde2013-03-23 22:01:491275 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
1276 occlusion.occlusion_from_outside_target().ToString());
1277 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
1278 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141279
[email protected]a27cbde2013-03-23 22:01:491280 // child2's contents will occlude child1 below it.
[email protected]e312aca2014-03-20 22:11:551281 EXPECT_EQ(gfx::Rect(20, 30, 80, 70).ToString(),
1282 occlusion.occlusion_on_contributing_surface_from_inside_target()
1283 .ToString());
1284 EXPECT_EQ(gfx::Rect().ToString(),
1285 occlusion.occlusion_on_contributing_surface_from_outside_target()
1286 .ToString());
[email protected]94f206c12012-08-25 00:09:141287
[email protected]d002dd02013-03-27 07:40:401288 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221289 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141290
[email protected]a27cbde2013-03-23 22:01:491291 EXPECT_EQ(gfx::Rect().ToString(),
1292 occlusion.occlusion_from_outside_target().ToString());
1293 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(),
1294 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141295
[email protected]a27cbde2013-03-23 22:01:491296 /* Justification for the above occlusion:
1297 100
1298 +---------------------+
1299 |20 | layer1
1300 10+----------------------------------+
1301 100 || 30 | layer2 |
1302 |20+----------------------------------+
1303 || | | | |
1304 || | | | |
1305 || | | | |
1306 +|-|------------------+ | |
1307 | | | | 510
1308 | | 510 | |
1309 | | | |
1310 | | | |
1311 | | | |
1312 | | | |
1313 | | 520 | |
1314 +----------------------------------+ |
1315 | |
1316 +----------------------------------+
1317 510
1318 */
1319 }
[email protected]94f206c12012-08-25 00:09:141320};
1321
[email protected]a27cbde2013-03-23 22:01:491322ALL_OCCLUSIONTRACKER_TEST(
1323 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:141324
[email protected]a27cbde2013-03-23 22:01:491325template <class Types>
[email protected]96baf3e2012-10-22 23:09:551326class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491327 protected:
[email protected]ca2902e92013-03-28 01:45:351328 explicit OcclusionTrackerTestFilters(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491329 : OcclusionTrackerTest<Types>(opaque_layers) {}
1330 void RunMyTest() {
1331 gfx::Transform layer_transform;
1332 layer_transform.Translate(250.0, 250.0);
1333 layer_transform.Rotate(90.0);
1334 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141335
[email protected]a27cbde2013-03-23 22:01:491336 typename Types::ContentLayerType* parent = this->CreateRoot(
1337 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1338 parent->SetMasksToBounds(true);
1339 typename Types::ContentLayerType* blur_layer =
1340 this->CreateDrawingLayer(parent,
1341 layer_transform,
1342 gfx::PointF(30.f, 30.f),
1343 gfx::Size(500, 500),
1344 true);
1345 typename Types::ContentLayerType* opaque_layer =
1346 this->CreateDrawingLayer(parent,
1347 layer_transform,
1348 gfx::PointF(30.f, 30.f),
1349 gfx::Size(500, 500),
1350 true);
1351 typename Types::ContentLayerType* opacity_layer =
1352 this->CreateDrawingLayer(parent,
1353 layer_transform,
1354 gfx::PointF(30.f, 30.f),
1355 gfx::Size(500, 500),
1356 true);
[email protected]94f206c12012-08-25 00:09:141357
[email protected]ae6b1a72013-06-25 18:49:291358 FilterOperations filters;
1359 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]a27cbde2013-03-23 22:01:491360 blur_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141361
[email protected]ae6b1a72013-06-25 18:49:291362 filters.Clear();
1363 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491364 opaque_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141365
[email protected]ae6b1a72013-06-25 18:49:291366 filters.Clear();
1367 filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491368 opacity_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141369
[email protected]a27cbde2013-03-23 22:01:491370 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141371
[email protected]34ba1ffb2014-03-05 06:55:031372 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491373 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141374
[email protected]a27cbde2013-03-23 22:01:491375 // Opacity layer won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401376 this->VisitLayer(opacity_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221377 this->EnterContributingSurface(opacity_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141378
[email protected]a27cbde2013-03-23 22:01:491379 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1380 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141381
[email protected]a27cbde2013-03-23 22:01:491382 // And has nothing to contribute to its parent surface.
[email protected]d002dd02013-03-27 07:40:401383 this->LeaveContributingSurface(opacity_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491384 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1385 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141386
[email protected]a27cbde2013-03-23 22:01:491387 // Opaque layer will contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401388 this->VisitLayer(opaque_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221389 this->EnterContributingSurface(opaque_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141390
[email protected]a27cbde2013-03-23 22:01:491391 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1392 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(),
1393 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141394
[email protected]a27cbde2013-03-23 22:01:491395 // And it gets translated to the parent surface.
[email protected]d002dd02013-03-27 07:40:401396 this->LeaveContributingSurface(opaque_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491397 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1398 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1399 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141400
[email protected]a27cbde2013-03-23 22:01:491401 // The blur layer needs to throw away any occlusion from outside its
1402 // subtree.
[email protected]e47b0a0a2013-11-18 23:26:221403 this->EnterLayer(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491404 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1405 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141406
[email protected]a27cbde2013-03-23 22:01:491407 // And it won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401408 this->LeaveLayer(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221409 this->EnterContributingSurface(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491410 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1411 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141412
[email protected]a27cbde2013-03-23 22:01:491413 // But the opaque layer's occlusion is preserved on the parent.
[email protected]d002dd02013-03-27 07:40:401414 this->LeaveContributingSurface(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221415 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491416 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1417 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1418 occlusion.occlusion_from_inside_target().ToString());
1419 }
[email protected]94f206c12012-08-25 00:09:141420};
1421
[email protected]96baf3e2012-10-22 23:09:551422ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:141423
[email protected]a27cbde2013-03-23 22:01:491424template <class Types>
[email protected]ca2902e92013-03-28 01:45:351425class OcclusionTrackerTestReplicaDoesOcclude
1426 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491427 protected:
[email protected]ca2902e92013-03-28 01:45:351428 explicit OcclusionTrackerTestReplicaDoesOcclude(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491429 : OcclusionTrackerTest<Types>(opaque_layers) {}
1430 void RunMyTest() {
1431 typename Types::ContentLayerType* parent = this->CreateRoot(
1432 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
[email protected]d5467eb72014-08-22 01:16:431433 typename Types::LayerType* surface = this->CreateDrawingSurface(
1434 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), true);
[email protected]a27cbde2013-03-23 22:01:491435 this->CreateReplicaLayer(
[email protected]d5467eb72014-08-22 01:16:431436 surface, this->identity_matrix, gfx::PointF(0.f, 50.f), gfx::Size());
[email protected]a27cbde2013-03-23 22:01:491437 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141438
[email protected]34ba1ffb2014-03-05 06:55:031439 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491440 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141441
[email protected]d002dd02013-03-27 07:40:401442 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141443
[email protected]a27cbde2013-03-23 22:01:491444 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1445 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141446
[email protected]d002dd02013-03-27 07:40:401447 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221448 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141449
[email protected]a27cbde2013-03-23 22:01:491450 // The surface and replica should both be occluding the parent.
[email protected]d5467eb72014-08-22 01:16:431451 EXPECT_EQ(gfx::Rect(50, 100).ToString(),
1452 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491453 }
[email protected]94f206c12012-08-25 00:09:141454};
1455
[email protected]96baf3e2012-10-22 23:09:551456ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude);
[email protected]94f206c12012-08-25 00:09:141457
[email protected]a27cbde2013-03-23 22:01:491458template <class Types>
[email protected]ca2902e92013-03-28 01:45:351459class OcclusionTrackerTestReplicaWithClipping
1460 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491461 protected:
[email protected]ca2902e92013-03-28 01:45:351462 explicit OcclusionTrackerTestReplicaWithClipping(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491463 : OcclusionTrackerTest<Types>(opaque_layers) {}
1464 void RunMyTest() {
1465 typename Types::ContentLayerType* parent = this->CreateRoot(
1466 this->identity_matrix, gfx::PointF(), gfx::Size(100, 170));
1467 parent->SetMasksToBounds(true);
1468 typename Types::LayerType* surface =
1469 this->CreateDrawingSurface(parent,
1470 this->identity_matrix,
1471 gfx::PointF(0.f, 100.f),
1472 gfx::Size(50, 50),
1473 true);
1474 this->CreateReplicaLayer(
[email protected]d5467eb72014-08-22 01:16:431475 surface, this->identity_matrix, gfx::PointF(0.f, 50.f), gfx::Size());
[email protected]a27cbde2013-03-23 22:01:491476 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141477
[email protected]34ba1ffb2014-03-05 06:55:031478 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491479 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141480
[email protected]d002dd02013-03-27 07:40:401481 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141482
[email protected]d5467eb72014-08-22 01:16:431483 // The surface layer's occlusion in its own space.
[email protected]a27cbde2013-03-23 22:01:491484 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1485 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431486 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141487
[email protected]d002dd02013-03-27 07:40:401488 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221489 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141490
[email protected]d5467eb72014-08-22 01:16:431491 // The surface and replica should both be occluding the parent, the
1492 // replica's occlusion is clipped by the parent.
1493 EXPECT_EQ(gfx::Rect(0, 100, 50, 70).ToString(),
1494 occlusion.occlusion_from_inside_target().ToString());
1495 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491496 }
[email protected]94f206c12012-08-25 00:09:141497};
1498
[email protected]96baf3e2012-10-22 23:09:551499ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping);
[email protected]94f206c12012-08-25 00:09:141500
[email protected]a27cbde2013-03-23 22:01:491501template <class Types>
[email protected]96baf3e2012-10-22 23:09:551502class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491503 protected:
[email protected]ca2902e92013-03-28 01:45:351504 explicit OcclusionTrackerTestReplicaWithMask(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491505 : OcclusionTrackerTest<Types>(opaque_layers) {}
1506 void RunMyTest() {
1507 typename Types::ContentLayerType* parent = this->CreateRoot(
1508 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
1509 typename Types::LayerType* surface =
1510 this->CreateDrawingSurface(parent,
1511 this->identity_matrix,
1512 gfx::PointF(0.f, 100.f),
1513 gfx::Size(50, 50),
1514 true);
1515 typename Types::LayerType* replica = this->CreateReplicaLayer(
1516 surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
1517 this->CreateMaskLayer(replica, gfx::Size(10, 10));
1518 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141519
[email protected]34ba1ffb2014-03-05 06:55:031520 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491521 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141522
[email protected]d002dd02013-03-27 07:40:401523 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141524
[email protected]a27cbde2013-03-23 22:01:491525 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1526 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141527
[email protected]d002dd02013-03-27 07:40:401528 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221529 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141530
[email protected]a27cbde2013-03-23 22:01:491531 // The replica should not be occluding the parent, since it has a mask
1532 // applied to it.
1533 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(),
1534 occlusion.occlusion_from_inside_target().ToString());
1535 }
[email protected]94f206c12012-08-25 00:09:141536};
1537
[email protected]96baf3e2012-10-22 23:09:551538ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask);
[email protected]94f206c12012-08-25 00:09:141539
[email protected]a27cbde2013-03-23 22:01:491540template <class Types>
[email protected]ca2902e92013-03-28 01:45:351541class OcclusionTrackerTestOpaqueContentsRegionEmpty
1542 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491543 protected:
[email protected]ca2902e92013-03-28 01:45:351544 explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491545 : OcclusionTrackerTest<Types>(opaque_layers) {}
1546 void RunMyTest() {
1547 typename Types::ContentLayerType* parent = this->CreateRoot(
1548 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1549 typename Types::ContentLayerType* layer =
1550 this->CreateDrawingSurface(parent,
1551 this->identity_matrix,
1552 gfx::PointF(),
1553 gfx::Size(200, 200),
1554 false);
1555 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141556
[email protected]34ba1ffb2014-03-05 06:55:031557 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491558 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:221559 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141560
[email protected]d5467eb72014-08-22 01:16:431561 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1562 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141563
[email protected]d002dd02013-03-27 07:40:401564 this->LeaveLayer(layer, &occlusion);
1565 this->VisitContributingSurface(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221566 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141567
[email protected]a27cbde2013-03-23 22:01:491568 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]d5467eb72014-08-22 01:16:431569 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491570 }
[email protected]94f206c12012-08-25 00:09:141571};
1572
[email protected]96baf3e2012-10-22 23:09:551573MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141574
[email protected]a27cbde2013-03-23 22:01:491575template <class Types>
[email protected]ca2902e92013-03-28 01:45:351576class OcclusionTrackerTestOpaqueContentsRegionNonEmpty
1577 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491578 protected:
[email protected]ca2902e92013-03-28 01:45:351579 explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491580 : OcclusionTrackerTest<Types>(opaque_layers) {}
1581 void RunMyTest() {
1582 typename Types::ContentLayerType* parent = this->CreateRoot(
1583 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1584 typename Types::ContentLayerType* layer =
1585 this->CreateDrawingLayer(parent,
1586 this->identity_matrix,
1587 gfx::PointF(100.f, 100.f),
1588 gfx::Size(200, 200),
1589 false);
1590 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141591 {
[email protected]34ba1ffb2014-03-05 06:55:031592 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491593 gfx::Rect(0, 0, 1000, 1000));
1594 layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:141595
[email protected]a27cbde2013-03-23 22:01:491596 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401597 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221598 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141599
[email protected]a27cbde2013-03-23 22:01:491600 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
1601 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141602 }
[email protected]a27cbde2013-03-23 22:01:491603 {
[email protected]34ba1ffb2014-03-05 06:55:031604 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491605 gfx::Rect(0, 0, 1000, 1000));
1606 layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
1607
1608 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401609 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221610 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491611
1612 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(),
1613 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491614 }
1615 {
[email protected]34ba1ffb2014-03-05 06:55:031616 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491617 gfx::Rect(0, 0, 1000, 1000));
1618 layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
1619
1620 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401621 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221622 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491623
1624 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
1625 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491626 }
1627 }
[email protected]94f206c12012-08-25 00:09:141628};
1629
[email protected]96baf3e2012-10-22 23:09:551630MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141631
[email protected]a27cbde2013-03-23 22:01:491632template <class Types>
[email protected]96baf3e2012-10-22 23:09:551633class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491634 protected:
[email protected]ca2902e92013-03-28 01:45:351635 explicit OcclusionTrackerTest3dTransform(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491636 : OcclusionTrackerTest<Types>(opaque_layers) {}
1637 void RunMyTest() {
1638 gfx::Transform transform;
1639 transform.RotateAboutYAxis(30.0);
[email protected]94f206c12012-08-25 00:09:141640
[email protected]a27cbde2013-03-23 22:01:491641 typename Types::ContentLayerType* parent = this->CreateRoot(
1642 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1643 typename Types::LayerType* container = this->CreateLayer(
1644 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1645 typename Types::ContentLayerType* layer =
1646 this->CreateDrawingLayer(container,
1647 transform,
1648 gfx::PointF(100.f, 100.f),
1649 gfx::Size(200, 200),
1650 true);
1651 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141652
[email protected]34ba1ffb2014-03-05 06:55:031653 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491654 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:221655 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141656
[email protected]a27cbde2013-03-23 22:01:491657 // The layer is rotated in 3d but without preserving 3d, so it only gets
1658 // resized.
[email protected]d5467eb72014-08-22 01:16:431659 EXPECT_EQ(
[email protected]a27cbde2013-03-23 22:01:491660 gfx::Rect(0, 0, 200, 200),
1661 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
1662 }
[email protected]94f206c12012-08-25 00:09:141663};
1664
[email protected]96baf3e2012-10-22 23:09:551665MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform);
[email protected]94f206c12012-08-25 00:09:141666
[email protected]a27cbde2013-03-23 22:01:491667template <class Types>
[email protected]ca2902e92013-03-28 01:45:351668class OcclusionTrackerTestUnsorted3dLayers
1669 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491670 protected:
[email protected]ca2902e92013-03-28 01:45:351671 explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491672 : OcclusionTrackerTest<Types>(opaque_layers) {}
1673 void RunMyTest() {
1674 // Currently, The main thread layer iterator does not iterate over 3d items
1675 // in sorted order, because layer sorting is not performed on the main
1676 // thread. Because of this, the occlusion tracker cannot assume that a 3d
1677 // layer occludes other layers that have not yet been iterated over. For
1678 // now, the expected behavior is that a 3d layer simply does not add any
1679 // occlusion to the occlusion tracker.
[email protected]94f206c12012-08-25 00:09:141680
[email protected]a27cbde2013-03-23 22:01:491681 gfx::Transform translation_to_front;
1682 translation_to_front.Translate3d(0.0, 0.0, -10.0);
1683 gfx::Transform translation_to_back;
1684 translation_to_front.Translate3d(0.0, 0.0, -100.0);
[email protected]94f206c12012-08-25 00:09:141685
[email protected]a27cbde2013-03-23 22:01:491686 typename Types::ContentLayerType* parent = this->CreateRoot(
1687 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1688 typename Types::ContentLayerType* child1 = this->CreateDrawingLayer(
1689 parent, translation_to_back, gfx::PointF(), gfx::Size(100, 100), true);
1690 typename Types::ContentLayerType* child2 =
1691 this->CreateDrawingLayer(parent,
1692 translation_to_front,
1693 gfx::PointF(50.f, 50.f),
1694 gfx::Size(100, 100),
1695 true);
[email protected]56fffdd2014-02-11 19:50:571696 parent->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281697 parent->Set3dSortingContextId(1);
1698 child1->Set3dSortingContextId(1);
1699 child2->Set3dSortingContextId(1);
[email protected]94f206c12012-08-25 00:09:141700
[email protected]a27cbde2013-03-23 22:01:491701 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141702
[email protected]34ba1ffb2014-03-05 06:55:031703 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491704 gfx::Rect(0, 0, 1000, 1000));
[email protected]d002dd02013-03-27 07:40:401705 this->VisitLayer(child2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491706 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1707 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141708
[email protected]d002dd02013-03-27 07:40:401709 this->VisitLayer(child1, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491710 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1711 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1712 }
[email protected]94f206c12012-08-25 00:09:141713};
1714
[email protected]a27cbde2013-03-23 22:01:491715// This test will have different layer ordering on the impl thread; the test
1716// will only work on the main thread.
[email protected]96baf3e2012-10-22 23:09:551717MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
[email protected]94f206c12012-08-25 00:09:141718
[email protected]a27cbde2013-03-23 22:01:491719template <class Types>
[email protected]ca2902e92013-03-28 01:45:351720class OcclusionTrackerTestPerspectiveTransform
1721 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491722 protected:
[email protected]ca2902e92013-03-28 01:45:351723 explicit OcclusionTrackerTestPerspectiveTransform(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491724 : OcclusionTrackerTest<Types>(opaque_layers) {}
1725 void RunMyTest() {
1726 gfx::Transform transform;
1727 transform.Translate(150.0, 150.0);
1728 transform.ApplyPerspectiveDepth(400.0);
1729 transform.RotateAboutXAxis(-30.0);
1730 transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:141731
[email protected]a27cbde2013-03-23 22:01:491732 typename Types::ContentLayerType* parent = this->CreateRoot(
1733 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1734 typename Types::LayerType* container = this->CreateLayer(
1735 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1736 typename Types::ContentLayerType* layer =
1737 this->CreateDrawingLayer(container,
1738 transform,
1739 gfx::PointF(100.f, 100.f),
1740 gfx::Size(200, 200),
1741 true);
[email protected]56fffdd2014-02-11 19:50:571742 container->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281743 container->Set3dSortingContextId(1);
1744 layer->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:571745 layer->SetShouldFlattenTransform(false);
1746
[email protected]a27cbde2013-03-23 22:01:491747 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141748
[email protected]34ba1ffb2014-03-05 06:55:031749 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491750 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:221751 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141752
[email protected]d5467eb72014-08-22 01:16:431753 EXPECT_EQ(
[email protected]a27cbde2013-03-23 22:01:491754 gfx::Rect(0, 0, 200, 200),
1755 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
1756 }
[email protected]94f206c12012-08-25 00:09:141757};
1758
[email protected]a27cbde2013-03-23 22:01:491759// This test requires accumulating occlusion of 3d layers, which are skipped by
1760// the occlusion tracker on the main thread. So this test should run on the impl
1761// thread.
[email protected]96baf3e2012-10-22 23:09:551762IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransform);
[email protected]a27cbde2013-03-23 22:01:491763template <class Types>
[email protected]ca2902e92013-03-28 01:45:351764class OcclusionTrackerTestPerspectiveTransformBehindCamera
1765 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491766 protected:
[email protected]ca2902e92013-03-28 01:45:351767 explicit OcclusionTrackerTestPerspectiveTransformBehindCamera(
1768 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491769 : OcclusionTrackerTest<Types>(opaque_layers) {}
1770 void RunMyTest() {
1771 // This test is based on the platform/chromium/compositing/3d-corners.html
1772 // layout test.
1773 gfx::Transform transform;
1774 transform.Translate(250.0, 50.0);
1775 transform.ApplyPerspectiveDepth(10.0);
1776 transform.Translate(-250.0, -50.0);
1777 transform.Translate(250.0, 50.0);
1778 transform.RotateAboutXAxis(-167.0);
1779 transform.Translate(-250.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141780
[email protected]a27cbde2013-03-23 22:01:491781 typename Types::ContentLayerType* parent = this->CreateRoot(
1782 this->identity_matrix, gfx::PointF(), gfx::Size(500, 100));
1783 typename Types::LayerType* container = this->CreateLayer(
1784 parent, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
1785 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1786 container, transform, gfx::PointF(), gfx::Size(500, 500), true);
[email protected]56fffdd2014-02-11 19:50:571787 container->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281788 container->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:571789 layer->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281790 layer->Set3dSortingContextId(1);
[email protected]a27cbde2013-03-23 22:01:491791 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141792
[email protected]34ba1ffb2014-03-05 06:55:031793 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491794 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:221795 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141796
[email protected]a27cbde2013-03-23 22:01:491797 // The bottom 11 pixel rows of this layer remain visible inside the
1798 // container, after translation to the target surface. When translated back,
1799 // this will include many more pixels but must include at least the bottom
1800 // 11 rows.
1801 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:451802 layer, gfx::Rect(0, 26, 500, 474)).
1803 Contains(gfx::Rect(0, 489, 500, 11)));
[email protected]a27cbde2013-03-23 22:01:491804 }
[email protected]94f206c12012-08-25 00:09:141805};
1806
[email protected]a27cbde2013-03-23 22:01:491807// This test requires accumulating occlusion of 3d layers, which are skipped by
1808// the occlusion tracker on the main thread. So this test should run on the impl
1809// thread.
[email protected]96baf3e2012-10-22 23:09:551810IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransformBehindCamera);
[email protected]94f206c12012-08-25 00:09:141811
[email protected]a27cbde2013-03-23 22:01:491812template <class Types>
[email protected]ca2902e92013-03-28 01:45:351813class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude
1814 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491815 protected:
[email protected]ca2902e92013-03-28 01:45:351816 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(
1817 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491818 : OcclusionTrackerTest<Types>(opaque_layers) {}
1819 void RunMyTest() {
1820 gfx::Transform transform;
1821 transform.Translate(50.0, 50.0);
1822 transform.ApplyPerspectiveDepth(100.0);
1823 transform.Translate3d(0.0, 0.0, 110.0);
1824 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141825
[email protected]a27cbde2013-03-23 22:01:491826 typename Types::ContentLayerType* parent = this->CreateRoot(
1827 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1828 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1829 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
[email protected]56fffdd2014-02-11 19:50:571830 parent->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281831 parent->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:571832 layer->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281833 layer->Set3dSortingContextId(1);
[email protected]a27cbde2013-03-23 22:01:491834 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141835
[email protected]34ba1ffb2014-03-05 06:55:031836 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491837 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141838
[email protected]a27cbde2013-03-23 22:01:491839 // The |layer| is entirely behind the camera and should not occlude.
[email protected]d002dd02013-03-27 07:40:401840 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221841 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491842 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1843 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1844 }
[email protected]94f206c12012-08-25 00:09:141845};
1846
[email protected]a27cbde2013-03-23 22:01:491847// This test requires accumulating occlusion of 3d layers, which are skipped by
1848// the occlusion tracker on the main thread. So this test should run on the impl
1849// thread.
[email protected]96baf3e2012-10-22 23:09:551850IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude);
[email protected]94f206c12012-08-25 00:09:141851
[email protected]a27cbde2013-03-23 22:01:491852template <class Types>
[email protected]ca2902e92013-03-28 01:45:351853class OcclusionTrackerTestLargePixelsOccludeInsideClipRect
1854 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491855 protected:
[email protected]ca2902e92013-03-28 01:45:351856 explicit OcclusionTrackerTestLargePixelsOccludeInsideClipRect(
1857 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491858 : OcclusionTrackerTest<Types>(opaque_layers) {}
1859 void RunMyTest() {
1860 gfx::Transform transform;
1861 transform.Translate(50.0, 50.0);
1862 transform.ApplyPerspectiveDepth(100.0);
1863 transform.Translate3d(0.0, 0.0, 99.0);
1864 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141865
[email protected]a27cbde2013-03-23 22:01:491866 typename Types::ContentLayerType* parent = this->CreateRoot(
1867 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1868 parent->SetMasksToBounds(true);
1869 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1870 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
[email protected]56fffdd2014-02-11 19:50:571871 parent->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281872 parent->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:571873 layer->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281874 layer->Set3dSortingContextId(1);
[email protected]a27cbde2013-03-23 22:01:491875 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141876
[email protected]34ba1ffb2014-03-05 06:55:031877 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491878 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141879
[email protected]a27cbde2013-03-23 22:01:491880 // This is very close to the camera, so pixels in its visible_content_rect()
1881 // will actually go outside of the layer's clip rect. Ensure that those
1882 // pixels don't occlude things outside the clip rect.
[email protected]d002dd02013-03-27 07:40:401883 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221884 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491885 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
1886 occlusion.occlusion_from_inside_target().ToString());
1887 EXPECT_EQ(gfx::Rect().ToString(),
1888 occlusion.occlusion_from_outside_target().ToString());
1889 }
[email protected]94f206c12012-08-25 00:09:141890};
1891
[email protected]a27cbde2013-03-23 22:01:491892// This test requires accumulating occlusion of 3d layers, which are skipped by
1893// the occlusion tracker on the main thread. So this test should run on the impl
1894// thread.
[email protected]96baf3e2012-10-22 23:09:551895IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect);
[email protected]94f206c12012-08-25 00:09:141896
[email protected]a27cbde2013-03-23 22:01:491897template <class Types>
[email protected]ca2902e92013-03-28 01:45:351898class OcclusionTrackerTestAnimationOpacity1OnMainThread
1899 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491900 protected:
[email protected]ca2902e92013-03-28 01:45:351901 explicit OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491902 : OcclusionTrackerTest<Types>(opaque_layers) {}
1903 void RunMyTest() {
1904 // parent
1905 // +--layer
1906 // +--surface
1907 // | +--surface_child
1908 // | +--surface_child2
1909 // +--parent2
1910 // +--topmost
[email protected]c8d71552013-01-22 03:43:021911
[email protected]a27cbde2013-03-23 22:01:491912 typename Types::ContentLayerType* parent = this->CreateRoot(
1913 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1914 typename Types::ContentLayerType* layer =
1915 this->CreateDrawingLayer(parent,
1916 this->identity_matrix,
1917 gfx::PointF(),
1918 gfx::Size(300, 300),
1919 true);
1920 typename Types::ContentLayerType* surface =
1921 this->CreateDrawingSurface(parent,
1922 this->identity_matrix,
1923 gfx::PointF(),
1924 gfx::Size(300, 300),
1925 true);
1926 typename Types::ContentLayerType* surface_child =
1927 this->CreateDrawingLayer(surface,
1928 this->identity_matrix,
1929 gfx::PointF(),
1930 gfx::Size(200, 300),
1931 true);
1932 typename Types::ContentLayerType* surface_child2 =
1933 this->CreateDrawingLayer(surface,
1934 this->identity_matrix,
1935 gfx::PointF(),
1936 gfx::Size(100, 300),
1937 true);
1938 typename Types::ContentLayerType* parent2 =
1939 this->CreateDrawingLayer(parent,
1940 this->identity_matrix,
1941 gfx::PointF(),
1942 gfx::Size(300, 300),
1943 false);
1944 typename Types::ContentLayerType* topmost =
1945 this->CreateDrawingLayer(parent,
1946 this->identity_matrix,
1947 gfx::PointF(250.f, 0.f),
1948 gfx::Size(50, 300),
1949 true);
[email protected]94f206c12012-08-25 00:09:141950
[email protected]a27cbde2013-03-23 22:01:491951 AddOpacityTransitionToController(
1952 layer->layer_animation_controller(), 10.0, 0.f, 1.f, false);
1953 AddOpacityTransitionToController(
1954 surface->layer_animation_controller(), 10.0, 0.f, 1.f, false);
1955 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141956
[email protected]a27cbde2013-03-23 22:01:491957 EXPECT_TRUE(layer->draw_opacity_is_animating());
1958 EXPECT_FALSE(surface->draw_opacity_is_animating());
1959 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:141960
[email protected]34ba1ffb2014-03-05 06:55:031961 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491962 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141963
[email protected]d002dd02013-03-27 07:40:401964 this->VisitLayer(topmost, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221965 this->EnterLayer(parent2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491966 // This occlusion will affect all surfaces.
1967 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1968 occlusion.occlusion_from_inside_target().ToString());
1969 EXPECT_EQ(gfx::Rect().ToString(),
1970 occlusion.occlusion_from_outside_target().ToString());
1971 EXPECT_EQ(gfx::Rect(0, 0, 250, 300).ToString(),
1972 occlusion.UnoccludedLayerContentRect(
1973 parent2, gfx::Rect(0, 0, 300, 300)).ToString());
[email protected]d002dd02013-03-27 07:40:401974 this->LeaveLayer(parent2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141975
[email protected]d002dd02013-03-27 07:40:401976 this->VisitLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221977 this->EnterLayer(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491978 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1979 occlusion.occlusion_from_inside_target().ToString());
1980 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1981 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431982 EXPECT_EQ(gfx::Rect(100, 0, 100, 300),
1983 occlusion.UnoccludedLayerContentRect(surface_child,
1984 gfx::Rect(0, 0, 200, 300)));
[email protected]d002dd02013-03-27 07:40:401985 this->LeaveLayer(surface_child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221986 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491987 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
1988 occlusion.occlusion_from_inside_target().ToString());
1989 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1990 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431991 EXPECT_EQ(gfx::Rect(200, 0, 50, 300),
1992 occlusion.UnoccludedLayerContentRect(surface,
1993 gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:401994 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141995
[email protected]e47b0a0a2013-11-18 23:26:221996 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491997 // Occlusion within the surface is lost when leaving the animating surface.
1998 EXPECT_EQ(gfx::Rect().ToString(),
1999 occlusion.occlusion_from_inside_target().ToString());
2000 EXPECT_EQ(gfx::Rect().ToString(),
2001 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432002 EXPECT_EQ(gfx::Rect(0, 0, 250, 300),
2003 occlusion.UnoccludedSurfaceContentRect(
2004 surface, false, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402005 this->LeaveContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142006
[email protected]a27cbde2013-03-23 22:01:492007 // Occlusion from outside the animating surface still exists.
2008 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2009 occlusion.occlusion_from_inside_target().ToString());
2010 EXPECT_EQ(gfx::Rect().ToString(),
2011 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:022012
[email protected]d002dd02013-03-27 07:40:402013 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222014 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:142015
[email protected]a27cbde2013-03-23 22:01:492016 // Occlusion is not added for the animating |layer|.
[email protected]d5467eb72014-08-22 01:16:432017 EXPECT_EQ(gfx::Rect(0, 0, 250, 300),
2018 occlusion.UnoccludedLayerContentRect(parent,
2019 gfx::Rect(0, 0, 300, 300)));
[email protected]a27cbde2013-03-23 22:01:492020 }
[email protected]94f206c12012-08-25 00:09:142021};
2022
[email protected]96baf3e2012-10-22 23:09:552023MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread);
[email protected]94f206c12012-08-25 00:09:142024
[email protected]a27cbde2013-03-23 22:01:492025template <class Types>
[email protected]ca2902e92013-03-28 01:45:352026class OcclusionTrackerTestAnimationOpacity0OnMainThread
2027 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492028 protected:
[email protected]ca2902e92013-03-28 01:45:352029 explicit OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492030 : OcclusionTrackerTest<Types>(opaque_layers) {}
2031 void RunMyTest() {
2032 typename Types::ContentLayerType* parent = this->CreateRoot(
2033 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2034 typename Types::ContentLayerType* layer =
2035 this->CreateDrawingLayer(parent,
2036 this->identity_matrix,
2037 gfx::PointF(),
2038 gfx::Size(300, 300),
2039 true);
2040 typename Types::ContentLayerType* surface =
2041 this->CreateDrawingSurface(parent,
2042 this->identity_matrix,
2043 gfx::PointF(),
2044 gfx::Size(300, 300),
2045 true);
2046 typename Types::ContentLayerType* surface_child =
2047 this->CreateDrawingLayer(surface,
2048 this->identity_matrix,
2049 gfx::PointF(),
2050 gfx::Size(200, 300),
2051 true);
2052 typename Types::ContentLayerType* surface_child2 =
2053 this->CreateDrawingLayer(surface,
2054 this->identity_matrix,
2055 gfx::PointF(),
2056 gfx::Size(100, 300),
2057 true);
2058 typename Types::ContentLayerType* parent2 =
2059 this->CreateDrawingLayer(parent,
2060 this->identity_matrix,
2061 gfx::PointF(),
2062 gfx::Size(300, 300),
2063 false);
2064 typename Types::ContentLayerType* topmost =
2065 this->CreateDrawingLayer(parent,
2066 this->identity_matrix,
2067 gfx::PointF(250.f, 0.f),
2068 gfx::Size(50, 300),
2069 true);
[email protected]94f206c12012-08-25 00:09:142070
[email protected]a27cbde2013-03-23 22:01:492071 AddOpacityTransitionToController(
2072 layer->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2073 AddOpacityTransitionToController(
2074 surface->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2075 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142076
[email protected]a27cbde2013-03-23 22:01:492077 EXPECT_TRUE(layer->draw_opacity_is_animating());
2078 EXPECT_FALSE(surface->draw_opacity_is_animating());
2079 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:142080
[email protected]34ba1ffb2014-03-05 06:55:032081 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492082 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142083
[email protected]d002dd02013-03-27 07:40:402084 this->VisitLayer(topmost, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222085 this->EnterLayer(parent2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492086 // This occlusion will affect all surfaces.
2087 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2088 occlusion.occlusion_from_inside_target().ToString());
2089 EXPECT_EQ(gfx::Rect().ToString(),
2090 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432091 EXPECT_EQ(gfx::Rect(0, 0, 250, 300),
2092 occlusion.UnoccludedLayerContentRect(parent,
2093 gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402094 this->LeaveLayer(parent2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142095
[email protected]d002dd02013-03-27 07:40:402096 this->VisitLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222097 this->EnterLayer(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492098 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2099 occlusion.occlusion_from_inside_target().ToString());
2100 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2101 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432102 EXPECT_EQ(gfx::Rect(100, 0, 100, 300),
2103 occlusion.UnoccludedLayerContentRect(surface_child,
2104 gfx::Rect(0, 0, 200, 300)));
[email protected]d002dd02013-03-27 07:40:402105 this->LeaveLayer(surface_child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222106 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492107 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
2108 occlusion.occlusion_from_inside_target().ToString());
2109 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2110 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432111 EXPECT_EQ(gfx::Rect(200, 0, 50, 300),
2112 occlusion.UnoccludedLayerContentRect(surface,
2113 gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402114 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142115
[email protected]e47b0a0a2013-11-18 23:26:222116 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492117 // Occlusion within the surface is lost when leaving the animating surface.
2118 EXPECT_EQ(gfx::Rect().ToString(),
2119 occlusion.occlusion_from_inside_target().ToString());
2120 EXPECT_EQ(gfx::Rect().ToString(),
2121 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432122 EXPECT_EQ(gfx::Rect(0, 0, 250, 300),
2123 occlusion.UnoccludedSurfaceContentRect(
2124 surface, false, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402125 this->LeaveContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142126
[email protected]a27cbde2013-03-23 22:01:492127 // Occlusion from outside the animating surface still exists.
2128 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2129 occlusion.occlusion_from_inside_target().ToString());
2130 EXPECT_EQ(gfx::Rect().ToString(),
2131 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:022132
[email protected]d002dd02013-03-27 07:40:402133 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222134 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:142135
[email protected]a27cbde2013-03-23 22:01:492136 // Occlusion is not added for the animating |layer|.
[email protected]d5467eb72014-08-22 01:16:432137 EXPECT_EQ(gfx::Rect(0, 0, 250, 300),
2138 occlusion.UnoccludedLayerContentRect(parent,
2139 gfx::Rect(0, 0, 300, 300)));
[email protected]a27cbde2013-03-23 22:01:492140 }
[email protected]94f206c12012-08-25 00:09:142141};
2142
[email protected]96baf3e2012-10-22 23:09:552143MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread);
[email protected]94f206c12012-08-25 00:09:142144
[email protected]a27cbde2013-03-23 22:01:492145template <class Types>
[email protected]ca2902e92013-03-28 01:45:352146class OcclusionTrackerTestAnimationTranslateOnMainThread
2147 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492148 protected:
[email protected]ca2902e92013-03-28 01:45:352149 explicit OcclusionTrackerTestAnimationTranslateOnMainThread(
2150 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492151 : OcclusionTrackerTest<Types>(opaque_layers) {}
2152 void RunMyTest() {
2153 typename Types::ContentLayerType* parent = this->CreateRoot(
2154 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2155 typename Types::ContentLayerType* layer =
2156 this->CreateDrawingLayer(parent,
2157 this->identity_matrix,
2158 gfx::PointF(),
2159 gfx::Size(300, 300),
2160 true);
2161 typename Types::ContentLayerType* surface =
2162 this->CreateDrawingSurface(parent,
2163 this->identity_matrix,
2164 gfx::PointF(),
2165 gfx::Size(300, 300),
2166 true);
2167 typename Types::ContentLayerType* surface_child =
2168 this->CreateDrawingLayer(surface,
2169 this->identity_matrix,
2170 gfx::PointF(),
2171 gfx::Size(200, 300),
2172 true);
2173 typename Types::ContentLayerType* surface_child2 =
2174 this->CreateDrawingLayer(surface,
2175 this->identity_matrix,
2176 gfx::PointF(),
2177 gfx::Size(100, 300),
2178 true);
2179 typename Types::ContentLayerType* surface2 = this->CreateDrawingSurface(
2180 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 300), true);
[email protected]94f206c12012-08-25 00:09:142181
[email protected]a27cbde2013-03-23 22:01:492182 AddAnimatedTransformToController(
2183 layer->layer_animation_controller(), 10.0, 30, 0);
2184 AddAnimatedTransformToController(
2185 surface->layer_animation_controller(), 10.0, 30, 0);
2186 AddAnimatedTransformToController(
2187 surface_child->layer_animation_controller(), 10.0, 30, 0);
2188 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142189
[email protected]a27cbde2013-03-23 22:01:492190 EXPECT_TRUE(layer->draw_transform_is_animating());
2191 EXPECT_TRUE(layer->screen_space_transform_is_animating());
2192 EXPECT_TRUE(
2193 surface->render_surface()->target_surface_transforms_are_animating());
2194 EXPECT_TRUE(
2195 surface->render_surface()->screen_space_transforms_are_animating());
2196 // The surface owning layer doesn't animate against its own surface.
2197 EXPECT_FALSE(surface->draw_transform_is_animating());
2198 EXPECT_TRUE(surface->screen_space_transform_is_animating());
2199 EXPECT_TRUE(surface_child->draw_transform_is_animating());
2200 EXPECT_TRUE(surface_child->screen_space_transform_is_animating());
[email protected]94f206c12012-08-25 00:09:142201
[email protected]34ba1ffb2014-03-05 06:55:032202 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492203 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142204
[email protected]d002dd02013-03-27 07:40:402205 this->VisitLayer(surface2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222206 this->EnterContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142207
[email protected]a27cbde2013-03-23 22:01:492208 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
2209 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142210
[email protected]d002dd02013-03-27 07:40:402211 this->LeaveContributingSurface(surface2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222212 this->EnterLayer(surface_child2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492213 // surface_child2 is moving in screen space but not relative to its target,
2214 // so occlusion should happen in its target space only. It also means that
2215 // things occluding from outside the target (e.g. surface2) cannot occlude
2216 // this layer.
2217 EXPECT_EQ(gfx::Rect().ToString(),
2218 occlusion.occlusion_from_outside_target().ToString());
[email protected]7d6d6c92014-03-06 01:18:502219 EXPECT_EQ(gfx::Rect().ToString(),
2220 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142221
[email protected]d002dd02013-03-27 07:40:402222 this->LeaveLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222223 this->EnterLayer(surface_child, &occlusion);
[email protected]7d6d6c92014-03-06 01:18:502224 // surface_child2 added to the occlusion since it is not moving relative
2225 // to its target.
[email protected]a27cbde2013-03-23 22:01:492226 EXPECT_EQ(gfx::Rect().ToString(),
2227 occlusion.occlusion_from_outside_target().ToString());
2228 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2229 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142230
[email protected]d002dd02013-03-27 07:40:402231 this->LeaveLayer(surface_child, &occlusion);
[email protected]7d6d6c92014-03-06 01:18:502232 // surface_child is moving relative to its target, so it does not add
2233 // occlusion.
[email protected]a27cbde2013-03-23 22:01:492234 EXPECT_EQ(gfx::Rect().ToString(),
2235 occlusion.occlusion_from_outside_target().ToString());
2236 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2237 occlusion.occlusion_from_inside_target().ToString());
[email protected]7d6d6c92014-03-06 01:18:502238
2239 this->EnterLayer(surface, &occlusion);
2240 EXPECT_EQ(gfx::Rect().ToString(),
2241 occlusion.occlusion_from_outside_target().ToString());
2242 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2243 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142244
[email protected]d002dd02013-03-27 07:40:402245 this->LeaveLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492246 // The surface's owning layer is moving in screen space but not relative to
[email protected]7d6d6c92014-03-06 01:18:502247 // its target, so it adds to the occlusion.
[email protected]a27cbde2013-03-23 22:01:492248 EXPECT_EQ(gfx::Rect().ToString(),
2249 occlusion.occlusion_from_outside_target().ToString());
2250 EXPECT_EQ(gfx::Rect(0, 0, 300, 300).ToString(),
2251 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142252
[email protected]e47b0a0a2013-11-18 23:26:222253 this->EnterContributingSurface(surface, &occlusion);
[email protected]d002dd02013-03-27 07:40:402254 this->LeaveContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492255 // The |surface| is moving in the screen and in its target, so all occlusion
[email protected]7d6d6c92014-03-06 01:18:502256 // within the surface is lost when leaving it. Only the |surface2| occlusion
2257 // is left.
2258 EXPECT_EQ(gfx::Rect().ToString(),
2259 occlusion.occlusion_from_outside_target().ToString());
2260 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
2261 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142262
[email protected]7d6d6c92014-03-06 01:18:502263 this->VisitLayer(layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492264 // The |layer| is animating in the screen and in its target, so no occlusion
2265 // is added.
[email protected]7d6d6c92014-03-06 01:18:502266 EXPECT_EQ(gfx::Rect().ToString(),
2267 occlusion.occlusion_from_outside_target().ToString());
2268 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
2269 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:492270 }
[email protected]94f206c12012-08-25 00:09:142271};
2272
[email protected]96baf3e2012-10-22 23:09:552273MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread);
[email protected]94f206c12012-08-25 00:09:142274
[email protected]a27cbde2013-03-23 22:01:492275template <class Types>
[email protected]ca2902e92013-03-28 01:45:352276class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent
2277 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492278 protected:
[email protected]ca2902e92013-03-28 01:45:352279 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(
2280 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492281 : OcclusionTrackerTest<Types>(opaque_layers) {}
2282 void RunMyTest() {
2283 gfx::Transform surface_transform;
2284 surface_transform.Translate(300.0, 300.0);
2285 surface_transform.Scale(2.0, 2.0);
2286 surface_transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:142287
[email protected]a27cbde2013-03-23 22:01:492288 typename Types::ContentLayerType* parent = this->CreateRoot(
2289 this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
2290 typename Types::ContentLayerType* surface = this->CreateDrawingSurface(
2291 parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false);
2292 typename Types::ContentLayerType* surface2 =
2293 this->CreateDrawingSurface(parent,
2294 this->identity_matrix,
2295 gfx::PointF(50.f, 50.f),
2296 gfx::Size(300, 300),
2297 false);
2298 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
2299 surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
2300 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142301
[email protected]34ba1ffb2014-03-05 06:55:032302 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492303 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142304
[email protected]d002dd02013-03-27 07:40:402305 this->VisitLayer(surface2, &occlusion);
2306 this->VisitContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142307
[email protected]a27cbde2013-03-23 22:01:492308 EXPECT_EQ(gfx::Rect().ToString(),
2309 occlusion.occlusion_from_outside_target().ToString());
2310 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(),
2311 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142312
[email protected]a27cbde2013-03-23 22:01:492313 // Clear any stored occlusion.
[email protected]d5467eb72014-08-22 01:16:432314 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2315 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
[email protected]94f206c12012-08-25 00:09:142316
[email protected]d002dd02013-03-27 07:40:402317 this->VisitLayer(surface, &occlusion);
2318 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142319
[email protected]a27cbde2013-03-23 22:01:492320 EXPECT_EQ(gfx::Rect().ToString(),
2321 occlusion.occlusion_from_outside_target().ToString());
2322 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(),
2323 occlusion.occlusion_from_inside_target().ToString());
2324 }
[email protected]94f206c12012-08-25 00:09:142325};
2326
[email protected]a27cbde2013-03-23 22:01:492327MAIN_AND_IMPL_THREAD_TEST(
2328 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:142329
[email protected]a27cbde2013-03-23 22:01:492330template <class Types>
[email protected]ca2902e92013-03-28 01:45:352331class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping
2332 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492333 protected:
[email protected]ca2902e92013-03-28 01:45:352334 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(
2335 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492336 : OcclusionTrackerTest<Types>(opaque_layers) {}
2337 void RunMyTest() {
2338 typename Types::ContentLayerType* parent = this->CreateRoot(
2339 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2340 parent->SetMasksToBounds(true);
2341 typename Types::ContentLayerType* surface =
2342 this->CreateDrawingSurface(parent,
2343 this->identity_matrix,
2344 gfx::PointF(),
2345 gfx::Size(500, 300),
2346 false);
2347 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
2348 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142349
[email protected]34ba1ffb2014-03-05 06:55:032350 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492351 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142352
[email protected]d002dd02013-03-27 07:40:402353 this->VisitLayer(surface, &occlusion);
2354 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142355
[email protected]a27cbde2013-03-23 22:01:492356 EXPECT_EQ(gfx::Rect().ToString(),
2357 occlusion.occlusion_from_outside_target().ToString());
2358 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(),
2359 occlusion.occlusion_from_inside_target().ToString());
2360 }
[email protected]94f206c12012-08-25 00:09:142361};
2362
[email protected]a27cbde2013-03-23 22:01:492363MAIN_AND_IMPL_THREAD_TEST(
2364 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:142365
[email protected]a27cbde2013-03-23 22:01:492366template <class Types>
[email protected]96baf3e2012-10-22 23:09:552367class OcclusionTrackerTestReplicaOccluded : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492368 protected:
[email protected]ca2902e92013-03-28 01:45:352369 explicit OcclusionTrackerTestReplicaOccluded(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492370 : OcclusionTrackerTest<Types>(opaque_layers) {}
2371 void RunMyTest() {
2372 typename Types::ContentLayerType* parent = this->CreateRoot(
2373 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2374 typename Types::LayerType* surface =
2375 this->CreateDrawingSurface(parent,
2376 this->identity_matrix,
2377 gfx::PointF(),
2378 gfx::Size(100, 100),
2379 true);
2380 this->CreateReplicaLayer(surface,
2381 this->identity_matrix,
2382 gfx::PointF(0.f, 100.f),
2383 gfx::Size(100, 100));
2384 typename Types::LayerType* topmost =
2385 this->CreateDrawingLayer(parent,
2386 this->identity_matrix,
2387 gfx::PointF(0.f, 100.f),
2388 gfx::Size(100, 100),
2389 true);
2390 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142391
[email protected]34ba1ffb2014-03-05 06:55:032392 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492393 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142394
[email protected]a27cbde2013-03-23 22:01:492395 // |topmost| occludes the replica, but not the surface itself.
[email protected]d002dd02013-03-27 07:40:402396 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142397
[email protected]a27cbde2013-03-23 22:01:492398 EXPECT_EQ(gfx::Rect().ToString(),
2399 occlusion.occlusion_from_outside_target().ToString());
2400 EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(),
2401 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142402
[email protected]d002dd02013-03-27 07:40:402403 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142404
[email protected]66b52e12013-11-17 15:53:182405 // Render target with replica ignores occlusion from outside.
2406 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:492407 occlusion.occlusion_from_outside_target().ToString());
2408 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2409 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142410
[email protected]e47b0a0a2013-11-18 23:26:222411 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142412
[email protected]a27cbde2013-03-23 22:01:492413 // Surface is not occluded so it shouldn't think it is.
[email protected]d5467eb72014-08-22 01:16:432414 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2415 occlusion.UnoccludedSurfaceContentRect(
2416 surface, false, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492417 }
[email protected]94f206c12012-08-25 00:09:142418};
2419
[email protected]96baf3e2012-10-22 23:09:552420ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaOccluded);
[email protected]94f206c12012-08-25 00:09:142421
[email protected]a27cbde2013-03-23 22:01:492422template <class Types>
[email protected]ca2902e92013-03-28 01:45:352423class OcclusionTrackerTestSurfaceWithReplicaUnoccluded
2424 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492425 protected:
[email protected]ca2902e92013-03-28 01:45:352426 explicit OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492427 : OcclusionTrackerTest<Types>(opaque_layers) {}
2428 void RunMyTest() {
2429 typename Types::ContentLayerType* parent = this->CreateRoot(
2430 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2431 typename Types::LayerType* surface =
2432 this->CreateDrawingSurface(parent,
2433 this->identity_matrix,
2434 gfx::PointF(),
2435 gfx::Size(100, 100),
2436 true);
2437 this->CreateReplicaLayer(surface,
2438 this->identity_matrix,
2439 gfx::PointF(0.f, 100.f),
2440 gfx::Size(100, 100));
2441 typename Types::LayerType* topmost =
2442 this->CreateDrawingLayer(parent,
2443 this->identity_matrix,
2444 gfx::PointF(),
2445 gfx::Size(100, 110),
2446 true);
2447 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142448
[email protected]34ba1ffb2014-03-05 06:55:032449 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492450 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142451
[email protected]a27cbde2013-03-23 22:01:492452 // |topmost| occludes the surface, but not the entire surface's replica.
[email protected]d002dd02013-03-27 07:40:402453 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142454
[email protected]a27cbde2013-03-23 22:01:492455 EXPECT_EQ(gfx::Rect().ToString(),
2456 occlusion.occlusion_from_outside_target().ToString());
2457 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(),
2458 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142459
[email protected]d002dd02013-03-27 07:40:402460 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142461
[email protected]66b52e12013-11-17 15:53:182462 // Render target with replica ignores occlusion from outside.
2463 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:492464 occlusion.occlusion_from_outside_target().ToString());
2465 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2466 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142467
[email protected]e47b0a0a2013-11-18 23:26:222468 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142469
[email protected]a27cbde2013-03-23 22:01:492470 // Surface is occluded, but only the top 10px of the replica.
[email protected]d5467eb72014-08-22 01:16:432471 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
2472 occlusion.UnoccludedSurfaceContentRect(
2473 surface, false, gfx::Rect(0, 0, 100, 100)));
2474 EXPECT_EQ(gfx::Rect(0, 10, 100, 90),
2475 occlusion.UnoccludedSurfaceContentRect(
2476 surface, true, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492477 }
[email protected]94f206c12012-08-25 00:09:142478};
2479
[email protected]96baf3e2012-10-22 23:09:552480ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded);
[email protected]94f206c12012-08-25 00:09:142481
[email protected]a27cbde2013-03-23 22:01:492482template <class Types>
[email protected]ca2902e92013-03-28 01:45:352483class OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently
2484 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492485 protected:
[email protected]ca2902e92013-03-28 01:45:352486 explicit OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently(
2487 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492488 : OcclusionTrackerTest<Types>(opaque_layers) {}
2489 void RunMyTest() {
2490 typename Types::ContentLayerType* parent = this->CreateRoot(
[email protected]d5467eb72014-08-22 01:16:432491 this->identity_matrix, gfx::PointF(), gfx::Size(200, 100));
[email protected]a27cbde2013-03-23 22:01:492492 typename Types::LayerType* surface =
2493 this->CreateDrawingSurface(parent,
2494 this->identity_matrix,
2495 gfx::PointF(),
2496 gfx::Size(100, 100),
2497 true);
2498 this->CreateReplicaLayer(surface,
2499 this->identity_matrix,
[email protected]d5467eb72014-08-22 01:16:432500 gfx::PointF(100.f, 0.f),
[email protected]a27cbde2013-03-23 22:01:492501 gfx::Size(100, 100));
[email protected]d5467eb72014-08-22 01:16:432502 typename Types::LayerType* over_surface =
2503 this->CreateDrawingLayer(parent,
2504 this->identity_matrix,
2505 gfx::PointF(60.f, 0.f),
2506 gfx::Size(40, 100),
2507 true);
[email protected]a27cbde2013-03-23 22:01:492508 typename Types::LayerType* over_replica =
2509 this->CreateDrawingLayer(parent,
2510 this->identity_matrix,
[email protected]d5467eb72014-08-22 01:16:432511 gfx::PointF(100.f, 0.f),
[email protected]a27cbde2013-03-23 22:01:492512 gfx::Size(50, 100),
2513 true);
2514 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142515
[email protected]34ba1ffb2014-03-05 06:55:032516 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492517 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142518
[email protected]a27cbde2013-03-23 22:01:492519 // These occlude the surface and replica differently, so we can test each
2520 // one.
[email protected]d002dd02013-03-27 07:40:402521 this->VisitLayer(over_replica, &occlusion);
2522 this->VisitLayer(over_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142523
[email protected]a27cbde2013-03-23 22:01:492524 EXPECT_EQ(gfx::Rect().ToString(),
2525 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432526 EXPECT_EQ(gfx::Rect(60, 0, 90, 100).ToString(),
[email protected]a27cbde2013-03-23 22:01:492527 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142528
[email protected]d002dd02013-03-27 07:40:402529 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142530
[email protected]66b52e12013-11-17 15:53:182531 // Render target with replica ignores occlusion from outside.
2532 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:492533 occlusion.occlusion_from_outside_target().ToString());
2534 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2535 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142536
[email protected]e47b0a0a2013-11-18 23:26:222537 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142538
[email protected]a27cbde2013-03-23 22:01:492539 // Surface and replica are occluded different amounts.
[email protected]d5467eb72014-08-22 01:16:432540 EXPECT_EQ(gfx::Rect(0, 0, 60, 100),
2541 occlusion.UnoccludedSurfaceContentRect(
2542 surface, false, gfx::Rect(0, 0, 100, 100)));
2543 EXPECT_EQ(gfx::Rect(50, 0, 50, 100),
2544 occlusion.UnoccludedSurfaceContentRect(
2545 surface, true, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492546 }
[email protected]94f206c12012-08-25 00:09:142547};
2548
[email protected]a27cbde2013-03-23 22:01:492549ALL_OCCLUSIONTRACKER_TEST(
2550 OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently);
[email protected]94f206c12012-08-25 00:09:142551
[email protected]a27cbde2013-03-23 22:01:492552template <class Types>
[email protected]ca2902e92013-03-28 01:45:352553class OcclusionTrackerTestSurfaceChildOfSurface
2554 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492555 protected:
[email protected]ca2902e92013-03-28 01:45:352556 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492557 : OcclusionTrackerTest<Types>(opaque_layers) {}
2558 void RunMyTest() {
2559 // This test verifies that the surface cliprect does not end up empty and
2560 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:142561
[email protected]a27cbde2013-03-23 22:01:492562 typename Types::ContentLayerType* parent = this->CreateRoot(
2563 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2564 typename Types::LayerType* surface =
2565 this->CreateDrawingSurface(parent,
2566 this->identity_matrix,
2567 gfx::PointF(),
2568 gfx::Size(100, 100),
2569 true);
2570 typename Types::LayerType* surface_child =
2571 this->CreateDrawingSurface(surface,
2572 this->identity_matrix,
2573 gfx::PointF(0.f, 10.f),
2574 gfx::Size(100, 50),
2575 true);
2576 typename Types::LayerType* topmost = this->CreateDrawingLayer(
2577 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
2578 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142579
[email protected]34ba1ffb2014-03-05 06:55:032580 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492581 gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142582
[email protected]a27cbde2013-03-23 22:01:492583 // |topmost| occludes everything partially so we know occlusion is happening
2584 // at all.
[email protected]d002dd02013-03-27 07:40:402585 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142586
[email protected]a27cbde2013-03-23 22:01:492587 EXPECT_EQ(gfx::Rect().ToString(),
2588 occlusion.occlusion_from_outside_target().ToString());
2589 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2590 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142591
[email protected]d002dd02013-03-27 07:40:402592 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:142593
[email protected]a27cbde2013-03-23 22:01:492594 // surface_child increases the occlusion in the screen by a narrow sliver.
2595 EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(),
2596 occlusion.occlusion_from_outside_target().ToString());
2597 // In its own surface, surface_child is at 0,0 as is its occlusion.
2598 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2599 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142600
[email protected]a27cbde2013-03-23 22:01:492601 // The root layer always has a clip rect. So the parent of |surface| has a
2602 // clip rect. However, the owning layer for |surface| does not mask to
2603 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
2604 // |surface_child| exercises different code paths as its parent does not
2605 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:142606
[email protected]e47b0a0a2013-11-18 23:26:222607 this->EnterContributingSurface(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492608 // The surface_child's parent does not have a clip rect as it owns a render
2609 // surface. Make sure the unoccluded rect does not get clipped away
2610 // inappropriately.
[email protected]d5467eb72014-08-22 01:16:432611 EXPECT_EQ(gfx::Rect(0, 40, 100, 10),
2612 occlusion.UnoccludedSurfaceContentRect(
2613 surface_child, false, gfx::Rect(0, 0, 100, 50)));
[email protected]d002dd02013-03-27 07:40:402614 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:142615
[email protected]a27cbde2013-03-23 22:01:492616 // When the surface_child's occlusion is transformed up to its parent, make
2617 // sure it is not clipped away inappropriately also.
[email protected]e47b0a0a2013-11-18 23:26:222618 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492619 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2620 occlusion.occlusion_from_outside_target().ToString());
2621 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(),
2622 occlusion.occlusion_from_inside_target().ToString());
[email protected]d002dd02013-03-27 07:40:402623 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142624
[email protected]e47b0a0a2013-11-18 23:26:222625 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492626 // The surface's parent does have a clip rect as it is the root layer.
[email protected]d5467eb72014-08-22 01:16:432627 EXPECT_EQ(gfx::Rect(0, 50, 100, 50),
2628 occlusion.UnoccludedSurfaceContentRect(
2629 surface, false, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492630 }
[email protected]94f206c12012-08-25 00:09:142631};
2632
[email protected]96baf3e2012-10-22 23:09:552633ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:142634
[email protected]a27cbde2013-03-23 22:01:492635template <class Types>
[email protected]ca2902e92013-03-28 01:45:352636class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter
2637 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492638 protected:
[email protected]ca2902e92013-03-28 01:45:352639 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:492640 bool opaque_layers)
2641 : OcclusionTrackerTest<Types>(opaque_layers) {}
2642 void RunMyTest() {
2643 gfx::Transform scale_by_half;
2644 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142645
[email protected]ae6b1a72013-06-25 18:49:292646 FilterOperations filters;
2647 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]94f206c12012-08-25 00:09:142648
[email protected]a27cbde2013-03-23 22:01:492649 // Save the distance of influence for the blur effect.
2650 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:292651 filters.GetOutsets(
2652 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:142653
[email protected]d5467eb72014-08-22 01:16:432654 enum Direction {
2655 LEFT,
2656 RIGHT,
2657 TOP,
2658 BOTTOM,
2659 LAST_DIRECTION = BOTTOM,
2660 };
[email protected]94f206c12012-08-25 00:09:142661
[email protected]d5467eb72014-08-22 01:16:432662 for (int i = 0; i <= LAST_DIRECTION; ++i) {
2663 SCOPED_TRACE(i);
[email protected]94f206c12012-08-25 00:09:142664
[email protected]d5467eb72014-08-22 01:16:432665 // Make a 50x50 filtered surface that is adjacent to occluding layers
2666 // which are above it in the z-order in various configurations. The
2667 // surface is scaled to test that the pixel moving is done in the target
2668 // space, where the background filter is applied.
2669 typename Types::ContentLayerType* parent = this->CreateRoot(
2670 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2671 typename Types::LayerType* filtered_surface =
2672 this->CreateDrawingLayer(parent,
2673 scale_by_half,
2674 gfx::PointF(50.f, 50.f),
2675 gfx::Size(100, 100),
2676 false);
2677 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142678
[email protected]d5467eb72014-08-22 01:16:432679 gfx::Rect occlusion_rect;
2680 switch (i) {
2681 case LEFT:
2682 occlusion_rect = gfx::Rect(0, 0, 50, 200);
2683 break;
2684 case RIGHT:
2685 occlusion_rect = gfx::Rect(100, 0, 50, 200);
2686 break;
2687 case TOP:
2688 occlusion_rect = gfx::Rect(0, 0, 200, 50);
2689 break;
2690 case BOTTOM:
2691 occlusion_rect = gfx::Rect(0, 100, 200, 50);
2692 break;
2693 }
[email protected]ac7c7f52012-11-08 06:26:502694
[email protected]d5467eb72014-08-22 01:16:432695 typename Types::LayerType* occluding_layer =
2696 this->CreateDrawingLayer(parent,
2697 this->identity_matrix,
2698 occlusion_rect.origin(),
2699 occlusion_rect.size(),
2700 true);
2701 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142702
[email protected]d5467eb72014-08-22 01:16:432703 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2704 gfx::Rect(0, 0, 200, 200));
[email protected]94f206c12012-08-25 00:09:142705
[email protected]d5467eb72014-08-22 01:16:432706 // This layer occludes pixels directly beside the filtered_surface.
2707 // Because filtered surface blends pixels in a radius, it will need to see
2708 // some of the pixels (up to radius far) underneath the occluding layers.
2709 this->VisitLayer(occluding_layer, &occlusion);
[email protected]ccb1c9a2012-12-17 03:53:192710
[email protected]d5467eb72014-08-22 01:16:432711 EXPECT_EQ(occlusion_rect.ToString(),
2712 occlusion.occlusion_from_inside_target().ToString());
2713 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142714
[email protected]d5467eb72014-08-22 01:16:432715 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142716
[email protected]d5467eb72014-08-22 01:16:432717 // The occlusion is used fully inside the surface.
2718 gfx::Rect occlusion_inside_surface =
2719 occlusion_rect - gfx::Vector2d(50, 50);
2720 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
2721 EXPECT_EQ(occlusion_inside_surface.ToString(),
2722 occlusion.occlusion_from_outside_target().ToString());
[email protected]ac7c7f52012-11-08 06:26:502723
[email protected]d5467eb72014-08-22 01:16:432724 // The surface has a background blur, so it needs pixels that are
2725 // currently considered occluded in order to be drawn. So the pixels it
2726 // needs should be removed some the occluded area so that when we get to
2727 // the parent they are drawn.
2728 this->VisitContributingSurface(filtered_surface, &occlusion);
2729 this->EnterLayer(parent, &occlusion);
[email protected]ac7c7f52012-11-08 06:26:502730
[email protected]d5467eb72014-08-22 01:16:432731 gfx::Rect expected_occlusion = occlusion_rect;
2732 switch (i) {
2733 case LEFT:
2734 expected_occlusion.Inset(0, 0, outset_right, 0);
2735 break;
2736 case RIGHT:
2737 expected_occlusion.Inset(outset_right, 0, 0, 0);
2738 break;
2739 case TOP:
2740 expected_occlusion.Inset(0, 0, 0, outset_right);
2741 break;
2742 case BOTTOM:
2743 expected_occlusion.Inset(0, outset_right, 0, 0);
2744 break;
2745 }
[email protected]94f206c12012-08-25 00:09:142746
[email protected]d5467eb72014-08-22 01:16:432747 EXPECT_EQ(expected_occlusion.ToString(),
2748 occlusion.occlusion_from_inside_target().ToString());
2749 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142750
[email protected]d5467eb72014-08-22 01:16:432751 this->DestroyLayers();
2752 }
[email protected]a27cbde2013-03-23 22:01:492753 }
[email protected]94f206c12012-08-25 00:09:142754};
2755
[email protected]a27cbde2013-03-23 22:01:492756ALL_OCCLUSIONTRACKER_TEST(
2757 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142758
[email protected]a27cbde2013-03-23 22:01:492759template <class Types>
[email protected]ca2902e92013-03-28 01:45:352760class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice
2761 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492762 protected:
[email protected]ca2902e92013-03-28 01:45:352763 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(
[email protected]a27cbde2013-03-23 22:01:492764 bool opaque_layers)
2765 : OcclusionTrackerTest<Types>(opaque_layers) {}
2766 void RunMyTest() {
2767 gfx::Transform scale_by_half;
2768 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142769
[email protected]a27cbde2013-03-23 22:01:492770 // Makes two surfaces that completely cover |parent|. The occlusion both
2771 // above and below the filters will be reduced by each of them.
2772 typename Types::ContentLayerType* root = this->CreateRoot(
2773 this->identity_matrix, gfx::PointF(), gfx::Size(75, 75));
2774 typename Types::LayerType* parent = this->CreateSurface(
2775 root, scale_by_half, gfx::PointF(), gfx::Size(150, 150));
2776 parent->SetMasksToBounds(true);
2777 typename Types::LayerType* filtered_surface1 = this->CreateDrawingLayer(
2778 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
2779 typename Types::LayerType* filtered_surface2 = this->CreateDrawingLayer(
2780 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
2781 typename Types::LayerType* occluding_layer_above =
2782 this->CreateDrawingLayer(parent,
2783 this->identity_matrix,
2784 gfx::PointF(100.f, 100.f),
2785 gfx::Size(50, 50),
2786 true);
[email protected]94f206c12012-08-25 00:09:142787
[email protected]a27cbde2013-03-23 22:01:492788 // Filters make the layers own surfaces.
[email protected]ae6b1a72013-06-25 18:49:292789 FilterOperations filters;
2790 filters.Append(FilterOperation::CreateBlurFilter(1.f));
[email protected]a27cbde2013-03-23 22:01:492791 filtered_surface1->SetBackgroundFilters(filters);
2792 filtered_surface2->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142793
[email protected]a27cbde2013-03-23 22:01:492794 // Save the distance of influence for the blur effect.
2795 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:292796 filters.GetOutsets(
2797 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:142798
[email protected]a27cbde2013-03-23 22:01:492799 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:142800
[email protected]34ba1ffb2014-03-05 06:55:032801 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492802 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142803
[email protected]d002dd02013-03-27 07:40:402804 this->VisitLayer(occluding_layer_above, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492805 EXPECT_EQ(gfx::Rect().ToString(),
2806 occlusion.occlusion_from_outside_target().ToString());
2807 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(),
2808 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142809
[email protected]d002dd02013-03-27 07:40:402810 this->VisitLayer(filtered_surface2, &occlusion);
2811 this->VisitContributingSurface(filtered_surface2, &occlusion);
2812 this->VisitLayer(filtered_surface1, &occlusion);
2813 this->VisitContributingSurface(filtered_surface1, &occlusion);
[email protected]94f206c12012-08-25 00:09:142814
[email protected]a27cbde2013-03-23 22:01:492815 // Test expectations in the target.
2816 gfx::Rect expected_occlusion =
2817 gfx::Rect(100 / 2 + outset_right * 2,
2818 100 / 2 + outset_bottom * 2,
2819 50 / 2 - (outset_left + outset_right) * 2,
2820 50 / 2 - (outset_top + outset_bottom) * 2);
2821 EXPECT_EQ(expected_occlusion.ToString(),
2822 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142823
[email protected]a27cbde2013-03-23 22:01:492824 // Test expectations in the screen are the same as in the target, as the
2825 // render surface is 1:1 with the screen.
2826 EXPECT_EQ(expected_occlusion.ToString(),
2827 occlusion.occlusion_from_outside_target().ToString());
2828 }
[email protected]94f206c12012-08-25 00:09:142829};
2830
[email protected]a27cbde2013-03-23 22:01:492831ALL_OCCLUSIONTRACKER_TEST(
2832 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:142833
[email protected]a27cbde2013-03-23 22:01:492834template <class Types>
[email protected]ca2902e92013-03-28 01:45:352835class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter
2836 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492837 protected:
[email protected]ca2902e92013-03-28 01:45:352838 explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:492839 bool opaque_layers)
2840 : OcclusionTrackerTest<Types>(opaque_layers) {}
2841 void RunMyTest() {
2842 gfx::Transform scale_by_half;
2843 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142844
[email protected]a27cbde2013-03-23 22:01:492845 // Make a surface and its replica, each 50x50, with a smaller 30x30 layer
2846 // centered below each. The surface is scaled to test that the pixel moving
2847 // is done in the target space, where the background filter is applied, but
2848 // the surface appears at 50, 50 and the replica at 200, 50.
2849 typename Types::ContentLayerType* parent = this->CreateRoot(
2850 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
2851 typename Types::LayerType* behind_surface_layer =
2852 this->CreateDrawingLayer(parent,
2853 this->identity_matrix,
2854 gfx::PointF(60.f, 60.f),
2855 gfx::Size(30, 30),
2856 true);
2857 typename Types::LayerType* behind_replica_layer =
2858 this->CreateDrawingLayer(parent,
2859 this->identity_matrix,
2860 gfx::PointF(210.f, 60.f),
2861 gfx::Size(30, 30),
2862 true);
2863 typename Types::LayerType* filtered_surface =
2864 this->CreateDrawingLayer(parent,
2865 scale_by_half,
2866 gfx::PointF(50.f, 50.f),
2867 gfx::Size(100, 100),
2868 false);
2869 this->CreateReplicaLayer(filtered_surface,
2870 this->identity_matrix,
2871 gfx::PointF(300.f, 0.f),
2872 gfx::Size());
[email protected]94f206c12012-08-25 00:09:142873
[email protected]a27cbde2013-03-23 22:01:492874 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:292875 FilterOperations filters;
2876 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:492877 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142878
[email protected]a27cbde2013-03-23 22:01:492879 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142880
[email protected]34ba1ffb2014-03-05 06:55:032881 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492882 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142883
[email protected]a27cbde2013-03-23 22:01:492884 // The surface has a background blur, so it blurs non-opaque pixels below
2885 // it.
[email protected]d002dd02013-03-27 07:40:402886 this->VisitLayer(filtered_surface, &occlusion);
2887 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142888
[email protected]d002dd02013-03-27 07:40:402889 this->VisitLayer(behind_replica_layer, &occlusion);
[email protected]d5467eb72014-08-22 01:16:432890
2891 // The layers behind the surface are not blurred, and their occlusion does
2892 // not change, until we leave the surface. So it should not be modified by
2893 // the filter here.
2894 gfx::Rect occlusion_behind_replica = gfx::Rect(210, 60, 30, 30);
2895 EXPECT_EQ(occlusion_behind_replica.ToString(),
2896 occlusion.occlusion_from_inside_target().ToString());
2897 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
2898
2899 // Clear the occlusion so the |behind_surface_layer| can add its occlusion
2900 // without existing occlusion interfering.
2901 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2902
[email protected]d002dd02013-03-27 07:40:402903 this->VisitLayer(behind_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:142904
[email protected]a27cbde2013-03-23 22:01:492905 // The layers behind the surface are not blurred, and their occlusion does
2906 // not change, until we leave the surface. So it should not be modified by
2907 // the filter here.
2908 gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30);
[email protected]d5467eb72014-08-22 01:16:432909 EXPECT_EQ(occlusion_behind_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:492910 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432911 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:492912 }
[email protected]94f206c12012-08-25 00:09:142913};
2914
[email protected]a27cbde2013-03-23 22:01:492915ALL_OCCLUSIONTRACKER_TEST(
2916 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142917
[email protected]a27cbde2013-03-23 22:01:492918template <class Types>
[email protected]ca2902e92013-03-28 01:45:352919class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded
2920 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492921 protected:
[email protected]ca2902e92013-03-28 01:45:352922 explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(
[email protected]a27cbde2013-03-23 22:01:492923 bool opaque_layers)
2924 : OcclusionTrackerTest<Types>(opaque_layers) {}
2925 void RunMyTest() {
2926 gfx::Transform scale_by_half;
2927 scale_by_half.Scale(0.5, 0.5);
2928
[email protected]66b52e12013-11-17 15:53:182929 // Make a 50x50 filtered surface that is completely occluded by an opaque
2930 // layer which is above it in the z-order. The surface is
[email protected]a27cbde2013-03-23 22:01:492931 // scaled to test that the pixel moving is done in the target space, where
[email protected]66b52e12013-11-17 15:53:182932 // the background filter is applied, but the surface appears at 50, 50.
[email protected]a27cbde2013-03-23 22:01:492933 typename Types::ContentLayerType* parent = this->CreateRoot(
[email protected]66b52e12013-11-17 15:53:182934 this->identity_matrix, gfx::PointF(), gfx::Size(200, 150));
[email protected]a27cbde2013-03-23 22:01:492935 typename Types::LayerType* filtered_surface =
2936 this->CreateDrawingLayer(parent,
2937 scale_by_half,
2938 gfx::PointF(50.f, 50.f),
2939 gfx::Size(100, 100),
2940 false);
[email protected]66b52e12013-11-17 15:53:182941 typename Types::LayerType* occluding_layer =
[email protected]a27cbde2013-03-23 22:01:492942 this->CreateDrawingLayer(parent,
2943 this->identity_matrix,
2944 gfx::PointF(50.f, 50.f),
2945 gfx::Size(50, 50),
2946 true);
[email protected]a27cbde2013-03-23 22:01:492947
2948 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:292949 FilterOperations filters;
2950 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:492951 filtered_surface->SetBackgroundFilters(filters);
2952
2953 this->CalcDrawEtc(parent);
2954
[email protected]34ba1ffb2014-03-05 06:55:032955 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492956 gfx::Rect(0, 0, 1000, 1000));
2957
[email protected]66b52e12013-11-17 15:53:182958 this->VisitLayer(occluding_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492959
[email protected]d002dd02013-03-27 07:40:402960 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142961 {
[email protected]a27cbde2013-03-23 22:01:492962 // The layers above the filtered surface occlude from outside.
2963 gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50);
[email protected]94f206c12012-08-25 00:09:142964
[email protected]a27cbde2013-03-23 22:01:492965 EXPECT_EQ(gfx::Rect().ToString(),
2966 occlusion.occlusion_from_inside_target().ToString());
[email protected]66b52e12013-11-17 15:53:182967 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:492968 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142969 }
[email protected]a27cbde2013-03-23 22:01:492970
2971 // The surface has a background blur, so it blurs non-opaque pixels below
2972 // it.
[email protected]d002dd02013-03-27 07:40:402973 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492974 {
2975 // The filter is completely occluded, so it should not blur anything and
2976 // reduce any occlusion.
2977 gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50);
[email protected]a27cbde2013-03-23 22:01:492978
[email protected]66b52e12013-11-17 15:53:182979 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:492980 occlusion.occlusion_from_inside_target().ToString());
2981 EXPECT_EQ(gfx::Rect().ToString(),
2982 occlusion.occlusion_from_outside_target().ToString());
2983 }
2984 }
[email protected]94f206c12012-08-25 00:09:142985};
2986
[email protected]a27cbde2013-03-23 22:01:492987ALL_OCCLUSIONTRACKER_TEST(
2988 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:142989
[email protected]a27cbde2013-03-23 22:01:492990template <class Types>
[email protected]ca2902e92013-03-28 01:45:352991class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded
2992 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492993 protected:
[email protected]ca2902e92013-03-28 01:45:352994 explicit
[email protected]a27cbde2013-03-23 22:01:492995 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded(
2996 bool opaque_layers)
2997 : OcclusionTrackerTest<Types>(opaque_layers) {}
2998 void RunMyTest() {
2999 gfx::Transform scale_by_half;
3000 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:143001
[email protected]a27cbde2013-03-23 22:01:493002 // Make a surface and its replica, each 50x50, that are partially occluded
3003 // by opaque layers which are above them in the z-order. The surface is
3004 // scaled to test that the pixel moving is done in the target space, where
3005 // the background filter is applied, but the surface appears at 50, 50 and
3006 // the replica at 200, 50.
3007 typename Types::ContentLayerType* parent = this->CreateRoot(
3008 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
3009 typename Types::LayerType* filtered_surface =
3010 this->CreateDrawingLayer(parent,
3011 scale_by_half,
3012 gfx::PointF(50.f, 50.f),
3013 gfx::Size(100, 100),
3014 false);
3015 this->CreateReplicaLayer(filtered_surface,
3016 this->identity_matrix,
3017 gfx::PointF(300.f, 0.f),
3018 gfx::Size());
3019 typename Types::LayerType* above_surface_layer =
3020 this->CreateDrawingLayer(parent,
3021 this->identity_matrix,
3022 gfx::PointF(70.f, 50.f),
3023 gfx::Size(30, 50),
3024 true);
3025 typename Types::LayerType* above_replica_layer =
3026 this->CreateDrawingLayer(parent,
3027 this->identity_matrix,
3028 gfx::PointF(200.f, 50.f),
3029 gfx::Size(30, 50),
3030 true);
3031 typename Types::LayerType* beside_surface_layer =
3032 this->CreateDrawingLayer(parent,
3033 this->identity_matrix,
3034 gfx::PointF(90.f, 40.f),
3035 gfx::Size(10, 10),
3036 true);
3037 typename Types::LayerType* beside_replica_layer =
3038 this->CreateDrawingLayer(parent,
3039 this->identity_matrix,
3040 gfx::PointF(200.f, 40.f),
3041 gfx::Size(10, 10),
3042 true);
[email protected]94f206c12012-08-25 00:09:143043
[email protected]a27cbde2013-03-23 22:01:493044 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:293045 FilterOperations filters;
3046 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:493047 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:143048
[email protected]a27cbde2013-03-23 22:01:493049 // Save the distance of influence for the blur effect.
3050 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:293051 filters.GetOutsets(
3052 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:143053
[email protected]a27cbde2013-03-23 22:01:493054 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143055
[email protected]34ba1ffb2014-03-05 06:55:033056 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:493057 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143058
[email protected]d002dd02013-03-27 07:40:403059 this->VisitLayer(beside_replica_layer, &occlusion);
3060 this->VisitLayer(beside_surface_layer, &occlusion);
3061 this->VisitLayer(above_replica_layer, &occlusion);
3062 this->VisitLayer(above_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:143063
[email protected]a27cbde2013-03-23 22:01:493064 // The surface has a background blur, so it blurs non-opaque pixels below
3065 // it.
[email protected]d002dd02013-03-27 07:40:403066 this->VisitLayer(filtered_surface, &occlusion);
3067 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143068
[email protected]a27cbde2013-03-23 22:01:493069 // The filter in the surface and replica are partially unoccluded. Only the
3070 // unoccluded parts should reduce occlusion. This means it will push back
[email protected]ed511b8d2013-03-25 03:29:293071 // the occlusion that touches the unoccluded part (occlusion_above___), but
[email protected]a27cbde2013-03-23 22:01:493072 // it will not touch occlusion_beside____ since that is not beside the
3073 // unoccluded part of the surface, even though it is beside the occluded
3074 // part of the surface.
3075 gfx::Rect occlusion_above_surface =
3076 gfx::Rect(70 + outset_right, 50, 30 - outset_right, 50);
3077 gfx::Rect occlusion_above_replica =
3078 gfx::Rect(200, 50, 30 - outset_left, 50);
3079 gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10);
3080 gfx::Rect occlusion_beside_replica = gfx::Rect(200, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:143081
[email protected]d5467eb72014-08-22 01:16:433082 SimpleEnclosedRegion expected_occlusion;
[email protected]a27cbde2013-03-23 22:01:493083 expected_occlusion.Union(occlusion_beside_replica);
[email protected]d5467eb72014-08-22 01:16:433084 expected_occlusion.Union(occlusion_beside_surface);
3085 expected_occlusion.Union(occlusion_above_replica);
3086 expected_occlusion.Union(occlusion_above_surface);
[email protected]94f206c12012-08-25 00:09:143087
[email protected]d5467eb72014-08-22 01:16:433088 EXPECT_EQ(expected_occlusion.ToString(),
[email protected]a27cbde2013-03-23 22:01:493089 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:433090 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:143091
[email protected]d5467eb72014-08-22 01:16:433092 const SimpleEnclosedRegion& actual_occlusion =
3093 occlusion.occlusion_from_inside_target();
3094 for (size_t i = 0; i < expected_occlusion.GetRegionComplexity(); ++i) {
3095 ASSERT_LT(i, actual_occlusion.GetRegionComplexity());
3096 EXPECT_EQ(expected_occlusion.GetRect(i), actual_occlusion.GetRect(i));
[email protected]94f206c12012-08-25 00:09:143097 }
[email protected]a27cbde2013-03-23 22:01:493098 }
[email protected]94f206c12012-08-25 00:09:143099};
3100
[email protected]a27cbde2013-03-23 22:01:493101ALL_OCCLUSIONTRACKER_TEST(
3102 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:143103
[email protected]a27cbde2013-03-23 22:01:493104template <class Types>
[email protected]ca2902e92013-03-28 01:45:353105class OcclusionTrackerTestMinimumTrackingSize
3106 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493107 protected:
[email protected]ca2902e92013-03-28 01:45:353108 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493109 : OcclusionTrackerTest<Types>(opaque_layers) {}
3110 void RunMyTest() {
3111 gfx::Size tracking_size(100, 100);
3112 gfx::Size below_tracking_size(99, 99);
[email protected]94f206c12012-08-25 00:09:143113
[email protected]a27cbde2013-03-23 22:01:493114 typename Types::ContentLayerType* parent = this->CreateRoot(
3115 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
3116 typename Types::LayerType* large = this->CreateDrawingLayer(
3117 parent, this->identity_matrix, gfx::PointF(), tracking_size, true);
3118 typename Types::LayerType* small =
3119 this->CreateDrawingLayer(parent,
3120 this->identity_matrix,
3121 gfx::PointF(),
3122 below_tracking_size,
3123 true);
3124 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143125
[email protected]34ba1ffb2014-03-05 06:55:033126 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:493127 gfx::Rect(0, 0, 1000, 1000));
3128 occlusion.set_minimum_tracking_size(tracking_size);
[email protected]94f206c12012-08-25 00:09:143129
[email protected]a27cbde2013-03-23 22:01:493130 // The small layer is not tracked because it is too small.
[email protected]d002dd02013-03-27 07:40:403131 this->VisitLayer(small, &occlusion);
[email protected]94f206c12012-08-25 00:09:143132
[email protected]a27cbde2013-03-23 22:01:493133 EXPECT_EQ(gfx::Rect().ToString(),
3134 occlusion.occlusion_from_outside_target().ToString());
3135 EXPECT_EQ(gfx::Rect().ToString(),
3136 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143137
[email protected]a27cbde2013-03-23 22:01:493138 // The large layer is tracked as it is large enough.
[email protected]d002dd02013-03-27 07:40:403139 this->VisitLayer(large, &occlusion);
[email protected]94f206c12012-08-25 00:09:143140
[email protected]a27cbde2013-03-23 22:01:493141 EXPECT_EQ(gfx::Rect().ToString(),
3142 occlusion.occlusion_from_outside_target().ToString());
[email protected]2c7c6702013-03-26 03:14:053143 EXPECT_EQ(gfx::Rect(tracking_size).ToString(),
[email protected]a27cbde2013-03-23 22:01:493144 occlusion.occlusion_from_inside_target().ToString());
3145 }
[email protected]94f206c12012-08-25 00:09:143146};
3147
[email protected]96baf3e2012-10-22 23:09:553148ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:143149
[email protected]a27cbde2013-03-23 22:01:493150template <class Types>
[email protected]1a5d9ce2013-04-30 01:31:093151class OcclusionTrackerTestScaledLayerIsClipped
3152 : public OcclusionTrackerTest<Types> {
3153 protected:
3154 explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers)
3155 : OcclusionTrackerTest<Types>(opaque_layers) {}
3156 void RunMyTest() {
3157 gfx::Transform scale_transform;
3158 scale_transform.Scale(512.0, 512.0);
3159
3160 typename Types::ContentLayerType* parent = this->CreateRoot(
3161 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
3162 typename Types::LayerType* clip = this->CreateLayer(parent,
3163 this->identity_matrix,
3164 gfx::PointF(10.f, 10.f),
3165 gfx::Size(50, 50));
3166 clip->SetMasksToBounds(true);
3167 typename Types::LayerType* scale = this->CreateLayer(
3168 clip, scale_transform, gfx::PointF(), gfx::Size(1, 1));
3169 typename Types::LayerType* scaled = this->CreateDrawingLayer(
3170 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
3171 this->CalcDrawEtc(parent);
3172
[email protected]34ba1ffb2014-03-05 06:55:033173 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]1a5d9ce2013-04-30 01:31:093174 gfx::Rect(0, 0, 1000, 1000));
3175
3176 this->VisitLayer(scaled, &occlusion);
3177
3178 EXPECT_EQ(gfx::Rect().ToString(),
3179 occlusion.occlusion_from_outside_target().ToString());
3180 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
3181 occlusion.occlusion_from_inside_target().ToString());
3182 }
3183};
3184
3185ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped)
3186
3187template <class Types>
3188class OcclusionTrackerTestScaledLayerInSurfaceIsClipped
3189 : public OcclusionTrackerTest<Types> {
3190 protected:
3191 explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers)
3192 : OcclusionTrackerTest<Types>(opaque_layers) {}
3193 void RunMyTest() {
3194 gfx::Transform scale_transform;
3195 scale_transform.Scale(512.0, 512.0);
3196
3197 typename Types::ContentLayerType* parent = this->CreateRoot(
3198 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
3199 typename Types::LayerType* clip = this->CreateLayer(parent,
3200 this->identity_matrix,
3201 gfx::PointF(10.f, 10.f),
3202 gfx::Size(50, 50));
3203 clip->SetMasksToBounds(true);
3204 typename Types::LayerType* surface = this->CreateDrawingSurface(
3205 clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false);
3206 typename Types::LayerType* scale = this->CreateLayer(
3207 surface, scale_transform, gfx::PointF(), gfx::Size(1, 1));
3208 typename Types::LayerType* scaled = this->CreateDrawingLayer(
3209 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
3210 this->CalcDrawEtc(parent);
3211
[email protected]34ba1ffb2014-03-05 06:55:033212 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]1a5d9ce2013-04-30 01:31:093213 gfx::Rect(0, 0, 1000, 1000));
3214
3215 this->VisitLayer(scaled, &occlusion);
3216 this->VisitLayer(surface, &occlusion);
3217 this->VisitContributingSurface(surface, &occlusion);
3218
3219 EXPECT_EQ(gfx::Rect().ToString(),
3220 occlusion.occlusion_from_outside_target().ToString());
3221 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
3222 occlusion.occlusion_from_inside_target().ToString());
3223 }
3224};
3225
3226ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped)
3227
[email protected]5b54b972013-07-26 13:25:423228template <class Types>
3229class OcclusionTrackerTestCopyRequestDoesOcclude
3230 : public OcclusionTrackerTest<Types> {
3231 protected:
3232 explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers)
3233 : OcclusionTrackerTest<Types>(opaque_layers) {}
3234 void RunMyTest() {
3235 typename Types::ContentLayerType* root = this->CreateRoot(
3236 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
3237 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
3238 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
3239 typename Types::LayerType* copy = this->CreateLayer(parent,
3240 this->identity_matrix,
3241 gfx::Point(100, 0),
3242 gfx::Size(200, 400));
3243 this->AddCopyRequest(copy);
3244 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
3245 copy,
3246 this->identity_matrix,
3247 gfx::PointF(),
3248 gfx::Size(200, 400),
3249 true);
3250 this->CalcDrawEtc(root);
3251
[email protected]34ba1ffb2014-03-05 06:55:033252 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]5b54b972013-07-26 13:25:423253 gfx::Rect(0, 0, 1000, 1000));
3254
3255 this->VisitLayer(copy_child, &occlusion);
3256 EXPECT_EQ(gfx::Rect().ToString(),
3257 occlusion.occlusion_from_outside_target().ToString());
3258 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
3259 occlusion.occlusion_from_inside_target().ToString());
3260
3261 // CopyRequests cause the layer to own a surface.
3262 this->VisitContributingSurface(copy, &occlusion);
3263
3264 // The occlusion from the copy should be kept.
3265 EXPECT_EQ(gfx::Rect().ToString(),
3266 occlusion.occlusion_from_outside_target().ToString());
3267 EXPECT_EQ(gfx::Rect(100, 0, 200, 400).ToString(),
3268 occlusion.occlusion_from_inside_target().ToString());
3269 }
3270};
3271
3272ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude)
3273
3274template <class Types>
3275class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude
3276 : public OcclusionTrackerTest<Types> {
3277 protected:
3278 explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude(
3279 bool opaque_layers)
3280 : OcclusionTrackerTest<Types>(opaque_layers) {}
3281 void RunMyTest() {
3282 typename Types::ContentLayerType* root = this->CreateRoot(
3283 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
3284 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
3285 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
3286 typename Types::LayerType* hide = this->CreateLayer(
3287 parent, this->identity_matrix, gfx::Point(), gfx::Size());
3288 typename Types::LayerType* copy = this->CreateLayer(
3289 hide, this->identity_matrix, gfx::Point(100, 0), gfx::Size(200, 400));
3290 this->AddCopyRequest(copy);
3291 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
3292 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
3293
3294 // The |copy| layer is hidden but since it is being copied, it will be
3295 // drawn.
3296 hide->SetHideLayerAndSubtree(true);
3297
3298 this->CalcDrawEtc(root);
3299
[email protected]34ba1ffb2014-03-05 06:55:033300 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]5b54b972013-07-26 13:25:423301 gfx::Rect(0, 0, 1000, 1000));
3302
3303 this->VisitLayer(copy_child, &occlusion);
3304 EXPECT_EQ(gfx::Rect().ToString(),
3305 occlusion.occlusion_from_outside_target().ToString());
3306 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
3307 occlusion.occlusion_from_inside_target().ToString());
3308
3309 // CopyRequests cause the layer to own a surface.
3310 this->VisitContributingSurface(copy, &occlusion);
3311
3312 // The occlusion from the copy should be dropped since it is hidden.
3313 EXPECT_EQ(gfx::Rect().ToString(),
3314 occlusion.occlusion_from_outside_target().ToString());
3315 EXPECT_EQ(gfx::Rect().ToString(),
3316 occlusion.occlusion_from_inside_target().ToString());
3317 }
3318};
3319
3320ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude)
3321
[email protected]d5467eb72014-08-22 01:16:433322template <class Types>
3323class OcclusionTrackerTestOccludedLayer : public OcclusionTrackerTest<Types> {
3324 protected:
3325 explicit OcclusionTrackerTestOccludedLayer(bool opaque_layers)
3326 : OcclusionTrackerTest<Types>(opaque_layers) {}
3327 void RunMyTest() {
3328 gfx::Transform translate;
3329 translate.Translate(10.0, 20.0);
3330 typename Types::ContentLayerType* root = this->CreateRoot(
3331 this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
3332 typename Types::LayerType* surface = this->CreateSurface(
3333 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
3334 typename Types::LayerType* layer = this->CreateDrawingLayer(
3335 surface, translate, gfx::Point(), gfx::Size(200, 200), false);
3336 typename Types::ContentLayerType* outside_layer = this->CreateDrawingLayer(
3337 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), false);
3338 this->CalcDrawEtc(root);
3339
3340 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
3341 gfx::Rect(0, 0, 200, 200));
3342 this->VisitLayer(outside_layer, &occlusion);
3343 this->EnterLayer(layer, &occlusion);
3344
3345 // No occlusion, is not occluded.
3346 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
3347 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
3348 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100)));
3349
3350 // Partial occlusion from outside, is not occluded.
3351 occlusion.set_occlusion_from_outside_target(
3352 SimpleEnclosedRegion(50, 50, 100, 100));
3353 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
3354 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
3355 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
3356 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
3357 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
3358 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
3359 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
3360 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
3361 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
3362
3363 // Full occlusion from outside, is occluded.
3364 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
3365 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
3366 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
3367 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
3368
3369 // Partial occlusion from inside, is not occluded.
3370 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
3371 occlusion.set_occlusion_from_inside_target(
3372 SimpleEnclosedRegion(50, 50, 100, 100));
3373 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
3374 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
3375 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
3376 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
3377 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
3378 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
3379 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
3380 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
3381
3382 // Full occlusion from inside, is occluded.
3383 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
3384 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
3385 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
3386 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
3387
3388 // Partial occlusion from both, is not occluded.
3389 occlusion.set_occlusion_from_outside_target(
3390 SimpleEnclosedRegion(50, 50, 100, 50));
3391 occlusion.set_occlusion_from_inside_target(
3392 SimpleEnclosedRegion(50, 100, 100, 50));
3393 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
3394 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
3395 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
3396 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
3397 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
3398 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
3399 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
3400 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
3401
3402 // Full occlusion from both, is occluded.
3403 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
3404 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
3405 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
3406 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
3407 }
3408};
3409
3410ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOccludedLayer)
3411
[email protected]ba565742012-11-10 09:29:483412} // namespace
3413} // namespace cc