blob: 8c3120d841ac31ea9b5082300ec659f7f3f50ebc [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"
[email protected]5b54b972013-07-26 13:25:4213#include "cc/output/copy_output_request.h"
14#include "cc/output/copy_output_result.h"
[email protected]ae6b1a72013-06-25 18:49:2915#include "cc/output/filter_operation.h"
16#include "cc/output/filter_operations.h"
[email protected]101441ce2012-10-16 01:45:0317#include "cc/test/animation_test_common.h"
khushalsagarb64b360d2015-10-21 19:25:1618#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2819#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4520#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0321#include "cc/test/geometry_test_utils.h"
[email protected]34ba1ffb2014-03-05 06:55:0322#include "cc/test/test_occlusion_tracker.h"
danakjcf610582015-06-16 22:48:5623#include "cc/test/test_task_graph_runner.h"
[email protected]556fd292013-03-18 08:03:0424#include "cc/trees/layer_tree_host_common.h"
25#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1826#include "testing/gmock/include/gmock/gmock.h"
27#include "testing/gtest/include/gtest/gtest.h"
[email protected]c8686a02012-11-27 08:29:0028#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1429
[email protected]ba565742012-11-10 09:29:4830namespace cc {
[email protected]94f206c12012-08-25 00:09:1431namespace {
32
[email protected]96baf3e2012-10-22 23:09:5533class TestContentLayerImpl : public LayerImpl {
[email protected]a27cbde2013-03-23 22:01:4934 public:
35 TestContentLayerImpl(LayerTreeImpl* tree_impl, int id)
36 : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) {
37 SetDrawsContent(true);
38 }
[email protected]94f206c12012-08-25 00:09:1439
danakj64767d902015-06-19 00:10:4340 SimpleEnclosedRegion VisibleOpaqueRegion() const override {
[email protected]d5467eb72014-08-22 01:16:4341 if (override_opaque_contents_rect_) {
42 return SimpleEnclosedRegion(
danakj64767d902015-06-19 00:10:4343 gfx::IntersectRects(opaque_contents_rect_, visible_layer_rect()));
[email protected]d5467eb72014-08-22 01:16:4344 }
danakj64767d902015-06-19 00:10:4345 return LayerImpl::VisibleOpaqueRegion();
[email protected]a27cbde2013-03-23 22:01:4946 }
[email protected]0023fc72014-01-10 20:05:0647 void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) {
[email protected]a27cbde2013-03-23 22:01:4948 override_opaque_contents_rect_ = true;
49 opaque_contents_rect_ = opaque_contents_rect;
50 }
[email protected]94f206c12012-08-25 00:09:1451
[email protected]a27cbde2013-03-23 22:01:4952 private:
53 bool override_opaque_contents_rect_;
54 gfx::Rect opaque_contents_rect_;
[email protected]94f206c12012-08-25 00:09:1455};
56
danakj00f7925e2015-06-15 21:19:2257class TestOcclusionTrackerWithClip : public TestOcclusionTracker {
[email protected]a27cbde2013-03-23 22:01:4958 public:
[email protected]0023fc72014-01-10 20:05:0659 explicit TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect)
danakj00f7925e2015-06-15 21:19:2260 : TestOcclusionTracker(viewport_rect) {}
[email protected]94f206c12012-08-25 00:09:1461
danakj00f7925e2015-06-15 21:19:2262 bool OccludedLayer(const LayerImpl* layer,
[email protected]0023fc72014-01-10 20:05:0663 const gfx::Rect& content_rect) const {
danakj64767d902015-06-19 00:10:4364 DCHECK(layer->visible_layer_rect().Contains(content_rect));
ajumad9432e32015-11-30 19:43:4465 return this->GetCurrentOcclusionForLayer(layer->DrawTransform())
vmpstr01a5bf352014-09-17 22:57:3166 .IsOccluded(content_rect);
[email protected]a27cbde2013-03-23 22:01:4967 }
[email protected]fbc293322013-10-01 05:07:1568
[email protected]a27cbde2013-03-23 22:01:4969 // Gives an unoccluded sub-rect of |content_rect| in the content space of the
vmpstr5b88d992014-09-18 23:25:0470 // layer. Simple wrapper around GetUnoccludedContentRect.
danakj00f7925e2015-06-15 21:19:2271 gfx::Rect UnoccludedLayerContentRect(const LayerImpl* layer,
[email protected]0023fc72014-01-10 20:05:0672 const gfx::Rect& content_rect) const {
danakj64767d902015-06-19 00:10:4373 DCHECK(layer->visible_layer_rect().Contains(content_rect));
ajumad9432e32015-11-30 19:43:4474 return this->GetCurrentOcclusionForLayer(layer->DrawTransform())
vmpstr5b88d992014-09-18 23:25:0475 .GetUnoccludedContentRect(content_rect);
[email protected]a27cbde2013-03-23 22:01:4976 }
[email protected]e312aca2014-03-20 22:11:5577
danakj00f7925e2015-06-15 21:19:2278 gfx::Rect UnoccludedSurfaceContentRect(const LayerImpl* layer,
[email protected]e312aca2014-03-20 22:11:5579 const gfx::Rect& content_rect) const {
danakj00f7925e2015-06-15 21:19:2280 RenderSurfaceImpl* surface = layer->render_surface();
danakj206a5812015-02-11 02:07:0881 return this->GetCurrentOcclusionForContributingSurface(
82 surface->draw_transform())
83 .GetUnoccludedContentRect(content_rect);
[email protected]e312aca2014-03-20 22:11:5584 }
[email protected]94f206c12012-08-25 00:09:1485};
86
danakj00f7925e2015-06-15 21:19:2287class OcclusionTrackerTest : public testing::Test {
[email protected]a27cbde2013-03-23 22:01:4988 protected:
[email protected]ca2902e92013-03-28 01:45:3589 explicit OcclusionTrackerTest(bool opaque_layers)
enne2097cab2014-09-25 20:16:3190 : opaque_layers_(opaque_layers),
loyso2cb3f32f2016-11-08 07:08:3491 animation_host_(AnimationHost::CreateForTesting(ThreadInstance::MAIN)),
92 host_(FakeLayerTreeHost::Create(&client_,
93 &task_graph_runner_,
94 animation_host_.get())),
danakj00f7925e2015-06-15 21:19:2295 next_layer_impl_id_(1) {}
[email protected]a27cbde2013-03-23 22:01:4996
97 virtual void RunMyTest() = 0;
98
danakjaeb95062014-11-14 01:35:3699 void TearDown() override { DestroyLayers(); }
[email protected]a27cbde2013-03-23 22:01:49100
danakj00f7925e2015-06-15 21:19:22101 TestContentLayerImpl* CreateRoot(const gfx::Transform& transform,
102 const gfx::PointF& position,
103 const gfx::Size& bounds) {
104 LayerTreeImpl* tree = host_->host_impl()->active_tree();
105 int id = next_layer_impl_id_++;
danakj60bc3bc2016-04-09 00:24:48106 std::unique_ptr<TestContentLayerImpl> layer(
107 new TestContentLayerImpl(tree, id));
danakj00f7925e2015-06-15 21:19:22108 TestContentLayerImpl* layer_ptr = layer.get();
[email protected]a27cbde2013-03-23 22:01:49109 SetProperties(layer_ptr, transform, position, bounds);
110
jaydasikabf1875a2016-06-28 03:39:59111 host_->host_impl()->active_tree()->SetRootLayerForTesting(std::move(layer));
[email protected]d600df7d2013-08-03 02:34:28112
jaydasika6b5a32bf2016-04-22 21:56:36113 layer_ptr->test_properties()->force_render_surface = true;
[email protected]d600df7d2013-08-03 02:34:28114 SetRootLayerOnMainThread(layer_ptr);
115
[email protected]a27cbde2013-03-23 22:01:49116 return layer_ptr;
117 }
118
danakj00f7925e2015-06-15 21:19:22119 LayerImpl* CreateLayer(LayerImpl* parent,
120 const gfx::Transform& transform,
121 const gfx::PointF& position,
122 const gfx::Size& bounds) {
123 LayerTreeImpl* tree = host_->host_impl()->active_tree();
124 int id = next_layer_impl_id_++;
danakj60bc3bc2016-04-09 00:24:48125 std::unique_ptr<LayerImpl> layer = LayerImpl::Create(tree, id);
danakj00f7925e2015-06-15 21:19:22126 LayerImpl* layer_ptr = layer.get();
[email protected]a27cbde2013-03-23 22:01:49127 SetProperties(layer_ptr, transform, position, bounds);
jaydasika89f7b5a2016-06-22 02:08:39128 parent->test_properties()->AddChild(std::move(layer));
[email protected]a27cbde2013-03-23 22:01:49129 return layer_ptr;
130 }
131
danakj00f7925e2015-06-15 21:19:22132 LayerImpl* CreateSurface(LayerImpl* parent,
133 const gfx::Transform& transform,
134 const gfx::PointF& position,
135 const gfx::Size& bounds) {
136 LayerImpl* layer = CreateLayer(parent, transform, position, bounds);
jaydasika6b5a32bf2016-04-22 21:56:36137 layer->test_properties()->force_render_surface = true;
[email protected]a27cbde2013-03-23 22:01:49138 return layer;
139 }
140
danakj00f7925e2015-06-15 21:19:22141 TestContentLayerImpl* CreateDrawingLayer(LayerImpl* parent,
142 const gfx::Transform& transform,
143 const gfx::PointF& position,
144 const gfx::Size& bounds,
145 bool opaque) {
146 LayerTreeImpl* tree = host_->host_impl()->active_tree();
147 int id = next_layer_impl_id_++;
danakj60bc3bc2016-04-09 00:24:48148 std::unique_ptr<TestContentLayerImpl> layer(
149 new TestContentLayerImpl(tree, id));
danakj00f7925e2015-06-15 21:19:22150 TestContentLayerImpl* layer_ptr = layer.get();
[email protected]a27cbde2013-03-23 22:01:49151 SetProperties(layer_ptr, transform, position, bounds);
152
153 if (opaque_layers_) {
154 layer_ptr->SetContentsOpaque(opaque);
155 } else {
156 layer_ptr->SetContentsOpaque(false);
157 if (opaque)
[email protected]2c7c6702013-03-26 03:14:05158 layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds));
[email protected]a27cbde2013-03-23 22:01:49159 else
160 layer_ptr->SetOpaqueContentsRect(gfx::Rect());
[email protected]586d51ed2012-12-07 20:31:45161 }
[email protected]94f206c12012-08-25 00:09:14162
jaydasika89f7b5a2016-06-22 02:08:39163 parent->test_properties()->AddChild(std::move(layer));
[email protected]a27cbde2013-03-23 22:01:49164 return layer_ptr;
165 }
[email protected]94f206c12012-08-25 00:09:14166
danakj00f7925e2015-06-15 21:19:22167 LayerImpl* CreateMaskLayer(LayerImpl* owning_layer, const gfx::Size& bounds) {
168 LayerTreeImpl* tree = host_->host_impl()->active_tree();
169 int id = next_layer_impl_id_++;
danakj60bc3bc2016-04-09 00:24:48170 std::unique_ptr<TestContentLayerImpl> layer(
171 new TestContentLayerImpl(tree, id));
danakj00f7925e2015-06-15 21:19:22172 TestContentLayerImpl* layer_ptr = layer.get();
[email protected]a27cbde2013-03-23 22:01:49173 SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds);
danakja04855a2015-11-18 20:39:10174 SetMask(owning_layer, std::move(layer));
[email protected]a27cbde2013-03-23 22:01:49175 return layer_ptr;
176 }
[email protected]586d51ed2012-12-07 20:31:45177
danakj00f7925e2015-06-15 21:19:22178 TestContentLayerImpl* CreateDrawingSurface(LayerImpl* parent,
179 const gfx::Transform& transform,
180 const gfx::PointF& position,
181 const gfx::Size& bounds,
182 bool opaque) {
183 TestContentLayerImpl* layer =
[email protected]a27cbde2013-03-23 22:01:49184 CreateDrawingLayer(parent, transform, position, bounds, opaque);
jaydasika6b5a32bf2016-04-22 21:56:36185 layer->test_properties()->force_render_surface = true;
[email protected]a27cbde2013-03-23 22:01:49186 return layer;
187 }
[email protected]94f206c12012-08-25 00:09:14188
[email protected]d5467eb72014-08-22 01:16:43189 void DestroyLayers() {
jaydasikabf1875a2016-06-28 03:39:59190 host_->host_impl()->active_tree()->SetRootLayerForTesting(nullptr);
[email protected]d5467eb72014-08-22 01:16:43191 render_surface_layer_list_impl_.clear();
[email protected]d5467eb72014-08-22 01:16:43192 mask_layers_.clear();
193 ResetLayerIterator();
194 }
[email protected]5b54b972013-07-26 13:25:42195
danakj60bc3bc2016-04-09 00:24:48196 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
[email protected]5b54b972013-07-26 13:25:42197
198 void AddCopyRequest(Layer* layer) {
danakj00f7925e2015-06-15 21:19:22199 layer->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
200 base::Bind(&OcclusionTrackerTest::CopyOutputCallback,
201 base::Unretained(this))));
[email protected]5b54b972013-07-26 13:25:42202 }
203
204 void AddCopyRequest(LayerImpl* layer) {
ajumae6f541b2016-05-31 16:50:50205 layer->test_properties()->copy_requests.push_back(
206 CopyOutputRequest::CreateBitmapRequest(
207 base::Bind(&OcclusionTrackerTest::CopyOutputCallback,
208 base::Unretained(this))));
[email protected]5b54b972013-07-26 13:25:42209 }
210
[email protected]a27cbde2013-03-23 22:01:49211 void CalcDrawEtc(TestContentLayerImpl* root) {
jaydasikabf1875a2016-06-28 03:39:59212 root->layer_tree_impl()->BuildLayerListForTesting();
213 DCHECK(root == root->layer_tree_impl()->root_layer_for_testing());
[email protected]94f206c12012-08-25 00:09:14214
enned8d1c5cb2015-06-16 19:09:35215 // These occlusion tests attach and detach layers in multiple
216 // iterations, so rebuild property trees every time.
217 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
218
danakj00f7925e2015-06-15 21:19:22219 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root);
enned8d1c5cb2015-06-16 19:09:35220
[email protected]7aad55f2013-07-26 11:25:53221 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:38222 root, root->bounds(), &render_surface_layer_list_impl_);
[email protected]7aad55f2013-07-26 11:25:53223 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:57224 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]94f206c12012-08-25 00:09:14225
[email protected]a27cbde2013-03-23 22:01:49226 layer_iterator_ = layer_iterator_begin_ =
enne389d1a12015-06-18 20:40:51227 LayerIterator::Begin(&render_surface_layer_list_impl_);
[email protected]a27cbde2013-03-23 22:01:49228 }
[email protected]94f206c12012-08-25 00:09:14229
danakj00f7925e2015-06-15 21:19:22230 void EnterLayer(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43231 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49232 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]e47b0a0a2013-11-18 23:26:22233 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49234 }
[email protected]94f206c12012-08-25 00:09:14235
danakj00f7925e2015-06-15 21:19:22236 void LeaveLayer(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43237 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49238 ASSERT_TRUE(layer_iterator_.represents_itself());
[email protected]d002dd02013-03-27 07:40:40239 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49240 ++layer_iterator_;
241 }
[email protected]94f206c12012-08-25 00:09:14242
danakj00f7925e2015-06-15 21:19:22243 void VisitLayer(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22244 EnterLayer(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49245 LeaveLayer(layer, occlusion);
246 }
[email protected]94f206c12012-08-25 00:09:14247
danakj00f7925e2015-06-15 21:19:22248 void EnterContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43249 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49250 ASSERT_TRUE(layer_iterator_.represents_target_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22251 occlusion->EnterLayer(layer_iterator_);
[email protected]d002dd02013-03-27 07:40:40252 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49253 ++layer_iterator_;
254 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]e47b0a0a2013-11-18 23:26:22255 occlusion->EnterLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49256 }
[email protected]94f206c12012-08-25 00:09:14257
danakj00f7925e2015-06-15 21:19:22258 void LeaveContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]d5467eb72014-08-22 01:16:43259 ASSERT_EQ(*layer_iterator_, layer);
[email protected]a27cbde2013-03-23 22:01:49260 ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
[email protected]d002dd02013-03-27 07:40:40261 occlusion->LeaveLayer(layer_iterator_);
[email protected]a27cbde2013-03-23 22:01:49262 ++layer_iterator_;
263 }
[email protected]94f206c12012-08-25 00:09:14264
danakj00f7925e2015-06-15 21:19:22265 void VisitContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) {
[email protected]e47b0a0a2013-11-18 23:26:22266 EnterContributingSurface(layer, occlusion);
[email protected]a27cbde2013-03-23 22:01:49267 LeaveContributingSurface(layer, occlusion);
268 }
[email protected]94f206c12012-08-25 00:09:14269
[email protected]a27cbde2013-03-23 22:01:49270 void ResetLayerIterator() { layer_iterator_ = layer_iterator_begin_; }
[email protected]94f206c12012-08-25 00:09:14271
[email protected]a27cbde2013-03-23 22:01:49272 const gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:14273
[email protected]a27cbde2013-03-23 22:01:49274 private:
[email protected]d600df7d2013-08-03 02:34:28275 void SetRootLayerOnMainThread(Layer* root) {
276 host_->SetRootLayer(scoped_refptr<Layer>(root));
277 }
278
279 void SetRootLayerOnMainThread(LayerImpl* root) {}
280
[email protected]a27cbde2013-03-23 22:01:49281 void SetProperties(LayerImpl* layer,
282 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:47283 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:26284 const gfx::Size& bounds) {
jaydasika10d43fc2016-08-18 04:06:04285 layer->test_properties()->transform = transform;
danakj3b8b2bf2015-06-18 03:09:01286 layer->SetPosition(position);
287 layer->SetBounds(bounds);
[email protected]a27cbde2013-03-23 22:01:49288 }
[email protected]94f206c12012-08-25 00:09:14289
danakj60bc3bc2016-04-09 00:24:48290 void SetMask(LayerImpl* owning_layer, std::unique_ptr<LayerImpl> layer) {
ajuma1d4026a32016-06-14 13:18:50291 owning_layer->test_properties()->SetMaskLayer(std::move(layer));
[email protected]a27cbde2013-03-23 22:01:49292 }
[email protected]94f206c12012-08-25 00:09:14293
[email protected]a27cbde2013-03-23 22:01:49294 bool opaque_layers_;
enne2097cab2014-09-25 20:16:31295 FakeLayerTreeHostClient client_;
danakjcf610582015-06-16 22:48:56296 TestTaskGraphRunner task_graph_runner_;
loyso2cb3f32f2016-11-08 07:08:34297 std::unique_ptr<AnimationHost> animation_host_;
danakj60bc3bc2016-04-09 00:24:48298 std::unique_ptr<FakeLayerTreeHost> host_;
[email protected]a27cbde2013-03-23 22:01:49299 // These hold ownership of the layers for the duration of the test.
[email protected]50761e92013-03-29 20:51:28300 LayerImplList render_surface_layer_list_impl_;
enne389d1a12015-06-18 20:40:51301 LayerIterator layer_iterator_begin_;
302 LayerIterator layer_iterator_;
[email protected]50761e92013-03-29 20:51:28303 LayerList mask_layers_;
danakj00f7925e2015-06-15 21:19:22304 int next_layer_impl_id_;
[email protected]94f206c12012-08-25 00:09:14305};
306
danakj00f7925e2015-06-15 21:19:22307#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
308 class ClassName##ImplThreadOpaqueLayers : public ClassName { \
309 public: /* NOLINT(whitespace/indent) */ \
310 ClassName##ImplThreadOpaqueLayers() : ClassName(true) {} \
311 }; \
[email protected]a27cbde2013-03-23 22:01:49312 TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); }
danakj00f7925e2015-06-15 21:19:22313#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
314 class ClassName##ImplThreadOpaquePaints : public ClassName { \
315 public: /* NOLINT(whitespace/indent) */ \
316 ClassName##ImplThreadOpaquePaints() : ClassName(false) {} \
317 }; \
[email protected]a27cbde2013-03-23 22:01:49318 TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); }
[email protected]94f206c12012-08-25 00:09:14319
[email protected]a27cbde2013-03-23 22:01:49320#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
[email protected]a27cbde2013-03-23 22:01:49321 RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
322 RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
[email protected]94f206c12012-08-25 00:09:14323
danakj00f7925e2015-06-15 21:19:22324class OcclusionTrackerTestIdentityTransforms : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49325 protected:
[email protected]ca2902e92013-03-28 01:45:35326 explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22327 : OcclusionTrackerTest(opaque_layers) {}
[email protected]ece1d952012-10-18 21:26:07328
dmichaelc78b0932014-12-17 23:39:47329 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22330 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49331 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22332 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49333 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22334 TestContentLayerImpl* layer = this->CreateDrawingLayer(
335 parent, this->identity_matrix, gfx::PointF(30.f, 30.f),
336 gfx::Size(500, 500), true);
[email protected]a27cbde2013-03-23 22:01:49337 parent->SetMasksToBounds(true);
338 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14339
danakj00f7925e2015-06-15 21:19:22340 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14341
[email protected]d002dd02013-03-27 07:40:40342 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22343 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14344
[email protected]a27cbde2013-03-23 22:01:49345 EXPECT_EQ(gfx::Rect().ToString(),
346 occlusion.occlusion_from_outside_target().ToString());
347 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
348 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49349 }
[email protected]94f206c12012-08-25 00:09:14350};
351
[email protected]96baf3e2012-10-22 23:09:55352ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
[email protected]94f206c12012-08-25 00:09:14353
danakj00f7925e2015-06-15 21:19:22354class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49355 protected:
[email protected]ca2902e92013-03-28 01:45:35356 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22357 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47358 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49359 gfx::Transform layer_transform;
360 layer_transform.Translate(250.0, 250.0);
361 layer_transform.Rotate(90.0);
362 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14363
danakj00f7925e2015-06-15 21:19:22364 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:24365 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22366 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49367 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22368 TestContentLayerImpl* layer = this->CreateDrawingLayer(
369 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
370 true);
[email protected]a27cbde2013-03-23 22:01:49371 parent->SetMasksToBounds(true);
372 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14373
danakj00f7925e2015-06-15 21:19:22374 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14375
[email protected]d002dd02013-03-27 07:40:40376 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22377 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14378
[email protected]a27cbde2013-03-23 22:01:49379 EXPECT_EQ(gfx::Rect().ToString(),
380 occlusion.occlusion_from_outside_target().ToString());
381 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
382 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49383 }
[email protected]94f206c12012-08-25 00:09:14384};
385
[email protected]96baf3e2012-10-22 23:09:55386ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
[email protected]94f206c12012-08-25 00:09:14387
danakj00f7925e2015-06-15 21:19:22388class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49389 protected:
[email protected]ca2902e92013-03-28 01:45:35390 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22391 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47392 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49393 gfx::Transform layer_transform;
394 layer_transform.Translate(20.0, 20.0);
[email protected]94f206c12012-08-25 00:09:14395
danakj00f7925e2015-06-15 21:19:22396 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49397 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22398 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49399 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22400 TestContentLayerImpl* layer = this->CreateDrawingLayer(
401 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
402 true);
[email protected]a27cbde2013-03-23 22:01:49403 parent->SetMasksToBounds(true);
404 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14405
danakj00f7925e2015-06-15 21:19:22406 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14407
[email protected]d002dd02013-03-27 07:40:40408 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22409 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14410
[email protected]a27cbde2013-03-23 22:01:49411 EXPECT_EQ(gfx::Rect().ToString(),
412 occlusion.occlusion_from_outside_target().ToString());
413 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
414 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49415 }
[email protected]94f206c12012-08-25 00:09:14416};
417
[email protected]96baf3e2012-10-22 23:09:55418ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
[email protected]94f206c12012-08-25 00:09:14419
danakj00f7925e2015-06-15 21:19:22420class OcclusionTrackerTestChildInRotatedChild : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49421 protected:
[email protected]ca2902e92013-03-28 01:45:35422 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22423 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47424 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49425 gfx::Transform child_transform;
426 child_transform.Translate(250.0, 250.0);
427 child_transform.Rotate(90.0);
428 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14429
danakj00f7925e2015-06-15 21:19:22430 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49431 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
432 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22433 LayerImpl* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49434 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
435 child->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22436 TestContentLayerImpl* layer = this->CreateDrawingLayer(
437 child, this->identity_matrix, gfx::PointF(10.f, 10.f),
438 gfx::Size(500, 500), true);
[email protected]a27cbde2013-03-23 22:01:49439 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14440
danakj00f7925e2015-06-15 21:19:22441 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14442
[email protected]d002dd02013-03-27 07:40:40443 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22444 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14445
[email protected]a27cbde2013-03-23 22:01:49446 EXPECT_EQ(gfx::Rect().ToString(),
447 occlusion.occlusion_from_outside_target().ToString());
448 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
449 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14450
[email protected]d002dd02013-03-27 07:40:40451 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22452 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14453
[email protected]a27cbde2013-03-23 22:01:49454 EXPECT_EQ(gfx::Rect().ToString(),
455 occlusion.occlusion_from_outside_target().ToString());
456 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
457 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14458
[email protected]a27cbde2013-03-23 22:01:49459 /* Justification for the above occlusion from |layer|:
460 100
461 +---------------------+
462 | |
463 | 30 | rotate(90)
464 | 30 + ---------------------------------+
465 100 | | 10 | | ==>
466 | |10+---------------------------------+
467 | | | | | |
468 | | | | | |
469 | | | | | |
470 +----|--|-------------+ | |
471 | | | |
472 | | | |
473 | | | |500
474 | | | |
475 | | | |
476 | | | |
477 | | | |
478 +--|-------------------------------+ |
479 | |
480 +---------------------------------+
481 500
482
483 +---------------------+
484 | |30 Visible region of |layer|: /////
485 | |
486 | +---------------------------------+
487 100| | |10 |
488 | +---------------------------------+ |
489 | | |///////////////| 420 | |
490 | | |///////////////|60 | |
491 | | |///////////////| | |
492 +--|--|---------------+ | |
493 20|10| 70 | |
494 | | | |
495 | | | |
496 | | | |
497 | | | |
498 | | | |
499 | | |10|
500 | +------------------------------|--+
501 | 490 |
502 +---------------------------------+
503 500
504
505 */
506 }
[email protected]94f206c12012-08-25 00:09:14507};
508
[email protected]96baf3e2012-10-22 23:09:55509ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
[email protected]94f206c12012-08-25 00:09:14510
danakj00f7925e2015-06-15 21:19:22511class OcclusionTrackerTestScaledRenderSurface : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49512 protected:
[email protected]ca2902e92013-03-28 01:45:35513 explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22514 : OcclusionTrackerTest(opaque_layers) {}
[email protected]710ffc02012-10-30 21:42:02515
dmichaelc78b0932014-12-17 23:39:47516 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22517 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49518 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
[email protected]710ffc02012-10-30 21:42:02519
[email protected]a27cbde2013-03-23 22:01:49520 gfx::Transform layer1_matrix;
521 layer1_matrix.Scale(2.0, 2.0);
danakj00f7925e2015-06-15 21:19:22522 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49523 parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true);
jaydasika6b5a32bf2016-04-22 21:56:36524 layer1->test_properties()->force_render_surface = true;
[email protected]710ffc02012-10-30 21:42:02525
[email protected]a27cbde2013-03-23 22:01:49526 gfx::Transform layer2_matrix;
527 layer2_matrix.Translate(25.0, 25.0);
danakj00f7925e2015-06-15 21:19:22528 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49529 layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true);
danakj00f7925e2015-06-15 21:19:22530 TestContentLayerImpl* occluder = this->CreateDrawingLayer(
531 parent, this->identity_matrix, gfx::PointF(100.f, 100.f),
532 gfx::Size(500, 500), true);
[email protected]a27cbde2013-03-23 22:01:49533 this->CalcDrawEtc(parent);
[email protected]710ffc02012-10-30 21:42:02534
danakj00f7925e2015-06-15 21:19:22535 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]710ffc02012-10-30 21:42:02536
[email protected]d002dd02013-03-27 07:40:40537 this->VisitLayer(occluder, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22538 this->EnterLayer(layer2, &occlusion);
[email protected]710ffc02012-10-30 21:42:02539
[email protected]a27cbde2013-03-23 22:01:49540 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
541 occlusion.occlusion_from_outside_target().ToString());
542 EXPECT_EQ(gfx::Rect().ToString(),
543 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49544 }
[email protected]710ffc02012-10-30 21:42:02545};
546
547ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
548
danakj00f7925e2015-06-15 21:19:22549class OcclusionTrackerTestVisitTargetTwoTimes : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49550 protected:
[email protected]ca2902e92013-03-28 01:45:35551 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22552 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47553 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22554 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49555 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:22556 LayerImpl* surface = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43557 root, this->identity_matrix, gfx::PointF(30.f, 30.f), gfx::Size());
danakj00f7925e2015-06-15 21:19:22558 TestContentLayerImpl* surface_child = this->CreateDrawingLayer(
559 surface, this->identity_matrix, gfx::PointF(10.f, 10.f),
560 gfx::Size(50, 50), true);
[email protected]d5467eb72014-08-22 01:16:43561 // |top_layer| makes |root|'s surface get considered by OcclusionTracker
562 // first, instead of |surface|'s. This exercises different code in
563 // LeaveToRenderTarget, as the target surface has already been seen when
564 // leaving |surface| later.
danakj00f7925e2015-06-15 21:19:22565 TestContentLayerImpl* top_layer = this->CreateDrawingLayer(
566 root, this->identity_matrix, gfx::PointF(40.f, 90.f), gfx::Size(50, 20),
567 true);
[email protected]a27cbde2013-03-23 22:01:49568 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14569
danakj00f7925e2015-06-15 21:19:22570 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14571
[email protected]d5467eb72014-08-22 01:16:43572 this->VisitLayer(top_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14573
[email protected]a27cbde2013-03-23 22:01:49574 EXPECT_EQ(gfx::Rect().ToString(),
575 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43576 EXPECT_EQ(gfx::Rect(40, 90, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49577 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14578
[email protected]d5467eb72014-08-22 01:16:43579 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14580
[email protected]d5467eb72014-08-22 01:16:43581 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49582 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43583 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49584 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14585
[email protected]d5467eb72014-08-22 01:16:43586 this->EnterContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:14587
[email protected]d5467eb72014-08-22 01:16:43588 EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(),
[email protected]a27cbde2013-03-23 22:01:49589 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43590 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49591 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14592
[email protected]d5467eb72014-08-22 01:16:43593 // Occlusion from |top_layer| already in the root target should get merged
594 // with the occlusion from the |surface| we are leaving now.
595 this->LeaveContributingSurface(surface, &occlusion);
596 this->EnterLayer(root, &occlusion);
[email protected]94f206c12012-08-25 00:09:14597
[email protected]d5467eb72014-08-22 01:16:43598 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
599 EXPECT_EQ(gfx::Rect(40, 40, 50, 70).ToString(),
[email protected]a27cbde2013-03-23 22:01:49600 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49601 }
[email protected]94f206c12012-08-25 00:09:14602};
603
[email protected]96baf3e2012-10-22 23:09:55604ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
[email protected]94f206c12012-08-25 00:09:14605
danakj00f7925e2015-06-15 21:19:22606class OcclusionTrackerTestSurfaceRotatedOffAxis : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49607 protected:
[email protected]ca2902e92013-03-28 01:45:35608 explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22609 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47610 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49611 gfx::Transform child_transform;
612 child_transform.Translate(250.0, 250.0);
613 child_transform.Rotate(95.0);
614 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14615
[email protected]a27cbde2013-03-23 22:01:49616 gfx::Transform layer_transform;
617 layer_transform.Translate(10.0, 10.0);
[email protected]94f206c12012-08-25 00:09:14618
danakj00f7925e2015-06-15 21:19:22619 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49620 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
danakj00f7925e2015-06-15 21:19:22621 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49622 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:22623 LayerImpl* child = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49624 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
danakj00f7925e2015-06-15 21:19:22625 TestContentLayerImpl* layer = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49626 child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true);
627 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14628
danakj00f7925e2015-06-15 21:19:22629 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14630
[email protected]8a822692014-02-12 17:30:55631 gfx::Rect clipped_layer_in_child = MathUtil::MapEnclosingClippedRect(
danakj64767d902015-06-19 00:10:43632 layer_transform, layer->visible_layer_rect());
[email protected]94f206c12012-08-25 00:09:14633
[email protected]d002dd02013-03-27 07:40:40634 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22635 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14636
[email protected]a27cbde2013-03-23 22:01:49637 EXPECT_EQ(gfx::Rect().ToString(),
638 occlusion.occlusion_from_outside_target().ToString());
639 EXPECT_EQ(clipped_layer_in_child.ToString(),
640 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14641
[email protected]d002dd02013-03-27 07:40:40642 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22643 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14644
[email protected]a27cbde2013-03-23 22:01:49645 EXPECT_EQ(gfx::Rect().ToString(),
646 occlusion.occlusion_from_outside_target().ToString());
647 EXPECT_EQ(gfx::Rect().ToString(),
648 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49649 }
[email protected]94f206c12012-08-25 00:09:14650};
651
[email protected]96baf3e2012-10-22 23:09:55652ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
[email protected]94f206c12012-08-25 00:09:14653
[email protected]ca2902e92013-03-28 01:45:35654class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
danakj00f7925e2015-06-15 21:19:22655 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49656 protected:
[email protected]ca2902e92013-03-28 01:45:35657 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22658 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47659 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49660 gfx::Transform child_transform;
661 child_transform.Translate(250.0, 250.0);
662 child_transform.Rotate(90.0);
663 child_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14664
danakj00f7925e2015-06-15 21:19:22665 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49666 this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
danakj00f7925e2015-06-15 21:19:22667 TestContentLayerImpl* parent = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:49668 root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
669 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22670 TestContentLayerImpl* child = this->CreateDrawingSurface(
671 parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
672 false);
[email protected]a27cbde2013-03-23 22:01:49673 child->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22674 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
675 child, this->identity_matrix, gfx::PointF(10.f, 10.f),
676 gfx::Size(500, 500), true);
677 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
678 child, this->identity_matrix, gfx::PointF(10.f, 450.f),
679 gfx::Size(500, 60), true);
[email protected]a27cbde2013-03-23 22:01:49680 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:14681
danakj00f7925e2015-06-15 21:19:22682 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14683
[email protected]d002dd02013-03-27 07:40:40684 this->VisitLayer(layer2, &occlusion);
685 this->VisitLayer(layer1, &occlusion);
686 this->VisitLayer(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22687 this->EnterContributingSurface(child, &occlusion);
[email protected]94f206c12012-08-25 00:09:14688
[email protected]a27cbde2013-03-23 22:01:49689 EXPECT_EQ(gfx::Rect().ToString(),
690 occlusion.occlusion_from_outside_target().ToString());
691 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
692 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14693
[email protected]d002dd02013-03-27 07:40:40694 this->LeaveContributingSurface(child, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22695 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14696
[email protected]a27cbde2013-03-23 22:01:49697 EXPECT_EQ(gfx::Rect().ToString(),
698 occlusion.occlusion_from_outside_target().ToString());
699 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
700 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14701
[email protected]a27cbde2013-03-23 22:01:49702 /* Justification for the above occlusion from |layer1| and |layer2|:
[email protected]94f206c12012-08-25 00:09:14703
704 +---------------------+
705 | |30 Visible region of |layer1|: /////
706 | | Visible region of |layer2|: \\\\\
707 | +---------------------------------+
708 | | |10 |
709 | +---------------+-----------------+ |
710 | | |\\\\\\\\\\\\|//| 420 | |
711 | | |\\\\\\\\\\\\|//|60 | |
712 | | |\\\\\\\\\\\\|//| | |
713 +--|--|------------|--+ | |
714 20|10| 70 | | |
715 | | | | |
716 | | | | |
717 | | | | |
718 | | | | |
719 | | | | |
720 | | | |10|
721 | +------------|-----------------|--+
722 | | 490 |
723 +---------------+-----------------+
724 60 440
725 */
[email protected]a27cbde2013-03-23 22:01:49726 }
[email protected]94f206c12012-08-25 00:09:14727};
728
[email protected]96baf3e2012-10-22 23:09:55729ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
[email protected]94f206c12012-08-25 00:09:14730
[email protected]ca2902e92013-03-28 01:45:35731class OcclusionTrackerTestOverlappingSurfaceSiblings
danakj00f7925e2015-06-15 21:19:22732 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49733 protected:
[email protected]ca2902e92013-03-28 01:45:35734 explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22735 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47736 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22737 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49738 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
739 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22740 LayerImpl* child1 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43741 parent, this->identity_matrix, gfx::PointF(10.f, 0.f), gfx::Size());
danakj00f7925e2015-06-15 21:19:22742 LayerImpl* child2 = this->CreateSurface(
[email protected]d5467eb72014-08-22 01:16:43743 parent, this->identity_matrix, gfx::PointF(30.f, 0.f), gfx::Size());
danakj00f7925e2015-06-15 21:19:22744 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
[email protected]d5467eb72014-08-22 01:16:43745 child1, this->identity_matrix, gfx::PointF(), gfx::Size(40, 50), true);
danakj00f7925e2015-06-15 21:19:22746 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
747 child2, this->identity_matrix, gfx::PointF(10.f, 0.f),
748 gfx::Size(40, 50), true);
[email protected]a27cbde2013-03-23 22:01:49749 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14750
danakj00f7925e2015-06-15 21:19:22751 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14752
[email protected]d002dd02013-03-27 07:40:40753 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22754 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:14755
[email protected]d5467eb72014-08-22 01:16:43756 // layer2's occlusion.
[email protected]a27cbde2013-03-23 22:01:49757 EXPECT_EQ(gfx::Rect().ToString(),
758 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43759 EXPECT_EQ(gfx::Rect(10, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49760 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14761
[email protected]d002dd02013-03-27 07:40:40762 this->LeaveContributingSurface(child2, &occlusion);
763 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22764 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:14765
[email protected]d5467eb72014-08-22 01:16:43766 // layer2's occlusion in the target space of layer1.
767 EXPECT_EQ(gfx::Rect(30, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49768 occlusion.occlusion_from_outside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:43769 // layer1's occlusion.
770 EXPECT_EQ(gfx::Rect(0, 0, 40, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49771 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14772
[email protected]d002dd02013-03-27 07:40:40773 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22774 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14775
[email protected]d5467eb72014-08-22 01:16:43776 // The occlusion from from layer1 and layer2 is merged.
777 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
778 EXPECT_EQ(gfx::Rect(10, 0, 70, 50).ToString(),
[email protected]a27cbde2013-03-23 22:01:49779 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:49780 }
[email protected]94f206c12012-08-25 00:09:14781};
782
[email protected]96baf3e2012-10-22 23:09:55783ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
[email protected]94f206c12012-08-25 00:09:14784
[email protected]ca2902e92013-03-28 01:45:35785class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms
danakj00f7925e2015-06-15 21:19:22786 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49787 protected:
[email protected]ca2902e92013-03-28 01:45:35788 explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(
[email protected]a27cbde2013-03-23 22:01:49789 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22790 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47791 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49792 gfx::Transform child1_transform;
793 child1_transform.Translate(250.0, 250.0);
794 child1_transform.Rotate(-90.0);
795 child1_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14796
[email protected]a27cbde2013-03-23 22:01:49797 gfx::Transform child2_transform;
798 child2_transform.Translate(250.0, 250.0);
799 child2_transform.Rotate(90.0);
800 child2_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14801
danakj00f7925e2015-06-15 21:19:22802 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49803 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
804 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22805 LayerImpl* child1 = this->CreateSurface(
[email protected]a27cbde2013-03-23 22:01:49806 parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10));
danakj00f7925e2015-06-15 21:19:22807 LayerImpl* child2 = this->CreateDrawingSurface(parent, child2_transform,
808 gfx::PointF(20.f, 40.f),
809 gfx::Size(10, 10), false);
810 TestContentLayerImpl* layer1 = this->CreateDrawingLayer(
811 child1, this->identity_matrix, gfx::PointF(-10.f, -20.f),
812 gfx::Size(510, 510), true);
813 TestContentLayerImpl* layer2 = this->CreateDrawingLayer(
814 child2, this->identity_matrix, gfx::PointF(-10.f, -10.f),
815 gfx::Size(510, 510), true);
[email protected]a27cbde2013-03-23 22:01:49816 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14817
danakj00f7925e2015-06-15 21:19:22818 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14819
[email protected]d002dd02013-03-27 07:40:40820 this->VisitLayer(layer2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22821 this->EnterLayer(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:14822
[email protected]a27cbde2013-03-23 22:01:49823 EXPECT_EQ(gfx::Rect().ToString(),
824 occlusion.occlusion_from_outside_target().ToString());
825 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
826 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14827
[email protected]d002dd02013-03-27 07:40:40828 this->LeaveLayer(child2, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22829 this->EnterContributingSurface(child2, &occlusion);
[email protected]94f206c12012-08-25 00:09:14830
danakjf080b5b2014-08-23 22:18:20831 EXPECT_EQ(gfx::Rect().ToString(),
832 occlusion.occlusion_from_outside_target().ToString());
833 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
834 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14835
[email protected]d002dd02013-03-27 07:40:40836 this->LeaveContributingSurface(child2, &occlusion);
837 this->VisitLayer(layer1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22838 this->EnterContributingSurface(child1, &occlusion);
[email protected]94f206c12012-08-25 00:09:14839
[email protected]a27cbde2013-03-23 22:01:49840 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
841 occlusion.occlusion_from_outside_target().ToString());
842 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
843 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14844
[email protected]d002dd02013-03-27 07:40:40845 this->LeaveContributingSurface(child1, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22846 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14847
[email protected]a27cbde2013-03-23 22:01:49848 EXPECT_EQ(gfx::Rect().ToString(),
849 occlusion.occlusion_from_outside_target().ToString());
850 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(),
851 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14852
[email protected]a27cbde2013-03-23 22:01:49853 /* Justification for the above occlusion:
854 100
855 +---------------------+
856 |20 | layer1
857 10+----------------------------------+
858 100 || 30 | layer2 |
859 |20+----------------------------------+
860 || | | | |
861 || | | | |
862 || | | | |
863 +|-|------------------+ | |
864 | | | | 510
865 | | 510 | |
866 | | | |
867 | | | |
868 | | | |
869 | | | |
870 | | 520 | |
871 +----------------------------------+ |
872 | |
873 +----------------------------------+
874 510
875 */
876 }
[email protected]94f206c12012-08-25 00:09:14877};
878
[email protected]a27cbde2013-03-23 22:01:49879ALL_OCCLUSIONTRACKER_TEST(
880 OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
[email protected]94f206c12012-08-25 00:09:14881
danakj00f7925e2015-06-15 21:19:22882class OcclusionTrackerTestFilters : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49883 protected:
[email protected]ca2902e92013-03-28 01:45:35884 explicit OcclusionTrackerTestFilters(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22885 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47886 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:49887 gfx::Transform layer_transform;
888 layer_transform.Translate(250.0, 250.0);
889 layer_transform.Rotate(90.0);
890 layer_transform.Translate(-250.0, -250.0);
[email protected]94f206c12012-08-25 00:09:14891
danakj00f7925e2015-06-15 21:19:22892 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49893 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
894 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:22895 TestContentLayerImpl* blur_layer = this->CreateDrawingLayer(
896 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
897 true);
898 TestContentLayerImpl* opaque_layer = this->CreateDrawingLayer(
899 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
900 true);
901 TestContentLayerImpl* opacity_layer = this->CreateDrawingLayer(
902 parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500),
903 true);
[email protected]94f206c12012-08-25 00:09:14904
jaydasika6b5a32bf2016-04-22 21:56:36905 blur_layer->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:29906 FilterOperations filters;
907 filters.Append(FilterOperation::CreateBlurFilter(10.f));
ajumacb2b74432016-07-21 19:11:15908 blur_layer->test_properties()->filters = filters;
[email protected]94f206c12012-08-25 00:09:14909
jaydasika6b5a32bf2016-04-22 21:56:36910 opaque_layer->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:29911 filters.Clear();
912 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f));
ajumacb2b74432016-07-21 19:11:15913 opaque_layer->test_properties()->filters = filters;
[email protected]94f206c12012-08-25 00:09:14914
jaydasika6b5a32bf2016-04-22 21:56:36915 opacity_layer->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:29916 filters.Clear();
917 filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
ajumacb2b74432016-07-21 19:11:15918 opacity_layer->test_properties()->filters = filters;
[email protected]94f206c12012-08-25 00:09:14919
[email protected]a27cbde2013-03-23 22:01:49920 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14921
danakj00f7925e2015-06-15 21:19:22922 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:14923
[email protected]a27cbde2013-03-23 22:01:49924 // Opacity layer won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:40925 this->VisitLayer(opacity_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22926 this->EnterContributingSurface(opacity_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14927
[email protected]a27cbde2013-03-23 22:01:49928 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
929 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14930
[email protected]a27cbde2013-03-23 22:01:49931 // And has nothing to contribute to its parent surface.
[email protected]d002dd02013-03-27 07:40:40932 this->LeaveContributingSurface(opacity_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49933 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
934 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14935
[email protected]a27cbde2013-03-23 22:01:49936 // Opaque layer will contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:40937 this->VisitLayer(opaque_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22938 this->EnterContributingSurface(opaque_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14939
[email protected]a27cbde2013-03-23 22:01:49940 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
941 EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(),
942 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14943
[email protected]a27cbde2013-03-23 22:01:49944 // And it gets translated to the parent surface.
[email protected]d002dd02013-03-27 07:40:40945 this->LeaveContributingSurface(opaque_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49946 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
947 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
948 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:14949
[email protected]a27cbde2013-03-23 22:01:49950 // The blur layer needs to throw away any occlusion from outside its
951 // subtree.
[email protected]e47b0a0a2013-11-18 23:26:22952 this->EnterLayer(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49953 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
954 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14955
[email protected]a27cbde2013-03-23 22:01:49956 // And it won't contribute to occlusion.
[email protected]d002dd02013-03-27 07:40:40957 this->LeaveLayer(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22958 this->EnterContributingSurface(blur_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49959 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
960 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14961
[email protected]a27cbde2013-03-23 22:01:49962 // But the opaque layer's occlusion is preserved on the parent.
[email protected]d002dd02013-03-27 07:40:40963 this->LeaveContributingSurface(blur_layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22964 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:49965 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
966 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
967 occlusion.occlusion_from_inside_target().ToString());
968 }
[email protected]94f206c12012-08-25 00:09:14969};
970
[email protected]96baf3e2012-10-22 23:09:55971ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
[email protected]94f206c12012-08-25 00:09:14972
[email protected]ca2902e92013-03-28 01:45:35973class OcclusionTrackerTestOpaqueContentsRegionEmpty
danakj00f7925e2015-06-15 21:19:22974 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:49975 protected:
[email protected]ca2902e92013-03-28 01:45:35976 explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:22977 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:47978 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:22979 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:49980 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
danakj00f7925e2015-06-15 21:19:22981 TestContentLayerImpl* layer =
982 this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(),
983 gfx::Size(200, 200), false);
[email protected]a27cbde2013-03-23 22:01:49984 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:14985
danakj00f7925e2015-06-15 21:19:22986 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]e47b0a0a2013-11-18 23:26:22987 this->EnterLayer(layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:14988
[email protected]d5467eb72014-08-22 01:16:43989 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
990 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:14991
[email protected]d002dd02013-03-27 07:40:40992 this->LeaveLayer(layer, &occlusion);
993 this->VisitContributingSurface(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:22994 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:14995
[email protected]a27cbde2013-03-23 22:01:49996 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]d5467eb72014-08-22 01:16:43997 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:49998 }
[email protected]94f206c12012-08-25 00:09:14999};
1000
danakj00f7925e2015-06-15 21:19:221001ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
[email protected]94f206c12012-08-25 00:09:141002
[email protected]ca2902e92013-03-28 01:45:351003class OcclusionTrackerTestOpaqueContentsRegionNonEmpty
danakj00f7925e2015-06-15 21:19:221004 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491005 protected:
[email protected]ca2902e92013-03-28 01:45:351006 explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221007 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471008 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221009 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491010 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
danakj00f7925e2015-06-15 21:19:221011 TestContentLayerImpl* layer = this->CreateDrawingLayer(
1012 parent, this->identity_matrix, gfx::PointF(100.f, 100.f),
1013 gfx::Size(200, 200), false);
[email protected]a27cbde2013-03-23 22:01:491014 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141015 {
danakj00f7925e2015-06-15 21:19:221016 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491017 layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
[email protected]94f206c12012-08-25 00:09:141018
[email protected]a27cbde2013-03-23 22:01:491019 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401020 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221021 this->EnterLayer(parent, &occlusion);
[email protected]94f206c12012-08-25 00:09:141022
[email protected]a27cbde2013-03-23 22:01:491023 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
1024 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141025 }
[email protected]a27cbde2013-03-23 22:01:491026 {
danakj00f7925e2015-06-15 21:19:221027 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491028 layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
1029
1030 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401031 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221032 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491033
1034 EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(),
1035 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491036 }
1037 {
danakj00f7925e2015-06-15 21:19:221038 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491039 layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
1040
1041 this->ResetLayerIterator();
[email protected]d002dd02013-03-27 07:40:401042 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221043 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491044
1045 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
1046 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491047 }
1048 }
[email protected]94f206c12012-08-25 00:09:141049};
1050
danakj00f7925e2015-06-15 21:19:221051ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
[email protected]94f206c12012-08-25 00:09:141052
[email protected]ca2902e92013-03-28 01:45:351053class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude
danakj00f7925e2015-06-15 21:19:221054 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491055 protected:
[email protected]ca2902e92013-03-28 01:45:351056 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(
1057 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221058 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471059 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491060 gfx::Transform transform;
1061 transform.Translate(50.0, 50.0);
1062 transform.ApplyPerspectiveDepth(100.0);
1063 transform.Translate3d(0.0, 0.0, 110.0);
1064 transform.Translate(-50.0, -50.0);
[email protected]94f206c12012-08-25 00:09:141065
danakj00f7925e2015-06-15 21:19:221066 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491067 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
danakj00f7925e2015-06-15 21:19:221068 TestContentLayerImpl* layer = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491069 parent, transform, gfx::PointF(), gfx::Size(100, 100), true);
jaydasikaca2605e2016-04-23 02:52:521070 parent->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:201071 parent->test_properties()->sorting_context_id = 1;
jaydasikaca2605e2016-04-23 02:52:521072 layer->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:201073 layer->test_properties()->sorting_context_id = 1;
[email protected]a27cbde2013-03-23 22:01:491074 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141075
danakj00f7925e2015-06-15 21:19:221076 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141077
[email protected]a27cbde2013-03-23 22:01:491078 // The |layer| is entirely behind the camera and should not occlude.
[email protected]d002dd02013-03-27 07:40:401079 this->VisitLayer(layer, &occlusion);
[email protected]e47b0a0a2013-11-18 23:26:221080 this->EnterLayer(parent, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491081 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1082 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1083 }
[email protected]94f206c12012-08-25 00:09:141084};
1085
[email protected]ca2902e92013-03-28 01:45:351086class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent
danakj00f7925e2015-06-15 21:19:221087 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491088 protected:
[email protected]ca2902e92013-03-28 01:45:351089 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent(
1090 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221091 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471092 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491093 gfx::Transform surface_transform;
1094 surface_transform.Translate(300.0, 300.0);
1095 surface_transform.Scale(2.0, 2.0);
1096 surface_transform.Translate(-150.0, -150.0);
[email protected]94f206c12012-08-25 00:09:141097
danakj00f7925e2015-06-15 21:19:221098 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491099 this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
danakj00f7925e2015-06-15 21:19:221100 TestContentLayerImpl* surface = this->CreateDrawingSurface(
[email protected]a27cbde2013-03-23 22:01:491101 parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false);
danakj00f7925e2015-06-15 21:19:221102 TestContentLayerImpl* surface2 = this->CreateDrawingSurface(
1103 parent, this->identity_matrix, gfx::PointF(50.f, 50.f),
1104 gfx::Size(300, 300), false);
[email protected]a27cbde2013-03-23 22:01:491105 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1106 surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200));
1107 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141108
danakj00f7925e2015-06-15 21:19:221109 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141110
[email protected]d002dd02013-03-27 07:40:401111 this->VisitLayer(surface2, &occlusion);
1112 this->VisitContributingSurface(surface2, &occlusion);
[email protected]94f206c12012-08-25 00:09:141113
[email protected]a27cbde2013-03-23 22:01:491114 EXPECT_EQ(gfx::Rect().ToString(),
1115 occlusion.occlusion_from_outside_target().ToString());
1116 EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(),
1117 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141118
[email protected]a27cbde2013-03-23 22:01:491119 // Clear any stored occlusion.
[email protected]d5467eb72014-08-22 01:16:431120 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
1121 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
[email protected]94f206c12012-08-25 00:09:141122
[email protected]d002dd02013-03-27 07:40:401123 this->VisitLayer(surface, &occlusion);
1124 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141125
[email protected]a27cbde2013-03-23 22:01:491126 EXPECT_EQ(gfx::Rect().ToString(),
1127 occlusion.occlusion_from_outside_target().ToString());
1128 EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(),
1129 occlusion.occlusion_from_inside_target().ToString());
1130 }
[email protected]94f206c12012-08-25 00:09:141131};
1132
danakj00f7925e2015-06-15 21:19:221133ALL_OCCLUSIONTRACKER_TEST(
[email protected]a27cbde2013-03-23 22:01:491134 OcclusionTrackerTestSurfaceOcclusionTranslatesToParent);
[email protected]94f206c12012-08-25 00:09:141135
[email protected]ca2902e92013-03-28 01:45:351136class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping
danakj00f7925e2015-06-15 21:19:221137 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491138 protected:
[email protected]ca2902e92013-03-28 01:45:351139 explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping(
1140 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221141 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471142 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221143 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491144 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1145 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221146 TestContentLayerImpl* surface =
1147 this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(),
1148 gfx::Size(500, 300), false);
[email protected]a27cbde2013-03-23 22:01:491149 surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200));
1150 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141151
danakj00f7925e2015-06-15 21:19:221152 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141153
[email protected]d002dd02013-03-27 07:40:401154 this->VisitLayer(surface, &occlusion);
1155 this->VisitContributingSurface(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141156
[email protected]a27cbde2013-03-23 22:01:491157 EXPECT_EQ(gfx::Rect().ToString(),
1158 occlusion.occlusion_from_outside_target().ToString());
1159 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(),
1160 occlusion.occlusion_from_inside_target().ToString());
1161 }
[email protected]94f206c12012-08-25 00:09:141162};
1163
danakj00f7925e2015-06-15 21:19:221164ALL_OCCLUSIONTRACKER_TEST(
[email protected]a27cbde2013-03-23 22:01:491165 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
[email protected]94f206c12012-08-25 00:09:141166
danakj00f7925e2015-06-15 21:19:221167class OcclusionTrackerTestSurfaceChildOfSurface : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491168 protected:
[email protected]ca2902e92013-03-28 01:45:351169 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221170 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471171 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491172 // This test verifies that the surface cliprect does not end up empty and
1173 // clip away the entire unoccluded rect.
[email protected]94f206c12012-08-25 00:09:141174
danakj00f7925e2015-06-15 21:19:221175 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491176 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
danakj00f7925e2015-06-15 21:19:221177 LayerImpl* surface =
1178 this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(),
1179 gfx::Size(100, 100), false);
1180 LayerImpl* surface_child = this->CreateDrawingSurface(
1181 surface, this->identity_matrix, gfx::PointF(0.f, 10.f),
1182 gfx::Size(100, 50), true);
1183 LayerImpl* topmost = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491184 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
1185 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141186
danakj00f7925e2015-06-15 21:19:221187 TestOcclusionTrackerWithClip occlusion(gfx::Rect(-100, -100, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141188
[email protected]a27cbde2013-03-23 22:01:491189 // |topmost| occludes everything partially so we know occlusion is happening
1190 // at all.
[email protected]d002dd02013-03-27 07:40:401191 this->VisitLayer(topmost, &occlusion);
[email protected]94f206c12012-08-25 00:09:141192
[email protected]a27cbde2013-03-23 22:01:491193 EXPECT_EQ(gfx::Rect().ToString(),
1194 occlusion.occlusion_from_outside_target().ToString());
1195 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1196 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141197
[email protected]d002dd02013-03-27 07:40:401198 this->VisitLayer(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141199
[email protected]a27cbde2013-03-23 22:01:491200 // surface_child increases the occlusion in the screen by a narrow sliver.
1201 EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(),
1202 occlusion.occlusion_from_outside_target().ToString());
1203 // In its own surface, surface_child is at 0,0 as is its occlusion.
1204 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1205 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141206
[email protected]a27cbde2013-03-23 22:01:491207 // The root layer always has a clip rect. So the parent of |surface| has a
1208 // clip rect. However, the owning layer for |surface| does not mask to
1209 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
1210 // |surface_child| exercises different code paths as its parent does not
1211 // have a clip rect.
[email protected]94f206c12012-08-25 00:09:141212
[email protected]e47b0a0a2013-11-18 23:26:221213 this->EnterContributingSurface(surface_child, &occlusion);
danakjf080b5b2014-08-23 22:18:201214 // The |surface_child| can't occlude its own surface, but occlusion from
1215 // |topmost| can.
1216 EXPECT_EQ(gfx::Rect().ToString(),
1217 occlusion.occlusion_on_contributing_surface_from_outside_target()
1218 .ToString());
1219 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1220 occlusion.occlusion_on_contributing_surface_from_inside_target()
1221 .ToString());
[email protected]d002dd02013-03-27 07:40:401222 this->LeaveContributingSurface(surface_child, &occlusion);
[email protected]94f206c12012-08-25 00:09:141223
[email protected]a27cbde2013-03-23 22:01:491224 // When the surface_child's occlusion is transformed up to its parent, make
danakjf080b5b2014-08-23 22:18:201225 // sure it is not clipped away inappropriately.
[email protected]e47b0a0a2013-11-18 23:26:221226 this->EnterLayer(surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491227 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1228 occlusion.occlusion_from_outside_target().ToString());
1229 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(),
1230 occlusion.occlusion_from_inside_target().ToString());
[email protected]d002dd02013-03-27 07:40:401231 this->LeaveLayer(surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141232
[email protected]e47b0a0a2013-11-18 23:26:221233 this->EnterContributingSurface(surface, &occlusion);
danakjf080b5b2014-08-23 22:18:201234 // The occlusion from inside |surface| can't affect the surface, but
1235 // |topmost| can.
1236 EXPECT_EQ(gfx::Rect().ToString(),
1237 occlusion.occlusion_on_contributing_surface_from_outside_target()
1238 .ToString());
1239 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
1240 occlusion.occlusion_on_contributing_surface_from_inside_target()
1241 .ToString());
1242
1243 this->LeaveContributingSurface(surface, &occlusion);
1244 this->EnterLayer(parent, &occlusion);
1245 // The occlusion in |surface| and without are merged into the parent.
1246 EXPECT_EQ(gfx::Rect().ToString(),
1247 occlusion.occlusion_from_outside_target().ToString());
1248 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(),
1249 occlusion.occlusion_from_inside_target().ToString());
[email protected]a27cbde2013-03-23 22:01:491250 }
[email protected]94f206c12012-08-25 00:09:141251};
1252
[email protected]96baf3e2012-10-22 23:09:551253ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
[email protected]94f206c12012-08-25 00:09:141254
[email protected]ca2902e92013-03-28 01:45:351255class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter
danakj00f7925e2015-06-15 21:19:221256 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491257 protected:
[email protected]ca2902e92013-03-28 01:45:351258 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:491259 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221260 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471261 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491262 gfx::Transform scale_by_half;
1263 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141264
[email protected]ae6b1a72013-06-25 18:49:291265 FilterOperations filters;
1266 filters.Append(FilterOperation::CreateBlurFilter(10.f));
[email protected]94f206c12012-08-25 00:09:141267
[email protected]d5467eb72014-08-22 01:16:431268 enum Direction {
1269 LEFT,
1270 RIGHT,
1271 TOP,
1272 BOTTOM,
1273 LAST_DIRECTION = BOTTOM,
1274 };
[email protected]94f206c12012-08-25 00:09:141275
[email protected]d5467eb72014-08-22 01:16:431276 for (int i = 0; i <= LAST_DIRECTION; ++i) {
1277 SCOPED_TRACE(i);
[email protected]94f206c12012-08-25 00:09:141278
[email protected]d5467eb72014-08-22 01:16:431279 // Make a 50x50 filtered surface that is adjacent to occluding layers
1280 // which are above it in the z-order in various configurations. The
1281 // surface is scaled to test that the pixel moving is done in the target
1282 // space, where the background filter is applied.
danakj00f7925e2015-06-15 21:19:221283 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]d5467eb72014-08-22 01:16:431284 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:221285 LayerImpl* filtered_surface = this->CreateDrawingLayer(
1286 parent, scale_by_half, gfx::PointF(50.f, 50.f), gfx::Size(100, 100),
1287 false);
ajuma50bce7e2016-06-24 20:56:041288 filtered_surface->test_properties()->background_filters = filters;
[email protected]d5467eb72014-08-22 01:16:431289 gfx::Rect occlusion_rect;
1290 switch (i) {
1291 case LEFT:
1292 occlusion_rect = gfx::Rect(0, 0, 50, 200);
1293 break;
1294 case RIGHT:
jbroman19a18b12016-07-07 02:37:381295 // This is the right edge; filtered_surface is scaled by half.
[email protected]d5467eb72014-08-22 01:16:431296 occlusion_rect = gfx::Rect(100, 0, 50, 200);
1297 break;
1298 case TOP:
1299 occlusion_rect = gfx::Rect(0, 0, 200, 50);
1300 break;
1301 case BOTTOM:
jbroman19a18b12016-07-07 02:37:381302 // This is the bottom edge; filtered_surface is scaled by half.
[email protected]d5467eb72014-08-22 01:16:431303 occlusion_rect = gfx::Rect(0, 100, 200, 50);
1304 break;
1305 }
[email protected]ac7c7f52012-11-08 06:26:501306
danakj00f7925e2015-06-15 21:19:221307 LayerImpl* occluding_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:241308 parent, this->identity_matrix, gfx::PointF(occlusion_rect.origin()),
danakj00f7925e2015-06-15 21:19:221309 occlusion_rect.size(), true);
jaydasika6b5a32bf2016-04-22 21:56:361310 occluding_layer->test_properties()->force_render_surface = false;
[email protected]d5467eb72014-08-22 01:16:431311 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141312
danakj00f7925e2015-06-15 21:19:221313 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
[email protected]94f206c12012-08-25 00:09:141314
[email protected]d5467eb72014-08-22 01:16:431315 // This layer occludes pixels directly beside the filtered_surface.
1316 // Because filtered surface blends pixels in a radius, it will need to see
1317 // some of the pixels (up to radius far) underneath the occluding layers.
1318 this->VisitLayer(occluding_layer, &occlusion);
[email protected]ccb1c9a2012-12-17 03:53:191319
[email protected]d5467eb72014-08-22 01:16:431320 EXPECT_EQ(occlusion_rect.ToString(),
1321 occlusion.occlusion_from_inside_target().ToString());
1322 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141323
[email protected]d5467eb72014-08-22 01:16:431324 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141325
[email protected]d5467eb72014-08-22 01:16:431326 // The occlusion is used fully inside the surface.
1327 gfx::Rect occlusion_inside_surface =
1328 occlusion_rect - gfx::Vector2d(50, 50);
1329 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1330 EXPECT_EQ(occlusion_inside_surface.ToString(),
1331 occlusion.occlusion_from_outside_target().ToString());
[email protected]ac7c7f52012-11-08 06:26:501332
[email protected]d5467eb72014-08-22 01:16:431333 // The surface has a background blur, so it needs pixels that are
jbroman19a18b12016-07-07 02:37:381334 // currently considered occluded in order to be drawn. The pixels it
1335 // needs should be removed from the occluded area, so that they are drawn
1336 // when we get to the parent.
[email protected]d5467eb72014-08-22 01:16:431337 this->VisitContributingSurface(filtered_surface, &occlusion);
1338 this->EnterLayer(parent, &occlusion);
[email protected]ac7c7f52012-11-08 06:26:501339
jbroman56c1f9c2016-07-06 19:08:101340 // The spread due to a 10px blur is 30px.
[email protected]d5467eb72014-08-22 01:16:431341 gfx::Rect expected_occlusion = occlusion_rect;
1342 switch (i) {
1343 case LEFT:
jbroman56c1f9c2016-07-06 19:08:101344 expected_occlusion.Inset(0, 0, 30, 0);
[email protected]d5467eb72014-08-22 01:16:431345 break;
1346 case RIGHT:
jbroman56c1f9c2016-07-06 19:08:101347 expected_occlusion.Inset(30, 0, 0, 0);
[email protected]d5467eb72014-08-22 01:16:431348 break;
1349 case TOP:
jbroman56c1f9c2016-07-06 19:08:101350 expected_occlusion.Inset(0, 0, 0, 30);
[email protected]d5467eb72014-08-22 01:16:431351 break;
1352 case BOTTOM:
jbroman56c1f9c2016-07-06 19:08:101353 expected_occlusion.Inset(0, 30, 0, 0);
[email protected]d5467eb72014-08-22 01:16:431354 break;
1355 }
[email protected]94f206c12012-08-25 00:09:141356
[email protected]d5467eb72014-08-22 01:16:431357 EXPECT_EQ(expected_occlusion.ToString(),
1358 occlusion.occlusion_from_inside_target().ToString());
1359 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141360
[email protected]d5467eb72014-08-22 01:16:431361 this->DestroyLayers();
1362 }
[email protected]a27cbde2013-03-23 22:01:491363 }
[email protected]94f206c12012-08-25 00:09:141364};
1365
[email protected]a27cbde2013-03-23 22:01:491366ALL_OCCLUSIONTRACKER_TEST(
1367 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:141368
ajuma977555362016-07-19 16:12:121369class OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter
jbroman19a18b12016-07-07 02:37:381370 : public OcclusionTrackerTest {
1371 protected:
ajuma977555362016-07-19 16:12:121372 explicit OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter(
jbroman19a18b12016-07-07 02:37:381373 bool opaque_layers)
1374 : OcclusionTrackerTest(opaque_layers) {}
1375 void RunMyTest() override {
1376 gfx::Transform scale_by_half;
1377 scale_by_half.Scale(0.5, 0.5);
1378
1379 FilterOperations filters;
1380 filters.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(10, 10),
1381 5, SK_ColorBLACK));
1382
1383 enum Direction {
1384 LEFT,
1385 RIGHT,
1386 TOP,
1387 BOTTOM,
1388 LAST_DIRECTION = BOTTOM,
1389 };
1390
1391 for (int i = 0; i <= LAST_DIRECTION; ++i) {
1392 SCOPED_TRACE(i);
1393
1394 // Make a 50x50 filtered surface that is adjacent to occluding layers
1395 // which are above it in the z-order in various configurations. The
1396 // surface is scaled to test that the pixel moving is done in the target
1397 // space, where the background filter is applied.
1398 TestContentLayerImpl* parent = this->CreateRoot(
1399 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
1400 LayerImpl* filtered_surface = this->CreateDrawingLayer(
1401 parent, scale_by_half, gfx::PointF(50.f, 50.f), gfx::Size(100, 100),
1402 false);
1403 filtered_surface->test_properties()->background_filters = filters;
1404 gfx::Rect occlusion_rect;
1405 switch (i) {
1406 case LEFT:
1407 occlusion_rect = gfx::Rect(0, 0, 50, 200);
1408 break;
1409 case RIGHT:
1410 // This is the right edge; filtered_surface is scaled by half.
1411 occlusion_rect = gfx::Rect(100, 0, 50, 200);
1412 break;
1413 case TOP:
1414 occlusion_rect = gfx::Rect(0, 0, 200, 50);
1415 break;
1416 case BOTTOM:
1417 // This is the bottom edge; filtered_surface is scaled by half.
1418 occlusion_rect = gfx::Rect(0, 100, 200, 50);
1419 break;
1420 }
1421
1422 LayerImpl* occluding_layer = this->CreateDrawingLayer(
1423 parent, this->identity_matrix, gfx::PointF(occlusion_rect.origin()),
1424 occlusion_rect.size(), true);
1425 occluding_layer->test_properties()->force_render_surface = false;
1426 this->CalcDrawEtc(parent);
1427
1428 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
1429
1430 // This layer occludes pixels directly beside the filtered_surface.
1431 // Because filtered surface blends pixels in a radius, it will need to see
1432 // some of the pixels (up to radius far) underneath the occluding layers.
1433 this->VisitLayer(occluding_layer, &occlusion);
1434
1435 EXPECT_EQ(occlusion_rect.ToString(),
1436 occlusion.occlusion_from_inside_target().ToString());
1437 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1438
1439 this->VisitLayer(filtered_surface, &occlusion);
1440
1441 // The occlusion is used fully inside the surface.
1442 gfx::Rect occlusion_inside_surface =
1443 occlusion_rect - gfx::Vector2d(50, 50);
1444 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1445 EXPECT_EQ(occlusion_inside_surface.ToString(),
1446 occlusion.occlusion_from_outside_target().ToString());
1447
1448 // The surface has a background filter, so it needs pixels that are
1449 // currently considered occluded in order to be drawn. The pixels it
1450 // needs should be removed from the occluded area, so that they are drawn
1451 // when we get to the parent.
1452 this->VisitContributingSurface(filtered_surface, &occlusion);
1453 this->EnterLayer(parent, &occlusion);
1454
1455 gfx::Rect expected_occlusion;
1456 switch (i) {
1457 case LEFT:
1458 // The right half of the occlusion is close enough to cast a shadow
1459 // that would be visible in the background filter. The shadow reaches
1460 // 3*5 + 10 = 25 pixels to the right.
1461 expected_occlusion = gfx::Rect(0, 0, 25, 200);
1462 break;
1463 case RIGHT:
1464 // The shadow spreads 3*5 - 10 = 5 pixels to the left, so the
1465 // occlusion must recede by 5 to account for that.
1466 expected_occlusion = gfx::Rect(105, 0, 45, 200);
1467 break;
1468 case TOP:
1469 // Similar to LEFT.
1470 expected_occlusion = gfx::Rect(0, 0, 200, 25);
1471 break;
1472 case BOTTOM:
1473 // Similar to RIGHT.
1474 expected_occlusion = gfx::Rect(0, 105, 200, 45);
1475 break;
1476 }
1477
1478 EXPECT_EQ(expected_occlusion.ToString(),
1479 occlusion.occlusion_from_inside_target().ToString());
1480 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1481
1482 this->DestroyLayers();
1483 }
1484 }
1485};
1486
1487ALL_OCCLUSIONTRACKER_TEST(
ajuma977555362016-07-19 16:12:121488 OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter);
jbroman19a18b12016-07-07 02:37:381489
[email protected]ca2902e92013-03-28 01:45:351490class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice
danakj00f7925e2015-06-15 21:19:221491 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491492 protected:
[email protected]ca2902e92013-03-28 01:45:351493 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice(
[email protected]a27cbde2013-03-23 22:01:491494 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221495 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471496 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491497 gfx::Transform scale_by_half;
1498 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141499
[email protected]a27cbde2013-03-23 22:01:491500 // Makes two surfaces that completely cover |parent|. The occlusion both
1501 // above and below the filters will be reduced by each of them.
danakj00f7925e2015-06-15 21:19:221502 TestContentLayerImpl* root = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491503 this->identity_matrix, gfx::PointF(), gfx::Size(75, 75));
danakj00f7925e2015-06-15 21:19:221504 LayerImpl* parent = this->CreateSurface(root, scale_by_half, gfx::PointF(),
1505 gfx::Size(150, 150));
[email protected]a27cbde2013-03-23 22:01:491506 parent->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221507 LayerImpl* filtered_surface1 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491508 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
danakj00f7925e2015-06-15 21:19:221509 LayerImpl* filtered_surface2 = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491510 parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false);
danakj00f7925e2015-06-15 21:19:221511 LayerImpl* occluding_layer_above = this->CreateDrawingLayer(
1512 parent, this->identity_matrix, gfx::PointF(100.f, 100.f),
1513 gfx::Size(50, 50), true);
[email protected]94f206c12012-08-25 00:09:141514
[email protected]a27cbde2013-03-23 22:01:491515 // Filters make the layers own surfaces.
jaydasika6b5a32bf2016-04-22 21:56:361516 filtered_surface1->test_properties()->force_render_surface = true;
1517 filtered_surface2->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291518 FilterOperations filters;
1519 filters.Append(FilterOperation::CreateBlurFilter(1.f));
ajuma50bce7e2016-06-24 20:56:041520 filtered_surface1->test_properties()->background_filters = filters;
1521 filtered_surface2->test_properties()->background_filters = filters;
[email protected]94f206c12012-08-25 00:09:141522
[email protected]a27cbde2013-03-23 22:01:491523 this->CalcDrawEtc(root);
[email protected]94f206c12012-08-25 00:09:141524
danakj00f7925e2015-06-15 21:19:221525 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141526
[email protected]d002dd02013-03-27 07:40:401527 this->VisitLayer(occluding_layer_above, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491528 EXPECT_EQ(gfx::Rect().ToString(),
1529 occlusion.occlusion_from_outside_target().ToString());
1530 EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(),
1531 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141532
[email protected]d002dd02013-03-27 07:40:401533 this->VisitLayer(filtered_surface2, &occlusion);
1534 this->VisitContributingSurface(filtered_surface2, &occlusion);
1535 this->VisitLayer(filtered_surface1, &occlusion);
1536 this->VisitContributingSurface(filtered_surface1, &occlusion);
[email protected]94f206c12012-08-25 00:09:141537
[email protected]a27cbde2013-03-23 22:01:491538 // Test expectations in the target.
jbroman56c1f9c2016-07-06 19:08:101539 int blur_outset = 3;
[email protected]a27cbde2013-03-23 22:01:491540 gfx::Rect expected_occlusion =
jbroman56c1f9c2016-07-06 19:08:101541 gfx::Rect(100 / 2 + blur_outset * 2, 100 / 2 + blur_outset * 2,
1542 50 / 2 - blur_outset * 4, 50 / 2 - blur_outset * 4);
[email protected]a27cbde2013-03-23 22:01:491543 EXPECT_EQ(expected_occlusion.ToString(),
1544 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141545
[email protected]a27cbde2013-03-23 22:01:491546 // Test expectations in the screen are the same as in the target, as the
1547 // render surface is 1:1 with the screen.
1548 EXPECT_EQ(expected_occlusion.ToString(),
1549 occlusion.occlusion_from_outside_target().ToString());
1550 }
[email protected]94f206c12012-08-25 00:09:141551};
1552
[email protected]a27cbde2013-03-23 22:01:491553ALL_OCCLUSIONTRACKER_TEST(
1554 OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice);
[email protected]94f206c12012-08-25 00:09:141555
[email protected]ca2902e92013-03-28 01:45:351556class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter
danakj00f7925e2015-06-15 21:19:221557 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491558 protected:
[email protected]ca2902e92013-03-28 01:45:351559 explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter(
[email protected]a27cbde2013-03-23 22:01:491560 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221561 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471562 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491563 gfx::Transform scale_by_half;
1564 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141565
wangxianzhu932d7f12016-09-30 05:47:001566 // Make a 50x50 surface, with a smaller 30x30 layer centered below it.
1567 // The surface is scaled to test that the pixel moving is done in the target
1568 // space, where the background filter is applied, and the surface appears at
1569 // 50, 50.
danakj00f7925e2015-06-15 21:19:221570 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491571 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
danakj00f7925e2015-06-15 21:19:221572 LayerImpl* behind_surface_layer = this->CreateDrawingLayer(
1573 parent, this->identity_matrix, gfx::PointF(60.f, 60.f),
1574 gfx::Size(30, 30), true);
danakj00f7925e2015-06-15 21:19:221575 LayerImpl* filtered_surface =
1576 this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f),
1577 gfx::Size(100, 100), false);
[email protected]94f206c12012-08-25 00:09:141578
[email protected]a27cbde2013-03-23 22:01:491579 // Filters make the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361580 filtered_surface->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291581 FilterOperations filters;
1582 filters.Append(FilterOperation::CreateBlurFilter(3.f));
ajuma50bce7e2016-06-24 20:56:041583 filtered_surface->test_properties()->background_filters = filters;
[email protected]94f206c12012-08-25 00:09:141584
[email protected]a27cbde2013-03-23 22:01:491585 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141586
danakj00f7925e2015-06-15 21:19:221587 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141588
[email protected]a27cbde2013-03-23 22:01:491589 // The surface has a background blur, so it blurs non-opaque pixels below
1590 // it.
[email protected]d002dd02013-03-27 07:40:401591 this->VisitLayer(filtered_surface, &occlusion);
1592 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141593
[email protected]d5467eb72014-08-22 01:16:431594 // The layers behind the surface are not blurred, and their occlusion does
1595 // not change, until we leave the surface. So it should not be modified by
1596 // the filter here.
[email protected]d5467eb72014-08-22 01:16:431597 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1598
1599 // Clear the occlusion so the |behind_surface_layer| can add its occlusion
1600 // without existing occlusion interfering.
1601 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
1602
[email protected]d002dd02013-03-27 07:40:401603 this->VisitLayer(behind_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141604
[email protected]a27cbde2013-03-23 22:01:491605 // The layers behind the surface are not blurred, and their occlusion does
1606 // not change, until we leave the surface. So it should not be modified by
1607 // the filter here.
1608 gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30);
[email protected]d5467eb72014-08-22 01:16:431609 EXPECT_EQ(occlusion_behind_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:491610 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431611 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]a27cbde2013-03-23 22:01:491612 }
[email protected]94f206c12012-08-25 00:09:141613};
1614
[email protected]a27cbde2013-03-23 22:01:491615ALL_OCCLUSIONTRACKER_TEST(
1616 OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter);
[email protected]94f206c12012-08-25 00:09:141617
[email protected]ca2902e92013-03-28 01:45:351618class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded
danakj00f7925e2015-06-15 21:19:221619 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491620 protected:
[email protected]ca2902e92013-03-28 01:45:351621 explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded(
[email protected]a27cbde2013-03-23 22:01:491622 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221623 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471624 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491625 gfx::Transform scale_by_half;
1626 scale_by_half.Scale(0.5, 0.5);
1627
[email protected]66b52e12013-11-17 15:53:181628 // Make a 50x50 filtered surface that is completely occluded by an opaque
1629 // layer which is above it in the z-order. The surface is
[email protected]a27cbde2013-03-23 22:01:491630 // scaled to test that the pixel moving is done in the target space, where
wangxianzhu932d7f12016-09-30 05:47:001631 // the background filter is applied, and the surface appears at 50, 50.
danakj00f7925e2015-06-15 21:19:221632 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]66b52e12013-11-17 15:53:181633 this->identity_matrix, gfx::PointF(), gfx::Size(200, 150));
danakj00f7925e2015-06-15 21:19:221634 LayerImpl* filtered_surface =
1635 this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f),
1636 gfx::Size(100, 100), false);
1637 LayerImpl* occluding_layer = this->CreateDrawingLayer(
1638 parent, this->identity_matrix, gfx::PointF(50.f, 50.f),
1639 gfx::Size(50, 50), true);
[email protected]a27cbde2013-03-23 22:01:491640
1641 // Filters make the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361642 filtered_surface->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291643 FilterOperations filters;
1644 filters.Append(FilterOperation::CreateBlurFilter(3.f));
ajuma50bce7e2016-06-24 20:56:041645 filtered_surface->test_properties()->background_filters = filters;
[email protected]a27cbde2013-03-23 22:01:491646
1647 this->CalcDrawEtc(parent);
1648
danakj00f7925e2015-06-15 21:19:221649 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491650
[email protected]66b52e12013-11-17 15:53:181651 this->VisitLayer(occluding_layer, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491652
[email protected]d002dd02013-03-27 07:40:401653 this->VisitLayer(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141654 {
[email protected]a27cbde2013-03-23 22:01:491655 // The layers above the filtered surface occlude from outside.
1656 gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50);
[email protected]94f206c12012-08-25 00:09:141657
[email protected]a27cbde2013-03-23 22:01:491658 EXPECT_EQ(gfx::Rect().ToString(),
1659 occlusion.occlusion_from_inside_target().ToString());
[email protected]66b52e12013-11-17 15:53:181660 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:491661 occlusion.occlusion_from_outside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141662 }
[email protected]a27cbde2013-03-23 22:01:491663
1664 // The surface has a background blur, so it blurs non-opaque pixels below
1665 // it.
[email protected]d002dd02013-03-27 07:40:401666 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]a27cbde2013-03-23 22:01:491667 {
1668 // The filter is completely occluded, so it should not blur anything and
1669 // reduce any occlusion.
1670 gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50);
[email protected]a27cbde2013-03-23 22:01:491671
[email protected]66b52e12013-11-17 15:53:181672 EXPECT_EQ(occlusion_above_surface.ToString(),
[email protected]a27cbde2013-03-23 22:01:491673 occlusion.occlusion_from_inside_target().ToString());
1674 EXPECT_EQ(gfx::Rect().ToString(),
1675 occlusion.occlusion_from_outside_target().ToString());
1676 }
1677 }
[email protected]94f206c12012-08-25 00:09:141678};
1679
[email protected]a27cbde2013-03-23 22:01:491680ALL_OCCLUSIONTRACKER_TEST(
1681 OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded);
[email protected]94f206c12012-08-25 00:09:141682
danakj00f7925e2015-06-15 21:19:221683class OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded
1684 : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491685 protected:
danakj00f7925e2015-06-15 21:19:221686 explicit OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded(
[email protected]a27cbde2013-03-23 22:01:491687 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221688 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471689 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491690 gfx::Transform scale_by_half;
1691 scale_by_half.Scale(0.5, 0.5);
[email protected]94f206c12012-08-25 00:09:141692
wangxianzhu932d7f12016-09-30 05:47:001693 // Make a 50x50 surface which is partially occluded by opaque layers which
1694 // are above it in the z-order. The surface is scaled to test that the
1695 // pixel moving is done in the target space, where the background filter is
1696 // applied, but the surface appears at 50, 50.
danakj00f7925e2015-06-15 21:19:221697 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491698 this->identity_matrix, gfx::PointF(), gfx::Size(300, 150));
danakj00f7925e2015-06-15 21:19:221699 LayerImpl* filtered_surface =
1700 this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f),
1701 gfx::Size(100, 100), false);
danakj00f7925e2015-06-15 21:19:221702 LayerImpl* above_surface_layer = this->CreateDrawingLayer(
1703 parent, this->identity_matrix, gfx::PointF(70.f, 50.f),
1704 gfx::Size(30, 50), true);
danakj00f7925e2015-06-15 21:19:221705 LayerImpl* beside_surface_layer = this->CreateDrawingLayer(
1706 parent, this->identity_matrix, gfx::PointF(90.f, 40.f),
1707 gfx::Size(10, 10), true);
[email protected]94f206c12012-08-25 00:09:141708
[email protected]a27cbde2013-03-23 22:01:491709 // Filters make the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361710 filtered_surface->test_properties()->force_render_surface = true;
[email protected]ae6b1a72013-06-25 18:49:291711 FilterOperations filters;
1712 filters.Append(FilterOperation::CreateBlurFilter(3.f));
ajuma50bce7e2016-06-24 20:56:041713 filtered_surface->test_properties()->background_filters = filters;
[email protected]94f206c12012-08-25 00:09:141714
[email protected]a27cbde2013-03-23 22:01:491715 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141716
danakj00f7925e2015-06-15 21:19:221717 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]94f206c12012-08-25 00:09:141718
[email protected]d002dd02013-03-27 07:40:401719 this->VisitLayer(beside_surface_layer, &occlusion);
[email protected]d002dd02013-03-27 07:40:401720 this->VisitLayer(above_surface_layer, &occlusion);
[email protected]94f206c12012-08-25 00:09:141721
[email protected]a27cbde2013-03-23 22:01:491722 // The surface has a background blur, so it blurs non-opaque pixels below
1723 // it.
[email protected]d002dd02013-03-27 07:40:401724 this->VisitLayer(filtered_surface, &occlusion);
1725 this->VisitContributingSurface(filtered_surface, &occlusion);
[email protected]94f206c12012-08-25 00:09:141726
wangxianzhu932d7f12016-09-30 05:47:001727 // The filter in the surface is partially unoccluded. Only the unoccluded
1728 // parts should reduce occlusion. This means it will push back the
1729 // occlusion that touches the unoccluded part (occlusion_above___), but
[email protected]a27cbde2013-03-23 22:01:491730 // it will not touch occlusion_beside____ since that is not beside the
1731 // unoccluded part of the surface, even though it is beside the occluded
1732 // part of the surface.
jbroman56c1f9c2016-07-06 19:08:101733 int blur_outset = 9;
[email protected]a27cbde2013-03-23 22:01:491734 gfx::Rect occlusion_above_surface =
jbroman56c1f9c2016-07-06 19:08:101735 gfx::Rect(70 + blur_outset, 50, 30 - blur_outset, 50);
[email protected]a27cbde2013-03-23 22:01:491736 gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10);
[email protected]94f206c12012-08-25 00:09:141737
[email protected]d5467eb72014-08-22 01:16:431738 SimpleEnclosedRegion expected_occlusion;
[email protected]d5467eb72014-08-22 01:16:431739 expected_occlusion.Union(occlusion_beside_surface);
[email protected]d5467eb72014-08-22 01:16:431740 expected_occlusion.Union(occlusion_above_surface);
[email protected]94f206c12012-08-25 00:09:141741
[email protected]d5467eb72014-08-22 01:16:431742 EXPECT_EQ(expected_occlusion.ToString(),
[email protected]a27cbde2013-03-23 22:01:491743 occlusion.occlusion_from_inside_target().ToString());
[email protected]d5467eb72014-08-22 01:16:431744 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
[email protected]94f206c12012-08-25 00:09:141745
[email protected]d5467eb72014-08-22 01:16:431746 const SimpleEnclosedRegion& actual_occlusion =
1747 occlusion.occlusion_from_inside_target();
1748 for (size_t i = 0; i < expected_occlusion.GetRegionComplexity(); ++i) {
1749 ASSERT_LT(i, actual_occlusion.GetRegionComplexity());
1750 EXPECT_EQ(expected_occlusion.GetRect(i), actual_occlusion.GetRect(i));
[email protected]94f206c12012-08-25 00:09:141751 }
[email protected]a27cbde2013-03-23 22:01:491752 }
[email protected]94f206c12012-08-25 00:09:141753};
1754
[email protected]a27cbde2013-03-23 22:01:491755ALL_OCCLUSIONTRACKER_TEST(
danakj00f7925e2015-06-15 21:19:221756 OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded);
[email protected]94f206c12012-08-25 00:09:141757
danakj4902c302015-02-13 22:12:161758class OcclusionTrackerTestBlendModeDoesNotOcclude
danakj00f7925e2015-06-15 21:19:221759 : public OcclusionTrackerTest {
danakj4902c302015-02-13 22:12:161760 protected:
1761 explicit OcclusionTrackerTestBlendModeDoesNotOcclude(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221762 : OcclusionTrackerTest(opaque_layers) {}
danakj4902c302015-02-13 22:12:161763 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221764 TestContentLayerImpl* parent = this->CreateRoot(
danakj4902c302015-02-13 22:12:161765 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
danakj00f7925e2015-06-15 21:19:221766 LayerImpl* blend_mode_layer = this->CreateDrawingLayer(
danakj4902c302015-02-13 22:12:161767 parent, this->identity_matrix, gfx::PointF(0.f, 0.f),
1768 gfx::Size(100, 100), true);
danakj00f7925e2015-06-15 21:19:221769 LayerImpl* top_layer = this->CreateDrawingLayer(
danakj4902c302015-02-13 22:12:161770 parent, this->identity_matrix, gfx::PointF(10.f, 12.f),
1771 gfx::Size(20, 22), true);
1772
1773 // Blend mode makes the layer own a surface.
jaydasika6b5a32bf2016-04-22 21:56:361774 blend_mode_layer->test_properties()->force_render_surface = true;
reedcc9c70f2016-11-22 04:26:011775 blend_mode_layer->test_properties()->blend_mode = SkBlendMode::kMultiply;
danakj4902c302015-02-13 22:12:161776
1777 this->CalcDrawEtc(parent);
1778
danakj00f7925e2015-06-15 21:19:221779 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
danakj4902c302015-02-13 22:12:161780
1781 this->VisitLayer(top_layer, &occlusion);
1782 // |top_layer| occludes.
1783 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(),
1784 occlusion.occlusion_from_inside_target().ToString());
1785 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1786
1787 this->VisitLayer(blend_mode_layer, &occlusion);
ajuma2d466aa2016-07-25 21:11:001788 // |top_layer| and |blend_mode_layer| both occlude, since the blend mode
1789 // gets applied by blend_mode_layer's render surface, not when drawing the
1790 // layer itself.
1791 EXPECT_EQ(gfx::Rect(100, 100).ToString(),
1792 occlusion.occlusion_from_inside_target().ToString());
danakj4902c302015-02-13 22:12:161793 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(),
1794 occlusion.occlusion_from_outside_target().ToString());
danakj4902c302015-02-13 22:12:161795
1796 this->VisitContributingSurface(blend_mode_layer, &occlusion);
1797 // |top_layer| occludes but not |blend_mode_layer|.
1798 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(),
1799 occlusion.occlusion_from_inside_target().ToString());
1800 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1801 }
1802};
1803
1804ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestBlendModeDoesNotOcclude);
1805
danakj00f7925e2015-06-15 21:19:221806class OcclusionTrackerTestMinimumTrackingSize : public OcclusionTrackerTest {
[email protected]a27cbde2013-03-23 22:01:491807 protected:
[email protected]ca2902e92013-03-28 01:45:351808 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221809 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471810 void RunMyTest() override {
[email protected]a27cbde2013-03-23 22:01:491811 gfx::Size tracking_size(100, 100);
1812 gfx::Size below_tracking_size(99, 99);
[email protected]94f206c12012-08-25 00:09:141813
danakj00f7925e2015-06-15 21:19:221814 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]a27cbde2013-03-23 22:01:491815 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221816 LayerImpl* large = this->CreateDrawingLayer(
[email protected]a27cbde2013-03-23 22:01:491817 parent, this->identity_matrix, gfx::PointF(), tracking_size, true);
danakj00f7925e2015-06-15 21:19:221818 LayerImpl* small =
1819 this->CreateDrawingLayer(parent, this->identity_matrix, gfx::PointF(),
1820 below_tracking_size, true);
[email protected]a27cbde2013-03-23 22:01:491821 this->CalcDrawEtc(parent);
[email protected]94f206c12012-08-25 00:09:141822
danakj00f7925e2015-06-15 21:19:221823 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]a27cbde2013-03-23 22:01:491824 occlusion.set_minimum_tracking_size(tracking_size);
[email protected]94f206c12012-08-25 00:09:141825
[email protected]a27cbde2013-03-23 22:01:491826 // The small layer is not tracked because it is too small.
[email protected]d002dd02013-03-27 07:40:401827 this->VisitLayer(small, &occlusion);
[email protected]94f206c12012-08-25 00:09:141828
[email protected]a27cbde2013-03-23 22:01:491829 EXPECT_EQ(gfx::Rect().ToString(),
1830 occlusion.occlusion_from_outside_target().ToString());
1831 EXPECT_EQ(gfx::Rect().ToString(),
1832 occlusion.occlusion_from_inside_target().ToString());
[email protected]94f206c12012-08-25 00:09:141833
[email protected]a27cbde2013-03-23 22:01:491834 // The large layer is tracked as it is large enough.
[email protected]d002dd02013-03-27 07:40:401835 this->VisitLayer(large, &occlusion);
[email protected]94f206c12012-08-25 00:09:141836
[email protected]a27cbde2013-03-23 22:01:491837 EXPECT_EQ(gfx::Rect().ToString(),
1838 occlusion.occlusion_from_outside_target().ToString());
[email protected]2c7c6702013-03-26 03:14:051839 EXPECT_EQ(gfx::Rect(tracking_size).ToString(),
[email protected]a27cbde2013-03-23 22:01:491840 occlusion.occlusion_from_inside_target().ToString());
1841 }
[email protected]94f206c12012-08-25 00:09:141842};
1843
[email protected]96baf3e2012-10-22 23:09:551844ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize);
[email protected]94f206c12012-08-25 00:09:141845
danakj00f7925e2015-06-15 21:19:221846class OcclusionTrackerTestScaledLayerIsClipped : public OcclusionTrackerTest {
[email protected]1a5d9ce2013-04-30 01:31:091847 protected:
1848 explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221849 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471850 void RunMyTest() override {
[email protected]1a5d9ce2013-04-30 01:31:091851 gfx::Transform scale_transform;
1852 scale_transform.Scale(512.0, 512.0);
1853
danakj00f7925e2015-06-15 21:19:221854 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]1a5d9ce2013-04-30 01:31:091855 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221856 LayerImpl* clip =
1857 this->CreateLayer(parent, this->identity_matrix,
1858 gfx::PointF(10.f, 10.f), gfx::Size(50, 50));
[email protected]1a5d9ce2013-04-30 01:31:091859 clip->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221860 LayerImpl* scale = this->CreateLayer(clip, scale_transform, gfx::PointF(),
1861 gfx::Size(1, 1));
1862 LayerImpl* scaled = this->CreateDrawingLayer(
[email protected]1a5d9ce2013-04-30 01:31:091863 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
1864 this->CalcDrawEtc(parent);
1865
danakj00f7925e2015-06-15 21:19:221866 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]1a5d9ce2013-04-30 01:31:091867
1868 this->VisitLayer(scaled, &occlusion);
1869
1870 EXPECT_EQ(gfx::Rect().ToString(),
1871 occlusion.occlusion_from_outside_target().ToString());
1872 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
1873 occlusion.occlusion_from_inside_target().ToString());
1874 }
1875};
1876
1877ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped)
1878
[email protected]1a5d9ce2013-04-30 01:31:091879class OcclusionTrackerTestScaledLayerInSurfaceIsClipped
danakj00f7925e2015-06-15 21:19:221880 : public OcclusionTrackerTest {
[email protected]1a5d9ce2013-04-30 01:31:091881 protected:
1882 explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221883 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471884 void RunMyTest() override {
[email protected]1a5d9ce2013-04-30 01:31:091885 gfx::Transform scale_transform;
1886 scale_transform.Scale(512.0, 512.0);
1887
danakj00f7925e2015-06-15 21:19:221888 TestContentLayerImpl* parent = this->CreateRoot(
[email protected]1a5d9ce2013-04-30 01:31:091889 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221890 LayerImpl* clip =
1891 this->CreateLayer(parent, this->identity_matrix,
1892 gfx::PointF(10.f, 10.f), gfx::Size(50, 50));
[email protected]1a5d9ce2013-04-30 01:31:091893 clip->SetMasksToBounds(true);
danakj00f7925e2015-06-15 21:19:221894 LayerImpl* surface = this->CreateDrawingSurface(
[email protected]1a5d9ce2013-04-30 01:31:091895 clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false);
danakj00f7925e2015-06-15 21:19:221896 LayerImpl* scale = this->CreateLayer(surface, scale_transform,
1897 gfx::PointF(), gfx::Size(1, 1));
1898 LayerImpl* scaled = this->CreateDrawingLayer(
[email protected]1a5d9ce2013-04-30 01:31:091899 scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true);
1900 this->CalcDrawEtc(parent);
1901
danakj00f7925e2015-06-15 21:19:221902 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]1a5d9ce2013-04-30 01:31:091903
1904 this->VisitLayer(scaled, &occlusion);
1905 this->VisitLayer(surface, &occlusion);
1906 this->VisitContributingSurface(surface, &occlusion);
1907
1908 EXPECT_EQ(gfx::Rect().ToString(),
1909 occlusion.occlusion_from_outside_target().ToString());
1910 EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(),
1911 occlusion.occlusion_from_inside_target().ToString());
1912 }
1913};
1914
1915ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped)
1916
danakj00f7925e2015-06-15 21:19:221917class OcclusionTrackerTestCopyRequestDoesOcclude : public OcclusionTrackerTest {
[email protected]5b54b972013-07-26 13:25:421918 protected:
1919 explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221920 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471921 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221922 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:241923 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221924 TestContentLayerImpl* parent = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:241925 root, this->identity_matrix, gfx::PointF(), gfx::Size(400, 400), true);
1926 LayerImpl* copy =
1927 this->CreateLayer(parent, this->identity_matrix, gfx::PointF(100, 0),
1928 gfx::Size(200, 400));
[email protected]5b54b972013-07-26 13:25:421929 this->AddCopyRequest(copy);
danakj00f7925e2015-06-15 21:19:221930 LayerImpl* copy_child = this->CreateDrawingLayer(
1931 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
1932 LayerImpl* top_layer =
danakj4902c302015-02-13 22:12:161933 this->CreateDrawingLayer(root, this->identity_matrix,
1934 gfx::PointF(50, 0), gfx::Size(50, 400), true);
[email protected]5b54b972013-07-26 13:25:421935 this->CalcDrawEtc(root);
1936
danakj00f7925e2015-06-15 21:19:221937 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]5b54b972013-07-26 13:25:421938
danakj4902c302015-02-13 22:12:161939 this->VisitLayer(top_layer, &occlusion);
1940 EXPECT_EQ(gfx::Rect().ToString(),
1941 occlusion.occlusion_from_outside_target().ToString());
1942 EXPECT_EQ(gfx::Rect(50, 0, 50, 400).ToString(),
1943 occlusion.occlusion_from_inside_target().ToString());
1944
[email protected]5b54b972013-07-26 13:25:421945 this->VisitLayer(copy_child, &occlusion);
danakj4902c302015-02-13 22:12:161946 // Layers outside the copy request do not occlude.
[email protected]5b54b972013-07-26 13:25:421947 EXPECT_EQ(gfx::Rect().ToString(),
1948 occlusion.occlusion_from_outside_target().ToString());
1949 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
1950 occlusion.occlusion_from_inside_target().ToString());
1951
1952 // CopyRequests cause the layer to own a surface.
1953 this->VisitContributingSurface(copy, &occlusion);
1954
1955 // The occlusion from the copy should be kept.
1956 EXPECT_EQ(gfx::Rect().ToString(),
1957 occlusion.occlusion_from_outside_target().ToString());
danakj4902c302015-02-13 22:12:161958 EXPECT_EQ(gfx::Rect(50, 0, 250, 400).ToString(),
[email protected]5b54b972013-07-26 13:25:421959 occlusion.occlusion_from_inside_target().ToString());
1960 }
1961};
1962
1963ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude)
1964
[email protected]5b54b972013-07-26 13:25:421965class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude
danakj00f7925e2015-06-15 21:19:221966 : public OcclusionTrackerTest {
[email protected]5b54b972013-07-26 13:25:421967 protected:
1968 explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude(
1969 bool opaque_layers)
danakj00f7925e2015-06-15 21:19:221970 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:471971 void RunMyTest() override {
danakj00f7925e2015-06-15 21:19:221972 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:241973 this->identity_matrix, gfx::PointF(), gfx::Size(400, 400));
danakj00f7925e2015-06-15 21:19:221974 TestContentLayerImpl* parent = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:241975 root, this->identity_matrix, gfx::PointF(), gfx::Size(400, 400), true);
danakj00f7925e2015-06-15 21:19:221976 LayerImpl* hide = this->CreateLayer(parent, this->identity_matrix,
danakja2fdbc702015-10-20 23:05:241977 gfx::PointF(), gfx::Size());
1978 LayerImpl* copy =
1979 this->CreateLayer(hide, this->identity_matrix, gfx::PointF(100.f, 0.f),
1980 gfx::Size(200, 400));
[email protected]5b54b972013-07-26 13:25:421981 this->AddCopyRequest(copy);
danakj00f7925e2015-06-15 21:19:221982 LayerImpl* copy_child = this->CreateDrawingLayer(
[email protected]5b54b972013-07-26 13:25:421983 copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true);
1984
1985 // The |copy| layer is hidden but since it is being copied, it will be
1986 // drawn.
jaydasika5121caa82016-05-05 15:43:351987 hide->test_properties()->hide_layer_and_subtree = true;
[email protected]5b54b972013-07-26 13:25:421988
1989 this->CalcDrawEtc(root);
1990
danakj00f7925e2015-06-15 21:19:221991 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000));
[email protected]5b54b972013-07-26 13:25:421992
1993 this->VisitLayer(copy_child, &occlusion);
1994 EXPECT_EQ(gfx::Rect().ToString(),
1995 occlusion.occlusion_from_outside_target().ToString());
1996 EXPECT_EQ(gfx::Rect(200, 400).ToString(),
1997 occlusion.occlusion_from_inside_target().ToString());
1998
1999 // CopyRequests cause the layer to own a surface.
2000 this->VisitContributingSurface(copy, &occlusion);
2001
2002 // The occlusion from the copy should be dropped since it is hidden.
2003 EXPECT_EQ(gfx::Rect().ToString(),
2004 occlusion.occlusion_from_outside_target().ToString());
2005 EXPECT_EQ(gfx::Rect().ToString(),
2006 occlusion.occlusion_from_inside_target().ToString());
2007 }
2008};
2009
2010ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude)
2011
danakj00f7925e2015-06-15 21:19:222012class OcclusionTrackerTestOccludedLayer : public OcclusionTrackerTest {
[email protected]d5467eb72014-08-22 01:16:432013 protected:
2014 explicit OcclusionTrackerTestOccludedLayer(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:222015 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472016 void RunMyTest() override {
[email protected]d5467eb72014-08-22 01:16:432017 gfx::Transform translate;
2018 translate.Translate(10.0, 20.0);
danakj00f7925e2015-06-15 21:19:222019 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:242020 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2021 LayerImpl* surface = this->CreateSurface(
2022 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:222023 LayerImpl* layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242024 surface, translate, gfx::PointF(), gfx::Size(200, 200), false);
danakj00f7925e2015-06-15 21:19:222025 TestContentLayerImpl* outside_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242026 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false);
[email protected]d5467eb72014-08-22 01:16:432027 this->CalcDrawEtc(root);
2028
danakj00f7925e2015-06-15 21:19:222029 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
[email protected]d5467eb72014-08-22 01:16:432030 this->VisitLayer(outside_layer, &occlusion);
2031 this->EnterLayer(layer, &occlusion);
2032
2033 // No occlusion, is not occluded.
2034 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2035 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2036 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100)));
2037
2038 // Partial occlusion from outside, is not occluded.
2039 occlusion.set_occlusion_from_outside_target(
2040 SimpleEnclosedRegion(50, 50, 100, 100));
2041 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2042 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2043 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2044 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2045 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2046 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2047 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2048 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2049 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2050
2051 // Full occlusion from outside, is occluded.
2052 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2053 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2054 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2055 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2056
2057 // Partial occlusion from inside, is not occluded.
2058 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2059 occlusion.set_occlusion_from_inside_target(
2060 SimpleEnclosedRegion(50, 50, 100, 100));
2061 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2062 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2063 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2064 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2065 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2066 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2067 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2068 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2069
2070 // Full occlusion from inside, is occluded.
2071 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2072 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2073 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2074 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2075
2076 // Partial occlusion from both, is not occluded.
2077 occlusion.set_occlusion_from_outside_target(
2078 SimpleEnclosedRegion(50, 50, 100, 50));
2079 occlusion.set_occlusion_from_inside_target(
2080 SimpleEnclosedRegion(50, 100, 100, 50));
2081 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
2082 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100)));
2083 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100)));
2084 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100)));
2085 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100)));
2086 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100)));
2087 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100)));
2088 EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100)));
2089
2090 // Full occlusion from both, is occluded.
2091 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
2092 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
2093 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
2094 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
2095 }
2096};
2097
2098ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOccludedLayer)
2099
danakj00f7925e2015-06-15 21:19:222100class OcclusionTrackerTestUnoccludedLayerQuery : public OcclusionTrackerTest {
danakjf080b5b2014-08-23 22:18:202101 protected:
2102 explicit OcclusionTrackerTestUnoccludedLayerQuery(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:222103 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472104 void RunMyTest() override {
danakjf080b5b2014-08-23 22:18:202105 gfx::Transform translate;
2106 translate.Translate(10.0, 20.0);
danakj00f7925e2015-06-15 21:19:222107 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:242108 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2109 LayerImpl* surface = this->CreateSurface(
2110 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:222111 LayerImpl* layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242112 surface, translate, gfx::PointF(), gfx::Size(200, 200), false);
danakj00f7925e2015-06-15 21:19:222113 TestContentLayerImpl* outside_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242114 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false);
danakjf080b5b2014-08-23 22:18:202115 this->CalcDrawEtc(root);
2116
danakj00f7925e2015-06-15 21:19:222117 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
danakjf080b5b2014-08-23 22:18:202118 this->VisitLayer(outside_layer, &occlusion);
2119 this->EnterLayer(layer, &occlusion);
2120
2121 // No occlusion, is not occluded.
2122 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2123 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2124 EXPECT_EQ(gfx::Rect(100, 100),
2125 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(100, 100)));
2126
2127 // Partial occlusion from outside.
2128 occlusion.set_occlusion_from_outside_target(
2129 SimpleEnclosedRegion(50, 50, 100, 100));
2130 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2131 EXPECT_EQ(
2132 gfx::Rect(0, 0, 100, 100),
2133 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
2134 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2135 occlusion.UnoccludedLayerContentRect(
2136 layer, gfx::Rect(90, 30, 100, 100)));
2137 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2138 occlusion.UnoccludedLayerContentRect(layer,
2139 gfx::Rect(40, 0, 100, 100)));
2140 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2141 occlusion.UnoccludedLayerContentRect(
2142 layer, gfx::Rect(40, 80, 100, 100)));
2143 EXPECT_EQ(
2144 gfx::Rect(0, 0, 80, 100),
2145 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
2146 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2147 occlusion.UnoccludedLayerContentRect(
2148 layer, gfx::Rect(90, 80, 100, 100)));
2149 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2150 occlusion.UnoccludedLayerContentRect(layer,
2151 gfx::Rect(0, 80, 100, 100)));
2152 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2153 occlusion.UnoccludedLayerContentRect(layer,
2154 gfx::Rect(90, 0, 100, 100)));
2155
2156 // Full occlusion from outside, is occluded.
2157 EXPECT_EQ(gfx::Rect(),
2158 occlusion.UnoccludedLayerContentRect(
2159 layer, gfx::Rect(40, 30, 100, 100)));
2160 EXPECT_EQ(
2161 gfx::Rect(),
2162 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
2163 EXPECT_EQ(gfx::Rect(),
2164 occlusion.UnoccludedLayerContentRect(
2165 layer, gfx::Rect(130, 120, 10, 10)));
2166 EXPECT_EQ(
2167 gfx::Rect(),
2168 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
2169
2170 // Partial occlusion from inside, is not occluded.
2171 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2172 occlusion.set_occlusion_from_inside_target(
2173 SimpleEnclosedRegion(50, 50, 100, 100));
2174 EXPECT_EQ(
2175 gfx::Rect(0, 0, 100, 100),
2176 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
2177 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2178 occlusion.UnoccludedLayerContentRect(
2179 layer, gfx::Rect(90, 30, 100, 100)));
2180 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2181 occlusion.UnoccludedLayerContentRect(layer,
2182 gfx::Rect(40, 0, 100, 100)));
2183 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2184 occlusion.UnoccludedLayerContentRect(
2185 layer, gfx::Rect(40, 80, 100, 100)));
2186 EXPECT_EQ(
2187 gfx::Rect(0, 0, 80, 100),
2188 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
2189 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2190 occlusion.UnoccludedLayerContentRect(
2191 layer, gfx::Rect(90, 80, 100, 100)));
2192 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2193 occlusion.UnoccludedLayerContentRect(layer,
2194 gfx::Rect(0, 80, 100, 100)));
2195 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2196 occlusion.UnoccludedLayerContentRect(layer,
2197 gfx::Rect(90, 0, 100, 100)));
2198
2199 // Full occlusion from inside, is occluded.
2200 EXPECT_EQ(gfx::Rect(),
2201 occlusion.UnoccludedLayerContentRect(
2202 layer, gfx::Rect(40, 30, 100, 100)));
2203 EXPECT_EQ(
2204 gfx::Rect(),
2205 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
2206 EXPECT_EQ(gfx::Rect(),
2207 occlusion.UnoccludedLayerContentRect(
2208 layer, gfx::Rect(130, 120, 10, 10)));
2209 EXPECT_EQ(
2210 gfx::Rect(),
2211 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
2212
2213 // Partial occlusion from both, is not occluded.
2214 occlusion.set_occlusion_from_outside_target(
2215 SimpleEnclosedRegion(50, 50, 100, 50));
2216 occlusion.set_occlusion_from_inside_target(
2217 SimpleEnclosedRegion(50, 100, 100, 50));
2218 EXPECT_EQ(
2219 gfx::Rect(0, 0, 100, 100),
2220 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
2221 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
2222 // it's larger.
2223 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
2224 occlusion.UnoccludedLayerContentRect(
2225 layer, gfx::Rect(90, 30, 100, 100)));
2226 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2227 occlusion.UnoccludedLayerContentRect(layer,
2228 gfx::Rect(40, 0, 100, 100)));
2229 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2230 occlusion.UnoccludedLayerContentRect(
2231 layer, gfx::Rect(40, 80, 100, 100)));
2232 EXPECT_EQ(
2233 gfx::Rect(0, 0, 80, 100),
2234 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
2235 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2236 occlusion.UnoccludedLayerContentRect(
2237 layer, gfx::Rect(90, 80, 100, 100)));
2238 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2239 occlusion.UnoccludedLayerContentRect(layer,
2240 gfx::Rect(0, 80, 100, 100)));
2241 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2242 occlusion.UnoccludedLayerContentRect(layer,
2243 gfx::Rect(90, 0, 100, 100)));
2244
2245 // Full occlusion from both, is occluded.
2246 EXPECT_EQ(gfx::Rect(),
2247 occlusion.UnoccludedLayerContentRect(
2248 layer, gfx::Rect(40, 30, 100, 100)));
2249 EXPECT_EQ(
2250 gfx::Rect(),
2251 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
2252 EXPECT_EQ(gfx::Rect(),
2253 occlusion.UnoccludedLayerContentRect(
2254 layer, gfx::Rect(130, 120, 10, 10)));
2255 EXPECT_EQ(
2256 gfx::Rect(),
2257 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
2258 }
2259};
2260
2261ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedLayerQuery)
2262
danakj00f7925e2015-06-15 21:19:222263class OcclusionTrackerTestUnoccludedSurfaceQuery : public OcclusionTrackerTest {
danakjf080b5b2014-08-23 22:18:202264 protected:
2265 explicit OcclusionTrackerTestUnoccludedSurfaceQuery(bool opaque_layers)
danakj00f7925e2015-06-15 21:19:222266 : OcclusionTrackerTest(opaque_layers) {}
dmichaelc78b0932014-12-17 23:39:472267 void RunMyTest() override {
danakjf080b5b2014-08-23 22:18:202268 gfx::Transform translate;
2269 translate.Translate(10.0, 20.0);
danakj00f7925e2015-06-15 21:19:222270 TestContentLayerImpl* root = this->CreateRoot(
danakja2fdbc702015-10-20 23:05:242271 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
2272 LayerImpl* surface = this->CreateSurface(root, translate, gfx::PointF(),
2273 gfx::Size(200, 200));
danakj00f7925e2015-06-15 21:19:222274 LayerImpl* layer =
danakja2fdbc702015-10-20 23:05:242275 this->CreateDrawingLayer(surface, this->identity_matrix, gfx::PointF(),
danakj00f7925e2015-06-15 21:19:222276 gfx::Size(200, 200), false);
2277 TestContentLayerImpl* outside_layer = this->CreateDrawingLayer(
danakja2fdbc702015-10-20 23:05:242278 root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false);
danakjf080b5b2014-08-23 22:18:202279 this->CalcDrawEtc(root);
2280
danakj00f7925e2015-06-15 21:19:222281 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200));
danakjf080b5b2014-08-23 22:18:202282 this->VisitLayer(outside_layer, &occlusion);
2283 this->VisitLayer(layer, &occlusion);
2284 this->EnterContributingSurface(surface, &occlusion);
2285
2286 // No occlusion, is not occluded.
2287 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2288 SimpleEnclosedRegion());
2289 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2290 SimpleEnclosedRegion());
2291 EXPECT_EQ(
2292 gfx::Rect(100, 100),
2293 occlusion.UnoccludedSurfaceContentRect(surface, gfx::Rect(100, 100)));
2294
2295 // Partial occlusion from outside.
2296 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2297 SimpleEnclosedRegion(50, 50, 100, 100));
2298 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2299 SimpleEnclosedRegion());
2300 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2301 occlusion.UnoccludedSurfaceContentRect(
2302 surface, gfx::Rect(0, 0, 100, 100)));
2303 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2304 occlusion.UnoccludedSurfaceContentRect(
2305 surface, gfx::Rect(90, 30, 100, 100)));
2306 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2307 occlusion.UnoccludedSurfaceContentRect(
2308 surface, gfx::Rect(40, 0, 100, 100)));
2309 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2310 occlusion.UnoccludedSurfaceContentRect(
2311 surface, gfx::Rect(40, 80, 100, 100)));
2312 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
2313 occlusion.UnoccludedSurfaceContentRect(surface,
2314 gfx::Rect(0, 0, 80, 100)));
2315 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2316 occlusion.UnoccludedSurfaceContentRect(
2317 surface, gfx::Rect(90, 80, 100, 100)));
2318 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2319 occlusion.UnoccludedSurfaceContentRect(
2320 surface, gfx::Rect(0, 80, 100, 100)));
2321 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2322 occlusion.UnoccludedSurfaceContentRect(
2323 surface, gfx::Rect(90, 0, 100, 100)));
2324
2325 // Full occlusion from outside, is occluded.
2326 EXPECT_EQ(gfx::Rect(),
2327 occlusion.UnoccludedSurfaceContentRect(
2328 surface, gfx::Rect(40, 30, 100, 100)));
2329 EXPECT_EQ(gfx::Rect(),
2330 occlusion.UnoccludedSurfaceContentRect(
2331 surface, gfx::Rect(40, 30, 10, 10)));
2332 EXPECT_EQ(gfx::Rect(),
2333 occlusion.UnoccludedSurfaceContentRect(
2334 surface, gfx::Rect(130, 120, 10, 10)));
2335 EXPECT_EQ(gfx::Rect(),
2336 occlusion.UnoccludedSurfaceContentRect(
2337 surface, gfx::Rect(80, 70, 50, 50)));
2338
2339 // Partial occlusion from inside, is not occluded.
2340 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2341 SimpleEnclosedRegion());
2342 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2343 SimpleEnclosedRegion(50, 50, 100, 100));
2344 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2345 occlusion.UnoccludedSurfaceContentRect(
2346 surface, gfx::Rect(0, 0, 100, 100)));
2347 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
2348 occlusion.UnoccludedSurfaceContentRect(
2349 surface, gfx::Rect(90, 30, 100, 100)));
2350 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2351 occlusion.UnoccludedSurfaceContentRect(
2352 surface, gfx::Rect(40, 0, 100, 100)));
2353 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2354 occlusion.UnoccludedSurfaceContentRect(
2355 surface, gfx::Rect(40, 80, 100, 100)));
2356 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
2357 occlusion.UnoccludedSurfaceContentRect(surface,
2358 gfx::Rect(0, 0, 80, 100)));
2359 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2360 occlusion.UnoccludedSurfaceContentRect(
2361 surface, gfx::Rect(90, 80, 100, 100)));
2362 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2363 occlusion.UnoccludedSurfaceContentRect(
2364 surface, gfx::Rect(0, 80, 100, 100)));
2365 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2366 occlusion.UnoccludedSurfaceContentRect(
2367 surface, gfx::Rect(90, 0, 100, 100)));
2368
2369 // Full occlusion from inside, is occluded.
2370 EXPECT_EQ(gfx::Rect(),
2371 occlusion.UnoccludedSurfaceContentRect(
2372 surface, gfx::Rect(40, 30, 100, 100)));
2373 EXPECT_EQ(gfx::Rect(),
2374 occlusion.UnoccludedSurfaceContentRect(
2375 surface, gfx::Rect(40, 30, 10, 10)));
2376 EXPECT_EQ(gfx::Rect(),
2377 occlusion.UnoccludedSurfaceContentRect(
2378 surface, gfx::Rect(130, 120, 10, 10)));
2379 EXPECT_EQ(gfx::Rect(),
2380 occlusion.UnoccludedSurfaceContentRect(
2381 surface, gfx::Rect(80, 70, 50, 50)));
2382
2383 // Partial occlusion from both, is not occluded.
2384 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
2385 SimpleEnclosedRegion(50, 50, 100, 50));
2386 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
2387 SimpleEnclosedRegion(50, 100, 100, 50));
2388 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2389 occlusion.UnoccludedSurfaceContentRect(
2390 surface, gfx::Rect(0, 0, 100, 100)));
2391 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
2392 // it's larger.
2393 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
2394 occlusion.UnoccludedSurfaceContentRect(
2395 surface, gfx::Rect(90, 30, 100, 100)));
2396 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
2397 occlusion.UnoccludedSurfaceContentRect(
2398 surface, gfx::Rect(40, 0, 100, 100)));
2399 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
2400 occlusion.UnoccludedSurfaceContentRect(
2401 surface, gfx::Rect(40, 80, 100, 100)));
2402 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
2403 occlusion.UnoccludedSurfaceContentRect(surface,
2404 gfx::Rect(0, 0, 80, 100)));
2405 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
2406 occlusion.UnoccludedSurfaceContentRect(
2407 surface, gfx::Rect(90, 80, 100, 100)));
2408 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
2409 occlusion.UnoccludedSurfaceContentRect(
2410 surface, gfx::Rect(0, 80, 100, 100)));
2411 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
2412 occlusion.UnoccludedSurfaceContentRect(
2413 surface, gfx::Rect(90, 0, 100, 100)));
2414
2415 // Full occlusion from both, is occluded.
2416 EXPECT_EQ(gfx::Rect(),
2417 occlusion.UnoccludedSurfaceContentRect(
2418 surface, gfx::Rect(40, 30, 100, 100)));
2419 EXPECT_EQ(gfx::Rect(),
2420 occlusion.UnoccludedSurfaceContentRect(
2421 surface, gfx::Rect(40, 30, 10, 10)));
2422 EXPECT_EQ(gfx::Rect(),
2423 occlusion.UnoccludedSurfaceContentRect(
2424 surface, gfx::Rect(130, 120, 10, 10)));
2425 EXPECT_EQ(gfx::Rect(),
2426 occlusion.UnoccludedSurfaceContentRect(
2427 surface, gfx::Rect(80, 70, 50, 50)));
2428 }
2429};
2430
2431ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery)
2432
[email protected]ba565742012-11-10 09:29:482433} // namespace
2434} // namespace cc