blob: 847d60c04d9feb742718f39ea83b6c598457b933 [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
dcheng716bedf2014-10-21 09:51:0836 SimpleEnclosedRegion VisibleContentOpaqueRegion() const override {
[email protected]d5467eb72014-08-22 01:16:4337 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:
dcheng716bedf2014-10-21 09:51:0849 ~TestContentLayer() override {}
[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
dcheng716bedf2014-10-21 09:51:0862 SimpleEnclosedRegion VisibleContentOpaqueRegion() const override {
[email protected]d5467eb72014-08-22 01:16:4363 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));
vmpstr01a5bf352014-09-17 22:57:3188 return this->GetCurrentOcclusionForLayer(layer->draw_transform())
89 .IsOccluded(content_rect);
[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
vmpstr5b88d992014-09-18 23:25:0493 // layer. Simple wrapper around GetUnoccludedContentRect.
[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));
vmpstr5b88d992014-09-18 23:25:0497 return this->GetCurrentOcclusionForLayer(layer->draw_transform())
98 .GetUnoccludedContentRect(content_rect);
[email protected]a27cbde2013-03-23 22:01:4999 }
[email protected]e312aca2014-03-20 22:11:55100
101 gfx::Rect UnoccludedSurfaceContentRect(const LayerType* layer,
[email protected]e312aca2014-03-20 22:11:55102 const gfx::Rect& content_rect) const {
103 typename LayerType::RenderSurfaceType* surface = layer->render_surface();
danakj206a5812015-02-11 02:07:08104 return this->GetCurrentOcclusionForContributingSurface(
105 surface->draw_transform())
106 .GetUnoccludedContentRect(content_rect);
[email protected]e312aca2014-03-20 22:11:55107 }
[email protected]94f206c12012-08-25 00:09:14108};
109
[email protected]96baf3e2012-10-22 23:09:55110struct OcclusionTrackerTestMainThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49111 typedef Layer LayerType;
[email protected]d600df7d2013-08-03 02:34:28112 typedef FakeLayerTreeHost HostType;
[email protected]a27cbde2013-03-23 22:01:49113 typedef RenderSurface RenderSurfaceType;
114 typedef TestContentLayer ContentLayerType;
115 typedef scoped_refptr<Layer> LayerPtrType;
116 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
[email protected]ba1b33e2014-02-28 16:44:51117 typedef LayerIterator<Layer> TestLayerIterator;
[email protected]34ba1ffb2014-03-05 06:55:03118 typedef OcclusionTracker<Layer> OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14119
[email protected]a27cbde2013-03-23 22:01:49120 static LayerPtrType CreateLayer(HostType* host) { return Layer::Create(); }
121 static ContentLayerPtrType CreateContentLayer(HostType* host) {
122 return make_scoped_refptr(new ContentLayerType());
123 }
[email protected]e0bd43a2012-10-12 16:54:21124
danakjf446a072014-09-27 21:55:48125 template <typename T>
126 static LayerPtrType PassLayerPtr(T* layer) {
[email protected]a27cbde2013-03-23 22:01:49127 LayerPtrType ref(*layer);
128 *layer = NULL;
129 return ref;
130 }
awoloszyne83f28c2014-12-22 15:40:00131 static void SetForceRenderSurface(LayerType* layer, bool force) {
132 layer->SetForceRenderSurface(force);
133 }
[email protected]d58499a2012-10-09 22:27:47134
[email protected]a27cbde2013-03-23 22:01:49135 static void DestroyLayer(LayerPtrType* layer) { *layer = NULL; }
[email protected]ad63b2f2014-08-11 17:39:54136
137 static void RecursiveUpdateNumChildren(LayerType* layerType) {}
[email protected]94f206c12012-08-25 00:09:14138};
139
[email protected]96baf3e2012-10-22 23:09:55140struct OcclusionTrackerTestImplThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49141 typedef LayerImpl LayerType;
142 typedef LayerTreeImpl HostType;
143 typedef RenderSurfaceImpl RenderSurfaceType;
144 typedef TestContentLayerImpl ContentLayerType;
145 typedef scoped_ptr<LayerImpl> LayerPtrType;
146 typedef scoped_ptr<ContentLayerType> ContentLayerPtrType;
[email protected]ba1b33e2014-02-28 16:44:51147 typedef LayerIterator<LayerImpl> TestLayerIterator;
[email protected]34ba1ffb2014-03-05 06:55:03148 typedef OcclusionTracker<LayerImpl> OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14149
[email protected]a27cbde2013-03-23 22:01:49150 static LayerPtrType CreateLayer(HostType* host) {
151 return LayerImpl::Create(host, next_layer_impl_id++);
152 }
153 static ContentLayerPtrType CreateContentLayer(HostType* host) {
154 return make_scoped_ptr(new ContentLayerType(host, next_layer_impl_id++));
155 }
156 static int next_layer_impl_id;
[email protected]d58499a2012-10-09 22:27:47157
danakjf446a072014-09-27 21:55:48158 template <typename T>
159 static LayerPtrType PassLayerPtr(T* layer) {
[email protected]a27cbde2013-03-23 22:01:49160 return layer->Pass();
161 }
[email protected]e0bd43a2012-10-12 16:54:21162
awoloszyne83f28c2014-12-22 15:40:00163 static void SetForceRenderSurface(LayerType* layer, bool force) {
164 layer->SetHasRenderSurface(force);
165 }
[email protected]a27cbde2013-03-23 22:01:49166 static void DestroyLayer(LayerPtrType* layer) { layer->reset(); }
[email protected]ad63b2f2014-08-11 17:39:54167
168 static void RecursiveUpdateNumChildren(LayerType* layer) {
169 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(layer);
170 }
[email protected]94f206c12012-08-25 00:09:14171};
172
[email protected]a27cbde2013-03-23 22:01:49173int OcclusionTrackerTestImplThreadTypes::next_layer_impl_id = 1;
[email protected]94f206c12012-08-25 00:09:14174
[email protected]a27cbde2013-03-23 22:01:49175template <typename Types> class OcclusionTrackerTest : public testing::Test {
176 protected:
[email protected]ca2902e92013-03-28 01:45:35177 explicit OcclusionTrackerTest(bool opaque_layers)
enne2097cab2014-09-25 20:16:31178 : opaque_layers_(opaque_layers),
179 client_(FakeLayerTreeHostClient::DIRECT_3D),
180 host_(FakeLayerTreeHost::Create(&client_)) {}
[email protected]a27cbde2013-03-23 22:01:49181
182 virtual void RunMyTest() = 0;
183
danakjaeb95062014-11-14 01:35:36184 void TearDown() override { DestroyLayers(); }
[email protected]a27cbde2013-03-23 22:01:49185
186 typename Types::HostType* GetHost();
187
188 typename Types::ContentLayerType* CreateRoot(const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47189 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26190 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49191 typename Types::ContentLayerPtrType layer(
192 Types::CreateContentLayer(GetHost()));
193 typename Types::ContentLayerType* layer_ptr = layer.get();
194 SetProperties(layer_ptr, transform, position, bounds);
195
[email protected]22898ed2013-06-01 04:52:30196 DCHECK(!root_.get());
[email protected]a27cbde2013-03-23 22:01:49197 root_ = Types::PassLayerPtr(&layer);
[email protected]d600df7d2013-08-03 02:34:28198
awoloszyne83f28c2014-12-22 15:40:00199 Types::SetForceRenderSurface(layer_ptr, true);
[email protected]d600df7d2013-08-03 02:34:28200 SetRootLayerOnMainThread(layer_ptr);
201
[email protected]a27cbde2013-03-23 22:01:49202 return layer_ptr;
203 }
204
205 typename Types::LayerType* CreateLayer(typename Types::LayerType* parent,
206 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47207 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26208 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49209 typename Types::LayerPtrType layer(Types::CreateLayer(GetHost()));
210 typename Types::LayerType* layer_ptr = layer.get();
211 SetProperties(layer_ptr, transform, position, bounds);
212 parent->AddChild(Types::PassLayerPtr(&layer));
213 return layer_ptr;
214 }
215
216 typename Types::LayerType* CreateSurface(typename Types::LayerType* parent,
217 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47218 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26219 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49220 typename Types::LayerType* layer =
221 CreateLayer(parent, transform, position, bounds);
awoloszyne83f28c2014-12-22 15:40:00222 Types::SetForceRenderSurface(layer, true);
[email protected]a27cbde2013-03-23 22:01:49223 return layer;
224 }
225
226 typename Types::ContentLayerType* CreateDrawingLayer(
227 typename Types::LayerType* parent,
228 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47229 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26230 const gfx::Size& bounds,
[email protected]a27cbde2013-03-23 22:01:49231 bool opaque) {
232 typename Types::ContentLayerPtrType layer(
233 Types::CreateContentLayer(GetHost()));
234 typename Types::ContentLayerType* layer_ptr = layer.get();
235 SetProperties(layer_ptr, transform, position, bounds);
236
237 if (opaque_layers_) {
238 layer_ptr->SetContentsOpaque(opaque);
239 } else {
240 layer_ptr->SetContentsOpaque(false);
241 if (opaque)
[email protected]2c7c6702013-03-26 03:14:05242 layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds));
[email protected]a27cbde2013-03-23 22:01:49243 else
244 layer_ptr->SetOpaqueContentsRect(gfx::Rect());
[email protected]586d51ed2012-12-07 20:31:45245 }
[email protected]94f206c12012-08-25 00:09:14246
[email protected]a27cbde2013-03-23 22:01:49247 parent->AddChild(Types::PassLayerPtr(&layer));
248 return layer_ptr;
249 }
[email protected]94f206c12012-08-25 00:09:14250
[email protected]a27cbde2013-03-23 22:01:49251 typename Types::LayerType* CreateReplicaLayer(
252 typename Types::LayerType* owning_layer,
253 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47254 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26255 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49256 typename Types::ContentLayerPtrType layer(
257 Types::CreateContentLayer(GetHost()));
258 typename Types::ContentLayerType* layer_ptr = layer.get();
259 SetProperties(layer_ptr, transform, position, bounds);
260 SetReplica(owning_layer, Types::PassLayerPtr(&layer));
261 return layer_ptr;
262 }
[email protected]94f206c12012-08-25 00:09:14263
[email protected]a27cbde2013-03-23 22:01:49264 typename Types::LayerType* CreateMaskLayer(
265 typename Types::LayerType* owning_layer,
[email protected]64348ea2014-01-29 22:58:26266 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49267 typename Types::ContentLayerPtrType layer(
268 Types::CreateContentLayer(GetHost()));
269 typename Types::ContentLayerType* layer_ptr = layer.get();
270 SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds);
271 SetMask(owning_layer, Types::PassLayerPtr(&layer));
272 return layer_ptr;
273 }
[email protected]586d51ed2012-12-07 20:31:45274
[email protected]a27cbde2013-03-23 22:01:49275 typename Types::ContentLayerType* CreateDrawingSurface(
276 typename Types::LayerType* parent,
277 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47278 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26279 const gfx::Size& bounds,
[email protected]a27cbde2013-03-23 22:01:49280 bool opaque) {
281 typename Types::ContentLayerType* layer =
282 CreateDrawingLayer(parent, transform, position, bounds, opaque);
awoloszyne83f28c2014-12-22 15:40:00283 Types::SetForceRenderSurface(layer, true);
[email protected]a27cbde2013-03-23 22:01:49284 return layer;
285 }
[email protected]94f206c12012-08-25 00:09:14286
[email protected]d5467eb72014-08-22 01:16:43287 void DestroyLayers() {
288 Types::DestroyLayer(&root_);
danakjf446a072014-09-27 21:55:48289 render_surface_layer_list_ = nullptr;
[email protected]d5467eb72014-08-22 01:16:43290 render_surface_layer_list_impl_.clear();
291 replica_layers_.clear();
292 mask_layers_.clear();
293 ResetLayerIterator();
294 }
[email protected]5b54b972013-07-26 13:25:42295
296 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
297
298 void AddCopyRequest(Layer* layer) {
299 layer->RequestCopyOfOutput(
300 CopyOutputRequest::CreateBitmapRequest(base::Bind(
301 &OcclusionTrackerTest<Types>::CopyOutputCallback,
302 base::Unretained(this))));
303 }
304
305 void AddCopyRequest(LayerImpl* layer) {
306 ScopedPtrVector<CopyOutputRequest> requests;
307 requests.push_back(
308 CopyOutputRequest::CreateBitmapRequest(base::Bind(
309 &OcclusionTrackerTest<Types>::CopyOutputCallback,
310 base::Unretained(this))));
awoloszyne83f28c2014-12-22 15:40:00311 layer->SetHasRenderSurface(true);
[email protected]5b54b972013-07-26 13:25:42312 layer->PassCopyRequests(&requests);
313 }
314
[email protected]a27cbde2013-03-23 22:01:49315 void CalcDrawEtc(TestContentLayerImpl* root) {
316 DCHECK(root == root_.get());
[email protected]94f206c12012-08-25 00:09:14317
[email protected]ad63b2f2014-08-11 17:39:54318 Types::RecursiveUpdateNumChildren(root);
[email protected]7aad55f2013-07-26 11:25:53319 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:22320 root, root->bounds(), &render_surface_layer_list_impl_);
[email protected]7aad55f2013-07-26 11:25:53321 inputs.can_adjust_raster_scales = true;
322 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14323
[email protected]a27cbde2013-03-23 22:01:49324 layer_iterator_ = layer_iterator_begin_ =
325 Types::TestLayerIterator::Begin(&render_surface_layer_list_impl_);
326 }
[email protected]94f206c12012-08-25 00:09:14327
[email protected]a27cbde2013-03-23 22:01:49328 void CalcDrawEtc(TestContentLayer* root) {
329 DCHECK(root == root_.get());
[email protected]a27cbde2013-03-23 22:01:49330 DCHECK(!root->render_surface());
[email protected]94f206c12012-08-25 00:09:14331
[email protected]989386c2013-07-18 21:37:23332 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
[email protected]7aad55f2013-07-26 11:25:53333 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:22334 root, root->bounds(), render_surface_layer_list_.get());
[email protected]7aad55f2013-07-26 11:25:53335 inputs.can_adjust_raster_scales = true;
336 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14337
[email protected]a27cbde2013-03-23 22:01:49338 layer_iterator_ = layer_iterator_begin_ =
[email protected]989386c2013-07-18 21:37:23339 Types::TestLayerIterator::Begin(render_surface_layer_list_.get());
[email protected]a27cbde2013-03-23 22:01:49340 }
[email protected]94f206c12012-08-25 00:09:14341
[email protected]a27cbde2013-03-23 22:01:49342 void EnterLayer(typename Types::LayerType* layer,
[email protected]e47b0a0a2013-11-18 23:26:22343 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43344 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49345 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]e47b0a0a2013-11-18 23:26:22346 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49347 }
[email protected]94f206c12012-08-25 00:09:14348
[email protected]a27cbde2013-03-23 22:01:49349 void LeaveLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40350 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43351 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49352 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]d002dd02013-03-27 07:40:40353 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49354 ++layer_iterator_;
355 }
[email protected]94f206c12012-08-25 00:09:14356
[email protected]a27cbde2013-03-23 22:01:49357 void VisitLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40358 typename Types::OcclusionTrackerType* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22359 EnterLayer(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49360 LeaveLayer(layer, occlusion);
361 }
[email protected]94f206c12012-08-25 00:09:14362
[email protected]a27cbde2013-03-23 22:01:49363 void EnterContributingSurface(
364 typename Types::LayerType* layer,
[email protected]e47b0a0a2013-11-18 23:26:22365 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43366 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49367 ASSERT_TRUE(layer_iterator_.represents_target_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22368 occlusion->EnterLayer(layer_iterator_);
[email protected]d002dd02013-03-27 07:40:40369 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49370 ++layer_iterator_;
371 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22372 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49373 }
[email protected]94f206c12012-08-25 00:09:14374
[email protected]a27cbde2013-03-23 22:01:49375 void LeaveContributingSurface(
376 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40377 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43378 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49379 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]d002dd02013-03-27 07:40:40380 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49381 ++layer_iterator_;
382 }
[email protected]94f206c12012-08-25 00:09:14383
[email protected]a27cbde2013-03-23 22:01:49384 void VisitContributingSurface(
385 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40386 typename Types::OcclusionTrackerType* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22387 EnterContributingSurface(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49388 LeaveContributingSurface(layer, occlusion);
389 }
[email protected]94f206c12012-08-25 00:09:14390
[email protected]a27cbde2013-03-23 22:01:49391 void ResetLayerIterator() { layer_iterator_ = layer_iterator_begin_; }
[email protected]94f206c12012-08-25 00:09:14392
[email protected]a27cbde2013-03-23 22:01:49393 const gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:14394
[email protected]a27cbde2013-03-23 22:01:49395 private:
[email protected]d600df7d2013-08-03 02:34:28396 void SetRootLayerOnMainThread(Layer* root) {
397 host_->SetRootLayer(scoped_refptr<Layer>(root));
398 }
399
400 void SetRootLayerOnMainThread(LayerImpl* root) {}
401
[email protected]a27cbde2013-03-23 22:01:49402 void SetBaseProperties(typename Types::LayerType* layer,
403 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47404 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26405 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49406 layer->SetTransform(transform);
[email protected]a27cbde2013-03-23 22:01:49407 layer->SetPosition(position);
408 layer->SetBounds(bounds);
409 }
[email protected]94f206c12012-08-25 00:09:14410
[email protected]a27cbde2013-03-23 22:01:49411 void SetProperties(Layer* layer,
412 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47413 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26414 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49415 SetBaseProperties(layer, transform, position, bounds);
416 }
[email protected]94f206c12012-08-25 00:09:14417
[email protected]a27cbde2013-03-23 22:01:49418 void SetProperties(LayerImpl* layer,
419 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47420 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26421 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49422 SetBaseProperties(layer, transform, position, bounds);
[email protected]94f206c12012-08-25 00:09:14423
bokancccfde72014-10-08 15:15:22424 layer->SetContentBounds(layer->bounds());
[email protected]a27cbde2013-03-23 22:01:49425 }
[email protected]94f206c12012-08-25 00:09:14426
[email protected]a27cbde2013-03-23 22:01:49427 void SetReplica(Layer* owning_layer, scoped_refptr<Layer> layer) {
428 owning_layer->SetReplicaLayer(layer.get());
429 replica_layers_.push_back(layer);
430 }
[email protected]94f206c12012-08-25 00:09:14431
[email protected]a27cbde2013-03-23 22:01:49432 void SetReplica(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
433 owning_layer->SetReplicaLayer(layer.Pass());
434 }
[email protected]94f206c12012-08-25 00:09:14435
[email protected]a27cbde2013-03-23 22:01:49436 void SetMask(Layer* owning_layer, scoped_refptr<Layer> layer) {
437 owning_layer->SetMaskLayer(layer.get());
438 mask_layers_.push_back(layer);
439 }
[email protected]94f206c12012-08-25 00:09:14440
[email protected]a27cbde2013-03-23 22:01:49441 void SetMask(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
442 owning_layer->SetMaskLayer(layer.Pass());
443 }
[email protected]94f206c12012-08-25 00:09:14444
[email protected]a27cbde2013-03-23 22:01:49445 bool opaque_layers_;
enne2097cab2014-09-25 20:16:31446 FakeLayerTreeHostClient client_;
[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
dmichaelc78b0932014-12-17 23:39:47528 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49529 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]a27cbde2013-03-23 22:01:49552 }
[email protected]94f206c12012-08-25 00:09:14553};
554
[email protected]96baf3e2012-10-22 23:09:55555ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14556
[email protected]a27cbde2013-03-23 22:01:49557template <class Types>
[email protected]96baf3e2012-10-22 23:09:55558class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49559 protected:
[email protected]ca2902e92013-03-28 01:45:35560 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49561 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47562 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49563 gfx::Transform layer_transform;
564 layer_transform.Translate(250.0, 250.0);
565 layer_transform.Rotate(90.0);
566 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14567
[email protected]a27cbde2013-03-23 22:01:49568 typename Types::ContentLayerType* root = this->CreateRoot(
569 this->identity_matrix, gfx::Point(0, 0), gfx::Size(200, 200));
570 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
571 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
572 typename Types::ContentLayerType* layer =
573 this->CreateDrawingLayer(parent,
574 layer_transform,
575 gfx::PointF(30.f, 30.f),
576 gfx::Size(500, 500),
577 true);
578 parent->SetMasksToBounds(true);
579 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14580
[email protected]34ba1ffb2014-03-05 06:55:03581 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49582 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14583
[email protected]d002dd02013-03-27 07:40:40584 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22585 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14586
[email protected]a27cbde2013-03-23 22:01:49587 EXPECT_EQ(gfx::Rect().ToString(),
588 occlusion.occlusion_from_outside_target().ToString());
589 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
590 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49591 }
[email protected]94f206c12012-08-25 00:09:14592};
593
[email protected]96baf3e2012-10-22 23:09:55594ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14595
[email protected]a27cbde2013-03-23 22:01:49596template <class Types>
[email protected]96baf3e2012-10-22 23:09:55597class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49598 protected:
[email protected]ca2902e92013-03-28 01:45:35599 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49600 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47601 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49602 gfx::Transform layer_transform;
603 layer_transform.Translate(20.0, 20.0);
[email protected]94f206c12012-08-25 00:09:14604
[email protected]a27cbde2013-03-23 22:01:49605 typename Types::ContentLayerType* root = this->CreateRoot(
606 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
607 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
608 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
609 typename Types::ContentLayerType* layer =
610 this->CreateDrawingLayer(parent,
611 layer_transform,
612 gfx::PointF(30.f, 30.f),
613 gfx::Size(500, 500),
614 true);
615 parent->SetMasksToBounds(true);
616 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14617
[email protected]34ba1ffb2014-03-05 06:55:03618 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49619 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14620
[email protected]d002dd02013-03-27 07:40:40621 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22622 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14623
[email protected]a27cbde2013-03-23 22:01:49624 EXPECT_EQ(gfx::Rect().ToString(),
625 occlusion.occlusion_from_outside_target().ToString());
626 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
627 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49628 }
[email protected]94f206c12012-08-25 00:09:14629};
630
[email protected]96baf3e2012-10-22 23:09:55631ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14632
[email protected]a27cbde2013-03-23 22:01:49633template <class Types>
[email protected]ca2902e92013-03-28 01:45:35634class OcclusionTrackerTestChildInRotatedChild
635 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49636 protected:
[email protected]ca2902e92013-03-28 01:45:35637 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49638 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47639 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49640 gfx::Transform child_transform;
641 child_transform.Translate(250.0, 250.0);
642 child_transform.Rotate(90.0);
643 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14644
[email protected]a27cbde2013-03-23 22:01:49645 typename Types::ContentLayerType* parent = this->CreateRoot(
646 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
647 parent->SetMasksToBounds(true);
[email protected]3a9a92d2013-07-11 04:37:00648 typename Types::LayerType* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49649 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
650 child->SetMasksToBounds(true);
651 typename Types::ContentLayerType* layer =
652 this->CreateDrawingLayer(child,
653 this->identity_matrix,
654 gfx::PointF(10.f, 10.f),
655 gfx::Size(500, 500),
656 true);
657 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14658
[email protected]34ba1ffb2014-03-05 06:55:03659 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49660 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14661
[email protected]d002dd02013-03-27 07:40:40662 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22663 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14664
[email protected]a27cbde2013-03-23 22:01:49665 EXPECT_EQ(gfx::Rect().ToString(),
666 occlusion.occlusion_from_outside_target().ToString());
667 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
668 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14669
[email protected]d002dd02013-03-27 07:40:40670 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22671 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14672
[email protected]a27cbde2013-03-23 22:01:49673 EXPECT_EQ(gfx::Rect().ToString(),
674 occlusion.occlusion_from_outside_target().ToString());
675 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
676 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14677
[email protected]a27cbde2013-03-23 22:01:49678 /* Justification for the above occlusion from |layer|:
679 100
680 +---------------------+
681 | |
682 | 30 | rotate(90)
683 | 30 + ---------------------------------+
684 100 | | 10 | | ==>
685 | |10+---------------------------------+
686 | | | | | |
687 | | | | | |
688 | | | | | |
689 +----|--|-------------+ | |
690 | | | |
691 | | | |
692 | | | |500
693 | | | |
694 | | | |
695 | | | |
696 | | | |
697 +--|-------------------------------+ |
698 | |
699 +---------------------------------+
700 500
701
702 +---------------------+
703 | |30 Visible region of |layer|: /////
704 | |
705 | +---------------------------------+
706 100| | |10 |
707 | +---------------------------------+ |
708 | | |///////////////| 420 | |
709 | | |///////////////|60 | |
710 | | |///////////////| | |
711 +--|--|---------------+ | |
712 20|10| 70 | |
713 | | | |
714 | | | |
715 | | | |
716 | | | |
717 | | | |
718 | | |10|
719 | +------------------------------|--+
720 | 490 |
721 +---------------------------------+
722 500
723
724 */
725 }
[email protected]94f206c12012-08-25 00:09:14726};
727
[email protected]96baf3e2012-10-22 23:09:55728ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14729
[email protected]a27cbde2013-03-23 22:01:49730template <class Types>
[email protected]ca2902e92013-03-28 01:45:35731class OcclusionTrackerTestScaledRenderSurface
732 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49733 protected:
[email protected]ca2902e92013-03-28 01:45:35734 explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49735 : OcclusionTrackerTest<Types>(opaque_layers) {}
[email protected]710ffc02012-10-30 21:42:02736
dmichaelc78b0932014-12-17 23:39:47737 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49738 typename Types::ContentLayerType* parent = this->CreateRoot(
739 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02740
[email protected]a27cbde2013-03-23 22:01:49741 gfx::Transform layer1_matrix;
742 layer1_matrix.Scale(2.0, 2.0);
743 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
744 parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true);
awoloszyne83f28c2014-12-22 15:40:00745 Types::SetForceRenderSurface(layer1, true);
[email protected]710ffc02012-10-30 21:42:02746
[email protected]a27cbde2013-03-23 22:01:49747 gfx::Transform layer2_matrix;
748 layer2_matrix.Translate(25.0, 25.0);
749 typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
750 layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true);
751 typename Types::ContentLayerType* occluder =
752 this->CreateDrawingLayer(parent,
753 this->identity_matrix,
754 gfx::PointF(100.f, 100.f),
755 gfx::Size(500, 500),
756 true);
757 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02758
[email protected]34ba1ffb2014-03-05 06:55:03759 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49760 gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02761
[email protected]d002dd02013-03-27 07:40:40762 this->VisitLayer(occluder, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22763 this->EnterLayer(layer2, &occlusion);
[email protected]710ffc02012-10-30 21:42:02764
[email protected]a27cbde2013-03-23 22:01:49765 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
766 occlusion.occlusion_from_outside_target().ToString());
767 EXPECT_EQ(gfx::Rect().ToString(),
768 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49769 }
[email protected]710ffc02012-10-30 21:42:02770};
771
772ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
773
[email protected]a27cbde2013-03-23 22:01:49774template <class Types>
[email protected]ca2902e92013-03-28 01:45:35775class OcclusionTrackerTestVisitTargetTwoTimes
776 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49777 protected:
[email protected]ca2902e92013-03-28 01:45:35778 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49779 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47780 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49781 typename Types::ContentLayerType* root = this->CreateRoot(
782 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]d5467eb72014-08-22 01:16:43783 typename Types::LayerType* surface = this->CreateSurface(
784 root, this->identity_matrix, gfx::PointF(30.f, 30.f), gfx::Size());
785 typename Types::ContentLayerType* surface_child =
786 this->CreateDrawingLayer(surface,
[email protected]a27cbde2013-03-23 22:01:49787 this->identity_matrix,
788 gfx::PointF(10.f, 10.f),
[email protected]d5467eb72014-08-22 01:16:43789 gfx::Size(50, 50),
[email protected]a27cbde2013-03-23 22:01:49790 true);
[email protected]d5467eb72014-08-22 01:16:43791 // |top_layer| makes |root|'s surface get considered by OcclusionTracker
792 // first, instead of |surface|'s. This exercises different code in
793 // LeaveToRenderTarget, as the target surface has already been seen when
794 // leaving |surface| later.
795 typename Types::ContentLayerType* top_layer =
796 this->CreateDrawingLayer(root,
[email protected]a27cbde2013-03-23 22:01:49797 this->identity_matrix,
[email protected]d5467eb72014-08-22 01:16:43798 gfx::PointF(40.f, 90.f),
799 gfx::Size(50, 20),
[email protected]a27cbde2013-03-23 22:01:49800 true);
801 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14802
[email protected]34ba1ffb2014-03-05 06:55:03803 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49804 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14805
[email protected]d5467eb72014-08-22 01:16:43806 this->VisitLayer(top_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14807
[email protected]a27cbde2013-03-23 22:01:49808 EXPECT_EQ(gfx::Rect().ToString(),
809 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43810 EXPECT_EQ(gfx::Rect(40, 90, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49811 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14812
[email protected]d5467eb72014-08-22 01:16:43813 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14814
[email protected]d5467eb72014-08-22 01:16:43815 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49816 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43817 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49818 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14819
[email protected]d5467eb72014-08-22 01:16:43820 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:14821
[email protected]d5467eb72014-08-22 01:16:43822 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49823 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43824 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49825 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14826
[email protected]d5467eb72014-08-22 01:16:43827 // Occlusion from |top_layer| already in the root target should get merged
828 // with the occlusion from the |surface| we are leaving now.
829 this->LeaveContributingSurface(surface, &occlusion);
830 this->EnterLayer(root, &occlusion);
[email protected]94f206c12012-08-25 00:09:14831
[email protected]d5467eb72014-08-22 01:16:43832 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
833 EXPECT_EQ(gfx::Rect(40, 40, 50, 70).ToString(),
[email protected]a27cbde2013-03-23 22:01:49834 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49835 }
[email protected]94f206c12012-08-25 00:09:14836};
837
[email protected]96baf3e2012-10-22 23:09:55838ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:14839
[email protected]a27cbde2013-03-23 22:01:49840template <class Types>
[email protected]ca2902e92013-03-28 01:45:35841class OcclusionTrackerTestSurfaceRotatedOffAxis
842 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49843 protected:
[email protected]ca2902e92013-03-28 01:45:35844 explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49845 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47846 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49847 gfx::Transform child_transform;
848 child_transform.Translate(250.0, 250.0);
849 child_transform.Rotate(95.0);
850 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14851
[email protected]a27cbde2013-03-23 22:01:49852 gfx::Transform layer_transform;
853 layer_transform.Translate(10.0, 10.0);
[email protected]94f206c12012-08-25 00:09:14854
[email protected]a27cbde2013-03-23 22:01:49855 typename Types::ContentLayerType* root = this->CreateRoot(
856 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
857 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
858 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
awoloszyne83f28c2014-12-22 15:40:00859 typename Types::LayerType* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49860 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
[email protected]a27cbde2013-03-23 22:01:49861 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
862 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true);
863 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14864
[email protected]34ba1ffb2014-03-05 06:55:03865 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49866 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14867
[email protected]8a822692014-02-12 17:30:55868 gfx::Rect clipped_layer_in_child = MathUtil::MapEnclosingClippedRect(
[email protected]a27cbde2013-03-23 22:01:49869 layer_transform, layer->visible_content_rect());
[email protected]94f206c12012-08-25 00:09:14870
[email protected]d002dd02013-03-27 07:40:40871 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22872 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14873
[email protected]a27cbde2013-03-23 22:01:49874 EXPECT_EQ(gfx::Rect().ToString(),
875 occlusion.occlusion_from_outside_target().ToString());
876 EXPECT_EQ(clipped_layer_in_child.ToString(),
877 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14878
[email protected]d002dd02013-03-27 07:40:40879 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22880 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14881
[email protected]a27cbde2013-03-23 22:01:49882 EXPECT_EQ(gfx::Rect().ToString(),
883 occlusion.occlusion_from_outside_target().ToString());
884 EXPECT_EQ(gfx::Rect().ToString(),
885 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49886 }
[email protected]94f206c12012-08-25 00:09:14887};
888
[email protected]96baf3e2012-10-22 23:09:55889ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:14890
[email protected]a27cbde2013-03-23 22:01:49891template <class Types>
[email protected]ca2902e92013-03-28 01:45:35892class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
893 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49894 protected:
[email protected]ca2902e92013-03-28 01:45:35895 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49896 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47897 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49898 gfx::Transform child_transform;
899 child_transform.Translate(250.0, 250.0);
900 child_transform.Rotate(90.0);
901 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14902
[email protected]a27cbde2013-03-23 22:01:49903 typename Types::ContentLayerType* root = this->CreateRoot(
904 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
905 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
906 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
907 parent->SetMasksToBounds(true);
908 typename Types::ContentLayerType* child =
[email protected]3a9a92d2013-07-11 04:37:00909 this->CreateDrawingSurface(parent,
[email protected]a27cbde2013-03-23 22:01:49910 child_transform,
911 gfx::PointF(30.f, 30.f),
912 gfx::Size(500, 500),
913 false);
914 child->SetMasksToBounds(true);
915 typename Types::ContentLayerType* layer1 =
916 this->CreateDrawingLayer(child,
917 this->identity_matrix,
918 gfx::PointF(10.f, 10.f),
919 gfx::Size(500, 500),
920 true);
921 typename Types::ContentLayerType* layer2 =
922 this->CreateDrawingLayer(child,
923 this->identity_matrix,
924 gfx::PointF(10.f, 450.f),
925 gfx::Size(500, 60),
926 true);
927 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14928
[email protected]34ba1ffb2014-03-05 06:55:03929 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49930 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14931
[email protected]d002dd02013-03-27 07:40:40932 this->VisitLayer(layer2, &occlusion);
933 this->VisitLayer(layer1, &occlusion);
934 this->VisitLayer(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22935 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14936
[email protected]a27cbde2013-03-23 22:01:49937 EXPECT_EQ(gfx::Rect().ToString(),
938 occlusion.occlusion_from_outside_target().ToString());
939 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
940 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14941
[email protected]d002dd02013-03-27 07:40:40942 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22943 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14944
[email protected]a27cbde2013-03-23 22:01:49945 EXPECT_EQ(gfx::Rect().ToString(),
946 occlusion.occlusion_from_outside_target().ToString());
947 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
948 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14949
[email protected]a27cbde2013-03-23 22:01:49950 /* Justification for the above occlusion from |layer1| and |layer2|:
[email protected]94f206c12012-08-25 00:09:14951
952 +---------------------+
953 | |30 Visible region of |layer1|: /////
954 | | Visible region of |layer2|: \\\\\
955 | +---------------------------------+
956 | | |10 |
957 | +---------------+-----------------+ |
958 | | |\\\\\\\\\\\\|//| 420 | |
959 | | |\\\\\\\\\\\\|//|60 | |
960 | | |\\\\\\\\\\\\|//| | |
961 +--|--|------------|--+ | |
962 20|10| 70 | | |
963 | | | | |
964 | | | | |
965 | | | | |
966 | | | | |
967 | | | | |
968 | | | |10|
969 | +------------|-----------------|--+
970 | | 490 |
971 +---------------+-----------------+
972 60 440
973 */
[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(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[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 OcclusionTrackerTestOverlappingSurfaceSiblings
981 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49982 protected:
[email protected]ca2902e92013-03-28 01:45:35983 explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49984 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47985 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49986 typename Types::ContentLayerType* parent = this->CreateRoot(
987 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
988 parent->SetMasksToBounds(true);
989 typename Types::LayerType* child1 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43990 parent, this->identity_matrix, gfx::PointF(10.f, 0.f), gfx::Size());
[email protected]a27cbde2013-03-23 22:01:49991 typename Types::LayerType* child2 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43992 parent, this->identity_matrix, gfx::PointF(30.f, 0.f), gfx::Size());
993 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
994 child1, this->identity_matrix, gfx::PointF(), gfx::Size(40, 50), true);
[email protected]a27cbde2013-03-23 22:01:49995 typename Types::ContentLayerType* layer2 =
996 this->CreateDrawingLayer(child2,
997 this->identity_matrix,
[email protected]d5467eb72014-08-22 01:16:43998 gfx::PointF(10.f, 0.f),
999 gfx::Size(40, 50),
[email protected]a27cbde2013-03-23 22:01:491000 true);
1001 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141002
[email protected]34ba1ffb2014-03-05 06:55:031003 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491004 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141005
[email protected]d002dd02013-03-27 07:40:401006 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221007 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141008
[email protected]d5467eb72014-08-22 01:16:431009 // layer2's occlusion.
[email protected]a27cbde2013-03-23 22:01:491010 EXPECT_EQ(gfx::Rect().ToString(),
1011 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431012 EXPECT_EQ(gfx::Rect(10, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491013 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141014
[email protected]d002dd02013-03-27 07:40:401015 this->LeaveContributingSurface(child2, &occlusion);
1016 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221017 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141018
[email protected]d5467eb72014-08-22 01:16:431019 // layer2's occlusion in the target space of layer1.
1020 EXPECT_EQ(gfx::Rect(30, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491021 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431022 // layer1's occlusion.
1023 EXPECT_EQ(gfx::Rect(0, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491024 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141025
[email protected]d002dd02013-03-27 07:40:401026 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221027 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141028
[email protected]d5467eb72014-08-22 01:16:431029 // The occlusion from from layer1 and layer2 is merged.
1030 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1031 EXPECT_EQ(gfx::Rect(10, 0, 70, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491032 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491033 }
[email protected]94f206c12012-08-25 00:09:141034};
1035
[email protected]96baf3e2012-10-22 23:09:551036ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:141037
[email protected]a27cbde2013-03-23 22:01:491038template <class Types>
[email protected]ca2902e92013-03-28 01:45:351039class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms
1040 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491041 protected:
[email protected]ca2902e92013-03-28 01:45:351042 explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(
[email protected]a27cbde2013-03-23 22:01:491043 bool opaque_layers)
1044 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471045 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491046 gfx::Transform child1_transform;
1047 child1_transform.Translate(250.0, 250.0);
1048 child1_transform.Rotate(-90.0);
1049 child1_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141050
[email protected]a27cbde2013-03-23 22:01:491051 gfx::Transform child2_transform;
1052 child2_transform.Translate(250.0, 250.0);
1053 child2_transform.Rotate(90.0);
1054 child2_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141055
[email protected]a27cbde2013-03-23 22:01:491056 typename Types::ContentLayerType* parent = this->CreateRoot(
1057 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1058 parent->SetMasksToBounds(true);
1059 typename Types::LayerType* child1 = this->CreateSurface(
1060 parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10));
1061 typename Types::LayerType* child2 =
1062 this->CreateDrawingSurface(parent,
1063 child2_transform,
1064 gfx::PointF(20.f, 40.f),
1065 gfx::Size(10, 10),
1066 false);
1067 typename Types::ContentLayerType* layer1 =
1068 this->CreateDrawingLayer(child1,
1069 this->identity_matrix,
1070 gfx::PointF(-10.f, -20.f),
1071 gfx::Size(510, 510),
1072 true);
1073 typename Types::ContentLayerType* layer2 =
1074 this->CreateDrawingLayer(child2,
1075 this->identity_matrix,
1076 gfx::PointF(-10.f, -10.f),
1077 gfx::Size(510, 510),
1078 true);
1079 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141080
[email protected]34ba1ffb2014-03-05 06:55:031081 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491082 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141083
[email protected]d002dd02013-03-27 07:40:401084 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221085 this->EnterLayer(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141086
[email protected]a27cbde2013-03-23 22:01:491087 EXPECT_EQ(gfx::Rect().ToString(),
1088 occlusion.occlusion_from_outside_target().ToString());
1089 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1090 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141091
[email protected]d002dd02013-03-27 07:40:401092 this->LeaveLayer(child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221093 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141094
danakjf080b5b2014-08-23 22:18:201095 EXPECT_EQ(gfx::Rect().ToString(),
1096 occlusion.occlusion_from_outside_target().ToString());
1097 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1098 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141099
[email protected]d002dd02013-03-27 07:40:401100 this->LeaveContributingSurface(child2, &occlusion);
1101 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221102 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141103
[email protected]a27cbde2013-03-23 22:01:491104 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
1105 occlusion.occlusion_from_outside_target().ToString());
1106 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
1107 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141108
[email protected]d002dd02013-03-27 07:40:401109 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221110 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141111
[email protected]a27cbde2013-03-23 22:01:491112 EXPECT_EQ(gfx::Rect().ToString(),
1113 occlusion.occlusion_from_outside_target().ToString());
1114 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(),
1115 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141116
[email protected]a27cbde2013-03-23 22:01:491117 /* Justification for the above occlusion:
1118 100
1119 +---------------------+
1120 |20 | layer1
1121 10+----------------------------------+
1122 100 || 30 | layer2 |
1123 |20+----------------------------------+
1124 || | | | |
1125 || | | | |
1126 || | | | |
1127 +|-|------------------+ | |
1128 | | | | 510
1129 | | 510 | |
1130 | | | |
1131 | | | |
1132 | | | |
1133 | | | |
1134 | | 520 | |
1135 +----------------------------------+ |
1136 | |
1137 +----------------------------------+
1138 510
1139 */
1140 }
[email protected]94f206c12012-08-25 00:09:141141};
1142
[email protected]a27cbde2013-03-23 22:01:491143ALL_OCCLUSIONTRACKER_TEST(
1144 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:141145
[email protected]a27cbde2013-03-23 22:01:491146template <class Types>
[email protected]96baf3e2012-10-22 23:09:551147class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491148 protected:
[email protected]ca2902e92013-03-28 01:45:351149 explicit OcclusionTrackerTestFilters(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491150 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471151 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491152 gfx::Transform layer_transform;
1153 layer_transform.Translate(250.0, 250.0);
1154 layer_transform.Rotate(90.0);
1155 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141156
[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::ContentLayerType* blur_layer =
1161 this->CreateDrawingLayer(parent,
1162 layer_transform,
1163 gfx::PointF(30.f, 30.f),
1164 gfx::Size(500, 500),
1165 true);
1166 typename Types::ContentLayerType* opaque_layer =
1167 this->CreateDrawingLayer(parent,
1168 layer_transform,
1169 gfx::PointF(30.f, 30.f),
1170 gfx::Size(500, 500),
1171 true);
1172 typename Types::ContentLayerType* opacity_layer =
1173 this->CreateDrawingLayer(parent,
1174 layer_transform,
1175 gfx::PointF(30.f, 30.f),
1176 gfx::Size(500, 500),
1177 true);
[email protected]94f206c12012-08-25 00:09:141178
awoloszyne83f28c2014-12-22 15:40:001179 Types::SetForceRenderSurface(blur_layer, true);
[email protected]ae6b1a72013-06-25 18:49:291180 FilterOperations filters;
1181 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]a27cbde2013-03-23 22:01:491182 blur_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141183
awoloszyne83f28c2014-12-22 15:40:001184 Types::SetForceRenderSurface(opaque_layer, true);
[email protected]ae6b1a72013-06-25 18:49:291185 filters.Clear();
1186 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491187 opaque_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141188
awoloszyne83f28c2014-12-22 15:40:001189 Types::SetForceRenderSurface(opacity_layer, true);
[email protected]ae6b1a72013-06-25 18:49:291190 filters.Clear();
1191 filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491192 opacity_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141193
[email protected]a27cbde2013-03-23 22:01:491194 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141195
[email protected]34ba1ffb2014-03-05 06:55:031196 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491197 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141198
[email protected]a27cbde2013-03-23 22:01:491199 // Opacity layer won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401200 this->VisitLayer(opacity_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221201 this->EnterContributingSurface(opacity_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141202
[email protected]a27cbde2013-03-23 22:01:491203 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1204 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141205
[email protected]a27cbde2013-03-23 22:01:491206 // And has nothing to contribute to its parent surface.
[email protected]d002dd02013-03-27 07:40:401207 this->LeaveContributingSurface(opacity_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491208 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1209 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141210
[email protected]a27cbde2013-03-23 22:01:491211 // Opaque layer will contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401212 this->VisitLayer(opaque_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221213 this->EnterContributingSurface(opaque_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141214
[email protected]a27cbde2013-03-23 22:01:491215 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1216 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(),
1217 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141218
[email protected]a27cbde2013-03-23 22:01:491219 // And it gets translated to the parent surface.
[email protected]d002dd02013-03-27 07:40:401220 this->LeaveContributingSurface(opaque_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491221 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1222 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1223 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141224
[email protected]a27cbde2013-03-23 22:01:491225 // The blur layer needs to throw away any occlusion from outside its
1226 // subtree.
[email protected]e47b0a0a2013-11-18 23:26:221227 this->EnterLayer(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491228 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1229 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141230
[email protected]a27cbde2013-03-23 22:01:491231 // And it won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401232 this->LeaveLayer(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221233 this->EnterContributingSurface(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491234 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1235 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141236
[email protected]a27cbde2013-03-23 22:01:491237 // But the opaque layer's occlusion is preserved on the parent.
[email protected]d002dd02013-03-27 07:40:401238 this->LeaveContributingSurface(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221239 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491240 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1241 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1242 occlusion.occlusion_from_inside_target().ToString());
1243 }
[email protected]94f206c12012-08-25 00:09:141244};
1245
[email protected]96baf3e2012-10-22 23:09:551246ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:141247
[email protected]a27cbde2013-03-23 22:01:491248template <class Types>
[email protected]ca2902e92013-03-28 01:45:351249class OcclusionTrackerTestReplicaDoesOcclude
1250 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491251 protected:
[email protected]ca2902e92013-03-28 01:45:351252 explicit OcclusionTrackerTestReplicaDoesOcclude(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491253 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471254 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491255 typename Types::ContentLayerType* parent = this->CreateRoot(
1256 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
[email protected]d5467eb72014-08-22 01:16:431257 typename Types::LayerType* surface = this->CreateDrawingSurface(
1258 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), true);
[email protected]a27cbde2013-03-23 22:01:491259 this->CreateReplicaLayer(
[email protected]d5467eb72014-08-22 01:16:431260 surface, this->identity_matrix, gfx::PointF(0.f, 50.f), gfx::Size());
[email protected]a27cbde2013-03-23 22:01:491261 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141262
[email protected]34ba1ffb2014-03-05 06:55:031263 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491264 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141265
[email protected]d002dd02013-03-27 07:40:401266 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141267
[email protected]a27cbde2013-03-23 22:01:491268 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1269 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141270
[email protected]d002dd02013-03-27 07:40:401271 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221272 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141273
[email protected]a27cbde2013-03-23 22:01:491274 // The surface and replica should both be occluding the parent.
[email protected]d5467eb72014-08-22 01:16:431275 EXPECT_EQ(gfx::Rect(50, 100).ToString(),
1276 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491277 }
[email protected]94f206c12012-08-25 00:09:141278};
1279
[email protected]96baf3e2012-10-22 23:09:551280ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude);
[email protected]94f206c12012-08-25 00:09:141281
[email protected]a27cbde2013-03-23 22:01:491282template <class Types>
[email protected]ca2902e92013-03-28 01:45:351283class OcclusionTrackerTestReplicaWithClipping
1284 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491285 protected:
[email protected]ca2902e92013-03-28 01:45:351286 explicit OcclusionTrackerTestReplicaWithClipping(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491287 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471288 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491289 typename Types::ContentLayerType* parent = this->CreateRoot(
1290 this->identity_matrix, gfx::PointF(), gfx::Size(100, 170));
1291 parent->SetMasksToBounds(true);
1292 typename Types::LayerType* surface =
1293 this->CreateDrawingSurface(parent,
1294 this->identity_matrix,
1295 gfx::PointF(0.f, 100.f),
1296 gfx::Size(50, 50),
1297 true);
1298 this->CreateReplicaLayer(
[email protected]d5467eb72014-08-22 01:16:431299 surface, this->identity_matrix, gfx::PointF(0.f, 50.f), gfx::Size());
[email protected]a27cbde2013-03-23 22:01:491300 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141301
[email protected]34ba1ffb2014-03-05 06:55:031302 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491303 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141304
[email protected]d002dd02013-03-27 07:40:401305 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141306
[email protected]d5467eb72014-08-22 01:16:431307 // The surface layer's occlusion in its own space.
[email protected]a27cbde2013-03-23 22:01:491308 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1309 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431310 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141311
[email protected]d002dd02013-03-27 07:40:401312 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221313 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141314
[email protected]d5467eb72014-08-22 01:16:431315 // The surface and replica should both be occluding the parent, the
1316 // replica's occlusion is clipped by the parent.
1317 EXPECT_EQ(gfx::Rect(0, 100, 50, 70).ToString(),
1318 occlusion.occlusion_from_inside_target().ToString());
1319 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491320 }
[email protected]94f206c12012-08-25 00:09:141321};
1322
[email protected]96baf3e2012-10-22 23:09:551323ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping);
[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 OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491327 protected:
[email protected]ca2902e92013-03-28 01:45:351328 explicit OcclusionTrackerTestReplicaWithMask(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491329 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471330 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491331 typename Types::ContentLayerType* parent = this->CreateRoot(
1332 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
1333 typename Types::LayerType* surface =
1334 this->CreateDrawingSurface(parent,
1335 this->identity_matrix,
1336 gfx::PointF(0.f, 100.f),
1337 gfx::Size(50, 50),
1338 true);
1339 typename Types::LayerType* replica = this->CreateReplicaLayer(
1340 surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
1341 this->CreateMaskLayer(replica, gfx::Size(10, 10));
1342 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141343
[email protected]34ba1ffb2014-03-05 06:55:031344 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491345 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141346
[email protected]d002dd02013-03-27 07:40:401347 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141348
[email protected]a27cbde2013-03-23 22:01:491349 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1350 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141351
[email protected]d002dd02013-03-27 07:40:401352 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221353 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141354
[email protected]a27cbde2013-03-23 22:01:491355 // The replica should not be occluding the parent, since it has a mask
1356 // applied to it.
1357 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(),
1358 occlusion.occlusion_from_inside_target().ToString());
1359 }
[email protected]94f206c12012-08-25 00:09:141360};
1361
[email protected]96baf3e2012-10-22 23:09:551362ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask);
[email protected]94f206c12012-08-25 00:09:141363
[email protected]a27cbde2013-03-23 22:01:491364template <class Types>
[email protected]ca2902e92013-03-28 01:45:351365class OcclusionTrackerTestOpaqueContentsRegionEmpty
1366 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491367 protected:
[email protected]ca2902e92013-03-28 01:45:351368 explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491369 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471370 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491371 typename Types::ContentLayerType* parent = this->CreateRoot(
1372 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1373 typename Types::ContentLayerType* layer =
1374 this->CreateDrawingSurface(parent,
1375 this->identity_matrix,
1376 gfx::PointF(),
1377 gfx::Size(200, 200),
1378 false);
1379 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141380
[email protected]34ba1ffb2014-03-05 06:55:031381 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491382 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:221383 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141384
[email protected]d5467eb72014-08-22 01:16:431385 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1386 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141387
[email protected]d002dd02013-03-27 07:40:401388 this->LeaveLayer(layer, &occlusion);
1389 this->VisitContributingSurface(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221390 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141391
[email protected]a27cbde2013-03-23 22:01:491392 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]d5467eb72014-08-22 01:16:431393 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491394 }
[email protected]94f206c12012-08-25 00:09:141395};
1396
[email protected]96baf3e2012-10-22 23:09:551397MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141398
[email protected]a27cbde2013-03-23 22:01:491399template <class Types>
[email protected]ca2902e92013-03-28 01:45:351400class OcclusionTrackerTestOpaqueContentsRegionNonEmpty
1401 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491402 protected:
[email protected]ca2902e92013-03-28 01:45:351403 explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491404 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471405 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491406 typename Types::ContentLayerType* parent = this->CreateRoot(
1407 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1408 typename Types::ContentLayerType* layer =
1409 this->CreateDrawingLayer(parent,
1410 this->identity_matrix,
1411 gfx::PointF(100.f, 100.f),
1412 gfx::Size(200, 200),
1413 false);
1414 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141415 {
[email protected]34ba1ffb2014-03-05 06:55:031416 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491417 gfx::Rect(0, 0, 1000, 1000));
1418 layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:141419
[email protected]a27cbde2013-03-23 22:01:491420 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401421 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221422 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141423
[email protected]a27cbde2013-03-23 22:01:491424 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
1425 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141426 }
[email protected]a27cbde2013-03-23 22:01:491427 {
[email protected]34ba1ffb2014-03-05 06:55:031428 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491429 gfx::Rect(0, 0, 1000, 1000));
1430 layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
1431
1432 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401433 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221434 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491435
1436 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(),
1437 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491438 }
1439 {
[email protected]34ba1ffb2014-03-05 06:55:031440 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491441 gfx::Rect(0, 0, 1000, 1000));
1442 layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
1443
1444 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401445 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221446 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491447
1448 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
1449 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491450 }
1451 }
[email protected]94f206c12012-08-25 00:09:141452};
1453
[email protected]96baf3e2012-10-22 23:09:551454MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141455
[email protected]a27cbde2013-03-23 22:01:491456template <class Types>
[email protected]ca2902e92013-03-28 01:45:351457class OcclusionTrackerTestUnsorted3dLayers
1458 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491459 protected:
[email protected]ca2902e92013-03-28 01:45:351460 explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491461 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471462 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491463 // Currently, The main thread layer iterator does not iterate over 3d items
1464 // in sorted order, because layer sorting is not performed on the main
1465 // thread. Because of this, the occlusion tracker cannot assume that a 3d
1466 // layer occludes other layers that have not yet been iterated over. For
1467 // now, the expected behavior is that a 3d layer simply does not add any
1468 // occlusion to the occlusion tracker.
[email protected]94f206c12012-08-25 00:09:141469
[email protected]a27cbde2013-03-23 22:01:491470 gfx::Transform translation_to_front;
1471 translation_to_front.Translate3d(0.0, 0.0, -10.0);
1472 gfx::Transform translation_to_back;
1473 translation_to_front.Translate3d(0.0, 0.0, -100.0);
[email protected]94f206c12012-08-25 00:09:141474
[email protected]a27cbde2013-03-23 22:01:491475 typename Types::ContentLayerType* parent = this->CreateRoot(
1476 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1477 typename Types::ContentLayerType* child1 = this->CreateDrawingLayer(
1478 parent, translation_to_back, gfx::PointF(), gfx::Size(100, 100), true);
1479 typename Types::ContentLayerType* child2 =
1480 this->CreateDrawingLayer(parent,
1481 translation_to_front,
1482 gfx::PointF(50.f, 50.f),
1483 gfx::Size(100, 100),
1484 true);
[email protected]56fffdd2014-02-11 19:50:571485 parent->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281486 parent->Set3dSortingContextId(1);
1487 child1->Set3dSortingContextId(1);
1488 child2->Set3dSortingContextId(1);
[email protected]94f206c12012-08-25 00:09:141489
[email protected]a27cbde2013-03-23 22:01:491490 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141491
[email protected]34ba1ffb2014-03-05 06:55:031492 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491493 gfx::Rect(0, 0, 1000, 1000));
[email protected]d002dd02013-03-27 07:40:401494 this->VisitLayer(child2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491495 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1496 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141497
[email protected]d002dd02013-03-27 07:40:401498 this->VisitLayer(child1, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491499 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1500 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1501 }
[email protected]94f206c12012-08-25 00:09:141502};
1503
[email protected]a27cbde2013-03-23 22:01:491504// This test will have different layer ordering on the impl thread; the test
1505// will only work on the main thread.
[email protected]96baf3e2012-10-22 23:09:551506MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
[email protected]94f206c12012-08-25 00:09:141507
[email protected]a27cbde2013-03-23 22:01:491508template <class Types>
[email protected]ca2902e92013-03-28 01:45:351509class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude
1510 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491511 protected:
[email protected]ca2902e92013-03-28 01:45:351512 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(
1513 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491514 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471515 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491516 gfx::Transform transform;
1517 transform.Translate(50.0, 50.0);
1518 transform.ApplyPerspectiveDepth(100.0);
1519 transform.Translate3d(0.0, 0.0, 110.0);
1520 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141521
[email protected]a27cbde2013-03-23 22:01:491522 typename Types::ContentLayerType* parent = this->CreateRoot(
1523 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1524 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1525 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
[email protected]56fffdd2014-02-11 19:50:571526 parent->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281527 parent->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:571528 layer->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281529 layer->Set3dSortingContextId(1);
[email protected]a27cbde2013-03-23 22:01:491530 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141531
[email protected]34ba1ffb2014-03-05 06:55:031532 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491533 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141534
[email protected]a27cbde2013-03-23 22:01:491535 // The |layer| is entirely behind the camera and should not occlude.
[email protected]d002dd02013-03-27 07:40:401536 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221537 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491538 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1539 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1540 }
[email protected]94f206c12012-08-25 00:09:141541};
1542
[email protected]a27cbde2013-03-23 22:01:491543// This test requires accumulating occlusion of 3d layers, which are skipped by
1544// the occlusion tracker on the main thread. So this test should run on the impl
1545// thread.
[email protected]96baf3e2012-10-22 23:09:551546IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude);
[email protected]94f206c12012-08-25 00:09:141547
[email protected]a27cbde2013-03-23 22:01:491548template <class Types>
[email protected]ca2902e92013-03-28 01:45:351549class OcclusionTrackerTestLargePixelsOccludeInsideClipRect
1550 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491551 protected:
[email protected]ca2902e92013-03-28 01:45:351552 explicit OcclusionTrackerTestLargePixelsOccludeInsideClipRect(
1553 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491554 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471555 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491556 gfx::Transform transform;
1557 transform.Translate(50.0, 50.0);
1558 transform.ApplyPerspectiveDepth(100.0);
1559 transform.Translate3d(0.0, 0.0, 99.0);
1560 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141561
[email protected]a27cbde2013-03-23 22:01:491562 typename Types::ContentLayerType* parent = this->CreateRoot(
1563 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1564 parent->SetMasksToBounds(true);
1565 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1566 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
[email protected]56fffdd2014-02-11 19:50:571567 parent->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281568 parent->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:571569 layer->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281570 layer->Set3dSortingContextId(1);
[email protected]a27cbde2013-03-23 22:01:491571 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141572
[email protected]34ba1ffb2014-03-05 06:55:031573 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491574 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141575
[email protected]a27cbde2013-03-23 22:01:491576 // This is very close to the camera, so pixels in its visible_content_rect()
1577 // will actually go outside of the layer's clip rect. Ensure that those
1578 // pixels don't occlude things outside the clip rect.
[email protected]d002dd02013-03-27 07:40:401579 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221580 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491581 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
1582 occlusion.occlusion_from_inside_target().ToString());
1583 EXPECT_EQ(gfx::Rect().ToString(),
1584 occlusion.occlusion_from_outside_target().ToString());
1585 }
[email protected]94f206c12012-08-25 00:09:141586};
1587
[email protected]a27cbde2013-03-23 22:01:491588// This test requires accumulating occlusion of 3d layers, which are skipped by
1589// the occlusion tracker on the main thread. So this test should run on the impl
1590// thread.
[email protected]96baf3e2012-10-22 23:09:551591IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect);
[email protected]94f206c12012-08-25 00:09:141592
[email protected]a27cbde2013-03-23 22:01:491593template <class Types>
[email protected]ca2902e92013-03-28 01:45:351594class OcclusionTrackerTestAnimationOpacity1OnMainThread
1595 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491596 protected:
[email protected]ca2902e92013-03-28 01:45:351597 explicit OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491598 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471599 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491600 // parent
1601 // +--layer
1602 // +--surface
1603 // | +--surface_child
1604 // | +--surface_child2
1605 // +--parent2
1606 // +--topmost
[email protected]c8d71552013-01-22 03:43:021607
[email protected]a27cbde2013-03-23 22:01:491608 typename Types::ContentLayerType* parent = this->CreateRoot(
1609 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1610 typename Types::ContentLayerType* layer =
1611 this->CreateDrawingLayer(parent,
1612 this->identity_matrix,
1613 gfx::PointF(),
1614 gfx::Size(300, 300),
1615 true);
1616 typename Types::ContentLayerType* surface =
1617 this->CreateDrawingSurface(parent,
1618 this->identity_matrix,
1619 gfx::PointF(),
1620 gfx::Size(300, 300),
1621 true);
1622 typename Types::ContentLayerType* surface_child =
1623 this->CreateDrawingLayer(surface,
1624 this->identity_matrix,
1625 gfx::PointF(),
1626 gfx::Size(200, 300),
1627 true);
1628 typename Types::ContentLayerType* surface_child2 =
1629 this->CreateDrawingLayer(surface,
1630 this->identity_matrix,
1631 gfx::PointF(),
1632 gfx::Size(100, 300),
1633 true);
1634 typename Types::ContentLayerType* parent2 =
1635 this->CreateDrawingLayer(parent,
1636 this->identity_matrix,
1637 gfx::PointF(),
1638 gfx::Size(300, 300),
1639 false);
1640 typename Types::ContentLayerType* topmost =
1641 this->CreateDrawingLayer(parent,
1642 this->identity_matrix,
1643 gfx::PointF(250.f, 0.f),
1644 gfx::Size(50, 300),
1645 true);
[email protected]94f206c12012-08-25 00:09:141646
[email protected]a27cbde2013-03-23 22:01:491647 AddOpacityTransitionToController(
1648 layer->layer_animation_controller(), 10.0, 0.f, 1.f, false);
1649 AddOpacityTransitionToController(
1650 surface->layer_animation_controller(), 10.0, 0.f, 1.f, false);
1651 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141652
[email protected]a27cbde2013-03-23 22:01:491653 EXPECT_TRUE(layer->draw_opacity_is_animating());
1654 EXPECT_FALSE(surface->draw_opacity_is_animating());
1655 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:141656
[email protected]34ba1ffb2014-03-05 06:55:031657 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491658 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141659
[email protected]d002dd02013-03-27 07:40:401660 this->VisitLayer(topmost, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221661 this->EnterLayer(parent2, &occlusion);
danakjf080b5b2014-08-23 22:18:201662
[email protected]a27cbde2013-03-23 22:01:491663 // This occlusion will affect all surfaces.
[email protected]a27cbde2013-03-23 22:01:491664 EXPECT_EQ(gfx::Rect().ToString(),
1665 occlusion.occlusion_from_outside_target().ToString());
danakjf080b5b2014-08-23 22:18:201666 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1667 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141668
danakjf080b5b2014-08-23 22:18:201669 this->LeaveLayer(parent2, &occlusion);
[email protected]d002dd02013-03-27 07:40:401670 this->VisitLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221671 this->EnterLayer(surface_child, &occlusion);
danakjf080b5b2014-08-23 22:18:201672 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1673 occlusion.occlusion_from_outside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491674 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1675 occlusion.occlusion_from_inside_target().ToString());
danakjf080b5b2014-08-23 22:18:201676
[email protected]d002dd02013-03-27 07:40:401677 this->LeaveLayer(surface_child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221678 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491679 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1680 occlusion.occlusion_from_outside_target().ToString());
danakjf080b5b2014-08-23 22:18:201681 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
1682 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141683
danakjf080b5b2014-08-23 22:18:201684 this->LeaveLayer(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221685 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491686 // Occlusion within the surface is lost when leaving the animating surface.
1687 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:491688 occlusion.occlusion_from_outside_target().ToString());
danakjf080b5b2014-08-23 22:18:201689 EXPECT_EQ(gfx::Rect().ToString(),
1690 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141691
danakjf080b5b2014-08-23 22:18:201692 this->LeaveContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491693 // Occlusion from outside the animating surface still exists.
1694 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1695 occlusion.occlusion_from_inside_target().ToString());
1696 EXPECT_EQ(gfx::Rect().ToString(),
1697 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:021698
[email protected]d002dd02013-03-27 07:40:401699 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221700 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141701
[email protected]a27cbde2013-03-23 22:01:491702 // Occlusion is not added for the animating |layer|.
danakjf080b5b2014-08-23 22:18:201703 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1704 occlusion.occlusion_from_inside_target().ToString());
1705 EXPECT_EQ(gfx::Rect().ToString(),
1706 occlusion.occlusion_from_outside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491707 }
[email protected]94f206c12012-08-25 00:09:141708};
1709
[email protected]96baf3e2012-10-22 23:09:551710MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread);
[email protected]94f206c12012-08-25 00:09:141711
[email protected]a27cbde2013-03-23 22:01:491712template <class Types>
[email protected]ca2902e92013-03-28 01:45:351713class OcclusionTrackerTestAnimationOpacity0OnMainThread
1714 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491715 protected:
[email protected]ca2902e92013-03-28 01:45:351716 explicit OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491717 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471718 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491719 typename Types::ContentLayerType* parent = this->CreateRoot(
1720 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1721 typename Types::ContentLayerType* layer =
1722 this->CreateDrawingLayer(parent,
1723 this->identity_matrix,
1724 gfx::PointF(),
1725 gfx::Size(300, 300),
1726 true);
1727 typename Types::ContentLayerType* surface =
1728 this->CreateDrawingSurface(parent,
1729 this->identity_matrix,
1730 gfx::PointF(),
1731 gfx::Size(300, 300),
1732 true);
1733 typename Types::ContentLayerType* surface_child =
1734 this->CreateDrawingLayer(surface,
1735 this->identity_matrix,
1736 gfx::PointF(),
1737 gfx::Size(200, 300),
1738 true);
1739 typename Types::ContentLayerType* surface_child2 =
1740 this->CreateDrawingLayer(surface,
1741 this->identity_matrix,
1742 gfx::PointF(),
1743 gfx::Size(100, 300),
1744 true);
1745 typename Types::ContentLayerType* parent2 =
1746 this->CreateDrawingLayer(parent,
1747 this->identity_matrix,
1748 gfx::PointF(),
1749 gfx::Size(300, 300),
1750 false);
1751 typename Types::ContentLayerType* topmost =
1752 this->CreateDrawingLayer(parent,
1753 this->identity_matrix,
1754 gfx::PointF(250.f, 0.f),
1755 gfx::Size(50, 300),
1756 true);
[email protected]94f206c12012-08-25 00:09:141757
[email protected]a27cbde2013-03-23 22:01:491758 AddOpacityTransitionToController(
1759 layer->layer_animation_controller(), 10.0, 1.f, 0.f, false);
1760 AddOpacityTransitionToController(
1761 surface->layer_animation_controller(), 10.0, 1.f, 0.f, false);
1762 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141763
[email protected]a27cbde2013-03-23 22:01:491764 EXPECT_TRUE(layer->draw_opacity_is_animating());
1765 EXPECT_FALSE(surface->draw_opacity_is_animating());
1766 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:141767
[email protected]34ba1ffb2014-03-05 06:55:031768 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491769 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141770
[email protected]d002dd02013-03-27 07:40:401771 this->VisitLayer(topmost, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221772 this->EnterLayer(parent2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491773 // This occlusion will affect all surfaces.
1774 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1775 occlusion.occlusion_from_inside_target().ToString());
1776 EXPECT_EQ(gfx::Rect().ToString(),
1777 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141778
danakjf080b5b2014-08-23 22:18:201779 this->LeaveLayer(parent2, &occlusion);
[email protected]d002dd02013-03-27 07:40:401780 this->VisitLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221781 this->EnterLayer(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491782 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1783 occlusion.occlusion_from_inside_target().ToString());
1784 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1785 occlusion.occlusion_from_outside_target().ToString());
danakjf080b5b2014-08-23 22:18:201786
[email protected]d002dd02013-03-27 07:40:401787 this->LeaveLayer(surface_child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221788 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491789 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
1790 occlusion.occlusion_from_inside_target().ToString());
1791 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1792 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141793
danakjf080b5b2014-08-23 22:18:201794 this->LeaveLayer(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221795 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491796 // Occlusion within the surface is lost when leaving the animating surface.
1797 EXPECT_EQ(gfx::Rect().ToString(),
1798 occlusion.occlusion_from_inside_target().ToString());
1799 EXPECT_EQ(gfx::Rect().ToString(),
1800 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141801
danakjf080b5b2014-08-23 22:18:201802 this->LeaveContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491803 // Occlusion from outside the animating surface still exists.
1804 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1805 occlusion.occlusion_from_inside_target().ToString());
1806 EXPECT_EQ(gfx::Rect().ToString(),
1807 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:021808
[email protected]d002dd02013-03-27 07:40:401809 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221810 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141811
[email protected]a27cbde2013-03-23 22:01:491812 // Occlusion is not added for the animating |layer|.
danakjf080b5b2014-08-23 22:18:201813 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1814 occlusion.occlusion_from_inside_target().ToString());
1815 EXPECT_EQ(gfx::Rect().ToString(),
1816 occlusion.occlusion_from_outside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491817 }
[email protected]94f206c12012-08-25 00:09:141818};
1819
[email protected]96baf3e2012-10-22 23:09:551820MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread);
[email protected]94f206c12012-08-25 00:09:141821
[email protected]a27cbde2013-03-23 22:01:491822template <class Types>
[email protected]ca2902e92013-03-28 01:45:351823class OcclusionTrackerTestAnimationTranslateOnMainThread
1824 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491825 protected:
[email protected]ca2902e92013-03-28 01:45:351826 explicit OcclusionTrackerTestAnimationTranslateOnMainThread(
1827 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491828 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471829 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491830 typename Types::ContentLayerType* parent = this->CreateRoot(
1831 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1832 typename Types::ContentLayerType* layer =
1833 this->CreateDrawingLayer(parent,
1834 this->identity_matrix,
1835 gfx::PointF(),
1836 gfx::Size(300, 300),
1837 true);
1838 typename Types::ContentLayerType* surface =
1839 this->CreateDrawingSurface(parent,
1840 this->identity_matrix,
1841 gfx::PointF(),
1842 gfx::Size(300, 300),
1843 true);
1844 typename Types::ContentLayerType* surface_child =
1845 this->CreateDrawingLayer(surface,
1846 this->identity_matrix,
1847 gfx::PointF(),
1848 gfx::Size(200, 300),
1849 true);
1850 typename Types::ContentLayerType* surface_child2 =
1851 this->CreateDrawingLayer(surface,
1852 this->identity_matrix,
1853 gfx::PointF(),
1854 gfx::Size(100, 300),
1855 true);
1856 typename Types::ContentLayerType* surface2 = this->CreateDrawingSurface(
1857 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 300), true);
[email protected]94f206c12012-08-25 00:09:141858
[email protected]a27cbde2013-03-23 22:01:491859 AddAnimatedTransformToController(
1860 layer->layer_animation_controller(), 10.0, 30, 0);
1861 AddAnimatedTransformToController(
1862 surface->layer_animation_controller(), 10.0, 30, 0);
1863 AddAnimatedTransformToController(
1864 surface_child->layer_animation_controller(), 10.0, 30, 0);
1865 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141866
[email protected]a27cbde2013-03-23 22:01:491867 EXPECT_TRUE(layer->draw_transform_is_animating());
1868 EXPECT_TRUE(layer->screen_space_transform_is_animating());
1869 EXPECT_TRUE(
1870 surface->render_surface()->target_surface_transforms_are_animating());
1871 EXPECT_TRUE(
1872 surface->render_surface()->screen_space_transforms_are_animating());
1873 // The surface owning layer doesn't animate against its own surface.
1874 EXPECT_FALSE(surface->draw_transform_is_animating());
1875 EXPECT_TRUE(surface->screen_space_transform_is_animating());
1876 EXPECT_TRUE(surface_child->draw_transform_is_animating());
1877 EXPECT_TRUE(surface_child->screen_space_transform_is_animating());
[email protected]94f206c12012-08-25 00:09:141878
[email protected]34ba1ffb2014-03-05 06:55:031879 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491880 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141881
[email protected]d002dd02013-03-27 07:40:401882 this->VisitLayer(surface2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221883 this->EnterContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141884
[email protected]a27cbde2013-03-23 22:01:491885 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
1886 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141887
[email protected]d002dd02013-03-27 07:40:401888 this->LeaveContributingSurface(surface2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221889 this->EnterLayer(surface_child2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491890 // surface_child2 is moving in screen space but not relative to its target,
1891 // so occlusion should happen in its target space only. It also means that
1892 // things occluding from outside the target (e.g. surface2) cannot occlude
1893 // this layer.
1894 EXPECT_EQ(gfx::Rect().ToString(),
1895 occlusion.occlusion_from_outside_target().ToString());
[email protected]7d6d6c92014-03-06 01:18:501896 EXPECT_EQ(gfx::Rect().ToString(),
1897 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141898
[email protected]d002dd02013-03-27 07:40:401899 this->LeaveLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221900 this->EnterLayer(surface_child, &occlusion);
[email protected]7d6d6c92014-03-06 01:18:501901 // surface_child2 added to the occlusion since it is not moving relative
1902 // to its target.
[email protected]a27cbde2013-03-23 22:01:491903 EXPECT_EQ(gfx::Rect().ToString(),
1904 occlusion.occlusion_from_outside_target().ToString());
1905 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1906 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141907
[email protected]d002dd02013-03-27 07:40:401908 this->LeaveLayer(surface_child, &occlusion);
[email protected]7d6d6c92014-03-06 01:18:501909 // surface_child is moving relative to its target, so it does not add
1910 // occlusion.
[email protected]a27cbde2013-03-23 22:01:491911 EXPECT_EQ(gfx::Rect().ToString(),
1912 occlusion.occlusion_from_outside_target().ToString());
1913 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1914 occlusion.occlusion_from_inside_target().ToString());
[email protected]7d6d6c92014-03-06 01:18:501915
1916 this->EnterLayer(surface, &occlusion);
1917 EXPECT_EQ(gfx::Rect().ToString(),
1918 occlusion.occlusion_from_outside_target().ToString());
1919 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1920 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141921
[email protected]d002dd02013-03-27 07:40:401922 this->LeaveLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491923 // The surface's owning layer is moving in screen space but not relative to
[email protected]7d6d6c92014-03-06 01:18:501924 // its target, so it adds to the occlusion.
[email protected]a27cbde2013-03-23 22:01:491925 EXPECT_EQ(gfx::Rect().ToString(),
1926 occlusion.occlusion_from_outside_target().ToString());
1927 EXPECT_EQ(gfx::Rect(0, 0, 300, 300).ToString(),
1928 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141929
[email protected]e47b0a0a2013-11-18 23:26:221930 this->EnterContributingSurface(surface, &occlusion);
[email protected]d002dd02013-03-27 07:40:401931 this->LeaveContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491932 // The |surface| is moving in the screen and in its target, so all occlusion
[email protected]7d6d6c92014-03-06 01:18:501933 // within the surface is lost when leaving it. Only the |surface2| occlusion
1934 // is left.
1935 EXPECT_EQ(gfx::Rect().ToString(),
1936 occlusion.occlusion_from_outside_target().ToString());
1937 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
1938 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141939
[email protected]7d6d6c92014-03-06 01:18:501940 this->VisitLayer(layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491941 // The |layer| is animating in the screen and in its target, so no occlusion
1942 // is added.
[email protected]7d6d6c92014-03-06 01:18:501943 EXPECT_EQ(gfx::Rect().ToString(),
1944 occlusion.occlusion_from_outside_target().ToString());
1945 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
1946 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491947 }
[email protected]94f206c12012-08-25 00:09:141948};
1949
[email protected]96baf3e2012-10-22 23:09:551950MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread);
[email protected]94f206c12012-08-25 00:09:141951
[email protected]a27cbde2013-03-23 22:01:491952template <class Types>
[email protected]ca2902e92013-03-28 01:45:351953class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent
1954 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491955 protected:
[email protected]ca2902e92013-03-28 01:45:351956 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(
1957 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491958 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471959 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491960 gfx::Transform surface_transform;
1961 surface_transform.Translate(300.0, 300.0);
1962 surface_transform.Scale(2.0, 2.0);
1963 surface_transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:141964
[email protected]a27cbde2013-03-23 22:01:491965 typename Types::ContentLayerType* parent = this->CreateRoot(
1966 this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
1967 typename Types::ContentLayerType* surface = this->CreateDrawingSurface(
1968 parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false);
1969 typename Types::ContentLayerType* surface2 =
1970 this->CreateDrawingSurface(parent,
1971 this->identity_matrix,
1972 gfx::PointF(50.f, 50.f),
1973 gfx::Size(300, 300),
1974 false);
1975 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1976 surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1977 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141978
[email protected]34ba1ffb2014-03-05 06:55:031979 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491980 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141981
[email protected]d002dd02013-03-27 07:40:401982 this->VisitLayer(surface2, &occlusion);
1983 this->VisitContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141984
[email protected]a27cbde2013-03-23 22:01:491985 EXPECT_EQ(gfx::Rect().ToString(),
1986 occlusion.occlusion_from_outside_target().ToString());
1987 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(),
1988 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141989
[email protected]a27cbde2013-03-23 22:01:491990 // Clear any stored occlusion.
[email protected]d5467eb72014-08-22 01:16:431991 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
1992 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
[email protected]94f206c12012-08-25 00:09:141993
[email protected]d002dd02013-03-27 07:40:401994 this->VisitLayer(surface, &occlusion);
1995 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141996
[email protected]a27cbde2013-03-23 22:01:491997 EXPECT_EQ(gfx::Rect().ToString(),
1998 occlusion.occlusion_from_outside_target().ToString());
1999 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(),
2000 occlusion.occlusion_from_inside_target().ToString());
2001 }
[email protected]94f206c12012-08-25 00:09:142002};
2003
[email protected]a27cbde2013-03-23 22:01:492004MAIN_AND_IMPL_THREAD_TEST(
2005 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:142006
[email protected]a27cbde2013-03-23 22:01:492007template <class Types>
[email protected]ca2902e92013-03-28 01:45:352008class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping
2009 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492010 protected:
[email protected]ca2902e92013-03-28 01:45:352011 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(
2012 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492013 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472014 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:492015 typename Types::ContentLayerType* parent = this->CreateRoot(
2016 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2017 parent->SetMasksToBounds(true);
2018 typename Types::ContentLayerType* surface =
2019 this->CreateDrawingSurface(parent,
2020 this->identity_matrix,
2021 gfx::PointF(),
2022 gfx::Size(500, 300),
2023 false);
2024 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
2025 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142026
[email protected]34ba1ffb2014-03-05 06:55:032027 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492028 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142029
[email protected]d002dd02013-03-27 07:40:402030 this->VisitLayer(surface, &occlusion);
2031 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142032
[email protected]a27cbde2013-03-23 22:01:492033 EXPECT_EQ(gfx::Rect().ToString(),
2034 occlusion.occlusion_from_outside_target().ToString());
2035 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(),
2036 occlusion.occlusion_from_inside_target().ToString());
2037 }
[email protected]94f206c12012-08-25 00:09:142038};
2039
[email protected]a27cbde2013-03-23 22:01:492040MAIN_AND_IMPL_THREAD_TEST(
2041 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:142042
[email protected]a27cbde2013-03-23 22:01:492043template <class Types>
[email protected]ca2902e92013-03-28 01:45:352044class OcclusionTrackerTestSurfaceWithReplicaUnoccluded
2045 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492046 protected:
[email protected]ca2902e92013-03-28 01:45:352047 explicit OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492048 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472049 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:492050 typename Types::ContentLayerType* parent = this->CreateRoot(
2051 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2052 typename Types::LayerType* surface =
2053 this->CreateDrawingSurface(parent,
2054 this->identity_matrix,
2055 gfx::PointF(),
2056 gfx::Size(100, 100),
2057 true);
2058 this->CreateReplicaLayer(surface,
2059 this->identity_matrix,
2060 gfx::PointF(0.f, 100.f),
2061 gfx::Size(100, 100));
2062 typename Types::LayerType* topmost =
2063 this->CreateDrawingLayer(parent,
2064 this->identity_matrix,
2065 gfx::PointF(),
2066 gfx::Size(100, 110),
2067 true);
2068 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142069
[email protected]34ba1ffb2014-03-05 06:55:032070 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492071 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142072
[email protected]a27cbde2013-03-23 22:01:492073 // |topmost| occludes the surface, but not the entire surface's replica.
[email protected]d002dd02013-03-27 07:40:402074 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142075
[email protected]a27cbde2013-03-23 22:01:492076 EXPECT_EQ(gfx::Rect().ToString(),
2077 occlusion.occlusion_from_outside_target().ToString());
2078 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(),
2079 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142080
[email protected]d002dd02013-03-27 07:40:402081 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142082
[email protected]66b52e12013-11-17 15:53:182083 // Render target with replica ignores occlusion from outside.
2084 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:492085 occlusion.occlusion_from_outside_target().ToString());
2086 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2087 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142088
[email protected]e47b0a0a2013-11-18 23:26:222089 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142090
danakjf080b5b2014-08-23 22:18:202091 // Only occlusion from outside the surface occludes the surface/replica.
2092 EXPECT_EQ(gfx::Rect().ToString(),
2093 occlusion.occlusion_on_contributing_surface_from_outside_target()
2094 .ToString());
2095 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(),
2096 occlusion.occlusion_on_contributing_surface_from_inside_target()
2097 .ToString());
[email protected]a27cbde2013-03-23 22:01:492098 }
[email protected]94f206c12012-08-25 00:09:142099};
2100
[email protected]96baf3e2012-10-22 23:09:552101ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded);
[email protected]94f206c12012-08-25 00:09:142102
[email protected]a27cbde2013-03-23 22:01:492103template <class Types>
[email protected]ca2902e92013-03-28 01:45:352104class OcclusionTrackerTestSurfaceChildOfSurface
2105 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492106 protected:
[email protected]ca2902e92013-03-28 01:45:352107 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492108 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472109 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:492110 // This test verifies that the surface cliprect does not end up empty and
2111 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:142112
[email protected]a27cbde2013-03-23 22:01:492113 typename Types::ContentLayerType* parent = this->CreateRoot(
2114 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2115 typename Types::LayerType* surface =
2116 this->CreateDrawingSurface(parent,
2117 this->identity_matrix,
2118 gfx::PointF(),
2119 gfx::Size(100, 100),
danakjf080b5b2014-08-23 22:18:202120 false);
[email protected]a27cbde2013-03-23 22:01:492121 typename Types::LayerType* surface_child =
2122 this->CreateDrawingSurface(surface,
2123 this->identity_matrix,
2124 gfx::PointF(0.f, 10.f),
2125 gfx::Size(100, 50),
2126 true);
2127 typename Types::LayerType* topmost = this->CreateDrawingLayer(
2128 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
2129 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142130
[email protected]34ba1ffb2014-03-05 06:55:032131 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492132 gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142133
[email protected]a27cbde2013-03-23 22:01:492134 // |topmost| occludes everything partially so we know occlusion is happening
2135 // at all.
[email protected]d002dd02013-03-27 07:40:402136 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142137
[email protected]a27cbde2013-03-23 22:01:492138 EXPECT_EQ(gfx::Rect().ToString(),
2139 occlusion.occlusion_from_outside_target().ToString());
2140 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2141 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142142
[email protected]d002dd02013-03-27 07:40:402143 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:142144
[email protected]a27cbde2013-03-23 22:01:492145 // surface_child increases the occlusion in the screen by a narrow sliver.
2146 EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(),
2147 occlusion.occlusion_from_outside_target().ToString());
2148 // In its own surface, surface_child is at 0,0 as is its occlusion.
2149 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2150 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142151
[email protected]a27cbde2013-03-23 22:01:492152 // The root layer always has a clip rect. So the parent of |surface| has a
2153 // clip rect. However, the owning layer for |surface| does not mask to
2154 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
2155 // |surface_child| exercises different code paths as its parent does not
2156 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:142157
[email protected]e47b0a0a2013-11-18 23:26:222158 this->EnterContributingSurface(surface_child, &occlusion);
danakjf080b5b2014-08-23 22:18:202159 // The |surface_child| can't occlude its own surface, but occlusion from
2160 // |topmost| can.
2161 EXPECT_EQ(gfx::Rect().ToString(),
2162 occlusion.occlusion_on_contributing_surface_from_outside_target()
2163 .ToString());
2164 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2165 occlusion.occlusion_on_contributing_surface_from_inside_target()
2166 .ToString());
[email protected]d002dd02013-03-27 07:40:402167 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:142168
[email protected]a27cbde2013-03-23 22:01:492169 // When the surface_child's occlusion is transformed up to its parent, make
danakjf080b5b2014-08-23 22:18:202170 // sure it is not clipped away inappropriately.
[email protected]e47b0a0a2013-11-18 23:26:222171 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492172 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2173 occlusion.occlusion_from_outside_target().ToString());
2174 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(),
2175 occlusion.occlusion_from_inside_target().ToString());
[email protected]d002dd02013-03-27 07:40:402176 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142177
[email protected]e47b0a0a2013-11-18 23:26:222178 this->EnterContributingSurface(surface, &occlusion);
danakjf080b5b2014-08-23 22:18:202179 // The occlusion from inside |surface| can't affect the surface, but
2180 // |topmost| can.
2181 EXPECT_EQ(gfx::Rect().ToString(),
2182 occlusion.occlusion_on_contributing_surface_from_outside_target()
2183 .ToString());
2184 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2185 occlusion.occlusion_on_contributing_surface_from_inside_target()
2186 .ToString());
2187
2188 this->LeaveContributingSurface(surface, &occlusion);
2189 this->EnterLayer(parent, &occlusion);
2190 // The occlusion in |surface| and without are merged into the parent.
2191 EXPECT_EQ(gfx::Rect().ToString(),
2192 occlusion.occlusion_from_outside_target().ToString());
2193 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(),
2194 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:492195 }
[email protected]94f206c12012-08-25 00:09:142196};
2197
[email protected]96baf3e2012-10-22 23:09:552198ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:142199
[email protected]a27cbde2013-03-23 22:01:492200template <class Types>
[email protected]ca2902e92013-03-28 01:45:352201class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter
2202 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492203 protected:
[email protected]ca2902e92013-03-28 01:45:352204 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:492205 bool opaque_layers)
2206 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472207 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:492208 gfx::Transform scale_by_half;
2209 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142210
[email protected]ae6b1a72013-06-25 18:49:292211 FilterOperations filters;
2212 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]94f206c12012-08-25 00:09:142213
[email protected]a27cbde2013-03-23 22:01:492214 // Save the distance of influence for the blur effect.
2215 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:292216 filters.GetOutsets(
2217 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:142218
[email protected]d5467eb72014-08-22 01:16:432219 enum Direction {
2220 LEFT,
2221 RIGHT,
2222 TOP,
2223 BOTTOM,
2224 LAST_DIRECTION = BOTTOM,
2225 };
[email protected]94f206c12012-08-25 00:09:142226
[email protected]d5467eb72014-08-22 01:16:432227 for (int i = 0; i <= LAST_DIRECTION; ++i) {
2228 SCOPED_TRACE(i);
[email protected]94f206c12012-08-25 00:09:142229
[email protected]d5467eb72014-08-22 01:16:432230 // Make a 50x50 filtered surface that is adjacent to occluding layers
2231 // which are above it in the z-order in various configurations. The
2232 // surface is scaled to test that the pixel moving is done in the target
2233 // space, where the background filter is applied.
2234 typename Types::ContentLayerType* parent = this->CreateRoot(
2235 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2236 typename Types::LayerType* filtered_surface =
2237 this->CreateDrawingLayer(parent,
2238 scale_by_half,
2239 gfx::PointF(50.f, 50.f),
2240 gfx::Size(100, 100),
2241 false);
awoloszyne83f28c2014-12-22 15:40:002242 Types::SetForceRenderSurface(filtered_surface, true);
[email protected]d5467eb72014-08-22 01:16:432243 filtered_surface->SetBackgroundFilters(filters);
[email protected]d5467eb72014-08-22 01:16:432244 gfx::Rect occlusion_rect;
2245 switch (i) {
2246 case LEFT:
2247 occlusion_rect = gfx::Rect(0, 0, 50, 200);
2248 break;
2249 case RIGHT:
2250 occlusion_rect = gfx::Rect(100, 0, 50, 200);
2251 break;
2252 case TOP:
2253 occlusion_rect = gfx::Rect(0, 0, 200, 50);
2254 break;
2255 case BOTTOM:
2256 occlusion_rect = gfx::Rect(0, 100, 200, 50);
2257 break;
2258 }
[email protected]ac7c7f52012-11-08 06:26:502259
[email protected]d5467eb72014-08-22 01:16:432260 typename Types::LayerType* occluding_layer =
2261 this->CreateDrawingLayer(parent,
2262 this->identity_matrix,
2263 occlusion_rect.origin(),
2264 occlusion_rect.size(),
2265 true);
2266 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142267
[email protected]d5467eb72014-08-22 01:16:432268 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2269 gfx::Rect(0, 0, 200, 200));
[email protected]94f206c12012-08-25 00:09:142270
[email protected]d5467eb72014-08-22 01:16:432271 // This layer occludes pixels directly beside the filtered_surface.
2272 // Because filtered surface blends pixels in a radius, it will need to see
2273 // some of the pixels (up to radius far) underneath the occluding layers.
2274 this->VisitLayer(occluding_layer, &occlusion);
[email protected]ccb1c9a2012-12-17 03:53:192275
[email protected]d5467eb72014-08-22 01:16:432276 EXPECT_EQ(occlusion_rect.ToString(),
2277 occlusion.occlusion_from_inside_target().ToString());
2278 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142279
[email protected]d5467eb72014-08-22 01:16:432280 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142281
[email protected]d5467eb72014-08-22 01:16:432282 // The occlusion is used fully inside the surface.
2283 gfx::Rect occlusion_inside_surface =
2284 occlusion_rect - gfx::Vector2d(50, 50);
2285 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
2286 EXPECT_EQ(occlusion_inside_surface.ToString(),
2287 occlusion.occlusion_from_outside_target().ToString());
[email protected]ac7c7f52012-11-08 06:26:502288
[email protected]d5467eb72014-08-22 01:16:432289 // The surface has a background blur, so it needs pixels that are
2290 // currently considered occluded in order to be drawn. So the pixels it
2291 // needs should be removed some the occluded area so that when we get to
2292 // the parent they are drawn.
2293 this->VisitContributingSurface(filtered_surface, &occlusion);
2294 this->EnterLayer(parent, &occlusion);
[email protected]ac7c7f52012-11-08 06:26:502295
[email protected]d5467eb72014-08-22 01:16:432296 gfx::Rect expected_occlusion = occlusion_rect;
2297 switch (i) {
2298 case LEFT:
2299 expected_occlusion.Inset(0, 0, outset_right, 0);
2300 break;
2301 case RIGHT:
2302 expected_occlusion.Inset(outset_right, 0, 0, 0);
2303 break;
2304 case TOP:
2305 expected_occlusion.Inset(0, 0, 0, outset_right);
2306 break;
2307 case BOTTOM:
2308 expected_occlusion.Inset(0, outset_right, 0, 0);
2309 break;
2310 }
[email protected]94f206c12012-08-25 00:09:142311
[email protected]d5467eb72014-08-22 01:16:432312 EXPECT_EQ(expected_occlusion.ToString(),
2313 occlusion.occlusion_from_inside_target().ToString());
2314 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142315
[email protected]d5467eb72014-08-22 01:16:432316 this->DestroyLayers();
2317 }
[email protected]a27cbde2013-03-23 22:01:492318 }
[email protected]94f206c12012-08-25 00:09:142319};
2320
[email protected]a27cbde2013-03-23 22:01:492321ALL_OCCLUSIONTRACKER_TEST(
2322 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142323
[email protected]a27cbde2013-03-23 22:01:492324template <class Types>
[email protected]ca2902e92013-03-28 01:45:352325class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice
2326 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492327 protected:
[email protected]ca2902e92013-03-28 01:45:352328 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(
[email protected]a27cbde2013-03-23 22:01:492329 bool opaque_layers)
2330 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472331 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:492332 gfx::Transform scale_by_half;
2333 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142334
[email protected]a27cbde2013-03-23 22:01:492335 // Makes two surfaces that completely cover |parent|. The occlusion both
2336 // above and below the filters will be reduced by each of them.
2337 typename Types::ContentLayerType* root = this->CreateRoot(
2338 this->identity_matrix, gfx::PointF(), gfx::Size(75, 75));
2339 typename Types::LayerType* parent = this->CreateSurface(
2340 root, scale_by_half, gfx::PointF(), gfx::Size(150, 150));
2341 parent->SetMasksToBounds(true);
2342 typename Types::LayerType* filtered_surface1 = this->CreateDrawingLayer(
2343 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
2344 typename Types::LayerType* filtered_surface2 = this->CreateDrawingLayer(
2345 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
2346 typename Types::LayerType* occluding_layer_above =
2347 this->CreateDrawingLayer(parent,
2348 this->identity_matrix,
2349 gfx::PointF(100.f, 100.f),
2350 gfx::Size(50, 50),
2351 true);
[email protected]94f206c12012-08-25 00:09:142352
[email protected]a27cbde2013-03-23 22:01:492353 // Filters make the layers own surfaces.
awoloszyne83f28c2014-12-22 15:40:002354 Types::SetForceRenderSurface(filtered_surface1, true);
2355 Types::SetForceRenderSurface(filtered_surface2, true);
[email protected]ae6b1a72013-06-25 18:49:292356 FilterOperations filters;
2357 filters.Append(FilterOperation::CreateBlurFilter(1.f));
[email protected]a27cbde2013-03-23 22:01:492358 filtered_surface1->SetBackgroundFilters(filters);
2359 filtered_surface2->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142360
[email protected]a27cbde2013-03-23 22:01:492361 // Save the distance of influence for the blur effect.
2362 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:292363 filters.GetOutsets(
2364 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:142365
[email protected]a27cbde2013-03-23 22:01:492366 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:142367
[email protected]34ba1ffb2014-03-05 06:55:032368 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492369 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142370
[email protected]d002dd02013-03-27 07:40:402371 this->VisitLayer(occluding_layer_above, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492372 EXPECT_EQ(gfx::Rect().ToString(),
2373 occlusion.occlusion_from_outside_target().ToString());
2374 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(),
2375 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142376
[email protected]d002dd02013-03-27 07:40:402377 this->VisitLayer(filtered_surface2, &occlusion);
2378 this->VisitContributingSurface(filtered_surface2, &occlusion);
2379 this->VisitLayer(filtered_surface1, &occlusion);
2380 this->VisitContributingSurface(filtered_surface1, &occlusion);
[email protected]94f206c12012-08-25 00:09:142381
[email protected]a27cbde2013-03-23 22:01:492382 // Test expectations in the target.
2383 gfx::Rect expected_occlusion =
2384 gfx::Rect(100 / 2 + outset_right * 2,
2385 100 / 2 + outset_bottom * 2,
2386 50 / 2 - (outset_left + outset_right) * 2,
2387 50 / 2 - (outset_top + outset_bottom) * 2);
2388 EXPECT_EQ(expected_occlusion.ToString(),
2389 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142390
[email protected]a27cbde2013-03-23 22:01:492391 // Test expectations in the screen are the same as in the target, as the
2392 // render surface is 1:1 with the screen.
2393 EXPECT_EQ(expected_occlusion.ToString(),
2394 occlusion.occlusion_from_outside_target().ToString());
2395 }
[email protected]94f206c12012-08-25 00:09:142396};
2397
[email protected]a27cbde2013-03-23 22:01:492398ALL_OCCLUSIONTRACKER_TEST(
2399 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:142400
[email protected]a27cbde2013-03-23 22:01:492401template <class Types>
[email protected]ca2902e92013-03-28 01:45:352402class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter
2403 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492404 protected:
[email protected]ca2902e92013-03-28 01:45:352405 explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:492406 bool opaque_layers)
2407 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472408 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:492409 gfx::Transform scale_by_half;
2410 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142411
[email protected]a27cbde2013-03-23 22:01:492412 // Make a surface and its replica, each 50x50, with a smaller 30x30 layer
2413 // centered below each. The surface is scaled to test that the pixel moving
2414 // is done in the target space, where the background filter is applied, but
2415 // the surface appears at 50, 50 and the replica at 200, 50.
2416 typename Types::ContentLayerType* parent = this->CreateRoot(
2417 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
2418 typename Types::LayerType* behind_surface_layer =
2419 this->CreateDrawingLayer(parent,
2420 this->identity_matrix,
2421 gfx::PointF(60.f, 60.f),
2422 gfx::Size(30, 30),
2423 true);
2424 typename Types::LayerType* behind_replica_layer =
2425 this->CreateDrawingLayer(parent,
2426 this->identity_matrix,
2427 gfx::PointF(210.f, 60.f),
2428 gfx::Size(30, 30),
2429 true);
2430 typename Types::LayerType* filtered_surface =
2431 this->CreateDrawingLayer(parent,
2432 scale_by_half,
2433 gfx::PointF(50.f, 50.f),
2434 gfx::Size(100, 100),
2435 false);
2436 this->CreateReplicaLayer(filtered_surface,
2437 this->identity_matrix,
2438 gfx::PointF(300.f, 0.f),
2439 gfx::Size());
[email protected]94f206c12012-08-25 00:09:142440
[email protected]a27cbde2013-03-23 22:01:492441 // Filters make the layer own a surface.
awoloszyne83f28c2014-12-22 15:40:002442 Types::SetForceRenderSurface(filtered_surface, true);
[email protected]ae6b1a72013-06-25 18:49:292443 FilterOperations filters;
2444 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:492445 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142446
[email protected]a27cbde2013-03-23 22:01:492447 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 // The surface has a background blur, so it blurs non-opaque pixels below
2453 // it.
[email protected]d002dd02013-03-27 07:40:402454 this->VisitLayer(filtered_surface, &occlusion);
2455 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142456
[email protected]d002dd02013-03-27 07:40:402457 this->VisitLayer(behind_replica_layer, &occlusion);
[email protected]d5467eb72014-08-22 01:16:432458
2459 // The layers behind the surface are not blurred, and their occlusion does
2460 // not change, until we leave the surface. So it should not be modified by
2461 // the filter here.
2462 gfx::Rect occlusion_behind_replica = gfx::Rect(210, 60, 30, 30);
2463 EXPECT_EQ(occlusion_behind_replica.ToString(),
2464 occlusion.occlusion_from_inside_target().ToString());
2465 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
2466
2467 // Clear the occlusion so the |behind_surface_layer| can add its occlusion
2468 // without existing occlusion interfering.
2469 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2470
[email protected]d002dd02013-03-27 07:40:402471 this->VisitLayer(behind_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:142472
[email protected]a27cbde2013-03-23 22:01:492473 // The layers behind the surface are not blurred, and their occlusion does
2474 // not change, until we leave the surface. So it should not be modified by
2475 // the filter here.
2476 gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30);
[email protected]d5467eb72014-08-22 01:16:432477 EXPECT_EQ(occlusion_behind_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:492478 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432479 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:492480 }
[email protected]94f206c12012-08-25 00:09:142481};
2482
[email protected]a27cbde2013-03-23 22:01:492483ALL_OCCLUSIONTRACKER_TEST(
2484 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142485
[email protected]a27cbde2013-03-23 22:01:492486template <class Types>
[email protected]ca2902e92013-03-28 01:45:352487class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded
2488 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492489 protected:
[email protected]ca2902e92013-03-28 01:45:352490 explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(
[email protected]a27cbde2013-03-23 22:01:492491 bool opaque_layers)
2492 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472493 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:492494 gfx::Transform scale_by_half;
2495 scale_by_half.Scale(0.5, 0.5);
2496
[email protected]66b52e12013-11-17 15:53:182497 // Make a 50x50 filtered surface that is completely occluded by an opaque
2498 // layer which is above it in the z-order. The surface is
[email protected]a27cbde2013-03-23 22:01:492499 // scaled to test that the pixel moving is done in the target space, where
[email protected]66b52e12013-11-17 15:53:182500 // the background filter is applied, but the surface appears at 50, 50.
[email protected]a27cbde2013-03-23 22:01:492501 typename Types::ContentLayerType* parent = this->CreateRoot(
[email protected]66b52e12013-11-17 15:53:182502 this->identity_matrix, gfx::PointF(), gfx::Size(200, 150));
[email protected]a27cbde2013-03-23 22:01:492503 typename Types::LayerType* filtered_surface =
2504 this->CreateDrawingLayer(parent,
2505 scale_by_half,
2506 gfx::PointF(50.f, 50.f),
2507 gfx::Size(100, 100),
2508 false);
[email protected]66b52e12013-11-17 15:53:182509 typename Types::LayerType* occluding_layer =
[email protected]a27cbde2013-03-23 22:01:492510 this->CreateDrawingLayer(parent,
2511 this->identity_matrix,
2512 gfx::PointF(50.f, 50.f),
2513 gfx::Size(50, 50),
2514 true);
[email protected]a27cbde2013-03-23 22:01:492515
2516 // Filters make the layer own a surface.
awoloszyne83f28c2014-12-22 15:40:002517 Types::SetForceRenderSurface(filtered_surface, true);
[email protected]ae6b1a72013-06-25 18:49:292518 FilterOperations filters;
2519 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:492520 filtered_surface->SetBackgroundFilters(filters);
2521
2522 this->CalcDrawEtc(parent);
2523
[email protected]34ba1ffb2014-03-05 06:55:032524 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492525 gfx::Rect(0, 0, 1000, 1000));
2526
[email protected]66b52e12013-11-17 15:53:182527 this->VisitLayer(occluding_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492528
[email protected]d002dd02013-03-27 07:40:402529 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142530 {
[email protected]a27cbde2013-03-23 22:01:492531 // The layers above the filtered surface occlude from outside.
2532 gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50);
[email protected]94f206c12012-08-25 00:09:142533
[email protected]a27cbde2013-03-23 22:01:492534 EXPECT_EQ(gfx::Rect().ToString(),
2535 occlusion.occlusion_from_inside_target().ToString());
[email protected]66b52e12013-11-17 15:53:182536 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:492537 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142538 }
[email protected]a27cbde2013-03-23 22:01:492539
2540 // The surface has a background blur, so it blurs non-opaque pixels below
2541 // it.
[email protected]d002dd02013-03-27 07:40:402542 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492543 {
2544 // The filter is completely occluded, so it should not blur anything and
2545 // reduce any occlusion.
2546 gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50);
[email protected]a27cbde2013-03-23 22:01:492547
[email protected]66b52e12013-11-17 15:53:182548 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:492549 occlusion.occlusion_from_inside_target().ToString());
2550 EXPECT_EQ(gfx::Rect().ToString(),
2551 occlusion.occlusion_from_outside_target().ToString());
2552 }
2553 }
[email protected]94f206c12012-08-25 00:09:142554};
2555
[email protected]a27cbde2013-03-23 22:01:492556ALL_OCCLUSIONTRACKER_TEST(
2557 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:142558
[email protected]a27cbde2013-03-23 22:01:492559template <class Types>
[email protected]ca2902e92013-03-28 01:45:352560class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded
2561 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492562 protected:
[email protected]ca2902e92013-03-28 01:45:352563 explicit
[email protected]a27cbde2013-03-23 22:01:492564 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded(
2565 bool opaque_layers)
2566 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472567 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:492568 gfx::Transform scale_by_half;
2569 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142570
[email protected]a27cbde2013-03-23 22:01:492571 // Make a surface and its replica, each 50x50, that are partially occluded
2572 // by opaque layers which are above them in the z-order. The surface is
2573 // scaled to test that the pixel moving is done in the target space, where
2574 // the background filter is applied, but the surface appears at 50, 50 and
2575 // the replica at 200, 50.
2576 typename Types::ContentLayerType* parent = this->CreateRoot(
2577 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
2578 typename Types::LayerType* filtered_surface =
2579 this->CreateDrawingLayer(parent,
2580 scale_by_half,
2581 gfx::PointF(50.f, 50.f),
2582 gfx::Size(100, 100),
2583 false);
2584 this->CreateReplicaLayer(filtered_surface,
2585 this->identity_matrix,
2586 gfx::PointF(300.f, 0.f),
2587 gfx::Size());
2588 typename Types::LayerType* above_surface_layer =
2589 this->CreateDrawingLayer(parent,
2590 this->identity_matrix,
2591 gfx::PointF(70.f, 50.f),
2592 gfx::Size(30, 50),
2593 true);
2594 typename Types::LayerType* above_replica_layer =
2595 this->CreateDrawingLayer(parent,
2596 this->identity_matrix,
2597 gfx::PointF(200.f, 50.f),
2598 gfx::Size(30, 50),
2599 true);
2600 typename Types::LayerType* beside_surface_layer =
2601 this->CreateDrawingLayer(parent,
2602 this->identity_matrix,
2603 gfx::PointF(90.f, 40.f),
2604 gfx::Size(10, 10),
2605 true);
2606 typename Types::LayerType* beside_replica_layer =
2607 this->CreateDrawingLayer(parent,
2608 this->identity_matrix,
2609 gfx::PointF(200.f, 40.f),
2610 gfx::Size(10, 10),
2611 true);
[email protected]94f206c12012-08-25 00:09:142612
[email protected]a27cbde2013-03-23 22:01:492613 // Filters make the layer own a surface.
awoloszyne83f28c2014-12-22 15:40:002614 Types::SetForceRenderSurface(filtered_surface, true);
[email protected]ae6b1a72013-06-25 18:49:292615 FilterOperations filters;
2616 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:492617 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142618
[email protected]a27cbde2013-03-23 22:01:492619 // Save the distance of influence for the blur effect.
2620 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:292621 filters.GetOutsets(
2622 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:142623
[email protected]a27cbde2013-03-23 22:01:492624 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142625
[email protected]34ba1ffb2014-03-05 06:55:032626 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492627 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142628
[email protected]d002dd02013-03-27 07:40:402629 this->VisitLayer(beside_replica_layer, &occlusion);
2630 this->VisitLayer(beside_surface_layer, &occlusion);
2631 this->VisitLayer(above_replica_layer, &occlusion);
2632 this->VisitLayer(above_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:142633
[email protected]a27cbde2013-03-23 22:01:492634 // The surface has a background blur, so it blurs non-opaque pixels below
2635 // it.
[email protected]d002dd02013-03-27 07:40:402636 this->VisitLayer(filtered_surface, &occlusion);
2637 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142638
[email protected]a27cbde2013-03-23 22:01:492639 // The filter in the surface and replica are partially unoccluded. Only the
2640 // unoccluded parts should reduce occlusion. This means it will push back
[email protected]ed511b8d2013-03-25 03:29:292641 // the occlusion that touches the unoccluded part (occlusion_above___), but
[email protected]a27cbde2013-03-23 22:01:492642 // it will not touch occlusion_beside____ since that is not beside the
2643 // unoccluded part of the surface, even though it is beside the occluded
2644 // part of the surface.
2645 gfx::Rect occlusion_above_surface =
2646 gfx::Rect(70 + outset_right, 50, 30 - outset_right, 50);
2647 gfx::Rect occlusion_above_replica =
2648 gfx::Rect(200, 50, 30 - outset_left, 50);
2649 gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10);
2650 gfx::Rect occlusion_beside_replica = gfx::Rect(200, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:142651
[email protected]d5467eb72014-08-22 01:16:432652 SimpleEnclosedRegion expected_occlusion;
[email protected]a27cbde2013-03-23 22:01:492653 expected_occlusion.Union(occlusion_beside_replica);
[email protected]d5467eb72014-08-22 01:16:432654 expected_occlusion.Union(occlusion_beside_surface);
2655 expected_occlusion.Union(occlusion_above_replica);
2656 expected_occlusion.Union(occlusion_above_surface);
[email protected]94f206c12012-08-25 00:09:142657
[email protected]d5467eb72014-08-22 01:16:432658 EXPECT_EQ(expected_occlusion.ToString(),
[email protected]a27cbde2013-03-23 22:01:492659 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432660 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142661
[email protected]d5467eb72014-08-22 01:16:432662 const SimpleEnclosedRegion& actual_occlusion =
2663 occlusion.occlusion_from_inside_target();
2664 for (size_t i = 0; i < expected_occlusion.GetRegionComplexity(); ++i) {
2665 ASSERT_LT(i, actual_occlusion.GetRegionComplexity());
2666 EXPECT_EQ(expected_occlusion.GetRect(i), actual_occlusion.GetRect(i));
[email protected]94f206c12012-08-25 00:09:142667 }
[email protected]a27cbde2013-03-23 22:01:492668 }
[email protected]94f206c12012-08-25 00:09:142669};
2670
[email protected]a27cbde2013-03-23 22:01:492671ALL_OCCLUSIONTRACKER_TEST(
2672 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:142673
[email protected]a27cbde2013-03-23 22:01:492674template <class Types>
[email protected]ca2902e92013-03-28 01:45:352675class OcclusionTrackerTestMinimumTrackingSize
2676 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492677 protected:
[email protected]ca2902e92013-03-28 01:45:352678 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492679 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472680 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:492681 gfx::Size tracking_size(100, 100);
2682 gfx::Size below_tracking_size(99, 99);
[email protected]94f206c12012-08-25 00:09:142683
[email protected]a27cbde2013-03-23 22:01:492684 typename Types::ContentLayerType* parent = this->CreateRoot(
2685 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
2686 typename Types::LayerType* large = this->CreateDrawingLayer(
2687 parent, this->identity_matrix, gfx::PointF(), tracking_size, true);
2688 typename Types::LayerType* small =
2689 this->CreateDrawingLayer(parent,
2690 this->identity_matrix,
2691 gfx::PointF(),
2692 below_tracking_size,
2693 true);
2694 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142695
[email protected]34ba1ffb2014-03-05 06:55:032696 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492697 gfx::Rect(0, 0, 1000, 1000));
2698 occlusion.set_minimum_tracking_size(tracking_size);
[email protected]94f206c12012-08-25 00:09:142699
[email protected]a27cbde2013-03-23 22:01:492700 // The small layer is not tracked because it is too small.
[email protected]d002dd02013-03-27 07:40:402701 this->VisitLayer(small, &occlusion);
[email protected]94f206c12012-08-25 00:09:142702
[email protected]a27cbde2013-03-23 22:01:492703 EXPECT_EQ(gfx::Rect().ToString(),
2704 occlusion.occlusion_from_outside_target().ToString());
2705 EXPECT_EQ(gfx::Rect().ToString(),
2706 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142707
[email protected]a27cbde2013-03-23 22:01:492708 // The large layer is tracked as it is large enough.
[email protected]d002dd02013-03-27 07:40:402709 this->VisitLayer(large, &occlusion);
[email protected]94f206c12012-08-25 00:09:142710
[email protected]a27cbde2013-03-23 22:01:492711 EXPECT_EQ(gfx::Rect().ToString(),
2712 occlusion.occlusion_from_outside_target().ToString());
[email protected]2c7c6702013-03-26 03:14:052713 EXPECT_EQ(gfx::Rect(tracking_size).ToString(),
[email protected]a27cbde2013-03-23 22:01:492714 occlusion.occlusion_from_inside_target().ToString());
2715 }
[email protected]94f206c12012-08-25 00:09:142716};
2717
[email protected]96baf3e2012-10-22 23:09:552718ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:142719
[email protected]a27cbde2013-03-23 22:01:492720template <class Types>
[email protected]1a5d9ce2013-04-30 01:31:092721class OcclusionTrackerTestScaledLayerIsClipped
2722 : public OcclusionTrackerTest<Types> {
2723 protected:
2724 explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers)
2725 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472726 void RunMyTest() override {
[email protected]1a5d9ce2013-04-30 01:31:092727 gfx::Transform scale_transform;
2728 scale_transform.Scale(512.0, 512.0);
2729
2730 typename Types::ContentLayerType* parent = this->CreateRoot(
2731 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
2732 typename Types::LayerType* clip = this->CreateLayer(parent,
2733 this->identity_matrix,
2734 gfx::PointF(10.f, 10.f),
2735 gfx::Size(50, 50));
2736 clip->SetMasksToBounds(true);
2737 typename Types::LayerType* scale = this->CreateLayer(
2738 clip, scale_transform, gfx::PointF(), gfx::Size(1, 1));
2739 typename Types::LayerType* scaled = this->CreateDrawingLayer(
2740 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
2741 this->CalcDrawEtc(parent);
2742
[email protected]34ba1ffb2014-03-05 06:55:032743 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]1a5d9ce2013-04-30 01:31:092744 gfx::Rect(0, 0, 1000, 1000));
2745
2746 this->VisitLayer(scaled, &occlusion);
2747
2748 EXPECT_EQ(gfx::Rect().ToString(),
2749 occlusion.occlusion_from_outside_target().ToString());
2750 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
2751 occlusion.occlusion_from_inside_target().ToString());
2752 }
2753};
2754
2755ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped)
2756
2757template <class Types>
2758class OcclusionTrackerTestScaledLayerInSurfaceIsClipped
2759 : public OcclusionTrackerTest<Types> {
2760 protected:
2761 explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers)
2762 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472763 void RunMyTest() override {
[email protected]1a5d9ce2013-04-30 01:31:092764 gfx::Transform scale_transform;
2765 scale_transform.Scale(512.0, 512.0);
2766
2767 typename Types::ContentLayerType* parent = this->CreateRoot(
2768 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
2769 typename Types::LayerType* clip = this->CreateLayer(parent,
2770 this->identity_matrix,
2771 gfx::PointF(10.f, 10.f),
2772 gfx::Size(50, 50));
2773 clip->SetMasksToBounds(true);
2774 typename Types::LayerType* surface = this->CreateDrawingSurface(
2775 clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false);
2776 typename Types::LayerType* scale = this->CreateLayer(
2777 surface, scale_transform, gfx::PointF(), gfx::Size(1, 1));
2778 typename Types::LayerType* scaled = this->CreateDrawingLayer(
2779 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
2780 this->CalcDrawEtc(parent);
2781
[email protected]34ba1ffb2014-03-05 06:55:032782 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]1a5d9ce2013-04-30 01:31:092783 gfx::Rect(0, 0, 1000, 1000));
2784
2785 this->VisitLayer(scaled, &occlusion);
2786 this->VisitLayer(surface, &occlusion);
2787 this->VisitContributingSurface(surface, &occlusion);
2788
2789 EXPECT_EQ(gfx::Rect().ToString(),
2790 occlusion.occlusion_from_outside_target().ToString());
2791 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
2792 occlusion.occlusion_from_inside_target().ToString());
2793 }
2794};
2795
2796ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped)
2797
[email protected]5b54b972013-07-26 13:25:422798template <class Types>
2799class OcclusionTrackerTestCopyRequestDoesOcclude
2800 : public OcclusionTrackerTest<Types> {
2801 protected:
2802 explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers)
2803 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472804 void RunMyTest() override {
[email protected]5b54b972013-07-26 13:25:422805 typename Types::ContentLayerType* root = this->CreateRoot(
2806 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
2807 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
2808 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
2809 typename Types::LayerType* copy = this->CreateLayer(parent,
2810 this->identity_matrix,
2811 gfx::Point(100, 0),
2812 gfx::Size(200, 400));
2813 this->AddCopyRequest(copy);
2814 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
2815 copy,
2816 this->identity_matrix,
2817 gfx::PointF(),
2818 gfx::Size(200, 400),
2819 true);
2820 this->CalcDrawEtc(root);
2821
[email protected]34ba1ffb2014-03-05 06:55:032822 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]5b54b972013-07-26 13:25:422823 gfx::Rect(0, 0, 1000, 1000));
2824
2825 this->VisitLayer(copy_child, &occlusion);
2826 EXPECT_EQ(gfx::Rect().ToString(),
2827 occlusion.occlusion_from_outside_target().ToString());
2828 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
2829 occlusion.occlusion_from_inside_target().ToString());
2830
2831 // CopyRequests cause the layer to own a surface.
2832 this->VisitContributingSurface(copy, &occlusion);
2833
2834 // The occlusion from the copy should be kept.
2835 EXPECT_EQ(gfx::Rect().ToString(),
2836 occlusion.occlusion_from_outside_target().ToString());
2837 EXPECT_EQ(gfx::Rect(100, 0, 200, 400).ToString(),
2838 occlusion.occlusion_from_inside_target().ToString());
2839 }
2840};
2841
2842ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude)
2843
2844template <class Types>
2845class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude
2846 : public OcclusionTrackerTest<Types> {
2847 protected:
2848 explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude(
2849 bool opaque_layers)
2850 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472851 void RunMyTest() override {
[email protected]5b54b972013-07-26 13:25:422852 typename Types::ContentLayerType* root = this->CreateRoot(
2853 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
2854 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
2855 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
2856 typename Types::LayerType* hide = this->CreateLayer(
2857 parent, this->identity_matrix, gfx::Point(), gfx::Size());
2858 typename Types::LayerType* copy = this->CreateLayer(
2859 hide, this->identity_matrix, gfx::Point(100, 0), gfx::Size(200, 400));
2860 this->AddCopyRequest(copy);
2861 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
2862 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
2863
2864 // The |copy| layer is hidden but since it is being copied, it will be
2865 // drawn.
2866 hide->SetHideLayerAndSubtree(true);
2867
2868 this->CalcDrawEtc(root);
2869
[email protected]34ba1ffb2014-03-05 06:55:032870 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]5b54b972013-07-26 13:25:422871 gfx::Rect(0, 0, 1000, 1000));
2872
2873 this->VisitLayer(copy_child, &occlusion);
2874 EXPECT_EQ(gfx::Rect().ToString(),
2875 occlusion.occlusion_from_outside_target().ToString());
2876 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
2877 occlusion.occlusion_from_inside_target().ToString());
2878
2879 // CopyRequests cause the layer to own a surface.
2880 this->VisitContributingSurface(copy, &occlusion);
2881
2882 // The occlusion from the copy should be dropped since it is hidden.
2883 EXPECT_EQ(gfx::Rect().ToString(),
2884 occlusion.occlusion_from_outside_target().ToString());
2885 EXPECT_EQ(gfx::Rect().ToString(),
2886 occlusion.occlusion_from_inside_target().ToString());
2887 }
2888};
2889
2890ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude)
2891
[email protected]d5467eb72014-08-22 01:16:432892template <class Types>
2893class OcclusionTrackerTestOccludedLayer : public OcclusionTrackerTest<Types> {
2894 protected:
2895 explicit OcclusionTrackerTestOccludedLayer(bool opaque_layers)
2896 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472897 void RunMyTest() override {
[email protected]d5467eb72014-08-22 01:16:432898 gfx::Transform translate;
2899 translate.Translate(10.0, 20.0);
2900 typename Types::ContentLayerType* root = this->CreateRoot(
2901 this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2902 typename Types::LayerType* surface = this->CreateSurface(
2903 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2904 typename Types::LayerType* layer = this->CreateDrawingLayer(
2905 surface, translate, gfx::Point(), gfx::Size(200, 200), false);
2906 typename Types::ContentLayerType* outside_layer = this->CreateDrawingLayer(
2907 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), false);
2908 this->CalcDrawEtc(root);
2909
2910 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2911 gfx::Rect(0, 0, 200, 200));
2912 this->VisitLayer(outside_layer, &occlusion);
2913 this->EnterLayer(layer, &occlusion);
2914
2915 // No occlusion, is not occluded.
2916 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2917 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2918 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100)));
2919
2920 // Partial occlusion from outside, is not occluded.
2921 occlusion.set_occlusion_from_outside_target(
2922 SimpleEnclosedRegion(50, 50, 100, 100));
2923 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2924 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2925 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2926 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2927 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2928 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2929 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2930 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2931 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2932
2933 // Full occlusion from outside, is occluded.
2934 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2935 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2936 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2937 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2938
2939 // Partial occlusion from inside, is not occluded.
2940 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2941 occlusion.set_occlusion_from_inside_target(
2942 SimpleEnclosedRegion(50, 50, 100, 100));
2943 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2944 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2945 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2946 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2947 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2948 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2949 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2950 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2951
2952 // Full occlusion from inside, is occluded.
2953 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2954 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2955 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2956 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2957
2958 // Partial occlusion from both, is not occluded.
2959 occlusion.set_occlusion_from_outside_target(
2960 SimpleEnclosedRegion(50, 50, 100, 50));
2961 occlusion.set_occlusion_from_inside_target(
2962 SimpleEnclosedRegion(50, 100, 100, 50));
2963 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2964 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2965 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2966 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2967 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2968 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2969 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2970 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2971
2972 // Full occlusion from both, is occluded.
2973 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2974 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2975 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2976 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2977 }
2978};
2979
2980ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOccludedLayer)
2981
danakjf080b5b2014-08-23 22:18:202982template <class Types>
2983class OcclusionTrackerTestUnoccludedLayerQuery
2984 : public OcclusionTrackerTest<Types> {
2985 protected:
2986 explicit OcclusionTrackerTestUnoccludedLayerQuery(bool opaque_layers)
2987 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472988 void RunMyTest() override {
danakjf080b5b2014-08-23 22:18:202989 gfx::Transform translate;
2990 translate.Translate(10.0, 20.0);
2991 typename Types::ContentLayerType* root = this->CreateRoot(
2992 this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2993 typename Types::LayerType* surface = this->CreateSurface(
2994 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2995 typename Types::LayerType* layer = this->CreateDrawingLayer(
2996 surface, translate, gfx::Point(), gfx::Size(200, 200), false);
2997 typename Types::ContentLayerType* outside_layer = this->CreateDrawingLayer(
2998 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), false);
2999 this->CalcDrawEtc(root);
3000
3001 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
3002 gfx::Rect(0, 0, 200, 200));
3003 this->VisitLayer(outside_layer, &occlusion);
3004 this->EnterLayer(layer, &occlusion);
3005
3006 // No occlusion, is not occluded.
3007 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
3008 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
3009 EXPECT_EQ(gfx::Rect(100, 100),
3010 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(100, 100)));
3011
3012 // Partial occlusion from outside.
3013 occlusion.set_occlusion_from_outside_target(
3014 SimpleEnclosedRegion(50, 50, 100, 100));
3015 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
3016 EXPECT_EQ(
3017 gfx::Rect(0, 0, 100, 100),
3018 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
3019 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3020 occlusion.UnoccludedLayerContentRect(
3021 layer, gfx::Rect(90, 30, 100, 100)));
3022 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3023 occlusion.UnoccludedLayerContentRect(layer,
3024 gfx::Rect(40, 0, 100, 100)));
3025 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3026 occlusion.UnoccludedLayerContentRect(
3027 layer, gfx::Rect(40, 80, 100, 100)));
3028 EXPECT_EQ(
3029 gfx::Rect(0, 0, 80, 100),
3030 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
3031 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3032 occlusion.UnoccludedLayerContentRect(
3033 layer, gfx::Rect(90, 80, 100, 100)));
3034 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3035 occlusion.UnoccludedLayerContentRect(layer,
3036 gfx::Rect(0, 80, 100, 100)));
3037 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3038 occlusion.UnoccludedLayerContentRect(layer,
3039 gfx::Rect(90, 0, 100, 100)));
3040
3041 // Full occlusion from outside, is occluded.
3042 EXPECT_EQ(gfx::Rect(),
3043 occlusion.UnoccludedLayerContentRect(
3044 layer, gfx::Rect(40, 30, 100, 100)));
3045 EXPECT_EQ(
3046 gfx::Rect(),
3047 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
3048 EXPECT_EQ(gfx::Rect(),
3049 occlusion.UnoccludedLayerContentRect(
3050 layer, gfx::Rect(130, 120, 10, 10)));
3051 EXPECT_EQ(
3052 gfx::Rect(),
3053 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
3054
3055 // Partial occlusion from inside, is not occluded.
3056 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
3057 occlusion.set_occlusion_from_inside_target(
3058 SimpleEnclosedRegion(50, 50, 100, 100));
3059 EXPECT_EQ(
3060 gfx::Rect(0, 0, 100, 100),
3061 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
3062 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3063 occlusion.UnoccludedLayerContentRect(
3064 layer, gfx::Rect(90, 30, 100, 100)));
3065 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3066 occlusion.UnoccludedLayerContentRect(layer,
3067 gfx::Rect(40, 0, 100, 100)));
3068 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3069 occlusion.UnoccludedLayerContentRect(
3070 layer, gfx::Rect(40, 80, 100, 100)));
3071 EXPECT_EQ(
3072 gfx::Rect(0, 0, 80, 100),
3073 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
3074 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3075 occlusion.UnoccludedLayerContentRect(
3076 layer, gfx::Rect(90, 80, 100, 100)));
3077 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3078 occlusion.UnoccludedLayerContentRect(layer,
3079 gfx::Rect(0, 80, 100, 100)));
3080 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3081 occlusion.UnoccludedLayerContentRect(layer,
3082 gfx::Rect(90, 0, 100, 100)));
3083
3084 // Full occlusion from inside, is occluded.
3085 EXPECT_EQ(gfx::Rect(),
3086 occlusion.UnoccludedLayerContentRect(
3087 layer, gfx::Rect(40, 30, 100, 100)));
3088 EXPECT_EQ(
3089 gfx::Rect(),
3090 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
3091 EXPECT_EQ(gfx::Rect(),
3092 occlusion.UnoccludedLayerContentRect(
3093 layer, gfx::Rect(130, 120, 10, 10)));
3094 EXPECT_EQ(
3095 gfx::Rect(),
3096 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
3097
3098 // Partial occlusion from both, is not occluded.
3099 occlusion.set_occlusion_from_outside_target(
3100 SimpleEnclosedRegion(50, 50, 100, 50));
3101 occlusion.set_occlusion_from_inside_target(
3102 SimpleEnclosedRegion(50, 100, 100, 50));
3103 EXPECT_EQ(
3104 gfx::Rect(0, 0, 100, 100),
3105 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
3106 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
3107 // it's larger.
3108 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
3109 occlusion.UnoccludedLayerContentRect(
3110 layer, gfx::Rect(90, 30, 100, 100)));
3111 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3112 occlusion.UnoccludedLayerContentRect(layer,
3113 gfx::Rect(40, 0, 100, 100)));
3114 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3115 occlusion.UnoccludedLayerContentRect(
3116 layer, gfx::Rect(40, 80, 100, 100)));
3117 EXPECT_EQ(
3118 gfx::Rect(0, 0, 80, 100),
3119 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
3120 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3121 occlusion.UnoccludedLayerContentRect(
3122 layer, gfx::Rect(90, 80, 100, 100)));
3123 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3124 occlusion.UnoccludedLayerContentRect(layer,
3125 gfx::Rect(0, 80, 100, 100)));
3126 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3127 occlusion.UnoccludedLayerContentRect(layer,
3128 gfx::Rect(90, 0, 100, 100)));
3129
3130 // Full occlusion from both, is occluded.
3131 EXPECT_EQ(gfx::Rect(),
3132 occlusion.UnoccludedLayerContentRect(
3133 layer, gfx::Rect(40, 30, 100, 100)));
3134 EXPECT_EQ(
3135 gfx::Rect(),
3136 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
3137 EXPECT_EQ(gfx::Rect(),
3138 occlusion.UnoccludedLayerContentRect(
3139 layer, gfx::Rect(130, 120, 10, 10)));
3140 EXPECT_EQ(
3141 gfx::Rect(),
3142 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
3143 }
3144};
3145
3146ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedLayerQuery)
3147
3148template <class Types>
3149class OcclusionTrackerTestUnoccludedSurfaceQuery
3150 : public OcclusionTrackerTest<Types> {
3151 protected:
3152 explicit OcclusionTrackerTestUnoccludedSurfaceQuery(bool opaque_layers)
3153 : OcclusionTrackerTest<Types>(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:473154 void RunMyTest() override {
danakjf080b5b2014-08-23 22:18:203155 gfx::Transform translate;
3156 translate.Translate(10.0, 20.0);
3157 typename Types::ContentLayerType* root = this->CreateRoot(
3158 this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
3159 typename Types::LayerType* surface =
3160 this->CreateSurface(root, translate, gfx::Point(), gfx::Size(200, 200));
3161 typename Types::LayerType* layer =
3162 this->CreateDrawingLayer(surface,
3163 this->identity_matrix,
3164 gfx::Point(),
3165 gfx::Size(200, 200),
3166 false);
3167 typename Types::ContentLayerType* outside_layer = this->CreateDrawingLayer(
3168 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), false);
3169 this->CalcDrawEtc(root);
3170
3171 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
3172 gfx::Rect(0, 0, 200, 200));
3173 this->VisitLayer(outside_layer, &occlusion);
3174 this->VisitLayer(layer, &occlusion);
3175 this->EnterContributingSurface(surface, &occlusion);
3176
3177 // No occlusion, is not occluded.
3178 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3179 SimpleEnclosedRegion());
3180 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3181 SimpleEnclosedRegion());
3182 EXPECT_EQ(
3183 gfx::Rect(100, 100),
3184 occlusion.UnoccludedSurfaceContentRect(surface, gfx::Rect(100, 100)));
3185
3186 // Partial occlusion from outside.
3187 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3188 SimpleEnclosedRegion(50, 50, 100, 100));
3189 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3190 SimpleEnclosedRegion());
3191 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3192 occlusion.UnoccludedSurfaceContentRect(
3193 surface, gfx::Rect(0, 0, 100, 100)));
3194 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3195 occlusion.UnoccludedSurfaceContentRect(
3196 surface, gfx::Rect(90, 30, 100, 100)));
3197 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3198 occlusion.UnoccludedSurfaceContentRect(
3199 surface, gfx::Rect(40, 0, 100, 100)));
3200 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3201 occlusion.UnoccludedSurfaceContentRect(
3202 surface, gfx::Rect(40, 80, 100, 100)));
3203 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
3204 occlusion.UnoccludedSurfaceContentRect(surface,
3205 gfx::Rect(0, 0, 80, 100)));
3206 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3207 occlusion.UnoccludedSurfaceContentRect(
3208 surface, gfx::Rect(90, 80, 100, 100)));
3209 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3210 occlusion.UnoccludedSurfaceContentRect(
3211 surface, gfx::Rect(0, 80, 100, 100)));
3212 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3213 occlusion.UnoccludedSurfaceContentRect(
3214 surface, gfx::Rect(90, 0, 100, 100)));
3215
3216 // Full occlusion from outside, is occluded.
3217 EXPECT_EQ(gfx::Rect(),
3218 occlusion.UnoccludedSurfaceContentRect(
3219 surface, gfx::Rect(40, 30, 100, 100)));
3220 EXPECT_EQ(gfx::Rect(),
3221 occlusion.UnoccludedSurfaceContentRect(
3222 surface, gfx::Rect(40, 30, 10, 10)));
3223 EXPECT_EQ(gfx::Rect(),
3224 occlusion.UnoccludedSurfaceContentRect(
3225 surface, gfx::Rect(130, 120, 10, 10)));
3226 EXPECT_EQ(gfx::Rect(),
3227 occlusion.UnoccludedSurfaceContentRect(
3228 surface, gfx::Rect(80, 70, 50, 50)));
3229
3230 // Partial occlusion from inside, is not occluded.
3231 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3232 SimpleEnclosedRegion());
3233 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3234 SimpleEnclosedRegion(50, 50, 100, 100));
3235 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3236 occlusion.UnoccludedSurfaceContentRect(
3237 surface, gfx::Rect(0, 0, 100, 100)));
3238 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3239 occlusion.UnoccludedSurfaceContentRect(
3240 surface, gfx::Rect(90, 30, 100, 100)));
3241 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3242 occlusion.UnoccludedSurfaceContentRect(
3243 surface, gfx::Rect(40, 0, 100, 100)));
3244 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3245 occlusion.UnoccludedSurfaceContentRect(
3246 surface, gfx::Rect(40, 80, 100, 100)));
3247 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
3248 occlusion.UnoccludedSurfaceContentRect(surface,
3249 gfx::Rect(0, 0, 80, 100)));
3250 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3251 occlusion.UnoccludedSurfaceContentRect(
3252 surface, gfx::Rect(90, 80, 100, 100)));
3253 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3254 occlusion.UnoccludedSurfaceContentRect(
3255 surface, gfx::Rect(0, 80, 100, 100)));
3256 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3257 occlusion.UnoccludedSurfaceContentRect(
3258 surface, gfx::Rect(90, 0, 100, 100)));
3259
3260 // Full occlusion from inside, is occluded.
3261 EXPECT_EQ(gfx::Rect(),
3262 occlusion.UnoccludedSurfaceContentRect(
3263 surface, gfx::Rect(40, 30, 100, 100)));
3264 EXPECT_EQ(gfx::Rect(),
3265 occlusion.UnoccludedSurfaceContentRect(
3266 surface, gfx::Rect(40, 30, 10, 10)));
3267 EXPECT_EQ(gfx::Rect(),
3268 occlusion.UnoccludedSurfaceContentRect(
3269 surface, gfx::Rect(130, 120, 10, 10)));
3270 EXPECT_EQ(gfx::Rect(),
3271 occlusion.UnoccludedSurfaceContentRect(
3272 surface, gfx::Rect(80, 70, 50, 50)));
3273
3274 // Partial occlusion from both, is not occluded.
3275 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3276 SimpleEnclosedRegion(50, 50, 100, 50));
3277 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3278 SimpleEnclosedRegion(50, 100, 100, 50));
3279 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3280 occlusion.UnoccludedSurfaceContentRect(
3281 surface, gfx::Rect(0, 0, 100, 100)));
3282 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
3283 // it's larger.
3284 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
3285 occlusion.UnoccludedSurfaceContentRect(
3286 surface, gfx::Rect(90, 30, 100, 100)));
3287 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3288 occlusion.UnoccludedSurfaceContentRect(
3289 surface, gfx::Rect(40, 0, 100, 100)));
3290 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3291 occlusion.UnoccludedSurfaceContentRect(
3292 surface, gfx::Rect(40, 80, 100, 100)));
3293 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
3294 occlusion.UnoccludedSurfaceContentRect(surface,
3295 gfx::Rect(0, 0, 80, 100)));
3296 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3297 occlusion.UnoccludedSurfaceContentRect(
3298 surface, gfx::Rect(90, 80, 100, 100)));
3299 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3300 occlusion.UnoccludedSurfaceContentRect(
3301 surface, gfx::Rect(0, 80, 100, 100)));
3302 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3303 occlusion.UnoccludedSurfaceContentRect(
3304 surface, gfx::Rect(90, 0, 100, 100)));
3305
3306 // Full occlusion from both, is occluded.
3307 EXPECT_EQ(gfx::Rect(),
3308 occlusion.UnoccludedSurfaceContentRect(
3309 surface, gfx::Rect(40, 30, 100, 100)));
3310 EXPECT_EQ(gfx::Rect(),
3311 occlusion.UnoccludedSurfaceContentRect(
3312 surface, gfx::Rect(40, 30, 10, 10)));
3313 EXPECT_EQ(gfx::Rect(),
3314 occlusion.UnoccludedSurfaceContentRect(
3315 surface, gfx::Rect(130, 120, 10, 10)));
3316 EXPECT_EQ(gfx::Rect(),
3317 occlusion.UnoccludedSurfaceContentRect(
3318 surface, gfx::Rect(80, 70, 50, 50)));
3319 }
3320};
3321
3322ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery)
3323
[email protected]ba565742012-11-10 09:29:483324} // namespace
3325} // namespace cc