[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 | |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 7 | #include "cc/animation/layer_animation_controller.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 8 | #include "cc/base/math_util.h" |
[email protected] | 6e84de2 | 2013-03-18 06:54:27 | [diff] [blame] | 9 | #include "cc/debug/overdraw_metrics.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 10 | #include "cc/layers/layer.h" |
| 11 | #include "cc/layers/layer_impl.h" |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 12 | #include "cc/output/copy_output_request.h" |
| 13 | #include "cc/output/copy_output_result.h" |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 14 | #include "cc/output/filter_operation.h" |
| 15 | #include "cc/output/filter_operations.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 16 | #include "cc/test/animation_test_common.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 17 | #include "cc/test/fake_impl_proxy.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 18 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 19 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 20 | #include "cc/test/geometry_test_utils.h" |
| 21 | #include "cc/test/occlusion_tracker_test_common.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 22 | #include "cc/trees/layer_tree_host_common.h" |
| 23 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 24 | #include "testing/gmock/include/gmock/gmock.h" |
| 25 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 26 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 27 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 28 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 29 | namespace { |
| 30 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 31 | class TestContentLayer : public Layer { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 32 | public: |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 33 | TestContentLayer() : Layer(), override_opaque_contents_rect_(false) { |
| 34 | SetIsDrawable(true); |
| 35 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 36 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 37 | virtual Region VisibleContentOpaqueRegion() const OVERRIDE { |
| 38 | if (override_opaque_contents_rect_) |
| 39 | return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect()); |
| 40 | return Layer::VisibleContentOpaqueRegion(); |
| 41 | } |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 42 | void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 43 | override_opaque_contents_rect_ = true; |
| 44 | opaque_contents_rect_ = opaque_contents_rect; |
| 45 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 46 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 47 | private: |
| 48 | virtual ~TestContentLayer() {} |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 49 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 50 | bool override_opaque_contents_rect_; |
| 51 | gfx::Rect opaque_contents_rect_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 52 | }; |
| 53 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 54 | class TestContentLayerImpl : public LayerImpl { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 55 | public: |
| 56 | TestContentLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 57 | : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) { |
| 58 | SetDrawsContent(true); |
| 59 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 60 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 61 | virtual Region VisibleContentOpaqueRegion() const OVERRIDE { |
| 62 | if (override_opaque_contents_rect_) |
| 63 | return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect()); |
| 64 | return LayerImpl::VisibleContentOpaqueRegion(); |
| 65 | } |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 66 | void SetOpaqueContentsRect(const gfx::Rect& opaque_contents_rect) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 67 | override_opaque_contents_rect_ = true; |
| 68 | opaque_contents_rect_ = opaque_contents_rect; |
| 69 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 70 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 71 | private: |
| 72 | bool override_opaque_contents_rect_; |
| 73 | gfx::Rect opaque_contents_rect_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 74 | }; |
| 75 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 76 | static inline bool LayerImplDrawTransformIsUnknown(const Layer* layer) { |
| 77 | return layer->draw_transform_is_animating(); |
| 78 | } |
| 79 | static inline bool LayerImplDrawTransformIsUnknown(const LayerImpl* layer) { |
| 80 | return false; |
| 81 | } |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 82 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 83 | template <typename LayerType, typename RenderSurfaceType> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 84 | class TestOcclusionTrackerWithClip |
| 85 | : public TestOcclusionTrackerBase<LayerType, RenderSurfaceType> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 86 | public: |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 87 | TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 88 | bool record_metrics_for_frame) |
| 89 | : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>( |
| 90 | viewport_rect, |
| 91 | record_metrics_for_frame) {} |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 92 | explicit TestOcclusionTrackerWithClip(const gfx::Rect& viewport_rect) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 93 | : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(viewport_rect, |
| 94 | false) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 95 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 96 | bool OccludedLayer(const LayerType* layer, |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 97 | const gfx::Rect& content_rect) const { |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 98 | DCHECK(layer->visible_content_rect().Contains(content_rect)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 99 | return this->Occluded(layer->render_target(), |
| 100 | content_rect, |
| 101 | layer->draw_transform(), |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 102 | LayerImplDrawTransformIsUnknown(layer)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 103 | } |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 104 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 105 | // Gives an unoccluded sub-rect of |content_rect| in the content space of the |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 106 | // layer. Simple wrapper around UnoccludedContentRect. |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 107 | gfx::Rect UnoccludedLayerContentRect(const LayerType* layer, |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 108 | const gfx::Rect& content_rect) const { |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 109 | DCHECK(layer->visible_content_rect().Contains(content_rect)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 110 | return this->UnoccludedContentRect( |
| 111 | layer->render_target(), |
| 112 | content_rect, |
| 113 | layer->draw_transform(), |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 114 | LayerImplDrawTransformIsUnknown(layer)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 115 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 116 | }; |
| 117 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 118 | struct OcclusionTrackerTestMainThreadTypes { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 119 | typedef Layer LayerType; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 120 | typedef FakeLayerTreeHost HostType; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 121 | typedef RenderSurface RenderSurfaceType; |
| 122 | typedef TestContentLayer ContentLayerType; |
| 123 | typedef scoped_refptr<Layer> LayerPtrType; |
| 124 | typedef scoped_refptr<ContentLayerType> ContentLayerPtrType; |
| 125 | typedef LayerIterator<Layer, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 126 | RenderSurfaceLayerList, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 127 | RenderSurface, |
| 128 | LayerIteratorActions::FrontToBack> TestLayerIterator; |
| 129 | typedef OcclusionTracker OcclusionTrackerType; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 130 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 131 | static LayerPtrType CreateLayer(HostType* host) { return Layer::Create(); } |
| 132 | static ContentLayerPtrType CreateContentLayer(HostType* host) { |
| 133 | return make_scoped_refptr(new ContentLayerType()); |
| 134 | } |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 135 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 136 | static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) { |
| 137 | LayerPtrType ref(*layer); |
| 138 | *layer = NULL; |
| 139 | return ref; |
| 140 | } |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 141 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 142 | static LayerPtrType PassLayerPtr(LayerPtrType* layer) { |
| 143 | LayerPtrType ref(*layer); |
| 144 | *layer = NULL; |
| 145 | return ref; |
| 146 | } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 147 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 148 | static void DestroyLayer(LayerPtrType* layer) { *layer = NULL; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 149 | }; |
| 150 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 151 | struct OcclusionTrackerTestImplThreadTypes { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 152 | typedef LayerImpl LayerType; |
| 153 | typedef LayerTreeImpl HostType; |
| 154 | typedef RenderSurfaceImpl RenderSurfaceType; |
| 155 | typedef TestContentLayerImpl ContentLayerType; |
| 156 | typedef scoped_ptr<LayerImpl> LayerPtrType; |
| 157 | typedef scoped_ptr<ContentLayerType> ContentLayerPtrType; |
| 158 | typedef LayerIterator<LayerImpl, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 159 | LayerImplList, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 160 | RenderSurfaceImpl, |
| 161 | LayerIteratorActions::FrontToBack> TestLayerIterator; |
| 162 | typedef OcclusionTrackerImpl OcclusionTrackerType; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 163 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 164 | static LayerPtrType CreateLayer(HostType* host) { |
| 165 | return LayerImpl::Create(host, next_layer_impl_id++); |
| 166 | } |
| 167 | static ContentLayerPtrType CreateContentLayer(HostType* host) { |
| 168 | return make_scoped_ptr(new ContentLayerType(host, next_layer_impl_id++)); |
| 169 | } |
| 170 | static int next_layer_impl_id; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 171 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 172 | static LayerPtrType PassLayerPtr(LayerPtrType* layer) { |
| 173 | return layer->Pass(); |
| 174 | } |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 175 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 176 | static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) { |
| 177 | return layer->PassAs<LayerType>(); |
| 178 | } |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 179 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 180 | static void DestroyLayer(LayerPtrType* layer) { layer->reset(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 181 | }; |
| 182 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 183 | int OcclusionTrackerTestImplThreadTypes::next_layer_impl_id = 1; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 184 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 185 | template <typename Types> class OcclusionTrackerTest : public testing::Test { |
| 186 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 187 | explicit OcclusionTrackerTest(bool opaque_layers) |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 188 | : opaque_layers_(opaque_layers), host_(FakeLayerTreeHost::Create()) {} |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 189 | |
| 190 | virtual void RunMyTest() = 0; |
| 191 | |
| 192 | virtual void TearDown() { |
| 193 | Types::DestroyLayer(&root_); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 194 | render_surface_layer_list_.reset(); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 195 | render_surface_layer_list_impl_.clear(); |
| 196 | replica_layers_.clear(); |
| 197 | mask_layers_.clear(); |
| 198 | } |
| 199 | |
| 200 | typename Types::HostType* GetHost(); |
| 201 | |
| 202 | typename Types::ContentLayerType* CreateRoot(const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 203 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 204 | const gfx::Size& bounds) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 205 | typename Types::ContentLayerPtrType layer( |
| 206 | Types::CreateContentLayer(GetHost())); |
| 207 | typename Types::ContentLayerType* layer_ptr = layer.get(); |
| 208 | SetProperties(layer_ptr, transform, position, bounds); |
| 209 | |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 210 | DCHECK(!root_.get()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 211 | root_ = Types::PassLayerPtr(&layer); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 212 | |
| 213 | SetRootLayerOnMainThread(layer_ptr); |
| 214 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 215 | return layer_ptr; |
| 216 | } |
| 217 | |
| 218 | typename Types::LayerType* CreateLayer(typename Types::LayerType* parent, |
| 219 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 220 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 221 | const gfx::Size& bounds) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 222 | typename Types::LayerPtrType layer(Types::CreateLayer(GetHost())); |
| 223 | typename Types::LayerType* layer_ptr = layer.get(); |
| 224 | SetProperties(layer_ptr, transform, position, bounds); |
| 225 | parent->AddChild(Types::PassLayerPtr(&layer)); |
| 226 | return layer_ptr; |
| 227 | } |
| 228 | |
| 229 | typename Types::LayerType* CreateSurface(typename Types::LayerType* parent, |
| 230 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 231 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 232 | const gfx::Size& bounds) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 233 | typename Types::LayerType* layer = |
| 234 | CreateLayer(parent, transform, position, bounds); |
| 235 | layer->SetForceRenderSurface(true); |
| 236 | return layer; |
| 237 | } |
| 238 | |
| 239 | typename Types::ContentLayerType* CreateDrawingLayer( |
| 240 | typename Types::LayerType* parent, |
| 241 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 242 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 243 | const gfx::Size& bounds, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 244 | bool opaque) { |
| 245 | typename Types::ContentLayerPtrType layer( |
| 246 | Types::CreateContentLayer(GetHost())); |
| 247 | typename Types::ContentLayerType* layer_ptr = layer.get(); |
| 248 | SetProperties(layer_ptr, transform, position, bounds); |
| 249 | |
| 250 | if (opaque_layers_) { |
| 251 | layer_ptr->SetContentsOpaque(opaque); |
| 252 | } else { |
| 253 | layer_ptr->SetContentsOpaque(false); |
| 254 | if (opaque) |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 255 | layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 256 | else |
| 257 | layer_ptr->SetOpaqueContentsRect(gfx::Rect()); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 258 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 259 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 260 | parent->AddChild(Types::PassLayerPtr(&layer)); |
| 261 | return layer_ptr; |
| 262 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 263 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 264 | typename Types::LayerType* CreateReplicaLayer( |
| 265 | typename Types::LayerType* owning_layer, |
| 266 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 267 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 268 | const gfx::Size& bounds) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 269 | typename Types::ContentLayerPtrType layer( |
| 270 | Types::CreateContentLayer(GetHost())); |
| 271 | typename Types::ContentLayerType* layer_ptr = layer.get(); |
| 272 | SetProperties(layer_ptr, transform, position, bounds); |
| 273 | SetReplica(owning_layer, Types::PassLayerPtr(&layer)); |
| 274 | return layer_ptr; |
| 275 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 276 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 277 | typename Types::LayerType* CreateMaskLayer( |
| 278 | typename Types::LayerType* owning_layer, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 279 | const gfx::Size& bounds) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 280 | typename Types::ContentLayerPtrType layer( |
| 281 | Types::CreateContentLayer(GetHost())); |
| 282 | typename Types::ContentLayerType* layer_ptr = layer.get(); |
| 283 | SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds); |
| 284 | SetMask(owning_layer, Types::PassLayerPtr(&layer)); |
| 285 | return layer_ptr; |
| 286 | } |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 287 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 288 | typename Types::ContentLayerType* CreateDrawingSurface( |
| 289 | typename Types::LayerType* parent, |
| 290 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 291 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 292 | const gfx::Size& bounds, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 293 | bool opaque) { |
| 294 | typename Types::ContentLayerType* layer = |
| 295 | CreateDrawingLayer(parent, transform, position, bounds, opaque); |
| 296 | layer->SetForceRenderSurface(true); |
| 297 | return layer; |
| 298 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 299 | |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 300 | |
| 301 | void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 302 | |
| 303 | void AddCopyRequest(Layer* layer) { |
| 304 | layer->RequestCopyOfOutput( |
| 305 | CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 306 | &OcclusionTrackerTest<Types>::CopyOutputCallback, |
| 307 | base::Unretained(this)))); |
| 308 | } |
| 309 | |
| 310 | void AddCopyRequest(LayerImpl* layer) { |
| 311 | ScopedPtrVector<CopyOutputRequest> requests; |
| 312 | requests.push_back( |
| 313 | CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 314 | &OcclusionTrackerTest<Types>::CopyOutputCallback, |
| 315 | base::Unretained(this)))); |
| 316 | layer->PassCopyRequests(&requests); |
| 317 | } |
| 318 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 319 | void CalcDrawEtc(TestContentLayerImpl* root) { |
| 320 | DCHECK(root == root_.get()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 321 | DCHECK(!root->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 322 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 323 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 324 | root, root->bounds(), &render_surface_layer_list_impl_); |
| 325 | inputs.can_adjust_raster_scales = true; |
| 326 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 327 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 328 | layer_iterator_ = layer_iterator_begin_ = |
| 329 | Types::TestLayerIterator::Begin(&render_surface_layer_list_impl_); |
| 330 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 331 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 332 | void CalcDrawEtc(TestContentLayer* root) { |
| 333 | DCHECK(root == root_.get()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 334 | DCHECK(!root->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 335 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 336 | render_surface_layer_list_.reset(new RenderSurfaceLayerList); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 337 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 338 | root, root->bounds(), render_surface_layer_list_.get()); |
| 339 | inputs.can_adjust_raster_scales = true; |
| 340 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 341 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 342 | layer_iterator_ = layer_iterator_begin_ = |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 343 | Types::TestLayerIterator::Begin(render_surface_layer_list_.get()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 344 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 345 | |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 346 | void SetDrawsContent(LayerImpl* layer_impl, bool draws_content) { |
| 347 | layer_impl->SetDrawsContent(draws_content); |
| 348 | } |
| 349 | |
| 350 | void SetDrawsContent(Layer* layer, bool draws_content) { |
| 351 | layer->SetIsDrawable(draws_content); |
| 352 | } |
| 353 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 354 | void EnterLayer(typename Types::LayerType* layer, |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 355 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 356 | ASSERT_EQ(layer, *layer_iterator_); |
| 357 | ASSERT_TRUE(layer_iterator_.represents_itself()); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 358 | occlusion->EnterLayer(layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 359 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 360 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 361 | void LeaveLayer(typename Types::LayerType* layer, |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 362 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 363 | ASSERT_EQ(layer, *layer_iterator_); |
| 364 | ASSERT_TRUE(layer_iterator_.represents_itself()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 365 | occlusion->LeaveLayer(layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 366 | ++layer_iterator_; |
| 367 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 368 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 369 | void VisitLayer(typename Types::LayerType* layer, |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 370 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 371 | EnterLayer(layer, occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 372 | LeaveLayer(layer, occlusion); |
| 373 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 374 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 375 | void EnterContributingSurface( |
| 376 | typename Types::LayerType* layer, |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 377 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 378 | ASSERT_EQ(layer, *layer_iterator_); |
| 379 | ASSERT_TRUE(layer_iterator_.represents_target_render_surface()); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 380 | occlusion->EnterLayer(layer_iterator_); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 381 | occlusion->LeaveLayer(layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 382 | ++layer_iterator_; |
| 383 | ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface()); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 384 | occlusion->EnterLayer(layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 385 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 386 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 387 | void LeaveContributingSurface( |
| 388 | typename Types::LayerType* layer, |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 389 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 390 | ASSERT_EQ(layer, *layer_iterator_); |
| 391 | ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 392 | occlusion->LeaveLayer(layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 393 | ++layer_iterator_; |
| 394 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 395 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 396 | void VisitContributingSurface( |
| 397 | typename Types::LayerType* layer, |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 398 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 399 | EnterContributingSurface(layer, occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 400 | LeaveContributingSurface(layer, occlusion); |
| 401 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 402 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 403 | void ResetLayerIterator() { layer_iterator_ = layer_iterator_begin_; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 404 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 405 | const gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 406 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 407 | private: |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 408 | void SetRootLayerOnMainThread(Layer* root) { |
| 409 | host_->SetRootLayer(scoped_refptr<Layer>(root)); |
| 410 | } |
| 411 | |
| 412 | void SetRootLayerOnMainThread(LayerImpl* root) {} |
| 413 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 414 | void SetBaseProperties(typename Types::LayerType* layer, |
| 415 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 416 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 417 | const gfx::Size& bounds) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 418 | layer->SetTransform(transform); |
| 419 | layer->SetSublayerTransform(gfx::Transform()); |
| 420 | layer->SetAnchorPoint(gfx::PointF()); |
| 421 | layer->SetPosition(position); |
| 422 | layer->SetBounds(bounds); |
| 423 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 424 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 425 | void SetProperties(Layer* layer, |
| 426 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 427 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 428 | const gfx::Size& bounds) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 429 | SetBaseProperties(layer, transform, position, bounds); |
| 430 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 431 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 432 | void SetProperties(LayerImpl* layer, |
| 433 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 434 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 435 | const gfx::Size& bounds) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 436 | SetBaseProperties(layer, transform, position, bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 437 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 438 | layer->SetContentBounds(layer->bounds()); |
| 439 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 440 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 441 | void SetReplica(Layer* owning_layer, scoped_refptr<Layer> layer) { |
| 442 | owning_layer->SetReplicaLayer(layer.get()); |
| 443 | replica_layers_.push_back(layer); |
| 444 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 445 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 446 | void SetReplica(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) { |
| 447 | owning_layer->SetReplicaLayer(layer.Pass()); |
| 448 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 449 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 450 | void SetMask(Layer* owning_layer, scoped_refptr<Layer> layer) { |
| 451 | owning_layer->SetMaskLayer(layer.get()); |
| 452 | mask_layers_.push_back(layer); |
| 453 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 454 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 455 | void SetMask(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) { |
| 456 | owning_layer->SetMaskLayer(layer.Pass()); |
| 457 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 458 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 459 | bool opaque_layers_; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 460 | scoped_ptr<FakeLayerTreeHost> host_; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 461 | // These hold ownership of the layers for the duration of the test. |
| 462 | typename Types::LayerPtrType root_; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 463 | scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_; |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 464 | LayerImplList render_surface_layer_list_impl_; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 465 | typename Types::TestLayerIterator layer_iterator_begin_; |
| 466 | typename Types::TestLayerIterator layer_iterator_; |
| 467 | typename Types::LayerType* last_layer_visited_; |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 468 | LayerList replica_layers_; |
| 469 | LayerList mask_layers_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 470 | }; |
| 471 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 472 | template <> |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 473 | FakeLayerTreeHost* |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 474 | OcclusionTrackerTest<OcclusionTrackerTestMainThreadTypes>::GetHost() { |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 475 | return host_.get(); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 476 | } |
| 477 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 478 | template <> |
| 479 | LayerTreeImpl* |
| 480 | OcclusionTrackerTest<OcclusionTrackerTestImplThreadTypes>::GetHost() { |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 481 | return host_->host_impl()->active_tree(); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 482 | } |
| 483 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 484 | #define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \ |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 485 | class ClassName##MainThreadOpaqueLayers \ |
| 486 | : public ClassName<OcclusionTrackerTestMainThreadTypes> { \ |
| 487 | public: /* NOLINT(whitespace/indent) */ \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 488 | ClassName##MainThreadOpaqueLayers() \ |
| 489 | : ClassName<OcclusionTrackerTestMainThreadTypes>(true) {} \ |
| 490 | }; \ |
| 491 | TEST_F(ClassName##MainThreadOpaqueLayers, RunTest) { RunMyTest(); } |
| 492 | #define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \ |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 493 | class ClassName##MainThreadOpaquePaints \ |
| 494 | : public ClassName<OcclusionTrackerTestMainThreadTypes> { \ |
| 495 | public: /* NOLINT(whitespace/indent) */ \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 496 | ClassName##MainThreadOpaquePaints() \ |
| 497 | : ClassName<OcclusionTrackerTestMainThreadTypes>(false) {} \ |
| 498 | }; \ |
| 499 | TEST_F(ClassName##MainThreadOpaquePaints, RunTest) { RunMyTest(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 500 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 501 | #define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \ |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 502 | class ClassName##ImplThreadOpaqueLayers \ |
| 503 | : public ClassName<OcclusionTrackerTestImplThreadTypes> { \ |
| 504 | public: /* NOLINT(whitespace/indent) */ \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 505 | ClassName##ImplThreadOpaqueLayers() \ |
| 506 | : ClassName<OcclusionTrackerTestImplThreadTypes>(true) {} \ |
| 507 | }; \ |
| 508 | TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); } |
| 509 | #define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \ |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 510 | class ClassName##ImplThreadOpaquePaints \ |
| 511 | : public ClassName<OcclusionTrackerTestImplThreadTypes> { \ |
| 512 | public: /* NOLINT(whitespace/indent) */ \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 513 | ClassName##ImplThreadOpaquePaints() \ |
| 514 | : ClassName<OcclusionTrackerTestImplThreadTypes>(false) {} \ |
| 515 | }; \ |
| 516 | TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 517 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 518 | #define ALL_OCCLUSIONTRACKER_TEST(ClassName) \ |
| 519 | RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \ |
| 520 | RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \ |
| 521 | RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \ |
| 522 | RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 523 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 524 | #define MAIN_THREAD_TEST(ClassName) \ |
| 525 | RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 526 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 527 | #define IMPL_THREAD_TEST(ClassName) \ |
| 528 | RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 529 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 530 | #define MAIN_AND_IMPL_THREAD_TEST(ClassName) \ |
| 531 | RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \ |
| 532 | RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 533 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 534 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 535 | class OcclusionTrackerTestIdentityTransforms |
| 536 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 537 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 538 | explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 539 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
[email protected] | ece1d95 | 2012-10-18 21:26:07 | [diff] [blame] | 540 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 541 | void RunMyTest() { |
| 542 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 543 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 544 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 545 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 546 | typename Types::ContentLayerType* layer = |
| 547 | this->CreateDrawingLayer(parent, |
| 548 | this->identity_matrix, |
| 549 | gfx::PointF(30.f, 30.f), |
| 550 | gfx::Size(500, 500), |
| 551 | true); |
| 552 | parent->SetMasksToBounds(true); |
| 553 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 554 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 555 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 556 | typename Types::RenderSurfaceType> occlusion( |
| 557 | gfx::Rect(0, 0, 1000, 1000), false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 558 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 559 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 560 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 561 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 562 | EXPECT_EQ(gfx::Rect().ToString(), |
| 563 | occlusion.occlusion_from_outside_target().ToString()); |
| 564 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 565 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 566 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 567 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70))); |
| 568 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70))); |
| 569 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70))); |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 570 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 69, 70))); |
| 571 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 69))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 572 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 573 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 574 | parent, gfx::Rect(30, 30, 70, 70)).IsEmpty()); |
| 575 | EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70), |
| 576 | occlusion.UnoccludedLayerContentRect( |
| 577 | parent, gfx::Rect(29, 30, 70, 70))); |
| 578 | EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70), |
| 579 | occlusion.UnoccludedLayerContentRect( |
| 580 | parent, gfx::Rect(29, 29, 70, 70))); |
| 581 | EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1), |
| 582 | occlusion.UnoccludedLayerContentRect( |
| 583 | parent, gfx::Rect(30, 29, 70, 70))); |
| 584 | EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1), |
| 585 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 586 | parent, gfx::Rect(31, 29, 69, 70))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 587 | EXPECT_RECT_EQ(gfx::Rect(), |
| 588 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 589 | parent, gfx::Rect(31, 30, 69, 70))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 590 | EXPECT_RECT_EQ(gfx::Rect(), |
| 591 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 592 | parent, gfx::Rect(31, 31, 69, 69))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 593 | EXPECT_RECT_EQ(gfx::Rect(), |
| 594 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 595 | parent, gfx::Rect(30, 31, 70, 69))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 596 | EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69), |
| 597 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 598 | parent, gfx::Rect(29, 31, 70, 69))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 599 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 600 | }; |
| 601 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 602 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 603 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 604 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 605 | class OcclusionTrackerTestQuadsMismatchLayer |
| 606 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 607 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 608 | explicit OcclusionTrackerTestQuadsMismatchLayer(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 609 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 610 | void RunMyTest() { |
| 611 | gfx::Transform layer_transform; |
| 612 | layer_transform.Translate(10.0, 10.0); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 613 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 614 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 615 | this->identity_matrix, gfx::Point(0, 0), gfx::Size(100, 100)); |
| 616 | typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer( |
| 617 | parent, layer_transform, gfx::PointF(), gfx::Size(90, 90), true); |
| 618 | typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer( |
| 619 | layer1, layer_transform, gfx::PointF(), gfx::Size(50, 50), true); |
| 620 | this->CalcDrawEtc(parent); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 621 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 622 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 623 | typename Types::RenderSurfaceType> occlusion( |
| 624 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 625 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 626 | this->VisitLayer(layer2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 627 | this->EnterLayer(layer1, &occlusion); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 628 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 629 | EXPECT_EQ(gfx::Rect().ToString(), |
| 630 | occlusion.occlusion_from_outside_target().ToString()); |
| 631 | EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(), |
| 632 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 633 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 634 | // This checks cases where the quads don't match their "containing" |
| 635 | // layers, e.g. in terms of transforms or clip rect. This is typical for |
| 636 | // DelegatedRendererLayer. |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 637 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 638 | gfx::Transform quad_transform; |
| 639 | quad_transform.Translate(30.0, 30.0); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 640 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 641 | EXPECT_TRUE(occlusion.UnoccludedContentRect(parent, |
| 642 | gfx::Rect(0, 0, 10, 10), |
| 643 | quad_transform, |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 644 | false).IsEmpty()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 645 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 646 | occlusion.UnoccludedContentRect(parent, |
| 647 | gfx::Rect(0, 0, 10, 10), |
| 648 | quad_transform, |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 649 | true)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 650 | EXPECT_RECT_EQ(gfx::Rect(40, 40, 10, 10), |
| 651 | occlusion.UnoccludedContentRect(parent, |
| 652 | gfx::Rect(40, 40, 10, 10), |
| 653 | quad_transform, |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 654 | false)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 655 | EXPECT_RECT_EQ(gfx::Rect(40, 30, 5, 10), |
| 656 | occlusion.UnoccludedContentRect(parent, |
| 657 | gfx::Rect(35, 30, 10, 10), |
| 658 | quad_transform, |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 659 | false)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 660 | } |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 661 | }; |
| 662 | |
| 663 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestQuadsMismatchLayer); |
| 664 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 665 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 666 | class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 667 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 668 | explicit OcclusionTrackerTestRotatedChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 669 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 670 | void RunMyTest() { |
| 671 | gfx::Transform layer_transform; |
| 672 | layer_transform.Translate(250.0, 250.0); |
| 673 | layer_transform.Rotate(90.0); |
| 674 | layer_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 675 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 676 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 677 | this->identity_matrix, gfx::Point(0, 0), gfx::Size(200, 200)); |
| 678 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 679 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 680 | typename Types::ContentLayerType* layer = |
| 681 | this->CreateDrawingLayer(parent, |
| 682 | layer_transform, |
| 683 | gfx::PointF(30.f, 30.f), |
| 684 | gfx::Size(500, 500), |
| 685 | true); |
| 686 | parent->SetMasksToBounds(true); |
| 687 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 688 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 689 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 690 | typename Types::RenderSurfaceType> occlusion( |
| 691 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 692 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 693 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 694 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 695 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 696 | EXPECT_EQ(gfx::Rect().ToString(), |
| 697 | occlusion.occlusion_from_outside_target().ToString()); |
| 698 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 699 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 700 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 701 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70))); |
| 702 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70))); |
| 703 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70))); |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 704 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 69, 70))); |
| 705 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 69))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 706 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 707 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 708 | parent, gfx::Rect(30, 30, 70, 70)).IsEmpty()); |
| 709 | EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70), |
| 710 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 711 | parent, gfx::Rect(29, 30, 69, 70))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 712 | EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70), |
| 713 | occlusion.UnoccludedLayerContentRect( |
| 714 | parent, gfx::Rect(29, 29, 70, 70))); |
| 715 | EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1), |
| 716 | occlusion.UnoccludedLayerContentRect( |
| 717 | parent, gfx::Rect(30, 29, 70, 70))); |
| 718 | EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1), |
| 719 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 720 | parent, gfx::Rect(31, 29, 69, 70))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 721 | EXPECT_RECT_EQ(gfx::Rect(), |
| 722 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 723 | parent, gfx::Rect(31, 30, 69, 70))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 724 | EXPECT_RECT_EQ(gfx::Rect(), |
| 725 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 726 | parent, gfx::Rect(31, 31, 69, 69))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 727 | EXPECT_RECT_EQ(gfx::Rect(), |
| 728 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 729 | parent, gfx::Rect(30, 31, 70, 69))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 730 | EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69), |
| 731 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 732 | parent, gfx::Rect(29, 31, 70, 69))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 733 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 734 | }; |
| 735 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 736 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 737 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 738 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 739 | class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 740 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 741 | explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 742 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 743 | void RunMyTest() { |
| 744 | gfx::Transform layer_transform; |
| 745 | layer_transform.Translate(20.0, 20.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 746 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 747 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 748 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 749 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 750 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 751 | typename Types::ContentLayerType* layer = |
| 752 | this->CreateDrawingLayer(parent, |
| 753 | layer_transform, |
| 754 | gfx::PointF(30.f, 30.f), |
| 755 | gfx::Size(500, 500), |
| 756 | true); |
| 757 | parent->SetMasksToBounds(true); |
| 758 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 759 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 760 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 761 | typename Types::RenderSurfaceType> occlusion( |
| 762 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 763 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 764 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 765 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 766 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 767 | EXPECT_EQ(gfx::Rect().ToString(), |
| 768 | occlusion.occlusion_from_outside_target().ToString()); |
| 769 | EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(), |
| 770 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 771 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 772 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 50, 50, 50))); |
| 773 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(49, 50, 50, 50))); |
| 774 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(50, 49, 50, 50))); |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 775 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(51, 50, 49, 50))); |
| 776 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 51, 50, 49))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 777 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 778 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 779 | parent, gfx::Rect(50, 50, 50, 50)).IsEmpty()); |
| 780 | EXPECT_RECT_EQ(gfx::Rect(49, 50, 1, 50), |
| 781 | occlusion.UnoccludedLayerContentRect( |
| 782 | parent, gfx::Rect(49, 50, 50, 50))); |
| 783 | EXPECT_RECT_EQ(gfx::Rect(49, 49, 50, 50), |
| 784 | occlusion.UnoccludedLayerContentRect( |
| 785 | parent, gfx::Rect(49, 49, 50, 50))); |
| 786 | EXPECT_RECT_EQ(gfx::Rect(50, 49, 50, 1), |
| 787 | occlusion.UnoccludedLayerContentRect( |
| 788 | parent, gfx::Rect(50, 49, 50, 50))); |
| 789 | EXPECT_RECT_EQ(gfx::Rect(51, 49, 49, 1), |
| 790 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 791 | parent, gfx::Rect(51, 49, 49, 50))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 792 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 793 | parent, gfx::Rect(51, 50, 49, 50)).IsEmpty()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 794 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 795 | parent, gfx::Rect(51, 51, 49, 49)).IsEmpty()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 796 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 797 | parent, gfx::Rect(50, 51, 50, 49)).IsEmpty()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 798 | EXPECT_RECT_EQ(gfx::Rect(49, 51, 1, 49), |
| 799 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 800 | parent, gfx::Rect(49, 51, 50, 49))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 801 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 802 | }; |
| 803 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 804 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 805 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 806 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 807 | class OcclusionTrackerTestChildInRotatedChild |
| 808 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 809 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 810 | explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 811 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 812 | void RunMyTest() { |
| 813 | gfx::Transform child_transform; |
| 814 | child_transform.Translate(250.0, 250.0); |
| 815 | child_transform.Rotate(90.0); |
| 816 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 817 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 818 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 819 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 820 | parent->SetMasksToBounds(true); |
[email protected] | 3a9a92d | 2013-07-11 04:37:00 | [diff] [blame] | 821 | typename Types::LayerType* child = this->CreateSurface( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 822 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); |
| 823 | child->SetMasksToBounds(true); |
| 824 | typename Types::ContentLayerType* layer = |
| 825 | this->CreateDrawingLayer(child, |
| 826 | this->identity_matrix, |
| 827 | gfx::PointF(10.f, 10.f), |
| 828 | gfx::Size(500, 500), |
| 829 | true); |
| 830 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 831 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 832 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 833 | typename Types::RenderSurfaceType> occlusion( |
| 834 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 835 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 836 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 837 | this->EnterContributingSurface(child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 838 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 839 | EXPECT_EQ(gfx::Rect().ToString(), |
| 840 | occlusion.occlusion_from_outside_target().ToString()); |
| 841 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), |
| 842 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 843 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 844 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 845 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 846 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 847 | EXPECT_EQ(gfx::Rect().ToString(), |
| 848 | occlusion.occlusion_from_outside_target().ToString()); |
| 849 | EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), |
| 850 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 851 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 852 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60))); |
| 853 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60))); |
| 854 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60))); |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 855 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 40, 69, 60))); |
| 856 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 41, 70, 59))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 857 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 858 | /* Justification for the above occlusion from |layer|: |
| 859 | 100 |
| 860 | +---------------------+ |
| 861 | | | |
| 862 | | 30 | rotate(90) |
| 863 | | 30 + ---------------------------------+ |
| 864 | 100 | | 10 | | ==> |
| 865 | | |10+---------------------------------+ |
| 866 | | | | | | | |
| 867 | | | | | | | |
| 868 | | | | | | | |
| 869 | +----|--|-------------+ | | |
| 870 | | | | | |
| 871 | | | | | |
| 872 | | | | |500 |
| 873 | | | | | |
| 874 | | | | | |
| 875 | | | | | |
| 876 | | | | | |
| 877 | +--|-------------------------------+ | |
| 878 | | | |
| 879 | +---------------------------------+ |
| 880 | 500 |
| 881 | |
| 882 | +---------------------+ |
| 883 | | |30 Visible region of |layer|: ///// |
| 884 | | | |
| 885 | | +---------------------------------+ |
| 886 | 100| | |10 | |
| 887 | | +---------------------------------+ | |
| 888 | | | |///////////////| 420 | | |
| 889 | | | |///////////////|60 | | |
| 890 | | | |///////////////| | | |
| 891 | +--|--|---------------+ | | |
| 892 | 20|10| 70 | | |
| 893 | | | | | |
| 894 | | | | | |
| 895 | | | | | |
| 896 | | | | | |
| 897 | | | | | |
| 898 | | | |10| |
| 899 | | +------------------------------|--+ |
| 900 | | 490 | |
| 901 | +---------------------------------+ |
| 902 | 500 |
| 903 | |
| 904 | */ |
| 905 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 906 | }; |
| 907 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 908 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 909 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 910 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 911 | class OcclusionTrackerTestScaledRenderSurface |
| 912 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 913 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 914 | explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 915 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 916 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 917 | void RunMyTest() { |
| 918 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 919 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 920 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 921 | gfx::Transform layer1_matrix; |
| 922 | layer1_matrix.Scale(2.0, 2.0); |
| 923 | typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer( |
| 924 | parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 925 | layer1->SetForceRenderSurface(true); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 926 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 927 | gfx::Transform layer2_matrix; |
| 928 | layer2_matrix.Translate(25.0, 25.0); |
| 929 | typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer( |
| 930 | layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true); |
| 931 | typename Types::ContentLayerType* occluder = |
| 932 | this->CreateDrawingLayer(parent, |
| 933 | this->identity_matrix, |
| 934 | gfx::PointF(100.f, 100.f), |
| 935 | gfx::Size(500, 500), |
| 936 | true); |
| 937 | this->CalcDrawEtc(parent); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 938 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 939 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 940 | typename Types::RenderSurfaceType> occlusion( |
| 941 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 942 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 943 | this->VisitLayer(occluder, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 944 | this->EnterLayer(layer2, &occlusion); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 945 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 946 | EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), |
| 947 | occlusion.occlusion_from_outside_target().ToString()); |
| 948 | EXPECT_EQ(gfx::Rect().ToString(), |
| 949 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 950 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 951 | EXPECT_RECT_EQ( |
| 952 | gfx::Rect(0, 0, 25, 25), |
| 953 | occlusion.UnoccludedLayerContentRect(layer2, gfx::Rect(0, 0, 25, 25))); |
| 954 | EXPECT_RECT_EQ(gfx::Rect(10, 25, 15, 25), |
| 955 | occlusion.UnoccludedLayerContentRect( |
| 956 | layer2, gfx::Rect(10, 25, 25, 25))); |
| 957 | EXPECT_RECT_EQ(gfx::Rect(25, 10, 25, 15), |
| 958 | occlusion.UnoccludedLayerContentRect( |
| 959 | layer2, gfx::Rect(25, 10, 25, 25))); |
| 960 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 961 | layer2, gfx::Rect(25, 25, 25, 25)).IsEmpty()); |
| 962 | } |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 963 | }; |
| 964 | |
| 965 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface); |
| 966 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 967 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 968 | class OcclusionTrackerTestVisitTargetTwoTimes |
| 969 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 970 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 971 | explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 972 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 973 | void RunMyTest() { |
| 974 | gfx::Transform child_transform; |
| 975 | child_transform.Translate(250.0, 250.0); |
| 976 | child_transform.Rotate(90.0); |
| 977 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 978 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 979 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 980 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 981 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 982 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 983 | parent->SetMasksToBounds(true); |
[email protected] | 3a9a92d | 2013-07-11 04:37:00 | [diff] [blame] | 984 | typename Types::LayerType* child = this->CreateSurface( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 985 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); |
| 986 | child->SetMasksToBounds(true); |
| 987 | typename Types::ContentLayerType* layer = |
| 988 | this->CreateDrawingLayer(child, |
| 989 | this->identity_matrix, |
| 990 | gfx::PointF(10.f, 10.f), |
| 991 | gfx::Size(500, 500), |
| 992 | true); |
| 993 | // |child2| makes |parent|'s surface get considered by OcclusionTracker |
| 994 | // first, instead of |child|'s. This exercises different code in |
| 995 | // LeaveToRenderTarget, as the target surface has already been seen. |
| 996 | typename Types::ContentLayerType* child2 = |
| 997 | this->CreateDrawingLayer(parent, |
| 998 | this->identity_matrix, |
| 999 | gfx::PointF(30.f, 30.f), |
| 1000 | gfx::Size(60, 20), |
| 1001 | true); |
| 1002 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1003 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1004 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1005 | typename Types::RenderSurfaceType> occlusion( |
| 1006 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1007 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1008 | this->VisitLayer(child2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1009 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1010 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1011 | occlusion.occlusion_from_outside_target().ToString()); |
| 1012 | EXPECT_EQ(gfx::Rect(30, 30, 60, 20).ToString(), |
| 1013 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1014 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1015 | this->VisitLayer(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1016 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1017 | EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(), |
| 1018 | occlusion.occlusion_from_outside_target().ToString()); |
| 1019 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), |
| 1020 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1021 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1022 | this->EnterContributingSurface(child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1023 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1024 | EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(), |
| 1025 | occlusion.occlusion_from_outside_target().ToString()); |
| 1026 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).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 | // Occlusion in |child2| should get merged with the |child| surface we are |
| 1030 | // leaving now. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1031 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1032 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1033 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1034 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1035 | occlusion.occlusion_from_outside_target().ToString()); |
| 1036 | EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60)) |
| 1037 | .ToString(), |
| 1038 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1039 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1040 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70))); |
| 1041 | EXPECT_RECT_EQ(gfx::Rect(90, 30, 10, 10), |
| 1042 | occlusion.UnoccludedLayerContentRect( |
| 1043 | parent, gfx::Rect(30, 30, 70, 70))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1044 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1045 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 60, 10))); |
| 1046 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 60, 10))); |
| 1047 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 60, 10))); |
| 1048 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 60, 10))); |
| 1049 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 60, 10))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1050 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1051 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60))); |
| 1052 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60))); |
| 1053 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1054 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1055 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1056 | parent, gfx::Rect(30, 30, 60, 10)).IsEmpty()); |
| 1057 | EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 10), |
| 1058 | occlusion.UnoccludedLayerContentRect( |
| 1059 | parent, gfx::Rect(29, 30, 60, 10))); |
| 1060 | EXPECT_RECT_EQ(gfx::Rect(30, 29, 60, 1), |
| 1061 | occlusion.UnoccludedLayerContentRect( |
| 1062 | parent, gfx::Rect(30, 29, 60, 10))); |
| 1063 | EXPECT_RECT_EQ(gfx::Rect(90, 30, 1, 10), |
| 1064 | occlusion.UnoccludedLayerContentRect( |
| 1065 | parent, gfx::Rect(31, 30, 60, 10))); |
| 1066 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1067 | parent, gfx::Rect(30, 31, 60, 10)).IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1068 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1069 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1070 | parent, gfx::Rect(30, 40, 70, 60)).IsEmpty()); |
| 1071 | EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60), |
| 1072 | occlusion.UnoccludedLayerContentRect( |
| 1073 | parent, gfx::Rect(29, 40, 70, 60))); |
| 1074 | // This rect is mostly occluded by |child2|. |
| 1075 | EXPECT_RECT_EQ(gfx::Rect(90, 39, 10, 1), |
| 1076 | occlusion.UnoccludedLayerContentRect( |
| 1077 | parent, gfx::Rect(30, 39, 70, 60))); |
| 1078 | // This rect extends past top/right ends of |child2|. |
| 1079 | EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 11), |
| 1080 | occlusion.UnoccludedLayerContentRect( |
| 1081 | parent, gfx::Rect(30, 29, 70, 70))); |
| 1082 | // This rect extends past left/right ends of |child2|. |
| 1083 | EXPECT_RECT_EQ(gfx::Rect(20, 39, 80, 60), |
| 1084 | occlusion.UnoccludedLayerContentRect( |
| 1085 | parent, gfx::Rect(20, 39, 80, 60))); |
| 1086 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1087 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 1088 | parent, gfx::Rect(31, 40, 69, 60))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1089 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1090 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 1091 | parent, gfx::Rect(30, 41, 70, 59))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1092 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1093 | /* Justification for the above occlusion from |layer|: |
| 1094 | 100 |
| 1095 | +---------------------+ |
| 1096 | | | |
| 1097 | | 30 | rotate(90) |
| 1098 | | 30 + ------------+--------------------+ |
| 1099 | 100 | | 10 | | | ==> |
| 1100 | | |10+----------|----------------------+ |
| 1101 | | + ------------+ | | | |
| 1102 | | | | | | | |
| 1103 | | | | | | | |
| 1104 | +----|--|-------------+ | | |
| 1105 | | | | | |
| 1106 | | | | | |
| 1107 | | | | |500 |
| 1108 | | | | | |
| 1109 | | | | | |
| 1110 | | | | | |
| 1111 | | | | | |
| 1112 | +--|-------------------------------+ | |
| 1113 | | | |
| 1114 | +---------------------------------+ |
| 1115 | 500 |
| 1116 | |
| 1117 | |
| 1118 | +---------------------+ |
| 1119 | | |30 Visible region of |layer|: ///// |
| 1120 | | 30 60 | |child2|: \\\\\ |
| 1121 | | 30 +------------+--------------------+ |
| 1122 | | |\\\\\\\\\\\\| |10 | |
| 1123 | | +--|\\\\\\\\\\\\|-----------------+ | |
| 1124 | | | +------------+//| 420 | | |
| 1125 | | | |///////////////|60 | | |
| 1126 | | | |///////////////| | | |
| 1127 | +--|--|---------------+ | | |
| 1128 | 20|10| 70 | | |
| 1129 | | | | | |
| 1130 | | | | | |
| 1131 | | | | | |
| 1132 | | | | | |
| 1133 | | | | | |
| 1134 | | | |10| |
| 1135 | | +------------------------------|--+ |
| 1136 | | 490 | |
| 1137 | +---------------------------------+ |
| 1138 | 500 |
| 1139 | */ |
| 1140 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1141 | }; |
| 1142 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1143 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1144 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1145 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1146 | class OcclusionTrackerTestSurfaceRotatedOffAxis |
| 1147 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1148 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1149 | explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1150 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1151 | void RunMyTest() { |
| 1152 | gfx::Transform child_transform; |
| 1153 | child_transform.Translate(250.0, 250.0); |
| 1154 | child_transform.Rotate(95.0); |
| 1155 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1156 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1157 | gfx::Transform layer_transform; |
| 1158 | layer_transform.Translate(10.0, 10.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1159 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1160 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 1161 | this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000)); |
| 1162 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 1163 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 1164 | typename Types::LayerType* child = this->CreateLayer( |
| 1165 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); |
| 1166 | child->SetMasksToBounds(true); |
| 1167 | typename Types::ContentLayerType* layer = this->CreateDrawingLayer( |
| 1168 | child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true); |
| 1169 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1170 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1171 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1172 | typename Types::RenderSurfaceType> occlusion( |
| 1173 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1174 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1175 | gfx::Rect clipped_layer_in_child = MathUtil::MapClippedRect( |
| 1176 | layer_transform, layer->visible_content_rect()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1177 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1178 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1179 | this->EnterContributingSurface(child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1180 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1181 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1182 | occlusion.occlusion_from_outside_target().ToString()); |
| 1183 | EXPECT_EQ(clipped_layer_in_child.ToString(), |
| 1184 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1185 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1186 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1187 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1188 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1189 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1190 | occlusion.occlusion_from_outside_target().ToString()); |
| 1191 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1192 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1193 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1194 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(75, 55, 1, 1))); |
| 1195 | EXPECT_RECT_EQ( |
| 1196 | gfx::Rect(75, 55, 1, 1), |
| 1197 | occlusion.UnoccludedLayerContentRect(parent, gfx::Rect(75, 55, 1, 1))); |
| 1198 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1199 | }; |
| 1200 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1201 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1202 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1203 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1204 | class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren |
| 1205 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1206 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1207 | explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1208 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1209 | void RunMyTest() { |
| 1210 | gfx::Transform child_transform; |
| 1211 | child_transform.Translate(250.0, 250.0); |
| 1212 | child_transform.Rotate(90.0); |
| 1213 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1214 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1215 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 1216 | this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000)); |
| 1217 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 1218 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 1219 | parent->SetMasksToBounds(true); |
| 1220 | typename Types::ContentLayerType* child = |
[email protected] | 3a9a92d | 2013-07-11 04:37:00 | [diff] [blame] | 1221 | this->CreateDrawingSurface(parent, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1222 | child_transform, |
| 1223 | gfx::PointF(30.f, 30.f), |
| 1224 | gfx::Size(500, 500), |
| 1225 | false); |
| 1226 | child->SetMasksToBounds(true); |
| 1227 | typename Types::ContentLayerType* layer1 = |
| 1228 | this->CreateDrawingLayer(child, |
| 1229 | this->identity_matrix, |
| 1230 | gfx::PointF(10.f, 10.f), |
| 1231 | gfx::Size(500, 500), |
| 1232 | true); |
| 1233 | typename Types::ContentLayerType* layer2 = |
| 1234 | this->CreateDrawingLayer(child, |
| 1235 | this->identity_matrix, |
| 1236 | gfx::PointF(10.f, 450.f), |
| 1237 | gfx::Size(500, 60), |
| 1238 | true); |
| 1239 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1240 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1241 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1242 | typename Types::RenderSurfaceType> occlusion( |
| 1243 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1244 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1245 | this->VisitLayer(layer2, &occlusion); |
| 1246 | this->VisitLayer(layer1, &occlusion); |
| 1247 | this->VisitLayer(child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1248 | this->EnterContributingSurface(child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1249 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1250 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1251 | occlusion.occlusion_from_outside_target().ToString()); |
| 1252 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), |
| 1253 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1254 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1255 | EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 430, 60, 70))); |
| 1256 | EXPECT_FALSE(occlusion.OccludedLayer(child, gfx::Rect(9, 430, 60, 70))); |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 1257 | EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(11, 430, 59, 70))); |
| 1258 | EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 431, 60, 69))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1259 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1260 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1261 | child, gfx::Rect(10, 430, 60, 70)).IsEmpty()); |
| 1262 | EXPECT_RECT_EQ( |
| 1263 | gfx::Rect(9, 430, 1, 70), |
| 1264 | occlusion.UnoccludedLayerContentRect(child, gfx::Rect(9, 430, 60, 70))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1265 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1266 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 1267 | child, gfx::Rect(11, 430, 59, 70))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1268 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1269 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 1270 | child, gfx::Rect(10, 431, 60, 69))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1271 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1272 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1273 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1274 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1275 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1276 | occlusion.occlusion_from_outside_target().ToString()); |
| 1277 | EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), |
| 1278 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1279 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1280 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60))); |
| 1281 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60))); |
| 1282 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1283 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1284 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1285 | parent, gfx::Rect(30, 40, 70, 60)).IsEmpty()); |
| 1286 | EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60), |
| 1287 | occlusion.UnoccludedLayerContentRect( |
| 1288 | parent, gfx::Rect(29, 40, 70, 60))); |
| 1289 | EXPECT_RECT_EQ(gfx::Rect(30, 39, 70, 1), |
| 1290 | occlusion.UnoccludedLayerContentRect( |
| 1291 | parent, gfx::Rect(30, 39, 70, 60))); |
| 1292 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1293 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 1294 | parent, gfx::Rect(31, 40, 69, 60))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1295 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1296 | occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 1297 | parent, gfx::Rect(30, 41, 70, 59))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1298 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1299 | /* Justification for the above occlusion from |layer1| and |layer2|: |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1300 | |
| 1301 | +---------------------+ |
| 1302 | | |30 Visible region of |layer1|: ///// |
| 1303 | | | Visible region of |layer2|: \\\\\ |
| 1304 | | +---------------------------------+ |
| 1305 | | | |10 | |
| 1306 | | +---------------+-----------------+ | |
| 1307 | | | |\\\\\\\\\\\\|//| 420 | | |
| 1308 | | | |\\\\\\\\\\\\|//|60 | | |
| 1309 | | | |\\\\\\\\\\\\|//| | | |
| 1310 | +--|--|------------|--+ | | |
| 1311 | 20|10| 70 | | | |
| 1312 | | | | | | |
| 1313 | | | | | | |
| 1314 | | | | | | |
| 1315 | | | | | | |
| 1316 | | | | | | |
| 1317 | | | | |10| |
| 1318 | | +------------|-----------------|--+ |
| 1319 | | | 490 | |
| 1320 | +---------------+-----------------+ |
| 1321 | 60 440 |
| 1322 | */ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1323 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1324 | }; |
| 1325 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1326 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1327 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1328 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1329 | class OcclusionTrackerTestOverlappingSurfaceSiblings |
| 1330 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1331 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1332 | explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1333 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1334 | void RunMyTest() { |
| 1335 | gfx::Transform child_transform; |
| 1336 | child_transform.Translate(250.0, 250.0); |
| 1337 | child_transform.Rotate(90.0); |
| 1338 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1339 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1340 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1341 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 1342 | parent->SetMasksToBounds(true); |
| 1343 | typename Types::LayerType* child1 = this->CreateSurface( |
| 1344 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(10, 10)); |
| 1345 | typename Types::LayerType* child2 = this->CreateSurface( |
| 1346 | parent, child_transform, gfx::PointF(20.f, 40.f), gfx::Size(10, 10)); |
| 1347 | typename Types::ContentLayerType* layer1 = |
| 1348 | this->CreateDrawingLayer(child1, |
| 1349 | this->identity_matrix, |
| 1350 | gfx::PointF(-10.f, -10.f), |
| 1351 | gfx::Size(510, 510), |
| 1352 | true); |
| 1353 | typename Types::ContentLayerType* layer2 = |
| 1354 | this->CreateDrawingLayer(child2, |
| 1355 | this->identity_matrix, |
| 1356 | gfx::PointF(-10.f, -10.f), |
| 1357 | gfx::Size(510, 510), |
| 1358 | true); |
| 1359 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1360 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1361 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1362 | typename Types::RenderSurfaceType> occlusion( |
| 1363 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1364 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1365 | this->VisitLayer(layer2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1366 | this->EnterContributingSurface(child2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1367 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1368 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1369 | occlusion.occlusion_from_outside_target().ToString()); |
| 1370 | EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), |
| 1371 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1372 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1373 | // There is nothing above child2's surface in the z-order. |
| 1374 | EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80), |
| 1375 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 1376 | child2, false, gfx::Rect(-10, 420, 70, 80))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1377 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1378 | this->LeaveContributingSurface(child2, &occlusion); |
| 1379 | this->VisitLayer(layer1, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1380 | this->EnterContributingSurface(child1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1381 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1382 | EXPECT_EQ(gfx::Rect(0, 430, 70, 80).ToString(), |
| 1383 | occlusion.occlusion_from_outside_target().ToString()); |
| 1384 | EXPECT_EQ(gfx::Rect(-10, 430, 80, 70).ToString(), |
| 1385 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1386 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1387 | // child2's contents will occlude child1 below it. |
| 1388 | EXPECT_RECT_EQ(gfx::Rect(-10, 430, 10, 70), |
| 1389 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 1390 | child1, false, gfx::Rect(-10, 430, 80, 70))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1391 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1392 | this->LeaveContributingSurface(child1, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1393 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1394 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1395 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1396 | occlusion.occlusion_from_outside_target().ToString()); |
| 1397 | EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70)) |
| 1398 | .ToString(), |
| 1399 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1400 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1401 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 20, 80, 80))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1402 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1403 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 20, 70, 80))); |
| 1404 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 20, 70, 80))); |
| 1405 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 19, 70, 80))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1406 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1407 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(20, 30, 80, 70))); |
| 1408 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(19, 30, 80, 70))); |
| 1409 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 29, 80, 70))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1410 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1411 | /* Justification for the above occlusion: |
| 1412 | 100 |
| 1413 | +---------------------+ |
| 1414 | | 20 | layer1 |
| 1415 | | 30+ ---------------------------------+ |
| 1416 | 100 | 30| | layer2 | |
| 1417 | |20+----------------------------------+ | |
| 1418 | | | | | | | |
| 1419 | | | | | | | |
| 1420 | | | | | | | |
| 1421 | +--|-|----------------+ | | |
| 1422 | | | | | 510 |
| 1423 | | | | | |
| 1424 | | | | | |
| 1425 | | | | | |
| 1426 | | | | | |
| 1427 | | | | | |
| 1428 | | | | | |
| 1429 | | +--------------------------------|-+ |
| 1430 | | | |
| 1431 | +----------------------------------+ |
| 1432 | 510 |
| 1433 | */ |
| 1434 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1435 | }; |
| 1436 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1437 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1438 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1439 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1440 | class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms |
| 1441 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1442 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1443 | explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1444 | bool opaque_layers) |
| 1445 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1446 | void RunMyTest() { |
| 1447 | gfx::Transform child1_transform; |
| 1448 | child1_transform.Translate(250.0, 250.0); |
| 1449 | child1_transform.Rotate(-90.0); |
| 1450 | child1_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1451 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1452 | gfx::Transform child2_transform; |
| 1453 | child2_transform.Translate(250.0, 250.0); |
| 1454 | child2_transform.Rotate(90.0); |
| 1455 | child2_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1456 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1457 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1458 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 1459 | parent->SetMasksToBounds(true); |
| 1460 | typename Types::LayerType* child1 = this->CreateSurface( |
| 1461 | parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10)); |
| 1462 | typename Types::LayerType* child2 = |
| 1463 | this->CreateDrawingSurface(parent, |
| 1464 | child2_transform, |
| 1465 | gfx::PointF(20.f, 40.f), |
| 1466 | gfx::Size(10, 10), |
| 1467 | false); |
| 1468 | typename Types::ContentLayerType* layer1 = |
| 1469 | this->CreateDrawingLayer(child1, |
| 1470 | this->identity_matrix, |
| 1471 | gfx::PointF(-10.f, -20.f), |
| 1472 | gfx::Size(510, 510), |
| 1473 | true); |
| 1474 | typename Types::ContentLayerType* layer2 = |
| 1475 | this->CreateDrawingLayer(child2, |
| 1476 | this->identity_matrix, |
| 1477 | gfx::PointF(-10.f, -10.f), |
| 1478 | gfx::Size(510, 510), |
| 1479 | true); |
| 1480 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1481 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1482 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1483 | typename Types::RenderSurfaceType> occlusion( |
| 1484 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1485 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1486 | this->VisitLayer(layer2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1487 | this->EnterLayer(child2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1488 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1489 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1490 | occlusion.occlusion_from_outside_target().ToString()); |
| 1491 | EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), |
| 1492 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1493 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1494 | this->LeaveLayer(child2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1495 | this->EnterContributingSurface(child2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1496 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1497 | // There is nothing above child2's surface in the z-order. |
| 1498 | EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80), |
| 1499 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 1500 | child2, false, gfx::Rect(-10, 420, 70, 80))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1501 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1502 | this->LeaveContributingSurface(child2, &occlusion); |
| 1503 | this->VisitLayer(layer1, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1504 | this->EnterContributingSurface(child1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1505 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1506 | EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(), |
| 1507 | occlusion.occlusion_from_outside_target().ToString()); |
| 1508 | EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(), |
| 1509 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1510 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1511 | // child2's contents will occlude child1 below it. |
| 1512 | EXPECT_RECT_EQ(gfx::Rect(420, -20, 80, 90), |
| 1513 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 1514 | child1, false, gfx::Rect(420, -20, 80, 90))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1515 | EXPECT_RECT_EQ(gfx::Rect(490, -10, 10, 80), |
| 1516 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 1517 | child1, false, gfx::Rect(420, -10, 80, 90))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1518 | EXPECT_RECT_EQ(gfx::Rect(420, -20, 70, 10), |
| 1519 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 1520 | child1, false, gfx::Rect(420, -20, 70, 90))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1521 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1522 | this->LeaveContributingSurface(child1, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1523 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1524 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1525 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1526 | occlusion.occlusion_from_outside_target().ToString()); |
| 1527 | EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), |
| 1528 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1529 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1530 | /* Justification for the above occlusion: |
| 1531 | 100 |
| 1532 | +---------------------+ |
| 1533 | |20 | layer1 |
| 1534 | 10+----------------------------------+ |
| 1535 | 100 || 30 | layer2 | |
| 1536 | |20+----------------------------------+ |
| 1537 | || | | | | |
| 1538 | || | | | | |
| 1539 | || | | | | |
| 1540 | +|-|------------------+ | | |
| 1541 | | | | | 510 |
| 1542 | | | 510 | | |
| 1543 | | | | | |
| 1544 | | | | | |
| 1545 | | | | | |
| 1546 | | | | | |
| 1547 | | | 520 | | |
| 1548 | +----------------------------------+ | |
| 1549 | | | |
| 1550 | +----------------------------------+ |
| 1551 | 510 |
| 1552 | */ |
| 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 | OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1558 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1559 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1560 | class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> { |
[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 OcclusionTrackerTestFilters(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1563 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1564 | void RunMyTest() { |
| 1565 | gfx::Transform layer_transform; |
| 1566 | layer_transform.Translate(250.0, 250.0); |
| 1567 | layer_transform.Rotate(90.0); |
| 1568 | layer_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1569 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1570 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1571 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 1572 | parent->SetMasksToBounds(true); |
| 1573 | typename Types::ContentLayerType* blur_layer = |
| 1574 | this->CreateDrawingLayer(parent, |
| 1575 | layer_transform, |
| 1576 | gfx::PointF(30.f, 30.f), |
| 1577 | gfx::Size(500, 500), |
| 1578 | true); |
| 1579 | typename Types::ContentLayerType* opaque_layer = |
| 1580 | this->CreateDrawingLayer(parent, |
| 1581 | layer_transform, |
| 1582 | gfx::PointF(30.f, 30.f), |
| 1583 | gfx::Size(500, 500), |
| 1584 | true); |
| 1585 | typename Types::ContentLayerType* opacity_layer = |
| 1586 | this->CreateDrawingLayer(parent, |
| 1587 | layer_transform, |
| 1588 | gfx::PointF(30.f, 30.f), |
| 1589 | gfx::Size(500, 500), |
| 1590 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1591 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1592 | FilterOperations filters; |
| 1593 | filters.Append(FilterOperation::CreateBlurFilter(10.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1594 | blur_layer->SetFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1595 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1596 | filters.Clear(); |
| 1597 | filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1598 | opaque_layer->SetFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1599 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1600 | filters.Clear(); |
| 1601 | filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1602 | opacity_layer->SetFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1603 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1604 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1605 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1606 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1607 | typename Types::RenderSurfaceType> occlusion( |
| 1608 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1609 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1610 | // Opacity layer won't contribute to occlusion. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1611 | this->VisitLayer(opacity_layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1612 | this->EnterContributingSurface(opacity_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1613 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1614 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1615 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1616 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1617 | // And has nothing to contribute to its parent surface. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1618 | this->LeaveContributingSurface(opacity_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1619 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1620 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1621 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1622 | // Opaque layer will contribute to occlusion. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1623 | this->VisitLayer(opaque_layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1624 | this->EnterContributingSurface(opaque_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1625 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1626 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1627 | EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(), |
| 1628 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1629 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1630 | // And it gets translated to the parent surface. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1631 | this->LeaveContributingSurface(opaque_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1632 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1633 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 1634 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1635 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1636 | // The blur layer needs to throw away any occlusion from outside its |
| 1637 | // subtree. |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1638 | this->EnterLayer(blur_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1639 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1640 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1641 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1642 | // And it won't contribute to occlusion. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1643 | this->LeaveLayer(blur_layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1644 | this->EnterContributingSurface(blur_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1645 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1646 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1647 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1648 | // But the opaque layer's occlusion is preserved on the parent. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1649 | this->LeaveContributingSurface(blur_layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1650 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1651 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1652 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 1653 | occlusion.occlusion_from_inside_target().ToString()); |
| 1654 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1655 | }; |
| 1656 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1657 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1658 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1659 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1660 | class OcclusionTrackerTestReplicaDoesOcclude |
| 1661 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1662 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1663 | explicit OcclusionTrackerTestReplicaDoesOcclude(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1664 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1665 | void RunMyTest() { |
| 1666 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1667 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 1668 | typename Types::LayerType* surface = |
| 1669 | this->CreateDrawingSurface(parent, |
| 1670 | this->identity_matrix, |
| 1671 | gfx::PointF(0.f, 100.f), |
| 1672 | gfx::Size(50, 50), |
| 1673 | true); |
| 1674 | this->CreateReplicaLayer( |
| 1675 | surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size()); |
| 1676 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1677 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1678 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1679 | typename Types::RenderSurfaceType> occlusion( |
| 1680 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1681 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1682 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1683 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1684 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), |
| 1685 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1686 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1687 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1688 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1689 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1690 | // The surface and replica should both be occluding the parent. |
| 1691 | EXPECT_EQ( |
| 1692 | UnionRegions(gfx::Rect(0, 100, 50, 50), |
| 1693 | gfx::Rect(50, 150, 50, 50)).ToString(), |
| 1694 | occlusion.occlusion_from_inside_target().ToString()); |
| 1695 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1696 | }; |
| 1697 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1698 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1699 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1700 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1701 | class OcclusionTrackerTestReplicaWithClipping |
| 1702 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1703 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1704 | explicit OcclusionTrackerTestReplicaWithClipping(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1705 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1706 | void RunMyTest() { |
| 1707 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1708 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 170)); |
| 1709 | parent->SetMasksToBounds(true); |
| 1710 | typename Types::LayerType* surface = |
| 1711 | this->CreateDrawingSurface(parent, |
| 1712 | this->identity_matrix, |
| 1713 | gfx::PointF(0.f, 100.f), |
| 1714 | gfx::Size(50, 50), |
| 1715 | true); |
| 1716 | this->CreateReplicaLayer( |
| 1717 | surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size()); |
| 1718 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1719 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1720 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1721 | typename Types::RenderSurfaceType> occlusion( |
| 1722 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1723 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1724 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1725 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1726 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), |
| 1727 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1728 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1729 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1730 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1731 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1732 | // The surface and replica should both be occluding the parent. |
| 1733 | EXPECT_EQ( |
| 1734 | UnionRegions(gfx::Rect(0, 100, 50, 50), |
| 1735 | gfx::Rect(50, 150, 50, 20)).ToString(), |
| 1736 | occlusion.occlusion_from_inside_target().ToString()); |
| 1737 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1738 | }; |
| 1739 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1740 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1741 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1742 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1743 | class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1744 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1745 | explicit OcclusionTrackerTestReplicaWithMask(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1746 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1747 | void RunMyTest() { |
| 1748 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1749 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 1750 | typename Types::LayerType* surface = |
| 1751 | this->CreateDrawingSurface(parent, |
| 1752 | this->identity_matrix, |
| 1753 | gfx::PointF(0.f, 100.f), |
| 1754 | gfx::Size(50, 50), |
| 1755 | true); |
| 1756 | typename Types::LayerType* replica = this->CreateReplicaLayer( |
| 1757 | surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size()); |
| 1758 | this->CreateMaskLayer(replica, gfx::Size(10, 10)); |
| 1759 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1760 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1761 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1762 | typename Types::RenderSurfaceType> occlusion( |
| 1763 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1764 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1765 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1766 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1767 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), |
| 1768 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1769 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1770 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1771 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1772 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1773 | // The replica should not be occluding the parent, since it has a mask |
| 1774 | // applied to it. |
| 1775 | EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), |
| 1776 | occlusion.occlusion_from_inside_target().ToString()); |
| 1777 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1778 | }; |
| 1779 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1780 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1781 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1782 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1783 | class OcclusionTrackerTestOpaqueContentsRegionEmpty |
| 1784 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1785 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1786 | explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1787 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1788 | void RunMyTest() { |
| 1789 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1790 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1791 | typename Types::ContentLayerType* layer = |
| 1792 | this->CreateDrawingSurface(parent, |
| 1793 | this->identity_matrix, |
| 1794 | gfx::PointF(), |
| 1795 | gfx::Size(200, 200), |
| 1796 | false); |
| 1797 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1798 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1799 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1800 | typename Types::RenderSurfaceType> occlusion( |
| 1801 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1802 | this->EnterLayer(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1803 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1804 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 1805 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 1806 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 1807 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1808 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1809 | this->LeaveLayer(layer, &occlusion); |
| 1810 | this->VisitContributingSurface(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1811 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1812 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1813 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1814 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1815 | }; |
| 1816 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1817 | MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1818 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1819 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1820 | class OcclusionTrackerTestOpaqueContentsRegionNonEmpty |
| 1821 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1822 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1823 | explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1824 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1825 | void RunMyTest() { |
| 1826 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1827 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1828 | typename Types::ContentLayerType* layer = |
| 1829 | this->CreateDrawingLayer(parent, |
| 1830 | this->identity_matrix, |
| 1831 | gfx::PointF(100.f, 100.f), |
| 1832 | gfx::Size(200, 200), |
| 1833 | false); |
| 1834 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1835 | { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1836 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1837 | typename Types::RenderSurfaceType> occlusion( |
| 1838 | gfx::Rect(0, 0, 1000, 1000)); |
| 1839 | layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1840 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1841 | this->ResetLayerIterator(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1842 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1843 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1844 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1845 | EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), |
| 1846 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1847 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1848 | EXPECT_FALSE( |
| 1849 | occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 1850 | EXPECT_TRUE( |
| 1851 | occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100))); |
| 1852 | EXPECT_FALSE( |
| 1853 | occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1854 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1855 | { |
| 1856 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1857 | typename Types::RenderSurfaceType> occlusion( |
| 1858 | gfx::Rect(0, 0, 1000, 1000)); |
| 1859 | layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180)); |
| 1860 | |
| 1861 | this->ResetLayerIterator(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1862 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1863 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1864 | |
| 1865 | EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(), |
| 1866 | occlusion.occlusion_from_inside_target().ToString()); |
| 1867 | |
| 1868 | EXPECT_FALSE( |
| 1869 | occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 1870 | EXPECT_FALSE( |
| 1871 | occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100))); |
| 1872 | EXPECT_TRUE( |
| 1873 | occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
| 1874 | } |
| 1875 | { |
| 1876 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1877 | typename Types::RenderSurfaceType> occlusion( |
| 1878 | gfx::Rect(0, 0, 1000, 1000)); |
| 1879 | layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100)); |
| 1880 | |
| 1881 | this->ResetLayerIterator(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1882 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1883 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1884 | |
| 1885 | EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(), |
| 1886 | occlusion.occlusion_from_inside_target().ToString()); |
| 1887 | |
| 1888 | EXPECT_FALSE( |
| 1889 | occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 1890 | EXPECT_FALSE( |
| 1891 | occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100))); |
| 1892 | EXPECT_FALSE( |
| 1893 | occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
| 1894 | } |
| 1895 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1896 | }; |
| 1897 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1898 | MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1899 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1900 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1901 | class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1902 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1903 | explicit OcclusionTrackerTest3dTransform(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1904 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1905 | void RunMyTest() { |
| 1906 | gfx::Transform transform; |
| 1907 | transform.RotateAboutYAxis(30.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1908 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1909 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1910 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1911 | typename Types::LayerType* container = this->CreateLayer( |
| 1912 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1913 | typename Types::ContentLayerType* layer = |
| 1914 | this->CreateDrawingLayer(container, |
| 1915 | transform, |
| 1916 | gfx::PointF(100.f, 100.f), |
| 1917 | gfx::Size(200, 200), |
| 1918 | true); |
| 1919 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1920 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1921 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1922 | typename Types::RenderSurfaceType> occlusion( |
| 1923 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 1924 | this->EnterLayer(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1925 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1926 | // The layer is rotated in 3d but without preserving 3d, so it only gets |
| 1927 | // resized. |
| 1928 | EXPECT_RECT_EQ( |
| 1929 | gfx::Rect(0, 0, 200, 200), |
| 1930 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200))); |
| 1931 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1932 | }; |
| 1933 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1934 | MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1935 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1936 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1937 | class OcclusionTrackerTestUnsorted3dLayers |
| 1938 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1939 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1940 | explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1941 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1942 | void RunMyTest() { |
| 1943 | // Currently, The main thread layer iterator does not iterate over 3d items |
| 1944 | // in sorted order, because layer sorting is not performed on the main |
| 1945 | // thread. Because of this, the occlusion tracker cannot assume that a 3d |
| 1946 | // layer occludes other layers that have not yet been iterated over. For |
| 1947 | // now, the expected behavior is that a 3d layer simply does not add any |
| 1948 | // occlusion to the occlusion tracker. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1949 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1950 | gfx::Transform translation_to_front; |
| 1951 | translation_to_front.Translate3d(0.0, 0.0, -10.0); |
| 1952 | gfx::Transform translation_to_back; |
| 1953 | translation_to_front.Translate3d(0.0, 0.0, -100.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1954 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1955 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1956 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1957 | typename Types::ContentLayerType* child1 = this->CreateDrawingLayer( |
| 1958 | parent, translation_to_back, gfx::PointF(), gfx::Size(100, 100), true); |
| 1959 | typename Types::ContentLayerType* child2 = |
| 1960 | this->CreateDrawingLayer(parent, |
| 1961 | translation_to_front, |
| 1962 | gfx::PointF(50.f, 50.f), |
| 1963 | gfx::Size(100, 100), |
| 1964 | true); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame^] | 1965 | parent->SetShouldFlattenTransform(false); |
| 1966 | parent->SetIs3dSorted(true); |
| 1967 | child1->SetIs3dSorted(true); |
| 1968 | child2->SetIs3dSorted(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1969 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1970 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1971 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1972 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1973 | typename Types::RenderSurfaceType> occlusion( |
| 1974 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1975 | this->VisitLayer(child2, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1976 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1977 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1978 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1979 | this->VisitLayer(child1, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1980 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1981 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
| 1982 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1983 | }; |
| 1984 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1985 | // This test will have different layer ordering on the impl thread; the test |
| 1986 | // will only work on the main thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1987 | MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1988 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1989 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1990 | class OcclusionTrackerTestPerspectiveTransform |
| 1991 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1992 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1993 | explicit OcclusionTrackerTestPerspectiveTransform(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1994 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1995 | void RunMyTest() { |
| 1996 | gfx::Transform transform; |
| 1997 | transform.Translate(150.0, 150.0); |
| 1998 | transform.ApplyPerspectiveDepth(400.0); |
| 1999 | transform.RotateAboutXAxis(-30.0); |
| 2000 | transform.Translate(-150.0, -150.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2001 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2002 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2003 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2004 | typename Types::LayerType* container = this->CreateLayer( |
| 2005 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2006 | typename Types::ContentLayerType* layer = |
| 2007 | this->CreateDrawingLayer(container, |
| 2008 | transform, |
| 2009 | gfx::PointF(100.f, 100.f), |
| 2010 | gfx::Size(200, 200), |
| 2011 | true); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame^] | 2012 | container->SetShouldFlattenTransform(false); |
| 2013 | container->SetIs3dSorted(true); |
| 2014 | layer->SetIs3dSorted(true); |
| 2015 | layer->SetShouldFlattenTransform(false); |
| 2016 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2017 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2018 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2019 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2020 | typename Types::RenderSurfaceType> occlusion( |
| 2021 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2022 | this->EnterLayer(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2023 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2024 | EXPECT_RECT_EQ( |
| 2025 | gfx::Rect(0, 0, 200, 200), |
| 2026 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200))); |
| 2027 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2028 | }; |
| 2029 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2030 | // This test requires accumulating occlusion of 3d layers, which are skipped by |
| 2031 | // the occlusion tracker on the main thread. So this test should run on the impl |
| 2032 | // thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2033 | IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransform); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2034 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2035 | class OcclusionTrackerTestPerspectiveTransformBehindCamera |
| 2036 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2037 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2038 | explicit OcclusionTrackerTestPerspectiveTransformBehindCamera( |
| 2039 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2040 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2041 | void RunMyTest() { |
| 2042 | // This test is based on the platform/chromium/compositing/3d-corners.html |
| 2043 | // layout test. |
| 2044 | gfx::Transform transform; |
| 2045 | transform.Translate(250.0, 50.0); |
| 2046 | transform.ApplyPerspectiveDepth(10.0); |
| 2047 | transform.Translate(-250.0, -50.0); |
| 2048 | transform.Translate(250.0, 50.0); |
| 2049 | transform.RotateAboutXAxis(-167.0); |
| 2050 | transform.Translate(-250.0, -50.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2051 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2052 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2053 | this->identity_matrix, gfx::PointF(), gfx::Size(500, 100)); |
| 2054 | typename Types::LayerType* container = this->CreateLayer( |
| 2055 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500)); |
| 2056 | typename Types::ContentLayerType* layer = this->CreateDrawingLayer( |
| 2057 | container, transform, gfx::PointF(), gfx::Size(500, 500), true); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame^] | 2058 | container->SetShouldFlattenTransform(false); |
| 2059 | container->SetIs3dSorted(true); |
| 2060 | layer->SetShouldFlattenTransform(false); |
| 2061 | layer->SetIs3dSorted(true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2062 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2063 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2064 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2065 | typename Types::RenderSurfaceType> occlusion( |
| 2066 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2067 | this->EnterLayer(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2068 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2069 | // The bottom 11 pixel rows of this layer remain visible inside the |
| 2070 | // container, after translation to the target surface. When translated back, |
| 2071 | // this will include many more pixels but must include at least the bottom |
| 2072 | // 11 rows. |
| 2073 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
[email protected] | cfc2d2d | 2013-10-04 23:26:45 | [diff] [blame] | 2074 | layer, gfx::Rect(0, 26, 500, 474)). |
| 2075 | Contains(gfx::Rect(0, 489, 500, 11))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2076 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2077 | }; |
| 2078 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2079 | // This test requires accumulating occlusion of 3d layers, which are skipped by |
| 2080 | // the occlusion tracker on the main thread. So this test should run on the impl |
| 2081 | // thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2082 | IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransformBehindCamera); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2083 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2084 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2085 | class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude |
| 2086 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2087 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2088 | explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude( |
| 2089 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2090 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2091 | void RunMyTest() { |
| 2092 | gfx::Transform transform; |
| 2093 | transform.Translate(50.0, 50.0); |
| 2094 | transform.ApplyPerspectiveDepth(100.0); |
| 2095 | transform.Translate3d(0.0, 0.0, 110.0); |
| 2096 | transform.Translate(-50.0, -50.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2097 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2098 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2099 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 2100 | typename Types::ContentLayerType* layer = this->CreateDrawingLayer( |
| 2101 | parent, transform, gfx::PointF(), gfx::Size(100, 100), true); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame^] | 2102 | parent->SetShouldFlattenTransform(false); |
| 2103 | parent->SetIs3dSorted(true); |
| 2104 | layer->SetShouldFlattenTransform(false); |
| 2105 | layer->SetIs3dSorted(true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2106 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2107 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2108 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2109 | typename Types::RenderSurfaceType> occlusion( |
| 2110 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2111 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2112 | // The |layer| is entirely behind the camera and should not occlude. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2113 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2114 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2115 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
| 2116 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 2117 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2118 | }; |
| 2119 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2120 | // This test requires accumulating occlusion of 3d layers, which are skipped by |
| 2121 | // the occlusion tracker on the main thread. So this test should run on the impl |
| 2122 | // thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2123 | IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2124 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2125 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2126 | class OcclusionTrackerTestLargePixelsOccludeInsideClipRect |
| 2127 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2128 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2129 | explicit OcclusionTrackerTestLargePixelsOccludeInsideClipRect( |
| 2130 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2131 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2132 | void RunMyTest() { |
| 2133 | gfx::Transform transform; |
| 2134 | transform.Translate(50.0, 50.0); |
| 2135 | transform.ApplyPerspectiveDepth(100.0); |
| 2136 | transform.Translate3d(0.0, 0.0, 99.0); |
| 2137 | transform.Translate(-50.0, -50.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2138 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2139 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2140 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 2141 | parent->SetMasksToBounds(true); |
| 2142 | typename Types::ContentLayerType* layer = this->CreateDrawingLayer( |
| 2143 | parent, transform, gfx::PointF(), gfx::Size(100, 100), true); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame^] | 2144 | parent->SetShouldFlattenTransform(false); |
| 2145 | parent->SetIs3dSorted(true); |
| 2146 | layer->SetShouldFlattenTransform(false); |
| 2147 | layer->SetIs3dSorted(true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2148 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2149 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2150 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2151 | typename Types::RenderSurfaceType> occlusion( |
| 2152 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2153 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2154 | // This is very close to the camera, so pixels in its visible_content_rect() |
| 2155 | // will actually go outside of the layer's clip rect. Ensure that those |
| 2156 | // pixels don't occlude things outside the clip rect. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2157 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2158 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2159 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 2160 | occlusion.occlusion_from_inside_target().ToString()); |
| 2161 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2162 | occlusion.occlusion_from_outside_target().ToString()); |
| 2163 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2164 | }; |
| 2165 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2166 | // This test requires accumulating occlusion of 3d layers, which are skipped by |
| 2167 | // the occlusion tracker on the main thread. So this test should run on the impl |
| 2168 | // thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2169 | IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2170 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2171 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2172 | class OcclusionTrackerTestAnimationOpacity1OnMainThread |
| 2173 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2174 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2175 | explicit OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2176 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2177 | void RunMyTest() { |
| 2178 | // parent |
| 2179 | // +--layer |
| 2180 | // +--surface |
| 2181 | // | +--surface_child |
| 2182 | // | +--surface_child2 |
| 2183 | // +--parent2 |
| 2184 | // +--topmost |
[email protected] | c8d7155 | 2013-01-22 03:43:02 | [diff] [blame] | 2185 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2186 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2187 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2188 | typename Types::ContentLayerType* layer = |
| 2189 | this->CreateDrawingLayer(parent, |
| 2190 | this->identity_matrix, |
| 2191 | gfx::PointF(), |
| 2192 | gfx::Size(300, 300), |
| 2193 | true); |
| 2194 | typename Types::ContentLayerType* surface = |
| 2195 | this->CreateDrawingSurface(parent, |
| 2196 | this->identity_matrix, |
| 2197 | gfx::PointF(), |
| 2198 | gfx::Size(300, 300), |
| 2199 | true); |
| 2200 | typename Types::ContentLayerType* surface_child = |
| 2201 | this->CreateDrawingLayer(surface, |
| 2202 | this->identity_matrix, |
| 2203 | gfx::PointF(), |
| 2204 | gfx::Size(200, 300), |
| 2205 | true); |
| 2206 | typename Types::ContentLayerType* surface_child2 = |
| 2207 | this->CreateDrawingLayer(surface, |
| 2208 | this->identity_matrix, |
| 2209 | gfx::PointF(), |
| 2210 | gfx::Size(100, 300), |
| 2211 | true); |
| 2212 | typename Types::ContentLayerType* parent2 = |
| 2213 | this->CreateDrawingLayer(parent, |
| 2214 | this->identity_matrix, |
| 2215 | gfx::PointF(), |
| 2216 | gfx::Size(300, 300), |
| 2217 | false); |
| 2218 | typename Types::ContentLayerType* topmost = |
| 2219 | this->CreateDrawingLayer(parent, |
| 2220 | this->identity_matrix, |
| 2221 | gfx::PointF(250.f, 0.f), |
| 2222 | gfx::Size(50, 300), |
| 2223 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2224 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2225 | AddOpacityTransitionToController( |
| 2226 | layer->layer_animation_controller(), 10.0, 0.f, 1.f, false); |
| 2227 | AddOpacityTransitionToController( |
| 2228 | surface->layer_animation_controller(), 10.0, 0.f, 1.f, false); |
| 2229 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2230 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2231 | EXPECT_TRUE(layer->draw_opacity_is_animating()); |
| 2232 | EXPECT_FALSE(surface->draw_opacity_is_animating()); |
| 2233 | EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2234 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2235 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2236 | typename Types::RenderSurfaceType> occlusion( |
| 2237 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2238 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2239 | this->VisitLayer(topmost, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2240 | this->EnterLayer(parent2, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2241 | // This occlusion will affect all surfaces. |
| 2242 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2243 | occlusion.occlusion_from_inside_target().ToString()); |
| 2244 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2245 | occlusion.occlusion_from_outside_target().ToString()); |
| 2246 | EXPECT_EQ(gfx::Rect(0, 0, 250, 300).ToString(), |
| 2247 | occlusion.UnoccludedLayerContentRect( |
| 2248 | parent2, gfx::Rect(0, 0, 300, 300)).ToString()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2249 | this->LeaveLayer(parent2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2250 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2251 | this->VisitLayer(surface_child2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2252 | this->EnterLayer(surface_child, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2253 | EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), |
| 2254 | occlusion.occlusion_from_inside_target().ToString()); |
| 2255 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2256 | occlusion.occlusion_from_outside_target().ToString()); |
| 2257 | EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300), |
| 2258 | occlusion.UnoccludedLayerContentRect( |
| 2259 | surface_child, gfx::Rect(0, 0, 200, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2260 | this->LeaveLayer(surface_child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2261 | this->EnterLayer(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2262 | EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(), |
| 2263 | occlusion.occlusion_from_inside_target().ToString()); |
| 2264 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2265 | occlusion.occlusion_from_outside_target().ToString()); |
| 2266 | EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300), |
| 2267 | occlusion.UnoccludedLayerContentRect( |
| 2268 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2269 | this->LeaveLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2270 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2271 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2272 | // Occlusion within the surface is lost when leaving the animating surface. |
| 2273 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2274 | occlusion.occlusion_from_inside_target().ToString()); |
| 2275 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2276 | occlusion.occlusion_from_outside_target().ToString()); |
| 2277 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2278 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2279 | surface, false, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2280 | this->LeaveContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2281 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2282 | // Occlusion from outside the animating surface still exists. |
| 2283 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2284 | occlusion.occlusion_from_inside_target().ToString()); |
| 2285 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2286 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | c8d7155 | 2013-01-22 03:43:02 | [diff] [blame] | 2287 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2288 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2289 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2290 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2291 | // Occlusion is not added for the animating |layer|. |
| 2292 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2293 | occlusion.UnoccludedLayerContentRect( |
| 2294 | parent, gfx::Rect(0, 0, 300, 300))); |
| 2295 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2296 | }; |
| 2297 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2298 | MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2299 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2300 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2301 | class OcclusionTrackerTestAnimationOpacity0OnMainThread |
| 2302 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2303 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2304 | explicit OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2305 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2306 | void RunMyTest() { |
| 2307 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2308 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2309 | typename Types::ContentLayerType* layer = |
| 2310 | this->CreateDrawingLayer(parent, |
| 2311 | this->identity_matrix, |
| 2312 | gfx::PointF(), |
| 2313 | gfx::Size(300, 300), |
| 2314 | true); |
| 2315 | typename Types::ContentLayerType* surface = |
| 2316 | this->CreateDrawingSurface(parent, |
| 2317 | this->identity_matrix, |
| 2318 | gfx::PointF(), |
| 2319 | gfx::Size(300, 300), |
| 2320 | true); |
| 2321 | typename Types::ContentLayerType* surface_child = |
| 2322 | this->CreateDrawingLayer(surface, |
| 2323 | this->identity_matrix, |
| 2324 | gfx::PointF(), |
| 2325 | gfx::Size(200, 300), |
| 2326 | true); |
| 2327 | typename Types::ContentLayerType* surface_child2 = |
| 2328 | this->CreateDrawingLayer(surface, |
| 2329 | this->identity_matrix, |
| 2330 | gfx::PointF(), |
| 2331 | gfx::Size(100, 300), |
| 2332 | true); |
| 2333 | typename Types::ContentLayerType* parent2 = |
| 2334 | this->CreateDrawingLayer(parent, |
| 2335 | this->identity_matrix, |
| 2336 | gfx::PointF(), |
| 2337 | gfx::Size(300, 300), |
| 2338 | false); |
| 2339 | typename Types::ContentLayerType* topmost = |
| 2340 | this->CreateDrawingLayer(parent, |
| 2341 | this->identity_matrix, |
| 2342 | gfx::PointF(250.f, 0.f), |
| 2343 | gfx::Size(50, 300), |
| 2344 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2345 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2346 | AddOpacityTransitionToController( |
| 2347 | layer->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2348 | AddOpacityTransitionToController( |
| 2349 | surface->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2350 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2351 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2352 | EXPECT_TRUE(layer->draw_opacity_is_animating()); |
| 2353 | EXPECT_FALSE(surface->draw_opacity_is_animating()); |
| 2354 | EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2355 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2356 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2357 | typename Types::RenderSurfaceType> occlusion( |
| 2358 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2359 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2360 | this->VisitLayer(topmost, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2361 | this->EnterLayer(parent2, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2362 | // This occlusion will affect all surfaces. |
| 2363 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2364 | occlusion.occlusion_from_inside_target().ToString()); |
| 2365 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2366 | occlusion.occlusion_from_outside_target().ToString()); |
| 2367 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2368 | occlusion.UnoccludedLayerContentRect( |
| 2369 | parent, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2370 | this->LeaveLayer(parent2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2371 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2372 | this->VisitLayer(surface_child2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2373 | this->EnterLayer(surface_child, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2374 | EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), |
| 2375 | occlusion.occlusion_from_inside_target().ToString()); |
| 2376 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2377 | occlusion.occlusion_from_outside_target().ToString()); |
| 2378 | EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300), |
| 2379 | occlusion.UnoccludedLayerContentRect( |
| 2380 | surface_child, gfx::Rect(0, 0, 200, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2381 | this->LeaveLayer(surface_child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2382 | this->EnterLayer(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2383 | EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(), |
| 2384 | occlusion.occlusion_from_inside_target().ToString()); |
| 2385 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2386 | occlusion.occlusion_from_outside_target().ToString()); |
| 2387 | EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300), |
| 2388 | occlusion.UnoccludedLayerContentRect( |
| 2389 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2390 | this->LeaveLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2391 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2392 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2393 | // Occlusion within the surface is lost when leaving the animating surface. |
| 2394 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2395 | occlusion.occlusion_from_inside_target().ToString()); |
| 2396 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2397 | occlusion.occlusion_from_outside_target().ToString()); |
| 2398 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2399 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2400 | surface, false, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2401 | this->LeaveContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2402 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2403 | // Occlusion from outside the animating surface still exists. |
| 2404 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2405 | occlusion.occlusion_from_inside_target().ToString()); |
| 2406 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2407 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | c8d7155 | 2013-01-22 03:43:02 | [diff] [blame] | 2408 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2409 | this->VisitLayer(layer, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2410 | this->EnterLayer(parent, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2411 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2412 | // Occlusion is not added for the animating |layer|. |
| 2413 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2414 | occlusion.UnoccludedLayerContentRect( |
| 2415 | parent, gfx::Rect(0, 0, 300, 300))); |
| 2416 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2417 | }; |
| 2418 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2419 | MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2420 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2421 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2422 | class OcclusionTrackerTestAnimationTranslateOnMainThread |
| 2423 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2424 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2425 | explicit OcclusionTrackerTestAnimationTranslateOnMainThread( |
| 2426 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2427 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2428 | void RunMyTest() { |
| 2429 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2430 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2431 | typename Types::ContentLayerType* layer = |
| 2432 | this->CreateDrawingLayer(parent, |
| 2433 | this->identity_matrix, |
| 2434 | gfx::PointF(), |
| 2435 | gfx::Size(300, 300), |
| 2436 | true); |
| 2437 | typename Types::ContentLayerType* surface = |
| 2438 | this->CreateDrawingSurface(parent, |
| 2439 | this->identity_matrix, |
| 2440 | gfx::PointF(), |
| 2441 | gfx::Size(300, 300), |
| 2442 | true); |
| 2443 | typename Types::ContentLayerType* surface_child = |
| 2444 | this->CreateDrawingLayer(surface, |
| 2445 | this->identity_matrix, |
| 2446 | gfx::PointF(), |
| 2447 | gfx::Size(200, 300), |
| 2448 | true); |
| 2449 | typename Types::ContentLayerType* surface_child2 = |
| 2450 | this->CreateDrawingLayer(surface, |
| 2451 | this->identity_matrix, |
| 2452 | gfx::PointF(), |
| 2453 | gfx::Size(100, 300), |
| 2454 | true); |
| 2455 | typename Types::ContentLayerType* surface2 = this->CreateDrawingSurface( |
| 2456 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 300), true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2457 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2458 | AddAnimatedTransformToController( |
| 2459 | layer->layer_animation_controller(), 10.0, 30, 0); |
| 2460 | AddAnimatedTransformToController( |
| 2461 | surface->layer_animation_controller(), 10.0, 30, 0); |
| 2462 | AddAnimatedTransformToController( |
| 2463 | surface_child->layer_animation_controller(), 10.0, 30, 0); |
| 2464 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2465 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2466 | EXPECT_TRUE(layer->draw_transform_is_animating()); |
| 2467 | EXPECT_TRUE(layer->screen_space_transform_is_animating()); |
| 2468 | EXPECT_TRUE( |
| 2469 | surface->render_surface()->target_surface_transforms_are_animating()); |
| 2470 | EXPECT_TRUE( |
| 2471 | surface->render_surface()->screen_space_transforms_are_animating()); |
| 2472 | // The surface owning layer doesn't animate against its own surface. |
| 2473 | EXPECT_FALSE(surface->draw_transform_is_animating()); |
| 2474 | EXPECT_TRUE(surface->screen_space_transform_is_animating()); |
| 2475 | EXPECT_TRUE(surface_child->draw_transform_is_animating()); |
| 2476 | EXPECT_TRUE(surface_child->screen_space_transform_is_animating()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2477 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2478 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2479 | typename Types::RenderSurfaceType> occlusion( |
| 2480 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2481 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2482 | this->VisitLayer(surface2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2483 | this->EnterContributingSurface(surface2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2484 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2485 | EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), |
| 2486 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2487 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2488 | this->LeaveContributingSurface(surface2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2489 | this->EnterLayer(surface_child2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2490 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2491 | // surface_child2 is moving in screen space but not relative to its target, |
| 2492 | // so occlusion should happen in its target space only. It also means that |
| 2493 | // things occluding from outside the target (e.g. surface2) cannot occlude |
| 2494 | // this layer. |
| 2495 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2496 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | ccb1c9a | 2012-12-17 03:53:19 | [diff] [blame] | 2497 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2498 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 300), |
| 2499 | occlusion.UnoccludedLayerContentRect( |
| 2500 | surface_child2, gfx::Rect(0, 0, 100, 300))); |
| 2501 | EXPECT_FALSE( |
| 2502 | occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 50, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2503 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2504 | this->LeaveLayer(surface_child2, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2505 | this->EnterLayer(surface_child, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2506 | EXPECT_FALSE( |
| 2507 | occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 100, 300))); |
| 2508 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2509 | occlusion.occlusion_from_outside_target().ToString()); |
| 2510 | EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), |
| 2511 | occlusion.occlusion_from_inside_target().ToString()); |
| 2512 | EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300), |
| 2513 | occlusion.UnoccludedLayerContentRect( |
| 2514 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2515 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2516 | // The surface_child is occluded by the surface_child2, but is moving |
| 2517 | // relative its target, so it can't be occluded. |
| 2518 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 300), |
| 2519 | occlusion.UnoccludedLayerContentRect( |
| 2520 | surface_child, gfx::Rect(0, 0, 200, 300))); |
| 2521 | EXPECT_FALSE( |
| 2522 | occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 50, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2523 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2524 | this->LeaveLayer(surface_child, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2525 | this->EnterLayer(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2526 | // The surface_child is moving in screen space but not relative to its |
| 2527 | // target, so occlusion should happen from within the target only. |
| 2528 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2529 | occlusion.occlusion_from_outside_target().ToString()); |
| 2530 | EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), |
| 2531 | occlusion.occlusion_from_inside_target().ToString()); |
| 2532 | EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300), |
| 2533 | occlusion.UnoccludedLayerContentRect( |
| 2534 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2535 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2536 | this->LeaveLayer(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2537 | // The surface's owning layer is moving in screen space but not relative to |
| 2538 | // its target, so occlusion should happen within the target only. |
| 2539 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2540 | occlusion.occlusion_from_outside_target().ToString()); |
| 2541 | EXPECT_EQ(gfx::Rect(0, 0, 300, 300).ToString(), |
| 2542 | occlusion.occlusion_from_inside_target().ToString()); |
| 2543 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 2544 | occlusion.UnoccludedLayerContentRect( |
| 2545 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2546 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2547 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2548 | // The contributing |surface| is animating so it can't be occluded. |
| 2549 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 300, 300), |
| 2550 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2551 | surface, false, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2552 | this->LeaveContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2553 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2554 | this->EnterLayer(layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2555 | // The |surface| is moving in the screen and in its target, so all occlusion |
| 2556 | // within the surface is lost when leaving it. |
| 2557 | EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300), |
| 2558 | occlusion.UnoccludedLayerContentRect( |
| 2559 | parent, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2560 | this->LeaveLayer(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2561 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2562 | this->EnterLayer(parent, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2563 | // The |layer| is animating in the screen and in its target, so no occlusion |
| 2564 | // is added. |
| 2565 | EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300), |
| 2566 | occlusion.UnoccludedLayerContentRect( |
| 2567 | parent, gfx::Rect(0, 0, 300, 300))); |
| 2568 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2569 | }; |
| 2570 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2571 | MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2572 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2573 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2574 | class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent |
| 2575 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2576 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2577 | explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent( |
| 2578 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2579 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2580 | void RunMyTest() { |
| 2581 | gfx::Transform surface_transform; |
| 2582 | surface_transform.Translate(300.0, 300.0); |
| 2583 | surface_transform.Scale(2.0, 2.0); |
| 2584 | surface_transform.Translate(-150.0, -150.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2585 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2586 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2587 | this->identity_matrix, gfx::PointF(), gfx::Size(500, 500)); |
| 2588 | typename Types::ContentLayerType* surface = this->CreateDrawingSurface( |
| 2589 | parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false); |
| 2590 | typename Types::ContentLayerType* surface2 = |
| 2591 | this->CreateDrawingSurface(parent, |
| 2592 | this->identity_matrix, |
| 2593 | gfx::PointF(50.f, 50.f), |
| 2594 | gfx::Size(300, 300), |
| 2595 | false); |
| 2596 | surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200)); |
| 2597 | surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200)); |
| 2598 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2599 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2600 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2601 | typename Types::RenderSurfaceType> occlusion( |
| 2602 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2603 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2604 | this->VisitLayer(surface2, &occlusion); |
| 2605 | this->VisitContributingSurface(surface2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2606 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2607 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2608 | occlusion.occlusion_from_outside_target().ToString()); |
| 2609 | EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(), |
| 2610 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2611 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2612 | // Clear any stored occlusion. |
| 2613 | occlusion.set_occlusion_from_outside_target(Region()); |
| 2614 | occlusion.set_occlusion_from_inside_target(Region()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2615 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2616 | this->VisitLayer(surface, &occlusion); |
| 2617 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2618 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2619 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2620 | occlusion.occlusion_from_outside_target().ToString()); |
| 2621 | EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(), |
| 2622 | occlusion.occlusion_from_inside_target().ToString()); |
| 2623 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2624 | }; |
| 2625 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2626 | MAIN_AND_IMPL_THREAD_TEST( |
| 2627 | OcclusionTrackerTestSurfaceOcclusionTranslatesToParent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2628 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2629 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2630 | class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping |
| 2631 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2632 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2633 | explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping( |
| 2634 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2635 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2636 | void RunMyTest() { |
| 2637 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2638 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2639 | parent->SetMasksToBounds(true); |
| 2640 | typename Types::ContentLayerType* surface = |
| 2641 | this->CreateDrawingSurface(parent, |
| 2642 | this->identity_matrix, |
| 2643 | gfx::PointF(), |
| 2644 | gfx::Size(500, 300), |
| 2645 | false); |
| 2646 | surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200)); |
| 2647 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2648 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2649 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2650 | typename Types::RenderSurfaceType> occlusion( |
| 2651 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2652 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2653 | this->VisitLayer(surface, &occlusion); |
| 2654 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2655 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2656 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2657 | occlusion.occlusion_from_outside_target().ToString()); |
| 2658 | EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(), |
| 2659 | occlusion.occlusion_from_inside_target().ToString()); |
| 2660 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2661 | }; |
| 2662 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2663 | MAIN_AND_IMPL_THREAD_TEST( |
| 2664 | OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2665 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2666 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2667 | class OcclusionTrackerTestReplicaOccluded : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2668 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2669 | explicit OcclusionTrackerTestReplicaOccluded(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2670 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2671 | void RunMyTest() { |
| 2672 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2673 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 2674 | typename Types::LayerType* surface = |
| 2675 | this->CreateDrawingSurface(parent, |
| 2676 | this->identity_matrix, |
| 2677 | gfx::PointF(), |
| 2678 | gfx::Size(100, 100), |
| 2679 | true); |
| 2680 | this->CreateReplicaLayer(surface, |
| 2681 | this->identity_matrix, |
| 2682 | gfx::PointF(0.f, 100.f), |
| 2683 | gfx::Size(100, 100)); |
| 2684 | typename Types::LayerType* topmost = |
| 2685 | this->CreateDrawingLayer(parent, |
| 2686 | this->identity_matrix, |
| 2687 | gfx::PointF(0.f, 100.f), |
| 2688 | gfx::Size(100, 100), |
| 2689 | true); |
| 2690 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2691 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2692 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2693 | typename Types::RenderSurfaceType> occlusion( |
| 2694 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2695 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2696 | // |topmost| occludes the replica, but not the surface itself. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2697 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2698 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2699 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2700 | occlusion.occlusion_from_outside_target().ToString()); |
| 2701 | EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(), |
| 2702 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2703 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2704 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2705 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 2706 | // Render target with replica ignores occlusion from outside. |
| 2707 | EXPECT_EQ(gfx::Rect().ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2708 | occlusion.occlusion_from_outside_target().ToString()); |
| 2709 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 2710 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2711 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2712 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2713 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2714 | // Surface is not occluded so it shouldn't think it is. |
| 2715 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2716 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2717 | surface, false, gfx::Rect(0, 0, 100, 100))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2718 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2719 | }; |
| 2720 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2721 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaOccluded); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2722 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2723 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2724 | class OcclusionTrackerTestSurfaceWithReplicaUnoccluded |
| 2725 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2726 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2727 | explicit OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2728 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2729 | void RunMyTest() { |
| 2730 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2731 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 2732 | typename Types::LayerType* surface = |
| 2733 | this->CreateDrawingSurface(parent, |
| 2734 | this->identity_matrix, |
| 2735 | gfx::PointF(), |
| 2736 | gfx::Size(100, 100), |
| 2737 | true); |
| 2738 | this->CreateReplicaLayer(surface, |
| 2739 | this->identity_matrix, |
| 2740 | gfx::PointF(0.f, 100.f), |
| 2741 | gfx::Size(100, 100)); |
| 2742 | typename Types::LayerType* topmost = |
| 2743 | this->CreateDrawingLayer(parent, |
| 2744 | this->identity_matrix, |
| 2745 | gfx::PointF(), |
| 2746 | gfx::Size(100, 110), |
| 2747 | true); |
| 2748 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2749 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2750 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2751 | typename Types::RenderSurfaceType> occlusion( |
| 2752 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2753 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2754 | // |topmost| occludes the surface, but not the entire surface's replica. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2755 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2756 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2757 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2758 | occlusion.occlusion_from_outside_target().ToString()); |
| 2759 | EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(), |
| 2760 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2761 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2762 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2763 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 2764 | // Render target with replica ignores occlusion from outside. |
| 2765 | EXPECT_EQ(gfx::Rect().ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2766 | occlusion.occlusion_from_outside_target().ToString()); |
| 2767 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 2768 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2769 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2770 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2771 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2772 | // Surface is occluded, but only the top 10px of the replica. |
| 2773 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 2774 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2775 | surface, false, gfx::Rect(0, 0, 100, 100))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2776 | EXPECT_RECT_EQ(gfx::Rect(0, 10, 100, 90), |
| 2777 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2778 | surface, true, gfx::Rect(0, 0, 100, 100))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2779 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2780 | }; |
| 2781 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2782 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2783 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2784 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2785 | class OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently |
| 2786 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2787 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2788 | explicit OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently( |
| 2789 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2790 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2791 | void RunMyTest() { |
| 2792 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2793 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 2794 | typename Types::LayerType* surface = |
| 2795 | this->CreateDrawingSurface(parent, |
| 2796 | this->identity_matrix, |
| 2797 | gfx::PointF(), |
| 2798 | gfx::Size(100, 100), |
| 2799 | true); |
| 2800 | this->CreateReplicaLayer(surface, |
| 2801 | this->identity_matrix, |
| 2802 | gfx::PointF(0.f, 100.f), |
| 2803 | gfx::Size(100, 100)); |
| 2804 | typename Types::LayerType* over_surface = this->CreateDrawingLayer( |
| 2805 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(40, 100), true); |
| 2806 | typename Types::LayerType* over_replica = |
| 2807 | this->CreateDrawingLayer(parent, |
| 2808 | this->identity_matrix, |
| 2809 | gfx::PointF(0.f, 100.f), |
| 2810 | gfx::Size(50, 100), |
| 2811 | true); |
| 2812 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2813 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2814 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2815 | typename Types::RenderSurfaceType> occlusion( |
| 2816 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2817 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2818 | // These occlude the surface and replica differently, so we can test each |
| 2819 | // one. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2820 | this->VisitLayer(over_replica, &occlusion); |
| 2821 | this->VisitLayer(over_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2822 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2823 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2824 | occlusion.occlusion_from_outside_target().ToString()); |
| 2825 | EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 40, 100), gfx::Rect(0, 100, 50, 100)) |
| 2826 | .ToString(), |
| 2827 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2828 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2829 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2830 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 2831 | // Render target with replica ignores occlusion from outside. |
| 2832 | EXPECT_EQ(gfx::Rect().ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2833 | occlusion.occlusion_from_outside_target().ToString()); |
| 2834 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 2835 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2836 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2837 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2838 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2839 | // Surface and replica are occluded different amounts. |
| 2840 | EXPECT_RECT_EQ(gfx::Rect(40, 0, 60, 100), |
| 2841 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2842 | surface, false, gfx::Rect(0, 0, 100, 100))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2843 | EXPECT_RECT_EQ(gfx::Rect(50, 0, 50, 100), |
| 2844 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2845 | surface, true, gfx::Rect(0, 0, 100, 100))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2846 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2847 | }; |
| 2848 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2849 | ALL_OCCLUSIONTRACKER_TEST( |
| 2850 | OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2851 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2852 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2853 | class OcclusionTrackerTestSurfaceChildOfSurface |
| 2854 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2855 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2856 | explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2857 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2858 | void RunMyTest() { |
| 2859 | // This test verifies that the surface cliprect does not end up empty and |
| 2860 | // clip away the entire unoccluded rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2861 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2862 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2863 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 2864 | typename Types::LayerType* surface = |
| 2865 | this->CreateDrawingSurface(parent, |
| 2866 | this->identity_matrix, |
| 2867 | gfx::PointF(), |
| 2868 | gfx::Size(100, 100), |
| 2869 | true); |
| 2870 | typename Types::LayerType* surface_child = |
| 2871 | this->CreateDrawingSurface(surface, |
| 2872 | this->identity_matrix, |
| 2873 | gfx::PointF(0.f, 10.f), |
| 2874 | gfx::Size(100, 50), |
| 2875 | true); |
| 2876 | typename Types::LayerType* topmost = this->CreateDrawingLayer( |
| 2877 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true); |
| 2878 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2879 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2880 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2881 | typename Types::RenderSurfaceType> occlusion( |
| 2882 | gfx::Rect(-100, -100, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2883 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2884 | // |topmost| occludes everything partially so we know occlusion is happening |
| 2885 | // at all. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2886 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2887 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2888 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2889 | occlusion.occlusion_from_outside_target().ToString()); |
| 2890 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 2891 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2892 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2893 | this->VisitLayer(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2894 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2895 | // surface_child increases the occlusion in the screen by a narrow sliver. |
| 2896 | EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(), |
| 2897 | occlusion.occlusion_from_outside_target().ToString()); |
| 2898 | // In its own surface, surface_child is at 0,0 as is its occlusion. |
| 2899 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 2900 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2901 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2902 | // The root layer always has a clip rect. So the parent of |surface| has a |
| 2903 | // clip rect. However, the owning layer for |surface| does not mask to |
| 2904 | // bounds, so it doesn't have a clip rect of its own. Thus the parent of |
| 2905 | // |surface_child| exercises different code paths as its parent does not |
| 2906 | // have a clip rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2907 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2908 | this->EnterContributingSurface(surface_child, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2909 | // The surface_child's parent does not have a clip rect as it owns a render |
| 2910 | // surface. Make sure the unoccluded rect does not get clipped away |
| 2911 | // inappropriately. |
| 2912 | EXPECT_RECT_EQ(gfx::Rect(0, 40, 100, 10), |
| 2913 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2914 | surface_child, false, gfx::Rect(0, 0, 100, 50))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2915 | this->LeaveContributingSurface(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2916 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2917 | // When the surface_child's occlusion is transformed up to its parent, make |
| 2918 | // sure it is not clipped away inappropriately also. |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2919 | this->EnterLayer(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2920 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 2921 | occlusion.occlusion_from_outside_target().ToString()); |
| 2922 | EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(), |
| 2923 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2924 | this->LeaveLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2925 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2926 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2927 | // The surface's parent does have a clip rect as it is the root layer. |
| 2928 | EXPECT_RECT_EQ(gfx::Rect(0, 50, 100, 50), |
| 2929 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2930 | surface, false, gfx::Rect(0, 0, 100, 100))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2931 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2932 | }; |
| 2933 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2934 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2935 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2936 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2937 | class OcclusionTrackerTestTopmostSurfaceIsClippedToViewport |
| 2938 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2939 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2940 | explicit OcclusionTrackerTestTopmostSurfaceIsClippedToViewport( |
| 2941 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2942 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2943 | void RunMyTest() { |
| 2944 | // This test verifies that the top-most surface is considered occluded |
| 2945 | // outside of its target's clip rect and outside the viewport rect. |
| 2946 | |
| 2947 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2948 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 2949 | typename Types::LayerType* surface = |
| 2950 | this->CreateDrawingSurface(parent, |
| 2951 | this->identity_matrix, |
| 2952 | gfx::PointF(), |
| 2953 | gfx::Size(100, 300), |
| 2954 | true); |
| 2955 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2956 | { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2957 | // Make a viewport rect that is larger than the root layer. |
| 2958 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2959 | typename Types::RenderSurfaceType> occlusion( |
| 2960 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2961 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2962 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2963 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2964 | // The root layer always has a clip rect. So the parent of |surface| has a |
| 2965 | // clip rect giving the surface itself a clip rect. |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2966 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2967 | // Make sure the parent's clip rect clips the unoccluded region of the |
| 2968 | // child surface. |
| 2969 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 200), |
| 2970 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2971 | surface, false, gfx::Rect(0, 0, 100, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2972 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2973 | this->ResetLayerIterator(); |
| 2974 | { |
| 2975 | // Make a viewport rect that is smaller than the root layer. |
| 2976 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2977 | typename Types::RenderSurfaceType> occlusion( |
| 2978 | gfx::Rect(0, 0, 100, 100)); |
| 2979 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2980 | this->VisitLayer(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2981 | |
| 2982 | // The root layer always has a clip rect. So the parent of |surface| has a |
| 2983 | // clip rect giving the surface itself a clip rect. |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 2984 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2985 | // Make sure the viewport rect clips the unoccluded region of the child |
| 2986 | // surface. |
| 2987 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2988 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 2989 | surface, false, gfx::Rect(0, 0, 100, 300))); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2990 | } |
| 2991 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2992 | }; |
| 2993 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2994 | ALL_OCCLUSIONTRACKER_TEST( |
| 2995 | OcclusionTrackerTestTopmostSurfaceIsClippedToViewport); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2996 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2997 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2998 | class OcclusionTrackerTestSurfaceChildOfClippingSurface |
| 2999 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3000 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3001 | explicit OcclusionTrackerTestSurfaceChildOfClippingSurface(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3002 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3003 | void RunMyTest() { |
| 3004 | // This test verifies that the surface cliprect does not end up empty and |
| 3005 | // clip away the entire unoccluded rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3006 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3007 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3008 | this->identity_matrix, gfx::PointF(), gfx::Size(80, 200)); |
| 3009 | parent->SetMasksToBounds(true); |
| 3010 | typename Types::LayerType* surface = |
| 3011 | this->CreateDrawingSurface(parent, |
| 3012 | this->identity_matrix, |
| 3013 | gfx::PointF(), |
| 3014 | gfx::Size(100, 100), |
| 3015 | true); |
| 3016 | typename Types::LayerType* surface_child = |
| 3017 | this->CreateDrawingSurface(surface, |
| 3018 | this->identity_matrix, |
| 3019 | gfx::PointF(), |
| 3020 | gfx::Size(100, 100), |
| 3021 | false); |
| 3022 | typename Types::LayerType* topmost = this->CreateDrawingLayer( |
| 3023 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true); |
| 3024 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3025 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3026 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3027 | typename Types::RenderSurfaceType> occlusion( |
| 3028 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3029 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3030 | // |topmost| occludes everything partially so we know occlusion is happening |
| 3031 | // at all. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3032 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3033 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3034 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3035 | occlusion.occlusion_from_outside_target().ToString()); |
| 3036 | EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), |
| 3037 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3038 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3039 | // surface_child is not opaque and does not occlude, so we have a non-empty |
| 3040 | // unoccluded area on surface. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3041 | this->VisitLayer(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3042 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3043 | EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), |
| 3044 | occlusion.occlusion_from_outside_target().ToString()); |
| 3045 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 3046 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3047 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3048 | // The root layer always has a clip rect. So the parent of |surface| has a |
| 3049 | // clip rect. However, the owning layer for |surface| does not mask to |
| 3050 | // bounds, so it doesn't have a clip rect of its own. Thus the parent of |
| 3051 | // |surface_child| exercises different code paths as its parent does not |
| 3052 | // have a clip rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3053 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 3054 | this->EnterContributingSurface(surface_child, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3055 | // The surface_child's parent does not have a clip rect as it owns a render |
| 3056 | // surface. |
| 3057 | EXPECT_EQ( |
| 3058 | gfx::Rect(0, 50, 80, 50).ToString(), |
| 3059 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 3060 | surface_child, false, gfx::Rect(0, 0, 100, 100)).ToString()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3061 | this->LeaveContributingSurface(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3062 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3063 | this->VisitLayer(surface, &occlusion); |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 3064 | this->EnterContributingSurface(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3065 | // The surface's parent does have a clip rect as it is the root layer. |
| 3066 | EXPECT_EQ(gfx::Rect(0, 50, 80, 50).ToString(), |
| 3067 | occlusion.UnoccludedContributingSurfaceContentRect( |
[email protected] | fbc29332 | 2013-10-01 05:07:15 | [diff] [blame] | 3068 | surface, false, gfx::Rect(0, 0, 100, 100)).ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3069 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3070 | }; |
| 3071 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3072 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfClippingSurface); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3073 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3074 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3075 | class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter |
| 3076 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3077 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3078 | explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3079 | bool opaque_layers) |
| 3080 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3081 | void RunMyTest() { |
| 3082 | gfx::Transform scale_by_half; |
| 3083 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3084 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3085 | // Make a 50x50 filtered surface that is completely surrounded by opaque |
| 3086 | // layers which are above it in the z-order. The surface is scaled to test |
| 3087 | // that the pixel moving is done in the target space, where the background |
| 3088 | // filter is applied. |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3089 | typename Types::ContentLayerType* parent = this->CreateRoot( |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3090 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 150)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3091 | typename Types::LayerType* filtered_surface = |
| 3092 | this->CreateDrawingLayer(parent, |
| 3093 | scale_by_half, |
| 3094 | gfx::PointF(50.f, 50.f), |
| 3095 | gfx::Size(100, 100), |
| 3096 | false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3097 | typename Types::LayerType* occluding_layer1 = this->CreateDrawingLayer( |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3098 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(200, 50), true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3099 | typename Types::LayerType* occluding_layer2 = |
| 3100 | this->CreateDrawingLayer(parent, |
| 3101 | this->identity_matrix, |
| 3102 | gfx::PointF(0.f, 100.f), |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3103 | gfx::Size(200, 50), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3104 | true); |
| 3105 | typename Types::LayerType* occluding_layer3 = |
| 3106 | this->CreateDrawingLayer(parent, |
| 3107 | this->identity_matrix, |
| 3108 | gfx::PointF(0.f, 50.f), |
| 3109 | gfx::Size(50, 50), |
| 3110 | true); |
| 3111 | typename Types::LayerType* occluding_layer4 = |
| 3112 | this->CreateDrawingLayer(parent, |
| 3113 | this->identity_matrix, |
| 3114 | gfx::PointF(100.f, 50.f), |
| 3115 | gfx::Size(100, 50), |
| 3116 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3117 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3118 | // Filters make the layer own a surface. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3119 | FilterOperations filters; |
| 3120 | filters.Append(FilterOperation::CreateBlurFilter(10.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3121 | filtered_surface->SetBackgroundFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3122 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3123 | // Save the distance of influence for the blur effect. |
| 3124 | int outset_top, outset_right, outset_bottom, outset_left; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3125 | filters.GetOutsets( |
| 3126 | &outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3127 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3128 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3129 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3130 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3131 | typename Types::RenderSurfaceType> occlusion( |
| 3132 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3133 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3134 | // These layers occlude pixels directly beside the filtered_surface. Because |
| 3135 | // filtered surface blends pixels in a radius, it will need to see some of |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 3136 | // the pixels (up to radius far) underneath the occluding layers. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3137 | this->VisitLayer(occluding_layer4, &occlusion); |
| 3138 | this->VisitLayer(occluding_layer3, &occlusion); |
| 3139 | this->VisitLayer(occluding_layer2, &occlusion); |
| 3140 | this->VisitLayer(occluding_layer1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3141 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3142 | Region expected_occlusion; |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3143 | expected_occlusion.Union(gfx::Rect(0, 0, 200, 50)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3144 | expected_occlusion.Union(gfx::Rect(0, 50, 50, 50)); |
| 3145 | expected_occlusion.Union(gfx::Rect(100, 50, 100, 50)); |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3146 | expected_occlusion.Union(gfx::Rect(0, 100, 200, 50)); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 3147 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3148 | EXPECT_EQ(expected_occlusion.ToString(), |
| 3149 | occlusion.occlusion_from_inside_target().ToString()); |
| 3150 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3151 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3152 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3153 | this->VisitLayer(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3154 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3155 | // The filtered layer does not occlude. |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3156 | Region expected_occlusion_outside_surface; |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3157 | expected_occlusion_outside_surface.Union(gfx::Rect(-50, -50, 200, 50)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3158 | expected_occlusion_outside_surface.Union(gfx::Rect(-50, 0, 50, 50)); |
| 3159 | expected_occlusion_outside_surface.Union(gfx::Rect(50, 0, 100, 50)); |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3160 | expected_occlusion_outside_surface.Union(gfx::Rect(-50, 50, 200, 50)); |
[email protected] | ccb1c9a | 2012-12-17 03:53:19 | [diff] [blame] | 3161 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3162 | EXPECT_EQ(expected_occlusion_outside_surface.ToString(), |
| 3163 | occlusion.occlusion_from_outside_target().ToString()); |
| 3164 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3165 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3166 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3167 | // The surface has a background blur, so it needs pixels that are currently |
| 3168 | // considered occluded in order to be drawn. So the pixels it needs should |
| 3169 | // be removed some the occluded area so that when we get to the parent they |
| 3170 | // are drawn. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3171 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3172 | |
[email protected] | e47b0a0a | 2013-11-18 23:26:22 | [diff] [blame] | 3173 | this->EnterLayer(parent, &occlusion); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 3174 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3175 | Region expected_blurred_occlusion; |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3176 | expected_blurred_occlusion.Union(gfx::Rect(0, 0, 200, 50 - outset_top)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3177 | expected_blurred_occlusion.Union(gfx::Rect( |
| 3178 | 0, 50 - outset_top, 50 - outset_left, 50 + outset_top + outset_bottom)); |
| 3179 | expected_blurred_occlusion.Union( |
| 3180 | gfx::Rect(100 + outset_right, |
| 3181 | 50 - outset_top, |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3182 | 100 - outset_right, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3183 | 50 + outset_top + outset_bottom)); |
| 3184 | expected_blurred_occlusion.Union( |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3185 | gfx::Rect(0, 100 + outset_bottom, 200, 50 - outset_bottom)); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 3186 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3187 | EXPECT_EQ(expected_blurred_occlusion.ToString(), |
| 3188 | occlusion.occlusion_from_inside_target().ToString()); |
| 3189 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3190 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3191 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3192 | gfx::Rect outset_rect; |
| 3193 | gfx::Rect test_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3194 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3195 | // Nothing in the blur outsets for the filtered_surface is occluded. |
| 3196 | outset_rect = gfx::Rect(50 - outset_left, |
| 3197 | 50 - outset_top, |
| 3198 | 50 + outset_left + outset_right, |
| 3199 | 50 + outset_top + outset_bottom); |
| 3200 | test_rect = outset_rect; |
| 3201 | EXPECT_EQ( |
| 3202 | outset_rect.ToString(), |
| 3203 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3204 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3205 | // Stuff outside the blur outsets is still occluded though. |
| 3206 | test_rect = outset_rect; |
| 3207 | test_rect.Inset(0, 0, -1, 0); |
| 3208 | EXPECT_EQ( |
| 3209 | outset_rect.ToString(), |
| 3210 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3211 | test_rect = outset_rect; |
| 3212 | test_rect.Inset(0, 0, 0, -1); |
| 3213 | EXPECT_EQ( |
| 3214 | outset_rect.ToString(), |
| 3215 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3216 | test_rect = outset_rect; |
| 3217 | test_rect.Inset(-1, 0, 0, 0); |
| 3218 | EXPECT_EQ( |
| 3219 | outset_rect.ToString(), |
| 3220 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3221 | test_rect = outset_rect; |
| 3222 | test_rect.Inset(0, -1, 0, 0); |
| 3223 | EXPECT_EQ( |
| 3224 | outset_rect.ToString(), |
| 3225 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3226 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3227 | }; |
| 3228 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3229 | ALL_OCCLUSIONTRACKER_TEST( |
| 3230 | OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3231 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3232 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3233 | class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice |
| 3234 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3235 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3236 | explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3237 | bool opaque_layers) |
| 3238 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3239 | void RunMyTest() { |
| 3240 | gfx::Transform scale_by_half; |
| 3241 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3242 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3243 | // Makes two surfaces that completely cover |parent|. The occlusion both |
| 3244 | // above and below the filters will be reduced by each of them. |
| 3245 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 3246 | this->identity_matrix, gfx::PointF(), gfx::Size(75, 75)); |
| 3247 | typename Types::LayerType* parent = this->CreateSurface( |
| 3248 | root, scale_by_half, gfx::PointF(), gfx::Size(150, 150)); |
| 3249 | parent->SetMasksToBounds(true); |
| 3250 | typename Types::LayerType* filtered_surface1 = this->CreateDrawingLayer( |
| 3251 | parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false); |
| 3252 | typename Types::LayerType* filtered_surface2 = this->CreateDrawingLayer( |
| 3253 | parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false); |
| 3254 | typename Types::LayerType* occluding_layer_above = |
| 3255 | this->CreateDrawingLayer(parent, |
| 3256 | this->identity_matrix, |
| 3257 | gfx::PointF(100.f, 100.f), |
| 3258 | gfx::Size(50, 50), |
| 3259 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3260 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3261 | // Filters make the layers own surfaces. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3262 | FilterOperations filters; |
| 3263 | filters.Append(FilterOperation::CreateBlurFilter(1.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3264 | filtered_surface1->SetBackgroundFilters(filters); |
| 3265 | filtered_surface2->SetBackgroundFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3266 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3267 | // Save the distance of influence for the blur effect. |
| 3268 | int outset_top, outset_right, outset_bottom, outset_left; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3269 | filters.GetOutsets( |
| 3270 | &outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3271 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3272 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3273 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3274 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3275 | typename Types::RenderSurfaceType> occlusion( |
| 3276 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3277 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3278 | this->VisitLayer(occluding_layer_above, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3279 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3280 | occlusion.occlusion_from_outside_target().ToString()); |
| 3281 | EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(), |
| 3282 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3283 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3284 | this->VisitLayer(filtered_surface2, &occlusion); |
| 3285 | this->VisitContributingSurface(filtered_surface2, &occlusion); |
| 3286 | this->VisitLayer(filtered_surface1, &occlusion); |
| 3287 | this->VisitContributingSurface(filtered_surface1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3288 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3289 | // Test expectations in the target. |
| 3290 | gfx::Rect expected_occlusion = |
| 3291 | gfx::Rect(100 / 2 + outset_right * 2, |
| 3292 | 100 / 2 + outset_bottom * 2, |
| 3293 | 50 / 2 - (outset_left + outset_right) * 2, |
| 3294 | 50 / 2 - (outset_top + outset_bottom) * 2); |
| 3295 | EXPECT_EQ(expected_occlusion.ToString(), |
| 3296 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3297 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3298 | // Test expectations in the screen are the same as in the target, as the |
| 3299 | // render surface is 1:1 with the screen. |
| 3300 | EXPECT_EQ(expected_occlusion.ToString(), |
| 3301 | occlusion.occlusion_from_outside_target().ToString()); |
| 3302 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3303 | }; |
| 3304 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3305 | ALL_OCCLUSIONTRACKER_TEST( |
| 3306 | OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3307 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3308 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3309 | class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter |
| 3310 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3311 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3312 | explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3313 | bool opaque_layers) |
| 3314 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3315 | void RunMyTest() { |
| 3316 | gfx::Transform scale_by_half; |
| 3317 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3318 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3319 | // Make a surface and its replica, each 50x50, with a smaller 30x30 layer |
| 3320 | // centered below each. The surface is scaled to test that the pixel moving |
| 3321 | // is done in the target space, where the background filter is applied, but |
| 3322 | // the surface appears at 50, 50 and the replica at 200, 50. |
| 3323 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3324 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 150)); |
| 3325 | typename Types::LayerType* behind_surface_layer = |
| 3326 | this->CreateDrawingLayer(parent, |
| 3327 | this->identity_matrix, |
| 3328 | gfx::PointF(60.f, 60.f), |
| 3329 | gfx::Size(30, 30), |
| 3330 | true); |
| 3331 | typename Types::LayerType* behind_replica_layer = |
| 3332 | this->CreateDrawingLayer(parent, |
| 3333 | this->identity_matrix, |
| 3334 | gfx::PointF(210.f, 60.f), |
| 3335 | gfx::Size(30, 30), |
| 3336 | true); |
| 3337 | typename Types::LayerType* filtered_surface = |
| 3338 | this->CreateDrawingLayer(parent, |
| 3339 | scale_by_half, |
| 3340 | gfx::PointF(50.f, 50.f), |
| 3341 | gfx::Size(100, 100), |
| 3342 | false); |
| 3343 | this->CreateReplicaLayer(filtered_surface, |
| 3344 | this->identity_matrix, |
| 3345 | gfx::PointF(300.f, 0.f), |
| 3346 | gfx::Size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3347 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3348 | // Filters make the layer own a surface. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3349 | FilterOperations filters; |
| 3350 | filters.Append(FilterOperation::CreateBlurFilter(3.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3351 | filtered_surface->SetBackgroundFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3352 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3353 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3354 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3355 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3356 | typename Types::RenderSurfaceType> occlusion( |
| 3357 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3358 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3359 | // The surface has a background blur, so it blurs non-opaque pixels below |
| 3360 | // it. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3361 | this->VisitLayer(filtered_surface, &occlusion); |
| 3362 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3363 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3364 | this->VisitLayer(behind_replica_layer, &occlusion); |
| 3365 | this->VisitLayer(behind_surface_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3366 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3367 | // The layers behind the surface are not blurred, and their occlusion does |
| 3368 | // not change, until we leave the surface. So it should not be modified by |
| 3369 | // the filter here. |
| 3370 | gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30); |
| 3371 | gfx::Rect occlusion_behind_replica = gfx::Rect(210, 60, 30, 30); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3372 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3373 | Region expected_opaque_bounds = |
| 3374 | UnionRegions(occlusion_behind_surface, occlusion_behind_replica); |
| 3375 | EXPECT_EQ(expected_opaque_bounds.ToString(), |
| 3376 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | ccb1c9a | 2012-12-17 03:53:19 | [diff] [blame] | 3377 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3378 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3379 | occlusion.occlusion_from_outside_target().ToString()); |
| 3380 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3381 | }; |
| 3382 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3383 | ALL_OCCLUSIONTRACKER_TEST( |
| 3384 | OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3385 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3386 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3387 | class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded |
| 3388 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3389 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3390 | explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3391 | bool opaque_layers) |
| 3392 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3393 | void RunMyTest() { |
| 3394 | gfx::Transform scale_by_half; |
| 3395 | scale_by_half.Scale(0.5, 0.5); |
| 3396 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3397 | // Make a 50x50 filtered surface that is completely occluded by an opaque |
| 3398 | // layer which is above it in the z-order. The surface is |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3399 | // scaled to test that the pixel moving is done in the target space, where |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3400 | // the background filter is applied, but the surface appears at 50, 50. |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3401 | typename Types::ContentLayerType* parent = this->CreateRoot( |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3402 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 150)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3403 | typename Types::LayerType* filtered_surface = |
| 3404 | this->CreateDrawingLayer(parent, |
| 3405 | scale_by_half, |
| 3406 | gfx::PointF(50.f, 50.f), |
| 3407 | gfx::Size(100, 100), |
| 3408 | false); |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3409 | typename Types::LayerType* occluding_layer = |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3410 | this->CreateDrawingLayer(parent, |
| 3411 | this->identity_matrix, |
| 3412 | gfx::PointF(50.f, 50.f), |
| 3413 | gfx::Size(50, 50), |
| 3414 | true); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3415 | |
| 3416 | // Filters make the layer own a surface. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3417 | FilterOperations filters; |
| 3418 | filters.Append(FilterOperation::CreateBlurFilter(3.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3419 | filtered_surface->SetBackgroundFilters(filters); |
| 3420 | |
| 3421 | this->CalcDrawEtc(parent); |
| 3422 | |
| 3423 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3424 | typename Types::RenderSurfaceType> occlusion( |
| 3425 | gfx::Rect(0, 0, 1000, 1000)); |
| 3426 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3427 | this->VisitLayer(occluding_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3428 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3429 | this->VisitLayer(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3430 | { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3431 | // The layers above the filtered surface occlude from outside. |
| 3432 | gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3433 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3434 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3435 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3436 | EXPECT_EQ(occlusion_above_surface.ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3437 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3438 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3439 | |
| 3440 | // The surface has a background blur, so it blurs non-opaque pixels below |
| 3441 | // it. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3442 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3443 | { |
| 3444 | // The filter is completely occluded, so it should not blur anything and |
| 3445 | // reduce any occlusion. |
| 3446 | gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3447 | |
[email protected] | 66b52e1 | 2013-11-17 15:53:18 | [diff] [blame] | 3448 | EXPECT_EQ(occlusion_above_surface.ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3449 | occlusion.occlusion_from_inside_target().ToString()); |
| 3450 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3451 | occlusion.occlusion_from_outside_target().ToString()); |
| 3452 | } |
| 3453 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3454 | }; |
| 3455 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3456 | ALL_OCCLUSIONTRACKER_TEST( |
| 3457 | OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3458 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3459 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3460 | class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded |
| 3461 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3462 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3463 | explicit |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3464 | OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded( |
| 3465 | bool opaque_layers) |
| 3466 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3467 | void RunMyTest() { |
| 3468 | gfx::Transform scale_by_half; |
| 3469 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3470 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3471 | // Make a surface and its replica, each 50x50, that are partially occluded |
| 3472 | // by opaque layers which are above them in the z-order. The surface is |
| 3473 | // scaled to test that the pixel moving is done in the target space, where |
| 3474 | // the background filter is applied, but the surface appears at 50, 50 and |
| 3475 | // the replica at 200, 50. |
| 3476 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3477 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 150)); |
| 3478 | typename Types::LayerType* filtered_surface = |
| 3479 | this->CreateDrawingLayer(parent, |
| 3480 | scale_by_half, |
| 3481 | gfx::PointF(50.f, 50.f), |
| 3482 | gfx::Size(100, 100), |
| 3483 | false); |
| 3484 | this->CreateReplicaLayer(filtered_surface, |
| 3485 | this->identity_matrix, |
| 3486 | gfx::PointF(300.f, 0.f), |
| 3487 | gfx::Size()); |
| 3488 | typename Types::LayerType* above_surface_layer = |
| 3489 | this->CreateDrawingLayer(parent, |
| 3490 | this->identity_matrix, |
| 3491 | gfx::PointF(70.f, 50.f), |
| 3492 | gfx::Size(30, 50), |
| 3493 | true); |
| 3494 | typename Types::LayerType* above_replica_layer = |
| 3495 | this->CreateDrawingLayer(parent, |
| 3496 | this->identity_matrix, |
| 3497 | gfx::PointF(200.f, 50.f), |
| 3498 | gfx::Size(30, 50), |
| 3499 | true); |
| 3500 | typename Types::LayerType* beside_surface_layer = |
| 3501 | this->CreateDrawingLayer(parent, |
| 3502 | this->identity_matrix, |
| 3503 | gfx::PointF(90.f, 40.f), |
| 3504 | gfx::Size(10, 10), |
| 3505 | true); |
| 3506 | typename Types::LayerType* beside_replica_layer = |
| 3507 | this->CreateDrawingLayer(parent, |
| 3508 | this->identity_matrix, |
| 3509 | gfx::PointF(200.f, 40.f), |
| 3510 | gfx::Size(10, 10), |
| 3511 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3512 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3513 | // Filters make the layer own a surface. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3514 | FilterOperations filters; |
| 3515 | filters.Append(FilterOperation::CreateBlurFilter(3.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3516 | filtered_surface->SetBackgroundFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3517 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3518 | // Save the distance of influence for the blur effect. |
| 3519 | int outset_top, outset_right, outset_bottom, outset_left; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3520 | filters.GetOutsets( |
| 3521 | &outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3522 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3523 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3524 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3525 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3526 | typename Types::RenderSurfaceType> occlusion( |
| 3527 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3528 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3529 | this->VisitLayer(beside_replica_layer, &occlusion); |
| 3530 | this->VisitLayer(beside_surface_layer, &occlusion); |
| 3531 | this->VisitLayer(above_replica_layer, &occlusion); |
| 3532 | this->VisitLayer(above_surface_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3533 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3534 | // The surface has a background blur, so it blurs non-opaque pixels below |
| 3535 | // it. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3536 | this->VisitLayer(filtered_surface, &occlusion); |
| 3537 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3538 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3539 | // The filter in the surface and replica are partially unoccluded. Only the |
| 3540 | // unoccluded parts should reduce occlusion. This means it will push back |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 3541 | // the occlusion that touches the unoccluded part (occlusion_above___), but |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3542 | // it will not touch occlusion_beside____ since that is not beside the |
| 3543 | // unoccluded part of the surface, even though it is beside the occluded |
| 3544 | // part of the surface. |
| 3545 | gfx::Rect occlusion_above_surface = |
| 3546 | gfx::Rect(70 + outset_right, 50, 30 - outset_right, 50); |
| 3547 | gfx::Rect occlusion_above_replica = |
| 3548 | gfx::Rect(200, 50, 30 - outset_left, 50); |
| 3549 | gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10); |
| 3550 | gfx::Rect occlusion_beside_replica = gfx::Rect(200, 40, 10, 10); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3551 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3552 | Region expected_occlusion; |
| 3553 | expected_occlusion.Union(occlusion_above_surface); |
| 3554 | expected_occlusion.Union(occlusion_above_replica); |
| 3555 | expected_occlusion.Union(occlusion_beside_surface); |
| 3556 | expected_occlusion.Union(occlusion_beside_replica); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3557 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3558 | ASSERT_EQ(expected_occlusion.ToString(), |
| 3559 | occlusion.occlusion_from_inside_target().ToString()); |
| 3560 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3561 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3562 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3563 | Region::Iterator expected_rects(expected_occlusion); |
| 3564 | Region::Iterator target_surface_rects( |
| 3565 | occlusion.occlusion_from_inside_target()); |
| 3566 | for (; expected_rects.has_rect(); |
| 3567 | expected_rects.next(), target_surface_rects.next()) { |
| 3568 | ASSERT_TRUE(target_surface_rects.has_rect()); |
| 3569 | EXPECT_EQ(expected_rects.rect(), target_surface_rects.rect()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3570 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3571 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3572 | }; |
| 3573 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3574 | ALL_OCCLUSIONTRACKER_TEST( |
| 3575 | OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3576 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3577 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3578 | class OcclusionTrackerTestMinimumTrackingSize |
| 3579 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3580 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3581 | explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3582 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3583 | void RunMyTest() { |
| 3584 | gfx::Size tracking_size(100, 100); |
| 3585 | gfx::Size below_tracking_size(99, 99); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3586 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3587 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3588 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 3589 | typename Types::LayerType* large = this->CreateDrawingLayer( |
| 3590 | parent, this->identity_matrix, gfx::PointF(), tracking_size, true); |
| 3591 | typename Types::LayerType* small = |
| 3592 | this->CreateDrawingLayer(parent, |
| 3593 | this->identity_matrix, |
| 3594 | gfx::PointF(), |
| 3595 | below_tracking_size, |
| 3596 | true); |
| 3597 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3598 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3599 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3600 | typename Types::RenderSurfaceType> occlusion( |
| 3601 | gfx::Rect(0, 0, 1000, 1000)); |
| 3602 | occlusion.set_minimum_tracking_size(tracking_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3603 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3604 | // The small layer is not tracked because it is too small. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3605 | this->VisitLayer(small, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3606 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3607 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3608 | occlusion.occlusion_from_outside_target().ToString()); |
| 3609 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3610 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3611 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3612 | // The large layer is tracked as it is large enough. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3613 | this->VisitLayer(large, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3614 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3615 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3616 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3617 | EXPECT_EQ(gfx::Rect(tracking_size).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3618 | occlusion.occlusion_from_inside_target().ToString()); |
| 3619 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3620 | }; |
| 3621 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3622 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3623 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3624 | template <class Types> |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 3625 | class OcclusionTrackerTestScaledLayerIsClipped |
| 3626 | : public OcclusionTrackerTest<Types> { |
| 3627 | protected: |
| 3628 | explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers) |
| 3629 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3630 | void RunMyTest() { |
| 3631 | gfx::Transform scale_transform; |
| 3632 | scale_transform.Scale(512.0, 512.0); |
| 3633 | |
| 3634 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3635 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 3636 | typename Types::LayerType* clip = this->CreateLayer(parent, |
| 3637 | this->identity_matrix, |
| 3638 | gfx::PointF(10.f, 10.f), |
| 3639 | gfx::Size(50, 50)); |
| 3640 | clip->SetMasksToBounds(true); |
| 3641 | typename Types::LayerType* scale = this->CreateLayer( |
| 3642 | clip, scale_transform, gfx::PointF(), gfx::Size(1, 1)); |
| 3643 | typename Types::LayerType* scaled = this->CreateDrawingLayer( |
| 3644 | scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true); |
| 3645 | this->CalcDrawEtc(parent); |
| 3646 | |
| 3647 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3648 | typename Types::RenderSurfaceType> occlusion( |
| 3649 | gfx::Rect(0, 0, 1000, 1000)); |
| 3650 | |
| 3651 | this->VisitLayer(scaled, &occlusion); |
| 3652 | |
| 3653 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3654 | occlusion.occlusion_from_outside_target().ToString()); |
| 3655 | EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(), |
| 3656 | occlusion.occlusion_from_inside_target().ToString()); |
| 3657 | } |
| 3658 | }; |
| 3659 | |
| 3660 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped) |
| 3661 | |
| 3662 | template <class Types> |
| 3663 | class OcclusionTrackerTestScaledLayerInSurfaceIsClipped |
| 3664 | : public OcclusionTrackerTest<Types> { |
| 3665 | protected: |
| 3666 | explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers) |
| 3667 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3668 | void RunMyTest() { |
| 3669 | gfx::Transform scale_transform; |
| 3670 | scale_transform.Scale(512.0, 512.0); |
| 3671 | |
| 3672 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3673 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 3674 | typename Types::LayerType* clip = this->CreateLayer(parent, |
| 3675 | this->identity_matrix, |
| 3676 | gfx::PointF(10.f, 10.f), |
| 3677 | gfx::Size(50, 50)); |
| 3678 | clip->SetMasksToBounds(true); |
| 3679 | typename Types::LayerType* surface = this->CreateDrawingSurface( |
| 3680 | clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false); |
| 3681 | typename Types::LayerType* scale = this->CreateLayer( |
| 3682 | surface, scale_transform, gfx::PointF(), gfx::Size(1, 1)); |
| 3683 | typename Types::LayerType* scaled = this->CreateDrawingLayer( |
| 3684 | scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true); |
| 3685 | this->CalcDrawEtc(parent); |
| 3686 | |
| 3687 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3688 | typename Types::RenderSurfaceType> occlusion( |
| 3689 | gfx::Rect(0, 0, 1000, 1000)); |
| 3690 | |
| 3691 | this->VisitLayer(scaled, &occlusion); |
| 3692 | this->VisitLayer(surface, &occlusion); |
| 3693 | this->VisitContributingSurface(surface, &occlusion); |
| 3694 | |
| 3695 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3696 | occlusion.occlusion_from_outside_target().ToString()); |
| 3697 | EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(), |
| 3698 | occlusion.occlusion_from_inside_target().ToString()); |
| 3699 | } |
| 3700 | }; |
| 3701 | |
| 3702 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped) |
| 3703 | |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame] | 3704 | template <class Types> |
| 3705 | class OcclusionTrackerTestCopyRequestDoesOcclude |
| 3706 | : public OcclusionTrackerTest<Types> { |
| 3707 | protected: |
| 3708 | explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers) |
| 3709 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3710 | void RunMyTest() { |
| 3711 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 3712 | this->identity_matrix, gfx::Point(), gfx::Size(400, 400)); |
| 3713 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 3714 | root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true); |
| 3715 | typename Types::LayerType* copy = this->CreateLayer(parent, |
| 3716 | this->identity_matrix, |
| 3717 | gfx::Point(100, 0), |
| 3718 | gfx::Size(200, 400)); |
| 3719 | this->AddCopyRequest(copy); |
| 3720 | typename Types::LayerType* copy_child = this->CreateDrawingLayer( |
| 3721 | copy, |
| 3722 | this->identity_matrix, |
| 3723 | gfx::PointF(), |
| 3724 | gfx::Size(200, 400), |
| 3725 | true); |
| 3726 | this->CalcDrawEtc(root); |
| 3727 | |
| 3728 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3729 | typename Types::RenderSurfaceType> occlusion( |
| 3730 | gfx::Rect(0, 0, 1000, 1000)); |
| 3731 | |
| 3732 | this->VisitLayer(copy_child, &occlusion); |
| 3733 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3734 | occlusion.occlusion_from_outside_target().ToString()); |
| 3735 | EXPECT_EQ(gfx::Rect(200, 400).ToString(), |
| 3736 | occlusion.occlusion_from_inside_target().ToString()); |
| 3737 | |
| 3738 | // CopyRequests cause the layer to own a surface. |
| 3739 | this->VisitContributingSurface(copy, &occlusion); |
| 3740 | |
| 3741 | // The occlusion from the copy should be kept. |
| 3742 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3743 | occlusion.occlusion_from_outside_target().ToString()); |
| 3744 | EXPECT_EQ(gfx::Rect(100, 0, 200, 400).ToString(), |
| 3745 | occlusion.occlusion_from_inside_target().ToString()); |
| 3746 | } |
| 3747 | }; |
| 3748 | |
| 3749 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude) |
| 3750 | |
| 3751 | template <class Types> |
| 3752 | class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude |
| 3753 | : public OcclusionTrackerTest<Types> { |
| 3754 | protected: |
| 3755 | explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude( |
| 3756 | bool opaque_layers) |
| 3757 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3758 | void RunMyTest() { |
| 3759 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 3760 | this->identity_matrix, gfx::Point(), gfx::Size(400, 400)); |
| 3761 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 3762 | root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true); |
| 3763 | typename Types::LayerType* hide = this->CreateLayer( |
| 3764 | parent, this->identity_matrix, gfx::Point(), gfx::Size()); |
| 3765 | typename Types::LayerType* copy = this->CreateLayer( |
| 3766 | hide, this->identity_matrix, gfx::Point(100, 0), gfx::Size(200, 400)); |
| 3767 | this->AddCopyRequest(copy); |
| 3768 | typename Types::LayerType* copy_child = this->CreateDrawingLayer( |
| 3769 | copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true); |
| 3770 | |
| 3771 | // The |copy| layer is hidden but since it is being copied, it will be |
| 3772 | // drawn. |
| 3773 | hide->SetHideLayerAndSubtree(true); |
| 3774 | |
| 3775 | this->CalcDrawEtc(root); |
| 3776 | |
| 3777 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3778 | typename Types::RenderSurfaceType> occlusion( |
| 3779 | gfx::Rect(0, 0, 1000, 1000)); |
| 3780 | |
| 3781 | this->VisitLayer(copy_child, &occlusion); |
| 3782 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3783 | occlusion.occlusion_from_outside_target().ToString()); |
| 3784 | EXPECT_EQ(gfx::Rect(200, 400).ToString(), |
| 3785 | occlusion.occlusion_from_inside_target().ToString()); |
| 3786 | |
| 3787 | // CopyRequests cause the layer to own a surface. |
| 3788 | this->VisitContributingSurface(copy, &occlusion); |
| 3789 | |
| 3790 | // The occlusion from the copy should be dropped since it is hidden. |
| 3791 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3792 | occlusion.occlusion_from_outside_target().ToString()); |
| 3793 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3794 | occlusion.occlusion_from_inside_target().ToString()); |
| 3795 | } |
| 3796 | }; |
| 3797 | |
| 3798 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude) |
| 3799 | |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 3800 | template <class Types> |
| 3801 | class OcclusionTrackerTestEmptyEventLayerDoesNotOcclude |
| 3802 | : public OcclusionTrackerTest<Types> { |
| 3803 | protected: |
| 3804 | explicit OcclusionTrackerTestEmptyEventLayerDoesNotOcclude( |
| 3805 | bool opaque_layers) |
| 3806 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3807 | void RunMyTest() { |
| 3808 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 3809 | this->identity_matrix, gfx::Point(), gfx::Size(400, 400)); |
| 3810 | typename Types::ContentLayerType* empty_layer = this->CreateDrawingLayer( |
| 3811 | root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), true); |
| 3812 | this->SetDrawsContent(empty_layer, false); |
| 3813 | empty_layer->SetTouchEventHandlerRegion(gfx::Rect(10, 10, 10, 10)); |
| 3814 | |
| 3815 | this->CalcDrawEtc(root); |
| 3816 | |
| 3817 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3818 | typename Types::RenderSurfaceType> occlusion( |
| 3819 | gfx::Rect(0, 0, 1000, 1000), false); |
| 3820 | |
| 3821 | this->VisitLayer(empty_layer, &occlusion); |
| 3822 | |
| 3823 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3824 | occlusion.occlusion_from_outside_target().ToString()); |
| 3825 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3826 | occlusion.occlusion_from_inside_target().ToString()); |
| 3827 | } |
| 3828 | }; |
| 3829 | |
| 3830 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestEmptyEventLayerDoesNotOcclude) |
| 3831 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 3832 | } // namespace |
| 3833 | } // namespace cc |