[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // 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] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/occlusion_tracker.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
loyso | 2cb3f32f | 2016-11-08 07:08:34 | [diff] [blame] | 9 | #include "cc/animation/animation_host.h" |
chrishtr | ac41ff9 | 2017-03-17 05:07:30 | [diff] [blame] | 10 | #include "cc/base/filter_operation.h" |
| 11 | #include "cc/base/filter_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 12 | #include "cc/base/math_util.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 13 | #include "cc/layers/layer.h" |
| 14 | #include "cc/layers/layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 15 | #include "cc/test/animation_test_common.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 16 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 17 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 18 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 19 | #include "cc/test/geometry_test_utils.h" |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 20 | #include "cc/test/layer_test_common.h" |
[email protected] | 34ba1ffb | 2014-03-05 06:55:03 | [diff] [blame] | 21 | #include "cc/test/test_occlusion_tracker.h" |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 22 | #include "cc/test/test_task_graph_runner.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 23 | #include "cc/trees/layer_tree_host_common.h" |
| 24 | #include "cc/trees/single_thread_proxy.h" |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame] | 25 | #include "components/viz/common/quads/copy_output_request.h" |
| 26 | #include "components/viz/common/quads/copy_output_result.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 27 | #include "testing/gmock/include/gmock/gmock.h" |
| 28 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 29 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 30 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 31 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 32 | namespace { |
| 33 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 34 | class TestContentLayerImpl : public LayerImpl { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 35 | public: |
| 36 | TestContentLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 37 | : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) { |
| 38 | SetDrawsContent(true); |
| 39 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 40 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 41 | SimpleEnclosedRegion VisibleOpaqueRegion() const override { |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 42 | if (override_opaque_contents_rect_) { |
| 43 | return SimpleEnclosedRegion( |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 44 | gfx::IntersectRects(opaque_contents_rect_, visible_layer_rect())); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 45 | } |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 46 | return LayerImpl::VisibleOpaqueRegion(); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 47 | } |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 48 | void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 49 | override_opaque_contents_rect_ = true; |
| 50 | opaque_contents_rect_ = opaque_contents_rect; |
| 51 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 52 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 53 | private: |
| 54 | bool override_opaque_contents_rect_; |
| 55 | gfx::Rect opaque_contents_rect_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 56 | }; |
| 57 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 58 | class TestOcclusionTrackerWithClip : public TestOcclusionTracker { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 59 | public: |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 60 | explicit TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 61 | : TestOcclusionTracker(viewport_rect) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 62 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 63 | bool OccludedLayer(const LayerImpl* layer, |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 64 | const gfx::Rect& content_rect) const { |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 65 | DCHECK(layer->visible_layer_rect().Contains(content_rect)); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 66 | return this->GetCurrentOcclusionForLayer(layer->DrawTransform()) |
vmpstr | 01a5bf35 | 2014-09-17 22:57:31 | [diff] [blame] | 67 | .IsOccluded(content_rect); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 68 | } |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 69 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 70 | // Gives an unoccluded sub-rect of |content_rect| in the content space of the |
vmpstr | 5b88d99 | 2014-09-18 23:25:04 | [diff] [blame] | 71 | // layer. Simple wrapper around GetUnoccludedContentRect. |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 72 | gfx::Rect UnoccludedLayerContentRect(const LayerImpl* layer, |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 73 | const gfx::Rect& content_rect) const { |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 74 | DCHECK(layer->visible_layer_rect().Contains(content_rect)); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 75 | return this->GetCurrentOcclusionForLayer(layer->DrawTransform()) |
vmpstr | 5b88d99 | 2014-09-18 23:25:04 | [diff] [blame] | 76 | .GetUnoccludedContentRect(content_rect); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 77 | } |
[email protected] | e312aca | 2014-03-20 22:11:55 | [diff] [blame] | 78 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 79 | gfx::Rect UnoccludedSurfaceContentRect(const LayerImpl* layer, |
[email protected] | e312aca | 2014-03-20 22:11:55 | [diff] [blame] | 80 | const gfx::Rect& content_rect) const { |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 81 | const RenderSurfaceImpl* surface = |
| 82 | GetRenderSurface(const_cast<LayerImpl*>(layer)); |
danakj | 206a581 | 2015-02-11 02:07:08 | [diff] [blame] | 83 | return this->GetCurrentOcclusionForContributingSurface( |
| 84 | surface->draw_transform()) |
| 85 | .GetUnoccludedContentRect(content_rect); |
[email protected] | e312aca | 2014-03-20 22:11:55 | [diff] [blame] | 86 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 87 | }; |
| 88 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 89 | class OcclusionTrackerTest : public testing::Test { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 90 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 91 | explicit OcclusionTrackerTest(bool opaque_layers) |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 92 | : opaque_layers_(opaque_layers), |
loyso | 2cb3f32f | 2016-11-08 07:08:34 | [diff] [blame] | 93 | animation_host_(AnimationHost::CreateForTesting(ThreadInstance::MAIN)), |
| 94 | host_(FakeLayerTreeHost::Create(&client_, |
| 95 | &task_graph_runner_, |
| 96 | animation_host_.get())), |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 97 | next_layer_impl_id_(1) {} |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 98 | |
| 99 | virtual void RunMyTest() = 0; |
| 100 | |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 101 | void TearDown() override { DestroyLayers(); } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 102 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 103 | TestContentLayerImpl* CreateRoot(const gfx::Transform& transform, |
| 104 | const gfx::PointF& position, |
| 105 | const gfx::Size& bounds) { |
| 106 | LayerTreeImpl* tree = host_->host_impl()->active_tree(); |
| 107 | int id = next_layer_impl_id_++; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 108 | std::unique_ptr<TestContentLayerImpl> layer( |
| 109 | new TestContentLayerImpl(tree, id)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 110 | TestContentLayerImpl* layer_ptr = layer.get(); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 111 | SetProperties(layer_ptr, transform, position, bounds); |
| 112 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 113 | host_->host_impl()->active_tree()->SetRootLayerForTesting(std::move(layer)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 114 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 115 | layer_ptr->test_properties()->force_render_surface = true; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 116 | SetRootLayerOnMainThread(layer_ptr); |
| 117 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 118 | return layer_ptr; |
| 119 | } |
| 120 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 121 | LayerImpl* CreateLayer(LayerImpl* parent, |
| 122 | const gfx::Transform& transform, |
| 123 | const gfx::PointF& position, |
| 124 | const gfx::Size& bounds) { |
| 125 | LayerTreeImpl* tree = host_->host_impl()->active_tree(); |
| 126 | int id = next_layer_impl_id_++; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 127 | std::unique_ptr<LayerImpl> layer = LayerImpl::Create(tree, id); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 128 | LayerImpl* layer_ptr = layer.get(); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 129 | SetProperties(layer_ptr, transform, position, bounds); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 130 | parent->test_properties()->AddChild(std::move(layer)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 131 | return layer_ptr; |
| 132 | } |
| 133 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 134 | LayerImpl* CreateSurface(LayerImpl* parent, |
| 135 | const gfx::Transform& transform, |
| 136 | const gfx::PointF& position, |
| 137 | const gfx::Size& bounds) { |
| 138 | LayerImpl* layer = CreateLayer(parent, transform, position, bounds); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 139 | layer->test_properties()->force_render_surface = true; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 140 | return layer; |
| 141 | } |
| 142 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 143 | TestContentLayerImpl* CreateDrawingLayer(LayerImpl* parent, |
| 144 | const gfx::Transform& transform, |
| 145 | const gfx::PointF& position, |
| 146 | const gfx::Size& bounds, |
| 147 | bool opaque) { |
| 148 | LayerTreeImpl* tree = host_->host_impl()->active_tree(); |
| 149 | int id = next_layer_impl_id_++; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 150 | std::unique_ptr<TestContentLayerImpl> layer( |
| 151 | new TestContentLayerImpl(tree, id)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 152 | TestContentLayerImpl* layer_ptr = layer.get(); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 153 | SetProperties(layer_ptr, transform, position, bounds); |
| 154 | |
| 155 | if (opaque_layers_) { |
| 156 | layer_ptr->SetContentsOpaque(opaque); |
| 157 | } else { |
| 158 | layer_ptr->SetContentsOpaque(false); |
| 159 | if (opaque) |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 160 | layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 161 | else |
| 162 | layer_ptr->SetOpaqueContentsRect(gfx::Rect()); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 163 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 164 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 165 | parent->test_properties()->AddChild(std::move(layer)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 166 | return layer_ptr; |
| 167 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 168 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 169 | LayerImpl* CreateMaskLayer(LayerImpl* owning_layer, const gfx::Size& bounds) { |
| 170 | LayerTreeImpl* tree = host_->host_impl()->active_tree(); |
| 171 | int id = next_layer_impl_id_++; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 172 | std::unique_ptr<TestContentLayerImpl> layer( |
| 173 | new TestContentLayerImpl(tree, id)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 174 | TestContentLayerImpl* layer_ptr = layer.get(); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 175 | SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 176 | SetMask(owning_layer, std::move(layer)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 177 | return layer_ptr; |
| 178 | } |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 179 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 180 | TestContentLayerImpl* CreateDrawingSurface(LayerImpl* parent, |
| 181 | const gfx::Transform& transform, |
| 182 | const gfx::PointF& position, |
| 183 | const gfx::Size& bounds, |
| 184 | bool opaque) { |
| 185 | TestContentLayerImpl* layer = |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 186 | CreateDrawingLayer(parent, transform, position, bounds, opaque); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 187 | layer->test_properties()->force_render_surface = true; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 188 | return layer; |
| 189 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 190 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 191 | void DestroyLayers() { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 192 | host_->host_impl()->active_tree()->SetRootLayerForTesting(nullptr); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 193 | render_surface_list_impl_.clear(); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 194 | mask_layers_.clear(); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 195 | layer_iterator_.reset(); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 196 | } |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 197 | |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame] | 198 | void CopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {} |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 199 | |
| 200 | void AddCopyRequest(Layer* layer) { |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame] | 201 | layer->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 202 | base::BindOnce(&OcclusionTrackerTest::CopyOutputCallback, |
| 203 | base::Unretained(this)))); |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void AddCopyRequest(LayerImpl* layer) { |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 207 | layer->test_properties()->copy_requests.push_back( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame] | 208 | viz::CopyOutputRequest::CreateBitmapRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 209 | base::BindOnce(&OcclusionTrackerTest::CopyOutputCallback, |
| 210 | base::Unretained(this)))); |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 211 | } |
| 212 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 213 | void CalcDrawEtc(TestContentLayerImpl* root) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 214 | root->layer_tree_impl()->BuildLayerListForTesting(); |
| 215 | DCHECK(root == root->layer_tree_impl()->root_layer_for_testing()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 216 | |
enne | d8d1c5cb | 2015-06-16 19:09:35 | [diff] [blame] | 217 | // These occlusion tests attach and detach layers in multiple |
| 218 | // iterations, so rebuild property trees every time. |
| 219 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 220 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 221 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 222 | root, root->bounds(), &render_surface_list_impl_); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 223 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 224 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 225 | |
Jeremy Roman | 909d927b | 2017-08-27 18:34:09 | [diff] [blame^] | 226 | layer_iterator_ = std::make_unique<EffectTreeLayerListIterator>( |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 227 | host_->host_impl()->active_tree()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 228 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 229 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 230 | void EnterLayer(LayerImpl* layer, OcclusionTracker* occlusion) { |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 231 | ASSERT_EQ(layer_iterator_->current_layer(), layer); |
| 232 | ASSERT_TRUE(layer_iterator_->state() == |
| 233 | EffectTreeLayerListIterator::State::LAYER); |
| 234 | occlusion->EnterLayer(*layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 235 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 236 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 237 | void LeaveLayer(LayerImpl* layer, OcclusionTracker* occlusion) { |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 238 | ASSERT_EQ(layer_iterator_->current_layer(), layer); |
| 239 | ASSERT_TRUE(layer_iterator_->state() == |
| 240 | EffectTreeLayerListIterator::State::LAYER); |
| 241 | occlusion->LeaveLayer(*layer_iterator_); |
| 242 | ++(*layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 243 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 244 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 245 | void VisitLayer(LayerImpl* layer, OcclusionTracker* occlusion) { |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 246 | EnterLayer(layer, occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 247 | LeaveLayer(layer, occlusion); |
| 248 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 249 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 250 | void EnterContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) { |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 251 | ASSERT_EQ(layer_iterator_->target_render_surface(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 252 | GetRenderSurface(layer)); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 253 | ASSERT_TRUE(layer_iterator_->state() == |
| 254 | EffectTreeLayerListIterator::State::TARGET_SURFACE); |
| 255 | occlusion->EnterLayer(*layer_iterator_); |
| 256 | occlusion->LeaveLayer(*layer_iterator_); |
| 257 | ++(*layer_iterator_); |
| 258 | ASSERT_TRUE(layer_iterator_->state() == |
| 259 | EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE); |
| 260 | occlusion->EnterLayer(*layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 261 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 262 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 263 | void LeaveContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) { |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 264 | ASSERT_EQ(layer_iterator_->current_render_surface(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 265 | GetRenderSurface(layer)); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 266 | ASSERT_TRUE(layer_iterator_->state() == |
| 267 | EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE); |
| 268 | occlusion->LeaveLayer(*layer_iterator_); |
| 269 | ++(*layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 270 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 271 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 272 | void VisitContributingSurface(LayerImpl* layer, OcclusionTracker* occlusion) { |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 273 | EnterContributingSurface(layer, occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 274 | LeaveContributingSurface(layer, occlusion); |
| 275 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 276 | |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 277 | void ResetLayerIterator() { |
| 278 | *layer_iterator_ = |
| 279 | EffectTreeLayerListIterator(host_->host_impl()->active_tree()); |
| 280 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 281 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 282 | const gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 283 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 284 | private: |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 285 | void SetRootLayerOnMainThread(Layer* root) { |
| 286 | host_->SetRootLayer(scoped_refptr<Layer>(root)); |
| 287 | } |
| 288 | |
| 289 | void SetRootLayerOnMainThread(LayerImpl* root) {} |
| 290 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 291 | void SetProperties(LayerImpl* layer, |
| 292 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 293 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 294 | const gfx::Size& bounds) { |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 295 | layer->test_properties()->transform = transform; |
danakj | 3b8b2bf | 2015-06-18 03:09:01 | [diff] [blame] | 296 | layer->SetPosition(position); |
| 297 | layer->SetBounds(bounds); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 298 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 299 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 300 | void SetMask(LayerImpl* owning_layer, std::unique_ptr<LayerImpl> layer) { |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 301 | owning_layer->test_properties()->SetMaskLayer(std::move(layer)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 302 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 303 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 304 | bool opaque_layers_; |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 305 | FakeLayerTreeHostClient client_; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 306 | TestTaskGraphRunner task_graph_runner_; |
loyso | 2cb3f32f | 2016-11-08 07:08:34 | [diff] [blame] | 307 | std::unique_ptr<AnimationHost> animation_host_; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 308 | std::unique_ptr<FakeLayerTreeHost> host_; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 309 | // These hold ownership of the layers for the duration of the test. |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 310 | RenderSurfaceList render_surface_list_impl_; |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 311 | std::unique_ptr<EffectTreeLayerListIterator> layer_iterator_; |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 312 | LayerList mask_layers_; |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 313 | int next_layer_impl_id_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 314 | }; |
| 315 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 316 | #define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \ |
| 317 | class ClassName##ImplThreadOpaqueLayers : public ClassName { \ |
| 318 | public: /* NOLINT(whitespace/indent) */ \ |
| 319 | ClassName##ImplThreadOpaqueLayers() : ClassName(true) {} \ |
| 320 | }; \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 321 | TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); } |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 322 | #define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \ |
| 323 | class ClassName##ImplThreadOpaquePaints : public ClassName { \ |
| 324 | public: /* NOLINT(whitespace/indent) */ \ |
| 325 | ClassName##ImplThreadOpaquePaints() : ClassName(false) {} \ |
| 326 | }; \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 327 | TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 328 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 329 | #define ALL_OCCLUSIONTRACKER_TEST(ClassName) \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 330 | RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \ |
| 331 | RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 332 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 333 | class OcclusionTrackerTestIdentityTransforms : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 334 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 335 | explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 336 | : OcclusionTrackerTest(opaque_layers) {} |
[email protected] | ece1d95 | 2012-10-18 21:26:07 | [diff] [blame] | 337 | |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 338 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 339 | TestContentLayerImpl* root = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 340 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 341 | TestContentLayerImpl* parent = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 342 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 343 | TestContentLayerImpl* layer = this->CreateDrawingLayer( |
| 344 | parent, this->identity_matrix, gfx::PointF(30.f, 30.f), |
| 345 | gfx::Size(500, 500), true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 346 | parent->SetMasksToBounds(true); |
| 347 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 348 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 349 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 350 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 351 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 352 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 353 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 354 | EXPECT_EQ(gfx::Rect().ToString(), |
| 355 | occlusion.occlusion_from_outside_target().ToString()); |
| 356 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 357 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 358 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 359 | }; |
| 360 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 361 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 362 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 363 | class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 364 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 365 | explicit OcclusionTrackerTestRotatedChild(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 366 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 367 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 368 | gfx::Transform layer_transform; |
| 369 | layer_transform.Translate(250.0, 250.0); |
| 370 | layer_transform.Rotate(90.0); |
| 371 | layer_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 372 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 373 | TestContentLayerImpl* root = this->CreateRoot( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 374 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 375 | TestContentLayerImpl* parent = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 376 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 377 | TestContentLayerImpl* layer = this->CreateDrawingLayer( |
| 378 | parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500), |
| 379 | true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 380 | parent->SetMasksToBounds(true); |
| 381 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 382 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 383 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 384 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 385 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 386 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 387 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 388 | EXPECT_EQ(gfx::Rect().ToString(), |
| 389 | occlusion.occlusion_from_outside_target().ToString()); |
| 390 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 391 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 392 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 393 | }; |
| 394 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 395 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 396 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 397 | class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 398 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 399 | explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 400 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 401 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 402 | gfx::Transform layer_transform; |
| 403 | layer_transform.Translate(20.0, 20.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 404 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 405 | TestContentLayerImpl* root = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 406 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 407 | TestContentLayerImpl* parent = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 408 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 409 | TestContentLayerImpl* layer = this->CreateDrawingLayer( |
| 410 | parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500), |
| 411 | true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 412 | parent->SetMasksToBounds(true); |
| 413 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 414 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 415 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 416 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 417 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 418 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 419 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 420 | EXPECT_EQ(gfx::Rect().ToString(), |
| 421 | occlusion.occlusion_from_outside_target().ToString()); |
| 422 | EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(), |
| 423 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 424 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 425 | }; |
| 426 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 427 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 428 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 429 | class OcclusionTrackerTestChildInRotatedChild : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 430 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 431 | explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 432 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 433 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 434 | gfx::Transform child_transform; |
| 435 | child_transform.Translate(250.0, 250.0); |
| 436 | child_transform.Rotate(90.0); |
| 437 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 438 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 439 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 440 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 441 | parent->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 442 | LayerImpl* child = this->CreateSurface( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 443 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); |
| 444 | child->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 445 | TestContentLayerImpl* layer = this->CreateDrawingLayer( |
| 446 | child, this->identity_matrix, gfx::PointF(10.f, 10.f), |
| 447 | gfx::Size(500, 500), true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 448 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 449 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 450 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 451 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 452 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 453 | this->EnterContributingSurface(child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 454 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 455 | EXPECT_EQ(gfx::Rect().ToString(), |
| 456 | occlusion.occlusion_from_outside_target().ToString()); |
| 457 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), |
| 458 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 459 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 460 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 461 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 462 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 463 | EXPECT_EQ(gfx::Rect().ToString(), |
| 464 | occlusion.occlusion_from_outside_target().ToString()); |
| 465 | EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), |
| 466 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 467 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 468 | /* Justification for the above occlusion from |layer|: |
| 469 | 100 |
| 470 | +---------------------+ |
| 471 | | | |
| 472 | | 30 | rotate(90) |
| 473 | | 30 + ---------------------------------+ |
| 474 | 100 | | 10 | | ==> |
| 475 | | |10+---------------------------------+ |
| 476 | | | | | | | |
| 477 | | | | | | | |
| 478 | | | | | | | |
| 479 | +----|--|-------------+ | | |
| 480 | | | | | |
| 481 | | | | | |
| 482 | | | | |500 |
| 483 | | | | | |
| 484 | | | | | |
| 485 | | | | | |
| 486 | | | | | |
| 487 | +--|-------------------------------+ | |
| 488 | | | |
| 489 | +---------------------------------+ |
| 490 | 500 |
| 491 | |
| 492 | +---------------------+ |
| 493 | | |30 Visible region of |layer|: ///// |
| 494 | | | |
| 495 | | +---------------------------------+ |
| 496 | 100| | |10 | |
| 497 | | +---------------------------------+ | |
| 498 | | | |///////////////| 420 | | |
| 499 | | | |///////////////|60 | | |
| 500 | | | |///////////////| | | |
| 501 | +--|--|---------------+ | | |
| 502 | 20|10| 70 | | |
| 503 | | | | | |
| 504 | | | | | |
| 505 | | | | | |
| 506 | | | | | |
| 507 | | | | | |
| 508 | | | |10| |
| 509 | | +------------------------------|--+ |
| 510 | | 490 | |
| 511 | +---------------------------------+ |
| 512 | 500 |
| 513 | |
| 514 | */ |
| 515 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 516 | }; |
| 517 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 518 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 519 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 520 | class OcclusionTrackerTestScaledRenderSurface : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 521 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 522 | explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 523 | : OcclusionTrackerTest(opaque_layers) {} |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 524 | |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 525 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 526 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 527 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 528 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 529 | gfx::Transform layer1_matrix; |
| 530 | layer1_matrix.Scale(2.0, 2.0); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 531 | TestContentLayerImpl* layer1 = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 532 | parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 533 | layer1->test_properties()->force_render_surface = true; |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 534 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 535 | gfx::Transform layer2_matrix; |
| 536 | layer2_matrix.Translate(25.0, 25.0); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 537 | TestContentLayerImpl* layer2 = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 538 | layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 539 | TestContentLayerImpl* occluder = this->CreateDrawingLayer( |
| 540 | parent, this->identity_matrix, gfx::PointF(100.f, 100.f), |
| 541 | gfx::Size(500, 500), true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 542 | this->CalcDrawEtc(parent); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 543 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 544 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 545 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 546 | this->VisitLayer(occluder, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 547 | this->EnterLayer(layer2, &occlusion); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 548 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 549 | EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), |
| 550 | occlusion.occlusion_from_outside_target().ToString()); |
| 551 | EXPECT_EQ(gfx::Rect().ToString(), |
| 552 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 553 | } |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 554 | }; |
| 555 | |
| 556 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface); |
| 557 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 558 | class OcclusionTrackerTestVisitTargetTwoTimes : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 559 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 560 | explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 561 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 562 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 563 | TestContentLayerImpl* root = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 564 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 565 | LayerImpl* surface = this->CreateSurface( |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 566 | root, this->identity_matrix, gfx::PointF(30.f, 30.f), gfx::Size()); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 567 | TestContentLayerImpl* surface_child = this->CreateDrawingLayer( |
| 568 | surface, this->identity_matrix, gfx::PointF(10.f, 10.f), |
| 569 | gfx::Size(50, 50), true); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 570 | // |top_layer| makes |root|'s surface get considered by OcclusionTracker |
| 571 | // first, instead of |surface|'s. This exercises different code in |
| 572 | // LeaveToRenderTarget, as the target surface has already been seen when |
| 573 | // leaving |surface| later. |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 574 | TestContentLayerImpl* top_layer = this->CreateDrawingLayer( |
| 575 | root, this->identity_matrix, gfx::PointF(40.f, 90.f), gfx::Size(50, 20), |
| 576 | true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 577 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 578 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 579 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 580 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 581 | this->VisitLayer(top_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 582 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 583 | EXPECT_EQ(gfx::Rect().ToString(), |
| 584 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 585 | EXPECT_EQ(gfx::Rect(40, 90, 50, 20).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 586 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 587 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 588 | this->VisitLayer(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 589 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 590 | EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 591 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 592 | EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 593 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 594 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 595 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 596 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 597 | EXPECT_EQ(gfx::Rect(10, 60, 50, 20).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 598 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 599 | EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 600 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 601 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 602 | // Occlusion from |top_layer| already in the root target should get merged |
| 603 | // with the occlusion from the |surface| we are leaving now. |
| 604 | this->LeaveContributingSurface(surface, &occlusion); |
| 605 | this->EnterLayer(root, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 606 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 607 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 608 | EXPECT_EQ(gfx::Rect(40, 40, 50, 70).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 609 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 610 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 611 | }; |
| 612 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 613 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 614 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 615 | class OcclusionTrackerTestSurfaceRotatedOffAxis : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 616 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 617 | explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 618 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 619 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 620 | gfx::Transform child_transform; |
| 621 | child_transform.Translate(250.0, 250.0); |
| 622 | child_transform.Rotate(95.0); |
| 623 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 624 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 625 | gfx::Transform layer_transform; |
| 626 | layer_transform.Translate(10.0, 10.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 627 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 628 | TestContentLayerImpl* root = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 629 | this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 630 | TestContentLayerImpl* parent = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 631 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 632 | LayerImpl* child = this->CreateSurface( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 633 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 634 | TestContentLayerImpl* layer = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 635 | child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true); |
| 636 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 637 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 638 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 639 | |
[email protected] | 8a82269 | 2014-02-12 17:30:55 | [diff] [blame] | 640 | gfx::Rect clipped_layer_in_child = MathUtil::MapEnclosingClippedRect( |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 641 | layer_transform, layer->visible_layer_rect()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 642 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 643 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 644 | this->EnterContributingSurface(child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 645 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 646 | EXPECT_EQ(gfx::Rect().ToString(), |
| 647 | occlusion.occlusion_from_outside_target().ToString()); |
| 648 | EXPECT_EQ(clipped_layer_in_child.ToString(), |
| 649 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 650 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 651 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 652 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 653 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 654 | EXPECT_EQ(gfx::Rect().ToString(), |
| 655 | occlusion.occlusion_from_outside_target().ToString()); |
| 656 | EXPECT_EQ(gfx::Rect().ToString(), |
| 657 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 658 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 659 | }; |
| 660 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 661 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 662 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 663 | class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 664 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 665 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 666 | explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 667 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 668 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 669 | gfx::Transform child_transform; |
| 670 | child_transform.Translate(250.0, 250.0); |
| 671 | child_transform.Rotate(90.0); |
| 672 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 673 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 674 | TestContentLayerImpl* root = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 675 | this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 676 | TestContentLayerImpl* parent = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 677 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 678 | parent->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 679 | TestContentLayerImpl* child = this->CreateDrawingSurface( |
| 680 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500), |
| 681 | false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 682 | child->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 683 | TestContentLayerImpl* layer1 = this->CreateDrawingLayer( |
| 684 | child, this->identity_matrix, gfx::PointF(10.f, 10.f), |
| 685 | gfx::Size(500, 500), true); |
| 686 | TestContentLayerImpl* layer2 = this->CreateDrawingLayer( |
| 687 | child, this->identity_matrix, gfx::PointF(10.f, 450.f), |
| 688 | gfx::Size(500, 60), true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 689 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 690 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 691 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 692 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 693 | this->VisitLayer(layer2, &occlusion); |
| 694 | this->VisitLayer(layer1, &occlusion); |
| 695 | this->VisitLayer(child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 696 | this->EnterContributingSurface(child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 697 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 698 | EXPECT_EQ(gfx::Rect().ToString(), |
| 699 | occlusion.occlusion_from_outside_target().ToString()); |
| 700 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), |
| 701 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 702 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 703 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 704 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 705 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 706 | EXPECT_EQ(gfx::Rect().ToString(), |
| 707 | occlusion.occlusion_from_outside_target().ToString()); |
| 708 | EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), |
| 709 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 710 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 711 | /* Justification for the above occlusion from |layer1| and |layer2|: |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 712 | |
| 713 | +---------------------+ |
| 714 | | |30 Visible region of |layer1|: ///// |
| 715 | | | Visible region of |layer2|: \\\\\ |
| 716 | | +---------------------------------+ |
| 717 | | | |10 | |
| 718 | | +---------------+-----------------+ | |
| 719 | | | |\\\\\\\\\\\\|//| 420 | | |
| 720 | | | |\\\\\\\\\\\\|//|60 | | |
| 721 | | | |\\\\\\\\\\\\|//| | | |
| 722 | +--|--|------------|--+ | | |
| 723 | 20|10| 70 | | | |
| 724 | | | | | | |
| 725 | | | | | | |
| 726 | | | | | | |
| 727 | | | | | | |
| 728 | | | | | | |
| 729 | | | | |10| |
| 730 | | +------------|-----------------|--+ |
| 731 | | | 490 | |
| 732 | +---------------+-----------------+ |
| 733 | 60 440 |
| 734 | */ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 735 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 736 | }; |
| 737 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 738 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 739 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 740 | class OcclusionTrackerTestOverlappingSurfaceSiblings |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 741 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 742 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 743 | explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 744 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 745 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 746 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 747 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 748 | parent->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 749 | LayerImpl* child1 = this->CreateSurface( |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 750 | parent, this->identity_matrix, gfx::PointF(10.f, 0.f), gfx::Size()); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 751 | LayerImpl* child2 = this->CreateSurface( |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 752 | parent, this->identity_matrix, gfx::PointF(30.f, 0.f), gfx::Size()); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 753 | TestContentLayerImpl* layer1 = this->CreateDrawingLayer( |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 754 | child1, this->identity_matrix, gfx::PointF(), gfx::Size(40, 50), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 755 | TestContentLayerImpl* layer2 = this->CreateDrawingLayer( |
| 756 | child2, this->identity_matrix, gfx::PointF(10.f, 0.f), |
| 757 | gfx::Size(40, 50), true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 758 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 759 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 760 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 761 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 762 | this->VisitLayer(layer2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 763 | this->EnterContributingSurface(child2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 764 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 765 | // layer2's occlusion. |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 766 | EXPECT_EQ(gfx::Rect().ToString(), |
| 767 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 768 | EXPECT_EQ(gfx::Rect(10, 0, 40, 50).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 769 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 770 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 771 | this->LeaveContributingSurface(child2, &occlusion); |
| 772 | this->VisitLayer(layer1, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 773 | this->EnterContributingSurface(child1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 774 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 775 | // layer2's occlusion in the target space of layer1. |
| 776 | EXPECT_EQ(gfx::Rect(30, 0, 40, 50).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 777 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 778 | // layer1's occlusion. |
| 779 | EXPECT_EQ(gfx::Rect(0, 0, 40, 50).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 780 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 781 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 782 | this->LeaveContributingSurface(child1, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 783 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 784 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 785 | // The occlusion from from layer1 and layer2 is merged. |
| 786 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 787 | EXPECT_EQ(gfx::Rect(10, 0, 70, 50).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 788 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 789 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 790 | }; |
| 791 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 792 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 793 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 794 | class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 795 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 796 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 797 | explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 798 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 799 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 800 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 801 | gfx::Transform child1_transform; |
| 802 | child1_transform.Translate(250.0, 250.0); |
| 803 | child1_transform.Rotate(-90.0); |
| 804 | child1_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 805 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 806 | gfx::Transform child2_transform; |
| 807 | child2_transform.Translate(250.0, 250.0); |
| 808 | child2_transform.Rotate(90.0); |
| 809 | child2_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 810 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 811 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 812 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 813 | parent->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 814 | LayerImpl* child1 = this->CreateSurface( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 815 | parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 816 | LayerImpl* child2 = this->CreateDrawingSurface(parent, child2_transform, |
| 817 | gfx::PointF(20.f, 40.f), |
| 818 | gfx::Size(10, 10), false); |
| 819 | TestContentLayerImpl* layer1 = this->CreateDrawingLayer( |
| 820 | child1, this->identity_matrix, gfx::PointF(-10.f, -20.f), |
| 821 | gfx::Size(510, 510), true); |
| 822 | TestContentLayerImpl* layer2 = this->CreateDrawingLayer( |
| 823 | child2, this->identity_matrix, gfx::PointF(-10.f, -10.f), |
| 824 | gfx::Size(510, 510), true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 825 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 826 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 827 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 828 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 829 | this->VisitLayer(layer2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 830 | this->EnterLayer(child2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 831 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 832 | EXPECT_EQ(gfx::Rect().ToString(), |
| 833 | occlusion.occlusion_from_outside_target().ToString()); |
| 834 | EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), |
| 835 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 836 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 837 | this->LeaveLayer(child2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 838 | this->EnterContributingSurface(child2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 839 | |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 840 | EXPECT_EQ(gfx::Rect().ToString(), |
| 841 | occlusion.occlusion_from_outside_target().ToString()); |
| 842 | EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), |
| 843 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 844 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 845 | this->LeaveContributingSurface(child2, &occlusion); |
| 846 | this->VisitLayer(layer1, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 847 | this->EnterContributingSurface(child1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 848 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 849 | EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(), |
| 850 | occlusion.occlusion_from_outside_target().ToString()); |
| 851 | EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(), |
| 852 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 853 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 854 | this->LeaveContributingSurface(child1, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 855 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 856 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 857 | EXPECT_EQ(gfx::Rect().ToString(), |
| 858 | occlusion.occlusion_from_outside_target().ToString()); |
| 859 | EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), |
| 860 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 861 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 862 | /* Justification for the above occlusion: |
| 863 | 100 |
| 864 | +---------------------+ |
| 865 | |20 | layer1 |
| 866 | 10+----------------------------------+ |
| 867 | 100 || 30 | layer2 | |
| 868 | |20+----------------------------------+ |
| 869 | || | | | | |
| 870 | || | | | | |
| 871 | || | | | | |
| 872 | +|-|------------------+ | | |
| 873 | | | | | 510 |
| 874 | | | 510 | | |
| 875 | | | | | |
| 876 | | | | | |
| 877 | | | | | |
| 878 | | | | | |
| 879 | | | 520 | | |
| 880 | +----------------------------------+ | |
| 881 | | | |
| 882 | +----------------------------------+ |
| 883 | 510 |
| 884 | */ |
| 885 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 886 | }; |
| 887 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 888 | ALL_OCCLUSIONTRACKER_TEST( |
| 889 | OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 890 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 891 | class OcclusionTrackerTestFilters : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 892 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 893 | explicit OcclusionTrackerTestFilters(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 894 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 895 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 896 | gfx::Transform layer_transform; |
| 897 | layer_transform.Translate(250.0, 250.0); |
| 898 | layer_transform.Rotate(90.0); |
| 899 | layer_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 900 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 901 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 902 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 903 | parent->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 904 | TestContentLayerImpl* blur_layer = this->CreateDrawingLayer( |
| 905 | parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500), |
| 906 | true); |
| 907 | TestContentLayerImpl* opaque_layer = this->CreateDrawingLayer( |
| 908 | parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500), |
| 909 | true); |
| 910 | TestContentLayerImpl* opacity_layer = this->CreateDrawingLayer( |
| 911 | parent, layer_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500), |
| 912 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 913 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 914 | blur_layer->test_properties()->force_render_surface = true; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 915 | FilterOperations filters; |
| 916 | filters.Append(FilterOperation::CreateBlurFilter(10.f)); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 917 | blur_layer->test_properties()->filters = filters; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 918 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 919 | opaque_layer->test_properties()->force_render_surface = true; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 920 | filters.Clear(); |
| 921 | filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 922 | opaque_layer->test_properties()->filters = filters; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 923 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 924 | opacity_layer->test_properties()->force_render_surface = true; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 925 | filters.Clear(); |
| 926 | filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 927 | opacity_layer->test_properties()->filters = filters; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 928 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 929 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 930 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 931 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 932 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 933 | // Opacity layer won't contribute to occlusion. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 934 | this->VisitLayer(opacity_layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 935 | this->EnterContributingSurface(opacity_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 936 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 937 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 938 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 939 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 940 | // And has nothing to contribute to its parent surface. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 941 | this->LeaveContributingSurface(opacity_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 942 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 943 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 944 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 945 | // Opaque layer will contribute to occlusion. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 946 | this->VisitLayer(opaque_layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 947 | this->EnterContributingSurface(opaque_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 948 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 949 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 950 | EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(), |
| 951 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 952 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 953 | // And it gets translated to the parent surface. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 954 | this->LeaveContributingSurface(opaque_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 955 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 956 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 957 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 958 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 959 | // The blur layer needs to throw away any occlusion from outside its |
| 960 | // subtree. |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 961 | this->EnterLayer(blur_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 962 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 963 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 964 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 965 | // And it won't contribute to occlusion. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 966 | this->LeaveLayer(blur_layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 967 | this->EnterContributingSurface(blur_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 968 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 969 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 970 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 971 | // But the opaque layer's occlusion is preserved on the parent. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 972 | this->LeaveContributingSurface(blur_layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 973 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 974 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 975 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 976 | occlusion.occlusion_from_inside_target().ToString()); |
| 977 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 978 | }; |
| 979 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 980 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 981 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 982 | class OcclusionTrackerTestOpaqueContentsRegionEmpty |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 983 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 984 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 985 | explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 986 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 987 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 988 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 989 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 990 | TestContentLayerImpl* layer = |
| 991 | this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(), |
| 992 | gfx::Size(200, 200), false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 993 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 994 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 995 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 996 | this->EnterLayer(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 997 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 998 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 999 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1000 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1001 | this->LeaveLayer(layer, &occlusion); |
| 1002 | this->VisitContributingSurface(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1003 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1004 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1005 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1006 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1007 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1008 | }; |
| 1009 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1010 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1011 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1012 | class OcclusionTrackerTestOpaqueContentsRegionNonEmpty |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1013 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1014 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1015 | explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1016 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1017 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1018 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1019 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1020 | TestContentLayerImpl* layer = this->CreateDrawingLayer( |
| 1021 | parent, this->identity_matrix, gfx::PointF(100.f, 100.f), |
| 1022 | gfx::Size(200, 200), false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1023 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1024 | { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1025 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1026 | layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1027 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1028 | this->ResetLayerIterator(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1029 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1030 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1031 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1032 | EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), |
| 1033 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1034 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1035 | { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1036 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1037 | layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180)); |
| 1038 | |
| 1039 | this->ResetLayerIterator(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1040 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1041 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1042 | |
| 1043 | EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(), |
| 1044 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1045 | } |
| 1046 | { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1047 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1048 | layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100)); |
| 1049 | |
| 1050 | this->ResetLayerIterator(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1051 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1052 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1053 | |
| 1054 | EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(), |
| 1055 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1056 | } |
| 1057 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1058 | }; |
| 1059 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1060 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1061 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1062 | class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1063 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1064 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1065 | explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude( |
| 1066 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1067 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1068 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1069 | gfx::Transform transform; |
| 1070 | transform.Translate(50.0, 50.0); |
| 1071 | transform.ApplyPerspectiveDepth(100.0); |
| 1072 | transform.Translate3d(0.0, 0.0, 110.0); |
| 1073 | transform.Translate(-50.0, -50.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1074 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1075 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1076 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1077 | TestContentLayerImpl* layer = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1078 | parent, transform, gfx::PointF(), gfx::Size(100, 100), true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1079 | parent->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 1080 | parent->test_properties()->sorting_context_id = 1; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1081 | layer->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 1082 | layer->test_properties()->sorting_context_id = 1; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1083 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1084 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1085 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1086 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1087 | // The |layer| is entirely behind the camera and should not occlude. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1088 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1089 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1090 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
| 1091 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1092 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1093 | }; |
| 1094 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1095 | class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1096 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1097 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1098 | explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent( |
| 1099 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1100 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1101 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1102 | gfx::Transform surface_transform; |
| 1103 | surface_transform.Translate(300.0, 300.0); |
| 1104 | surface_transform.Scale(2.0, 2.0); |
| 1105 | surface_transform.Translate(-150.0, -150.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1106 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1107 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1108 | this->identity_matrix, gfx::PointF(), gfx::Size(500, 500)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1109 | TestContentLayerImpl* surface = this->CreateDrawingSurface( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1110 | parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1111 | TestContentLayerImpl* surface2 = this->CreateDrawingSurface( |
| 1112 | parent, this->identity_matrix, gfx::PointF(50.f, 50.f), |
| 1113 | gfx::Size(300, 300), false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1114 | surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200)); |
| 1115 | surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200)); |
| 1116 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1117 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1118 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1119 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1120 | this->VisitLayer(surface2, &occlusion); |
| 1121 | this->VisitContributingSurface(surface2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1122 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1123 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1124 | occlusion.occlusion_from_outside_target().ToString()); |
| 1125 | EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(), |
| 1126 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1127 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1128 | // Clear any stored occlusion. |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1129 | occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion()); |
| 1130 | occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1131 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1132 | this->VisitLayer(surface, &occlusion); |
| 1133 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1134 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1135 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1136 | occlusion.occlusion_from_outside_target().ToString()); |
| 1137 | EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(), |
| 1138 | occlusion.occlusion_from_inside_target().ToString()); |
| 1139 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1140 | }; |
| 1141 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1142 | ALL_OCCLUSIONTRACKER_TEST( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1143 | OcclusionTrackerTestSurfaceOcclusionTranslatesToParent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1144 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1145 | class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1146 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1147 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1148 | explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping( |
| 1149 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1150 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1151 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1152 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1153 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1154 | parent->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1155 | TestContentLayerImpl* surface = |
| 1156 | this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(), |
| 1157 | gfx::Size(500, 300), false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1158 | surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200)); |
| 1159 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1160 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1161 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1162 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1163 | this->VisitLayer(surface, &occlusion); |
| 1164 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1165 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1166 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1167 | occlusion.occlusion_from_outside_target().ToString()); |
| 1168 | EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(), |
| 1169 | occlusion.occlusion_from_inside_target().ToString()); |
| 1170 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1171 | }; |
| 1172 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1173 | ALL_OCCLUSIONTRACKER_TEST( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1174 | OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1175 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1176 | class OcclusionTrackerTestSurfaceChildOfSurface : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1177 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1178 | explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1179 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1180 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1181 | // This test verifies that the surface cliprect does not end up empty and |
| 1182 | // clip away the entire unoccluded rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1183 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1184 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1185 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1186 | LayerImpl* surface = |
| 1187 | this->CreateDrawingSurface(parent, this->identity_matrix, gfx::PointF(), |
| 1188 | gfx::Size(100, 100), false); |
| 1189 | LayerImpl* surface_child = this->CreateDrawingSurface( |
| 1190 | surface, this->identity_matrix, gfx::PointF(0.f, 10.f), |
| 1191 | gfx::Size(100, 50), true); |
| 1192 | LayerImpl* topmost = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1193 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true); |
| 1194 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1195 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1196 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(-100, -100, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1197 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1198 | // |topmost| occludes everything partially so we know occlusion is happening |
| 1199 | // at all. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1200 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1201 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1202 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1203 | occlusion.occlusion_from_outside_target().ToString()); |
| 1204 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 1205 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1206 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1207 | this->VisitLayer(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1208 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1209 | // surface_child increases the occlusion in the screen by a narrow sliver. |
| 1210 | EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(), |
| 1211 | occlusion.occlusion_from_outside_target().ToString()); |
| 1212 | // In its own surface, surface_child is at 0,0 as is its occlusion. |
| 1213 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 1214 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1215 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1216 | // The root layer always has a clip rect. So the parent of |surface| has a |
| 1217 | // clip rect. However, the owning layer for |surface| does not mask to |
| 1218 | // bounds, so it doesn't have a clip rect of its own. Thus the parent of |
| 1219 | // |surface_child| exercises different code paths as its parent does not |
| 1220 | // have a clip rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1221 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1222 | this->EnterContributingSurface(surface_child, &occlusion); |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 1223 | // The |surface_child| can't occlude its own surface, but occlusion from |
| 1224 | // |topmost| can. |
| 1225 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1226 | occlusion.occlusion_on_contributing_surface_from_outside_target() |
| 1227 | .ToString()); |
| 1228 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 1229 | occlusion.occlusion_on_contributing_surface_from_inside_target() |
| 1230 | .ToString()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1231 | this->LeaveContributingSurface(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1232 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1233 | // When the surface_child's occlusion is transformed up to its parent, make |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 1234 | // sure it is not clipped away inappropriately. |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1235 | this->EnterLayer(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1236 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 1237 | occlusion.occlusion_from_outside_target().ToString()); |
| 1238 | EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(), |
| 1239 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1240 | this->LeaveLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1241 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1242 | this->EnterContributingSurface(surface, &occlusion); |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 1243 | // The occlusion from inside |surface| can't affect the surface, but |
| 1244 | // |topmost| can. |
| 1245 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1246 | occlusion.occlusion_on_contributing_surface_from_outside_target() |
| 1247 | .ToString()); |
| 1248 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 1249 | occlusion.occlusion_on_contributing_surface_from_inside_target() |
| 1250 | .ToString()); |
| 1251 | |
| 1252 | this->LeaveContributingSurface(surface, &occlusion); |
| 1253 | this->EnterLayer(parent, &occlusion); |
| 1254 | // The occlusion in |surface| and without are merged into the parent. |
| 1255 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1256 | occlusion.occlusion_from_outside_target().ToString()); |
| 1257 | EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(), |
| 1258 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1259 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1260 | }; |
| 1261 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1262 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1263 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1264 | class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1265 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1266 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1267 | explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1268 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1269 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1270 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1271 | gfx::Transform scale_by_half; |
| 1272 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1273 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1274 | FilterOperations filters; |
| 1275 | filters.Append(FilterOperation::CreateBlurFilter(10.f)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1276 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1277 | enum Direction { |
| 1278 | LEFT, |
| 1279 | RIGHT, |
| 1280 | TOP, |
| 1281 | BOTTOM, |
| 1282 | LAST_DIRECTION = BOTTOM, |
| 1283 | }; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1284 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1285 | for (int i = 0; i <= LAST_DIRECTION; ++i) { |
| 1286 | SCOPED_TRACE(i); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1287 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1288 | // Make a 50x50 filtered surface that is adjacent to occluding layers |
| 1289 | // which are above it in the z-order in various configurations. The |
| 1290 | // surface is scaled to test that the pixel moving is done in the target |
| 1291 | // space, where the background filter is applied. |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1292 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1293 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1294 | LayerImpl* filtered_surface = this->CreateDrawingLayer( |
| 1295 | parent, scale_by_half, gfx::PointF(50.f, 50.f), gfx::Size(100, 100), |
| 1296 | false); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1297 | filtered_surface->test_properties()->background_filters = filters; |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1298 | gfx::Rect occlusion_rect; |
| 1299 | switch (i) { |
| 1300 | case LEFT: |
| 1301 | occlusion_rect = gfx::Rect(0, 0, 50, 200); |
| 1302 | break; |
| 1303 | case RIGHT: |
jbroman | 19a18b1 | 2016-07-07 02:37:38 | [diff] [blame] | 1304 | // This is the right edge; filtered_surface is scaled by half. |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1305 | occlusion_rect = gfx::Rect(100, 0, 50, 200); |
| 1306 | break; |
| 1307 | case TOP: |
| 1308 | occlusion_rect = gfx::Rect(0, 0, 200, 50); |
| 1309 | break; |
| 1310 | case BOTTOM: |
jbroman | 19a18b1 | 2016-07-07 02:37:38 | [diff] [blame] | 1311 | // This is the bottom edge; filtered_surface is scaled by half. |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1312 | occlusion_rect = gfx::Rect(0, 100, 200, 50); |
| 1313 | break; |
| 1314 | } |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 1315 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1316 | LayerImpl* occluding_layer = this->CreateDrawingLayer( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 1317 | parent, this->identity_matrix, gfx::PointF(occlusion_rect.origin()), |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1318 | occlusion_rect.size(), true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1319 | occluding_layer->test_properties()->force_render_surface = false; |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1320 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1321 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1322 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1323 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1324 | // This layer occludes pixels directly beside the filtered_surface. |
| 1325 | // Because filtered surface blends pixels in a radius, it will need to see |
| 1326 | // some of the pixels (up to radius far) underneath the occluding layers. |
| 1327 | this->VisitLayer(occluding_layer, &occlusion); |
[email protected] | ccb1c9a | 2012-12-17 03:53:19 | [diff] [blame] | 1328 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1329 | EXPECT_EQ(occlusion_rect.ToString(), |
| 1330 | occlusion.occlusion_from_inside_target().ToString()); |
| 1331 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1332 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1333 | this->VisitLayer(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1334 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1335 | // The occlusion is used fully inside the surface. |
| 1336 | gfx::Rect occlusion_inside_surface = |
| 1337 | occlusion_rect - gfx::Vector2d(50, 50); |
| 1338 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
| 1339 | EXPECT_EQ(occlusion_inside_surface.ToString(), |
| 1340 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 1341 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1342 | // The surface has a background blur, so it needs pixels that are |
jbroman | 19a18b1 | 2016-07-07 02:37:38 | [diff] [blame] | 1343 | // currently considered occluded in order to be drawn. The pixels it |
| 1344 | // needs should be removed from the occluded area, so that they are drawn |
| 1345 | // when we get to the parent. |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1346 | this->VisitContributingSurface(filtered_surface, &occlusion); |
| 1347 | this->EnterLayer(parent, &occlusion); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 1348 | |
jbroman | 56c1f9c | 2016-07-06 19:08:10 | [diff] [blame] | 1349 | // The spread due to a 10px blur is 30px. |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1350 | gfx::Rect expected_occlusion = occlusion_rect; |
| 1351 | switch (i) { |
| 1352 | case LEFT: |
jbroman | 56c1f9c | 2016-07-06 19:08:10 | [diff] [blame] | 1353 | expected_occlusion.Inset(0, 0, 30, 0); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1354 | break; |
| 1355 | case RIGHT: |
jbroman | 56c1f9c | 2016-07-06 19:08:10 | [diff] [blame] | 1356 | expected_occlusion.Inset(30, 0, 0, 0); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1357 | break; |
| 1358 | case TOP: |
jbroman | 56c1f9c | 2016-07-06 19:08:10 | [diff] [blame] | 1359 | expected_occlusion.Inset(0, 0, 0, 30); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1360 | break; |
| 1361 | case BOTTOM: |
jbroman | 56c1f9c | 2016-07-06 19:08:10 | [diff] [blame] | 1362 | expected_occlusion.Inset(0, 30, 0, 0); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1363 | break; |
| 1364 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1365 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1366 | EXPECT_EQ(expected_occlusion.ToString(), |
| 1367 | occlusion.occlusion_from_inside_target().ToString()); |
| 1368 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1369 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1370 | this->DestroyLayers(); |
| 1371 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1372 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1373 | }; |
| 1374 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1375 | ALL_OCCLUSIONTRACKER_TEST( |
| 1376 | OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1377 | |
ajuma | 97755536 | 2016-07-19 16:12:12 | [diff] [blame] | 1378 | class OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter |
jbroman | 19a18b1 | 2016-07-07 02:37:38 | [diff] [blame] | 1379 | : public OcclusionTrackerTest { |
| 1380 | protected: |
ajuma | 97755536 | 2016-07-19 16:12:12 | [diff] [blame] | 1381 | explicit OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter( |
jbroman | 19a18b1 | 2016-07-07 02:37:38 | [diff] [blame] | 1382 | bool opaque_layers) |
| 1383 | : OcclusionTrackerTest(opaque_layers) {} |
| 1384 | void RunMyTest() override { |
| 1385 | gfx::Transform scale_by_half; |
| 1386 | scale_by_half.Scale(0.5, 0.5); |
| 1387 | |
| 1388 | FilterOperations filters; |
| 1389 | filters.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(10, 10), |
| 1390 | 5, SK_ColorBLACK)); |
| 1391 | |
| 1392 | enum Direction { |
| 1393 | LEFT, |
| 1394 | RIGHT, |
| 1395 | TOP, |
| 1396 | BOTTOM, |
| 1397 | LAST_DIRECTION = BOTTOM, |
| 1398 | }; |
| 1399 | |
| 1400 | for (int i = 0; i <= LAST_DIRECTION; ++i) { |
| 1401 | SCOPED_TRACE(i); |
| 1402 | |
| 1403 | // Make a 50x50 filtered surface that is adjacent to occluding layers |
| 1404 | // which are above it in the z-order in various configurations. The |
| 1405 | // surface is scaled to test that the pixel moving is done in the target |
| 1406 | // space, where the background filter is applied. |
| 1407 | TestContentLayerImpl* parent = this->CreateRoot( |
| 1408 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 1409 | LayerImpl* filtered_surface = this->CreateDrawingLayer( |
| 1410 | parent, scale_by_half, gfx::PointF(50.f, 50.f), gfx::Size(100, 100), |
| 1411 | false); |
| 1412 | filtered_surface->test_properties()->background_filters = filters; |
| 1413 | gfx::Rect occlusion_rect; |
| 1414 | switch (i) { |
| 1415 | case LEFT: |
| 1416 | occlusion_rect = gfx::Rect(0, 0, 50, 200); |
| 1417 | break; |
| 1418 | case RIGHT: |
| 1419 | // This is the right edge; filtered_surface is scaled by half. |
| 1420 | occlusion_rect = gfx::Rect(100, 0, 50, 200); |
| 1421 | break; |
| 1422 | case TOP: |
| 1423 | occlusion_rect = gfx::Rect(0, 0, 200, 50); |
| 1424 | break; |
| 1425 | case BOTTOM: |
| 1426 | // This is the bottom edge; filtered_surface is scaled by half. |
| 1427 | occlusion_rect = gfx::Rect(0, 100, 200, 50); |
| 1428 | break; |
| 1429 | } |
| 1430 | |
| 1431 | LayerImpl* occluding_layer = this->CreateDrawingLayer( |
| 1432 | parent, this->identity_matrix, gfx::PointF(occlusion_rect.origin()), |
| 1433 | occlusion_rect.size(), true); |
| 1434 | occluding_layer->test_properties()->force_render_surface = false; |
| 1435 | this->CalcDrawEtc(parent); |
| 1436 | |
| 1437 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200)); |
| 1438 | |
| 1439 | // This layer occludes pixels directly beside the filtered_surface. |
| 1440 | // Because filtered surface blends pixels in a radius, it will need to see |
| 1441 | // some of the pixels (up to radius far) underneath the occluding layers. |
| 1442 | this->VisitLayer(occluding_layer, &occlusion); |
| 1443 | |
| 1444 | EXPECT_EQ(occlusion_rect.ToString(), |
| 1445 | occlusion.occlusion_from_inside_target().ToString()); |
| 1446 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1447 | |
| 1448 | this->VisitLayer(filtered_surface, &occlusion); |
| 1449 | |
| 1450 | // The occlusion is used fully inside the surface. |
| 1451 | gfx::Rect occlusion_inside_surface = |
| 1452 | occlusion_rect - gfx::Vector2d(50, 50); |
| 1453 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
| 1454 | EXPECT_EQ(occlusion_inside_surface.ToString(), |
| 1455 | occlusion.occlusion_from_outside_target().ToString()); |
| 1456 | |
| 1457 | // The surface has a background filter, so it needs pixels that are |
| 1458 | // currently considered occluded in order to be drawn. The pixels it |
| 1459 | // needs should be removed from the occluded area, so that they are drawn |
| 1460 | // when we get to the parent. |
| 1461 | this->VisitContributingSurface(filtered_surface, &occlusion); |
| 1462 | this->EnterLayer(parent, &occlusion); |
| 1463 | |
| 1464 | gfx::Rect expected_occlusion; |
| 1465 | switch (i) { |
| 1466 | case LEFT: |
| 1467 | // The right half of the occlusion is close enough to cast a shadow |
| 1468 | // that would be visible in the background filter. The shadow reaches |
| 1469 | // 3*5 + 10 = 25 pixels to the right. |
| 1470 | expected_occlusion = gfx::Rect(0, 0, 25, 200); |
| 1471 | break; |
| 1472 | case RIGHT: |
| 1473 | // The shadow spreads 3*5 - 10 = 5 pixels to the left, so the |
| 1474 | // occlusion must recede by 5 to account for that. |
| 1475 | expected_occlusion = gfx::Rect(105, 0, 45, 200); |
| 1476 | break; |
| 1477 | case TOP: |
| 1478 | // Similar to LEFT. |
| 1479 | expected_occlusion = gfx::Rect(0, 0, 200, 25); |
| 1480 | break; |
| 1481 | case BOTTOM: |
| 1482 | // Similar to RIGHT. |
| 1483 | expected_occlusion = gfx::Rect(0, 105, 200, 45); |
| 1484 | break; |
| 1485 | } |
| 1486 | |
| 1487 | EXPECT_EQ(expected_occlusion.ToString(), |
| 1488 | occlusion.occlusion_from_inside_target().ToString()); |
| 1489 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1490 | |
| 1491 | this->DestroyLayers(); |
| 1492 | } |
| 1493 | } |
| 1494 | }; |
| 1495 | |
| 1496 | ALL_OCCLUSIONTRACKER_TEST( |
ajuma | 97755536 | 2016-07-19 16:12:12 | [diff] [blame] | 1497 | OcclusionTrackerTestPixelsNeededForDropShadowBackgroundFilter); |
jbroman | 19a18b1 | 2016-07-07 02:37:38 | [diff] [blame] | 1498 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1499 | class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1500 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1501 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1502 | explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1503 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1504 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1505 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1506 | gfx::Transform scale_by_half; |
| 1507 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1508 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1509 | // Makes two surfaces that completely cover |parent|. The occlusion both |
| 1510 | // above and below the filters will be reduced by each of them. |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1511 | TestContentLayerImpl* root = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1512 | this->identity_matrix, gfx::PointF(), gfx::Size(75, 75)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1513 | LayerImpl* parent = this->CreateSurface(root, scale_by_half, gfx::PointF(), |
| 1514 | gfx::Size(150, 150)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1515 | parent->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1516 | LayerImpl* filtered_surface1 = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1517 | parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1518 | LayerImpl* filtered_surface2 = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1519 | parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1520 | LayerImpl* occluding_layer_above = this->CreateDrawingLayer( |
| 1521 | parent, this->identity_matrix, gfx::PointF(100.f, 100.f), |
| 1522 | gfx::Size(50, 50), true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1523 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1524 | // Filters make the layers own surfaces. |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1525 | filtered_surface1->test_properties()->force_render_surface = true; |
| 1526 | filtered_surface2->test_properties()->force_render_surface = true; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1527 | FilterOperations filters; |
| 1528 | filters.Append(FilterOperation::CreateBlurFilter(1.f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1529 | filtered_surface1->test_properties()->background_filters = filters; |
| 1530 | filtered_surface2->test_properties()->background_filters = filters; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1531 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1532 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1533 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1534 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1535 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1536 | this->VisitLayer(occluding_layer_above, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1537 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1538 | occlusion.occlusion_from_outside_target().ToString()); |
| 1539 | EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(), |
| 1540 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1541 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1542 | this->VisitLayer(filtered_surface2, &occlusion); |
| 1543 | this->VisitContributingSurface(filtered_surface2, &occlusion); |
| 1544 | this->VisitLayer(filtered_surface1, &occlusion); |
| 1545 | this->VisitContributingSurface(filtered_surface1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1546 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1547 | // Test expectations in the target. |
jbroman | 56c1f9c | 2016-07-06 19:08:10 | [diff] [blame] | 1548 | int blur_outset = 3; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1549 | gfx::Rect expected_occlusion = |
jbroman | 56c1f9c | 2016-07-06 19:08:10 | [diff] [blame] | 1550 | gfx::Rect(100 / 2 + blur_outset * 2, 100 / 2 + blur_outset * 2, |
| 1551 | 50 / 2 - blur_outset * 4, 50 / 2 - blur_outset * 4); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1552 | EXPECT_EQ(expected_occlusion.ToString(), |
| 1553 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1554 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1555 | // Test expectations in the screen are the same as in the target, as the |
| 1556 | // render surface is 1:1 with the screen. |
| 1557 | EXPECT_EQ(expected_occlusion.ToString(), |
| 1558 | occlusion.occlusion_from_outside_target().ToString()); |
| 1559 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1560 | }; |
| 1561 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1562 | ALL_OCCLUSIONTRACKER_TEST( |
| 1563 | OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1564 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1565 | class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1566 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1567 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1568 | explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1569 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1570 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1571 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1572 | gfx::Transform scale_by_half; |
| 1573 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1574 | |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 1575 | // Make a 50x50 surface, with a smaller 30x30 layer centered below it. |
| 1576 | // The surface is scaled to test that the pixel moving is done in the target |
| 1577 | // space, where the background filter is applied, and the surface appears at |
| 1578 | // 50, 50. |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1579 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1580 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 150)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1581 | LayerImpl* behind_surface_layer = this->CreateDrawingLayer( |
| 1582 | parent, this->identity_matrix, gfx::PointF(60.f, 60.f), |
| 1583 | gfx::Size(30, 30), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1584 | LayerImpl* filtered_surface = |
| 1585 | this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f), |
| 1586 | gfx::Size(100, 100), false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1587 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1588 | // Filters make the layer own a surface. |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1589 | filtered_surface->test_properties()->force_render_surface = true; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1590 | FilterOperations filters; |
| 1591 | filters.Append(FilterOperation::CreateBlurFilter(3.f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1592 | filtered_surface->test_properties()->background_filters = filters; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1593 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1594 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1595 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1596 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1597 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1598 | // The surface has a background blur, so it blurs non-opaque pixels below |
| 1599 | // it. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1600 | this->VisitLayer(filtered_surface, &occlusion); |
| 1601 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1602 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1603 | // The layers behind the surface are not blurred, and their occlusion does |
| 1604 | // not change, until we leave the surface. So it should not be modified by |
| 1605 | // the filter here. |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1606 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1607 | |
| 1608 | // Clear the occlusion so the |behind_surface_layer| can add its occlusion |
| 1609 | // without existing occlusion interfering. |
| 1610 | occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion()); |
| 1611 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1612 | this->VisitLayer(behind_surface_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1613 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1614 | // The layers behind the surface are not blurred, and their occlusion does |
| 1615 | // not change, until we leave the surface. So it should not be modified by |
| 1616 | // the filter here. |
| 1617 | gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1618 | EXPECT_EQ(occlusion_behind_surface.ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1619 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1620 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1621 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1622 | }; |
| 1623 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1624 | ALL_OCCLUSIONTRACKER_TEST( |
| 1625 | OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1626 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1627 | class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1628 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1629 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1630 | explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1631 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1632 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1633 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1634 | gfx::Transform scale_by_half; |
| 1635 | scale_by_half.Scale(0.5, 0.5); |
| 1636 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 1637 | // Make a 50x50 filtered surface that is completely occluded by an opaque |
| 1638 | // layer which is above it in the z-order. The surface is |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1639 | // scaled to test that the pixel moving is done in the target space, where |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 1640 | // the background filter is applied, and the surface appears at 50, 50. |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1641 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 1642 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 150)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1643 | LayerImpl* filtered_surface = |
| 1644 | this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f), |
| 1645 | gfx::Size(100, 100), false); |
| 1646 | LayerImpl* occluding_layer = this->CreateDrawingLayer( |
| 1647 | parent, this->identity_matrix, gfx::PointF(50.f, 50.f), |
| 1648 | gfx::Size(50, 50), true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1649 | |
| 1650 | // Filters make the layer own a surface. |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1651 | filtered_surface->test_properties()->force_render_surface = true; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1652 | FilterOperations filters; |
| 1653 | filters.Append(FilterOperation::CreateBlurFilter(3.f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1654 | filtered_surface->test_properties()->background_filters = filters; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1655 | |
| 1656 | this->CalcDrawEtc(parent); |
| 1657 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1658 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1659 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 1660 | this->VisitLayer(occluding_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1661 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1662 | this->VisitLayer(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1663 | { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1664 | // The layers above the filtered surface occlude from outside. |
| 1665 | gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1666 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1667 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1668 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 1669 | EXPECT_EQ(occlusion_above_surface.ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1670 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1671 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1672 | |
| 1673 | // The surface has a background blur, so it blurs non-opaque pixels below |
| 1674 | // it. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1675 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1676 | { |
| 1677 | // The filter is completely occluded, so it should not blur anything and |
| 1678 | // reduce any occlusion. |
| 1679 | gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1680 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 1681 | EXPECT_EQ(occlusion_above_surface.ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1682 | occlusion.occlusion_from_inside_target().ToString()); |
| 1683 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1684 | occlusion.occlusion_from_outside_target().ToString()); |
| 1685 | } |
| 1686 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1687 | }; |
| 1688 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1689 | ALL_OCCLUSIONTRACKER_TEST( |
| 1690 | OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1691 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1692 | class OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded |
| 1693 | : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1694 | protected: |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1695 | explicit OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1696 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1697 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1698 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1699 | gfx::Transform scale_by_half; |
| 1700 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1701 | |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 1702 | // Make a 50x50 surface which is partially occluded by opaque layers which |
| 1703 | // are above it in the z-order. The surface is scaled to test that the |
| 1704 | // pixel moving is done in the target space, where the background filter is |
| 1705 | // applied, but the surface appears at 50, 50. |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1706 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1707 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 150)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1708 | LayerImpl* filtered_surface = |
| 1709 | this->CreateDrawingLayer(parent, scale_by_half, gfx::PointF(50.f, 50.f), |
| 1710 | gfx::Size(100, 100), false); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1711 | LayerImpl* above_surface_layer = this->CreateDrawingLayer( |
| 1712 | parent, this->identity_matrix, gfx::PointF(70.f, 50.f), |
| 1713 | gfx::Size(30, 50), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1714 | LayerImpl* beside_surface_layer = this->CreateDrawingLayer( |
| 1715 | parent, this->identity_matrix, gfx::PointF(90.f, 40.f), |
| 1716 | gfx::Size(10, 10), true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1717 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1718 | // Filters make the layer own a surface. |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1719 | filtered_surface->test_properties()->force_render_surface = true; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1720 | FilterOperations filters; |
| 1721 | filters.Append(FilterOperation::CreateBlurFilter(3.f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1722 | filtered_surface->test_properties()->background_filters = filters; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1723 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1724 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1725 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1726 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1727 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1728 | this->VisitLayer(beside_surface_layer, &occlusion); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1729 | this->VisitLayer(above_surface_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1730 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1731 | // The surface has a background blur, so it blurs non-opaque pixels below |
| 1732 | // it. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1733 | this->VisitLayer(filtered_surface, &occlusion); |
| 1734 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1735 | |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 1736 | // The filter in the surface is partially unoccluded. Only the unoccluded |
| 1737 | // parts should reduce occlusion. This means it will push back the |
| 1738 | // occlusion that touches the unoccluded part (occlusion_above___), but |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1739 | // it will not touch occlusion_beside____ since that is not beside the |
| 1740 | // unoccluded part of the surface, even though it is beside the occluded |
| 1741 | // part of the surface. |
jbroman | 56c1f9c | 2016-07-06 19:08:10 | [diff] [blame] | 1742 | int blur_outset = 9; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1743 | gfx::Rect occlusion_above_surface = |
jbroman | 56c1f9c | 2016-07-06 19:08:10 | [diff] [blame] | 1744 | gfx::Rect(70 + blur_outset, 50, 30 - blur_outset, 50); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1745 | gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1746 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1747 | SimpleEnclosedRegion expected_occlusion; |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1748 | expected_occlusion.Union(occlusion_beside_surface); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1749 | expected_occlusion.Union(occlusion_above_surface); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1750 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1751 | EXPECT_EQ(expected_occlusion.ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1752 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1753 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1754 | |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1755 | const SimpleEnclosedRegion& actual_occlusion = |
| 1756 | occlusion.occlusion_from_inside_target(); |
| 1757 | for (size_t i = 0; i < expected_occlusion.GetRegionComplexity(); ++i) { |
| 1758 | ASSERT_LT(i, actual_occlusion.GetRegionComplexity()); |
| 1759 | EXPECT_EQ(expected_occlusion.GetRect(i), actual_occlusion.GetRect(i)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1760 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1761 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1762 | }; |
| 1763 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1764 | ALL_OCCLUSIONTRACKER_TEST( |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1765 | OcclusionTrackerTestReduceOcclusionWhenBkgdFilterIsPartiallyOccluded); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1766 | |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1767 | class OcclusionTrackerTestBlendModeDoesNotOcclude |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1768 | : public OcclusionTrackerTest { |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1769 | protected: |
| 1770 | explicit OcclusionTrackerTestBlendModeDoesNotOcclude(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1771 | : OcclusionTrackerTest(opaque_layers) {} |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1772 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1773 | TestContentLayerImpl* parent = this->CreateRoot( |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1774 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1775 | LayerImpl* blend_mode_layer = this->CreateDrawingLayer( |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1776 | parent, this->identity_matrix, gfx::PointF(0.f, 0.f), |
| 1777 | gfx::Size(100, 100), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1778 | LayerImpl* top_layer = this->CreateDrawingLayer( |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1779 | parent, this->identity_matrix, gfx::PointF(10.f, 12.f), |
| 1780 | gfx::Size(20, 22), true); |
| 1781 | |
| 1782 | // Blend mode makes the layer own a surface. |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1783 | blend_mode_layer->test_properties()->force_render_surface = true; |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 1784 | blend_mode_layer->test_properties()->blend_mode = SkBlendMode::kMultiply; |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1785 | |
| 1786 | this->CalcDrawEtc(parent); |
| 1787 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1788 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1789 | |
| 1790 | this->VisitLayer(top_layer, &occlusion); |
| 1791 | // |top_layer| occludes. |
| 1792 | EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(), |
| 1793 | occlusion.occlusion_from_inside_target().ToString()); |
| 1794 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1795 | |
| 1796 | this->VisitLayer(blend_mode_layer, &occlusion); |
ajuma | 2d466aa | 2016-07-25 21:11:00 | [diff] [blame] | 1797 | // |top_layer| and |blend_mode_layer| both occlude, since the blend mode |
| 1798 | // gets applied by blend_mode_layer's render surface, not when drawing the |
| 1799 | // layer itself. |
| 1800 | EXPECT_EQ(gfx::Rect(100, 100).ToString(), |
| 1801 | occlusion.occlusion_from_inside_target().ToString()); |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1802 | EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(), |
| 1803 | occlusion.occlusion_from_outside_target().ToString()); |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1804 | |
| 1805 | this->VisitContributingSurface(blend_mode_layer, &occlusion); |
| 1806 | // |top_layer| occludes but not |blend_mode_layer|. |
| 1807 | EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(), |
| 1808 | occlusion.occlusion_from_inside_target().ToString()); |
| 1809 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1810 | } |
| 1811 | }; |
| 1812 | |
| 1813 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestBlendModeDoesNotOcclude); |
| 1814 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1815 | class OcclusionTrackerTestMinimumTrackingSize : public OcclusionTrackerTest { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1816 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1817 | explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1818 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1819 | void RunMyTest() override { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1820 | gfx::Size tracking_size(100, 100); |
| 1821 | gfx::Size below_tracking_size(99, 99); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1822 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1823 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1824 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1825 | LayerImpl* large = this->CreateDrawingLayer( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1826 | parent, this->identity_matrix, gfx::PointF(), tracking_size, true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1827 | LayerImpl* small = |
| 1828 | this->CreateDrawingLayer(parent, this->identity_matrix, gfx::PointF(), |
| 1829 | below_tracking_size, true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1830 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1831 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1832 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1833 | occlusion.set_minimum_tracking_size(tracking_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1834 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1835 | // The small layer is not tracked because it is too small. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1836 | this->VisitLayer(small, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1837 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1838 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1839 | occlusion.occlusion_from_outside_target().ToString()); |
| 1840 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1841 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1842 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1843 | // The large layer is tracked as it is large enough. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1844 | this->VisitLayer(large, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1845 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1846 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1847 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 1848 | EXPECT_EQ(gfx::Rect(tracking_size).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1849 | occlusion.occlusion_from_inside_target().ToString()); |
| 1850 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1851 | }; |
| 1852 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1853 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1854 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1855 | class OcclusionTrackerTestScaledLayerIsClipped : public OcclusionTrackerTest { |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1856 | protected: |
| 1857 | explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1858 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1859 | void RunMyTest() override { |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1860 | gfx::Transform scale_transform; |
| 1861 | scale_transform.Scale(512.0, 512.0); |
| 1862 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1863 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1864 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1865 | LayerImpl* clip = |
| 1866 | this->CreateLayer(parent, this->identity_matrix, |
| 1867 | gfx::PointF(10.f, 10.f), gfx::Size(50, 50)); |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1868 | clip->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1869 | LayerImpl* scale = this->CreateLayer(clip, scale_transform, gfx::PointF(), |
| 1870 | gfx::Size(1, 1)); |
| 1871 | LayerImpl* scaled = this->CreateDrawingLayer( |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1872 | scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true); |
| 1873 | this->CalcDrawEtc(parent); |
| 1874 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1875 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1876 | |
| 1877 | this->VisitLayer(scaled, &occlusion); |
| 1878 | |
| 1879 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1880 | occlusion.occlusion_from_outside_target().ToString()); |
| 1881 | EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(), |
| 1882 | occlusion.occlusion_from_inside_target().ToString()); |
| 1883 | } |
| 1884 | }; |
| 1885 | |
| 1886 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped) |
| 1887 | |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1888 | class OcclusionTrackerTestScaledLayerInSurfaceIsClipped |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1889 | : public OcclusionTrackerTest { |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1890 | protected: |
| 1891 | explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1892 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1893 | void RunMyTest() override { |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1894 | gfx::Transform scale_transform; |
| 1895 | scale_transform.Scale(512.0, 512.0); |
| 1896 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1897 | TestContentLayerImpl* parent = this->CreateRoot( |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1898 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1899 | LayerImpl* clip = |
| 1900 | this->CreateLayer(parent, this->identity_matrix, |
| 1901 | gfx::PointF(10.f, 10.f), gfx::Size(50, 50)); |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1902 | clip->SetMasksToBounds(true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1903 | LayerImpl* surface = this->CreateDrawingSurface( |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1904 | clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1905 | LayerImpl* scale = this->CreateLayer(surface, scale_transform, |
| 1906 | gfx::PointF(), gfx::Size(1, 1)); |
| 1907 | LayerImpl* scaled = this->CreateDrawingLayer( |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1908 | scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true); |
| 1909 | this->CalcDrawEtc(parent); |
| 1910 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1911 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 1912 | |
| 1913 | this->VisitLayer(scaled, &occlusion); |
| 1914 | this->VisitLayer(surface, &occlusion); |
| 1915 | this->VisitContributingSurface(surface, &occlusion); |
| 1916 | |
| 1917 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1918 | occlusion.occlusion_from_outside_target().ToString()); |
| 1919 | EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(), |
| 1920 | occlusion.occlusion_from_inside_target().ToString()); |
| 1921 | } |
| 1922 | }; |
| 1923 | |
| 1924 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped) |
| 1925 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1926 | class OcclusionTrackerTestCopyRequestDoesOcclude : public OcclusionTrackerTest { |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1927 | protected: |
| 1928 | explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1929 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1930 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1931 | TestContentLayerImpl* root = this->CreateRoot( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 1932 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1933 | TestContentLayerImpl* parent = this->CreateDrawingLayer( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 1934 | root, this->identity_matrix, gfx::PointF(), gfx::Size(400, 400), true); |
| 1935 | LayerImpl* copy = |
| 1936 | this->CreateLayer(parent, this->identity_matrix, gfx::PointF(100, 0), |
| 1937 | gfx::Size(200, 400)); |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1938 | this->AddCopyRequest(copy); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1939 | LayerImpl* copy_child = this->CreateDrawingLayer( |
| 1940 | copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true); |
| 1941 | LayerImpl* top_layer = |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1942 | this->CreateDrawingLayer(root, this->identity_matrix, |
| 1943 | gfx::PointF(50, 0), gfx::Size(50, 400), true); |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1944 | this->CalcDrawEtc(root); |
| 1945 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1946 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1947 | |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1948 | this->VisitLayer(top_layer, &occlusion); |
| 1949 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1950 | occlusion.occlusion_from_outside_target().ToString()); |
| 1951 | EXPECT_EQ(gfx::Rect(50, 0, 50, 400).ToString(), |
| 1952 | occlusion.occlusion_from_inside_target().ToString()); |
| 1953 | |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1954 | this->VisitLayer(copy_child, &occlusion); |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1955 | // Layers outside the copy request do not occlude. |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1956 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1957 | occlusion.occlusion_from_outside_target().ToString()); |
| 1958 | EXPECT_EQ(gfx::Rect(200, 400).ToString(), |
| 1959 | occlusion.occlusion_from_inside_target().ToString()); |
| 1960 | |
| 1961 | // CopyRequests cause the layer to own a surface. |
| 1962 | this->VisitContributingSurface(copy, &occlusion); |
| 1963 | |
| 1964 | // The occlusion from the copy should be kept. |
| 1965 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1966 | occlusion.occlusion_from_outside_target().ToString()); |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 1967 | EXPECT_EQ(gfx::Rect(50, 0, 250, 400).ToString(), |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1968 | occlusion.occlusion_from_inside_target().ToString()); |
| 1969 | } |
| 1970 | }; |
| 1971 | |
| 1972 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude) |
| 1973 | |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1974 | class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1975 | : public OcclusionTrackerTest { |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1976 | protected: |
| 1977 | explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude( |
| 1978 | bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1979 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 1980 | void RunMyTest() override { |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1981 | TestContentLayerImpl* root = this->CreateRoot( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 1982 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1983 | TestContentLayerImpl* parent = this->CreateDrawingLayer( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 1984 | root, this->identity_matrix, gfx::PointF(), gfx::Size(400, 400), true); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1985 | LayerImpl* hide = this->CreateLayer(parent, this->identity_matrix, |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 1986 | gfx::PointF(), gfx::Size()); |
| 1987 | LayerImpl* copy = |
| 1988 | this->CreateLayer(hide, this->identity_matrix, gfx::PointF(100.f, 0.f), |
| 1989 | gfx::Size(200, 400)); |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1990 | this->AddCopyRequest(copy); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 1991 | LayerImpl* copy_child = this->CreateDrawingLayer( |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1992 | copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true); |
| 1993 | |
| 1994 | // The |copy| layer is hidden but since it is being copied, it will be |
| 1995 | // drawn. |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 1996 | hide->test_properties()->hide_layer_and_subtree = true; |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 1997 | |
| 1998 | this->CalcDrawEtc(root); |
| 1999 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2000 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 2001 | |
| 2002 | this->VisitLayer(copy_child, &occlusion); |
| 2003 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2004 | occlusion.occlusion_from_outside_target().ToString()); |
| 2005 | EXPECT_EQ(gfx::Rect(200, 400).ToString(), |
| 2006 | occlusion.occlusion_from_inside_target().ToString()); |
| 2007 | |
| 2008 | // CopyRequests cause the layer to own a surface. |
| 2009 | this->VisitContributingSurface(copy, &occlusion); |
| 2010 | |
| 2011 | // The occlusion from the copy should be dropped since it is hidden. |
| 2012 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2013 | occlusion.occlusion_from_outside_target().ToString()); |
| 2014 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2015 | occlusion.occlusion_from_inside_target().ToString()); |
| 2016 | } |
| 2017 | }; |
| 2018 | |
| 2019 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude) |
| 2020 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2021 | class OcclusionTrackerTestOccludedLayer : public OcclusionTrackerTest { |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 2022 | protected: |
| 2023 | explicit OcclusionTrackerTestOccludedLayer(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2024 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 2025 | void RunMyTest() override { |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 2026 | gfx::Transform translate; |
| 2027 | translate.Translate(10.0, 20.0); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2028 | TestContentLayerImpl* root = this->CreateRoot( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2029 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 2030 | LayerImpl* surface = this->CreateSurface( |
| 2031 | root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2032 | LayerImpl* layer = this->CreateDrawingLayer( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2033 | surface, translate, gfx::PointF(), gfx::Size(200, 200), false); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2034 | TestContentLayerImpl* outside_layer = this->CreateDrawingLayer( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2035 | root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 2036 | this->CalcDrawEtc(root); |
| 2037 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2038 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200)); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 2039 | this->VisitLayer(outside_layer, &occlusion); |
| 2040 | this->EnterLayer(layer, &occlusion); |
| 2041 | |
| 2042 | // No occlusion, is not occluded. |
| 2043 | occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion()); |
| 2044 | occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion()); |
| 2045 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100))); |
| 2046 | |
| 2047 | // Partial occlusion from outside, is not occluded. |
| 2048 | occlusion.set_occlusion_from_outside_target( |
| 2049 | SimpleEnclosedRegion(50, 50, 100, 100)); |
| 2050 | occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion()); |
| 2051 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 2052 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100))); |
| 2053 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100))); |
| 2054 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100))); |
| 2055 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100))); |
| 2056 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100))); |
| 2057 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100))); |
| 2058 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100))); |
| 2059 | |
| 2060 | // Full occlusion from outside, is occluded. |
| 2061 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100))); |
| 2062 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10))); |
| 2063 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10))); |
| 2064 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50))); |
| 2065 | |
| 2066 | // Partial occlusion from inside, is not occluded. |
| 2067 | occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion()); |
| 2068 | occlusion.set_occlusion_from_inside_target( |
| 2069 | SimpleEnclosedRegion(50, 50, 100, 100)); |
| 2070 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 2071 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100))); |
| 2072 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100))); |
| 2073 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100))); |
| 2074 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100))); |
| 2075 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100))); |
| 2076 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100))); |
| 2077 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100))); |
| 2078 | |
| 2079 | // Full occlusion from inside, is occluded. |
| 2080 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100))); |
| 2081 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10))); |
| 2082 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10))); |
| 2083 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50))); |
| 2084 | |
| 2085 | // Partial occlusion from both, is not occluded. |
| 2086 | occlusion.set_occlusion_from_outside_target( |
| 2087 | SimpleEnclosedRegion(50, 50, 100, 50)); |
| 2088 | occlusion.set_occlusion_from_inside_target( |
| 2089 | SimpleEnclosedRegion(50, 100, 100, 50)); |
| 2090 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 2091 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 30, 100, 100))); |
| 2092 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 0, 100, 100))); |
| 2093 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(40, 80, 100, 100))); |
| 2094 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 80, 100))); |
| 2095 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 80, 100, 100))); |
| 2096 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 80, 100, 100))); |
| 2097 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(90, 0, 100, 100))); |
| 2098 | |
| 2099 | // Full occlusion from both, is occluded. |
| 2100 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100))); |
| 2101 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10))); |
| 2102 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10))); |
| 2103 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50))); |
| 2104 | } |
| 2105 | }; |
| 2106 | |
| 2107 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOccludedLayer) |
| 2108 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2109 | class OcclusionTrackerTestUnoccludedLayerQuery : public OcclusionTrackerTest { |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 2110 | protected: |
| 2111 | explicit OcclusionTrackerTestUnoccludedLayerQuery(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2112 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 2113 | void RunMyTest() override { |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 2114 | gfx::Transform translate; |
| 2115 | translate.Translate(10.0, 20.0); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2116 | TestContentLayerImpl* root = this->CreateRoot( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2117 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 2118 | LayerImpl* surface = this->CreateSurface( |
| 2119 | root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2120 | LayerImpl* layer = this->CreateDrawingLayer( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2121 | surface, translate, gfx::PointF(), gfx::Size(200, 200), false); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2122 | TestContentLayerImpl* outside_layer = this->CreateDrawingLayer( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2123 | root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false); |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 2124 | this->CalcDrawEtc(root); |
| 2125 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2126 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200)); |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 2127 | this->VisitLayer(outside_layer, &occlusion); |
| 2128 | this->EnterLayer(layer, &occlusion); |
| 2129 | |
| 2130 | // No occlusion, is not occluded. |
| 2131 | occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion()); |
| 2132 | occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion()); |
| 2133 | EXPECT_EQ(gfx::Rect(100, 100), |
| 2134 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(100, 100))); |
| 2135 | |
| 2136 | // Partial occlusion from outside. |
| 2137 | occlusion.set_occlusion_from_outside_target( |
| 2138 | SimpleEnclosedRegion(50, 50, 100, 100)); |
| 2139 | occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion()); |
| 2140 | EXPECT_EQ( |
| 2141 | gfx::Rect(0, 0, 100, 100), |
| 2142 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100))); |
| 2143 | EXPECT_EQ(gfx::Rect(140, 30, 50, 100), |
| 2144 | occlusion.UnoccludedLayerContentRect( |
| 2145 | layer, gfx::Rect(90, 30, 100, 100))); |
| 2146 | EXPECT_EQ(gfx::Rect(40, 0, 100, 30), |
| 2147 | occlusion.UnoccludedLayerContentRect(layer, |
| 2148 | gfx::Rect(40, 0, 100, 100))); |
| 2149 | EXPECT_EQ(gfx::Rect(40, 130, 100, 50), |
| 2150 | occlusion.UnoccludedLayerContentRect( |
| 2151 | layer, gfx::Rect(40, 80, 100, 100))); |
| 2152 | EXPECT_EQ( |
| 2153 | gfx::Rect(0, 0, 80, 100), |
| 2154 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100))); |
| 2155 | EXPECT_EQ(gfx::Rect(90, 80, 100, 100), |
| 2156 | occlusion.UnoccludedLayerContentRect( |
| 2157 | layer, gfx::Rect(90, 80, 100, 100))); |
| 2158 | EXPECT_EQ(gfx::Rect(0, 80, 100, 100), |
| 2159 | occlusion.UnoccludedLayerContentRect(layer, |
| 2160 | gfx::Rect(0, 80, 100, 100))); |
| 2161 | EXPECT_EQ(gfx::Rect(90, 0, 100, 100), |
| 2162 | occlusion.UnoccludedLayerContentRect(layer, |
| 2163 | gfx::Rect(90, 0, 100, 100))); |
| 2164 | |
| 2165 | // Full occlusion from outside, is occluded. |
| 2166 | EXPECT_EQ(gfx::Rect(), |
| 2167 | occlusion.UnoccludedLayerContentRect( |
| 2168 | layer, gfx::Rect(40, 30, 100, 100))); |
| 2169 | EXPECT_EQ( |
| 2170 | gfx::Rect(), |
| 2171 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10))); |
| 2172 | EXPECT_EQ(gfx::Rect(), |
| 2173 | occlusion.UnoccludedLayerContentRect( |
| 2174 | layer, gfx::Rect(130, 120, 10, 10))); |
| 2175 | EXPECT_EQ( |
| 2176 | gfx::Rect(), |
| 2177 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50))); |
| 2178 | |
| 2179 | // Partial occlusion from inside, is not occluded. |
| 2180 | occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion()); |
| 2181 | occlusion.set_occlusion_from_inside_target( |
| 2182 | SimpleEnclosedRegion(50, 50, 100, 100)); |
| 2183 | EXPECT_EQ( |
| 2184 | gfx::Rect(0, 0, 100, 100), |
| 2185 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100))); |
| 2186 | EXPECT_EQ(gfx::Rect(140, 30, 50, 100), |
| 2187 | occlusion.UnoccludedLayerContentRect( |
| 2188 | layer, gfx::Rect(90, 30, 100, 100))); |
| 2189 | EXPECT_EQ(gfx::Rect(40, 0, 100, 30), |
| 2190 | occlusion.UnoccludedLayerContentRect(layer, |
| 2191 | gfx::Rect(40, 0, 100, 100))); |
| 2192 | EXPECT_EQ(gfx::Rect(40, 130, 100, 50), |
| 2193 | occlusion.UnoccludedLayerContentRect( |
| 2194 | layer, gfx::Rect(40, 80, 100, 100))); |
| 2195 | EXPECT_EQ( |
| 2196 | gfx::Rect(0, 0, 80, 100), |
| 2197 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100))); |
| 2198 | EXPECT_EQ(gfx::Rect(90, 80, 100, 100), |
| 2199 | occlusion.UnoccludedLayerContentRect( |
| 2200 | layer, gfx::Rect(90, 80, 100, 100))); |
| 2201 | EXPECT_EQ(gfx::Rect(0, 80, 100, 100), |
| 2202 | occlusion.UnoccludedLayerContentRect(layer, |
| 2203 | gfx::Rect(0, 80, 100, 100))); |
| 2204 | EXPECT_EQ(gfx::Rect(90, 0, 100, 100), |
| 2205 | occlusion.UnoccludedLayerContentRect(layer, |
| 2206 | gfx::Rect(90, 0, 100, 100))); |
| 2207 | |
| 2208 | // Full occlusion from inside, is occluded. |
| 2209 | EXPECT_EQ(gfx::Rect(), |
| 2210 | occlusion.UnoccludedLayerContentRect( |
| 2211 | layer, gfx::Rect(40, 30, 100, 100))); |
| 2212 | EXPECT_EQ( |
| 2213 | gfx::Rect(), |
| 2214 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10))); |
| 2215 | EXPECT_EQ(gfx::Rect(), |
| 2216 | occlusion.UnoccludedLayerContentRect( |
| 2217 | layer, gfx::Rect(130, 120, 10, 10))); |
| 2218 | EXPECT_EQ( |
| 2219 | gfx::Rect(), |
| 2220 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50))); |
| 2221 | |
| 2222 | // Partial occlusion from both, is not occluded. |
| 2223 | occlusion.set_occlusion_from_outside_target( |
| 2224 | SimpleEnclosedRegion(50, 50, 100, 50)); |
| 2225 | occlusion.set_occlusion_from_inside_target( |
| 2226 | SimpleEnclosedRegion(50, 100, 100, 50)); |
| 2227 | EXPECT_EQ( |
| 2228 | gfx::Rect(0, 0, 100, 100), |
| 2229 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100))); |
| 2230 | // This could be (140, 30, 50, 100). But because we do a lossy subtract, |
| 2231 | // it's larger. |
| 2232 | EXPECT_EQ(gfx::Rect(90, 30, 100, 100), |
| 2233 | occlusion.UnoccludedLayerContentRect( |
| 2234 | layer, gfx::Rect(90, 30, 100, 100))); |
| 2235 | EXPECT_EQ(gfx::Rect(40, 0, 100, 30), |
| 2236 | occlusion.UnoccludedLayerContentRect(layer, |
| 2237 | gfx::Rect(40, 0, 100, 100))); |
| 2238 | EXPECT_EQ(gfx::Rect(40, 130, 100, 50), |
| 2239 | occlusion.UnoccludedLayerContentRect( |
| 2240 | layer, gfx::Rect(40, 80, 100, 100))); |
| 2241 | EXPECT_EQ( |
| 2242 | gfx::Rect(0, 0, 80, 100), |
| 2243 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100))); |
| 2244 | EXPECT_EQ(gfx::Rect(90, 80, 100, 100), |
| 2245 | occlusion.UnoccludedLayerContentRect( |
| 2246 | layer, gfx::Rect(90, 80, 100, 100))); |
| 2247 | EXPECT_EQ(gfx::Rect(0, 80, 100, 100), |
| 2248 | occlusion.UnoccludedLayerContentRect(layer, |
| 2249 | gfx::Rect(0, 80, 100, 100))); |
| 2250 | EXPECT_EQ(gfx::Rect(90, 0, 100, 100), |
| 2251 | occlusion.UnoccludedLayerContentRect(layer, |
| 2252 | gfx::Rect(90, 0, 100, 100))); |
| 2253 | |
| 2254 | // Full occlusion from both, is occluded. |
| 2255 | EXPECT_EQ(gfx::Rect(), |
| 2256 | occlusion.UnoccludedLayerContentRect( |
| 2257 | layer, gfx::Rect(40, 30, 100, 100))); |
| 2258 | EXPECT_EQ( |
| 2259 | gfx::Rect(), |
| 2260 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10))); |
| 2261 | EXPECT_EQ(gfx::Rect(), |
| 2262 | occlusion.UnoccludedLayerContentRect( |
| 2263 | layer, gfx::Rect(130, 120, 10, 10))); |
| 2264 | EXPECT_EQ( |
| 2265 | gfx::Rect(), |
| 2266 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50))); |
| 2267 | } |
| 2268 | }; |
| 2269 | |
| 2270 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedLayerQuery) |
| 2271 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2272 | class OcclusionTrackerTestUnoccludedSurfaceQuery : public OcclusionTrackerTest { |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 2273 | protected: |
| 2274 | explicit OcclusionTrackerTestUnoccludedSurfaceQuery(bool opaque_layers) |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2275 | : OcclusionTrackerTest(opaque_layers) {} |
dmichael | c78b093 | 2014-12-17 23:39:47 | [diff] [blame] | 2276 | void RunMyTest() override { |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 2277 | gfx::Transform translate; |
| 2278 | translate.Translate(10.0, 20.0); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2279 | TestContentLayerImpl* root = this->CreateRoot( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2280 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 2281 | LayerImpl* surface = this->CreateSurface(root, translate, gfx::PointF(), |
| 2282 | gfx::Size(200, 200)); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2283 | LayerImpl* layer = |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2284 | this->CreateDrawingLayer(surface, this->identity_matrix, gfx::PointF(), |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2285 | gfx::Size(200, 200), false); |
| 2286 | TestContentLayerImpl* outside_layer = this->CreateDrawingLayer( |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2287 | root, this->identity_matrix, gfx::PointF(), gfx::Size(200, 200), false); |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 2288 | this->CalcDrawEtc(root); |
| 2289 | |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 2290 | TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200)); |
danakj | f080b5b | 2014-08-23 22:18:20 | [diff] [blame] | 2291 | this->VisitLayer(outside_layer, &occlusion); |
| 2292 | this->VisitLayer(layer, &occlusion); |
| 2293 | this->EnterContributingSurface(surface, &occlusion); |
| 2294 | |
| 2295 | // No occlusion, is not occluded. |
| 2296 | occlusion.set_occlusion_on_contributing_surface_from_outside_target( |
| 2297 | SimpleEnclosedRegion()); |
| 2298 | occlusion.set_occlusion_on_contributing_surface_from_inside_target( |
| 2299 | SimpleEnclosedRegion()); |
| 2300 | EXPECT_EQ( |
| 2301 | gfx::Rect(100, 100), |
| 2302 | occlusion.UnoccludedSurfaceContentRect(surface, gfx::Rect(100, 100))); |
| 2303 | |
| 2304 | // Partial occlusion from outside. |
| 2305 | occlusion.set_occlusion_on_contributing_surface_from_outside_target( |
| 2306 | SimpleEnclosedRegion(50, 50, 100, 100)); |
| 2307 | occlusion.set_occlusion_on_contributing_surface_from_inside_target( |
| 2308 | SimpleEnclosedRegion()); |
| 2309 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2310 | occlusion.UnoccludedSurfaceContentRect( |
| 2311 | surface, gfx::Rect(0, 0, 100, 100))); |
| 2312 | EXPECT_EQ(gfx::Rect(140, 30, 50, 100), |
| 2313 | occlusion.UnoccludedSurfaceContentRect( |
| 2314 | surface, gfx::Rect(90, 30, 100, 100))); |
| 2315 | EXPECT_EQ(gfx::Rect(40, 0, 100, 30), |
| 2316 | occlusion.UnoccludedSurfaceContentRect( |
| 2317 | surface, gfx::Rect(40, 0, 100, 100))); |
| 2318 | EXPECT_EQ(gfx::Rect(40, 130, 100, 50), |
| 2319 | occlusion.UnoccludedSurfaceContentRect( |
| 2320 | surface, gfx::Rect(40, 80, 100, 100))); |
| 2321 | EXPECT_EQ(gfx::Rect(0, 0, 80, 100), |
| 2322 | occlusion.UnoccludedSurfaceContentRect(surface, |
| 2323 | gfx::Rect(0, 0, 80, 100))); |
| 2324 | EXPECT_EQ(gfx::Rect(90, 80, 100, 100), |
| 2325 | occlusion.UnoccludedSurfaceContentRect( |
| 2326 | surface, gfx::Rect(90, 80, 100, 100))); |
| 2327 | EXPECT_EQ(gfx::Rect(0, 80, 100, 100), |
| 2328 | occlusion.UnoccludedSurfaceContentRect( |
| 2329 | surface, gfx::Rect(0, 80, 100, 100))); |
| 2330 | EXPECT_EQ(gfx::Rect(90, 0, 100, 100), |
| 2331 | occlusion.UnoccludedSurfaceContentRect( |
| 2332 | surface, gfx::Rect(90, 0, 100, 100))); |
| 2333 | |
| 2334 | // Full occlusion from outside, is occluded. |
| 2335 | EXPECT_EQ(gfx::Rect(), |
| 2336 | occlusion.UnoccludedSurfaceContentRect( |
| 2337 | surface, gfx::Rect(40, 30, 100, 100))); |
| 2338 | EXPECT_EQ(gfx::Rect(), |
| 2339 | occlusion.UnoccludedSurfaceContentRect( |
| 2340 | surface, gfx::Rect(40, 30, 10, 10))); |
| 2341 | EXPECT_EQ(gfx::Rect(), |
| 2342 | occlusion.UnoccludedSurfaceContentRect( |
| 2343 | surface, gfx::Rect(130, 120, 10, 10))); |
| 2344 | EXPECT_EQ(gfx::Rect(), |
| 2345 | occlusion.UnoccludedSurfaceContentRect( |
| 2346 | surface, gfx::Rect(80, 70, 50, 50))); |
| 2347 | |
| 2348 | // Partial occlusion from inside, is not occluded. |
| 2349 | occlusion.set_occlusion_on_contributing_surface_from_outside_target( |
| 2350 | SimpleEnclosedRegion()); |
| 2351 | occlusion.set_occlusion_on_contributing_surface_from_inside_target( |
| 2352 | SimpleEnclosedRegion(50, 50, 100, 100)); |
| 2353 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2354 | occlusion.UnoccludedSurfaceContentRect( |
| 2355 | surface, gfx::Rect(0, 0, 100, 100))); |
| 2356 | EXPECT_EQ(gfx::Rect(140, 30, 50, 100), |
| 2357 | occlusion.UnoccludedSurfaceContentRect( |
| 2358 | surface, gfx::Rect(90, 30, 100, 100))); |
| 2359 | EXPECT_EQ(gfx::Rect(40, 0, 100, 30), |
| 2360 | occlusion.UnoccludedSurfaceContentRect( |
| 2361 | surface, gfx::Rect(40, 0, 100, 100))); |
| 2362 | EXPECT_EQ(gfx::Rect(40, 130, 100, 50), |
| 2363 | occlusion.UnoccludedSurfaceContentRect( |
| 2364 | surface, gfx::Rect(40, 80, 100, 100))); |
| 2365 | EXPECT_EQ(gfx::Rect(0, 0, 80, 100), |
| 2366 | occlusion.UnoccludedSurfaceContentRect(surface, |
| 2367 | gfx::Rect(0, 0, 80, 100))); |
| 2368 | EXPECT_EQ(gfx::Rect(90, 80, 100, 100), |
| 2369 | occlusion.UnoccludedSurfaceContentRect( |
| 2370 | surface, gfx::Rect(90, 80, 100, 100))); |
| 2371 | EXPECT_EQ(gfx::Rect(0, 80, 100, 100), |
| 2372 | occlusion.UnoccludedSurfaceContentRect( |
| 2373 | surface, gfx::Rect(0, 80, 100, 100))); |
| 2374 | EXPECT_EQ(gfx::Rect(90, 0, 100, 100), |
| 2375 | occlusion.UnoccludedSurfaceContentRect( |
| 2376 | surface, gfx::Rect(90, 0, 100, 100))); |
| 2377 | |
| 2378 | // Full occlusion from inside, is occluded. |
| 2379 | EXPECT_EQ(gfx::Rect(), |
| 2380 | occlusion.UnoccludedSurfaceContentRect( |
| 2381 | surface, gfx::Rect(40, 30, 100, 100))); |
| 2382 | EXPECT_EQ(gfx::Rect(), |
| 2383 | occlusion.UnoccludedSurfaceContentRect( |
| 2384 | surface, gfx::Rect(40, 30, 10, 10))); |
| 2385 | EXPECT_EQ(gfx::Rect(), |
| 2386 | occlusion.UnoccludedSurfaceContentRect( |
| 2387 | surface, gfx::Rect(130, 120, 10, 10))); |
| 2388 | EXPECT_EQ(gfx::Rect(), |
| 2389 | occlusion.UnoccludedSurfaceContentRect( |
| 2390 | surface, gfx::Rect(80, 70, 50, 50))); |
| 2391 | |
| 2392 | // Partial occlusion from both, is not occluded. |
| 2393 | occlusion.set_occlusion_on_contributing_surface_from_outside_target( |
| 2394 | SimpleEnclosedRegion(50, 50, 100, 50)); |
| 2395 | occlusion.set_occlusion_on_contributing_surface_from_inside_target( |
| 2396 | SimpleEnclosedRegion(50, 100, 100, 50)); |
| 2397 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2398 | occlusion.UnoccludedSurfaceContentRect( |
| 2399 | surface, gfx::Rect(0, 0, 100, 100))); |
| 2400 | // This could be (140, 30, 50, 100). But because we do a lossy subtract, |
| 2401 | // it's larger. |
| 2402 | EXPECT_EQ(gfx::Rect(90, 30, 100, 100), |
| 2403 | occlusion.UnoccludedSurfaceContentRect( |
| 2404 | surface, gfx::Rect(90, 30, 100, 100))); |
| 2405 | EXPECT_EQ(gfx::Rect(40, 0, 100, 30), |
| 2406 | occlusion.UnoccludedSurfaceContentRect( |
| 2407 | surface, gfx::Rect(40, 0, 100, 100))); |
| 2408 | EXPECT_EQ(gfx::Rect(40, 130, 100, 50), |
| 2409 | occlusion.UnoccludedSurfaceContentRect( |
| 2410 | surface, gfx::Rect(40, 80, 100, 100))); |
| 2411 | EXPECT_EQ(gfx::Rect(0, 0, 80, 100), |
| 2412 | occlusion.UnoccludedSurfaceContentRect(surface, |
| 2413 | gfx::Rect(0, 0, 80, 100))); |
| 2414 | EXPECT_EQ(gfx::Rect(90, 80, 100, 100), |
| 2415 | occlusion.UnoccludedSurfaceContentRect( |
| 2416 | surface, gfx::Rect(90, 80, 100, 100))); |
| 2417 | EXPECT_EQ(gfx::Rect(0, 80, 100, 100), |
| 2418 | occlusion.UnoccludedSurfaceContentRect( |
| 2419 | surface, gfx::Rect(0, 80, 100, 100))); |
| 2420 | EXPECT_EQ(gfx::Rect(90, 0, 100, 100), |
| 2421 | occlusion.UnoccludedSurfaceContentRect( |
| 2422 | surface, gfx::Rect(90, 0, 100, 100))); |
| 2423 | |
| 2424 | // Full occlusion from both, is occluded. |
| 2425 | EXPECT_EQ(gfx::Rect(), |
| 2426 | occlusion.UnoccludedSurfaceContentRect( |
| 2427 | surface, gfx::Rect(40, 30, 100, 100))); |
| 2428 | EXPECT_EQ(gfx::Rect(), |
| 2429 | occlusion.UnoccludedSurfaceContentRect( |
| 2430 | surface, gfx::Rect(40, 30, 10, 10))); |
| 2431 | EXPECT_EQ(gfx::Rect(), |
| 2432 | occlusion.UnoccludedSurfaceContentRect( |
| 2433 | surface, gfx::Rect(130, 120, 10, 10))); |
| 2434 | EXPECT_EQ(gfx::Rect(), |
| 2435 | occlusion.UnoccludedSurfaceContentRect( |
| 2436 | surface, gfx::Rect(80, 70, 50, 50))); |
| 2437 | } |
| 2438 | }; |
| 2439 | |
| 2440 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery) |
| 2441 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 2442 | } // namespace |
| 2443 | } // namespace cc |