blob: 8893f46dc88a97eeadca022b207442ac9550b5f4 [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"
[email protected]681ccff2013-03-18 06:13:5210#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:5211#include "cc/layers/layer.h"
12#include "cc/layers/layer_impl.h"
Khushal7865b5be2017-11-22 03:12:0613#include "cc/paint/filter_operation.h"
14#include "cc/paint/filter_operations.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"
danakjf20f4502017-09-26 17:13:3125#include "components/viz/common/frame_sinks/copy_output_request.h"
26#include "components/viz/common/frame_sinks/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
[email protected]5b54b972013-07-26 13:25:42198 void AddCopyRequest(Layer* layer) {
Yuri Wiitalab9ad27a2017-09-06 19:13:50199 layer->RequestCopyOfOutput(viz::CopyOutputRequest::CreateStubForTesting());
[email protected]5b54b972013-07-26 13:25:42200 }
201
202 void AddCopyRequest(LayerImpl* layer) {
ajumae6f541b2016-05-31 16:50:50203 layer->test_properties()->copy_requests.push_back(
Yuri Wiitalab9ad27a2017-09-06 19:13:50204 viz::CopyOutputRequest::CreateStubForTesting());
[email protected]5b54b972013-07-26 13:25:42205 }
206
[email protected]a27cbde2013-03-23 22:01:49207 void CalcDrawEtc(TestContentLayerImpl* root) {
jaydasikabf1875a2016-06-28 03:39:59208 root->layer_tree_impl()->BuildLayerListForTesting();
209 DCHECK(root == root->layer_tree_impl()->root_layer_for_testing());
[email protected]94f206c12012-08-25 00:09:14210
enned8d1c5cb2015-06-16 19:09:35211 // These occlusion tests attach and detach layers in multiple
212 // iterations, so rebuild property trees every time.
213 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
214
[email protected]7aad55f2013-07-26 11:25:53215 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:52216 root, root->bounds(), &render_surface_list_impl_);
[email protected]7aad55f2013-07-26 11:25:53217 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:57218 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]94f206c12012-08-25 00:09:14219
Jeremy Roman909d927b2017-08-27 18:34:09220 layer_iterator_ = std::make_unique<EffectTreeLayerListIterator>(
ajuma956219582017-04-04 19:58:14221 host_->host_impl()->active_tree());
[email protected]a27cbde2013-03-23 22:01:49222 }
[email protected]94f206c12012-08-25 00:09:14223
danakj00f7925e2015-06-15 21:19:22224 void EnterLayer(LayerImpl* layer, OcclusionTracker* occlusion) {
ajuma956219582017-04-04 19:58:14225 ASSERT_EQ(layer_iterator_->current_layer(), layer);
226 ASSERT_TRUE(layer_iterator_->state() ==
227 EffectTreeLayerListIterator::State::LAYER);
228 occlusion->EnterLayer(*layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49229 }
[email protected]94f206c12012-08-25 00:09:14230
danakj00f7925e2015-06-15 21:19:22231 void LeaveLayer(LayerImpl* layer, OcclusionTracker* occlusion) {
ajuma956219582017-04-04 19:58:14232 ASSERT_EQ(layer_iterator_->current_layer(), layer);
233 ASSERT_TRUE(layer_iterator_->state() ==
234 EffectTreeLayerListIterator::State::LAYER);
235 occlusion->LeaveLayer(*layer_iterator_);
236 ++(*layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49237 }
[email protected]94f206c12012-08-25 00:09:14238
danakj00f7925e2015-06-15 21:19:22239 void VisitLayer(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22240 EnterLayer(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49241 LeaveLayer(layer, occlusion);
242 }
[email protected]94f206c12012-08-25 00:09:14243
danakj00f7925e2015-06-15 21:19:22244 void EnterContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) {
ajuma956219582017-04-04 19:58:14245 ASSERT_EQ(layer_iterator_->target_render_surface(),
chrishtr7e3aaf22017-05-04 15:04:01246 GetRenderSurface(layer));
ajuma956219582017-04-04 19:58:14247 ASSERT_TRUE(layer_iterator_->state() ==
248 EffectTreeLayerListIterator::State::TARGET_SURFACE);
249 occlusion->EnterLayer(*layer_iterator_);
250 occlusion->LeaveLayer(*layer_iterator_);
251 ++(*layer_iterator_);
252 ASSERT_TRUE(layer_iterator_->state() ==
253 EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE);
254 occlusion->EnterLayer(*layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49255 }
[email protected]94f206c12012-08-25 00:09:14256
danakj00f7925e2015-06-15 21:19:22257 void LeaveContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) {
ajuma956219582017-04-04 19:58:14258 ASSERT_EQ(layer_iterator_->current_render_surface(),
chrishtr7e3aaf22017-05-04 15:04:01259 GetRenderSurface(layer));
ajuma956219582017-04-04 19:58:14260 ASSERT_TRUE(layer_iterator_->state() ==
261 EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE);
262 occlusion->LeaveLayer(*layer_iterator_);
263 ++(*layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49264 }
[email protected]94f206c12012-08-25 00:09:14265
danakj00f7925e2015-06-15 21:19:22266 void VisitContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22267 EnterContributingSurface(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49268 LeaveContributingSurface(layer, occlusion);
269 }
[email protected]94f206c12012-08-25 00:09:14270
ajuma956219582017-04-04 19:58:14271 void ResetLayerIterator() {
272 *layer_iterator_ =
273 EffectTreeLayerListIterator(host_->host_impl()->active_tree());
274 }
[email protected]94f206c12012-08-25 00:09:14275
[email protected]a27cbde2013-03-23 22:01:49276 const gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:14277
[email protected]a27cbde2013-03-23 22:01:49278 private:
[email protected]d600df7d2013-08-03 02:34:28279 void SetRootLayerOnMainThread(Layer* root) {
280 host_->SetRootLayer(scoped_refptr<Layer>(root));
281 }
282
283 void SetRootLayerOnMainThread(LayerImpl* root) {}
284
[email protected]a27cbde2013-03-23 22:01:49285 void SetProperties(LayerImpl* layer,
286 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47287 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26288 const gfx::Size& bounds) {
jaydasika10d43fc2016-08-18 04:06:04289 layer->test_properties()->transform = transform;
danakj3b8b2bf2015-06-18 03:09:01290 layer->SetPosition(position);
291 layer->SetBounds(bounds);
[email protected]a27cbde2013-03-23 22:01:49292 }
[email protected]94f206c12012-08-25 00:09:14293
danakj60bc3bc2016-04-09 00:24:48294 void SetMask(LayerImpl* owning_layer, std::unique_ptr<LayerImpl> layer) {
ajuma1d4026a32016-06-14 13:18:50295 owning_layer->test_properties()->SetMaskLayer(std::move(layer));
[email protected]a27cbde2013-03-23 22:01:49296 }
[email protected]94f206c12012-08-25 00:09:14297
[email protected]a27cbde2013-03-23 22:01:49298 bool opaque_layers_;
enne2097cab2014-09-25 20:16:31299 FakeLayerTreeHostClient client_;
danakjcf610582015-06-16 22:48:56300 TestTaskGraphRunner task_graph_runner_;
loyso2cb3f32f2016-11-08 07:08:34301 std::unique_ptr<AnimationHost> animation_host_;
danakj60bc3bc2016-04-09 00:24:48302 std::unique_ptr<FakeLayerTreeHost> host_;
[email protected]a27cbde2013-03-23 22:01:49303 // These hold ownership of the layers for the duration of the test.
ajumab784ef42017-04-28 23:01:52304 RenderSurfaceList render_surface_list_impl_;
ajuma956219582017-04-04 19:58:14305 std::unique_ptr<EffectTreeLayerListIterator> layer_iterator_;
[email protected]50761e92013-03-29 20:51:28306 LayerList mask_layers_;
danakj00f7925e2015-06-15 21:19:22307 int next_layer_impl_id_;
[email protected]94f206c12012-08-25 00:09:14308};
309
danakj00f7925e2015-06-15 21:19:22310#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
311 class ClassName##ImplThreadOpaqueLayers : public ClassName { \
312 public: /* NOLINT(whitespace/indent) */ \
313 ClassName##ImplThreadOpaqueLayers() : ClassName(true) {} \
314 }; \
[email protected]a27cbde2013-03-23 22:01:49315 TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); }
danakj00f7925e2015-06-15 21:19:22316#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
317 class ClassName##ImplThreadOpaquePaints : public ClassName { \
318 public: /* NOLINT(whitespace/indent) */ \
319 ClassName##ImplThreadOpaquePaints() : ClassName(false) {} \
320 }; \
[email protected]a27cbde2013-03-23 22:01:49321 TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14322
[email protected]a27cbde2013-03-23 22:01:49323#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
[email protected]a27cbde2013-03-23 22:01:49324 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
325 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
[email protected]94f206c12012-08-25 00:09:14326
danakj00f7925e2015-06-15 21:19:22327class OcclusionTrackerTestIdentityTransforms : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49328 protected:
[email protected]ca2902e92013-03-28 01:45:35329 explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22330 : OcclusionTrackerTest(opaque_layers) {}
[email protected]ece1d952012-10-18 21:26:07331
dmichaelc78b0932014-12-17 23:39:47332 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22333 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49334 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22335 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49336 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22337 TestContentLayerImpl* layer = this->CreateDrawingLayer(
338 parent, this->identity_matrix, gfx::PointF(30.f, 30.f),
339 gfx::Size(500, 500), true);
[email protected]a27cbde2013-03-23 22:01:49340 parent->SetMasksToBounds(true);
341 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14342
danakj00f7925e2015-06-15 21:19:22343 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14344
[email protected]d002dd02013-03-27 07:40:40345 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22346 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14347
[email protected]a27cbde2013-03-23 22:01:49348 EXPECT_EQ(gfx::Rect().ToString(),
349 occlusion.occlusion_from_outside_target().ToString());
350 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
351 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49352 }
[email protected]94f206c12012-08-25 00:09:14353};
354
[email protected]96baf3e2012-10-22 23:09:55355ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14356
danakj00f7925e2015-06-15 21:19:22357class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49358 protected:
[email protected]ca2902e92013-03-28 01:45:35359 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22360 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47361 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49362 gfx::Transform layer_transform;
363 layer_transform.Translate(250.0, 250.0);
364 layer_transform.Rotate(90.0);
365 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14366
danakj00f7925e2015-06-15 21:19:22367 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:24368 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22369 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49370 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22371 TestContentLayerImpl* layer = this->CreateDrawingLayer(
372 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
373 true);
[email protected]a27cbde2013-03-23 22:01:49374 parent->SetMasksToBounds(true);
375 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14376
danakj00f7925e2015-06-15 21:19:22377 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14378
[email protected]d002dd02013-03-27 07:40:40379 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22380 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14381
[email protected]a27cbde2013-03-23 22:01:49382 EXPECT_EQ(gfx::Rect().ToString(),
383 occlusion.occlusion_from_outside_target().ToString());
384 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
385 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49386 }
[email protected]94f206c12012-08-25 00:09:14387};
388
[email protected]96baf3e2012-10-22 23:09:55389ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14390
danakj00f7925e2015-06-15 21:19:22391class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49392 protected:
[email protected]ca2902e92013-03-28 01:45:35393 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22394 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47395 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49396 gfx::Transform layer_transform;
397 layer_transform.Translate(20.0, 20.0);
[email protected]94f206c12012-08-25 00:09:14398
danakj00f7925e2015-06-15 21:19:22399 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49400 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22401 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49402 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22403 TestContentLayerImpl* layer = this->CreateDrawingLayer(
404 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
405 true);
[email protected]a27cbde2013-03-23 22:01:49406 parent->SetMasksToBounds(true);
407 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14408
danakj00f7925e2015-06-15 21:19:22409 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14410
[email protected]d002dd02013-03-27 07:40:40411 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22412 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14413
[email protected]a27cbde2013-03-23 22:01:49414 EXPECT_EQ(gfx::Rect().ToString(),
415 occlusion.occlusion_from_outside_target().ToString());
416 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
417 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49418 }
[email protected]94f206c12012-08-25 00:09:14419};
420
[email protected]96baf3e2012-10-22 23:09:55421ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14422
danakj00f7925e2015-06-15 21:19:22423class OcclusionTrackerTestChildInRotatedChild : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49424 protected:
[email protected]ca2902e92013-03-28 01:45:35425 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22426 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47427 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49428 gfx::Transform child_transform;
429 child_transform.Translate(250.0, 250.0);
430 child_transform.Rotate(90.0);
431 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14432
danakj00f7925e2015-06-15 21:19:22433 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49434 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
435 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22436 LayerImpl* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49437 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
438 child->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22439 TestContentLayerImpl* layer = this->CreateDrawingLayer(
440 child, this->identity_matrix, gfx::PointF(10.f, 10.f),
441 gfx::Size(500, 500), true);
[email protected]a27cbde2013-03-23 22:01:49442 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14443
danakj00f7925e2015-06-15 21:19:22444 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14445
[email protected]d002dd02013-03-27 07:40:40446 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22447 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14448
[email protected]a27cbde2013-03-23 22:01:49449 EXPECT_EQ(gfx::Rect().ToString(),
450 occlusion.occlusion_from_outside_target().ToString());
451 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
452 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14453
[email protected]d002dd02013-03-27 07:40:40454 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22455 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14456
[email protected]a27cbde2013-03-23 22:01:49457 EXPECT_EQ(gfx::Rect().ToString(),
458 occlusion.occlusion_from_outside_target().ToString());
459 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
460 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14461
[email protected]a27cbde2013-03-23 22:01:49462 /* Justification for the above occlusion from |layer|:
463 100
464 +---------------------+
465 | |
466 | 30 | rotate(90)
467 | 30 + ---------------------------------+
468 100 | | 10 | | ==>
469 | |10+---------------------------------+
470 | | | | | |
471 | | | | | |
472 | | | | | |
473 +----|--|-------------+ | |
474 | | | |
475 | | | |
476 | | | |500
477 | | | |
478 | | | |
479 | | | |
480 | | | |
481 +--|-------------------------------+ |
482 | |
483 +---------------------------------+
484 500
485
486 +---------------------+
487 | |30 Visible region of |layer|: /////
488 | |
489 | +---------------------------------+
490 100| | |10 |
491 | +---------------------------------+ |
492 | | |///////////////| 420 | |
493 | | |///////////////|60 | |
494 | | |///////////////| | |
495 +--|--|---------------+ | |
496 20|10| 70 | |
497 | | | |
498 | | | |
499 | | | |
500 | | | |
501 | | | |
502 | | |10|
503 | +------------------------------|--+
504 | 490 |
505 +---------------------------------+
506 500
507
508 */
509 }
[email protected]94f206c12012-08-25 00:09:14510};
511
[email protected]96baf3e2012-10-22 23:09:55512ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14513
danakj00f7925e2015-06-15 21:19:22514class OcclusionTrackerTestScaledRenderSurface : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49515 protected:
[email protected]ca2902e92013-03-28 01:45:35516 explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22517 : OcclusionTrackerTest(opaque_layers) {}
[email protected]710ffc02012-10-30 21:42:02518
dmichaelc78b0932014-12-17 23:39:47519 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22520 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49521 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02522
[email protected]a27cbde2013-03-23 22:01:49523 gfx::Transform layer1_matrix;
524 layer1_matrix.Scale(2.0, 2.0);
danakj00f7925e2015-06-15 21:19:22525 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49526 parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true);
jaydasika6b5a32bf2016-04-22 21:56:36527 layer1->test_properties()->force_render_surface = true;
[email protected]710ffc02012-10-30 21:42:02528
[email protected]a27cbde2013-03-23 22:01:49529 gfx::Transform layer2_matrix;
530 layer2_matrix.Translate(25.0, 25.0);
danakj00f7925e2015-06-15 21:19:22531 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49532 layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true);
danakj00f7925e2015-06-15 21:19:22533 TestContentLayerImpl* occluder = this->CreateDrawingLayer(
534 parent, this->identity_matrix, gfx::PointF(100.f, 100.f),
535 gfx::Size(500, 500), true);
[email protected]a27cbde2013-03-23 22:01:49536 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02537
danakj00f7925e2015-06-15 21:19:22538 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02539
[email protected]d002dd02013-03-27 07:40:40540 this->VisitLayer(occluder, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22541 this->EnterLayer(layer2, &occlusion);
[email protected]710ffc02012-10-30 21:42:02542
[email protected]a27cbde2013-03-23 22:01:49543 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
544 occlusion.occlusion_from_outside_target().ToString());
545 EXPECT_EQ(gfx::Rect().ToString(),
546 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49547 }
[email protected]710ffc02012-10-30 21:42:02548};
549
550ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
551
danakj00f7925e2015-06-15 21:19:22552class OcclusionTrackerTestVisitTargetTwoTimes : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49553 protected:
[email protected]ca2902e92013-03-28 01:45:35554 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22555 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47556 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22557 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49558 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22559 LayerImpl* surface = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43560 root, this->identity_matrix, gfx::PointF(30.f, 30.f), gfx::Size());
danakj00f7925e2015-06-15 21:19:22561 TestContentLayerImpl* surface_child = this->CreateDrawingLayer(
562 surface, this->identity_matrix, gfx::PointF(10.f, 10.f),
563 gfx::Size(50, 50), true);
[email protected]d5467eb72014-08-22 01:16:43564 // |top_layer| makes |root|'s surface get considered by OcclusionTracker
565 // first, instead of |surface|'s. This exercises different code in
566 // LeaveToRenderTarget, as the target surface has already been seen when
567 // leaving |surface| later.
danakj00f7925e2015-06-15 21:19:22568 TestContentLayerImpl* top_layer = this->CreateDrawingLayer(
569 root, this->identity_matrix, gfx::PointF(40.f, 90.f), gfx::Size(50, 20),
570 true);
[email protected]a27cbde2013-03-23 22:01:49571 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14572
danakj00f7925e2015-06-15 21:19:22573 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14574
[email protected]d5467eb72014-08-22 01:16:43575 this->VisitLayer(top_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14576
[email protected]a27cbde2013-03-23 22:01:49577 EXPECT_EQ(gfx::Rect().ToString(),
578 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43579 EXPECT_EQ(gfx::Rect(40, 90, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49580 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14581
[email protected]d5467eb72014-08-22 01:16:43582 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14583
[email protected]d5467eb72014-08-22 01:16:43584 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49585 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43586 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49587 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14588
[email protected]d5467eb72014-08-22 01:16:43589 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:14590
[email protected]d5467eb72014-08-22 01:16:43591 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49592 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43593 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49594 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14595
[email protected]d5467eb72014-08-22 01:16:43596 // Occlusion from |top_layer| already in the root target should get merged
597 // with the occlusion from the |surface| we are leaving now.
598 this->LeaveContributingSurface(surface, &occlusion);
599 this->EnterLayer(root, &occlusion);
[email protected]94f206c12012-08-25 00:09:14600
[email protected]d5467eb72014-08-22 01:16:43601 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
602 EXPECT_EQ(gfx::Rect(40, 40, 50, 70).ToString(),
[email protected]a27cbde2013-03-23 22:01:49603 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49604 }
[email protected]94f206c12012-08-25 00:09:14605};
606
[email protected]96baf3e2012-10-22 23:09:55607ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:14608
danakj00f7925e2015-06-15 21:19:22609class OcclusionTrackerTestSurfaceRotatedOffAxis : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49610 protected:
[email protected]ca2902e92013-03-28 01:45:35611 explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22612 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47613 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49614 gfx::Transform child_transform;
615 child_transform.Translate(250.0, 250.0);
616 child_transform.Rotate(95.0);
617 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14618
[email protected]a27cbde2013-03-23 22:01:49619 gfx::Transform layer_transform;
620 layer_transform.Translate(10.0, 10.0);
[email protected]94f206c12012-08-25 00:09:14621
danakj00f7925e2015-06-15 21:19:22622 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49623 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
danakj00f7925e2015-06-15 21:19:22624 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49625 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22626 LayerImpl* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49627 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
danakj00f7925e2015-06-15 21:19:22628 TestContentLayerImpl* layer = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49629 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true);
630 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14631
danakj00f7925e2015-06-15 21:19:22632 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14633
[email protected]8a822692014-02-12 17:30:55634 gfx::Rect clipped_layer_in_child = MathUtil::MapEnclosingClippedRect(
danakj64767d902015-06-19 00:10:43635 layer_transform, layer->visible_layer_rect());
[email protected]94f206c12012-08-25 00:09:14636
[email protected]d002dd02013-03-27 07:40:40637 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22638 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14639
[email protected]a27cbde2013-03-23 22:01:49640 EXPECT_EQ(gfx::Rect().ToString(),
641 occlusion.occlusion_from_outside_target().ToString());
642 EXPECT_EQ(clipped_layer_in_child.ToString(),
643 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14644
[email protected]d002dd02013-03-27 07:40:40645 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22646 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14647
[email protected]a27cbde2013-03-23 22:01:49648 EXPECT_EQ(gfx::Rect().ToString(),
649 occlusion.occlusion_from_outside_target().ToString());
650 EXPECT_EQ(gfx::Rect().ToString(),
651 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49652 }
[email protected]94f206c12012-08-25 00:09:14653};
654
[email protected]96baf3e2012-10-22 23:09:55655ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:14656
[email protected]ca2902e92013-03-28 01:45:35657class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
danakj00f7925e2015-06-15 21:19:22658 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49659 protected:
[email protected]ca2902e92013-03-28 01:45:35660 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22661 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47662 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49663 gfx::Transform child_transform;
664 child_transform.Translate(250.0, 250.0);
665 child_transform.Rotate(90.0);
666 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14667
danakj00f7925e2015-06-15 21:19:22668 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49669 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
danakj00f7925e2015-06-15 21:19:22670 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49671 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
672 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22673 TestContentLayerImpl* child = this->CreateDrawingSurface(
674 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
675 false);
[email protected]a27cbde2013-03-23 22:01:49676 child->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22677 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
678 child, this->identity_matrix, gfx::PointF(10.f, 10.f),
679 gfx::Size(500, 500), true);
680 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
681 child, this->identity_matrix, gfx::PointF(10.f, 450.f),
682 gfx::Size(500, 60), true);
[email protected]a27cbde2013-03-23 22:01:49683 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14684
danakj00f7925e2015-06-15 21:19:22685 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14686
[email protected]d002dd02013-03-27 07:40:40687 this->VisitLayer(layer2, &occlusion);
688 this->VisitLayer(layer1, &occlusion);
689 this->VisitLayer(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22690 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14691
[email protected]a27cbde2013-03-23 22:01:49692 EXPECT_EQ(gfx::Rect().ToString(),
693 occlusion.occlusion_from_outside_target().ToString());
694 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
695 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14696
[email protected]d002dd02013-03-27 07:40:40697 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22698 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14699
[email protected]a27cbde2013-03-23 22:01:49700 EXPECT_EQ(gfx::Rect().ToString(),
701 occlusion.occlusion_from_outside_target().ToString());
702 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
703 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14704
[email protected]a27cbde2013-03-23 22:01:49705 /* Justification for the above occlusion from |layer1| and |layer2|:
[email protected]94f206c12012-08-25 00:09:14706
707 +---------------------+
708 | |30 Visible region of |layer1|: /////
709 | | Visible region of |layer2|: \\\\\
710 | +---------------------------------+
711 | | |10 |
712 | +---------------+-----------------+ |
713 | | |\\\\\\\\\\\\|//| 420 | |
714 | | |\\\\\\\\\\\\|//|60 | |
715 | | |\\\\\\\\\\\\|//| | |
716 +--|--|------------|--+ | |
717 20|10| 70 | | |
718 | | | | |
719 | | | | |
720 | | | | |
721 | | | | |
722 | | | | |
723 | | | |10|
724 | +------------|-----------------|--+
725 | | 490 |
726 +---------------+-----------------+
727 60 440
728 */
[email protected]a27cbde2013-03-23 22:01:49729 }
[email protected]94f206c12012-08-25 00:09:14730};
731
[email protected]96baf3e2012-10-22 23:09:55732ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:14733
[email protected]ca2902e92013-03-28 01:45:35734class OcclusionTrackerTestOverlappingSurfaceSiblings
danakj00f7925e2015-06-15 21:19:22735 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49736 protected:
[email protected]ca2902e92013-03-28 01:45:35737 explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22738 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47739 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22740 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49741 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
742 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22743 LayerImpl* child1 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43744 parent, this->identity_matrix, gfx::PointF(10.f, 0.f), gfx::Size());
danakj00f7925e2015-06-15 21:19:22745 LayerImpl* child2 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43746 parent, this->identity_matrix, gfx::PointF(30.f, 0.f), gfx::Size());
danakj00f7925e2015-06-15 21:19:22747 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
[email protected]d5467eb72014-08-22 01:16:43748 child1, this->identity_matrix, gfx::PointF(), gfx::Size(40, 50), true);
danakj00f7925e2015-06-15 21:19:22749 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
750 child2, this->identity_matrix, gfx::PointF(10.f, 0.f),
751 gfx::Size(40, 50), true);
[email protected]a27cbde2013-03-23 22:01:49752 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14753
danakj00f7925e2015-06-15 21:19:22754 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14755
[email protected]d002dd02013-03-27 07:40:40756 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22757 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:14758
[email protected]d5467eb72014-08-22 01:16:43759 // layer2's occlusion.
[email protected]a27cbde2013-03-23 22:01:49760 EXPECT_EQ(gfx::Rect().ToString(),
761 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43762 EXPECT_EQ(gfx::Rect(10, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49763 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14764
[email protected]d002dd02013-03-27 07:40:40765 this->LeaveContributingSurface(child2, &occlusion);
766 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22767 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:14768
[email protected]d5467eb72014-08-22 01:16:43769 // layer2's occlusion in the target space of layer1.
770 EXPECT_EQ(gfx::Rect(30, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49771 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43772 // layer1's occlusion.
773 EXPECT_EQ(gfx::Rect(0, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49774 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14775
[email protected]d002dd02013-03-27 07:40:40776 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22777 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14778
[email protected]d5467eb72014-08-22 01:16:43779 // The occlusion from from layer1 and layer2 is merged.
780 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
781 EXPECT_EQ(gfx::Rect(10, 0, 70, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49782 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49783 }
[email protected]94f206c12012-08-25 00:09:14784};
785
[email protected]96baf3e2012-10-22 23:09:55786ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:14787
[email protected]ca2902e92013-03-28 01:45:35788class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms
danakj00f7925e2015-06-15 21:19:22789 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49790 protected:
[email protected]ca2902e92013-03-28 01:45:35791 explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(
[email protected]a27cbde2013-03-23 22:01:49792 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22793 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47794 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49795 gfx::Transform child1_transform;
796 child1_transform.Translate(250.0, 250.0);
797 child1_transform.Rotate(-90.0);
798 child1_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14799
[email protected]a27cbde2013-03-23 22:01:49800 gfx::Transform child2_transform;
801 child2_transform.Translate(250.0, 250.0);
802 child2_transform.Rotate(90.0);
803 child2_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14804
danakj00f7925e2015-06-15 21:19:22805 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49806 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
807 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22808 LayerImpl* child1 = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49809 parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10));
danakj00f7925e2015-06-15 21:19:22810 LayerImpl* child2 = this->CreateDrawingSurface(parent, child2_transform,
811 gfx::PointF(20.f, 40.f),
812 gfx::Size(10, 10), false);
813 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
814 child1, this->identity_matrix, gfx::PointF(-10.f, -20.f),
815 gfx::Size(510, 510), true);
816 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
817 child2, this->identity_matrix, gfx::PointF(-10.f, -10.f),
818 gfx::Size(510, 510), true);
[email protected]a27cbde2013-03-23 22:01:49819 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14820
danakj00f7925e2015-06-15 21:19:22821 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14822
[email protected]d002dd02013-03-27 07:40:40823 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22824 this->EnterLayer(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:14825
[email protected]a27cbde2013-03-23 22:01:49826 EXPECT_EQ(gfx::Rect().ToString(),
827 occlusion.occlusion_from_outside_target().ToString());
828 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
829 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14830
[email protected]d002dd02013-03-27 07:40:40831 this->LeaveLayer(child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22832 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:14833
danakjf080b5b2014-08-23 22:18:20834 EXPECT_EQ(gfx::Rect().ToString(),
835 occlusion.occlusion_from_outside_target().ToString());
836 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
837 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14838
[email protected]d002dd02013-03-27 07:40:40839 this->LeaveContributingSurface(child2, &occlusion);
840 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22841 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:14842
[email protected]a27cbde2013-03-23 22:01:49843 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
844 occlusion.occlusion_from_outside_target().ToString());
845 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
846 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14847
[email protected]d002dd02013-03-27 07:40:40848 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22849 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14850
[email protected]a27cbde2013-03-23 22:01:49851 EXPECT_EQ(gfx::Rect().ToString(),
852 occlusion.occlusion_from_outside_target().ToString());
853 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(),
854 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14855
[email protected]a27cbde2013-03-23 22:01:49856 /* Justification for the above occlusion:
857 100
858 +---------------------+
859 |20 | layer1
860 10+----------------------------------+
861 100 || 30 | layer2 |
862 |20+----------------------------------+
863 || | | | |
864 || | | | |
865 || | | | |
866 +|-|------------------+ | |
867 | | | | 510
868 | | 510 | |
869 | | | |
870 | | | |
871 | | | |
872 | | | |
873 | | 520 | |
874 +----------------------------------+ |
875 | |
876 +----------------------------------+
877 510
878 */
879 }
[email protected]94f206c12012-08-25 00:09:14880};
881
[email protected]a27cbde2013-03-23 22:01:49882ALL_OCCLUSIONTRACKER_TEST(
883 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:14884
danakj00f7925e2015-06-15 21:19:22885class OcclusionTrackerTestFilters : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49886 protected:
[email protected]ca2902e92013-03-28 01:45:35887 explicit OcclusionTrackerTestFilters(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22888 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47889 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49890 gfx::Transform layer_transform;
891 layer_transform.Translate(250.0, 250.0);
892 layer_transform.Rotate(90.0);
893 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14894
danakj00f7925e2015-06-15 21:19:22895 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49896 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
897 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22898 TestContentLayerImpl* blur_layer = this->CreateDrawingLayer(
899 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
900 true);
901 TestContentLayerImpl* opaque_layer = this->CreateDrawingLayer(
902 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
903 true);
904 TestContentLayerImpl* opacity_layer = this->CreateDrawingLayer(
905 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
906 true);
[email protected]94f206c12012-08-25 00:09:14907
jaydasika6b5a32bf2016-04-22 21:56:36908 blur_layer->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:29909 FilterOperations filters;
910 filters.Append(FilterOperation::CreateBlurFilter(10.f));
ajumacb2b74432016-07-21 19:11:15911 blur_layer->test_properties()->filters = filters;
[email protected]94f206c12012-08-25 00:09:14912
jaydasika6b5a32bf2016-04-22 21:56:36913 opaque_layer->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:29914 filters.Clear();
915 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f));
ajumacb2b74432016-07-21 19:11:15916 opaque_layer->test_properties()->filters = filters;
[email protected]94f206c12012-08-25 00:09:14917
jaydasika6b5a32bf2016-04-22 21:56:36918 opacity_layer->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:29919 filters.Clear();
920 filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
ajumacb2b74432016-07-21 19:11:15921 opacity_layer->test_properties()->filters = filters;
[email protected]94f206c12012-08-25 00:09:14922
[email protected]a27cbde2013-03-23 22:01:49923 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14924
danakj00f7925e2015-06-15 21:19:22925 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14926
[email protected]a27cbde2013-03-23 22:01:49927 // Opacity layer won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:40928 this->VisitLayer(opacity_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22929 this->EnterContributingSurface(opacity_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14930
[email protected]a27cbde2013-03-23 22:01:49931 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
932 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14933
[email protected]a27cbde2013-03-23 22:01:49934 // And has nothing to contribute to its parent surface.
[email protected]d002dd02013-03-27 07:40:40935 this->LeaveContributingSurface(opacity_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49936 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
937 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14938
[email protected]a27cbde2013-03-23 22:01:49939 // Opaque layer will contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:40940 this->VisitLayer(opaque_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22941 this->EnterContributingSurface(opaque_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14942
[email protected]a27cbde2013-03-23 22:01:49943 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
944 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(),
945 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14946
[email protected]a27cbde2013-03-23 22:01:49947 // And it gets translated to the parent surface.
[email protected]d002dd02013-03-27 07:40:40948 this->LeaveContributingSurface(opaque_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49949 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
950 EXPECT_EQ(gfx::Rect(30, 30, 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 // The blur layer needs to throw away any occlusion from outside its
954 // subtree.
[email protected]e47b0a0a2013-11-18 23:26:22955 this->EnterLayer(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49956 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
957 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14958
[email protected]a27cbde2013-03-23 22:01:49959 // And it won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:40960 this->LeaveLayer(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22961 this->EnterContributingSurface(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 // But the opaque layer's occlusion is preserved on the parent.
[email protected]d002dd02013-03-27 07:40:40966 this->LeaveContributingSurface(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22967 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49968 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
969 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
970 occlusion.occlusion_from_inside_target().ToString());
971 }
[email protected]94f206c12012-08-25 00:09:14972};
973
[email protected]96baf3e2012-10-22 23:09:55974ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:14975
[email protected]ca2902e92013-03-28 01:45:35976class OcclusionTrackerTestOpaqueContentsRegionEmpty
danakj00f7925e2015-06-15 21:19:22977 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49978 protected:
[email protected]ca2902e92013-03-28 01:45:35979 explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22980 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47981 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22982 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49983 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
danakj00f7925e2015-06-15 21:19:22984 TestContentLayerImpl* layer =
985 this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(),
986 gfx::Size(200, 200), false);
[email protected]a27cbde2013-03-23 22:01:49987 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14988
danakj00f7925e2015-06-15 21:19:22989 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:22990 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14991
[email protected]d5467eb72014-08-22 01:16:43992 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
993 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14994
[email protected]d002dd02013-03-27 07:40:40995 this->LeaveLayer(layer, &occlusion);
996 this->VisitContributingSurface(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22997 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14998
[email protected]a27cbde2013-03-23 22:01:49999 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]d5467eb72014-08-22 01:16:431000 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491001 }
[email protected]94f206c12012-08-25 00:09:141002};
1003
danakj00f7925e2015-06-15 21:19:221004ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141005
[email protected]ca2902e92013-03-28 01:45:351006class OcclusionTrackerTestOpaqueContentsRegionNonEmpty
danakj00f7925e2015-06-15 21:19:221007 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491008 protected:
[email protected]ca2902e92013-03-28 01:45:351009 explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221010 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471011 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221012 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491013 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
danakj00f7925e2015-06-15 21:19:221014 TestContentLayerImpl* layer = this->CreateDrawingLayer(
1015 parent, this->identity_matrix, gfx::PointF(100.f, 100.f),
1016 gfx::Size(200, 200), false);
[email protected]a27cbde2013-03-23 22:01:491017 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141018 {
danakj00f7925e2015-06-15 21:19:221019 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491020 layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:141021
[email protected]a27cbde2013-03-23 22:01:491022 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401023 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221024 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141025
[email protected]a27cbde2013-03-23 22:01:491026 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
1027 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141028 }
[email protected]a27cbde2013-03-23 22:01:491029 {
danakj00f7925e2015-06-15 21:19:221030 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491031 layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
1032
1033 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401034 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221035 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491036
1037 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(),
1038 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491039 }
1040 {
danakj00f7925e2015-06-15 21:19:221041 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491042 layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
1043
1044 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401045 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221046 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491047
1048 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
1049 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491050 }
1051 }
[email protected]94f206c12012-08-25 00:09:141052};
1053
danakj00f7925e2015-06-15 21:19:221054ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141055
[email protected]ca2902e92013-03-28 01:45:351056class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude
danakj00f7925e2015-06-15 21:19:221057 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491058 protected:
[email protected]ca2902e92013-03-28 01:45:351059 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(
1060 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221061 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471062 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491063 gfx::Transform transform;
1064 transform.Translate(50.0, 50.0);
1065 transform.ApplyPerspectiveDepth(100.0);
1066 transform.Translate3d(0.0, 0.0, 110.0);
1067 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141068
danakj00f7925e2015-06-15 21:19:221069 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491070 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
danakj00f7925e2015-06-15 21:19:221071 TestContentLayerImpl* layer = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491072 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
jaydasikaca2605e2016-04-23 02:52:521073 parent->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:201074 parent->test_properties()->sorting_context_id = 1;
jaydasikaca2605e2016-04-23 02:52:521075 layer->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:201076 layer->test_properties()->sorting_context_id = 1;
[email protected]a27cbde2013-03-23 22:01:491077 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141078
danakj00f7925e2015-06-15 21:19:221079 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141080
[email protected]a27cbde2013-03-23 22:01:491081 // The |layer| is entirely behind the camera and should not occlude.
[email protected]d002dd02013-03-27 07:40:401082 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221083 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491084 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1085 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1086 }
[email protected]94f206c12012-08-25 00:09:141087};
1088
[email protected]ca2902e92013-03-28 01:45:351089class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent
danakj00f7925e2015-06-15 21:19:221090 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491091 protected:
[email protected]ca2902e92013-03-28 01:45:351092 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(
1093 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221094 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471095 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491096 gfx::Transform surface_transform;
1097 surface_transform.Translate(300.0, 300.0);
1098 surface_transform.Scale(2.0, 2.0);
1099 surface_transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:141100
danakj00f7925e2015-06-15 21:19:221101 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491102 this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
danakj00f7925e2015-06-15 21:19:221103 TestContentLayerImpl* surface = this->CreateDrawingSurface(
[email protected]a27cbde2013-03-23 22:01:491104 parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false);
danakj00f7925e2015-06-15 21:19:221105 TestContentLayerImpl* surface2 = this->CreateDrawingSurface(
1106 parent, this->identity_matrix, gfx::PointF(50.f, 50.f),
1107 gfx::Size(300, 300), false);
[email protected]a27cbde2013-03-23 22:01:491108 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1109 surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1110 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141111
danakj00f7925e2015-06-15 21:19:221112 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141113
[email protected]d002dd02013-03-27 07:40:401114 this->VisitLayer(surface2, &occlusion);
1115 this->VisitContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141116
[email protected]a27cbde2013-03-23 22:01:491117 EXPECT_EQ(gfx::Rect().ToString(),
1118 occlusion.occlusion_from_outside_target().ToString());
1119 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(),
1120 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141121
[email protected]a27cbde2013-03-23 22:01:491122 // Clear any stored occlusion.
[email protected]d5467eb72014-08-22 01:16:431123 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
1124 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
[email protected]94f206c12012-08-25 00:09:141125
[email protected]d002dd02013-03-27 07:40:401126 this->VisitLayer(surface, &occlusion);
1127 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141128
[email protected]a27cbde2013-03-23 22:01:491129 EXPECT_EQ(gfx::Rect().ToString(),
1130 occlusion.occlusion_from_outside_target().ToString());
1131 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(),
1132 occlusion.occlusion_from_inside_target().ToString());
1133 }
[email protected]94f206c12012-08-25 00:09:141134};
1135
danakj00f7925e2015-06-15 21:19:221136ALL_OCCLUSIONTRACKER_TEST(
[email protected]a27cbde2013-03-23 22:01:491137 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:141138
[email protected]ca2902e92013-03-28 01:45:351139class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping
danakj00f7925e2015-06-15 21:19:221140 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491141 protected:
[email protected]ca2902e92013-03-28 01:45:351142 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(
1143 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221144 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471145 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221146 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491147 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1148 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221149 TestContentLayerImpl* surface =
1150 this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(),
1151 gfx::Size(500, 300), false);
[email protected]a27cbde2013-03-23 22:01:491152 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
1153 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141154
danakj00f7925e2015-06-15 21:19:221155 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141156
[email protected]d002dd02013-03-27 07:40:401157 this->VisitLayer(surface, &occlusion);
1158 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141159
[email protected]a27cbde2013-03-23 22:01:491160 EXPECT_EQ(gfx::Rect().ToString(),
1161 occlusion.occlusion_from_outside_target().ToString());
1162 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(),
1163 occlusion.occlusion_from_inside_target().ToString());
1164 }
[email protected]94f206c12012-08-25 00:09:141165};
1166
danakj00f7925e2015-06-15 21:19:221167ALL_OCCLUSIONTRACKER_TEST(
[email protected]a27cbde2013-03-23 22:01:491168 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:141169
danakj00f7925e2015-06-15 21:19:221170class OcclusionTrackerTestSurfaceChildOfSurface : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491171 protected:
[email protected]ca2902e92013-03-28 01:45:351172 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221173 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471174 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491175 // This test verifies that the surface cliprect does not end up empty and
1176 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:141177
danakj00f7925e2015-06-15 21:19:221178 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491179 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
danakj00f7925e2015-06-15 21:19:221180 LayerImpl* surface =
1181 this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(),
1182 gfx::Size(100, 100), false);
1183 LayerImpl* surface_child = this->CreateDrawingSurface(
1184 surface, this->identity_matrix, gfx::PointF(0.f, 10.f),
1185 gfx::Size(100, 50), true);
1186 LayerImpl* topmost = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491187 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
1188 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141189
danakj00f7925e2015-06-15 21:19:221190 TestOcclusionTrackerWithClip occlusion(gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141191
[email protected]a27cbde2013-03-23 22:01:491192 // |topmost| occludes everything partially so we know occlusion is happening
1193 // at all.
[email protected]d002dd02013-03-27 07:40:401194 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:141195
[email protected]a27cbde2013-03-23 22:01:491196 EXPECT_EQ(gfx::Rect().ToString(),
1197 occlusion.occlusion_from_outside_target().ToString());
1198 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1199 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141200
[email protected]d002dd02013-03-27 07:40:401201 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141202
[email protected]a27cbde2013-03-23 22:01:491203 // surface_child increases the occlusion in the screen by a narrow sliver.
1204 EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(),
1205 occlusion.occlusion_from_outside_target().ToString());
1206 // In its own surface, surface_child is at 0,0 as is its occlusion.
1207 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1208 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141209
[email protected]a27cbde2013-03-23 22:01:491210 // The root layer always has a clip rect. So the parent of |surface| has a
1211 // clip rect. However, the owning layer for |surface| does not mask to
1212 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
1213 // |surface_child| exercises different code paths as its parent does not
1214 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:141215
[email protected]e47b0a0a2013-11-18 23:26:221216 this->EnterContributingSurface(surface_child, &occlusion);
danakjf080b5b2014-08-23 22:18:201217 // The |surface_child| can't occlude its own surface, but occlusion from
1218 // |topmost| can.
1219 EXPECT_EQ(gfx::Rect().ToString(),
1220 occlusion.occlusion_on_contributing_surface_from_outside_target()
1221 .ToString());
1222 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1223 occlusion.occlusion_on_contributing_surface_from_inside_target()
1224 .ToString());
[email protected]d002dd02013-03-27 07:40:401225 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141226
[email protected]a27cbde2013-03-23 22:01:491227 // When the surface_child's occlusion is transformed up to its parent, make
danakjf080b5b2014-08-23 22:18:201228 // sure it is not clipped away inappropriately.
[email protected]e47b0a0a2013-11-18 23:26:221229 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491230 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1231 occlusion.occlusion_from_outside_target().ToString());
1232 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(),
1233 occlusion.occlusion_from_inside_target().ToString());
[email protected]d002dd02013-03-27 07:40:401234 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141235
[email protected]e47b0a0a2013-11-18 23:26:221236 this->EnterContributingSurface(surface, &occlusion);
danakjf080b5b2014-08-23 22:18:201237 // The occlusion from inside |surface| can't affect the surface, but
1238 // |topmost| can.
1239 EXPECT_EQ(gfx::Rect().ToString(),
1240 occlusion.occlusion_on_contributing_surface_from_outside_target()
1241 .ToString());
1242 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1243 occlusion.occlusion_on_contributing_surface_from_inside_target()
1244 .ToString());
1245
1246 this->LeaveContributingSurface(surface, &occlusion);
1247 this->EnterLayer(parent, &occlusion);
1248 // The occlusion in |surface| and without are merged into the parent.
1249 EXPECT_EQ(gfx::Rect().ToString(),
1250 occlusion.occlusion_from_outside_target().ToString());
1251 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(),
1252 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491253 }
[email protected]94f206c12012-08-25 00:09:141254};
1255
[email protected]96baf3e2012-10-22 23:09:551256ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:141257
[email protected]ca2902e92013-03-28 01:45:351258class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter
danakj00f7925e2015-06-15 21:19:221259 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491260 protected:
[email protected]ca2902e92013-03-28 01:45:351261 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:491262 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221263 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471264 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491265 gfx::Transform scale_by_half;
1266 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141267
[email protected]ae6b1a72013-06-25 18:49:291268 FilterOperations filters;
1269 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]94f206c12012-08-25 00:09:141270
[email protected]d5467eb72014-08-22 01:16:431271 enum Direction {
1272 LEFT,
1273 RIGHT,
1274 TOP,
1275 BOTTOM,
1276 LAST_DIRECTION = BOTTOM,
1277 };
[email protected]94f206c12012-08-25 00:09:141278
[email protected]d5467eb72014-08-22 01:16:431279 for (int i = 0; i <= LAST_DIRECTION; ++i) {
1280 SCOPED_TRACE(i);
[email protected]94f206c12012-08-25 00:09:141281
[email protected]d5467eb72014-08-22 01:16:431282 // Make a 50x50 filtered surface that is adjacent to occluding layers
1283 // which are above it in the z-order in various configurations. The
1284 // surface is scaled to test that the pixel moving is done in the target
1285 // space, where the background filter is applied.
danakj00f7925e2015-06-15 21:19:221286 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]d5467eb72014-08-22 01:16:431287 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:221288 LayerImpl* filtered_surface = this->CreateDrawingLayer(
1289 parent, scale_by_half, gfx::PointF(50.f, 50.f), gfx::Size(100, 100),
1290 false);
ajuma50bce7e2016-06-24 20:56:041291 filtered_surface->test_properties()->background_filters = filters;
[email protected]d5467eb72014-08-22 01:16:431292 gfx::Rect occlusion_rect;
1293 switch (i) {
1294 case LEFT:
1295 occlusion_rect = gfx::Rect(0, 0, 50, 200);
1296 break;
1297 case RIGHT:
jbroman19a18b12016-07-07 02:37:381298 // This is the right edge; filtered_surface is scaled by half.
[email protected]d5467eb72014-08-22 01:16:431299 occlusion_rect = gfx::Rect(100, 0, 50, 200);
1300 break;
1301 case TOP:
1302 occlusion_rect = gfx::Rect(0, 0, 200, 50);
1303 break;
1304 case BOTTOM:
jbroman19a18b12016-07-07 02:37:381305 // This is the bottom edge; filtered_surface is scaled by half.
[email protected]d5467eb72014-08-22 01:16:431306 occlusion_rect = gfx::Rect(0, 100, 200, 50);
1307 break;
1308 }
[email protected]ac7c7f52012-11-08 06:26:501309
danakj00f7925e2015-06-15 21:19:221310 LayerImpl* occluding_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:241311 parent, this->identity_matrix, gfx::PointF(occlusion_rect.origin()),
danakj00f7925e2015-06-15 21:19:221312 occlusion_rect.size(), true);
jaydasika6b5a32bf2016-04-22 21:56:361313 occluding_layer->test_properties()->force_render_surface = false;
[email protected]d5467eb72014-08-22 01:16:431314 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141315
danakj00f7925e2015-06-15 21:19:221316 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
[email protected]94f206c12012-08-25 00:09:141317
[email protected]d5467eb72014-08-22 01:16:431318 // This layer occludes pixels directly beside the filtered_surface.
1319 // Because filtered surface blends pixels in a radius, it will need to see
1320 // some of the pixels (up to radius far) underneath the occluding layers.
1321 this->VisitLayer(occluding_layer, &occlusion);
[email protected]ccb1c9a2012-12-17 03:53:191322
[email protected]d5467eb72014-08-22 01:16:431323 EXPECT_EQ(occlusion_rect.ToString(),
1324 occlusion.occlusion_from_inside_target().ToString());
1325 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141326
[email protected]d5467eb72014-08-22 01:16:431327 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141328
[email protected]d5467eb72014-08-22 01:16:431329 // The occlusion is used fully inside the surface.
1330 gfx::Rect occlusion_inside_surface =
1331 occlusion_rect - gfx::Vector2d(50, 50);
1332 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1333 EXPECT_EQ(occlusion_inside_surface.ToString(),
1334 occlusion.occlusion_from_outside_target().ToString());
[email protected]ac7c7f52012-11-08 06:26:501335
[email protected]d5467eb72014-08-22 01:16:431336 // The surface has a background blur, so it needs pixels that are
jbroman19a18b12016-07-07 02:37:381337 // currently considered occluded in order to be drawn. The pixels it
1338 // needs should be removed from the occluded area, so that they are drawn
1339 // when we get to the parent.
[email protected]d5467eb72014-08-22 01:16:431340 this->VisitContributingSurface(filtered_surface, &occlusion);
1341 this->EnterLayer(parent, &occlusion);
[email protected]ac7c7f52012-11-08 06:26:501342
jbroman56c1f9c2016-07-06 19:08:101343 // The spread due to a 10px blur is 30px.
[email protected]d5467eb72014-08-22 01:16:431344 gfx::Rect expected_occlusion = occlusion_rect;
1345 switch (i) {
1346 case LEFT:
jbroman56c1f9c2016-07-06 19:08:101347 expected_occlusion.Inset(0, 0, 30, 0);
[email protected]d5467eb72014-08-22 01:16:431348 break;
1349 case RIGHT:
jbroman56c1f9c2016-07-06 19:08:101350 expected_occlusion.Inset(30, 0, 0, 0);
[email protected]d5467eb72014-08-22 01:16:431351 break;
1352 case TOP:
jbroman56c1f9c2016-07-06 19:08:101353 expected_occlusion.Inset(0, 0, 0, 30);
[email protected]d5467eb72014-08-22 01:16:431354 break;
1355 case BOTTOM:
jbroman56c1f9c2016-07-06 19:08:101356 expected_occlusion.Inset(0, 30, 0, 0);
[email protected]d5467eb72014-08-22 01:16:431357 break;
1358 }
[email protected]94f206c12012-08-25 00:09:141359
[email protected]d5467eb72014-08-22 01:16:431360 EXPECT_EQ(expected_occlusion.ToString(),
1361 occlusion.occlusion_from_inside_target().ToString());
1362 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141363
[email protected]d5467eb72014-08-22 01:16:431364 this->DestroyLayers();
1365 }
[email protected]a27cbde2013-03-23 22:01:491366 }
[email protected]94f206c12012-08-25 00:09:141367};
1368
[email protected]a27cbde2013-03-23 22:01:491369ALL_OCCLUSIONTRACKER_TEST(
1370 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:141371
ajuma977555362016-07-19 16:12:121372class OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter
jbroman19a18b12016-07-07 02:37:381373 : public OcclusionTrackerTest {
1374 protected:
ajuma977555362016-07-19 16:12:121375 explicit OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter(
jbroman19a18b12016-07-07 02:37:381376 bool opaque_layers)
1377 : OcclusionTrackerTest(opaque_layers) {}
1378 void RunMyTest() override {
1379 gfx::Transform scale_by_half;
1380 scale_by_half.Scale(0.5, 0.5);
1381
1382 FilterOperations filters;
1383 filters.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(10, 10),
1384 5, SK_ColorBLACK));
1385
1386 enum Direction {
1387 LEFT,
1388 RIGHT,
1389 TOP,
1390 BOTTOM,
1391 LAST_DIRECTION = BOTTOM,
1392 };
1393
1394 for (int i = 0; i <= LAST_DIRECTION; ++i) {
1395 SCOPED_TRACE(i);
1396
1397 // Make a 50x50 filtered surface that is adjacent to occluding layers
1398 // which are above it in the z-order in various configurations. The
1399 // surface is scaled to test that the pixel moving is done in the target
1400 // space, where the background filter is applied.
1401 TestContentLayerImpl* parent = this->CreateRoot(
1402 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
1403 LayerImpl* filtered_surface = this->CreateDrawingLayer(
1404 parent, scale_by_half, gfx::PointF(50.f, 50.f), gfx::Size(100, 100),
1405 false);
1406 filtered_surface->test_properties()->background_filters = filters;
1407 gfx::Rect occlusion_rect;
1408 switch (i) {
1409 case LEFT:
1410 occlusion_rect = gfx::Rect(0, 0, 50, 200);
1411 break;
1412 case RIGHT:
1413 // This is the right edge; filtered_surface is scaled by half.
1414 occlusion_rect = gfx::Rect(100, 0, 50, 200);
1415 break;
1416 case TOP:
1417 occlusion_rect = gfx::Rect(0, 0, 200, 50);
1418 break;
1419 case BOTTOM:
1420 // This is the bottom edge; filtered_surface is scaled by half.
1421 occlusion_rect = gfx::Rect(0, 100, 200, 50);
1422 break;
1423 }
1424
1425 LayerImpl* occluding_layer = this->CreateDrawingLayer(
1426 parent, this->identity_matrix, gfx::PointF(occlusion_rect.origin()),
1427 occlusion_rect.size(), true);
1428 occluding_layer->test_properties()->force_render_surface = false;
1429 this->CalcDrawEtc(parent);
1430
1431 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
1432
1433 // This layer occludes pixels directly beside the filtered_surface.
1434 // Because filtered surface blends pixels in a radius, it will need to see
1435 // some of the pixels (up to radius far) underneath the occluding layers.
1436 this->VisitLayer(occluding_layer, &occlusion);
1437
1438 EXPECT_EQ(occlusion_rect.ToString(),
1439 occlusion.occlusion_from_inside_target().ToString());
1440 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1441
1442 this->VisitLayer(filtered_surface, &occlusion);
1443
1444 // The occlusion is used fully inside the surface.
1445 gfx::Rect occlusion_inside_surface =
1446 occlusion_rect - gfx::Vector2d(50, 50);
1447 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1448 EXPECT_EQ(occlusion_inside_surface.ToString(),
1449 occlusion.occlusion_from_outside_target().ToString());
1450
1451 // The surface has a background filter, so it needs pixels that are
1452 // currently considered occluded in order to be drawn. The pixels it
1453 // needs should be removed from the occluded area, so that they are drawn
1454 // when we get to the parent.
1455 this->VisitContributingSurface(filtered_surface, &occlusion);
1456 this->EnterLayer(parent, &occlusion);
1457
1458 gfx::Rect expected_occlusion;
1459 switch (i) {
1460 case LEFT:
1461 // The right half of the occlusion is close enough to cast a shadow
1462 // that would be visible in the background filter. The shadow reaches
1463 // 3*5 + 10 = 25 pixels to the right.
1464 expected_occlusion = gfx::Rect(0, 0, 25, 200);
1465 break;
1466 case RIGHT:
1467 // The shadow spreads 3*5 - 10 = 5 pixels to the left, so the
1468 // occlusion must recede by 5 to account for that.
1469 expected_occlusion = gfx::Rect(105, 0, 45, 200);
1470 break;
1471 case TOP:
1472 // Similar to LEFT.
1473 expected_occlusion = gfx::Rect(0, 0, 200, 25);
1474 break;
1475 case BOTTOM:
1476 // Similar to RIGHT.
1477 expected_occlusion = gfx::Rect(0, 105, 200, 45);
1478 break;
1479 }
1480
1481 EXPECT_EQ(expected_occlusion.ToString(),
1482 occlusion.occlusion_from_inside_target().ToString());
1483 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1484
1485 this->DestroyLayers();
1486 }
1487 }
1488};
1489
1490ALL_OCCLUSIONTRACKER_TEST(
ajuma977555362016-07-19 16:12:121491 OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter);
jbroman19a18b12016-07-07 02:37:381492
[email protected]ca2902e92013-03-28 01:45:351493class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice
danakj00f7925e2015-06-15 21:19:221494 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491495 protected:
[email protected]ca2902e92013-03-28 01:45:351496 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(
[email protected]a27cbde2013-03-23 22:01:491497 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221498 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471499 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491500 gfx::Transform scale_by_half;
1501 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141502
[email protected]a27cbde2013-03-23 22:01:491503 // Makes two surfaces that completely cover |parent|. The occlusion both
1504 // above and below the filters will be reduced by each of them.
danakj00f7925e2015-06-15 21:19:221505 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491506 this->identity_matrix, gfx::PointF(), gfx::Size(75, 75));
danakj00f7925e2015-06-15 21:19:221507 LayerImpl* parent = this->CreateSurface(root, scale_by_half, gfx::PointF(),
1508 gfx::Size(150, 150));
[email protected]a27cbde2013-03-23 22:01:491509 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221510 LayerImpl* filtered_surface1 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491511 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
danakj00f7925e2015-06-15 21:19:221512 LayerImpl* filtered_surface2 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491513 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
danakj00f7925e2015-06-15 21:19:221514 LayerImpl* occluding_layer_above = this->CreateDrawingLayer(
1515 parent, this->identity_matrix, gfx::PointF(100.f, 100.f),
1516 gfx::Size(50, 50), true);
[email protected]94f206c12012-08-25 00:09:141517
[email protected]a27cbde2013-03-23 22:01:491518 // Filters make the layers own surfaces.
jaydasika6b5a32bf2016-04-22 21:56:361519 filtered_surface1->test_properties()->force_render_surface = true;
1520 filtered_surface2->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291521 FilterOperations filters;
1522 filters.Append(FilterOperation::CreateBlurFilter(1.f));
ajuma50bce7e2016-06-24 20:56:041523 filtered_surface1->test_properties()->background_filters = filters;
1524 filtered_surface2->test_properties()->background_filters = filters;
[email protected]94f206c12012-08-25 00:09:141525
[email protected]a27cbde2013-03-23 22:01:491526 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141527
danakj00f7925e2015-06-15 21:19:221528 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141529
[email protected]d002dd02013-03-27 07:40:401530 this->VisitLayer(occluding_layer_above, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491531 EXPECT_EQ(gfx::Rect().ToString(),
1532 occlusion.occlusion_from_outside_target().ToString());
1533 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(),
1534 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141535
[email protected]d002dd02013-03-27 07:40:401536 this->VisitLayer(filtered_surface2, &occlusion);
1537 this->VisitContributingSurface(filtered_surface2, &occlusion);
1538 this->VisitLayer(filtered_surface1, &occlusion);
1539 this->VisitContributingSurface(filtered_surface1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141540
[email protected]a27cbde2013-03-23 22:01:491541 // Test expectations in the target.
jbroman56c1f9c2016-07-06 19:08:101542 int blur_outset = 3;
[email protected]a27cbde2013-03-23 22:01:491543 gfx::Rect expected_occlusion =
jbroman56c1f9c2016-07-06 19:08:101544 gfx::Rect(100 / 2 + blur_outset * 2, 100 / 2 + blur_outset * 2,
1545 50 / 2 - blur_outset * 4, 50 / 2 - blur_outset * 4);
[email protected]a27cbde2013-03-23 22:01:491546 EXPECT_EQ(expected_occlusion.ToString(),
1547 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141548
[email protected]a27cbde2013-03-23 22:01:491549 // Test expectations in the screen are the same as in the target, as the
1550 // render surface is 1:1 with the screen.
1551 EXPECT_EQ(expected_occlusion.ToString(),
1552 occlusion.occlusion_from_outside_target().ToString());
1553 }
[email protected]94f206c12012-08-25 00:09:141554};
1555
[email protected]a27cbde2013-03-23 22:01:491556ALL_OCCLUSIONTRACKER_TEST(
1557 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:141558
[email protected]ca2902e92013-03-28 01:45:351559class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter
danakj00f7925e2015-06-15 21:19:221560 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491561 protected:
[email protected]ca2902e92013-03-28 01:45:351562 explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:491563 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221564 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471565 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491566 gfx::Transform scale_by_half;
1567 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141568
wangxianzhu932d7f12016-09-30 05:47:001569 // Make a 50x50 surface, with a smaller 30x30 layer centered below it.
1570 // The surface is scaled to test that the pixel moving is done in the target
1571 // space, where the background filter is applied, and the surface appears at
1572 // 50, 50.
danakj00f7925e2015-06-15 21:19:221573 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491574 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
danakj00f7925e2015-06-15 21:19:221575 LayerImpl* behind_surface_layer = this->CreateDrawingLayer(
1576 parent, this->identity_matrix, gfx::PointF(60.f, 60.f),
1577 gfx::Size(30, 30), true);
danakj00f7925e2015-06-15 21:19:221578 LayerImpl* filtered_surface =
1579 this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f),
1580 gfx::Size(100, 100), false);
[email protected]94f206c12012-08-25 00:09:141581
[email protected]a27cbde2013-03-23 22:01:491582 // Filters make the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361583 filtered_surface->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291584 FilterOperations filters;
1585 filters.Append(FilterOperation::CreateBlurFilter(3.f));
ajuma50bce7e2016-06-24 20:56:041586 filtered_surface->test_properties()->background_filters = filters;
[email protected]94f206c12012-08-25 00:09:141587
[email protected]a27cbde2013-03-23 22:01:491588 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141589
danakj00f7925e2015-06-15 21:19:221590 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141591
[email protected]a27cbde2013-03-23 22:01:491592 // The surface has a background blur, so it blurs non-opaque pixels below
1593 // it.
[email protected]d002dd02013-03-27 07:40:401594 this->VisitLayer(filtered_surface, &occlusion);
1595 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141596
[email protected]d5467eb72014-08-22 01:16:431597 // The layers behind the surface are not blurred, and their occlusion does
1598 // not change, until we leave the surface. So it should not be modified by
1599 // the filter here.
[email protected]d5467eb72014-08-22 01:16:431600 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1601
1602 // Clear the occlusion so the |behind_surface_layer| can add its occlusion
1603 // without existing occlusion interfering.
1604 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
1605
[email protected]d002dd02013-03-27 07:40:401606 this->VisitLayer(behind_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141607
[email protected]a27cbde2013-03-23 22:01:491608 // The layers behind the surface are not blurred, and their occlusion does
1609 // not change, until we leave the surface. So it should not be modified by
1610 // the filter here.
1611 gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30);
[email protected]d5467eb72014-08-22 01:16:431612 EXPECT_EQ(occlusion_behind_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:491613 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431614 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491615 }
[email protected]94f206c12012-08-25 00:09:141616};
1617
[email protected]a27cbde2013-03-23 22:01:491618ALL_OCCLUSIONTRACKER_TEST(
1619 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:141620
[email protected]ca2902e92013-03-28 01:45:351621class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded
danakj00f7925e2015-06-15 21:19:221622 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491623 protected:
[email protected]ca2902e92013-03-28 01:45:351624 explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(
[email protected]a27cbde2013-03-23 22:01:491625 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221626 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471627 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491628 gfx::Transform scale_by_half;
1629 scale_by_half.Scale(0.5, 0.5);
1630
[email protected]66b52e12013-11-17 15:53:181631 // Make a 50x50 filtered surface that is completely occluded by an opaque
1632 // layer which is above it in the z-order. The surface is
[email protected]a27cbde2013-03-23 22:01:491633 // scaled to test that the pixel moving is done in the target space, where
wangxianzhu932d7f12016-09-30 05:47:001634 // the background filter is applied, and the surface appears at 50, 50.
danakj00f7925e2015-06-15 21:19:221635 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]66b52e12013-11-17 15:53:181636 this->identity_matrix, gfx::PointF(), gfx::Size(200, 150));
danakj00f7925e2015-06-15 21:19:221637 LayerImpl* filtered_surface =
1638 this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f),
1639 gfx::Size(100, 100), false);
1640 LayerImpl* occluding_layer = this->CreateDrawingLayer(
1641 parent, this->identity_matrix, gfx::PointF(50.f, 50.f),
1642 gfx::Size(50, 50), true);
[email protected]a27cbde2013-03-23 22:01:491643
1644 // Filters make the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361645 filtered_surface->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291646 FilterOperations filters;
1647 filters.Append(FilterOperation::CreateBlurFilter(3.f));
ajuma50bce7e2016-06-24 20:56:041648 filtered_surface->test_properties()->background_filters = filters;
[email protected]a27cbde2013-03-23 22:01:491649
1650 this->CalcDrawEtc(parent);
1651
danakj00f7925e2015-06-15 21:19:221652 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491653
[email protected]66b52e12013-11-17 15:53:181654 this->VisitLayer(occluding_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491655
[email protected]d002dd02013-03-27 07:40:401656 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141657 {
[email protected]a27cbde2013-03-23 22:01:491658 // The layers above the filtered surface occlude from outside.
1659 gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50);
[email protected]94f206c12012-08-25 00:09:141660
[email protected]a27cbde2013-03-23 22:01:491661 EXPECT_EQ(gfx::Rect().ToString(),
1662 occlusion.occlusion_from_inside_target().ToString());
[email protected]66b52e12013-11-17 15:53:181663 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:491664 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141665 }
[email protected]a27cbde2013-03-23 22:01:491666
1667 // The surface has a background blur, so it blurs non-opaque pixels below
1668 // it.
[email protected]d002dd02013-03-27 07:40:401669 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491670 {
1671 // The filter is completely occluded, so it should not blur anything and
1672 // reduce any occlusion.
1673 gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50);
[email protected]a27cbde2013-03-23 22:01:491674
[email protected]66b52e12013-11-17 15:53:181675 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:491676 occlusion.occlusion_from_inside_target().ToString());
1677 EXPECT_EQ(gfx::Rect().ToString(),
1678 occlusion.occlusion_from_outside_target().ToString());
1679 }
1680 }
[email protected]94f206c12012-08-25 00:09:141681};
1682
[email protected]a27cbde2013-03-23 22:01:491683ALL_OCCLUSIONTRACKER_TEST(
1684 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:141685
danakj00f7925e2015-06-15 21:19:221686class OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded
1687 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491688 protected:
danakj00f7925e2015-06-15 21:19:221689 explicit OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded(
[email protected]a27cbde2013-03-23 22:01:491690 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221691 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471692 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491693 gfx::Transform scale_by_half;
1694 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141695
wangxianzhu932d7f12016-09-30 05:47:001696 // Make a 50x50 surface which is partially occluded by opaque layers which
1697 // are above it in the z-order. The surface is scaled to test that the
1698 // pixel moving is done in the target space, where the background filter is
1699 // applied, but the surface appears at 50, 50.
danakj00f7925e2015-06-15 21:19:221700 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491701 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
danakj00f7925e2015-06-15 21:19:221702 LayerImpl* filtered_surface =
1703 this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f),
1704 gfx::Size(100, 100), false);
danakj00f7925e2015-06-15 21:19:221705 LayerImpl* above_surface_layer = this->CreateDrawingLayer(
1706 parent, this->identity_matrix, gfx::PointF(70.f, 50.f),
1707 gfx::Size(30, 50), true);
danakj00f7925e2015-06-15 21:19:221708 LayerImpl* beside_surface_layer = this->CreateDrawingLayer(
1709 parent, this->identity_matrix, gfx::PointF(90.f, 40.f),
1710 gfx::Size(10, 10), true);
[email protected]94f206c12012-08-25 00:09:141711
[email protected]a27cbde2013-03-23 22:01:491712 // Filters make the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361713 filtered_surface->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291714 FilterOperations filters;
1715 filters.Append(FilterOperation::CreateBlurFilter(3.f));
ajuma50bce7e2016-06-24 20:56:041716 filtered_surface->test_properties()->background_filters = filters;
[email protected]94f206c12012-08-25 00:09:141717
[email protected]a27cbde2013-03-23 22:01:491718 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141719
danakj00f7925e2015-06-15 21:19:221720 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141721
[email protected]d002dd02013-03-27 07:40:401722 this->VisitLayer(beside_surface_layer, &occlusion);
[email protected]d002dd02013-03-27 07:40:401723 this->VisitLayer(above_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141724
[email protected]a27cbde2013-03-23 22:01:491725 // The surface has a background blur, so it blurs non-opaque pixels below
1726 // it.
[email protected]d002dd02013-03-27 07:40:401727 this->VisitLayer(filtered_surface, &occlusion);
1728 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141729
wangxianzhu932d7f12016-09-30 05:47:001730 // The filter in the surface is partially unoccluded. Only the unoccluded
1731 // parts should reduce occlusion. This means it will push back the
1732 // occlusion that touches the unoccluded part (occlusion_above___), but
[email protected]a27cbde2013-03-23 22:01:491733 // it will not touch occlusion_beside____ since that is not beside the
1734 // unoccluded part of the surface, even though it is beside the occluded
1735 // part of the surface.
jbroman56c1f9c2016-07-06 19:08:101736 int blur_outset = 9;
[email protected]a27cbde2013-03-23 22:01:491737 gfx::Rect occlusion_above_surface =
jbroman56c1f9c2016-07-06 19:08:101738 gfx::Rect(70 + blur_outset, 50, 30 - blur_outset, 50);
[email protected]a27cbde2013-03-23 22:01:491739 gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:141740
[email protected]d5467eb72014-08-22 01:16:431741 SimpleEnclosedRegion expected_occlusion;
[email protected]d5467eb72014-08-22 01:16:431742 expected_occlusion.Union(occlusion_beside_surface);
[email protected]d5467eb72014-08-22 01:16:431743 expected_occlusion.Union(occlusion_above_surface);
[email protected]94f206c12012-08-25 00:09:141744
[email protected]d5467eb72014-08-22 01:16:431745 EXPECT_EQ(expected_occlusion.ToString(),
[email protected]a27cbde2013-03-23 22:01:491746 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431747 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141748
[email protected]d5467eb72014-08-22 01:16:431749 const SimpleEnclosedRegion& actual_occlusion =
1750 occlusion.occlusion_from_inside_target();
1751 for (size_t i = 0; i < expected_occlusion.GetRegionComplexity(); ++i) {
1752 ASSERT_LT(i, actual_occlusion.GetRegionComplexity());
1753 EXPECT_EQ(expected_occlusion.GetRect(i), actual_occlusion.GetRect(i));
[email protected]94f206c12012-08-25 00:09:141754 }
[email protected]a27cbde2013-03-23 22:01:491755 }
[email protected]94f206c12012-08-25 00:09:141756};
1757
[email protected]a27cbde2013-03-23 22:01:491758ALL_OCCLUSIONTRACKER_TEST(
danakj00f7925e2015-06-15 21:19:221759 OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:141760
danakj4902c302015-02-13 22:12:161761class OcclusionTrackerTestBlendModeDoesNotOcclude
danakj00f7925e2015-06-15 21:19:221762 : public OcclusionTrackerTest {
danakj4902c302015-02-13 22:12:161763 protected:
1764 explicit OcclusionTrackerTestBlendModeDoesNotOcclude(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221765 : OcclusionTrackerTest(opaque_layers) {}
danakj4902c302015-02-13 22:12:161766 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221767 TestContentLayerImpl* parent = this->CreateRoot(
danakj4902c302015-02-13 22:12:161768 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
danakj00f7925e2015-06-15 21:19:221769 LayerImpl* blend_mode_layer = this->CreateDrawingLayer(
danakj4902c302015-02-13 22:12:161770 parent, this->identity_matrix, gfx::PointF(0.f, 0.f),
1771 gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:221772 LayerImpl* top_layer = this->CreateDrawingLayer(
danakj4902c302015-02-13 22:12:161773 parent, this->identity_matrix, gfx::PointF(10.f, 12.f),
1774 gfx::Size(20, 22), true);
1775
1776 // Blend mode makes the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361777 blend_mode_layer->test_properties()->force_render_surface = true;
reedcc9c70f2016-11-22 04:26:011778 blend_mode_layer->test_properties()->blend_mode = SkBlendMode::kMultiply;
danakj4902c302015-02-13 22:12:161779
1780 this->CalcDrawEtc(parent);
1781
danakj00f7925e2015-06-15 21:19:221782 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
danakj4902c302015-02-13 22:12:161783
1784 this->VisitLayer(top_layer, &occlusion);
1785 // |top_layer| occludes.
1786 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(),
1787 occlusion.occlusion_from_inside_target().ToString());
1788 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1789
1790 this->VisitLayer(blend_mode_layer, &occlusion);
ajuma2d466aa2016-07-25 21:11:001791 // |top_layer| and |blend_mode_layer| both occlude, since the blend mode
1792 // gets applied by blend_mode_layer's render surface, not when drawing the
1793 // layer itself.
1794 EXPECT_EQ(gfx::Rect(100, 100).ToString(),
1795 occlusion.occlusion_from_inside_target().ToString());
danakj4902c302015-02-13 22:12:161796 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(),
1797 occlusion.occlusion_from_outside_target().ToString());
danakj4902c302015-02-13 22:12:161798
1799 this->VisitContributingSurface(blend_mode_layer, &occlusion);
1800 // |top_layer| occludes but not |blend_mode_layer|.
1801 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(),
1802 occlusion.occlusion_from_inside_target().ToString());
1803 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1804 }
1805};
1806
1807ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestBlendModeDoesNotOcclude);
1808
danakj00f7925e2015-06-15 21:19:221809class OcclusionTrackerTestMinimumTrackingSize : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491810 protected:
[email protected]ca2902e92013-03-28 01:45:351811 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221812 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471813 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491814 gfx::Size tracking_size(100, 100);
1815 gfx::Size below_tracking_size(99, 99);
[email protected]94f206c12012-08-25 00:09:141816
danakj00f7925e2015-06-15 21:19:221817 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491818 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221819 LayerImpl* large = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491820 parent, this->identity_matrix, gfx::PointF(), tracking_size, true);
danakj00f7925e2015-06-15 21:19:221821 LayerImpl* small =
1822 this->CreateDrawingLayer(parent, this->identity_matrix, gfx::PointF(),
1823 below_tracking_size, true);
[email protected]a27cbde2013-03-23 22:01:491824 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141825
danakj00f7925e2015-06-15 21:19:221826 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491827 occlusion.set_minimum_tracking_size(tracking_size);
[email protected]94f206c12012-08-25 00:09:141828
[email protected]a27cbde2013-03-23 22:01:491829 // The small layer is not tracked because it is too small.
[email protected]d002dd02013-03-27 07:40:401830 this->VisitLayer(small, &occlusion);
[email protected]94f206c12012-08-25 00:09:141831
[email protected]a27cbde2013-03-23 22:01:491832 EXPECT_EQ(gfx::Rect().ToString(),
1833 occlusion.occlusion_from_outside_target().ToString());
1834 EXPECT_EQ(gfx::Rect().ToString(),
1835 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141836
[email protected]a27cbde2013-03-23 22:01:491837 // The large layer is tracked as it is large enough.
[email protected]d002dd02013-03-27 07:40:401838 this->VisitLayer(large, &occlusion);
[email protected]94f206c12012-08-25 00:09:141839
[email protected]a27cbde2013-03-23 22:01:491840 EXPECT_EQ(gfx::Rect().ToString(),
1841 occlusion.occlusion_from_outside_target().ToString());
[email protected]2c7c6702013-03-26 03:14:051842 EXPECT_EQ(gfx::Rect(tracking_size).ToString(),
[email protected]a27cbde2013-03-23 22:01:491843 occlusion.occlusion_from_inside_target().ToString());
1844 }
[email protected]94f206c12012-08-25 00:09:141845};
1846
[email protected]96baf3e2012-10-22 23:09:551847ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:141848
danakj00f7925e2015-06-15 21:19:221849class OcclusionTrackerTestScaledLayerIsClipped : public OcclusionTrackerTest {
[email protected]1a5d9ce2013-04-30 01:31:091850 protected:
1851 explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221852 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471853 void RunMyTest() override {
[email protected]1a5d9ce2013-04-30 01:31:091854 gfx::Transform scale_transform;
1855 scale_transform.Scale(512.0, 512.0);
1856
danakj00f7925e2015-06-15 21:19:221857 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]1a5d9ce2013-04-30 01:31:091858 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221859 LayerImpl* clip =
1860 this->CreateLayer(parent, this->identity_matrix,
1861 gfx::PointF(10.f, 10.f), gfx::Size(50, 50));
[email protected]1a5d9ce2013-04-30 01:31:091862 clip->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221863 LayerImpl* scale = this->CreateLayer(clip, scale_transform, gfx::PointF(),
1864 gfx::Size(1, 1));
1865 LayerImpl* scaled = this->CreateDrawingLayer(
[email protected]1a5d9ce2013-04-30 01:31:091866 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
1867 this->CalcDrawEtc(parent);
1868
danakj00f7925e2015-06-15 21:19:221869 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]1a5d9ce2013-04-30 01:31:091870
1871 this->VisitLayer(scaled, &occlusion);
1872
1873 EXPECT_EQ(gfx::Rect().ToString(),
1874 occlusion.occlusion_from_outside_target().ToString());
1875 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
1876 occlusion.occlusion_from_inside_target().ToString());
1877 }
1878};
1879
1880ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped)
1881
[email protected]1a5d9ce2013-04-30 01:31:091882class OcclusionTrackerTestScaledLayerInSurfaceIsClipped
danakj00f7925e2015-06-15 21:19:221883 : public OcclusionTrackerTest {
[email protected]1a5d9ce2013-04-30 01:31:091884 protected:
1885 explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221886 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471887 void RunMyTest() override {
[email protected]1a5d9ce2013-04-30 01:31:091888 gfx::Transform scale_transform;
1889 scale_transform.Scale(512.0, 512.0);
1890
danakj00f7925e2015-06-15 21:19:221891 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]1a5d9ce2013-04-30 01:31:091892 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221893 LayerImpl* clip =
1894 this->CreateLayer(parent, this->identity_matrix,
1895 gfx::PointF(10.f, 10.f), gfx::Size(50, 50));
[email protected]1a5d9ce2013-04-30 01:31:091896 clip->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221897 LayerImpl* surface = this->CreateDrawingSurface(
[email protected]1a5d9ce2013-04-30 01:31:091898 clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false);
danakj00f7925e2015-06-15 21:19:221899 LayerImpl* scale = this->CreateLayer(surface, scale_transform,
1900 gfx::PointF(), gfx::Size(1, 1));
1901 LayerImpl* scaled = this->CreateDrawingLayer(
[email protected]1a5d9ce2013-04-30 01:31:091902 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
1903 this->CalcDrawEtc(parent);
1904
danakj00f7925e2015-06-15 21:19:221905 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]1a5d9ce2013-04-30 01:31:091906
1907 this->VisitLayer(scaled, &occlusion);
1908 this->VisitLayer(surface, &occlusion);
1909 this->VisitContributingSurface(surface, &occlusion);
1910
1911 EXPECT_EQ(gfx::Rect().ToString(),
1912 occlusion.occlusion_from_outside_target().ToString());
1913 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
1914 occlusion.occlusion_from_inside_target().ToString());
1915 }
1916};
1917
1918ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped)
1919
danakj00f7925e2015-06-15 21:19:221920class OcclusionTrackerTestCopyRequestDoesOcclude : public OcclusionTrackerTest {
[email protected]5b54b972013-07-26 13:25:421921 protected:
1922 explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221923 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471924 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221925 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:241926 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221927 TestContentLayerImpl* parent = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:241928 root, this->identity_matrix, gfx::PointF(), gfx::Size(400, 400), true);
1929 LayerImpl* copy =
1930 this->CreateLayer(parent, this->identity_matrix, gfx::PointF(100, 0),
1931 gfx::Size(200, 400));
[email protected]5b54b972013-07-26 13:25:421932 this->AddCopyRequest(copy);
danakj00f7925e2015-06-15 21:19:221933 LayerImpl* copy_child = this->CreateDrawingLayer(
1934 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
1935 LayerImpl* top_layer =
danakj4902c302015-02-13 22:12:161936 this->CreateDrawingLayer(root, this->identity_matrix,
1937 gfx::PointF(50, 0), gfx::Size(50, 400), true);
[email protected]5b54b972013-07-26 13:25:421938 this->CalcDrawEtc(root);
1939
danakj00f7925e2015-06-15 21:19:221940 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]5b54b972013-07-26 13:25:421941
danakj4902c302015-02-13 22:12:161942 this->VisitLayer(top_layer, &occlusion);
1943 EXPECT_EQ(gfx::Rect().ToString(),
1944 occlusion.occlusion_from_outside_target().ToString());
1945 EXPECT_EQ(gfx::Rect(50, 0, 50, 400).ToString(),
1946 occlusion.occlusion_from_inside_target().ToString());
1947
[email protected]5b54b972013-07-26 13:25:421948 this->VisitLayer(copy_child, &occlusion);
danakj4902c302015-02-13 22:12:161949 // Layers outside the copy request do not occlude.
[email protected]5b54b972013-07-26 13:25:421950 EXPECT_EQ(gfx::Rect().ToString(),
1951 occlusion.occlusion_from_outside_target().ToString());
1952 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
1953 occlusion.occlusion_from_inside_target().ToString());
1954
1955 // CopyRequests cause the layer to own a surface.
1956 this->VisitContributingSurface(copy, &occlusion);
1957
1958 // The occlusion from the copy should be kept.
1959 EXPECT_EQ(gfx::Rect().ToString(),
1960 occlusion.occlusion_from_outside_target().ToString());
danakj4902c302015-02-13 22:12:161961 EXPECT_EQ(gfx::Rect(50, 0, 250, 400).ToString(),
[email protected]5b54b972013-07-26 13:25:421962 occlusion.occlusion_from_inside_target().ToString());
1963 }
1964};
1965
1966ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude)
1967
[email protected]5b54b972013-07-26 13:25:421968class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude
danakj00f7925e2015-06-15 21:19:221969 : public OcclusionTrackerTest {
[email protected]5b54b972013-07-26 13:25:421970 protected:
1971 explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude(
1972 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221973 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471974 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221975 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:241976 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221977 TestContentLayerImpl* parent = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:241978 root, this->identity_matrix, gfx::PointF(), gfx::Size(400, 400), true);
danakj00f7925e2015-06-15 21:19:221979 LayerImpl* hide = this->CreateLayer(parent, this->identity_matrix,
danakja2fdbc702015-10-20 23:05:241980 gfx::PointF(), gfx::Size());
1981 LayerImpl* copy =
1982 this->CreateLayer(hide, this->identity_matrix, gfx::PointF(100.f, 0.f),
1983 gfx::Size(200, 400));
[email protected]5b54b972013-07-26 13:25:421984 this->AddCopyRequest(copy);
danakj00f7925e2015-06-15 21:19:221985 LayerImpl* copy_child = this->CreateDrawingLayer(
[email protected]5b54b972013-07-26 13:25:421986 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
1987
1988 // The |copy| layer is hidden but since it is being copied, it will be
1989 // drawn.
jaydasika5121caa82016-05-05 15:43:351990 hide->test_properties()->hide_layer_and_subtree = true;
[email protected]5b54b972013-07-26 13:25:421991
1992 this->CalcDrawEtc(root);
1993
danakj00f7925e2015-06-15 21:19:221994 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]5b54b972013-07-26 13:25:421995
1996 this->VisitLayer(copy_child, &occlusion);
1997 EXPECT_EQ(gfx::Rect().ToString(),
1998 occlusion.occlusion_from_outside_target().ToString());
1999 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
2000 occlusion.occlusion_from_inside_target().ToString());
2001
2002 // CopyRequests cause the layer to own a surface.
2003 this->VisitContributingSurface(copy, &occlusion);
2004
2005 // The occlusion from the copy should be dropped since it is hidden.
2006 EXPECT_EQ(gfx::Rect().ToString(),
2007 occlusion.occlusion_from_outside_target().ToString());
2008 EXPECT_EQ(gfx::Rect().ToString(),
2009 occlusion.occlusion_from_inside_target().ToString());
2010 }
2011};
2012
2013ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude)
2014
danakj00f7925e2015-06-15 21:19:222015class OcclusionTrackerTestOccludedLayer : public OcclusionTrackerTest {
[email protected]d5467eb72014-08-22 01:16:432016 protected:
2017 explicit OcclusionTrackerTestOccludedLayer(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:222018 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472019 void RunMyTest() override {
[email protected]d5467eb72014-08-22 01:16:432020 gfx::Transform translate;
2021 translate.Translate(10.0, 20.0);
danakj00f7925e2015-06-15 21:19:222022 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:242023 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2024 LayerImpl* surface = this->CreateSurface(
2025 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:222026 LayerImpl* layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242027 surface, translate, gfx::PointF(), gfx::Size(200, 200), false);
danakj00f7925e2015-06-15 21:19:222028 TestContentLayerImpl* outside_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242029 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false);
[email protected]d5467eb72014-08-22 01:16:432030 this->CalcDrawEtc(root);
2031
danakj00f7925e2015-06-15 21:19:222032 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
[email protected]d5467eb72014-08-22 01:16:432033 this->VisitLayer(outside_layer, &occlusion);
2034 this->EnterLayer(layer, &occlusion);
2035
2036 // No occlusion, is not occluded.
2037 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2038 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2039 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100)));
2040
2041 // Partial occlusion from outside, is not occluded.
2042 occlusion.set_occlusion_from_outside_target(
2043 SimpleEnclosedRegion(50, 50, 100, 100));
2044 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2045 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2046 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2047 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2048 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2049 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2050 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2051 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2052 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2053
2054 // Full occlusion from outside, is occluded.
2055 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2056 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2057 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2058 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2059
2060 // Partial occlusion from inside, is not occluded.
2061 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2062 occlusion.set_occlusion_from_inside_target(
2063 SimpleEnclosedRegion(50, 50, 100, 100));
2064 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2065 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2066 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2067 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2068 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2069 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2070 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2071 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2072
2073 // Full occlusion from inside, is occluded.
2074 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2075 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2076 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2077 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2078
2079 // Partial occlusion from both, is not occluded.
2080 occlusion.set_occlusion_from_outside_target(
2081 SimpleEnclosedRegion(50, 50, 100, 50));
2082 occlusion.set_occlusion_from_inside_target(
2083 SimpleEnclosedRegion(50, 100, 100, 50));
2084 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2085 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2086 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2087 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2088 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2089 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2090 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2091 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2092
2093 // Full occlusion from both, is occluded.
2094 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2095 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2096 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2097 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2098 }
2099};
2100
2101ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOccludedLayer)
2102
danakj00f7925e2015-06-15 21:19:222103class OcclusionTrackerTestUnoccludedLayerQuery : public OcclusionTrackerTest {
danakjf080b5b2014-08-23 22:18:202104 protected:
2105 explicit OcclusionTrackerTestUnoccludedLayerQuery(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:222106 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472107 void RunMyTest() override {
danakjf080b5b2014-08-23 22:18:202108 gfx::Transform translate;
2109 translate.Translate(10.0, 20.0);
danakj00f7925e2015-06-15 21:19:222110 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:242111 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2112 LayerImpl* surface = this->CreateSurface(
2113 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:222114 LayerImpl* layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242115 surface, translate, gfx::PointF(), gfx::Size(200, 200), false);
danakj00f7925e2015-06-15 21:19:222116 TestContentLayerImpl* outside_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242117 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false);
danakjf080b5b2014-08-23 22:18:202118 this->CalcDrawEtc(root);
2119
danakj00f7925e2015-06-15 21:19:222120 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
danakjf080b5b2014-08-23 22:18:202121 this->VisitLayer(outside_layer, &occlusion);
2122 this->EnterLayer(layer, &occlusion);
2123
2124 // No occlusion, is not occluded.
2125 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2126 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2127 EXPECT_EQ(gfx::Rect(100, 100),
2128 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(100, 100)));
2129
2130 // Partial occlusion from outside.
2131 occlusion.set_occlusion_from_outside_target(
2132 SimpleEnclosedRegion(50, 50, 100, 100));
2133 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2134 EXPECT_EQ(
2135 gfx::Rect(0, 0, 100, 100),
2136 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
2137 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2138 occlusion.UnoccludedLayerContentRect(
2139 layer, gfx::Rect(90, 30, 100, 100)));
2140 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2141 occlusion.UnoccludedLayerContentRect(layer,
2142 gfx::Rect(40, 0, 100, 100)));
2143 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2144 occlusion.UnoccludedLayerContentRect(
2145 layer, gfx::Rect(40, 80, 100, 100)));
2146 EXPECT_EQ(
2147 gfx::Rect(0, 0, 80, 100),
2148 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
2149 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2150 occlusion.UnoccludedLayerContentRect(
2151 layer, gfx::Rect(90, 80, 100, 100)));
2152 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2153 occlusion.UnoccludedLayerContentRect(layer,
2154 gfx::Rect(0, 80, 100, 100)));
2155 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2156 occlusion.UnoccludedLayerContentRect(layer,
2157 gfx::Rect(90, 0, 100, 100)));
2158
2159 // Full occlusion from outside, is occluded.
2160 EXPECT_EQ(gfx::Rect(),
2161 occlusion.UnoccludedLayerContentRect(
2162 layer, gfx::Rect(40, 30, 100, 100)));
2163 EXPECT_EQ(
2164 gfx::Rect(),
2165 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
2166 EXPECT_EQ(gfx::Rect(),
2167 occlusion.UnoccludedLayerContentRect(
2168 layer, gfx::Rect(130, 120, 10, 10)));
2169 EXPECT_EQ(
2170 gfx::Rect(),
2171 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
2172
2173 // Partial occlusion from inside, is not occluded.
2174 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2175 occlusion.set_occlusion_from_inside_target(
2176 SimpleEnclosedRegion(50, 50, 100, 100));
2177 EXPECT_EQ(
2178 gfx::Rect(0, 0, 100, 100),
2179 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
2180 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2181 occlusion.UnoccludedLayerContentRect(
2182 layer, gfx::Rect(90, 30, 100, 100)));
2183 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2184 occlusion.UnoccludedLayerContentRect(layer,
2185 gfx::Rect(40, 0, 100, 100)));
2186 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2187 occlusion.UnoccludedLayerContentRect(
2188 layer, gfx::Rect(40, 80, 100, 100)));
2189 EXPECT_EQ(
2190 gfx::Rect(0, 0, 80, 100),
2191 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
2192 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2193 occlusion.UnoccludedLayerContentRect(
2194 layer, gfx::Rect(90, 80, 100, 100)));
2195 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2196 occlusion.UnoccludedLayerContentRect(layer,
2197 gfx::Rect(0, 80, 100, 100)));
2198 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2199 occlusion.UnoccludedLayerContentRect(layer,
2200 gfx::Rect(90, 0, 100, 100)));
2201
2202 // Full occlusion from inside, is occluded.
2203 EXPECT_EQ(gfx::Rect(),
2204 occlusion.UnoccludedLayerContentRect(
2205 layer, gfx::Rect(40, 30, 100, 100)));
2206 EXPECT_EQ(
2207 gfx::Rect(),
2208 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
2209 EXPECT_EQ(gfx::Rect(),
2210 occlusion.UnoccludedLayerContentRect(
2211 layer, gfx::Rect(130, 120, 10, 10)));
2212 EXPECT_EQ(
2213 gfx::Rect(),
2214 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
2215
2216 // Partial occlusion from both, is not occluded.
2217 occlusion.set_occlusion_from_outside_target(
2218 SimpleEnclosedRegion(50, 50, 100, 50));
2219 occlusion.set_occlusion_from_inside_target(
2220 SimpleEnclosedRegion(50, 100, 100, 50));
2221 EXPECT_EQ(
2222 gfx::Rect(0, 0, 100, 100),
2223 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
2224 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
2225 // it's larger.
2226 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
2227 occlusion.UnoccludedLayerContentRect(
2228 layer, gfx::Rect(90, 30, 100, 100)));
2229 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2230 occlusion.UnoccludedLayerContentRect(layer,
2231 gfx::Rect(40, 0, 100, 100)));
2232 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2233 occlusion.UnoccludedLayerContentRect(
2234 layer, gfx::Rect(40, 80, 100, 100)));
2235 EXPECT_EQ(
2236 gfx::Rect(0, 0, 80, 100),
2237 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
2238 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2239 occlusion.UnoccludedLayerContentRect(
2240 layer, gfx::Rect(90, 80, 100, 100)));
2241 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2242 occlusion.UnoccludedLayerContentRect(layer,
2243 gfx::Rect(0, 80, 100, 100)));
2244 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2245 occlusion.UnoccludedLayerContentRect(layer,
2246 gfx::Rect(90, 0, 100, 100)));
2247
2248 // Full occlusion from both, is occluded.
2249 EXPECT_EQ(gfx::Rect(),
2250 occlusion.UnoccludedLayerContentRect(
2251 layer, gfx::Rect(40, 30, 100, 100)));
2252 EXPECT_EQ(
2253 gfx::Rect(),
2254 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
2255 EXPECT_EQ(gfx::Rect(),
2256 occlusion.UnoccludedLayerContentRect(
2257 layer, gfx::Rect(130, 120, 10, 10)));
2258 EXPECT_EQ(
2259 gfx::Rect(),
2260 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
2261 }
2262};
2263
2264ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedLayerQuery)
2265
danakj00f7925e2015-06-15 21:19:222266class OcclusionTrackerTestUnoccludedSurfaceQuery : public OcclusionTrackerTest {
danakjf080b5b2014-08-23 22:18:202267 protected:
2268 explicit OcclusionTrackerTestUnoccludedSurfaceQuery(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:222269 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472270 void RunMyTest() override {
danakjf080b5b2014-08-23 22:18:202271 gfx::Transform translate;
2272 translate.Translate(10.0, 20.0);
danakj00f7925e2015-06-15 21:19:222273 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:242274 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2275 LayerImpl* surface = this->CreateSurface(root, translate, gfx::PointF(),
2276 gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:222277 LayerImpl* layer =
danakja2fdbc702015-10-20 23:05:242278 this->CreateDrawingLayer(surface, this->identity_matrix, gfx::PointF(),
danakj00f7925e2015-06-15 21:19:222279 gfx::Size(200, 200), false);
2280 TestContentLayerImpl* outside_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242281 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false);
danakjf080b5b2014-08-23 22:18:202282 this->CalcDrawEtc(root);
2283
danakj00f7925e2015-06-15 21:19:222284 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
danakjf080b5b2014-08-23 22:18:202285 this->VisitLayer(outside_layer, &occlusion);
2286 this->VisitLayer(layer, &occlusion);
2287 this->EnterContributingSurface(surface, &occlusion);
2288
2289 // No occlusion, is not occluded.
2290 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2291 SimpleEnclosedRegion());
2292 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2293 SimpleEnclosedRegion());
2294 EXPECT_EQ(
2295 gfx::Rect(100, 100),
2296 occlusion.UnoccludedSurfaceContentRect(surface, gfx::Rect(100, 100)));
2297
2298 // Partial occlusion from outside.
2299 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2300 SimpleEnclosedRegion(50, 50, 100, 100));
2301 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2302 SimpleEnclosedRegion());
2303 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2304 occlusion.UnoccludedSurfaceContentRect(
2305 surface, gfx::Rect(0, 0, 100, 100)));
2306 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2307 occlusion.UnoccludedSurfaceContentRect(
2308 surface, gfx::Rect(90, 30, 100, 100)));
2309 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2310 occlusion.UnoccludedSurfaceContentRect(
2311 surface, gfx::Rect(40, 0, 100, 100)));
2312 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2313 occlusion.UnoccludedSurfaceContentRect(
2314 surface, gfx::Rect(40, 80, 100, 100)));
2315 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
2316 occlusion.UnoccludedSurfaceContentRect(surface,
2317 gfx::Rect(0, 0, 80, 100)));
2318 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2319 occlusion.UnoccludedSurfaceContentRect(
2320 surface, gfx::Rect(90, 80, 100, 100)));
2321 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2322 occlusion.UnoccludedSurfaceContentRect(
2323 surface, gfx::Rect(0, 80, 100, 100)));
2324 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2325 occlusion.UnoccludedSurfaceContentRect(
2326 surface, gfx::Rect(90, 0, 100, 100)));
2327
2328 // Full occlusion from outside, is occluded.
2329 EXPECT_EQ(gfx::Rect(),
2330 occlusion.UnoccludedSurfaceContentRect(
2331 surface, gfx::Rect(40, 30, 100, 100)));
2332 EXPECT_EQ(gfx::Rect(),
2333 occlusion.UnoccludedSurfaceContentRect(
2334 surface, gfx::Rect(40, 30, 10, 10)));
2335 EXPECT_EQ(gfx::Rect(),
2336 occlusion.UnoccludedSurfaceContentRect(
2337 surface, gfx::Rect(130, 120, 10, 10)));
2338 EXPECT_EQ(gfx::Rect(),
2339 occlusion.UnoccludedSurfaceContentRect(
2340 surface, gfx::Rect(80, 70, 50, 50)));
2341
2342 // Partial occlusion from inside, is not occluded.
2343 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2344 SimpleEnclosedRegion());
2345 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2346 SimpleEnclosedRegion(50, 50, 100, 100));
2347 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2348 occlusion.UnoccludedSurfaceContentRect(
2349 surface, gfx::Rect(0, 0, 100, 100)));
2350 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2351 occlusion.UnoccludedSurfaceContentRect(
2352 surface, gfx::Rect(90, 30, 100, 100)));
2353 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2354 occlusion.UnoccludedSurfaceContentRect(
2355 surface, gfx::Rect(40, 0, 100, 100)));
2356 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2357 occlusion.UnoccludedSurfaceContentRect(
2358 surface, gfx::Rect(40, 80, 100, 100)));
2359 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
2360 occlusion.UnoccludedSurfaceContentRect(surface,
2361 gfx::Rect(0, 0, 80, 100)));
2362 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2363 occlusion.UnoccludedSurfaceContentRect(
2364 surface, gfx::Rect(90, 80, 100, 100)));
2365 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2366 occlusion.UnoccludedSurfaceContentRect(
2367 surface, gfx::Rect(0, 80, 100, 100)));
2368 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2369 occlusion.UnoccludedSurfaceContentRect(
2370 surface, gfx::Rect(90, 0, 100, 100)));
2371
2372 // Full occlusion from inside, is occluded.
2373 EXPECT_EQ(gfx::Rect(),
2374 occlusion.UnoccludedSurfaceContentRect(
2375 surface, gfx::Rect(40, 30, 100, 100)));
2376 EXPECT_EQ(gfx::Rect(),
2377 occlusion.UnoccludedSurfaceContentRect(
2378 surface, gfx::Rect(40, 30, 10, 10)));
2379 EXPECT_EQ(gfx::Rect(),
2380 occlusion.UnoccludedSurfaceContentRect(
2381 surface, gfx::Rect(130, 120, 10, 10)));
2382 EXPECT_EQ(gfx::Rect(),
2383 occlusion.UnoccludedSurfaceContentRect(
2384 surface, gfx::Rect(80, 70, 50, 50)));
2385
2386 // Partial occlusion from both, is not occluded.
2387 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2388 SimpleEnclosedRegion(50, 50, 100, 50));
2389 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2390 SimpleEnclosedRegion(50, 100, 100, 50));
2391 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2392 occlusion.UnoccludedSurfaceContentRect(
2393 surface, gfx::Rect(0, 0, 100, 100)));
2394 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
2395 // it's larger.
2396 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
2397 occlusion.UnoccludedSurfaceContentRect(
2398 surface, gfx::Rect(90, 30, 100, 100)));
2399 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2400 occlusion.UnoccludedSurfaceContentRect(
2401 surface, gfx::Rect(40, 0, 100, 100)));
2402 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2403 occlusion.UnoccludedSurfaceContentRect(
2404 surface, gfx::Rect(40, 80, 100, 100)));
2405 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
2406 occlusion.UnoccludedSurfaceContentRect(surface,
2407 gfx::Rect(0, 0, 80, 100)));
2408 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2409 occlusion.UnoccludedSurfaceContentRect(
2410 surface, gfx::Rect(90, 80, 100, 100)));
2411 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2412 occlusion.UnoccludedSurfaceContentRect(
2413 surface, gfx::Rect(0, 80, 100, 100)));
2414 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2415 occlusion.UnoccludedSurfaceContentRect(
2416 surface, gfx::Rect(90, 0, 100, 100)));
2417
2418 // Full occlusion from both, is occluded.
2419 EXPECT_EQ(gfx::Rect(),
2420 occlusion.UnoccludedSurfaceContentRect(
2421 surface, gfx::Rect(40, 30, 100, 100)));
2422 EXPECT_EQ(gfx::Rect(),
2423 occlusion.UnoccludedSurfaceContentRect(
2424 surface, gfx::Rect(40, 30, 10, 10)));
2425 EXPECT_EQ(gfx::Rect(),
2426 occlusion.UnoccludedSurfaceContentRect(
2427 surface, gfx::Rect(130, 120, 10, 10)));
2428 EXPECT_EQ(gfx::Rect(),
2429 occlusion.UnoccludedSurfaceContentRect(
2430 surface, gfx::Rect(80, 70, 50, 50)));
2431 }
2432};
2433
2434ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery)
2435
[email protected]ba565742012-11-10 09:29:482436} // namespace
2437} // namespace cc