blob: c7c9ff6e6d8237a12722c2d8e0ff849e6968a111 [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
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
loyso2cb3f32f2016-11-08 07:08:349#include "cc/animation/animation_host.h"
chrishtrac41ff92017-03-17 05:07:3010#include "cc/base/filter_operation.h"
11#include "cc/base/filter_operations.h"
[email protected]681ccff2013-03-18 06:13:5212#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:5213#include "cc/layers/layer.h"
14#include "cc/layers/layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0315#include "cc/test/animation_test_common.h"
khushalsagarb64b360d2015-10-21 19:25:1616#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2817#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4518#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0319#include "cc/test/geometry_test_utils.h"
chrishtr7e3aaf22017-05-04 15:04:0120#include "cc/test/layer_test_common.h"
[email protected]34ba1ffb2014-03-05 06:55:0321#include "cc/test/test_occlusion_tracker.h"
danakjcf610582015-06-16 22:48:5622#include "cc/test/test_task_graph_runner.h"
[email protected]556fd292013-03-18 08:03:0423#include "cc/trees/layer_tree_host_common.h"
24#include "cc/trees/single_thread_proxy.h"
Fady Samueldfecb7d2017-07-26 11:41:0425#include "components/viz/common/quads/copy_output_request.h"
26#include "components/viz/common/quads/copy_output_result.h"
[email protected]7f0c53db2012-10-02 00:23:1827#include "testing/gmock/include/gmock/gmock.h"
28#include "testing/gtest/include/gtest/gtest.h"
[email protected]c8686a02012-11-27 08:29:0029#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1430
[email protected]ba565742012-11-10 09:29:4831namespace cc {
[email protected]94f206c12012-08-25 00:09:1432namespace {
33
[email protected]96baf3e2012-10-22 23:09:5534class TestContentLayerImpl : public LayerImpl {
[email protected]a27cbde2013-03-23 22:01:4935 public:
36 TestContentLayerImpl(LayerTreeImpl* tree_impl, int id)
37 : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) {
38 SetDrawsContent(true);
39 }
[email protected]94f206c12012-08-25 00:09:1440
danakj64767d902015-06-19 00:10:4341 SimpleEnclosedRegion VisibleOpaqueRegion() const override {
[email protected]d5467eb72014-08-22 01:16:4342 if (override_opaque_contents_rect_) {
43 return SimpleEnclosedRegion(
danakj64767d902015-06-19 00:10:4344 gfx::IntersectRects(opaque_contents_rect_, visible_layer_rect()));
[email protected]d5467eb72014-08-22 01:16:4345 }
danakj64767d902015-06-19 00:10:4346 return LayerImpl::VisibleOpaqueRegion();
[email protected]a27cbde2013-03-23 22:01:4947 }
[email protected]0023fc72014-01-10 20:05:0648 void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) {
[email protected]a27cbde2013-03-23 22:01:4949 override_opaque_contents_rect_ = true;
50 opaque_contents_rect_ = opaque_contents_rect;
51 }
[email protected]94f206c12012-08-25 00:09:1452
[email protected]a27cbde2013-03-23 22:01:4953 private:
54 bool override_opaque_contents_rect_;
55 gfx::Rect opaque_contents_rect_;
[email protected]94f206c12012-08-25 00:09:1456};
57
danakj00f7925e2015-06-15 21:19:2258class TestOcclusionTrackerWithClip : public TestOcclusionTracker {
[email protected]a27cbde2013-03-23 22:01:4959 public:
[email protected]0023fc72014-01-10 20:05:0660 explicit TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect)
danakj00f7925e2015-06-15 21:19:2261 : TestOcclusionTracker(viewport_rect) {}
[email protected]94f206c12012-08-25 00:09:1462
danakj00f7925e2015-06-15 21:19:2263 bool OccludedLayer(const LayerImpl* layer,
[email protected]0023fc72014-01-10 20:05:0664 const gfx::Rect& content_rect) const {
danakj64767d902015-06-19 00:10:4365 DCHECK(layer->visible_layer_rect().Contains(content_rect));
ajumad9432e32015-11-30 19:43:4466 return this->GetCurrentOcclusionForLayer(layer->DrawTransform())
vmpstr01a5bf352014-09-17 22:57:3167 .IsOccluded(content_rect);
[email protected]a27cbde2013-03-23 22:01:4968 }
[email protected]fbc293322013-10-01 05:07:1569
[email protected]a27cbde2013-03-23 22:01:4970 // Gives an unoccluded sub-rect of |content_rect| in the content space of the
vmpstr5b88d992014-09-18 23:25:0471 // layer. Simple wrapper around GetUnoccludedContentRect.
danakj00f7925e2015-06-15 21:19:2272 gfx::Rect UnoccludedLayerContentRect(const LayerImpl* layer,
[email protected]0023fc72014-01-10 20:05:0673 const gfx::Rect& content_rect) const {
danakj64767d902015-06-19 00:10:4374 DCHECK(layer->visible_layer_rect().Contains(content_rect));
ajumad9432e32015-11-30 19:43:4475 return this->GetCurrentOcclusionForLayer(layer->DrawTransform())
vmpstr5b88d992014-09-18 23:25:0476 .GetUnoccludedContentRect(content_rect);
[email protected]a27cbde2013-03-23 22:01:4977 }
[email protected]e312aca2014-03-20 22:11:5578
danakj00f7925e2015-06-15 21:19:2279 gfx::Rect UnoccludedSurfaceContentRect(const LayerImpl* layer,
[email protected]e312aca2014-03-20 22:11:5580 const gfx::Rect& content_rect) const {
chrishtr5f60ca02017-05-11 23:09:4981 const RenderSurfaceImpl* surface =
82 GetRenderSurface(const_cast<LayerImpl*>(layer));
danakj206a5812015-02-11 02:07:0883 return this->GetCurrentOcclusionForContributingSurface(
84 surface->draw_transform())
85 .GetUnoccludedContentRect(content_rect);
[email protected]e312aca2014-03-20 22:11:5586 }
[email protected]94f206c12012-08-25 00:09:1487};
88
danakj00f7925e2015-06-15 21:19:2289class OcclusionTrackerTest : public testing::Test {
[email protected]a27cbde2013-03-23 22:01:4990 protected:
[email protected]ca2902e92013-03-28 01:45:3591 explicit OcclusionTrackerTest(bool opaque_layers)
enne2097cab2014-09-25 20:16:3192 : opaque_layers_(opaque_layers),
loyso2cb3f32f2016-11-08 07:08:3493 animation_host_(AnimationHost::CreateForTesting(ThreadInstance::MAIN)),
94 host_(FakeLayerTreeHost::Create(&client_,
95 &task_graph_runner_,
96 animation_host_.get())),
danakj00f7925e2015-06-15 21:19:2297 next_layer_impl_id_(1) {}
[email protected]a27cbde2013-03-23 22:01:4998
99 virtual void RunMyTest() = 0;
100
danakjaeb95062014-11-14 01:35:36101 void TearDown() override { DestroyLayers(); }
[email protected]a27cbde2013-03-23 22:01:49102
danakj00f7925e2015-06-15 21:19:22103 TestContentLayerImpl* CreateRoot(const gfx::Transform& transform,
104 const gfx::PointF& position,
105 const gfx::Size& bounds) {
106 LayerTreeImpl* tree = host_->host_impl()->active_tree();
107 int id = next_layer_impl_id_++;
danakj60bc3bc2016-04-09 00:24:48108 std::unique_ptr<TestContentLayerImpl> layer(
109 new TestContentLayerImpl(tree, id));
danakj00f7925e2015-06-15 21:19:22110 TestContentLayerImpl* layer_ptr = layer.get();
[email protected]a27cbde2013-03-23 22:01:49111 SetProperties(layer_ptr, transform, position, bounds);
112
jaydasikabf1875a2016-06-28 03:39:59113 host_->host_impl()->active_tree()->SetRootLayerForTesting(std::move(layer));
[email protected]d600df7d2013-08-03 02:34:28114
jaydasika6b5a32bf2016-04-22 21:56:36115 layer_ptr->test_properties()->force_render_surface = true;
[email protected]d600df7d2013-08-03 02:34:28116 SetRootLayerOnMainThread(layer_ptr);
117
[email protected]a27cbde2013-03-23 22:01:49118 return layer_ptr;
119 }
120
danakj00f7925e2015-06-15 21:19:22121 LayerImpl* CreateLayer(LayerImpl* parent,
122 const gfx::Transform& transform,
123 const gfx::PointF& position,
124 const gfx::Size& bounds) {
125 LayerTreeImpl* tree = host_->host_impl()->active_tree();
126 int id = next_layer_impl_id_++;
danakj60bc3bc2016-04-09 00:24:48127 std::unique_ptr<LayerImpl> layer = LayerImpl::Create(tree, id);
danakj00f7925e2015-06-15 21:19:22128 LayerImpl* layer_ptr = layer.get();
[email protected]a27cbde2013-03-23 22:01:49129 SetProperties(layer_ptr, transform, position, bounds);
jaydasika89f7b5a2016-06-22 02:08:39130 parent->test_properties()->AddChild(std::move(layer));
[email protected]a27cbde2013-03-23 22:01:49131 return layer_ptr;
132 }
133
danakj00f7925e2015-06-15 21:19:22134 LayerImpl* CreateSurface(LayerImpl* parent,
135 const gfx::Transform& transform,
136 const gfx::PointF& position,
137 const gfx::Size& bounds) {
138 LayerImpl* layer = CreateLayer(parent, transform, position, bounds);
jaydasika6b5a32bf2016-04-22 21:56:36139 layer->test_properties()->force_render_surface = true;
[email protected]a27cbde2013-03-23 22:01:49140 return layer;
141 }
142
danakj00f7925e2015-06-15 21:19:22143 TestContentLayerImpl* CreateDrawingLayer(LayerImpl* parent,
144 const gfx::Transform& transform,
145 const gfx::PointF& position,
146 const gfx::Size& bounds,
147 bool opaque) {
148 LayerTreeImpl* tree = host_->host_impl()->active_tree();
149 int id = next_layer_impl_id_++;
danakj60bc3bc2016-04-09 00:24:48150 std::unique_ptr<TestContentLayerImpl> layer(
151 new TestContentLayerImpl(tree, id));
danakj00f7925e2015-06-15 21:19:22152 TestContentLayerImpl* layer_ptr = layer.get();
[email protected]a27cbde2013-03-23 22:01:49153 SetProperties(layer_ptr, transform, position, bounds);
154
155 if (opaque_layers_) {
156 layer_ptr->SetContentsOpaque(opaque);
157 } else {
158 layer_ptr->SetContentsOpaque(false);
159 if (opaque)
[email protected]2c7c6702013-03-26 03:14:05160 layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds));
[email protected]a27cbde2013-03-23 22:01:49161 else
162 layer_ptr->SetOpaqueContentsRect(gfx::Rect());
[email protected]586d51ed2012-12-07 20:31:45163 }
[email protected]94f206c12012-08-25 00:09:14164
jaydasika89f7b5a2016-06-22 02:08:39165 parent->test_properties()->AddChild(std::move(layer));
[email protected]a27cbde2013-03-23 22:01:49166 return layer_ptr;
167 }
[email protected]94f206c12012-08-25 00:09:14168
danakj00f7925e2015-06-15 21:19:22169 LayerImpl* CreateMaskLayer(LayerImpl* owning_layer, const gfx::Size& bounds) {
170 LayerTreeImpl* tree = host_->host_impl()->active_tree();
171 int id = next_layer_impl_id_++;
danakj60bc3bc2016-04-09 00:24:48172 std::unique_ptr<TestContentLayerImpl> layer(
173 new TestContentLayerImpl(tree, id));
danakj00f7925e2015-06-15 21:19:22174 TestContentLayerImpl* layer_ptr = layer.get();
[email protected]a27cbde2013-03-23 22:01:49175 SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds);
danakja04855a2015-11-18 20:39:10176 SetMask(owning_layer, std::move(layer));
[email protected]a27cbde2013-03-23 22:01:49177 return layer_ptr;
178 }
[email protected]586d51ed2012-12-07 20:31:45179
danakj00f7925e2015-06-15 21:19:22180 TestContentLayerImpl* CreateDrawingSurface(LayerImpl* parent,
181 const gfx::Transform& transform,
182 const gfx::PointF& position,
183 const gfx::Size& bounds,
184 bool opaque) {
185 TestContentLayerImpl* layer =
[email protected]a27cbde2013-03-23 22:01:49186 CreateDrawingLayer(parent, transform, position, bounds, opaque);
jaydasika6b5a32bf2016-04-22 21:56:36187 layer->test_properties()->force_render_surface = true;
[email protected]a27cbde2013-03-23 22:01:49188 return layer;
189 }
[email protected]94f206c12012-08-25 00:09:14190
[email protected]d5467eb72014-08-22 01:16:43191 void DestroyLayers() {
jaydasikabf1875a2016-06-28 03:39:59192 host_->host_impl()->active_tree()->SetRootLayerForTesting(nullptr);
ajumab784ef42017-04-28 23:01:52193 render_surface_list_impl_.clear();
[email protected]d5467eb72014-08-22 01:16:43194 mask_layers_.clear();
ajuma956219582017-04-04 19:58:14195 layer_iterator_.reset();
[email protected]d5467eb72014-08-22 01:16:43196 }
[email protected]5b54b972013-07-26 13:25:42197
Fady Samueldfecb7d2017-07-26 11:41:04198 void CopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {}
[email protected]5b54b972013-07-26 13:25:42199
200 void AddCopyRequest(Layer* layer) {
Fady Samueldfecb7d2017-07-26 11:41:04201 layer->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
Yuri Wiitalab2511762017-07-19 00:17:53202 base::BindOnce(&OcclusionTrackerTest::CopyOutputCallback,
203 base::Unretained(this))));
[email protected]5b54b972013-07-26 13:25:42204 }
205
206 void AddCopyRequest(LayerImpl* layer) {
ajumae6f541b2016-05-31 16:50:50207 layer->test_properties()->copy_requests.push_back(
Fady Samueldfecb7d2017-07-26 11:41:04208 viz::CopyOutputRequest::CreateBitmapRequest(
Yuri Wiitalab2511762017-07-19 00:17:53209 base::BindOnce(&OcclusionTrackerTest::CopyOutputCallback,
210 base::Unretained(this))));
[email protected]5b54b972013-07-26 13:25:42211 }
212
[email protected]a27cbde2013-03-23 22:01:49213 void CalcDrawEtc(TestContentLayerImpl* root) {
jaydasikabf1875a2016-06-28 03:39:59214 root->layer_tree_impl()->BuildLayerListForTesting();
215 DCHECK(root == root->layer_tree_impl()->root_layer_for_testing());
[email protected]94f206c12012-08-25 00:09:14216
enned8d1c5cb2015-06-16 19:09:35217 // These occlusion tests attach and detach layers in multiple
218 // iterations, so rebuild property trees every time.
219 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
220
[email protected]7aad55f2013-07-26 11:25:53221 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:52222 root, root->bounds(), &render_surface_list_impl_);
[email protected]7aad55f2013-07-26 11:25:53223 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:57224 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]94f206c12012-08-25 00:09:14225
Jeremy Roman909d927b2017-08-27 18:34:09226 layer_iterator_ = std::make_unique<EffectTreeLayerListIterator>(
ajuma956219582017-04-04 19:58:14227 host_->host_impl()->active_tree());
[email protected]a27cbde2013-03-23 22:01:49228 }
[email protected]94f206c12012-08-25 00:09:14229
danakj00f7925e2015-06-15 21:19:22230 void EnterLayer(LayerImpl* layer, OcclusionTracker* occlusion) {
ajuma956219582017-04-04 19:58:14231 ASSERT_EQ(layer_iterator_->current_layer(), layer);
232 ASSERT_TRUE(layer_iterator_->state() ==
233 EffectTreeLayerListIterator::State::LAYER);
234 occlusion->EnterLayer(*layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49235 }
[email protected]94f206c12012-08-25 00:09:14236
danakj00f7925e2015-06-15 21:19:22237 void LeaveLayer(LayerImpl* layer, OcclusionTracker* occlusion) {
ajuma956219582017-04-04 19:58:14238 ASSERT_EQ(layer_iterator_->current_layer(), layer);
239 ASSERT_TRUE(layer_iterator_->state() ==
240 EffectTreeLayerListIterator::State::LAYER);
241 occlusion->LeaveLayer(*layer_iterator_);
242 ++(*layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49243 }
[email protected]94f206c12012-08-25 00:09:14244
danakj00f7925e2015-06-15 21:19:22245 void VisitLayer(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22246 EnterLayer(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49247 LeaveLayer(layer, occlusion);
248 }
[email protected]94f206c12012-08-25 00:09:14249
danakj00f7925e2015-06-15 21:19:22250 void EnterContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) {
ajuma956219582017-04-04 19:58:14251 ASSERT_EQ(layer_iterator_->target_render_surface(),
chrishtr7e3aaf22017-05-04 15:04:01252 GetRenderSurface(layer));
ajuma956219582017-04-04 19:58:14253 ASSERT_TRUE(layer_iterator_->state() ==
254 EffectTreeLayerListIterator::State::TARGET_SURFACE);
255 occlusion->EnterLayer(*layer_iterator_);
256 occlusion->LeaveLayer(*layer_iterator_);
257 ++(*layer_iterator_);
258 ASSERT_TRUE(layer_iterator_->state() ==
259 EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE);
260 occlusion->EnterLayer(*layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49261 }
[email protected]94f206c12012-08-25 00:09:14262
danakj00f7925e2015-06-15 21:19:22263 void LeaveContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) {
ajuma956219582017-04-04 19:58:14264 ASSERT_EQ(layer_iterator_->current_render_surface(),
chrishtr7e3aaf22017-05-04 15:04:01265 GetRenderSurface(layer));
ajuma956219582017-04-04 19:58:14266 ASSERT_TRUE(layer_iterator_->state() ==
267 EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE);
268 occlusion->LeaveLayer(*layer_iterator_);
269 ++(*layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49270 }
[email protected]94f206c12012-08-25 00:09:14271
danakj00f7925e2015-06-15 21:19:22272 void VisitContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22273 EnterContributingSurface(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49274 LeaveContributingSurface(layer, occlusion);
275 }
[email protected]94f206c12012-08-25 00:09:14276
ajuma956219582017-04-04 19:58:14277 void ResetLayerIterator() {
278 *layer_iterator_ =
279 EffectTreeLayerListIterator(host_->host_impl()->active_tree());
280 }
[email protected]94f206c12012-08-25 00:09:14281
[email protected]a27cbde2013-03-23 22:01:49282 const gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:14283
[email protected]a27cbde2013-03-23 22:01:49284 private:
[email protected]d600df7d2013-08-03 02:34:28285 void SetRootLayerOnMainThread(Layer* root) {
286 host_->SetRootLayer(scoped_refptr<Layer>(root));
287 }
288
289 void SetRootLayerOnMainThread(LayerImpl* root) {}
290
[email protected]a27cbde2013-03-23 22:01:49291 void SetProperties(LayerImpl* layer,
292 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47293 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26294 const gfx::Size& bounds) {
jaydasika10d43fc2016-08-18 04:06:04295 layer->test_properties()->transform = transform;
danakj3b8b2bf2015-06-18 03:09:01296 layer->SetPosition(position);
297 layer->SetBounds(bounds);
[email protected]a27cbde2013-03-23 22:01:49298 }
[email protected]94f206c12012-08-25 00:09:14299
danakj60bc3bc2016-04-09 00:24:48300 void SetMask(LayerImpl* owning_layer, std::unique_ptr<LayerImpl> layer) {
ajuma1d4026a32016-06-14 13:18:50301 owning_layer->test_properties()->SetMaskLayer(std::move(layer));
[email protected]a27cbde2013-03-23 22:01:49302 }
[email protected]94f206c12012-08-25 00:09:14303
[email protected]a27cbde2013-03-23 22:01:49304 bool opaque_layers_;
enne2097cab2014-09-25 20:16:31305 FakeLayerTreeHostClient client_;
danakjcf610582015-06-16 22:48:56306 TestTaskGraphRunner task_graph_runner_;
loyso2cb3f32f2016-11-08 07:08:34307 std::unique_ptr<AnimationHost> animation_host_;
danakj60bc3bc2016-04-09 00:24:48308 std::unique_ptr<FakeLayerTreeHost> host_;
[email protected]a27cbde2013-03-23 22:01:49309 // These hold ownership of the layers for the duration of the test.
ajumab784ef42017-04-28 23:01:52310 RenderSurfaceList render_surface_list_impl_;
ajuma956219582017-04-04 19:58:14311 std::unique_ptr<EffectTreeLayerListIterator> layer_iterator_;
[email protected]50761e92013-03-29 20:51:28312 LayerList mask_layers_;
danakj00f7925e2015-06-15 21:19:22313 int next_layer_impl_id_;
[email protected]94f206c12012-08-25 00:09:14314};
315
danakj00f7925e2015-06-15 21:19:22316#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
317 class ClassName##ImplThreadOpaqueLayers : public ClassName { \
318 public: /* NOLINT(whitespace/indent) */ \
319 ClassName##ImplThreadOpaqueLayers() : ClassName(true) {} \
320 }; \
[email protected]a27cbde2013-03-23 22:01:49321 TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); }
danakj00f7925e2015-06-15 21:19:22322#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
323 class ClassName##ImplThreadOpaquePaints : public ClassName { \
324 public: /* NOLINT(whitespace/indent) */ \
325 ClassName##ImplThreadOpaquePaints() : ClassName(false) {} \
326 }; \
[email protected]a27cbde2013-03-23 22:01:49327 TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14328
[email protected]a27cbde2013-03-23 22:01:49329#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
[email protected]a27cbde2013-03-23 22:01:49330 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
331 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
[email protected]94f206c12012-08-25 00:09:14332
danakj00f7925e2015-06-15 21:19:22333class OcclusionTrackerTestIdentityTransforms : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49334 protected:
[email protected]ca2902e92013-03-28 01:45:35335 explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22336 : OcclusionTrackerTest(opaque_layers) {}
[email protected]ece1d952012-10-18 21:26:07337
dmichaelc78b0932014-12-17 23:39:47338 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22339 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49340 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22341 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49342 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22343 TestContentLayerImpl* layer = this->CreateDrawingLayer(
344 parent, this->identity_matrix, gfx::PointF(30.f, 30.f),
345 gfx::Size(500, 500), true);
[email protected]a27cbde2013-03-23 22:01:49346 parent->SetMasksToBounds(true);
347 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14348
danakj00f7925e2015-06-15 21:19:22349 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14350
[email protected]d002dd02013-03-27 07:40:40351 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22352 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14353
[email protected]a27cbde2013-03-23 22:01:49354 EXPECT_EQ(gfx::Rect().ToString(),
355 occlusion.occlusion_from_outside_target().ToString());
356 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
357 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49358 }
[email protected]94f206c12012-08-25 00:09:14359};
360
[email protected]96baf3e2012-10-22 23:09:55361ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14362
danakj00f7925e2015-06-15 21:19:22363class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49364 protected:
[email protected]ca2902e92013-03-28 01:45:35365 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22366 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47367 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49368 gfx::Transform layer_transform;
369 layer_transform.Translate(250.0, 250.0);
370 layer_transform.Rotate(90.0);
371 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14372
danakj00f7925e2015-06-15 21:19:22373 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:24374 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22375 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49376 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22377 TestContentLayerImpl* layer = this->CreateDrawingLayer(
378 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
379 true);
[email protected]a27cbde2013-03-23 22:01:49380 parent->SetMasksToBounds(true);
381 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14382
danakj00f7925e2015-06-15 21:19:22383 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14384
[email protected]d002dd02013-03-27 07:40:40385 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22386 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14387
[email protected]a27cbde2013-03-23 22:01:49388 EXPECT_EQ(gfx::Rect().ToString(),
389 occlusion.occlusion_from_outside_target().ToString());
390 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
391 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49392 }
[email protected]94f206c12012-08-25 00:09:14393};
394
[email protected]96baf3e2012-10-22 23:09:55395ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14396
danakj00f7925e2015-06-15 21:19:22397class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49398 protected:
[email protected]ca2902e92013-03-28 01:45:35399 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22400 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47401 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49402 gfx::Transform layer_transform;
403 layer_transform.Translate(20.0, 20.0);
[email protected]94f206c12012-08-25 00:09:14404
danakj00f7925e2015-06-15 21:19:22405 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49406 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22407 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49408 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22409 TestContentLayerImpl* layer = this->CreateDrawingLayer(
410 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
411 true);
[email protected]a27cbde2013-03-23 22:01:49412 parent->SetMasksToBounds(true);
413 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14414
danakj00f7925e2015-06-15 21:19:22415 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14416
[email protected]d002dd02013-03-27 07:40:40417 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22418 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14419
[email protected]a27cbde2013-03-23 22:01:49420 EXPECT_EQ(gfx::Rect().ToString(),
421 occlusion.occlusion_from_outside_target().ToString());
422 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
423 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49424 }
[email protected]94f206c12012-08-25 00:09:14425};
426
[email protected]96baf3e2012-10-22 23:09:55427ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14428
danakj00f7925e2015-06-15 21:19:22429class OcclusionTrackerTestChildInRotatedChild : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49430 protected:
[email protected]ca2902e92013-03-28 01:45:35431 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22432 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47433 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49434 gfx::Transform child_transform;
435 child_transform.Translate(250.0, 250.0);
436 child_transform.Rotate(90.0);
437 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14438
danakj00f7925e2015-06-15 21:19:22439 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49440 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
441 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22442 LayerImpl* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49443 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
444 child->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22445 TestContentLayerImpl* layer = this->CreateDrawingLayer(
446 child, this->identity_matrix, gfx::PointF(10.f, 10.f),
447 gfx::Size(500, 500), true);
[email protected]a27cbde2013-03-23 22:01:49448 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14449
danakj00f7925e2015-06-15 21:19:22450 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14451
[email protected]d002dd02013-03-27 07:40:40452 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22453 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14454
[email protected]a27cbde2013-03-23 22:01:49455 EXPECT_EQ(gfx::Rect().ToString(),
456 occlusion.occlusion_from_outside_target().ToString());
457 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
458 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14459
[email protected]d002dd02013-03-27 07:40:40460 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22461 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14462
[email protected]a27cbde2013-03-23 22:01:49463 EXPECT_EQ(gfx::Rect().ToString(),
464 occlusion.occlusion_from_outside_target().ToString());
465 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
466 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14467
[email protected]a27cbde2013-03-23 22:01:49468 /* Justification for the above occlusion from |layer|:
469 100
470 +---------------------+
471 | |
472 | 30 | rotate(90)
473 | 30 + ---------------------------------+
474 100 | | 10 | | ==>
475 | |10+---------------------------------+
476 | | | | | |
477 | | | | | |
478 | | | | | |
479 +----|--|-------------+ | |
480 | | | |
481 | | | |
482 | | | |500
483 | | | |
484 | | | |
485 | | | |
486 | | | |
487 +--|-------------------------------+ |
488 | |
489 +---------------------------------+
490 500
491
492 +---------------------+
493 | |30 Visible region of |layer|: /////
494 | |
495 | +---------------------------------+
496 100| | |10 |
497 | +---------------------------------+ |
498 | | |///////////////| 420 | |
499 | | |///////////////|60 | |
500 | | |///////////////| | |
501 +--|--|---------------+ | |
502 20|10| 70 | |
503 | | | |
504 | | | |
505 | | | |
506 | | | |
507 | | | |
508 | | |10|
509 | +------------------------------|--+
510 | 490 |
511 +---------------------------------+
512 500
513
514 */
515 }
[email protected]94f206c12012-08-25 00:09:14516};
517
[email protected]96baf3e2012-10-22 23:09:55518ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14519
danakj00f7925e2015-06-15 21:19:22520class OcclusionTrackerTestScaledRenderSurface : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49521 protected:
[email protected]ca2902e92013-03-28 01:45:35522 explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22523 : OcclusionTrackerTest(opaque_layers) {}
[email protected]710ffc02012-10-30 21:42:02524
dmichaelc78b0932014-12-17 23:39:47525 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22526 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49527 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02528
[email protected]a27cbde2013-03-23 22:01:49529 gfx::Transform layer1_matrix;
530 layer1_matrix.Scale(2.0, 2.0);
danakj00f7925e2015-06-15 21:19:22531 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49532 parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true);
jaydasika6b5a32bf2016-04-22 21:56:36533 layer1->test_properties()->force_render_surface = true;
[email protected]710ffc02012-10-30 21:42:02534
[email protected]a27cbde2013-03-23 22:01:49535 gfx::Transform layer2_matrix;
536 layer2_matrix.Translate(25.0, 25.0);
danakj00f7925e2015-06-15 21:19:22537 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49538 layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true);
danakj00f7925e2015-06-15 21:19:22539 TestContentLayerImpl* occluder = this->CreateDrawingLayer(
540 parent, this->identity_matrix, gfx::PointF(100.f, 100.f),
541 gfx::Size(500, 500), true);
[email protected]a27cbde2013-03-23 22:01:49542 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02543
danakj00f7925e2015-06-15 21:19:22544 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02545
[email protected]d002dd02013-03-27 07:40:40546 this->VisitLayer(occluder, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22547 this->EnterLayer(layer2, &occlusion);
[email protected]710ffc02012-10-30 21:42:02548
[email protected]a27cbde2013-03-23 22:01:49549 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
550 occlusion.occlusion_from_outside_target().ToString());
551 EXPECT_EQ(gfx::Rect().ToString(),
552 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49553 }
[email protected]710ffc02012-10-30 21:42:02554};
555
556ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
557
danakj00f7925e2015-06-15 21:19:22558class OcclusionTrackerTestVisitTargetTwoTimes : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49559 protected:
[email protected]ca2902e92013-03-28 01:45:35560 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22561 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47562 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22563 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49564 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22565 LayerImpl* surface = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43566 root, this->identity_matrix, gfx::PointF(30.f, 30.f), gfx::Size());
danakj00f7925e2015-06-15 21:19:22567 TestContentLayerImpl* surface_child = this->CreateDrawingLayer(
568 surface, this->identity_matrix, gfx::PointF(10.f, 10.f),
569 gfx::Size(50, 50), true);
[email protected]d5467eb72014-08-22 01:16:43570 // |top_layer| makes |root|'s surface get considered by OcclusionTracker
571 // first, instead of |surface|'s. This exercises different code in
572 // LeaveToRenderTarget, as the target surface has already been seen when
573 // leaving |surface| later.
danakj00f7925e2015-06-15 21:19:22574 TestContentLayerImpl* top_layer = this->CreateDrawingLayer(
575 root, this->identity_matrix, gfx::PointF(40.f, 90.f), gfx::Size(50, 20),
576 true);
[email protected]a27cbde2013-03-23 22:01:49577 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14578
danakj00f7925e2015-06-15 21:19:22579 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14580
[email protected]d5467eb72014-08-22 01:16:43581 this->VisitLayer(top_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14582
[email protected]a27cbde2013-03-23 22:01:49583 EXPECT_EQ(gfx::Rect().ToString(),
584 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43585 EXPECT_EQ(gfx::Rect(40, 90, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49586 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14587
[email protected]d5467eb72014-08-22 01:16:43588 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14589
[email protected]d5467eb72014-08-22 01:16:43590 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49591 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43592 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49593 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14594
[email protected]d5467eb72014-08-22 01:16:43595 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:14596
[email protected]d5467eb72014-08-22 01:16:43597 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49598 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43599 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49600 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14601
[email protected]d5467eb72014-08-22 01:16:43602 // Occlusion from |top_layer| already in the root target should get merged
603 // with the occlusion from the |surface| we are leaving now.
604 this->LeaveContributingSurface(surface, &occlusion);
605 this->EnterLayer(root, &occlusion);
[email protected]94f206c12012-08-25 00:09:14606
[email protected]d5467eb72014-08-22 01:16:43607 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
608 EXPECT_EQ(gfx::Rect(40, 40, 50, 70).ToString(),
[email protected]a27cbde2013-03-23 22:01:49609 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49610 }
[email protected]94f206c12012-08-25 00:09:14611};
612
[email protected]96baf3e2012-10-22 23:09:55613ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:14614
danakj00f7925e2015-06-15 21:19:22615class OcclusionTrackerTestSurfaceRotatedOffAxis : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49616 protected:
[email protected]ca2902e92013-03-28 01:45:35617 explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22618 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47619 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49620 gfx::Transform child_transform;
621 child_transform.Translate(250.0, 250.0);
622 child_transform.Rotate(95.0);
623 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14624
[email protected]a27cbde2013-03-23 22:01:49625 gfx::Transform layer_transform;
626 layer_transform.Translate(10.0, 10.0);
[email protected]94f206c12012-08-25 00:09:14627
danakj00f7925e2015-06-15 21:19:22628 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49629 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
danakj00f7925e2015-06-15 21:19:22630 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49631 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22632 LayerImpl* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49633 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
danakj00f7925e2015-06-15 21:19:22634 TestContentLayerImpl* layer = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49635 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true);
636 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14637
danakj00f7925e2015-06-15 21:19:22638 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14639
[email protected]8a822692014-02-12 17:30:55640 gfx::Rect clipped_layer_in_child = MathUtil::MapEnclosingClippedRect(
danakj64767d902015-06-19 00:10:43641 layer_transform, layer->visible_layer_rect());
[email protected]94f206c12012-08-25 00:09:14642
[email protected]d002dd02013-03-27 07:40:40643 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22644 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14645
[email protected]a27cbde2013-03-23 22:01:49646 EXPECT_EQ(gfx::Rect().ToString(),
647 occlusion.occlusion_from_outside_target().ToString());
648 EXPECT_EQ(clipped_layer_in_child.ToString(),
649 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14650
[email protected]d002dd02013-03-27 07:40:40651 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22652 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14653
[email protected]a27cbde2013-03-23 22:01:49654 EXPECT_EQ(gfx::Rect().ToString(),
655 occlusion.occlusion_from_outside_target().ToString());
656 EXPECT_EQ(gfx::Rect().ToString(),
657 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49658 }
[email protected]94f206c12012-08-25 00:09:14659};
660
[email protected]96baf3e2012-10-22 23:09:55661ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:14662
[email protected]ca2902e92013-03-28 01:45:35663class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
danakj00f7925e2015-06-15 21:19:22664 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49665 protected:
[email protected]ca2902e92013-03-28 01:45:35666 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22667 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47668 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49669 gfx::Transform child_transform;
670 child_transform.Translate(250.0, 250.0);
671 child_transform.Rotate(90.0);
672 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14673
danakj00f7925e2015-06-15 21:19:22674 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49675 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
danakj00f7925e2015-06-15 21:19:22676 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49677 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
678 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22679 TestContentLayerImpl* child = this->CreateDrawingSurface(
680 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
681 false);
[email protected]a27cbde2013-03-23 22:01:49682 child->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22683 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
684 child, this->identity_matrix, gfx::PointF(10.f, 10.f),
685 gfx::Size(500, 500), true);
686 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
687 child, this->identity_matrix, gfx::PointF(10.f, 450.f),
688 gfx::Size(500, 60), true);
[email protected]a27cbde2013-03-23 22:01:49689 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14690
danakj00f7925e2015-06-15 21:19:22691 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14692
[email protected]d002dd02013-03-27 07:40:40693 this->VisitLayer(layer2, &occlusion);
694 this->VisitLayer(layer1, &occlusion);
695 this->VisitLayer(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22696 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14697
[email protected]a27cbde2013-03-23 22:01:49698 EXPECT_EQ(gfx::Rect().ToString(),
699 occlusion.occlusion_from_outside_target().ToString());
700 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
701 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14702
[email protected]d002dd02013-03-27 07:40:40703 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22704 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14705
[email protected]a27cbde2013-03-23 22:01:49706 EXPECT_EQ(gfx::Rect().ToString(),
707 occlusion.occlusion_from_outside_target().ToString());
708 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
709 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14710
[email protected]a27cbde2013-03-23 22:01:49711 /* Justification for the above occlusion from |layer1| and |layer2|:
[email protected]94f206c12012-08-25 00:09:14712
713 +---------------------+
714 | |30 Visible region of |layer1|: /////
715 | | Visible region of |layer2|: \\\\\
716 | +---------------------------------+
717 | | |10 |
718 | +---------------+-----------------+ |
719 | | |\\\\\\\\\\\\|//| 420 | |
720 | | |\\\\\\\\\\\\|//|60 | |
721 | | |\\\\\\\\\\\\|//| | |
722 +--|--|------------|--+ | |
723 20|10| 70 | | |
724 | | | | |
725 | | | | |
726 | | | | |
727 | | | | |
728 | | | | |
729 | | | |10|
730 | +------------|-----------------|--+
731 | | 490 |
732 +---------------+-----------------+
733 60 440
734 */
[email protected]a27cbde2013-03-23 22:01:49735 }
[email protected]94f206c12012-08-25 00:09:14736};
737
[email protected]96baf3e2012-10-22 23:09:55738ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:14739
[email protected]ca2902e92013-03-28 01:45:35740class OcclusionTrackerTestOverlappingSurfaceSiblings
danakj00f7925e2015-06-15 21:19:22741 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49742 protected:
[email protected]ca2902e92013-03-28 01:45:35743 explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22744 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47745 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22746 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49747 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
748 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22749 LayerImpl* child1 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43750 parent, this->identity_matrix, gfx::PointF(10.f, 0.f), gfx::Size());
danakj00f7925e2015-06-15 21:19:22751 LayerImpl* child2 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43752 parent, this->identity_matrix, gfx::PointF(30.f, 0.f), gfx::Size());
danakj00f7925e2015-06-15 21:19:22753 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
[email protected]d5467eb72014-08-22 01:16:43754 child1, this->identity_matrix, gfx::PointF(), gfx::Size(40, 50), true);
danakj00f7925e2015-06-15 21:19:22755 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
756 child2, this->identity_matrix, gfx::PointF(10.f, 0.f),
757 gfx::Size(40, 50), true);
[email protected]a27cbde2013-03-23 22:01:49758 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14759
danakj00f7925e2015-06-15 21:19:22760 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14761
[email protected]d002dd02013-03-27 07:40:40762 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22763 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:14764
[email protected]d5467eb72014-08-22 01:16:43765 // layer2's occlusion.
[email protected]a27cbde2013-03-23 22:01:49766 EXPECT_EQ(gfx::Rect().ToString(),
767 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43768 EXPECT_EQ(gfx::Rect(10, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49769 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14770
[email protected]d002dd02013-03-27 07:40:40771 this->LeaveContributingSurface(child2, &occlusion);
772 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22773 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:14774
[email protected]d5467eb72014-08-22 01:16:43775 // layer2's occlusion in the target space of layer1.
776 EXPECT_EQ(gfx::Rect(30, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49777 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43778 // layer1's occlusion.
779 EXPECT_EQ(gfx::Rect(0, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49780 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14781
[email protected]d002dd02013-03-27 07:40:40782 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22783 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14784
[email protected]d5467eb72014-08-22 01:16:43785 // The occlusion from from layer1 and layer2 is merged.
786 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
787 EXPECT_EQ(gfx::Rect(10, 0, 70, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49788 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49789 }
[email protected]94f206c12012-08-25 00:09:14790};
791
[email protected]96baf3e2012-10-22 23:09:55792ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:14793
[email protected]ca2902e92013-03-28 01:45:35794class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms
danakj00f7925e2015-06-15 21:19:22795 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49796 protected:
[email protected]ca2902e92013-03-28 01:45:35797 explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(
[email protected]a27cbde2013-03-23 22:01:49798 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22799 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47800 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49801 gfx::Transform child1_transform;
802 child1_transform.Translate(250.0, 250.0);
803 child1_transform.Rotate(-90.0);
804 child1_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14805
[email protected]a27cbde2013-03-23 22:01:49806 gfx::Transform child2_transform;
807 child2_transform.Translate(250.0, 250.0);
808 child2_transform.Rotate(90.0);
809 child2_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14810
danakj00f7925e2015-06-15 21:19:22811 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49812 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
813 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22814 LayerImpl* child1 = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49815 parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10));
danakj00f7925e2015-06-15 21:19:22816 LayerImpl* child2 = this->CreateDrawingSurface(parent, child2_transform,
817 gfx::PointF(20.f, 40.f),
818 gfx::Size(10, 10), false);
819 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
820 child1, this->identity_matrix, gfx::PointF(-10.f, -20.f),
821 gfx::Size(510, 510), true);
822 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
823 child2, this->identity_matrix, gfx::PointF(-10.f, -10.f),
824 gfx::Size(510, 510), true);
[email protected]a27cbde2013-03-23 22:01:49825 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14826
danakj00f7925e2015-06-15 21:19:22827 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14828
[email protected]d002dd02013-03-27 07:40:40829 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22830 this->EnterLayer(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:14831
[email protected]a27cbde2013-03-23 22:01:49832 EXPECT_EQ(gfx::Rect().ToString(),
833 occlusion.occlusion_from_outside_target().ToString());
834 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
835 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14836
[email protected]d002dd02013-03-27 07:40:40837 this->LeaveLayer(child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22838 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:14839
danakjf080b5b2014-08-23 22:18:20840 EXPECT_EQ(gfx::Rect().ToString(),
841 occlusion.occlusion_from_outside_target().ToString());
842 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
843 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14844
[email protected]d002dd02013-03-27 07:40:40845 this->LeaveContributingSurface(child2, &occlusion);
846 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22847 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:14848
[email protected]a27cbde2013-03-23 22:01:49849 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
850 occlusion.occlusion_from_outside_target().ToString());
851 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
852 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14853
[email protected]d002dd02013-03-27 07:40:40854 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22855 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14856
[email protected]a27cbde2013-03-23 22:01:49857 EXPECT_EQ(gfx::Rect().ToString(),
858 occlusion.occlusion_from_outside_target().ToString());
859 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(),
860 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14861
[email protected]a27cbde2013-03-23 22:01:49862 /* Justification for the above occlusion:
863 100
864 +---------------------+
865 |20 | layer1
866 10+----------------------------------+
867 100 || 30 | layer2 |
868 |20+----------------------------------+
869 || | | | |
870 || | | | |
871 || | | | |
872 +|-|------------------+ | |
873 | | | | 510
874 | | 510 | |
875 | | | |
876 | | | |
877 | | | |
878 | | | |
879 | | 520 | |
880 +----------------------------------+ |
881 | |
882 +----------------------------------+
883 510
884 */
885 }
[email protected]94f206c12012-08-25 00:09:14886};
887
[email protected]a27cbde2013-03-23 22:01:49888ALL_OCCLUSIONTRACKER_TEST(
889 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:14890
danakj00f7925e2015-06-15 21:19:22891class OcclusionTrackerTestFilters : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49892 protected:
[email protected]ca2902e92013-03-28 01:45:35893 explicit OcclusionTrackerTestFilters(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22894 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47895 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49896 gfx::Transform layer_transform;
897 layer_transform.Translate(250.0, 250.0);
898 layer_transform.Rotate(90.0);
899 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14900
danakj00f7925e2015-06-15 21:19:22901 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49902 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
903 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22904 TestContentLayerImpl* blur_layer = this->CreateDrawingLayer(
905 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
906 true);
907 TestContentLayerImpl* opaque_layer = this->CreateDrawingLayer(
908 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
909 true);
910 TestContentLayerImpl* opacity_layer = this->CreateDrawingLayer(
911 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
912 true);
[email protected]94f206c12012-08-25 00:09:14913
jaydasika6b5a32bf2016-04-22 21:56:36914 blur_layer->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:29915 FilterOperations filters;
916 filters.Append(FilterOperation::CreateBlurFilter(10.f));
ajumacb2b74432016-07-21 19:11:15917 blur_layer->test_properties()->filters = filters;
[email protected]94f206c12012-08-25 00:09:14918
jaydasika6b5a32bf2016-04-22 21:56:36919 opaque_layer->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:29920 filters.Clear();
921 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f));
ajumacb2b74432016-07-21 19:11:15922 opaque_layer->test_properties()->filters = filters;
[email protected]94f206c12012-08-25 00:09:14923
jaydasika6b5a32bf2016-04-22 21:56:36924 opacity_layer->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:29925 filters.Clear();
926 filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
ajumacb2b74432016-07-21 19:11:15927 opacity_layer->test_properties()->filters = filters;
[email protected]94f206c12012-08-25 00:09:14928
[email protected]a27cbde2013-03-23 22:01:49929 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14930
danakj00f7925e2015-06-15 21:19:22931 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14932
[email protected]a27cbde2013-03-23 22:01:49933 // Opacity layer won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:40934 this->VisitLayer(opacity_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22935 this->EnterContributingSurface(opacity_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14936
[email protected]a27cbde2013-03-23 22:01:49937 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
938 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14939
[email protected]a27cbde2013-03-23 22:01:49940 // And has nothing to contribute to its parent surface.
[email protected]d002dd02013-03-27 07:40:40941 this->LeaveContributingSurface(opacity_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49942 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
943 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14944
[email protected]a27cbde2013-03-23 22:01:49945 // Opaque layer will contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:40946 this->VisitLayer(opaque_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22947 this->EnterContributingSurface(opaque_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14948
[email protected]a27cbde2013-03-23 22:01:49949 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
950 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(),
951 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14952
[email protected]a27cbde2013-03-23 22:01:49953 // And it gets translated to the parent surface.
[email protected]d002dd02013-03-27 07:40:40954 this->LeaveContributingSurface(opaque_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49955 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
956 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
957 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14958
[email protected]a27cbde2013-03-23 22:01:49959 // The blur layer needs to throw away any occlusion from outside its
960 // subtree.
[email protected]e47b0a0a2013-11-18 23:26:22961 this->EnterLayer(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49962 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
963 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14964
[email protected]a27cbde2013-03-23 22:01:49965 // And it won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:40966 this->LeaveLayer(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22967 this->EnterContributingSurface(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49968 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
969 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14970
[email protected]a27cbde2013-03-23 22:01:49971 // But the opaque layer's occlusion is preserved on the parent.
[email protected]d002dd02013-03-27 07:40:40972 this->LeaveContributingSurface(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22973 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49974 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
975 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
976 occlusion.occlusion_from_inside_target().ToString());
977 }
[email protected]94f206c12012-08-25 00:09:14978};
979
[email protected]96baf3e2012-10-22 23:09:55980ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:14981
[email protected]ca2902e92013-03-28 01:45:35982class OcclusionTrackerTestOpaqueContentsRegionEmpty
danakj00f7925e2015-06-15 21:19:22983 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49984 protected:
[email protected]ca2902e92013-03-28 01:45:35985 explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22986 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47987 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22988 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49989 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
danakj00f7925e2015-06-15 21:19:22990 TestContentLayerImpl* layer =
991 this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(),
992 gfx::Size(200, 200), false);
[email protected]a27cbde2013-03-23 22:01:49993 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14994
danakj00f7925e2015-06-15 21:19:22995 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:22996 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14997
[email protected]d5467eb72014-08-22 01:16:43998 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
999 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141000
[email protected]d002dd02013-03-27 07:40:401001 this->LeaveLayer(layer, &occlusion);
1002 this->VisitContributingSurface(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221003 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141004
[email protected]a27cbde2013-03-23 22:01:491005 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]d5467eb72014-08-22 01:16:431006 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491007 }
[email protected]94f206c12012-08-25 00:09:141008};
1009
danakj00f7925e2015-06-15 21:19:221010ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141011
[email protected]ca2902e92013-03-28 01:45:351012class OcclusionTrackerTestOpaqueContentsRegionNonEmpty
danakj00f7925e2015-06-15 21:19:221013 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491014 protected:
[email protected]ca2902e92013-03-28 01:45:351015 explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221016 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471017 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221018 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491019 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
danakj00f7925e2015-06-15 21:19:221020 TestContentLayerImpl* layer = this->CreateDrawingLayer(
1021 parent, this->identity_matrix, gfx::PointF(100.f, 100.f),
1022 gfx::Size(200, 200), false);
[email protected]a27cbde2013-03-23 22:01:491023 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141024 {
danakj00f7925e2015-06-15 21:19:221025 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491026 layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:141027
[email protected]a27cbde2013-03-23 22:01:491028 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401029 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221030 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141031
[email protected]a27cbde2013-03-23 22:01:491032 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
1033 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141034 }
[email protected]a27cbde2013-03-23 22:01:491035 {
danakj00f7925e2015-06-15 21:19:221036 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491037 layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
1038
1039 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401040 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221041 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491042
1043 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(),
1044 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491045 }
1046 {
danakj00f7925e2015-06-15 21:19:221047 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491048 layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
1049
1050 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401051 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221052 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491053
1054 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
1055 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491056 }
1057 }
[email protected]94f206c12012-08-25 00:09:141058};
1059
danakj00f7925e2015-06-15 21:19:221060ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141061
[email protected]ca2902e92013-03-28 01:45:351062class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude
danakj00f7925e2015-06-15 21:19:221063 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491064 protected:
[email protected]ca2902e92013-03-28 01:45:351065 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(
1066 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221067 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471068 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491069 gfx::Transform transform;
1070 transform.Translate(50.0, 50.0);
1071 transform.ApplyPerspectiveDepth(100.0);
1072 transform.Translate3d(0.0, 0.0, 110.0);
1073 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141074
danakj00f7925e2015-06-15 21:19:221075 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491076 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
danakj00f7925e2015-06-15 21:19:221077 TestContentLayerImpl* layer = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491078 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
jaydasikaca2605e2016-04-23 02:52:521079 parent->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:201080 parent->test_properties()->sorting_context_id = 1;
jaydasikaca2605e2016-04-23 02:52:521081 layer->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:201082 layer->test_properties()->sorting_context_id = 1;
[email protected]a27cbde2013-03-23 22:01:491083 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141084
danakj00f7925e2015-06-15 21:19:221085 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141086
[email protected]a27cbde2013-03-23 22:01:491087 // The |layer| is entirely behind the camera and should not occlude.
[email protected]d002dd02013-03-27 07:40:401088 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221089 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491090 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1091 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1092 }
[email protected]94f206c12012-08-25 00:09:141093};
1094
[email protected]ca2902e92013-03-28 01:45:351095class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent
danakj00f7925e2015-06-15 21:19:221096 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491097 protected:
[email protected]ca2902e92013-03-28 01:45:351098 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(
1099 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221100 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471101 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491102 gfx::Transform surface_transform;
1103 surface_transform.Translate(300.0, 300.0);
1104 surface_transform.Scale(2.0, 2.0);
1105 surface_transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:141106
danakj00f7925e2015-06-15 21:19:221107 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491108 this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
danakj00f7925e2015-06-15 21:19:221109 TestContentLayerImpl* surface = this->CreateDrawingSurface(
[email protected]a27cbde2013-03-23 22:01:491110 parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false);
danakj00f7925e2015-06-15 21:19:221111 TestContentLayerImpl* surface2 = this->CreateDrawingSurface(
1112 parent, this->identity_matrix, gfx::PointF(50.f, 50.f),
1113 gfx::Size(300, 300), false);
[email protected]a27cbde2013-03-23 22:01:491114 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1115 surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1116 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141117
danakj00f7925e2015-06-15 21:19:221118 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141119
[email protected]d002dd02013-03-27 07:40:401120 this->VisitLayer(surface2, &occlusion);
1121 this->VisitContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141122
[email protected]a27cbde2013-03-23 22:01:491123 EXPECT_EQ(gfx::Rect().ToString(),
1124 occlusion.occlusion_from_outside_target().ToString());
1125 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(),
1126 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141127
[email protected]a27cbde2013-03-23 22:01:491128 // Clear any stored occlusion.
[email protected]d5467eb72014-08-22 01:16:431129 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
1130 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
[email protected]94f206c12012-08-25 00:09:141131
[email protected]d002dd02013-03-27 07:40:401132 this->VisitLayer(surface, &occlusion);
1133 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141134
[email protected]a27cbde2013-03-23 22:01:491135 EXPECT_EQ(gfx::Rect().ToString(),
1136 occlusion.occlusion_from_outside_target().ToString());
1137 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(),
1138 occlusion.occlusion_from_inside_target().ToString());
1139 }
[email protected]94f206c12012-08-25 00:09:141140};
1141
danakj00f7925e2015-06-15 21:19:221142ALL_OCCLUSIONTRACKER_TEST(
[email protected]a27cbde2013-03-23 22:01:491143 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:141144
[email protected]ca2902e92013-03-28 01:45:351145class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping
danakj00f7925e2015-06-15 21:19:221146 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491147 protected:
[email protected]ca2902e92013-03-28 01:45:351148 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(
1149 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221150 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471151 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221152 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491153 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1154 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221155 TestContentLayerImpl* surface =
1156 this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(),
1157 gfx::Size(500, 300), false);
[email protected]a27cbde2013-03-23 22:01:491158 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
1159 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141160
danakj00f7925e2015-06-15 21:19:221161 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141162
[email protected]d002dd02013-03-27 07:40:401163 this->VisitLayer(surface, &occlusion);
1164 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141165
[email protected]a27cbde2013-03-23 22:01:491166 EXPECT_EQ(gfx::Rect().ToString(),
1167 occlusion.occlusion_from_outside_target().ToString());
1168 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(),
1169 occlusion.occlusion_from_inside_target().ToString());
1170 }
[email protected]94f206c12012-08-25 00:09:141171};
1172
danakj00f7925e2015-06-15 21:19:221173ALL_OCCLUSIONTRACKER_TEST(
[email protected]a27cbde2013-03-23 22:01:491174 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:141175
danakj00f7925e2015-06-15 21:19:221176class OcclusionTrackerTestSurfaceChildOfSurface : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491177 protected:
[email protected]ca2902e92013-03-28 01:45:351178 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221179 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471180 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491181 // This test verifies that the surface cliprect does not end up empty and
1182 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:141183
danakj00f7925e2015-06-15 21:19:221184 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491185 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
danakj00f7925e2015-06-15 21:19:221186 LayerImpl* surface =
1187 this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(),
1188 gfx::Size(100, 100), false);
1189 LayerImpl* surface_child = this->CreateDrawingSurface(
1190 surface, this->identity_matrix, gfx::PointF(0.f, 10.f),
1191 gfx::Size(100, 50), true);
1192 LayerImpl* topmost = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491193 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
1194 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141195
danakj00f7925e2015-06-15 21:19:221196 TestOcclusionTrackerWithClip occlusion(gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141197
[email protected]a27cbde2013-03-23 22:01:491198 // |topmost| occludes everything partially so we know occlusion is happening
1199 // at all.
[email protected]d002dd02013-03-27 07:40:401200 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:141201
[email protected]a27cbde2013-03-23 22:01:491202 EXPECT_EQ(gfx::Rect().ToString(),
1203 occlusion.occlusion_from_outside_target().ToString());
1204 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1205 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141206
[email protected]d002dd02013-03-27 07:40:401207 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141208
[email protected]a27cbde2013-03-23 22:01:491209 // surface_child increases the occlusion in the screen by a narrow sliver.
1210 EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(),
1211 occlusion.occlusion_from_outside_target().ToString());
1212 // In its own surface, surface_child is at 0,0 as is its occlusion.
1213 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1214 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141215
[email protected]a27cbde2013-03-23 22:01:491216 // The root layer always has a clip rect. So the parent of |surface| has a
1217 // clip rect. However, the owning layer for |surface| does not mask to
1218 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
1219 // |surface_child| exercises different code paths as its parent does not
1220 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:141221
[email protected]e47b0a0a2013-11-18 23:26:221222 this->EnterContributingSurface(surface_child, &occlusion);
danakjf080b5b2014-08-23 22:18:201223 // The |surface_child| can't occlude its own surface, but occlusion from
1224 // |topmost| can.
1225 EXPECT_EQ(gfx::Rect().ToString(),
1226 occlusion.occlusion_on_contributing_surface_from_outside_target()
1227 .ToString());
1228 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1229 occlusion.occlusion_on_contributing_surface_from_inside_target()
1230 .ToString());
[email protected]d002dd02013-03-27 07:40:401231 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141232
[email protected]a27cbde2013-03-23 22:01:491233 // When the surface_child's occlusion is transformed up to its parent, make
danakjf080b5b2014-08-23 22:18:201234 // sure it is not clipped away inappropriately.
[email protected]e47b0a0a2013-11-18 23:26:221235 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491236 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1237 occlusion.occlusion_from_outside_target().ToString());
1238 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(),
1239 occlusion.occlusion_from_inside_target().ToString());
[email protected]d002dd02013-03-27 07:40:401240 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141241
[email protected]e47b0a0a2013-11-18 23:26:221242 this->EnterContributingSurface(surface, &occlusion);
danakjf080b5b2014-08-23 22:18:201243 // The occlusion from inside |surface| can't affect the surface, but
1244 // |topmost| can.
1245 EXPECT_EQ(gfx::Rect().ToString(),
1246 occlusion.occlusion_on_contributing_surface_from_outside_target()
1247 .ToString());
1248 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1249 occlusion.occlusion_on_contributing_surface_from_inside_target()
1250 .ToString());
1251
1252 this->LeaveContributingSurface(surface, &occlusion);
1253 this->EnterLayer(parent, &occlusion);
1254 // The occlusion in |surface| and without are merged into the parent.
1255 EXPECT_EQ(gfx::Rect().ToString(),
1256 occlusion.occlusion_from_outside_target().ToString());
1257 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(),
1258 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491259 }
[email protected]94f206c12012-08-25 00:09:141260};
1261
[email protected]96baf3e2012-10-22 23:09:551262ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:141263
[email protected]ca2902e92013-03-28 01:45:351264class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter
danakj00f7925e2015-06-15 21:19:221265 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491266 protected:
[email protected]ca2902e92013-03-28 01:45:351267 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:491268 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221269 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471270 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491271 gfx::Transform scale_by_half;
1272 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141273
[email protected]ae6b1a72013-06-25 18:49:291274 FilterOperations filters;
1275 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]94f206c12012-08-25 00:09:141276
[email protected]d5467eb72014-08-22 01:16:431277 enum Direction {
1278 LEFT,
1279 RIGHT,
1280 TOP,
1281 BOTTOM,
1282 LAST_DIRECTION = BOTTOM,
1283 };
[email protected]94f206c12012-08-25 00:09:141284
[email protected]d5467eb72014-08-22 01:16:431285 for (int i = 0; i <= LAST_DIRECTION; ++i) {
1286 SCOPED_TRACE(i);
[email protected]94f206c12012-08-25 00:09:141287
[email protected]d5467eb72014-08-22 01:16:431288 // Make a 50x50 filtered surface that is adjacent to occluding layers
1289 // which are above it in the z-order in various configurations. The
1290 // surface is scaled to test that the pixel moving is done in the target
1291 // space, where the background filter is applied.
danakj00f7925e2015-06-15 21:19:221292 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]d5467eb72014-08-22 01:16:431293 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:221294 LayerImpl* filtered_surface = this->CreateDrawingLayer(
1295 parent, scale_by_half, gfx::PointF(50.f, 50.f), gfx::Size(100, 100),
1296 false);
ajuma50bce7e2016-06-24 20:56:041297 filtered_surface->test_properties()->background_filters = filters;
[email protected]d5467eb72014-08-22 01:16:431298 gfx::Rect occlusion_rect;
1299 switch (i) {
1300 case LEFT:
1301 occlusion_rect = gfx::Rect(0, 0, 50, 200);
1302 break;
1303 case RIGHT:
jbroman19a18b12016-07-07 02:37:381304 // This is the right edge; filtered_surface is scaled by half.
[email protected]d5467eb72014-08-22 01:16:431305 occlusion_rect = gfx::Rect(100, 0, 50, 200);
1306 break;
1307 case TOP:
1308 occlusion_rect = gfx::Rect(0, 0, 200, 50);
1309 break;
1310 case BOTTOM:
jbroman19a18b12016-07-07 02:37:381311 // This is the bottom edge; filtered_surface is scaled by half.
[email protected]d5467eb72014-08-22 01:16:431312 occlusion_rect = gfx::Rect(0, 100, 200, 50);
1313 break;
1314 }
[email protected]ac7c7f52012-11-08 06:26:501315
danakj00f7925e2015-06-15 21:19:221316 LayerImpl* occluding_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:241317 parent, this->identity_matrix, gfx::PointF(occlusion_rect.origin()),
danakj00f7925e2015-06-15 21:19:221318 occlusion_rect.size(), true);
jaydasika6b5a32bf2016-04-22 21:56:361319 occluding_layer->test_properties()->force_render_surface = false;
[email protected]d5467eb72014-08-22 01:16:431320 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141321
danakj00f7925e2015-06-15 21:19:221322 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
[email protected]94f206c12012-08-25 00:09:141323
[email protected]d5467eb72014-08-22 01:16:431324 // This layer occludes pixels directly beside the filtered_surface.
1325 // Because filtered surface blends pixels in a radius, it will need to see
1326 // some of the pixels (up to radius far) underneath the occluding layers.
1327 this->VisitLayer(occluding_layer, &occlusion);
[email protected]ccb1c9a2012-12-17 03:53:191328
[email protected]d5467eb72014-08-22 01:16:431329 EXPECT_EQ(occlusion_rect.ToString(),
1330 occlusion.occlusion_from_inside_target().ToString());
1331 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141332
[email protected]d5467eb72014-08-22 01:16:431333 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141334
[email protected]d5467eb72014-08-22 01:16:431335 // The occlusion is used fully inside the surface.
1336 gfx::Rect occlusion_inside_surface =
1337 occlusion_rect - gfx::Vector2d(50, 50);
1338 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1339 EXPECT_EQ(occlusion_inside_surface.ToString(),
1340 occlusion.occlusion_from_outside_target().ToString());
[email protected]ac7c7f52012-11-08 06:26:501341
[email protected]d5467eb72014-08-22 01:16:431342 // The surface has a background blur, so it needs pixels that are
jbroman19a18b12016-07-07 02:37:381343 // currently considered occluded in order to be drawn. The pixels it
1344 // needs should be removed from the occluded area, so that they are drawn
1345 // when we get to the parent.
[email protected]d5467eb72014-08-22 01:16:431346 this->VisitContributingSurface(filtered_surface, &occlusion);
1347 this->EnterLayer(parent, &occlusion);
[email protected]ac7c7f52012-11-08 06:26:501348
jbroman56c1f9c2016-07-06 19:08:101349 // The spread due to a 10px blur is 30px.
[email protected]d5467eb72014-08-22 01:16:431350 gfx::Rect expected_occlusion = occlusion_rect;
1351 switch (i) {
1352 case LEFT:
jbroman56c1f9c2016-07-06 19:08:101353 expected_occlusion.Inset(0, 0, 30, 0);
[email protected]d5467eb72014-08-22 01:16:431354 break;
1355 case RIGHT:
jbroman56c1f9c2016-07-06 19:08:101356 expected_occlusion.Inset(30, 0, 0, 0);
[email protected]d5467eb72014-08-22 01:16:431357 break;
1358 case TOP:
jbroman56c1f9c2016-07-06 19:08:101359 expected_occlusion.Inset(0, 0, 0, 30);
[email protected]d5467eb72014-08-22 01:16:431360 break;
1361 case BOTTOM:
jbroman56c1f9c2016-07-06 19:08:101362 expected_occlusion.Inset(0, 30, 0, 0);
[email protected]d5467eb72014-08-22 01:16:431363 break;
1364 }
[email protected]94f206c12012-08-25 00:09:141365
[email protected]d5467eb72014-08-22 01:16:431366 EXPECT_EQ(expected_occlusion.ToString(),
1367 occlusion.occlusion_from_inside_target().ToString());
1368 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141369
[email protected]d5467eb72014-08-22 01:16:431370 this->DestroyLayers();
1371 }
[email protected]a27cbde2013-03-23 22:01:491372 }
[email protected]94f206c12012-08-25 00:09:141373};
1374
[email protected]a27cbde2013-03-23 22:01:491375ALL_OCCLUSIONTRACKER_TEST(
1376 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:141377
ajuma977555362016-07-19 16:12:121378class OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter
jbroman19a18b12016-07-07 02:37:381379 : public OcclusionTrackerTest {
1380 protected:
ajuma977555362016-07-19 16:12:121381 explicit OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter(
jbroman19a18b12016-07-07 02:37:381382 bool opaque_layers)
1383 : OcclusionTrackerTest(opaque_layers) {}
1384 void RunMyTest() override {
1385 gfx::Transform scale_by_half;
1386 scale_by_half.Scale(0.5, 0.5);
1387
1388 FilterOperations filters;
1389 filters.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(10, 10),
1390 5, SK_ColorBLACK));
1391
1392 enum Direction {
1393 LEFT,
1394 RIGHT,
1395 TOP,
1396 BOTTOM,
1397 LAST_DIRECTION = BOTTOM,
1398 };
1399
1400 for (int i = 0; i <= LAST_DIRECTION; ++i) {
1401 SCOPED_TRACE(i);
1402
1403 // Make a 50x50 filtered surface that is adjacent to occluding layers
1404 // which are above it in the z-order in various configurations. The
1405 // surface is scaled to test that the pixel moving is done in the target
1406 // space, where the background filter is applied.
1407 TestContentLayerImpl* parent = this->CreateRoot(
1408 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
1409 LayerImpl* filtered_surface = this->CreateDrawingLayer(
1410 parent, scale_by_half, gfx::PointF(50.f, 50.f), gfx::Size(100, 100),
1411 false);
1412 filtered_surface->test_properties()->background_filters = filters;
1413 gfx::Rect occlusion_rect;
1414 switch (i) {
1415 case LEFT:
1416 occlusion_rect = gfx::Rect(0, 0, 50, 200);
1417 break;
1418 case RIGHT:
1419 // This is the right edge; filtered_surface is scaled by half.
1420 occlusion_rect = gfx::Rect(100, 0, 50, 200);
1421 break;
1422 case TOP:
1423 occlusion_rect = gfx::Rect(0, 0, 200, 50);
1424 break;
1425 case BOTTOM:
1426 // This is the bottom edge; filtered_surface is scaled by half.
1427 occlusion_rect = gfx::Rect(0, 100, 200, 50);
1428 break;
1429 }
1430
1431 LayerImpl* occluding_layer = this->CreateDrawingLayer(
1432 parent, this->identity_matrix, gfx::PointF(occlusion_rect.origin()),
1433 occlusion_rect.size(), true);
1434 occluding_layer->test_properties()->force_render_surface = false;
1435 this->CalcDrawEtc(parent);
1436
1437 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
1438
1439 // This layer occludes pixels directly beside the filtered_surface.
1440 // Because filtered surface blends pixels in a radius, it will need to see
1441 // some of the pixels (up to radius far) underneath the occluding layers.
1442 this->VisitLayer(occluding_layer, &occlusion);
1443
1444 EXPECT_EQ(occlusion_rect.ToString(),
1445 occlusion.occlusion_from_inside_target().ToString());
1446 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1447
1448 this->VisitLayer(filtered_surface, &occlusion);
1449
1450 // The occlusion is used fully inside the surface.
1451 gfx::Rect occlusion_inside_surface =
1452 occlusion_rect - gfx::Vector2d(50, 50);
1453 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1454 EXPECT_EQ(occlusion_inside_surface.ToString(),
1455 occlusion.occlusion_from_outside_target().ToString());
1456
1457 // The surface has a background filter, so it needs pixels that are
1458 // currently considered occluded in order to be drawn. The pixels it
1459 // needs should be removed from the occluded area, so that they are drawn
1460 // when we get to the parent.
1461 this->VisitContributingSurface(filtered_surface, &occlusion);
1462 this->EnterLayer(parent, &occlusion);
1463
1464 gfx::Rect expected_occlusion;
1465 switch (i) {
1466 case LEFT:
1467 // The right half of the occlusion is close enough to cast a shadow
1468 // that would be visible in the background filter. The shadow reaches
1469 // 3*5 + 10 = 25 pixels to the right.
1470 expected_occlusion = gfx::Rect(0, 0, 25, 200);
1471 break;
1472 case RIGHT:
1473 // The shadow spreads 3*5 - 10 = 5 pixels to the left, so the
1474 // occlusion must recede by 5 to account for that.
1475 expected_occlusion = gfx::Rect(105, 0, 45, 200);
1476 break;
1477 case TOP:
1478 // Similar to LEFT.
1479 expected_occlusion = gfx::Rect(0, 0, 200, 25);
1480 break;
1481 case BOTTOM:
1482 // Similar to RIGHT.
1483 expected_occlusion = gfx::Rect(0, 105, 200, 45);
1484 break;
1485 }
1486
1487 EXPECT_EQ(expected_occlusion.ToString(),
1488 occlusion.occlusion_from_inside_target().ToString());
1489 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1490
1491 this->DestroyLayers();
1492 }
1493 }
1494};
1495
1496ALL_OCCLUSIONTRACKER_TEST(
ajuma977555362016-07-19 16:12:121497 OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter);
jbroman19a18b12016-07-07 02:37:381498
[email protected]ca2902e92013-03-28 01:45:351499class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice
danakj00f7925e2015-06-15 21:19:221500 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491501 protected:
[email protected]ca2902e92013-03-28 01:45:351502 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(
[email protected]a27cbde2013-03-23 22:01:491503 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221504 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471505 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491506 gfx::Transform scale_by_half;
1507 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141508
[email protected]a27cbde2013-03-23 22:01:491509 // Makes two surfaces that completely cover |parent|. The occlusion both
1510 // above and below the filters will be reduced by each of them.
danakj00f7925e2015-06-15 21:19:221511 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491512 this->identity_matrix, gfx::PointF(), gfx::Size(75, 75));
danakj00f7925e2015-06-15 21:19:221513 LayerImpl* parent = this->CreateSurface(root, scale_by_half, gfx::PointF(),
1514 gfx::Size(150, 150));
[email protected]a27cbde2013-03-23 22:01:491515 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221516 LayerImpl* filtered_surface1 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491517 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
danakj00f7925e2015-06-15 21:19:221518 LayerImpl* filtered_surface2 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491519 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
danakj00f7925e2015-06-15 21:19:221520 LayerImpl* occluding_layer_above = this->CreateDrawingLayer(
1521 parent, this->identity_matrix, gfx::PointF(100.f, 100.f),
1522 gfx::Size(50, 50), true);
[email protected]94f206c12012-08-25 00:09:141523
[email protected]a27cbde2013-03-23 22:01:491524 // Filters make the layers own surfaces.
jaydasika6b5a32bf2016-04-22 21:56:361525 filtered_surface1->test_properties()->force_render_surface = true;
1526 filtered_surface2->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291527 FilterOperations filters;
1528 filters.Append(FilterOperation::CreateBlurFilter(1.f));
ajuma50bce7e2016-06-24 20:56:041529 filtered_surface1->test_properties()->background_filters = filters;
1530 filtered_surface2->test_properties()->background_filters = filters;
[email protected]94f206c12012-08-25 00:09:141531
[email protected]a27cbde2013-03-23 22:01:491532 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141533
danakj00f7925e2015-06-15 21:19:221534 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141535
[email protected]d002dd02013-03-27 07:40:401536 this->VisitLayer(occluding_layer_above, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491537 EXPECT_EQ(gfx::Rect().ToString(),
1538 occlusion.occlusion_from_outside_target().ToString());
1539 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(),
1540 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141541
[email protected]d002dd02013-03-27 07:40:401542 this->VisitLayer(filtered_surface2, &occlusion);
1543 this->VisitContributingSurface(filtered_surface2, &occlusion);
1544 this->VisitLayer(filtered_surface1, &occlusion);
1545 this->VisitContributingSurface(filtered_surface1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141546
[email protected]a27cbde2013-03-23 22:01:491547 // Test expectations in the target.
jbroman56c1f9c2016-07-06 19:08:101548 int blur_outset = 3;
[email protected]a27cbde2013-03-23 22:01:491549 gfx::Rect expected_occlusion =
jbroman56c1f9c2016-07-06 19:08:101550 gfx::Rect(100 / 2 + blur_outset * 2, 100 / 2 + blur_outset * 2,
1551 50 / 2 - blur_outset * 4, 50 / 2 - blur_outset * 4);
[email protected]a27cbde2013-03-23 22:01:491552 EXPECT_EQ(expected_occlusion.ToString(),
1553 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141554
[email protected]a27cbde2013-03-23 22:01:491555 // Test expectations in the screen are the same as in the target, as the
1556 // render surface is 1:1 with the screen.
1557 EXPECT_EQ(expected_occlusion.ToString(),
1558 occlusion.occlusion_from_outside_target().ToString());
1559 }
[email protected]94f206c12012-08-25 00:09:141560};
1561
[email protected]a27cbde2013-03-23 22:01:491562ALL_OCCLUSIONTRACKER_TEST(
1563 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:141564
[email protected]ca2902e92013-03-28 01:45:351565class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter
danakj00f7925e2015-06-15 21:19:221566 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491567 protected:
[email protected]ca2902e92013-03-28 01:45:351568 explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:491569 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221570 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471571 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491572 gfx::Transform scale_by_half;
1573 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141574
wangxianzhu932d7f12016-09-30 05:47:001575 // Make a 50x50 surface, with a smaller 30x30 layer centered below it.
1576 // The surface is scaled to test that the pixel moving is done in the target
1577 // space, where the background filter is applied, and the surface appears at
1578 // 50, 50.
danakj00f7925e2015-06-15 21:19:221579 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491580 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
danakj00f7925e2015-06-15 21:19:221581 LayerImpl* behind_surface_layer = this->CreateDrawingLayer(
1582 parent, this->identity_matrix, gfx::PointF(60.f, 60.f),
1583 gfx::Size(30, 30), true);
danakj00f7925e2015-06-15 21:19:221584 LayerImpl* filtered_surface =
1585 this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f),
1586 gfx::Size(100, 100), false);
[email protected]94f206c12012-08-25 00:09:141587
[email protected]a27cbde2013-03-23 22:01:491588 // Filters make the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361589 filtered_surface->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291590 FilterOperations filters;
1591 filters.Append(FilterOperation::CreateBlurFilter(3.f));
ajuma50bce7e2016-06-24 20:56:041592 filtered_surface->test_properties()->background_filters = filters;
[email protected]94f206c12012-08-25 00:09:141593
[email protected]a27cbde2013-03-23 22:01:491594 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141595
danakj00f7925e2015-06-15 21:19:221596 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141597
[email protected]a27cbde2013-03-23 22:01:491598 // The surface has a background blur, so it blurs non-opaque pixels below
1599 // it.
[email protected]d002dd02013-03-27 07:40:401600 this->VisitLayer(filtered_surface, &occlusion);
1601 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141602
[email protected]d5467eb72014-08-22 01:16:431603 // The layers behind the surface are not blurred, and their occlusion does
1604 // not change, until we leave the surface. So it should not be modified by
1605 // the filter here.
[email protected]d5467eb72014-08-22 01:16:431606 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1607
1608 // Clear the occlusion so the |behind_surface_layer| can add its occlusion
1609 // without existing occlusion interfering.
1610 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
1611
[email protected]d002dd02013-03-27 07:40:401612 this->VisitLayer(behind_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141613
[email protected]a27cbde2013-03-23 22:01:491614 // The layers behind the surface are not blurred, and their occlusion does
1615 // not change, until we leave the surface. So it should not be modified by
1616 // the filter here.
1617 gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30);
[email protected]d5467eb72014-08-22 01:16:431618 EXPECT_EQ(occlusion_behind_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:491619 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431620 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491621 }
[email protected]94f206c12012-08-25 00:09:141622};
1623
[email protected]a27cbde2013-03-23 22:01:491624ALL_OCCLUSIONTRACKER_TEST(
1625 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:141626
[email protected]ca2902e92013-03-28 01:45:351627class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded
danakj00f7925e2015-06-15 21:19:221628 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491629 protected:
[email protected]ca2902e92013-03-28 01:45:351630 explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(
[email protected]a27cbde2013-03-23 22:01:491631 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221632 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471633 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491634 gfx::Transform scale_by_half;
1635 scale_by_half.Scale(0.5, 0.5);
1636
[email protected]66b52e12013-11-17 15:53:181637 // Make a 50x50 filtered surface that is completely occluded by an opaque
1638 // layer which is above it in the z-order. The surface is
[email protected]a27cbde2013-03-23 22:01:491639 // scaled to test that the pixel moving is done in the target space, where
wangxianzhu932d7f12016-09-30 05:47:001640 // the background filter is applied, and the surface appears at 50, 50.
danakj00f7925e2015-06-15 21:19:221641 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]66b52e12013-11-17 15:53:181642 this->identity_matrix, gfx::PointF(), gfx::Size(200, 150));
danakj00f7925e2015-06-15 21:19:221643 LayerImpl* filtered_surface =
1644 this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f),
1645 gfx::Size(100, 100), false);
1646 LayerImpl* occluding_layer = this->CreateDrawingLayer(
1647 parent, this->identity_matrix, gfx::PointF(50.f, 50.f),
1648 gfx::Size(50, 50), true);
[email protected]a27cbde2013-03-23 22:01:491649
1650 // Filters make the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361651 filtered_surface->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291652 FilterOperations filters;
1653 filters.Append(FilterOperation::CreateBlurFilter(3.f));
ajuma50bce7e2016-06-24 20:56:041654 filtered_surface->test_properties()->background_filters = filters;
[email protected]a27cbde2013-03-23 22:01:491655
1656 this->CalcDrawEtc(parent);
1657
danakj00f7925e2015-06-15 21:19:221658 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491659
[email protected]66b52e12013-11-17 15:53:181660 this->VisitLayer(occluding_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491661
[email protected]d002dd02013-03-27 07:40:401662 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141663 {
[email protected]a27cbde2013-03-23 22:01:491664 // The layers above the filtered surface occlude from outside.
1665 gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50);
[email protected]94f206c12012-08-25 00:09:141666
[email protected]a27cbde2013-03-23 22:01:491667 EXPECT_EQ(gfx::Rect().ToString(),
1668 occlusion.occlusion_from_inside_target().ToString());
[email protected]66b52e12013-11-17 15:53:181669 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:491670 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141671 }
[email protected]a27cbde2013-03-23 22:01:491672
1673 // The surface has a background blur, so it blurs non-opaque pixels below
1674 // it.
[email protected]d002dd02013-03-27 07:40:401675 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491676 {
1677 // The filter is completely occluded, so it should not blur anything and
1678 // reduce any occlusion.
1679 gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50);
[email protected]a27cbde2013-03-23 22:01:491680
[email protected]66b52e12013-11-17 15:53:181681 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:491682 occlusion.occlusion_from_inside_target().ToString());
1683 EXPECT_EQ(gfx::Rect().ToString(),
1684 occlusion.occlusion_from_outside_target().ToString());
1685 }
1686 }
[email protected]94f206c12012-08-25 00:09:141687};
1688
[email protected]a27cbde2013-03-23 22:01:491689ALL_OCCLUSIONTRACKER_TEST(
1690 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:141691
danakj00f7925e2015-06-15 21:19:221692class OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded
1693 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491694 protected:
danakj00f7925e2015-06-15 21:19:221695 explicit OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded(
[email protected]a27cbde2013-03-23 22:01:491696 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221697 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471698 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491699 gfx::Transform scale_by_half;
1700 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141701
wangxianzhu932d7f12016-09-30 05:47:001702 // Make a 50x50 surface which is partially occluded by opaque layers which
1703 // are above it in the z-order. The surface is scaled to test that the
1704 // pixel moving is done in the target space, where the background filter is
1705 // applied, but the surface appears at 50, 50.
danakj00f7925e2015-06-15 21:19:221706 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491707 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
danakj00f7925e2015-06-15 21:19:221708 LayerImpl* filtered_surface =
1709 this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f),
1710 gfx::Size(100, 100), false);
danakj00f7925e2015-06-15 21:19:221711 LayerImpl* above_surface_layer = this->CreateDrawingLayer(
1712 parent, this->identity_matrix, gfx::PointF(70.f, 50.f),
1713 gfx::Size(30, 50), true);
danakj00f7925e2015-06-15 21:19:221714 LayerImpl* beside_surface_layer = this->CreateDrawingLayer(
1715 parent, this->identity_matrix, gfx::PointF(90.f, 40.f),
1716 gfx::Size(10, 10), true);
[email protected]94f206c12012-08-25 00:09:141717
[email protected]a27cbde2013-03-23 22:01:491718 // Filters make the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361719 filtered_surface->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291720 FilterOperations filters;
1721 filters.Append(FilterOperation::CreateBlurFilter(3.f));
ajuma50bce7e2016-06-24 20:56:041722 filtered_surface->test_properties()->background_filters = filters;
[email protected]94f206c12012-08-25 00:09:141723
[email protected]a27cbde2013-03-23 22:01:491724 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141725
danakj00f7925e2015-06-15 21:19:221726 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141727
[email protected]d002dd02013-03-27 07:40:401728 this->VisitLayer(beside_surface_layer, &occlusion);
[email protected]d002dd02013-03-27 07:40:401729 this->VisitLayer(above_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141730
[email protected]a27cbde2013-03-23 22:01:491731 // The surface has a background blur, so it blurs non-opaque pixels below
1732 // it.
[email protected]d002dd02013-03-27 07:40:401733 this->VisitLayer(filtered_surface, &occlusion);
1734 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141735
wangxianzhu932d7f12016-09-30 05:47:001736 // The filter in the surface is partially unoccluded. Only the unoccluded
1737 // parts should reduce occlusion. This means it will push back the
1738 // occlusion that touches the unoccluded part (occlusion_above___), but
[email protected]a27cbde2013-03-23 22:01:491739 // it will not touch occlusion_beside____ since that is not beside the
1740 // unoccluded part of the surface, even though it is beside the occluded
1741 // part of the surface.
jbroman56c1f9c2016-07-06 19:08:101742 int blur_outset = 9;
[email protected]a27cbde2013-03-23 22:01:491743 gfx::Rect occlusion_above_surface =
jbroman56c1f9c2016-07-06 19:08:101744 gfx::Rect(70 + blur_outset, 50, 30 - blur_outset, 50);
[email protected]a27cbde2013-03-23 22:01:491745 gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:141746
[email protected]d5467eb72014-08-22 01:16:431747 SimpleEnclosedRegion expected_occlusion;
[email protected]d5467eb72014-08-22 01:16:431748 expected_occlusion.Union(occlusion_beside_surface);
[email protected]d5467eb72014-08-22 01:16:431749 expected_occlusion.Union(occlusion_above_surface);
[email protected]94f206c12012-08-25 00:09:141750
[email protected]d5467eb72014-08-22 01:16:431751 EXPECT_EQ(expected_occlusion.ToString(),
[email protected]a27cbde2013-03-23 22:01:491752 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431753 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141754
[email protected]d5467eb72014-08-22 01:16:431755 const SimpleEnclosedRegion& actual_occlusion =
1756 occlusion.occlusion_from_inside_target();
1757 for (size_t i = 0; i < expected_occlusion.GetRegionComplexity(); ++i) {
1758 ASSERT_LT(i, actual_occlusion.GetRegionComplexity());
1759 EXPECT_EQ(expected_occlusion.GetRect(i), actual_occlusion.GetRect(i));
[email protected]94f206c12012-08-25 00:09:141760 }
[email protected]a27cbde2013-03-23 22:01:491761 }
[email protected]94f206c12012-08-25 00:09:141762};
1763
[email protected]a27cbde2013-03-23 22:01:491764ALL_OCCLUSIONTRACKER_TEST(
danakj00f7925e2015-06-15 21:19:221765 OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:141766
danakj4902c302015-02-13 22:12:161767class OcclusionTrackerTestBlendModeDoesNotOcclude
danakj00f7925e2015-06-15 21:19:221768 : public OcclusionTrackerTest {
danakj4902c302015-02-13 22:12:161769 protected:
1770 explicit OcclusionTrackerTestBlendModeDoesNotOcclude(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221771 : OcclusionTrackerTest(opaque_layers) {}
danakj4902c302015-02-13 22:12:161772 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221773 TestContentLayerImpl* parent = this->CreateRoot(
danakj4902c302015-02-13 22:12:161774 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
danakj00f7925e2015-06-15 21:19:221775 LayerImpl* blend_mode_layer = this->CreateDrawingLayer(
danakj4902c302015-02-13 22:12:161776 parent, this->identity_matrix, gfx::PointF(0.f, 0.f),
1777 gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:221778 LayerImpl* top_layer = this->CreateDrawingLayer(
danakj4902c302015-02-13 22:12:161779 parent, this->identity_matrix, gfx::PointF(10.f, 12.f),
1780 gfx::Size(20, 22), true);
1781
1782 // Blend mode makes the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361783 blend_mode_layer->test_properties()->force_render_surface = true;
reedcc9c70f2016-11-22 04:26:011784 blend_mode_layer->test_properties()->blend_mode = SkBlendMode::kMultiply;
danakj4902c302015-02-13 22:12:161785
1786 this->CalcDrawEtc(parent);
1787
danakj00f7925e2015-06-15 21:19:221788 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
danakj4902c302015-02-13 22:12:161789
1790 this->VisitLayer(top_layer, &occlusion);
1791 // |top_layer| occludes.
1792 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(),
1793 occlusion.occlusion_from_inside_target().ToString());
1794 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1795
1796 this->VisitLayer(blend_mode_layer, &occlusion);
ajuma2d466aa2016-07-25 21:11:001797 // |top_layer| and |blend_mode_layer| both occlude, since the blend mode
1798 // gets applied by blend_mode_layer's render surface, not when drawing the
1799 // layer itself.
1800 EXPECT_EQ(gfx::Rect(100, 100).ToString(),
1801 occlusion.occlusion_from_inside_target().ToString());
danakj4902c302015-02-13 22:12:161802 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(),
1803 occlusion.occlusion_from_outside_target().ToString());
danakj4902c302015-02-13 22:12:161804
1805 this->VisitContributingSurface(blend_mode_layer, &occlusion);
1806 // |top_layer| occludes but not |blend_mode_layer|.
1807 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(),
1808 occlusion.occlusion_from_inside_target().ToString());
1809 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1810 }
1811};
1812
1813ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestBlendModeDoesNotOcclude);
1814
danakj00f7925e2015-06-15 21:19:221815class OcclusionTrackerTestMinimumTrackingSize : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491816 protected:
[email protected]ca2902e92013-03-28 01:45:351817 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221818 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471819 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491820 gfx::Size tracking_size(100, 100);
1821 gfx::Size below_tracking_size(99, 99);
[email protected]94f206c12012-08-25 00:09:141822
danakj00f7925e2015-06-15 21:19:221823 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491824 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221825 LayerImpl* large = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491826 parent, this->identity_matrix, gfx::PointF(), tracking_size, true);
danakj00f7925e2015-06-15 21:19:221827 LayerImpl* small =
1828 this->CreateDrawingLayer(parent, this->identity_matrix, gfx::PointF(),
1829 below_tracking_size, true);
[email protected]a27cbde2013-03-23 22:01:491830 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141831
danakj00f7925e2015-06-15 21:19:221832 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491833 occlusion.set_minimum_tracking_size(tracking_size);
[email protected]94f206c12012-08-25 00:09:141834
[email protected]a27cbde2013-03-23 22:01:491835 // The small layer is not tracked because it is too small.
[email protected]d002dd02013-03-27 07:40:401836 this->VisitLayer(small, &occlusion);
[email protected]94f206c12012-08-25 00:09:141837
[email protected]a27cbde2013-03-23 22:01:491838 EXPECT_EQ(gfx::Rect().ToString(),
1839 occlusion.occlusion_from_outside_target().ToString());
1840 EXPECT_EQ(gfx::Rect().ToString(),
1841 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141842
[email protected]a27cbde2013-03-23 22:01:491843 // The large layer is tracked as it is large enough.
[email protected]d002dd02013-03-27 07:40:401844 this->VisitLayer(large, &occlusion);
[email protected]94f206c12012-08-25 00:09:141845
[email protected]a27cbde2013-03-23 22:01:491846 EXPECT_EQ(gfx::Rect().ToString(),
1847 occlusion.occlusion_from_outside_target().ToString());
[email protected]2c7c6702013-03-26 03:14:051848 EXPECT_EQ(gfx::Rect(tracking_size).ToString(),
[email protected]a27cbde2013-03-23 22:01:491849 occlusion.occlusion_from_inside_target().ToString());
1850 }
[email protected]94f206c12012-08-25 00:09:141851};
1852
[email protected]96baf3e2012-10-22 23:09:551853ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:141854
danakj00f7925e2015-06-15 21:19:221855class OcclusionTrackerTestScaledLayerIsClipped : public OcclusionTrackerTest {
[email protected]1a5d9ce2013-04-30 01:31:091856 protected:
1857 explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221858 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471859 void RunMyTest() override {
[email protected]1a5d9ce2013-04-30 01:31:091860 gfx::Transform scale_transform;
1861 scale_transform.Scale(512.0, 512.0);
1862
danakj00f7925e2015-06-15 21:19:221863 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]1a5d9ce2013-04-30 01:31:091864 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221865 LayerImpl* clip =
1866 this->CreateLayer(parent, this->identity_matrix,
1867 gfx::PointF(10.f, 10.f), gfx::Size(50, 50));
[email protected]1a5d9ce2013-04-30 01:31:091868 clip->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221869 LayerImpl* scale = this->CreateLayer(clip, scale_transform, gfx::PointF(),
1870 gfx::Size(1, 1));
1871 LayerImpl* scaled = this->CreateDrawingLayer(
[email protected]1a5d9ce2013-04-30 01:31:091872 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
1873 this->CalcDrawEtc(parent);
1874
danakj00f7925e2015-06-15 21:19:221875 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]1a5d9ce2013-04-30 01:31:091876
1877 this->VisitLayer(scaled, &occlusion);
1878
1879 EXPECT_EQ(gfx::Rect().ToString(),
1880 occlusion.occlusion_from_outside_target().ToString());
1881 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
1882 occlusion.occlusion_from_inside_target().ToString());
1883 }
1884};
1885
1886ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped)
1887
[email protected]1a5d9ce2013-04-30 01:31:091888class OcclusionTrackerTestScaledLayerInSurfaceIsClipped
danakj00f7925e2015-06-15 21:19:221889 : public OcclusionTrackerTest {
[email protected]1a5d9ce2013-04-30 01:31:091890 protected:
1891 explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221892 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471893 void RunMyTest() override {
[email protected]1a5d9ce2013-04-30 01:31:091894 gfx::Transform scale_transform;
1895 scale_transform.Scale(512.0, 512.0);
1896
danakj00f7925e2015-06-15 21:19:221897 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]1a5d9ce2013-04-30 01:31:091898 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221899 LayerImpl* clip =
1900 this->CreateLayer(parent, this->identity_matrix,
1901 gfx::PointF(10.f, 10.f), gfx::Size(50, 50));
[email protected]1a5d9ce2013-04-30 01:31:091902 clip->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221903 LayerImpl* surface = this->CreateDrawingSurface(
[email protected]1a5d9ce2013-04-30 01:31:091904 clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false);
danakj00f7925e2015-06-15 21:19:221905 LayerImpl* scale = this->CreateLayer(surface, scale_transform,
1906 gfx::PointF(), gfx::Size(1, 1));
1907 LayerImpl* scaled = this->CreateDrawingLayer(
[email protected]1a5d9ce2013-04-30 01:31:091908 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
1909 this->CalcDrawEtc(parent);
1910
danakj00f7925e2015-06-15 21:19:221911 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]1a5d9ce2013-04-30 01:31:091912
1913 this->VisitLayer(scaled, &occlusion);
1914 this->VisitLayer(surface, &occlusion);
1915 this->VisitContributingSurface(surface, &occlusion);
1916
1917 EXPECT_EQ(gfx::Rect().ToString(),
1918 occlusion.occlusion_from_outside_target().ToString());
1919 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
1920 occlusion.occlusion_from_inside_target().ToString());
1921 }
1922};
1923
1924ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped)
1925
danakj00f7925e2015-06-15 21:19:221926class OcclusionTrackerTestCopyRequestDoesOcclude : public OcclusionTrackerTest {
[email protected]5b54b972013-07-26 13:25:421927 protected:
1928 explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221929 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471930 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221931 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:241932 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221933 TestContentLayerImpl* parent = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:241934 root, this->identity_matrix, gfx::PointF(), gfx::Size(400, 400), true);
1935 LayerImpl* copy =
1936 this->CreateLayer(parent, this->identity_matrix, gfx::PointF(100, 0),
1937 gfx::Size(200, 400));
[email protected]5b54b972013-07-26 13:25:421938 this->AddCopyRequest(copy);
danakj00f7925e2015-06-15 21:19:221939 LayerImpl* copy_child = this->CreateDrawingLayer(
1940 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
1941 LayerImpl* top_layer =
danakj4902c302015-02-13 22:12:161942 this->CreateDrawingLayer(root, this->identity_matrix,
1943 gfx::PointF(50, 0), gfx::Size(50, 400), true);
[email protected]5b54b972013-07-26 13:25:421944 this->CalcDrawEtc(root);
1945
danakj00f7925e2015-06-15 21:19:221946 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]5b54b972013-07-26 13:25:421947
danakj4902c302015-02-13 22:12:161948 this->VisitLayer(top_layer, &occlusion);
1949 EXPECT_EQ(gfx::Rect().ToString(),
1950 occlusion.occlusion_from_outside_target().ToString());
1951 EXPECT_EQ(gfx::Rect(50, 0, 50, 400).ToString(),
1952 occlusion.occlusion_from_inside_target().ToString());
1953
[email protected]5b54b972013-07-26 13:25:421954 this->VisitLayer(copy_child, &occlusion);
danakj4902c302015-02-13 22:12:161955 // Layers outside the copy request do not occlude.
[email protected]5b54b972013-07-26 13:25:421956 EXPECT_EQ(gfx::Rect().ToString(),
1957 occlusion.occlusion_from_outside_target().ToString());
1958 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
1959 occlusion.occlusion_from_inside_target().ToString());
1960
1961 // CopyRequests cause the layer to own a surface.
1962 this->VisitContributingSurface(copy, &occlusion);
1963
1964 // The occlusion from the copy should be kept.
1965 EXPECT_EQ(gfx::Rect().ToString(),
1966 occlusion.occlusion_from_outside_target().ToString());
danakj4902c302015-02-13 22:12:161967 EXPECT_EQ(gfx::Rect(50, 0, 250, 400).ToString(),
[email protected]5b54b972013-07-26 13:25:421968 occlusion.occlusion_from_inside_target().ToString());
1969 }
1970};
1971
1972ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude)
1973
[email protected]5b54b972013-07-26 13:25:421974class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude
danakj00f7925e2015-06-15 21:19:221975 : public OcclusionTrackerTest {
[email protected]5b54b972013-07-26 13:25:421976 protected:
1977 explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude(
1978 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221979 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471980 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221981 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:241982 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221983 TestContentLayerImpl* parent = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:241984 root, this->identity_matrix, gfx::PointF(), gfx::Size(400, 400), true);
danakj00f7925e2015-06-15 21:19:221985 LayerImpl* hide = this->CreateLayer(parent, this->identity_matrix,
danakja2fdbc702015-10-20 23:05:241986 gfx::PointF(), gfx::Size());
1987 LayerImpl* copy =
1988 this->CreateLayer(hide, this->identity_matrix, gfx::PointF(100.f, 0.f),
1989 gfx::Size(200, 400));
[email protected]5b54b972013-07-26 13:25:421990 this->AddCopyRequest(copy);
danakj00f7925e2015-06-15 21:19:221991 LayerImpl* copy_child = this->CreateDrawingLayer(
[email protected]5b54b972013-07-26 13:25:421992 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
1993
1994 // The |copy| layer is hidden but since it is being copied, it will be
1995 // drawn.
jaydasika5121caa82016-05-05 15:43:351996 hide->test_properties()->hide_layer_and_subtree = true;
[email protected]5b54b972013-07-26 13:25:421997
1998 this->CalcDrawEtc(root);
1999
danakj00f7925e2015-06-15 21:19:222000 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]5b54b972013-07-26 13:25:422001
2002 this->VisitLayer(copy_child, &occlusion);
2003 EXPECT_EQ(gfx::Rect().ToString(),
2004 occlusion.occlusion_from_outside_target().ToString());
2005 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
2006 occlusion.occlusion_from_inside_target().ToString());
2007
2008 // CopyRequests cause the layer to own a surface.
2009 this->VisitContributingSurface(copy, &occlusion);
2010
2011 // The occlusion from the copy should be dropped since it is hidden.
2012 EXPECT_EQ(gfx::Rect().ToString(),
2013 occlusion.occlusion_from_outside_target().ToString());
2014 EXPECT_EQ(gfx::Rect().ToString(),
2015 occlusion.occlusion_from_inside_target().ToString());
2016 }
2017};
2018
2019ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude)
2020
danakj00f7925e2015-06-15 21:19:222021class OcclusionTrackerTestOccludedLayer : public OcclusionTrackerTest {
[email protected]d5467eb72014-08-22 01:16:432022 protected:
2023 explicit OcclusionTrackerTestOccludedLayer(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:222024 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472025 void RunMyTest() override {
[email protected]d5467eb72014-08-22 01:16:432026 gfx::Transform translate;
2027 translate.Translate(10.0, 20.0);
danakj00f7925e2015-06-15 21:19:222028 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:242029 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2030 LayerImpl* surface = this->CreateSurface(
2031 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:222032 LayerImpl* layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242033 surface, translate, gfx::PointF(), gfx::Size(200, 200), false);
danakj00f7925e2015-06-15 21:19:222034 TestContentLayerImpl* outside_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242035 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false);
[email protected]d5467eb72014-08-22 01:16:432036 this->CalcDrawEtc(root);
2037
danakj00f7925e2015-06-15 21:19:222038 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
[email protected]d5467eb72014-08-22 01:16:432039 this->VisitLayer(outside_layer, &occlusion);
2040 this->EnterLayer(layer, &occlusion);
2041
2042 // No occlusion, is not occluded.
2043 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2044 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2045 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100)));
2046
2047 // Partial occlusion from outside, is not occluded.
2048 occlusion.set_occlusion_from_outside_target(
2049 SimpleEnclosedRegion(50, 50, 100, 100));
2050 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2051 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2052 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2053 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2054 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2055 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2056 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2057 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2058 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2059
2060 // Full occlusion from outside, is occluded.
2061 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2062 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2063 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2064 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2065
2066 // Partial occlusion from inside, is not occluded.
2067 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2068 occlusion.set_occlusion_from_inside_target(
2069 SimpleEnclosedRegion(50, 50, 100, 100));
2070 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2071 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2072 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2073 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2074 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2075 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2076 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2077 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2078
2079 // Full occlusion from inside, is occluded.
2080 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2081 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2082 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2083 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2084
2085 // Partial occlusion from both, is not occluded.
2086 occlusion.set_occlusion_from_outside_target(
2087 SimpleEnclosedRegion(50, 50, 100, 50));
2088 occlusion.set_occlusion_from_inside_target(
2089 SimpleEnclosedRegion(50, 100, 100, 50));
2090 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2091 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2092 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2093 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2094 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2095 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2096 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2097 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2098
2099 // Full occlusion from both, is occluded.
2100 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2101 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2102 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2103 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2104 }
2105};
2106
2107ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOccludedLayer)
2108
danakj00f7925e2015-06-15 21:19:222109class OcclusionTrackerTestUnoccludedLayerQuery : public OcclusionTrackerTest {
danakjf080b5b2014-08-23 22:18:202110 protected:
2111 explicit OcclusionTrackerTestUnoccludedLayerQuery(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:222112 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472113 void RunMyTest() override {
danakjf080b5b2014-08-23 22:18:202114 gfx::Transform translate;
2115 translate.Translate(10.0, 20.0);
danakj00f7925e2015-06-15 21:19:222116 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:242117 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2118 LayerImpl* surface = this->CreateSurface(
2119 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:222120 LayerImpl* layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242121 surface, translate, gfx::PointF(), gfx::Size(200, 200), false);
danakj00f7925e2015-06-15 21:19:222122 TestContentLayerImpl* outside_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242123 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false);
danakjf080b5b2014-08-23 22:18:202124 this->CalcDrawEtc(root);
2125
danakj00f7925e2015-06-15 21:19:222126 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
danakjf080b5b2014-08-23 22:18:202127 this->VisitLayer(outside_layer, &occlusion);
2128 this->EnterLayer(layer, &occlusion);
2129
2130 // No occlusion, is not occluded.
2131 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2132 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2133 EXPECT_EQ(gfx::Rect(100, 100),
2134 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(100, 100)));
2135
2136 // Partial occlusion from outside.
2137 occlusion.set_occlusion_from_outside_target(
2138 SimpleEnclosedRegion(50, 50, 100, 100));
2139 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2140 EXPECT_EQ(
2141 gfx::Rect(0, 0, 100, 100),
2142 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
2143 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2144 occlusion.UnoccludedLayerContentRect(
2145 layer, gfx::Rect(90, 30, 100, 100)));
2146 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2147 occlusion.UnoccludedLayerContentRect(layer,
2148 gfx::Rect(40, 0, 100, 100)));
2149 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2150 occlusion.UnoccludedLayerContentRect(
2151 layer, gfx::Rect(40, 80, 100, 100)));
2152 EXPECT_EQ(
2153 gfx::Rect(0, 0, 80, 100),
2154 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
2155 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2156 occlusion.UnoccludedLayerContentRect(
2157 layer, gfx::Rect(90, 80, 100, 100)));
2158 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2159 occlusion.UnoccludedLayerContentRect(layer,
2160 gfx::Rect(0, 80, 100, 100)));
2161 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2162 occlusion.UnoccludedLayerContentRect(layer,
2163 gfx::Rect(90, 0, 100, 100)));
2164
2165 // Full occlusion from outside, is occluded.
2166 EXPECT_EQ(gfx::Rect(),
2167 occlusion.UnoccludedLayerContentRect(
2168 layer, gfx::Rect(40, 30, 100, 100)));
2169 EXPECT_EQ(
2170 gfx::Rect(),
2171 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
2172 EXPECT_EQ(gfx::Rect(),
2173 occlusion.UnoccludedLayerContentRect(
2174 layer, gfx::Rect(130, 120, 10, 10)));
2175 EXPECT_EQ(
2176 gfx::Rect(),
2177 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
2178
2179 // Partial occlusion from inside, is not occluded.
2180 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2181 occlusion.set_occlusion_from_inside_target(
2182 SimpleEnclosedRegion(50, 50, 100, 100));
2183 EXPECT_EQ(
2184 gfx::Rect(0, 0, 100, 100),
2185 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
2186 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2187 occlusion.UnoccludedLayerContentRect(
2188 layer, gfx::Rect(90, 30, 100, 100)));
2189 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2190 occlusion.UnoccludedLayerContentRect(layer,
2191 gfx::Rect(40, 0, 100, 100)));
2192 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2193 occlusion.UnoccludedLayerContentRect(
2194 layer, gfx::Rect(40, 80, 100, 100)));
2195 EXPECT_EQ(
2196 gfx::Rect(0, 0, 80, 100),
2197 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
2198 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2199 occlusion.UnoccludedLayerContentRect(
2200 layer, gfx::Rect(90, 80, 100, 100)));
2201 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2202 occlusion.UnoccludedLayerContentRect(layer,
2203 gfx::Rect(0, 80, 100, 100)));
2204 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2205 occlusion.UnoccludedLayerContentRect(layer,
2206 gfx::Rect(90, 0, 100, 100)));
2207
2208 // Full occlusion from inside, is occluded.
2209 EXPECT_EQ(gfx::Rect(),
2210 occlusion.UnoccludedLayerContentRect(
2211 layer, gfx::Rect(40, 30, 100, 100)));
2212 EXPECT_EQ(
2213 gfx::Rect(),
2214 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
2215 EXPECT_EQ(gfx::Rect(),
2216 occlusion.UnoccludedLayerContentRect(
2217 layer, gfx::Rect(130, 120, 10, 10)));
2218 EXPECT_EQ(
2219 gfx::Rect(),
2220 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
2221
2222 // Partial occlusion from both, is not occluded.
2223 occlusion.set_occlusion_from_outside_target(
2224 SimpleEnclosedRegion(50, 50, 100, 50));
2225 occlusion.set_occlusion_from_inside_target(
2226 SimpleEnclosedRegion(50, 100, 100, 50));
2227 EXPECT_EQ(
2228 gfx::Rect(0, 0, 100, 100),
2229 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
2230 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
2231 // it's larger.
2232 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
2233 occlusion.UnoccludedLayerContentRect(
2234 layer, gfx::Rect(90, 30, 100, 100)));
2235 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2236 occlusion.UnoccludedLayerContentRect(layer,
2237 gfx::Rect(40, 0, 100, 100)));
2238 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2239 occlusion.UnoccludedLayerContentRect(
2240 layer, gfx::Rect(40, 80, 100, 100)));
2241 EXPECT_EQ(
2242 gfx::Rect(0, 0, 80, 100),
2243 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
2244 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2245 occlusion.UnoccludedLayerContentRect(
2246 layer, gfx::Rect(90, 80, 100, 100)));
2247 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2248 occlusion.UnoccludedLayerContentRect(layer,
2249 gfx::Rect(0, 80, 100, 100)));
2250 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2251 occlusion.UnoccludedLayerContentRect(layer,
2252 gfx::Rect(90, 0, 100, 100)));
2253
2254 // Full occlusion from both, is occluded.
2255 EXPECT_EQ(gfx::Rect(),
2256 occlusion.UnoccludedLayerContentRect(
2257 layer, gfx::Rect(40, 30, 100, 100)));
2258 EXPECT_EQ(
2259 gfx::Rect(),
2260 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
2261 EXPECT_EQ(gfx::Rect(),
2262 occlusion.UnoccludedLayerContentRect(
2263 layer, gfx::Rect(130, 120, 10, 10)));
2264 EXPECT_EQ(
2265 gfx::Rect(),
2266 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
2267 }
2268};
2269
2270ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedLayerQuery)
2271
danakj00f7925e2015-06-15 21:19:222272class OcclusionTrackerTestUnoccludedSurfaceQuery : public OcclusionTrackerTest {
danakjf080b5b2014-08-23 22:18:202273 protected:
2274 explicit OcclusionTrackerTestUnoccludedSurfaceQuery(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:222275 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472276 void RunMyTest() override {
danakjf080b5b2014-08-23 22:18:202277 gfx::Transform translate;
2278 translate.Translate(10.0, 20.0);
danakj00f7925e2015-06-15 21:19:222279 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:242280 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2281 LayerImpl* surface = this->CreateSurface(root, translate, gfx::PointF(),
2282 gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:222283 LayerImpl* layer =
danakja2fdbc702015-10-20 23:05:242284 this->CreateDrawingLayer(surface, this->identity_matrix, gfx::PointF(),
danakj00f7925e2015-06-15 21:19:222285 gfx::Size(200, 200), false);
2286 TestContentLayerImpl* outside_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242287 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false);
danakjf080b5b2014-08-23 22:18:202288 this->CalcDrawEtc(root);
2289
danakj00f7925e2015-06-15 21:19:222290 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
danakjf080b5b2014-08-23 22:18:202291 this->VisitLayer(outside_layer, &occlusion);
2292 this->VisitLayer(layer, &occlusion);
2293 this->EnterContributingSurface(surface, &occlusion);
2294
2295 // No occlusion, is not occluded.
2296 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2297 SimpleEnclosedRegion());
2298 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2299 SimpleEnclosedRegion());
2300 EXPECT_EQ(
2301 gfx::Rect(100, 100),
2302 occlusion.UnoccludedSurfaceContentRect(surface, gfx::Rect(100, 100)));
2303
2304 // Partial occlusion from outside.
2305 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2306 SimpleEnclosedRegion(50, 50, 100, 100));
2307 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2308 SimpleEnclosedRegion());
2309 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2310 occlusion.UnoccludedSurfaceContentRect(
2311 surface, gfx::Rect(0, 0, 100, 100)));
2312 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2313 occlusion.UnoccludedSurfaceContentRect(
2314 surface, gfx::Rect(90, 30, 100, 100)));
2315 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2316 occlusion.UnoccludedSurfaceContentRect(
2317 surface, gfx::Rect(40, 0, 100, 100)));
2318 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2319 occlusion.UnoccludedSurfaceContentRect(
2320 surface, gfx::Rect(40, 80, 100, 100)));
2321 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
2322 occlusion.UnoccludedSurfaceContentRect(surface,
2323 gfx::Rect(0, 0, 80, 100)));
2324 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2325 occlusion.UnoccludedSurfaceContentRect(
2326 surface, gfx::Rect(90, 80, 100, 100)));
2327 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2328 occlusion.UnoccludedSurfaceContentRect(
2329 surface, gfx::Rect(0, 80, 100, 100)));
2330 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2331 occlusion.UnoccludedSurfaceContentRect(
2332 surface, gfx::Rect(90, 0, 100, 100)));
2333
2334 // Full occlusion from outside, is occluded.
2335 EXPECT_EQ(gfx::Rect(),
2336 occlusion.UnoccludedSurfaceContentRect(
2337 surface, gfx::Rect(40, 30, 100, 100)));
2338 EXPECT_EQ(gfx::Rect(),
2339 occlusion.UnoccludedSurfaceContentRect(
2340 surface, gfx::Rect(40, 30, 10, 10)));
2341 EXPECT_EQ(gfx::Rect(),
2342 occlusion.UnoccludedSurfaceContentRect(
2343 surface, gfx::Rect(130, 120, 10, 10)));
2344 EXPECT_EQ(gfx::Rect(),
2345 occlusion.UnoccludedSurfaceContentRect(
2346 surface, gfx::Rect(80, 70, 50, 50)));
2347
2348 // Partial occlusion from inside, is not occluded.
2349 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2350 SimpleEnclosedRegion());
2351 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2352 SimpleEnclosedRegion(50, 50, 100, 100));
2353 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2354 occlusion.UnoccludedSurfaceContentRect(
2355 surface, gfx::Rect(0, 0, 100, 100)));
2356 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2357 occlusion.UnoccludedSurfaceContentRect(
2358 surface, gfx::Rect(90, 30, 100, 100)));
2359 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2360 occlusion.UnoccludedSurfaceContentRect(
2361 surface, gfx::Rect(40, 0, 100, 100)));
2362 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2363 occlusion.UnoccludedSurfaceContentRect(
2364 surface, gfx::Rect(40, 80, 100, 100)));
2365 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
2366 occlusion.UnoccludedSurfaceContentRect(surface,
2367 gfx::Rect(0, 0, 80, 100)));
2368 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2369 occlusion.UnoccludedSurfaceContentRect(
2370 surface, gfx::Rect(90, 80, 100, 100)));
2371 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2372 occlusion.UnoccludedSurfaceContentRect(
2373 surface, gfx::Rect(0, 80, 100, 100)));
2374 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2375 occlusion.UnoccludedSurfaceContentRect(
2376 surface, gfx::Rect(90, 0, 100, 100)));
2377
2378 // Full occlusion from inside, is occluded.
2379 EXPECT_EQ(gfx::Rect(),
2380 occlusion.UnoccludedSurfaceContentRect(
2381 surface, gfx::Rect(40, 30, 100, 100)));
2382 EXPECT_EQ(gfx::Rect(),
2383 occlusion.UnoccludedSurfaceContentRect(
2384 surface, gfx::Rect(40, 30, 10, 10)));
2385 EXPECT_EQ(gfx::Rect(),
2386 occlusion.UnoccludedSurfaceContentRect(
2387 surface, gfx::Rect(130, 120, 10, 10)));
2388 EXPECT_EQ(gfx::Rect(),
2389 occlusion.UnoccludedSurfaceContentRect(
2390 surface, gfx::Rect(80, 70, 50, 50)));
2391
2392 // Partial occlusion from both, is not occluded.
2393 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2394 SimpleEnclosedRegion(50, 50, 100, 50));
2395 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2396 SimpleEnclosedRegion(50, 100, 100, 50));
2397 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2398 occlusion.UnoccludedSurfaceContentRect(
2399 surface, gfx::Rect(0, 0, 100, 100)));
2400 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
2401 // it's larger.
2402 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
2403 occlusion.UnoccludedSurfaceContentRect(
2404 surface, gfx::Rect(90, 30, 100, 100)));
2405 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2406 occlusion.UnoccludedSurfaceContentRect(
2407 surface, gfx::Rect(40, 0, 100, 100)));
2408 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2409 occlusion.UnoccludedSurfaceContentRect(
2410 surface, gfx::Rect(40, 80, 100, 100)));
2411 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
2412 occlusion.UnoccludedSurfaceContentRect(surface,
2413 gfx::Rect(0, 0, 80, 100)));
2414 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2415 occlusion.UnoccludedSurfaceContentRect(
2416 surface, gfx::Rect(90, 80, 100, 100)));
2417 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2418 occlusion.UnoccludedSurfaceContentRect(
2419 surface, gfx::Rect(0, 80, 100, 100)));
2420 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2421 occlusion.UnoccludedSurfaceContentRect(
2422 surface, gfx::Rect(90, 0, 100, 100)));
2423
2424 // Full occlusion from both, is occluded.
2425 EXPECT_EQ(gfx::Rect(),
2426 occlusion.UnoccludedSurfaceContentRect(
2427 surface, gfx::Rect(40, 30, 100, 100)));
2428 EXPECT_EQ(gfx::Rect(),
2429 occlusion.UnoccludedSurfaceContentRect(
2430 surface, gfx::Rect(40, 30, 10, 10)));
2431 EXPECT_EQ(gfx::Rect(),
2432 occlusion.UnoccludedSurfaceContentRect(
2433 surface, gfx::Rect(130, 120, 10, 10)));
2434 EXPECT_EQ(gfx::Rect(),
2435 occlusion.UnoccludedSurfaceContentRect(
2436 surface, gfx::Rect(80, 70, 50, 50)));
2437 }
2438};
2439
2440ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery)
2441
[email protected]ba565742012-11-10 09:29:482442} // namespace
2443} // namespace cc