blob: 59261f396aa4b70b2bd2f6f314bb8d89e326dacb [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"
[email protected]d600df7d2013-08-03 02:34:2818#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4519#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0320#include "cc/test/geometry_test_utils.h"
21#include "cc/test/occlusion_tracker_test_common.h"
[email protected]556fd292013-03-18 08:03:0422#include "cc/trees/layer_tree_host_common.h"
23#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1824#include "testing/gmock/include/gmock/gmock.h"
25#include "testing/gtest/include/gtest/gtest.h"
[email protected]c8686a02012-11-27 08:29:0026#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1427
[email protected]ba565742012-11-10 09:29:4828namespace cc {
[email protected]94f206c12012-08-25 00:09:1429namespace {
30
[email protected]96baf3e2012-10-22 23:09:5531class TestContentLayer : public Layer {
[email protected]a27cbde2013-03-23 22:01:4932 public:
[email protected]afc4f262013-10-05 01:14:1033 TestContentLayer() : Layer(), override_opaque_contents_rect_(false) {
34 SetIsDrawable(true);
35 }
[email protected]94f206c12012-08-25 00:09:1436
[email protected]a27cbde2013-03-23 22:01:4937 virtual Region VisibleContentOpaqueRegion() const OVERRIDE {
38 if (override_opaque_contents_rect_)
39 return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect());
40 return Layer::VisibleContentOpaqueRegion();
41 }
[email protected]0023fc72014-01-10 20:05:0642 void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) {
[email protected]a27cbde2013-03-23 22:01:4943 override_opaque_contents_rect_ = true;
44 opaque_contents_rect_ = opaque_contents_rect;
45 }
[email protected]94f206c12012-08-25 00:09:1446
[email protected]a27cbde2013-03-23 22:01:4947 private:
48 virtual ~TestContentLayer() {}
[email protected]d58499a2012-10-09 22:27:4749
[email protected]a27cbde2013-03-23 22:01:4950 bool override_opaque_contents_rect_;
51 gfx::Rect opaque_contents_rect_;
[email protected]94f206c12012-08-25 00:09:1452};
53
[email protected]96baf3e2012-10-22 23:09:5554class TestContentLayerImpl : public LayerImpl {
[email protected]a27cbde2013-03-23 22:01:4955 public:
56 TestContentLayerImpl(LayerTreeImpl* tree_impl, int id)
57 : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) {
58 SetDrawsContent(true);
59 }
[email protected]94f206c12012-08-25 00:09:1460
[email protected]a27cbde2013-03-23 22:01:4961 virtual Region VisibleContentOpaqueRegion() const OVERRIDE {
62 if (override_opaque_contents_rect_)
63 return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect());
64 return LayerImpl::VisibleContentOpaqueRegion();
65 }
[email protected]0023fc72014-01-10 20:05:0666 void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) {
[email protected]a27cbde2013-03-23 22:01:4967 override_opaque_contents_rect_ = true;
68 opaque_contents_rect_ = opaque_contents_rect;
69 }
[email protected]94f206c12012-08-25 00:09:1470
[email protected]a27cbde2013-03-23 22:01:4971 private:
72 bool override_opaque_contents_rect_;
73 gfx::Rect opaque_contents_rect_;
[email protected]94f206c12012-08-25 00:09:1474};
75
[email protected]a27cbde2013-03-23 22:01:4976static inline bool LayerImplDrawTransformIsUnknown(const Layer* layer) {
77 return layer->draw_transform_is_animating();
78}
79static inline bool LayerImplDrawTransformIsUnknown(const LayerImpl* layer) {
80 return false;
81}
[email protected]710ffc02012-10-30 21:42:0282
[email protected]a27cbde2013-03-23 22:01:4983template <typename LayerType, typename RenderSurfaceType>
[email protected]ca2902e92013-03-28 01:45:3584class TestOcclusionTrackerWithClip
85 : public TestOcclusionTrackerBase<LayerType, RenderSurfaceType> {
[email protected]a27cbde2013-03-23 22:01:4986 public:
[email protected]0023fc72014-01-10 20:05:0687 TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect,
[email protected]a27cbde2013-03-23 22:01:4988 bool record_metrics_for_frame)
89 : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(
90 viewport_rect,
91 record_metrics_for_frame) {}
[email protected]0023fc72014-01-10 20:05:0692 explicit TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect)
[email protected]a27cbde2013-03-23 22:01:4993 : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(viewport_rect,
94 false) {}
[email protected]94f206c12012-08-25 00:09:1495
[email protected]a27cbde2013-03-23 22:01:4996 bool OccludedLayer(const LayerType* layer,
[email protected]0023fc72014-01-10 20:05:0697 const gfx::Rect& content_rect) const {
[email protected]cfc2d2d2013-10-04 23:26:4598 DCHECK(layer->visible_content_rect().Contains(content_rect));
[email protected]a27cbde2013-03-23 22:01:4999 return this->Occluded(layer->render_target(),
100 content_rect,
101 layer->draw_transform(),
[email protected]cfc2d2d2013-10-04 23:26:45102 LayerImplDrawTransformIsUnknown(layer));
[email protected]a27cbde2013-03-23 22:01:49103 }
[email protected]fbc293322013-10-01 05:07:15104
[email protected]a27cbde2013-03-23 22:01:49105 // Gives an unoccluded sub-rect of |content_rect| in the content space of the
[email protected]ed511b8d2013-03-25 03:29:29106 // layer. Simple wrapper around UnoccludedContentRect.
[email protected]a27cbde2013-03-23 22:01:49107 gfx::Rect UnoccludedLayerContentRect(const LayerType* layer,
[email protected]0023fc72014-01-10 20:05:06108 const gfx::Rect& content_rect) const {
[email protected]cfc2d2d2013-10-04 23:26:45109 DCHECK(layer->visible_content_rect().Contains(content_rect));
[email protected]a27cbde2013-03-23 22:01:49110 return this->UnoccludedContentRect(
111 layer->render_target(),
112 content_rect,
113 layer->draw_transform(),
[email protected]cfc2d2d2013-10-04 23:26:45114 LayerImplDrawTransformIsUnknown(layer));
[email protected]a27cbde2013-03-23 22:01:49115 }
[email protected]94f206c12012-08-25 00:09:14116};
117
[email protected]96baf3e2012-10-22 23:09:55118struct OcclusionTrackerTestMainThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49119 typedef Layer LayerType;
[email protected]d600df7d2013-08-03 02:34:28120 typedef FakeLayerTreeHost HostType;
[email protected]a27cbde2013-03-23 22:01:49121 typedef RenderSurface RenderSurfaceType;
122 typedef TestContentLayer ContentLayerType;
123 typedef scoped_refptr<Layer> LayerPtrType;
124 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
125 typedef LayerIterator<Layer,
[email protected]989386c2013-07-18 21:37:23126 RenderSurfaceLayerList,
[email protected]a27cbde2013-03-23 22:01:49127 RenderSurface,
128 LayerIteratorActions::FrontToBack> TestLayerIterator;
129 typedef OcclusionTracker OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14130
[email protected]a27cbde2013-03-23 22:01:49131 static LayerPtrType CreateLayer(HostType* host) { return Layer::Create(); }
132 static ContentLayerPtrType CreateContentLayer(HostType* host) {
133 return make_scoped_refptr(new ContentLayerType());
134 }
[email protected]e0bd43a2012-10-12 16:54:21135
[email protected]a27cbde2013-03-23 22:01:49136 static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) {
137 LayerPtrType ref(*layer);
138 *layer = NULL;
139 return ref;
140 }
[email protected]e0bd43a2012-10-12 16:54:21141
[email protected]a27cbde2013-03-23 22:01:49142 static LayerPtrType PassLayerPtr(LayerPtrType* layer) {
143 LayerPtrType ref(*layer);
144 *layer = NULL;
145 return ref;
146 }
[email protected]d58499a2012-10-09 22:27:47147
[email protected]a27cbde2013-03-23 22:01:49148 static void DestroyLayer(LayerPtrType* layer) { *layer = NULL; }
[email protected]94f206c12012-08-25 00:09:14149};
150
[email protected]96baf3e2012-10-22 23:09:55151struct OcclusionTrackerTestImplThreadTypes {
[email protected]a27cbde2013-03-23 22:01:49152 typedef LayerImpl LayerType;
153 typedef LayerTreeImpl HostType;
154 typedef RenderSurfaceImpl RenderSurfaceType;
155 typedef TestContentLayerImpl ContentLayerType;
156 typedef scoped_ptr<LayerImpl> LayerPtrType;
157 typedef scoped_ptr<ContentLayerType> ContentLayerPtrType;
158 typedef LayerIterator<LayerImpl,
[email protected]50761e92013-03-29 20:51:28159 LayerImplList,
[email protected]a27cbde2013-03-23 22:01:49160 RenderSurfaceImpl,
161 LayerIteratorActions::FrontToBack> TestLayerIterator;
162 typedef OcclusionTrackerImpl OcclusionTrackerType;
[email protected]94f206c12012-08-25 00:09:14163
[email protected]a27cbde2013-03-23 22:01:49164 static LayerPtrType CreateLayer(HostType* host) {
165 return LayerImpl::Create(host, next_layer_impl_id++);
166 }
167 static ContentLayerPtrType CreateContentLayer(HostType* host) {
168 return make_scoped_ptr(new ContentLayerType(host, next_layer_impl_id++));
169 }
170 static int next_layer_impl_id;
[email protected]d58499a2012-10-09 22:27:47171
[email protected]a27cbde2013-03-23 22:01:49172 static LayerPtrType PassLayerPtr(LayerPtrType* layer) {
173 return layer->Pass();
174 }
[email protected]e0bd43a2012-10-12 16:54:21175
[email protected]a27cbde2013-03-23 22:01:49176 static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) {
177 return layer->PassAs<LayerType>();
178 }
[email protected]e0bd43a2012-10-12 16:54:21179
[email protected]a27cbde2013-03-23 22:01:49180 static void DestroyLayer(LayerPtrType* layer) { layer->reset(); }
[email protected]94f206c12012-08-25 00:09:14181};
182
[email protected]a27cbde2013-03-23 22:01:49183int OcclusionTrackerTestImplThreadTypes::next_layer_impl_id = 1;
[email protected]94f206c12012-08-25 00:09:14184
[email protected]a27cbde2013-03-23 22:01:49185template <typename Types> class OcclusionTrackerTest : public testing::Test {
186 protected:
[email protected]ca2902e92013-03-28 01:45:35187 explicit OcclusionTrackerTest(bool opaque_layers)
[email protected]d600df7d2013-08-03 02:34:28188 : opaque_layers_(opaque_layers), host_(FakeLayerTreeHost::Create()) {}
[email protected]a27cbde2013-03-23 22:01:49189
190 virtual void RunMyTest() = 0;
191
192 virtual void TearDown() {
193 Types::DestroyLayer(&root_);
[email protected]989386c2013-07-18 21:37:23194 render_surface_layer_list_.reset();
[email protected]a27cbde2013-03-23 22:01:49195 render_surface_layer_list_impl_.clear();
196 replica_layers_.clear();
197 mask_layers_.clear();
198 }
199
200 typename Types::HostType* GetHost();
201
202 typename Types::ContentLayerType* CreateRoot(const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47203 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26204 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49205 typename Types::ContentLayerPtrType layer(
206 Types::CreateContentLayer(GetHost()));
207 typename Types::ContentLayerType* layer_ptr = layer.get();
208 SetProperties(layer_ptr, transform, position, bounds);
209
[email protected]22898ed2013-06-01 04:52:30210 DCHECK(!root_.get());
[email protected]a27cbde2013-03-23 22:01:49211 root_ = Types::PassLayerPtr(&layer);
[email protected]d600df7d2013-08-03 02:34:28212
213 SetRootLayerOnMainThread(layer_ptr);
214
[email protected]a27cbde2013-03-23 22:01:49215 return layer_ptr;
216 }
217
218 typename Types::LayerType* CreateLayer(typename Types::LayerType* parent,
219 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47220 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26221 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49222 typename Types::LayerPtrType layer(Types::CreateLayer(GetHost()));
223 typename Types::LayerType* layer_ptr = layer.get();
224 SetProperties(layer_ptr, transform, position, bounds);
225 parent->AddChild(Types::PassLayerPtr(&layer));
226 return layer_ptr;
227 }
228
229 typename Types::LayerType* CreateSurface(typename Types::LayerType* parent,
230 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47231 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26232 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49233 typename Types::LayerType* layer =
234 CreateLayer(parent, transform, position, bounds);
235 layer->SetForceRenderSurface(true);
236 return layer;
237 }
238
239 typename Types::ContentLayerType* CreateDrawingLayer(
240 typename Types::LayerType* parent,
241 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47242 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26243 const gfx::Size& bounds,
[email protected]a27cbde2013-03-23 22:01:49244 bool opaque) {
245 typename Types::ContentLayerPtrType layer(
246 Types::CreateContentLayer(GetHost()));
247 typename Types::ContentLayerType* layer_ptr = layer.get();
248 SetProperties(layer_ptr, transform, position, bounds);
249
250 if (opaque_layers_) {
251 layer_ptr->SetContentsOpaque(opaque);
252 } else {
253 layer_ptr->SetContentsOpaque(false);
254 if (opaque)
[email protected]2c7c6702013-03-26 03:14:05255 layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds));
[email protected]a27cbde2013-03-23 22:01:49256 else
257 layer_ptr->SetOpaqueContentsRect(gfx::Rect());
[email protected]586d51ed2012-12-07 20:31:45258 }
[email protected]94f206c12012-08-25 00:09:14259
[email protected]a27cbde2013-03-23 22:01:49260 parent->AddChild(Types::PassLayerPtr(&layer));
261 return layer_ptr;
262 }
[email protected]94f206c12012-08-25 00:09:14263
[email protected]a27cbde2013-03-23 22:01:49264 typename Types::LayerType* CreateReplicaLayer(
265 typename Types::LayerType* owning_layer,
266 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47267 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26268 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49269 typename Types::ContentLayerPtrType layer(
270 Types::CreateContentLayer(GetHost()));
271 typename Types::ContentLayerType* layer_ptr = layer.get();
272 SetProperties(layer_ptr, transform, position, bounds);
273 SetReplica(owning_layer, Types::PassLayerPtr(&layer));
274 return layer_ptr;
275 }
[email protected]94f206c12012-08-25 00:09:14276
[email protected]a27cbde2013-03-23 22:01:49277 typename Types::LayerType* CreateMaskLayer(
278 typename Types::LayerType* owning_layer,
[email protected]64348ea2014-01-29 22:58:26279 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49280 typename Types::ContentLayerPtrType layer(
281 Types::CreateContentLayer(GetHost()));
282 typename Types::ContentLayerType* layer_ptr = layer.get();
283 SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds);
284 SetMask(owning_layer, Types::PassLayerPtr(&layer));
285 return layer_ptr;
286 }
[email protected]586d51ed2012-12-07 20:31:45287
[email protected]a27cbde2013-03-23 22:01:49288 typename Types::ContentLayerType* CreateDrawingSurface(
289 typename Types::LayerType* parent,
290 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47291 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26292 const gfx::Size& bounds,
[email protected]a27cbde2013-03-23 22:01:49293 bool opaque) {
294 typename Types::ContentLayerType* layer =
295 CreateDrawingLayer(parent, transform, position, bounds, opaque);
296 layer->SetForceRenderSurface(true);
297 return layer;
298 }
[email protected]94f206c12012-08-25 00:09:14299
[email protected]5b54b972013-07-26 13:25:42300
301 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
302
303 void AddCopyRequest(Layer* layer) {
304 layer->RequestCopyOfOutput(
305 CopyOutputRequest::CreateBitmapRequest(base::Bind(
306 &OcclusionTrackerTest<Types>::CopyOutputCallback,
307 base::Unretained(this))));
308 }
309
310 void AddCopyRequest(LayerImpl* layer) {
311 ScopedPtrVector<CopyOutputRequest> requests;
312 requests.push_back(
313 CopyOutputRequest::CreateBitmapRequest(base::Bind(
314 &OcclusionTrackerTest<Types>::CopyOutputCallback,
315 base::Unretained(this))));
316 layer->PassCopyRequests(&requests);
317 }
318
[email protected]a27cbde2013-03-23 22:01:49319 void CalcDrawEtc(TestContentLayerImpl* root) {
320 DCHECK(root == root_.get());
[email protected]a27cbde2013-03-23 22:01:49321 DCHECK(!root->render_surface());
[email protected]94f206c12012-08-25 00:09:14322
[email protected]7aad55f2013-07-26 11:25:53323 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
324 root, root->bounds(), &render_surface_layer_list_impl_);
325 inputs.can_adjust_raster_scales = true;
326 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14327
[email protected]a27cbde2013-03-23 22:01:49328 layer_iterator_ = layer_iterator_begin_ =
329 Types::TestLayerIterator::Begin(&render_surface_layer_list_impl_);
330 }
[email protected]94f206c12012-08-25 00:09:14331
[email protected]a27cbde2013-03-23 22:01:49332 void CalcDrawEtc(TestContentLayer* root) {
333 DCHECK(root == root_.get());
[email protected]a27cbde2013-03-23 22:01:49334 DCHECK(!root->render_surface());
[email protected]94f206c12012-08-25 00:09:14335
[email protected]989386c2013-07-18 21:37:23336 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
[email protected]7aad55f2013-07-26 11:25:53337 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
338 root, root->bounds(), render_surface_layer_list_.get());
339 inputs.can_adjust_raster_scales = true;
340 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:14341
[email protected]a27cbde2013-03-23 22:01:49342 layer_iterator_ = layer_iterator_begin_ =
[email protected]989386c2013-07-18 21:37:23343 Types::TestLayerIterator::Begin(render_surface_layer_list_.get());
[email protected]a27cbde2013-03-23 22:01:49344 }
[email protected]94f206c12012-08-25 00:09:14345
[email protected]afc4f262013-10-05 01:14:10346 void SetDrawsContent(LayerImpl* layer_impl, bool draws_content) {
347 layer_impl->SetDrawsContent(draws_content);
348 }
349
350 void SetDrawsContent(Layer* layer, bool draws_content) {
351 layer->SetIsDrawable(draws_content);
352 }
353
[email protected]a27cbde2013-03-23 22:01:49354 void EnterLayer(typename Types::LayerType* layer,
[email protected]e47b0a0a2013-11-18 23:26:22355 typename Types::OcclusionTrackerType* occlusion) {
[email protected]a27cbde2013-03-23 22:01:49356 ASSERT_EQ(layer, *layer_iterator_);
357 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]e47b0a0a2013-11-18 23:26:22358 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49359 }
[email protected]94f206c12012-08-25 00:09:14360
[email protected]a27cbde2013-03-23 22:01:49361 void LeaveLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40362 typename Types::OcclusionTrackerType* occlusion) {
[email protected]a27cbde2013-03-23 22:01:49363 ASSERT_EQ(layer, *layer_iterator_);
364 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]d002dd02013-03-27 07:40:40365 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49366 ++layer_iterator_;
367 }
[email protected]94f206c12012-08-25 00:09:14368
[email protected]a27cbde2013-03-23 22:01:49369 void VisitLayer(typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40370 typename Types::OcclusionTrackerType* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22371 EnterLayer(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49372 LeaveLayer(layer, occlusion);
373 }
[email protected]94f206c12012-08-25 00:09:14374
[email protected]a27cbde2013-03-23 22:01:49375 void EnterContributingSurface(
376 typename Types::LayerType* layer,
[email protected]e47b0a0a2013-11-18 23:26:22377 typename Types::OcclusionTrackerType* occlusion) {
[email protected]a27cbde2013-03-23 22:01:49378 ASSERT_EQ(layer, *layer_iterator_);
379 ASSERT_TRUE(layer_iterator_.represents_target_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22380 occlusion->EnterLayer(layer_iterator_);
[email protected]d002dd02013-03-27 07:40:40381 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49382 ++layer_iterator_;
383 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22384 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49385 }
[email protected]94f206c12012-08-25 00:09:14386
[email protected]a27cbde2013-03-23 22:01:49387 void LeaveContributingSurface(
388 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40389 typename Types::OcclusionTrackerType* occlusion) {
[email protected]a27cbde2013-03-23 22:01:49390 ASSERT_EQ(layer, *layer_iterator_);
391 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]d002dd02013-03-27 07:40:40392 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49393 ++layer_iterator_;
394 }
[email protected]94f206c12012-08-25 00:09:14395
[email protected]a27cbde2013-03-23 22:01:49396 void VisitContributingSurface(
397 typename Types::LayerType* layer,
[email protected]d002dd02013-03-27 07:40:40398 typename Types::OcclusionTrackerType* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22399 EnterContributingSurface(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49400 LeaveContributingSurface(layer, occlusion);
401 }
[email protected]94f206c12012-08-25 00:09:14402
[email protected]a27cbde2013-03-23 22:01:49403 void ResetLayerIterator() { layer_iterator_ = layer_iterator_begin_; }
[email protected]94f206c12012-08-25 00:09:14404
[email protected]a27cbde2013-03-23 22:01:49405 const gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:14406
[email protected]a27cbde2013-03-23 22:01:49407 private:
[email protected]d600df7d2013-08-03 02:34:28408 void SetRootLayerOnMainThread(Layer* root) {
409 host_->SetRootLayer(scoped_refptr<Layer>(root));
410 }
411
412 void SetRootLayerOnMainThread(LayerImpl* root) {}
413
[email protected]a27cbde2013-03-23 22:01:49414 void SetBaseProperties(typename Types::LayerType* layer,
415 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47416 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26417 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49418 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,
[email protected]14bc5d682014-01-17 07:26:47427 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26428 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49429 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,
[email protected]14bc5d682014-01-17 07:26:47434 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26435 const gfx::Size& bounds) {
[email protected]a27cbde2013-03-23 22:01:49436 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 bool opaque_layers_;
[email protected]d600df7d2013-08-03 02:34:28460 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]a27cbde2013-03-23 22:01:49461 // These hold ownership of the layers for the duration of the test.
462 typename Types::LayerPtrType root_;
[email protected]989386c2013-07-18 21:37:23463 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
[email protected]50761e92013-03-29 20:51:28464 LayerImplList render_surface_layer_list_impl_;
[email protected]a27cbde2013-03-23 22:01:49465 typename Types::TestLayerIterator layer_iterator_begin_;
466 typename Types::TestLayerIterator layer_iterator_;
467 typename Types::LayerType* last_layer_visited_;
[email protected]50761e92013-03-29 20:51:28468 LayerList replica_layers_;
469 LayerList mask_layers_;
[email protected]94f206c12012-08-25 00:09:14470};
471
[email protected]a27cbde2013-03-23 22:01:49472template <>
[email protected]d600df7d2013-08-03 02:34:28473FakeLayerTreeHost*
[email protected]a27cbde2013-03-23 22:01:49474OcclusionTrackerTest<OcclusionTrackerTestMainThreadTypes>::GetHost() {
[email protected]d600df7d2013-08-03 02:34:28475 return host_.get();
[email protected]586d51ed2012-12-07 20:31:45476}
477
[email protected]a27cbde2013-03-23 22:01:49478template <>
479LayerTreeImpl*
480OcclusionTrackerTest<OcclusionTrackerTestImplThreadTypes>::GetHost() {
[email protected]d600df7d2013-08-03 02:34:28481 return host_->host_impl()->active_tree();
[email protected]586d51ed2012-12-07 20:31:45482}
483
[email protected]a27cbde2013-03-23 22:01:49484#define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35485 class ClassName##MainThreadOpaqueLayers \
486 : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
487 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49488 ClassName##MainThreadOpaqueLayers() \
489 : ClassName<OcclusionTrackerTestMainThreadTypes>(true) {} \
490 }; \
491 TEST_F(ClassName##MainThreadOpaqueLayers, RunTest) { RunMyTest(); }
492#define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35493 class ClassName##MainThreadOpaquePaints \
494 : public ClassName<OcclusionTrackerTestMainThreadTypes> { \
495 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49496 ClassName##MainThreadOpaquePaints() \
497 : ClassName<OcclusionTrackerTestMainThreadTypes>(false) {} \
498 }; \
499 TEST_F(ClassName##MainThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14500
[email protected]a27cbde2013-03-23 22:01:49501#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35502 class ClassName##ImplThreadOpaqueLayers \
503 : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
504 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49505 ClassName##ImplThreadOpaqueLayers() \
506 : ClassName<OcclusionTrackerTestImplThreadTypes>(true) {} \
507 }; \
508 TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); }
509#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
[email protected]ca2902e92013-03-28 01:45:35510 class ClassName##ImplThreadOpaquePaints \
511 : public ClassName<OcclusionTrackerTestImplThreadTypes> { \
512 public: /* NOLINT(whitespace/indent) */ \
[email protected]a27cbde2013-03-23 22:01:49513 ClassName##ImplThreadOpaquePaints() \
514 : ClassName<OcclusionTrackerTestImplThreadTypes>(false) {} \
515 }; \
516 TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14517
[email protected]a27cbde2013-03-23 22:01:49518#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
519 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
520 RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
521 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
522 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
[email protected]94f206c12012-08-25 00:09:14523
[email protected]a27cbde2013-03-23 22:01:49524#define MAIN_THREAD_TEST(ClassName) \
525 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14526
[email protected]a27cbde2013-03-23 22:01:49527#define IMPL_THREAD_TEST(ClassName) \
528 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14529
[email protected]a27cbde2013-03-23 22:01:49530#define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
531 RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
532 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
[email protected]94f206c12012-08-25 00:09:14533
[email protected]a27cbde2013-03-23 22:01:49534template <class Types>
[email protected]ca2902e92013-03-28 01:45:35535class OcclusionTrackerTestIdentityTransforms
536 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49537 protected:
[email protected]ca2902e92013-03-28 01:45:35538 explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49539 : OcclusionTrackerTest<Types>(opaque_layers) {}
[email protected]ece1d952012-10-18 21:26:07540
[email protected]a27cbde2013-03-23 22:01:49541 void RunMyTest() {
542 typename Types::ContentLayerType* root = this->CreateRoot(
543 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
544 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
545 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
546 typename Types::ContentLayerType* layer =
547 this->CreateDrawingLayer(parent,
548 this->identity_matrix,
549 gfx::PointF(30.f, 30.f),
550 gfx::Size(500, 500),
551 true);
552 parent->SetMasksToBounds(true);
553 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14554
[email protected]a27cbde2013-03-23 22:01:49555 TestOcclusionTrackerWithClip<typename Types::LayerType,
556 typename Types::RenderSurfaceType> occlusion(
557 gfx::Rect(0, 0, 1000, 1000), false);
[email protected]94f206c12012-08-25 00:09:14558
[email protected]d002dd02013-03-27 07:40:40559 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22560 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14561
[email protected]a27cbde2013-03-23 22:01:49562 EXPECT_EQ(gfx::Rect().ToString(),
563 occlusion.occlusion_from_outside_target().ToString());
564 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
565 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14566
[email protected]a27cbde2013-03-23 22:01:49567 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
568 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
569 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
[email protected]cfc2d2d2013-10-04 23:26:45570 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 69, 70)));
571 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 69)));
[email protected]94f206c12012-08-25 00:09:14572
[email protected]a27cbde2013-03-23 22:01:49573 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
574 parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
575 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70),
576 occlusion.UnoccludedLayerContentRect(
577 parent, gfx::Rect(29, 30, 70, 70)));
578 EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70),
579 occlusion.UnoccludedLayerContentRect(
580 parent, gfx::Rect(29, 29, 70, 70)));
581 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1),
582 occlusion.UnoccludedLayerContentRect(
583 parent, gfx::Rect(30, 29, 70, 70)));
584 EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1),
585 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45586 parent, gfx::Rect(31, 29, 69, 70)));
[email protected]a27cbde2013-03-23 22:01:49587 EXPECT_RECT_EQ(gfx::Rect(),
588 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45589 parent, gfx::Rect(31, 30, 69, 70)));
[email protected]a27cbde2013-03-23 22:01:49590 EXPECT_RECT_EQ(gfx::Rect(),
591 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45592 parent, gfx::Rect(31, 31, 69, 69)));
[email protected]a27cbde2013-03-23 22:01:49593 EXPECT_RECT_EQ(gfx::Rect(),
594 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45595 parent, gfx::Rect(30, 31, 70, 69)));
[email protected]a27cbde2013-03-23 22:01:49596 EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69),
597 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45598 parent, gfx::Rect(29, 31, 70, 69)));
[email protected]a27cbde2013-03-23 22:01:49599 }
[email protected]94f206c12012-08-25 00:09:14600};
601
[email protected]96baf3e2012-10-22 23:09:55602ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14603
[email protected]a27cbde2013-03-23 22:01:49604template <class Types>
[email protected]ca2902e92013-03-28 01:45:35605class OcclusionTrackerTestQuadsMismatchLayer
606 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49607 protected:
[email protected]ca2902e92013-03-28 01:45:35608 explicit OcclusionTrackerTestQuadsMismatchLayer(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49609 : OcclusionTrackerTest<Types>(opaque_layers) {}
610 void RunMyTest() {
611 gfx::Transform layer_transform;
612 layer_transform.Translate(10.0, 10.0);
[email protected]710ffc02012-10-30 21:42:02613
[email protected]a27cbde2013-03-23 22:01:49614 typename Types::ContentLayerType* parent = this->CreateRoot(
615 this->identity_matrix, gfx::Point(0, 0), gfx::Size(100, 100));
616 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
617 parent, layer_transform, gfx::PointF(), gfx::Size(90, 90), true);
618 typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
619 layer1, layer_transform, gfx::PointF(), gfx::Size(50, 50), true);
620 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02621
[email protected]a27cbde2013-03-23 22:01:49622 TestOcclusionTrackerWithClip<typename Types::LayerType,
623 typename Types::RenderSurfaceType> occlusion(
624 gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02625
[email protected]d002dd02013-03-27 07:40:40626 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22627 this->EnterLayer(layer1, &occlusion);
[email protected]710ffc02012-10-30 21:42:02628
[email protected]a27cbde2013-03-23 22:01:49629 EXPECT_EQ(gfx::Rect().ToString(),
630 occlusion.occlusion_from_outside_target().ToString());
631 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
632 occlusion.occlusion_from_inside_target().ToString());
[email protected]710ffc02012-10-30 21:42:02633
[email protected]a27cbde2013-03-23 22:01:49634 // This checks cases where the quads don't match their "containing"
635 // layers, e.g. in terms of transforms or clip rect. This is typical for
636 // DelegatedRendererLayer.
[email protected]710ffc02012-10-30 21:42:02637
[email protected]a27cbde2013-03-23 22:01:49638 gfx::Transform quad_transform;
639 quad_transform.Translate(30.0, 30.0);
[email protected]710ffc02012-10-30 21:42:02640
[email protected]a27cbde2013-03-23 22:01:49641 EXPECT_TRUE(occlusion.UnoccludedContentRect(parent,
642 gfx::Rect(0, 0, 10, 10),
643 quad_transform,
[email protected]cfc2d2d2013-10-04 23:26:45644 false).IsEmpty());
[email protected]a27cbde2013-03-23 22:01:49645 EXPECT_RECT_EQ(gfx::Rect(0, 0, 10, 10),
646 occlusion.UnoccludedContentRect(parent,
647 gfx::Rect(0, 0, 10, 10),
648 quad_transform,
[email protected]cfc2d2d2013-10-04 23:26:45649 true));
[email protected]a27cbde2013-03-23 22:01:49650 EXPECT_RECT_EQ(gfx::Rect(40, 40, 10, 10),
651 occlusion.UnoccludedContentRect(parent,
652 gfx::Rect(40, 40, 10, 10),
653 quad_transform,
[email protected]cfc2d2d2013-10-04 23:26:45654 false));
[email protected]a27cbde2013-03-23 22:01:49655 EXPECT_RECT_EQ(gfx::Rect(40, 30, 5, 10),
656 occlusion.UnoccludedContentRect(parent,
657 gfx::Rect(35, 30, 10, 10),
658 quad_transform,
[email protected]cfc2d2d2013-10-04 23:26:45659 false));
[email protected]a27cbde2013-03-23 22:01:49660 }
[email protected]710ffc02012-10-30 21:42:02661};
662
663ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestQuadsMismatchLayer);
664
[email protected]a27cbde2013-03-23 22:01:49665template <class Types>
[email protected]96baf3e2012-10-22 23:09:55666class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49667 protected:
[email protected]ca2902e92013-03-28 01:45:35668 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49669 : OcclusionTrackerTest<Types>(opaque_layers) {}
670 void RunMyTest() {
671 gfx::Transform layer_transform;
672 layer_transform.Translate(250.0, 250.0);
673 layer_transform.Rotate(90.0);
674 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14675
[email protected]a27cbde2013-03-23 22:01:49676 typename Types::ContentLayerType* root = this->CreateRoot(
677 this->identity_matrix, gfx::Point(0, 0), gfx::Size(200, 200));
678 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
679 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
680 typename Types::ContentLayerType* layer =
681 this->CreateDrawingLayer(parent,
682 layer_transform,
683 gfx::PointF(30.f, 30.f),
684 gfx::Size(500, 500),
685 true);
686 parent->SetMasksToBounds(true);
687 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14688
[email protected]a27cbde2013-03-23 22:01:49689 TestOcclusionTrackerWithClip<typename Types::LayerType,
690 typename Types::RenderSurfaceType> occlusion(
691 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14692
[email protected]d002dd02013-03-27 07:40:40693 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22694 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14695
[email protected]a27cbde2013-03-23 22:01:49696 EXPECT_EQ(gfx::Rect().ToString(),
697 occlusion.occlusion_from_outside_target().ToString());
698 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
699 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14700
[email protected]a27cbde2013-03-23 22:01:49701 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
702 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
703 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
[email protected]cfc2d2d2013-10-04 23:26:45704 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 69, 70)));
705 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 69)));
[email protected]94f206c12012-08-25 00:09:14706
[email protected]a27cbde2013-03-23 22:01:49707 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
708 parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
709 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70),
710 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45711 parent, gfx::Rect(29, 30, 69, 70)));
[email protected]a27cbde2013-03-23 22:01:49712 EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70),
713 occlusion.UnoccludedLayerContentRect(
714 parent, gfx::Rect(29, 29, 70, 70)));
715 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1),
716 occlusion.UnoccludedLayerContentRect(
717 parent, gfx::Rect(30, 29, 70, 70)));
718 EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1),
719 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45720 parent, gfx::Rect(31, 29, 69, 70)));
[email protected]a27cbde2013-03-23 22:01:49721 EXPECT_RECT_EQ(gfx::Rect(),
722 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45723 parent, gfx::Rect(31, 30, 69, 70)));
[email protected]a27cbde2013-03-23 22:01:49724 EXPECT_RECT_EQ(gfx::Rect(),
725 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45726 parent, gfx::Rect(31, 31, 69, 69)));
[email protected]a27cbde2013-03-23 22:01:49727 EXPECT_RECT_EQ(gfx::Rect(),
728 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45729 parent, gfx::Rect(30, 31, 70, 69)));
[email protected]a27cbde2013-03-23 22:01:49730 EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69),
731 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45732 parent, gfx::Rect(29, 31, 70, 69)));
[email protected]a27cbde2013-03-23 22:01:49733 }
[email protected]94f206c12012-08-25 00:09:14734};
735
[email protected]96baf3e2012-10-22 23:09:55736ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14737
[email protected]a27cbde2013-03-23 22:01:49738template <class Types>
[email protected]96baf3e2012-10-22 23:09:55739class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49740 protected:
[email protected]ca2902e92013-03-28 01:45:35741 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49742 : OcclusionTrackerTest<Types>(opaque_layers) {}
743 void RunMyTest() {
744 gfx::Transform layer_transform;
745 layer_transform.Translate(20.0, 20.0);
[email protected]94f206c12012-08-25 00:09:14746
[email protected]a27cbde2013-03-23 22:01:49747 typename Types::ContentLayerType* root = this->CreateRoot(
748 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
749 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
750 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
751 typename Types::ContentLayerType* layer =
752 this->CreateDrawingLayer(parent,
753 layer_transform,
754 gfx::PointF(30.f, 30.f),
755 gfx::Size(500, 500),
756 true);
757 parent->SetMasksToBounds(true);
758 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14759
[email protected]a27cbde2013-03-23 22:01:49760 TestOcclusionTrackerWithClip<typename Types::LayerType,
761 typename Types::RenderSurfaceType> occlusion(
762 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14763
[email protected]d002dd02013-03-27 07:40:40764 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22765 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14766
[email protected]a27cbde2013-03-23 22:01:49767 EXPECT_EQ(gfx::Rect().ToString(),
768 occlusion.occlusion_from_outside_target().ToString());
769 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
770 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14771
[email protected]a27cbde2013-03-23 22:01:49772 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 50, 50, 50)));
773 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(49, 50, 50, 50)));
774 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(50, 49, 50, 50)));
[email protected]cfc2d2d2013-10-04 23:26:45775 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(51, 50, 49, 50)));
776 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 51, 50, 49)));
[email protected]94f206c12012-08-25 00:09:14777
[email protected]a27cbde2013-03-23 22:01:49778 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
779 parent, gfx::Rect(50, 50, 50, 50)).IsEmpty());
780 EXPECT_RECT_EQ(gfx::Rect(49, 50, 1, 50),
781 occlusion.UnoccludedLayerContentRect(
782 parent, gfx::Rect(49, 50, 50, 50)));
783 EXPECT_RECT_EQ(gfx::Rect(49, 49, 50, 50),
784 occlusion.UnoccludedLayerContentRect(
785 parent, gfx::Rect(49, 49, 50, 50)));
786 EXPECT_RECT_EQ(gfx::Rect(50, 49, 50, 1),
787 occlusion.UnoccludedLayerContentRect(
788 parent, gfx::Rect(50, 49, 50, 50)));
789 EXPECT_RECT_EQ(gfx::Rect(51, 49, 49, 1),
790 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45791 parent, gfx::Rect(51, 49, 49, 50)));
[email protected]a27cbde2013-03-23 22:01:49792 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45793 parent, gfx::Rect(51, 50, 49, 50)).IsEmpty());
[email protected]a27cbde2013-03-23 22:01:49794 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45795 parent, gfx::Rect(51, 51, 49, 49)).IsEmpty());
[email protected]a27cbde2013-03-23 22:01:49796 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45797 parent, gfx::Rect(50, 51, 50, 49)).IsEmpty());
[email protected]a27cbde2013-03-23 22:01:49798 EXPECT_RECT_EQ(gfx::Rect(49, 51, 1, 49),
799 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:45800 parent, gfx::Rect(49, 51, 50, 49)));
[email protected]a27cbde2013-03-23 22:01:49801 }
[email protected]94f206c12012-08-25 00:09:14802};
803
[email protected]96baf3e2012-10-22 23:09:55804ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14805
[email protected]a27cbde2013-03-23 22:01:49806template <class Types>
[email protected]ca2902e92013-03-28 01:45:35807class OcclusionTrackerTestChildInRotatedChild
808 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49809 protected:
[email protected]ca2902e92013-03-28 01:45:35810 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49811 : OcclusionTrackerTest<Types>(opaque_layers) {}
812 void RunMyTest() {
813 gfx::Transform child_transform;
814 child_transform.Translate(250.0, 250.0);
815 child_transform.Rotate(90.0);
816 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14817
[email protected]a27cbde2013-03-23 22:01:49818 typename Types::ContentLayerType* parent = this->CreateRoot(
819 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
820 parent->SetMasksToBounds(true);
[email protected]3a9a92d2013-07-11 04:37:00821 typename Types::LayerType* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49822 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
823 child->SetMasksToBounds(true);
824 typename Types::ContentLayerType* layer =
825 this->CreateDrawingLayer(child,
826 this->identity_matrix,
827 gfx::PointF(10.f, 10.f),
828 gfx::Size(500, 500),
829 true);
830 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14831
[email protected]a27cbde2013-03-23 22:01:49832 TestOcclusionTrackerWithClip<typename Types::LayerType,
833 typename Types::RenderSurfaceType> occlusion(
834 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14835
[email protected]d002dd02013-03-27 07:40:40836 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22837 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14838
[email protected]a27cbde2013-03-23 22:01:49839 EXPECT_EQ(gfx::Rect().ToString(),
840 occlusion.occlusion_from_outside_target().ToString());
841 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
842 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14843
[email protected]d002dd02013-03-27 07:40:40844 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22845 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14846
[email protected]a27cbde2013-03-23 22:01:49847 EXPECT_EQ(gfx::Rect().ToString(),
848 occlusion.occlusion_from_outside_target().ToString());
849 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
850 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14851
[email protected]a27cbde2013-03-23 22:01:49852 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
853 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
854 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]cfc2d2d2013-10-04 23:26:45855 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 40, 69, 60)));
856 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 41, 70, 59)));
[email protected]94f206c12012-08-25 00:09:14857
[email protected]a27cbde2013-03-23 22:01:49858 /* Justification for the above occlusion from |layer|:
859 100
860 +---------------------+
861 | |
862 | 30 | rotate(90)
863 | 30 + ---------------------------------+
864 100 | | 10 | | ==>
865 | |10+---------------------------------+
866 | | | | | |
867 | | | | | |
868 | | | | | |
869 +----|--|-------------+ | |
870 | | | |
871 | | | |
872 | | | |500
873 | | | |
874 | | | |
875 | | | |
876 | | | |
877 +--|-------------------------------+ |
878 | |
879 +---------------------------------+
880 500
881
882 +---------------------+
883 | |30 Visible region of |layer|: /////
884 | |
885 | +---------------------------------+
886 100| | |10 |
887 | +---------------------------------+ |
888 | | |///////////////| 420 | |
889 | | |///////////////|60 | |
890 | | |///////////////| | |
891 +--|--|---------------+ | |
892 20|10| 70 | |
893 | | | |
894 | | | |
895 | | | |
896 | | | |
897 | | | |
898 | | |10|
899 | +------------------------------|--+
900 | 490 |
901 +---------------------------------+
902 500
903
904 */
905 }
[email protected]94f206c12012-08-25 00:09:14906};
907
[email protected]96baf3e2012-10-22 23:09:55908ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14909
[email protected]a27cbde2013-03-23 22:01:49910template <class Types>
[email protected]ca2902e92013-03-28 01:45:35911class OcclusionTrackerTestScaledRenderSurface
912 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49913 protected:
[email protected]ca2902e92013-03-28 01:45:35914 explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49915 : OcclusionTrackerTest<Types>(opaque_layers) {}
[email protected]710ffc02012-10-30 21:42:02916
[email protected]a27cbde2013-03-23 22:01:49917 void RunMyTest() {
918 typename Types::ContentLayerType* parent = this->CreateRoot(
919 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02920
[email protected]a27cbde2013-03-23 22:01:49921 gfx::Transform layer1_matrix;
922 layer1_matrix.Scale(2.0, 2.0);
923 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
924 parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true);
925 layer1->SetForceRenderSurface(true);
[email protected]710ffc02012-10-30 21:42:02926
[email protected]a27cbde2013-03-23 22:01:49927 gfx::Transform layer2_matrix;
928 layer2_matrix.Translate(25.0, 25.0);
929 typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
930 layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true);
931 typename Types::ContentLayerType* occluder =
932 this->CreateDrawingLayer(parent,
933 this->identity_matrix,
934 gfx::PointF(100.f, 100.f),
935 gfx::Size(500, 500),
936 true);
937 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02938
[email protected]a27cbde2013-03-23 22:01:49939 TestOcclusionTrackerWithClip<typename Types::LayerType,
940 typename Types::RenderSurfaceType> occlusion(
941 gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02942
[email protected]d002dd02013-03-27 07:40:40943 this->VisitLayer(occluder, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22944 this->EnterLayer(layer2, &occlusion);
[email protected]710ffc02012-10-30 21:42:02945
[email protected]a27cbde2013-03-23 22:01:49946 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
947 occlusion.occlusion_from_outside_target().ToString());
948 EXPECT_EQ(gfx::Rect().ToString(),
949 occlusion.occlusion_from_inside_target().ToString());
[email protected]710ffc02012-10-30 21:42:02950
[email protected]a27cbde2013-03-23 22:01:49951 EXPECT_RECT_EQ(
952 gfx::Rect(0, 0, 25, 25),
953 occlusion.UnoccludedLayerContentRect(layer2, gfx::Rect(0, 0, 25, 25)));
954 EXPECT_RECT_EQ(gfx::Rect(10, 25, 15, 25),
955 occlusion.UnoccludedLayerContentRect(
956 layer2, gfx::Rect(10, 25, 25, 25)));
957 EXPECT_RECT_EQ(gfx::Rect(25, 10, 25, 15),
958 occlusion.UnoccludedLayerContentRect(
959 layer2, gfx::Rect(25, 10, 25, 25)));
960 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
961 layer2, gfx::Rect(25, 25, 25, 25)).IsEmpty());
962 }
[email protected]710ffc02012-10-30 21:42:02963};
964
965ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
966
[email protected]a27cbde2013-03-23 22:01:49967template <class Types>
[email protected]ca2902e92013-03-28 01:45:35968class OcclusionTrackerTestVisitTargetTwoTimes
969 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:49970 protected:
[email protected]ca2902e92013-03-28 01:45:35971 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:49972 : OcclusionTrackerTest<Types>(opaque_layers) {}
973 void RunMyTest() {
974 gfx::Transform child_transform;
975 child_transform.Translate(250.0, 250.0);
976 child_transform.Rotate(90.0);
977 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14978
[email protected]a27cbde2013-03-23 22:01:49979 typename Types::ContentLayerType* root = this->CreateRoot(
980 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
981 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
982 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
983 parent->SetMasksToBounds(true);
[email protected]3a9a92d2013-07-11 04:37:00984 typename Types::LayerType* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49985 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
986 child->SetMasksToBounds(true);
987 typename Types::ContentLayerType* layer =
988 this->CreateDrawingLayer(child,
989 this->identity_matrix,
990 gfx::PointF(10.f, 10.f),
991 gfx::Size(500, 500),
992 true);
993 // |child2| makes |parent|'s surface get considered by OcclusionTracker
994 // first, instead of |child|'s. This exercises different code in
995 // LeaveToRenderTarget, as the target surface has already been seen.
996 typename Types::ContentLayerType* child2 =
997 this->CreateDrawingLayer(parent,
998 this->identity_matrix,
999 gfx::PointF(30.f, 30.f),
1000 gfx::Size(60, 20),
1001 true);
1002 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141003
[email protected]a27cbde2013-03-23 22:01:491004 TestOcclusionTrackerWithClip<typename Types::LayerType,
1005 typename Types::RenderSurfaceType> occlusion(
1006 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141007
[email protected]d002dd02013-03-27 07:40:401008 this->VisitLayer(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141009
[email protected]a27cbde2013-03-23 22:01:491010 EXPECT_EQ(gfx::Rect().ToString(),
1011 occlusion.occlusion_from_outside_target().ToString());
1012 EXPECT_EQ(gfx::Rect(30, 30, 60, 20).ToString(),
1013 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141014
[email protected]d002dd02013-03-27 07:40:401015 this->VisitLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141016
[email protected]a27cbde2013-03-23 22:01:491017 EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(),
1018 occlusion.occlusion_from_outside_target().ToString());
1019 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
1020 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141021
[email protected]e47b0a0a2013-11-18 23:26:221022 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141023
[email protected]a27cbde2013-03-23 22:01:491024 EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(),
1025 occlusion.occlusion_from_outside_target().ToString());
1026 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
1027 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141028
[email protected]a27cbde2013-03-23 22:01:491029 // Occlusion in |child2| should get merged with the |child| surface we are
1030 // leaving now.
[email protected]d002dd02013-03-27 07:40:401031 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221032 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141033
[email protected]a27cbde2013-03-23 22:01:491034 EXPECT_EQ(gfx::Rect().ToString(),
1035 occlusion.occlusion_from_outside_target().ToString());
1036 EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60))
1037 .ToString(),
1038 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141039
[email protected]a27cbde2013-03-23 22:01:491040 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
1041 EXPECT_RECT_EQ(gfx::Rect(90, 30, 10, 10),
1042 occlusion.UnoccludedLayerContentRect(
1043 parent, gfx::Rect(30, 30, 70, 70)));
[email protected]94f206c12012-08-25 00:09:141044
[email protected]a27cbde2013-03-23 22:01:491045 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 60, 10)));
1046 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 60, 10)));
1047 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 60, 10)));
1048 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 60, 10)));
1049 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 60, 10)));
[email protected]94f206c12012-08-25 00:09:141050
[email protected]a27cbde2013-03-23 22:01:491051 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
1052 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
1053 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:141054
[email protected]a27cbde2013-03-23 22:01:491055 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1056 parent, gfx::Rect(30, 30, 60, 10)).IsEmpty());
1057 EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 10),
1058 occlusion.UnoccludedLayerContentRect(
1059 parent, gfx::Rect(29, 30, 60, 10)));
1060 EXPECT_RECT_EQ(gfx::Rect(30, 29, 60, 1),
1061 occlusion.UnoccludedLayerContentRect(
1062 parent, gfx::Rect(30, 29, 60, 10)));
1063 EXPECT_RECT_EQ(gfx::Rect(90, 30, 1, 10),
1064 occlusion.UnoccludedLayerContentRect(
1065 parent, gfx::Rect(31, 30, 60, 10)));
1066 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1067 parent, gfx::Rect(30, 31, 60, 10)).IsEmpty());
[email protected]94f206c12012-08-25 00:09:141068
[email protected]a27cbde2013-03-23 22:01:491069 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1070 parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
1071 EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60),
1072 occlusion.UnoccludedLayerContentRect(
1073 parent, gfx::Rect(29, 40, 70, 60)));
1074 // This rect is mostly occluded by |child2|.
1075 EXPECT_RECT_EQ(gfx::Rect(90, 39, 10, 1),
1076 occlusion.UnoccludedLayerContentRect(
1077 parent, gfx::Rect(30, 39, 70, 60)));
1078 // This rect extends past top/right ends of |child2|.
1079 EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 11),
1080 occlusion.UnoccludedLayerContentRect(
1081 parent, gfx::Rect(30, 29, 70, 70)));
1082 // This rect extends past left/right ends of |child2|.
1083 EXPECT_RECT_EQ(gfx::Rect(20, 39, 80, 60),
1084 occlusion.UnoccludedLayerContentRect(
1085 parent, gfx::Rect(20, 39, 80, 60)));
1086 EXPECT_RECT_EQ(gfx::Rect(),
1087 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:451088 parent, gfx::Rect(31, 40, 69, 60)));
[email protected]a27cbde2013-03-23 22:01:491089 EXPECT_RECT_EQ(gfx::Rect(),
1090 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:451091 parent, gfx::Rect(30, 41, 70, 59)));
[email protected]94f206c12012-08-25 00:09:141092
[email protected]a27cbde2013-03-23 22:01:491093 /* Justification for the above occlusion from |layer|:
1094 100
1095 +---------------------+
1096 | |
1097 | 30 | rotate(90)
1098 | 30 + ------------+--------------------+
1099 100 | | 10 | | | ==>
1100 | |10+----------|----------------------+
1101 | + ------------+ | | |
1102 | | | | | |
1103 | | | | | |
1104 +----|--|-------------+ | |
1105 | | | |
1106 | | | |
1107 | | | |500
1108 | | | |
1109 | | | |
1110 | | | |
1111 | | | |
1112 +--|-------------------------------+ |
1113 | |
1114 +---------------------------------+
1115 500
1116
1117
1118 +---------------------+
1119 | |30 Visible region of |layer|: /////
1120 | 30 60 | |child2|: \\\\\
1121 | 30 +------------+--------------------+
1122 | |\\\\\\\\\\\\| |10 |
1123 | +--|\\\\\\\\\\\\|-----------------+ |
1124 | | +------------+//| 420 | |
1125 | | |///////////////|60 | |
1126 | | |///////////////| | |
1127 +--|--|---------------+ | |
1128 20|10| 70 | |
1129 | | | |
1130 | | | |
1131 | | | |
1132 | | | |
1133 | | | |
1134 | | |10|
1135 | +------------------------------|--+
1136 | 490 |
1137 +---------------------------------+
1138 500
1139 */
1140 }
[email protected]94f206c12012-08-25 00:09:141141};
1142
[email protected]96baf3e2012-10-22 23:09:551143ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:141144
[email protected]a27cbde2013-03-23 22:01:491145template <class Types>
[email protected]ca2902e92013-03-28 01:45:351146class OcclusionTrackerTestSurfaceRotatedOffAxis
1147 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491148 protected:
[email protected]ca2902e92013-03-28 01:45:351149 explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491150 : OcclusionTrackerTest<Types>(opaque_layers) {}
1151 void RunMyTest() {
1152 gfx::Transform child_transform;
1153 child_transform.Translate(250.0, 250.0);
1154 child_transform.Rotate(95.0);
1155 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141156
[email protected]a27cbde2013-03-23 22:01:491157 gfx::Transform layer_transform;
1158 layer_transform.Translate(10.0, 10.0);
[email protected]94f206c12012-08-25 00:09:141159
[email protected]a27cbde2013-03-23 22:01:491160 typename Types::ContentLayerType* root = this->CreateRoot(
1161 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
1162 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
1163 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
1164 typename Types::LayerType* child = this->CreateLayer(
1165 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
1166 child->SetMasksToBounds(true);
1167 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1168 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true);
1169 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141170
[email protected]a27cbde2013-03-23 22:01:491171 TestOcclusionTrackerWithClip<typename Types::LayerType,
1172 typename Types::RenderSurfaceType> occlusion(
1173 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141174
[email protected]a27cbde2013-03-23 22:01:491175 gfx::Rect clipped_layer_in_child = MathUtil::MapClippedRect(
1176 layer_transform, layer->visible_content_rect());
[email protected]94f206c12012-08-25 00:09:141177
[email protected]d002dd02013-03-27 07:40:401178 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221179 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141180
[email protected]a27cbde2013-03-23 22:01:491181 EXPECT_EQ(gfx::Rect().ToString(),
1182 occlusion.occlusion_from_outside_target().ToString());
1183 EXPECT_EQ(clipped_layer_in_child.ToString(),
1184 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141185
[email protected]d002dd02013-03-27 07:40:401186 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221187 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141188
[email protected]a27cbde2013-03-23 22:01:491189 EXPECT_EQ(gfx::Rect().ToString(),
1190 occlusion.occlusion_from_outside_target().ToString());
1191 EXPECT_EQ(gfx::Rect().ToString(),
1192 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141193
[email protected]a27cbde2013-03-23 22:01:491194 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(75, 55, 1, 1)));
1195 EXPECT_RECT_EQ(
1196 gfx::Rect(75, 55, 1, 1),
1197 occlusion.UnoccludedLayerContentRect(parent, gfx::Rect(75, 55, 1, 1)));
1198 }
[email protected]94f206c12012-08-25 00:09:141199};
1200
[email protected]96baf3e2012-10-22 23:09:551201ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:141202
[email protected]a27cbde2013-03-23 22:01:491203template <class Types>
[email protected]ca2902e92013-03-28 01:45:351204class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
1205 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491206 protected:
[email protected]ca2902e92013-03-28 01:45:351207 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491208 : OcclusionTrackerTest<Types>(opaque_layers) {}
1209 void RunMyTest() {
1210 gfx::Transform child_transform;
1211 child_transform.Translate(250.0, 250.0);
1212 child_transform.Rotate(90.0);
1213 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141214
[email protected]a27cbde2013-03-23 22:01:491215 typename Types::ContentLayerType* root = this->CreateRoot(
1216 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
1217 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
1218 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
1219 parent->SetMasksToBounds(true);
1220 typename Types::ContentLayerType* child =
[email protected]3a9a92d2013-07-11 04:37:001221 this->CreateDrawingSurface(parent,
[email protected]a27cbde2013-03-23 22:01:491222 child_transform,
1223 gfx::PointF(30.f, 30.f),
1224 gfx::Size(500, 500),
1225 false);
1226 child->SetMasksToBounds(true);
1227 typename Types::ContentLayerType* layer1 =
1228 this->CreateDrawingLayer(child,
1229 this->identity_matrix,
1230 gfx::PointF(10.f, 10.f),
1231 gfx::Size(500, 500),
1232 true);
1233 typename Types::ContentLayerType* layer2 =
1234 this->CreateDrawingLayer(child,
1235 this->identity_matrix,
1236 gfx::PointF(10.f, 450.f),
1237 gfx::Size(500, 60),
1238 true);
1239 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141240
[email protected]a27cbde2013-03-23 22:01:491241 TestOcclusionTrackerWithClip<typename Types::LayerType,
1242 typename Types::RenderSurfaceType> occlusion(
1243 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141244
[email protected]d002dd02013-03-27 07:40:401245 this->VisitLayer(layer2, &occlusion);
1246 this->VisitLayer(layer1, &occlusion);
1247 this->VisitLayer(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221248 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141249
[email protected]a27cbde2013-03-23 22:01:491250 EXPECT_EQ(gfx::Rect().ToString(),
1251 occlusion.occlusion_from_outside_target().ToString());
1252 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
1253 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141254
[email protected]a27cbde2013-03-23 22:01:491255 EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 430, 60, 70)));
1256 EXPECT_FALSE(occlusion.OccludedLayer(child, gfx::Rect(9, 430, 60, 70)));
[email protected]cfc2d2d2013-10-04 23:26:451257 EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(11, 430, 59, 70)));
1258 EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 431, 60, 69)));
[email protected]94f206c12012-08-25 00:09:141259
[email protected]a27cbde2013-03-23 22:01:491260 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1261 child, gfx::Rect(10, 430, 60, 70)).IsEmpty());
1262 EXPECT_RECT_EQ(
1263 gfx::Rect(9, 430, 1, 70),
1264 occlusion.UnoccludedLayerContentRect(child, gfx::Rect(9, 430, 60, 70)));
[email protected]a27cbde2013-03-23 22:01:491265 EXPECT_RECT_EQ(gfx::Rect(),
1266 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:451267 child, gfx::Rect(11, 430, 59, 70)));
[email protected]a27cbde2013-03-23 22:01:491268 EXPECT_RECT_EQ(gfx::Rect(),
1269 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:451270 child, gfx::Rect(10, 431, 60, 69)));
[email protected]94f206c12012-08-25 00:09:141271
[email protected]d002dd02013-03-27 07:40:401272 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221273 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141274
[email protected]a27cbde2013-03-23 22:01:491275 EXPECT_EQ(gfx::Rect().ToString(),
1276 occlusion.occlusion_from_outside_target().ToString());
1277 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
1278 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141279
[email protected]a27cbde2013-03-23 22:01:491280 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
1281 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
1282 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
[email protected]94f206c12012-08-25 00:09:141283
[email protected]a27cbde2013-03-23 22:01:491284 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1285 parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
1286 EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60),
1287 occlusion.UnoccludedLayerContentRect(
1288 parent, gfx::Rect(29, 40, 70, 60)));
1289 EXPECT_RECT_EQ(gfx::Rect(30, 39, 70, 1),
1290 occlusion.UnoccludedLayerContentRect(
1291 parent, gfx::Rect(30, 39, 70, 60)));
1292 EXPECT_RECT_EQ(gfx::Rect(),
1293 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:451294 parent, gfx::Rect(31, 40, 69, 60)));
[email protected]a27cbde2013-03-23 22:01:491295 EXPECT_RECT_EQ(gfx::Rect(),
1296 occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:451297 parent, gfx::Rect(30, 41, 70, 59)));
[email protected]94f206c12012-08-25 00:09:141298
[email protected]a27cbde2013-03-23 22:01:491299 /* Justification for the above occlusion from |layer1| and |layer2|:
[email protected]94f206c12012-08-25 00:09:141300
1301 +---------------------+
1302 | |30 Visible region of |layer1|: /////
1303 | | Visible region of |layer2|: \\\\\
1304 | +---------------------------------+
1305 | | |10 |
1306 | +---------------+-----------------+ |
1307 | | |\\\\\\\\\\\\|//| 420 | |
1308 | | |\\\\\\\\\\\\|//|60 | |
1309 | | |\\\\\\\\\\\\|//| | |
1310 +--|--|------------|--+ | |
1311 20|10| 70 | | |
1312 | | | | |
1313 | | | | |
1314 | | | | |
1315 | | | | |
1316 | | | | |
1317 | | | |10|
1318 | +------------|-----------------|--+
1319 | | 490 |
1320 +---------------+-----------------+
1321 60 440
1322 */
[email protected]a27cbde2013-03-23 22:01:491323 }
[email protected]94f206c12012-08-25 00:09:141324};
1325
[email protected]96baf3e2012-10-22 23:09:551326ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:141327
[email protected]a27cbde2013-03-23 22:01:491328template <class Types>
[email protected]ca2902e92013-03-28 01:45:351329class OcclusionTrackerTestOverlappingSurfaceSiblings
1330 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491331 protected:
[email protected]ca2902e92013-03-28 01:45:351332 explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491333 : OcclusionTrackerTest<Types>(opaque_layers) {}
1334 void RunMyTest() {
1335 gfx::Transform child_transform;
1336 child_transform.Translate(250.0, 250.0);
1337 child_transform.Rotate(90.0);
1338 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141339
[email protected]a27cbde2013-03-23 22:01:491340 typename Types::ContentLayerType* parent = this->CreateRoot(
1341 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1342 parent->SetMasksToBounds(true);
1343 typename Types::LayerType* child1 = this->CreateSurface(
1344 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(10, 10));
1345 typename Types::LayerType* child2 = this->CreateSurface(
1346 parent, child_transform, gfx::PointF(20.f, 40.f), gfx::Size(10, 10));
1347 typename Types::ContentLayerType* layer1 =
1348 this->CreateDrawingLayer(child1,
1349 this->identity_matrix,
1350 gfx::PointF(-10.f, -10.f),
1351 gfx::Size(510, 510),
1352 true);
1353 typename Types::ContentLayerType* layer2 =
1354 this->CreateDrawingLayer(child2,
1355 this->identity_matrix,
1356 gfx::PointF(-10.f, -10.f),
1357 gfx::Size(510, 510),
1358 true);
1359 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141360
[email protected]a27cbde2013-03-23 22:01:491361 TestOcclusionTrackerWithClip<typename Types::LayerType,
1362 typename Types::RenderSurfaceType> occlusion(
1363 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141364
[email protected]d002dd02013-03-27 07:40:401365 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221366 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141367
[email protected]a27cbde2013-03-23 22:01:491368 EXPECT_EQ(gfx::Rect().ToString(),
1369 occlusion.occlusion_from_outside_target().ToString());
1370 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1371 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141372
[email protected]a27cbde2013-03-23 22:01:491373 // There is nothing above child2's surface in the z-order.
1374 EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80),
1375 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:151376 child2, false, gfx::Rect(-10, 420, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141377
[email protected]d002dd02013-03-27 07:40:401378 this->LeaveContributingSurface(child2, &occlusion);
1379 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221380 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141381
[email protected]a27cbde2013-03-23 22:01:491382 EXPECT_EQ(gfx::Rect(0, 430, 70, 80).ToString(),
1383 occlusion.occlusion_from_outside_target().ToString());
1384 EXPECT_EQ(gfx::Rect(-10, 430, 80, 70).ToString(),
1385 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141386
[email protected]a27cbde2013-03-23 22:01:491387 // child2's contents will occlude child1 below it.
1388 EXPECT_RECT_EQ(gfx::Rect(-10, 430, 10, 70),
1389 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:151390 child1, false, gfx::Rect(-10, 430, 80, 70)));
[email protected]94f206c12012-08-25 00:09:141391
[email protected]d002dd02013-03-27 07:40:401392 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221393 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141394
[email protected]a27cbde2013-03-23 22:01:491395 EXPECT_EQ(gfx::Rect().ToString(),
1396 occlusion.occlusion_from_outside_target().ToString());
1397 EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70))
1398 .ToString(),
1399 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141400
[email protected]a27cbde2013-03-23 22:01:491401 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 20, 80, 80)));
[email protected]94f206c12012-08-25 00:09:141402
[email protected]a27cbde2013-03-23 22:01:491403 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 20, 70, 80)));
1404 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 20, 70, 80)));
1405 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 19, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141406
[email protected]a27cbde2013-03-23 22:01:491407 EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(20, 30, 80, 70)));
1408 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(19, 30, 80, 70)));
1409 EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 29, 80, 70)));
[email protected]94f206c12012-08-25 00:09:141410
[email protected]a27cbde2013-03-23 22:01:491411 /* Justification for the above occlusion:
1412 100
1413 +---------------------+
1414 | 20 | layer1
1415 | 30+ ---------------------------------+
1416 100 | 30| | layer2 |
1417 |20+----------------------------------+ |
1418 | | | | | |
1419 | | | | | |
1420 | | | | | |
1421 +--|-|----------------+ | |
1422 | | | | 510
1423 | | | |
1424 | | | |
1425 | | | |
1426 | | | |
1427 | | | |
1428 | | | |
1429 | +--------------------------------|-+
1430 | |
1431 +----------------------------------+
1432 510
1433 */
1434 }
[email protected]94f206c12012-08-25 00:09:141435};
1436
[email protected]96baf3e2012-10-22 23:09:551437ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:141438
[email protected]a27cbde2013-03-23 22:01:491439template <class Types>
[email protected]ca2902e92013-03-28 01:45:351440class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms
1441 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491442 protected:
[email protected]ca2902e92013-03-28 01:45:351443 explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(
[email protected]a27cbde2013-03-23 22:01:491444 bool opaque_layers)
1445 : OcclusionTrackerTest<Types>(opaque_layers) {}
1446 void RunMyTest() {
1447 gfx::Transform child1_transform;
1448 child1_transform.Translate(250.0, 250.0);
1449 child1_transform.Rotate(-90.0);
1450 child1_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141451
[email protected]a27cbde2013-03-23 22:01:491452 gfx::Transform child2_transform;
1453 child2_transform.Translate(250.0, 250.0);
1454 child2_transform.Rotate(90.0);
1455 child2_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141456
[email protected]a27cbde2013-03-23 22:01:491457 typename Types::ContentLayerType* parent = this->CreateRoot(
1458 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1459 parent->SetMasksToBounds(true);
1460 typename Types::LayerType* child1 = this->CreateSurface(
1461 parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10));
1462 typename Types::LayerType* child2 =
1463 this->CreateDrawingSurface(parent,
1464 child2_transform,
1465 gfx::PointF(20.f, 40.f),
1466 gfx::Size(10, 10),
1467 false);
1468 typename Types::ContentLayerType* layer1 =
1469 this->CreateDrawingLayer(child1,
1470 this->identity_matrix,
1471 gfx::PointF(-10.f, -20.f),
1472 gfx::Size(510, 510),
1473 true);
1474 typename Types::ContentLayerType* layer2 =
1475 this->CreateDrawingLayer(child2,
1476 this->identity_matrix,
1477 gfx::PointF(-10.f, -10.f),
1478 gfx::Size(510, 510),
1479 true);
1480 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141481
[email protected]a27cbde2013-03-23 22:01:491482 TestOcclusionTrackerWithClip<typename Types::LayerType,
1483 typename Types::RenderSurfaceType> occlusion(
1484 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141485
[email protected]d002dd02013-03-27 07:40:401486 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221487 this->EnterLayer(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141488
[email protected]a27cbde2013-03-23 22:01:491489 EXPECT_EQ(gfx::Rect().ToString(),
1490 occlusion.occlusion_from_outside_target().ToString());
1491 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1492 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141493
[email protected]d002dd02013-03-27 07:40:401494 this->LeaveLayer(child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221495 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141496
[email protected]a27cbde2013-03-23 22:01:491497 // There is nothing above child2's surface in the z-order.
1498 EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80),
1499 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:151500 child2, false, gfx::Rect(-10, 420, 70, 80)));
[email protected]94f206c12012-08-25 00:09:141501
[email protected]d002dd02013-03-27 07:40:401502 this->LeaveContributingSurface(child2, &occlusion);
1503 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221504 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141505
[email protected]a27cbde2013-03-23 22:01:491506 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
1507 occlusion.occlusion_from_outside_target().ToString());
1508 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
1509 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141510
[email protected]a27cbde2013-03-23 22:01:491511 // child2's contents will occlude child1 below it.
1512 EXPECT_RECT_EQ(gfx::Rect(420, -20, 80, 90),
1513 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:151514 child1, false, gfx::Rect(420, -20, 80, 90)));
[email protected]a27cbde2013-03-23 22:01:491515 EXPECT_RECT_EQ(gfx::Rect(490, -10, 10, 80),
1516 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:151517 child1, false, gfx::Rect(420, -10, 80, 90)));
[email protected]a27cbde2013-03-23 22:01:491518 EXPECT_RECT_EQ(gfx::Rect(420, -20, 70, 10),
1519 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:151520 child1, false, gfx::Rect(420, -20, 70, 90)));
[email protected]94f206c12012-08-25 00:09:141521
[email protected]d002dd02013-03-27 07:40:401522 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221523 this->EnterLayer(parent, &occlusion);
[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, 20, 90, 80).ToString(),
1528 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141529
[email protected]a27cbde2013-03-23 22:01:491530 /* Justification for the above occlusion:
1531 100
1532 +---------------------+
1533 |20 | layer1
1534 10+----------------------------------+
1535 100 || 30 | layer2 |
1536 |20+----------------------------------+
1537 || | | | |
1538 || | | | |
1539 || | | | |
1540 +|-|------------------+ | |
1541 | | | | 510
1542 | | 510 | |
1543 | | | |
1544 | | | |
1545 | | | |
1546 | | | |
1547 | | 520 | |
1548 +----------------------------------+ |
1549 | |
1550 +----------------------------------+
1551 510
1552 */
1553 }
[email protected]94f206c12012-08-25 00:09:141554};
1555
[email protected]a27cbde2013-03-23 22:01:491556ALL_OCCLUSIONTRACKER_TEST(
1557 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:141558
[email protected]a27cbde2013-03-23 22:01:491559template <class Types>
[email protected]96baf3e2012-10-22 23:09:551560class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491561 protected:
[email protected]ca2902e92013-03-28 01:45:351562 explicit OcclusionTrackerTestFilters(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491563 : OcclusionTrackerTest<Types>(opaque_layers) {}
1564 void RunMyTest() {
1565 gfx::Transform layer_transform;
1566 layer_transform.Translate(250.0, 250.0);
1567 layer_transform.Rotate(90.0);
1568 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:141569
[email protected]a27cbde2013-03-23 22:01:491570 typename Types::ContentLayerType* parent = this->CreateRoot(
1571 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
1572 parent->SetMasksToBounds(true);
1573 typename Types::ContentLayerType* blur_layer =
1574 this->CreateDrawingLayer(parent,
1575 layer_transform,
1576 gfx::PointF(30.f, 30.f),
1577 gfx::Size(500, 500),
1578 true);
1579 typename Types::ContentLayerType* opaque_layer =
1580 this->CreateDrawingLayer(parent,
1581 layer_transform,
1582 gfx::PointF(30.f, 30.f),
1583 gfx::Size(500, 500),
1584 true);
1585 typename Types::ContentLayerType* opacity_layer =
1586 this->CreateDrawingLayer(parent,
1587 layer_transform,
1588 gfx::PointF(30.f, 30.f),
1589 gfx::Size(500, 500),
1590 true);
[email protected]94f206c12012-08-25 00:09:141591
[email protected]ae6b1a72013-06-25 18:49:291592 FilterOperations filters;
1593 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]a27cbde2013-03-23 22:01:491594 blur_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141595
[email protected]ae6b1a72013-06-25 18:49:291596 filters.Clear();
1597 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491598 opaque_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141599
[email protected]ae6b1a72013-06-25 18:49:291600 filters.Clear();
1601 filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
[email protected]a27cbde2013-03-23 22:01:491602 opacity_layer->SetFilters(filters);
[email protected]94f206c12012-08-25 00:09:141603
[email protected]a27cbde2013-03-23 22:01:491604 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141605
[email protected]a27cbde2013-03-23 22:01:491606 TestOcclusionTrackerWithClip<typename Types::LayerType,
1607 typename Types::RenderSurfaceType> occlusion(
1608 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141609
[email protected]a27cbde2013-03-23 22:01:491610 // Opacity layer won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401611 this->VisitLayer(opacity_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221612 this->EnterContributingSurface(opacity_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141613
[email protected]a27cbde2013-03-23 22:01:491614 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1615 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141616
[email protected]a27cbde2013-03-23 22:01:491617 // And has nothing to contribute to its parent surface.
[email protected]d002dd02013-03-27 07:40:401618 this->LeaveContributingSurface(opacity_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491619 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1620 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141621
[email protected]a27cbde2013-03-23 22:01:491622 // Opaque layer will contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401623 this->VisitLayer(opaque_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221624 this->EnterContributingSurface(opaque_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141625
[email protected]a27cbde2013-03-23 22:01:491626 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1627 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(),
1628 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141629
[email protected]a27cbde2013-03-23 22:01:491630 // And it gets translated to the parent surface.
[email protected]d002dd02013-03-27 07:40:401631 this->LeaveContributingSurface(opaque_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491632 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1633 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1634 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141635
[email protected]a27cbde2013-03-23 22:01:491636 // The blur layer needs to throw away any occlusion from outside its
1637 // subtree.
[email protected]e47b0a0a2013-11-18 23:26:221638 this->EnterLayer(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491639 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1640 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141641
[email protected]a27cbde2013-03-23 22:01:491642 // And it won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:401643 this->LeaveLayer(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221644 this->EnterContributingSurface(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491645 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1646 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141647
[email protected]a27cbde2013-03-23 22:01:491648 // But the opaque layer's occlusion is preserved on the parent.
[email protected]d002dd02013-03-27 07:40:401649 this->LeaveContributingSurface(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221650 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491651 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1652 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
1653 occlusion.occlusion_from_inside_target().ToString());
1654 }
[email protected]94f206c12012-08-25 00:09:141655};
1656
[email protected]96baf3e2012-10-22 23:09:551657ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:141658
[email protected]a27cbde2013-03-23 22:01:491659template <class Types>
[email protected]ca2902e92013-03-28 01:45:351660class OcclusionTrackerTestReplicaDoesOcclude
1661 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491662 protected:
[email protected]ca2902e92013-03-28 01:45:351663 explicit OcclusionTrackerTestReplicaDoesOcclude(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491664 : OcclusionTrackerTest<Types>(opaque_layers) {}
1665 void RunMyTest() {
1666 typename Types::ContentLayerType* parent = this->CreateRoot(
1667 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
1668 typename Types::LayerType* surface =
1669 this->CreateDrawingSurface(parent,
1670 this->identity_matrix,
1671 gfx::PointF(0.f, 100.f),
1672 gfx::Size(50, 50),
1673 true);
1674 this->CreateReplicaLayer(
1675 surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
1676 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141677
[email protected]a27cbde2013-03-23 22:01:491678 TestOcclusionTrackerWithClip<typename Types::LayerType,
1679 typename Types::RenderSurfaceType> occlusion(
1680 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141681
[email protected]d002dd02013-03-27 07:40:401682 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141683
[email protected]a27cbde2013-03-23 22:01:491684 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1685 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141686
[email protected]d002dd02013-03-27 07:40:401687 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221688 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141689
[email protected]a27cbde2013-03-23 22:01:491690 // The surface and replica should both be occluding the parent.
1691 EXPECT_EQ(
1692 UnionRegions(gfx::Rect(0, 100, 50, 50),
1693 gfx::Rect(50, 150, 50, 50)).ToString(),
1694 occlusion.occlusion_from_inside_target().ToString());
1695 }
[email protected]94f206c12012-08-25 00:09:141696};
1697
[email protected]96baf3e2012-10-22 23:09:551698ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude);
[email protected]94f206c12012-08-25 00:09:141699
[email protected]a27cbde2013-03-23 22:01:491700template <class Types>
[email protected]ca2902e92013-03-28 01:45:351701class OcclusionTrackerTestReplicaWithClipping
1702 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491703 protected:
[email protected]ca2902e92013-03-28 01:45:351704 explicit OcclusionTrackerTestReplicaWithClipping(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491705 : OcclusionTrackerTest<Types>(opaque_layers) {}
1706 void RunMyTest() {
1707 typename Types::ContentLayerType* parent = this->CreateRoot(
1708 this->identity_matrix, gfx::PointF(), gfx::Size(100, 170));
1709 parent->SetMasksToBounds(true);
1710 typename Types::LayerType* surface =
1711 this->CreateDrawingSurface(parent,
1712 this->identity_matrix,
1713 gfx::PointF(0.f, 100.f),
1714 gfx::Size(50, 50),
1715 true);
1716 this->CreateReplicaLayer(
1717 surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
1718 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141719
[email protected]a27cbde2013-03-23 22:01:491720 TestOcclusionTrackerWithClip<typename Types::LayerType,
1721 typename Types::RenderSurfaceType> occlusion(
1722 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141723
[email protected]d002dd02013-03-27 07:40:401724 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141725
[email protected]a27cbde2013-03-23 22:01:491726 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1727 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141728
[email protected]d002dd02013-03-27 07:40:401729 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221730 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141731
[email protected]a27cbde2013-03-23 22:01:491732 // The surface and replica should both be occluding the parent.
1733 EXPECT_EQ(
1734 UnionRegions(gfx::Rect(0, 100, 50, 50),
1735 gfx::Rect(50, 150, 50, 20)).ToString(),
1736 occlusion.occlusion_from_inside_target().ToString());
1737 }
[email protected]94f206c12012-08-25 00:09:141738};
1739
[email protected]96baf3e2012-10-22 23:09:551740ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping);
[email protected]94f206c12012-08-25 00:09:141741
[email protected]a27cbde2013-03-23 22:01:491742template <class Types>
[email protected]96baf3e2012-10-22 23:09:551743class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491744 protected:
[email protected]ca2902e92013-03-28 01:45:351745 explicit OcclusionTrackerTestReplicaWithMask(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491746 : OcclusionTrackerTest<Types>(opaque_layers) {}
1747 void RunMyTest() {
1748 typename Types::ContentLayerType* parent = this->CreateRoot(
1749 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
1750 typename Types::LayerType* surface =
1751 this->CreateDrawingSurface(parent,
1752 this->identity_matrix,
1753 gfx::PointF(0.f, 100.f),
1754 gfx::Size(50, 50),
1755 true);
1756 typename Types::LayerType* replica = this->CreateReplicaLayer(
1757 surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
1758 this->CreateMaskLayer(replica, gfx::Size(10, 10));
1759 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141760
[email protected]a27cbde2013-03-23 22:01:491761 TestOcclusionTrackerWithClip<typename Types::LayerType,
1762 typename Types::RenderSurfaceType> occlusion(
1763 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141764
[email protected]d002dd02013-03-27 07:40:401765 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141766
[email protected]a27cbde2013-03-23 22:01:491767 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
1768 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141769
[email protected]d002dd02013-03-27 07:40:401770 this->VisitContributingSurface(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221771 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141772
[email protected]a27cbde2013-03-23 22:01:491773 // The replica should not be occluding the parent, since it has a mask
1774 // applied to it.
1775 EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(),
1776 occlusion.occlusion_from_inside_target().ToString());
1777 }
[email protected]94f206c12012-08-25 00:09:141778};
1779
[email protected]96baf3e2012-10-22 23:09:551780ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask);
[email protected]94f206c12012-08-25 00:09:141781
[email protected]a27cbde2013-03-23 22:01:491782template <class Types>
[email protected]ca2902e92013-03-28 01:45:351783class OcclusionTrackerTestOpaqueContentsRegionEmpty
1784 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491785 protected:
[email protected]ca2902e92013-03-28 01:45:351786 explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491787 : OcclusionTrackerTest<Types>(opaque_layers) {}
1788 void RunMyTest() {
1789 typename Types::ContentLayerType* parent = this->CreateRoot(
1790 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1791 typename Types::ContentLayerType* layer =
1792 this->CreateDrawingSurface(parent,
1793 this->identity_matrix,
1794 gfx::PointF(),
1795 gfx::Size(200, 200),
1796 false);
1797 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141798
[email protected]a27cbde2013-03-23 22:01:491799 TestOcclusionTrackerWithClip<typename Types::LayerType,
1800 typename Types::RenderSurfaceType> occlusion(
1801 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:221802 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141803
[email protected]a27cbde2013-03-23 22:01:491804 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
1805 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
1806 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
1807 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141808
[email protected]d002dd02013-03-27 07:40:401809 this->LeaveLayer(layer, &occlusion);
1810 this->VisitContributingSurface(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221811 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141812
[email protected]a27cbde2013-03-23 22:01:491813 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1814 }
[email protected]94f206c12012-08-25 00:09:141815};
1816
[email protected]96baf3e2012-10-22 23:09:551817MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141818
[email protected]a27cbde2013-03-23 22:01:491819template <class Types>
[email protected]ca2902e92013-03-28 01:45:351820class OcclusionTrackerTestOpaqueContentsRegionNonEmpty
1821 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491822 protected:
[email protected]ca2902e92013-03-28 01:45:351823 explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491824 : OcclusionTrackerTest<Types>(opaque_layers) {}
1825 void RunMyTest() {
1826 typename Types::ContentLayerType* parent = this->CreateRoot(
1827 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1828 typename Types::ContentLayerType* layer =
1829 this->CreateDrawingLayer(parent,
1830 this->identity_matrix,
1831 gfx::PointF(100.f, 100.f),
1832 gfx::Size(200, 200),
1833 false);
1834 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141835 {
[email protected]a27cbde2013-03-23 22:01:491836 TestOcclusionTrackerWithClip<typename Types::LayerType,
1837 typename Types::RenderSurfaceType> occlusion(
1838 gfx::Rect(0, 0, 1000, 1000));
1839 layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:141840
[email protected]a27cbde2013-03-23 22:01:491841 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401842 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221843 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141844
[email protected]a27cbde2013-03-23 22:01:491845 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
1846 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141847
[email protected]a27cbde2013-03-23 22:01:491848 EXPECT_FALSE(
1849 occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1850 EXPECT_TRUE(
1851 occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1852 EXPECT_FALSE(
1853 occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
[email protected]94f206c12012-08-25 00:09:141854 }
[email protected]a27cbde2013-03-23 22:01:491855 {
1856 TestOcclusionTrackerWithClip<typename Types::LayerType,
1857 typename Types::RenderSurfaceType> occlusion(
1858 gfx::Rect(0, 0, 1000, 1000));
1859 layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
1860
1861 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401862 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221863 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491864
1865 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(),
1866 occlusion.occlusion_from_inside_target().ToString());
1867
1868 EXPECT_FALSE(
1869 occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1870 EXPECT_FALSE(
1871 occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1872 EXPECT_TRUE(
1873 occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
1874 }
1875 {
1876 TestOcclusionTrackerWithClip<typename Types::LayerType,
1877 typename Types::RenderSurfaceType> occlusion(
1878 gfx::Rect(0, 0, 1000, 1000));
1879 layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
1880
1881 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401882 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221883 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491884
1885 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
1886 occlusion.occlusion_from_inside_target().ToString());
1887
1888 EXPECT_FALSE(
1889 occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
1890 EXPECT_FALSE(
1891 occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
1892 EXPECT_FALSE(
1893 occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
1894 }
1895 }
[email protected]94f206c12012-08-25 00:09:141896};
1897
[email protected]96baf3e2012-10-22 23:09:551898MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141899
[email protected]a27cbde2013-03-23 22:01:491900template <class Types>
[email protected]96baf3e2012-10-22 23:09:551901class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491902 protected:
[email protected]ca2902e92013-03-28 01:45:351903 explicit OcclusionTrackerTest3dTransform(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491904 : OcclusionTrackerTest<Types>(opaque_layers) {}
1905 void RunMyTest() {
1906 gfx::Transform transform;
1907 transform.RotateAboutYAxis(30.0);
[email protected]94f206c12012-08-25 00:09:141908
[email protected]a27cbde2013-03-23 22:01:491909 typename Types::ContentLayerType* parent = this->CreateRoot(
1910 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1911 typename Types::LayerType* container = this->CreateLayer(
1912 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1913 typename Types::ContentLayerType* layer =
1914 this->CreateDrawingLayer(container,
1915 transform,
1916 gfx::PointF(100.f, 100.f),
1917 gfx::Size(200, 200),
1918 true);
1919 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141920
[email protected]a27cbde2013-03-23 22:01:491921 TestOcclusionTrackerWithClip<typename Types::LayerType,
1922 typename Types::RenderSurfaceType> occlusion(
1923 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:221924 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141925
[email protected]a27cbde2013-03-23 22:01:491926 // The layer is rotated in 3d but without preserving 3d, so it only gets
1927 // resized.
1928 EXPECT_RECT_EQ(
1929 gfx::Rect(0, 0, 200, 200),
1930 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
1931 }
[email protected]94f206c12012-08-25 00:09:141932};
1933
[email protected]96baf3e2012-10-22 23:09:551934MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform);
[email protected]94f206c12012-08-25 00:09:141935
[email protected]a27cbde2013-03-23 22:01:491936template <class Types>
[email protected]ca2902e92013-03-28 01:45:351937class OcclusionTrackerTestUnsorted3dLayers
1938 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491939 protected:
[email protected]ca2902e92013-03-28 01:45:351940 explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491941 : OcclusionTrackerTest<Types>(opaque_layers) {}
1942 void RunMyTest() {
1943 // Currently, The main thread layer iterator does not iterate over 3d items
1944 // in sorted order, because layer sorting is not performed on the main
1945 // thread. Because of this, the occlusion tracker cannot assume that a 3d
1946 // layer occludes other layers that have not yet been iterated over. For
1947 // now, the expected behavior is that a 3d layer simply does not add any
1948 // occlusion to the occlusion tracker.
[email protected]94f206c12012-08-25 00:09:141949
[email protected]a27cbde2013-03-23 22:01:491950 gfx::Transform translation_to_front;
1951 translation_to_front.Translate3d(0.0, 0.0, -10.0);
1952 gfx::Transform translation_to_back;
1953 translation_to_front.Translate3d(0.0, 0.0, -100.0);
[email protected]94f206c12012-08-25 00:09:141954
[email protected]a27cbde2013-03-23 22:01:491955 typename Types::ContentLayerType* parent = this->CreateRoot(
1956 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1957 typename Types::ContentLayerType* child1 = this->CreateDrawingLayer(
1958 parent, translation_to_back, gfx::PointF(), gfx::Size(100, 100), true);
1959 typename Types::ContentLayerType* child2 =
1960 this->CreateDrawingLayer(parent,
1961 translation_to_front,
1962 gfx::PointF(50.f, 50.f),
1963 gfx::Size(100, 100),
1964 true);
[email protected]56fffdd2014-02-11 19:50:571965 parent->SetShouldFlattenTransform(false);
1966 parent->SetIs3dSorted(true);
1967 child1->SetIs3dSorted(true);
1968 child2->SetIs3dSorted(true);
[email protected]94f206c12012-08-25 00:09:141969
[email protected]a27cbde2013-03-23 22:01:491970 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141971
[email protected]a27cbde2013-03-23 22:01:491972 TestOcclusionTrackerWithClip<typename Types::LayerType,
1973 typename Types::RenderSurfaceType> occlusion(
1974 gfx::Rect(0, 0, 1000, 1000));
[email protected]d002dd02013-03-27 07:40:401975 this->VisitLayer(child2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491976 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1977 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141978
[email protected]d002dd02013-03-27 07:40:401979 this->VisitLayer(child1, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491980 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1981 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1982 }
[email protected]94f206c12012-08-25 00:09:141983};
1984
[email protected]a27cbde2013-03-23 22:01:491985// This test will have different layer ordering on the impl thread; the test
1986// will only work on the main thread.
[email protected]96baf3e2012-10-22 23:09:551987MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
[email protected]94f206c12012-08-25 00:09:141988
[email protected]a27cbde2013-03-23 22:01:491989template <class Types>
[email protected]ca2902e92013-03-28 01:45:351990class OcclusionTrackerTestPerspectiveTransform
1991 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:491992 protected:
[email protected]ca2902e92013-03-28 01:45:351993 explicit OcclusionTrackerTestPerspectiveTransform(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:491994 : OcclusionTrackerTest<Types>(opaque_layers) {}
1995 void RunMyTest() {
1996 gfx::Transform transform;
1997 transform.Translate(150.0, 150.0);
1998 transform.ApplyPerspectiveDepth(400.0);
1999 transform.RotateAboutXAxis(-30.0);
2000 transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:142001
[email protected]a27cbde2013-03-23 22:01:492002 typename Types::ContentLayerType* parent = this->CreateRoot(
2003 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2004 typename Types::LayerType* container = this->CreateLayer(
2005 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2006 typename Types::ContentLayerType* layer =
2007 this->CreateDrawingLayer(container,
2008 transform,
2009 gfx::PointF(100.f, 100.f),
2010 gfx::Size(200, 200),
2011 true);
[email protected]56fffdd2014-02-11 19:50:572012 container->SetShouldFlattenTransform(false);
2013 container->SetIs3dSorted(true);
2014 layer->SetIs3dSorted(true);
2015 layer->SetShouldFlattenTransform(false);
2016
[email protected]a27cbde2013-03-23 22:01:492017 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142018
[email protected]a27cbde2013-03-23 22:01:492019 TestOcclusionTrackerWithClip<typename Types::LayerType,
2020 typename Types::RenderSurfaceType> occlusion(
2021 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:222022 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:142023
[email protected]a27cbde2013-03-23 22:01:492024 EXPECT_RECT_EQ(
2025 gfx::Rect(0, 0, 200, 200),
2026 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
2027 }
[email protected]94f206c12012-08-25 00:09:142028};
2029
[email protected]a27cbde2013-03-23 22:01:492030// This test requires accumulating occlusion of 3d layers, which are skipped by
2031// the occlusion tracker on the main thread. So this test should run on the impl
2032// thread.
[email protected]96baf3e2012-10-22 23:09:552033IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransform);
[email protected]a27cbde2013-03-23 22:01:492034template <class Types>
[email protected]ca2902e92013-03-28 01:45:352035class OcclusionTrackerTestPerspectiveTransformBehindCamera
2036 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492037 protected:
[email protected]ca2902e92013-03-28 01:45:352038 explicit OcclusionTrackerTestPerspectiveTransformBehindCamera(
2039 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492040 : OcclusionTrackerTest<Types>(opaque_layers) {}
2041 void RunMyTest() {
2042 // This test is based on the platform/chromium/compositing/3d-corners.html
2043 // layout test.
2044 gfx::Transform transform;
2045 transform.Translate(250.0, 50.0);
2046 transform.ApplyPerspectiveDepth(10.0);
2047 transform.Translate(-250.0, -50.0);
2048 transform.Translate(250.0, 50.0);
2049 transform.RotateAboutXAxis(-167.0);
2050 transform.Translate(-250.0, -50.0);
[email protected]94f206c12012-08-25 00:09:142051
[email protected]a27cbde2013-03-23 22:01:492052 typename Types::ContentLayerType* parent = this->CreateRoot(
2053 this->identity_matrix, gfx::PointF(), gfx::Size(500, 100));
2054 typename Types::LayerType* container = this->CreateLayer(
2055 parent, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
2056 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
2057 container, transform, gfx::PointF(), gfx::Size(500, 500), true);
[email protected]56fffdd2014-02-11 19:50:572058 container->SetShouldFlattenTransform(false);
2059 container->SetIs3dSorted(true);
2060 layer->SetShouldFlattenTransform(false);
2061 layer->SetIs3dSorted(true);
[email protected]a27cbde2013-03-23 22:01:492062 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142063
[email protected]a27cbde2013-03-23 22:01:492064 TestOcclusionTrackerWithClip<typename Types::LayerType,
2065 typename Types::RenderSurfaceType> occlusion(
2066 gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:222067 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:142068
[email protected]a27cbde2013-03-23 22:01:492069 // The bottom 11 pixel rows of this layer remain visible inside the
2070 // container, after translation to the target surface. When translated back,
2071 // this will include many more pixels but must include at least the bottom
2072 // 11 rows.
2073 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
[email protected]cfc2d2d2013-10-04 23:26:452074 layer, gfx::Rect(0, 26, 500, 474)).
2075 Contains(gfx::Rect(0, 489, 500, 11)));
[email protected]a27cbde2013-03-23 22:01:492076 }
[email protected]94f206c12012-08-25 00:09:142077};
2078
[email protected]a27cbde2013-03-23 22:01:492079// This test requires accumulating occlusion of 3d layers, which are skipped by
2080// the occlusion tracker on the main thread. So this test should run on the impl
2081// thread.
[email protected]96baf3e2012-10-22 23:09:552082IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransformBehindCamera);
[email protected]94f206c12012-08-25 00:09:142083
[email protected]a27cbde2013-03-23 22:01:492084template <class Types>
[email protected]ca2902e92013-03-28 01:45:352085class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude
2086 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492087 protected:
[email protected]ca2902e92013-03-28 01:45:352088 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(
2089 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492090 : OcclusionTrackerTest<Types>(opaque_layers) {}
2091 void RunMyTest() {
2092 gfx::Transform transform;
2093 transform.Translate(50.0, 50.0);
2094 transform.ApplyPerspectiveDepth(100.0);
2095 transform.Translate3d(0.0, 0.0, 110.0);
2096 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:142097
[email protected]a27cbde2013-03-23 22:01:492098 typename Types::ContentLayerType* parent = this->CreateRoot(
2099 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
2100 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
2101 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
[email protected]56fffdd2014-02-11 19:50:572102 parent->SetShouldFlattenTransform(false);
2103 parent->SetIs3dSorted(true);
2104 layer->SetShouldFlattenTransform(false);
2105 layer->SetIs3dSorted(true);
[email protected]a27cbde2013-03-23 22:01:492106 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142107
[email protected]a27cbde2013-03-23 22:01:492108 TestOcclusionTrackerWithClip<typename Types::LayerType,
2109 typename Types::RenderSurfaceType> occlusion(
2110 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142111
[email protected]a27cbde2013-03-23 22:01:492112 // The |layer| is entirely behind the camera and should not occlude.
[email protected]d002dd02013-03-27 07:40:402113 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222114 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492115 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
2116 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
2117 }
[email protected]94f206c12012-08-25 00:09:142118};
2119
[email protected]a27cbde2013-03-23 22:01:492120// This test requires accumulating occlusion of 3d layers, which are skipped by
2121// the occlusion tracker on the main thread. So this test should run on the impl
2122// thread.
[email protected]96baf3e2012-10-22 23:09:552123IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude);
[email protected]94f206c12012-08-25 00:09:142124
[email protected]a27cbde2013-03-23 22:01:492125template <class Types>
[email protected]ca2902e92013-03-28 01:45:352126class OcclusionTrackerTestLargePixelsOccludeInsideClipRect
2127 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492128 protected:
[email protected]ca2902e92013-03-28 01:45:352129 explicit OcclusionTrackerTestLargePixelsOccludeInsideClipRect(
2130 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492131 : OcclusionTrackerTest<Types>(opaque_layers) {}
2132 void RunMyTest() {
2133 gfx::Transform transform;
2134 transform.Translate(50.0, 50.0);
2135 transform.ApplyPerspectiveDepth(100.0);
2136 transform.Translate3d(0.0, 0.0, 99.0);
2137 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:142138
[email protected]a27cbde2013-03-23 22:01:492139 typename Types::ContentLayerType* parent = this->CreateRoot(
2140 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
2141 parent->SetMasksToBounds(true);
2142 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
2143 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
[email protected]56fffdd2014-02-11 19:50:572144 parent->SetShouldFlattenTransform(false);
2145 parent->SetIs3dSorted(true);
2146 layer->SetShouldFlattenTransform(false);
2147 layer->SetIs3dSorted(true);
[email protected]a27cbde2013-03-23 22:01:492148 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142149
[email protected]a27cbde2013-03-23 22:01:492150 TestOcclusionTrackerWithClip<typename Types::LayerType,
2151 typename Types::RenderSurfaceType> occlusion(
2152 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142153
[email protected]a27cbde2013-03-23 22:01:492154 // This is very close to the camera, so pixels in its visible_content_rect()
2155 // will actually go outside of the layer's clip rect. Ensure that those
2156 // pixels don't occlude things outside the clip rect.
[email protected]d002dd02013-03-27 07:40:402157 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222158 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492159 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2160 occlusion.occlusion_from_inside_target().ToString());
2161 EXPECT_EQ(gfx::Rect().ToString(),
2162 occlusion.occlusion_from_outside_target().ToString());
2163 }
[email protected]94f206c12012-08-25 00:09:142164};
2165
[email protected]a27cbde2013-03-23 22:01:492166// This test requires accumulating occlusion of 3d layers, which are skipped by
2167// the occlusion tracker on the main thread. So this test should run on the impl
2168// thread.
[email protected]96baf3e2012-10-22 23:09:552169IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect);
[email protected]94f206c12012-08-25 00:09:142170
[email protected]a27cbde2013-03-23 22:01:492171template <class Types>
[email protected]ca2902e92013-03-28 01:45:352172class OcclusionTrackerTestAnimationOpacity1OnMainThread
2173 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492174 protected:
[email protected]ca2902e92013-03-28 01:45:352175 explicit OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492176 : OcclusionTrackerTest<Types>(opaque_layers) {}
2177 void RunMyTest() {
2178 // parent
2179 // +--layer
2180 // +--surface
2181 // | +--surface_child
2182 // | +--surface_child2
2183 // +--parent2
2184 // +--topmost
[email protected]c8d71552013-01-22 03:43:022185
[email protected]a27cbde2013-03-23 22:01:492186 typename Types::ContentLayerType* parent = this->CreateRoot(
2187 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2188 typename Types::ContentLayerType* layer =
2189 this->CreateDrawingLayer(parent,
2190 this->identity_matrix,
2191 gfx::PointF(),
2192 gfx::Size(300, 300),
2193 true);
2194 typename Types::ContentLayerType* surface =
2195 this->CreateDrawingSurface(parent,
2196 this->identity_matrix,
2197 gfx::PointF(),
2198 gfx::Size(300, 300),
2199 true);
2200 typename Types::ContentLayerType* surface_child =
2201 this->CreateDrawingLayer(surface,
2202 this->identity_matrix,
2203 gfx::PointF(),
2204 gfx::Size(200, 300),
2205 true);
2206 typename Types::ContentLayerType* surface_child2 =
2207 this->CreateDrawingLayer(surface,
2208 this->identity_matrix,
2209 gfx::PointF(),
2210 gfx::Size(100, 300),
2211 true);
2212 typename Types::ContentLayerType* parent2 =
2213 this->CreateDrawingLayer(parent,
2214 this->identity_matrix,
2215 gfx::PointF(),
2216 gfx::Size(300, 300),
2217 false);
2218 typename Types::ContentLayerType* topmost =
2219 this->CreateDrawingLayer(parent,
2220 this->identity_matrix,
2221 gfx::PointF(250.f, 0.f),
2222 gfx::Size(50, 300),
2223 true);
[email protected]94f206c12012-08-25 00:09:142224
[email protected]a27cbde2013-03-23 22:01:492225 AddOpacityTransitionToController(
2226 layer->layer_animation_controller(), 10.0, 0.f, 1.f, false);
2227 AddOpacityTransitionToController(
2228 surface->layer_animation_controller(), 10.0, 0.f, 1.f, false);
2229 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142230
[email protected]a27cbde2013-03-23 22:01:492231 EXPECT_TRUE(layer->draw_opacity_is_animating());
2232 EXPECT_FALSE(surface->draw_opacity_is_animating());
2233 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:142234
[email protected]a27cbde2013-03-23 22:01:492235 TestOcclusionTrackerWithClip<typename Types::LayerType,
2236 typename Types::RenderSurfaceType> occlusion(
2237 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142238
[email protected]d002dd02013-03-27 07:40:402239 this->VisitLayer(topmost, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222240 this->EnterLayer(parent2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492241 // This occlusion will affect all surfaces.
2242 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2243 occlusion.occlusion_from_inside_target().ToString());
2244 EXPECT_EQ(gfx::Rect().ToString(),
2245 occlusion.occlusion_from_outside_target().ToString());
2246 EXPECT_EQ(gfx::Rect(0, 0, 250, 300).ToString(),
2247 occlusion.UnoccludedLayerContentRect(
2248 parent2, gfx::Rect(0, 0, 300, 300)).ToString());
[email protected]d002dd02013-03-27 07:40:402249 this->LeaveLayer(parent2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142250
[email protected]d002dd02013-03-27 07:40:402251 this->VisitLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222252 this->EnterLayer(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492253 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2254 occlusion.occlusion_from_inside_target().ToString());
2255 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2256 occlusion.occlusion_from_outside_target().ToString());
2257 EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300),
2258 occlusion.UnoccludedLayerContentRect(
2259 surface_child, gfx::Rect(0, 0, 200, 300)));
[email protected]d002dd02013-03-27 07:40:402260 this->LeaveLayer(surface_child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222261 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492262 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
2263 occlusion.occlusion_from_inside_target().ToString());
2264 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2265 occlusion.occlusion_from_outside_target().ToString());
2266 EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300),
2267 occlusion.UnoccludedLayerContentRect(
2268 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402269 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142270
[email protected]e47b0a0a2013-11-18 23:26:222271 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492272 // Occlusion within the surface is lost when leaving the animating surface.
2273 EXPECT_EQ(gfx::Rect().ToString(),
2274 occlusion.occlusion_from_inside_target().ToString());
2275 EXPECT_EQ(gfx::Rect().ToString(),
2276 occlusion.occlusion_from_outside_target().ToString());
2277 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2278 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152279 surface, false, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402280 this->LeaveContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142281
[email protected]a27cbde2013-03-23 22:01:492282 // Occlusion from outside the animating surface still exists.
2283 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2284 occlusion.occlusion_from_inside_target().ToString());
2285 EXPECT_EQ(gfx::Rect().ToString(),
2286 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:022287
[email protected]d002dd02013-03-27 07:40:402288 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222289 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:142290
[email protected]a27cbde2013-03-23 22:01:492291 // Occlusion is not added for the animating |layer|.
2292 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2293 occlusion.UnoccludedLayerContentRect(
2294 parent, gfx::Rect(0, 0, 300, 300)));
2295 }
[email protected]94f206c12012-08-25 00:09:142296};
2297
[email protected]96baf3e2012-10-22 23:09:552298MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread);
[email protected]94f206c12012-08-25 00:09:142299
[email protected]a27cbde2013-03-23 22:01:492300template <class Types>
[email protected]ca2902e92013-03-28 01:45:352301class OcclusionTrackerTestAnimationOpacity0OnMainThread
2302 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492303 protected:
[email protected]ca2902e92013-03-28 01:45:352304 explicit OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492305 : OcclusionTrackerTest<Types>(opaque_layers) {}
2306 void RunMyTest() {
2307 typename Types::ContentLayerType* parent = this->CreateRoot(
2308 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2309 typename Types::ContentLayerType* layer =
2310 this->CreateDrawingLayer(parent,
2311 this->identity_matrix,
2312 gfx::PointF(),
2313 gfx::Size(300, 300),
2314 true);
2315 typename Types::ContentLayerType* surface =
2316 this->CreateDrawingSurface(parent,
2317 this->identity_matrix,
2318 gfx::PointF(),
2319 gfx::Size(300, 300),
2320 true);
2321 typename Types::ContentLayerType* surface_child =
2322 this->CreateDrawingLayer(surface,
2323 this->identity_matrix,
2324 gfx::PointF(),
2325 gfx::Size(200, 300),
2326 true);
2327 typename Types::ContentLayerType* surface_child2 =
2328 this->CreateDrawingLayer(surface,
2329 this->identity_matrix,
2330 gfx::PointF(),
2331 gfx::Size(100, 300),
2332 true);
2333 typename Types::ContentLayerType* parent2 =
2334 this->CreateDrawingLayer(parent,
2335 this->identity_matrix,
2336 gfx::PointF(),
2337 gfx::Size(300, 300),
2338 false);
2339 typename Types::ContentLayerType* topmost =
2340 this->CreateDrawingLayer(parent,
2341 this->identity_matrix,
2342 gfx::PointF(250.f, 0.f),
2343 gfx::Size(50, 300),
2344 true);
[email protected]94f206c12012-08-25 00:09:142345
[email protected]a27cbde2013-03-23 22:01:492346 AddOpacityTransitionToController(
2347 layer->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2348 AddOpacityTransitionToController(
2349 surface->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2350 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142351
[email protected]a27cbde2013-03-23 22:01:492352 EXPECT_TRUE(layer->draw_opacity_is_animating());
2353 EXPECT_FALSE(surface->draw_opacity_is_animating());
2354 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
[email protected]94f206c12012-08-25 00:09:142355
[email protected]a27cbde2013-03-23 22:01:492356 TestOcclusionTrackerWithClip<typename Types::LayerType,
2357 typename Types::RenderSurfaceType> occlusion(
2358 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142359
[email protected]d002dd02013-03-27 07:40:402360 this->VisitLayer(topmost, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222361 this->EnterLayer(parent2, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492362 // This occlusion will affect all surfaces.
2363 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2364 occlusion.occlusion_from_inside_target().ToString());
2365 EXPECT_EQ(gfx::Rect().ToString(),
2366 occlusion.occlusion_from_outside_target().ToString());
2367 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2368 occlusion.UnoccludedLayerContentRect(
2369 parent, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402370 this->LeaveLayer(parent2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142371
[email protected]d002dd02013-03-27 07:40:402372 this->VisitLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222373 this->EnterLayer(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492374 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2375 occlusion.occlusion_from_inside_target().ToString());
2376 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2377 occlusion.occlusion_from_outside_target().ToString());
2378 EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300),
2379 occlusion.UnoccludedLayerContentRect(
2380 surface_child, gfx::Rect(0, 0, 200, 300)));
[email protected]d002dd02013-03-27 07:40:402381 this->LeaveLayer(surface_child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222382 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492383 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
2384 occlusion.occlusion_from_inside_target().ToString());
2385 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2386 occlusion.occlusion_from_outside_target().ToString());
2387 EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300),
2388 occlusion.UnoccludedLayerContentRect(
2389 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402390 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142391
[email protected]e47b0a0a2013-11-18 23:26:222392 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492393 // Occlusion within the surface is lost when leaving the animating surface.
2394 EXPECT_EQ(gfx::Rect().ToString(),
2395 occlusion.occlusion_from_inside_target().ToString());
2396 EXPECT_EQ(gfx::Rect().ToString(),
2397 occlusion.occlusion_from_outside_target().ToString());
2398 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2399 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152400 surface, false, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402401 this->LeaveContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142402
[email protected]a27cbde2013-03-23 22:01:492403 // Occlusion from outside the animating surface still exists.
2404 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2405 occlusion.occlusion_from_inside_target().ToString());
2406 EXPECT_EQ(gfx::Rect().ToString(),
2407 occlusion.occlusion_from_outside_target().ToString());
[email protected]c8d71552013-01-22 03:43:022408
[email protected]d002dd02013-03-27 07:40:402409 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222410 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:142411
[email protected]a27cbde2013-03-23 22:01:492412 // Occlusion is not added for the animating |layer|.
2413 EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300),
2414 occlusion.UnoccludedLayerContentRect(
2415 parent, gfx::Rect(0, 0, 300, 300)));
2416 }
[email protected]94f206c12012-08-25 00:09:142417};
2418
[email protected]96baf3e2012-10-22 23:09:552419MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread);
[email protected]94f206c12012-08-25 00:09:142420
[email protected]a27cbde2013-03-23 22:01:492421template <class Types>
[email protected]ca2902e92013-03-28 01:45:352422class OcclusionTrackerTestAnimationTranslateOnMainThread
2423 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492424 protected:
[email protected]ca2902e92013-03-28 01:45:352425 explicit OcclusionTrackerTestAnimationTranslateOnMainThread(
2426 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492427 : OcclusionTrackerTest<Types>(opaque_layers) {}
2428 void RunMyTest() {
2429 typename Types::ContentLayerType* parent = this->CreateRoot(
2430 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2431 typename Types::ContentLayerType* layer =
2432 this->CreateDrawingLayer(parent,
2433 this->identity_matrix,
2434 gfx::PointF(),
2435 gfx::Size(300, 300),
2436 true);
2437 typename Types::ContentLayerType* surface =
2438 this->CreateDrawingSurface(parent,
2439 this->identity_matrix,
2440 gfx::PointF(),
2441 gfx::Size(300, 300),
2442 true);
2443 typename Types::ContentLayerType* surface_child =
2444 this->CreateDrawingLayer(surface,
2445 this->identity_matrix,
2446 gfx::PointF(),
2447 gfx::Size(200, 300),
2448 true);
2449 typename Types::ContentLayerType* surface_child2 =
2450 this->CreateDrawingLayer(surface,
2451 this->identity_matrix,
2452 gfx::PointF(),
2453 gfx::Size(100, 300),
2454 true);
2455 typename Types::ContentLayerType* surface2 = this->CreateDrawingSurface(
2456 parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 300), true);
[email protected]94f206c12012-08-25 00:09:142457
[email protected]a27cbde2013-03-23 22:01:492458 AddAnimatedTransformToController(
2459 layer->layer_animation_controller(), 10.0, 30, 0);
2460 AddAnimatedTransformToController(
2461 surface->layer_animation_controller(), 10.0, 30, 0);
2462 AddAnimatedTransformToController(
2463 surface_child->layer_animation_controller(), 10.0, 30, 0);
2464 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142465
[email protected]a27cbde2013-03-23 22:01:492466 EXPECT_TRUE(layer->draw_transform_is_animating());
2467 EXPECT_TRUE(layer->screen_space_transform_is_animating());
2468 EXPECT_TRUE(
2469 surface->render_surface()->target_surface_transforms_are_animating());
2470 EXPECT_TRUE(
2471 surface->render_surface()->screen_space_transforms_are_animating());
2472 // The surface owning layer doesn't animate against its own surface.
2473 EXPECT_FALSE(surface->draw_transform_is_animating());
2474 EXPECT_TRUE(surface->screen_space_transform_is_animating());
2475 EXPECT_TRUE(surface_child->draw_transform_is_animating());
2476 EXPECT_TRUE(surface_child->screen_space_transform_is_animating());
[email protected]94f206c12012-08-25 00:09:142477
[email protected]a27cbde2013-03-23 22:01:492478 TestOcclusionTrackerWithClip<typename Types::LayerType,
2479 typename Types::RenderSurfaceType> occlusion(
2480 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142481
[email protected]d002dd02013-03-27 07:40:402482 this->VisitLayer(surface2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222483 this->EnterContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142484
[email protected]a27cbde2013-03-23 22:01:492485 EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(),
2486 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142487
[email protected]d002dd02013-03-27 07:40:402488 this->LeaveContributingSurface(surface2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222489 this->EnterLayer(surface_child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142490
[email protected]a27cbde2013-03-23 22:01:492491 // surface_child2 is moving in screen space but not relative to its target,
2492 // so occlusion should happen in its target space only. It also means that
2493 // things occluding from outside the target (e.g. surface2) cannot occlude
2494 // this layer.
2495 EXPECT_EQ(gfx::Rect().ToString(),
2496 occlusion.occlusion_from_outside_target().ToString());
[email protected]ccb1c9a2012-12-17 03:53:192497
[email protected]a27cbde2013-03-23 22:01:492498 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 300),
2499 occlusion.UnoccludedLayerContentRect(
2500 surface_child2, gfx::Rect(0, 0, 100, 300)));
2501 EXPECT_FALSE(
2502 occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 50, 300)));
[email protected]94f206c12012-08-25 00:09:142503
[email protected]d002dd02013-03-27 07:40:402504 this->LeaveLayer(surface_child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222505 this->EnterLayer(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492506 EXPECT_FALSE(
2507 occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 100, 300)));
2508 EXPECT_EQ(gfx::Rect().ToString(),
2509 occlusion.occlusion_from_outside_target().ToString());
2510 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2511 occlusion.occlusion_from_inside_target().ToString());
2512 EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300),
2513 occlusion.UnoccludedLayerContentRect(
2514 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142515
[email protected]a27cbde2013-03-23 22:01:492516 // The surface_child is occluded by the surface_child2, but is moving
2517 // relative its target, so it can't be occluded.
2518 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 300),
2519 occlusion.UnoccludedLayerContentRect(
2520 surface_child, gfx::Rect(0, 0, 200, 300)));
2521 EXPECT_FALSE(
2522 occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 50, 300)));
[email protected]94f206c12012-08-25 00:09:142523
[email protected]d002dd02013-03-27 07:40:402524 this->LeaveLayer(surface_child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:222525 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492526 // The surface_child is moving in screen space but not relative to its
2527 // target, so occlusion should happen from within the target only.
2528 EXPECT_EQ(gfx::Rect().ToString(),
2529 occlusion.occlusion_from_outside_target().ToString());
2530 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2531 occlusion.occlusion_from_inside_target().ToString());
2532 EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300),
2533 occlusion.UnoccludedLayerContentRect(
2534 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142535
[email protected]d002dd02013-03-27 07:40:402536 this->LeaveLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492537 // The surface's owning layer is moving in screen space but not relative to
2538 // its target, so occlusion should happen within the target only.
2539 EXPECT_EQ(gfx::Rect().ToString(),
2540 occlusion.occlusion_from_outside_target().ToString());
2541 EXPECT_EQ(gfx::Rect(0, 0, 300, 300).ToString(),
2542 occlusion.occlusion_from_inside_target().ToString());
2543 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2544 occlusion.UnoccludedLayerContentRect(
2545 surface, gfx::Rect(0, 0, 300, 300)));
[email protected]94f206c12012-08-25 00:09:142546
[email protected]e47b0a0a2013-11-18 23:26:222547 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492548 // The contributing |surface| is animating so it can't be occluded.
2549 EXPECT_RECT_EQ(gfx::Rect(0, 0, 300, 300),
2550 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152551 surface, false, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402552 this->LeaveContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142553
[email protected]e47b0a0a2013-11-18 23:26:222554 this->EnterLayer(layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492555 // The |surface| is moving in the screen and in its target, so all occlusion
2556 // within the surface is lost when leaving it.
2557 EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300),
2558 occlusion.UnoccludedLayerContentRect(
2559 parent, gfx::Rect(0, 0, 300, 300)));
[email protected]d002dd02013-03-27 07:40:402560 this->LeaveLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:142561
[email protected]e47b0a0a2013-11-18 23:26:222562 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492563 // The |layer| is animating in the screen and in its target, so no occlusion
2564 // is added.
2565 EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300),
2566 occlusion.UnoccludedLayerContentRect(
2567 parent, gfx::Rect(0, 0, 300, 300)));
2568 }
[email protected]94f206c12012-08-25 00:09:142569};
2570
[email protected]96baf3e2012-10-22 23:09:552571MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread);
[email protected]94f206c12012-08-25 00:09:142572
[email protected]a27cbde2013-03-23 22:01:492573template <class Types>
[email protected]ca2902e92013-03-28 01:45:352574class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent
2575 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492576 protected:
[email protected]ca2902e92013-03-28 01:45:352577 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(
2578 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492579 : OcclusionTrackerTest<Types>(opaque_layers) {}
2580 void RunMyTest() {
2581 gfx::Transform surface_transform;
2582 surface_transform.Translate(300.0, 300.0);
2583 surface_transform.Scale(2.0, 2.0);
2584 surface_transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:142585
[email protected]a27cbde2013-03-23 22:01:492586 typename Types::ContentLayerType* parent = this->CreateRoot(
2587 this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
2588 typename Types::ContentLayerType* surface = this->CreateDrawingSurface(
2589 parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false);
2590 typename Types::ContentLayerType* surface2 =
2591 this->CreateDrawingSurface(parent,
2592 this->identity_matrix,
2593 gfx::PointF(50.f, 50.f),
2594 gfx::Size(300, 300),
2595 false);
2596 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
2597 surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
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]d002dd02013-03-27 07:40:402604 this->VisitLayer(surface2, &occlusion);
2605 this->VisitContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:142606
[email protected]a27cbde2013-03-23 22:01:492607 EXPECT_EQ(gfx::Rect().ToString(),
2608 occlusion.occlusion_from_outside_target().ToString());
2609 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(),
2610 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142611
[email protected]a27cbde2013-03-23 22:01:492612 // Clear any stored occlusion.
2613 occlusion.set_occlusion_from_outside_target(Region());
2614 occlusion.set_occlusion_from_inside_target(Region());
[email protected]94f206c12012-08-25 00:09:142615
[email protected]d002dd02013-03-27 07:40:402616 this->VisitLayer(surface, &occlusion);
2617 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142618
[email protected]a27cbde2013-03-23 22:01:492619 EXPECT_EQ(gfx::Rect().ToString(),
2620 occlusion.occlusion_from_outside_target().ToString());
2621 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(),
2622 occlusion.occlusion_from_inside_target().ToString());
2623 }
[email protected]94f206c12012-08-25 00:09:142624};
2625
[email protected]a27cbde2013-03-23 22:01:492626MAIN_AND_IMPL_THREAD_TEST(
2627 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:142628
[email protected]a27cbde2013-03-23 22:01:492629template <class Types>
[email protected]ca2902e92013-03-28 01:45:352630class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping
2631 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492632 protected:
[email protected]ca2902e92013-03-28 01:45:352633 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(
2634 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492635 : OcclusionTrackerTest<Types>(opaque_layers) {}
2636 void RunMyTest() {
2637 typename Types::ContentLayerType* parent = this->CreateRoot(
2638 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
2639 parent->SetMasksToBounds(true);
2640 typename Types::ContentLayerType* surface =
2641 this->CreateDrawingSurface(parent,
2642 this->identity_matrix,
2643 gfx::PointF(),
2644 gfx::Size(500, 300),
2645 false);
2646 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
2647 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142648
[email protected]a27cbde2013-03-23 22:01:492649 TestOcclusionTrackerWithClip<typename Types::LayerType,
2650 typename Types::RenderSurfaceType> occlusion(
2651 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142652
[email protected]d002dd02013-03-27 07:40:402653 this->VisitLayer(surface, &occlusion);
2654 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142655
[email protected]a27cbde2013-03-23 22:01:492656 EXPECT_EQ(gfx::Rect().ToString(),
2657 occlusion.occlusion_from_outside_target().ToString());
2658 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(),
2659 occlusion.occlusion_from_inside_target().ToString());
2660 }
[email protected]94f206c12012-08-25 00:09:142661};
2662
[email protected]a27cbde2013-03-23 22:01:492663MAIN_AND_IMPL_THREAD_TEST(
2664 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:142665
[email protected]a27cbde2013-03-23 22:01:492666template <class Types>
[email protected]96baf3e2012-10-22 23:09:552667class OcclusionTrackerTestReplicaOccluded : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492668 protected:
[email protected]ca2902e92013-03-28 01:45:352669 explicit OcclusionTrackerTestReplicaOccluded(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492670 : OcclusionTrackerTest<Types>(opaque_layers) {}
2671 void RunMyTest() {
2672 typename Types::ContentLayerType* parent = this->CreateRoot(
2673 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2674 typename Types::LayerType* surface =
2675 this->CreateDrawingSurface(parent,
2676 this->identity_matrix,
2677 gfx::PointF(),
2678 gfx::Size(100, 100),
2679 true);
2680 this->CreateReplicaLayer(surface,
2681 this->identity_matrix,
2682 gfx::PointF(0.f, 100.f),
2683 gfx::Size(100, 100));
2684 typename Types::LayerType* topmost =
2685 this->CreateDrawingLayer(parent,
2686 this->identity_matrix,
2687 gfx::PointF(0.f, 100.f),
2688 gfx::Size(100, 100),
2689 true);
2690 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142691
[email protected]a27cbde2013-03-23 22:01:492692 TestOcclusionTrackerWithClip<typename Types::LayerType,
2693 typename Types::RenderSurfaceType> occlusion(
2694 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142695
[email protected]a27cbde2013-03-23 22:01:492696 // |topmost| occludes the replica, but not the surface itself.
[email protected]d002dd02013-03-27 07:40:402697 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142698
[email protected]a27cbde2013-03-23 22:01:492699 EXPECT_EQ(gfx::Rect().ToString(),
2700 occlusion.occlusion_from_outside_target().ToString());
2701 EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(),
2702 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142703
[email protected]d002dd02013-03-27 07:40:402704 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142705
[email protected]66b52e12013-11-17 15:53:182706 // Render target with replica ignores occlusion from outside.
2707 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:492708 occlusion.occlusion_from_outside_target().ToString());
2709 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2710 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142711
[email protected]e47b0a0a2013-11-18 23:26:222712 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142713
[email protected]a27cbde2013-03-23 22:01:492714 // Surface is not occluded so it shouldn't think it is.
2715 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2716 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152717 surface, false, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492718 }
[email protected]94f206c12012-08-25 00:09:142719};
2720
[email protected]96baf3e2012-10-22 23:09:552721ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaOccluded);
[email protected]94f206c12012-08-25 00:09:142722
[email protected]a27cbde2013-03-23 22:01:492723template <class Types>
[email protected]ca2902e92013-03-28 01:45:352724class OcclusionTrackerTestSurfaceWithReplicaUnoccluded
2725 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492726 protected:
[email protected]ca2902e92013-03-28 01:45:352727 explicit OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492728 : OcclusionTrackerTest<Types>(opaque_layers) {}
2729 void RunMyTest() {
2730 typename Types::ContentLayerType* parent = this->CreateRoot(
2731 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2732 typename Types::LayerType* surface =
2733 this->CreateDrawingSurface(parent,
2734 this->identity_matrix,
2735 gfx::PointF(),
2736 gfx::Size(100, 100),
2737 true);
2738 this->CreateReplicaLayer(surface,
2739 this->identity_matrix,
2740 gfx::PointF(0.f, 100.f),
2741 gfx::Size(100, 100));
2742 typename Types::LayerType* topmost =
2743 this->CreateDrawingLayer(parent,
2744 this->identity_matrix,
2745 gfx::PointF(),
2746 gfx::Size(100, 110),
2747 true);
2748 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142749
[email protected]a27cbde2013-03-23 22:01:492750 TestOcclusionTrackerWithClip<typename Types::LayerType,
2751 typename Types::RenderSurfaceType> occlusion(
2752 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142753
[email protected]a27cbde2013-03-23 22:01:492754 // |topmost| occludes the surface, but not the entire surface's replica.
[email protected]d002dd02013-03-27 07:40:402755 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142756
[email protected]a27cbde2013-03-23 22:01:492757 EXPECT_EQ(gfx::Rect().ToString(),
2758 occlusion.occlusion_from_outside_target().ToString());
2759 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(),
2760 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142761
[email protected]d002dd02013-03-27 07:40:402762 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142763
[email protected]66b52e12013-11-17 15:53:182764 // Render target with replica ignores occlusion from outside.
2765 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:492766 occlusion.occlusion_from_outside_target().ToString());
2767 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2768 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142769
[email protected]e47b0a0a2013-11-18 23:26:222770 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142771
[email protected]a27cbde2013-03-23 22:01:492772 // Surface is occluded, but only the top 10px of the replica.
2773 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2774 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152775 surface, false, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492776 EXPECT_RECT_EQ(gfx::Rect(0, 10, 100, 90),
2777 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152778 surface, true, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492779 }
[email protected]94f206c12012-08-25 00:09:142780};
2781
[email protected]96baf3e2012-10-22 23:09:552782ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded);
[email protected]94f206c12012-08-25 00:09:142783
[email protected]a27cbde2013-03-23 22:01:492784template <class Types>
[email protected]ca2902e92013-03-28 01:45:352785class OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently
2786 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492787 protected:
[email protected]ca2902e92013-03-28 01:45:352788 explicit OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently(
2789 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492790 : OcclusionTrackerTest<Types>(opaque_layers) {}
2791 void RunMyTest() {
2792 typename Types::ContentLayerType* parent = this->CreateRoot(
2793 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2794 typename Types::LayerType* surface =
2795 this->CreateDrawingSurface(parent,
2796 this->identity_matrix,
2797 gfx::PointF(),
2798 gfx::Size(100, 100),
2799 true);
2800 this->CreateReplicaLayer(surface,
2801 this->identity_matrix,
2802 gfx::PointF(0.f, 100.f),
2803 gfx::Size(100, 100));
2804 typename Types::LayerType* over_surface = this->CreateDrawingLayer(
2805 parent, this->identity_matrix, gfx::PointF(), gfx::Size(40, 100), true);
2806 typename Types::LayerType* over_replica =
2807 this->CreateDrawingLayer(parent,
2808 this->identity_matrix,
2809 gfx::PointF(0.f, 100.f),
2810 gfx::Size(50, 100),
2811 true);
2812 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142813
[email protected]a27cbde2013-03-23 22:01:492814 TestOcclusionTrackerWithClip<typename Types::LayerType,
2815 typename Types::RenderSurfaceType> occlusion(
2816 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142817
[email protected]a27cbde2013-03-23 22:01:492818 // These occlude the surface and replica differently, so we can test each
2819 // one.
[email protected]d002dd02013-03-27 07:40:402820 this->VisitLayer(over_replica, &occlusion);
2821 this->VisitLayer(over_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142822
[email protected]a27cbde2013-03-23 22:01:492823 EXPECT_EQ(gfx::Rect().ToString(),
2824 occlusion.occlusion_from_outside_target().ToString());
2825 EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 40, 100), gfx::Rect(0, 100, 50, 100))
2826 .ToString(),
2827 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142828
[email protected]d002dd02013-03-27 07:40:402829 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142830
[email protected]66b52e12013-11-17 15:53:182831 // Render target with replica ignores occlusion from outside.
2832 EXPECT_EQ(gfx::Rect().ToString(),
[email protected]a27cbde2013-03-23 22:01:492833 occlusion.occlusion_from_outside_target().ToString());
2834 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2835 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142836
[email protected]e47b0a0a2013-11-18 23:26:222837 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142838
[email protected]a27cbde2013-03-23 22:01:492839 // Surface and replica are occluded different amounts.
2840 EXPECT_RECT_EQ(gfx::Rect(40, 0, 60, 100),
2841 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152842 surface, false, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492843 EXPECT_RECT_EQ(gfx::Rect(50, 0, 50, 100),
2844 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152845 surface, true, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492846 }
[email protected]94f206c12012-08-25 00:09:142847};
2848
[email protected]a27cbde2013-03-23 22:01:492849ALL_OCCLUSIONTRACKER_TEST(
2850 OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently);
[email protected]94f206c12012-08-25 00:09:142851
[email protected]a27cbde2013-03-23 22:01:492852template <class Types>
[email protected]ca2902e92013-03-28 01:45:352853class OcclusionTrackerTestSurfaceChildOfSurface
2854 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492855 protected:
[email protected]ca2902e92013-03-28 01:45:352856 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492857 : OcclusionTrackerTest<Types>(opaque_layers) {}
2858 void RunMyTest() {
2859 // This test verifies that the surface cliprect does not end up empty and
2860 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:142861
[email protected]a27cbde2013-03-23 22:01:492862 typename Types::ContentLayerType* parent = this->CreateRoot(
2863 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2864 typename Types::LayerType* surface =
2865 this->CreateDrawingSurface(parent,
2866 this->identity_matrix,
2867 gfx::PointF(),
2868 gfx::Size(100, 100),
2869 true);
2870 typename Types::LayerType* surface_child =
2871 this->CreateDrawingSurface(surface,
2872 this->identity_matrix,
2873 gfx::PointF(0.f, 10.f),
2874 gfx::Size(100, 50),
2875 true);
2876 typename Types::LayerType* topmost = this->CreateDrawingLayer(
2877 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
2878 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142879
[email protected]a27cbde2013-03-23 22:01:492880 TestOcclusionTrackerWithClip<typename Types::LayerType,
2881 typename Types::RenderSurfaceType> occlusion(
2882 gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142883
[email protected]a27cbde2013-03-23 22:01:492884 // |topmost| occludes everything partially so we know occlusion is happening
2885 // at all.
[email protected]d002dd02013-03-27 07:40:402886 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:142887
[email protected]a27cbde2013-03-23 22:01:492888 EXPECT_EQ(gfx::Rect().ToString(),
2889 occlusion.occlusion_from_outside_target().ToString());
2890 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2891 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142892
[email protected]d002dd02013-03-27 07:40:402893 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:142894
[email protected]a27cbde2013-03-23 22:01:492895 // surface_child increases the occlusion in the screen by a narrow sliver.
2896 EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(),
2897 occlusion.occlusion_from_outside_target().ToString());
2898 // In its own surface, surface_child is at 0,0 as is its occlusion.
2899 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2900 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:142901
[email protected]a27cbde2013-03-23 22:01:492902 // The root layer always has a clip rect. So the parent of |surface| has a
2903 // clip rect. However, the owning layer for |surface| does not mask to
2904 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
2905 // |surface_child| exercises different code paths as its parent does not
2906 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:142907
[email protected]e47b0a0a2013-11-18 23:26:222908 this->EnterContributingSurface(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492909 // The surface_child's parent does not have a clip rect as it owns a render
2910 // surface. Make sure the unoccluded rect does not get clipped away
2911 // inappropriately.
2912 EXPECT_RECT_EQ(gfx::Rect(0, 40, 100, 10),
2913 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152914 surface_child, false, gfx::Rect(0, 0, 100, 50)));
[email protected]d002dd02013-03-27 07:40:402915 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:142916
[email protected]a27cbde2013-03-23 22:01:492917 // When the surface_child's occlusion is transformed up to its parent, make
2918 // sure it is not clipped away inappropriately also.
[email protected]e47b0a0a2013-11-18 23:26:222919 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492920 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2921 occlusion.occlusion_from_outside_target().ToString());
2922 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(),
2923 occlusion.occlusion_from_inside_target().ToString());
[email protected]d002dd02013-03-27 07:40:402924 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142925
[email protected]e47b0a0a2013-11-18 23:26:222926 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492927 // The surface's parent does have a clip rect as it is the root layer.
2928 EXPECT_RECT_EQ(gfx::Rect(0, 50, 100, 50),
2929 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152930 surface, false, gfx::Rect(0, 0, 100, 100)));
[email protected]a27cbde2013-03-23 22:01:492931 }
[email protected]94f206c12012-08-25 00:09:142932};
2933
[email protected]96baf3e2012-10-22 23:09:552934ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:142935
[email protected]a27cbde2013-03-23 22:01:492936template <class Types>
[email protected]ca2902e92013-03-28 01:45:352937class OcclusionTrackerTestTopmostSurfaceIsClippedToViewport
2938 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:492939 protected:
[email protected]ca2902e92013-03-28 01:45:352940 explicit OcclusionTrackerTestTopmostSurfaceIsClippedToViewport(
2941 bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:492942 : OcclusionTrackerTest<Types>(opaque_layers) {}
2943 void RunMyTest() {
2944 // This test verifies that the top-most surface is considered occluded
2945 // outside of its target's clip rect and outside the viewport rect.
2946
2947 typename Types::ContentLayerType* parent = this->CreateRoot(
2948 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2949 typename Types::LayerType* surface =
2950 this->CreateDrawingSurface(parent,
2951 this->identity_matrix,
2952 gfx::PointF(),
2953 gfx::Size(100, 300),
2954 true);
2955 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:142956 {
[email protected]a27cbde2013-03-23 22:01:492957 // Make a viewport rect that is larger than the root layer.
2958 TestOcclusionTrackerWithClip<typename Types::LayerType,
2959 typename Types::RenderSurfaceType> occlusion(
2960 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:142961
[email protected]d002dd02013-03-27 07:40:402962 this->VisitLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:142963
[email protected]a27cbde2013-03-23 22:01:492964 // The root layer always has a clip rect. So the parent of |surface| has a
2965 // clip rect giving the surface itself a clip rect.
[email protected]e47b0a0a2013-11-18 23:26:222966 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492967 // Make sure the parent's clip rect clips the unoccluded region of the
2968 // child surface.
2969 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 200),
2970 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152971 surface, false, gfx::Rect(0, 0, 100, 300)));
[email protected]94f206c12012-08-25 00:09:142972 }
[email protected]a27cbde2013-03-23 22:01:492973 this->ResetLayerIterator();
2974 {
2975 // Make a viewport rect that is smaller than the root layer.
2976 TestOcclusionTrackerWithClip<typename Types::LayerType,
2977 typename Types::RenderSurfaceType> occlusion(
2978 gfx::Rect(0, 0, 100, 100));
2979
[email protected]d002dd02013-03-27 07:40:402980 this->VisitLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492981
2982 // The root layer always has a clip rect. So the parent of |surface| has a
2983 // clip rect giving the surface itself a clip rect.
[email protected]e47b0a0a2013-11-18 23:26:222984 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:492985 // Make sure the viewport rect clips the unoccluded region of the child
2986 // surface.
2987 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2988 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:152989 surface, false, gfx::Rect(0, 0, 100, 300)));
[email protected]a27cbde2013-03-23 22:01:492990 }
2991 }
[email protected]94f206c12012-08-25 00:09:142992};
2993
[email protected]a27cbde2013-03-23 22:01:492994ALL_OCCLUSIONTRACKER_TEST(
2995 OcclusionTrackerTestTopmostSurfaceIsClippedToViewport);
[email protected]94f206c12012-08-25 00:09:142996
[email protected]a27cbde2013-03-23 22:01:492997template <class Types>
[email protected]ca2902e92013-03-28 01:45:352998class OcclusionTrackerTestSurfaceChildOfClippingSurface
2999 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493000 protected:
[email protected]ca2902e92013-03-28 01:45:353001 explicit OcclusionTrackerTestSurfaceChildOfClippingSurface(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493002 : OcclusionTrackerTest<Types>(opaque_layers) {}
3003 void RunMyTest() {
3004 // This test verifies that the surface cliprect does not end up empty and
3005 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:143006
[email protected]a27cbde2013-03-23 22:01:493007 typename Types::ContentLayerType* parent = this->CreateRoot(
3008 this->identity_matrix, gfx::PointF(), gfx::Size(80, 200));
3009 parent->SetMasksToBounds(true);
3010 typename Types::LayerType* surface =
3011 this->CreateDrawingSurface(parent,
3012 this->identity_matrix,
3013 gfx::PointF(),
3014 gfx::Size(100, 100),
3015 true);
3016 typename Types::LayerType* surface_child =
3017 this->CreateDrawingSurface(surface,
3018 this->identity_matrix,
3019 gfx::PointF(),
3020 gfx::Size(100, 100),
3021 false);
3022 typename Types::LayerType* topmost = this->CreateDrawingLayer(
3023 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
3024 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143025
[email protected]a27cbde2013-03-23 22:01:493026 TestOcclusionTrackerWithClip<typename Types::LayerType,
3027 typename Types::RenderSurfaceType> occlusion(
3028 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143029
[email protected]a27cbde2013-03-23 22:01:493030 // |topmost| occludes everything partially so we know occlusion is happening
3031 // at all.
[email protected]d002dd02013-03-27 07:40:403032 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:143033
[email protected]a27cbde2013-03-23 22:01:493034 EXPECT_EQ(gfx::Rect().ToString(),
3035 occlusion.occlusion_from_outside_target().ToString());
3036 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(),
3037 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143038
[email protected]a27cbde2013-03-23 22:01:493039 // surface_child is not opaque and does not occlude, so we have a non-empty
3040 // unoccluded area on surface.
[email protected]d002dd02013-03-27 07:40:403041 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:143042
[email protected]a27cbde2013-03-23 22:01:493043 EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(),
3044 occlusion.occlusion_from_outside_target().ToString());
3045 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
3046 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143047
[email protected]a27cbde2013-03-23 22:01:493048 // The root layer always has a clip rect. So the parent of |surface| has a
3049 // clip rect. However, the owning layer for |surface| does not mask to
3050 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
3051 // |surface_child| exercises different code paths as its parent does not
3052 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:143053
[email protected]e47b0a0a2013-11-18 23:26:223054 this->EnterContributingSurface(surface_child, &occlusion);
[email protected]a27cbde2013-03-23 22:01:493055 // The surface_child's parent does not have a clip rect as it owns a render
3056 // surface.
3057 EXPECT_EQ(
3058 gfx::Rect(0, 50, 80, 50).ToString(),
3059 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:153060 surface_child, false, gfx::Rect(0, 0, 100, 100)).ToString());
[email protected]d002dd02013-03-27 07:40:403061 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:143062
[email protected]d002dd02013-03-27 07:40:403063 this->VisitLayer(surface, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:223064 this->EnterContributingSurface(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:493065 // The surface's parent does have a clip rect as it is the root layer.
3066 EXPECT_EQ(gfx::Rect(0, 50, 80, 50).ToString(),
3067 occlusion.UnoccludedContributingSurfaceContentRect(
[email protected]fbc293322013-10-01 05:07:153068 surface, false, gfx::Rect(0, 0, 100, 100)).ToString());
[email protected]a27cbde2013-03-23 22:01:493069 }
[email protected]94f206c12012-08-25 00:09:143070};
3071
[email protected]96baf3e2012-10-22 23:09:553072ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfClippingSurface);
[email protected]94f206c12012-08-25 00:09:143073
[email protected]a27cbde2013-03-23 22:01:493074template <class Types>
[email protected]ca2902e92013-03-28 01:45:353075class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter
3076 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493077 protected:
[email protected]ca2902e92013-03-28 01:45:353078 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:493079 bool opaque_layers)
3080 : OcclusionTrackerTest<Types>(opaque_layers) {}
3081 void RunMyTest() {
3082 gfx::Transform scale_by_half;
3083 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:143084
[email protected]66b52e12013-11-17 15:53:183085 // Make a 50x50 filtered surface that is completely surrounded by opaque
3086 // layers which are above it in the z-order. The surface is scaled to test
3087 // that the pixel moving is done in the target space, where the background
3088 // filter is applied.
[email protected]a27cbde2013-03-23 22:01:493089 typename Types::ContentLayerType* parent = this->CreateRoot(
[email protected]66b52e12013-11-17 15:53:183090 this->identity_matrix, gfx::PointF(), gfx::Size(200, 150));
[email protected]a27cbde2013-03-23 22:01:493091 typename Types::LayerType* filtered_surface =
3092 this->CreateDrawingLayer(parent,
3093 scale_by_half,
3094 gfx::PointF(50.f, 50.f),
3095 gfx::Size(100, 100),
3096 false);
[email protected]a27cbde2013-03-23 22:01:493097 typename Types::LayerType* occluding_layer1 = this->CreateDrawingLayer(
[email protected]66b52e12013-11-17 15:53:183098 parent, this->identity_matrix, gfx::PointF(), gfx::Size(200, 50), true);
[email protected]a27cbde2013-03-23 22:01:493099 typename Types::LayerType* occluding_layer2 =
3100 this->CreateDrawingLayer(parent,
3101 this->identity_matrix,
3102 gfx::PointF(0.f, 100.f),
[email protected]66b52e12013-11-17 15:53:183103 gfx::Size(200, 50),
[email protected]a27cbde2013-03-23 22:01:493104 true);
3105 typename Types::LayerType* occluding_layer3 =
3106 this->CreateDrawingLayer(parent,
3107 this->identity_matrix,
3108 gfx::PointF(0.f, 50.f),
3109 gfx::Size(50, 50),
3110 true);
3111 typename Types::LayerType* occluding_layer4 =
3112 this->CreateDrawingLayer(parent,
3113 this->identity_matrix,
3114 gfx::PointF(100.f, 50.f),
3115 gfx::Size(100, 50),
3116 true);
[email protected]94f206c12012-08-25 00:09:143117
[email protected]a27cbde2013-03-23 22:01:493118 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:293119 FilterOperations filters;
3120 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]a27cbde2013-03-23 22:01:493121 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:143122
[email protected]a27cbde2013-03-23 22:01:493123 // Save the distance of influence for the blur effect.
3124 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:293125 filters.GetOutsets(
3126 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:143127
[email protected]a27cbde2013-03-23 22:01:493128 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143129
[email protected]a27cbde2013-03-23 22:01:493130 TestOcclusionTrackerWithClip<typename Types::LayerType,
3131 typename Types::RenderSurfaceType> occlusion(
3132 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143133
[email protected]a27cbde2013-03-23 22:01:493134 // These layers occlude pixels directly beside the filtered_surface. Because
3135 // filtered surface blends pixels in a radius, it will need to see some of
[email protected]ed511b8d2013-03-25 03:29:293136 // the pixels (up to radius far) underneath the occluding layers.
[email protected]d002dd02013-03-27 07:40:403137 this->VisitLayer(occluding_layer4, &occlusion);
3138 this->VisitLayer(occluding_layer3, &occlusion);
3139 this->VisitLayer(occluding_layer2, &occlusion);
3140 this->VisitLayer(occluding_layer1, &occlusion);
[email protected]94f206c12012-08-25 00:09:143141
[email protected]a27cbde2013-03-23 22:01:493142 Region expected_occlusion;
[email protected]66b52e12013-11-17 15:53:183143 expected_occlusion.Union(gfx::Rect(0, 0, 200, 50));
[email protected]a27cbde2013-03-23 22:01:493144 expected_occlusion.Union(gfx::Rect(0, 50, 50, 50));
3145 expected_occlusion.Union(gfx::Rect(100, 50, 100, 50));
[email protected]66b52e12013-11-17 15:53:183146 expected_occlusion.Union(gfx::Rect(0, 100, 200, 50));
[email protected]ac7c7f52012-11-08 06:26:503147
[email protected]a27cbde2013-03-23 22:01:493148 EXPECT_EQ(expected_occlusion.ToString(),
3149 occlusion.occlusion_from_inside_target().ToString());
3150 EXPECT_EQ(gfx::Rect().ToString(),
3151 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143152
[email protected]d002dd02013-03-27 07:40:403153 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143154
[email protected]66b52e12013-11-17 15:53:183155 // The filtered layer does not occlude.
[email protected]a27cbde2013-03-23 22:01:493156 Region expected_occlusion_outside_surface;
[email protected]66b52e12013-11-17 15:53:183157 expected_occlusion_outside_surface.Union(gfx::Rect(-50, -50, 200, 50));
[email protected]a27cbde2013-03-23 22:01:493158 expected_occlusion_outside_surface.Union(gfx::Rect(-50, 0, 50, 50));
3159 expected_occlusion_outside_surface.Union(gfx::Rect(50, 0, 100, 50));
[email protected]66b52e12013-11-17 15:53:183160 expected_occlusion_outside_surface.Union(gfx::Rect(-50, 50, 200, 50));
[email protected]ccb1c9a2012-12-17 03:53:193161
[email protected]a27cbde2013-03-23 22:01:493162 EXPECT_EQ(expected_occlusion_outside_surface.ToString(),
3163 occlusion.occlusion_from_outside_target().ToString());
3164 EXPECT_EQ(gfx::Rect().ToString(),
3165 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143166
[email protected]a27cbde2013-03-23 22:01:493167 // The surface has a background blur, so it needs pixels that are currently
3168 // considered occluded in order to be drawn. So the pixels it needs should
3169 // be removed some the occluded area so that when we get to the parent they
3170 // are drawn.
[email protected]d002dd02013-03-27 07:40:403171 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143172
[email protected]e47b0a0a2013-11-18 23:26:223173 this->EnterLayer(parent, &occlusion);
[email protected]ac7c7f52012-11-08 06:26:503174
[email protected]a27cbde2013-03-23 22:01:493175 Region expected_blurred_occlusion;
[email protected]66b52e12013-11-17 15:53:183176 expected_blurred_occlusion.Union(gfx::Rect(0, 0, 200, 50 - outset_top));
[email protected]a27cbde2013-03-23 22:01:493177 expected_blurred_occlusion.Union(gfx::Rect(
3178 0, 50 - outset_top, 50 - outset_left, 50 + outset_top + outset_bottom));
3179 expected_blurred_occlusion.Union(
3180 gfx::Rect(100 + outset_right,
3181 50 - outset_top,
[email protected]66b52e12013-11-17 15:53:183182 100 - outset_right,
[email protected]a27cbde2013-03-23 22:01:493183 50 + outset_top + outset_bottom));
3184 expected_blurred_occlusion.Union(
[email protected]66b52e12013-11-17 15:53:183185 gfx::Rect(0, 100 + outset_bottom, 200, 50 - outset_bottom));
[email protected]ac7c7f52012-11-08 06:26:503186
[email protected]a27cbde2013-03-23 22:01:493187 EXPECT_EQ(expected_blurred_occlusion.ToString(),
3188 occlusion.occlusion_from_inside_target().ToString());
3189 EXPECT_EQ(gfx::Rect().ToString(),
3190 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143191
[email protected]a27cbde2013-03-23 22:01:493192 gfx::Rect outset_rect;
3193 gfx::Rect test_rect;
[email protected]94f206c12012-08-25 00:09:143194
[email protected]a27cbde2013-03-23 22:01:493195 // Nothing in the blur outsets for the filtered_surface is occluded.
3196 outset_rect = gfx::Rect(50 - outset_left,
3197 50 - outset_top,
3198 50 + outset_left + outset_right,
3199 50 + outset_top + outset_bottom);
3200 test_rect = outset_rect;
3201 EXPECT_EQ(
3202 outset_rect.ToString(),
3203 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
[email protected]94f206c12012-08-25 00:09:143204
[email protected]a27cbde2013-03-23 22:01:493205 // Stuff outside the blur outsets is still occluded though.
3206 test_rect = outset_rect;
3207 test_rect.Inset(0, 0, -1, 0);
3208 EXPECT_EQ(
3209 outset_rect.ToString(),
3210 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3211 test_rect = outset_rect;
3212 test_rect.Inset(0, 0, 0, -1);
3213 EXPECT_EQ(
3214 outset_rect.ToString(),
3215 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3216 test_rect = outset_rect;
3217 test_rect.Inset(-1, 0, 0, 0);
3218 EXPECT_EQ(
3219 outset_rect.ToString(),
3220 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
3221 test_rect = outset_rect;
3222 test_rect.Inset(0, -1, 0, 0);
3223 EXPECT_EQ(
3224 outset_rect.ToString(),
3225 occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString());
[email protected]a27cbde2013-03-23 22:01:493226 }
[email protected]94f206c12012-08-25 00:09:143227};
3228
[email protected]a27cbde2013-03-23 22:01:493229ALL_OCCLUSIONTRACKER_TEST(
3230 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[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 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice
3234 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493235 protected:
[email protected]ca2902e92013-03-28 01:45:353236 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(
[email protected]a27cbde2013-03-23 22:01:493237 bool opaque_layers)
3238 : OcclusionTrackerTest<Types>(opaque_layers) {}
3239 void RunMyTest() {
3240 gfx::Transform scale_by_half;
3241 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:143242
[email protected]a27cbde2013-03-23 22:01:493243 // Makes two surfaces that completely cover |parent|. The occlusion both
3244 // above and below the filters will be reduced by each of them.
3245 typename Types::ContentLayerType* root = this->CreateRoot(
3246 this->identity_matrix, gfx::PointF(), gfx::Size(75, 75));
3247 typename Types::LayerType* parent = this->CreateSurface(
3248 root, scale_by_half, gfx::PointF(), gfx::Size(150, 150));
3249 parent->SetMasksToBounds(true);
3250 typename Types::LayerType* filtered_surface1 = this->CreateDrawingLayer(
3251 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
3252 typename Types::LayerType* filtered_surface2 = this->CreateDrawingLayer(
3253 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
3254 typename Types::LayerType* occluding_layer_above =
3255 this->CreateDrawingLayer(parent,
3256 this->identity_matrix,
3257 gfx::PointF(100.f, 100.f),
3258 gfx::Size(50, 50),
3259 true);
[email protected]94f206c12012-08-25 00:09:143260
[email protected]a27cbde2013-03-23 22:01:493261 // Filters make the layers own surfaces.
[email protected]ae6b1a72013-06-25 18:49:293262 FilterOperations filters;
3263 filters.Append(FilterOperation::CreateBlurFilter(1.f));
[email protected]a27cbde2013-03-23 22:01:493264 filtered_surface1->SetBackgroundFilters(filters);
3265 filtered_surface2->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:143266
[email protected]a27cbde2013-03-23 22:01:493267 // Save the distance of influence for the blur effect.
3268 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:293269 filters.GetOutsets(
3270 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:143271
[email protected]a27cbde2013-03-23 22:01:493272 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:143273
[email protected]a27cbde2013-03-23 22:01:493274 TestOcclusionTrackerWithClip<typename Types::LayerType,
3275 typename Types::RenderSurfaceType> occlusion(
3276 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143277
[email protected]d002dd02013-03-27 07:40:403278 this->VisitLayer(occluding_layer_above, &occlusion);
[email protected]a27cbde2013-03-23 22:01:493279 EXPECT_EQ(gfx::Rect().ToString(),
3280 occlusion.occlusion_from_outside_target().ToString());
3281 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(),
3282 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143283
[email protected]d002dd02013-03-27 07:40:403284 this->VisitLayer(filtered_surface2, &occlusion);
3285 this->VisitContributingSurface(filtered_surface2, &occlusion);
3286 this->VisitLayer(filtered_surface1, &occlusion);
3287 this->VisitContributingSurface(filtered_surface1, &occlusion);
[email protected]94f206c12012-08-25 00:09:143288
[email protected]a27cbde2013-03-23 22:01:493289 // Test expectations in the target.
3290 gfx::Rect expected_occlusion =
3291 gfx::Rect(100 / 2 + outset_right * 2,
3292 100 / 2 + outset_bottom * 2,
3293 50 / 2 - (outset_left + outset_right) * 2,
3294 50 / 2 - (outset_top + outset_bottom) * 2);
3295 EXPECT_EQ(expected_occlusion.ToString(),
3296 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143297
[email protected]a27cbde2013-03-23 22:01:493298 // Test expectations in the screen are the same as in the target, as the
3299 // render surface is 1:1 with the screen.
3300 EXPECT_EQ(expected_occlusion.ToString(),
3301 occlusion.occlusion_from_outside_target().ToString());
3302 }
[email protected]94f206c12012-08-25 00:09:143303};
3304
[email protected]a27cbde2013-03-23 22:01:493305ALL_OCCLUSIONTRACKER_TEST(
3306 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:143307
[email protected]a27cbde2013-03-23 22:01:493308template <class Types>
[email protected]ca2902e92013-03-28 01:45:353309class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter
3310 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493311 protected:
[email protected]ca2902e92013-03-28 01:45:353312 explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:493313 bool opaque_layers)
3314 : OcclusionTrackerTest<Types>(opaque_layers) {}
3315 void RunMyTest() {
3316 gfx::Transform scale_by_half;
3317 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:143318
[email protected]a27cbde2013-03-23 22:01:493319 // Make a surface and its replica, each 50x50, with a smaller 30x30 layer
3320 // centered below each. The surface is scaled to test that the pixel moving
3321 // is done in the target space, where the background filter is applied, but
3322 // the surface appears at 50, 50 and the replica at 200, 50.
3323 typename Types::ContentLayerType* parent = this->CreateRoot(
3324 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
3325 typename Types::LayerType* behind_surface_layer =
3326 this->CreateDrawingLayer(parent,
3327 this->identity_matrix,
3328 gfx::PointF(60.f, 60.f),
3329 gfx::Size(30, 30),
3330 true);
3331 typename Types::LayerType* behind_replica_layer =
3332 this->CreateDrawingLayer(parent,
3333 this->identity_matrix,
3334 gfx::PointF(210.f, 60.f),
3335 gfx::Size(30, 30),
3336 true);
3337 typename Types::LayerType* filtered_surface =
3338 this->CreateDrawingLayer(parent,
3339 scale_by_half,
3340 gfx::PointF(50.f, 50.f),
3341 gfx::Size(100, 100),
3342 false);
3343 this->CreateReplicaLayer(filtered_surface,
3344 this->identity_matrix,
3345 gfx::PointF(300.f, 0.f),
3346 gfx::Size());
[email protected]94f206c12012-08-25 00:09:143347
[email protected]a27cbde2013-03-23 22:01:493348 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:293349 FilterOperations filters;
3350 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:493351 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:143352
[email protected]a27cbde2013-03-23 22:01:493353 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143354
[email protected]a27cbde2013-03-23 22:01:493355 TestOcclusionTrackerWithClip<typename Types::LayerType,
3356 typename Types::RenderSurfaceType> occlusion(
3357 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143358
[email protected]a27cbde2013-03-23 22:01:493359 // The surface has a background blur, so it blurs non-opaque pixels below
3360 // it.
[email protected]d002dd02013-03-27 07:40:403361 this->VisitLayer(filtered_surface, &occlusion);
3362 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143363
[email protected]d002dd02013-03-27 07:40:403364 this->VisitLayer(behind_replica_layer, &occlusion);
3365 this->VisitLayer(behind_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:143366
[email protected]a27cbde2013-03-23 22:01:493367 // The layers behind the surface are not blurred, and their occlusion does
3368 // not change, until we leave the surface. So it should not be modified by
3369 // the filter here.
3370 gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30);
3371 gfx::Rect occlusion_behind_replica = gfx::Rect(210, 60, 30, 30);
[email protected]94f206c12012-08-25 00:09:143372
[email protected]a27cbde2013-03-23 22:01:493373 Region expected_opaque_bounds =
3374 UnionRegions(occlusion_behind_surface, occlusion_behind_replica);
3375 EXPECT_EQ(expected_opaque_bounds.ToString(),
3376 occlusion.occlusion_from_inside_target().ToString());
[email protected]ccb1c9a2012-12-17 03:53:193377
[email protected]a27cbde2013-03-23 22:01:493378 EXPECT_EQ(gfx::Rect().ToString(),
3379 occlusion.occlusion_from_outside_target().ToString());
3380 }
[email protected]94f206c12012-08-25 00:09:143381};
3382
[email protected]a27cbde2013-03-23 22:01:493383ALL_OCCLUSIONTRACKER_TEST(
3384 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:143385
[email protected]a27cbde2013-03-23 22:01:493386template <class Types>
[email protected]ca2902e92013-03-28 01:45:353387class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded
3388 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493389 protected:
[email protected]ca2902e92013-03-28 01:45:353390 explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(
[email protected]a27cbde2013-03-23 22:01:493391 bool opaque_layers)
3392 : OcclusionTrackerTest<Types>(opaque_layers) {}
3393 void RunMyTest() {
3394 gfx::Transform scale_by_half;
3395 scale_by_half.Scale(0.5, 0.5);
3396
[email protected]66b52e12013-11-17 15:53:183397 // Make a 50x50 filtered surface that is completely occluded by an opaque
3398 // layer which is above it in the z-order. The surface is
[email protected]a27cbde2013-03-23 22:01:493399 // scaled to test that the pixel moving is done in the target space, where
[email protected]66b52e12013-11-17 15:53:183400 // the background filter is applied, but the surface appears at 50, 50.
[email protected]a27cbde2013-03-23 22:01:493401 typename Types::ContentLayerType* parent = this->CreateRoot(
[email protected]66b52e12013-11-17 15:53:183402 this->identity_matrix, gfx::PointF(), gfx::Size(200, 150));
[email protected]a27cbde2013-03-23 22:01:493403 typename Types::LayerType* filtered_surface =
3404 this->CreateDrawingLayer(parent,
3405 scale_by_half,
3406 gfx::PointF(50.f, 50.f),
3407 gfx::Size(100, 100),
3408 false);
[email protected]66b52e12013-11-17 15:53:183409 typename Types::LayerType* occluding_layer =
[email protected]a27cbde2013-03-23 22:01:493410 this->CreateDrawingLayer(parent,
3411 this->identity_matrix,
3412 gfx::PointF(50.f, 50.f),
3413 gfx::Size(50, 50),
3414 true);
[email protected]a27cbde2013-03-23 22:01:493415
3416 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:293417 FilterOperations filters;
3418 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:493419 filtered_surface->SetBackgroundFilters(filters);
3420
3421 this->CalcDrawEtc(parent);
3422
3423 TestOcclusionTrackerWithClip<typename Types::LayerType,
3424 typename Types::RenderSurfaceType> occlusion(
3425 gfx::Rect(0, 0, 1000, 1000));
3426
[email protected]66b52e12013-11-17 15:53:183427 this->VisitLayer(occluding_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:493428
[email protected]d002dd02013-03-27 07:40:403429 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143430 {
[email protected]a27cbde2013-03-23 22:01:493431 // The layers above the filtered surface occlude from outside.
3432 gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50);
[email protected]94f206c12012-08-25 00:09:143433
[email protected]a27cbde2013-03-23 22:01:493434 EXPECT_EQ(gfx::Rect().ToString(),
3435 occlusion.occlusion_from_inside_target().ToString());
[email protected]66b52e12013-11-17 15:53:183436 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:493437 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143438 }
[email protected]a27cbde2013-03-23 22:01:493439
3440 // The surface has a background blur, so it blurs non-opaque pixels below
3441 // it.
[email protected]d002dd02013-03-27 07:40:403442 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:493443 {
3444 // The filter is completely occluded, so it should not blur anything and
3445 // reduce any occlusion.
3446 gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50);
[email protected]a27cbde2013-03-23 22:01:493447
[email protected]66b52e12013-11-17 15:53:183448 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:493449 occlusion.occlusion_from_inside_target().ToString());
3450 EXPECT_EQ(gfx::Rect().ToString(),
3451 occlusion.occlusion_from_outside_target().ToString());
3452 }
3453 }
[email protected]94f206c12012-08-25 00:09:143454};
3455
[email protected]a27cbde2013-03-23 22:01:493456ALL_OCCLUSIONTRACKER_TEST(
3457 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:143458
[email protected]a27cbde2013-03-23 22:01:493459template <class Types>
[email protected]ca2902e92013-03-28 01:45:353460class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded
3461 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493462 protected:
[email protected]ca2902e92013-03-28 01:45:353463 explicit
[email protected]a27cbde2013-03-23 22:01:493464 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded(
3465 bool opaque_layers)
3466 : OcclusionTrackerTest<Types>(opaque_layers) {}
3467 void RunMyTest() {
3468 gfx::Transform scale_by_half;
3469 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:143470
[email protected]a27cbde2013-03-23 22:01:493471 // Make a surface and its replica, each 50x50, that are partially occluded
3472 // by opaque layers which are above them in the z-order. The surface is
3473 // scaled to test that the pixel moving is done in the target space, where
3474 // the background filter is applied, but the surface appears at 50, 50 and
3475 // the replica at 200, 50.
3476 typename Types::ContentLayerType* parent = this->CreateRoot(
3477 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
3478 typename Types::LayerType* filtered_surface =
3479 this->CreateDrawingLayer(parent,
3480 scale_by_half,
3481 gfx::PointF(50.f, 50.f),
3482 gfx::Size(100, 100),
3483 false);
3484 this->CreateReplicaLayer(filtered_surface,
3485 this->identity_matrix,
3486 gfx::PointF(300.f, 0.f),
3487 gfx::Size());
3488 typename Types::LayerType* above_surface_layer =
3489 this->CreateDrawingLayer(parent,
3490 this->identity_matrix,
3491 gfx::PointF(70.f, 50.f),
3492 gfx::Size(30, 50),
3493 true);
3494 typename Types::LayerType* above_replica_layer =
3495 this->CreateDrawingLayer(parent,
3496 this->identity_matrix,
3497 gfx::PointF(200.f, 50.f),
3498 gfx::Size(30, 50),
3499 true);
3500 typename Types::LayerType* beside_surface_layer =
3501 this->CreateDrawingLayer(parent,
3502 this->identity_matrix,
3503 gfx::PointF(90.f, 40.f),
3504 gfx::Size(10, 10),
3505 true);
3506 typename Types::LayerType* beside_replica_layer =
3507 this->CreateDrawingLayer(parent,
3508 this->identity_matrix,
3509 gfx::PointF(200.f, 40.f),
3510 gfx::Size(10, 10),
3511 true);
[email protected]94f206c12012-08-25 00:09:143512
[email protected]a27cbde2013-03-23 22:01:493513 // Filters make the layer own a surface.
[email protected]ae6b1a72013-06-25 18:49:293514 FilterOperations filters;
3515 filters.Append(FilterOperation::CreateBlurFilter(3.f));
[email protected]a27cbde2013-03-23 22:01:493516 filtered_surface->SetBackgroundFilters(filters);
[email protected]94f206c12012-08-25 00:09:143517
[email protected]a27cbde2013-03-23 22:01:493518 // Save the distance of influence for the blur effect.
3519 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:293520 filters.GetOutsets(
3521 &outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:143522
[email protected]a27cbde2013-03-23 22:01:493523 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143524
[email protected]a27cbde2013-03-23 22:01:493525 TestOcclusionTrackerWithClip<typename Types::LayerType,
3526 typename Types::RenderSurfaceType> occlusion(
3527 gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:143528
[email protected]d002dd02013-03-27 07:40:403529 this->VisitLayer(beside_replica_layer, &occlusion);
3530 this->VisitLayer(beside_surface_layer, &occlusion);
3531 this->VisitLayer(above_replica_layer, &occlusion);
3532 this->VisitLayer(above_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:143533
[email protected]a27cbde2013-03-23 22:01:493534 // The surface has a background blur, so it blurs non-opaque pixels below
3535 // it.
[email protected]d002dd02013-03-27 07:40:403536 this->VisitLayer(filtered_surface, &occlusion);
3537 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:143538
[email protected]a27cbde2013-03-23 22:01:493539 // The filter in the surface and replica are partially unoccluded. Only the
3540 // unoccluded parts should reduce occlusion. This means it will push back
[email protected]ed511b8d2013-03-25 03:29:293541 // the occlusion that touches the unoccluded part (occlusion_above___), but
[email protected]a27cbde2013-03-23 22:01:493542 // it will not touch occlusion_beside____ since that is not beside the
3543 // unoccluded part of the surface, even though it is beside the occluded
3544 // part of the surface.
3545 gfx::Rect occlusion_above_surface =
3546 gfx::Rect(70 + outset_right, 50, 30 - outset_right, 50);
3547 gfx::Rect occlusion_above_replica =
3548 gfx::Rect(200, 50, 30 - outset_left, 50);
3549 gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10);
3550 gfx::Rect occlusion_beside_replica = gfx::Rect(200, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:143551
[email protected]a27cbde2013-03-23 22:01:493552 Region expected_occlusion;
3553 expected_occlusion.Union(occlusion_above_surface);
3554 expected_occlusion.Union(occlusion_above_replica);
3555 expected_occlusion.Union(occlusion_beside_surface);
3556 expected_occlusion.Union(occlusion_beside_replica);
[email protected]94f206c12012-08-25 00:09:143557
[email protected]a27cbde2013-03-23 22:01:493558 ASSERT_EQ(expected_occlusion.ToString(),
3559 occlusion.occlusion_from_inside_target().ToString());
3560 EXPECT_EQ(gfx::Rect().ToString(),
3561 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143562
[email protected]a27cbde2013-03-23 22:01:493563 Region::Iterator expected_rects(expected_occlusion);
3564 Region::Iterator target_surface_rects(
3565 occlusion.occlusion_from_inside_target());
3566 for (; expected_rects.has_rect();
3567 expected_rects.next(), target_surface_rects.next()) {
3568 ASSERT_TRUE(target_surface_rects.has_rect());
3569 EXPECT_EQ(expected_rects.rect(), target_surface_rects.rect());
[email protected]94f206c12012-08-25 00:09:143570 }
[email protected]a27cbde2013-03-23 22:01:493571 }
[email protected]94f206c12012-08-25 00:09:143572};
3573
[email protected]a27cbde2013-03-23 22:01:493574ALL_OCCLUSIONTRACKER_TEST(
3575 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:143576
[email protected]a27cbde2013-03-23 22:01:493577template <class Types>
[email protected]ca2902e92013-03-28 01:45:353578class OcclusionTrackerTestMinimumTrackingSize
3579 : public OcclusionTrackerTest<Types> {
[email protected]a27cbde2013-03-23 22:01:493580 protected:
[email protected]ca2902e92013-03-28 01:45:353581 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers)
[email protected]a27cbde2013-03-23 22:01:493582 : OcclusionTrackerTest<Types>(opaque_layers) {}
3583 void RunMyTest() {
3584 gfx::Size tracking_size(100, 100);
3585 gfx::Size below_tracking_size(99, 99);
[email protected]94f206c12012-08-25 00:09:143586
[email protected]a27cbde2013-03-23 22:01:493587 typename Types::ContentLayerType* parent = this->CreateRoot(
3588 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
3589 typename Types::LayerType* large = this->CreateDrawingLayer(
3590 parent, this->identity_matrix, gfx::PointF(), tracking_size, true);
3591 typename Types::LayerType* small =
3592 this->CreateDrawingLayer(parent,
3593 this->identity_matrix,
3594 gfx::PointF(),
3595 below_tracking_size,
3596 true);
3597 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:143598
[email protected]a27cbde2013-03-23 22:01:493599 TestOcclusionTrackerWithClip<typename Types::LayerType,
3600 typename Types::RenderSurfaceType> occlusion(
3601 gfx::Rect(0, 0, 1000, 1000));
3602 occlusion.set_minimum_tracking_size(tracking_size);
[email protected]94f206c12012-08-25 00:09:143603
[email protected]a27cbde2013-03-23 22:01:493604 // The small layer is not tracked because it is too small.
[email protected]d002dd02013-03-27 07:40:403605 this->VisitLayer(small, &occlusion);
[email protected]94f206c12012-08-25 00:09:143606
[email protected]a27cbde2013-03-23 22:01:493607 EXPECT_EQ(gfx::Rect().ToString(),
3608 occlusion.occlusion_from_outside_target().ToString());
3609 EXPECT_EQ(gfx::Rect().ToString(),
3610 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:143611
[email protected]a27cbde2013-03-23 22:01:493612 // The large layer is tracked as it is large enough.
[email protected]d002dd02013-03-27 07:40:403613 this->VisitLayer(large, &occlusion);
[email protected]94f206c12012-08-25 00:09:143614
[email protected]a27cbde2013-03-23 22:01:493615 EXPECT_EQ(gfx::Rect().ToString(),
3616 occlusion.occlusion_from_outside_target().ToString());
[email protected]2c7c6702013-03-26 03:14:053617 EXPECT_EQ(gfx::Rect(tracking_size).ToString(),
[email protected]a27cbde2013-03-23 22:01:493618 occlusion.occlusion_from_inside_target().ToString());
3619 }
[email protected]94f206c12012-08-25 00:09:143620};
3621
[email protected]96baf3e2012-10-22 23:09:553622ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:143623
[email protected]a27cbde2013-03-23 22:01:493624template <class Types>
[email protected]1a5d9ce2013-04-30 01:31:093625class OcclusionTrackerTestScaledLayerIsClipped
3626 : public OcclusionTrackerTest<Types> {
3627 protected:
3628 explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers)
3629 : OcclusionTrackerTest<Types>(opaque_layers) {}
3630 void RunMyTest() {
3631 gfx::Transform scale_transform;
3632 scale_transform.Scale(512.0, 512.0);
3633
3634 typename Types::ContentLayerType* parent = this->CreateRoot(
3635 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
3636 typename Types::LayerType* clip = this->CreateLayer(parent,
3637 this->identity_matrix,
3638 gfx::PointF(10.f, 10.f),
3639 gfx::Size(50, 50));
3640 clip->SetMasksToBounds(true);
3641 typename Types::LayerType* scale = this->CreateLayer(
3642 clip, scale_transform, gfx::PointF(), gfx::Size(1, 1));
3643 typename Types::LayerType* scaled = this->CreateDrawingLayer(
3644 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
3645 this->CalcDrawEtc(parent);
3646
3647 TestOcclusionTrackerWithClip<typename Types::LayerType,
3648 typename Types::RenderSurfaceType> occlusion(
3649 gfx::Rect(0, 0, 1000, 1000));
3650
3651 this->VisitLayer(scaled, &occlusion);
3652
3653 EXPECT_EQ(gfx::Rect().ToString(),
3654 occlusion.occlusion_from_outside_target().ToString());
3655 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
3656 occlusion.occlusion_from_inside_target().ToString());
3657 }
3658};
3659
3660ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped)
3661
3662template <class Types>
3663class OcclusionTrackerTestScaledLayerInSurfaceIsClipped
3664 : public OcclusionTrackerTest<Types> {
3665 protected:
3666 explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers)
3667 : OcclusionTrackerTest<Types>(opaque_layers) {}
3668 void RunMyTest() {
3669 gfx::Transform scale_transform;
3670 scale_transform.Scale(512.0, 512.0);
3671
3672 typename Types::ContentLayerType* parent = this->CreateRoot(
3673 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
3674 typename Types::LayerType* clip = this->CreateLayer(parent,
3675 this->identity_matrix,
3676 gfx::PointF(10.f, 10.f),
3677 gfx::Size(50, 50));
3678 clip->SetMasksToBounds(true);
3679 typename Types::LayerType* surface = this->CreateDrawingSurface(
3680 clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false);
3681 typename Types::LayerType* scale = this->CreateLayer(
3682 surface, scale_transform, gfx::PointF(), gfx::Size(1, 1));
3683 typename Types::LayerType* scaled = this->CreateDrawingLayer(
3684 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
3685 this->CalcDrawEtc(parent);
3686
3687 TestOcclusionTrackerWithClip<typename Types::LayerType,
3688 typename Types::RenderSurfaceType> occlusion(
3689 gfx::Rect(0, 0, 1000, 1000));
3690
3691 this->VisitLayer(scaled, &occlusion);
3692 this->VisitLayer(surface, &occlusion);
3693 this->VisitContributingSurface(surface, &occlusion);
3694
3695 EXPECT_EQ(gfx::Rect().ToString(),
3696 occlusion.occlusion_from_outside_target().ToString());
3697 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
3698 occlusion.occlusion_from_inside_target().ToString());
3699 }
3700};
3701
3702ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped)
3703
[email protected]5b54b972013-07-26 13:25:423704template <class Types>
3705class OcclusionTrackerTestCopyRequestDoesOcclude
3706 : public OcclusionTrackerTest<Types> {
3707 protected:
3708 explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers)
3709 : OcclusionTrackerTest<Types>(opaque_layers) {}
3710 void RunMyTest() {
3711 typename Types::ContentLayerType* root = this->CreateRoot(
3712 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
3713 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
3714 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
3715 typename Types::LayerType* copy = this->CreateLayer(parent,
3716 this->identity_matrix,
3717 gfx::Point(100, 0),
3718 gfx::Size(200, 400));
3719 this->AddCopyRequest(copy);
3720 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
3721 copy,
3722 this->identity_matrix,
3723 gfx::PointF(),
3724 gfx::Size(200, 400),
3725 true);
3726 this->CalcDrawEtc(root);
3727
3728 TestOcclusionTrackerWithClip<typename Types::LayerType,
3729 typename Types::RenderSurfaceType> occlusion(
3730 gfx::Rect(0, 0, 1000, 1000));
3731
3732 this->VisitLayer(copy_child, &occlusion);
3733 EXPECT_EQ(gfx::Rect().ToString(),
3734 occlusion.occlusion_from_outside_target().ToString());
3735 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
3736 occlusion.occlusion_from_inside_target().ToString());
3737
3738 // CopyRequests cause the layer to own a surface.
3739 this->VisitContributingSurface(copy, &occlusion);
3740
3741 // The occlusion from the copy should be kept.
3742 EXPECT_EQ(gfx::Rect().ToString(),
3743 occlusion.occlusion_from_outside_target().ToString());
3744 EXPECT_EQ(gfx::Rect(100, 0, 200, 400).ToString(),
3745 occlusion.occlusion_from_inside_target().ToString());
3746 }
3747};
3748
3749ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude)
3750
3751template <class Types>
3752class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude
3753 : public OcclusionTrackerTest<Types> {
3754 protected:
3755 explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude(
3756 bool opaque_layers)
3757 : OcclusionTrackerTest<Types>(opaque_layers) {}
3758 void RunMyTest() {
3759 typename Types::ContentLayerType* root = this->CreateRoot(
3760 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
3761 typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
3762 root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true);
3763 typename Types::LayerType* hide = this->CreateLayer(
3764 parent, this->identity_matrix, gfx::Point(), gfx::Size());
3765 typename Types::LayerType* copy = this->CreateLayer(
3766 hide, this->identity_matrix, gfx::Point(100, 0), gfx::Size(200, 400));
3767 this->AddCopyRequest(copy);
3768 typename Types::LayerType* copy_child = this->CreateDrawingLayer(
3769 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
3770
3771 // The |copy| layer is hidden but since it is being copied, it will be
3772 // drawn.
3773 hide->SetHideLayerAndSubtree(true);
3774
3775 this->CalcDrawEtc(root);
3776
3777 TestOcclusionTrackerWithClip<typename Types::LayerType,
3778 typename Types::RenderSurfaceType> occlusion(
3779 gfx::Rect(0, 0, 1000, 1000));
3780
3781 this->VisitLayer(copy_child, &occlusion);
3782 EXPECT_EQ(gfx::Rect().ToString(),
3783 occlusion.occlusion_from_outside_target().ToString());
3784 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
3785 occlusion.occlusion_from_inside_target().ToString());
3786
3787 // CopyRequests cause the layer to own a surface.
3788 this->VisitContributingSurface(copy, &occlusion);
3789
3790 // The occlusion from the copy should be dropped since it is hidden.
3791 EXPECT_EQ(gfx::Rect().ToString(),
3792 occlusion.occlusion_from_outside_target().ToString());
3793 EXPECT_EQ(gfx::Rect().ToString(),
3794 occlusion.occlusion_from_inside_target().ToString());
3795 }
3796};
3797
3798ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude)
3799
[email protected]afc4f262013-10-05 01:14:103800template <class Types>
3801class OcclusionTrackerTestEmptyEventLayerDoesNotOcclude
3802 : public OcclusionTrackerTest<Types> {
3803 protected:
3804 explicit OcclusionTrackerTestEmptyEventLayerDoesNotOcclude(
3805 bool opaque_layers)
3806 : OcclusionTrackerTest<Types>(opaque_layers) {}
3807 void RunMyTest() {
3808 typename Types::ContentLayerType* root = this->CreateRoot(
3809 this->identity_matrix, gfx::Point(), gfx::Size(400, 400));
3810 typename Types::ContentLayerType* empty_layer = this->CreateDrawingLayer(
3811 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), true);
3812 this->SetDrawsContent(empty_layer, false);
3813 empty_layer->SetTouchEventHandlerRegion(gfx::Rect(10, 10, 10, 10));
3814
3815 this->CalcDrawEtc(root);
3816
3817 TestOcclusionTrackerWithClip<typename Types::LayerType,
3818 typename Types::RenderSurfaceType> occlusion(
3819 gfx::Rect(0, 0, 1000, 1000), false);
3820
3821 this->VisitLayer(empty_layer, &occlusion);
3822
3823 EXPECT_EQ(gfx::Rect().ToString(),
3824 occlusion.occlusion_from_outside_target().ToString());
3825 EXPECT_EQ(gfx::Rect().ToString(),
3826 occlusion.occlusion_from_inside_target().ToString());
3827 }
3828};
3829
3830ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestEmptyEventLayerDoesNotOcclude)
3831
[email protected]ba565742012-11-10 09:29:483832} // namespace
3833} // namespace cc