blob: 6ab339723adb9a177d585f93f9f623d40f771c36 [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
mostynbf68776d82014-10-06 18:07:3736 virtual 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:
49 virtual ~TestContentLayer() {}
[email protected]d58499a2012-10-09 22:27:4750
[email protected]a27cbde2013-03-23 22:01:4951 bool override_opaque_contents_rect_;
52 gfx::Rect opaque_contents_rect_;
[email protected]94f206c12012-08-25 00:09:1453};
54
[email protected]96baf3e2012-10-22 23:09:5555class TestContentLayerImpl : public LayerImpl {
[email protected]a27cbde2013-03-23 22:01:4956 public:
57 TestContentLayerImpl(LayerTreeImpl* tree_impl, int id)
58 : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) {
59 SetDrawsContent(true);
60 }
[email protected]94f206c12012-08-25 00:09:1461
mostynbf68776d82014-10-06 18:07:3762 virtual 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();
danakjf080b5b2014-08-23 22:18:20104 return this->UnoccludedContributingSurfaceContentRect(
105 content_rect, surface->draw_transform());
[email protected]e312aca2014-03-20 22:11:55106 }
[email protected]94f206c12012-08-25 00:09:14107};
108
[email protected]96baf3e2012-10-22 23:09:55109struct OcclusionTrackerTestMainThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49110 typedef Layer LayerType;
[email protected]d600df7d2013-08-03 02:34:28111 typedef FakeLayerTreeHost HostType;
[email protected]a27cbde2013-03-23 22:01:49112 typedef RenderSurface RenderSurfaceType;
113 typedef TestContentLayer ContentLayerType;
114 typedef scoped_refptr<Layer> LayerPtrType;
115 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
[email protected]ba1b33e2014-02-28 16:44:51116 typedef LayerIterator<Layer> TestLayerIterator;
[email protected]34ba1ffb2014-03-05 06:55:03117 typedef OcclusionTracker<Layer> OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14118
[email protected]a27cbde2013-03-23 22:01:49119 static LayerPtrType CreateLayer(HostType* host) { return Layer::Create(); }
120 static ContentLayerPtrType CreateContentLayer(HostType* host) {
121 return make_scoped_refptr(new ContentLayerType());
122 }
[email protected]e0bd43a2012-10-12 16:54:21123
danakjf446a072014-09-27 21:55:48124 template <typename T>
125 static LayerPtrType PassLayerPtr(T* layer) {
[email protected]a27cbde2013-03-23 22:01:49126 LayerPtrType ref(*layer);
127 *layer = NULL;
128 return ref;
129 }
[email protected]d58499a2012-10-09 22:27:47130
[email protected]a27cbde2013-03-23 22:01:49131 static void DestroyLayer(LayerPtrType* layer) { *layer = NULL; }
[email protected]ad63b2f2014-08-11 17:39:54132
133 static void RecursiveUpdateNumChildren(LayerType* layerType) {}
[email protected]94f206c12012-08-25 00:09:14134};
135
[email protected]96baf3e2012-10-22 23:09:55136struct OcclusionTrackerTestImplThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49137 typedef LayerImpl LayerType;
138 typedef LayerTreeImpl HostType;
139 typedef RenderSurfaceImpl RenderSurfaceType;
140 typedef TestContentLayerImpl ContentLayerType;
141 typedef scoped_ptr<LayerImpl> LayerPtrType;
142 typedef scoped_ptr<ContentLayerType> ContentLayerPtrType;
[email protected]ba1b33e2014-02-28 16:44:51143 typedef LayerIterator<LayerImpl> TestLayerIterator;
[email protected]34ba1ffb2014-03-05 06:55:03144 typedef OcclusionTracker<LayerImpl> OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14145
[email protected]a27cbde2013-03-23 22:01:49146 static LayerPtrType CreateLayer(HostType* host) {
147 return LayerImpl::Create(host, next_layer_impl_id++);
148 }
149 static ContentLayerPtrType CreateContentLayer(HostType* host) {
150 return make_scoped_ptr(new ContentLayerType(host, next_layer_impl_id++));
151 }
152 static int next_layer_impl_id;
[email protected]d58499a2012-10-09 22:27:47153
danakjf446a072014-09-27 21:55:48154 template <typename T>
155 static LayerPtrType PassLayerPtr(T* layer) {
[email protected]a27cbde2013-03-23 22:01:49156 return layer->Pass();
157 }
[email protected]e0bd43a2012-10-12 16:54:21158
[email protected]a27cbde2013-03-23 22:01:49159 static void DestroyLayer(LayerPtrType* layer) { layer->reset(); }
[email protected]ad63b2f2014-08-11 17:39:54160
161 static void RecursiveUpdateNumChildren(LayerType* layer) {
162 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(layer);
163 }
[email protected]94f206c12012-08-25 00:09:14164};
165
[email protected]a27cbde2013-03-23 22:01:49166int OcclusionTrackerTestImplThreadTypes::next_layer_impl_id = 1;
[email protected]94f206c12012-08-25 00:09:14167
[email protected]a27cbde2013-03-23 22:01:49168template <typename Types> class OcclusionTrackerTest : public testing::Test {
169 protected:
[email protected]ca2902e92013-03-28 01:45:35170 explicit OcclusionTrackerTest(bool opaque_layers)
enne2097cab2014-09-25 20:16:31171 : opaque_layers_(opaque_layers),
172 client_(FakeLayerTreeHostClient::DIRECT_3D),
173 host_(FakeLayerTreeHost::Create(&client_)) {}
[email protected]a27cbde2013-03-23 22:01:49174
175 virtual void RunMyTest() = 0;
176
[email protected]d5467eb72014-08-22 01:16:43177 virtual void TearDown() { DestroyLayers(); }
[email protected]a27cbde2013-03-23 22:01:49178
179 typename Types::HostType* GetHost();
180
181 typename Types::ContentLayerType* CreateRoot(const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47182 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26183 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49184 typename Types::ContentLayerPtrType layer(
185 Types::CreateContentLayer(GetHost()));
186 typename Types::ContentLayerType* layer_ptr = layer.get();
187 SetProperties(layer_ptr, transform, position, bounds);
188
[email protected]22898ed2013-06-01 04:52:30189 DCHECK(!root_.get());
[email protected]a27cbde2013-03-23 22:01:49190 root_ = Types::PassLayerPtr(&layer);
[email protected]d600df7d2013-08-03 02:34:28191
192 SetRootLayerOnMainThread(layer_ptr);
193
[email protected]a27cbde2013-03-23 22:01:49194 return layer_ptr;
195 }
196
197 typename Types::LayerType* CreateLayer(typename Types::LayerType* parent,
198 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47199 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26200 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49201 typename Types::LayerPtrType layer(Types::CreateLayer(GetHost()));
202 typename Types::LayerType* layer_ptr = layer.get();
203 SetProperties(layer_ptr, transform, position, bounds);
204 parent->AddChild(Types::PassLayerPtr(&layer));
205 return layer_ptr;
206 }
207
208 typename Types::LayerType* CreateSurface(typename Types::LayerType* parent,
209 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47210 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26211 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49212 typename Types::LayerType* layer =
213 CreateLayer(parent, transform, position, bounds);
214 layer->SetForceRenderSurface(true);
215 return layer;
216 }
217
218 typename Types::ContentLayerType* CreateDrawingLayer(
219 typename Types::LayerType* parent,
220 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47221 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26222 const gfx::Size& bounds,
[email protected]a27cbde2013-03-23 22:01:49223 bool opaque) {
224 typename Types::ContentLayerPtrType layer(
225 Types::CreateContentLayer(GetHost()));
226 typename Types::ContentLayerType* layer_ptr = layer.get();
227 SetProperties(layer_ptr, transform, position, bounds);
228
229 if (opaque_layers_) {
230 layer_ptr->SetContentsOpaque(opaque);
231 } else {
232 layer_ptr->SetContentsOpaque(false);
233 if (opaque)
[email protected]2c7c6702013-03-26 03:14:05234 layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds));
[email protected]a27cbde2013-03-23 22:01:49235 else
236 layer_ptr->SetOpaqueContentsRect(gfx::Rect());
[email protected]586d51ed2012-12-07 20:31:45237 }
[email protected]94f206c12012-08-25 00:09:14238
[email protected]a27cbde2013-03-23 22:01:49239 parent->AddChild(Types::PassLayerPtr(&layer));
240 return layer_ptr;
241 }
[email protected]94f206c12012-08-25 00:09:14242
[email protected]a27cbde2013-03-23 22:01:49243 typename Types::LayerType* CreateReplicaLayer(
244 typename Types::LayerType* owning_layer,
245 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47246 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26247 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49248 typename Types::ContentLayerPtrType layer(
249 Types::CreateContentLayer(GetHost()));
250 typename Types::ContentLayerType* layer_ptr = layer.get();
251 SetProperties(layer_ptr, transform, position, bounds);
252 SetReplica(owning_layer, Types::PassLayerPtr(&layer));
253 return layer_ptr;
254 }
[email protected]94f206c12012-08-25 00:09:14255
[email protected]a27cbde2013-03-23 22:01:49256 typename Types::LayerType* CreateMaskLayer(
257 typename Types::LayerType* owning_layer,
[email protected]64348ea2014-01-29 22:58:26258 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49259 typename Types::ContentLayerPtrType layer(
260 Types::CreateContentLayer(GetHost()));
261 typename Types::ContentLayerType* layer_ptr = layer.get();
262 SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds);
263 SetMask(owning_layer, Types::PassLayerPtr(&layer));
264 return layer_ptr;
265 }
[email protected]586d51ed2012-12-07 20:31:45266
[email protected]a27cbde2013-03-23 22:01:49267 typename Types::ContentLayerType* CreateDrawingSurface(
268 typename Types::LayerType* parent,
269 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47270 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26271 const gfx::Size& bounds,
[email protected]a27cbde2013-03-23 22:01:49272 bool opaque) {
273 typename Types::ContentLayerType* layer =
274 CreateDrawingLayer(parent, transform, position, bounds, opaque);
275 layer->SetForceRenderSurface(true);
276 return layer;
277 }
[email protected]94f206c12012-08-25 00:09:14278
[email protected]d5467eb72014-08-22 01:16:43279 void DestroyLayers() {
280 Types::DestroyLayer(&root_);
danakjf446a072014-09-27 21:55:48281 render_surface_layer_list_ = nullptr;
[email protected]d5467eb72014-08-22 01:16:43282 render_surface_layer_list_impl_.clear();
283 replica_layers_.clear();
284 mask_layers_.clear();
285 ResetLayerIterator();
286 }
[email protected]5b54b972013-07-26 13:25:42287
288 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
289
290 void AddCopyRequest(Layer* layer) {
291 layer->RequestCopyOfOutput(
292 CopyOutputRequest::CreateBitmapRequest(base::Bind(
293 &OcclusionTrackerTest<Types>::CopyOutputCallback,
294 base::Unretained(this))));
295 }
296
297 void AddCopyRequest(LayerImpl* layer) {
298 ScopedPtrVector<CopyOutputRequest> requests;
299 requests.push_back(
300 CopyOutputRequest::CreateBitmapRequest(base::Bind(
301 &OcclusionTrackerTest<Types>::CopyOutputCallback,
302 base::Unretained(this))));
303 layer->PassCopyRequests(&requests);
304 }
305
[email protected]a27cbde2013-03-23 22:01:49306 void CalcDrawEtc(TestContentLayerImpl* root) {
307 DCHECK(root == root_.get());
[email protected]a27cbde2013-03-23 22:01:49308 DCHECK(!root->render_surface());
[email protected]94f206c12012-08-25 00:09:14309
[email protected]ad63b2f2014-08-11 17:39:54310 Types::RecursiveUpdateNumChildren(root);
[email protected]7aad55f2013-07-26 11:25:53311 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:22312 root, root->bounds(), &render_surface_layer_list_impl_);
[email protected]7aad55f2013-07-26 11:25:53313 inputs.can_adjust_raster_scales = true;
314 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14315
[email protected]a27cbde2013-03-23 22:01:49316 layer_iterator_ = layer_iterator_begin_ =
317 Types::TestLayerIterator::Begin(&render_surface_layer_list_impl_);
318 }
[email protected]94f206c12012-08-25 00:09:14319
[email protected]a27cbde2013-03-23 22:01:49320 void CalcDrawEtc(TestContentLayer* root) {
321 DCHECK(root == root_.get());
[email protected]a27cbde2013-03-23 22:01:49322 DCHECK(!root->render_surface());
[email protected]94f206c12012-08-25 00:09:14323
[email protected]989386c2013-07-18 21:37:23324 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
[email protected]7aad55f2013-07-26 11:25:53325 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:22326 root, root->bounds(), render_surface_layer_list_.get());
[email protected]7aad55f2013-07-26 11:25:53327 inputs.can_adjust_raster_scales = true;
328 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14329
[email protected]a27cbde2013-03-23 22:01:49330 layer_iterator_ = layer_iterator_begin_ =
[email protected]989386c2013-07-18 21:37:23331 Types::TestLayerIterator::Begin(render_surface_layer_list_.get());
[email protected]a27cbde2013-03-23 22:01:49332 }
[email protected]94f206c12012-08-25 00:09:14333
[email protected]a27cbde2013-03-23 22:01:49334 void EnterLayer(typename Types::LayerType* layer,
[email protected]e47b0a0a2013-11-18 23:26:22335 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43336 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49337 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]e47b0a0a2013-11-18 23:26:22338 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49339 }
[email protected]94f206c12012-08-25 00:09:14340
[email protected]a27cbde2013-03-23 22:01:49341 void LeaveLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40342 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43343 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49344 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]d002dd02013-03-27 07:40:40345 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49346 ++layer_iterator_;
347 }
[email protected]94f206c12012-08-25 00:09:14348
[email protected]a27cbde2013-03-23 22:01:49349 void VisitLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40350 typename Types::OcclusionTrackerType* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22351 EnterLayer(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49352 LeaveLayer(layer, occlusion);
353 }
[email protected]94f206c12012-08-25 00:09:14354
[email protected]a27cbde2013-03-23 22:01:49355 void EnterContributingSurface(
356 typename Types::LayerType* layer,
[email protected]e47b0a0a2013-11-18 23:26:22357 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43358 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49359 ASSERT_TRUE(layer_iterator_.represents_target_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22360 occlusion->EnterLayer(layer_iterator_);
[email protected]d002dd02013-03-27 07:40:40361 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49362 ++layer_iterator_;
363 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22364 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49365 }
[email protected]94f206c12012-08-25 00:09:14366
[email protected]a27cbde2013-03-23 22:01:49367 void LeaveContributingSurface(
368 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40369 typename Types::OcclusionTrackerType* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43370 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49371 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]d002dd02013-03-27 07:40:40372 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49373 ++layer_iterator_;
374 }
[email protected]94f206c12012-08-25 00:09:14375
[email protected]a27cbde2013-03-23 22:01:49376 void VisitContributingSurface(
377 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40378 typename Types::OcclusionTrackerType* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22379 EnterContributingSurface(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49380 LeaveContributingSurface(layer, occlusion);
381 }
[email protected]94f206c12012-08-25 00:09:14382
[email protected]a27cbde2013-03-23 22:01:49383 void ResetLayerIterator() { layer_iterator_ = layer_iterator_begin_; }
[email protected]94f206c12012-08-25 00:09:14384
[email protected]a27cbde2013-03-23 22:01:49385 const gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:14386
[email protected]a27cbde2013-03-23 22:01:49387 private:
[email protected]d600df7d2013-08-03 02:34:28388 void SetRootLayerOnMainThread(Layer* root) {
389 host_->SetRootLayer(scoped_refptr<Layer>(root));
390 }
391
392 void SetRootLayerOnMainThread(LayerImpl* root) {}
393
[email protected]a27cbde2013-03-23 22:01:49394 void SetBaseProperties(typename Types::LayerType* layer,
395 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47396 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26397 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49398 layer->SetTransform(transform);
[email protected]a27cbde2013-03-23 22:01:49399 layer->SetPosition(position);
400 layer->SetBounds(bounds);
401 }
[email protected]94f206c12012-08-25 00:09:14402
[email protected]a27cbde2013-03-23 22:01:49403 void SetProperties(Layer* layer,
404 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47405 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26406 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49407 SetBaseProperties(layer, transform, position, bounds);
408 }
[email protected]94f206c12012-08-25 00:09:14409
[email protected]a27cbde2013-03-23 22:01:49410 void SetProperties(LayerImpl* layer,
411 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47412 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26413 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49414 SetBaseProperties(layer, transform, position, bounds);
[email protected]94f206c12012-08-25 00:09:14415
bokancccfde72014-10-08 15:15:22416 layer->SetContentBounds(layer->bounds());
[email protected]a27cbde2013-03-23 22:01:49417 }
[email protected]94f206c12012-08-25 00:09:14418
[email protected]a27cbde2013-03-23 22:01:49419 void SetReplica(Layer* owning_layer, scoped_refptr<Layer> layer) {
420 owning_layer->SetReplicaLayer(layer.get());
421 replica_layers_.push_back(layer);
422 }
[email protected]94f206c12012-08-25 00:09:14423
[email protected]a27cbde2013-03-23 22:01:49424 void SetReplica(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
425 owning_layer->SetReplicaLayer(layer.Pass());
426 }
[email protected]94f206c12012-08-25 00:09:14427
[email protected]a27cbde2013-03-23 22:01:49428 void SetMask(Layer* owning_layer, scoped_refptr<Layer> layer) {
429 owning_layer->SetMaskLayer(layer.get());
430 mask_layers_.push_back(layer);
431 }
[email protected]94f206c12012-08-25 00:09:14432
[email protected]a27cbde2013-03-23 22:01:49433 void SetMask(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
434 owning_layer->SetMaskLayer(layer.Pass());
435 }
[email protected]94f206c12012-08-25 00:09:14436
[email protected]a27cbde2013-03-23 22:01:49437 bool opaque_layers_;
enne2097cab2014-09-25 20:16:31438 FakeLayerTreeHostClient client_;
[email protected]d600df7d2013-08-03 02:34:28439 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]a27cbde2013-03-23 22:01:49440 // These hold ownership of the layers for the duration of the test.
441 typename Types::LayerPtrType root_;
[email protected]989386c2013-07-18 21:37:23442 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
[email protected]50761e92013-03-29 20:51:28443 LayerImplList render_surface_layer_list_impl_;
[email protected]a27cbde2013-03-23 22:01:49444 typename Types::TestLayerIterator layer_iterator_begin_;
445 typename Types::TestLayerIterator layer_iterator_;
446 typename Types::LayerType* last_layer_visited_;
[email protected]50761e92013-03-29 20:51:28447 LayerList replica_layers_;
448 LayerList mask_layers_;
[email protected]94f206c12012-08-25 00:09:14449};
450
[email protected]a27cbde2013-03-23 22:01:49451template <>
[email protected]d600df7d2013-08-03 02:34:28452FakeLayerTreeHost*
[email protected]a27cbde2013-03-23 22:01:49453OcclusionTrackerTest<OcclusionTrackerTestMainThreadTypes>::GetHost() {
[email protected]d600df7d2013-08-03 02:34:28454 return host_.get();
[email protected]586d51ed2012-12-07 20:31:45455}
456
[email protected]a27cbde2013-03-23 22:01:49457template <>
458LayerTreeImpl*
459OcclusionTrackerTest<OcclusionTrackerTestImplThreadTypes>::GetHost() {
[email protected]d600df7d2013-08-03 02:34:28460 return host_->host_impl()->active_tree();
[email protected]586d51ed2012-12-07 20:31:45461}
462
[email protected]a27cbde2013-03-23 22:01:49463#define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35464 class ClassName##MainThreadOpaqueLayers \
465 : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
466 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49467 ClassName##MainThreadOpaqueLayers() \
468 : ClassName<OcclusionTrackerTestMainThreadTypes>(true) {} \
469 }; \
470 TEST_F(ClassName##MainThreadOpaqueLayers, RunTest) { RunMyTest(); }
471#define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35472 class ClassName##MainThreadOpaquePaints \
473 : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
474 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49475 ClassName##MainThreadOpaquePaints() \
476 : ClassName<OcclusionTrackerTestMainThreadTypes>(false) {} \
477 }; \
478 TEST_F(ClassName##MainThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14479
[email protected]a27cbde2013-03-23 22:01:49480#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35481 class ClassName##ImplThreadOpaqueLayers \
482 : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
483 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49484 ClassName##ImplThreadOpaqueLayers() \
485 : ClassName<OcclusionTrackerTestImplThreadTypes>(true) {} \
486 }; \
487 TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); }
488#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35489 class ClassName##ImplThreadOpaquePaints \
490 : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
491 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49492 ClassName##ImplThreadOpaquePaints() \
493 : ClassName<OcclusionTrackerTestImplThreadTypes>(false) {} \
494 }; \
495 TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14496
[email protected]a27cbde2013-03-23 22:01:49497#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
498 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
499 RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
500 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
501 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
[email protected]94f206c12012-08-25 00:09:14502
[email protected]a27cbde2013-03-23 22:01:49503#define MAIN_THREAD_TEST(ClassName) \
504 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14505
[email protected]a27cbde2013-03-23 22:01:49506#define IMPL_THREAD_TEST(ClassName) \
507 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14508
[email protected]a27cbde2013-03-23 22:01:49509#define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
510 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
511 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14512
[email protected]a27cbde2013-03-23 22:01:49513template <class Types>
[email protected]ca2902e92013-03-28 01:45:35514class OcclusionTrackerTestIdentityTransforms
515 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49516 protected:
[email protected]ca2902e92013-03-28 01:45:35517 explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49518 : OcclusionTrackerTest<Types>(opaque_layers) {}
[email protected]ece1d952012-10-18 21:26:07519
[email protected]a27cbde2013-03-23 22:01:49520 void RunMyTest() {
521 typename Types::ContentLayerType* root = this->CreateRoot(
522 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
523 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
524 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
525 typename Types::ContentLayerType* layer =
526 this->CreateDrawingLayer(parent,
527 this->identity_matrix,
528 gfx::PointF(30.f, 30.f),
529 gfx::Size(500, 500),
530 true);
531 parent->SetMasksToBounds(true);
532 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14533
[email protected]34ba1ffb2014-03-05 06:55:03534 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]97c6a7342014-03-12 20:36:43535 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14536
[email protected]d002dd02013-03-27 07:40:40537 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22538 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14539
[email protected]a27cbde2013-03-23 22:01:49540 EXPECT_EQ(gfx::Rect().ToString(),
541 occlusion.occlusion_from_outside_target().ToString());
542 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
543 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49544 }
[email protected]94f206c12012-08-25 00:09:14545};
546
[email protected]96baf3e2012-10-22 23:09:55547ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14548
[email protected]a27cbde2013-03-23 22:01:49549template <class Types>
[email protected]96baf3e2012-10-22 23:09:55550class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49551 protected:
[email protected]ca2902e92013-03-28 01:45:35552 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49553 : OcclusionTrackerTest<Types>(opaque_layers) {}
554 void RunMyTest() {
555 gfx::Transform layer_transform;
556 layer_transform.Translate(250.0, 250.0);
557 layer_transform.Rotate(90.0);
558 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14559
[email protected]a27cbde2013-03-23 22:01:49560 typename Types::ContentLayerType* root = this->CreateRoot(
561 this->identity_matrix, gfx::Point(0, 0), gfx::Size(200, 200));
562 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
563 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
564 typename Types::ContentLayerType* layer =
565 this->CreateDrawingLayer(parent,
566 layer_transform,
567 gfx::PointF(30.f, 30.f),
568 gfx::Size(500, 500),
569 true);
570 parent->SetMasksToBounds(true);
571 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14572
[email protected]34ba1ffb2014-03-05 06:55:03573 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49574 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14575
[email protected]d002dd02013-03-27 07:40:40576 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22577 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14578
[email protected]a27cbde2013-03-23 22:01:49579 EXPECT_EQ(gfx::Rect().ToString(),
580 occlusion.occlusion_from_outside_target().ToString());
581 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
582 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49583 }
[email protected]94f206c12012-08-25 00:09:14584};
585
[email protected]96baf3e2012-10-22 23:09:55586ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14587
[email protected]a27cbde2013-03-23 22:01:49588template <class Types>
[email protected]96baf3e2012-10-22 23:09:55589class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49590 protected:
[email protected]ca2902e92013-03-28 01:45:35591 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49592 : OcclusionTrackerTest<Types>(opaque_layers) {}
593 void RunMyTest() {
594 gfx::Transform layer_transform;
595 layer_transform.Translate(20.0, 20.0);
[email protected]94f206c12012-08-25 00:09:14596
[email protected]a27cbde2013-03-23 22:01:49597 typename Types::ContentLayerType* root = this->CreateRoot(
598 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
599 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
600 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
601 typename Types::ContentLayerType* layer =
602 this->CreateDrawingLayer(parent,
603 layer_transform,
604 gfx::PointF(30.f, 30.f),
605 gfx::Size(500, 500),
606 true);
607 parent->SetMasksToBounds(true);
608 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14609
[email protected]34ba1ffb2014-03-05 06:55:03610 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49611 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14612
[email protected]d002dd02013-03-27 07:40:40613 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22614 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14615
[email protected]a27cbde2013-03-23 22:01:49616 EXPECT_EQ(gfx::Rect().ToString(),
617 occlusion.occlusion_from_outside_target().ToString());
618 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
619 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49620 }
[email protected]94f206c12012-08-25 00:09:14621};
622
[email protected]96baf3e2012-10-22 23:09:55623ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14624
[email protected]a27cbde2013-03-23 22:01:49625template <class Types>
[email protected]ca2902e92013-03-28 01:45:35626class OcclusionTrackerTestChildInRotatedChild
627 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49628 protected:
[email protected]ca2902e92013-03-28 01:45:35629 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49630 : OcclusionTrackerTest<Types>(opaque_layers) {}
631 void RunMyTest() {
632 gfx::Transform child_transform;
633 child_transform.Translate(250.0, 250.0);
634 child_transform.Rotate(90.0);
635 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14636
[email protected]a27cbde2013-03-23 22:01:49637 typename Types::ContentLayerType* parent = this->CreateRoot(
638 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
639 parent->SetMasksToBounds(true);
[email protected]3a9a92d2013-07-11 04:37:00640 typename Types::LayerType* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49641 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
642 child->SetMasksToBounds(true);
643 typename Types::ContentLayerType* layer =
644 this->CreateDrawingLayer(child,
645 this->identity_matrix,
646 gfx::PointF(10.f, 10.f),
647 gfx::Size(500, 500),
648 true);
649 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14650
[email protected]34ba1ffb2014-03-05 06:55:03651 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49652 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14653
[email protected]d002dd02013-03-27 07:40:40654 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22655 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14656
[email protected]a27cbde2013-03-23 22:01:49657 EXPECT_EQ(gfx::Rect().ToString(),
658 occlusion.occlusion_from_outside_target().ToString());
659 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
660 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14661
[email protected]d002dd02013-03-27 07:40:40662 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22663 this->EnterLayer(parent, &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(30, 40, 70, 60).ToString(),
668 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14669
[email protected]a27cbde2013-03-23 22:01:49670 /* Justification for the above occlusion from |layer|:
671 100
672 +---------------------+
673 | |
674 | 30 | rotate(90)
675 | 30 + ---------------------------------+
676 100 | | 10 | | ==>
677 | |10+---------------------------------+
678 | | | | | |
679 | | | | | |
680 | | | | | |
681 +----|--|-------------+ | |
682 | | | |
683 | | | |
684 | | | |500
685 | | | |
686 | | | |
687 | | | |
688 | | | |
689 +--|-------------------------------+ |
690 | |
691 +---------------------------------+
692 500
693
694 +---------------------+
695 | |30 Visible region of |layer|: /////
696 | |
697 | +---------------------------------+
698 100| | |10 |
699 | +---------------------------------+ |
700 | | |///////////////| 420 | |
701 | | |///////////////|60 | |
702 | | |///////////////| | |
703 +--|--|---------------+ | |
704 20|10| 70 | |
705 | | | |
706 | | | |
707 | | | |
708 | | | |
709 | | | |
710 | | |10|
711 | +------------------------------|--+
712 | 490 |
713 +---------------------------------+
714 500
715
716 */
717 }
[email protected]94f206c12012-08-25 00:09:14718};
719
[email protected]96baf3e2012-10-22 23:09:55720ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14721
[email protected]a27cbde2013-03-23 22:01:49722template <class Types>
[email protected]ca2902e92013-03-28 01:45:35723class OcclusionTrackerTestScaledRenderSurface
724 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49725 protected:
[email protected]ca2902e92013-03-28 01:45:35726 explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49727 : OcclusionTrackerTest<Types>(opaque_layers) {}
[email protected]710ffc02012-10-30 21:42:02728
[email protected]a27cbde2013-03-23 22:01:49729 void RunMyTest() {
730 typename Types::ContentLayerType* parent = this->CreateRoot(
731 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02732
[email protected]a27cbde2013-03-23 22:01:49733 gfx::Transform layer1_matrix;
734 layer1_matrix.Scale(2.0, 2.0);
735 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
736 parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true);
737 layer1->SetForceRenderSurface(true);
[email protected]710ffc02012-10-30 21:42:02738
[email protected]a27cbde2013-03-23 22:01:49739 gfx::Transform layer2_matrix;
740 layer2_matrix.Translate(25.0, 25.0);
741 typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
742 layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true);
743 typename Types::ContentLayerType* occluder =
744 this->CreateDrawingLayer(parent,
745 this->identity_matrix,
746 gfx::PointF(100.f, 100.f),
747 gfx::Size(500, 500),
748 true);
749 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02750
[email protected]34ba1ffb2014-03-05 06:55:03751 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49752 gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02753
[email protected]d002dd02013-03-27 07:40:40754 this->VisitLayer(occluder, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22755 this->EnterLayer(layer2, &occlusion);
[email protected]710ffc02012-10-30 21:42:02756
[email protected]a27cbde2013-03-23 22:01:49757 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
758 occlusion.occlusion_from_outside_target().ToString());
759 EXPECT_EQ(gfx::Rect().ToString(),
760 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49761 }
[email protected]710ffc02012-10-30 21:42:02762};
763
764ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
765
[email protected]a27cbde2013-03-23 22:01:49766template <class Types>
[email protected]ca2902e92013-03-28 01:45:35767class OcclusionTrackerTestVisitTargetTwoTimes
768 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49769 protected:
[email protected]ca2902e92013-03-28 01:45:35770 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49771 : OcclusionTrackerTest<Types>(opaque_layers) {}
772 void RunMyTest() {
[email protected]a27cbde2013-03-23 22:01:49773 typename Types::ContentLayerType* root = this->CreateRoot(
774 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]d5467eb72014-08-22 01:16:43775 typename Types::LayerType* surface = this->CreateSurface(
776 root, this->identity_matrix, gfx::PointF(30.f, 30.f), gfx::Size());
777 typename Types::ContentLayerType* surface_child =
778 this->CreateDrawingLayer(surface,
[email protected]a27cbde2013-03-23 22:01:49779 this->identity_matrix,
780 gfx::PointF(10.f, 10.f),
[email protected]d5467eb72014-08-22 01:16:43781 gfx::Size(50, 50),
[email protected]a27cbde2013-03-23 22:01:49782 true);
[email protected]d5467eb72014-08-22 01:16:43783 // |top_layer| makes |root|'s surface get considered by OcclusionTracker
784 // first, instead of |surface|'s. This exercises different code in
785 // LeaveToRenderTarget, as the target surface has already been seen when
786 // leaving |surface| later.
787 typename Types::ContentLayerType* top_layer =
788 this->CreateDrawingLayer(root,
[email protected]a27cbde2013-03-23 22:01:49789 this->identity_matrix,
[email protected]d5467eb72014-08-22 01:16:43790 gfx::PointF(40.f, 90.f),
791 gfx::Size(50, 20),
[email protected]a27cbde2013-03-23 22:01:49792 true);
793 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14794
[email protected]34ba1ffb2014-03-05 06:55:03795 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49796 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14797
[email protected]d5467eb72014-08-22 01:16:43798 this->VisitLayer(top_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14799
[email protected]a27cbde2013-03-23 22:01:49800 EXPECT_EQ(gfx::Rect().ToString(),
801 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43802 EXPECT_EQ(gfx::Rect(40, 90, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49803 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14804
[email protected]d5467eb72014-08-22 01:16:43805 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14806
[email protected]d5467eb72014-08-22 01:16:43807 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49808 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43809 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49810 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14811
[email protected]d5467eb72014-08-22 01:16:43812 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:14813
[email protected]d5467eb72014-08-22 01:16:43814 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49815 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43816 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49817 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14818
[email protected]d5467eb72014-08-22 01:16:43819 // Occlusion from |top_layer| already in the root target should get merged
820 // with the occlusion from the |surface| we are leaving now.
821 this->LeaveContributingSurface(surface, &occlusion);
822 this->EnterLayer(root, &occlusion);
[email protected]94f206c12012-08-25 00:09:14823
[email protected]d5467eb72014-08-22 01:16:43824 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
825 EXPECT_EQ(gfx::Rect(40, 40, 50, 70).ToString(),
[email protected]a27cbde2013-03-23 22:01:49826 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49827 }
[email protected]94f206c12012-08-25 00:09:14828};
829
[email protected]96baf3e2012-10-22 23:09:55830ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:14831
[email protected]a27cbde2013-03-23 22:01:49832template <class Types>
[email protected]ca2902e92013-03-28 01:45:35833class OcclusionTrackerTestSurfaceRotatedOffAxis
834 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49835 protected:
[email protected]ca2902e92013-03-28 01:45:35836 explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49837 : OcclusionTrackerTest<Types>(opaque_layers) {}
838 void RunMyTest() {
839 gfx::Transform child_transform;
840 child_transform.Translate(250.0, 250.0);
841 child_transform.Rotate(95.0);
842 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14843
[email protected]a27cbde2013-03-23 22:01:49844 gfx::Transform layer_transform;
845 layer_transform.Translate(10.0, 10.0);
[email protected]94f206c12012-08-25 00:09:14846
[email protected]a27cbde2013-03-23 22:01:49847 typename Types::ContentLayerType* root = this->CreateRoot(
848 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
849 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
850 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
851 typename Types::LayerType* child = this->CreateLayer(
852 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
853 child->SetMasksToBounds(true);
854 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
855 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true);
856 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14857
[email protected]34ba1ffb2014-03-05 06:55:03858 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49859 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14860
[email protected]8a822692014-02-12 17:30:55861 gfx::Rect clipped_layer_in_child = MathUtil::MapEnclosingClippedRect(
[email protected]a27cbde2013-03-23 22:01:49862 layer_transform, layer->visible_content_rect());
[email protected]94f206c12012-08-25 00:09:14863
[email protected]d002dd02013-03-27 07:40:40864 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22865 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14866
[email protected]a27cbde2013-03-23 22:01:49867 EXPECT_EQ(gfx::Rect().ToString(),
868 occlusion.occlusion_from_outside_target().ToString());
869 EXPECT_EQ(clipped_layer_in_child.ToString(),
870 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14871
[email protected]d002dd02013-03-27 07:40:40872 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22873 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14874
[email protected]a27cbde2013-03-23 22:01:49875 EXPECT_EQ(gfx::Rect().ToString(),
876 occlusion.occlusion_from_outside_target().ToString());
877 EXPECT_EQ(gfx::Rect().ToString(),
878 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49879 }
[email protected]94f206c12012-08-25 00:09:14880};
881
[email protected]96baf3e2012-10-22 23:09:55882ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:14883
[email protected]a27cbde2013-03-23 22:01:49884template <class Types>
[email protected]ca2902e92013-03-28 01:45:35885class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
886 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49887 protected:
[email protected]ca2902e92013-03-28 01:45:35888 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49889 : OcclusionTrackerTest<Types>(opaque_layers) {}
890 void RunMyTest() {
891 gfx::Transform child_transform;
892 child_transform.Translate(250.0, 250.0);
893 child_transform.Rotate(90.0);
894 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14895
[email protected]a27cbde2013-03-23 22:01:49896 typename Types::ContentLayerType* root = this->CreateRoot(
897 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
898 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
899 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
900 parent->SetMasksToBounds(true);
901 typename Types::ContentLayerType* child =
[email protected]3a9a92d2013-07-11 04:37:00902 this->CreateDrawingSurface(parent,
[email protected]a27cbde2013-03-23 22:01:49903 child_transform,
904 gfx::PointF(30.f, 30.f),
905 gfx::Size(500, 500),
906 false);
907 child->SetMasksToBounds(true);
908 typename Types::ContentLayerType* layer1 =
909 this->CreateDrawingLayer(child,
910 this->identity_matrix,
911 gfx::PointF(10.f, 10.f),
912 gfx::Size(500, 500),
913 true);
914 typename Types::ContentLayerType* layer2 =
915 this->CreateDrawingLayer(child,
916 this->identity_matrix,
917 gfx::PointF(10.f, 450.f),
918 gfx::Size(500, 60),
919 true);
920 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14921
[email protected]34ba1ffb2014-03-05 06:55:03922 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49923 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14924
[email protected]d002dd02013-03-27 07:40:40925 this->VisitLayer(layer2, &occlusion);
926 this->VisitLayer(layer1, &occlusion);
927 this->VisitLayer(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22928 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14929
[email protected]a27cbde2013-03-23 22:01:49930 EXPECT_EQ(gfx::Rect().ToString(),
931 occlusion.occlusion_from_outside_target().ToString());
932 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
933 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14934
[email protected]d002dd02013-03-27 07:40:40935 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22936 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14937
[email protected]a27cbde2013-03-23 22:01:49938 EXPECT_EQ(gfx::Rect().ToString(),
939 occlusion.occlusion_from_outside_target().ToString());
940 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
941 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14942
[email protected]a27cbde2013-03-23 22:01:49943 /* Justification for the above occlusion from |layer1| and |layer2|:
[email protected]94f206c12012-08-25 00:09:14944
945 +---------------------+
946 | |30 Visible region of |layer1|: /////
947 | | Visible region of |layer2|: \\\\\
948 | +---------------------------------+
949 | | |10 |
950 | +---------------+-----------------+ |
951 | | |\\\\\\\\\\\\|//| 420 | |
952 | | |\\\\\\\\\\\\|//|60 | |
953 | | |\\\\\\\\\\\\|//| | |
954 +--|--|------------|--+ | |
955 20|10| 70 | | |
956 | | | | |
957 | | | | |
958 | | | | |
959 | | | | |
960 | | | | |
961 | | | |10|
962 | +------------|-----------------|--+
963 | | 490 |
964 +---------------+-----------------+
965 60 440
966 */
[email protected]a27cbde2013-03-23 22:01:49967 }
[email protected]94f206c12012-08-25 00:09:14968};
969
[email protected]96baf3e2012-10-22 23:09:55970ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:14971
[email protected]a27cbde2013-03-23 22:01:49972template <class Types>
[email protected]ca2902e92013-03-28 01:45:35973class OcclusionTrackerTestOverlappingSurfaceSiblings
974 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49975 protected:
[email protected]ca2902e92013-03-28 01:45:35976 explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49977 : OcclusionTrackerTest<Types>(opaque_layers) {}
978 void RunMyTest() {
[email protected]a27cbde2013-03-23 22:01:49979 typename Types::ContentLayerType* parent = this->CreateRoot(
980 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
981 parent->SetMasksToBounds(true);
982 typename Types::LayerType* child1 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43983 parent, this->identity_matrix, gfx::PointF(10.f, 0.f), gfx::Size());
[email protected]a27cbde2013-03-23 22:01:49984 typename Types::LayerType* child2 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43985 parent, this->identity_matrix, gfx::PointF(30.f, 0.f), gfx::Size());
986 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
987 child1, this->identity_matrix, gfx::PointF(), gfx::Size(40, 50), true);
[email protected]a27cbde2013-03-23 22:01:49988 typename Types::ContentLayerType* layer2 =
989 this->CreateDrawingLayer(child2,
990 this->identity_matrix,
[email protected]d5467eb72014-08-22 01:16:43991 gfx::PointF(10.f, 0.f),
992 gfx::Size(40, 50),
[email protected]a27cbde2013-03-23 22:01:49993 true);
994 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14995
[email protected]34ba1ffb2014-03-05 06:55:03996 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:49997 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14998
[email protected]d002dd02013-03-27 07:40:40999 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221000 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141001
[email protected]d5467eb72014-08-22 01:16:431002 // layer2's occlusion.
[email protected]a27cbde2013-03-23 22:01:491003 EXPECT_EQ(gfx::Rect().ToString(),
1004 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431005 EXPECT_EQ(gfx::Rect(10, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491006 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141007
[email protected]d002dd02013-03-27 07:40:401008 this->LeaveContributingSurface(child2, &occlusion);
1009 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221010 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141011
[email protected]d5467eb72014-08-22 01:16:431012 // layer2's occlusion in the target space of layer1.
1013 EXPECT_EQ(gfx::Rect(30, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491014 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431015 // layer1's occlusion.
1016 EXPECT_EQ(gfx::Rect(0, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491017 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141018
[email protected]d002dd02013-03-27 07:40:401019 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221020 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141021
[email protected]d5467eb72014-08-22 01:16:431022 // The occlusion from from layer1 and layer2 is merged.
1023 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1024 EXPECT_EQ(gfx::Rect(10, 0, 70, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:491025 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491026 }
[email protected]94f206c12012-08-25 00:09:141027};
1028
[email protected]96baf3e2012-10-22 23:09:551029ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:141030
[email protected]a27cbde2013-03-23 22:01:491031template <class Types>
[email protected]ca2902e92013-03-28 01:45:351032class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms
1033 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491034 protected:
[email protected]ca2902e92013-03-28 01:45:351035 explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(
[email protected]a27cbde2013-03-23 22:01:491036 bool opaque_layers)
1037 : OcclusionTrackerTest<Types>(opaque_layers) {}
1038 void RunMyTest() {
1039 gfx::Transform child1_transform;
1040 child1_transform.Translate(250.0, 250.0);
1041 child1_transform.Rotate(-90.0);
1042 child1_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141043
[email protected]a27cbde2013-03-23 22:01:491044 gfx::Transform child2_transform;
1045 child2_transform.Translate(250.0, 250.0);
1046 child2_transform.Rotate(90.0);
1047 child2_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141048
[email protected]a27cbde2013-03-23 22:01:491049 typename Types::ContentLayerType* parent = this->CreateRoot(
1050 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1051 parent->SetMasksToBounds(true);
1052 typename Types::LayerType* child1 = this->CreateSurface(
1053 parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10));
1054 typename Types::LayerType* child2 =
1055 this->CreateDrawingSurface(parent,
1056 child2_transform,
1057 gfx::PointF(20.f, 40.f),
1058 gfx::Size(10, 10),
1059 false);
1060 typename Types::ContentLayerType* layer1 =
1061 this->CreateDrawingLayer(child1,
1062 this->identity_matrix,
1063 gfx::PointF(-10.f, -20.f),
1064 gfx::Size(510, 510),
1065 true);
1066 typename Types::ContentLayerType* layer2 =
1067 this->CreateDrawingLayer(child2,
1068 this->identity_matrix,
1069 gfx::PointF(-10.f, -10.f),
1070 gfx::Size(510, 510),
1071 true);
1072 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141073
[email protected]34ba1ffb2014-03-05 06:55:031074 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491075 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141076
[email protected]d002dd02013-03-27 07:40:401077 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221078 this->EnterLayer(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141079
[email protected]a27cbde2013-03-23 22:01:491080 EXPECT_EQ(gfx::Rect().ToString(),
1081 occlusion.occlusion_from_outside_target().ToString());
1082 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1083 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141084
[email protected]d002dd02013-03-27 07:40:401085 this->LeaveLayer(child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221086 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141087
danakjf080b5b2014-08-23 22:18:201088 EXPECT_EQ(gfx::Rect().ToString(),
1089 occlusion.occlusion_from_outside_target().ToString());
1090 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1091 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141092
[email protected]d002dd02013-03-27 07:40:401093 this->LeaveContributingSurface(child2, &occlusion);
1094 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221095 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141096
[email protected]a27cbde2013-03-23 22:01:491097 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
1098 occlusion.occlusion_from_outside_target().ToString());
1099 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
1100 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141101
[email protected]d002dd02013-03-27 07:40:401102 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221103 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141104
[email protected]a27cbde2013-03-23 22:01:491105 EXPECT_EQ(gfx::Rect().ToString(),
1106 occlusion.occlusion_from_outside_target().ToString());
1107 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(),
1108 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141109
[email protected]a27cbde2013-03-23 22:01:491110 /* Justification for the above occlusion:
1111 100
1112 +---------------------+
1113 |20 | layer1
1114 10+----------------------------------+
1115 100 || 30 | layer2 |
1116 |20+----------------------------------+
1117 || | | | |
1118 || | | | |
1119 || | | | |
1120 +|-|------------------+ | |
1121 | | | | 510
1122 | | 510 | |
1123 | | | |
1124 | | | |
1125 | | | |
1126 | | | |
1127 | | 520 | |
1128 +----------------------------------+ |
1129 | |
1130 +----------------------------------+
1131 510
1132 */
1133 }
[email protected]94f206c12012-08-25 00:09:141134};
1135
[email protected]a27cbde2013-03-23 22:01:491136ALL_OCCLUSIONTRACKER_TEST(
1137 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:141138
[email protected]a27cbde2013-03-23 22:01:491139template <class Types>
[email protected]96baf3e2012-10-22 23:09:551140class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491141 protected:
[email protected]ca2902e92013-03-28 01:45:351142 explicit OcclusionTrackerTestFilters(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491143 : OcclusionTrackerTest<Types>(opaque_layers) {}
1144 void RunMyTest() {
1145 gfx::Transform layer_transform;
1146 layer_transform.Translate(250.0, 250.0);
1147 layer_transform.Rotate(90.0);
1148 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141149
[email protected]a27cbde2013-03-23 22:01:491150 typename Types::ContentLayerType* parent = this->CreateRoot(
1151 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1152 parent->SetMasksToBounds(true);
1153 typename Types::ContentLayerType* blur_layer =
1154 this->CreateDrawingLayer(parent,
1155 layer_transform,
1156 gfx::PointF(30.f, 30.f),
1157 gfx::Size(500, 500),
1158 true);
1159 typename Types::ContentLayerType* opaque_layer =
1160 this->CreateDrawingLayer(parent,
1161 layer_transform,
1162 gfx::PointF(30.f, 30.f),
1163 gfx::Size(500, 500),
1164 true);
1165 typename Types::ContentLayerType* opacity_layer =
1166 this->CreateDrawingLayer(parent,
1167 layer_transform,
1168 gfx::PointF(30.f, 30.f),
1169 gfx::Size(500, 500),
1170 true);
[email protected]94f206c12012-08-25 00:09:141171
[email protected]ae6b1a72013-06-25 18:49:291172 FilterOperations filters;
1173 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]a27cbde2013-03-23 22:01:491174 blur_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141175
[email protected]ae6b1a72013-06-25 18:49:291176 filters.Clear();
1177 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491178 opaque_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141179
[email protected]ae6b1a72013-06-25 18:49:291180 filters.Clear();
1181 filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491182 opacity_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141183
[email protected]a27cbde2013-03-23 22:01:491184 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141185
[email protected]34ba1ffb2014-03-05 06:55:031186 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491187 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141188
[email protected]a27cbde2013-03-23 22:01:491189 // Opacity layer won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401190 this->VisitLayer(opacity_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221191 this->EnterContributingSurface(opacity_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141192
[email protected]a27cbde2013-03-23 22:01:491193 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1194 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141195
[email protected]a27cbde2013-03-23 22:01:491196 // And has nothing to contribute to its parent surface.
[email protected]d002dd02013-03-27 07:40:401197 this->LeaveContributingSurface(opacity_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491198 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1199 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141200
[email protected]a27cbde2013-03-23 22:01:491201 // Opaque layer will contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401202 this->VisitLayer(opaque_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221203 this->EnterContributingSurface(opaque_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141204
[email protected]a27cbde2013-03-23 22:01:491205 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1206 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(),
1207 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141208
[email protected]a27cbde2013-03-23 22:01:491209 // And it gets translated to the parent surface.
[email protected]d002dd02013-03-27 07:40:401210 this->LeaveContributingSurface(opaque_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491211 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1212 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1213 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141214
[email protected]a27cbde2013-03-23 22:01:491215 // The blur layer needs to throw away any occlusion from outside its
1216 // subtree.
[email protected]e47b0a0a2013-11-18 23:26:221217 this->EnterLayer(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491218 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1219 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141220
[email protected]a27cbde2013-03-23 22:01:491221 // And it won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401222 this->LeaveLayer(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221223 this->EnterContributingSurface(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491224 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1225 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141226
[email protected]a27cbde2013-03-23 22:01:491227 // But the opaque layer's occlusion is preserved on the parent.
[email protected]d002dd02013-03-27 07:40:401228 this->LeaveContributingSurface(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221229 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491230 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1231 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1232 occlusion.occlusion_from_inside_target().ToString());
1233 }
[email protected]94f206c12012-08-25 00:09:141234};
1235
[email protected]96baf3e2012-10-22 23:09:551236ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:141237
[email protected]a27cbde2013-03-23 22:01:491238template <class Types>
[email protected]ca2902e92013-03-28 01:45:351239class OcclusionTrackerTestReplicaDoesOcclude
1240 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491241 protected:
[email protected]ca2902e92013-03-28 01:45:351242 explicit OcclusionTrackerTestReplicaDoesOcclude(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491243 : OcclusionTrackerTest<Types>(opaque_layers) {}
1244 void RunMyTest() {
1245 typename Types::ContentLayerType* parent = this->CreateRoot(
1246 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
[email protected]d5467eb72014-08-22 01:16:431247 typename Types::LayerType* surface = this->CreateDrawingSurface(
1248 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), true);
[email protected]a27cbde2013-03-23 22:01:491249 this->CreateReplicaLayer(
[email protected]d5467eb72014-08-22 01:16:431250 surface, this->identity_matrix, gfx::PointF(0.f, 50.f), gfx::Size());
[email protected]a27cbde2013-03-23 22:01:491251 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141252
[email protected]34ba1ffb2014-03-05 06:55:031253 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491254 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141255
[email protected]d002dd02013-03-27 07:40:401256 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141257
[email protected]a27cbde2013-03-23 22:01:491258 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1259 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141260
[email protected]d002dd02013-03-27 07:40:401261 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221262 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141263
[email protected]a27cbde2013-03-23 22:01:491264 // The surface and replica should both be occluding the parent.
[email protected]d5467eb72014-08-22 01:16:431265 EXPECT_EQ(gfx::Rect(50, 100).ToString(),
1266 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491267 }
[email protected]94f206c12012-08-25 00:09:141268};
1269
[email protected]96baf3e2012-10-22 23:09:551270ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude);
[email protected]94f206c12012-08-25 00:09:141271
[email protected]a27cbde2013-03-23 22:01:491272template <class Types>
[email protected]ca2902e92013-03-28 01:45:351273class OcclusionTrackerTestReplicaWithClipping
1274 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491275 protected:
[email protected]ca2902e92013-03-28 01:45:351276 explicit OcclusionTrackerTestReplicaWithClipping(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491277 : OcclusionTrackerTest<Types>(opaque_layers) {}
1278 void RunMyTest() {
1279 typename Types::ContentLayerType* parent = this->CreateRoot(
1280 this->identity_matrix, gfx::PointF(), gfx::Size(100, 170));
1281 parent->SetMasksToBounds(true);
1282 typename Types::LayerType* surface =
1283 this->CreateDrawingSurface(parent,
1284 this->identity_matrix,
1285 gfx::PointF(0.f, 100.f),
1286 gfx::Size(50, 50),
1287 true);
1288 this->CreateReplicaLayer(
[email protected]d5467eb72014-08-22 01:16:431289 surface, this->identity_matrix, gfx::PointF(0.f, 50.f), gfx::Size());
[email protected]a27cbde2013-03-23 22:01:491290 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141291
[email protected]34ba1ffb2014-03-05 06:55:031292 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491293 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141294
[email protected]d002dd02013-03-27 07:40:401295 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141296
[email protected]d5467eb72014-08-22 01:16:431297 // The surface layer's occlusion in its own space.
[email protected]a27cbde2013-03-23 22:01:491298 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1299 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431300 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141301
[email protected]d002dd02013-03-27 07:40:401302 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221303 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141304
[email protected]d5467eb72014-08-22 01:16:431305 // The surface and replica should both be occluding the parent, the
1306 // replica's occlusion is clipped by the parent.
1307 EXPECT_EQ(gfx::Rect(0, 100, 50, 70).ToString(),
1308 occlusion.occlusion_from_inside_target().ToString());
1309 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491310 }
[email protected]94f206c12012-08-25 00:09:141311};
1312
[email protected]96baf3e2012-10-22 23:09:551313ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping);
[email protected]94f206c12012-08-25 00:09:141314
[email protected]a27cbde2013-03-23 22:01:491315template <class Types>
[email protected]96baf3e2012-10-22 23:09:551316class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491317 protected:
[email protected]ca2902e92013-03-28 01:45:351318 explicit OcclusionTrackerTestReplicaWithMask(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491319 : OcclusionTrackerTest<Types>(opaque_layers) {}
1320 void RunMyTest() {
1321 typename Types::ContentLayerType* parent = this->CreateRoot(
1322 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
1323 typename Types::LayerType* surface =
1324 this->CreateDrawingSurface(parent,
1325 this->identity_matrix,
1326 gfx::PointF(0.f, 100.f),
1327 gfx::Size(50, 50),
1328 true);
1329 typename Types::LayerType* replica = this->CreateReplicaLayer(
1330 surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
1331 this->CreateMaskLayer(replica, gfx::Size(10, 10));
1332 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141333
[email protected]34ba1ffb2014-03-05 06:55:031334 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491335 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141336
[email protected]d002dd02013-03-27 07:40:401337 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141338
[email protected]a27cbde2013-03-23 22:01:491339 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1340 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141341
[email protected]d002dd02013-03-27 07:40:401342 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221343 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141344
[email protected]a27cbde2013-03-23 22:01:491345 // The replica should not be occluding the parent, since it has a mask
1346 // applied to it.
1347 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(),
1348 occlusion.occlusion_from_inside_target().ToString());
1349 }
[email protected]94f206c12012-08-25 00:09:141350};
1351
[email protected]96baf3e2012-10-22 23:09:551352ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask);
[email protected]94f206c12012-08-25 00:09:141353
[email protected]a27cbde2013-03-23 22:01:491354template <class Types>
[email protected]ca2902e92013-03-28 01:45:351355class OcclusionTrackerTestOpaqueContentsRegionEmpty
1356 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491357 protected:
[email protected]ca2902e92013-03-28 01:45:351358 explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491359 : OcclusionTrackerTest<Types>(opaque_layers) {}
1360 void RunMyTest() {
1361 typename Types::ContentLayerType* parent = this->CreateRoot(
1362 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1363 typename Types::ContentLayerType* layer =
1364 this->CreateDrawingSurface(parent,
1365 this->identity_matrix,
1366 gfx::PointF(),
1367 gfx::Size(200, 200),
1368 false);
1369 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141370
[email protected]34ba1ffb2014-03-05 06:55:031371 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491372 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:221373 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141374
[email protected]d5467eb72014-08-22 01:16:431375 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1376 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141377
[email protected]d002dd02013-03-27 07:40:401378 this->LeaveLayer(layer, &occlusion);
1379 this->VisitContributingSurface(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221380 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141381
[email protected]a27cbde2013-03-23 22:01:491382 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]d5467eb72014-08-22 01:16:431383 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491384 }
[email protected]94f206c12012-08-25 00:09:141385};
1386
[email protected]96baf3e2012-10-22 23:09:551387MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141388
[email protected]a27cbde2013-03-23 22:01:491389template <class Types>
[email protected]ca2902e92013-03-28 01:45:351390class OcclusionTrackerTestOpaqueContentsRegionNonEmpty
1391 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491392 protected:
[email protected]ca2902e92013-03-28 01:45:351393 explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491394 : OcclusionTrackerTest<Types>(opaque_layers) {}
1395 void RunMyTest() {
1396 typename Types::ContentLayerType* parent = this->CreateRoot(
1397 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1398 typename Types::ContentLayerType* layer =
1399 this->CreateDrawingLayer(parent,
1400 this->identity_matrix,
1401 gfx::PointF(100.f, 100.f),
1402 gfx::Size(200, 200),
1403 false);
1404 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141405 {
[email protected]34ba1ffb2014-03-05 06:55:031406 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491407 gfx::Rect(0, 0, 1000, 1000));
1408 layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:141409
[email protected]a27cbde2013-03-23 22:01:491410 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401411 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221412 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141413
[email protected]a27cbde2013-03-23 22:01:491414 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
1415 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141416 }
[email protected]a27cbde2013-03-23 22:01:491417 {
[email protected]34ba1ffb2014-03-05 06:55:031418 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491419 gfx::Rect(0, 0, 1000, 1000));
1420 layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
1421
1422 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401423 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221424 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491425
1426 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(),
1427 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491428 }
1429 {
[email protected]34ba1ffb2014-03-05 06:55:031430 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491431 gfx::Rect(0, 0, 1000, 1000));
1432 layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
1433
1434 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401435 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221436 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491437
1438 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
1439 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491440 }
1441 }
[email protected]94f206c12012-08-25 00:09:141442};
1443
[email protected]96baf3e2012-10-22 23:09:551444MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141445
[email protected]a27cbde2013-03-23 22:01:491446template <class Types>
[email protected]ca2902e92013-03-28 01:45:351447class OcclusionTrackerTestUnsorted3dLayers
1448 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491449 protected:
[email protected]ca2902e92013-03-28 01:45:351450 explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491451 : OcclusionTrackerTest<Types>(opaque_layers) {}
1452 void RunMyTest() {
1453 // Currently, The main thread layer iterator does not iterate over 3d items
1454 // in sorted order, because layer sorting is not performed on the main
1455 // thread. Because of this, the occlusion tracker cannot assume that a 3d
1456 // layer occludes other layers that have not yet been iterated over. For
1457 // now, the expected behavior is that a 3d layer simply does not add any
1458 // occlusion to the occlusion tracker.
[email protected]94f206c12012-08-25 00:09:141459
[email protected]a27cbde2013-03-23 22:01:491460 gfx::Transform translation_to_front;
1461 translation_to_front.Translate3d(0.0, 0.0, -10.0);
1462 gfx::Transform translation_to_back;
1463 translation_to_front.Translate3d(0.0, 0.0, -100.0);
[email protected]94f206c12012-08-25 00:09:141464
[email protected]a27cbde2013-03-23 22:01:491465 typename Types::ContentLayerType* parent = this->CreateRoot(
1466 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1467 typename Types::ContentLayerType* child1 = this->CreateDrawingLayer(
1468 parent, translation_to_back, gfx::PointF(), gfx::Size(100, 100), true);
1469 typename Types::ContentLayerType* child2 =
1470 this->CreateDrawingLayer(parent,
1471 translation_to_front,
1472 gfx::PointF(50.f, 50.f),
1473 gfx::Size(100, 100),
1474 true);
[email protected]56fffdd2014-02-11 19:50:571475 parent->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281476 parent->Set3dSortingContextId(1);
1477 child1->Set3dSortingContextId(1);
1478 child2->Set3dSortingContextId(1);
[email protected]94f206c12012-08-25 00:09:141479
[email protected]a27cbde2013-03-23 22:01:491480 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141481
[email protected]34ba1ffb2014-03-05 06:55:031482 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491483 gfx::Rect(0, 0, 1000, 1000));
[email protected]d002dd02013-03-27 07:40:401484 this->VisitLayer(child2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491485 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1486 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141487
[email protected]d002dd02013-03-27 07:40:401488 this->VisitLayer(child1, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491489 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1490 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1491 }
[email protected]94f206c12012-08-25 00:09:141492};
1493
[email protected]a27cbde2013-03-23 22:01:491494// This test will have different layer ordering on the impl thread; the test
1495// will only work on the main thread.
[email protected]96baf3e2012-10-22 23:09:551496MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
[email protected]94f206c12012-08-25 00:09:141497
[email protected]a27cbde2013-03-23 22:01:491498template <class Types>
[email protected]ca2902e92013-03-28 01:45:351499class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude
1500 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491501 protected:
[email protected]ca2902e92013-03-28 01:45:351502 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(
1503 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491504 : OcclusionTrackerTest<Types>(opaque_layers) {}
1505 void RunMyTest() {
1506 gfx::Transform transform;
1507 transform.Translate(50.0, 50.0);
1508 transform.ApplyPerspectiveDepth(100.0);
1509 transform.Translate3d(0.0, 0.0, 110.0);
1510 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141511
[email protected]a27cbde2013-03-23 22:01:491512 typename Types::ContentLayerType* parent = this->CreateRoot(
1513 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1514 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1515 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
[email protected]56fffdd2014-02-11 19:50:571516 parent->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281517 parent->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:571518 layer->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281519 layer->Set3dSortingContextId(1);
[email protected]a27cbde2013-03-23 22:01:491520 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141521
[email protected]34ba1ffb2014-03-05 06:55:031522 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491523 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141524
[email protected]a27cbde2013-03-23 22:01:491525 // The |layer| is entirely behind the camera and should not occlude.
[email protected]d002dd02013-03-27 07:40:401526 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221527 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491528 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1529 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1530 }
[email protected]94f206c12012-08-25 00:09:141531};
1532
[email protected]a27cbde2013-03-23 22:01:491533// This test requires accumulating occlusion of 3d layers, which are skipped by
1534// the occlusion tracker on the main thread. So this test should run on the impl
1535// thread.
[email protected]96baf3e2012-10-22 23:09:551536IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude);
[email protected]94f206c12012-08-25 00:09:141537
[email protected]a27cbde2013-03-23 22:01:491538template <class Types>
[email protected]ca2902e92013-03-28 01:45:351539class OcclusionTrackerTestLargePixelsOccludeInsideClipRect
1540 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491541 protected:
[email protected]ca2902e92013-03-28 01:45:351542 explicit OcclusionTrackerTestLargePixelsOccludeInsideClipRect(
1543 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491544 : OcclusionTrackerTest<Types>(opaque_layers) {}
1545 void RunMyTest() {
1546 gfx::Transform transform;
1547 transform.Translate(50.0, 50.0);
1548 transform.ApplyPerspectiveDepth(100.0);
1549 transform.Translate3d(0.0, 0.0, 99.0);
1550 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141551
[email protected]a27cbde2013-03-23 22:01:491552 typename Types::ContentLayerType* parent = this->CreateRoot(
1553 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1554 parent->SetMasksToBounds(true);
1555 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1556 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
[email protected]56fffdd2014-02-11 19:50:571557 parent->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281558 parent->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:571559 layer->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:281560 layer->Set3dSortingContextId(1);
[email protected]a27cbde2013-03-23 22:01:491561 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141562
[email protected]34ba1ffb2014-03-05 06:55:031563 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491564 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141565
[email protected]a27cbde2013-03-23 22:01:491566 // This is very close to the camera, so pixels in its visible_content_rect()
1567 // will actually go outside of the layer's clip rect. Ensure that those
1568 // pixels don't occlude things outside the clip rect.
[email protected]d002dd02013-03-27 07:40:401569 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221570 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491571 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
1572 occlusion.occlusion_from_inside_target().ToString());
1573 EXPECT_EQ(gfx::Rect().ToString(),
1574 occlusion.occlusion_from_outside_target().ToString());
1575 }
[email protected]94f206c12012-08-25 00:09:141576};
1577
[email protected]a27cbde2013-03-23 22:01:491578// This test requires accumulating occlusion of 3d layers, which are skipped by
1579// the occlusion tracker on the main thread. So this test should run on the impl
1580// thread.
[email protected]96baf3e2012-10-22 23:09:551581IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect);
[email protected]94f206c12012-08-25 00:09:141582
[email protected]a27cbde2013-03-23 22:01:491583template <class Types>
[email protected]ca2902e92013-03-28 01:45:351584class OcclusionTrackerTestAnimationOpacity1OnMainThread
1585 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491586 protected:
[email protected]ca2902e92013-03-28 01:45:351587 explicit OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491588 : OcclusionTrackerTest<Types>(opaque_layers) {}
1589 void RunMyTest() {
1590 // parent
1591 // +--layer
1592 // +--surface
1593 // | +--surface_child
1594 // | +--surface_child2
1595 // +--parent2
1596 // +--topmost
[email protected]c8d71552013-01-22 03:43:021597
[email protected]a27cbde2013-03-23 22:01:491598 typename Types::ContentLayerType* parent = this->CreateRoot(
1599 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1600 typename Types::ContentLayerType* layer =
1601 this->CreateDrawingLayer(parent,
1602 this->identity_matrix,
1603 gfx::PointF(),
1604 gfx::Size(300, 300),
1605 true);
1606 typename Types::ContentLayerType* surface =
1607 this->CreateDrawingSurface(parent,
1608 this->identity_matrix,
1609 gfx::PointF(),
1610 gfx::Size(300, 300),
1611 true);
1612 typename Types::ContentLayerType* surface_child =
1613 this->CreateDrawingLayer(surface,
1614 this->identity_matrix,
1615 gfx::PointF(),
1616 gfx::Size(200, 300),
1617 true);
1618 typename Types::ContentLayerType* surface_child2 =
1619 this->CreateDrawingLayer(surface,
1620 this->identity_matrix,
1621 gfx::PointF(),
1622 gfx::Size(100, 300),
1623 true);
1624 typename Types::ContentLayerType* parent2 =
1625 this->CreateDrawingLayer(parent,
1626 this->identity_matrix,
1627 gfx::PointF(),
1628 gfx::Size(300, 300),
1629 false);
1630 typename Types::ContentLayerType* topmost =
1631 this->CreateDrawingLayer(parent,
1632 this->identity_matrix,
1633 gfx::PointF(250.f, 0.f),
1634 gfx::Size(50, 300),
1635 true);
[email protected]94f206c12012-08-25 00:09:141636
[email protected]a27cbde2013-03-23 22:01:491637 AddOpacityTransitionToController(
1638 layer->layer_animation_controller(), 10.0, 0.f, 1.f, false);
1639 AddOpacityTransitionToController(
1640 surface->layer_animation_controller(), 10.0, 0.f, 1.f, false);
1641 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141642
[email protected]a27cbde2013-03-23 22:01:491643 EXPECT_TRUE(layer->draw_opacity_is_animating());
1644 EXPECT_FALSE(surface->draw_opacity_is_animating());
1645 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:141646
[email protected]34ba1ffb2014-03-05 06:55:031647 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491648 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141649
[email protected]d002dd02013-03-27 07:40:401650 this->VisitLayer(topmost, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221651 this->EnterLayer(parent2, &occlusion);
danakjf080b5b2014-08-23 22:18:201652
[email protected]a27cbde2013-03-23 22:01:491653 // This occlusion will affect all surfaces.
[email protected]a27cbde2013-03-23 22:01:491654 EXPECT_EQ(gfx::Rect().ToString(),
1655 occlusion.occlusion_from_outside_target().ToString());
danakjf080b5b2014-08-23 22:18:201656 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1657 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141658
danakjf080b5b2014-08-23 22:18:201659 this->LeaveLayer(parent2, &occlusion);
[email protected]d002dd02013-03-27 07:40:401660 this->VisitLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221661 this->EnterLayer(surface_child, &occlusion);
danakjf080b5b2014-08-23 22:18:201662 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1663 occlusion.occlusion_from_outside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491664 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1665 occlusion.occlusion_from_inside_target().ToString());
danakjf080b5b2014-08-23 22:18:201666
[email protected]d002dd02013-03-27 07:40:401667 this->LeaveLayer(surface_child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221668 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491669 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1670 occlusion.occlusion_from_outside_target().ToString());
danakjf080b5b2014-08-23 22:18:201671 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
1672 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141673
danakjf080b5b2014-08-23 22:18:201674 this->LeaveLayer(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221675 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491676 // Occlusion within the surface is lost when leaving the animating surface.
1677 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:491678 occlusion.occlusion_from_outside_target().ToString());
danakjf080b5b2014-08-23 22:18:201679 EXPECT_EQ(gfx::Rect().ToString(),
1680 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141681
danakjf080b5b2014-08-23 22:18:201682 this->LeaveContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491683 // Occlusion from outside the animating surface still exists.
1684 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1685 occlusion.occlusion_from_inside_target().ToString());
1686 EXPECT_EQ(gfx::Rect().ToString(),
1687 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:021688
[email protected]d002dd02013-03-27 07:40:401689 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221690 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141691
[email protected]a27cbde2013-03-23 22:01:491692 // Occlusion is not added for the animating |layer|.
danakjf080b5b2014-08-23 22:18:201693 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1694 occlusion.occlusion_from_inside_target().ToString());
1695 EXPECT_EQ(gfx::Rect().ToString(),
1696 occlusion.occlusion_from_outside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491697 }
[email protected]94f206c12012-08-25 00:09:141698};
1699
[email protected]96baf3e2012-10-22 23:09:551700MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread);
[email protected]94f206c12012-08-25 00:09:141701
[email protected]a27cbde2013-03-23 22:01:491702template <class Types>
[email protected]ca2902e92013-03-28 01:45:351703class OcclusionTrackerTestAnimationOpacity0OnMainThread
1704 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491705 protected:
[email protected]ca2902e92013-03-28 01:45:351706 explicit OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491707 : OcclusionTrackerTest<Types>(opaque_layers) {}
1708 void RunMyTest() {
1709 typename Types::ContentLayerType* parent = this->CreateRoot(
1710 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1711 typename Types::ContentLayerType* layer =
1712 this->CreateDrawingLayer(parent,
1713 this->identity_matrix,
1714 gfx::PointF(),
1715 gfx::Size(300, 300),
1716 true);
1717 typename Types::ContentLayerType* surface =
1718 this->CreateDrawingSurface(parent,
1719 this->identity_matrix,
1720 gfx::PointF(),
1721 gfx::Size(300, 300),
1722 true);
1723 typename Types::ContentLayerType* surface_child =
1724 this->CreateDrawingLayer(surface,
1725 this->identity_matrix,
1726 gfx::PointF(),
1727 gfx::Size(200, 300),
1728 true);
1729 typename Types::ContentLayerType* surface_child2 =
1730 this->CreateDrawingLayer(surface,
1731 this->identity_matrix,
1732 gfx::PointF(),
1733 gfx::Size(100, 300),
1734 true);
1735 typename Types::ContentLayerType* parent2 =
1736 this->CreateDrawingLayer(parent,
1737 this->identity_matrix,
1738 gfx::PointF(),
1739 gfx::Size(300, 300),
1740 false);
1741 typename Types::ContentLayerType* topmost =
1742 this->CreateDrawingLayer(parent,
1743 this->identity_matrix,
1744 gfx::PointF(250.f, 0.f),
1745 gfx::Size(50, 300),
1746 true);
[email protected]94f206c12012-08-25 00:09:141747
[email protected]a27cbde2013-03-23 22:01:491748 AddOpacityTransitionToController(
1749 layer->layer_animation_controller(), 10.0, 1.f, 0.f, false);
1750 AddOpacityTransitionToController(
1751 surface->layer_animation_controller(), 10.0, 1.f, 0.f, false);
1752 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141753
[email protected]a27cbde2013-03-23 22:01:491754 EXPECT_TRUE(layer->draw_opacity_is_animating());
1755 EXPECT_FALSE(surface->draw_opacity_is_animating());
1756 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:141757
[email protected]34ba1ffb2014-03-05 06:55:031758 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491759 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141760
[email protected]d002dd02013-03-27 07:40:401761 this->VisitLayer(topmost, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221762 this->EnterLayer(parent2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491763 // This occlusion will affect all surfaces.
1764 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1765 occlusion.occlusion_from_inside_target().ToString());
1766 EXPECT_EQ(gfx::Rect().ToString(),
1767 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141768
danakjf080b5b2014-08-23 22:18:201769 this->LeaveLayer(parent2, &occlusion);
[email protected]d002dd02013-03-27 07:40:401770 this->VisitLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221771 this->EnterLayer(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491772 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1773 occlusion.occlusion_from_inside_target().ToString());
1774 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1775 occlusion.occlusion_from_outside_target().ToString());
danakjf080b5b2014-08-23 22:18:201776
[email protected]d002dd02013-03-27 07:40:401777 this->LeaveLayer(surface_child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221778 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491779 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
1780 occlusion.occlusion_from_inside_target().ToString());
1781 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1782 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141783
danakjf080b5b2014-08-23 22:18:201784 this->LeaveLayer(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221785 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491786 // Occlusion within the surface is lost when leaving the animating surface.
1787 EXPECT_EQ(gfx::Rect().ToString(),
1788 occlusion.occlusion_from_inside_target().ToString());
1789 EXPECT_EQ(gfx::Rect().ToString(),
1790 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141791
danakjf080b5b2014-08-23 22:18:201792 this->LeaveContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491793 // Occlusion from outside the animating surface still exists.
1794 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1795 occlusion.occlusion_from_inside_target().ToString());
1796 EXPECT_EQ(gfx::Rect().ToString(),
1797 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:021798
[email protected]d002dd02013-03-27 07:40:401799 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221800 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141801
[email protected]a27cbde2013-03-23 22:01:491802 // Occlusion is not added for the animating |layer|.
danakjf080b5b2014-08-23 22:18:201803 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1804 occlusion.occlusion_from_inside_target().ToString());
1805 EXPECT_EQ(gfx::Rect().ToString(),
1806 occlusion.occlusion_from_outside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491807 }
[email protected]94f206c12012-08-25 00:09:141808};
1809
[email protected]96baf3e2012-10-22 23:09:551810MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread);
[email protected]94f206c12012-08-25 00:09:141811
[email protected]a27cbde2013-03-23 22:01:491812template <class Types>
[email protected]ca2902e92013-03-28 01:45:351813class OcclusionTrackerTestAnimationTranslateOnMainThread
1814 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491815 protected:
[email protected]ca2902e92013-03-28 01:45:351816 explicit OcclusionTrackerTestAnimationTranslateOnMainThread(
1817 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491818 : OcclusionTrackerTest<Types>(opaque_layers) {}
1819 void RunMyTest() {
1820 typename Types::ContentLayerType* parent = this->CreateRoot(
1821 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1822 typename Types::ContentLayerType* layer =
1823 this->CreateDrawingLayer(parent,
1824 this->identity_matrix,
1825 gfx::PointF(),
1826 gfx::Size(300, 300),
1827 true);
1828 typename Types::ContentLayerType* surface =
1829 this->CreateDrawingSurface(parent,
1830 this->identity_matrix,
1831 gfx::PointF(),
1832 gfx::Size(300, 300),
1833 true);
1834 typename Types::ContentLayerType* surface_child =
1835 this->CreateDrawingLayer(surface,
1836 this->identity_matrix,
1837 gfx::PointF(),
1838 gfx::Size(200, 300),
1839 true);
1840 typename Types::ContentLayerType* surface_child2 =
1841 this->CreateDrawingLayer(surface,
1842 this->identity_matrix,
1843 gfx::PointF(),
1844 gfx::Size(100, 300),
1845 true);
1846 typename Types::ContentLayerType* surface2 = this->CreateDrawingSurface(
1847 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 300), true);
[email protected]94f206c12012-08-25 00:09:141848
[email protected]a27cbde2013-03-23 22:01:491849 AddAnimatedTransformToController(
1850 layer->layer_animation_controller(), 10.0, 30, 0);
1851 AddAnimatedTransformToController(
1852 surface->layer_animation_controller(), 10.0, 30, 0);
1853 AddAnimatedTransformToController(
1854 surface_child->layer_animation_controller(), 10.0, 30, 0);
1855 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141856
[email protected]a27cbde2013-03-23 22:01:491857 EXPECT_TRUE(layer->draw_transform_is_animating());
1858 EXPECT_TRUE(layer->screen_space_transform_is_animating());
1859 EXPECT_TRUE(
1860 surface->render_surface()->target_surface_transforms_are_animating());
1861 EXPECT_TRUE(
1862 surface->render_surface()->screen_space_transforms_are_animating());
1863 // The surface owning layer doesn't animate against its own surface.
1864 EXPECT_FALSE(surface->draw_transform_is_animating());
1865 EXPECT_TRUE(surface->screen_space_transform_is_animating());
1866 EXPECT_TRUE(surface_child->draw_transform_is_animating());
1867 EXPECT_TRUE(surface_child->screen_space_transform_is_animating());
[email protected]94f206c12012-08-25 00:09:141868
[email protected]34ba1ffb2014-03-05 06:55:031869 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491870 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141871
[email protected]d002dd02013-03-27 07:40:401872 this->VisitLayer(surface2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221873 this->EnterContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141874
[email protected]a27cbde2013-03-23 22:01:491875 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
1876 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141877
[email protected]d002dd02013-03-27 07:40:401878 this->LeaveContributingSurface(surface2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221879 this->EnterLayer(surface_child2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491880 // surface_child2 is moving in screen space but not relative to its target,
1881 // so occlusion should happen in its target space only. It also means that
1882 // things occluding from outside the target (e.g. surface2) cannot occlude
1883 // this layer.
1884 EXPECT_EQ(gfx::Rect().ToString(),
1885 occlusion.occlusion_from_outside_target().ToString());
[email protected]7d6d6c92014-03-06 01:18:501886 EXPECT_EQ(gfx::Rect().ToString(),
1887 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141888
[email protected]d002dd02013-03-27 07:40:401889 this->LeaveLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221890 this->EnterLayer(surface_child, &occlusion);
[email protected]7d6d6c92014-03-06 01:18:501891 // surface_child2 added to the occlusion since it is not moving relative
1892 // to its target.
[email protected]a27cbde2013-03-23 22:01:491893 EXPECT_EQ(gfx::Rect().ToString(),
1894 occlusion.occlusion_from_outside_target().ToString());
1895 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1896 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141897
[email protected]d002dd02013-03-27 07:40:401898 this->LeaveLayer(surface_child, &occlusion);
[email protected]7d6d6c92014-03-06 01:18:501899 // surface_child is moving relative to its target, so it does not add
1900 // occlusion.
[email protected]a27cbde2013-03-23 22:01:491901 EXPECT_EQ(gfx::Rect().ToString(),
1902 occlusion.occlusion_from_outside_target().ToString());
1903 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1904 occlusion.occlusion_from_inside_target().ToString());
[email protected]7d6d6c92014-03-06 01:18:501905
1906 this->EnterLayer(surface, &occlusion);
1907 EXPECT_EQ(gfx::Rect().ToString(),
1908 occlusion.occlusion_from_outside_target().ToString());
1909 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1910 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141911
[email protected]d002dd02013-03-27 07:40:401912 this->LeaveLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491913 // The surface's owning layer is moving in screen space but not relative to
[email protected]7d6d6c92014-03-06 01:18:501914 // its target, so it adds to the occlusion.
[email protected]a27cbde2013-03-23 22:01:491915 EXPECT_EQ(gfx::Rect().ToString(),
1916 occlusion.occlusion_from_outside_target().ToString());
1917 EXPECT_EQ(gfx::Rect(0, 0, 300, 300).ToString(),
1918 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141919
[email protected]e47b0a0a2013-11-18 23:26:221920 this->EnterContributingSurface(surface, &occlusion);
[email protected]d002dd02013-03-27 07:40:401921 this->LeaveContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491922 // The |surface| is moving in the screen and in its target, so all occlusion
[email protected]7d6d6c92014-03-06 01:18:501923 // within the surface is lost when leaving it. Only the |surface2| occlusion
1924 // is left.
1925 EXPECT_EQ(gfx::Rect().ToString(),
1926 occlusion.occlusion_from_outside_target().ToString());
1927 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
1928 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141929
[email protected]7d6d6c92014-03-06 01:18:501930 this->VisitLayer(layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491931 // The |layer| is animating in the screen and in its target, so no occlusion
1932 // is added.
[email protected]7d6d6c92014-03-06 01:18:501933 EXPECT_EQ(gfx::Rect().ToString(),
1934 occlusion.occlusion_from_outside_target().ToString());
1935 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
1936 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491937 }
[email protected]94f206c12012-08-25 00:09:141938};
1939
[email protected]96baf3e2012-10-22 23:09:551940MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread);
[email protected]94f206c12012-08-25 00:09:141941
[email protected]a27cbde2013-03-23 22:01:491942template <class Types>
[email protected]ca2902e92013-03-28 01:45:351943class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent
1944 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491945 protected:
[email protected]ca2902e92013-03-28 01:45:351946 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(
1947 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491948 : OcclusionTrackerTest<Types>(opaque_layers) {}
1949 void RunMyTest() {
1950 gfx::Transform surface_transform;
1951 surface_transform.Translate(300.0, 300.0);
1952 surface_transform.Scale(2.0, 2.0);
1953 surface_transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:141954
[email protected]a27cbde2013-03-23 22:01:491955 typename Types::ContentLayerType* parent = this->CreateRoot(
1956 this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
1957 typename Types::ContentLayerType* surface = this->CreateDrawingSurface(
1958 parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false);
1959 typename Types::ContentLayerType* surface2 =
1960 this->CreateDrawingSurface(parent,
1961 this->identity_matrix,
1962 gfx::PointF(50.f, 50.f),
1963 gfx::Size(300, 300),
1964 false);
1965 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1966 surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1967 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141968
[email protected]34ba1ffb2014-03-05 06:55:031969 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:491970 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141971
[email protected]d002dd02013-03-27 07:40:401972 this->VisitLayer(surface2, &occlusion);
1973 this->VisitContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141974
[email protected]a27cbde2013-03-23 22:01:491975 EXPECT_EQ(gfx::Rect().ToString(),
1976 occlusion.occlusion_from_outside_target().ToString());
1977 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(),
1978 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141979
[email protected]a27cbde2013-03-23 22:01:491980 // Clear any stored occlusion.
[email protected]d5467eb72014-08-22 01:16:431981 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
1982 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
[email protected]94f206c12012-08-25 00:09:141983
[email protected]d002dd02013-03-27 07:40:401984 this->VisitLayer(surface, &occlusion);
1985 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141986
[email protected]a27cbde2013-03-23 22:01:491987 EXPECT_EQ(gfx::Rect().ToString(),
1988 occlusion.occlusion_from_outside_target().ToString());
1989 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(),
1990 occlusion.occlusion_from_inside_target().ToString());
1991 }
[email protected]94f206c12012-08-25 00:09:141992};
1993
[email protected]a27cbde2013-03-23 22:01:491994MAIN_AND_IMPL_THREAD_TEST(
1995 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:141996
[email protected]a27cbde2013-03-23 22:01:491997template <class Types>
[email protected]ca2902e92013-03-28 01:45:351998class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping
1999 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492000 protected:
[email protected]ca2902e92013-03-28 01:45:352001 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(
2002 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492003 : OcclusionTrackerTest<Types>(opaque_layers) {}
2004 void RunMyTest() {
2005 typename Types::ContentLayerType* parent = this->CreateRoot(
2006 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2007 parent->SetMasksToBounds(true);
2008 typename Types::ContentLayerType* surface =
2009 this->CreateDrawingSurface(parent,
2010 this->identity_matrix,
2011 gfx::PointF(),
2012 gfx::Size(500, 300),
2013 false);
2014 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
2015 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142016
[email protected]34ba1ffb2014-03-05 06:55:032017 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492018 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142019
[email protected]d002dd02013-03-27 07:40:402020 this->VisitLayer(surface, &occlusion);
2021 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142022
[email protected]a27cbde2013-03-23 22:01:492023 EXPECT_EQ(gfx::Rect().ToString(),
2024 occlusion.occlusion_from_outside_target().ToString());
2025 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(),
2026 occlusion.occlusion_from_inside_target().ToString());
2027 }
[email protected]94f206c12012-08-25 00:09:142028};
2029
[email protected]a27cbde2013-03-23 22:01:492030MAIN_AND_IMPL_THREAD_TEST(
2031 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:142032
[email protected]a27cbde2013-03-23 22:01:492033template <class Types>
[email protected]ca2902e92013-03-28 01:45:352034class OcclusionTrackerTestSurfaceWithReplicaUnoccluded
2035 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492036 protected:
[email protected]ca2902e92013-03-28 01:45:352037 explicit OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492038 : OcclusionTrackerTest<Types>(opaque_layers) {}
2039 void RunMyTest() {
2040 typename Types::ContentLayerType* parent = this->CreateRoot(
2041 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2042 typename Types::LayerType* surface =
2043 this->CreateDrawingSurface(parent,
2044 this->identity_matrix,
2045 gfx::PointF(),
2046 gfx::Size(100, 100),
2047 true);
2048 this->CreateReplicaLayer(surface,
2049 this->identity_matrix,
2050 gfx::PointF(0.f, 100.f),
2051 gfx::Size(100, 100));
2052 typename Types::LayerType* topmost =
2053 this->CreateDrawingLayer(parent,
2054 this->identity_matrix,
2055 gfx::PointF(),
2056 gfx::Size(100, 110),
2057 true);
2058 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142059
[email protected]34ba1ffb2014-03-05 06:55:032060 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492061 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142062
[email protected]a27cbde2013-03-23 22:01:492063 // |topmost| occludes the surface, but not the entire surface's replica.
[email protected]d002dd02013-03-27 07:40:402064 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142065
[email protected]a27cbde2013-03-23 22:01:492066 EXPECT_EQ(gfx::Rect().ToString(),
2067 occlusion.occlusion_from_outside_target().ToString());
2068 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(),
2069 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142070
[email protected]d002dd02013-03-27 07:40:402071 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142072
[email protected]66b52e12013-11-17 15:53:182073 // Render target with replica ignores occlusion from outside.
2074 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:492075 occlusion.occlusion_from_outside_target().ToString());
2076 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2077 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142078
[email protected]e47b0a0a2013-11-18 23:26:222079 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142080
danakjf080b5b2014-08-23 22:18:202081 // Only occlusion from outside the surface occludes the surface/replica.
2082 EXPECT_EQ(gfx::Rect().ToString(),
2083 occlusion.occlusion_on_contributing_surface_from_outside_target()
2084 .ToString());
2085 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(),
2086 occlusion.occlusion_on_contributing_surface_from_inside_target()
2087 .ToString());
[email protected]a27cbde2013-03-23 22:01:492088 }
[email protected]94f206c12012-08-25 00:09:142089};
2090
[email protected]96baf3e2012-10-22 23:09:552091ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded);
[email protected]94f206c12012-08-25 00:09:142092
[email protected]a27cbde2013-03-23 22:01:492093template <class Types>
[email protected]ca2902e92013-03-28 01:45:352094class OcclusionTrackerTestSurfaceChildOfSurface
2095 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492096 protected:
[email protected]ca2902e92013-03-28 01:45:352097 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492098 : OcclusionTrackerTest<Types>(opaque_layers) {}
2099 void RunMyTest() {
2100 // This test verifies that the surface cliprect does not end up empty and
2101 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:142102
[email protected]a27cbde2013-03-23 22:01:492103 typename Types::ContentLayerType* parent = this->CreateRoot(
2104 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2105 typename Types::LayerType* surface =
2106 this->CreateDrawingSurface(parent,
2107 this->identity_matrix,
2108 gfx::PointF(),
2109 gfx::Size(100, 100),
danakjf080b5b2014-08-23 22:18:202110 false);
[email protected]a27cbde2013-03-23 22:01:492111 typename Types::LayerType* surface_child =
2112 this->CreateDrawingSurface(surface,
2113 this->identity_matrix,
2114 gfx::PointF(0.f, 10.f),
2115 gfx::Size(100, 50),
2116 true);
2117 typename Types::LayerType* topmost = this->CreateDrawingLayer(
2118 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
2119 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142120
[email protected]34ba1ffb2014-03-05 06:55:032121 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492122 gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142123
[email protected]a27cbde2013-03-23 22:01:492124 // |topmost| occludes everything partially so we know occlusion is happening
2125 // at all.
[email protected]d002dd02013-03-27 07:40:402126 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142127
[email protected]a27cbde2013-03-23 22:01:492128 EXPECT_EQ(gfx::Rect().ToString(),
2129 occlusion.occlusion_from_outside_target().ToString());
2130 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2131 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142132
[email protected]d002dd02013-03-27 07:40:402133 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:142134
[email protected]a27cbde2013-03-23 22:01:492135 // surface_child increases the occlusion in the screen by a narrow sliver.
2136 EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(),
2137 occlusion.occlusion_from_outside_target().ToString());
2138 // In its own surface, surface_child is at 0,0 as is its occlusion.
2139 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2140 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142141
[email protected]a27cbde2013-03-23 22:01:492142 // The root layer always has a clip rect. So the parent of |surface| has a
2143 // clip rect. However, the owning layer for |surface| does not mask to
2144 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
2145 // |surface_child| exercises different code paths as its parent does not
2146 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:142147
[email protected]e47b0a0a2013-11-18 23:26:222148 this->EnterContributingSurface(surface_child, &occlusion);
danakjf080b5b2014-08-23 22:18:202149 // The |surface_child| can't occlude its own surface, but occlusion from
2150 // |topmost| can.
2151 EXPECT_EQ(gfx::Rect().ToString(),
2152 occlusion.occlusion_on_contributing_surface_from_outside_target()
2153 .ToString());
2154 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2155 occlusion.occlusion_on_contributing_surface_from_inside_target()
2156 .ToString());
[email protected]d002dd02013-03-27 07:40:402157 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:142158
[email protected]a27cbde2013-03-23 22:01:492159 // When the surface_child's occlusion is transformed up to its parent, make
danakjf080b5b2014-08-23 22:18:202160 // sure it is not clipped away inappropriately.
[email protected]e47b0a0a2013-11-18 23:26:222161 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492162 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2163 occlusion.occlusion_from_outside_target().ToString());
2164 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(),
2165 occlusion.occlusion_from_inside_target().ToString());
[email protected]d002dd02013-03-27 07:40:402166 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142167
[email protected]e47b0a0a2013-11-18 23:26:222168 this->EnterContributingSurface(surface, &occlusion);
danakjf080b5b2014-08-23 22:18:202169 // The occlusion from inside |surface| can't affect the surface, but
2170 // |topmost| can.
2171 EXPECT_EQ(gfx::Rect().ToString(),
2172 occlusion.occlusion_on_contributing_surface_from_outside_target()
2173 .ToString());
2174 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2175 occlusion.occlusion_on_contributing_surface_from_inside_target()
2176 .ToString());
2177
2178 this->LeaveContributingSurface(surface, &occlusion);
2179 this->EnterLayer(parent, &occlusion);
2180 // The occlusion in |surface| and without are merged into the parent.
2181 EXPECT_EQ(gfx::Rect().ToString(),
2182 occlusion.occlusion_from_outside_target().ToString());
2183 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(),
2184 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:492185 }
[email protected]94f206c12012-08-25 00:09:142186};
2187
[email protected]96baf3e2012-10-22 23:09:552188ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:142189
[email protected]a27cbde2013-03-23 22:01:492190template <class Types>
[email protected]ca2902e92013-03-28 01:45:352191class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter
2192 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492193 protected:
[email protected]ca2902e92013-03-28 01:45:352194 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:492195 bool opaque_layers)
2196 : OcclusionTrackerTest<Types>(opaque_layers) {}
2197 void RunMyTest() {
2198 gfx::Transform scale_by_half;
2199 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142200
[email protected]ae6b1a72013-06-25 18:49:292201 FilterOperations filters;
2202 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]94f206c12012-08-25 00:09:142203
[email protected]a27cbde2013-03-23 22:01:492204 // Save the distance of influence for the blur effect.
2205 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:292206 filters.GetOutsets(
2207 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:142208
[email protected]d5467eb72014-08-22 01:16:432209 enum Direction {
2210 LEFT,
2211 RIGHT,
2212 TOP,
2213 BOTTOM,
2214 LAST_DIRECTION = BOTTOM,
2215 };
[email protected]94f206c12012-08-25 00:09:142216
[email protected]d5467eb72014-08-22 01:16:432217 for (int i = 0; i <= LAST_DIRECTION; ++i) {
2218 SCOPED_TRACE(i);
[email protected]94f206c12012-08-25 00:09:142219
[email protected]d5467eb72014-08-22 01:16:432220 // Make a 50x50 filtered surface that is adjacent to occluding layers
2221 // which are above it in the z-order in various configurations. The
2222 // surface is scaled to test that the pixel moving is done in the target
2223 // space, where the background filter is applied.
2224 typename Types::ContentLayerType* parent = this->CreateRoot(
2225 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2226 typename Types::LayerType* filtered_surface =
2227 this->CreateDrawingLayer(parent,
2228 scale_by_half,
2229 gfx::PointF(50.f, 50.f),
2230 gfx::Size(100, 100),
2231 false);
2232 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142233
[email protected]d5467eb72014-08-22 01:16:432234 gfx::Rect occlusion_rect;
2235 switch (i) {
2236 case LEFT:
2237 occlusion_rect = gfx::Rect(0, 0, 50, 200);
2238 break;
2239 case RIGHT:
2240 occlusion_rect = gfx::Rect(100, 0, 50, 200);
2241 break;
2242 case TOP:
2243 occlusion_rect = gfx::Rect(0, 0, 200, 50);
2244 break;
2245 case BOTTOM:
2246 occlusion_rect = gfx::Rect(0, 100, 200, 50);
2247 break;
2248 }
[email protected]ac7c7f52012-11-08 06:26:502249
[email protected]d5467eb72014-08-22 01:16:432250 typename Types::LayerType* occluding_layer =
2251 this->CreateDrawingLayer(parent,
2252 this->identity_matrix,
2253 occlusion_rect.origin(),
2254 occlusion_rect.size(),
2255 true);
2256 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142257
[email protected]d5467eb72014-08-22 01:16:432258 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2259 gfx::Rect(0, 0, 200, 200));
[email protected]94f206c12012-08-25 00:09:142260
[email protected]d5467eb72014-08-22 01:16:432261 // This layer occludes pixels directly beside the filtered_surface.
2262 // Because filtered surface blends pixels in a radius, it will need to see
2263 // some of the pixels (up to radius far) underneath the occluding layers.
2264 this->VisitLayer(occluding_layer, &occlusion);
[email protected]ccb1c9a2012-12-17 03:53:192265
[email protected]d5467eb72014-08-22 01:16:432266 EXPECT_EQ(occlusion_rect.ToString(),
2267 occlusion.occlusion_from_inside_target().ToString());
2268 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142269
[email protected]d5467eb72014-08-22 01:16:432270 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142271
[email protected]d5467eb72014-08-22 01:16:432272 // The occlusion is used fully inside the surface.
2273 gfx::Rect occlusion_inside_surface =
2274 occlusion_rect - gfx::Vector2d(50, 50);
2275 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
2276 EXPECT_EQ(occlusion_inside_surface.ToString(),
2277 occlusion.occlusion_from_outside_target().ToString());
[email protected]ac7c7f52012-11-08 06:26:502278
[email protected]d5467eb72014-08-22 01:16:432279 // The surface has a background blur, so it needs pixels that are
2280 // currently considered occluded in order to be drawn. So the pixels it
2281 // needs should be removed some the occluded area so that when we get to
2282 // the parent they are drawn.
2283 this->VisitContributingSurface(filtered_surface, &occlusion);
2284 this->EnterLayer(parent, &occlusion);
[email protected]ac7c7f52012-11-08 06:26:502285
[email protected]d5467eb72014-08-22 01:16:432286 gfx::Rect expected_occlusion = occlusion_rect;
2287 switch (i) {
2288 case LEFT:
2289 expected_occlusion.Inset(0, 0, outset_right, 0);
2290 break;
2291 case RIGHT:
2292 expected_occlusion.Inset(outset_right, 0, 0, 0);
2293 break;
2294 case TOP:
2295 expected_occlusion.Inset(0, 0, 0, outset_right);
2296 break;
2297 case BOTTOM:
2298 expected_occlusion.Inset(0, outset_right, 0, 0);
2299 break;
2300 }
[email protected]94f206c12012-08-25 00:09:142301
[email protected]d5467eb72014-08-22 01:16:432302 EXPECT_EQ(expected_occlusion.ToString(),
2303 occlusion.occlusion_from_inside_target().ToString());
2304 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142305
[email protected]d5467eb72014-08-22 01:16:432306 this->DestroyLayers();
2307 }
[email protected]a27cbde2013-03-23 22:01:492308 }
[email protected]94f206c12012-08-25 00:09:142309};
2310
[email protected]a27cbde2013-03-23 22:01:492311ALL_OCCLUSIONTRACKER_TEST(
2312 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142313
[email protected]a27cbde2013-03-23 22:01:492314template <class Types>
[email protected]ca2902e92013-03-28 01:45:352315class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice
2316 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492317 protected:
[email protected]ca2902e92013-03-28 01:45:352318 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(
[email protected]a27cbde2013-03-23 22:01:492319 bool opaque_layers)
2320 : OcclusionTrackerTest<Types>(opaque_layers) {}
2321 void RunMyTest() {
2322 gfx::Transform scale_by_half;
2323 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142324
[email protected]a27cbde2013-03-23 22:01:492325 // Makes two surfaces that completely cover |parent|. The occlusion both
2326 // above and below the filters will be reduced by each of them.
2327 typename Types::ContentLayerType* root = this->CreateRoot(
2328 this->identity_matrix, gfx::PointF(), gfx::Size(75, 75));
2329 typename Types::LayerType* parent = this->CreateSurface(
2330 root, scale_by_half, gfx::PointF(), gfx::Size(150, 150));
2331 parent->SetMasksToBounds(true);
2332 typename Types::LayerType* filtered_surface1 = this->CreateDrawingLayer(
2333 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
2334 typename Types::LayerType* filtered_surface2 = this->CreateDrawingLayer(
2335 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
2336 typename Types::LayerType* occluding_layer_above =
2337 this->CreateDrawingLayer(parent,
2338 this->identity_matrix,
2339 gfx::PointF(100.f, 100.f),
2340 gfx::Size(50, 50),
2341 true);
[email protected]94f206c12012-08-25 00:09:142342
[email protected]a27cbde2013-03-23 22:01:492343 // Filters make the layers own surfaces.
[email protected]ae6b1a72013-06-25 18:49:292344 FilterOperations filters;
2345 filters.Append(FilterOperation::CreateBlurFilter(1.f));
[email protected]a27cbde2013-03-23 22:01:492346 filtered_surface1->SetBackgroundFilters(filters);
2347 filtered_surface2->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142348
[email protected]a27cbde2013-03-23 22:01:492349 // Save the distance of influence for the blur effect.
2350 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:292351 filters.GetOutsets(
2352 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:142353
[email protected]a27cbde2013-03-23 22:01:492354 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:142355
[email protected]34ba1ffb2014-03-05 06:55:032356 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492357 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142358
[email protected]d002dd02013-03-27 07:40:402359 this->VisitLayer(occluding_layer_above, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492360 EXPECT_EQ(gfx::Rect().ToString(),
2361 occlusion.occlusion_from_outside_target().ToString());
2362 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(),
2363 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142364
[email protected]d002dd02013-03-27 07:40:402365 this->VisitLayer(filtered_surface2, &occlusion);
2366 this->VisitContributingSurface(filtered_surface2, &occlusion);
2367 this->VisitLayer(filtered_surface1, &occlusion);
2368 this->VisitContributingSurface(filtered_surface1, &occlusion);
[email protected]94f206c12012-08-25 00:09:142369
[email protected]a27cbde2013-03-23 22:01:492370 // Test expectations in the target.
2371 gfx::Rect expected_occlusion =
2372 gfx::Rect(100 / 2 + outset_right * 2,
2373 100 / 2 + outset_bottom * 2,
2374 50 / 2 - (outset_left + outset_right) * 2,
2375 50 / 2 - (outset_top + outset_bottom) * 2);
2376 EXPECT_EQ(expected_occlusion.ToString(),
2377 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142378
[email protected]a27cbde2013-03-23 22:01:492379 // Test expectations in the screen are the same as in the target, as the
2380 // render surface is 1:1 with the screen.
2381 EXPECT_EQ(expected_occlusion.ToString(),
2382 occlusion.occlusion_from_outside_target().ToString());
2383 }
[email protected]94f206c12012-08-25 00:09:142384};
2385
[email protected]a27cbde2013-03-23 22:01:492386ALL_OCCLUSIONTRACKER_TEST(
2387 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:142388
[email protected]a27cbde2013-03-23 22:01:492389template <class Types>
[email protected]ca2902e92013-03-28 01:45:352390class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter
2391 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492392 protected:
[email protected]ca2902e92013-03-28 01:45:352393 explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:492394 bool opaque_layers)
2395 : OcclusionTrackerTest<Types>(opaque_layers) {}
2396 void RunMyTest() {
2397 gfx::Transform scale_by_half;
2398 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142399
[email protected]a27cbde2013-03-23 22:01:492400 // Make a surface and its replica, each 50x50, with a smaller 30x30 layer
2401 // centered below each. The surface is scaled to test that the pixel moving
2402 // is done in the target space, where the background filter is applied, but
2403 // the surface appears at 50, 50 and the replica at 200, 50.
2404 typename Types::ContentLayerType* parent = this->CreateRoot(
2405 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
2406 typename Types::LayerType* behind_surface_layer =
2407 this->CreateDrawingLayer(parent,
2408 this->identity_matrix,
2409 gfx::PointF(60.f, 60.f),
2410 gfx::Size(30, 30),
2411 true);
2412 typename Types::LayerType* behind_replica_layer =
2413 this->CreateDrawingLayer(parent,
2414 this->identity_matrix,
2415 gfx::PointF(210.f, 60.f),
2416 gfx::Size(30, 30),
2417 true);
2418 typename Types::LayerType* filtered_surface =
2419 this->CreateDrawingLayer(parent,
2420 scale_by_half,
2421 gfx::PointF(50.f, 50.f),
2422 gfx::Size(100, 100),
2423 false);
2424 this->CreateReplicaLayer(filtered_surface,
2425 this->identity_matrix,
2426 gfx::PointF(300.f, 0.f),
2427 gfx::Size());
[email protected]94f206c12012-08-25 00:09:142428
[email protected]a27cbde2013-03-23 22:01:492429 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:292430 FilterOperations filters;
2431 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:492432 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142433
[email protected]a27cbde2013-03-23 22:01:492434 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142435
[email protected]34ba1ffb2014-03-05 06:55:032436 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492437 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142438
[email protected]a27cbde2013-03-23 22:01:492439 // The surface has a background blur, so it blurs non-opaque pixels below
2440 // it.
[email protected]d002dd02013-03-27 07:40:402441 this->VisitLayer(filtered_surface, &occlusion);
2442 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142443
[email protected]d002dd02013-03-27 07:40:402444 this->VisitLayer(behind_replica_layer, &occlusion);
[email protected]d5467eb72014-08-22 01:16:432445
2446 // The layers behind the surface are not blurred, and their occlusion does
2447 // not change, until we leave the surface. So it should not be modified by
2448 // the filter here.
2449 gfx::Rect occlusion_behind_replica = gfx::Rect(210, 60, 30, 30);
2450 EXPECT_EQ(occlusion_behind_replica.ToString(),
2451 occlusion.occlusion_from_inside_target().ToString());
2452 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
2453
2454 // Clear the occlusion so the |behind_surface_layer| can add its occlusion
2455 // without existing occlusion interfering.
2456 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2457
[email protected]d002dd02013-03-27 07:40:402458 this->VisitLayer(behind_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:142459
[email protected]a27cbde2013-03-23 22:01:492460 // The layers behind the surface are not blurred, and their occlusion does
2461 // not change, until we leave the surface. So it should not be modified by
2462 // the filter here.
2463 gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30);
[email protected]d5467eb72014-08-22 01:16:432464 EXPECT_EQ(occlusion_behind_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:492465 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432466 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:492467 }
[email protected]94f206c12012-08-25 00:09:142468};
2469
[email protected]a27cbde2013-03-23 22:01:492470ALL_OCCLUSIONTRACKER_TEST(
2471 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:142472
[email protected]a27cbde2013-03-23 22:01:492473template <class Types>
[email protected]ca2902e92013-03-28 01:45:352474class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded
2475 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492476 protected:
[email protected]ca2902e92013-03-28 01:45:352477 explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(
[email protected]a27cbde2013-03-23 22:01:492478 bool opaque_layers)
2479 : OcclusionTrackerTest<Types>(opaque_layers) {}
2480 void RunMyTest() {
2481 gfx::Transform scale_by_half;
2482 scale_by_half.Scale(0.5, 0.5);
2483
[email protected]66b52e12013-11-17 15:53:182484 // Make a 50x50 filtered surface that is completely occluded by an opaque
2485 // layer which is above it in the z-order. The surface is
[email protected]a27cbde2013-03-23 22:01:492486 // scaled to test that the pixel moving is done in the target space, where
[email protected]66b52e12013-11-17 15:53:182487 // the background filter is applied, but the surface appears at 50, 50.
[email protected]a27cbde2013-03-23 22:01:492488 typename Types::ContentLayerType* parent = this->CreateRoot(
[email protected]66b52e12013-11-17 15:53:182489 this->identity_matrix, gfx::PointF(), gfx::Size(200, 150));
[email protected]a27cbde2013-03-23 22:01:492490 typename Types::LayerType* filtered_surface =
2491 this->CreateDrawingLayer(parent,
2492 scale_by_half,
2493 gfx::PointF(50.f, 50.f),
2494 gfx::Size(100, 100),
2495 false);
[email protected]66b52e12013-11-17 15:53:182496 typename Types::LayerType* occluding_layer =
[email protected]a27cbde2013-03-23 22:01:492497 this->CreateDrawingLayer(parent,
2498 this->identity_matrix,
2499 gfx::PointF(50.f, 50.f),
2500 gfx::Size(50, 50),
2501 true);
[email protected]a27cbde2013-03-23 22:01:492502
2503 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:292504 FilterOperations filters;
2505 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:492506 filtered_surface->SetBackgroundFilters(filters);
2507
2508 this->CalcDrawEtc(parent);
2509
[email protected]34ba1ffb2014-03-05 06:55:032510 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492511 gfx::Rect(0, 0, 1000, 1000));
2512
[email protected]66b52e12013-11-17 15:53:182513 this->VisitLayer(occluding_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492514
[email protected]d002dd02013-03-27 07:40:402515 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142516 {
[email protected]a27cbde2013-03-23 22:01:492517 // The layers above the filtered surface occlude from outside.
2518 gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50);
[email protected]94f206c12012-08-25 00:09:142519
[email protected]a27cbde2013-03-23 22:01:492520 EXPECT_EQ(gfx::Rect().ToString(),
2521 occlusion.occlusion_from_inside_target().ToString());
[email protected]66b52e12013-11-17 15:53:182522 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:492523 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142524 }
[email protected]a27cbde2013-03-23 22:01:492525
2526 // The surface has a background blur, so it blurs non-opaque pixels below
2527 // it.
[email protected]d002dd02013-03-27 07:40:402528 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492529 {
2530 // The filter is completely occluded, so it should not blur anything and
2531 // reduce any occlusion.
2532 gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50);
[email protected]a27cbde2013-03-23 22:01:492533
[email protected]66b52e12013-11-17 15:53:182534 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:492535 occlusion.occlusion_from_inside_target().ToString());
2536 EXPECT_EQ(gfx::Rect().ToString(),
2537 occlusion.occlusion_from_outside_target().ToString());
2538 }
2539 }
[email protected]94f206c12012-08-25 00:09:142540};
2541
[email protected]a27cbde2013-03-23 22:01:492542ALL_OCCLUSIONTRACKER_TEST(
2543 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:142544
[email protected]a27cbde2013-03-23 22:01:492545template <class Types>
[email protected]ca2902e92013-03-28 01:45:352546class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded
2547 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492548 protected:
[email protected]ca2902e92013-03-28 01:45:352549 explicit
[email protected]a27cbde2013-03-23 22:01:492550 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded(
2551 bool opaque_layers)
2552 : OcclusionTrackerTest<Types>(opaque_layers) {}
2553 void RunMyTest() {
2554 gfx::Transform scale_by_half;
2555 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:142556
[email protected]a27cbde2013-03-23 22:01:492557 // Make a surface and its replica, each 50x50, that are partially occluded
2558 // by opaque layers which are above them in the z-order. The surface is
2559 // scaled to test that the pixel moving is done in the target space, where
2560 // the background filter is applied, but the surface appears at 50, 50 and
2561 // the replica at 200, 50.
2562 typename Types::ContentLayerType* parent = this->CreateRoot(
2563 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
2564 typename Types::LayerType* filtered_surface =
2565 this->CreateDrawingLayer(parent,
2566 scale_by_half,
2567 gfx::PointF(50.f, 50.f),
2568 gfx::Size(100, 100),
2569 false);
2570 this->CreateReplicaLayer(filtered_surface,
2571 this->identity_matrix,
2572 gfx::PointF(300.f, 0.f),
2573 gfx::Size());
2574 typename Types::LayerType* above_surface_layer =
2575 this->CreateDrawingLayer(parent,
2576 this->identity_matrix,
2577 gfx::PointF(70.f, 50.f),
2578 gfx::Size(30, 50),
2579 true);
2580 typename Types::LayerType* above_replica_layer =
2581 this->CreateDrawingLayer(parent,
2582 this->identity_matrix,
2583 gfx::PointF(200.f, 50.f),
2584 gfx::Size(30, 50),
2585 true);
2586 typename Types::LayerType* beside_surface_layer =
2587 this->CreateDrawingLayer(parent,
2588 this->identity_matrix,
2589 gfx::PointF(90.f, 40.f),
2590 gfx::Size(10, 10),
2591 true);
2592 typename Types::LayerType* beside_replica_layer =
2593 this->CreateDrawingLayer(parent,
2594 this->identity_matrix,
2595 gfx::PointF(200.f, 40.f),
2596 gfx::Size(10, 10),
2597 true);
[email protected]94f206c12012-08-25 00:09:142598
[email protected]a27cbde2013-03-23 22:01:492599 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:292600 FilterOperations filters;
2601 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:492602 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:142603
[email protected]a27cbde2013-03-23 22:01:492604 // Save the distance of influence for the blur effect.
2605 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:292606 filters.GetOutsets(
2607 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:142608
[email protected]a27cbde2013-03-23 22:01:492609 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142610
[email protected]34ba1ffb2014-03-05 06:55:032611 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492612 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142613
[email protected]d002dd02013-03-27 07:40:402614 this->VisitLayer(beside_replica_layer, &occlusion);
2615 this->VisitLayer(beside_surface_layer, &occlusion);
2616 this->VisitLayer(above_replica_layer, &occlusion);
2617 this->VisitLayer(above_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:142618
[email protected]a27cbde2013-03-23 22:01:492619 // The surface has a background blur, so it blurs non-opaque pixels below
2620 // it.
[email protected]d002dd02013-03-27 07:40:402621 this->VisitLayer(filtered_surface, &occlusion);
2622 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142623
[email protected]a27cbde2013-03-23 22:01:492624 // The filter in the surface and replica are partially unoccluded. Only the
2625 // unoccluded parts should reduce occlusion. This means it will push back
[email protected]ed511b8d2013-03-25 03:29:292626 // the occlusion that touches the unoccluded part (occlusion_above___), but
[email protected]a27cbde2013-03-23 22:01:492627 // it will not touch occlusion_beside____ since that is not beside the
2628 // unoccluded part of the surface, even though it is beside the occluded
2629 // part of the surface.
2630 gfx::Rect occlusion_above_surface =
2631 gfx::Rect(70 + outset_right, 50, 30 - outset_right, 50);
2632 gfx::Rect occlusion_above_replica =
2633 gfx::Rect(200, 50, 30 - outset_left, 50);
2634 gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10);
2635 gfx::Rect occlusion_beside_replica = gfx::Rect(200, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:142636
[email protected]d5467eb72014-08-22 01:16:432637 SimpleEnclosedRegion expected_occlusion;
[email protected]a27cbde2013-03-23 22:01:492638 expected_occlusion.Union(occlusion_beside_replica);
[email protected]d5467eb72014-08-22 01:16:432639 expected_occlusion.Union(occlusion_beside_surface);
2640 expected_occlusion.Union(occlusion_above_replica);
2641 expected_occlusion.Union(occlusion_above_surface);
[email protected]94f206c12012-08-25 00:09:142642
[email protected]d5467eb72014-08-22 01:16:432643 EXPECT_EQ(expected_occlusion.ToString(),
[email protected]a27cbde2013-03-23 22:01:492644 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:432645 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142646
[email protected]d5467eb72014-08-22 01:16:432647 const SimpleEnclosedRegion& actual_occlusion =
2648 occlusion.occlusion_from_inside_target();
2649 for (size_t i = 0; i < expected_occlusion.GetRegionComplexity(); ++i) {
2650 ASSERT_LT(i, actual_occlusion.GetRegionComplexity());
2651 EXPECT_EQ(expected_occlusion.GetRect(i), actual_occlusion.GetRect(i));
[email protected]94f206c12012-08-25 00:09:142652 }
[email protected]a27cbde2013-03-23 22:01:492653 }
[email protected]94f206c12012-08-25 00:09:142654};
2655
[email protected]a27cbde2013-03-23 22:01:492656ALL_OCCLUSIONTRACKER_TEST(
2657 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:142658
[email protected]a27cbde2013-03-23 22:01:492659template <class Types>
[email protected]ca2902e92013-03-28 01:45:352660class OcclusionTrackerTestMinimumTrackingSize
2661 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492662 protected:
[email protected]ca2902e92013-03-28 01:45:352663 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492664 : OcclusionTrackerTest<Types>(opaque_layers) {}
2665 void RunMyTest() {
2666 gfx::Size tracking_size(100, 100);
2667 gfx::Size below_tracking_size(99, 99);
[email protected]94f206c12012-08-25 00:09:142668
[email protected]a27cbde2013-03-23 22:01:492669 typename Types::ContentLayerType* parent = this->CreateRoot(
2670 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
2671 typename Types::LayerType* large = this->CreateDrawingLayer(
2672 parent, this->identity_matrix, gfx::PointF(), tracking_size, true);
2673 typename Types::LayerType* small =
2674 this->CreateDrawingLayer(parent,
2675 this->identity_matrix,
2676 gfx::PointF(),
2677 below_tracking_size,
2678 true);
2679 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142680
[email protected]34ba1ffb2014-03-05 06:55:032681 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]a27cbde2013-03-23 22:01:492682 gfx::Rect(0, 0, 1000, 1000));
2683 occlusion.set_minimum_tracking_size(tracking_size);
[email protected]94f206c12012-08-25 00:09:142684
[email protected]a27cbde2013-03-23 22:01:492685 // The small layer is not tracked because it is too small.
[email protected]d002dd02013-03-27 07:40:402686 this->VisitLayer(small, &occlusion);
[email protected]94f206c12012-08-25 00:09:142687
[email protected]a27cbde2013-03-23 22:01:492688 EXPECT_EQ(gfx::Rect().ToString(),
2689 occlusion.occlusion_from_outside_target().ToString());
2690 EXPECT_EQ(gfx::Rect().ToString(),
2691 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142692
[email protected]a27cbde2013-03-23 22:01:492693 // The large layer is tracked as it is large enough.
[email protected]d002dd02013-03-27 07:40:402694 this->VisitLayer(large, &occlusion);
[email protected]94f206c12012-08-25 00:09:142695
[email protected]a27cbde2013-03-23 22:01:492696 EXPECT_EQ(gfx::Rect().ToString(),
2697 occlusion.occlusion_from_outside_target().ToString());
[email protected]2c7c6702013-03-26 03:14:052698 EXPECT_EQ(gfx::Rect(tracking_size).ToString(),
[email protected]a27cbde2013-03-23 22:01:492699 occlusion.occlusion_from_inside_target().ToString());
2700 }
[email protected]94f206c12012-08-25 00:09:142701};
2702
[email protected]96baf3e2012-10-22 23:09:552703ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:142704
[email protected]a27cbde2013-03-23 22:01:492705template <class Types>
[email protected]1a5d9ce2013-04-30 01:31:092706class OcclusionTrackerTestScaledLayerIsClipped
2707 : public OcclusionTrackerTest<Types> {
2708 protected:
2709 explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers)
2710 : OcclusionTrackerTest<Types>(opaque_layers) {}
2711 void RunMyTest() {
2712 gfx::Transform scale_transform;
2713 scale_transform.Scale(512.0, 512.0);
2714
2715 typename Types::ContentLayerType* parent = this->CreateRoot(
2716 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
2717 typename Types::LayerType* clip = this->CreateLayer(parent,
2718 this->identity_matrix,
2719 gfx::PointF(10.f, 10.f),
2720 gfx::Size(50, 50));
2721 clip->SetMasksToBounds(true);
2722 typename Types::LayerType* scale = this->CreateLayer(
2723 clip, scale_transform, gfx::PointF(), gfx::Size(1, 1));
2724 typename Types::LayerType* scaled = this->CreateDrawingLayer(
2725 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
2726 this->CalcDrawEtc(parent);
2727
[email protected]34ba1ffb2014-03-05 06:55:032728 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]1a5d9ce2013-04-30 01:31:092729 gfx::Rect(0, 0, 1000, 1000));
2730
2731 this->VisitLayer(scaled, &occlusion);
2732
2733 EXPECT_EQ(gfx::Rect().ToString(),
2734 occlusion.occlusion_from_outside_target().ToString());
2735 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
2736 occlusion.occlusion_from_inside_target().ToString());
2737 }
2738};
2739
2740ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped)
2741
2742template <class Types>
2743class OcclusionTrackerTestScaledLayerInSurfaceIsClipped
2744 : public OcclusionTrackerTest<Types> {
2745 protected:
2746 explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers)
2747 : OcclusionTrackerTest<Types>(opaque_layers) {}
2748 void RunMyTest() {
2749 gfx::Transform scale_transform;
2750 scale_transform.Scale(512.0, 512.0);
2751
2752 typename Types::ContentLayerType* parent = this->CreateRoot(
2753 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
2754 typename Types::LayerType* clip = this->CreateLayer(parent,
2755 this->identity_matrix,
2756 gfx::PointF(10.f, 10.f),
2757 gfx::Size(50, 50));
2758 clip->SetMasksToBounds(true);
2759 typename Types::LayerType* surface = this->CreateDrawingSurface(
2760 clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false);
2761 typename Types::LayerType* scale = this->CreateLayer(
2762 surface, scale_transform, gfx::PointF(), gfx::Size(1, 1));
2763 typename Types::LayerType* scaled = this->CreateDrawingLayer(
2764 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
2765 this->CalcDrawEtc(parent);
2766
[email protected]34ba1ffb2014-03-05 06:55:032767 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]1a5d9ce2013-04-30 01:31:092768 gfx::Rect(0, 0, 1000, 1000));
2769
2770 this->VisitLayer(scaled, &occlusion);
2771 this->VisitLayer(surface, &occlusion);
2772 this->VisitContributingSurface(surface, &occlusion);
2773
2774 EXPECT_EQ(gfx::Rect().ToString(),
2775 occlusion.occlusion_from_outside_target().ToString());
2776 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
2777 occlusion.occlusion_from_inside_target().ToString());
2778 }
2779};
2780
2781ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped)
2782
[email protected]5b54b972013-07-26 13:25:422783template <class Types>
2784class OcclusionTrackerTestCopyRequestDoesOcclude
2785 : public OcclusionTrackerTest<Types> {
2786 protected:
2787 explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers)
2788 : OcclusionTrackerTest<Types>(opaque_layers) {}
2789 void RunMyTest() {
2790 typename Types::ContentLayerType* root = this->CreateRoot(
2791 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
2792 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
2793 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
2794 typename Types::LayerType* copy = this->CreateLayer(parent,
2795 this->identity_matrix,
2796 gfx::Point(100, 0),
2797 gfx::Size(200, 400));
2798 this->AddCopyRequest(copy);
2799 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
2800 copy,
2801 this->identity_matrix,
2802 gfx::PointF(),
2803 gfx::Size(200, 400),
2804 true);
2805 this->CalcDrawEtc(root);
2806
[email protected]34ba1ffb2014-03-05 06:55:032807 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]5b54b972013-07-26 13:25:422808 gfx::Rect(0, 0, 1000, 1000));
2809
2810 this->VisitLayer(copy_child, &occlusion);
2811 EXPECT_EQ(gfx::Rect().ToString(),
2812 occlusion.occlusion_from_outside_target().ToString());
2813 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
2814 occlusion.occlusion_from_inside_target().ToString());
2815
2816 // CopyRequests cause the layer to own a surface.
2817 this->VisitContributingSurface(copy, &occlusion);
2818
2819 // The occlusion from the copy should be kept.
2820 EXPECT_EQ(gfx::Rect().ToString(),
2821 occlusion.occlusion_from_outside_target().ToString());
2822 EXPECT_EQ(gfx::Rect(100, 0, 200, 400).ToString(),
2823 occlusion.occlusion_from_inside_target().ToString());
2824 }
2825};
2826
2827ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude)
2828
2829template <class Types>
2830class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude
2831 : public OcclusionTrackerTest<Types> {
2832 protected:
2833 explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude(
2834 bool opaque_layers)
2835 : OcclusionTrackerTest<Types>(opaque_layers) {}
2836 void RunMyTest() {
2837 typename Types::ContentLayerType* root = this->CreateRoot(
2838 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
2839 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
2840 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
2841 typename Types::LayerType* hide = this->CreateLayer(
2842 parent, this->identity_matrix, gfx::Point(), gfx::Size());
2843 typename Types::LayerType* copy = this->CreateLayer(
2844 hide, this->identity_matrix, gfx::Point(100, 0), gfx::Size(200, 400));
2845 this->AddCopyRequest(copy);
2846 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
2847 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
2848
2849 // The |copy| layer is hidden but since it is being copied, it will be
2850 // drawn.
2851 hide->SetHideLayerAndSubtree(true);
2852
2853 this->CalcDrawEtc(root);
2854
[email protected]34ba1ffb2014-03-05 06:55:032855 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
[email protected]5b54b972013-07-26 13:25:422856 gfx::Rect(0, 0, 1000, 1000));
2857
2858 this->VisitLayer(copy_child, &occlusion);
2859 EXPECT_EQ(gfx::Rect().ToString(),
2860 occlusion.occlusion_from_outside_target().ToString());
2861 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
2862 occlusion.occlusion_from_inside_target().ToString());
2863
2864 // CopyRequests cause the layer to own a surface.
2865 this->VisitContributingSurface(copy, &occlusion);
2866
2867 // The occlusion from the copy should be dropped since it is hidden.
2868 EXPECT_EQ(gfx::Rect().ToString(),
2869 occlusion.occlusion_from_outside_target().ToString());
2870 EXPECT_EQ(gfx::Rect().ToString(),
2871 occlusion.occlusion_from_inside_target().ToString());
2872 }
2873};
2874
2875ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude)
2876
[email protected]d5467eb72014-08-22 01:16:432877template <class Types>
2878class OcclusionTrackerTestOccludedLayer : public OcclusionTrackerTest<Types> {
2879 protected:
2880 explicit OcclusionTrackerTestOccludedLayer(bool opaque_layers)
2881 : OcclusionTrackerTest<Types>(opaque_layers) {}
2882 void RunMyTest() {
2883 gfx::Transform translate;
2884 translate.Translate(10.0, 20.0);
2885 typename Types::ContentLayerType* root = this->CreateRoot(
2886 this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2887 typename Types::LayerType* surface = this->CreateSurface(
2888 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2889 typename Types::LayerType* layer = this->CreateDrawingLayer(
2890 surface, translate, gfx::Point(), gfx::Size(200, 200), false);
2891 typename Types::ContentLayerType* outside_layer = this->CreateDrawingLayer(
2892 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), false);
2893 this->CalcDrawEtc(root);
2894
2895 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2896 gfx::Rect(0, 0, 200, 200));
2897 this->VisitLayer(outside_layer, &occlusion);
2898 this->EnterLayer(layer, &occlusion);
2899
2900 // No occlusion, is not occluded.
2901 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2902 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2903 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100)));
2904
2905 // Partial occlusion from outside, is not occluded.
2906 occlusion.set_occlusion_from_outside_target(
2907 SimpleEnclosedRegion(50, 50, 100, 100));
2908 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2909 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2910 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2911 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2912 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2913 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2914 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2915 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2916 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2917
2918 // Full occlusion from outside, is occluded.
2919 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2920 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2921 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2922 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2923
2924 // Partial occlusion from inside, is not occluded.
2925 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2926 occlusion.set_occlusion_from_inside_target(
2927 SimpleEnclosedRegion(50, 50, 100, 100));
2928 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2929 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2930 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2931 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2932 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2933 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2934 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2935 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2936
2937 // Full occlusion from inside, is occluded.
2938 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2939 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2940 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2941 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2942
2943 // Partial occlusion from both, is not occluded.
2944 occlusion.set_occlusion_from_outside_target(
2945 SimpleEnclosedRegion(50, 50, 100, 50));
2946 occlusion.set_occlusion_from_inside_target(
2947 SimpleEnclosedRegion(50, 100, 100, 50));
2948 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2949 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2950 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2951 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2952 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2953 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2954 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2955 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2956
2957 // Full occlusion from both, is occluded.
2958 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2959 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2960 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2961 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2962 }
2963};
2964
2965ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOccludedLayer)
2966
danakjf080b5b2014-08-23 22:18:202967template <class Types>
2968class OcclusionTrackerTestUnoccludedLayerQuery
2969 : public OcclusionTrackerTest<Types> {
2970 protected:
2971 explicit OcclusionTrackerTestUnoccludedLayerQuery(bool opaque_layers)
2972 : OcclusionTrackerTest<Types>(opaque_layers) {}
2973 void RunMyTest() {
2974 gfx::Transform translate;
2975 translate.Translate(10.0, 20.0);
2976 typename Types::ContentLayerType* root = this->CreateRoot(
2977 this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2978 typename Types::LayerType* surface = this->CreateSurface(
2979 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2980 typename Types::LayerType* layer = this->CreateDrawingLayer(
2981 surface, translate, gfx::Point(), gfx::Size(200, 200), false);
2982 typename Types::ContentLayerType* outside_layer = this->CreateDrawingLayer(
2983 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), false);
2984 this->CalcDrawEtc(root);
2985
2986 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2987 gfx::Rect(0, 0, 200, 200));
2988 this->VisitLayer(outside_layer, &occlusion);
2989 this->EnterLayer(layer, &occlusion);
2990
2991 // No occlusion, is not occluded.
2992 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2993 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2994 EXPECT_EQ(gfx::Rect(100, 100),
2995 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(100, 100)));
2996
2997 // Partial occlusion from outside.
2998 occlusion.set_occlusion_from_outside_target(
2999 SimpleEnclosedRegion(50, 50, 100, 100));
3000 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
3001 EXPECT_EQ(
3002 gfx::Rect(0, 0, 100, 100),
3003 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
3004 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3005 occlusion.UnoccludedLayerContentRect(
3006 layer, gfx::Rect(90, 30, 100, 100)));
3007 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3008 occlusion.UnoccludedLayerContentRect(layer,
3009 gfx::Rect(40, 0, 100, 100)));
3010 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3011 occlusion.UnoccludedLayerContentRect(
3012 layer, gfx::Rect(40, 80, 100, 100)));
3013 EXPECT_EQ(
3014 gfx::Rect(0, 0, 80, 100),
3015 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
3016 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3017 occlusion.UnoccludedLayerContentRect(
3018 layer, gfx::Rect(90, 80, 100, 100)));
3019 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3020 occlusion.UnoccludedLayerContentRect(layer,
3021 gfx::Rect(0, 80, 100, 100)));
3022 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3023 occlusion.UnoccludedLayerContentRect(layer,
3024 gfx::Rect(90, 0, 100, 100)));
3025
3026 // Full occlusion from outside, is occluded.
3027 EXPECT_EQ(gfx::Rect(),
3028 occlusion.UnoccludedLayerContentRect(
3029 layer, gfx::Rect(40, 30, 100, 100)));
3030 EXPECT_EQ(
3031 gfx::Rect(),
3032 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
3033 EXPECT_EQ(gfx::Rect(),
3034 occlusion.UnoccludedLayerContentRect(
3035 layer, gfx::Rect(130, 120, 10, 10)));
3036 EXPECT_EQ(
3037 gfx::Rect(),
3038 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
3039
3040 // Partial occlusion from inside, is not occluded.
3041 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
3042 occlusion.set_occlusion_from_inside_target(
3043 SimpleEnclosedRegion(50, 50, 100, 100));
3044 EXPECT_EQ(
3045 gfx::Rect(0, 0, 100, 100),
3046 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
3047 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3048 occlusion.UnoccludedLayerContentRect(
3049 layer, gfx::Rect(90, 30, 100, 100)));
3050 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3051 occlusion.UnoccludedLayerContentRect(layer,
3052 gfx::Rect(40, 0, 100, 100)));
3053 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3054 occlusion.UnoccludedLayerContentRect(
3055 layer, gfx::Rect(40, 80, 100, 100)));
3056 EXPECT_EQ(
3057 gfx::Rect(0, 0, 80, 100),
3058 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
3059 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3060 occlusion.UnoccludedLayerContentRect(
3061 layer, gfx::Rect(90, 80, 100, 100)));
3062 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3063 occlusion.UnoccludedLayerContentRect(layer,
3064 gfx::Rect(0, 80, 100, 100)));
3065 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3066 occlusion.UnoccludedLayerContentRect(layer,
3067 gfx::Rect(90, 0, 100, 100)));
3068
3069 // Full occlusion from inside, is occluded.
3070 EXPECT_EQ(gfx::Rect(),
3071 occlusion.UnoccludedLayerContentRect(
3072 layer, gfx::Rect(40, 30, 100, 100)));
3073 EXPECT_EQ(
3074 gfx::Rect(),
3075 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
3076 EXPECT_EQ(gfx::Rect(),
3077 occlusion.UnoccludedLayerContentRect(
3078 layer, gfx::Rect(130, 120, 10, 10)));
3079 EXPECT_EQ(
3080 gfx::Rect(),
3081 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
3082
3083 // Partial occlusion from both, is not occluded.
3084 occlusion.set_occlusion_from_outside_target(
3085 SimpleEnclosedRegion(50, 50, 100, 50));
3086 occlusion.set_occlusion_from_inside_target(
3087 SimpleEnclosedRegion(50, 100, 100, 50));
3088 EXPECT_EQ(
3089 gfx::Rect(0, 0, 100, 100),
3090 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
3091 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
3092 // it's larger.
3093 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
3094 occlusion.UnoccludedLayerContentRect(
3095 layer, gfx::Rect(90, 30, 100, 100)));
3096 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3097 occlusion.UnoccludedLayerContentRect(layer,
3098 gfx::Rect(40, 0, 100, 100)));
3099 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3100 occlusion.UnoccludedLayerContentRect(
3101 layer, gfx::Rect(40, 80, 100, 100)));
3102 EXPECT_EQ(
3103 gfx::Rect(0, 0, 80, 100),
3104 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
3105 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3106 occlusion.UnoccludedLayerContentRect(
3107 layer, gfx::Rect(90, 80, 100, 100)));
3108 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3109 occlusion.UnoccludedLayerContentRect(layer,
3110 gfx::Rect(0, 80, 100, 100)));
3111 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3112 occlusion.UnoccludedLayerContentRect(layer,
3113 gfx::Rect(90, 0, 100, 100)));
3114
3115 // Full occlusion from both, is occluded.
3116 EXPECT_EQ(gfx::Rect(),
3117 occlusion.UnoccludedLayerContentRect(
3118 layer, gfx::Rect(40, 30, 100, 100)));
3119 EXPECT_EQ(
3120 gfx::Rect(),
3121 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
3122 EXPECT_EQ(gfx::Rect(),
3123 occlusion.UnoccludedLayerContentRect(
3124 layer, gfx::Rect(130, 120, 10, 10)));
3125 EXPECT_EQ(
3126 gfx::Rect(),
3127 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
3128 }
3129};
3130
3131ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedLayerQuery)
3132
3133template <class Types>
3134class OcclusionTrackerTestUnoccludedSurfaceQuery
3135 : public OcclusionTrackerTest<Types> {
3136 protected:
3137 explicit OcclusionTrackerTestUnoccludedSurfaceQuery(bool opaque_layers)
3138 : OcclusionTrackerTest<Types>(opaque_layers) {}
3139 void RunMyTest() {
3140 gfx::Transform translate;
3141 translate.Translate(10.0, 20.0);
3142 typename Types::ContentLayerType* root = this->CreateRoot(
3143 this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
3144 typename Types::LayerType* surface =
3145 this->CreateSurface(root, translate, gfx::Point(), gfx::Size(200, 200));
3146 typename Types::LayerType* layer =
3147 this->CreateDrawingLayer(surface,
3148 this->identity_matrix,
3149 gfx::Point(),
3150 gfx::Size(200, 200),
3151 false);
3152 typename Types::ContentLayerType* outside_layer = this->CreateDrawingLayer(
3153 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), false);
3154 this->CalcDrawEtc(root);
3155
3156 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
3157 gfx::Rect(0, 0, 200, 200));
3158 this->VisitLayer(outside_layer, &occlusion);
3159 this->VisitLayer(layer, &occlusion);
3160 this->EnterContributingSurface(surface, &occlusion);
3161
3162 // No occlusion, is not occluded.
3163 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3164 SimpleEnclosedRegion());
3165 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3166 SimpleEnclosedRegion());
3167 EXPECT_EQ(
3168 gfx::Rect(100, 100),
3169 occlusion.UnoccludedSurfaceContentRect(surface, gfx::Rect(100, 100)));
3170
3171 // Partial occlusion from outside.
3172 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3173 SimpleEnclosedRegion(50, 50, 100, 100));
3174 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3175 SimpleEnclosedRegion());
3176 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3177 occlusion.UnoccludedSurfaceContentRect(
3178 surface, gfx::Rect(0, 0, 100, 100)));
3179 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3180 occlusion.UnoccludedSurfaceContentRect(
3181 surface, gfx::Rect(90, 30, 100, 100)));
3182 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3183 occlusion.UnoccludedSurfaceContentRect(
3184 surface, gfx::Rect(40, 0, 100, 100)));
3185 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3186 occlusion.UnoccludedSurfaceContentRect(
3187 surface, gfx::Rect(40, 80, 100, 100)));
3188 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
3189 occlusion.UnoccludedSurfaceContentRect(surface,
3190 gfx::Rect(0, 0, 80, 100)));
3191 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3192 occlusion.UnoccludedSurfaceContentRect(
3193 surface, gfx::Rect(90, 80, 100, 100)));
3194 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3195 occlusion.UnoccludedSurfaceContentRect(
3196 surface, gfx::Rect(0, 80, 100, 100)));
3197 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3198 occlusion.UnoccludedSurfaceContentRect(
3199 surface, gfx::Rect(90, 0, 100, 100)));
3200
3201 // Full occlusion from outside, is occluded.
3202 EXPECT_EQ(gfx::Rect(),
3203 occlusion.UnoccludedSurfaceContentRect(
3204 surface, gfx::Rect(40, 30, 100, 100)));
3205 EXPECT_EQ(gfx::Rect(),
3206 occlusion.UnoccludedSurfaceContentRect(
3207 surface, gfx::Rect(40, 30, 10, 10)));
3208 EXPECT_EQ(gfx::Rect(),
3209 occlusion.UnoccludedSurfaceContentRect(
3210 surface, gfx::Rect(130, 120, 10, 10)));
3211 EXPECT_EQ(gfx::Rect(),
3212 occlusion.UnoccludedSurfaceContentRect(
3213 surface, gfx::Rect(80, 70, 50, 50)));
3214
3215 // Partial occlusion from inside, is not occluded.
3216 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3217 SimpleEnclosedRegion());
3218 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3219 SimpleEnclosedRegion(50, 50, 100, 100));
3220 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3221 occlusion.UnoccludedSurfaceContentRect(
3222 surface, gfx::Rect(0, 0, 100, 100)));
3223 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3224 occlusion.UnoccludedSurfaceContentRect(
3225 surface, gfx::Rect(90, 30, 100, 100)));
3226 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3227 occlusion.UnoccludedSurfaceContentRect(
3228 surface, gfx::Rect(40, 0, 100, 100)));
3229 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3230 occlusion.UnoccludedSurfaceContentRect(
3231 surface, gfx::Rect(40, 80, 100, 100)));
3232 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
3233 occlusion.UnoccludedSurfaceContentRect(surface,
3234 gfx::Rect(0, 0, 80, 100)));
3235 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3236 occlusion.UnoccludedSurfaceContentRect(
3237 surface, gfx::Rect(90, 80, 100, 100)));
3238 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3239 occlusion.UnoccludedSurfaceContentRect(
3240 surface, gfx::Rect(0, 80, 100, 100)));
3241 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3242 occlusion.UnoccludedSurfaceContentRect(
3243 surface, gfx::Rect(90, 0, 100, 100)));
3244
3245 // Full occlusion from inside, is occluded.
3246 EXPECT_EQ(gfx::Rect(),
3247 occlusion.UnoccludedSurfaceContentRect(
3248 surface, gfx::Rect(40, 30, 100, 100)));
3249 EXPECT_EQ(gfx::Rect(),
3250 occlusion.UnoccludedSurfaceContentRect(
3251 surface, gfx::Rect(40, 30, 10, 10)));
3252 EXPECT_EQ(gfx::Rect(),
3253 occlusion.UnoccludedSurfaceContentRect(
3254 surface, gfx::Rect(130, 120, 10, 10)));
3255 EXPECT_EQ(gfx::Rect(),
3256 occlusion.UnoccludedSurfaceContentRect(
3257 surface, gfx::Rect(80, 70, 50, 50)));
3258
3259 // Partial occlusion from both, is not occluded.
3260 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3261 SimpleEnclosedRegion(50, 50, 100, 50));
3262 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3263 SimpleEnclosedRegion(50, 100, 100, 50));
3264 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3265 occlusion.UnoccludedSurfaceContentRect(
3266 surface, gfx::Rect(0, 0, 100, 100)));
3267 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
3268 // it's larger.
3269 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
3270 occlusion.UnoccludedSurfaceContentRect(
3271 surface, gfx::Rect(90, 30, 100, 100)));
3272 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3273 occlusion.UnoccludedSurfaceContentRect(
3274 surface, gfx::Rect(40, 0, 100, 100)));
3275 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3276 occlusion.UnoccludedSurfaceContentRect(
3277 surface, gfx::Rect(40, 80, 100, 100)));
3278 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
3279 occlusion.UnoccludedSurfaceContentRect(surface,
3280 gfx::Rect(0, 0, 80, 100)));
3281 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3282 occlusion.UnoccludedSurfaceContentRect(
3283 surface, gfx::Rect(90, 80, 100, 100)));
3284 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3285 occlusion.UnoccludedSurfaceContentRect(
3286 surface, gfx::Rect(0, 80, 100, 100)));
3287 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3288 occlusion.UnoccludedSurfaceContentRect(
3289 surface, gfx::Rect(90, 0, 100, 100)));
3290
3291 // Full occlusion from both, is occluded.
3292 EXPECT_EQ(gfx::Rect(),
3293 occlusion.UnoccludedSurfaceContentRect(
3294 surface, gfx::Rect(40, 30, 100, 100)));
3295 EXPECT_EQ(gfx::Rect(),
3296 occlusion.UnoccludedSurfaceContentRect(
3297 surface, gfx::Rect(40, 30, 10, 10)));
3298 EXPECT_EQ(gfx::Rect(),
3299 occlusion.UnoccludedSurfaceContentRect(
3300 surface, gfx::Rect(130, 120, 10, 10)));
3301 EXPECT_EQ(gfx::Rect(),
3302 occlusion.UnoccludedSurfaceContentRect(
3303 surface, gfx::Rect(80, 70, 50, 50)));
3304 }
3305};
3306
3307ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery)
3308
[email protected]ba565742012-11-10 09:29:483309} // namespace
3310} // namespace cc