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