blob: e91184aa90f23485ab489228fefa76ee1c011763 [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]6e84de22013-03-18 06:54:279#include "cc/debug/overdraw_metrics.h"
[email protected]cc3cfaa2013-03-18 09:05:5210#include "cc/layers/layer.h"
11#include "cc/layers/layer_impl.h"
[email protected]5b54b972013-07-26 13:25:4212#include "cc/output/copy_output_request.h"
13#include "cc/output/copy_output_result.h"
[email protected]ae6b1a72013-06-25 18:49:2914#include "cc/output/filter_operation.h"
15#include "cc/output/filter_operations.h"
[email protected]101441ce2012-10-16 01:45:0316#include "cc/test/animation_test_common.h"
[email protected]586d51ed2012-12-07 20:31:4517#include "cc/test/fake_impl_proxy.h"
18#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0319#include "cc/test/geometry_test_utils.h"
20#include "cc/test/occlusion_tracker_test_common.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:
32 TestContentLayer() : Layer(), override_opaque_contents_rect_(false) {}
[email protected]94f206c12012-08-25 00:09:1433
[email protected]a27cbde2013-03-23 22:01:4934 virtual bool DrawsContent() const OVERRIDE { return true; }
35 virtual Region VisibleContentOpaqueRegion() const OVERRIDE {
36 if (override_opaque_contents_rect_)
37 return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect());
38 return Layer::VisibleContentOpaqueRegion();
39 }
40 void SetOpaqueContentsRect(gfx::Rect opaque_contents_rect) {
41 override_opaque_contents_rect_ = true;
42 opaque_contents_rect_ = opaque_contents_rect;
43 }
[email protected]94f206c12012-08-25 00:09:1444
[email protected]a27cbde2013-03-23 22:01:4945 private:
46 virtual ~TestContentLayer() {}
[email protected]d58499a2012-10-09 22:27:4747
[email protected]a27cbde2013-03-23 22:01:4948 bool override_opaque_contents_rect_;
49 gfx::Rect opaque_contents_rect_;
[email protected]94f206c12012-08-25 00:09:1450};
51
[email protected]96baf3e2012-10-22 23:09:5552class TestContentLayerImpl : public LayerImpl {
[email protected]a27cbde2013-03-23 22:01:4953 public:
54 TestContentLayerImpl(LayerTreeImpl* tree_impl, int id)
55 : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) {
56 SetDrawsContent(true);
57 }
[email protected]94f206c12012-08-25 00:09:1458
[email protected]a27cbde2013-03-23 22:01:4959 virtual Region VisibleContentOpaqueRegion() const OVERRIDE {
60 if (override_opaque_contents_rect_)
61 return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect());
62 return LayerImpl::VisibleContentOpaqueRegion();
63 }
64 void SetOpaqueContentsRect(gfx::Rect opaque_contents_rect) {
65 override_opaque_contents_rect_ = true;
66 opaque_contents_rect_ = opaque_contents_rect;
67 }
[email protected]94f206c12012-08-25 00:09:1468
[email protected]a27cbde2013-03-23 22:01:4969 private:
70 bool override_opaque_contents_rect_;
71 gfx::Rect opaque_contents_rect_;
[email protected]94f206c12012-08-25 00:09:1472};
73
[email protected]a27cbde2013-03-23 22:01:4974static inline bool LayerImplDrawTransformIsUnknown(const Layer* layer) {
75 return layer->draw_transform_is_animating();
76}
77static inline bool LayerImplDrawTransformIsUnknown(const LayerImpl* layer) {
78 return false;
79}
[email protected]710ffc02012-10-30 21:42:0280
[email protected]a27cbde2013-03-23 22:01:4981template <typename LayerType, typename RenderSurfaceType>
[email protected]ca2902e92013-03-28 01:45:3582class TestOcclusionTrackerWithClip
83 : public TestOcclusionTrackerBase<LayerType, RenderSurfaceType> {
[email protected]a27cbde2013-03-23 22:01:4984 public:
85 TestOcclusionTrackerWithClip(gfx::Rect viewport_rect,
86 bool record_metrics_for_frame)
87 : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(
88 viewport_rect,
89 record_metrics_for_frame) {}
[email protected]ca2902e92013-03-28 01:45:3590 explicit TestOcclusionTrackerWithClip(gfx::Rect viewport_rect)
[email protected]a27cbde2013-03-23 22:01:4991 : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(viewport_rect,
92 false) {}
[email protected]94f206c12012-08-25 00:09:1493
[email protected]a27cbde2013-03-23 22:01:4994 bool OccludedLayer(const LayerType* layer, gfx::Rect content_rect) {
95 bool temp;
96 return OccludedLayer(layer, content_rect, &temp);
97 }
98
99 bool OccludedLayer(const LayerType* layer,
100 gfx::Rect content_rect,
101 bool* has_occlusion_from_outside_target_surface) const {
102 return this->Occluded(layer->render_target(),
103 content_rect,
104 layer->draw_transform(),
105 LayerImplDrawTransformIsUnknown(layer),
106 layer->is_clipped(),
107 layer->clip_rect(),
108 has_occlusion_from_outside_target_surface);
109 }
110 // Gives an unoccluded sub-rect of |content_rect| in the content space of the
[email protected]ed511b8d2013-03-25 03:29:29111 // layer. Simple wrapper around UnoccludedContentRect.
[email protected]a27cbde2013-03-23 22:01:49112 gfx::Rect UnoccludedLayerContentRect(const LayerType* layer,
113 gfx::Rect content_rect) const {
114 bool temp;
115 return UnoccludedLayerContentRect(layer, content_rect, &temp);
116 }
117
118 gfx::Rect UnoccludedLayerContentRect(
119 const LayerType* layer,
120 gfx::Rect content_rect,
121 bool* has_occlusion_from_outside_target_surface) const {
122 return this->UnoccludedContentRect(
123 layer->render_target(),
124 content_rect,
125 layer->draw_transform(),
126 LayerImplDrawTransformIsUnknown(layer),
127 layer->is_clipped(),
128 layer->clip_rect(),
129 has_occlusion_from_outside_target_surface);
130 }
[email protected]94f206c12012-08-25 00:09:14131};
132
[email protected]96baf3e2012-10-22 23:09:55133struct OcclusionTrackerTestMainThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49134 typedef Layer LayerType;
135 typedef LayerTreeHost HostType;
136 typedef RenderSurface RenderSurfaceType;
137 typedef TestContentLayer ContentLayerType;
138 typedef scoped_refptr<Layer> LayerPtrType;
139 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
140 typedef LayerIterator<Layer,
[email protected]989386c2013-07-18 21:37:23141 RenderSurfaceLayerList,
[email protected]a27cbde2013-03-23 22:01:49142 RenderSurface,
143 LayerIteratorActions::FrontToBack> TestLayerIterator;
144 typedef OcclusionTracker OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14145
[email protected]a27cbde2013-03-23 22:01:49146 static LayerPtrType CreateLayer(HostType* host) { return Layer::Create(); }
147 static ContentLayerPtrType CreateContentLayer(HostType* host) {
148 return make_scoped_refptr(new ContentLayerType());
149 }
[email protected]e0bd43a2012-10-12 16:54:21150
[email protected]a27cbde2013-03-23 22:01:49151 static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) {
152 LayerPtrType ref(*layer);
153 *layer = NULL;
154 return ref;
155 }
[email protected]e0bd43a2012-10-12 16:54:21156
[email protected]a27cbde2013-03-23 22:01:49157 static LayerPtrType PassLayerPtr(LayerPtrType* layer) {
158 LayerPtrType ref(*layer);
159 *layer = NULL;
160 return ref;
161 }
[email protected]d58499a2012-10-09 22:27:47162
[email protected]a27cbde2013-03-23 22:01:49163 static void DestroyLayer(LayerPtrType* layer) { *layer = NULL; }
[email protected]94f206c12012-08-25 00:09:14164};
165
[email protected]96baf3e2012-10-22 23:09:55166struct OcclusionTrackerTestImplThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49167 typedef LayerImpl LayerType;
168 typedef LayerTreeImpl HostType;
169 typedef RenderSurfaceImpl RenderSurfaceType;
170 typedef TestContentLayerImpl ContentLayerType;
171 typedef scoped_ptr<LayerImpl> LayerPtrType;
172 typedef scoped_ptr<ContentLayerType> ContentLayerPtrType;
173 typedef LayerIterator<LayerImpl,
[email protected]50761e92013-03-29 20:51:28174 LayerImplList,
[email protected]a27cbde2013-03-23 22:01:49175 RenderSurfaceImpl,
176 LayerIteratorActions::FrontToBack> TestLayerIterator;
177 typedef OcclusionTrackerImpl OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14178
[email protected]a27cbde2013-03-23 22:01:49179 static LayerPtrType CreateLayer(HostType* host) {
180 return LayerImpl::Create(host, next_layer_impl_id++);
181 }
182 static ContentLayerPtrType CreateContentLayer(HostType* host) {
183 return make_scoped_ptr(new ContentLayerType(host, next_layer_impl_id++));
184 }
185 static int next_layer_impl_id;
[email protected]d58499a2012-10-09 22:27:47186
[email protected]a27cbde2013-03-23 22:01:49187 static LayerPtrType PassLayerPtr(LayerPtrType* layer) {
188 return layer->Pass();
189 }
[email protected]e0bd43a2012-10-12 16:54:21190
[email protected]a27cbde2013-03-23 22:01:49191 static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) {
192 return layer->PassAs<LayerType>();
193 }
[email protected]e0bd43a2012-10-12 16:54:21194
[email protected]a27cbde2013-03-23 22:01:49195 static void DestroyLayer(LayerPtrType* layer) { layer->reset(); }
[email protected]94f206c12012-08-25 00:09:14196};
197
[email protected]a27cbde2013-03-23 22:01:49198int OcclusionTrackerTestImplThreadTypes::next_layer_impl_id = 1;
[email protected]94f206c12012-08-25 00:09:14199
[email protected]a27cbde2013-03-23 22:01:49200template <typename Types> class OcclusionTrackerTest : public testing::Test {
201 protected:
[email protected]ca2902e92013-03-28 01:45:35202 explicit OcclusionTrackerTest(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49203 : host_impl_(&proxy_), opaque_layers_(opaque_layers) {}
204
205 virtual void RunMyTest() = 0;
206
207 virtual void TearDown() {
208 Types::DestroyLayer(&root_);
[email protected]989386c2013-07-18 21:37:23209 render_surface_layer_list_.reset();
[email protected]a27cbde2013-03-23 22:01:49210 render_surface_layer_list_impl_.clear();
211 replica_layers_.clear();
212 mask_layers_.clear();
213 }
214
215 typename Types::HostType* GetHost();
216
217 typename Types::ContentLayerType* CreateRoot(const gfx::Transform& transform,
218 gfx::PointF position,
219 gfx::Size bounds) {
220 typename Types::ContentLayerPtrType layer(
221 Types::CreateContentLayer(GetHost()));
222 typename Types::ContentLayerType* layer_ptr = layer.get();
223 SetProperties(layer_ptr, transform, position, bounds);
224
[email protected]22898ed2013-06-01 04:52:30225 DCHECK(!root_.get());
[email protected]a27cbde2013-03-23 22:01:49226 root_ = Types::PassLayerPtr(&layer);
227 return layer_ptr;
228 }
229
230 typename Types::LayerType* CreateLayer(typename Types::LayerType* parent,
231 const gfx::Transform& transform,
232 gfx::PointF position,
233 gfx::Size bounds) {
234 typename Types::LayerPtrType layer(Types::CreateLayer(GetHost()));
235 typename Types::LayerType* layer_ptr = layer.get();
236 SetProperties(layer_ptr, transform, position, bounds);
237 parent->AddChild(Types::PassLayerPtr(&layer));
238 return layer_ptr;
239 }
240
241 typename Types::LayerType* CreateSurface(typename Types::LayerType* parent,
242 const gfx::Transform& transform,
243 gfx::PointF position,
244 gfx::Size bounds) {
245 typename Types::LayerType* layer =
246 CreateLayer(parent, transform, position, bounds);
247 layer->SetForceRenderSurface(true);
248 return layer;
249 }
250
251 typename Types::ContentLayerType* CreateDrawingLayer(
252 typename Types::LayerType* parent,
253 const gfx::Transform& transform,
254 gfx::PointF position,
255 gfx::Size bounds,
256 bool opaque) {
257 typename Types::ContentLayerPtrType layer(
258 Types::CreateContentLayer(GetHost()));
259 typename Types::ContentLayerType* layer_ptr = layer.get();
260 SetProperties(layer_ptr, transform, position, bounds);
261
262 if (opaque_layers_) {
263 layer_ptr->SetContentsOpaque(opaque);
264 } else {
265 layer_ptr->SetContentsOpaque(false);
266 if (opaque)
[email protected]2c7c6702013-03-26 03:14:05267 layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds));
[email protected]a27cbde2013-03-23 22:01:49268 else
269 layer_ptr->SetOpaqueContentsRect(gfx::Rect());
[email protected]586d51ed2012-12-07 20:31:45270 }
[email protected]94f206c12012-08-25 00:09:14271
[email protected]a27cbde2013-03-23 22:01:49272 parent->AddChild(Types::PassLayerPtr(&layer));
273 return layer_ptr;
274 }
[email protected]94f206c12012-08-25 00:09:14275
[email protected]a27cbde2013-03-23 22:01:49276 typename Types::LayerType* CreateReplicaLayer(
277 typename Types::LayerType* owning_layer,
278 const gfx::Transform& transform,
279 gfx::PointF position,
280 gfx::Size bounds) {
281 typename Types::ContentLayerPtrType layer(
282 Types::CreateContentLayer(GetHost()));
283 typename Types::ContentLayerType* layer_ptr = layer.get();
284 SetProperties(layer_ptr, transform, position, bounds);
285 SetReplica(owning_layer, Types::PassLayerPtr(&layer));
286 return layer_ptr;
287 }
[email protected]94f206c12012-08-25 00:09:14288
[email protected]a27cbde2013-03-23 22:01:49289 typename Types::LayerType* CreateMaskLayer(
290 typename Types::LayerType* owning_layer,
291 gfx::Size bounds) {
292 typename Types::ContentLayerPtrType layer(
293 Types::CreateContentLayer(GetHost()));
294 typename Types::ContentLayerType* layer_ptr = layer.get();
295 SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds);
296 SetMask(owning_layer, Types::PassLayerPtr(&layer));
297 return layer_ptr;
298 }
[email protected]586d51ed2012-12-07 20:31:45299
[email protected]a27cbde2013-03-23 22:01:49300 typename Types::ContentLayerType* CreateDrawingSurface(
301 typename Types::LayerType* parent,
302 const gfx::Transform& transform,
303 gfx::PointF position,
304 gfx::Size bounds,
305 bool opaque) {
306 typename Types::ContentLayerType* layer =
307 CreateDrawingLayer(parent, transform, position, bounds, opaque);
308 layer->SetForceRenderSurface(true);
309 return layer;
310 }
[email protected]94f206c12012-08-25 00:09:14311
[email protected]5b54b972013-07-26 13:25:42312
313 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
314
315 void AddCopyRequest(Layer* layer) {
316 layer->RequestCopyOfOutput(
317 CopyOutputRequest::CreateBitmapRequest(base::Bind(
318 &OcclusionTrackerTest<Types>::CopyOutputCallback,
319 base::Unretained(this))));
320 }
321
322 void AddCopyRequest(LayerImpl* layer) {
323 ScopedPtrVector<CopyOutputRequest> requests;
324 requests.push_back(
325 CopyOutputRequest::CreateBitmapRequest(base::Bind(
326 &OcclusionTrackerTest<Types>::CopyOutputCallback,
327 base::Unretained(this))));
328 layer->PassCopyRequests(&requests);
329 }
330
[email protected]a27cbde2013-03-23 22:01:49331 void CalcDrawEtc(TestContentLayerImpl* root) {
332 DCHECK(root == root_.get());
[email protected]a27cbde2013-03-23 22:01:49333 DCHECK(!root->render_surface());
[email protected]94f206c12012-08-25 00:09:14334
[email protected]7aad55f2013-07-26 11:25:53335 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
336 root, root->bounds(), &render_surface_layer_list_impl_);
337 inputs.can_adjust_raster_scales = true;
338 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14339
[email protected]a27cbde2013-03-23 22:01:49340 layer_iterator_ = layer_iterator_begin_ =
341 Types::TestLayerIterator::Begin(&render_surface_layer_list_impl_);
342 }
[email protected]94f206c12012-08-25 00:09:14343
[email protected]a27cbde2013-03-23 22:01:49344 void CalcDrawEtc(TestContentLayer* root) {
345 DCHECK(root == root_.get());
[email protected]a27cbde2013-03-23 22:01:49346 DCHECK(!root->render_surface());
[email protected]94f206c12012-08-25 00:09:14347
[email protected]989386c2013-07-18 21:37:23348 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
[email protected]7aad55f2013-07-26 11:25:53349 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
350 root, root->bounds(), render_surface_layer_list_.get());
351 inputs.can_adjust_raster_scales = true;
352 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14353
[email protected]a27cbde2013-03-23 22:01:49354 layer_iterator_ = layer_iterator_begin_ =
[email protected]989386c2013-07-18 21:37:23355 Types::TestLayerIterator::Begin(render_surface_layer_list_.get());
[email protected]a27cbde2013-03-23 22:01:49356 }
[email protected]94f206c12012-08-25 00:09:14357
[email protected]a27cbde2013-03-23 22:01:49358 void EnterLayer(typename Types::LayerType* layer,
[email protected]2ea5e6c2013-04-26 21:52:23359 typename Types::OcclusionTrackerType* occlusion,
360 bool prevent_occlusion) {
[email protected]a27cbde2013-03-23 22:01:49361 ASSERT_EQ(layer, *layer_iterator_);
362 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]2ea5e6c2013-04-26 21:52:23363 occlusion->EnterLayer(layer_iterator_, prevent_occlusion);
[email protected]a27cbde2013-03-23 22:01:49364 }
[email protected]94f206c12012-08-25 00:09:14365
[email protected]a27cbde2013-03-23 22:01:49366 void LeaveLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40367 typename Types::OcclusionTrackerType* occlusion) {
[email protected]a27cbde2013-03-23 22:01:49368 ASSERT_EQ(layer, *layer_iterator_);
369 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]d002dd02013-03-27 07:40:40370 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49371 ++layer_iterator_;
372 }
[email protected]94f206c12012-08-25 00:09:14373
[email protected]a27cbde2013-03-23 22:01:49374 void VisitLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40375 typename Types::OcclusionTrackerType* occlusion) {
[email protected]2ea5e6c2013-04-26 21:52:23376 EnterLayer(layer, occlusion, false);
[email protected]a27cbde2013-03-23 22:01:49377 LeaveLayer(layer, occlusion);
378 }
[email protected]94f206c12012-08-25 00:09:14379
[email protected]a27cbde2013-03-23 22:01:49380 void EnterContributingSurface(
381 typename Types::LayerType* layer,
[email protected]2ea5e6c2013-04-26 21:52:23382 typename Types::OcclusionTrackerType* occlusion,
383 bool prevent_occlusion) {
[email protected]a27cbde2013-03-23 22:01:49384 ASSERT_EQ(layer, *layer_iterator_);
385 ASSERT_TRUE(layer_iterator_.represents_target_render_surface());
[email protected]2ea5e6c2013-04-26 21:52:23386 occlusion->EnterLayer(layer_iterator_, false);
[email protected]d002dd02013-03-27 07:40:40387 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49388 ++layer_iterator_;
389 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]2ea5e6c2013-04-26 21:52:23390 occlusion->EnterLayer(layer_iterator_, prevent_occlusion);
[email protected]a27cbde2013-03-23 22:01:49391 }
[email protected]94f206c12012-08-25 00:09:14392
[email protected]a27cbde2013-03-23 22:01:49393 void LeaveContributingSurface(
394 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40395 typename Types::OcclusionTrackerType* occlusion) {
[email protected]a27cbde2013-03-23 22:01:49396 ASSERT_EQ(layer, *layer_iterator_);
397 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]d002dd02013-03-27 07:40:40398 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49399 ++layer_iterator_;
400 }
[email protected]94f206c12012-08-25 00:09:14401
[email protected]a27cbde2013-03-23 22:01:49402 void VisitContributingSurface(
403 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40404 typename Types::OcclusionTrackerType* occlusion) {
[email protected]2ea5e6c2013-04-26 21:52:23405 EnterContributingSurface(layer, occlusion, false);
[email protected]a27cbde2013-03-23 22:01:49406 LeaveContributingSurface(layer, occlusion);
407 }
[email protected]94f206c12012-08-25 00:09:14408
[email protected]a27cbde2013-03-23 22:01:49409 void ResetLayerIterator() { layer_iterator_ = layer_iterator_begin_; }
[email protected]94f206c12012-08-25 00:09:14410
[email protected]a27cbde2013-03-23 22:01:49411 const gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:14412
[email protected]a27cbde2013-03-23 22:01:49413 private:
414 void SetBaseProperties(typename Types::LayerType* layer,
415 const gfx::Transform& transform,
416 gfx::PointF position,
417 gfx::Size bounds) {
418 layer->SetTransform(transform);
419 layer->SetSublayerTransform(gfx::Transform());
420 layer->SetAnchorPoint(gfx::PointF());
421 layer->SetPosition(position);
422 layer->SetBounds(bounds);
423 }
[email protected]94f206c12012-08-25 00:09:14424
[email protected]a27cbde2013-03-23 22:01:49425 void SetProperties(Layer* layer,
426 const gfx::Transform& transform,
427 gfx::PointF position,
428 gfx::Size bounds) {
429 SetBaseProperties(layer, transform, position, bounds);
430 }
[email protected]94f206c12012-08-25 00:09:14431
[email protected]a27cbde2013-03-23 22:01:49432 void SetProperties(LayerImpl* layer,
433 const gfx::Transform& transform,
434 gfx::PointF position,
435 gfx::Size bounds) {
436 SetBaseProperties(layer, transform, position, bounds);
[email protected]94f206c12012-08-25 00:09:14437
[email protected]a27cbde2013-03-23 22:01:49438 layer->SetContentBounds(layer->bounds());
439 }
[email protected]94f206c12012-08-25 00:09:14440
[email protected]a27cbde2013-03-23 22:01:49441 void SetReplica(Layer* owning_layer, scoped_refptr<Layer> layer) {
442 owning_layer->SetReplicaLayer(layer.get());
443 replica_layers_.push_back(layer);
444 }
[email protected]94f206c12012-08-25 00:09:14445
[email protected]a27cbde2013-03-23 22:01:49446 void SetReplica(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
447 owning_layer->SetReplicaLayer(layer.Pass());
448 }
[email protected]94f206c12012-08-25 00:09:14449
[email protected]a27cbde2013-03-23 22:01:49450 void SetMask(Layer* owning_layer, scoped_refptr<Layer> layer) {
451 owning_layer->SetMaskLayer(layer.get());
452 mask_layers_.push_back(layer);
453 }
[email protected]94f206c12012-08-25 00:09:14454
[email protected]a27cbde2013-03-23 22:01:49455 void SetMask(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
456 owning_layer->SetMaskLayer(layer.Pass());
457 }
[email protected]94f206c12012-08-25 00:09:14458
[email protected]a27cbde2013-03-23 22:01:49459 FakeImplProxy proxy_;
460 FakeLayerTreeHostImpl host_impl_;
461 bool opaque_layers_;
462 // These hold ownership of the layers for the duration of the test.
463 typename Types::LayerPtrType root_;
[email protected]989386c2013-07-18 21:37:23464 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
[email protected]50761e92013-03-29 20:51:28465 LayerImplList render_surface_layer_list_impl_;
[email protected]a27cbde2013-03-23 22:01:49466 typename Types::TestLayerIterator layer_iterator_begin_;
467 typename Types::TestLayerIterator layer_iterator_;
468 typename Types::LayerType* last_layer_visited_;
[email protected]50761e92013-03-29 20:51:28469 LayerList replica_layers_;
470 LayerList mask_layers_;
[email protected]94f206c12012-08-25 00:09:14471};
472
[email protected]a27cbde2013-03-23 22:01:49473template <>
474LayerTreeHost*
475OcclusionTrackerTest<OcclusionTrackerTestMainThreadTypes>::GetHost() {
476 return NULL;
[email protected]586d51ed2012-12-07 20:31:45477}
478
[email protected]a27cbde2013-03-23 22:01:49479template <>
480LayerTreeImpl*
481OcclusionTrackerTest<OcclusionTrackerTestImplThreadTypes>::GetHost() {
482 return host_impl_.active_tree();
[email protected]586d51ed2012-12-07 20:31:45483}
484
[email protected]a27cbde2013-03-23 22:01:49485#define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35486 class ClassName##MainThreadOpaqueLayers \
487 : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
488 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49489 ClassName##MainThreadOpaqueLayers() \
490 : ClassName<OcclusionTrackerTestMainThreadTypes>(true) {} \
491 }; \
492 TEST_F(ClassName##MainThreadOpaqueLayers, RunTest) { RunMyTest(); }
493#define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35494 class ClassName##MainThreadOpaquePaints \
495 : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
496 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49497 ClassName##MainThreadOpaquePaints() \
498 : ClassName<OcclusionTrackerTestMainThreadTypes>(false) {} \
499 }; \
500 TEST_F(ClassName##MainThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14501
[email protected]a27cbde2013-03-23 22:01:49502#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35503 class ClassName##ImplThreadOpaqueLayers \
504 : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
505 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49506 ClassName##ImplThreadOpaqueLayers() \
507 : ClassName<OcclusionTrackerTestImplThreadTypes>(true) {} \
508 }; \
509 TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); }
510#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35511 class ClassName##ImplThreadOpaquePaints \
512 : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
513 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49514 ClassName##ImplThreadOpaquePaints() \
515 : ClassName<OcclusionTrackerTestImplThreadTypes>(false) {} \
516 }; \
517 TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14518
[email protected]a27cbde2013-03-23 22:01:49519#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
520 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
521 RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
522 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
523 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
[email protected]94f206c12012-08-25 00:09:14524
[email protected]a27cbde2013-03-23 22:01:49525#define MAIN_THREAD_TEST(ClassName) \
526 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14527
[email protected]a27cbde2013-03-23 22:01:49528#define IMPL_THREAD_TEST(ClassName) \
529 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14530
[email protected]a27cbde2013-03-23 22:01:49531#define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
532 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
533 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14534
[email protected]a27cbde2013-03-23 22:01:49535template <class Types>
[email protected]ca2902e92013-03-28 01:45:35536class OcclusionTrackerTestIdentityTransforms
537 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49538 protected:
[email protected]ca2902e92013-03-28 01:45:35539 explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49540 : OcclusionTrackerTest<Types>(opaque_layers) {}
[email protected]ece1d952012-10-18 21:26:07541
[email protected]a27cbde2013-03-23 22:01:49542 void RunMyTest() {
543 typename Types::ContentLayerType* root = this->CreateRoot(
544 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
545 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
546 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
547 typename Types::ContentLayerType* layer =
548 this->CreateDrawingLayer(parent,
549 this->identity_matrix,
550 gfx::PointF(30.f, 30.f),
551 gfx::Size(500, 500),
552 true);
553 parent->SetMasksToBounds(true);
554 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14555
[email protected]a27cbde2013-03-23 22:01:49556 TestOcclusionTrackerWithClip<typename Types::LayerType,
557 typename Types::RenderSurfaceType> occlusion(
558 gfx::Rect(0, 0, 1000, 1000), false);
[email protected]94f206c12012-08-25 00:09:14559
[email protected]d002dd02013-03-27 07:40:40560 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:23561 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:14562
[email protected]a27cbde2013-03-23 22:01:49563 EXPECT_EQ(gfx::Rect().ToString(),
564 occlusion.occlusion_from_outside_target().ToString());
565 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
566 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14567
[email protected]a27cbde2013-03-23 22:01:49568 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
569 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
570 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
571 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
572 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14573
[email protected]a27cbde2013-03-23 22:01:49574 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
575 parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
576 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70),
577 occlusion.UnoccludedLayerContentRect(
578 parent, gfx::Rect(29, 30, 70, 70)));
579 EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70),
580 occlusion.UnoccludedLayerContentRect(
581 parent, gfx::Rect(29, 29, 70, 70)));
582 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1),
583 occlusion.UnoccludedLayerContentRect(
584 parent, gfx::Rect(30, 29, 70, 70)));
585 EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1),
586 occlusion.UnoccludedLayerContentRect(
587 parent, gfx::Rect(31, 29, 70, 70)));
588 EXPECT_RECT_EQ(gfx::Rect(),
589 occlusion.UnoccludedLayerContentRect(
590 parent, gfx::Rect(31, 30, 70, 70)));
591 EXPECT_RECT_EQ(gfx::Rect(),
592 occlusion.UnoccludedLayerContentRect(
593 parent, gfx::Rect(31, 31, 70, 70)));
594 EXPECT_RECT_EQ(gfx::Rect(),
595 occlusion.UnoccludedLayerContentRect(
596 parent, gfx::Rect(30, 31, 70, 70)));
597 EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69),
598 occlusion.UnoccludedLayerContentRect(
599 parent, gfx::Rect(29, 31, 70, 70)));
600 }
[email protected]94f206c12012-08-25 00:09:14601};
602
[email protected]96baf3e2012-10-22 23:09:55603ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14604
[email protected]a27cbde2013-03-23 22:01:49605template <class Types>
[email protected]ca2902e92013-03-28 01:45:35606class OcclusionTrackerTestQuadsMismatchLayer
607 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49608 protected:
[email protected]ca2902e92013-03-28 01:45:35609 explicit OcclusionTrackerTestQuadsMismatchLayer(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49610 : OcclusionTrackerTest<Types>(opaque_layers) {}
611 void RunMyTest() {
612 gfx::Transform layer_transform;
613 layer_transform.Translate(10.0, 10.0);
[email protected]710ffc02012-10-30 21:42:02614
[email protected]a27cbde2013-03-23 22:01:49615 typename Types::ContentLayerType* parent = this->CreateRoot(
616 this->identity_matrix, gfx::Point(0, 0), gfx::Size(100, 100));
617 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
618 parent, layer_transform, gfx::PointF(), gfx::Size(90, 90), true);
619 typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
620 layer1, layer_transform, gfx::PointF(), gfx::Size(50, 50), true);
621 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02622
[email protected]a27cbde2013-03-23 22:01:49623 TestOcclusionTrackerWithClip<typename Types::LayerType,
624 typename Types::RenderSurfaceType> occlusion(
625 gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02626
[email protected]d002dd02013-03-27 07:40:40627 this->VisitLayer(layer2, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:23628 this->EnterLayer(layer1, &occlusion, false);
[email protected]710ffc02012-10-30 21:42:02629
[email protected]a27cbde2013-03-23 22:01:49630 EXPECT_EQ(gfx::Rect().ToString(),
631 occlusion.occlusion_from_outside_target().ToString());
632 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
633 occlusion.occlusion_from_inside_target().ToString());
[email protected]710ffc02012-10-30 21:42:02634
[email protected]a27cbde2013-03-23 22:01:49635 // This checks cases where the quads don't match their "containing"
636 // layers, e.g. in terms of transforms or clip rect. This is typical for
637 // DelegatedRendererLayer.
[email protected]710ffc02012-10-30 21:42:02638
[email protected]a27cbde2013-03-23 22:01:49639 gfx::Transform quad_transform;
640 quad_transform.Translate(30.0, 30.0);
641 gfx::Rect clip_rect_in_target(0, 0, 100, 100);
[email protected]710ffc02012-10-30 21:42:02642
[email protected]a27cbde2013-03-23 22:01:49643 EXPECT_TRUE(occlusion.UnoccludedContentRect(parent,
644 gfx::Rect(0, 0, 10, 10),
645 quad_transform,
646 false,
647 true,
648 clip_rect_in_target,
649 NULL).IsEmpty());
650 EXPECT_RECT_EQ(gfx::Rect(0, 0, 10, 10),
651 occlusion.UnoccludedContentRect(parent,
652 gfx::Rect(0, 0, 10, 10),
653 quad_transform,
654 true,
655 true,
656 clip_rect_in_target,
657 NULL));
658 EXPECT_RECT_EQ(gfx::Rect(40, 40, 10, 10),
659 occlusion.UnoccludedContentRect(parent,
660 gfx::Rect(40, 40, 10, 10),
661 quad_transform,
662 false,
663 true,
664 clip_rect_in_target,
665 NULL));
666 EXPECT_RECT_EQ(gfx::Rect(40, 30, 5, 10),
667 occlusion.UnoccludedContentRect(parent,
668 gfx::Rect(35, 30, 10, 10),
669 quad_transform,
670 false,
671 true,
672 clip_rect_in_target,
673 NULL));
674 EXPECT_RECT_EQ(gfx::Rect(40, 40, 5, 5),
675 occlusion.UnoccludedContentRect(parent,
676 gfx::Rect(40, 40, 10, 10),
677 quad_transform,
678 false,
679 true,
680 gfx::Rect(0, 0, 75, 75),
681 NULL));
682 }
[email protected]710ffc02012-10-30 21:42:02683};
684
685ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestQuadsMismatchLayer);
686
[email protected]a27cbde2013-03-23 22:01:49687template <class Types>
[email protected]96baf3e2012-10-22 23:09:55688class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49689 protected:
[email protected]ca2902e92013-03-28 01:45:35690 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49691 : OcclusionTrackerTest<Types>(opaque_layers) {}
692 void RunMyTest() {
693 gfx::Transform layer_transform;
694 layer_transform.Translate(250.0, 250.0);
695 layer_transform.Rotate(90.0);
696 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14697
[email protected]a27cbde2013-03-23 22:01:49698 typename Types::ContentLayerType* root = this->CreateRoot(
699 this->identity_matrix, gfx::Point(0, 0), gfx::Size(200, 200));
700 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
701 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
702 typename Types::ContentLayerType* layer =
703 this->CreateDrawingLayer(parent,
704 layer_transform,
705 gfx::PointF(30.f, 30.f),
706 gfx::Size(500, 500),
707 true);
708 parent->SetMasksToBounds(true);
709 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14710
[email protected]a27cbde2013-03-23 22:01:49711 TestOcclusionTrackerWithClip<typename Types::LayerType,
712 typename Types::RenderSurfaceType> occlusion(
713 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14714
[email protected]d002dd02013-03-27 07:40:40715 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:23716 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:14717
[email protected]a27cbde2013-03-23 22:01:49718 EXPECT_EQ(gfx::Rect().ToString(),
719 occlusion.occlusion_from_outside_target().ToString());
720 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
721 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14722
[email protected]a27cbde2013-03-23 22:01:49723 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
724 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
725 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
726 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
727 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
[email protected]94f206c12012-08-25 00:09:14728
[email protected]a27cbde2013-03-23 22:01:49729 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
730 parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
731 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70),
732 occlusion.UnoccludedLayerContentRect(
733 parent, gfx::Rect(29, 30, 70, 70)));
734 EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70),
735 occlusion.UnoccludedLayerContentRect(
736 parent, gfx::Rect(29, 29, 70, 70)));
737 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1),
738 occlusion.UnoccludedLayerContentRect(
739 parent, gfx::Rect(30, 29, 70, 70)));
740 EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1),
741 occlusion.UnoccludedLayerContentRect(
742 parent, gfx::Rect(31, 29, 70, 70)));
743 EXPECT_RECT_EQ(gfx::Rect(),
744 occlusion.UnoccludedLayerContentRect(
745 parent, gfx::Rect(31, 30, 70, 70)));
746 EXPECT_RECT_EQ(gfx::Rect(),
747 occlusion.UnoccludedLayerContentRect(
748 parent, gfx::Rect(31, 31, 70, 70)));
749 EXPECT_RECT_EQ(gfx::Rect(),
750 occlusion.UnoccludedLayerContentRect(
751 parent, gfx::Rect(30, 31, 70, 70)));
752 EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69),
753 occlusion.UnoccludedLayerContentRect(
754 parent, gfx::Rect(29, 31, 70, 70)));
755 }
[email protected]94f206c12012-08-25 00:09:14756};
757
[email protected]96baf3e2012-10-22 23:09:55758ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14759
[email protected]a27cbde2013-03-23 22:01:49760template <class Types>
[email protected]96baf3e2012-10-22 23:09:55761class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49762 protected:
[email protected]ca2902e92013-03-28 01:45:35763 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49764 : OcclusionTrackerTest<Types>(opaque_layers) {}
765 void RunMyTest() {
766 gfx::Transform layer_transform;
767 layer_transform.Translate(20.0, 20.0);
[email protected]94f206c12012-08-25 00:09:14768
[email protected]a27cbde2013-03-23 22:01:49769 typename Types::ContentLayerType* root = this->CreateRoot(
770 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
771 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
772 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
773 typename Types::ContentLayerType* layer =
774 this->CreateDrawingLayer(parent,
775 layer_transform,
776 gfx::PointF(30.f, 30.f),
777 gfx::Size(500, 500),
778 true);
779 parent->SetMasksToBounds(true);
780 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14781
[email protected]a27cbde2013-03-23 22:01:49782 TestOcclusionTrackerWithClip<typename Types::LayerType,
783 typename Types::RenderSurfaceType> occlusion(
784 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14785
[email protected]d002dd02013-03-27 07:40:40786 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:23787 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:14788
[email protected]a27cbde2013-03-23 22:01:49789 EXPECT_EQ(gfx::Rect().ToString(),
790 occlusion.occlusion_from_outside_target().ToString());
791 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
792 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14793
[email protected]a27cbde2013-03-23 22:01:49794 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 50, 50, 50)));
795 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(49, 50, 50, 50)));
796 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(50, 49, 50, 50)));
797 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(51, 50, 50, 50)));
798 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 51, 50, 50)));
[email protected]94f206c12012-08-25 00:09:14799
[email protected]a27cbde2013-03-23 22:01:49800 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
801 parent, gfx::Rect(50, 50, 50, 50)).IsEmpty());
802 EXPECT_RECT_EQ(gfx::Rect(49, 50, 1, 50),
803 occlusion.UnoccludedLayerContentRect(
804 parent, gfx::Rect(49, 50, 50, 50)));
805 EXPECT_RECT_EQ(gfx::Rect(49, 49, 50, 50),
806 occlusion.UnoccludedLayerContentRect(
807 parent, gfx::Rect(49, 49, 50, 50)));
808 EXPECT_RECT_EQ(gfx::Rect(50, 49, 50, 1),
809 occlusion.UnoccludedLayerContentRect(
810 parent, gfx::Rect(50, 49, 50, 50)));
811 EXPECT_RECT_EQ(gfx::Rect(51, 49, 49, 1),
812 occlusion.UnoccludedLayerContentRect(
813 parent, gfx::Rect(51, 49, 50, 50)));
814 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
815 parent, gfx::Rect(51, 50, 50, 50)).IsEmpty());
816 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
817 parent, gfx::Rect(51, 51, 50, 50)).IsEmpty());
818 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
819 parent, gfx::Rect(50, 51, 50, 50)).IsEmpty());
820 EXPECT_RECT_EQ(gfx::Rect(49, 51, 1, 49),
821 occlusion.UnoccludedLayerContentRect(
822 parent, gfx::Rect(49, 51, 50, 50)));
823 }
[email protected]94f206c12012-08-25 00:09:14824};
825
[email protected]96baf3e2012-10-22 23:09:55826ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14827
[email protected]a27cbde2013-03-23 22:01:49828template <class Types>
[email protected]ca2902e92013-03-28 01:45:35829class OcclusionTrackerTestChildInRotatedChild
830 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49831 protected:
[email protected]ca2902e92013-03-28 01:45:35832 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49833 : OcclusionTrackerTest<Types>(opaque_layers) {}
834 void RunMyTest() {
835 gfx::Transform child_transform;
836 child_transform.Translate(250.0, 250.0);
837 child_transform.Rotate(90.0);
838 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14839
[email protected]a27cbde2013-03-23 22:01:49840 typename Types::ContentLayerType* parent = this->CreateRoot(
841 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
842 parent->SetMasksToBounds(true);
[email protected]3a9a92d2013-07-11 04:37:00843 typename Types::LayerType* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49844 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
845 child->SetMasksToBounds(true);
846 typename Types::ContentLayerType* layer =
847 this->CreateDrawingLayer(child,
848 this->identity_matrix,
849 gfx::PointF(10.f, 10.f),
850 gfx::Size(500, 500),
851 true);
852 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14853
[email protected]a27cbde2013-03-23 22:01:49854 TestOcclusionTrackerWithClip<typename Types::LayerType,
855 typename Types::RenderSurfaceType> occlusion(
856 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14857
[email protected]d002dd02013-03-27 07:40:40858 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:23859 this->EnterContributingSurface(child, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:14860
[email protected]a27cbde2013-03-23 22:01:49861 EXPECT_EQ(gfx::Rect().ToString(),
862 occlusion.occlusion_from_outside_target().ToString());
863 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
864 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14865
[email protected]d002dd02013-03-27 07:40:40866 this->LeaveContributingSurface(child, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:23867 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:14868
[email protected]a27cbde2013-03-23 22:01:49869 EXPECT_EQ(gfx::Rect().ToString(),
870 occlusion.occlusion_from_outside_target().ToString());
871 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
872 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14873
[email protected]a27cbde2013-03-23 22:01:49874 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
875 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
876 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
877 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 40, 70, 60)));
878 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 41, 70, 60)));
[email protected]94f206c12012-08-25 00:09:14879
[email protected]a27cbde2013-03-23 22:01:49880 /* Justification for the above occlusion from |layer|:
881 100
882 +---------------------+
883 | |
884 | 30 | rotate(90)
885 | 30 + ---------------------------------+
886 100 | | 10 | | ==>
887 | |10+---------------------------------+
888 | | | | | |
889 | | | | | |
890 | | | | | |
891 +----|--|-------------+ | |
892 | | | |
893 | | | |
894 | | | |500
895 | | | |
896 | | | |
897 | | | |
898 | | | |
899 +--|-------------------------------+ |
900 | |
901 +---------------------------------+
902 500
903
904 +---------------------+
905 | |30 Visible region of |layer|: /////
906 | |
907 | +---------------------------------+
908 100| | |10 |
909 | +---------------------------------+ |
910 | | |///////////////| 420 | |
911 | | |///////////////|60 | |
912 | | |///////////////| | |
913 +--|--|---------------+ | |
914 20|10| 70 | |
915 | | | |
916 | | | |
917 | | | |
918 | | | |
919 | | | |
920 | | |10|
921 | +------------------------------|--+
922 | 490 |
923 +---------------------------------+
924 500
925
926 */
927 }
[email protected]94f206c12012-08-25 00:09:14928};
929
[email protected]96baf3e2012-10-22 23:09:55930ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14931
[email protected]a27cbde2013-03-23 22:01:49932template <class Types>
[email protected]ca2902e92013-03-28 01:45:35933class OcclusionTrackerTestScaledRenderSurface
934 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49935 protected:
[email protected]ca2902e92013-03-28 01:45:35936 explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49937 : OcclusionTrackerTest<Types>(opaque_layers) {}
[email protected]710ffc02012-10-30 21:42:02938
[email protected]a27cbde2013-03-23 22:01:49939 void RunMyTest() {
940 typename Types::ContentLayerType* parent = this->CreateRoot(
941 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02942
[email protected]a27cbde2013-03-23 22:01:49943 gfx::Transform layer1_matrix;
944 layer1_matrix.Scale(2.0, 2.0);
945 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
946 parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true);
947 layer1->SetForceRenderSurface(true);
[email protected]710ffc02012-10-30 21:42:02948
[email protected]a27cbde2013-03-23 22:01:49949 gfx::Transform layer2_matrix;
950 layer2_matrix.Translate(25.0, 25.0);
951 typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
952 layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true);
953 typename Types::ContentLayerType* occluder =
954 this->CreateDrawingLayer(parent,
955 this->identity_matrix,
956 gfx::PointF(100.f, 100.f),
957 gfx::Size(500, 500),
958 true);
959 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02960
[email protected]a27cbde2013-03-23 22:01:49961 TestOcclusionTrackerWithClip<typename Types::LayerType,
962 typename Types::RenderSurfaceType> occlusion(
963 gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02964
[email protected]d002dd02013-03-27 07:40:40965 this->VisitLayer(occluder, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:23966 this->EnterLayer(layer2, &occlusion, false);
[email protected]710ffc02012-10-30 21:42:02967
[email protected]a27cbde2013-03-23 22:01:49968 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
969 occlusion.occlusion_from_outside_target().ToString());
970 EXPECT_EQ(gfx::Rect().ToString(),
971 occlusion.occlusion_from_inside_target().ToString());
[email protected]710ffc02012-10-30 21:42:02972
[email protected]a27cbde2013-03-23 22:01:49973 EXPECT_RECT_EQ(
974 gfx::Rect(0, 0, 25, 25),
975 occlusion.UnoccludedLayerContentRect(layer2, gfx::Rect(0, 0, 25, 25)));
976 EXPECT_RECT_EQ(gfx::Rect(10, 25, 15, 25),
977 occlusion.UnoccludedLayerContentRect(
978 layer2, gfx::Rect(10, 25, 25, 25)));
979 EXPECT_RECT_EQ(gfx::Rect(25, 10, 25, 15),
980 occlusion.UnoccludedLayerContentRect(
981 layer2, gfx::Rect(25, 10, 25, 25)));
982 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
983 layer2, gfx::Rect(25, 25, 25, 25)).IsEmpty());
984 }
[email protected]710ffc02012-10-30 21:42:02985};
986
987ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
988
[email protected]a27cbde2013-03-23 22:01:49989template <class Types>
[email protected]ca2902e92013-03-28 01:45:35990class OcclusionTrackerTestVisitTargetTwoTimes
991 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49992 protected:
[email protected]ca2902e92013-03-28 01:45:35993 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49994 : OcclusionTrackerTest<Types>(opaque_layers) {}
995 void RunMyTest() {
996 gfx::Transform child_transform;
997 child_transform.Translate(250.0, 250.0);
998 child_transform.Rotate(90.0);
999 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141000
[email protected]a27cbde2013-03-23 22:01:491001 typename Types::ContentLayerType* root = this->CreateRoot(
1002 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
1003 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
1004 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
1005 parent->SetMasksToBounds(true);
[email protected]3a9a92d2013-07-11 04:37:001006 typename Types::LayerType* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:491007 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
1008 child->SetMasksToBounds(true);
1009 typename Types::ContentLayerType* layer =
1010 this->CreateDrawingLayer(child,
1011 this->identity_matrix,
1012 gfx::PointF(10.f, 10.f),
1013 gfx::Size(500, 500),
1014 true);
1015 // |child2| makes |parent|'s surface get considered by OcclusionTracker
1016 // first, instead of |child|'s. This exercises different code in
1017 // LeaveToRenderTarget, as the target surface has already been seen.
1018 typename Types::ContentLayerType* child2 =
1019 this->CreateDrawingLayer(parent,
1020 this->identity_matrix,
1021 gfx::PointF(30.f, 30.f),
1022 gfx::Size(60, 20),
1023 true);
1024 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141025
[email protected]a27cbde2013-03-23 22:01:491026 TestOcclusionTrackerWithClip<typename Types::LayerType,
1027 typename Types::RenderSurfaceType> occlusion(
1028 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141029
[email protected]d002dd02013-03-27 07:40:401030 this->VisitLayer(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141031
[email protected]a27cbde2013-03-23 22:01:491032 EXPECT_EQ(gfx::Rect().ToString(),
1033 occlusion.occlusion_from_outside_target().ToString());
1034 EXPECT_EQ(gfx::Rect(30, 30, 60, 20).ToString(),
1035 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141036
[email protected]d002dd02013-03-27 07:40:401037 this->VisitLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141038
[email protected]a27cbde2013-03-23 22:01:491039 EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(),
1040 occlusion.occlusion_from_outside_target().ToString());
1041 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
1042 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141043
[email protected]2ea5e6c2013-04-26 21:52:231044 this->EnterContributingSurface(child, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141045
[email protected]a27cbde2013-03-23 22:01:491046 EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(),
1047 occlusion.occlusion_from_outside_target().ToString());
1048 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
1049 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141050
[email protected]a27cbde2013-03-23 22:01:491051 // Occlusion in |child2| should get merged with the |child| surface we are
1052 // leaving now.
[email protected]d002dd02013-03-27 07:40:401053 this->LeaveContributingSurface(child, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231054 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141055
[email protected]a27cbde2013-03-23 22:01:491056 EXPECT_EQ(gfx::Rect().ToString(),
1057 occlusion.occlusion_from_outside_target().ToString());
1058 EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60))
1059 .ToString(),
1060 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141061
[email protected]a27cbde2013-03-23 22:01:491062 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
1063 EXPECT_RECT_EQ(gfx::Rect(90, 30, 10, 10),
1064 occlusion.UnoccludedLayerContentRect(
1065 parent, gfx::Rect(30, 30, 70, 70)));
[email protected]94f206c12012-08-25 00:09:141066
[email protected]a27cbde2013-03-23 22:01:491067 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 60, 10)));
1068 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 60, 10)));
1069 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 60, 10)));
1070 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 60, 10)));
1071 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 60, 10)));
[email protected]94f206c12012-08-25 00:09:141072
[email protected]a27cbde2013-03-23 22:01:491073 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
1074 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
1075 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:141076
[email protected]a27cbde2013-03-23 22:01:491077 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1078 parent, gfx::Rect(30, 30, 60, 10)).IsEmpty());
1079 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 10),
1080 occlusion.UnoccludedLayerContentRect(
1081 parent, gfx::Rect(29, 30, 60, 10)));
1082 EXPECT_RECT_EQ(gfx::Rect(30, 29, 60, 1),
1083 occlusion.UnoccludedLayerContentRect(
1084 parent, gfx::Rect(30, 29, 60, 10)));
1085 EXPECT_RECT_EQ(gfx::Rect(90, 30, 1, 10),
1086 occlusion.UnoccludedLayerContentRect(
1087 parent, gfx::Rect(31, 30, 60, 10)));
1088 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1089 parent, gfx::Rect(30, 31, 60, 10)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141090
[email protected]a27cbde2013-03-23 22:01:491091 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1092 parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
1093 EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60),
1094 occlusion.UnoccludedLayerContentRect(
1095 parent, gfx::Rect(29, 40, 70, 60)));
1096 // This rect is mostly occluded by |child2|.
1097 EXPECT_RECT_EQ(gfx::Rect(90, 39, 10, 1),
1098 occlusion.UnoccludedLayerContentRect(
1099 parent, gfx::Rect(30, 39, 70, 60)));
1100 // This rect extends past top/right ends of |child2|.
1101 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 11),
1102 occlusion.UnoccludedLayerContentRect(
1103 parent, gfx::Rect(30, 29, 70, 70)));
1104 // This rect extends past left/right ends of |child2|.
1105 EXPECT_RECT_EQ(gfx::Rect(20, 39, 80, 60),
1106 occlusion.UnoccludedLayerContentRect(
1107 parent, gfx::Rect(20, 39, 80, 60)));
1108 EXPECT_RECT_EQ(gfx::Rect(),
1109 occlusion.UnoccludedLayerContentRect(
1110 parent, gfx::Rect(31, 40, 70, 60)));
1111 EXPECT_RECT_EQ(gfx::Rect(),
1112 occlusion.UnoccludedLayerContentRect(
1113 parent, gfx::Rect(30, 41, 70, 60)));
[email protected]94f206c12012-08-25 00:09:141114
[email protected]a27cbde2013-03-23 22:01:491115 /* Justification for the above occlusion from |layer|:
1116 100
1117 +---------------------+
1118 | |
1119 | 30 | rotate(90)
1120 | 30 + ------------+--------------------+
1121 100 | | 10 | | | ==>
1122 | |10+----------|----------------------+
1123 | + ------------+ | | |
1124 | | | | | |
1125 | | | | | |
1126 +----|--|-------------+ | |
1127 | | | |
1128 | | | |
1129 | | | |500
1130 | | | |
1131 | | | |
1132 | | | |
1133 | | | |
1134 +--|-------------------------------+ |
1135 | |
1136 +---------------------------------+
1137 500
1138
1139
1140 +---------------------+
1141 | |30 Visible region of |layer|: /////
1142 | 30 60 | |child2|: \\\\\
1143 | 30 +------------+--------------------+
1144 | |\\\\\\\\\\\\| |10 |
1145 | +--|\\\\\\\\\\\\|-----------------+ |
1146 | | +------------+//| 420 | |
1147 | | |///////////////|60 | |
1148 | | |///////////////| | |
1149 +--|--|---------------+ | |
1150 20|10| 70 | |
1151 | | | |
1152 | | | |
1153 | | | |
1154 | | | |
1155 | | | |
1156 | | |10|
1157 | +------------------------------|--+
1158 | 490 |
1159 +---------------------------------+
1160 500
1161 */
1162 }
[email protected]94f206c12012-08-25 00:09:141163};
1164
[email protected]96baf3e2012-10-22 23:09:551165ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:141166
[email protected]a27cbde2013-03-23 22:01:491167template <class Types>
[email protected]ca2902e92013-03-28 01:45:351168class OcclusionTrackerTestSurfaceRotatedOffAxis
1169 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491170 protected:
[email protected]ca2902e92013-03-28 01:45:351171 explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491172 : OcclusionTrackerTest<Types>(opaque_layers) {}
1173 void RunMyTest() {
1174 gfx::Transform child_transform;
1175 child_transform.Translate(250.0, 250.0);
1176 child_transform.Rotate(95.0);
1177 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141178
[email protected]a27cbde2013-03-23 22:01:491179 gfx::Transform layer_transform;
1180 layer_transform.Translate(10.0, 10.0);
[email protected]94f206c12012-08-25 00:09:141181
[email protected]a27cbde2013-03-23 22:01:491182 typename Types::ContentLayerType* root = this->CreateRoot(
1183 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
1184 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
1185 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
1186 typename Types::LayerType* child = this->CreateLayer(
1187 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
1188 child->SetMasksToBounds(true);
1189 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1190 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true);
1191 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141192
[email protected]a27cbde2013-03-23 22:01:491193 TestOcclusionTrackerWithClip<typename Types::LayerType,
1194 typename Types::RenderSurfaceType> occlusion(
1195 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141196
[email protected]a27cbde2013-03-23 22:01:491197 gfx::Rect clipped_layer_in_child = MathUtil::MapClippedRect(
1198 layer_transform, layer->visible_content_rect());
[email protected]94f206c12012-08-25 00:09:141199
[email protected]d002dd02013-03-27 07:40:401200 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231201 this->EnterContributingSurface(child, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141202
[email protected]a27cbde2013-03-23 22:01:491203 EXPECT_EQ(gfx::Rect().ToString(),
1204 occlusion.occlusion_from_outside_target().ToString());
1205 EXPECT_EQ(clipped_layer_in_child.ToString(),
1206 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141207
[email protected]d002dd02013-03-27 07:40:401208 this->LeaveContributingSurface(child, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231209 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141210
[email protected]a27cbde2013-03-23 22:01:491211 EXPECT_EQ(gfx::Rect().ToString(),
1212 occlusion.occlusion_from_outside_target().ToString());
1213 EXPECT_EQ(gfx::Rect().ToString(),
1214 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141215
[email protected]a27cbde2013-03-23 22:01:491216 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(75, 55, 1, 1)));
1217 EXPECT_RECT_EQ(
1218 gfx::Rect(75, 55, 1, 1),
1219 occlusion.UnoccludedLayerContentRect(parent, gfx::Rect(75, 55, 1, 1)));
1220 }
[email protected]94f206c12012-08-25 00:09:141221};
1222
[email protected]96baf3e2012-10-22 23:09:551223ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:141224
[email protected]a27cbde2013-03-23 22:01:491225template <class Types>
[email protected]ca2902e92013-03-28 01:45:351226class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
1227 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491228 protected:
[email protected]ca2902e92013-03-28 01:45:351229 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491230 : OcclusionTrackerTest<Types>(opaque_layers) {}
1231 void RunMyTest() {
1232 gfx::Transform child_transform;
1233 child_transform.Translate(250.0, 250.0);
1234 child_transform.Rotate(90.0);
1235 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141236
[email protected]a27cbde2013-03-23 22:01:491237 typename Types::ContentLayerType* root = this->CreateRoot(
1238 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
1239 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
1240 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
1241 parent->SetMasksToBounds(true);
1242 typename Types::ContentLayerType* child =
[email protected]3a9a92d2013-07-11 04:37:001243 this->CreateDrawingSurface(parent,
[email protected]a27cbde2013-03-23 22:01:491244 child_transform,
1245 gfx::PointF(30.f, 30.f),
1246 gfx::Size(500, 500),
1247 false);
1248 child->SetMasksToBounds(true);
1249 typename Types::ContentLayerType* layer1 =
1250 this->CreateDrawingLayer(child,
1251 this->identity_matrix,
1252 gfx::PointF(10.f, 10.f),
1253 gfx::Size(500, 500),
1254 true);
1255 typename Types::ContentLayerType* layer2 =
1256 this->CreateDrawingLayer(child,
1257 this->identity_matrix,
1258 gfx::PointF(10.f, 450.f),
1259 gfx::Size(500, 60),
1260 true);
1261 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141262
[email protected]a27cbde2013-03-23 22:01:491263 TestOcclusionTrackerWithClip<typename Types::LayerType,
1264 typename Types::RenderSurfaceType> occlusion(
1265 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141266
[email protected]d002dd02013-03-27 07:40:401267 this->VisitLayer(layer2, &occlusion);
1268 this->VisitLayer(layer1, &occlusion);
1269 this->VisitLayer(child, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231270 this->EnterContributingSurface(child, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141271
[email protected]a27cbde2013-03-23 22:01:491272 EXPECT_EQ(gfx::Rect().ToString(),
1273 occlusion.occlusion_from_outside_target().ToString());
1274 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
1275 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141276
[email protected]a27cbde2013-03-23 22:01:491277 EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 430, 60, 70)));
1278 EXPECT_FALSE(occlusion.OccludedLayer(child, gfx::Rect(9, 430, 60, 70)));
1279 // These rects are occluded except for the part outside the bounds of the
1280 // target surface.
1281 EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 429, 60, 70)));
1282 EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(11, 430, 60, 70)));
1283 EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 431, 60, 70)));
[email protected]94f206c12012-08-25 00:09:141284
[email protected]a27cbde2013-03-23 22:01:491285 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1286 child, gfx::Rect(10, 430, 60, 70)).IsEmpty());
1287 EXPECT_RECT_EQ(
1288 gfx::Rect(9, 430, 1, 70),
1289 occlusion.UnoccludedLayerContentRect(child, gfx::Rect(9, 430, 60, 70)));
1290 // These rects are occluded except for the part outside the bounds of the
1291 // target surface.
1292 EXPECT_RECT_EQ(gfx::Rect(),
1293 occlusion.UnoccludedLayerContentRect(
1294 child, gfx::Rect(10, 429, 60, 70)));
1295 EXPECT_RECT_EQ(gfx::Rect(),
1296 occlusion.UnoccludedLayerContentRect(
1297 child, gfx::Rect(11, 430, 60, 70)));
1298 EXPECT_RECT_EQ(gfx::Rect(),
1299 occlusion.UnoccludedLayerContentRect(
1300 child, gfx::Rect(10, 431, 60, 70)));
[email protected]94f206c12012-08-25 00:09:141301
[email protected]d002dd02013-03-27 07:40:401302 this->LeaveContributingSurface(child, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231303 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141304
[email protected]a27cbde2013-03-23 22:01:491305 EXPECT_EQ(gfx::Rect().ToString(),
1306 occlusion.occlusion_from_outside_target().ToString());
1307 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
1308 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141309
[email protected]a27cbde2013-03-23 22:01:491310 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
1311 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
1312 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:141313
[email protected]a27cbde2013-03-23 22:01:491314 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1315 parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
1316 EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60),
1317 occlusion.UnoccludedLayerContentRect(
1318 parent, gfx::Rect(29, 40, 70, 60)));
1319 EXPECT_RECT_EQ(gfx::Rect(30, 39, 70, 1),
1320 occlusion.UnoccludedLayerContentRect(
1321 parent, gfx::Rect(30, 39, 70, 60)));
1322 EXPECT_RECT_EQ(gfx::Rect(),
1323 occlusion.UnoccludedLayerContentRect(
1324 parent, gfx::Rect(31, 40, 70, 60)));
1325 EXPECT_RECT_EQ(gfx::Rect(),
1326 occlusion.UnoccludedLayerContentRect(
1327 parent, gfx::Rect(30, 41, 70, 60)));
[email protected]94f206c12012-08-25 00:09:141328
[email protected]a27cbde2013-03-23 22:01:491329 /* Justification for the above occlusion from |layer1| and |layer2|:
[email protected]94f206c12012-08-25 00:09:141330
1331 +---------------------+
1332 | |30 Visible region of |layer1|: /////
1333 | | Visible region of |layer2|: \\\\\
1334 | +---------------------------------+
1335 | | |10 |
1336 | +---------------+-----------------+ |
1337 | | |\\\\\\\\\\\\|//| 420 | |
1338 | | |\\\\\\\\\\\\|//|60 | |
1339 | | |\\\\\\\\\\\\|//| | |
1340 +--|--|------------|--+ | |
1341 20|10| 70 | | |
1342 | | | | |
1343 | | | | |
1344 | | | | |
1345 | | | | |
1346 | | | | |
1347 | | | |10|
1348 | +------------|-----------------|--+
1349 | | 490 |
1350 +---------------+-----------------+
1351 60 440
1352 */
[email protected]a27cbde2013-03-23 22:01:491353 }
[email protected]94f206c12012-08-25 00:09:141354};
1355
[email protected]96baf3e2012-10-22 23:09:551356ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:141357
[email protected]a27cbde2013-03-23 22:01:491358template <class Types>
[email protected]ca2902e92013-03-28 01:45:351359class OcclusionTrackerTestOverlappingSurfaceSiblings
1360 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491361 protected:
[email protected]ca2902e92013-03-28 01:45:351362 explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491363 : OcclusionTrackerTest<Types>(opaque_layers) {}
1364 void RunMyTest() {
1365 gfx::Transform child_transform;
1366 child_transform.Translate(250.0, 250.0);
1367 child_transform.Rotate(90.0);
1368 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141369
[email protected]a27cbde2013-03-23 22:01:491370 typename Types::ContentLayerType* parent = this->CreateRoot(
1371 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1372 parent->SetMasksToBounds(true);
1373 typename Types::LayerType* child1 = this->CreateSurface(
1374 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(10, 10));
1375 typename Types::LayerType* child2 = this->CreateSurface(
1376 parent, child_transform, gfx::PointF(20.f, 40.f), gfx::Size(10, 10));
1377 typename Types::ContentLayerType* layer1 =
1378 this->CreateDrawingLayer(child1,
1379 this->identity_matrix,
1380 gfx::PointF(-10.f, -10.f),
1381 gfx::Size(510, 510),
1382 true);
1383 typename Types::ContentLayerType* layer2 =
1384 this->CreateDrawingLayer(child2,
1385 this->identity_matrix,
1386 gfx::PointF(-10.f, -10.f),
1387 gfx::Size(510, 510),
1388 true);
1389 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141390
[email protected]a27cbde2013-03-23 22:01:491391 TestOcclusionTrackerWithClip<typename Types::LayerType,
1392 typename Types::RenderSurfaceType> occlusion(
1393 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141394
[email protected]d002dd02013-03-27 07:40:401395 this->VisitLayer(layer2, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231396 this->EnterContributingSurface(child2, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141397
[email protected]a27cbde2013-03-23 22:01:491398 EXPECT_EQ(gfx::Rect().ToString(),
1399 occlusion.occlusion_from_outside_target().ToString());
1400 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1401 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141402
[email protected]a27cbde2013-03-23 22:01:491403 EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 420, 70, 80)));
1404 EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-11, 420, 70, 80)));
1405 EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 419, 70, 80)));
1406 EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 420, 71, 80)));
1407 EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 420, 70, 81)));
[email protected]94f206c12012-08-25 00:09:141408
[email protected]a27cbde2013-03-23 22:01:491409 // There is nothing above child2's surface in the z-order.
1410 EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80),
1411 occlusion.UnoccludedContributingSurfaceContentRect(
1412 child2, false, gfx::Rect(-10, 420, 70, 80), NULL));
[email protected]94f206c12012-08-25 00:09:141413
[email protected]d002dd02013-03-27 07:40:401414 this->LeaveContributingSurface(child2, &occlusion);
1415 this->VisitLayer(layer1, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231416 this->EnterContributingSurface(child1, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141417
[email protected]a27cbde2013-03-23 22:01:491418 EXPECT_EQ(gfx::Rect(0, 430, 70, 80).ToString(),
1419 occlusion.occlusion_from_outside_target().ToString());
1420 EXPECT_EQ(gfx::Rect(-10, 430, 80, 70).ToString(),
1421 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141422
[email protected]a27cbde2013-03-23 22:01:491423 // child2's contents will occlude child1 below it.
1424 EXPECT_RECT_EQ(gfx::Rect(-10, 430, 10, 70),
1425 occlusion.UnoccludedContributingSurfaceContentRect(
1426 child1, false, gfx::Rect(-10, 430, 80, 70), NULL));
[email protected]94f206c12012-08-25 00:09:141427
[email protected]d002dd02013-03-27 07:40:401428 this->LeaveContributingSurface(child1, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231429 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141430
[email protected]a27cbde2013-03-23 22:01:491431 EXPECT_EQ(gfx::Rect().ToString(),
1432 occlusion.occlusion_from_outside_target().ToString());
1433 EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70))
1434 .ToString(),
1435 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141436
[email protected]a27cbde2013-03-23 22:01:491437 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 20, 80, 80)));
[email protected]94f206c12012-08-25 00:09:141438
[email protected]a27cbde2013-03-23 22:01:491439 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 20, 70, 80)));
1440 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 20, 70, 80)));
1441 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 19, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141442
[email protected]a27cbde2013-03-23 22:01:491443 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(20, 30, 80, 70)));
1444 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(19, 30, 80, 70)));
1445 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 29, 80, 70)));
[email protected]94f206c12012-08-25 00:09:141446
[email protected]a27cbde2013-03-23 22:01:491447 /* Justification for the above occlusion:
1448 100
1449 +---------------------+
1450 | 20 | layer1
1451 | 30+ ---------------------------------+
1452 100 | 30| | layer2 |
1453 |20+----------------------------------+ |
1454 | | | | | |
1455 | | | | | |
1456 | | | | | |
1457 +--|-|----------------+ | |
1458 | | | | 510
1459 | | | |
1460 | | | |
1461 | | | |
1462 | | | |
1463 | | | |
1464 | | | |
1465 | +--------------------------------|-+
1466 | |
1467 +----------------------------------+
1468 510
1469 */
1470 }
[email protected]94f206c12012-08-25 00:09:141471};
1472
[email protected]96baf3e2012-10-22 23:09:551473ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:141474
[email protected]a27cbde2013-03-23 22:01:491475template <class Types>
[email protected]ca2902e92013-03-28 01:45:351476class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms
1477 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491478 protected:
[email protected]ca2902e92013-03-28 01:45:351479 explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(
[email protected]a27cbde2013-03-23 22:01:491480 bool opaque_layers)
1481 : OcclusionTrackerTest<Types>(opaque_layers) {}
1482 void RunMyTest() {
1483 gfx::Transform child1_transform;
1484 child1_transform.Translate(250.0, 250.0);
1485 child1_transform.Rotate(-90.0);
1486 child1_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141487
[email protected]a27cbde2013-03-23 22:01:491488 gfx::Transform child2_transform;
1489 child2_transform.Translate(250.0, 250.0);
1490 child2_transform.Rotate(90.0);
1491 child2_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141492
[email protected]a27cbde2013-03-23 22:01:491493 typename Types::ContentLayerType* parent = this->CreateRoot(
1494 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1495 parent->SetMasksToBounds(true);
1496 typename Types::LayerType* child1 = this->CreateSurface(
1497 parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10));
1498 typename Types::LayerType* child2 =
1499 this->CreateDrawingSurface(parent,
1500 child2_transform,
1501 gfx::PointF(20.f, 40.f),
1502 gfx::Size(10, 10),
1503 false);
1504 typename Types::ContentLayerType* layer1 =
1505 this->CreateDrawingLayer(child1,
1506 this->identity_matrix,
1507 gfx::PointF(-10.f, -20.f),
1508 gfx::Size(510, 510),
1509 true);
1510 typename Types::ContentLayerType* layer2 =
1511 this->CreateDrawingLayer(child2,
1512 this->identity_matrix,
1513 gfx::PointF(-10.f, -10.f),
1514 gfx::Size(510, 510),
1515 true);
1516 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141517
[email protected]a27cbde2013-03-23 22:01:491518 TestOcclusionTrackerWithClip<typename Types::LayerType,
1519 typename Types::RenderSurfaceType> occlusion(
1520 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141521
[email protected]d002dd02013-03-27 07:40:401522 this->VisitLayer(layer2, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231523 this->EnterLayer(child2, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141524
[email protected]a27cbde2013-03-23 22:01:491525 EXPECT_EQ(gfx::Rect().ToString(),
1526 occlusion.occlusion_from_outside_target().ToString());
1527 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1528 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141529
[email protected]d002dd02013-03-27 07:40:401530 this->LeaveLayer(child2, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231531 this->EnterContributingSurface(child2, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141532
[email protected]a27cbde2013-03-23 22:01:491533 // There is nothing above child2's surface in the z-order.
1534 EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80),
1535 occlusion.UnoccludedContributingSurfaceContentRect(
1536 child2, false, gfx::Rect(-10, 420, 70, 80), NULL));
[email protected]94f206c12012-08-25 00:09:141537
[email protected]d002dd02013-03-27 07:40:401538 this->LeaveContributingSurface(child2, &occlusion);
1539 this->VisitLayer(layer1, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231540 this->EnterContributingSurface(child1, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141541
[email protected]a27cbde2013-03-23 22:01:491542 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
1543 occlusion.occlusion_from_outside_target().ToString());
1544 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
1545 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141546
[email protected]a27cbde2013-03-23 22:01:491547 // child2's contents will occlude child1 below it.
1548 EXPECT_RECT_EQ(gfx::Rect(420, -20, 80, 90),
1549 occlusion.UnoccludedContributingSurfaceContentRect(
1550 child1, false, gfx::Rect(420, -20, 80, 90), NULL));
1551 EXPECT_RECT_EQ(gfx::Rect(490, -10, 10, 80),
1552 occlusion.UnoccludedContributingSurfaceContentRect(
1553 child1, false, gfx::Rect(420, -10, 80, 90), NULL));
1554 EXPECT_RECT_EQ(gfx::Rect(420, -20, 70, 10),
1555 occlusion.UnoccludedContributingSurfaceContentRect(
1556 child1, false, gfx::Rect(420, -20, 70, 90), NULL));
[email protected]94f206c12012-08-25 00:09:141557
[email protected]d002dd02013-03-27 07:40:401558 this->LeaveContributingSurface(child1, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231559 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141560
[email protected]a27cbde2013-03-23 22:01:491561 EXPECT_EQ(gfx::Rect().ToString(),
1562 occlusion.occlusion_from_outside_target().ToString());
1563 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(),
1564 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141565
[email protected]a27cbde2013-03-23 22:01:491566 /* Justification for the above occlusion:
1567 100
1568 +---------------------+
1569 |20 | layer1
1570 10+----------------------------------+
1571 100 || 30 | layer2 |
1572 |20+----------------------------------+
1573 || | | | |
1574 || | | | |
1575 || | | | |
1576 +|-|------------------+ | |
1577 | | | | 510
1578 | | 510 | |
1579 | | | |
1580 | | | |
1581 | | | |
1582 | | | |
1583 | | 520 | |
1584 +----------------------------------+ |
1585 | |
1586 +----------------------------------+
1587 510
1588 */
1589 }
[email protected]94f206c12012-08-25 00:09:141590};
1591
[email protected]a27cbde2013-03-23 22:01:491592ALL_OCCLUSIONTRACKER_TEST(
1593 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:141594
[email protected]a27cbde2013-03-23 22:01:491595template <class Types>
[email protected]96baf3e2012-10-22 23:09:551596class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491597 protected:
[email protected]ca2902e92013-03-28 01:45:351598 explicit OcclusionTrackerTestFilters(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491599 : OcclusionTrackerTest<Types>(opaque_layers) {}
1600 void RunMyTest() {
1601 gfx::Transform layer_transform;
1602 layer_transform.Translate(250.0, 250.0);
1603 layer_transform.Rotate(90.0);
1604 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141605
[email protected]a27cbde2013-03-23 22:01:491606 typename Types::ContentLayerType* parent = this->CreateRoot(
1607 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1608 parent->SetMasksToBounds(true);
1609 typename Types::ContentLayerType* blur_layer =
1610 this->CreateDrawingLayer(parent,
1611 layer_transform,
1612 gfx::PointF(30.f, 30.f),
1613 gfx::Size(500, 500),
1614 true);
1615 typename Types::ContentLayerType* opaque_layer =
1616 this->CreateDrawingLayer(parent,
1617 layer_transform,
1618 gfx::PointF(30.f, 30.f),
1619 gfx::Size(500, 500),
1620 true);
1621 typename Types::ContentLayerType* opacity_layer =
1622 this->CreateDrawingLayer(parent,
1623 layer_transform,
1624 gfx::PointF(30.f, 30.f),
1625 gfx::Size(500, 500),
1626 true);
[email protected]94f206c12012-08-25 00:09:141627
[email protected]ae6b1a72013-06-25 18:49:291628 FilterOperations filters;
1629 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]a27cbde2013-03-23 22:01:491630 blur_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141631
[email protected]ae6b1a72013-06-25 18:49:291632 filters.Clear();
1633 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491634 opaque_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141635
[email protected]ae6b1a72013-06-25 18:49:291636 filters.Clear();
1637 filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491638 opacity_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141639
[email protected]a27cbde2013-03-23 22:01:491640 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141641
[email protected]a27cbde2013-03-23 22:01:491642 TestOcclusionTrackerWithClip<typename Types::LayerType,
1643 typename Types::RenderSurfaceType> occlusion(
1644 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141645
[email protected]a27cbde2013-03-23 22:01:491646 // Opacity layer won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401647 this->VisitLayer(opacity_layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231648 this->EnterContributingSurface(opacity_layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141649
[email protected]a27cbde2013-03-23 22:01:491650 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1651 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141652
[email protected]a27cbde2013-03-23 22:01:491653 // And has nothing to contribute to its parent surface.
[email protected]d002dd02013-03-27 07:40:401654 this->LeaveContributingSurface(opacity_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491655 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1656 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141657
[email protected]a27cbde2013-03-23 22:01:491658 // Opaque layer will contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401659 this->VisitLayer(opaque_layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231660 this->EnterContributingSurface(opaque_layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141661
[email protected]a27cbde2013-03-23 22:01:491662 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1663 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(),
1664 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141665
[email protected]a27cbde2013-03-23 22:01:491666 // And it gets translated to the parent surface.
[email protected]d002dd02013-03-27 07:40:401667 this->LeaveContributingSurface(opaque_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491668 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1669 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1670 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141671
[email protected]a27cbde2013-03-23 22:01:491672 // The blur layer needs to throw away any occlusion from outside its
1673 // subtree.
[email protected]2ea5e6c2013-04-26 21:52:231674 this->EnterLayer(blur_layer, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:491675 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1676 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141677
[email protected]a27cbde2013-03-23 22:01:491678 // And it won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401679 this->LeaveLayer(blur_layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231680 this->EnterContributingSurface(blur_layer, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:491681 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1682 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141683
[email protected]a27cbde2013-03-23 22:01:491684 // But the opaque layer's occlusion is preserved on the parent.
[email protected]d002dd02013-03-27 07:40:401685 this->LeaveContributingSurface(blur_layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231686 this->EnterLayer(parent, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:491687 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1688 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1689 occlusion.occlusion_from_inside_target().ToString());
1690 }
[email protected]94f206c12012-08-25 00:09:141691};
1692
[email protected]96baf3e2012-10-22 23:09:551693ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:141694
[email protected]a27cbde2013-03-23 22:01:491695template <class Types>
[email protected]ca2902e92013-03-28 01:45:351696class OcclusionTrackerTestReplicaDoesOcclude
1697 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491698 protected:
[email protected]ca2902e92013-03-28 01:45:351699 explicit OcclusionTrackerTestReplicaDoesOcclude(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491700 : OcclusionTrackerTest<Types>(opaque_layers) {}
1701 void RunMyTest() {
1702 typename Types::ContentLayerType* parent = this->CreateRoot(
1703 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
1704 typename Types::LayerType* surface =
1705 this->CreateDrawingSurface(parent,
1706 this->identity_matrix,
1707 gfx::PointF(0.f, 100.f),
1708 gfx::Size(50, 50),
1709 true);
1710 this->CreateReplicaLayer(
1711 surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
1712 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141713
[email protected]a27cbde2013-03-23 22:01:491714 TestOcclusionTrackerWithClip<typename Types::LayerType,
1715 typename Types::RenderSurfaceType> occlusion(
1716 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141717
[email protected]d002dd02013-03-27 07:40:401718 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141719
[email protected]a27cbde2013-03-23 22:01:491720 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1721 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141722
[email protected]d002dd02013-03-27 07:40:401723 this->VisitContributingSurface(surface, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231724 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141725
[email protected]a27cbde2013-03-23 22:01:491726 // The surface and replica should both be occluding the parent.
1727 EXPECT_EQ(
1728 UnionRegions(gfx::Rect(0, 100, 50, 50),
1729 gfx::Rect(50, 150, 50, 50)).ToString(),
1730 occlusion.occlusion_from_inside_target().ToString());
1731 }
[email protected]94f206c12012-08-25 00:09:141732};
1733
[email protected]96baf3e2012-10-22 23:09:551734ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude);
[email protected]94f206c12012-08-25 00:09:141735
[email protected]a27cbde2013-03-23 22:01:491736template <class Types>
[email protected]ca2902e92013-03-28 01:45:351737class OcclusionTrackerTestReplicaWithClipping
1738 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491739 protected:
[email protected]ca2902e92013-03-28 01:45:351740 explicit OcclusionTrackerTestReplicaWithClipping(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491741 : OcclusionTrackerTest<Types>(opaque_layers) {}
1742 void RunMyTest() {
1743 typename Types::ContentLayerType* parent = this->CreateRoot(
1744 this->identity_matrix, gfx::PointF(), gfx::Size(100, 170));
1745 parent->SetMasksToBounds(true);
1746 typename Types::LayerType* surface =
1747 this->CreateDrawingSurface(parent,
1748 this->identity_matrix,
1749 gfx::PointF(0.f, 100.f),
1750 gfx::Size(50, 50),
1751 true);
1752 this->CreateReplicaLayer(
1753 surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
1754 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141755
[email protected]a27cbde2013-03-23 22:01:491756 TestOcclusionTrackerWithClip<typename Types::LayerType,
1757 typename Types::RenderSurfaceType> occlusion(
1758 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141759
[email protected]d002dd02013-03-27 07:40:401760 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141761
[email protected]a27cbde2013-03-23 22:01:491762 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1763 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141764
[email protected]d002dd02013-03-27 07:40:401765 this->VisitContributingSurface(surface, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231766 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141767
[email protected]a27cbde2013-03-23 22:01:491768 // The surface and replica should both be occluding the parent.
1769 EXPECT_EQ(
1770 UnionRegions(gfx::Rect(0, 100, 50, 50),
1771 gfx::Rect(50, 150, 50, 20)).ToString(),
1772 occlusion.occlusion_from_inside_target().ToString());
1773 }
[email protected]94f206c12012-08-25 00:09:141774};
1775
[email protected]96baf3e2012-10-22 23:09:551776ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping);
[email protected]94f206c12012-08-25 00:09:141777
[email protected]a27cbde2013-03-23 22:01:491778template <class Types>
[email protected]96baf3e2012-10-22 23:09:551779class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491780 protected:
[email protected]ca2902e92013-03-28 01:45:351781 explicit OcclusionTrackerTestReplicaWithMask(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491782 : OcclusionTrackerTest<Types>(opaque_layers) {}
1783 void RunMyTest() {
1784 typename Types::ContentLayerType* parent = this->CreateRoot(
1785 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
1786 typename Types::LayerType* surface =
1787 this->CreateDrawingSurface(parent,
1788 this->identity_matrix,
1789 gfx::PointF(0.f, 100.f),
1790 gfx::Size(50, 50),
1791 true);
1792 typename Types::LayerType* replica = this->CreateReplicaLayer(
1793 surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
1794 this->CreateMaskLayer(replica, gfx::Size(10, 10));
1795 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141796
[email protected]a27cbde2013-03-23 22:01:491797 TestOcclusionTrackerWithClip<typename Types::LayerType,
1798 typename Types::RenderSurfaceType> occlusion(
1799 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141800
[email protected]d002dd02013-03-27 07:40:401801 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141802
[email protected]a27cbde2013-03-23 22:01:491803 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1804 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141805
[email protected]d002dd02013-03-27 07:40:401806 this->VisitContributingSurface(surface, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231807 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141808
[email protected]a27cbde2013-03-23 22:01:491809 // The replica should not be occluding the parent, since it has a mask
1810 // applied to it.
1811 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(),
1812 occlusion.occlusion_from_inside_target().ToString());
1813 }
[email protected]94f206c12012-08-25 00:09:141814};
1815
[email protected]96baf3e2012-10-22 23:09:551816ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask);
[email protected]94f206c12012-08-25 00:09:141817
[email protected]a27cbde2013-03-23 22:01:491818template <class Types>
[email protected]ca2902e92013-03-28 01:45:351819class OcclusionTrackerTestLayerClipRectOutsideChild
1820 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491821 protected:
[email protected]ca2902e92013-03-28 01:45:351822 explicit OcclusionTrackerTestLayerClipRectOutsideChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491823 : OcclusionTrackerTest<Types>(opaque_layers) {}
1824 void RunMyTest() {
1825 typename Types::ContentLayerType* parent = this->CreateRoot(
1826 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1827 typename Types::ContentLayerType* clip =
1828 this->CreateDrawingLayer(parent,
1829 this->identity_matrix,
1830 gfx::PointF(200.f, 100.f),
1831 gfx::Size(100, 100),
1832 false);
1833 clip->SetMasksToBounds(true);
1834 typename Types::ContentLayerType* layer =
1835 this->CreateDrawingLayer(clip,
1836 this->identity_matrix,
1837 gfx::PointF(-200.f, -100.f),
1838 gfx::Size(200, 200),
1839 false);
1840 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141841
[email protected]a27cbde2013-03-23 22:01:491842 TestOcclusionTrackerWithClip<typename Types::LayerType,
1843 typename Types::RenderSurfaceType> occlusion(
1844 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141845
[email protected]2ea5e6c2013-04-26 21:52:231846 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141847
[email protected]a27cbde2013-03-23 22:01:491848 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1849 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1850 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1851 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
1852 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141853
[email protected]d002dd02013-03-27 07:40:401854 this->LeaveLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231855 this->EnterLayer(clip, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141856
[email protected]a27cbde2013-03-23 22:01:491857 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(-100, 0, 100, 100)));
1858 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, -100, 100, 100)));
1859 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 0, 100, 100)));
1860 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 100, 100, 100)));
1861 EXPECT_FALSE(occlusion.OccludedLayer(clip, gfx::Rect(0, 0, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141862
[email protected]a27cbde2013-03-23 22:01:491863 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
1864 occlusion.UnoccludedLayerContentRect(
1865 clip, gfx::Rect(-100, -100, 300, 300)));
1866 }
[email protected]94f206c12012-08-25 00:09:141867};
1868
[email protected]96baf3e2012-10-22 23:09:551869ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOutsideChild);
[email protected]94f206c12012-08-25 00:09:141870
[email protected]a27cbde2013-03-23 22:01:491871template <class Types>
[email protected]ca2902e92013-03-28 01:45:351872class OcclusionTrackerTestViewportRectOutsideChild
1873 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491874 protected:
[email protected]ca2902e92013-03-28 01:45:351875 explicit OcclusionTrackerTestViewportRectOutsideChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491876 : OcclusionTrackerTest<Types>(opaque_layers) {}
1877 void RunMyTest() {
1878 typename Types::ContentLayerType* parent = this->CreateRoot(
1879 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1880 typename Types::ContentLayerType* layer =
1881 this->CreateDrawingSurface(parent,
1882 this->identity_matrix,
1883 gfx::PointF(),
1884 gfx::Size(200, 200),
1885 true);
1886 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141887
[email protected]a27cbde2013-03-23 22:01:491888 TestOcclusionTrackerWithClip<typename Types::LayerType,
1889 typename Types::RenderSurfaceType> occlusion(
1890 gfx::Rect(200, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:141891
[email protected]2ea5e6c2013-04-26 21:52:231892 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141893
[email protected]a27cbde2013-03-23 22:01:491894 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1895 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1896 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1897 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
1898 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141899
[email protected]d002dd02013-03-27 07:40:401900 this->LeaveLayer(layer, &occlusion);
1901 this->VisitContributingSurface(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:231902 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141903
[email protected]a27cbde2013-03-23 22:01:491904 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
1905 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1906 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
1907 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1908 EXPECT_FALSE(
1909 occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
1910 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
1911 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
1912 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
1913 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141914
[email protected]a27cbde2013-03-23 22:01:491915 EXPECT_RECT_EQ(gfx::Rect(200, 100, 100, 100),
1916 occlusion.UnoccludedLayerContentRect(
1917 parent, gfx::Rect(0, 0, 300, 300)));
1918 }
[email protected]94f206c12012-08-25 00:09:141919};
1920
[email protected]96baf3e2012-10-22 23:09:551921ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOutsideChild);
[email protected]94f206c12012-08-25 00:09:141922
[email protected]a27cbde2013-03-23 22:01:491923template <class Types>
[email protected]ca2902e92013-03-28 01:45:351924class OcclusionTrackerTestLayerClipRectOverChild
1925 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491926 protected:
[email protected]ca2902e92013-03-28 01:45:351927 explicit OcclusionTrackerTestLayerClipRectOverChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491928 : OcclusionTrackerTest<Types>(opaque_layers) {}
1929 void RunMyTest() {
1930 typename Types::ContentLayerType* parent = this->CreateRoot(
1931 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1932 typename Types::ContentLayerType* clip =
1933 this->CreateDrawingLayer(parent,
1934 this->identity_matrix,
1935 gfx::PointF(100.f, 100.f),
1936 gfx::Size(100, 100),
1937 false);
1938 clip->SetMasksToBounds(true);
1939 typename Types::ContentLayerType* layer =
1940 this->CreateDrawingSurface(clip,
1941 this->identity_matrix,
1942 gfx::PointF(-100.f, -100.f),
1943 gfx::Size(200, 200),
1944 true);
1945 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141946
[email protected]a27cbde2013-03-23 22:01:491947 TestOcclusionTrackerWithClip<typename Types::LayerType,
1948 typename Types::RenderSurfaceType> occlusion(
1949 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141950
[email protected]2ea5e6c2013-04-26 21:52:231951 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:141952
[email protected]a27cbde2013-03-23 22:01:491953 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1954 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1955 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1956 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141957
[email protected]d002dd02013-03-27 07:40:401958 this->LeaveLayer(layer, &occlusion);
1959 this->VisitContributingSurface(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141960
[email protected]a27cbde2013-03-23 22:01:491961 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
1962 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141963
[email protected]2ea5e6c2013-04-26 21:52:231964 this->EnterLayer(clip, &occlusion, false);
[email protected]c8d71552013-01-22 03:43:021965
[email protected]a27cbde2013-03-23 22:01:491966 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 0, 100, 100)));
1967 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 100, 100, 100)));
1968 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 0, 100, 100)));
1969 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 100, 100, 100)));
1970 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(200, 100, 100, 100)));
1971 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(200, 0, 100, 100)));
1972 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 200, 100, 100)));
1973 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 200, 100, 100)));
1974 EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(200, 200, 100, 100)));
[email protected]c8d71552013-01-22 03:43:021975
[email protected]a27cbde2013-03-23 22:01:491976 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1977 clip, gfx::Rect(0, 0, 300, 300)).IsEmpty());
1978 }
[email protected]94f206c12012-08-25 00:09:141979};
1980
[email protected]96baf3e2012-10-22 23:09:551981ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOverChild);
[email protected]94f206c12012-08-25 00:09:141982
[email protected]a27cbde2013-03-23 22:01:491983template <class Types>
[email protected]ca2902e92013-03-28 01:45:351984class OcclusionTrackerTestViewportRectOverChild
1985 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491986 protected:
[email protected]ca2902e92013-03-28 01:45:351987 explicit OcclusionTrackerTestViewportRectOverChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491988 : OcclusionTrackerTest<Types>(opaque_layers) {}
1989 void RunMyTest() {
1990 typename Types::ContentLayerType* parent = this->CreateRoot(
1991 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1992 typename Types::ContentLayerType* layer =
1993 this->CreateDrawingSurface(parent,
1994 this->identity_matrix,
1995 gfx::PointF(),
1996 gfx::Size(200, 200),
1997 true);
1998 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141999
[email protected]a27cbde2013-03-23 22:01:492000 TestOcclusionTrackerWithClip<typename Types::LayerType,
2001 typename Types::RenderSurfaceType> occlusion(
2002 gfx::Rect(100, 100, 100, 100));
[email protected]94f206c12012-08-25 00:09:142003
[email protected]2ea5e6c2013-04-26 21:52:232004 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142005
[email protected]a27cbde2013-03-23 22:01:492006 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2007 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
2008 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
2009 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142010
[email protected]d002dd02013-03-27 07:40:402011 this->LeaveLayer(layer, &occlusion);
2012 this->VisitContributingSurface(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232013 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142014
[email protected]a27cbde2013-03-23 22:01:492015 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
2016 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
2017 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
2018 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
2019 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
2020 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
2021 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
2022 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
2023 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142024
[email protected]a27cbde2013-03-23 22:01:492025 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
2026 parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
2027 }
[email protected]94f206c12012-08-25 00:09:142028};
2029
[email protected]96baf3e2012-10-22 23:09:552030ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverChild);
[email protected]94f206c12012-08-25 00:09:142031
[email protected]a27cbde2013-03-23 22:01:492032template <class Types>
[email protected]ca2902e92013-03-28 01:45:352033class OcclusionTrackerTestLayerClipRectPartlyOverChild
2034 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492035 protected:
[email protected]ca2902e92013-03-28 01:45:352036 explicit OcclusionTrackerTestLayerClipRectPartlyOverChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492037 : OcclusionTrackerTest<Types>(opaque_layers) {}
2038 void RunMyTest() {
2039 typename Types::ContentLayerType* parent = this->CreateRoot(
2040 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2041 typename Types::ContentLayerType* clip =
2042 this->CreateDrawingLayer(parent,
2043 this->identity_matrix,
2044 gfx::PointF(50.f, 50.f),
2045 gfx::Size(200, 200),
2046 false);
2047 clip->SetMasksToBounds(true);
2048 typename Types::ContentLayerType* layer =
2049 this->CreateDrawingSurface(clip,
2050 this->identity_matrix,
2051 gfx::PointF(-50.f, -50.f),
2052 gfx::Size(200, 200),
2053 true);
2054 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142055
[email protected]a27cbde2013-03-23 22:01:492056 TestOcclusionTrackerWithClip<typename Types::LayerType,
2057 typename Types::RenderSurfaceType> occlusion(
2058 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142059
[email protected]2ea5e6c2013-04-26 21:52:232060 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142061
[email protected]a27cbde2013-03-23 22:01:492062 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2063 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
2064 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
2065 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142066
[email protected]a27cbde2013-03-23 22:01:492067 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 50)));
2068 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 50, 100)));
2069 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 50)));
2070 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 50, 100)));
[email protected]c8d71552013-01-22 03:43:022071
[email protected]d002dd02013-03-27 07:40:402072 this->LeaveLayer(layer, &occlusion);
2073 this->VisitContributingSurface(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232074 this->EnterLayer(clip, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142075
[email protected]a27cbde2013-03-23 22:01:492076 EXPECT_EQ(gfx::Rect(50, 50, 150, 150).ToString(),
2077 occlusion.occlusion_from_inside_target().ToString());
2078 }
[email protected]94f206c12012-08-25 00:09:142079};
2080
[email protected]96baf3e2012-10-22 23:09:552081ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectPartlyOverChild);
[email protected]94f206c12012-08-25 00:09:142082
[email protected]a27cbde2013-03-23 22:01:492083template <class Types>
[email protected]ca2902e92013-03-28 01:45:352084class OcclusionTrackerTestViewportRectPartlyOverChild
2085 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492086 protected:
[email protected]ca2902e92013-03-28 01:45:352087 explicit OcclusionTrackerTestViewportRectPartlyOverChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492088 : OcclusionTrackerTest<Types>(opaque_layers) {}
2089 void RunMyTest() {
2090 typename Types::ContentLayerType* parent = this->CreateRoot(
2091 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2092 typename Types::ContentLayerType* layer =
2093 this->CreateDrawingSurface(parent,
2094 this->identity_matrix,
2095 gfx::PointF(),
2096 gfx::Size(200, 200),
2097 true);
2098 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142099
[email protected]a27cbde2013-03-23 22:01:492100 TestOcclusionTrackerWithClip<typename Types::LayerType,
2101 typename Types::RenderSurfaceType> occlusion(
2102 gfx::Rect(50, 50, 200, 200));
[email protected]94f206c12012-08-25 00:09:142103
[email protected]2ea5e6c2013-04-26 21:52:232104 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142105
[email protected]a27cbde2013-03-23 22:01:492106 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2107 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
2108 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
2109 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142110
[email protected]d002dd02013-03-27 07:40:402111 this->LeaveLayer(layer, &occlusion);
2112 this->VisitContributingSurface(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232113 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142114
[email protected]a27cbde2013-03-23 22:01:492115 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
2116 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
2117 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
2118 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
2119 EXPECT_FALSE(
2120 occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
2121 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
2122 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
2123 EXPECT_FALSE(
2124 occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
2125 EXPECT_FALSE(
2126 occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142127
[email protected]a27cbde2013-03-23 22:01:492128 EXPECT_RECT_EQ(gfx::Rect(50, 50, 200, 200),
2129 occlusion.UnoccludedLayerContentRect(
2130 parent, gfx::Rect(0, 0, 300, 300)));
2131 EXPECT_RECT_EQ(gfx::Rect(200, 50, 50, 50),
2132 occlusion.UnoccludedLayerContentRect(
2133 parent, gfx::Rect(0, 0, 300, 100)));
2134 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100),
2135 occlusion.UnoccludedLayerContentRect(
2136 parent, gfx::Rect(0, 100, 300, 100)));
2137 EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100),
2138 occlusion.UnoccludedLayerContentRect(
2139 parent, gfx::Rect(200, 100, 100, 100)));
2140 EXPECT_RECT_EQ(gfx::Rect(100, 200, 100, 50),
2141 occlusion.UnoccludedLayerContentRect(
2142 parent, gfx::Rect(100, 200, 100, 100)));
2143 }
[email protected]94f206c12012-08-25 00:09:142144};
2145
[email protected]96baf3e2012-10-22 23:09:552146ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectPartlyOverChild);
[email protected]94f206c12012-08-25 00:09:142147
[email protected]a27cbde2013-03-23 22:01:492148template <class Types>
[email protected]ca2902e92013-03-28 01:45:352149class OcclusionTrackerTestViewportRectOverNothing
2150 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492151 protected:
[email protected]ca2902e92013-03-28 01:45:352152 explicit OcclusionTrackerTestViewportRectOverNothing(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492153 : OcclusionTrackerTest<Types>(opaque_layers) {}
2154 void RunMyTest() {
2155 typename Types::ContentLayerType* parent = this->CreateRoot(
2156 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2157 typename Types::ContentLayerType* layer =
2158 this->CreateDrawingSurface(parent,
2159 this->identity_matrix,
2160 gfx::PointF(),
2161 gfx::Size(200, 200),
2162 true);
2163 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142164
[email protected]a27cbde2013-03-23 22:01:492165 TestOcclusionTrackerWithClip<typename Types::LayerType,
2166 typename Types::RenderSurfaceType> occlusion(
2167 gfx::Rect(500, 500, 100, 100));
[email protected]94f206c12012-08-25 00:09:142168
[email protected]2ea5e6c2013-04-26 21:52:232169 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142170
[email protected]a27cbde2013-03-23 22:01:492171 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2172 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
2173 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
2174 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142175
[email protected]d002dd02013-03-27 07:40:402176 this->LeaveLayer(layer, &occlusion);
2177 this->VisitContributingSurface(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232178 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142179
[email protected]a27cbde2013-03-23 22:01:492180 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
2181 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
2182 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
2183 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
2184 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
2185 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
2186 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
2187 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
2188 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142189
[email protected]a27cbde2013-03-23 22:01:492190 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
2191 parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
2192 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
2193 parent, gfx::Rect(0, 0, 300, 100)).IsEmpty());
2194 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
2195 parent, gfx::Rect(0, 100, 300, 100)).IsEmpty());
2196 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
2197 parent, gfx::Rect(200, 100, 100, 100)).IsEmpty());
2198 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
2199 parent, gfx::Rect(100, 200, 100, 100)).IsEmpty());
2200 }
[email protected]94f206c12012-08-25 00:09:142201};
2202
[email protected]96baf3e2012-10-22 23:09:552203ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverNothing);
[email protected]94f206c12012-08-25 00:09:142204
[email protected]a27cbde2013-03-23 22:01:492205template <class Types>
[email protected]ca2902e92013-03-28 01:45:352206class OcclusionTrackerTestLayerClipRectForLayerOffOrigin
2207 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492208 protected:
[email protected]ca2902e92013-03-28 01:45:352209 explicit OcclusionTrackerTestLayerClipRectForLayerOffOrigin(
2210 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492211 : OcclusionTrackerTest<Types>(opaque_layers) {}
2212 void RunMyTest() {
2213 typename Types::ContentLayerType* parent = this->CreateRoot(
2214 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2215 typename Types::ContentLayerType* layer =
2216 this->CreateDrawingSurface(parent,
2217 this->identity_matrix,
2218 gfx::PointF(),
2219 gfx::Size(200, 200),
2220 true);
2221 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142222
[email protected]a27cbde2013-03-23 22:01:492223 TestOcclusionTrackerWithClip<typename Types::LayerType,
2224 typename Types::RenderSurfaceType> occlusion(
2225 gfx::Rect(0, 0, 1000, 1000));
[email protected]2ea5e6c2013-04-26 21:52:232226 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142227
[email protected]a27cbde2013-03-23 22:01:492228 // This layer is translated when drawn into its target. So if the clip rect
2229 // given from the target surface is not in that target space, then after
2230 // translating these query rects into the target, they will fall outside the
2231 // clip and be considered occluded.
2232 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2233 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
2234 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
2235 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
2236 }
[email protected]94f206c12012-08-25 00:09:142237};
2238
[email protected]96baf3e2012-10-22 23:09:552239ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectForLayerOffOrigin);
[email protected]94f206c12012-08-25 00:09:142240
[email protected]a27cbde2013-03-23 22:01:492241template <class Types>
[email protected]ca2902e92013-03-28 01:45:352242class OcclusionTrackerTestOpaqueContentsRegionEmpty
2243 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492244 protected:
[email protected]ca2902e92013-03-28 01:45:352245 explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492246 : OcclusionTrackerTest<Types>(opaque_layers) {}
2247 void RunMyTest() {
2248 typename Types::ContentLayerType* parent = this->CreateRoot(
2249 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2250 typename Types::ContentLayerType* layer =
2251 this->CreateDrawingSurface(parent,
2252 this->identity_matrix,
2253 gfx::PointF(),
2254 gfx::Size(200, 200),
2255 false);
2256 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142257
[email protected]a27cbde2013-03-23 22:01:492258 TestOcclusionTrackerWithClip<typename Types::LayerType,
2259 typename Types::RenderSurfaceType> occlusion(
2260 gfx::Rect(0, 0, 1000, 1000));
[email protected]2ea5e6c2013-04-26 21:52:232261 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142262
[email protected]a27cbde2013-03-23 22:01:492263 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2264 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
2265 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
2266 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142267
[email protected]a27cbde2013-03-23 22:01:492268 // Occluded since its outside the surface bounds.
2269 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142270
[email protected]d002dd02013-03-27 07:40:402271 this->LeaveLayer(layer, &occlusion);
2272 this->VisitContributingSurface(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232273 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142274
[email protected]a27cbde2013-03-23 22:01:492275 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
2276 }
[email protected]94f206c12012-08-25 00:09:142277};
2278
[email protected]96baf3e2012-10-22 23:09:552279MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:142280
[email protected]a27cbde2013-03-23 22:01:492281template <class Types>
[email protected]ca2902e92013-03-28 01:45:352282class OcclusionTrackerTestOpaqueContentsRegionNonEmpty
2283 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492284 protected:
[email protected]ca2902e92013-03-28 01:45:352285 explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492286 : OcclusionTrackerTest<Types>(opaque_layers) {}
2287 void RunMyTest() {
2288 typename Types::ContentLayerType* parent = this->CreateRoot(
2289 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2290 typename Types::ContentLayerType* layer =
2291 this->CreateDrawingLayer(parent,
2292 this->identity_matrix,
2293 gfx::PointF(100.f, 100.f),
2294 gfx::Size(200, 200),
2295 false);
2296 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142297 {
[email protected]a27cbde2013-03-23 22:01:492298 TestOcclusionTrackerWithClip<typename Types::LayerType,
2299 typename Types::RenderSurfaceType> occlusion(
2300 gfx::Rect(0, 0, 1000, 1000));
2301 layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:142302
[email protected]a27cbde2013-03-23 22:01:492303 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:402304 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232305 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142306
[email protected]a27cbde2013-03-23 22:01:492307 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
2308 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142309
[email protected]a27cbde2013-03-23 22:01:492310 EXPECT_FALSE(
2311 occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
2312 EXPECT_TRUE(
2313 occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
2314 EXPECT_FALSE(
2315 occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:142316 }
[email protected]a27cbde2013-03-23 22:01:492317 {
2318 TestOcclusionTrackerWithClip<typename Types::LayerType,
2319 typename Types::RenderSurfaceType> occlusion(
2320 gfx::Rect(0, 0, 1000, 1000));
2321 layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
2322
2323 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:402324 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232325 this->EnterLayer(parent, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492326
2327 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(),
2328 occlusion.occlusion_from_inside_target().ToString());
2329
2330 EXPECT_FALSE(
2331 occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
2332 EXPECT_FALSE(
2333 occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
2334 EXPECT_TRUE(
2335 occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
2336 }
2337 {
2338 TestOcclusionTrackerWithClip<typename Types::LayerType,
2339 typename Types::RenderSurfaceType> occlusion(
2340 gfx::Rect(0, 0, 1000, 1000));
2341 layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
2342
2343 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:402344 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232345 this->EnterLayer(parent, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492346
2347 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
2348 occlusion.occlusion_from_inside_target().ToString());
2349
2350 EXPECT_FALSE(
2351 occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
2352 EXPECT_FALSE(
2353 occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
2354 EXPECT_FALSE(
2355 occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
2356 }
2357 }
[email protected]94f206c12012-08-25 00:09:142358};
2359
[email protected]96baf3e2012-10-22 23:09:552360MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:142361
[email protected]a27cbde2013-03-23 22:01:492362template <class Types>
[email protected]96baf3e2012-10-22 23:09:552363class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492364 protected:
[email protected]ca2902e92013-03-28 01:45:352365 explicit OcclusionTrackerTest3dTransform(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492366 : OcclusionTrackerTest<Types>(opaque_layers) {}
2367 void RunMyTest() {
2368 gfx::Transform transform;
2369 transform.RotateAboutYAxis(30.0);
[email protected]94f206c12012-08-25 00:09:142370
[email protected]a27cbde2013-03-23 22:01:492371 typename Types::ContentLayerType* parent = this->CreateRoot(
2372 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2373 typename Types::LayerType* container = this->CreateLayer(
2374 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2375 typename Types::ContentLayerType* layer =
2376 this->CreateDrawingLayer(container,
2377 transform,
2378 gfx::PointF(100.f, 100.f),
2379 gfx::Size(200, 200),
2380 true);
2381 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142382
[email protected]a27cbde2013-03-23 22:01:492383 TestOcclusionTrackerWithClip<typename Types::LayerType,
2384 typename Types::RenderSurfaceType> occlusion(
2385 gfx::Rect(0, 0, 1000, 1000));
[email protected]2ea5e6c2013-04-26 21:52:232386 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142387
[email protected]a27cbde2013-03-23 22:01:492388 // The layer is rotated in 3d but without preserving 3d, so it only gets
2389 // resized.
2390 EXPECT_RECT_EQ(
2391 gfx::Rect(0, 0, 200, 200),
2392 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
2393 }
[email protected]94f206c12012-08-25 00:09:142394};
2395
[email protected]96baf3e2012-10-22 23:09:552396MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform);
[email protected]94f206c12012-08-25 00:09:142397
[email protected]a27cbde2013-03-23 22:01:492398template <class Types>
[email protected]ca2902e92013-03-28 01:45:352399class OcclusionTrackerTestUnsorted3dLayers
2400 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492401 protected:
[email protected]ca2902e92013-03-28 01:45:352402 explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492403 : OcclusionTrackerTest<Types>(opaque_layers) {}
2404 void RunMyTest() {
2405 // Currently, The main thread layer iterator does not iterate over 3d items
2406 // in sorted order, because layer sorting is not performed on the main
2407 // thread. Because of this, the occlusion tracker cannot assume that a 3d
2408 // layer occludes other layers that have not yet been iterated over. For
2409 // now, the expected behavior is that a 3d layer simply does not add any
2410 // occlusion to the occlusion tracker.
[email protected]94f206c12012-08-25 00:09:142411
[email protected]a27cbde2013-03-23 22:01:492412 gfx::Transform translation_to_front;
2413 translation_to_front.Translate3d(0.0, 0.0, -10.0);
2414 gfx::Transform translation_to_back;
2415 translation_to_front.Translate3d(0.0, 0.0, -100.0);
[email protected]94f206c12012-08-25 00:09:142416
[email protected]a27cbde2013-03-23 22:01:492417 typename Types::ContentLayerType* parent = this->CreateRoot(
2418 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2419 typename Types::ContentLayerType* child1 = this->CreateDrawingLayer(
2420 parent, translation_to_back, gfx::PointF(), gfx::Size(100, 100), true);
2421 typename Types::ContentLayerType* child2 =
2422 this->CreateDrawingLayer(parent,
2423 translation_to_front,
2424 gfx::PointF(50.f, 50.f),
2425 gfx::Size(100, 100),
2426 true);
2427 parent->SetPreserves3d(true);
[email protected]94f206c12012-08-25 00:09:142428
[email protected]a27cbde2013-03-23 22:01:492429 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142430
[email protected]a27cbde2013-03-23 22:01:492431 TestOcclusionTrackerWithClip<typename Types::LayerType,
2432 typename Types::RenderSurfaceType> occlusion(
2433 gfx::Rect(0, 0, 1000, 1000));
[email protected]d002dd02013-03-27 07:40:402434 this->VisitLayer(child2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492435 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
2436 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:142437
[email protected]d002dd02013-03-27 07:40:402438 this->VisitLayer(child1, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492439 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
2440 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
2441 }
[email protected]94f206c12012-08-25 00:09:142442};
2443
[email protected]a27cbde2013-03-23 22:01:492444// This test will have different layer ordering on the impl thread; the test
2445// will only work on the main thread.
[email protected]96baf3e2012-10-22 23:09:552446MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
[email protected]94f206c12012-08-25 00:09:142447
[email protected]a27cbde2013-03-23 22:01:492448template <class Types>
[email protected]ca2902e92013-03-28 01:45:352449class OcclusionTrackerTestPerspectiveTransform
2450 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492451 protected:
[email protected]ca2902e92013-03-28 01:45:352452 explicit OcclusionTrackerTestPerspectiveTransform(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492453 : OcclusionTrackerTest<Types>(opaque_layers) {}
2454 void RunMyTest() {
2455 gfx::Transform transform;
2456 transform.Translate(150.0, 150.0);
2457 transform.ApplyPerspectiveDepth(400.0);
2458 transform.RotateAboutXAxis(-30.0);
2459 transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:142460
[email protected]a27cbde2013-03-23 22:01:492461 typename Types::ContentLayerType* parent = this->CreateRoot(
2462 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2463 typename Types::LayerType* container = this->CreateLayer(
2464 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2465 typename Types::ContentLayerType* layer =
2466 this->CreateDrawingLayer(container,
2467 transform,
2468 gfx::PointF(100.f, 100.f),
2469 gfx::Size(200, 200),
2470 true);
2471 container->SetPreserves3d(true);
2472 layer->SetPreserves3d(true);
2473 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142474
[email protected]a27cbde2013-03-23 22:01:492475 TestOcclusionTrackerWithClip<typename Types::LayerType,
2476 typename Types::RenderSurfaceType> occlusion(
2477 gfx::Rect(0, 0, 1000, 1000));
[email protected]2ea5e6c2013-04-26 21:52:232478 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142479
[email protected]a27cbde2013-03-23 22:01:492480 EXPECT_RECT_EQ(
2481 gfx::Rect(0, 0, 200, 200),
2482 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
2483 }
[email protected]94f206c12012-08-25 00:09:142484};
2485
[email protected]a27cbde2013-03-23 22:01:492486// This test requires accumulating occlusion of 3d layers, which are skipped by
2487// the occlusion tracker on the main thread. So this test should run on the impl
2488// thread.
[email protected]96baf3e2012-10-22 23:09:552489IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransform);
[email protected]94f206c12012-08-25 00:09:142490
[email protected]a27cbde2013-03-23 22:01:492491template <class Types>
[email protected]ca2902e92013-03-28 01:45:352492class OcclusionTrackerTestPerspectiveTransformBehindCamera
2493 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492494 protected:
[email protected]ca2902e92013-03-28 01:45:352495 explicit OcclusionTrackerTestPerspectiveTransformBehindCamera(
2496 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492497 : OcclusionTrackerTest<Types>(opaque_layers) {}
2498 void RunMyTest() {
2499 // This test is based on the platform/chromium/compositing/3d-corners.html
2500 // layout test.
2501 gfx::Transform transform;
2502 transform.Translate(250.0, 50.0);
2503 transform.ApplyPerspectiveDepth(10.0);
2504 transform.Translate(-250.0, -50.0);
2505 transform.Translate(250.0, 50.0);
2506 transform.RotateAboutXAxis(-167.0);
2507 transform.Translate(-250.0, -50.0);
[email protected]94f206c12012-08-25 00:09:142508
[email protected]a27cbde2013-03-23 22:01:492509 typename Types::ContentLayerType* parent = this->CreateRoot(
2510 this->identity_matrix, gfx::PointF(), gfx::Size(500, 100));
2511 typename Types::LayerType* container = this->CreateLayer(
2512 parent, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
2513 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
2514 container, transform, gfx::PointF(), gfx::Size(500, 500), true);
2515 container->SetPreserves3d(true);
2516 layer->SetPreserves3d(true);
2517 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142518
[email protected]a27cbde2013-03-23 22:01:492519 TestOcclusionTrackerWithClip<typename Types::LayerType,
2520 typename Types::RenderSurfaceType> occlusion(
2521 gfx::Rect(0, 0, 1000, 1000));
[email protected]2ea5e6c2013-04-26 21:52:232522 this->EnterLayer(layer, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142523
[email protected]a27cbde2013-03-23 22:01:492524 // The bottom 11 pixel rows of this layer remain visible inside the
2525 // container, after translation to the target surface. When translated back,
2526 // this will include many more pixels but must include at least the bottom
2527 // 11 rows.
2528 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
2529 layer, gfx::Rect(0, 0, 500, 500)).Contains(gfx::Rect(0, 489, 500, 11)));
2530 }
[email protected]94f206c12012-08-25 00:09:142531};
2532
[email protected]a27cbde2013-03-23 22:01:492533// This test requires accumulating occlusion of 3d layers, which are skipped by
2534// the occlusion tracker on the main thread. So this test should run on the impl
2535// thread.
[email protected]96baf3e2012-10-22 23:09:552536IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransformBehindCamera);
[email protected]94f206c12012-08-25 00:09:142537
[email protected]a27cbde2013-03-23 22:01:492538template <class Types>
[email protected]ca2902e92013-03-28 01:45:352539class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude
2540 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492541 protected:
[email protected]ca2902e92013-03-28 01:45:352542 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(
2543 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492544 : OcclusionTrackerTest<Types>(opaque_layers) {}
2545 void RunMyTest() {
2546 gfx::Transform transform;
2547 transform.Translate(50.0, 50.0);
2548 transform.ApplyPerspectiveDepth(100.0);
2549 transform.Translate3d(0.0, 0.0, 110.0);
2550 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:142551
[email protected]a27cbde2013-03-23 22:01:492552 typename Types::ContentLayerType* parent = this->CreateRoot(
2553 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
2554 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
2555 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
2556 parent->SetPreserves3d(true);
2557 layer->SetPreserves3d(true);
2558 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142559
[email protected]a27cbde2013-03-23 22:01:492560 TestOcclusionTrackerWithClip<typename Types::LayerType,
2561 typename Types::RenderSurfaceType> occlusion(
2562 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142563
[email protected]a27cbde2013-03-23 22:01:492564 // The |layer| is entirely behind the camera and should not occlude.
[email protected]d002dd02013-03-27 07:40:402565 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232566 this->EnterLayer(parent, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492567 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
2568 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
2569 }
[email protected]94f206c12012-08-25 00:09:142570};
2571
[email protected]a27cbde2013-03-23 22:01:492572// This test requires accumulating occlusion of 3d layers, which are skipped by
2573// the occlusion tracker on the main thread. So this test should run on the impl
2574// thread.
[email protected]96baf3e2012-10-22 23:09:552575IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude);
[email protected]94f206c12012-08-25 00:09:142576
[email protected]a27cbde2013-03-23 22:01:492577template <class Types>
[email protected]ca2902e92013-03-28 01:45:352578class OcclusionTrackerTestLargePixelsOccludeInsideClipRect
2579 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492580 protected:
[email protected]ca2902e92013-03-28 01:45:352581 explicit OcclusionTrackerTestLargePixelsOccludeInsideClipRect(
2582 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492583 : OcclusionTrackerTest<Types>(opaque_layers) {}
2584 void RunMyTest() {
2585 gfx::Transform transform;
2586 transform.Translate(50.0, 50.0);
2587 transform.ApplyPerspectiveDepth(100.0);
2588 transform.Translate3d(0.0, 0.0, 99.0);
2589 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:142590
[email protected]a27cbde2013-03-23 22:01:492591 typename Types::ContentLayerType* parent = this->CreateRoot(
2592 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
2593 parent->SetMasksToBounds(true);
2594 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
2595 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
2596 parent->SetPreserves3d(true);
2597 layer->SetPreserves3d(true);
2598 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142599
[email protected]a27cbde2013-03-23 22:01:492600 TestOcclusionTrackerWithClip<typename Types::LayerType,
2601 typename Types::RenderSurfaceType> occlusion(
2602 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142603
[email protected]a27cbde2013-03-23 22:01:492604 // This is very close to the camera, so pixels in its visible_content_rect()
2605 // will actually go outside of the layer's clip rect. Ensure that those
2606 // pixels don't occlude things outside the clip rect.
[email protected]d002dd02013-03-27 07:40:402607 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232608 this->EnterLayer(parent, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492609 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2610 occlusion.occlusion_from_inside_target().ToString());
2611 EXPECT_EQ(gfx::Rect().ToString(),
2612 occlusion.occlusion_from_outside_target().ToString());
2613 }
[email protected]94f206c12012-08-25 00:09:142614};
2615
[email protected]a27cbde2013-03-23 22:01:492616// This test requires accumulating occlusion of 3d layers, which are skipped by
2617// the occlusion tracker on the main thread. So this test should run on the impl
2618// thread.
[email protected]96baf3e2012-10-22 23:09:552619IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect);
[email protected]94f206c12012-08-25 00:09:142620
[email protected]a27cbde2013-03-23 22:01:492621template <class Types>
[email protected]ca2902e92013-03-28 01:45:352622class OcclusionTrackerTestAnimationOpacity1OnMainThread
2623 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492624 protected:
[email protected]ca2902e92013-03-28 01:45:352625 explicit OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492626 : OcclusionTrackerTest<Types>(opaque_layers) {}
2627 void RunMyTest() {
2628 // parent
2629 // +--layer
2630 // +--surface
2631 // | +--surface_child
2632 // | +--surface_child2
2633 // +--parent2
2634 // +--topmost
[email protected]c8d71552013-01-22 03:43:022635
[email protected]a27cbde2013-03-23 22:01:492636 typename Types::ContentLayerType* parent = this->CreateRoot(
2637 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2638 typename Types::ContentLayerType* layer =
2639 this->CreateDrawingLayer(parent,
2640 this->identity_matrix,
2641 gfx::PointF(),
2642 gfx::Size(300, 300),
2643 true);
2644 typename Types::ContentLayerType* surface =
2645 this->CreateDrawingSurface(parent,
2646 this->identity_matrix,
2647 gfx::PointF(),
2648 gfx::Size(300, 300),
2649 true);
2650 typename Types::ContentLayerType* surface_child =
2651 this->CreateDrawingLayer(surface,
2652 this->identity_matrix,
2653 gfx::PointF(),
2654 gfx::Size(200, 300),
2655 true);
2656 typename Types::ContentLayerType* surface_child2 =
2657 this->CreateDrawingLayer(surface,
2658 this->identity_matrix,
2659 gfx::PointF(),
2660 gfx::Size(100, 300),
2661 true);
2662 typename Types::ContentLayerType* parent2 =
2663 this->CreateDrawingLayer(parent,
2664 this->identity_matrix,
2665 gfx::PointF(),
2666 gfx::Size(300, 300),
2667 false);
2668 typename Types::ContentLayerType* topmost =
2669 this->CreateDrawingLayer(parent,
2670 this->identity_matrix,
2671 gfx::PointF(250.f, 0.f),
2672 gfx::Size(50, 300),
2673 true);
[email protected]94f206c12012-08-25 00:09:142674
[email protected]a27cbde2013-03-23 22:01:492675 AddOpacityTransitionToController(
2676 layer->layer_animation_controller(), 10.0, 0.f, 1.f, false);
2677 AddOpacityTransitionToController(
2678 surface->layer_animation_controller(), 10.0, 0.f, 1.f, false);
2679 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142680
[email protected]a27cbde2013-03-23 22:01:492681 EXPECT_TRUE(layer->draw_opacity_is_animating());
2682 EXPECT_FALSE(surface->draw_opacity_is_animating());
2683 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:142684
[email protected]a27cbde2013-03-23 22:01:492685 TestOcclusionTrackerWithClip<typename Types::LayerType,
2686 typename Types::RenderSurfaceType> occlusion(
2687 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142688
[email protected]d002dd02013-03-27 07:40:402689 this->VisitLayer(topmost, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232690 this->EnterLayer(parent2, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492691 // This occlusion will affect all surfaces.
2692 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2693 occlusion.occlusion_from_inside_target().ToString());
2694 EXPECT_EQ(gfx::Rect().ToString(),
2695 occlusion.occlusion_from_outside_target().ToString());
2696 EXPECT_EQ(gfx::Rect(0, 0, 250, 300).ToString(),
2697 occlusion.UnoccludedLayerContentRect(
2698 parent2, gfx::Rect(0, 0, 300, 300)).ToString());
[email protected]d002dd02013-03-27 07:40:402699 this->LeaveLayer(parent2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142700
[email protected]d002dd02013-03-27 07:40:402701 this->VisitLayer(surface_child2, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232702 this->EnterLayer(surface_child, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492703 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2704 occlusion.occlusion_from_inside_target().ToString());
2705 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2706 occlusion.occlusion_from_outside_target().ToString());
2707 EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300),
2708 occlusion.UnoccludedLayerContentRect(
2709 surface_child, gfx::Rect(0, 0, 200, 300)));
[email protected]d002dd02013-03-27 07:40:402710 this->LeaveLayer(surface_child, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232711 this->EnterLayer(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492712 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
2713 occlusion.occlusion_from_inside_target().ToString());
2714 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2715 occlusion.occlusion_from_outside_target().ToString());
2716 EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300),
2717 occlusion.UnoccludedLayerContentRect(
2718 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402719 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142720
[email protected]2ea5e6c2013-04-26 21:52:232721 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492722 // Occlusion within the surface is lost when leaving the animating surface.
2723 EXPECT_EQ(gfx::Rect().ToString(),
2724 occlusion.occlusion_from_inside_target().ToString());
2725 EXPECT_EQ(gfx::Rect().ToString(),
2726 occlusion.occlusion_from_outside_target().ToString());
2727 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2728 occlusion.UnoccludedContributingSurfaceContentRect(
2729 surface, false, gfx::Rect(0, 0, 300, 300), NULL));
[email protected]d002dd02013-03-27 07:40:402730 this->LeaveContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142731
[email protected]a27cbde2013-03-23 22:01:492732 // Occlusion from outside the animating surface still exists.
2733 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2734 occlusion.occlusion_from_inside_target().ToString());
2735 EXPECT_EQ(gfx::Rect().ToString(),
2736 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:022737
[email protected]d002dd02013-03-27 07:40:402738 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232739 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142740
[email protected]a27cbde2013-03-23 22:01:492741 // Occlusion is not added for the animating |layer|.
2742 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2743 occlusion.UnoccludedLayerContentRect(
2744 parent, gfx::Rect(0, 0, 300, 300)));
2745 }
[email protected]94f206c12012-08-25 00:09:142746};
2747
[email protected]96baf3e2012-10-22 23:09:552748MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread);
[email protected]94f206c12012-08-25 00:09:142749
[email protected]a27cbde2013-03-23 22:01:492750template <class Types>
[email protected]ca2902e92013-03-28 01:45:352751class OcclusionTrackerTestAnimationOpacity0OnMainThread
2752 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492753 protected:
[email protected]ca2902e92013-03-28 01:45:352754 explicit OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492755 : OcclusionTrackerTest<Types>(opaque_layers) {}
2756 void RunMyTest() {
2757 typename Types::ContentLayerType* parent = this->CreateRoot(
2758 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2759 typename Types::ContentLayerType* layer =
2760 this->CreateDrawingLayer(parent,
2761 this->identity_matrix,
2762 gfx::PointF(),
2763 gfx::Size(300, 300),
2764 true);
2765 typename Types::ContentLayerType* surface =
2766 this->CreateDrawingSurface(parent,
2767 this->identity_matrix,
2768 gfx::PointF(),
2769 gfx::Size(300, 300),
2770 true);
2771 typename Types::ContentLayerType* surface_child =
2772 this->CreateDrawingLayer(surface,
2773 this->identity_matrix,
2774 gfx::PointF(),
2775 gfx::Size(200, 300),
2776 true);
2777 typename Types::ContentLayerType* surface_child2 =
2778 this->CreateDrawingLayer(surface,
2779 this->identity_matrix,
2780 gfx::PointF(),
2781 gfx::Size(100, 300),
2782 true);
2783 typename Types::ContentLayerType* parent2 =
2784 this->CreateDrawingLayer(parent,
2785 this->identity_matrix,
2786 gfx::PointF(),
2787 gfx::Size(300, 300),
2788 false);
2789 typename Types::ContentLayerType* topmost =
2790 this->CreateDrawingLayer(parent,
2791 this->identity_matrix,
2792 gfx::PointF(250.f, 0.f),
2793 gfx::Size(50, 300),
2794 true);
[email protected]94f206c12012-08-25 00:09:142795
[email protected]a27cbde2013-03-23 22:01:492796 AddOpacityTransitionToController(
2797 layer->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2798 AddOpacityTransitionToController(
2799 surface->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2800 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142801
[email protected]a27cbde2013-03-23 22:01:492802 EXPECT_TRUE(layer->draw_opacity_is_animating());
2803 EXPECT_FALSE(surface->draw_opacity_is_animating());
2804 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:142805
[email protected]a27cbde2013-03-23 22:01:492806 TestOcclusionTrackerWithClip<typename Types::LayerType,
2807 typename Types::RenderSurfaceType> occlusion(
2808 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142809
[email protected]d002dd02013-03-27 07:40:402810 this->VisitLayer(topmost, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232811 this->EnterLayer(parent2, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492812 // This occlusion will affect all surfaces.
2813 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2814 occlusion.occlusion_from_inside_target().ToString());
2815 EXPECT_EQ(gfx::Rect().ToString(),
2816 occlusion.occlusion_from_outside_target().ToString());
2817 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2818 occlusion.UnoccludedLayerContentRect(
2819 parent, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402820 this->LeaveLayer(parent2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142821
[email protected]d002dd02013-03-27 07:40:402822 this->VisitLayer(surface_child2, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232823 this->EnterLayer(surface_child, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492824 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2825 occlusion.occlusion_from_inside_target().ToString());
2826 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2827 occlusion.occlusion_from_outside_target().ToString());
2828 EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300),
2829 occlusion.UnoccludedLayerContentRect(
2830 surface_child, gfx::Rect(0, 0, 200, 300)));
[email protected]d002dd02013-03-27 07:40:402831 this->LeaveLayer(surface_child, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232832 this->EnterLayer(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492833 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
2834 occlusion.occlusion_from_inside_target().ToString());
2835 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2836 occlusion.occlusion_from_outside_target().ToString());
2837 EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300),
2838 occlusion.UnoccludedLayerContentRect(
2839 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402840 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142841
[email protected]2ea5e6c2013-04-26 21:52:232842 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492843 // Occlusion within the surface is lost when leaving the animating surface.
2844 EXPECT_EQ(gfx::Rect().ToString(),
2845 occlusion.occlusion_from_inside_target().ToString());
2846 EXPECT_EQ(gfx::Rect().ToString(),
2847 occlusion.occlusion_from_outside_target().ToString());
2848 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2849 occlusion.UnoccludedContributingSurfaceContentRect(
2850 surface, false, gfx::Rect(0, 0, 300, 300), NULL));
[email protected]d002dd02013-03-27 07:40:402851 this->LeaveContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142852
[email protected]a27cbde2013-03-23 22:01:492853 // Occlusion from outside the animating surface still exists.
2854 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2855 occlusion.occlusion_from_inside_target().ToString());
2856 EXPECT_EQ(gfx::Rect().ToString(),
2857 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:022858
[email protected]d002dd02013-03-27 07:40:402859 this->VisitLayer(layer, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232860 this->EnterLayer(parent, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142861
[email protected]a27cbde2013-03-23 22:01:492862 // Occlusion is not added for the animating |layer|.
2863 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2864 occlusion.UnoccludedLayerContentRect(
2865 parent, gfx::Rect(0, 0, 300, 300)));
2866 }
[email protected]94f206c12012-08-25 00:09:142867};
2868
[email protected]96baf3e2012-10-22 23:09:552869MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread);
[email protected]94f206c12012-08-25 00:09:142870
[email protected]a27cbde2013-03-23 22:01:492871template <class Types>
[email protected]ca2902e92013-03-28 01:45:352872class OcclusionTrackerTestAnimationTranslateOnMainThread
2873 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492874 protected:
[email protected]ca2902e92013-03-28 01:45:352875 explicit OcclusionTrackerTestAnimationTranslateOnMainThread(
2876 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492877 : OcclusionTrackerTest<Types>(opaque_layers) {}
2878 void RunMyTest() {
2879 typename Types::ContentLayerType* parent = this->CreateRoot(
2880 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2881 typename Types::ContentLayerType* layer =
2882 this->CreateDrawingLayer(parent,
2883 this->identity_matrix,
2884 gfx::PointF(),
2885 gfx::Size(300, 300),
2886 true);
2887 typename Types::ContentLayerType* surface =
2888 this->CreateDrawingSurface(parent,
2889 this->identity_matrix,
2890 gfx::PointF(),
2891 gfx::Size(300, 300),
2892 true);
2893 typename Types::ContentLayerType* surface_child =
2894 this->CreateDrawingLayer(surface,
2895 this->identity_matrix,
2896 gfx::PointF(),
2897 gfx::Size(200, 300),
2898 true);
2899 typename Types::ContentLayerType* surface_child2 =
2900 this->CreateDrawingLayer(surface,
2901 this->identity_matrix,
2902 gfx::PointF(),
2903 gfx::Size(100, 300),
2904 true);
2905 typename Types::ContentLayerType* surface2 = this->CreateDrawingSurface(
2906 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 300), true);
[email protected]94f206c12012-08-25 00:09:142907
[email protected]a27cbde2013-03-23 22:01:492908 AddAnimatedTransformToController(
2909 layer->layer_animation_controller(), 10.0, 30, 0);
2910 AddAnimatedTransformToController(
2911 surface->layer_animation_controller(), 10.0, 30, 0);
2912 AddAnimatedTransformToController(
2913 surface_child->layer_animation_controller(), 10.0, 30, 0);
2914 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142915
[email protected]a27cbde2013-03-23 22:01:492916 EXPECT_TRUE(layer->draw_transform_is_animating());
2917 EXPECT_TRUE(layer->screen_space_transform_is_animating());
2918 EXPECT_TRUE(
2919 surface->render_surface()->target_surface_transforms_are_animating());
2920 EXPECT_TRUE(
2921 surface->render_surface()->screen_space_transforms_are_animating());
2922 // The surface owning layer doesn't animate against its own surface.
2923 EXPECT_FALSE(surface->draw_transform_is_animating());
2924 EXPECT_TRUE(surface->screen_space_transform_is_animating());
2925 EXPECT_TRUE(surface_child->draw_transform_is_animating());
2926 EXPECT_TRUE(surface_child->screen_space_transform_is_animating());
[email protected]94f206c12012-08-25 00:09:142927
[email protected]a27cbde2013-03-23 22:01:492928 TestOcclusionTrackerWithClip<typename Types::LayerType,
2929 typename Types::RenderSurfaceType> occlusion(
2930 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142931
[email protected]d002dd02013-03-27 07:40:402932 this->VisitLayer(surface2, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232933 this->EnterContributingSurface(surface2, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142934
[email protected]a27cbde2013-03-23 22:01:492935 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
2936 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142937
[email protected]d002dd02013-03-27 07:40:402938 this->LeaveContributingSurface(surface2, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232939 this->EnterLayer(surface_child2, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:142940
[email protected]a27cbde2013-03-23 22:01:492941 // surface_child2 is moving in screen space but not relative to its target,
2942 // so occlusion should happen in its target space only. It also means that
2943 // things occluding from outside the target (e.g. surface2) cannot occlude
2944 // this layer.
2945 EXPECT_EQ(gfx::Rect().ToString(),
2946 occlusion.occlusion_from_outside_target().ToString());
[email protected]ccb1c9a2012-12-17 03:53:192947
[email protected]a27cbde2013-03-23 22:01:492948 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 300),
2949 occlusion.UnoccludedLayerContentRect(
2950 surface_child2, gfx::Rect(0, 0, 100, 300)));
2951 EXPECT_FALSE(
2952 occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 50, 300)));
[email protected]94f206c12012-08-25 00:09:142953
[email protected]d002dd02013-03-27 07:40:402954 this->LeaveLayer(surface_child2, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232955 this->EnterLayer(surface_child, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492956 EXPECT_FALSE(
2957 occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 100, 300)));
2958 EXPECT_EQ(gfx::Rect().ToString(),
2959 occlusion.occlusion_from_outside_target().ToString());
2960 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2961 occlusion.occlusion_from_inside_target().ToString());
2962 EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300),
2963 occlusion.UnoccludedLayerContentRect(
2964 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142965
[email protected]a27cbde2013-03-23 22:01:492966 // The surface_child is occluded by the surface_child2, but is moving
2967 // relative its target, so it can't be occluded.
2968 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 300),
2969 occlusion.UnoccludedLayerContentRect(
2970 surface_child, gfx::Rect(0, 0, 200, 300)));
2971 EXPECT_FALSE(
2972 occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 50, 300)));
[email protected]94f206c12012-08-25 00:09:142973
[email protected]d002dd02013-03-27 07:40:402974 this->LeaveLayer(surface_child, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:232975 this->EnterLayer(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492976 // The surface_child is moving in screen space but not relative to its
2977 // target, so occlusion should happen from within the target only.
2978 EXPECT_EQ(gfx::Rect().ToString(),
2979 occlusion.occlusion_from_outside_target().ToString());
2980 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2981 occlusion.occlusion_from_inside_target().ToString());
2982 EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300),
2983 occlusion.UnoccludedLayerContentRect(
2984 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142985
[email protected]d002dd02013-03-27 07:40:402986 this->LeaveLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492987 // The surface's owning layer is moving in screen space but not relative to
2988 // its target, so occlusion should happen within the target only.
2989 EXPECT_EQ(gfx::Rect().ToString(),
2990 occlusion.occlusion_from_outside_target().ToString());
2991 EXPECT_EQ(gfx::Rect(0, 0, 300, 300).ToString(),
2992 occlusion.occlusion_from_inside_target().ToString());
2993 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2994 occlusion.UnoccludedLayerContentRect(
2995 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142996
[email protected]2ea5e6c2013-04-26 21:52:232997 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:492998 // The contributing |surface| is animating so it can't be occluded.
2999 EXPECT_RECT_EQ(gfx::Rect(0, 0, 300, 300),
3000 occlusion.UnoccludedContributingSurfaceContentRect(
3001 surface, false, gfx::Rect(0, 0, 300, 300), NULL));
[email protected]d002dd02013-03-27 07:40:403002 this->LeaveContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143003
[email protected]2ea5e6c2013-04-26 21:52:233004 this->EnterLayer(layer, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:493005 // The |surface| is moving in the screen and in its target, so all occlusion
3006 // within the surface is lost when leaving it.
3007 EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300),
3008 occlusion.UnoccludedLayerContentRect(
3009 parent, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:403010 this->LeaveLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:143011
[email protected]2ea5e6c2013-04-26 21:52:233012 this->EnterLayer(parent, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:493013 // The |layer| is animating in the screen and in its target, so no occlusion
3014 // is added.
3015 EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300),
3016 occlusion.UnoccludedLayerContentRect(
3017 parent, gfx::Rect(0, 0, 300, 300)));
3018 }
[email protected]94f206c12012-08-25 00:09:143019};
3020
[email protected]96baf3e2012-10-22 23:09:553021MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread);
[email protected]94f206c12012-08-25 00:09:143022
[email protected]a27cbde2013-03-23 22:01:493023template <class Types>
[email protected]ca2902e92013-03-28 01:45:353024class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent
3025 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493026 protected:
[email protected]ca2902e92013-03-28 01:45:353027 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(
3028 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493029 : OcclusionTrackerTest<Types>(opaque_layers) {}
3030 void RunMyTest() {
3031 gfx::Transform surface_transform;
3032 surface_transform.Translate(300.0, 300.0);
3033 surface_transform.Scale(2.0, 2.0);
3034 surface_transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:143035
[email protected]a27cbde2013-03-23 22:01:493036 typename Types::ContentLayerType* parent = this->CreateRoot(
3037 this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
3038 typename Types::ContentLayerType* surface = this->CreateDrawingSurface(
3039 parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false);
3040 typename Types::ContentLayerType* surface2 =
3041 this->CreateDrawingSurface(parent,
3042 this->identity_matrix,
3043 gfx::PointF(50.f, 50.f),
3044 gfx::Size(300, 300),
3045 false);
3046 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
3047 surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
3048 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143049
[email protected]a27cbde2013-03-23 22:01:493050 TestOcclusionTrackerWithClip<typename Types::LayerType,
3051 typename Types::RenderSurfaceType> occlusion(
3052 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143053
[email protected]d002dd02013-03-27 07:40:403054 this->VisitLayer(surface2, &occlusion);
3055 this->VisitContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:143056
[email protected]a27cbde2013-03-23 22:01:493057 EXPECT_EQ(gfx::Rect().ToString(),
3058 occlusion.occlusion_from_outside_target().ToString());
3059 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(),
3060 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143061
[email protected]a27cbde2013-03-23 22:01:493062 // Clear any stored occlusion.
3063 occlusion.set_occlusion_from_outside_target(Region());
3064 occlusion.set_occlusion_from_inside_target(Region());
[email protected]94f206c12012-08-25 00:09:143065
[email protected]d002dd02013-03-27 07:40:403066 this->VisitLayer(surface, &occlusion);
3067 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143068
[email protected]a27cbde2013-03-23 22:01:493069 EXPECT_EQ(gfx::Rect().ToString(),
3070 occlusion.occlusion_from_outside_target().ToString());
3071 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(),
3072 occlusion.occlusion_from_inside_target().ToString());
3073 }
[email protected]94f206c12012-08-25 00:09:143074};
3075
[email protected]a27cbde2013-03-23 22:01:493076MAIN_AND_IMPL_THREAD_TEST(
3077 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:143078
[email protected]a27cbde2013-03-23 22:01:493079template <class Types>
[email protected]ca2902e92013-03-28 01:45:353080class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping
3081 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493082 protected:
[email protected]ca2902e92013-03-28 01:45:353083 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(
3084 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493085 : OcclusionTrackerTest<Types>(opaque_layers) {}
3086 void RunMyTest() {
3087 typename Types::ContentLayerType* parent = this->CreateRoot(
3088 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
3089 parent->SetMasksToBounds(true);
3090 typename Types::ContentLayerType* surface =
3091 this->CreateDrawingSurface(parent,
3092 this->identity_matrix,
3093 gfx::PointF(),
3094 gfx::Size(500, 300),
3095 false);
3096 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
3097 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143098
[email protected]a27cbde2013-03-23 22:01:493099 TestOcclusionTrackerWithClip<typename Types::LayerType,
3100 typename Types::RenderSurfaceType> occlusion(
3101 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143102
[email protected]d002dd02013-03-27 07:40:403103 this->VisitLayer(surface, &occlusion);
3104 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143105
[email protected]a27cbde2013-03-23 22:01:493106 EXPECT_EQ(gfx::Rect().ToString(),
3107 occlusion.occlusion_from_outside_target().ToString());
3108 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(),
3109 occlusion.occlusion_from_inside_target().ToString());
3110 }
[email protected]94f206c12012-08-25 00:09:143111};
3112
[email protected]a27cbde2013-03-23 22:01:493113MAIN_AND_IMPL_THREAD_TEST(
3114 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:143115
[email protected]a27cbde2013-03-23 22:01:493116template <class Types>
[email protected]96baf3e2012-10-22 23:09:553117class OcclusionTrackerTestReplicaOccluded : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493118 protected:
[email protected]ca2902e92013-03-28 01:45:353119 explicit OcclusionTrackerTestReplicaOccluded(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493120 : OcclusionTrackerTest<Types>(opaque_layers) {}
3121 void RunMyTest() {
3122 typename Types::ContentLayerType* parent = this->CreateRoot(
3123 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
3124 typename Types::LayerType* surface =
3125 this->CreateDrawingSurface(parent,
3126 this->identity_matrix,
3127 gfx::PointF(),
3128 gfx::Size(100, 100),
3129 true);
3130 this->CreateReplicaLayer(surface,
3131 this->identity_matrix,
3132 gfx::PointF(0.f, 100.f),
3133 gfx::Size(100, 100));
3134 typename Types::LayerType* topmost =
3135 this->CreateDrawingLayer(parent,
3136 this->identity_matrix,
3137 gfx::PointF(0.f, 100.f),
3138 gfx::Size(100, 100),
3139 true);
3140 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143141
[email protected]a27cbde2013-03-23 22:01:493142 TestOcclusionTrackerWithClip<typename Types::LayerType,
3143 typename Types::RenderSurfaceType> occlusion(
3144 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143145
[email protected]a27cbde2013-03-23 22:01:493146 // |topmost| occludes the replica, but not the surface itself.
[email protected]d002dd02013-03-27 07:40:403147 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:143148
[email protected]a27cbde2013-03-23 22:01:493149 EXPECT_EQ(gfx::Rect().ToString(),
3150 occlusion.occlusion_from_outside_target().ToString());
3151 EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(),
3152 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143153
[email protected]d002dd02013-03-27 07:40:403154 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143155
[email protected]a27cbde2013-03-23 22:01:493156 EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(),
3157 occlusion.occlusion_from_outside_target().ToString());
3158 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
3159 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143160
[email protected]2ea5e6c2013-04-26 21:52:233161 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:143162
[email protected]a27cbde2013-03-23 22:01:493163 // Surface is not occluded so it shouldn't think it is.
3164 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3165 occlusion.UnoccludedContributingSurfaceContentRect(
3166 surface, false, gfx::Rect(0, 0, 100, 100), NULL));
3167 }
[email protected]94f206c12012-08-25 00:09:143168};
3169
[email protected]96baf3e2012-10-22 23:09:553170ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaOccluded);
[email protected]94f206c12012-08-25 00:09:143171
[email protected]a27cbde2013-03-23 22:01:493172template <class Types>
[email protected]ca2902e92013-03-28 01:45:353173class OcclusionTrackerTestSurfaceWithReplicaUnoccluded
3174 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493175 protected:
[email protected]ca2902e92013-03-28 01:45:353176 explicit OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493177 : OcclusionTrackerTest<Types>(opaque_layers) {}
3178 void RunMyTest() {
3179 typename Types::ContentLayerType* parent = this->CreateRoot(
3180 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
3181 typename Types::LayerType* surface =
3182 this->CreateDrawingSurface(parent,
3183 this->identity_matrix,
3184 gfx::PointF(),
3185 gfx::Size(100, 100),
3186 true);
3187 this->CreateReplicaLayer(surface,
3188 this->identity_matrix,
3189 gfx::PointF(0.f, 100.f),
3190 gfx::Size(100, 100));
3191 typename Types::LayerType* topmost =
3192 this->CreateDrawingLayer(parent,
3193 this->identity_matrix,
3194 gfx::PointF(),
3195 gfx::Size(100, 110),
3196 true);
3197 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143198
[email protected]a27cbde2013-03-23 22:01:493199 TestOcclusionTrackerWithClip<typename Types::LayerType,
3200 typename Types::RenderSurfaceType> occlusion(
3201 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143202
[email protected]a27cbde2013-03-23 22:01:493203 // |topmost| occludes the surface, but not the entire surface's replica.
[email protected]d002dd02013-03-27 07:40:403204 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:143205
[email protected]a27cbde2013-03-23 22:01:493206 EXPECT_EQ(gfx::Rect().ToString(),
3207 occlusion.occlusion_from_outside_target().ToString());
3208 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(),
3209 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143210
[email protected]d002dd02013-03-27 07:40:403211 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143212
[email protected]a27cbde2013-03-23 22:01:493213 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(),
3214 occlusion.occlusion_from_outside_target().ToString());
3215 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
3216 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143217
[email protected]2ea5e6c2013-04-26 21:52:233218 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:143219
[email protected]a27cbde2013-03-23 22:01:493220 // Surface is occluded, but only the top 10px of the replica.
3221 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3222 occlusion.UnoccludedContributingSurfaceContentRect(
3223 surface, false, gfx::Rect(0, 0, 100, 100), NULL));
3224 EXPECT_RECT_EQ(gfx::Rect(0, 10, 100, 90),
3225 occlusion.UnoccludedContributingSurfaceContentRect(
3226 surface, true, gfx::Rect(0, 0, 100, 100), NULL));
3227 }
[email protected]94f206c12012-08-25 00:09:143228};
3229
[email protected]96baf3e2012-10-22 23:09:553230ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded);
[email protected]94f206c12012-08-25 00:09:143231
[email protected]a27cbde2013-03-23 22:01:493232template <class Types>
[email protected]ca2902e92013-03-28 01:45:353233class OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently
3234 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493235 protected:
[email protected]ca2902e92013-03-28 01:45:353236 explicit OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently(
3237 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493238 : OcclusionTrackerTest<Types>(opaque_layers) {}
3239 void RunMyTest() {
3240 typename Types::ContentLayerType* parent = this->CreateRoot(
3241 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
3242 typename Types::LayerType* surface =
3243 this->CreateDrawingSurface(parent,
3244 this->identity_matrix,
3245 gfx::PointF(),
3246 gfx::Size(100, 100),
3247 true);
3248 this->CreateReplicaLayer(surface,
3249 this->identity_matrix,
3250 gfx::PointF(0.f, 100.f),
3251 gfx::Size(100, 100));
3252 typename Types::LayerType* over_surface = this->CreateDrawingLayer(
3253 parent, this->identity_matrix, gfx::PointF(), gfx::Size(40, 100), true);
3254 typename Types::LayerType* over_replica =
3255 this->CreateDrawingLayer(parent,
3256 this->identity_matrix,
3257 gfx::PointF(0.f, 100.f),
3258 gfx::Size(50, 100),
3259 true);
3260 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143261
[email protected]a27cbde2013-03-23 22:01:493262 TestOcclusionTrackerWithClip<typename Types::LayerType,
3263 typename Types::RenderSurfaceType> occlusion(
3264 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143265
[email protected]a27cbde2013-03-23 22:01:493266 // These occlude the surface and replica differently, so we can test each
3267 // one.
[email protected]d002dd02013-03-27 07:40:403268 this->VisitLayer(over_replica, &occlusion);
3269 this->VisitLayer(over_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143270
[email protected]a27cbde2013-03-23 22:01:493271 EXPECT_EQ(gfx::Rect().ToString(),
3272 occlusion.occlusion_from_outside_target().ToString());
3273 EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 40, 100), gfx::Rect(0, 100, 50, 100))
3274 .ToString(),
3275 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143276
[email protected]d002dd02013-03-27 07:40:403277 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143278
[email protected]a27cbde2013-03-23 22:01:493279 EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 40, 100), gfx::Rect(0, 100, 50, 100))
3280 .ToString(),
3281 occlusion.occlusion_from_outside_target().ToString());
3282 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
3283 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143284
[email protected]2ea5e6c2013-04-26 21:52:233285 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]94f206c12012-08-25 00:09:143286
[email protected]a27cbde2013-03-23 22:01:493287 // Surface and replica are occluded different amounts.
3288 EXPECT_RECT_EQ(gfx::Rect(40, 0, 60, 100),
3289 occlusion.UnoccludedContributingSurfaceContentRect(
3290 surface, false, gfx::Rect(0, 0, 100, 100), NULL));
3291 EXPECT_RECT_EQ(gfx::Rect(50, 0, 50, 100),
3292 occlusion.UnoccludedContributingSurfaceContentRect(
3293 surface, true, gfx::Rect(0, 0, 100, 100), NULL));
3294 }
[email protected]94f206c12012-08-25 00:09:143295};
3296
[email protected]a27cbde2013-03-23 22:01:493297ALL_OCCLUSIONTRACKER_TEST(
3298 OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently);
[email protected]94f206c12012-08-25 00:09:143299
[email protected]a27cbde2013-03-23 22:01:493300template <class Types>
[email protected]ca2902e92013-03-28 01:45:353301class OcclusionTrackerTestSurfaceChildOfSurface
3302 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493303 protected:
[email protected]ca2902e92013-03-28 01:45:353304 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493305 : OcclusionTrackerTest<Types>(opaque_layers) {}
3306 void RunMyTest() {
3307 // This test verifies that the surface cliprect does not end up empty and
3308 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:143309
[email protected]a27cbde2013-03-23 22:01:493310 typename Types::ContentLayerType* parent = this->CreateRoot(
3311 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
3312 typename Types::LayerType* surface =
3313 this->CreateDrawingSurface(parent,
3314 this->identity_matrix,
3315 gfx::PointF(),
3316 gfx::Size(100, 100),
3317 true);
3318 typename Types::LayerType* surface_child =
3319 this->CreateDrawingSurface(surface,
3320 this->identity_matrix,
3321 gfx::PointF(0.f, 10.f),
3322 gfx::Size(100, 50),
3323 true);
3324 typename Types::LayerType* topmost = this->CreateDrawingLayer(
3325 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
3326 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143327
[email protected]a27cbde2013-03-23 22:01:493328 TestOcclusionTrackerWithClip<typename Types::LayerType,
3329 typename Types::RenderSurfaceType> occlusion(
3330 gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143331
[email protected]a27cbde2013-03-23 22:01:493332 // |topmost| occludes everything partially so we know occlusion is happening
3333 // at all.
[email protected]d002dd02013-03-27 07:40:403334 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:143335
[email protected]a27cbde2013-03-23 22:01:493336 EXPECT_EQ(gfx::Rect().ToString(),
3337 occlusion.occlusion_from_outside_target().ToString());
3338 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
3339 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143340
[email protected]d002dd02013-03-27 07:40:403341 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:143342
[email protected]a27cbde2013-03-23 22:01:493343 // surface_child increases the occlusion in the screen by a narrow sliver.
3344 EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(),
3345 occlusion.occlusion_from_outside_target().ToString());
3346 // In its own surface, surface_child is at 0,0 as is its occlusion.
3347 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
3348 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143349
[email protected]a27cbde2013-03-23 22:01:493350 // The root layer always has a clip rect. So the parent of |surface| has a
3351 // clip rect. However, the owning layer for |surface| does not mask to
3352 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
3353 // |surface_child| exercises different code paths as its parent does not
3354 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:143355
[email protected]2ea5e6c2013-04-26 21:52:233356 this->EnterContributingSurface(surface_child, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:493357 // The surface_child's parent does not have a clip rect as it owns a render
3358 // surface. Make sure the unoccluded rect does not get clipped away
3359 // inappropriately.
3360 EXPECT_RECT_EQ(gfx::Rect(0, 40, 100, 10),
3361 occlusion.UnoccludedContributingSurfaceContentRect(
3362 surface_child, false, gfx::Rect(0, 0, 100, 50), NULL));
[email protected]d002dd02013-03-27 07:40:403363 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:143364
[email protected]a27cbde2013-03-23 22:01:493365 // When the surface_child's occlusion is transformed up to its parent, make
3366 // sure it is not clipped away inappropriately also.
[email protected]2ea5e6c2013-04-26 21:52:233367 this->EnterLayer(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:493368 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
3369 occlusion.occlusion_from_outside_target().ToString());
3370 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(),
3371 occlusion.occlusion_from_inside_target().ToString());
[email protected]d002dd02013-03-27 07:40:403372 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143373
[email protected]2ea5e6c2013-04-26 21:52:233374 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:493375 // The surface's parent does have a clip rect as it is the root layer.
3376 EXPECT_RECT_EQ(gfx::Rect(0, 50, 100, 50),
3377 occlusion.UnoccludedContributingSurfaceContentRect(
3378 surface, false, gfx::Rect(0, 0, 100, 100), NULL));
3379 }
[email protected]94f206c12012-08-25 00:09:143380};
3381
[email protected]96baf3e2012-10-22 23:09:553382ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:143383
[email protected]a27cbde2013-03-23 22:01:493384template <class Types>
[email protected]ca2902e92013-03-28 01:45:353385class OcclusionTrackerTestTopmostSurfaceIsClippedToViewport
3386 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493387 protected:
[email protected]ca2902e92013-03-28 01:45:353388 explicit OcclusionTrackerTestTopmostSurfaceIsClippedToViewport(
3389 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493390 : OcclusionTrackerTest<Types>(opaque_layers) {}
3391 void RunMyTest() {
3392 // This test verifies that the top-most surface is considered occluded
3393 // outside of its target's clip rect and outside the viewport rect.
3394
3395 typename Types::ContentLayerType* parent = this->CreateRoot(
3396 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
3397 typename Types::LayerType* surface =
3398 this->CreateDrawingSurface(parent,
3399 this->identity_matrix,
3400 gfx::PointF(),
3401 gfx::Size(100, 300),
3402 true);
3403 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143404 {
[email protected]a27cbde2013-03-23 22:01:493405 // Make a viewport rect that is larger than the root layer.
3406 TestOcclusionTrackerWithClip<typename Types::LayerType,
3407 typename Types::RenderSurfaceType> occlusion(
3408 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143409
[email protected]d002dd02013-03-27 07:40:403410 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143411
[email protected]a27cbde2013-03-23 22:01:493412 // The root layer always has a clip rect. So the parent of |surface| has a
3413 // clip rect giving the surface itself a clip rect.
[email protected]2ea5e6c2013-04-26 21:52:233414 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:493415 // Make sure the parent's clip rect clips the unoccluded region of the
3416 // child surface.
3417 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 200),
3418 occlusion.UnoccludedContributingSurfaceContentRect(
3419 surface, false, gfx::Rect(0, 0, 100, 300), NULL));
[email protected]94f206c12012-08-25 00:09:143420 }
[email protected]a27cbde2013-03-23 22:01:493421 this->ResetLayerIterator();
3422 {
3423 // Make a viewport rect that is smaller than the root layer.
3424 TestOcclusionTrackerWithClip<typename Types::LayerType,
3425 typename Types::RenderSurfaceType> occlusion(
3426 gfx::Rect(0, 0, 100, 100));
3427
[email protected]d002dd02013-03-27 07:40:403428 this->VisitLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:493429
3430 // The root layer always has a clip rect. So the parent of |surface| has a
3431 // clip rect giving the surface itself a clip rect.
[email protected]2ea5e6c2013-04-26 21:52:233432 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:493433 // Make sure the viewport rect clips the unoccluded region of the child
3434 // surface.
3435 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3436 occlusion.UnoccludedContributingSurfaceContentRect(
3437 surface, false, gfx::Rect(0, 0, 100, 300), NULL));
3438 }
3439 }
[email protected]94f206c12012-08-25 00:09:143440};
3441
[email protected]a27cbde2013-03-23 22:01:493442ALL_OCCLUSIONTRACKER_TEST(
3443 OcclusionTrackerTestTopmostSurfaceIsClippedToViewport);
[email protected]94f206c12012-08-25 00:09:143444
[email protected]a27cbde2013-03-23 22:01:493445template <class Types>
[email protected]ca2902e92013-03-28 01:45:353446class OcclusionTrackerTestSurfaceChildOfClippingSurface
3447 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493448 protected:
[email protected]ca2902e92013-03-28 01:45:353449 explicit OcclusionTrackerTestSurfaceChildOfClippingSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493450 : OcclusionTrackerTest<Types>(opaque_layers) {}
3451 void RunMyTest() {
3452 // This test verifies that the surface cliprect does not end up empty and
3453 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:143454
[email protected]a27cbde2013-03-23 22:01:493455 typename Types::ContentLayerType* parent = this->CreateRoot(
3456 this->identity_matrix, gfx::PointF(), gfx::Size(80, 200));
3457 parent->SetMasksToBounds(true);
3458 typename Types::LayerType* surface =
3459 this->CreateDrawingSurface(parent,
3460 this->identity_matrix,
3461 gfx::PointF(),
3462 gfx::Size(100, 100),
3463 true);
3464 typename Types::LayerType* surface_child =
3465 this->CreateDrawingSurface(surface,
3466 this->identity_matrix,
3467 gfx::PointF(),
3468 gfx::Size(100, 100),
3469 false);
3470 typename Types::LayerType* topmost = this->CreateDrawingLayer(
3471 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
3472 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143473
[email protected]a27cbde2013-03-23 22:01:493474 TestOcclusionTrackerWithClip<typename Types::LayerType,
3475 typename Types::RenderSurfaceType> occlusion(
3476 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143477
[email protected]a27cbde2013-03-23 22:01:493478 // |topmost| occludes everything partially so we know occlusion is happening
3479 // at all.
[email protected]d002dd02013-03-27 07:40:403480 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:143481
[email protected]a27cbde2013-03-23 22:01:493482 EXPECT_EQ(gfx::Rect().ToString(),
3483 occlusion.occlusion_from_outside_target().ToString());
3484 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(),
3485 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143486
[email protected]a27cbde2013-03-23 22:01:493487 // surface_child is not opaque and does not occlude, so we have a non-empty
3488 // unoccluded area on surface.
[email protected]d002dd02013-03-27 07:40:403489 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:143490
[email protected]a27cbde2013-03-23 22:01:493491 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(),
3492 occlusion.occlusion_from_outside_target().ToString());
3493 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
3494 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143495
[email protected]a27cbde2013-03-23 22:01:493496 // The root layer always has a clip rect. So the parent of |surface| has a
3497 // clip rect. However, the owning layer for |surface| does not mask to
3498 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
3499 // |surface_child| exercises different code paths as its parent does not
3500 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:143501
[email protected]2ea5e6c2013-04-26 21:52:233502 this->EnterContributingSurface(surface_child, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:493503 // The surface_child's parent does not have a clip rect as it owns a render
3504 // surface.
3505 EXPECT_EQ(
3506 gfx::Rect(0, 50, 80, 50).ToString(),
3507 occlusion.UnoccludedContributingSurfaceContentRect(
3508 surface_child, false, gfx::Rect(0, 0, 100, 100), NULL).ToString());
[email protected]d002dd02013-03-27 07:40:403509 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:143510
[email protected]d002dd02013-03-27 07:40:403511 this->VisitLayer(surface, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:233512 this->EnterContributingSurface(surface, &occlusion, false);
[email protected]a27cbde2013-03-23 22:01:493513 // The surface's parent does have a clip rect as it is the root layer.
3514 EXPECT_EQ(gfx::Rect(0, 50, 80, 50).ToString(),
3515 occlusion.UnoccludedContributingSurfaceContentRect(
3516 surface, false, gfx::Rect(0, 0, 100, 100), NULL).ToString());
3517 }
[email protected]94f206c12012-08-25 00:09:143518};
3519
[email protected]96baf3e2012-10-22 23:09:553520ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfClippingSurface);
[email protected]94f206c12012-08-25 00:09:143521
[email protected]a27cbde2013-03-23 22:01:493522template <class Types>
[email protected]ca2902e92013-03-28 01:45:353523class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter
3524 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493525 protected:
[email protected]ca2902e92013-03-28 01:45:353526 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:493527 bool opaque_layers)
3528 : OcclusionTrackerTest<Types>(opaque_layers) {}
3529 void RunMyTest() {
3530 gfx::Transform scale_by_half;
3531 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:143532
[email protected]a27cbde2013-03-23 22:01:493533 // Make a surface and its replica, each 50x50, that are completely
3534 // surrounded by opaque layers which are above them in the z-order. The
3535 // surface is scaled to test that the pixel moving is done in the target
3536 // space, where the background filter is applied, but the surface appears at
3537 // 50, 50 and the replica at 200, 50.
3538 typename Types::ContentLayerType* parent = this->CreateRoot(
3539 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
3540 typename Types::LayerType* filtered_surface =
3541 this->CreateDrawingLayer(parent,
3542 scale_by_half,
3543 gfx::PointF(50.f, 50.f),
3544 gfx::Size(100, 100),
3545 false);
3546 this->CreateReplicaLayer(filtered_surface,
3547 this->identity_matrix,
3548 gfx::PointF(300.f, 0.f),
3549 gfx::Size());
3550 typename Types::LayerType* occluding_layer1 = this->CreateDrawingLayer(
3551 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 50), true);
3552 typename Types::LayerType* occluding_layer2 =
3553 this->CreateDrawingLayer(parent,
3554 this->identity_matrix,
3555 gfx::PointF(0.f, 100.f),
3556 gfx::Size(300, 50),
3557 true);
3558 typename Types::LayerType* occluding_layer3 =
3559 this->CreateDrawingLayer(parent,
3560 this->identity_matrix,
3561 gfx::PointF(0.f, 50.f),
3562 gfx::Size(50, 50),
3563 true);
3564 typename Types::LayerType* occluding_layer4 =
3565 this->CreateDrawingLayer(parent,
3566 this->identity_matrix,
3567 gfx::PointF(100.f, 50.f),
3568 gfx::Size(100, 50),
3569 true);
3570 typename Types::LayerType* occluding_layer5 =
3571 this->CreateDrawingLayer(parent,
3572 this->identity_matrix,
3573 gfx::PointF(250.f, 50.f),
3574 gfx::Size(50, 50),
3575 true);
[email protected]94f206c12012-08-25 00:09:143576
[email protected]a27cbde2013-03-23 22:01:493577 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:293578 FilterOperations filters;
3579 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]a27cbde2013-03-23 22:01:493580 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:143581
[email protected]a27cbde2013-03-23 22:01:493582 // Save the distance of influence for the blur effect.
3583 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:293584 filters.GetOutsets(
3585 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:143586
[email protected]a27cbde2013-03-23 22:01:493587 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143588
[email protected]a27cbde2013-03-23 22:01:493589 TestOcclusionTrackerWithClip<typename Types::LayerType,
3590 typename Types::RenderSurfaceType> occlusion(
3591 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143592
[email protected]a27cbde2013-03-23 22:01:493593 // These layers occlude pixels directly beside the filtered_surface. Because
3594 // filtered surface blends pixels in a radius, it will need to see some of
[email protected]ed511b8d2013-03-25 03:29:293595 // the pixels (up to radius far) underneath the occluding layers.
[email protected]d002dd02013-03-27 07:40:403596 this->VisitLayer(occluding_layer5, &occlusion);
3597 this->VisitLayer(occluding_layer4, &occlusion);
3598 this->VisitLayer(occluding_layer3, &occlusion);
3599 this->VisitLayer(occluding_layer2, &occlusion);
3600 this->VisitLayer(occluding_layer1, &occlusion);
[email protected]94f206c12012-08-25 00:09:143601
[email protected]a27cbde2013-03-23 22:01:493602 Region expected_occlusion;
3603 expected_occlusion.Union(gfx::Rect(0, 0, 300, 50));
3604 expected_occlusion.Union(gfx::Rect(0, 50, 50, 50));
3605 expected_occlusion.Union(gfx::Rect(100, 50, 100, 50));
3606 expected_occlusion.Union(gfx::Rect(250, 50, 50, 50));
3607 expected_occlusion.Union(gfx::Rect(0, 100, 300, 50));
[email protected]ac7c7f52012-11-08 06:26:503608
[email protected]a27cbde2013-03-23 22:01:493609 EXPECT_EQ(expected_occlusion.ToString(),
3610 occlusion.occlusion_from_inside_target().ToString());
3611 EXPECT_EQ(gfx::Rect().ToString(),
3612 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143613
[email protected]d002dd02013-03-27 07:40:403614 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143615
[email protected]a27cbde2013-03-23 22:01:493616 // The filtered layer/replica does not occlude.
3617 Region expected_occlusion_outside_surface;
3618 expected_occlusion_outside_surface.Union(gfx::Rect(-50, -50, 300, 50));
3619 expected_occlusion_outside_surface.Union(gfx::Rect(-50, 0, 50, 50));
3620 expected_occlusion_outside_surface.Union(gfx::Rect(50, 0, 100, 50));
3621 expected_occlusion_outside_surface.Union(gfx::Rect(200, 0, 50, 50));
3622 expected_occlusion_outside_surface.Union(gfx::Rect(-50, 50, 300, 50));
[email protected]ccb1c9a2012-12-17 03:53:193623
[email protected]a27cbde2013-03-23 22:01:493624 EXPECT_EQ(expected_occlusion_outside_surface.ToString(),
3625 occlusion.occlusion_from_outside_target().ToString());
3626 EXPECT_EQ(gfx::Rect().ToString(),
3627 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143628
[email protected]a27cbde2013-03-23 22:01:493629 // The surface has a background blur, so it needs pixels that are currently
3630 // considered occluded in order to be drawn. So the pixels it needs should
3631 // be removed some the occluded area so that when we get to the parent they
3632 // are drawn.
[email protected]d002dd02013-03-27 07:40:403633 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143634
[email protected]2ea5e6c2013-04-26 21:52:233635 this->EnterLayer(parent, &occlusion, false);
[email protected]ac7c7f52012-11-08 06:26:503636
[email protected]a27cbde2013-03-23 22:01:493637 Region expected_blurred_occlusion;
3638 expected_blurred_occlusion.Union(gfx::Rect(0, 0, 300, 50 - outset_top));
3639 expected_blurred_occlusion.Union(gfx::Rect(
3640 0, 50 - outset_top, 50 - outset_left, 50 + outset_top + outset_bottom));
3641 expected_blurred_occlusion.Union(
3642 gfx::Rect(100 + outset_right,
3643 50 - outset_top,
3644 100 - outset_right - outset_left,
3645 50 + outset_top + outset_bottom));
3646 expected_blurred_occlusion.Union(
3647 gfx::Rect(250 + outset_right,
3648 50 - outset_top,
3649 50 - outset_right,
3650 50 + outset_top + outset_bottom));
3651 expected_blurred_occlusion.Union(
3652 gfx::Rect(0, 100 + outset_bottom, 300, 50 - outset_bottom));
[email protected]ac7c7f52012-11-08 06:26:503653
[email protected]a27cbde2013-03-23 22:01:493654 EXPECT_EQ(expected_blurred_occlusion.ToString(),
3655 occlusion.occlusion_from_inside_target().ToString());
3656 EXPECT_EQ(gfx::Rect().ToString(),
3657 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143658
[email protected]a27cbde2013-03-23 22:01:493659 gfx::Rect outset_rect;
3660 gfx::Rect test_rect;
[email protected]94f206c12012-08-25 00:09:143661
[email protected]a27cbde2013-03-23 22:01:493662 // Nothing in the blur outsets for the filtered_surface is occluded.
3663 outset_rect = gfx::Rect(50 - outset_left,
3664 50 - outset_top,
3665 50 + outset_left + outset_right,
3666 50 + outset_top + outset_bottom);
3667 test_rect = outset_rect;
3668 EXPECT_EQ(
3669 outset_rect.ToString(),
3670 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
[email protected]94f206c12012-08-25 00:09:143671
[email protected]a27cbde2013-03-23 22:01:493672 // Stuff outside the blur outsets is still occluded though.
3673 test_rect = outset_rect;
3674 test_rect.Inset(0, 0, -1, 0);
3675 EXPECT_EQ(
3676 outset_rect.ToString(),
3677 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3678 test_rect = outset_rect;
3679 test_rect.Inset(0, 0, 0, -1);
3680 EXPECT_EQ(
3681 outset_rect.ToString(),
3682 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3683 test_rect = outset_rect;
3684 test_rect.Inset(-1, 0, 0, 0);
3685 EXPECT_EQ(
3686 outset_rect.ToString(),
3687 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3688 test_rect = outset_rect;
3689 test_rect.Inset(0, -1, 0, 0);
3690 EXPECT_EQ(
3691 outset_rect.ToString(),
3692 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
[email protected]94f206c12012-08-25 00:09:143693
[email protected]a27cbde2013-03-23 22:01:493694 // Nothing in the blur outsets for the filtered_surface's replica is
3695 // occluded.
3696 outset_rect = gfx::Rect(200 - outset_left,
3697 50 - outset_top,
3698 50 + outset_left + outset_right,
3699 50 + outset_top + outset_bottom);
3700 test_rect = outset_rect;
3701 EXPECT_EQ(
3702 outset_rect.ToString(),
3703 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
[email protected]94f206c12012-08-25 00:09:143704
[email protected]a27cbde2013-03-23 22:01:493705 // Stuff outside the blur outsets is still occluded though.
3706 test_rect = outset_rect;
3707 test_rect.Inset(0, 0, -1, 0);
3708 EXPECT_EQ(
3709 outset_rect.ToString(),
3710 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3711 test_rect = outset_rect;
3712 test_rect.Inset(0, 0, 0, -1);
3713 EXPECT_EQ(
3714 outset_rect.ToString(),
3715 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3716 test_rect = outset_rect;
3717 test_rect.Inset(-1, 0, 0, 0);
3718 EXPECT_EQ(
3719 outset_rect.ToString(),
3720 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3721 test_rect = outset_rect;
3722 test_rect.Inset(0, -1, 0, 0);
3723 EXPECT_EQ(
3724 outset_rect.ToString(),
3725 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3726 }
[email protected]94f206c12012-08-25 00:09:143727};
3728
[email protected]a27cbde2013-03-23 22:01:493729ALL_OCCLUSIONTRACKER_TEST(
3730 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:143731
[email protected]a27cbde2013-03-23 22:01:493732template <class Types>
[email protected]ca2902e92013-03-28 01:45:353733class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice
3734 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493735 protected:
[email protected]ca2902e92013-03-28 01:45:353736 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(
[email protected]a27cbde2013-03-23 22:01:493737 bool opaque_layers)
3738 : OcclusionTrackerTest<Types>(opaque_layers) {}
3739 void RunMyTest() {
3740 gfx::Transform scale_by_half;
3741 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:143742
[email protected]a27cbde2013-03-23 22:01:493743 // Makes two surfaces that completely cover |parent|. The occlusion both
3744 // above and below the filters will be reduced by each of them.
3745 typename Types::ContentLayerType* root = this->CreateRoot(
3746 this->identity_matrix, gfx::PointF(), gfx::Size(75, 75));
3747 typename Types::LayerType* parent = this->CreateSurface(
3748 root, scale_by_half, gfx::PointF(), gfx::Size(150, 150));
3749 parent->SetMasksToBounds(true);
3750 typename Types::LayerType* filtered_surface1 = this->CreateDrawingLayer(
3751 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
3752 typename Types::LayerType* filtered_surface2 = this->CreateDrawingLayer(
3753 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
3754 typename Types::LayerType* occluding_layer_above =
3755 this->CreateDrawingLayer(parent,
3756 this->identity_matrix,
3757 gfx::PointF(100.f, 100.f),
3758 gfx::Size(50, 50),
3759 true);
[email protected]94f206c12012-08-25 00:09:143760
[email protected]a27cbde2013-03-23 22:01:493761 // Filters make the layers own surfaces.
[email protected]ae6b1a72013-06-25 18:49:293762 FilterOperations filters;
3763 filters.Append(FilterOperation::CreateBlurFilter(1.f));
[email protected]a27cbde2013-03-23 22:01:493764 filtered_surface1->SetBackgroundFilters(filters);
3765 filtered_surface2->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:143766
[email protected]a27cbde2013-03-23 22:01:493767 // Save the distance of influence for the blur effect.
3768 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:293769 filters.GetOutsets(
3770 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:143771
[email protected]a27cbde2013-03-23 22:01:493772 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:143773
[email protected]a27cbde2013-03-23 22:01:493774 TestOcclusionTrackerWithClip<typename Types::LayerType,
3775 typename Types::RenderSurfaceType> occlusion(
3776 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143777
[email protected]d002dd02013-03-27 07:40:403778 this->VisitLayer(occluding_layer_above, &occlusion);
[email protected]a27cbde2013-03-23 22:01:493779 EXPECT_EQ(gfx::Rect().ToString(),
3780 occlusion.occlusion_from_outside_target().ToString());
3781 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(),
3782 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143783
[email protected]d002dd02013-03-27 07:40:403784 this->VisitLayer(filtered_surface2, &occlusion);
3785 this->VisitContributingSurface(filtered_surface2, &occlusion);
3786 this->VisitLayer(filtered_surface1, &occlusion);
3787 this->VisitContributingSurface(filtered_surface1, &occlusion);
[email protected]94f206c12012-08-25 00:09:143788
[email protected]a27cbde2013-03-23 22:01:493789 // Test expectations in the target.
3790 gfx::Rect expected_occlusion =
3791 gfx::Rect(100 / 2 + outset_right * 2,
3792 100 / 2 + outset_bottom * 2,
3793 50 / 2 - (outset_left + outset_right) * 2,
3794 50 / 2 - (outset_top + outset_bottom) * 2);
3795 EXPECT_EQ(expected_occlusion.ToString(),
3796 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143797
[email protected]a27cbde2013-03-23 22:01:493798 // Test expectations in the screen are the same as in the target, as the
3799 // render surface is 1:1 with the screen.
3800 EXPECT_EQ(expected_occlusion.ToString(),
3801 occlusion.occlusion_from_outside_target().ToString());
3802 }
[email protected]94f206c12012-08-25 00:09:143803};
3804
[email protected]a27cbde2013-03-23 22:01:493805ALL_OCCLUSIONTRACKER_TEST(
3806 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:143807
[email protected]a27cbde2013-03-23 22:01:493808template <class Types>
[email protected]ca2902e92013-03-28 01:45:353809class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip
3810 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493811 protected:
[email protected]ca2902e92013-03-28 01:45:353812 explicit
[email protected]a27cbde2013-03-23 22:01:493813 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip(
3814 bool opaque_layers)
3815 : OcclusionTrackerTest<Types>(opaque_layers) {}
3816 void RunMyTest() {
3817 // Make a surface and its replica, Each 50x50, that are completely
3818 // surrounded by opaque layers which are above them in the z-order.
3819 typename Types::ContentLayerType* parent = this->CreateRoot(
3820 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
3821 // We stick the filtered surface inside a clipping surface so that we can
3822 // make sure the clip is honored when exposing pixels for
3823 // the background filter.
3824 typename Types::LayerType* clipping_surface =
3825 this->CreateDrawingSurface(parent,
3826 this->identity_matrix,
3827 gfx::PointF(),
3828 gfx::Size(300, 70),
3829 false);
3830 clipping_surface->SetMasksToBounds(true);
3831 typename Types::LayerType* filtered_surface =
3832 this->CreateDrawingLayer(clipping_surface,
3833 this->identity_matrix,
3834 gfx::PointF(50.f, 50.f),
3835 gfx::Size(50, 50),
3836 false);
3837 this->CreateReplicaLayer(filtered_surface,
3838 this->identity_matrix,
3839 gfx::PointF(150.f, 0.f),
3840 gfx::Size());
3841 typename Types::LayerType* occluding_layer1 = this->CreateDrawingLayer(
3842 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 50), true);
3843 typename Types::LayerType* occluding_layer2 =
3844 this->CreateDrawingLayer(parent,
3845 this->identity_matrix,
3846 gfx::PointF(0.f, 100.f),
3847 gfx::Size(300, 50),
3848 true);
3849 typename Types::LayerType* occluding_layer3 =
3850 this->CreateDrawingLayer(parent,
3851 this->identity_matrix,
3852 gfx::PointF(0.f, 50.f),
3853 gfx::Size(50, 50),
3854 true);
3855 typename Types::LayerType* occluding_layer4 =
3856 this->CreateDrawingLayer(parent,
3857 this->identity_matrix,
3858 gfx::PointF(100.f, 50.f),
3859 gfx::Size(100, 50),
3860 true);
3861 typename Types::LayerType* occluding_layer5 =
3862 this->CreateDrawingLayer(parent,
3863 this->identity_matrix,
3864 gfx::PointF(250.f, 50.f),
3865 gfx::Size(50, 50),
3866 true);
[email protected]94f206c12012-08-25 00:09:143867
[email protected]a27cbde2013-03-23 22:01:493868 // Filters make the layer own a surface. This filter is large enough that it
3869 // goes outside the bottom of the clipping_surface.
[email protected]ae6b1a72013-06-25 18:49:293870 FilterOperations filters;
3871 filters.Append(FilterOperation::CreateBlurFilter(12.f));
[email protected]a27cbde2013-03-23 22:01:493872 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:143873
[email protected]a27cbde2013-03-23 22:01:493874 // Save the distance of influence for the blur effect.
3875 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:293876 filters.GetOutsets(
3877 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:143878
[email protected]a27cbde2013-03-23 22:01:493879 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143880
[email protected]a27cbde2013-03-23 22:01:493881 TestOcclusionTrackerWithClip<typename Types::LayerType,
3882 typename Types::RenderSurfaceType> occlusion(
3883 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143884
[email protected]a27cbde2013-03-23 22:01:493885 // These layers occlude pixels directly beside the filtered_surface. Because
3886 // filtered surface blends pixels in a radius, it will need to see some of
[email protected]ed511b8d2013-03-25 03:29:293887 // the pixels (up to radius far) underneath the occluding layers.
[email protected]d002dd02013-03-27 07:40:403888 this->VisitLayer(occluding_layer5, &occlusion);
3889 this->VisitLayer(occluding_layer4, &occlusion);
3890 this->VisitLayer(occluding_layer3, &occlusion);
3891 this->VisitLayer(occluding_layer2, &occlusion);
3892 this->VisitLayer(occluding_layer1, &occlusion);
[email protected]94f206c12012-08-25 00:09:143893
[email protected]a27cbde2013-03-23 22:01:493894 Region expected_occlusion;
3895 expected_occlusion.Union(gfx::Rect(0, 0, 300, 50));
3896 expected_occlusion.Union(gfx::Rect(0, 50, 50, 50));
3897 expected_occlusion.Union(gfx::Rect(100, 50, 100, 50));
3898 expected_occlusion.Union(gfx::Rect(250, 50, 50, 50));
3899 expected_occlusion.Union(gfx::Rect(0, 100, 300, 50));
[email protected]ac7c7f52012-11-08 06:26:503900
[email protected]a27cbde2013-03-23 22:01:493901 EXPECT_EQ(expected_occlusion.ToString(),
3902 occlusion.occlusion_from_inside_target().ToString());
3903 EXPECT_EQ(gfx::Rect().ToString(),
3904 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143905
[email protected]a27cbde2013-03-23 22:01:493906 // Everything outside the surface/replica is occluded but the
3907 // surface/replica itself is not.
[email protected]d002dd02013-03-27 07:40:403908 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143909
[email protected]a27cbde2013-03-23 22:01:493910 // The filtered layer/replica does not occlude.
3911 Region expected_occlusion_outside_surface;
3912 expected_occlusion_outside_surface.Union(gfx::Rect(-50, -50, 300, 50));
3913 expected_occlusion_outside_surface.Union(gfx::Rect(-50, 0, 50, 50));
3914 expected_occlusion_outside_surface.Union(gfx::Rect(50, 0, 100, 50));
3915 expected_occlusion_outside_surface.Union(gfx::Rect(200, 0, 50, 50));
3916 expected_occlusion_outside_surface.Union(gfx::Rect(-50, 50, 300, 50));
[email protected]ccb1c9a2012-12-17 03:53:193917
[email protected]a27cbde2013-03-23 22:01:493918 EXPECT_EQ(expected_occlusion_outside_surface.ToString(),
3919 occlusion.occlusion_from_outside_target().ToString());
3920 EXPECT_EQ(gfx::Rect().ToString(),
3921 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143922
[email protected]a27cbde2013-03-23 22:01:493923 // The surface has a background blur, so it needs pixels that are currently
3924 // considered occluded in order to be drawn. So the pixels it needs should
3925 // be removed some the occluded area so that when we get to the parent they
3926 // are drawn.
[email protected]d002dd02013-03-27 07:40:403927 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143928
[email protected]d002dd02013-03-27 07:40:403929 this->VisitLayer(clipping_surface, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:233930 this->EnterContributingSurface(clipping_surface, &occlusion, false);
[email protected]ac7c7f52012-11-08 06:26:503931
[email protected]a27cbde2013-03-23 22:01:493932 Region expected_blurred_occlusion;
3933 expected_blurred_occlusion.Union(gfx::Rect(0, 0, 300, 50 - outset_top));
3934 expected_blurred_occlusion.Union(gfx::Rect(
3935 0, 50 - outset_top, 50 - outset_left, 20 + outset_top + outset_bottom));
3936 expected_blurred_occlusion.Union(
3937 gfx::Rect(100 + outset_right,
3938 50 - outset_top,
3939 100 - outset_right - outset_left,
3940 20 + outset_top + outset_bottom));
3941 expected_blurred_occlusion.Union(
3942 gfx::Rect(250 + outset_right,
3943 50 - outset_top,
3944 50 - outset_right,
3945 20 + outset_top + outset_bottom));
3946 expected_blurred_occlusion.Union(gfx::Rect(0, 100 + 5, 300, 50 - 5));
[email protected]ac7c7f52012-11-08 06:26:503947
[email protected]a27cbde2013-03-23 22:01:493948 EXPECT_EQ(expected_blurred_occlusion.ToString(),
3949 occlusion.occlusion_from_outside_target().ToString());
3950 EXPECT_EQ(gfx::Rect().ToString(),
3951 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143952
[email protected]a27cbde2013-03-23 22:01:493953 gfx::Rect outset_rect;
3954 gfx::Rect clipped_outset_rect;
3955 gfx::Rect test_rect;
[email protected]94f206c12012-08-25 00:09:143956
[email protected]a27cbde2013-03-23 22:01:493957 // Nothing in the (clipped) blur outsets for the filtered_surface is
3958 // occluded.
3959 outset_rect = gfx::Rect(50 - outset_left,
3960 50 - outset_top,
3961 50 + outset_left + outset_right,
3962 50 + outset_top + outset_bottom);
3963 clipped_outset_rect = outset_rect;
3964 clipped_outset_rect.Intersect(gfx::Rect(0 - outset_left,
3965 0 - outset_top,
3966 300 + outset_left + outset_right,
3967 70 + outset_top + outset_bottom));
3968 clipped_outset_rect.Intersect(gfx::Rect(0, 0, 300, 70));
3969 test_rect = outset_rect;
3970 EXPECT_RECT_EQ(
3971 clipped_outset_rect,
3972 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
[email protected]94f206c12012-08-25 00:09:143973
[email protected]a27cbde2013-03-23 22:01:493974 // Stuff outside the (clipped) blur outsets is still occluded though.
3975 test_rect = outset_rect;
3976 test_rect.Inset(0, 0, -1, 0);
3977 EXPECT_RECT_EQ(
3978 clipped_outset_rect,
3979 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
3980 test_rect = outset_rect;
3981 test_rect.Inset(0, 0, 0, -1);
3982 EXPECT_RECT_EQ(
3983 clipped_outset_rect,
3984 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
3985 test_rect = outset_rect;
3986 test_rect.Inset(-1, 0, 0, 0);
3987 EXPECT_RECT_EQ(
3988 clipped_outset_rect,
3989 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
3990 test_rect = outset_rect;
3991 test_rect.Inset(0, -1, 0, 0);
3992 EXPECT_RECT_EQ(
3993 clipped_outset_rect,
3994 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
[email protected]94f206c12012-08-25 00:09:143995
[email protected]a27cbde2013-03-23 22:01:493996 // Nothing in the (clipped) blur outsets for the filtered_surface's replica
3997 // is occluded.
3998 outset_rect = gfx::Rect(200 - outset_left,
3999 50 - outset_top,
4000 50 + outset_left + outset_right,
4001 50 + outset_top + outset_bottom);
4002 clipped_outset_rect = outset_rect;
4003 clipped_outset_rect.Intersect(gfx::Rect(0 - outset_left,
4004 0 - outset_top,
4005 300 + outset_left + outset_right,
4006 70 + outset_top + outset_bottom));
4007 clipped_outset_rect.Intersect(gfx::Rect(0, 0, 300, 70));
4008 test_rect = outset_rect;
4009 EXPECT_RECT_EQ(
4010 clipped_outset_rect,
4011 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
[email protected]94f206c12012-08-25 00:09:144012
[email protected]a27cbde2013-03-23 22:01:494013 // Stuff outside the (clipped) blur outsets is still occluded though.
4014 test_rect = outset_rect;
4015 test_rect.Inset(0, 0, -1, 0);
4016 EXPECT_RECT_EQ(
4017 clipped_outset_rect,
4018 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
4019 test_rect = outset_rect;
4020 test_rect.Inset(0, 0, 0, -1);
4021 EXPECT_RECT_EQ(
4022 clipped_outset_rect,
4023 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
4024 test_rect = outset_rect;
4025 test_rect.Inset(-1, 0, 0, 0);
4026 EXPECT_RECT_EQ(
4027 clipped_outset_rect,
4028 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
4029 test_rect = outset_rect;
4030 test_rect.Inset(0, -1, 0, 0);
4031 EXPECT_RECT_EQ(
4032 clipped_outset_rect,
4033 occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect));
4034 }
[email protected]94f206c12012-08-25 00:09:144035};
4036
[email protected]a27cbde2013-03-23 22:01:494037ALL_OCCLUSIONTRACKER_TEST(
4038 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip);
[email protected]94f206c12012-08-25 00:09:144039
[email protected]a27cbde2013-03-23 22:01:494040template <class Types>
[email protected]ca2902e92013-03-28 01:45:354041class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter
4042 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:494043 protected:
[email protected]ca2902e92013-03-28 01:45:354044 explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:494045 bool opaque_layers)
4046 : OcclusionTrackerTest<Types>(opaque_layers) {}
4047 void RunMyTest() {
4048 gfx::Transform scale_by_half;
4049 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:144050
[email protected]a27cbde2013-03-23 22:01:494051 // Make a surface and its replica, each 50x50, with a smaller 30x30 layer
4052 // centered below each. The surface is scaled to test that the pixel moving
4053 // is done in the target space, where the background filter is applied, but
4054 // the surface appears at 50, 50 and the replica at 200, 50.
4055 typename Types::ContentLayerType* parent = this->CreateRoot(
4056 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
4057 typename Types::LayerType* behind_surface_layer =
4058 this->CreateDrawingLayer(parent,
4059 this->identity_matrix,
4060 gfx::PointF(60.f, 60.f),
4061 gfx::Size(30, 30),
4062 true);
4063 typename Types::LayerType* behind_replica_layer =
4064 this->CreateDrawingLayer(parent,
4065 this->identity_matrix,
4066 gfx::PointF(210.f, 60.f),
4067 gfx::Size(30, 30),
4068 true);
4069 typename Types::LayerType* filtered_surface =
4070 this->CreateDrawingLayer(parent,
4071 scale_by_half,
4072 gfx::PointF(50.f, 50.f),
4073 gfx::Size(100, 100),
4074 false);
4075 this->CreateReplicaLayer(filtered_surface,
4076 this->identity_matrix,
4077 gfx::PointF(300.f, 0.f),
4078 gfx::Size());
[email protected]94f206c12012-08-25 00:09:144079
[email protected]a27cbde2013-03-23 22:01:494080 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:294081 FilterOperations filters;
4082 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:494083 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:144084
[email protected]a27cbde2013-03-23 22:01:494085 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:144086
[email protected]a27cbde2013-03-23 22:01:494087 TestOcclusionTrackerWithClip<typename Types::LayerType,
4088 typename Types::RenderSurfaceType> occlusion(
4089 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:144090
[email protected]a27cbde2013-03-23 22:01:494091 // The surface has a background blur, so it blurs non-opaque pixels below
4092 // it.
[email protected]d002dd02013-03-27 07:40:404093 this->VisitLayer(filtered_surface, &occlusion);
4094 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:144095
[email protected]d002dd02013-03-27 07:40:404096 this->VisitLayer(behind_replica_layer, &occlusion);
4097 this->VisitLayer(behind_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:144098
[email protected]a27cbde2013-03-23 22:01:494099 // The layers behind the surface are not blurred, and their occlusion does
4100 // not change, until we leave the surface. So it should not be modified by
4101 // the filter here.
4102 gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30);
4103 gfx::Rect occlusion_behind_replica = gfx::Rect(210, 60, 30, 30);
[email protected]94f206c12012-08-25 00:09:144104
[email protected]a27cbde2013-03-23 22:01:494105 Region expected_opaque_bounds =
4106 UnionRegions(occlusion_behind_surface, occlusion_behind_replica);
4107 EXPECT_EQ(expected_opaque_bounds.ToString(),
4108 occlusion.occlusion_from_inside_target().ToString());
[email protected]ccb1c9a2012-12-17 03:53:194109
[email protected]a27cbde2013-03-23 22:01:494110 EXPECT_EQ(gfx::Rect().ToString(),
4111 occlusion.occlusion_from_outside_target().ToString());
4112 }
[email protected]94f206c12012-08-25 00:09:144113};
4114
[email protected]a27cbde2013-03-23 22:01:494115ALL_OCCLUSIONTRACKER_TEST(
4116 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:144117
[email protected]a27cbde2013-03-23 22:01:494118template <class Types>
[email protected]ca2902e92013-03-28 01:45:354119class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded
4120 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:494121 protected:
[email protected]ca2902e92013-03-28 01:45:354122 explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(
[email protected]a27cbde2013-03-23 22:01:494123 bool opaque_layers)
4124 : OcclusionTrackerTest<Types>(opaque_layers) {}
4125 void RunMyTest() {
4126 gfx::Transform scale_by_half;
4127 scale_by_half.Scale(0.5, 0.5);
4128
4129 // Make a surface and its replica, each 50x50, that are completely occluded
4130 // by opaque layers which are above them in the z-order. The surface is
4131 // scaled to test that the pixel moving is done in the target space, where
4132 // the background filter is applied, but the surface appears at 50, 50 and
4133 // the replica at 200, 50.
4134 typename Types::ContentLayerType* parent = this->CreateRoot(
4135 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
4136 typename Types::LayerType* filtered_surface =
4137 this->CreateDrawingLayer(parent,
4138 scale_by_half,
4139 gfx::PointF(50.f, 50.f),
4140 gfx::Size(100, 100),
4141 false);
4142 this->CreateReplicaLayer(filtered_surface,
4143 this->identity_matrix,
4144 gfx::PointF(300.f, 0.f),
4145 gfx::Size());
4146 typename Types::LayerType* above_surface_layer =
4147 this->CreateDrawingLayer(parent,
4148 this->identity_matrix,
4149 gfx::PointF(50.f, 50.f),
4150 gfx::Size(50, 50),
4151 true);
4152 typename Types::LayerType* above_replica_layer =
4153 this->CreateDrawingLayer(parent,
4154 this->identity_matrix,
4155 gfx::PointF(200.f, 50.f),
4156 gfx::Size(50, 50),
4157 true);
4158
4159 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:294160 FilterOperations filters;
4161 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:494162 filtered_surface->SetBackgroundFilters(filters);
4163
4164 this->CalcDrawEtc(parent);
4165
4166 TestOcclusionTrackerWithClip<typename Types::LayerType,
4167 typename Types::RenderSurfaceType> occlusion(
4168 gfx::Rect(0, 0, 1000, 1000));
4169
[email protected]d002dd02013-03-27 07:40:404170 this->VisitLayer(above_replica_layer, &occlusion);
4171 this->VisitLayer(above_surface_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:494172
[email protected]d002dd02013-03-27 07:40:404173 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:144174 {
[email protected]a27cbde2013-03-23 22:01:494175 // The layers above the filtered surface occlude from outside.
4176 gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50);
4177 gfx::Rect occlusion_above_replica = gfx::Rect(150, 0, 50, 50);
4178 Region expected_opaque_region =
4179 UnionRegions(occlusion_above_surface, occlusion_above_replica);
[email protected]94f206c12012-08-25 00:09:144180
[email protected]a27cbde2013-03-23 22:01:494181 EXPECT_EQ(gfx::Rect().ToString(),
4182 occlusion.occlusion_from_inside_target().ToString());
4183 EXPECT_EQ(expected_opaque_region.ToString(),
4184 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:144185 }
[email protected]a27cbde2013-03-23 22:01:494186
4187 // The surface has a background blur, so it blurs non-opaque pixels below
4188 // it.
[email protected]d002dd02013-03-27 07:40:404189 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:494190 {
4191 // The filter is completely occluded, so it should not blur anything and
4192 // reduce any occlusion.
4193 gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50);
4194 gfx::Rect occlusion_above_replica = gfx::Rect(200, 50, 50, 50);
4195 Region expected_opaque_region =
4196 UnionRegions(occlusion_above_surface, occlusion_above_replica);
4197
4198 EXPECT_EQ(expected_opaque_region.ToString(),
4199 occlusion.occlusion_from_inside_target().ToString());
4200 EXPECT_EQ(gfx::Rect().ToString(),
4201 occlusion.occlusion_from_outside_target().ToString());
4202 }
4203 }
[email protected]94f206c12012-08-25 00:09:144204};
4205
[email protected]a27cbde2013-03-23 22:01:494206ALL_OCCLUSIONTRACKER_TEST(
4207 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:144208
[email protected]a27cbde2013-03-23 22:01:494209template <class Types>
[email protected]ca2902e92013-03-28 01:45:354210class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded
4211 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:494212 protected:
[email protected]ca2902e92013-03-28 01:45:354213 explicit
[email protected]a27cbde2013-03-23 22:01:494214 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded(
4215 bool opaque_layers)
4216 : OcclusionTrackerTest<Types>(opaque_layers) {}
4217 void RunMyTest() {
4218 gfx::Transform scale_by_half;
4219 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:144220
[email protected]a27cbde2013-03-23 22:01:494221 // Make a surface and its replica, each 50x50, that are partially occluded
4222 // by opaque layers which are above them in the z-order. The surface is
4223 // scaled to test that the pixel moving is done in the target space, where
4224 // the background filter is applied, but the surface appears at 50, 50 and
4225 // the replica at 200, 50.
4226 typename Types::ContentLayerType* parent = this->CreateRoot(
4227 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
4228 typename Types::LayerType* filtered_surface =
4229 this->CreateDrawingLayer(parent,
4230 scale_by_half,
4231 gfx::PointF(50.f, 50.f),
4232 gfx::Size(100, 100),
4233 false);
4234 this->CreateReplicaLayer(filtered_surface,
4235 this->identity_matrix,
4236 gfx::PointF(300.f, 0.f),
4237 gfx::Size());
4238 typename Types::LayerType* above_surface_layer =
4239 this->CreateDrawingLayer(parent,
4240 this->identity_matrix,
4241 gfx::PointF(70.f, 50.f),
4242 gfx::Size(30, 50),
4243 true);
4244 typename Types::LayerType* above_replica_layer =
4245 this->CreateDrawingLayer(parent,
4246 this->identity_matrix,
4247 gfx::PointF(200.f, 50.f),
4248 gfx::Size(30, 50),
4249 true);
4250 typename Types::LayerType* beside_surface_layer =
4251 this->CreateDrawingLayer(parent,
4252 this->identity_matrix,
4253 gfx::PointF(90.f, 40.f),
4254 gfx::Size(10, 10),
4255 true);
4256 typename Types::LayerType* beside_replica_layer =
4257 this->CreateDrawingLayer(parent,
4258 this->identity_matrix,
4259 gfx::PointF(200.f, 40.f),
4260 gfx::Size(10, 10),
4261 true);
[email protected]94f206c12012-08-25 00:09:144262
[email protected]a27cbde2013-03-23 22:01:494263 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:294264 FilterOperations filters;
4265 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:494266 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:144267
[email protected]a27cbde2013-03-23 22:01:494268 // Save the distance of influence for the blur effect.
4269 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:294270 filters.GetOutsets(
4271 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:144272
[email protected]a27cbde2013-03-23 22:01:494273 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:144274
[email protected]a27cbde2013-03-23 22:01:494275 TestOcclusionTrackerWithClip<typename Types::LayerType,
4276 typename Types::RenderSurfaceType> occlusion(
4277 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:144278
[email protected]d002dd02013-03-27 07:40:404279 this->VisitLayer(beside_replica_layer, &occlusion);
4280 this->VisitLayer(beside_surface_layer, &occlusion);
4281 this->VisitLayer(above_replica_layer, &occlusion);
4282 this->VisitLayer(above_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:144283
[email protected]a27cbde2013-03-23 22:01:494284 // The surface has a background blur, so it blurs non-opaque pixels below
4285 // it.
[email protected]d002dd02013-03-27 07:40:404286 this->VisitLayer(filtered_surface, &occlusion);
4287 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:144288
[email protected]a27cbde2013-03-23 22:01:494289 // The filter in the surface and replica are partially unoccluded. Only the
4290 // unoccluded parts should reduce occlusion. This means it will push back
[email protected]ed511b8d2013-03-25 03:29:294291 // the occlusion that touches the unoccluded part (occlusion_above___), but
[email protected]a27cbde2013-03-23 22:01:494292 // it will not touch occlusion_beside____ since that is not beside the
4293 // unoccluded part of the surface, even though it is beside the occluded
4294 // part of the surface.
4295 gfx::Rect occlusion_above_surface =
4296 gfx::Rect(70 + outset_right, 50, 30 - outset_right, 50);
4297 gfx::Rect occlusion_above_replica =
4298 gfx::Rect(200, 50, 30 - outset_left, 50);
4299 gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10);
4300 gfx::Rect occlusion_beside_replica = gfx::Rect(200, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:144301
[email protected]a27cbde2013-03-23 22:01:494302 Region expected_occlusion;
4303 expected_occlusion.Union(occlusion_above_surface);
4304 expected_occlusion.Union(occlusion_above_replica);
4305 expected_occlusion.Union(occlusion_beside_surface);
4306 expected_occlusion.Union(occlusion_beside_replica);
[email protected]94f206c12012-08-25 00:09:144307
[email protected]a27cbde2013-03-23 22:01:494308 ASSERT_EQ(expected_occlusion.ToString(),
4309 occlusion.occlusion_from_inside_target().ToString());
4310 EXPECT_EQ(gfx::Rect().ToString(),
4311 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:144312
[email protected]a27cbde2013-03-23 22:01:494313 Region::Iterator expected_rects(expected_occlusion);
4314 Region::Iterator target_surface_rects(
4315 occlusion.occlusion_from_inside_target());
4316 for (; expected_rects.has_rect();
4317 expected_rects.next(), target_surface_rects.next()) {
4318 ASSERT_TRUE(target_surface_rects.has_rect());
4319 EXPECT_EQ(expected_rects.rect(), target_surface_rects.rect());
[email protected]94f206c12012-08-25 00:09:144320 }
[email protected]a27cbde2013-03-23 22:01:494321 }
[email protected]94f206c12012-08-25 00:09:144322};
4323
[email protected]a27cbde2013-03-23 22:01:494324ALL_OCCLUSIONTRACKER_TEST(
4325 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:144326
[email protected]a27cbde2013-03-23 22:01:494327template <class Types>
[email protected]ca2902e92013-03-28 01:45:354328class OcclusionTrackerTestMinimumTrackingSize
4329 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:494330 protected:
[email protected]ca2902e92013-03-28 01:45:354331 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:494332 : OcclusionTrackerTest<Types>(opaque_layers) {}
4333 void RunMyTest() {
4334 gfx::Size tracking_size(100, 100);
4335 gfx::Size below_tracking_size(99, 99);
[email protected]94f206c12012-08-25 00:09:144336
[email protected]a27cbde2013-03-23 22:01:494337 typename Types::ContentLayerType* parent = this->CreateRoot(
4338 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
4339 typename Types::LayerType* large = this->CreateDrawingLayer(
4340 parent, this->identity_matrix, gfx::PointF(), tracking_size, true);
4341 typename Types::LayerType* small =
4342 this->CreateDrawingLayer(parent,
4343 this->identity_matrix,
4344 gfx::PointF(),
4345 below_tracking_size,
4346 true);
4347 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:144348
[email protected]a27cbde2013-03-23 22:01:494349 TestOcclusionTrackerWithClip<typename Types::LayerType,
4350 typename Types::RenderSurfaceType> occlusion(
4351 gfx::Rect(0, 0, 1000, 1000));
4352 occlusion.set_minimum_tracking_size(tracking_size);
[email protected]94f206c12012-08-25 00:09:144353
[email protected]a27cbde2013-03-23 22:01:494354 // The small layer is not tracked because it is too small.
[email protected]d002dd02013-03-27 07:40:404355 this->VisitLayer(small, &occlusion);
[email protected]94f206c12012-08-25 00:09:144356
[email protected]a27cbde2013-03-23 22:01:494357 EXPECT_EQ(gfx::Rect().ToString(),
4358 occlusion.occlusion_from_outside_target().ToString());
4359 EXPECT_EQ(gfx::Rect().ToString(),
4360 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:144361
[email protected]a27cbde2013-03-23 22:01:494362 // The large layer is tracked as it is large enough.
[email protected]d002dd02013-03-27 07:40:404363 this->VisitLayer(large, &occlusion);
[email protected]94f206c12012-08-25 00:09:144364
[email protected]a27cbde2013-03-23 22:01:494365 EXPECT_EQ(gfx::Rect().ToString(),
4366 occlusion.occlusion_from_outside_target().ToString());
[email protected]2c7c6702013-03-26 03:14:054367 EXPECT_EQ(gfx::Rect(tracking_size).ToString(),
[email protected]a27cbde2013-03-23 22:01:494368 occlusion.occlusion_from_inside_target().ToString());
4369 }
[email protected]94f206c12012-08-25 00:09:144370};
4371
[email protected]96baf3e2012-10-22 23:09:554372ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:144373
[email protected]a27cbde2013-03-23 22:01:494374template <class Types>
[email protected]ca2902e92013-03-28 01:45:354375class OcclusionTrackerTestViewportClipIsExternalOcclusion
4376 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:494377 protected:
[email protected]ca2902e92013-03-28 01:45:354378 explicit OcclusionTrackerTestViewportClipIsExternalOcclusion(
4379 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:494380 : OcclusionTrackerTest<Types>(opaque_layers) {}
4381 void RunMyTest() {
4382 typename Types::ContentLayerType* parent = this->CreateRoot(
4383 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
4384 typename Types::LayerType* small =
4385 this->CreateDrawingSurface(parent,
4386 this->identity_matrix,
4387 gfx::PointF(),
4388 gfx::Size(200, 200),
4389 false);
4390 typename Types::LayerType* large =
4391 this->CreateDrawingLayer(small,
4392 this->identity_matrix,
4393 gfx::PointF(),
4394 gfx::Size(400, 400),
4395 false);
4396 small->SetMasksToBounds(true);
4397 this->CalcDrawEtc(parent);
[email protected]bae49f2c2013-01-18 12:14:314398
[email protected]a27cbde2013-03-23 22:01:494399 TestOcclusionTrackerWithClip<typename Types::LayerType,
4400 typename Types::RenderSurfaceType> occlusion(
4401 gfx::Rect(0, 0, 100, 100));
[email protected]bae49f2c2013-01-18 12:14:314402
[email protected]2ea5e6c2013-04-26 21:52:234403 this->EnterLayer(large, &occlusion, false);
[email protected]bae49f2c2013-01-18 12:14:314404
[email protected]a27cbde2013-03-23 22:01:494405 bool has_occlusion_from_outside_target_surface = false;
4406 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
4407 occlusion.UnoccludedLayerContentRect(
4408 large,
4409 gfx::Rect(0, 0, 400, 400),
4410 &has_occlusion_from_outside_target_surface));
4411 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
[email protected]bae49f2c2013-01-18 12:14:314412
[email protected]a27cbde2013-03-23 22:01:494413 has_occlusion_from_outside_target_surface = false;
4414 EXPECT_FALSE(
4415 occlusion.OccludedLayer(large,
4416 gfx::Rect(0, 0, 400, 400),
4417 &has_occlusion_from_outside_target_surface));
4418 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
[email protected]bae49f2c2013-01-18 12:14:314419
[email protected]d002dd02013-03-27 07:40:404420 this->LeaveLayer(large, &occlusion);
4421 this->VisitLayer(small, &occlusion);
[email protected]bae49f2c2013-01-18 12:14:314422
[email protected]a27cbde2013-03-23 22:01:494423 has_occlusion_from_outside_target_surface = false;
4424 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
4425 occlusion.UnoccludedLayerContentRect(
4426 small,
4427 gfx::Rect(0, 0, 200, 200),
4428 &has_occlusion_from_outside_target_surface));
4429 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
[email protected]bae49f2c2013-01-18 12:14:314430
[email protected]a27cbde2013-03-23 22:01:494431 has_occlusion_from_outside_target_surface = false;
4432 EXPECT_FALSE(
4433 occlusion.OccludedLayer(small,
4434 gfx::Rect(0, 0, 200, 200),
4435 &has_occlusion_from_outside_target_surface));
4436 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
[email protected]bae49f2c2013-01-18 12:14:314437
[email protected]2ea5e6c2013-04-26 21:52:234438 this->EnterContributingSurface(small, &occlusion, false);
[email protected]bae49f2c2013-01-18 12:14:314439
[email protected]a27cbde2013-03-23 22:01:494440 has_occlusion_from_outside_target_surface = false;
4441 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
4442 occlusion.UnoccludedContributingSurfaceContentRect(
4443 small,
4444 false,
4445 gfx::Rect(0, 0, 200, 200),
4446 &has_occlusion_from_outside_target_surface));
4447 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
4448 }
[email protected]bae49f2c2013-01-18 12:14:314449};
4450
[email protected]a27cbde2013-03-23 22:01:494451ALL_OCCLUSIONTRACKER_TEST(
[email protected]ca2902e92013-03-28 01:45:354452 OcclusionTrackerTestViewportClipIsExternalOcclusion)
4453
4454template <class Types>
4455class OcclusionTrackerTestLayerClipIsExternalOcclusion
4456 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:494457 protected:
[email protected]ca2902e92013-03-28 01:45:354458 explicit OcclusionTrackerTestLayerClipIsExternalOcclusion(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:494459 : OcclusionTrackerTest<Types>(opaque_layers) {}
4460 void RunMyTest() {
4461 typename Types::ContentLayerType* parent = this->CreateRoot(
4462 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
4463 typename Types::LayerType* smallest = this->CreateDrawingLayer(
4464 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false);
4465 typename Types::LayerType* smaller =
4466 this->CreateDrawingSurface(smallest,
4467 this->identity_matrix,
4468 gfx::PointF(),
4469 gfx::Size(100, 100),
4470 false);
4471 typename Types::LayerType* small =
4472 this->CreateDrawingSurface(smaller,
4473 this->identity_matrix,
4474 gfx::PointF(),
4475 gfx::Size(200, 200),
4476 false);
4477 typename Types::LayerType* large =
4478 this->CreateDrawingLayer(small,
4479 this->identity_matrix,
4480 gfx::PointF(),
4481 gfx::Size(400, 400),
4482 false);
4483 smallest->SetMasksToBounds(true);
4484 smaller->SetMasksToBounds(true);
4485 small->SetMasksToBounds(true);
4486 this->CalcDrawEtc(parent);
[email protected]bae49f2c2013-01-18 12:14:314487
[email protected]a27cbde2013-03-23 22:01:494488 TestOcclusionTrackerWithClip<typename Types::LayerType,
4489 typename Types::RenderSurfaceType> occlusion(
4490 gfx::Rect(0, 0, 1000, 1000));
[email protected]bae49f2c2013-01-18 12:14:314491
[email protected]2ea5e6c2013-04-26 21:52:234492 this->EnterLayer(large, &occlusion, false);
[email protected]bae49f2c2013-01-18 12:14:314493
[email protected]a27cbde2013-03-23 22:01:494494 // Clipping from the smaller layer is from outside the target surface.
4495 bool has_occlusion_from_outside_target_surface = false;
4496 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
4497 occlusion.UnoccludedLayerContentRect(
4498 large,
4499 gfx::Rect(0, 0, 400, 400),
4500 &has_occlusion_from_outside_target_surface));
4501 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
[email protected]bae49f2c2013-01-18 12:14:314502
[email protected]a27cbde2013-03-23 22:01:494503 has_occlusion_from_outside_target_surface = false;
4504 EXPECT_FALSE(
4505 occlusion.OccludedLayer(large,
4506 gfx::Rect(0, 0, 400, 400),
4507 &has_occlusion_from_outside_target_surface));
4508 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
[email protected]bae49f2c2013-01-18 12:14:314509
[email protected]d002dd02013-03-27 07:40:404510 this->LeaveLayer(large, &occlusion);
4511 this->VisitLayer(small, &occlusion);
[email protected]bae49f2c2013-01-18 12:14:314512
[email protected]a27cbde2013-03-23 22:01:494513 // Clipping from the smaller layer is from outside the target surface.
4514 has_occlusion_from_outside_target_surface = false;
4515 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
4516 occlusion.UnoccludedLayerContentRect(
4517 small,
4518 gfx::Rect(0, 0, 200, 200),
4519 &has_occlusion_from_outside_target_surface));
4520 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
[email protected]bae49f2c2013-01-18 12:14:314521
[email protected]a27cbde2013-03-23 22:01:494522 has_occlusion_from_outside_target_surface = false;
4523 EXPECT_FALSE(
4524 occlusion.OccludedLayer(small,
4525 gfx::Rect(0, 0, 200, 200),
4526 &has_occlusion_from_outside_target_surface));
4527 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
[email protected]bae49f2c2013-01-18 12:14:314528
[email protected]2ea5e6c2013-04-26 21:52:234529 this->EnterContributingSurface(small, &occlusion, false);
[email protected]bae49f2c2013-01-18 12:14:314530
[email protected]a27cbde2013-03-23 22:01:494531 // The |small| surface is clipped from outside its target by |smallest|.
4532 has_occlusion_from_outside_target_surface = false;
4533 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50),
4534 occlusion.UnoccludedContributingSurfaceContentRect(
4535 small,
4536 false,
4537 gfx::Rect(0, 0, 200, 200),
4538 &has_occlusion_from_outside_target_surface));
4539 EXPECT_TRUE(has_occlusion_from_outside_target_surface);
[email protected]bae49f2c2013-01-18 12:14:314540
[email protected]d002dd02013-03-27 07:40:404541 this->LeaveContributingSurface(small, &occlusion);
4542 this->VisitLayer(smaller, &occlusion);
[email protected]2ea5e6c2013-04-26 21:52:234543 this->EnterContributingSurface(smaller, &occlusion, false);
[email protected]bae49f2c2013-01-18 12:14:314544
[email protected]a27cbde2013-03-23 22:01:494545 // The |smaller| surface is clipped from inside its target by |smallest|.
4546 has_occlusion_from_outside_target_surface = false;
4547 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50),
4548 occlusion.UnoccludedContributingSurfaceContentRect(
4549 smaller,
4550 false,
4551 gfx::Rect(0, 0, 100, 100),
4552 &has_occlusion_from_outside_target_surface));
4553 EXPECT_FALSE(has_occlusion_from_outside_target_surface);
4554 }
[email protected]bae49f2c2013-01-18 12:14:314555};
4556
4557ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipIsExternalOcclusion)
4558
[email protected]2ea5e6c2013-04-26 21:52:234559template <class Types>
4560class OcclusionTrackerTestPreventOcclusionOnLayer
4561 : public OcclusionTrackerTest<Types> {
4562 protected:
4563 explicit OcclusionTrackerTestPreventOcclusionOnLayer(bool opaque_layers)
4564 : OcclusionTrackerTest<Types>(opaque_layers) {}
4565 void RunMyTest() {
4566 typename Types::ContentLayerType* parent = this->CreateRoot(
4567 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
4568 typename Types::LayerType* unprevented = this->CreateDrawingLayer(
4569 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false);
4570 typename Types::LayerType* prevented = this->CreateDrawingLayer(
4571 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false);
4572 typename Types::LayerType* occluding = this->CreateDrawingLayer(
4573 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), true);
4574 this->CalcDrawEtc(parent);
4575
4576 TestOcclusionTrackerWithClip<typename Types::LayerType,
4577 typename Types::RenderSurfaceType> occlusion(
4578 gfx::Rect(0, 0, 1000, 1000));
4579 bool external_occlusion = false;
4580
4581 this->VisitLayer(occluding, &occlusion);
4582 this->EnterLayer(prevented, &occlusion, true);
4583
4584 // This layer is not occluded because it is prevented.
4585 EXPECT_FALSE(occlusion.OccludedLayer(prevented,
4586 gfx::Rect(50, 50),
4587 &external_occlusion));
4588 EXPECT_FALSE(external_occlusion);
4589
4590 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4591 occlusion.UnoccludedLayerContentRect(
4592 prevented,
4593 gfx::Rect(50, 50),
4594 &external_occlusion).ToString());
4595 EXPECT_FALSE(external_occlusion);
4596
4597 this->LeaveLayer(prevented, &occlusion);
4598 this->EnterLayer(unprevented, &occlusion, false);
4599
4600 // This layer is fully occluded.
4601 EXPECT_TRUE(occlusion.OccludedLayer(unprevented,
4602 gfx::Rect(50, 50),
4603 &external_occlusion));
4604 EXPECT_FALSE(external_occlusion);
4605
4606 EXPECT_EQ(gfx::Rect().ToString(),
4607 occlusion.UnoccludedLayerContentRect(
4608 unprevented,
4609 gfx::Rect(50, 50),
4610 &external_occlusion).ToString());
4611 EXPECT_FALSE(external_occlusion);
4612
4613 this->LeaveLayer(unprevented, &occlusion);
4614 }
4615};
4616
4617ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestPreventOcclusionOnLayer)
4618
4619template <class Types>
4620class OcclusionTrackerTestPreventOcclusionOnContributingSurface
4621 : public OcclusionTrackerTest<Types> {
4622 protected:
4623 explicit OcclusionTrackerTestPreventOcclusionOnContributingSurface(
4624 bool opaque_layers)
4625 : OcclusionTrackerTest<Types>(opaque_layers) {}
4626 void RunMyTest() {
4627 typename Types::ContentLayerType* parent = this->CreateRoot(
4628 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
4629 typename Types::LayerType* unprevented = this->CreateDrawingSurface(
4630 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false);
4631 typename Types::LayerType* prevented = this->CreateDrawingSurface(
4632 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false);
4633 typename Types::LayerType* occluding = this->CreateDrawingLayer(
4634 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), true);
4635 this->CalcDrawEtc(parent);
4636
4637 TestOcclusionTrackerWithClip<typename Types::LayerType,
4638 typename Types::RenderSurfaceType> occlusion(
4639 gfx::Rect(0, 0, 1000, 1000));
4640 bool external_occlusion = false;
4641
4642 this->VisitLayer(occluding, &occlusion);
4643 this->EnterLayer(prevented, &occlusion, true);
4644
4645 // This layer is not occluded because it is prevented.
4646 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4647 occlusion.UnoccludedLayerContentRect(
4648 prevented,
4649 gfx::Rect(50, 50),
4650 &external_occlusion).ToString());
4651 EXPECT_FALSE(external_occlusion);
4652
4653 this->LeaveLayer(prevented, &occlusion);
4654 this->EnterContributingSurface(prevented, &occlusion, true);
4655
4656 // This contributing surface is not occluded because it is prevented.
4657 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4658 occlusion.UnoccludedContributingSurfaceContentRect(
4659 prevented,
4660 false, // is_replica
4661 gfx::Rect(50, 50),
4662 &external_occlusion).ToString());
4663 EXPECT_FALSE(external_occlusion);
4664
4665 this->LeaveContributingSurface(prevented, &occlusion);
4666 this->EnterLayer(unprevented, &occlusion, false);
4667
4668 // This layer is fully occluded from outside its surface.
4669 EXPECT_EQ(gfx::Rect().ToString(),
4670 occlusion.UnoccludedLayerContentRect(
4671 unprevented,
4672 gfx::Rect(50, 50),
4673 &external_occlusion).ToString());
4674 EXPECT_TRUE(external_occlusion);
4675
4676 this->LeaveLayer(unprevented, &occlusion);
4677 this->EnterContributingSurface(unprevented, &occlusion, false);
4678
4679 // This contributing surface is fully occluded.
4680 EXPECT_EQ(gfx::Rect().ToString(),
4681 occlusion.UnoccludedContributingSurfaceContentRect(
4682 unprevented,
4683 false, // is_replica
4684 gfx::Rect(50, 50),
4685 &external_occlusion).ToString());
4686 EXPECT_FALSE(external_occlusion);
4687
4688 this->LeaveContributingSurface(unprevented, &occlusion);
4689 }
4690};
4691
4692ALL_OCCLUSIONTRACKER_TEST(
4693 OcclusionTrackerTestPreventOcclusionOnContributingSurface)
4694
4695template <class Types>
4696class OcclusionTrackerTestPreventOcclusionByClipping
4697 : public OcclusionTrackerTest<Types> {
4698 protected:
4699 explicit OcclusionTrackerTestPreventOcclusionByClipping(bool opaque_layers)
4700 : OcclusionTrackerTest<Types>(opaque_layers) {}
4701 void RunMyTest() {
4702 typename Types::ContentLayerType* parent = this->CreateRoot(
4703 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
4704 typename Types::LayerType* unprevented = this->CreateDrawingLayer(
4705 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false);
4706 typename Types::LayerType* prevented = this->CreateDrawingLayer(
4707 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false);
4708 this->CalcDrawEtc(parent);
4709
4710 TestOcclusionTrackerWithClip<typename Types::LayerType,
4711 typename Types::RenderSurfaceType> occlusion(
4712 gfx::Rect(0, 0, 10, 10));
4713 bool external_occlusion = false;
4714
4715 this->EnterLayer(prevented, &occlusion, true);
4716
4717 // This layer is not occluded because it is prevented.
4718 EXPECT_FALSE(occlusion.OccludedLayer(prevented,
4719 gfx::Rect(50, 50),
4720 &external_occlusion));
4721 EXPECT_FALSE(external_occlusion);
4722
4723 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4724 occlusion.UnoccludedLayerContentRect(
4725 prevented,
4726 gfx::Rect(50, 50),
4727 &external_occlusion).ToString());
4728 EXPECT_FALSE(external_occlusion);
4729
4730 this->LeaveLayer(prevented, &occlusion);
4731 this->EnterLayer(unprevented, &occlusion, false);
4732
4733 // This layer is clipped by the screen space clip rect.
4734 EXPECT_EQ(gfx::Rect(10, 10).ToString(),
4735 occlusion.UnoccludedLayerContentRect(
4736 unprevented,
4737 gfx::Rect(50, 50),
4738 &external_occlusion).ToString());
4739 EXPECT_TRUE(external_occlusion);
4740
4741 this->LeaveLayer(unprevented, &occlusion);
4742 }
4743};
4744
4745ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestPreventOcclusionByClipping)
4746
[email protected]1a5d9ce2013-04-30 01:31:094747template <class Types>
4748class OcclusionTrackerTestScaledLayerIsClipped
4749 : public OcclusionTrackerTest<Types> {
4750 protected:
4751 explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers)
4752 : OcclusionTrackerTest<Types>(opaque_layers) {}
4753 void RunMyTest() {
4754 gfx::Transform scale_transform;
4755 scale_transform.Scale(512.0, 512.0);
4756
4757 typename Types::ContentLayerType* parent = this->CreateRoot(
4758 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
4759 typename Types::LayerType* clip = this->CreateLayer(parent,
4760 this->identity_matrix,
4761 gfx::PointF(10.f, 10.f),
4762 gfx::Size(50, 50));
4763 clip->SetMasksToBounds(true);
4764 typename Types::LayerType* scale = this->CreateLayer(
4765 clip, scale_transform, gfx::PointF(), gfx::Size(1, 1));
4766 typename Types::LayerType* scaled = this->CreateDrawingLayer(
4767 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
4768 this->CalcDrawEtc(parent);
4769
4770 TestOcclusionTrackerWithClip<typename Types::LayerType,
4771 typename Types::RenderSurfaceType> occlusion(
4772 gfx::Rect(0, 0, 1000, 1000));
4773
4774 this->VisitLayer(scaled, &occlusion);
4775
4776 EXPECT_EQ(gfx::Rect().ToString(),
4777 occlusion.occlusion_from_outside_target().ToString());
4778 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
4779 occlusion.occlusion_from_inside_target().ToString());
4780 }
4781};
4782
4783ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped)
4784
4785template <class Types>
4786class OcclusionTrackerTestScaledLayerInSurfaceIsClipped
4787 : public OcclusionTrackerTest<Types> {
4788 protected:
4789 explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers)
4790 : OcclusionTrackerTest<Types>(opaque_layers) {}
4791 void RunMyTest() {
4792 gfx::Transform scale_transform;
4793 scale_transform.Scale(512.0, 512.0);
4794
4795 typename Types::ContentLayerType* parent = this->CreateRoot(
4796 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
4797 typename Types::LayerType* clip = this->CreateLayer(parent,
4798 this->identity_matrix,
4799 gfx::PointF(10.f, 10.f),
4800 gfx::Size(50, 50));
4801 clip->SetMasksToBounds(true);
4802 typename Types::LayerType* surface = this->CreateDrawingSurface(
4803 clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false);
4804 typename Types::LayerType* scale = this->CreateLayer(
4805 surface, scale_transform, gfx::PointF(), gfx::Size(1, 1));
4806 typename Types::LayerType* scaled = this->CreateDrawingLayer(
4807 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
4808 this->CalcDrawEtc(parent);
4809
4810 TestOcclusionTrackerWithClip<typename Types::LayerType,
4811 typename Types::RenderSurfaceType> occlusion(
4812 gfx::Rect(0, 0, 1000, 1000));
4813
4814 this->VisitLayer(scaled, &occlusion);
4815 this->VisitLayer(surface, &occlusion);
4816 this->VisitContributingSurface(surface, &occlusion);
4817
4818 EXPECT_EQ(gfx::Rect().ToString(),
4819 occlusion.occlusion_from_outside_target().ToString());
4820 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
4821 occlusion.occlusion_from_inside_target().ToString());
4822 }
4823};
4824
4825ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped)
4826
[email protected]5b54b972013-07-26 13:25:424827template <class Types>
4828class OcclusionTrackerTestCopyRequestDoesOcclude
4829 : public OcclusionTrackerTest<Types> {
4830 protected:
4831 explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers)
4832 : OcclusionTrackerTest<Types>(opaque_layers) {}
4833 void RunMyTest() {
4834 typename Types::ContentLayerType* root = this->CreateRoot(
4835 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
4836 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
4837 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
4838 typename Types::LayerType* copy = this->CreateLayer(parent,
4839 this->identity_matrix,
4840 gfx::Point(100, 0),
4841 gfx::Size(200, 400));
4842 this->AddCopyRequest(copy);
4843 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
4844 copy,
4845 this->identity_matrix,
4846 gfx::PointF(),
4847 gfx::Size(200, 400),
4848 true);
4849 this->CalcDrawEtc(root);
4850
4851 TestOcclusionTrackerWithClip<typename Types::LayerType,
4852 typename Types::RenderSurfaceType> occlusion(
4853 gfx::Rect(0, 0, 1000, 1000));
4854
4855 this->VisitLayer(copy_child, &occlusion);
4856 EXPECT_EQ(gfx::Rect().ToString(),
4857 occlusion.occlusion_from_outside_target().ToString());
4858 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
4859 occlusion.occlusion_from_inside_target().ToString());
4860
4861 // CopyRequests cause the layer to own a surface.
4862 this->VisitContributingSurface(copy, &occlusion);
4863
4864 // The occlusion from the copy should be kept.
4865 EXPECT_EQ(gfx::Rect().ToString(),
4866 occlusion.occlusion_from_outside_target().ToString());
4867 EXPECT_EQ(gfx::Rect(100, 0, 200, 400).ToString(),
4868 occlusion.occlusion_from_inside_target().ToString());
4869 }
4870};
4871
4872ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude)
4873
4874template <class Types>
4875class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude
4876 : public OcclusionTrackerTest<Types> {
4877 protected:
4878 explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude(
4879 bool opaque_layers)
4880 : OcclusionTrackerTest<Types>(opaque_layers) {}
4881 void RunMyTest() {
4882 typename Types::ContentLayerType* root = this->CreateRoot(
4883 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
4884 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
4885 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
4886 typename Types::LayerType* hide = this->CreateLayer(
4887 parent, this->identity_matrix, gfx::Point(), gfx::Size());
4888 typename Types::LayerType* copy = this->CreateLayer(
4889 hide, this->identity_matrix, gfx::Point(100, 0), gfx::Size(200, 400));
4890 this->AddCopyRequest(copy);
4891 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
4892 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
4893
4894 // The |copy| layer is hidden but since it is being copied, it will be
4895 // drawn.
4896 hide->SetHideLayerAndSubtree(true);
4897
4898 this->CalcDrawEtc(root);
4899
4900 TestOcclusionTrackerWithClip<typename Types::LayerType,
4901 typename Types::RenderSurfaceType> occlusion(
4902 gfx::Rect(0, 0, 1000, 1000));
4903
4904 this->VisitLayer(copy_child, &occlusion);
4905 EXPECT_EQ(gfx::Rect().ToString(),
4906 occlusion.occlusion_from_outside_target().ToString());
4907 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
4908 occlusion.occlusion_from_inside_target().ToString());
4909
4910 // CopyRequests cause the layer to own a surface.
4911 this->VisitContributingSurface(copy, &occlusion);
4912
4913 // The occlusion from the copy should be dropped since it is hidden.
4914 EXPECT_EQ(gfx::Rect().ToString(),
4915 occlusion.occlusion_from_outside_target().ToString());
4916 EXPECT_EQ(gfx::Rect().ToString(),
4917 occlusion.occlusion_from_inside_target().ToString());
4918 }
4919};
4920
4921ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude)
4922
[email protected]ba565742012-11-10 09:29:484923} // namespace
4924} // namespace cc