[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" |
| 18 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 19 | #include "cc/test/geometry_test_utils.h" |
| 20 | #include "cc/test/occlusion_tracker_test_common.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 21 | #include "cc/trees/layer_tree_host_common.h" |
| 22 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 23 | #include "testing/gmock/include/gmock/gmock.h" |
| 24 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 25 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 26 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 27 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 28 | namespace { |
| 29 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 30 | class TestContentLayer : public Layer { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 31 | public: |
| 32 | TestContentLayer() : Layer(), override_opaque_contents_rect_(false) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 33 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 34 | virtual bool DrawsContent() const OVERRIDE { return true; } |
| 35 | virtual Region VisibleContentOpaqueRegion() const OVERRIDE { |
| 36 | if (override_opaque_contents_rect_) |
| 37 | return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect()); |
| 38 | return Layer::VisibleContentOpaqueRegion(); |
| 39 | } |
| 40 | void SetOpaqueContentsRect(gfx::Rect opaque_contents_rect) { |
| 41 | override_opaque_contents_rect_ = true; |
| 42 | opaque_contents_rect_ = opaque_contents_rect; |
| 43 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 44 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 45 | private: |
| 46 | virtual ~TestContentLayer() {} |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 47 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 48 | bool override_opaque_contents_rect_; |
| 49 | gfx::Rect opaque_contents_rect_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 50 | }; |
| 51 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 52 | class TestContentLayerImpl : public LayerImpl { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 53 | public: |
| 54 | TestContentLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 55 | : LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) { |
| 56 | SetDrawsContent(true); |
| 57 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 58 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 59 | virtual Region VisibleContentOpaqueRegion() const OVERRIDE { |
| 60 | if (override_opaque_contents_rect_) |
| 61 | return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect()); |
| 62 | return LayerImpl::VisibleContentOpaqueRegion(); |
| 63 | } |
| 64 | void SetOpaqueContentsRect(gfx::Rect opaque_contents_rect) { |
| 65 | override_opaque_contents_rect_ = true; |
| 66 | opaque_contents_rect_ = opaque_contents_rect; |
| 67 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 68 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 69 | private: |
| 70 | bool override_opaque_contents_rect_; |
| 71 | gfx::Rect opaque_contents_rect_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 72 | }; |
| 73 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 74 | static inline bool LayerImplDrawTransformIsUnknown(const Layer* layer) { |
| 75 | return layer->draw_transform_is_animating(); |
| 76 | } |
| 77 | static inline bool LayerImplDrawTransformIsUnknown(const LayerImpl* layer) { |
| 78 | return false; |
| 79 | } |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 80 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 81 | template <typename LayerType, typename RenderSurfaceType> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 82 | class TestOcclusionTrackerWithClip |
| 83 | : public TestOcclusionTrackerBase<LayerType, RenderSurfaceType> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 84 | public: |
| 85 | TestOcclusionTrackerWithClip(gfx::Rect viewport_rect, |
| 86 | bool record_metrics_for_frame) |
| 87 | : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>( |
| 88 | viewport_rect, |
| 89 | record_metrics_for_frame) {} |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 90 | explicit TestOcclusionTrackerWithClip(gfx::Rect viewport_rect) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 91 | : TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(viewport_rect, |
| 92 | false) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 93 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 94 | bool OccludedLayer(const LayerType* layer, gfx::Rect content_rect) { |
| 95 | bool temp; |
| 96 | return OccludedLayer(layer, content_rect, &temp); |
| 97 | } |
| 98 | |
| 99 | bool OccludedLayer(const LayerType* layer, |
| 100 | gfx::Rect content_rect, |
| 101 | bool* has_occlusion_from_outside_target_surface) const { |
| 102 | return this->Occluded(layer->render_target(), |
| 103 | content_rect, |
| 104 | layer->draw_transform(), |
| 105 | LayerImplDrawTransformIsUnknown(layer), |
| 106 | layer->is_clipped(), |
| 107 | layer->clip_rect(), |
| 108 | has_occlusion_from_outside_target_surface); |
| 109 | } |
| 110 | // 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] | 111 | // layer. Simple wrapper around UnoccludedContentRect. |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 112 | gfx::Rect UnoccludedLayerContentRect(const LayerType* layer, |
| 113 | gfx::Rect content_rect) const { |
| 114 | bool temp; |
| 115 | return UnoccludedLayerContentRect(layer, content_rect, &temp); |
| 116 | } |
| 117 | |
| 118 | gfx::Rect UnoccludedLayerContentRect( |
| 119 | const LayerType* layer, |
| 120 | gfx::Rect content_rect, |
| 121 | bool* has_occlusion_from_outside_target_surface) const { |
| 122 | return this->UnoccludedContentRect( |
| 123 | layer->render_target(), |
| 124 | content_rect, |
| 125 | layer->draw_transform(), |
| 126 | LayerImplDrawTransformIsUnknown(layer), |
| 127 | layer->is_clipped(), |
| 128 | layer->clip_rect(), |
| 129 | has_occlusion_from_outside_target_surface); |
| 130 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 131 | }; |
| 132 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 133 | struct OcclusionTrackerTestMainThreadTypes { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 134 | typedef Layer LayerType; |
| 135 | typedef LayerTreeHost HostType; |
| 136 | typedef RenderSurface RenderSurfaceType; |
| 137 | typedef TestContentLayer ContentLayerType; |
| 138 | typedef scoped_refptr<Layer> LayerPtrType; |
| 139 | typedef scoped_refptr<ContentLayerType> ContentLayerPtrType; |
| 140 | typedef LayerIterator<Layer, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 141 | RenderSurfaceLayerList, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 142 | RenderSurface, |
| 143 | LayerIteratorActions::FrontToBack> TestLayerIterator; |
| 144 | typedef OcclusionTracker OcclusionTrackerType; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 145 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 146 | static LayerPtrType CreateLayer(HostType* host) { return Layer::Create(); } |
| 147 | static ContentLayerPtrType CreateContentLayer(HostType* host) { |
| 148 | return make_scoped_refptr(new ContentLayerType()); |
| 149 | } |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 150 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 151 | static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) { |
| 152 | LayerPtrType ref(*layer); |
| 153 | *layer = NULL; |
| 154 | return ref; |
| 155 | } |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 156 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 157 | static LayerPtrType PassLayerPtr(LayerPtrType* layer) { |
| 158 | LayerPtrType ref(*layer); |
| 159 | *layer = NULL; |
| 160 | return ref; |
| 161 | } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 162 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 163 | static void DestroyLayer(LayerPtrType* layer) { *layer = NULL; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 164 | }; |
| 165 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 166 | struct OcclusionTrackerTestImplThreadTypes { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 167 | typedef LayerImpl LayerType; |
| 168 | typedef LayerTreeImpl HostType; |
| 169 | typedef RenderSurfaceImpl RenderSurfaceType; |
| 170 | typedef TestContentLayerImpl ContentLayerType; |
| 171 | typedef scoped_ptr<LayerImpl> LayerPtrType; |
| 172 | typedef scoped_ptr<ContentLayerType> ContentLayerPtrType; |
| 173 | typedef LayerIterator<LayerImpl, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 174 | LayerImplList, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 175 | RenderSurfaceImpl, |
| 176 | LayerIteratorActions::FrontToBack> TestLayerIterator; |
| 177 | typedef OcclusionTrackerImpl OcclusionTrackerType; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 178 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 179 | static LayerPtrType CreateLayer(HostType* host) { |
| 180 | return LayerImpl::Create(host, next_layer_impl_id++); |
| 181 | } |
| 182 | static ContentLayerPtrType CreateContentLayer(HostType* host) { |
| 183 | return make_scoped_ptr(new ContentLayerType(host, next_layer_impl_id++)); |
| 184 | } |
| 185 | static int next_layer_impl_id; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 186 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 187 | static LayerPtrType PassLayerPtr(LayerPtrType* layer) { |
| 188 | return layer->Pass(); |
| 189 | } |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 190 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 191 | static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) { |
| 192 | return layer->PassAs<LayerType>(); |
| 193 | } |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 194 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 195 | static void DestroyLayer(LayerPtrType* layer) { layer->reset(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 196 | }; |
| 197 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 198 | int OcclusionTrackerTestImplThreadTypes::next_layer_impl_id = 1; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 199 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 200 | template <typename Types> class OcclusionTrackerTest : public testing::Test { |
| 201 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 202 | explicit OcclusionTrackerTest(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 203 | : host_impl_(&proxy_), opaque_layers_(opaque_layers) {} |
| 204 | |
| 205 | virtual void RunMyTest() = 0; |
| 206 | |
| 207 | virtual void TearDown() { |
| 208 | Types::DestroyLayer(&root_); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 209 | render_surface_layer_list_.reset(); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 210 | render_surface_layer_list_impl_.clear(); |
| 211 | replica_layers_.clear(); |
| 212 | mask_layers_.clear(); |
| 213 | } |
| 214 | |
| 215 | typename Types::HostType* GetHost(); |
| 216 | |
| 217 | typename Types::ContentLayerType* CreateRoot(const gfx::Transform& transform, |
| 218 | gfx::PointF position, |
| 219 | gfx::Size bounds) { |
| 220 | typename Types::ContentLayerPtrType layer( |
| 221 | Types::CreateContentLayer(GetHost())); |
| 222 | typename Types::ContentLayerType* layer_ptr = layer.get(); |
| 223 | SetProperties(layer_ptr, transform, position, bounds); |
| 224 | |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 225 | DCHECK(!root_.get()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 226 | root_ = Types::PassLayerPtr(&layer); |
| 227 | return layer_ptr; |
| 228 | } |
| 229 | |
| 230 | typename Types::LayerType* CreateLayer(typename Types::LayerType* parent, |
| 231 | const gfx::Transform& transform, |
| 232 | gfx::PointF position, |
| 233 | gfx::Size bounds) { |
| 234 | typename Types::LayerPtrType layer(Types::CreateLayer(GetHost())); |
| 235 | typename Types::LayerType* layer_ptr = layer.get(); |
| 236 | SetProperties(layer_ptr, transform, position, bounds); |
| 237 | parent->AddChild(Types::PassLayerPtr(&layer)); |
| 238 | return layer_ptr; |
| 239 | } |
| 240 | |
| 241 | typename Types::LayerType* CreateSurface(typename Types::LayerType* parent, |
| 242 | const gfx::Transform& transform, |
| 243 | gfx::PointF position, |
| 244 | gfx::Size bounds) { |
| 245 | typename Types::LayerType* layer = |
| 246 | CreateLayer(parent, transform, position, bounds); |
| 247 | layer->SetForceRenderSurface(true); |
| 248 | return layer; |
| 249 | } |
| 250 | |
| 251 | typename Types::ContentLayerType* CreateDrawingLayer( |
| 252 | typename Types::LayerType* parent, |
| 253 | const gfx::Transform& transform, |
| 254 | gfx::PointF position, |
| 255 | gfx::Size bounds, |
| 256 | bool opaque) { |
| 257 | typename Types::ContentLayerPtrType layer( |
| 258 | Types::CreateContentLayer(GetHost())); |
| 259 | typename Types::ContentLayerType* layer_ptr = layer.get(); |
| 260 | SetProperties(layer_ptr, transform, position, bounds); |
| 261 | |
| 262 | if (opaque_layers_) { |
| 263 | layer_ptr->SetContentsOpaque(opaque); |
| 264 | } else { |
| 265 | layer_ptr->SetContentsOpaque(false); |
| 266 | if (opaque) |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 267 | layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 268 | else |
| 269 | layer_ptr->SetOpaqueContentsRect(gfx::Rect()); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 270 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 271 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 272 | parent->AddChild(Types::PassLayerPtr(&layer)); |
| 273 | return layer_ptr; |
| 274 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 275 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 276 | typename Types::LayerType* CreateReplicaLayer( |
| 277 | typename Types::LayerType* owning_layer, |
| 278 | const gfx::Transform& transform, |
| 279 | gfx::PointF position, |
| 280 | gfx::Size bounds) { |
| 281 | typename Types::ContentLayerPtrType layer( |
| 282 | Types::CreateContentLayer(GetHost())); |
| 283 | typename Types::ContentLayerType* layer_ptr = layer.get(); |
| 284 | SetProperties(layer_ptr, transform, position, bounds); |
| 285 | SetReplica(owning_layer, Types::PassLayerPtr(&layer)); |
| 286 | return layer_ptr; |
| 287 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 288 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 289 | typename Types::LayerType* CreateMaskLayer( |
| 290 | typename Types::LayerType* owning_layer, |
| 291 | gfx::Size bounds) { |
| 292 | typename Types::ContentLayerPtrType layer( |
| 293 | Types::CreateContentLayer(GetHost())); |
| 294 | typename Types::ContentLayerType* layer_ptr = layer.get(); |
| 295 | SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds); |
| 296 | SetMask(owning_layer, Types::PassLayerPtr(&layer)); |
| 297 | return layer_ptr; |
| 298 | } |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 299 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 300 | typename Types::ContentLayerType* CreateDrawingSurface( |
| 301 | typename Types::LayerType* parent, |
| 302 | const gfx::Transform& transform, |
| 303 | gfx::PointF position, |
| 304 | gfx::Size bounds, |
| 305 | bool opaque) { |
| 306 | typename Types::ContentLayerType* layer = |
| 307 | CreateDrawingLayer(parent, transform, position, bounds, opaque); |
| 308 | layer->SetForceRenderSurface(true); |
| 309 | return layer; |
| 310 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 311 | |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame^] | 312 | |
| 313 | void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 314 | |
| 315 | void AddCopyRequest(Layer* layer) { |
| 316 | layer->RequestCopyOfOutput( |
| 317 | CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 318 | &OcclusionTrackerTest<Types>::CopyOutputCallback, |
| 319 | base::Unretained(this)))); |
| 320 | } |
| 321 | |
| 322 | void AddCopyRequest(LayerImpl* layer) { |
| 323 | ScopedPtrVector<CopyOutputRequest> requests; |
| 324 | requests.push_back( |
| 325 | CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 326 | &OcclusionTrackerTest<Types>::CopyOutputCallback, |
| 327 | base::Unretained(this)))); |
| 328 | layer->PassCopyRequests(&requests); |
| 329 | } |
| 330 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 331 | void CalcDrawEtc(TestContentLayerImpl* root) { |
| 332 | DCHECK(root == root_.get()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 333 | DCHECK(!root->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 334 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 335 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 336 | root, root->bounds(), &render_surface_layer_list_impl_); |
| 337 | inputs.can_adjust_raster_scales = true; |
| 338 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 339 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 340 | layer_iterator_ = layer_iterator_begin_ = |
| 341 | Types::TestLayerIterator::Begin(&render_surface_layer_list_impl_); |
| 342 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 343 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 344 | void CalcDrawEtc(TestContentLayer* root) { |
| 345 | DCHECK(root == root_.get()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 346 | DCHECK(!root->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 347 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 348 | render_surface_layer_list_.reset(new RenderSurfaceLayerList); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 349 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 350 | root, root->bounds(), render_surface_layer_list_.get()); |
| 351 | inputs.can_adjust_raster_scales = true; |
| 352 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 353 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 354 | layer_iterator_ = layer_iterator_begin_ = |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 355 | Types::TestLayerIterator::Begin(render_surface_layer_list_.get()); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 356 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 357 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 358 | void EnterLayer(typename Types::LayerType* layer, |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 359 | typename Types::OcclusionTrackerType* occlusion, |
| 360 | bool prevent_occlusion) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 361 | ASSERT_EQ(layer, *layer_iterator_); |
| 362 | ASSERT_TRUE(layer_iterator_.represents_itself()); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 363 | occlusion->EnterLayer(layer_iterator_, prevent_occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 364 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 365 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 366 | void LeaveLayer(typename Types::LayerType* layer, |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 367 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 368 | ASSERT_EQ(layer, *layer_iterator_); |
| 369 | ASSERT_TRUE(layer_iterator_.represents_itself()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 370 | occlusion->LeaveLayer(layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 371 | ++layer_iterator_; |
| 372 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 373 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 374 | void VisitLayer(typename Types::LayerType* layer, |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 375 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 376 | EnterLayer(layer, occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 377 | LeaveLayer(layer, occlusion); |
| 378 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 379 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 380 | void EnterContributingSurface( |
| 381 | typename Types::LayerType* layer, |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 382 | typename Types::OcclusionTrackerType* occlusion, |
| 383 | bool prevent_occlusion) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 384 | ASSERT_EQ(layer, *layer_iterator_); |
| 385 | ASSERT_TRUE(layer_iterator_.represents_target_render_surface()); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 386 | occlusion->EnterLayer(layer_iterator_, false); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 387 | occlusion->LeaveLayer(layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 388 | ++layer_iterator_; |
| 389 | ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface()); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 390 | occlusion->EnterLayer(layer_iterator_, prevent_occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 391 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 392 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 393 | void LeaveContributingSurface( |
| 394 | typename Types::LayerType* layer, |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 395 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 396 | ASSERT_EQ(layer, *layer_iterator_); |
| 397 | ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 398 | occlusion->LeaveLayer(layer_iterator_); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 399 | ++layer_iterator_; |
| 400 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 401 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 402 | void VisitContributingSurface( |
| 403 | typename Types::LayerType* layer, |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 404 | typename Types::OcclusionTrackerType* occlusion) { |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 405 | EnterContributingSurface(layer, occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 406 | LeaveContributingSurface(layer, occlusion); |
| 407 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 408 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 409 | void ResetLayerIterator() { layer_iterator_ = layer_iterator_begin_; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 410 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 411 | const gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 412 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 413 | private: |
| 414 | void SetBaseProperties(typename Types::LayerType* layer, |
| 415 | const gfx::Transform& transform, |
| 416 | gfx::PointF position, |
| 417 | gfx::Size bounds) { |
| 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, |
| 427 | gfx::PointF position, |
| 428 | gfx::Size bounds) { |
| 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, |
| 434 | gfx::PointF position, |
| 435 | gfx::Size bounds) { |
| 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 | FakeImplProxy proxy_; |
| 460 | FakeLayerTreeHostImpl host_impl_; |
| 461 | bool opaque_layers_; |
| 462 | // These hold ownership of the layers for the duration of the test. |
| 463 | typename Types::LayerPtrType root_; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 464 | scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_; |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 465 | LayerImplList render_surface_layer_list_impl_; |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 466 | typename Types::TestLayerIterator layer_iterator_begin_; |
| 467 | typename Types::TestLayerIterator layer_iterator_; |
| 468 | typename Types::LayerType* last_layer_visited_; |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 469 | LayerList replica_layers_; |
| 470 | LayerList mask_layers_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 471 | }; |
| 472 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 473 | template <> |
| 474 | LayerTreeHost* |
| 475 | OcclusionTrackerTest<OcclusionTrackerTestMainThreadTypes>::GetHost() { |
| 476 | return NULL; |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 477 | } |
| 478 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 479 | template <> |
| 480 | LayerTreeImpl* |
| 481 | OcclusionTrackerTest<OcclusionTrackerTestImplThreadTypes>::GetHost() { |
| 482 | return host_impl_.active_tree(); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 483 | } |
| 484 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 485 | #define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \ |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 486 | class ClassName##MainThreadOpaqueLayers \ |
| 487 | : public ClassName<OcclusionTrackerTestMainThreadTypes> { \ |
| 488 | public: /* NOLINT(whitespace/indent) */ \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 489 | ClassName##MainThreadOpaqueLayers() \ |
| 490 | : ClassName<OcclusionTrackerTestMainThreadTypes>(true) {} \ |
| 491 | }; \ |
| 492 | TEST_F(ClassName##MainThreadOpaqueLayers, RunTest) { RunMyTest(); } |
| 493 | #define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \ |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 494 | class ClassName##MainThreadOpaquePaints \ |
| 495 | : public ClassName<OcclusionTrackerTestMainThreadTypes> { \ |
| 496 | public: /* NOLINT(whitespace/indent) */ \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 497 | ClassName##MainThreadOpaquePaints() \ |
| 498 | : ClassName<OcclusionTrackerTestMainThreadTypes>(false) {} \ |
| 499 | }; \ |
| 500 | TEST_F(ClassName##MainThreadOpaquePaints, RunTest) { RunMyTest(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 501 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 502 | #define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \ |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 503 | class ClassName##ImplThreadOpaqueLayers \ |
| 504 | : public ClassName<OcclusionTrackerTestImplThreadTypes> { \ |
| 505 | public: /* NOLINT(whitespace/indent) */ \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 506 | ClassName##ImplThreadOpaqueLayers() \ |
| 507 | : ClassName<OcclusionTrackerTestImplThreadTypes>(true) {} \ |
| 508 | }; \ |
| 509 | TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); } |
| 510 | #define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \ |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 511 | class ClassName##ImplThreadOpaquePaints \ |
| 512 | : public ClassName<OcclusionTrackerTestImplThreadTypes> { \ |
| 513 | public: /* NOLINT(whitespace/indent) */ \ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 514 | ClassName##ImplThreadOpaquePaints() \ |
| 515 | : ClassName<OcclusionTrackerTestImplThreadTypes>(false) {} \ |
| 516 | }; \ |
| 517 | TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 518 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 519 | #define ALL_OCCLUSIONTRACKER_TEST(ClassName) \ |
| 520 | RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \ |
| 521 | RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \ |
| 522 | RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \ |
| 523 | RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 524 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 525 | #define MAIN_THREAD_TEST(ClassName) \ |
| 526 | RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 527 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 528 | #define IMPL_THREAD_TEST(ClassName) \ |
| 529 | RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 530 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 531 | #define MAIN_AND_IMPL_THREAD_TEST(ClassName) \ |
| 532 | RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \ |
| 533 | RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 534 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 535 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 536 | class OcclusionTrackerTestIdentityTransforms |
| 537 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 538 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 539 | explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 540 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
[email protected] | ece1d95 | 2012-10-18 21:26:07 | [diff] [blame] | 541 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 542 | void RunMyTest() { |
| 543 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 544 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 545 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 546 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 547 | typename Types::ContentLayerType* layer = |
| 548 | this->CreateDrawingLayer(parent, |
| 549 | this->identity_matrix, |
| 550 | gfx::PointF(30.f, 30.f), |
| 551 | gfx::Size(500, 500), |
| 552 | true); |
| 553 | parent->SetMasksToBounds(true); |
| 554 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 555 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 556 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 557 | typename Types::RenderSurfaceType> occlusion( |
| 558 | gfx::Rect(0, 0, 1000, 1000), false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 559 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 560 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 561 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 562 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 563 | EXPECT_EQ(gfx::Rect().ToString(), |
| 564 | occlusion.occlusion_from_outside_target().ToString()); |
| 565 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 566 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 567 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 568 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70))); |
| 569 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70))); |
| 570 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70))); |
| 571 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 70, 70))); |
| 572 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 70))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 573 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 574 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 575 | parent, gfx::Rect(30, 30, 70, 70)).IsEmpty()); |
| 576 | EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70), |
| 577 | occlusion.UnoccludedLayerContentRect( |
| 578 | parent, gfx::Rect(29, 30, 70, 70))); |
| 579 | EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70), |
| 580 | occlusion.UnoccludedLayerContentRect( |
| 581 | parent, gfx::Rect(29, 29, 70, 70))); |
| 582 | EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1), |
| 583 | occlusion.UnoccludedLayerContentRect( |
| 584 | parent, gfx::Rect(30, 29, 70, 70))); |
| 585 | EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1), |
| 586 | occlusion.UnoccludedLayerContentRect( |
| 587 | parent, gfx::Rect(31, 29, 70, 70))); |
| 588 | EXPECT_RECT_EQ(gfx::Rect(), |
| 589 | occlusion.UnoccludedLayerContentRect( |
| 590 | parent, gfx::Rect(31, 30, 70, 70))); |
| 591 | EXPECT_RECT_EQ(gfx::Rect(), |
| 592 | occlusion.UnoccludedLayerContentRect( |
| 593 | parent, gfx::Rect(31, 31, 70, 70))); |
| 594 | EXPECT_RECT_EQ(gfx::Rect(), |
| 595 | occlusion.UnoccludedLayerContentRect( |
| 596 | parent, gfx::Rect(30, 31, 70, 70))); |
| 597 | EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69), |
| 598 | occlusion.UnoccludedLayerContentRect( |
| 599 | parent, gfx::Rect(29, 31, 70, 70))); |
| 600 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 601 | }; |
| 602 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 603 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 604 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 605 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 606 | class OcclusionTrackerTestQuadsMismatchLayer |
| 607 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 608 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 609 | explicit OcclusionTrackerTestQuadsMismatchLayer(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 610 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 611 | void RunMyTest() { |
| 612 | gfx::Transform layer_transform; |
| 613 | layer_transform.Translate(10.0, 10.0); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 614 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 615 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 616 | this->identity_matrix, gfx::Point(0, 0), gfx::Size(100, 100)); |
| 617 | typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer( |
| 618 | parent, layer_transform, gfx::PointF(), gfx::Size(90, 90), true); |
| 619 | typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer( |
| 620 | layer1, layer_transform, gfx::PointF(), gfx::Size(50, 50), true); |
| 621 | this->CalcDrawEtc(parent); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 622 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 623 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 624 | typename Types::RenderSurfaceType> occlusion( |
| 625 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 626 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 627 | this->VisitLayer(layer2, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 628 | this->EnterLayer(layer1, &occlusion, false); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 629 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 630 | EXPECT_EQ(gfx::Rect().ToString(), |
| 631 | occlusion.occlusion_from_outside_target().ToString()); |
| 632 | EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(), |
| 633 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 634 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 635 | // This checks cases where the quads don't match their "containing" |
| 636 | // layers, e.g. in terms of transforms or clip rect. This is typical for |
| 637 | // DelegatedRendererLayer. |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 638 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 639 | gfx::Transform quad_transform; |
| 640 | quad_transform.Translate(30.0, 30.0); |
| 641 | gfx::Rect clip_rect_in_target(0, 0, 100, 100); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 642 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 643 | EXPECT_TRUE(occlusion.UnoccludedContentRect(parent, |
| 644 | gfx::Rect(0, 0, 10, 10), |
| 645 | quad_transform, |
| 646 | false, |
| 647 | true, |
| 648 | clip_rect_in_target, |
| 649 | NULL).IsEmpty()); |
| 650 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 651 | occlusion.UnoccludedContentRect(parent, |
| 652 | gfx::Rect(0, 0, 10, 10), |
| 653 | quad_transform, |
| 654 | true, |
| 655 | true, |
| 656 | clip_rect_in_target, |
| 657 | NULL)); |
| 658 | EXPECT_RECT_EQ(gfx::Rect(40, 40, 10, 10), |
| 659 | occlusion.UnoccludedContentRect(parent, |
| 660 | gfx::Rect(40, 40, 10, 10), |
| 661 | quad_transform, |
| 662 | false, |
| 663 | true, |
| 664 | clip_rect_in_target, |
| 665 | NULL)); |
| 666 | EXPECT_RECT_EQ(gfx::Rect(40, 30, 5, 10), |
| 667 | occlusion.UnoccludedContentRect(parent, |
| 668 | gfx::Rect(35, 30, 10, 10), |
| 669 | quad_transform, |
| 670 | false, |
| 671 | true, |
| 672 | clip_rect_in_target, |
| 673 | NULL)); |
| 674 | EXPECT_RECT_EQ(gfx::Rect(40, 40, 5, 5), |
| 675 | occlusion.UnoccludedContentRect(parent, |
| 676 | gfx::Rect(40, 40, 10, 10), |
| 677 | quad_transform, |
| 678 | false, |
| 679 | true, |
| 680 | gfx::Rect(0, 0, 75, 75), |
| 681 | NULL)); |
| 682 | } |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 683 | }; |
| 684 | |
| 685 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestQuadsMismatchLayer); |
| 686 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 687 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 688 | class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 689 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 690 | explicit OcclusionTrackerTestRotatedChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 691 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 692 | void RunMyTest() { |
| 693 | gfx::Transform layer_transform; |
| 694 | layer_transform.Translate(250.0, 250.0); |
| 695 | layer_transform.Rotate(90.0); |
| 696 | layer_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 697 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 698 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 699 | this->identity_matrix, gfx::Point(0, 0), gfx::Size(200, 200)); |
| 700 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 701 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 702 | typename Types::ContentLayerType* layer = |
| 703 | this->CreateDrawingLayer(parent, |
| 704 | layer_transform, |
| 705 | gfx::PointF(30.f, 30.f), |
| 706 | gfx::Size(500, 500), |
| 707 | true); |
| 708 | parent->SetMasksToBounds(true); |
| 709 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 710 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 711 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 712 | typename Types::RenderSurfaceType> occlusion( |
| 713 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 714 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 715 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 716 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 717 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 718 | EXPECT_EQ(gfx::Rect().ToString(), |
| 719 | occlusion.occlusion_from_outside_target().ToString()); |
| 720 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 721 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 722 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 723 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70))); |
| 724 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70))); |
| 725 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70))); |
| 726 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 70, 70))); |
| 727 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 70))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 728 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 729 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 730 | parent, gfx::Rect(30, 30, 70, 70)).IsEmpty()); |
| 731 | EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70), |
| 732 | occlusion.UnoccludedLayerContentRect( |
| 733 | parent, gfx::Rect(29, 30, 70, 70))); |
| 734 | EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70), |
| 735 | occlusion.UnoccludedLayerContentRect( |
| 736 | parent, gfx::Rect(29, 29, 70, 70))); |
| 737 | EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1), |
| 738 | occlusion.UnoccludedLayerContentRect( |
| 739 | parent, gfx::Rect(30, 29, 70, 70))); |
| 740 | EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1), |
| 741 | occlusion.UnoccludedLayerContentRect( |
| 742 | parent, gfx::Rect(31, 29, 70, 70))); |
| 743 | EXPECT_RECT_EQ(gfx::Rect(), |
| 744 | occlusion.UnoccludedLayerContentRect( |
| 745 | parent, gfx::Rect(31, 30, 70, 70))); |
| 746 | EXPECT_RECT_EQ(gfx::Rect(), |
| 747 | occlusion.UnoccludedLayerContentRect( |
| 748 | parent, gfx::Rect(31, 31, 70, 70))); |
| 749 | EXPECT_RECT_EQ(gfx::Rect(), |
| 750 | occlusion.UnoccludedLayerContentRect( |
| 751 | parent, gfx::Rect(30, 31, 70, 70))); |
| 752 | EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69), |
| 753 | occlusion.UnoccludedLayerContentRect( |
| 754 | parent, gfx::Rect(29, 31, 70, 70))); |
| 755 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 756 | }; |
| 757 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 758 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 759 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 760 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 761 | class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 762 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 763 | explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 764 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 765 | void RunMyTest() { |
| 766 | gfx::Transform layer_transform; |
| 767 | layer_transform.Translate(20.0, 20.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 768 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 769 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 770 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 771 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 772 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 773 | typename Types::ContentLayerType* layer = |
| 774 | this->CreateDrawingLayer(parent, |
| 775 | layer_transform, |
| 776 | gfx::PointF(30.f, 30.f), |
| 777 | gfx::Size(500, 500), |
| 778 | true); |
| 779 | parent->SetMasksToBounds(true); |
| 780 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 781 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 782 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 783 | typename Types::RenderSurfaceType> occlusion( |
| 784 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 785 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 786 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 787 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 788 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 789 | EXPECT_EQ(gfx::Rect().ToString(), |
| 790 | occlusion.occlusion_from_outside_target().ToString()); |
| 791 | EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(), |
| 792 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 793 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 794 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 50, 50, 50))); |
| 795 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(49, 50, 50, 50))); |
| 796 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(50, 49, 50, 50))); |
| 797 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(51, 50, 50, 50))); |
| 798 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 51, 50, 50))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 799 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 800 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 801 | parent, gfx::Rect(50, 50, 50, 50)).IsEmpty()); |
| 802 | EXPECT_RECT_EQ(gfx::Rect(49, 50, 1, 50), |
| 803 | occlusion.UnoccludedLayerContentRect( |
| 804 | parent, gfx::Rect(49, 50, 50, 50))); |
| 805 | EXPECT_RECT_EQ(gfx::Rect(49, 49, 50, 50), |
| 806 | occlusion.UnoccludedLayerContentRect( |
| 807 | parent, gfx::Rect(49, 49, 50, 50))); |
| 808 | EXPECT_RECT_EQ(gfx::Rect(50, 49, 50, 1), |
| 809 | occlusion.UnoccludedLayerContentRect( |
| 810 | parent, gfx::Rect(50, 49, 50, 50))); |
| 811 | EXPECT_RECT_EQ(gfx::Rect(51, 49, 49, 1), |
| 812 | occlusion.UnoccludedLayerContentRect( |
| 813 | parent, gfx::Rect(51, 49, 50, 50))); |
| 814 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 815 | parent, gfx::Rect(51, 50, 50, 50)).IsEmpty()); |
| 816 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 817 | parent, gfx::Rect(51, 51, 50, 50)).IsEmpty()); |
| 818 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 819 | parent, gfx::Rect(50, 51, 50, 50)).IsEmpty()); |
| 820 | EXPECT_RECT_EQ(gfx::Rect(49, 51, 1, 49), |
| 821 | occlusion.UnoccludedLayerContentRect( |
| 822 | parent, gfx::Rect(49, 51, 50, 50))); |
| 823 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 824 | }; |
| 825 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 826 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 827 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 828 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 829 | class OcclusionTrackerTestChildInRotatedChild |
| 830 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 831 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 832 | explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 833 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 834 | void RunMyTest() { |
| 835 | gfx::Transform child_transform; |
| 836 | child_transform.Translate(250.0, 250.0); |
| 837 | child_transform.Rotate(90.0); |
| 838 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 839 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 840 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 841 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 842 | parent->SetMasksToBounds(true); |
[email protected] | 3a9a92d | 2013-07-11 04:37:00 | [diff] [blame] | 843 | typename Types::LayerType* child = this->CreateSurface( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 844 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); |
| 845 | child->SetMasksToBounds(true); |
| 846 | typename Types::ContentLayerType* layer = |
| 847 | this->CreateDrawingLayer(child, |
| 848 | this->identity_matrix, |
| 849 | gfx::PointF(10.f, 10.f), |
| 850 | gfx::Size(500, 500), |
| 851 | true); |
| 852 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 853 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 854 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 855 | typename Types::RenderSurfaceType> occlusion( |
| 856 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 857 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 858 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 859 | this->EnterContributingSurface(child, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 860 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 861 | EXPECT_EQ(gfx::Rect().ToString(), |
| 862 | occlusion.occlusion_from_outside_target().ToString()); |
| 863 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), |
| 864 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 865 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 866 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 867 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 868 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 869 | EXPECT_EQ(gfx::Rect().ToString(), |
| 870 | occlusion.occlusion_from_outside_target().ToString()); |
| 871 | EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), |
| 872 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 873 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 874 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60))); |
| 875 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60))); |
| 876 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60))); |
| 877 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 40, 70, 60))); |
| 878 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 41, 70, 60))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 879 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 880 | /* Justification for the above occlusion from |layer|: |
| 881 | 100 |
| 882 | +---------------------+ |
| 883 | | | |
| 884 | | 30 | rotate(90) |
| 885 | | 30 + ---------------------------------+ |
| 886 | 100 | | 10 | | ==> |
| 887 | | |10+---------------------------------+ |
| 888 | | | | | | | |
| 889 | | | | | | | |
| 890 | | | | | | | |
| 891 | +----|--|-------------+ | | |
| 892 | | | | | |
| 893 | | | | | |
| 894 | | | | |500 |
| 895 | | | | | |
| 896 | | | | | |
| 897 | | | | | |
| 898 | | | | | |
| 899 | +--|-------------------------------+ | |
| 900 | | | |
| 901 | +---------------------------------+ |
| 902 | 500 |
| 903 | |
| 904 | +---------------------+ |
| 905 | | |30 Visible region of |layer|: ///// |
| 906 | | | |
| 907 | | +---------------------------------+ |
| 908 | 100| | |10 | |
| 909 | | +---------------------------------+ | |
| 910 | | | |///////////////| 420 | | |
| 911 | | | |///////////////|60 | | |
| 912 | | | |///////////////| | | |
| 913 | +--|--|---------------+ | | |
| 914 | 20|10| 70 | | |
| 915 | | | | | |
| 916 | | | | | |
| 917 | | | | | |
| 918 | | | | | |
| 919 | | | | | |
| 920 | | | |10| |
| 921 | | +------------------------------|--+ |
| 922 | | 490 | |
| 923 | +---------------------------------+ |
| 924 | 500 |
| 925 | |
| 926 | */ |
| 927 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 928 | }; |
| 929 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 930 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 931 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 932 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 933 | class OcclusionTrackerTestScaledRenderSurface |
| 934 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 935 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 936 | explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 937 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 938 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 939 | void RunMyTest() { |
| 940 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 941 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 942 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 943 | gfx::Transform layer1_matrix; |
| 944 | layer1_matrix.Scale(2.0, 2.0); |
| 945 | typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer( |
| 946 | parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 947 | layer1->SetForceRenderSurface(true); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 948 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 949 | gfx::Transform layer2_matrix; |
| 950 | layer2_matrix.Translate(25.0, 25.0); |
| 951 | typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer( |
| 952 | layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true); |
| 953 | typename Types::ContentLayerType* occluder = |
| 954 | this->CreateDrawingLayer(parent, |
| 955 | this->identity_matrix, |
| 956 | gfx::PointF(100.f, 100.f), |
| 957 | gfx::Size(500, 500), |
| 958 | true); |
| 959 | this->CalcDrawEtc(parent); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 960 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 961 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 962 | typename Types::RenderSurfaceType> occlusion( |
| 963 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 964 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 965 | this->VisitLayer(occluder, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 966 | this->EnterLayer(layer2, &occlusion, false); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 967 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 968 | EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), |
| 969 | occlusion.occlusion_from_outside_target().ToString()); |
| 970 | EXPECT_EQ(gfx::Rect().ToString(), |
| 971 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 972 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 973 | EXPECT_RECT_EQ( |
| 974 | gfx::Rect(0, 0, 25, 25), |
| 975 | occlusion.UnoccludedLayerContentRect(layer2, gfx::Rect(0, 0, 25, 25))); |
| 976 | EXPECT_RECT_EQ(gfx::Rect(10, 25, 15, 25), |
| 977 | occlusion.UnoccludedLayerContentRect( |
| 978 | layer2, gfx::Rect(10, 25, 25, 25))); |
| 979 | EXPECT_RECT_EQ(gfx::Rect(25, 10, 25, 15), |
| 980 | occlusion.UnoccludedLayerContentRect( |
| 981 | layer2, gfx::Rect(25, 10, 25, 25))); |
| 982 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 983 | layer2, gfx::Rect(25, 25, 25, 25)).IsEmpty()); |
| 984 | } |
[email protected] | 710ffc0 | 2012-10-30 21:42:02 | [diff] [blame] | 985 | }; |
| 986 | |
| 987 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface); |
| 988 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 989 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 990 | class OcclusionTrackerTestVisitTargetTwoTimes |
| 991 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 992 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 993 | explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 994 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 995 | void RunMyTest() { |
| 996 | gfx::Transform child_transform; |
| 997 | child_transform.Translate(250.0, 250.0); |
| 998 | child_transform.Rotate(90.0); |
| 999 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1000 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1001 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 1002 | this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); |
| 1003 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 1004 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 1005 | parent->SetMasksToBounds(true); |
[email protected] | 3a9a92d | 2013-07-11 04:37:00 | [diff] [blame] | 1006 | typename Types::LayerType* child = this->CreateSurface( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1007 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); |
| 1008 | child->SetMasksToBounds(true); |
| 1009 | typename Types::ContentLayerType* layer = |
| 1010 | this->CreateDrawingLayer(child, |
| 1011 | this->identity_matrix, |
| 1012 | gfx::PointF(10.f, 10.f), |
| 1013 | gfx::Size(500, 500), |
| 1014 | true); |
| 1015 | // |child2| makes |parent|'s surface get considered by OcclusionTracker |
| 1016 | // first, instead of |child|'s. This exercises different code in |
| 1017 | // LeaveToRenderTarget, as the target surface has already been seen. |
| 1018 | typename Types::ContentLayerType* child2 = |
| 1019 | this->CreateDrawingLayer(parent, |
| 1020 | this->identity_matrix, |
| 1021 | gfx::PointF(30.f, 30.f), |
| 1022 | gfx::Size(60, 20), |
| 1023 | true); |
| 1024 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1025 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1026 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1027 | typename Types::RenderSurfaceType> occlusion( |
| 1028 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1029 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1030 | this->VisitLayer(child2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1031 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1032 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1033 | occlusion.occlusion_from_outside_target().ToString()); |
| 1034 | EXPECT_EQ(gfx::Rect(30, 30, 60, 20).ToString(), |
| 1035 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1036 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1037 | this->VisitLayer(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1038 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1039 | EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(), |
| 1040 | occlusion.occlusion_from_outside_target().ToString()); |
| 1041 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), |
| 1042 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1043 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1044 | this->EnterContributingSurface(child, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1045 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1046 | EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(), |
| 1047 | occlusion.occlusion_from_outside_target().ToString()); |
| 1048 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), |
| 1049 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1050 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1051 | // Occlusion in |child2| should get merged with the |child| surface we are |
| 1052 | // leaving now. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1053 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1054 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1055 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1056 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1057 | occlusion.occlusion_from_outside_target().ToString()); |
| 1058 | EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60)) |
| 1059 | .ToString(), |
| 1060 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1061 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1062 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70))); |
| 1063 | EXPECT_RECT_EQ(gfx::Rect(90, 30, 10, 10), |
| 1064 | occlusion.UnoccludedLayerContentRect( |
| 1065 | parent, gfx::Rect(30, 30, 70, 70))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1066 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1067 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 60, 10))); |
| 1068 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 60, 10))); |
| 1069 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 60, 10))); |
| 1070 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 60, 10))); |
| 1071 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 60, 10))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1072 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1073 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60))); |
| 1074 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60))); |
| 1075 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1076 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1077 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1078 | parent, gfx::Rect(30, 30, 60, 10)).IsEmpty()); |
| 1079 | EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 10), |
| 1080 | occlusion.UnoccludedLayerContentRect( |
| 1081 | parent, gfx::Rect(29, 30, 60, 10))); |
| 1082 | EXPECT_RECT_EQ(gfx::Rect(30, 29, 60, 1), |
| 1083 | occlusion.UnoccludedLayerContentRect( |
| 1084 | parent, gfx::Rect(30, 29, 60, 10))); |
| 1085 | EXPECT_RECT_EQ(gfx::Rect(90, 30, 1, 10), |
| 1086 | occlusion.UnoccludedLayerContentRect( |
| 1087 | parent, gfx::Rect(31, 30, 60, 10))); |
| 1088 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1089 | parent, gfx::Rect(30, 31, 60, 10)).IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1090 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1091 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1092 | parent, gfx::Rect(30, 40, 70, 60)).IsEmpty()); |
| 1093 | EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60), |
| 1094 | occlusion.UnoccludedLayerContentRect( |
| 1095 | parent, gfx::Rect(29, 40, 70, 60))); |
| 1096 | // This rect is mostly occluded by |child2|. |
| 1097 | EXPECT_RECT_EQ(gfx::Rect(90, 39, 10, 1), |
| 1098 | occlusion.UnoccludedLayerContentRect( |
| 1099 | parent, gfx::Rect(30, 39, 70, 60))); |
| 1100 | // This rect extends past top/right ends of |child2|. |
| 1101 | EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 11), |
| 1102 | occlusion.UnoccludedLayerContentRect( |
| 1103 | parent, gfx::Rect(30, 29, 70, 70))); |
| 1104 | // This rect extends past left/right ends of |child2|. |
| 1105 | EXPECT_RECT_EQ(gfx::Rect(20, 39, 80, 60), |
| 1106 | occlusion.UnoccludedLayerContentRect( |
| 1107 | parent, gfx::Rect(20, 39, 80, 60))); |
| 1108 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1109 | occlusion.UnoccludedLayerContentRect( |
| 1110 | parent, gfx::Rect(31, 40, 70, 60))); |
| 1111 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1112 | occlusion.UnoccludedLayerContentRect( |
| 1113 | parent, gfx::Rect(30, 41, 70, 60))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1114 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1115 | /* Justification for the above occlusion from |layer|: |
| 1116 | 100 |
| 1117 | +---------------------+ |
| 1118 | | | |
| 1119 | | 30 | rotate(90) |
| 1120 | | 30 + ------------+--------------------+ |
| 1121 | 100 | | 10 | | | ==> |
| 1122 | | |10+----------|----------------------+ |
| 1123 | | + ------------+ | | | |
| 1124 | | | | | | | |
| 1125 | | | | | | | |
| 1126 | +----|--|-------------+ | | |
| 1127 | | | | | |
| 1128 | | | | | |
| 1129 | | | | |500 |
| 1130 | | | | | |
| 1131 | | | | | |
| 1132 | | | | | |
| 1133 | | | | | |
| 1134 | +--|-------------------------------+ | |
| 1135 | | | |
| 1136 | +---------------------------------+ |
| 1137 | 500 |
| 1138 | |
| 1139 | |
| 1140 | +---------------------+ |
| 1141 | | |30 Visible region of |layer|: ///// |
| 1142 | | 30 60 | |child2|: \\\\\ |
| 1143 | | 30 +------------+--------------------+ |
| 1144 | | |\\\\\\\\\\\\| |10 | |
| 1145 | | +--|\\\\\\\\\\\\|-----------------+ | |
| 1146 | | | +------------+//| 420 | | |
| 1147 | | | |///////////////|60 | | |
| 1148 | | | |///////////////| | | |
| 1149 | +--|--|---------------+ | | |
| 1150 | 20|10| 70 | | |
| 1151 | | | | | |
| 1152 | | | | | |
| 1153 | | | | | |
| 1154 | | | | | |
| 1155 | | | | | |
| 1156 | | | |10| |
| 1157 | | +------------------------------|--+ |
| 1158 | | 490 | |
| 1159 | +---------------------------------+ |
| 1160 | 500 |
| 1161 | */ |
| 1162 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1163 | }; |
| 1164 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1165 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1166 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1167 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1168 | class OcclusionTrackerTestSurfaceRotatedOffAxis |
| 1169 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1170 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1171 | explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1172 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1173 | void RunMyTest() { |
| 1174 | gfx::Transform child_transform; |
| 1175 | child_transform.Translate(250.0, 250.0); |
| 1176 | child_transform.Rotate(95.0); |
| 1177 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1178 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1179 | gfx::Transform layer_transform; |
| 1180 | layer_transform.Translate(10.0, 10.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1181 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1182 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 1183 | this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000)); |
| 1184 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 1185 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 1186 | typename Types::LayerType* child = this->CreateLayer( |
| 1187 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500)); |
| 1188 | child->SetMasksToBounds(true); |
| 1189 | typename Types::ContentLayerType* layer = this->CreateDrawingLayer( |
| 1190 | child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true); |
| 1191 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1192 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1193 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1194 | typename Types::RenderSurfaceType> occlusion( |
| 1195 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1196 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1197 | gfx::Rect clipped_layer_in_child = MathUtil::MapClippedRect( |
| 1198 | layer_transform, layer->visible_content_rect()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1199 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1200 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1201 | this->EnterContributingSurface(child, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1202 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1203 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1204 | occlusion.occlusion_from_outside_target().ToString()); |
| 1205 | EXPECT_EQ(clipped_layer_in_child.ToString(), |
| 1206 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1207 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1208 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1209 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1210 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1211 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1212 | occlusion.occlusion_from_outside_target().ToString()); |
| 1213 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1214 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1215 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1216 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(75, 55, 1, 1))); |
| 1217 | EXPECT_RECT_EQ( |
| 1218 | gfx::Rect(75, 55, 1, 1), |
| 1219 | occlusion.UnoccludedLayerContentRect(parent, gfx::Rect(75, 55, 1, 1))); |
| 1220 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1221 | }; |
| 1222 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1223 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1224 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1225 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1226 | class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren |
| 1227 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1228 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1229 | explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1230 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1231 | void RunMyTest() { |
| 1232 | gfx::Transform child_transform; |
| 1233 | child_transform.Translate(250.0, 250.0); |
| 1234 | child_transform.Rotate(90.0); |
| 1235 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1236 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1237 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 1238 | this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000)); |
| 1239 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 1240 | root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true); |
| 1241 | parent->SetMasksToBounds(true); |
| 1242 | typename Types::ContentLayerType* child = |
[email protected] | 3a9a92d | 2013-07-11 04:37:00 | [diff] [blame] | 1243 | this->CreateDrawingSurface(parent, |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1244 | child_transform, |
| 1245 | gfx::PointF(30.f, 30.f), |
| 1246 | gfx::Size(500, 500), |
| 1247 | false); |
| 1248 | child->SetMasksToBounds(true); |
| 1249 | typename Types::ContentLayerType* layer1 = |
| 1250 | this->CreateDrawingLayer(child, |
| 1251 | this->identity_matrix, |
| 1252 | gfx::PointF(10.f, 10.f), |
| 1253 | gfx::Size(500, 500), |
| 1254 | true); |
| 1255 | typename Types::ContentLayerType* layer2 = |
| 1256 | this->CreateDrawingLayer(child, |
| 1257 | this->identity_matrix, |
| 1258 | gfx::PointF(10.f, 450.f), |
| 1259 | gfx::Size(500, 60), |
| 1260 | true); |
| 1261 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1262 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1263 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1264 | typename Types::RenderSurfaceType> occlusion( |
| 1265 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1266 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1267 | this->VisitLayer(layer2, &occlusion); |
| 1268 | this->VisitLayer(layer1, &occlusion); |
| 1269 | this->VisitLayer(child, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1270 | this->EnterContributingSurface(child, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1271 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1272 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1273 | occlusion.occlusion_from_outside_target().ToString()); |
| 1274 | EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), |
| 1275 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1276 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1277 | EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 430, 60, 70))); |
| 1278 | EXPECT_FALSE(occlusion.OccludedLayer(child, gfx::Rect(9, 430, 60, 70))); |
| 1279 | // These rects are occluded except for the part outside the bounds of the |
| 1280 | // target surface. |
| 1281 | EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 429, 60, 70))); |
| 1282 | EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(11, 430, 60, 70))); |
| 1283 | EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 431, 60, 70))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1284 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1285 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1286 | child, gfx::Rect(10, 430, 60, 70)).IsEmpty()); |
| 1287 | EXPECT_RECT_EQ( |
| 1288 | gfx::Rect(9, 430, 1, 70), |
| 1289 | occlusion.UnoccludedLayerContentRect(child, gfx::Rect(9, 430, 60, 70))); |
| 1290 | // These rects are occluded except for the part outside the bounds of the |
| 1291 | // target surface. |
| 1292 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1293 | occlusion.UnoccludedLayerContentRect( |
| 1294 | child, gfx::Rect(10, 429, 60, 70))); |
| 1295 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1296 | occlusion.UnoccludedLayerContentRect( |
| 1297 | child, gfx::Rect(11, 430, 60, 70))); |
| 1298 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1299 | occlusion.UnoccludedLayerContentRect( |
| 1300 | child, gfx::Rect(10, 431, 60, 70))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1301 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1302 | this->LeaveContributingSurface(child, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1303 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1304 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1305 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1306 | occlusion.occlusion_from_outside_target().ToString()); |
| 1307 | EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), |
| 1308 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1309 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1310 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60))); |
| 1311 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60))); |
| 1312 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1313 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1314 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1315 | parent, gfx::Rect(30, 40, 70, 60)).IsEmpty()); |
| 1316 | EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60), |
| 1317 | occlusion.UnoccludedLayerContentRect( |
| 1318 | parent, gfx::Rect(29, 40, 70, 60))); |
| 1319 | EXPECT_RECT_EQ(gfx::Rect(30, 39, 70, 1), |
| 1320 | occlusion.UnoccludedLayerContentRect( |
| 1321 | parent, gfx::Rect(30, 39, 70, 60))); |
| 1322 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1323 | occlusion.UnoccludedLayerContentRect( |
| 1324 | parent, gfx::Rect(31, 40, 70, 60))); |
| 1325 | EXPECT_RECT_EQ(gfx::Rect(), |
| 1326 | occlusion.UnoccludedLayerContentRect( |
| 1327 | parent, gfx::Rect(30, 41, 70, 60))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1328 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1329 | /* Justification for the above occlusion from |layer1| and |layer2|: |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1330 | |
| 1331 | +---------------------+ |
| 1332 | | |30 Visible region of |layer1|: ///// |
| 1333 | | | Visible region of |layer2|: \\\\\ |
| 1334 | | +---------------------------------+ |
| 1335 | | | |10 | |
| 1336 | | +---------------+-----------------+ | |
| 1337 | | | |\\\\\\\\\\\\|//| 420 | | |
| 1338 | | | |\\\\\\\\\\\\|//|60 | | |
| 1339 | | | |\\\\\\\\\\\\|//| | | |
| 1340 | +--|--|------------|--+ | | |
| 1341 | 20|10| 70 | | | |
| 1342 | | | | | | |
| 1343 | | | | | | |
| 1344 | | | | | | |
| 1345 | | | | | | |
| 1346 | | | | | | |
| 1347 | | | | |10| |
| 1348 | | +------------|-----------------|--+ |
| 1349 | | | 490 | |
| 1350 | +---------------+-----------------+ |
| 1351 | 60 440 |
| 1352 | */ |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1353 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1354 | }; |
| 1355 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1356 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1357 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1358 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1359 | class OcclusionTrackerTestOverlappingSurfaceSiblings |
| 1360 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1361 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1362 | explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1363 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1364 | void RunMyTest() { |
| 1365 | gfx::Transform child_transform; |
| 1366 | child_transform.Translate(250.0, 250.0); |
| 1367 | child_transform.Rotate(90.0); |
| 1368 | child_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1369 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1370 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1371 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 1372 | parent->SetMasksToBounds(true); |
| 1373 | typename Types::LayerType* child1 = this->CreateSurface( |
| 1374 | parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(10, 10)); |
| 1375 | typename Types::LayerType* child2 = this->CreateSurface( |
| 1376 | parent, child_transform, gfx::PointF(20.f, 40.f), gfx::Size(10, 10)); |
| 1377 | typename Types::ContentLayerType* layer1 = |
| 1378 | this->CreateDrawingLayer(child1, |
| 1379 | this->identity_matrix, |
| 1380 | gfx::PointF(-10.f, -10.f), |
| 1381 | gfx::Size(510, 510), |
| 1382 | true); |
| 1383 | typename Types::ContentLayerType* layer2 = |
| 1384 | this->CreateDrawingLayer(child2, |
| 1385 | this->identity_matrix, |
| 1386 | gfx::PointF(-10.f, -10.f), |
| 1387 | gfx::Size(510, 510), |
| 1388 | true); |
| 1389 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1390 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1391 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1392 | typename Types::RenderSurfaceType> occlusion( |
| 1393 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1394 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1395 | this->VisitLayer(layer2, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1396 | this->EnterContributingSurface(child2, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1397 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1398 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1399 | occlusion.occlusion_from_outside_target().ToString()); |
| 1400 | EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), |
| 1401 | occlusion.occlusion_from_inside_target().ToString()); |
[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(child2, gfx::Rect(-10, 420, 70, 80))); |
| 1404 | EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-11, 420, 70, 80))); |
| 1405 | EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 419, 70, 80))); |
| 1406 | EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 420, 71, 80))); |
| 1407 | EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 420, 70, 81))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1408 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1409 | // There is nothing above child2's surface in the z-order. |
| 1410 | EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80), |
| 1411 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 1412 | child2, false, gfx::Rect(-10, 420, 70, 80), NULL)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1413 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1414 | this->LeaveContributingSurface(child2, &occlusion); |
| 1415 | this->VisitLayer(layer1, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1416 | this->EnterContributingSurface(child1, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1417 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1418 | EXPECT_EQ(gfx::Rect(0, 430, 70, 80).ToString(), |
| 1419 | occlusion.occlusion_from_outside_target().ToString()); |
| 1420 | EXPECT_EQ(gfx::Rect(-10, 430, 80, 70).ToString(), |
| 1421 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1422 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1423 | // child2's contents will occlude child1 below it. |
| 1424 | EXPECT_RECT_EQ(gfx::Rect(-10, 430, 10, 70), |
| 1425 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 1426 | child1, false, gfx::Rect(-10, 430, 80, 70), NULL)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1427 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1428 | this->LeaveContributingSurface(child1, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1429 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1430 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1431 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1432 | occlusion.occlusion_from_outside_target().ToString()); |
| 1433 | EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70)) |
| 1434 | .ToString(), |
| 1435 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1436 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1437 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 20, 80, 80))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1438 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1439 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 20, 70, 80))); |
| 1440 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 20, 70, 80))); |
| 1441 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 19, 70, 80))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1442 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1443 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(20, 30, 80, 70))); |
| 1444 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(19, 30, 80, 70))); |
| 1445 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 29, 80, 70))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1446 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1447 | /* Justification for the above occlusion: |
| 1448 | 100 |
| 1449 | +---------------------+ |
| 1450 | | 20 | layer1 |
| 1451 | | 30+ ---------------------------------+ |
| 1452 | 100 | 30| | layer2 | |
| 1453 | |20+----------------------------------+ | |
| 1454 | | | | | | | |
| 1455 | | | | | | | |
| 1456 | | | | | | | |
| 1457 | +--|-|----------------+ | | |
| 1458 | | | | | 510 |
| 1459 | | | | | |
| 1460 | | | | | |
| 1461 | | | | | |
| 1462 | | | | | |
| 1463 | | | | | |
| 1464 | | | | | |
| 1465 | | +--------------------------------|-+ |
| 1466 | | | |
| 1467 | +----------------------------------+ |
| 1468 | 510 |
| 1469 | */ |
| 1470 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1471 | }; |
| 1472 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1473 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1474 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1475 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1476 | class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms |
| 1477 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1478 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1479 | explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1480 | bool opaque_layers) |
| 1481 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1482 | void RunMyTest() { |
| 1483 | gfx::Transform child1_transform; |
| 1484 | child1_transform.Translate(250.0, 250.0); |
| 1485 | child1_transform.Rotate(-90.0); |
| 1486 | child1_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1487 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1488 | gfx::Transform child2_transform; |
| 1489 | child2_transform.Translate(250.0, 250.0); |
| 1490 | child2_transform.Rotate(90.0); |
| 1491 | child2_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1492 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1493 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1494 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 1495 | parent->SetMasksToBounds(true); |
| 1496 | typename Types::LayerType* child1 = this->CreateSurface( |
| 1497 | parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10)); |
| 1498 | typename Types::LayerType* child2 = |
| 1499 | this->CreateDrawingSurface(parent, |
| 1500 | child2_transform, |
| 1501 | gfx::PointF(20.f, 40.f), |
| 1502 | gfx::Size(10, 10), |
| 1503 | false); |
| 1504 | typename Types::ContentLayerType* layer1 = |
| 1505 | this->CreateDrawingLayer(child1, |
| 1506 | this->identity_matrix, |
| 1507 | gfx::PointF(-10.f, -20.f), |
| 1508 | gfx::Size(510, 510), |
| 1509 | true); |
| 1510 | typename Types::ContentLayerType* layer2 = |
| 1511 | this->CreateDrawingLayer(child2, |
| 1512 | this->identity_matrix, |
| 1513 | gfx::PointF(-10.f, -10.f), |
| 1514 | gfx::Size(510, 510), |
| 1515 | true); |
| 1516 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1517 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1518 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1519 | typename Types::RenderSurfaceType> occlusion( |
| 1520 | gfx::Rect(0, 0, 1000, 1000)); |
[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->VisitLayer(layer2, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1523 | this->EnterLayer(child2, &occlusion, false); |
[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, 420, 70, 80).ToString(), |
| 1528 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1529 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1530 | this->LeaveLayer(child2, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1531 | this->EnterContributingSurface(child2, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1532 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1533 | // There is nothing above child2's surface in the z-order. |
| 1534 | EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80), |
| 1535 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 1536 | child2, false, gfx::Rect(-10, 420, 70, 80), NULL)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1537 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1538 | this->LeaveContributingSurface(child2, &occlusion); |
| 1539 | this->VisitLayer(layer1, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1540 | this->EnterContributingSurface(child1, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1541 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1542 | EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(), |
| 1543 | occlusion.occlusion_from_outside_target().ToString()); |
| 1544 | EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(), |
| 1545 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1546 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1547 | // child2's contents will occlude child1 below it. |
| 1548 | EXPECT_RECT_EQ(gfx::Rect(420, -20, 80, 90), |
| 1549 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 1550 | child1, false, gfx::Rect(420, -20, 80, 90), NULL)); |
| 1551 | EXPECT_RECT_EQ(gfx::Rect(490, -10, 10, 80), |
| 1552 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 1553 | child1, false, gfx::Rect(420, -10, 80, 90), NULL)); |
| 1554 | EXPECT_RECT_EQ(gfx::Rect(420, -20, 70, 10), |
| 1555 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 1556 | child1, false, gfx::Rect(420, -20, 70, 90), NULL)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1557 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1558 | this->LeaveContributingSurface(child1, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1559 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1560 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1561 | EXPECT_EQ(gfx::Rect().ToString(), |
| 1562 | occlusion.occlusion_from_outside_target().ToString()); |
| 1563 | EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), |
| 1564 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1565 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1566 | /* Justification for the above occlusion: |
| 1567 | 100 |
| 1568 | +---------------------+ |
| 1569 | |20 | layer1 |
| 1570 | 10+----------------------------------+ |
| 1571 | 100 || 30 | layer2 | |
| 1572 | |20+----------------------------------+ |
| 1573 | || | | | | |
| 1574 | || | | | | |
| 1575 | || | | | | |
| 1576 | +|-|------------------+ | | |
| 1577 | | | | | 510 |
| 1578 | | | 510 | | |
| 1579 | | | | | |
| 1580 | | | | | |
| 1581 | | | | | |
| 1582 | | | | | |
| 1583 | | | 520 | | |
| 1584 | +----------------------------------+ | |
| 1585 | | | |
| 1586 | +----------------------------------+ |
| 1587 | 510 |
| 1588 | */ |
| 1589 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1590 | }; |
| 1591 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1592 | ALL_OCCLUSIONTRACKER_TEST( |
| 1593 | OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1594 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1595 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1596 | class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1597 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1598 | explicit OcclusionTrackerTestFilters(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1599 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1600 | void RunMyTest() { |
| 1601 | gfx::Transform layer_transform; |
| 1602 | layer_transform.Translate(250.0, 250.0); |
| 1603 | layer_transform.Rotate(90.0); |
| 1604 | layer_transform.Translate(-250.0, -250.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1605 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1606 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1607 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 1608 | parent->SetMasksToBounds(true); |
| 1609 | typename Types::ContentLayerType* blur_layer = |
| 1610 | this->CreateDrawingLayer(parent, |
| 1611 | layer_transform, |
| 1612 | gfx::PointF(30.f, 30.f), |
| 1613 | gfx::Size(500, 500), |
| 1614 | true); |
| 1615 | typename Types::ContentLayerType* opaque_layer = |
| 1616 | this->CreateDrawingLayer(parent, |
| 1617 | layer_transform, |
| 1618 | gfx::PointF(30.f, 30.f), |
| 1619 | gfx::Size(500, 500), |
| 1620 | true); |
| 1621 | typename Types::ContentLayerType* opacity_layer = |
| 1622 | this->CreateDrawingLayer(parent, |
| 1623 | layer_transform, |
| 1624 | gfx::PointF(30.f, 30.f), |
| 1625 | gfx::Size(500, 500), |
| 1626 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1627 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1628 | FilterOperations filters; |
| 1629 | filters.Append(FilterOperation::CreateBlurFilter(10.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1630 | blur_layer->SetFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1631 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1632 | filters.Clear(); |
| 1633 | filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1634 | opaque_layer->SetFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1635 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1636 | filters.Clear(); |
| 1637 | filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1638 | opacity_layer->SetFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1639 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1640 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1641 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1642 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1643 | typename Types::RenderSurfaceType> occlusion( |
| 1644 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1645 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1646 | // Opacity layer won't contribute to occlusion. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1647 | this->VisitLayer(opacity_layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1648 | this->EnterContributingSurface(opacity_layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1649 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1650 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1651 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1652 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1653 | // And has nothing to contribute to its parent surface. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1654 | this->LeaveContributingSurface(opacity_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1655 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1656 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1657 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1658 | // Opaque layer will contribute to occlusion. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1659 | this->VisitLayer(opaque_layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1660 | this->EnterContributingSurface(opaque_layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1661 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1662 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1663 | EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(), |
| 1664 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1665 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1666 | // And it gets translated to the parent surface. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1667 | this->LeaveContributingSurface(opaque_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1668 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1669 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 1670 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1671 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1672 | // The blur layer needs to throw away any occlusion from outside its |
| 1673 | // subtree. |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1674 | this->EnterLayer(blur_layer, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1675 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1676 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1677 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1678 | // And it won't contribute to occlusion. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1679 | this->LeaveLayer(blur_layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1680 | this->EnterContributingSurface(blur_layer, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1681 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1682 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1683 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1684 | // But the opaque layer's occlusion is preserved on the parent. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1685 | this->LeaveContributingSurface(blur_layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1686 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1687 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1688 | EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), |
| 1689 | occlusion.occlusion_from_inside_target().ToString()); |
| 1690 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1691 | }; |
| 1692 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1693 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1694 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1695 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1696 | class OcclusionTrackerTestReplicaDoesOcclude |
| 1697 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1698 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1699 | explicit OcclusionTrackerTestReplicaDoesOcclude(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1700 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1701 | void RunMyTest() { |
| 1702 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1703 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 1704 | typename Types::LayerType* surface = |
| 1705 | this->CreateDrawingSurface(parent, |
| 1706 | this->identity_matrix, |
| 1707 | gfx::PointF(0.f, 100.f), |
| 1708 | gfx::Size(50, 50), |
| 1709 | true); |
| 1710 | this->CreateReplicaLayer( |
| 1711 | surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size()); |
| 1712 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1713 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1714 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1715 | typename Types::RenderSurfaceType> occlusion( |
| 1716 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1717 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1718 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1719 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1720 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), |
| 1721 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1722 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1723 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1724 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1725 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1726 | // The surface and replica should both be occluding the parent. |
| 1727 | EXPECT_EQ( |
| 1728 | UnionRegions(gfx::Rect(0, 100, 50, 50), |
| 1729 | gfx::Rect(50, 150, 50, 50)).ToString(), |
| 1730 | occlusion.occlusion_from_inside_target().ToString()); |
| 1731 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1732 | }; |
| 1733 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1734 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1735 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1736 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1737 | class OcclusionTrackerTestReplicaWithClipping |
| 1738 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1739 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1740 | explicit OcclusionTrackerTestReplicaWithClipping(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1741 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1742 | void RunMyTest() { |
| 1743 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1744 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 170)); |
| 1745 | parent->SetMasksToBounds(true); |
| 1746 | typename Types::LayerType* surface = |
| 1747 | this->CreateDrawingSurface(parent, |
| 1748 | this->identity_matrix, |
| 1749 | gfx::PointF(0.f, 100.f), |
| 1750 | gfx::Size(50, 50), |
| 1751 | true); |
| 1752 | this->CreateReplicaLayer( |
| 1753 | surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size()); |
| 1754 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1755 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1756 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1757 | typename Types::RenderSurfaceType> occlusion( |
| 1758 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1759 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1760 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1761 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1762 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), |
| 1763 | occlusion.occlusion_from_inside_target().ToString()); |
[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->VisitContributingSurface(surface, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1766 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1767 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1768 | // The surface and replica should both be occluding the parent. |
| 1769 | EXPECT_EQ( |
| 1770 | UnionRegions(gfx::Rect(0, 100, 50, 50), |
| 1771 | gfx::Rect(50, 150, 50, 20)).ToString(), |
| 1772 | occlusion.occlusion_from_inside_target().ToString()); |
| 1773 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1774 | }; |
| 1775 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1776 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1777 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1778 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1779 | class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1780 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1781 | explicit OcclusionTrackerTestReplicaWithMask(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1782 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1783 | void RunMyTest() { |
| 1784 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1785 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 1786 | typename Types::LayerType* surface = |
| 1787 | this->CreateDrawingSurface(parent, |
| 1788 | this->identity_matrix, |
| 1789 | gfx::PointF(0.f, 100.f), |
| 1790 | gfx::Size(50, 50), |
| 1791 | true); |
| 1792 | typename Types::LayerType* replica = this->CreateReplicaLayer( |
| 1793 | surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size()); |
| 1794 | this->CreateMaskLayer(replica, gfx::Size(10, 10)); |
| 1795 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1796 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1797 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1798 | typename Types::RenderSurfaceType> occlusion( |
| 1799 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1800 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1801 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1802 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1803 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), |
| 1804 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1805 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1806 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1807 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1808 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1809 | // The replica should not be occluding the parent, since it has a mask |
| 1810 | // applied to it. |
| 1811 | EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(), |
| 1812 | occlusion.occlusion_from_inside_target().ToString()); |
| 1813 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1814 | }; |
| 1815 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1816 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1817 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1818 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1819 | class OcclusionTrackerTestLayerClipRectOutsideChild |
| 1820 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1821 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1822 | explicit OcclusionTrackerTestLayerClipRectOutsideChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1823 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1824 | void RunMyTest() { |
| 1825 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1826 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1827 | typename Types::ContentLayerType* clip = |
| 1828 | this->CreateDrawingLayer(parent, |
| 1829 | this->identity_matrix, |
| 1830 | gfx::PointF(200.f, 100.f), |
| 1831 | gfx::Size(100, 100), |
| 1832 | false); |
| 1833 | clip->SetMasksToBounds(true); |
| 1834 | typename Types::ContentLayerType* layer = |
| 1835 | this->CreateDrawingLayer(clip, |
| 1836 | this->identity_matrix, |
| 1837 | gfx::PointF(-200.f, -100.f), |
| 1838 | gfx::Size(200, 200), |
| 1839 | false); |
| 1840 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1841 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1842 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1843 | typename Types::RenderSurfaceType> occlusion( |
| 1844 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1845 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1846 | this->EnterLayer(layer, &occlusion, false); |
[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_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 1849 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 1850 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 1851 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
| 1852 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(200, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1853 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1854 | this->LeaveLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1855 | this->EnterLayer(clip, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1856 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1857 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(-100, 0, 100, 100))); |
| 1858 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, -100, 100, 100))); |
| 1859 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 0, 100, 100))); |
| 1860 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 100, 100, 100))); |
| 1861 | EXPECT_FALSE(occlusion.OccludedLayer(clip, gfx::Rect(0, 0, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1862 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1863 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 1864 | occlusion.UnoccludedLayerContentRect( |
| 1865 | clip, gfx::Rect(-100, -100, 300, 300))); |
| 1866 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1867 | }; |
| 1868 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1869 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOutsideChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1870 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1871 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1872 | class OcclusionTrackerTestViewportRectOutsideChild |
| 1873 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1874 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1875 | explicit OcclusionTrackerTestViewportRectOutsideChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1876 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1877 | void RunMyTest() { |
| 1878 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1879 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1880 | typename Types::ContentLayerType* layer = |
| 1881 | this->CreateDrawingSurface(parent, |
| 1882 | this->identity_matrix, |
| 1883 | gfx::PointF(), |
| 1884 | gfx::Size(200, 200), |
| 1885 | true); |
| 1886 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1887 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1888 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1889 | typename Types::RenderSurfaceType> occlusion( |
| 1890 | gfx::Rect(200, 100, 100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1891 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1892 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1893 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1894 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 1895 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 1896 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 1897 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
| 1898 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(200, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1899 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1900 | this->LeaveLayer(layer, &occlusion); |
| 1901 | this->VisitContributingSurface(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1902 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1903 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1904 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100))); |
| 1905 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 1906 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100))); |
| 1907 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 1908 | EXPECT_FALSE( |
| 1909 | occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100))); |
| 1910 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100))); |
| 1911 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100))); |
| 1912 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100))); |
| 1913 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1914 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1915 | EXPECT_RECT_EQ(gfx::Rect(200, 100, 100, 100), |
| 1916 | occlusion.UnoccludedLayerContentRect( |
| 1917 | parent, gfx::Rect(0, 0, 300, 300))); |
| 1918 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1919 | }; |
| 1920 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1921 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOutsideChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1922 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1923 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1924 | class OcclusionTrackerTestLayerClipRectOverChild |
| 1925 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1926 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1927 | explicit OcclusionTrackerTestLayerClipRectOverChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1928 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1929 | void RunMyTest() { |
| 1930 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1931 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1932 | typename Types::ContentLayerType* clip = |
| 1933 | this->CreateDrawingLayer(parent, |
| 1934 | this->identity_matrix, |
| 1935 | gfx::PointF(100.f, 100.f), |
| 1936 | gfx::Size(100, 100), |
| 1937 | false); |
| 1938 | clip->SetMasksToBounds(true); |
| 1939 | typename Types::ContentLayerType* layer = |
| 1940 | this->CreateDrawingSurface(clip, |
| 1941 | this->identity_matrix, |
| 1942 | gfx::PointF(-100.f, -100.f), |
| 1943 | gfx::Size(200, 200), |
| 1944 | true); |
| 1945 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1946 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1947 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 1948 | typename Types::RenderSurfaceType> occlusion( |
| 1949 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1950 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1951 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1952 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1953 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 1954 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 1955 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 1956 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1957 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 1958 | this->LeaveLayer(layer, &occlusion); |
| 1959 | this->VisitContributingSurface(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1960 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1961 | EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), |
| 1962 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1963 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 1964 | this->EnterLayer(clip, &occlusion, false); |
[email protected] | c8d7155 | 2013-01-22 03:43:02 | [diff] [blame] | 1965 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1966 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 0, 100, 100))); |
| 1967 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 100, 100, 100))); |
| 1968 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 0, 100, 100))); |
| 1969 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 100, 100, 100))); |
| 1970 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(200, 100, 100, 100))); |
| 1971 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(200, 0, 100, 100))); |
| 1972 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 200, 100, 100))); |
| 1973 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 200, 100, 100))); |
| 1974 | EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(200, 200, 100, 100))); |
[email protected] | c8d7155 | 2013-01-22 03:43:02 | [diff] [blame] | 1975 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1976 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 1977 | clip, gfx::Rect(0, 0, 300, 300)).IsEmpty()); |
| 1978 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1979 | }; |
| 1980 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 1981 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOverChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1982 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1983 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1984 | class OcclusionTrackerTestViewportRectOverChild |
| 1985 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1986 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1987 | explicit OcclusionTrackerTestViewportRectOverChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 1988 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 1989 | void RunMyTest() { |
| 1990 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 1991 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 1992 | typename Types::ContentLayerType* layer = |
| 1993 | this->CreateDrawingSurface(parent, |
| 1994 | this->identity_matrix, |
| 1995 | gfx::PointF(), |
| 1996 | gfx::Size(200, 200), |
| 1997 | true); |
| 1998 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1999 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2000 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2001 | typename Types::RenderSurfaceType> occlusion( |
| 2002 | gfx::Rect(100, 100, 100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2003 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2004 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2005 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2006 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 2007 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 2008 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 2009 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2010 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2011 | this->LeaveLayer(layer, &occlusion); |
| 2012 | this->VisitContributingSurface(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2013 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2014 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2015 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100))); |
| 2016 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 2017 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100))); |
| 2018 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100))); |
| 2019 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100))); |
| 2020 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100))); |
| 2021 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100))); |
| 2022 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100))); |
| 2023 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2024 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2025 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 2026 | parent, gfx::Rect(0, 0, 300, 300)).IsEmpty()); |
| 2027 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2028 | }; |
| 2029 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2030 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2031 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2032 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2033 | class OcclusionTrackerTestLayerClipRectPartlyOverChild |
| 2034 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2035 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2036 | explicit OcclusionTrackerTestLayerClipRectPartlyOverChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2037 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2038 | void RunMyTest() { |
| 2039 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2040 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2041 | typename Types::ContentLayerType* clip = |
| 2042 | this->CreateDrawingLayer(parent, |
| 2043 | this->identity_matrix, |
| 2044 | gfx::PointF(50.f, 50.f), |
| 2045 | gfx::Size(200, 200), |
| 2046 | false); |
| 2047 | clip->SetMasksToBounds(true); |
| 2048 | typename Types::ContentLayerType* layer = |
| 2049 | this->CreateDrawingSurface(clip, |
| 2050 | this->identity_matrix, |
| 2051 | gfx::PointF(-50.f, -50.f), |
| 2052 | gfx::Size(200, 200), |
| 2053 | true); |
| 2054 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2055 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2056 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2057 | typename Types::RenderSurfaceType> occlusion( |
| 2058 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2059 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2060 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2061 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2062 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 2063 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 2064 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 2065 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2066 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2067 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 50))); |
| 2068 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 50, 100))); |
| 2069 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 50))); |
| 2070 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 50, 100))); |
[email protected] | c8d7155 | 2013-01-22 03:43:02 | [diff] [blame] | 2071 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2072 | this->LeaveLayer(layer, &occlusion); |
| 2073 | this->VisitContributingSurface(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2074 | this->EnterLayer(clip, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2075 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2076 | EXPECT_EQ(gfx::Rect(50, 50, 150, 150).ToString(), |
| 2077 | occlusion.occlusion_from_inside_target().ToString()); |
| 2078 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2079 | }; |
| 2080 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2081 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectPartlyOverChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2082 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2083 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2084 | class OcclusionTrackerTestViewportRectPartlyOverChild |
| 2085 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2086 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2087 | explicit OcclusionTrackerTestViewportRectPartlyOverChild(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2088 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2089 | void RunMyTest() { |
| 2090 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2091 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2092 | typename Types::ContentLayerType* layer = |
| 2093 | this->CreateDrawingSurface(parent, |
| 2094 | this->identity_matrix, |
| 2095 | gfx::PointF(), |
| 2096 | gfx::Size(200, 200), |
| 2097 | true); |
| 2098 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2099 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2100 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2101 | typename Types::RenderSurfaceType> occlusion( |
| 2102 | gfx::Rect(50, 50, 200, 200)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2103 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2104 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2105 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2106 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 2107 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 2108 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 2109 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2110 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2111 | this->LeaveLayer(layer, &occlusion); |
| 2112 | this->VisitContributingSurface(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2113 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2114 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2115 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100))); |
| 2116 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 2117 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100))); |
| 2118 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100))); |
| 2119 | EXPECT_FALSE( |
| 2120 | occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100))); |
| 2121 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100))); |
| 2122 | EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100))); |
| 2123 | EXPECT_FALSE( |
| 2124 | occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100))); |
| 2125 | EXPECT_FALSE( |
| 2126 | occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2127 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2128 | EXPECT_RECT_EQ(gfx::Rect(50, 50, 200, 200), |
| 2129 | occlusion.UnoccludedLayerContentRect( |
| 2130 | parent, gfx::Rect(0, 0, 300, 300))); |
| 2131 | EXPECT_RECT_EQ(gfx::Rect(200, 50, 50, 50), |
| 2132 | occlusion.UnoccludedLayerContentRect( |
| 2133 | parent, gfx::Rect(0, 0, 300, 100))); |
| 2134 | EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), |
| 2135 | occlusion.UnoccludedLayerContentRect( |
| 2136 | parent, gfx::Rect(0, 100, 300, 100))); |
| 2137 | EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100), |
| 2138 | occlusion.UnoccludedLayerContentRect( |
| 2139 | parent, gfx::Rect(200, 100, 100, 100))); |
| 2140 | EXPECT_RECT_EQ(gfx::Rect(100, 200, 100, 50), |
| 2141 | occlusion.UnoccludedLayerContentRect( |
| 2142 | parent, gfx::Rect(100, 200, 100, 100))); |
| 2143 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2144 | }; |
| 2145 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2146 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectPartlyOverChild); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2147 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2148 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2149 | class OcclusionTrackerTestViewportRectOverNothing |
| 2150 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2151 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2152 | explicit OcclusionTrackerTestViewportRectOverNothing(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2153 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2154 | void RunMyTest() { |
| 2155 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2156 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2157 | typename Types::ContentLayerType* layer = |
| 2158 | this->CreateDrawingSurface(parent, |
| 2159 | this->identity_matrix, |
| 2160 | gfx::PointF(), |
| 2161 | gfx::Size(200, 200), |
| 2162 | true); |
| 2163 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2164 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2165 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2166 | typename Types::RenderSurfaceType> occlusion( |
| 2167 | gfx::Rect(500, 500, 100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2168 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2169 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2170 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2171 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 2172 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 2173 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 2174 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2175 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2176 | this->LeaveLayer(layer, &occlusion); |
| 2177 | this->VisitContributingSurface(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2178 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2179 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2180 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100))); |
| 2181 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 2182 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100))); |
| 2183 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100))); |
| 2184 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100))); |
| 2185 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100))); |
| 2186 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100))); |
| 2187 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100))); |
| 2188 | EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2189 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2190 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 2191 | parent, gfx::Rect(0, 0, 300, 300)).IsEmpty()); |
| 2192 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 2193 | parent, gfx::Rect(0, 0, 300, 100)).IsEmpty()); |
| 2194 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 2195 | parent, gfx::Rect(0, 100, 300, 100)).IsEmpty()); |
| 2196 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 2197 | parent, gfx::Rect(200, 100, 100, 100)).IsEmpty()); |
| 2198 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 2199 | parent, gfx::Rect(100, 200, 100, 100)).IsEmpty()); |
| 2200 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2201 | }; |
| 2202 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2203 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverNothing); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2204 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2205 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2206 | class OcclusionTrackerTestLayerClipRectForLayerOffOrigin |
| 2207 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2208 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2209 | explicit OcclusionTrackerTestLayerClipRectForLayerOffOrigin( |
| 2210 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2211 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2212 | void RunMyTest() { |
| 2213 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2214 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2215 | typename Types::ContentLayerType* layer = |
| 2216 | this->CreateDrawingSurface(parent, |
| 2217 | this->identity_matrix, |
| 2218 | gfx::PointF(), |
| 2219 | gfx::Size(200, 200), |
| 2220 | true); |
| 2221 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2222 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2223 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2224 | typename Types::RenderSurfaceType> occlusion( |
| 2225 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2226 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2227 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2228 | // This layer is translated when drawn into its target. So if the clip rect |
| 2229 | // given from the target surface is not in that target space, then after |
| 2230 | // translating these query rects into the target, they will fall outside the |
| 2231 | // clip and be considered occluded. |
| 2232 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 2233 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 2234 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 2235 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
| 2236 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2237 | }; |
| 2238 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2239 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectForLayerOffOrigin); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2240 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2241 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2242 | class OcclusionTrackerTestOpaqueContentsRegionEmpty |
| 2243 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2244 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2245 | explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2246 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2247 | void RunMyTest() { |
| 2248 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2249 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2250 | typename Types::ContentLayerType* layer = |
| 2251 | this->CreateDrawingSurface(parent, |
| 2252 | this->identity_matrix, |
| 2253 | gfx::PointF(), |
| 2254 | gfx::Size(200, 200), |
| 2255 | false); |
| 2256 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2257 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2258 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2259 | typename Types::RenderSurfaceType> occlusion( |
| 2260 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2261 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2262 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2263 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100))); |
| 2264 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100))); |
| 2265 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100))); |
| 2266 | EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2267 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2268 | // Occluded since its outside the surface bounds. |
| 2269 | EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(200, 100, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2270 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2271 | this->LeaveLayer(layer, &occlusion); |
| 2272 | this->VisitContributingSurface(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2273 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2274 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2275 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 2276 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2277 | }; |
| 2278 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2279 | MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2280 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2281 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2282 | class OcclusionTrackerTestOpaqueContentsRegionNonEmpty |
| 2283 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2284 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2285 | explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2286 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2287 | void RunMyTest() { |
| 2288 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2289 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2290 | typename Types::ContentLayerType* layer = |
| 2291 | this->CreateDrawingLayer(parent, |
| 2292 | this->identity_matrix, |
| 2293 | gfx::PointF(100.f, 100.f), |
| 2294 | gfx::Size(200, 200), |
| 2295 | false); |
| 2296 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2297 | { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2298 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2299 | typename Types::RenderSurfaceType> occlusion( |
| 2300 | gfx::Rect(0, 0, 1000, 1000)); |
| 2301 | layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2302 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2303 | this->ResetLayerIterator(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2304 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2305 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2306 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2307 | EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), |
| 2308 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2309 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2310 | EXPECT_FALSE( |
| 2311 | occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 2312 | EXPECT_TRUE( |
| 2313 | occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100))); |
| 2314 | EXPECT_FALSE( |
| 2315 | occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2316 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2317 | { |
| 2318 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2319 | typename Types::RenderSurfaceType> occlusion( |
| 2320 | gfx::Rect(0, 0, 1000, 1000)); |
| 2321 | layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180)); |
| 2322 | |
| 2323 | this->ResetLayerIterator(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2324 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2325 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2326 | |
| 2327 | EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(), |
| 2328 | occlusion.occlusion_from_inside_target().ToString()); |
| 2329 | |
| 2330 | EXPECT_FALSE( |
| 2331 | occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 2332 | EXPECT_FALSE( |
| 2333 | occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100))); |
| 2334 | EXPECT_TRUE( |
| 2335 | occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
| 2336 | } |
| 2337 | { |
| 2338 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2339 | typename Types::RenderSurfaceType> occlusion( |
| 2340 | gfx::Rect(0, 0, 1000, 1000)); |
| 2341 | layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100)); |
| 2342 | |
| 2343 | this->ResetLayerIterator(); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2344 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2345 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2346 | |
| 2347 | EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(), |
| 2348 | occlusion.occlusion_from_inside_target().ToString()); |
| 2349 | |
| 2350 | EXPECT_FALSE( |
| 2351 | occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100))); |
| 2352 | EXPECT_FALSE( |
| 2353 | occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100))); |
| 2354 | EXPECT_FALSE( |
| 2355 | occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100))); |
| 2356 | } |
| 2357 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2358 | }; |
| 2359 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2360 | MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2361 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2362 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2363 | class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2364 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2365 | explicit OcclusionTrackerTest3dTransform(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2366 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2367 | void RunMyTest() { |
| 2368 | gfx::Transform transform; |
| 2369 | transform.RotateAboutYAxis(30.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2370 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2371 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2372 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2373 | typename Types::LayerType* container = this->CreateLayer( |
| 2374 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2375 | typename Types::ContentLayerType* layer = |
| 2376 | this->CreateDrawingLayer(container, |
| 2377 | transform, |
| 2378 | gfx::PointF(100.f, 100.f), |
| 2379 | gfx::Size(200, 200), |
| 2380 | true); |
| 2381 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2382 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2383 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2384 | typename Types::RenderSurfaceType> occlusion( |
| 2385 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2386 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2387 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2388 | // The layer is rotated in 3d but without preserving 3d, so it only gets |
| 2389 | // resized. |
| 2390 | EXPECT_RECT_EQ( |
| 2391 | gfx::Rect(0, 0, 200, 200), |
| 2392 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200))); |
| 2393 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2394 | }; |
| 2395 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2396 | MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2397 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2398 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2399 | class OcclusionTrackerTestUnsorted3dLayers |
| 2400 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2401 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2402 | explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2403 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2404 | void RunMyTest() { |
| 2405 | // Currently, The main thread layer iterator does not iterate over 3d items |
| 2406 | // in sorted order, because layer sorting is not performed on the main |
| 2407 | // thread. Because of this, the occlusion tracker cannot assume that a 3d |
| 2408 | // layer occludes other layers that have not yet been iterated over. For |
| 2409 | // now, the expected behavior is that a 3d layer simply does not add any |
| 2410 | // occlusion to the occlusion tracker. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2411 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2412 | gfx::Transform translation_to_front; |
| 2413 | translation_to_front.Translate3d(0.0, 0.0, -10.0); |
| 2414 | gfx::Transform translation_to_back; |
| 2415 | translation_to_front.Translate3d(0.0, 0.0, -100.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2416 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2417 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2418 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2419 | typename Types::ContentLayerType* child1 = this->CreateDrawingLayer( |
| 2420 | parent, translation_to_back, gfx::PointF(), gfx::Size(100, 100), true); |
| 2421 | typename Types::ContentLayerType* child2 = |
| 2422 | this->CreateDrawingLayer(parent, |
| 2423 | translation_to_front, |
| 2424 | gfx::PointF(50.f, 50.f), |
| 2425 | gfx::Size(100, 100), |
| 2426 | true); |
| 2427 | parent->SetPreserves3d(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2428 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2429 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2430 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2431 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2432 | typename Types::RenderSurfaceType> occlusion( |
| 2433 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2434 | this->VisitLayer(child2, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2435 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 2436 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2437 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2438 | this->VisitLayer(child1, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2439 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 2440 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
| 2441 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2442 | }; |
| 2443 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2444 | // This test will have different layer ordering on the impl thread; the test |
| 2445 | // will only work on the main thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2446 | MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2447 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2448 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2449 | class OcclusionTrackerTestPerspectiveTransform |
| 2450 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2451 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2452 | explicit OcclusionTrackerTestPerspectiveTransform(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2453 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2454 | void RunMyTest() { |
| 2455 | gfx::Transform transform; |
| 2456 | transform.Translate(150.0, 150.0); |
| 2457 | transform.ApplyPerspectiveDepth(400.0); |
| 2458 | transform.RotateAboutXAxis(-30.0); |
| 2459 | transform.Translate(-150.0, -150.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2460 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2461 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2462 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2463 | typename Types::LayerType* container = this->CreateLayer( |
| 2464 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2465 | typename Types::ContentLayerType* layer = |
| 2466 | this->CreateDrawingLayer(container, |
| 2467 | transform, |
| 2468 | gfx::PointF(100.f, 100.f), |
| 2469 | gfx::Size(200, 200), |
| 2470 | true); |
| 2471 | container->SetPreserves3d(true); |
| 2472 | layer->SetPreserves3d(true); |
| 2473 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2474 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2475 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2476 | typename Types::RenderSurfaceType> occlusion( |
| 2477 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2478 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2479 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2480 | EXPECT_RECT_EQ( |
| 2481 | gfx::Rect(0, 0, 200, 200), |
| 2482 | occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200))); |
| 2483 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2484 | }; |
| 2485 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2486 | // This test requires accumulating occlusion of 3d layers, which are skipped by |
| 2487 | // the occlusion tracker on the main thread. So this test should run on the impl |
| 2488 | // thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2489 | IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2490 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2491 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2492 | class OcclusionTrackerTestPerspectiveTransformBehindCamera |
| 2493 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2494 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2495 | explicit OcclusionTrackerTestPerspectiveTransformBehindCamera( |
| 2496 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2497 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2498 | void RunMyTest() { |
| 2499 | // This test is based on the platform/chromium/compositing/3d-corners.html |
| 2500 | // layout test. |
| 2501 | gfx::Transform transform; |
| 2502 | transform.Translate(250.0, 50.0); |
| 2503 | transform.ApplyPerspectiveDepth(10.0); |
| 2504 | transform.Translate(-250.0, -50.0); |
| 2505 | transform.Translate(250.0, 50.0); |
| 2506 | transform.RotateAboutXAxis(-167.0); |
| 2507 | transform.Translate(-250.0, -50.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2508 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2509 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2510 | this->identity_matrix, gfx::PointF(), gfx::Size(500, 100)); |
| 2511 | typename Types::LayerType* container = this->CreateLayer( |
| 2512 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500)); |
| 2513 | typename Types::ContentLayerType* layer = this->CreateDrawingLayer( |
| 2514 | container, transform, gfx::PointF(), gfx::Size(500, 500), true); |
| 2515 | container->SetPreserves3d(true); |
| 2516 | layer->SetPreserves3d(true); |
| 2517 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2518 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2519 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2520 | typename Types::RenderSurfaceType> occlusion( |
| 2521 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2522 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2523 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2524 | // The bottom 11 pixel rows of this layer remain visible inside the |
| 2525 | // container, after translation to the target surface. When translated back, |
| 2526 | // this will include many more pixels but must include at least the bottom |
| 2527 | // 11 rows. |
| 2528 | EXPECT_TRUE(occlusion.UnoccludedLayerContentRect( |
| 2529 | layer, gfx::Rect(0, 0, 500, 500)).Contains(gfx::Rect(0, 489, 500, 11))); |
| 2530 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2531 | }; |
| 2532 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2533 | // This test requires accumulating occlusion of 3d layers, which are skipped by |
| 2534 | // the occlusion tracker on the main thread. So this test should run on the impl |
| 2535 | // thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2536 | IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransformBehindCamera); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2537 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2538 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2539 | class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude |
| 2540 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2541 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2542 | explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude( |
| 2543 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2544 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2545 | void RunMyTest() { |
| 2546 | gfx::Transform transform; |
| 2547 | transform.Translate(50.0, 50.0); |
| 2548 | transform.ApplyPerspectiveDepth(100.0); |
| 2549 | transform.Translate3d(0.0, 0.0, 110.0); |
| 2550 | transform.Translate(-50.0, -50.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2551 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2552 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2553 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 2554 | typename Types::ContentLayerType* layer = this->CreateDrawingLayer( |
| 2555 | parent, transform, gfx::PointF(), gfx::Size(100, 100), true); |
| 2556 | parent->SetPreserves3d(true); |
| 2557 | layer->SetPreserves3d(true); |
| 2558 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2559 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2560 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2561 | typename Types::RenderSurfaceType> occlusion( |
| 2562 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2563 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2564 | // The |layer| is entirely behind the camera and should not occlude. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2565 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2566 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2567 | EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
| 2568 | EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 2569 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2570 | }; |
| 2571 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2572 | // This test requires accumulating occlusion of 3d layers, which are skipped by |
| 2573 | // the occlusion tracker on the main thread. So this test should run on the impl |
| 2574 | // thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2575 | IMPL_THREAD_TEST(OcclusionTrackerTestLayerBehindCameraDoesNotOcclude); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2576 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2577 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2578 | class OcclusionTrackerTestLargePixelsOccludeInsideClipRect |
| 2579 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2580 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2581 | explicit OcclusionTrackerTestLargePixelsOccludeInsideClipRect( |
| 2582 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2583 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2584 | void RunMyTest() { |
| 2585 | gfx::Transform transform; |
| 2586 | transform.Translate(50.0, 50.0); |
| 2587 | transform.ApplyPerspectiveDepth(100.0); |
| 2588 | transform.Translate3d(0.0, 0.0, 99.0); |
| 2589 | transform.Translate(-50.0, -50.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2590 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2591 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2592 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 2593 | parent->SetMasksToBounds(true); |
| 2594 | typename Types::ContentLayerType* layer = this->CreateDrawingLayer( |
| 2595 | parent, transform, gfx::PointF(), gfx::Size(100, 100), true); |
| 2596 | parent->SetPreserves3d(true); |
| 2597 | layer->SetPreserves3d(true); |
| 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] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2604 | // This is very close to the camera, so pixels in its visible_content_rect() |
| 2605 | // will actually go outside of the layer's clip rect. Ensure that those |
| 2606 | // pixels don't occlude things outside the clip rect. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2607 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2608 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2609 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 2610 | occlusion.occlusion_from_inside_target().ToString()); |
| 2611 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2612 | occlusion.occlusion_from_outside_target().ToString()); |
| 2613 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2614 | }; |
| 2615 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2616 | // This test requires accumulating occlusion of 3d layers, which are skipped by |
| 2617 | // the occlusion tracker on the main thread. So this test should run on the impl |
| 2618 | // thread. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2619 | IMPL_THREAD_TEST(OcclusionTrackerTestLargePixelsOccludeInsideClipRect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2620 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2621 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2622 | class OcclusionTrackerTestAnimationOpacity1OnMainThread |
| 2623 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2624 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2625 | explicit OcclusionTrackerTestAnimationOpacity1OnMainThread(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2626 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2627 | void RunMyTest() { |
| 2628 | // parent |
| 2629 | // +--layer |
| 2630 | // +--surface |
| 2631 | // | +--surface_child |
| 2632 | // | +--surface_child2 |
| 2633 | // +--parent2 |
| 2634 | // +--topmost |
[email protected] | c8d7155 | 2013-01-22 03:43:02 | [diff] [blame] | 2635 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2636 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2637 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2638 | typename Types::ContentLayerType* layer = |
| 2639 | this->CreateDrawingLayer(parent, |
| 2640 | this->identity_matrix, |
| 2641 | gfx::PointF(), |
| 2642 | gfx::Size(300, 300), |
| 2643 | true); |
| 2644 | typename Types::ContentLayerType* surface = |
| 2645 | this->CreateDrawingSurface(parent, |
| 2646 | this->identity_matrix, |
| 2647 | gfx::PointF(), |
| 2648 | gfx::Size(300, 300), |
| 2649 | true); |
| 2650 | typename Types::ContentLayerType* surface_child = |
| 2651 | this->CreateDrawingLayer(surface, |
| 2652 | this->identity_matrix, |
| 2653 | gfx::PointF(), |
| 2654 | gfx::Size(200, 300), |
| 2655 | true); |
| 2656 | typename Types::ContentLayerType* surface_child2 = |
| 2657 | this->CreateDrawingLayer(surface, |
| 2658 | this->identity_matrix, |
| 2659 | gfx::PointF(), |
| 2660 | gfx::Size(100, 300), |
| 2661 | true); |
| 2662 | typename Types::ContentLayerType* parent2 = |
| 2663 | this->CreateDrawingLayer(parent, |
| 2664 | this->identity_matrix, |
| 2665 | gfx::PointF(), |
| 2666 | gfx::Size(300, 300), |
| 2667 | false); |
| 2668 | typename Types::ContentLayerType* topmost = |
| 2669 | this->CreateDrawingLayer(parent, |
| 2670 | this->identity_matrix, |
| 2671 | gfx::PointF(250.f, 0.f), |
| 2672 | gfx::Size(50, 300), |
| 2673 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2674 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2675 | AddOpacityTransitionToController( |
| 2676 | layer->layer_animation_controller(), 10.0, 0.f, 1.f, false); |
| 2677 | AddOpacityTransitionToController( |
| 2678 | surface->layer_animation_controller(), 10.0, 0.f, 1.f, false); |
| 2679 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2680 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2681 | EXPECT_TRUE(layer->draw_opacity_is_animating()); |
| 2682 | EXPECT_FALSE(surface->draw_opacity_is_animating()); |
| 2683 | EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2684 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2685 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2686 | typename Types::RenderSurfaceType> occlusion( |
| 2687 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2688 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2689 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2690 | this->EnterLayer(parent2, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2691 | // This occlusion will affect all surfaces. |
| 2692 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2693 | occlusion.occlusion_from_inside_target().ToString()); |
| 2694 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2695 | occlusion.occlusion_from_outside_target().ToString()); |
| 2696 | EXPECT_EQ(gfx::Rect(0, 0, 250, 300).ToString(), |
| 2697 | occlusion.UnoccludedLayerContentRect( |
| 2698 | parent2, gfx::Rect(0, 0, 300, 300)).ToString()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2699 | this->LeaveLayer(parent2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2700 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2701 | this->VisitLayer(surface_child2, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2702 | this->EnterLayer(surface_child, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2703 | EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), |
| 2704 | occlusion.occlusion_from_inside_target().ToString()); |
| 2705 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2706 | occlusion.occlusion_from_outside_target().ToString()); |
| 2707 | EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300), |
| 2708 | occlusion.UnoccludedLayerContentRect( |
| 2709 | surface_child, gfx::Rect(0, 0, 200, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2710 | this->LeaveLayer(surface_child, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2711 | this->EnterLayer(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2712 | EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(), |
| 2713 | occlusion.occlusion_from_inside_target().ToString()); |
| 2714 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2715 | occlusion.occlusion_from_outside_target().ToString()); |
| 2716 | EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300), |
| 2717 | occlusion.UnoccludedLayerContentRect( |
| 2718 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2719 | this->LeaveLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2720 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2721 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2722 | // Occlusion within the surface is lost when leaving the animating surface. |
| 2723 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2724 | occlusion.occlusion_from_inside_target().ToString()); |
| 2725 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2726 | occlusion.occlusion_from_outside_target().ToString()); |
| 2727 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2728 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 2729 | surface, false, gfx::Rect(0, 0, 300, 300), NULL)); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2730 | this->LeaveContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2731 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2732 | // Occlusion from outside the animating surface still exists. |
| 2733 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2734 | occlusion.occlusion_from_inside_target().ToString()); |
| 2735 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2736 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | c8d7155 | 2013-01-22 03:43:02 | [diff] [blame] | 2737 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2738 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2739 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2740 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2741 | // Occlusion is not added for the animating |layer|. |
| 2742 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2743 | occlusion.UnoccludedLayerContentRect( |
| 2744 | parent, gfx::Rect(0, 0, 300, 300))); |
| 2745 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2746 | }; |
| 2747 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2748 | MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2749 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2750 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2751 | class OcclusionTrackerTestAnimationOpacity0OnMainThread |
| 2752 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2753 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2754 | explicit OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2755 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2756 | void RunMyTest() { |
| 2757 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2758 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2759 | typename Types::ContentLayerType* layer = |
| 2760 | this->CreateDrawingLayer(parent, |
| 2761 | this->identity_matrix, |
| 2762 | gfx::PointF(), |
| 2763 | gfx::Size(300, 300), |
| 2764 | true); |
| 2765 | typename Types::ContentLayerType* surface = |
| 2766 | this->CreateDrawingSurface(parent, |
| 2767 | this->identity_matrix, |
| 2768 | gfx::PointF(), |
| 2769 | gfx::Size(300, 300), |
| 2770 | true); |
| 2771 | typename Types::ContentLayerType* surface_child = |
| 2772 | this->CreateDrawingLayer(surface, |
| 2773 | this->identity_matrix, |
| 2774 | gfx::PointF(), |
| 2775 | gfx::Size(200, 300), |
| 2776 | true); |
| 2777 | typename Types::ContentLayerType* surface_child2 = |
| 2778 | this->CreateDrawingLayer(surface, |
| 2779 | this->identity_matrix, |
| 2780 | gfx::PointF(), |
| 2781 | gfx::Size(100, 300), |
| 2782 | true); |
| 2783 | typename Types::ContentLayerType* parent2 = |
| 2784 | this->CreateDrawingLayer(parent, |
| 2785 | this->identity_matrix, |
| 2786 | gfx::PointF(), |
| 2787 | gfx::Size(300, 300), |
| 2788 | false); |
| 2789 | typename Types::ContentLayerType* topmost = |
| 2790 | this->CreateDrawingLayer(parent, |
| 2791 | this->identity_matrix, |
| 2792 | gfx::PointF(250.f, 0.f), |
| 2793 | gfx::Size(50, 300), |
| 2794 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2795 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2796 | AddOpacityTransitionToController( |
| 2797 | layer->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2798 | AddOpacityTransitionToController( |
| 2799 | surface->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2800 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2801 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2802 | EXPECT_TRUE(layer->draw_opacity_is_animating()); |
| 2803 | EXPECT_FALSE(surface->draw_opacity_is_animating()); |
| 2804 | EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2805 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2806 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2807 | typename Types::RenderSurfaceType> occlusion( |
| 2808 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2809 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2810 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2811 | this->EnterLayer(parent2, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2812 | // This occlusion will affect all surfaces. |
| 2813 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2814 | occlusion.occlusion_from_inside_target().ToString()); |
| 2815 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2816 | occlusion.occlusion_from_outside_target().ToString()); |
| 2817 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2818 | occlusion.UnoccludedLayerContentRect( |
| 2819 | parent, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2820 | this->LeaveLayer(parent2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2821 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2822 | this->VisitLayer(surface_child2, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2823 | this->EnterLayer(surface_child, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2824 | EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), |
| 2825 | occlusion.occlusion_from_inside_target().ToString()); |
| 2826 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2827 | occlusion.occlusion_from_outside_target().ToString()); |
| 2828 | EXPECT_RECT_EQ(gfx::Rect(100, 0, 100, 300), |
| 2829 | occlusion.UnoccludedLayerContentRect( |
| 2830 | surface_child, gfx::Rect(0, 0, 200, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2831 | this->LeaveLayer(surface_child, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2832 | this->EnterLayer(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2833 | EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(), |
| 2834 | occlusion.occlusion_from_inside_target().ToString()); |
| 2835 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2836 | occlusion.occlusion_from_outside_target().ToString()); |
| 2837 | EXPECT_RECT_EQ(gfx::Rect(200, 0, 50, 300), |
| 2838 | occlusion.UnoccludedLayerContentRect( |
| 2839 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2840 | this->LeaveLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2841 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2842 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2843 | // Occlusion within the surface is lost when leaving the animating surface. |
| 2844 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2845 | occlusion.occlusion_from_inside_target().ToString()); |
| 2846 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2847 | occlusion.occlusion_from_outside_target().ToString()); |
| 2848 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2849 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 2850 | surface, false, gfx::Rect(0, 0, 300, 300), NULL)); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2851 | this->LeaveContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2852 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2853 | // Occlusion from outside the animating surface still exists. |
| 2854 | EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), |
| 2855 | occlusion.occlusion_from_inside_target().ToString()); |
| 2856 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2857 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | c8d7155 | 2013-01-22 03:43:02 | [diff] [blame] | 2858 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2859 | this->VisitLayer(layer, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2860 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2861 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2862 | // Occlusion is not added for the animating |layer|. |
| 2863 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 250, 300), |
| 2864 | occlusion.UnoccludedLayerContentRect( |
| 2865 | parent, gfx::Rect(0, 0, 300, 300))); |
| 2866 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2867 | }; |
| 2868 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 2869 | MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2870 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2871 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2872 | class OcclusionTrackerTestAnimationTranslateOnMainThread |
| 2873 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2874 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 2875 | explicit OcclusionTrackerTestAnimationTranslateOnMainThread( |
| 2876 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2877 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2878 | void RunMyTest() { |
| 2879 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2880 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 2881 | typename Types::ContentLayerType* layer = |
| 2882 | this->CreateDrawingLayer(parent, |
| 2883 | this->identity_matrix, |
| 2884 | gfx::PointF(), |
| 2885 | gfx::Size(300, 300), |
| 2886 | true); |
| 2887 | typename Types::ContentLayerType* surface = |
| 2888 | this->CreateDrawingSurface(parent, |
| 2889 | this->identity_matrix, |
| 2890 | gfx::PointF(), |
| 2891 | gfx::Size(300, 300), |
| 2892 | true); |
| 2893 | typename Types::ContentLayerType* surface_child = |
| 2894 | this->CreateDrawingLayer(surface, |
| 2895 | this->identity_matrix, |
| 2896 | gfx::PointF(), |
| 2897 | gfx::Size(200, 300), |
| 2898 | true); |
| 2899 | typename Types::ContentLayerType* surface_child2 = |
| 2900 | this->CreateDrawingLayer(surface, |
| 2901 | this->identity_matrix, |
| 2902 | gfx::PointF(), |
| 2903 | gfx::Size(100, 300), |
| 2904 | true); |
| 2905 | typename Types::ContentLayerType* surface2 = this->CreateDrawingSurface( |
| 2906 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 300), true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2907 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2908 | AddAnimatedTransformToController( |
| 2909 | layer->layer_animation_controller(), 10.0, 30, 0); |
| 2910 | AddAnimatedTransformToController( |
| 2911 | surface->layer_animation_controller(), 10.0, 30, 0); |
| 2912 | AddAnimatedTransformToController( |
| 2913 | surface_child->layer_animation_controller(), 10.0, 30, 0); |
| 2914 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2915 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2916 | EXPECT_TRUE(layer->draw_transform_is_animating()); |
| 2917 | EXPECT_TRUE(layer->screen_space_transform_is_animating()); |
| 2918 | EXPECT_TRUE( |
| 2919 | surface->render_surface()->target_surface_transforms_are_animating()); |
| 2920 | EXPECT_TRUE( |
| 2921 | surface->render_surface()->screen_space_transforms_are_animating()); |
| 2922 | // The surface owning layer doesn't animate against its own surface. |
| 2923 | EXPECT_FALSE(surface->draw_transform_is_animating()); |
| 2924 | EXPECT_TRUE(surface->screen_space_transform_is_animating()); |
| 2925 | EXPECT_TRUE(surface_child->draw_transform_is_animating()); |
| 2926 | EXPECT_TRUE(surface_child->screen_space_transform_is_animating()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2927 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2928 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 2929 | typename Types::RenderSurfaceType> occlusion( |
| 2930 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2931 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2932 | this->VisitLayer(surface2, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2933 | this->EnterContributingSurface(surface2, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2934 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2935 | EXPECT_EQ(gfx::Rect(0, 0, 50, 300).ToString(), |
| 2936 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2937 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2938 | this->LeaveContributingSurface(surface2, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2939 | this->EnterLayer(surface_child2, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2940 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2941 | // surface_child2 is moving in screen space but not relative to its target, |
| 2942 | // so occlusion should happen in its target space only. It also means that |
| 2943 | // things occluding from outside the target (e.g. surface2) cannot occlude |
| 2944 | // this layer. |
| 2945 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2946 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | ccb1c9a | 2012-12-17 03:53:19 | [diff] [blame] | 2947 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2948 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 300), |
| 2949 | occlusion.UnoccludedLayerContentRect( |
| 2950 | surface_child2, gfx::Rect(0, 0, 100, 300))); |
| 2951 | EXPECT_FALSE( |
| 2952 | occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 50, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2953 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2954 | this->LeaveLayer(surface_child2, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2955 | this->EnterLayer(surface_child, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2956 | EXPECT_FALSE( |
| 2957 | occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 100, 300))); |
| 2958 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2959 | occlusion.occlusion_from_outside_target().ToString()); |
| 2960 | EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), |
| 2961 | occlusion.occlusion_from_inside_target().ToString()); |
| 2962 | EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300), |
| 2963 | occlusion.UnoccludedLayerContentRect( |
| 2964 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2965 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2966 | // The surface_child is occluded by the surface_child2, but is moving |
| 2967 | // relative its target, so it can't be occluded. |
| 2968 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 300), |
| 2969 | occlusion.UnoccludedLayerContentRect( |
| 2970 | surface_child, gfx::Rect(0, 0, 200, 300))); |
| 2971 | EXPECT_FALSE( |
| 2972 | occlusion.OccludedLayer(surface_child, gfx::Rect(0, 0, 50, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2973 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2974 | this->LeaveLayer(surface_child, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2975 | this->EnterLayer(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2976 | // The surface_child is moving in screen space but not relative to its |
| 2977 | // target, so occlusion should happen from within the target only. |
| 2978 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2979 | occlusion.occlusion_from_outside_target().ToString()); |
| 2980 | EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), |
| 2981 | occlusion.occlusion_from_inside_target().ToString()); |
| 2982 | EXPECT_RECT_EQ(gfx::Rect(100, 0, 200, 300), |
| 2983 | occlusion.UnoccludedLayerContentRect( |
| 2984 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2985 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 2986 | this->LeaveLayer(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2987 | // The surface's owning layer is moving in screen space but not relative to |
| 2988 | // its target, so occlusion should happen within the target only. |
| 2989 | EXPECT_EQ(gfx::Rect().ToString(), |
| 2990 | occlusion.occlusion_from_outside_target().ToString()); |
| 2991 | EXPECT_EQ(gfx::Rect(0, 0, 300, 300).ToString(), |
| 2992 | occlusion.occlusion_from_inside_target().ToString()); |
| 2993 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 2994 | occlusion.UnoccludedLayerContentRect( |
| 2995 | surface, gfx::Rect(0, 0, 300, 300))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2996 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 2997 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 2998 | // The contributing |surface| is animating so it can't be occluded. |
| 2999 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 300, 300), |
| 3000 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3001 | surface, false, gfx::Rect(0, 0, 300, 300), NULL)); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3002 | this->LeaveContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3003 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3004 | this->EnterLayer(layer, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3005 | // The |surface| is moving in the screen and in its target, so all occlusion |
| 3006 | // within the surface is lost when leaving it. |
| 3007 | EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300), |
| 3008 | occlusion.UnoccludedLayerContentRect( |
| 3009 | parent, gfx::Rect(0, 0, 300, 300))); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3010 | this->LeaveLayer(layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3011 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3012 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3013 | // The |layer| is animating in the screen and in its target, so no occlusion |
| 3014 | // is added. |
| 3015 | EXPECT_RECT_EQ(gfx::Rect(50, 0, 250, 300), |
| 3016 | occlusion.UnoccludedLayerContentRect( |
| 3017 | parent, gfx::Rect(0, 0, 300, 300))); |
| 3018 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3019 | }; |
| 3020 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3021 | MAIN_THREAD_TEST(OcclusionTrackerTestAnimationTranslateOnMainThread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3022 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3023 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3024 | class OcclusionTrackerTestSurfaceOcclusionTranslatesToParent |
| 3025 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3026 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3027 | explicit OcclusionTrackerTestSurfaceOcclusionTranslatesToParent( |
| 3028 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3029 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3030 | void RunMyTest() { |
| 3031 | gfx::Transform surface_transform; |
| 3032 | surface_transform.Translate(300.0, 300.0); |
| 3033 | surface_transform.Scale(2.0, 2.0); |
| 3034 | surface_transform.Translate(-150.0, -150.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3035 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3036 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3037 | this->identity_matrix, gfx::PointF(), gfx::Size(500, 500)); |
| 3038 | typename Types::ContentLayerType* surface = this->CreateDrawingSurface( |
| 3039 | parent, surface_transform, gfx::PointF(), gfx::Size(300, 300), false); |
| 3040 | typename Types::ContentLayerType* surface2 = |
| 3041 | this->CreateDrawingSurface(parent, |
| 3042 | this->identity_matrix, |
| 3043 | gfx::PointF(50.f, 50.f), |
| 3044 | gfx::Size(300, 300), |
| 3045 | false); |
| 3046 | surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200)); |
| 3047 | surface2->SetOpaqueContentsRect(gfx::Rect(0, 0, 200, 200)); |
| 3048 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3049 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3050 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3051 | typename Types::RenderSurfaceType> occlusion( |
| 3052 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3053 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3054 | this->VisitLayer(surface2, &occlusion); |
| 3055 | this->VisitContributingSurface(surface2, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3056 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3057 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3058 | occlusion.occlusion_from_outside_target().ToString()); |
| 3059 | EXPECT_EQ(gfx::Rect(50, 50, 200, 200).ToString(), |
| 3060 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3061 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3062 | // Clear any stored occlusion. |
| 3063 | occlusion.set_occlusion_from_outside_target(Region()); |
| 3064 | occlusion.set_occlusion_from_inside_target(Region()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3065 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3066 | this->VisitLayer(surface, &occlusion); |
| 3067 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3068 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3069 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3070 | occlusion.occlusion_from_outside_target().ToString()); |
| 3071 | EXPECT_EQ(gfx::Rect(0, 0, 400, 400).ToString(), |
| 3072 | occlusion.occlusion_from_inside_target().ToString()); |
| 3073 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3074 | }; |
| 3075 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3076 | MAIN_AND_IMPL_THREAD_TEST( |
| 3077 | OcclusionTrackerTestSurfaceOcclusionTranslatesToParent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3078 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3079 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3080 | class OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping |
| 3081 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3082 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3083 | explicit OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping( |
| 3084 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3085 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3086 | void RunMyTest() { |
| 3087 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3088 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 300)); |
| 3089 | parent->SetMasksToBounds(true); |
| 3090 | typename Types::ContentLayerType* surface = |
| 3091 | this->CreateDrawingSurface(parent, |
| 3092 | this->identity_matrix, |
| 3093 | gfx::PointF(), |
| 3094 | gfx::Size(500, 300), |
| 3095 | false); |
| 3096 | surface->SetOpaqueContentsRect(gfx::Rect(0, 0, 400, 200)); |
| 3097 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3098 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3099 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3100 | typename Types::RenderSurfaceType> occlusion( |
| 3101 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3102 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3103 | this->VisitLayer(surface, &occlusion); |
| 3104 | this->VisitContributingSurface(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3105 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3106 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3107 | occlusion.occlusion_from_outside_target().ToString()); |
| 3108 | EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(), |
| 3109 | occlusion.occlusion_from_inside_target().ToString()); |
| 3110 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3111 | }; |
| 3112 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3113 | MAIN_AND_IMPL_THREAD_TEST( |
| 3114 | OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3115 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3116 | template <class Types> |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3117 | class OcclusionTrackerTestReplicaOccluded : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3118 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3119 | explicit OcclusionTrackerTestReplicaOccluded(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3120 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3121 | void RunMyTest() { |
| 3122 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3123 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 3124 | typename Types::LayerType* surface = |
| 3125 | this->CreateDrawingSurface(parent, |
| 3126 | this->identity_matrix, |
| 3127 | gfx::PointF(), |
| 3128 | gfx::Size(100, 100), |
| 3129 | true); |
| 3130 | this->CreateReplicaLayer(surface, |
| 3131 | this->identity_matrix, |
| 3132 | gfx::PointF(0.f, 100.f), |
| 3133 | gfx::Size(100, 100)); |
| 3134 | typename Types::LayerType* topmost = |
| 3135 | this->CreateDrawingLayer(parent, |
| 3136 | this->identity_matrix, |
| 3137 | gfx::PointF(0.f, 100.f), |
| 3138 | gfx::Size(100, 100), |
| 3139 | true); |
| 3140 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3141 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3142 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3143 | typename Types::RenderSurfaceType> occlusion( |
| 3144 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3145 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3146 | // |topmost| occludes the replica, but not the surface itself. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3147 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3148 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3149 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3150 | occlusion.occlusion_from_outside_target().ToString()); |
| 3151 | EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(), |
| 3152 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3153 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3154 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3155 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3156 | EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(), |
| 3157 | occlusion.occlusion_from_outside_target().ToString()); |
| 3158 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 3159 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3160 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3161 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3162 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3163 | // Surface is not occluded so it shouldn't think it is. |
| 3164 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3165 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3166 | surface, false, gfx::Rect(0, 0, 100, 100), NULL)); |
| 3167 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3168 | }; |
| 3169 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3170 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaOccluded); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3171 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3172 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3173 | class OcclusionTrackerTestSurfaceWithReplicaUnoccluded |
| 3174 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3175 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3176 | explicit OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3177 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3178 | void RunMyTest() { |
| 3179 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3180 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 3181 | typename Types::LayerType* surface = |
| 3182 | this->CreateDrawingSurface(parent, |
| 3183 | this->identity_matrix, |
| 3184 | gfx::PointF(), |
| 3185 | gfx::Size(100, 100), |
| 3186 | true); |
| 3187 | this->CreateReplicaLayer(surface, |
| 3188 | this->identity_matrix, |
| 3189 | gfx::PointF(0.f, 100.f), |
| 3190 | gfx::Size(100, 100)); |
| 3191 | typename Types::LayerType* topmost = |
| 3192 | this->CreateDrawingLayer(parent, |
| 3193 | this->identity_matrix, |
| 3194 | gfx::PointF(), |
| 3195 | gfx::Size(100, 110), |
| 3196 | true); |
| 3197 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3198 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3199 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3200 | typename Types::RenderSurfaceType> occlusion( |
| 3201 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3202 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3203 | // |topmost| occludes the surface, but not the entire surface's replica. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3204 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3205 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3206 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3207 | occlusion.occlusion_from_outside_target().ToString()); |
| 3208 | EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(), |
| 3209 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3210 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3211 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3212 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3213 | EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(), |
| 3214 | occlusion.occlusion_from_outside_target().ToString()); |
| 3215 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 3216 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3217 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3218 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3219 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3220 | // Surface is occluded, but only the top 10px of the replica. |
| 3221 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3222 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3223 | surface, false, gfx::Rect(0, 0, 100, 100), NULL)); |
| 3224 | EXPECT_RECT_EQ(gfx::Rect(0, 10, 100, 90), |
| 3225 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3226 | surface, true, gfx::Rect(0, 0, 100, 100), NULL)); |
| 3227 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3228 | }; |
| 3229 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3230 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded); |
[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 OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently |
| 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 OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently( |
| 3237 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3238 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3239 | void RunMyTest() { |
| 3240 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3241 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 3242 | typename Types::LayerType* surface = |
| 3243 | this->CreateDrawingSurface(parent, |
| 3244 | this->identity_matrix, |
| 3245 | gfx::PointF(), |
| 3246 | gfx::Size(100, 100), |
| 3247 | true); |
| 3248 | this->CreateReplicaLayer(surface, |
| 3249 | this->identity_matrix, |
| 3250 | gfx::PointF(0.f, 100.f), |
| 3251 | gfx::Size(100, 100)); |
| 3252 | typename Types::LayerType* over_surface = this->CreateDrawingLayer( |
| 3253 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(40, 100), true); |
| 3254 | typename Types::LayerType* over_replica = |
| 3255 | this->CreateDrawingLayer(parent, |
| 3256 | this->identity_matrix, |
| 3257 | gfx::PointF(0.f, 100.f), |
| 3258 | gfx::Size(50, 100), |
| 3259 | true); |
| 3260 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3261 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3262 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3263 | typename Types::RenderSurfaceType> occlusion( |
| 3264 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3265 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3266 | // These occlude the surface and replica differently, so we can test each |
| 3267 | // one. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3268 | this->VisitLayer(over_replica, &occlusion); |
| 3269 | this->VisitLayer(over_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3270 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3271 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3272 | occlusion.occlusion_from_outside_target().ToString()); |
| 3273 | EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 40, 100), gfx::Rect(0, 100, 50, 100)) |
| 3274 | .ToString(), |
| 3275 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3276 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3277 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3278 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3279 | EXPECT_EQ(UnionRegions(gfx::Rect(0, 0, 40, 100), gfx::Rect(0, 100, 50, 100)) |
| 3280 | .ToString(), |
| 3281 | occlusion.occlusion_from_outside_target().ToString()); |
| 3282 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 3283 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3284 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3285 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3286 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3287 | // Surface and replica are occluded different amounts. |
| 3288 | EXPECT_RECT_EQ(gfx::Rect(40, 0, 60, 100), |
| 3289 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3290 | surface, false, gfx::Rect(0, 0, 100, 100), NULL)); |
| 3291 | EXPECT_RECT_EQ(gfx::Rect(50, 0, 50, 100), |
| 3292 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3293 | surface, true, gfx::Rect(0, 0, 100, 100), NULL)); |
| 3294 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3295 | }; |
| 3296 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3297 | ALL_OCCLUSIONTRACKER_TEST( |
| 3298 | OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3299 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3300 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3301 | class OcclusionTrackerTestSurfaceChildOfSurface |
| 3302 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3303 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3304 | explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3305 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3306 | void RunMyTest() { |
| 3307 | // This test verifies that the surface cliprect does not end up empty and |
| 3308 | // clip away the entire unoccluded rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3309 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3310 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3311 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 3312 | typename Types::LayerType* surface = |
| 3313 | this->CreateDrawingSurface(parent, |
| 3314 | this->identity_matrix, |
| 3315 | gfx::PointF(), |
| 3316 | gfx::Size(100, 100), |
| 3317 | true); |
| 3318 | typename Types::LayerType* surface_child = |
| 3319 | this->CreateDrawingSurface(surface, |
| 3320 | this->identity_matrix, |
| 3321 | gfx::PointF(0.f, 10.f), |
| 3322 | gfx::Size(100, 50), |
| 3323 | true); |
| 3324 | typename Types::LayerType* topmost = this->CreateDrawingLayer( |
| 3325 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true); |
| 3326 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3327 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3328 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3329 | typename Types::RenderSurfaceType> occlusion( |
| 3330 | gfx::Rect(-100, -100, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3331 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3332 | // |topmost| occludes everything partially so we know occlusion is happening |
| 3333 | // at all. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3334 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3335 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3336 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3337 | occlusion.occlusion_from_outside_target().ToString()); |
| 3338 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 3339 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3340 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3341 | this->VisitLayer(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3342 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3343 | // surface_child increases the occlusion in the screen by a narrow sliver. |
| 3344 | EXPECT_EQ(gfx::Rect(0, -10, 100, 50).ToString(), |
| 3345 | occlusion.occlusion_from_outside_target().ToString()); |
| 3346 | // In its own surface, surface_child is at 0,0 as is its occlusion. |
| 3347 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 3348 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3349 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3350 | // The root layer always has a clip rect. So the parent of |surface| has a |
| 3351 | // clip rect. However, the owning layer for |surface| does not mask to |
| 3352 | // bounds, so it doesn't have a clip rect of its own. Thus the parent of |
| 3353 | // |surface_child| exercises different code paths as its parent does not |
| 3354 | // have a clip rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3355 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3356 | this->EnterContributingSurface(surface_child, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3357 | // The surface_child's parent does not have a clip rect as it owns a render |
| 3358 | // surface. Make sure the unoccluded rect does not get clipped away |
| 3359 | // inappropriately. |
| 3360 | EXPECT_RECT_EQ(gfx::Rect(0, 40, 100, 10), |
| 3361 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3362 | surface_child, false, gfx::Rect(0, 0, 100, 50), NULL)); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3363 | this->LeaveContributingSurface(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3364 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3365 | // When the surface_child's occlusion is transformed up to its parent, make |
| 3366 | // sure it is not clipped away inappropriately also. |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3367 | this->EnterLayer(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3368 | EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), |
| 3369 | occlusion.occlusion_from_outside_target().ToString()); |
| 3370 | EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(), |
| 3371 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3372 | this->LeaveLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3373 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3374 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3375 | // The surface's parent does have a clip rect as it is the root layer. |
| 3376 | EXPECT_RECT_EQ(gfx::Rect(0, 50, 100, 50), |
| 3377 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3378 | surface, false, gfx::Rect(0, 0, 100, 100), NULL)); |
| 3379 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3380 | }; |
| 3381 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3382 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3383 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3384 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3385 | class OcclusionTrackerTestTopmostSurfaceIsClippedToViewport |
| 3386 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3387 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3388 | explicit OcclusionTrackerTestTopmostSurfaceIsClippedToViewport( |
| 3389 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3390 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3391 | void RunMyTest() { |
| 3392 | // This test verifies that the top-most surface is considered occluded |
| 3393 | // outside of its target's clip rect and outside the viewport rect. |
| 3394 | |
| 3395 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3396 | this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); |
| 3397 | typename Types::LayerType* surface = |
| 3398 | this->CreateDrawingSurface(parent, |
| 3399 | this->identity_matrix, |
| 3400 | gfx::PointF(), |
| 3401 | gfx::Size(100, 300), |
| 3402 | true); |
| 3403 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3404 | { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3405 | // Make a viewport rect that is larger than the root layer. |
| 3406 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3407 | typename Types::RenderSurfaceType> occlusion( |
| 3408 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3409 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3410 | this->VisitLayer(surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3411 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3412 | // The root layer always has a clip rect. So the parent of |surface| has a |
| 3413 | // clip rect giving the surface itself a clip rect. |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3414 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3415 | // Make sure the parent's clip rect clips the unoccluded region of the |
| 3416 | // child surface. |
| 3417 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 200), |
| 3418 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3419 | surface, false, gfx::Rect(0, 0, 100, 300), NULL)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3420 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3421 | this->ResetLayerIterator(); |
| 3422 | { |
| 3423 | // Make a viewport rect that is smaller than the root layer. |
| 3424 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3425 | typename Types::RenderSurfaceType> occlusion( |
| 3426 | gfx::Rect(0, 0, 100, 100)); |
| 3427 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3428 | this->VisitLayer(surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3429 | |
| 3430 | // The root layer always has a clip rect. So the parent of |surface| has a |
| 3431 | // clip rect giving the surface itself a clip rect. |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3432 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3433 | // Make sure the viewport rect clips the unoccluded region of the child |
| 3434 | // surface. |
| 3435 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3436 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3437 | surface, false, gfx::Rect(0, 0, 100, 300), NULL)); |
| 3438 | } |
| 3439 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3440 | }; |
| 3441 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3442 | ALL_OCCLUSIONTRACKER_TEST( |
| 3443 | OcclusionTrackerTestTopmostSurfaceIsClippedToViewport); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3444 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3445 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3446 | class OcclusionTrackerTestSurfaceChildOfClippingSurface |
| 3447 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3448 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3449 | explicit OcclusionTrackerTestSurfaceChildOfClippingSurface(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3450 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3451 | void RunMyTest() { |
| 3452 | // This test verifies that the surface cliprect does not end up empty and |
| 3453 | // clip away the entire unoccluded rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3454 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3455 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3456 | this->identity_matrix, gfx::PointF(), gfx::Size(80, 200)); |
| 3457 | parent->SetMasksToBounds(true); |
| 3458 | typename Types::LayerType* surface = |
| 3459 | this->CreateDrawingSurface(parent, |
| 3460 | this->identity_matrix, |
| 3461 | gfx::PointF(), |
| 3462 | gfx::Size(100, 100), |
| 3463 | true); |
| 3464 | typename Types::LayerType* surface_child = |
| 3465 | this->CreateDrawingSurface(surface, |
| 3466 | this->identity_matrix, |
| 3467 | gfx::PointF(), |
| 3468 | gfx::Size(100, 100), |
| 3469 | false); |
| 3470 | typename Types::LayerType* topmost = this->CreateDrawingLayer( |
| 3471 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true); |
| 3472 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3473 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3474 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3475 | typename Types::RenderSurfaceType> occlusion( |
| 3476 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3477 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3478 | // |topmost| occludes everything partially so we know occlusion is happening |
| 3479 | // at all. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3480 | this->VisitLayer(topmost, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3481 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3482 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3483 | occlusion.occlusion_from_outside_target().ToString()); |
| 3484 | EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), |
| 3485 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3486 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3487 | // surface_child is not opaque and does not occlude, so we have a non-empty |
| 3488 | // unoccluded area on surface. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3489 | this->VisitLayer(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3490 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3491 | EXPECT_EQ(gfx::Rect(0, 0, 80, 50).ToString(), |
| 3492 | occlusion.occlusion_from_outside_target().ToString()); |
| 3493 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 3494 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3495 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3496 | // The root layer always has a clip rect. So the parent of |surface| has a |
| 3497 | // clip rect. However, the owning layer for |surface| does not mask to |
| 3498 | // bounds, so it doesn't have a clip rect of its own. Thus the parent of |
| 3499 | // |surface_child| exercises different code paths as its parent does not |
| 3500 | // have a clip rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3501 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3502 | this->EnterContributingSurface(surface_child, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3503 | // The surface_child's parent does not have a clip rect as it owns a render |
| 3504 | // surface. |
| 3505 | EXPECT_EQ( |
| 3506 | gfx::Rect(0, 50, 80, 50).ToString(), |
| 3507 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3508 | surface_child, false, gfx::Rect(0, 0, 100, 100), NULL).ToString()); |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3509 | this->LeaveContributingSurface(surface_child, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3510 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3511 | this->VisitLayer(surface, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3512 | this->EnterContributingSurface(surface, &occlusion, false); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3513 | // The surface's parent does have a clip rect as it is the root layer. |
| 3514 | EXPECT_EQ(gfx::Rect(0, 50, 80, 50).ToString(), |
| 3515 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 3516 | surface, false, gfx::Rect(0, 0, 100, 100), NULL).ToString()); |
| 3517 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3518 | }; |
| 3519 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 3520 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfClippingSurface); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3521 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3522 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3523 | class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter |
| 3524 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3525 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3526 | explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3527 | bool opaque_layers) |
| 3528 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3529 | void RunMyTest() { |
| 3530 | gfx::Transform scale_by_half; |
| 3531 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3532 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3533 | // Make a surface and its replica, each 50x50, that are completely |
| 3534 | // surrounded by opaque layers which are above them in the z-order. The |
| 3535 | // surface is scaled to test that the pixel moving is done in the target |
| 3536 | // space, where the background filter is applied, but the surface appears at |
| 3537 | // 50, 50 and the replica at 200, 50. |
| 3538 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3539 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 150)); |
| 3540 | typename Types::LayerType* filtered_surface = |
| 3541 | this->CreateDrawingLayer(parent, |
| 3542 | scale_by_half, |
| 3543 | gfx::PointF(50.f, 50.f), |
| 3544 | gfx::Size(100, 100), |
| 3545 | false); |
| 3546 | this->CreateReplicaLayer(filtered_surface, |
| 3547 | this->identity_matrix, |
| 3548 | gfx::PointF(300.f, 0.f), |
| 3549 | gfx::Size()); |
| 3550 | typename Types::LayerType* occluding_layer1 = this->CreateDrawingLayer( |
| 3551 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 50), true); |
| 3552 | typename Types::LayerType* occluding_layer2 = |
| 3553 | this->CreateDrawingLayer(parent, |
| 3554 | this->identity_matrix, |
| 3555 | gfx::PointF(0.f, 100.f), |
| 3556 | gfx::Size(300, 50), |
| 3557 | true); |
| 3558 | typename Types::LayerType* occluding_layer3 = |
| 3559 | this->CreateDrawingLayer(parent, |
| 3560 | this->identity_matrix, |
| 3561 | gfx::PointF(0.f, 50.f), |
| 3562 | gfx::Size(50, 50), |
| 3563 | true); |
| 3564 | typename Types::LayerType* occluding_layer4 = |
| 3565 | this->CreateDrawingLayer(parent, |
| 3566 | this->identity_matrix, |
| 3567 | gfx::PointF(100.f, 50.f), |
| 3568 | gfx::Size(100, 50), |
| 3569 | true); |
| 3570 | typename Types::LayerType* occluding_layer5 = |
| 3571 | this->CreateDrawingLayer(parent, |
| 3572 | this->identity_matrix, |
| 3573 | gfx::PointF(250.f, 50.f), |
| 3574 | gfx::Size(50, 50), |
| 3575 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3576 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3577 | // Filters make the layer own a surface. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3578 | FilterOperations filters; |
| 3579 | filters.Append(FilterOperation::CreateBlurFilter(10.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3580 | filtered_surface->SetBackgroundFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3581 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3582 | // Save the distance of influence for the blur effect. |
| 3583 | int outset_top, outset_right, outset_bottom, outset_left; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3584 | filters.GetOutsets( |
| 3585 | &outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3586 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3587 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3588 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3589 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3590 | typename Types::RenderSurfaceType> occlusion( |
| 3591 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3592 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3593 | // These layers occlude pixels directly beside the filtered_surface. Because |
| 3594 | // 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] | 3595 | // the pixels (up to radius far) underneath the occluding layers. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3596 | this->VisitLayer(occluding_layer5, &occlusion); |
| 3597 | this->VisitLayer(occluding_layer4, &occlusion); |
| 3598 | this->VisitLayer(occluding_layer3, &occlusion); |
| 3599 | this->VisitLayer(occluding_layer2, &occlusion); |
| 3600 | this->VisitLayer(occluding_layer1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3601 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3602 | Region expected_occlusion; |
| 3603 | expected_occlusion.Union(gfx::Rect(0, 0, 300, 50)); |
| 3604 | expected_occlusion.Union(gfx::Rect(0, 50, 50, 50)); |
| 3605 | expected_occlusion.Union(gfx::Rect(100, 50, 100, 50)); |
| 3606 | expected_occlusion.Union(gfx::Rect(250, 50, 50, 50)); |
| 3607 | expected_occlusion.Union(gfx::Rect(0, 100, 300, 50)); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 3608 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3609 | EXPECT_EQ(expected_occlusion.ToString(), |
| 3610 | occlusion.occlusion_from_inside_target().ToString()); |
| 3611 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3612 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3613 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3614 | this->VisitLayer(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3615 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3616 | // The filtered layer/replica does not occlude. |
| 3617 | Region expected_occlusion_outside_surface; |
| 3618 | expected_occlusion_outside_surface.Union(gfx::Rect(-50, -50, 300, 50)); |
| 3619 | expected_occlusion_outside_surface.Union(gfx::Rect(-50, 0, 50, 50)); |
| 3620 | expected_occlusion_outside_surface.Union(gfx::Rect(50, 0, 100, 50)); |
| 3621 | expected_occlusion_outside_surface.Union(gfx::Rect(200, 0, 50, 50)); |
| 3622 | expected_occlusion_outside_surface.Union(gfx::Rect(-50, 50, 300, 50)); |
[email protected] | ccb1c9a | 2012-12-17 03:53:19 | [diff] [blame] | 3623 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3624 | EXPECT_EQ(expected_occlusion_outside_surface.ToString(), |
| 3625 | occlusion.occlusion_from_outside_target().ToString()); |
| 3626 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3627 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3628 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3629 | // The surface has a background blur, so it needs pixels that are currently |
| 3630 | // considered occluded in order to be drawn. So the pixels it needs should |
| 3631 | // be removed some the occluded area so that when we get to the parent they |
| 3632 | // are drawn. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3633 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3634 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3635 | this->EnterLayer(parent, &occlusion, false); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 3636 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3637 | Region expected_blurred_occlusion; |
| 3638 | expected_blurred_occlusion.Union(gfx::Rect(0, 0, 300, 50 - outset_top)); |
| 3639 | expected_blurred_occlusion.Union(gfx::Rect( |
| 3640 | 0, 50 - outset_top, 50 - outset_left, 50 + outset_top + outset_bottom)); |
| 3641 | expected_blurred_occlusion.Union( |
| 3642 | gfx::Rect(100 + outset_right, |
| 3643 | 50 - outset_top, |
| 3644 | 100 - outset_right - outset_left, |
| 3645 | 50 + outset_top + outset_bottom)); |
| 3646 | expected_blurred_occlusion.Union( |
| 3647 | gfx::Rect(250 + outset_right, |
| 3648 | 50 - outset_top, |
| 3649 | 50 - outset_right, |
| 3650 | 50 + outset_top + outset_bottom)); |
| 3651 | expected_blurred_occlusion.Union( |
| 3652 | gfx::Rect(0, 100 + outset_bottom, 300, 50 - outset_bottom)); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 3653 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3654 | EXPECT_EQ(expected_blurred_occlusion.ToString(), |
| 3655 | occlusion.occlusion_from_inside_target().ToString()); |
| 3656 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3657 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3658 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3659 | gfx::Rect outset_rect; |
| 3660 | gfx::Rect test_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3661 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3662 | // Nothing in the blur outsets for the filtered_surface is occluded. |
| 3663 | outset_rect = gfx::Rect(50 - outset_left, |
| 3664 | 50 - outset_top, |
| 3665 | 50 + outset_left + outset_right, |
| 3666 | 50 + outset_top + outset_bottom); |
| 3667 | test_rect = outset_rect; |
| 3668 | EXPECT_EQ( |
| 3669 | outset_rect.ToString(), |
| 3670 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3671 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3672 | // Stuff outside the blur outsets is still occluded though. |
| 3673 | test_rect = outset_rect; |
| 3674 | test_rect.Inset(0, 0, -1, 0); |
| 3675 | EXPECT_EQ( |
| 3676 | outset_rect.ToString(), |
| 3677 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3678 | test_rect = outset_rect; |
| 3679 | test_rect.Inset(0, 0, 0, -1); |
| 3680 | EXPECT_EQ( |
| 3681 | outset_rect.ToString(), |
| 3682 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3683 | test_rect = outset_rect; |
| 3684 | test_rect.Inset(-1, 0, 0, 0); |
| 3685 | EXPECT_EQ( |
| 3686 | outset_rect.ToString(), |
| 3687 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3688 | test_rect = outset_rect; |
| 3689 | test_rect.Inset(0, -1, 0, 0); |
| 3690 | EXPECT_EQ( |
| 3691 | outset_rect.ToString(), |
| 3692 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3693 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3694 | // Nothing in the blur outsets for the filtered_surface's replica is |
| 3695 | // occluded. |
| 3696 | outset_rect = gfx::Rect(200 - outset_left, |
| 3697 | 50 - outset_top, |
| 3698 | 50 + outset_left + outset_right, |
| 3699 | 50 + outset_top + outset_bottom); |
| 3700 | test_rect = outset_rect; |
| 3701 | EXPECT_EQ( |
| 3702 | outset_rect.ToString(), |
| 3703 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3704 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3705 | // Stuff outside the blur outsets is still occluded though. |
| 3706 | test_rect = outset_rect; |
| 3707 | test_rect.Inset(0, 0, -1, 0); |
| 3708 | EXPECT_EQ( |
| 3709 | outset_rect.ToString(), |
| 3710 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3711 | test_rect = outset_rect; |
| 3712 | test_rect.Inset(0, 0, 0, -1); |
| 3713 | EXPECT_EQ( |
| 3714 | outset_rect.ToString(), |
| 3715 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3716 | test_rect = outset_rect; |
| 3717 | test_rect.Inset(-1, 0, 0, 0); |
| 3718 | EXPECT_EQ( |
| 3719 | outset_rect.ToString(), |
| 3720 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3721 | test_rect = outset_rect; |
| 3722 | test_rect.Inset(0, -1, 0, 0); |
| 3723 | EXPECT_EQ( |
| 3724 | outset_rect.ToString(), |
| 3725 | occlusion.UnoccludedLayerContentRect(parent, test_rect).ToString()); |
| 3726 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3727 | }; |
| 3728 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3729 | ALL_OCCLUSIONTRACKER_TEST( |
| 3730 | OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3731 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3732 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3733 | class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice |
| 3734 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3735 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3736 | explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3737 | bool opaque_layers) |
| 3738 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3739 | void RunMyTest() { |
| 3740 | gfx::Transform scale_by_half; |
| 3741 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3742 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3743 | // Makes two surfaces that completely cover |parent|. The occlusion both |
| 3744 | // above and below the filters will be reduced by each of them. |
| 3745 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 3746 | this->identity_matrix, gfx::PointF(), gfx::Size(75, 75)); |
| 3747 | typename Types::LayerType* parent = this->CreateSurface( |
| 3748 | root, scale_by_half, gfx::PointF(), gfx::Size(150, 150)); |
| 3749 | parent->SetMasksToBounds(true); |
| 3750 | typename Types::LayerType* filtered_surface1 = this->CreateDrawingLayer( |
| 3751 | parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false); |
| 3752 | typename Types::LayerType* filtered_surface2 = this->CreateDrawingLayer( |
| 3753 | parent, scale_by_half, gfx::PointF(), gfx::Size(300, 300), false); |
| 3754 | typename Types::LayerType* occluding_layer_above = |
| 3755 | this->CreateDrawingLayer(parent, |
| 3756 | this->identity_matrix, |
| 3757 | gfx::PointF(100.f, 100.f), |
| 3758 | gfx::Size(50, 50), |
| 3759 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3760 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3761 | // Filters make the layers own surfaces. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3762 | FilterOperations filters; |
| 3763 | filters.Append(FilterOperation::CreateBlurFilter(1.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3764 | filtered_surface1->SetBackgroundFilters(filters); |
| 3765 | filtered_surface2->SetBackgroundFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3766 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3767 | // Save the distance of influence for the blur effect. |
| 3768 | int outset_top, outset_right, outset_bottom, outset_left; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3769 | filters.GetOutsets( |
| 3770 | &outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3771 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3772 | this->CalcDrawEtc(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3773 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3774 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3775 | typename Types::RenderSurfaceType> occlusion( |
| 3776 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3777 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3778 | this->VisitLayer(occluding_layer_above, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3779 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3780 | occlusion.occlusion_from_outside_target().ToString()); |
| 3781 | EXPECT_EQ(gfx::Rect(100 / 2, 100 / 2, 50 / 2, 50 / 2).ToString(), |
| 3782 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3783 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3784 | this->VisitLayer(filtered_surface2, &occlusion); |
| 3785 | this->VisitContributingSurface(filtered_surface2, &occlusion); |
| 3786 | this->VisitLayer(filtered_surface1, &occlusion); |
| 3787 | this->VisitContributingSurface(filtered_surface1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3788 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3789 | // Test expectations in the target. |
| 3790 | gfx::Rect expected_occlusion = |
| 3791 | gfx::Rect(100 / 2 + outset_right * 2, |
| 3792 | 100 / 2 + outset_bottom * 2, |
| 3793 | 50 / 2 - (outset_left + outset_right) * 2, |
| 3794 | 50 / 2 - (outset_top + outset_bottom) * 2); |
| 3795 | EXPECT_EQ(expected_occlusion.ToString(), |
| 3796 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3797 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3798 | // Test expectations in the screen are the same as in the target, as the |
| 3799 | // render surface is 1:1 with the screen. |
| 3800 | EXPECT_EQ(expected_occlusion.ToString(), |
| 3801 | occlusion.occlusion_from_outside_target().ToString()); |
| 3802 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3803 | }; |
| 3804 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3805 | ALL_OCCLUSIONTRACKER_TEST( |
| 3806 | OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3807 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3808 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3809 | class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip |
| 3810 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3811 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 3812 | explicit |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3813 | OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip( |
| 3814 | bool opaque_layers) |
| 3815 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 3816 | void RunMyTest() { |
| 3817 | // Make a surface and its replica, Each 50x50, that are completely |
| 3818 | // surrounded by opaque layers which are above them in the z-order. |
| 3819 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 3820 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 150)); |
| 3821 | // We stick the filtered surface inside a clipping surface so that we can |
| 3822 | // make sure the clip is honored when exposing pixels for |
| 3823 | // the background filter. |
| 3824 | typename Types::LayerType* clipping_surface = |
| 3825 | this->CreateDrawingSurface(parent, |
| 3826 | this->identity_matrix, |
| 3827 | gfx::PointF(), |
| 3828 | gfx::Size(300, 70), |
| 3829 | false); |
| 3830 | clipping_surface->SetMasksToBounds(true); |
| 3831 | typename Types::LayerType* filtered_surface = |
| 3832 | this->CreateDrawingLayer(clipping_surface, |
| 3833 | this->identity_matrix, |
| 3834 | gfx::PointF(50.f, 50.f), |
| 3835 | gfx::Size(50, 50), |
| 3836 | false); |
| 3837 | this->CreateReplicaLayer(filtered_surface, |
| 3838 | this->identity_matrix, |
| 3839 | gfx::PointF(150.f, 0.f), |
| 3840 | gfx::Size()); |
| 3841 | typename Types::LayerType* occluding_layer1 = this->CreateDrawingLayer( |
| 3842 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 50), true); |
| 3843 | typename Types::LayerType* occluding_layer2 = |
| 3844 | this->CreateDrawingLayer(parent, |
| 3845 | this->identity_matrix, |
| 3846 | gfx::PointF(0.f, 100.f), |
| 3847 | gfx::Size(300, 50), |
| 3848 | true); |
| 3849 | typename Types::LayerType* occluding_layer3 = |
| 3850 | this->CreateDrawingLayer(parent, |
| 3851 | this->identity_matrix, |
| 3852 | gfx::PointF(0.f, 50.f), |
| 3853 | gfx::Size(50, 50), |
| 3854 | true); |
| 3855 | typename Types::LayerType* occluding_layer4 = |
| 3856 | this->CreateDrawingLayer(parent, |
| 3857 | this->identity_matrix, |
| 3858 | gfx::PointF(100.f, 50.f), |
| 3859 | gfx::Size(100, 50), |
| 3860 | true); |
| 3861 | typename Types::LayerType* occluding_layer5 = |
| 3862 | this->CreateDrawingLayer(parent, |
| 3863 | this->identity_matrix, |
| 3864 | gfx::PointF(250.f, 50.f), |
| 3865 | gfx::Size(50, 50), |
| 3866 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3867 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3868 | // Filters make the layer own a surface. This filter is large enough that it |
| 3869 | // goes outside the bottom of the clipping_surface. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3870 | FilterOperations filters; |
| 3871 | filters.Append(FilterOperation::CreateBlurFilter(12.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3872 | filtered_surface->SetBackgroundFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3873 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3874 | // Save the distance of influence for the blur effect. |
| 3875 | int outset_top, outset_right, outset_bottom, outset_left; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 3876 | filters.GetOutsets( |
| 3877 | &outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3878 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3879 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3880 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3881 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 3882 | typename Types::RenderSurfaceType> occlusion( |
| 3883 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3884 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3885 | // These layers occlude pixels directly beside the filtered_surface. Because |
| 3886 | // 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] | 3887 | // the pixels (up to radius far) underneath the occluding layers. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3888 | this->VisitLayer(occluding_layer5, &occlusion); |
| 3889 | this->VisitLayer(occluding_layer4, &occlusion); |
| 3890 | this->VisitLayer(occluding_layer3, &occlusion); |
| 3891 | this->VisitLayer(occluding_layer2, &occlusion); |
| 3892 | this->VisitLayer(occluding_layer1, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3893 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3894 | Region expected_occlusion; |
| 3895 | expected_occlusion.Union(gfx::Rect(0, 0, 300, 50)); |
| 3896 | expected_occlusion.Union(gfx::Rect(0, 50, 50, 50)); |
| 3897 | expected_occlusion.Union(gfx::Rect(100, 50, 100, 50)); |
| 3898 | expected_occlusion.Union(gfx::Rect(250, 50, 50, 50)); |
| 3899 | expected_occlusion.Union(gfx::Rect(0, 100, 300, 50)); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 3900 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3901 | EXPECT_EQ(expected_occlusion.ToString(), |
| 3902 | occlusion.occlusion_from_inside_target().ToString()); |
| 3903 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3904 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3905 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3906 | // Everything outside the surface/replica is occluded but the |
| 3907 | // surface/replica itself is not. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3908 | this->VisitLayer(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3909 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3910 | // The filtered layer/replica does not occlude. |
| 3911 | Region expected_occlusion_outside_surface; |
| 3912 | expected_occlusion_outside_surface.Union(gfx::Rect(-50, -50, 300, 50)); |
| 3913 | expected_occlusion_outside_surface.Union(gfx::Rect(-50, 0, 50, 50)); |
| 3914 | expected_occlusion_outside_surface.Union(gfx::Rect(50, 0, 100, 50)); |
| 3915 | expected_occlusion_outside_surface.Union(gfx::Rect(200, 0, 50, 50)); |
| 3916 | expected_occlusion_outside_surface.Union(gfx::Rect(-50, 50, 300, 50)); |
[email protected] | ccb1c9a | 2012-12-17 03:53:19 | [diff] [blame] | 3917 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3918 | EXPECT_EQ(expected_occlusion_outside_surface.ToString(), |
| 3919 | occlusion.occlusion_from_outside_target().ToString()); |
| 3920 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3921 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3922 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3923 | // The surface has a background blur, so it needs pixels that are currently |
| 3924 | // considered occluded in order to be drawn. So the pixels it needs should |
| 3925 | // be removed some the occluded area so that when we get to the parent they |
| 3926 | // are drawn. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3927 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3928 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 3929 | this->VisitLayer(clipping_surface, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 3930 | this->EnterContributingSurface(clipping_surface, &occlusion, false); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 3931 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3932 | Region expected_blurred_occlusion; |
| 3933 | expected_blurred_occlusion.Union(gfx::Rect(0, 0, 300, 50 - outset_top)); |
| 3934 | expected_blurred_occlusion.Union(gfx::Rect( |
| 3935 | 0, 50 - outset_top, 50 - outset_left, 20 + outset_top + outset_bottom)); |
| 3936 | expected_blurred_occlusion.Union( |
| 3937 | gfx::Rect(100 + outset_right, |
| 3938 | 50 - outset_top, |
| 3939 | 100 - outset_right - outset_left, |
| 3940 | 20 + outset_top + outset_bottom)); |
| 3941 | expected_blurred_occlusion.Union( |
| 3942 | gfx::Rect(250 + outset_right, |
| 3943 | 50 - outset_top, |
| 3944 | 50 - outset_right, |
| 3945 | 20 + outset_top + outset_bottom)); |
| 3946 | expected_blurred_occlusion.Union(gfx::Rect(0, 100 + 5, 300, 50 - 5)); |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 3947 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3948 | EXPECT_EQ(expected_blurred_occlusion.ToString(), |
| 3949 | occlusion.occlusion_from_outside_target().ToString()); |
| 3950 | EXPECT_EQ(gfx::Rect().ToString(), |
| 3951 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3952 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3953 | gfx::Rect outset_rect; |
| 3954 | gfx::Rect clipped_outset_rect; |
| 3955 | gfx::Rect test_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3956 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3957 | // Nothing in the (clipped) blur outsets for the filtered_surface is |
| 3958 | // occluded. |
| 3959 | outset_rect = gfx::Rect(50 - outset_left, |
| 3960 | 50 - outset_top, |
| 3961 | 50 + outset_left + outset_right, |
| 3962 | 50 + outset_top + outset_bottom); |
| 3963 | clipped_outset_rect = outset_rect; |
| 3964 | clipped_outset_rect.Intersect(gfx::Rect(0 - outset_left, |
| 3965 | 0 - outset_top, |
| 3966 | 300 + outset_left + outset_right, |
| 3967 | 70 + outset_top + outset_bottom)); |
| 3968 | clipped_outset_rect.Intersect(gfx::Rect(0, 0, 300, 70)); |
| 3969 | test_rect = outset_rect; |
| 3970 | EXPECT_RECT_EQ( |
| 3971 | clipped_outset_rect, |
| 3972 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3973 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3974 | // Stuff outside the (clipped) blur outsets is still occluded though. |
| 3975 | test_rect = outset_rect; |
| 3976 | test_rect.Inset(0, 0, -1, 0); |
| 3977 | EXPECT_RECT_EQ( |
| 3978 | clipped_outset_rect, |
| 3979 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
| 3980 | test_rect = outset_rect; |
| 3981 | test_rect.Inset(0, 0, 0, -1); |
| 3982 | EXPECT_RECT_EQ( |
| 3983 | clipped_outset_rect, |
| 3984 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
| 3985 | test_rect = outset_rect; |
| 3986 | test_rect.Inset(-1, 0, 0, 0); |
| 3987 | EXPECT_RECT_EQ( |
| 3988 | clipped_outset_rect, |
| 3989 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
| 3990 | test_rect = outset_rect; |
| 3991 | test_rect.Inset(0, -1, 0, 0); |
| 3992 | EXPECT_RECT_EQ( |
| 3993 | clipped_outset_rect, |
| 3994 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3995 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 3996 | // Nothing in the (clipped) blur outsets for the filtered_surface's replica |
| 3997 | // is occluded. |
| 3998 | outset_rect = gfx::Rect(200 - outset_left, |
| 3999 | 50 - outset_top, |
| 4000 | 50 + outset_left + outset_right, |
| 4001 | 50 + outset_top + outset_bottom); |
| 4002 | clipped_outset_rect = outset_rect; |
| 4003 | clipped_outset_rect.Intersect(gfx::Rect(0 - outset_left, |
| 4004 | 0 - outset_top, |
| 4005 | 300 + outset_left + outset_right, |
| 4006 | 70 + outset_top + outset_bottom)); |
| 4007 | clipped_outset_rect.Intersect(gfx::Rect(0, 0, 300, 70)); |
| 4008 | test_rect = outset_rect; |
| 4009 | EXPECT_RECT_EQ( |
| 4010 | clipped_outset_rect, |
| 4011 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4012 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4013 | // Stuff outside the (clipped) blur outsets is still occluded though. |
| 4014 | test_rect = outset_rect; |
| 4015 | test_rect.Inset(0, 0, -1, 0); |
| 4016 | EXPECT_RECT_EQ( |
| 4017 | clipped_outset_rect, |
| 4018 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
| 4019 | test_rect = outset_rect; |
| 4020 | test_rect.Inset(0, 0, 0, -1); |
| 4021 | EXPECT_RECT_EQ( |
| 4022 | clipped_outset_rect, |
| 4023 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
| 4024 | test_rect = outset_rect; |
| 4025 | test_rect.Inset(-1, 0, 0, 0); |
| 4026 | EXPECT_RECT_EQ( |
| 4027 | clipped_outset_rect, |
| 4028 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
| 4029 | test_rect = outset_rect; |
| 4030 | test_rect.Inset(0, -1, 0, 0); |
| 4031 | EXPECT_RECT_EQ( |
| 4032 | clipped_outset_rect, |
| 4033 | occlusion.UnoccludedLayerContentRect(clipping_surface, test_rect)); |
| 4034 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4035 | }; |
| 4036 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4037 | ALL_OCCLUSIONTRACKER_TEST( |
| 4038 | OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilterWithClip); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4039 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4040 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4041 | class OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter |
| 4042 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4043 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4044 | explicit OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4045 | bool opaque_layers) |
| 4046 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4047 | void RunMyTest() { |
| 4048 | gfx::Transform scale_by_half; |
| 4049 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4050 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4051 | // Make a surface and its replica, each 50x50, with a smaller 30x30 layer |
| 4052 | // centered below each. The surface is scaled to test that the pixel moving |
| 4053 | // is done in the target space, where the background filter is applied, but |
| 4054 | // the surface appears at 50, 50 and the replica at 200, 50. |
| 4055 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4056 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 150)); |
| 4057 | typename Types::LayerType* behind_surface_layer = |
| 4058 | this->CreateDrawingLayer(parent, |
| 4059 | this->identity_matrix, |
| 4060 | gfx::PointF(60.f, 60.f), |
| 4061 | gfx::Size(30, 30), |
| 4062 | true); |
| 4063 | typename Types::LayerType* behind_replica_layer = |
| 4064 | this->CreateDrawingLayer(parent, |
| 4065 | this->identity_matrix, |
| 4066 | gfx::PointF(210.f, 60.f), |
| 4067 | gfx::Size(30, 30), |
| 4068 | true); |
| 4069 | typename Types::LayerType* filtered_surface = |
| 4070 | this->CreateDrawingLayer(parent, |
| 4071 | scale_by_half, |
| 4072 | gfx::PointF(50.f, 50.f), |
| 4073 | gfx::Size(100, 100), |
| 4074 | false); |
| 4075 | this->CreateReplicaLayer(filtered_surface, |
| 4076 | this->identity_matrix, |
| 4077 | gfx::PointF(300.f, 0.f), |
| 4078 | gfx::Size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4079 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4080 | // Filters make the layer own a surface. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 4081 | FilterOperations filters; |
| 4082 | filters.Append(FilterOperation::CreateBlurFilter(3.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4083 | filtered_surface->SetBackgroundFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4084 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4085 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4086 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4087 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4088 | typename Types::RenderSurfaceType> occlusion( |
| 4089 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4090 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4091 | // The surface has a background blur, so it blurs non-opaque pixels below |
| 4092 | // it. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4093 | this->VisitLayer(filtered_surface, &occlusion); |
| 4094 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4095 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4096 | this->VisitLayer(behind_replica_layer, &occlusion); |
| 4097 | this->VisitLayer(behind_surface_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4098 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4099 | // The layers behind the surface are not blurred, and their occlusion does |
| 4100 | // not change, until we leave the surface. So it should not be modified by |
| 4101 | // the filter here. |
| 4102 | gfx::Rect occlusion_behind_surface = gfx::Rect(60, 60, 30, 30); |
| 4103 | gfx::Rect occlusion_behind_replica = gfx::Rect(210, 60, 30, 30); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4104 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4105 | Region expected_opaque_bounds = |
| 4106 | UnionRegions(occlusion_behind_surface, occlusion_behind_replica); |
| 4107 | EXPECT_EQ(expected_opaque_bounds.ToString(), |
| 4108 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | ccb1c9a | 2012-12-17 03:53:19 | [diff] [blame] | 4109 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4110 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4111 | occlusion.occlusion_from_outside_target().ToString()); |
| 4112 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4113 | }; |
| 4114 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4115 | ALL_OCCLUSIONTRACKER_TEST( |
| 4116 | OcclusionTrackerTestDontReduceOcclusionBelowBackgroundFilter); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4117 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4118 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4119 | class OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded |
| 4120 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4121 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4122 | explicit OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded( |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4123 | bool opaque_layers) |
| 4124 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4125 | void RunMyTest() { |
| 4126 | gfx::Transform scale_by_half; |
| 4127 | scale_by_half.Scale(0.5, 0.5); |
| 4128 | |
| 4129 | // Make a surface and its replica, each 50x50, that are completely occluded |
| 4130 | // by opaque layers which are above them in the z-order. The surface is |
| 4131 | // scaled to test that the pixel moving is done in the target space, where |
| 4132 | // the background filter is applied, but the surface appears at 50, 50 and |
| 4133 | // the replica at 200, 50. |
| 4134 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4135 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 150)); |
| 4136 | typename Types::LayerType* filtered_surface = |
| 4137 | this->CreateDrawingLayer(parent, |
| 4138 | scale_by_half, |
| 4139 | gfx::PointF(50.f, 50.f), |
| 4140 | gfx::Size(100, 100), |
| 4141 | false); |
| 4142 | this->CreateReplicaLayer(filtered_surface, |
| 4143 | this->identity_matrix, |
| 4144 | gfx::PointF(300.f, 0.f), |
| 4145 | gfx::Size()); |
| 4146 | typename Types::LayerType* above_surface_layer = |
| 4147 | this->CreateDrawingLayer(parent, |
| 4148 | this->identity_matrix, |
| 4149 | gfx::PointF(50.f, 50.f), |
| 4150 | gfx::Size(50, 50), |
| 4151 | true); |
| 4152 | typename Types::LayerType* above_replica_layer = |
| 4153 | this->CreateDrawingLayer(parent, |
| 4154 | this->identity_matrix, |
| 4155 | gfx::PointF(200.f, 50.f), |
| 4156 | gfx::Size(50, 50), |
| 4157 | true); |
| 4158 | |
| 4159 | // Filters make the layer own a surface. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 4160 | FilterOperations filters; |
| 4161 | filters.Append(FilterOperation::CreateBlurFilter(3.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4162 | filtered_surface->SetBackgroundFilters(filters); |
| 4163 | |
| 4164 | this->CalcDrawEtc(parent); |
| 4165 | |
| 4166 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4167 | typename Types::RenderSurfaceType> occlusion( |
| 4168 | gfx::Rect(0, 0, 1000, 1000)); |
| 4169 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4170 | this->VisitLayer(above_replica_layer, &occlusion); |
| 4171 | this->VisitLayer(above_surface_layer, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4172 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4173 | this->VisitLayer(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4174 | { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4175 | // The layers above the filtered surface occlude from outside. |
| 4176 | gfx::Rect occlusion_above_surface = gfx::Rect(0, 0, 50, 50); |
| 4177 | gfx::Rect occlusion_above_replica = gfx::Rect(150, 0, 50, 50); |
| 4178 | Region expected_opaque_region = |
| 4179 | UnionRegions(occlusion_above_surface, occlusion_above_replica); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4180 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4181 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4182 | occlusion.occlusion_from_inside_target().ToString()); |
| 4183 | EXPECT_EQ(expected_opaque_region.ToString(), |
| 4184 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4185 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4186 | |
| 4187 | // The surface has a background blur, so it blurs non-opaque pixels below |
| 4188 | // it. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4189 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4190 | { |
| 4191 | // The filter is completely occluded, so it should not blur anything and |
| 4192 | // reduce any occlusion. |
| 4193 | gfx::Rect occlusion_above_surface = gfx::Rect(50, 50, 50, 50); |
| 4194 | gfx::Rect occlusion_above_replica = gfx::Rect(200, 50, 50, 50); |
| 4195 | Region expected_opaque_region = |
| 4196 | UnionRegions(occlusion_above_surface, occlusion_above_replica); |
| 4197 | |
| 4198 | EXPECT_EQ(expected_opaque_region.ToString(), |
| 4199 | occlusion.occlusion_from_inside_target().ToString()); |
| 4200 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4201 | occlusion.occlusion_from_outside_target().ToString()); |
| 4202 | } |
| 4203 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4204 | }; |
| 4205 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4206 | ALL_OCCLUSIONTRACKER_TEST( |
| 4207 | OcclusionTrackerTestDontReduceOcclusionIfBackgroundFilterIsOccluded); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4208 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4209 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4210 | class OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded |
| 4211 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4212 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4213 | explicit |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4214 | OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded( |
| 4215 | bool opaque_layers) |
| 4216 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4217 | void RunMyTest() { |
| 4218 | gfx::Transform scale_by_half; |
| 4219 | scale_by_half.Scale(0.5, 0.5); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4220 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4221 | // Make a surface and its replica, each 50x50, that are partially occluded |
| 4222 | // by opaque layers which are above them in the z-order. The surface is |
| 4223 | // scaled to test that the pixel moving is done in the target space, where |
| 4224 | // the background filter is applied, but the surface appears at 50, 50 and |
| 4225 | // the replica at 200, 50. |
| 4226 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4227 | this->identity_matrix, gfx::PointF(), gfx::Size(300, 150)); |
| 4228 | typename Types::LayerType* filtered_surface = |
| 4229 | this->CreateDrawingLayer(parent, |
| 4230 | scale_by_half, |
| 4231 | gfx::PointF(50.f, 50.f), |
| 4232 | gfx::Size(100, 100), |
| 4233 | false); |
| 4234 | this->CreateReplicaLayer(filtered_surface, |
| 4235 | this->identity_matrix, |
| 4236 | gfx::PointF(300.f, 0.f), |
| 4237 | gfx::Size()); |
| 4238 | typename Types::LayerType* above_surface_layer = |
| 4239 | this->CreateDrawingLayer(parent, |
| 4240 | this->identity_matrix, |
| 4241 | gfx::PointF(70.f, 50.f), |
| 4242 | gfx::Size(30, 50), |
| 4243 | true); |
| 4244 | typename Types::LayerType* above_replica_layer = |
| 4245 | this->CreateDrawingLayer(parent, |
| 4246 | this->identity_matrix, |
| 4247 | gfx::PointF(200.f, 50.f), |
| 4248 | gfx::Size(30, 50), |
| 4249 | true); |
| 4250 | typename Types::LayerType* beside_surface_layer = |
| 4251 | this->CreateDrawingLayer(parent, |
| 4252 | this->identity_matrix, |
| 4253 | gfx::PointF(90.f, 40.f), |
| 4254 | gfx::Size(10, 10), |
| 4255 | true); |
| 4256 | typename Types::LayerType* beside_replica_layer = |
| 4257 | this->CreateDrawingLayer(parent, |
| 4258 | this->identity_matrix, |
| 4259 | gfx::PointF(200.f, 40.f), |
| 4260 | gfx::Size(10, 10), |
| 4261 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4262 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4263 | // Filters make the layer own a surface. |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 4264 | FilterOperations filters; |
| 4265 | filters.Append(FilterOperation::CreateBlurFilter(3.f)); |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4266 | filtered_surface->SetBackgroundFilters(filters); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4267 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4268 | // Save the distance of influence for the blur effect. |
| 4269 | int outset_top, outset_right, outset_bottom, outset_left; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 4270 | filters.GetOutsets( |
| 4271 | &outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4272 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4273 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4274 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4275 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4276 | typename Types::RenderSurfaceType> occlusion( |
| 4277 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4278 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4279 | this->VisitLayer(beside_replica_layer, &occlusion); |
| 4280 | this->VisitLayer(beside_surface_layer, &occlusion); |
| 4281 | this->VisitLayer(above_replica_layer, &occlusion); |
| 4282 | this->VisitLayer(above_surface_layer, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4283 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4284 | // The surface has a background blur, so it blurs non-opaque pixels below |
| 4285 | // it. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4286 | this->VisitLayer(filtered_surface, &occlusion); |
| 4287 | this->VisitContributingSurface(filtered_surface, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4288 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4289 | // The filter in the surface and replica are partially unoccluded. Only the |
| 4290 | // unoccluded parts should reduce occlusion. This means it will push back |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 4291 | // the occlusion that touches the unoccluded part (occlusion_above___), but |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4292 | // it will not touch occlusion_beside____ since that is not beside the |
| 4293 | // unoccluded part of the surface, even though it is beside the occluded |
| 4294 | // part of the surface. |
| 4295 | gfx::Rect occlusion_above_surface = |
| 4296 | gfx::Rect(70 + outset_right, 50, 30 - outset_right, 50); |
| 4297 | gfx::Rect occlusion_above_replica = |
| 4298 | gfx::Rect(200, 50, 30 - outset_left, 50); |
| 4299 | gfx::Rect occlusion_beside_surface = gfx::Rect(90, 40, 10, 10); |
| 4300 | gfx::Rect occlusion_beside_replica = gfx::Rect(200, 40, 10, 10); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4301 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4302 | Region expected_occlusion; |
| 4303 | expected_occlusion.Union(occlusion_above_surface); |
| 4304 | expected_occlusion.Union(occlusion_above_replica); |
| 4305 | expected_occlusion.Union(occlusion_beside_surface); |
| 4306 | expected_occlusion.Union(occlusion_beside_replica); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4307 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4308 | ASSERT_EQ(expected_occlusion.ToString(), |
| 4309 | occlusion.occlusion_from_inside_target().ToString()); |
| 4310 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4311 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4312 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4313 | Region::Iterator expected_rects(expected_occlusion); |
| 4314 | Region::Iterator target_surface_rects( |
| 4315 | occlusion.occlusion_from_inside_target()); |
| 4316 | for (; expected_rects.has_rect(); |
| 4317 | expected_rects.next(), target_surface_rects.next()) { |
| 4318 | ASSERT_TRUE(target_surface_rects.has_rect()); |
| 4319 | EXPECT_EQ(expected_rects.rect(), target_surface_rects.rect()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4320 | } |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4321 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4322 | }; |
| 4323 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4324 | ALL_OCCLUSIONTRACKER_TEST( |
| 4325 | OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4326 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4327 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4328 | class OcclusionTrackerTestMinimumTrackingSize |
| 4329 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4330 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4331 | explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4332 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4333 | void RunMyTest() { |
| 4334 | gfx::Size tracking_size(100, 100); |
| 4335 | gfx::Size below_tracking_size(99, 99); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4336 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4337 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4338 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 4339 | typename Types::LayerType* large = this->CreateDrawingLayer( |
| 4340 | parent, this->identity_matrix, gfx::PointF(), tracking_size, true); |
| 4341 | typename Types::LayerType* small = |
| 4342 | this->CreateDrawingLayer(parent, |
| 4343 | this->identity_matrix, |
| 4344 | gfx::PointF(), |
| 4345 | below_tracking_size, |
| 4346 | true); |
| 4347 | this->CalcDrawEtc(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4348 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4349 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4350 | typename Types::RenderSurfaceType> occlusion( |
| 4351 | gfx::Rect(0, 0, 1000, 1000)); |
| 4352 | occlusion.set_minimum_tracking_size(tracking_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4353 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4354 | // The small layer is not tracked because it is too small. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4355 | this->VisitLayer(small, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4356 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4357 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4358 | occlusion.occlusion_from_outside_target().ToString()); |
| 4359 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4360 | occlusion.occlusion_from_inside_target().ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4361 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4362 | // The large layer is tracked as it is large enough. |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4363 | this->VisitLayer(large, &occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4364 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4365 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4366 | occlusion.occlusion_from_outside_target().ToString()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4367 | EXPECT_EQ(gfx::Rect(tracking_size).ToString(), |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4368 | occlusion.occlusion_from_inside_target().ToString()); |
| 4369 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4370 | }; |
| 4371 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 4372 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestMinimumTrackingSize); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4373 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4374 | template <class Types> |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4375 | class OcclusionTrackerTestViewportClipIsExternalOcclusion |
| 4376 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4377 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4378 | explicit OcclusionTrackerTestViewportClipIsExternalOcclusion( |
| 4379 | bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4380 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4381 | void RunMyTest() { |
| 4382 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4383 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 4384 | typename Types::LayerType* small = |
| 4385 | this->CreateDrawingSurface(parent, |
| 4386 | this->identity_matrix, |
| 4387 | gfx::PointF(), |
| 4388 | gfx::Size(200, 200), |
| 4389 | false); |
| 4390 | typename Types::LayerType* large = |
| 4391 | this->CreateDrawingLayer(small, |
| 4392 | this->identity_matrix, |
| 4393 | gfx::PointF(), |
| 4394 | gfx::Size(400, 400), |
| 4395 | false); |
| 4396 | small->SetMasksToBounds(true); |
| 4397 | this->CalcDrawEtc(parent); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4398 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4399 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4400 | typename Types::RenderSurfaceType> occlusion( |
| 4401 | gfx::Rect(0, 0, 100, 100)); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4402 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 4403 | this->EnterLayer(large, &occlusion, false); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4404 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4405 | bool has_occlusion_from_outside_target_surface = false; |
| 4406 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 4407 | occlusion.UnoccludedLayerContentRect( |
| 4408 | large, |
| 4409 | gfx::Rect(0, 0, 400, 400), |
| 4410 | &has_occlusion_from_outside_target_surface)); |
| 4411 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4412 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4413 | has_occlusion_from_outside_target_surface = false; |
| 4414 | EXPECT_FALSE( |
| 4415 | occlusion.OccludedLayer(large, |
| 4416 | gfx::Rect(0, 0, 400, 400), |
| 4417 | &has_occlusion_from_outside_target_surface)); |
| 4418 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4419 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4420 | this->LeaveLayer(large, &occlusion); |
| 4421 | this->VisitLayer(small, &occlusion); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4422 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4423 | has_occlusion_from_outside_target_surface = false; |
| 4424 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 4425 | occlusion.UnoccludedLayerContentRect( |
| 4426 | small, |
| 4427 | gfx::Rect(0, 0, 200, 200), |
| 4428 | &has_occlusion_from_outside_target_surface)); |
| 4429 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4430 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4431 | has_occlusion_from_outside_target_surface = false; |
| 4432 | EXPECT_FALSE( |
| 4433 | occlusion.OccludedLayer(small, |
| 4434 | gfx::Rect(0, 0, 200, 200), |
| 4435 | &has_occlusion_from_outside_target_surface)); |
| 4436 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4437 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 4438 | this->EnterContributingSurface(small, &occlusion, false); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4439 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4440 | has_occlusion_from_outside_target_surface = false; |
| 4441 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 4442 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 4443 | small, |
| 4444 | false, |
| 4445 | gfx::Rect(0, 0, 200, 200), |
| 4446 | &has_occlusion_from_outside_target_surface)); |
| 4447 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
| 4448 | } |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4449 | }; |
| 4450 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4451 | ALL_OCCLUSIONTRACKER_TEST( |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4452 | OcclusionTrackerTestViewportClipIsExternalOcclusion) |
| 4453 | |
| 4454 | template <class Types> |
| 4455 | class OcclusionTrackerTestLayerClipIsExternalOcclusion |
| 4456 | : public OcclusionTrackerTest<Types> { |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4457 | protected: |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4458 | explicit OcclusionTrackerTestLayerClipIsExternalOcclusion(bool opaque_layers) |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4459 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4460 | void RunMyTest() { |
| 4461 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4462 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 4463 | typename Types::LayerType* smallest = this->CreateDrawingLayer( |
| 4464 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false); |
| 4465 | typename Types::LayerType* smaller = |
| 4466 | this->CreateDrawingSurface(smallest, |
| 4467 | this->identity_matrix, |
| 4468 | gfx::PointF(), |
| 4469 | gfx::Size(100, 100), |
| 4470 | false); |
| 4471 | typename Types::LayerType* small = |
| 4472 | this->CreateDrawingSurface(smaller, |
| 4473 | this->identity_matrix, |
| 4474 | gfx::PointF(), |
| 4475 | gfx::Size(200, 200), |
| 4476 | false); |
| 4477 | typename Types::LayerType* large = |
| 4478 | this->CreateDrawingLayer(small, |
| 4479 | this->identity_matrix, |
| 4480 | gfx::PointF(), |
| 4481 | gfx::Size(400, 400), |
| 4482 | false); |
| 4483 | smallest->SetMasksToBounds(true); |
| 4484 | smaller->SetMasksToBounds(true); |
| 4485 | small->SetMasksToBounds(true); |
| 4486 | this->CalcDrawEtc(parent); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4487 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4488 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4489 | typename Types::RenderSurfaceType> occlusion( |
| 4490 | gfx::Rect(0, 0, 1000, 1000)); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4491 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 4492 | this->EnterLayer(large, &occlusion, false); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4493 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4494 | // Clipping from the smaller layer is from outside the target surface. |
| 4495 | bool has_occlusion_from_outside_target_surface = false; |
| 4496 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 4497 | occlusion.UnoccludedLayerContentRect( |
| 4498 | large, |
| 4499 | gfx::Rect(0, 0, 400, 400), |
| 4500 | &has_occlusion_from_outside_target_surface)); |
| 4501 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4502 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4503 | has_occlusion_from_outside_target_surface = false; |
| 4504 | EXPECT_FALSE( |
| 4505 | occlusion.OccludedLayer(large, |
| 4506 | gfx::Rect(0, 0, 400, 400), |
| 4507 | &has_occlusion_from_outside_target_surface)); |
| 4508 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4509 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4510 | this->LeaveLayer(large, &occlusion); |
| 4511 | this->VisitLayer(small, &occlusion); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4512 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4513 | // Clipping from the smaller layer is from outside the target surface. |
| 4514 | has_occlusion_from_outside_target_surface = false; |
| 4515 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 4516 | occlusion.UnoccludedLayerContentRect( |
| 4517 | small, |
| 4518 | gfx::Rect(0, 0, 200, 200), |
| 4519 | &has_occlusion_from_outside_target_surface)); |
| 4520 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4521 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4522 | has_occlusion_from_outside_target_surface = false; |
| 4523 | EXPECT_FALSE( |
| 4524 | occlusion.OccludedLayer(small, |
| 4525 | gfx::Rect(0, 0, 200, 200), |
| 4526 | &has_occlusion_from_outside_target_surface)); |
| 4527 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4528 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 4529 | this->EnterContributingSurface(small, &occlusion, false); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4530 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4531 | // The |small| surface is clipped from outside its target by |smallest|. |
| 4532 | has_occlusion_from_outside_target_surface = false; |
| 4533 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 4534 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 4535 | small, |
| 4536 | false, |
| 4537 | gfx::Rect(0, 0, 200, 200), |
| 4538 | &has_occlusion_from_outside_target_surface)); |
| 4539 | EXPECT_TRUE(has_occlusion_from_outside_target_surface); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4540 | |
[email protected] | d002dd0 | 2013-03-27 07:40:40 | [diff] [blame] | 4541 | this->LeaveContributingSurface(small, &occlusion); |
| 4542 | this->VisitLayer(smaller, &occlusion); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 4543 | this->EnterContributingSurface(smaller, &occlusion, false); |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4544 | |
[email protected] | a27cbde | 2013-03-23 22:01:49 | [diff] [blame] | 4545 | // The |smaller| surface is clipped from inside its target by |smallest|. |
| 4546 | has_occlusion_from_outside_target_surface = false; |
| 4547 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 4548 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 4549 | smaller, |
| 4550 | false, |
| 4551 | gfx::Rect(0, 0, 100, 100), |
| 4552 | &has_occlusion_from_outside_target_surface)); |
| 4553 | EXPECT_FALSE(has_occlusion_from_outside_target_surface); |
| 4554 | } |
[email protected] | bae49f2c | 2013-01-18 12:14:31 | [diff] [blame] | 4555 | }; |
| 4556 | |
| 4557 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipIsExternalOcclusion) |
| 4558 | |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 4559 | template <class Types> |
| 4560 | class OcclusionTrackerTestPreventOcclusionOnLayer |
| 4561 | : public OcclusionTrackerTest<Types> { |
| 4562 | protected: |
| 4563 | explicit OcclusionTrackerTestPreventOcclusionOnLayer(bool opaque_layers) |
| 4564 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4565 | void RunMyTest() { |
| 4566 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4567 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 4568 | typename Types::LayerType* unprevented = this->CreateDrawingLayer( |
| 4569 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false); |
| 4570 | typename Types::LayerType* prevented = this->CreateDrawingLayer( |
| 4571 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false); |
| 4572 | typename Types::LayerType* occluding = this->CreateDrawingLayer( |
| 4573 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), true); |
| 4574 | this->CalcDrawEtc(parent); |
| 4575 | |
| 4576 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4577 | typename Types::RenderSurfaceType> occlusion( |
| 4578 | gfx::Rect(0, 0, 1000, 1000)); |
| 4579 | bool external_occlusion = false; |
| 4580 | |
| 4581 | this->VisitLayer(occluding, &occlusion); |
| 4582 | this->EnterLayer(prevented, &occlusion, true); |
| 4583 | |
| 4584 | // This layer is not occluded because it is prevented. |
| 4585 | EXPECT_FALSE(occlusion.OccludedLayer(prevented, |
| 4586 | gfx::Rect(50, 50), |
| 4587 | &external_occlusion)); |
| 4588 | EXPECT_FALSE(external_occlusion); |
| 4589 | |
| 4590 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 4591 | occlusion.UnoccludedLayerContentRect( |
| 4592 | prevented, |
| 4593 | gfx::Rect(50, 50), |
| 4594 | &external_occlusion).ToString()); |
| 4595 | EXPECT_FALSE(external_occlusion); |
| 4596 | |
| 4597 | this->LeaveLayer(prevented, &occlusion); |
| 4598 | this->EnterLayer(unprevented, &occlusion, false); |
| 4599 | |
| 4600 | // This layer is fully occluded. |
| 4601 | EXPECT_TRUE(occlusion.OccludedLayer(unprevented, |
| 4602 | gfx::Rect(50, 50), |
| 4603 | &external_occlusion)); |
| 4604 | EXPECT_FALSE(external_occlusion); |
| 4605 | |
| 4606 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4607 | occlusion.UnoccludedLayerContentRect( |
| 4608 | unprevented, |
| 4609 | gfx::Rect(50, 50), |
| 4610 | &external_occlusion).ToString()); |
| 4611 | EXPECT_FALSE(external_occlusion); |
| 4612 | |
| 4613 | this->LeaveLayer(unprevented, &occlusion); |
| 4614 | } |
| 4615 | }; |
| 4616 | |
| 4617 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestPreventOcclusionOnLayer) |
| 4618 | |
| 4619 | template <class Types> |
| 4620 | class OcclusionTrackerTestPreventOcclusionOnContributingSurface |
| 4621 | : public OcclusionTrackerTest<Types> { |
| 4622 | protected: |
| 4623 | explicit OcclusionTrackerTestPreventOcclusionOnContributingSurface( |
| 4624 | bool opaque_layers) |
| 4625 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4626 | void RunMyTest() { |
| 4627 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4628 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 4629 | typename Types::LayerType* unprevented = this->CreateDrawingSurface( |
| 4630 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false); |
| 4631 | typename Types::LayerType* prevented = this->CreateDrawingSurface( |
| 4632 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false); |
| 4633 | typename Types::LayerType* occluding = this->CreateDrawingLayer( |
| 4634 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), true); |
| 4635 | this->CalcDrawEtc(parent); |
| 4636 | |
| 4637 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4638 | typename Types::RenderSurfaceType> occlusion( |
| 4639 | gfx::Rect(0, 0, 1000, 1000)); |
| 4640 | bool external_occlusion = false; |
| 4641 | |
| 4642 | this->VisitLayer(occluding, &occlusion); |
| 4643 | this->EnterLayer(prevented, &occlusion, true); |
| 4644 | |
| 4645 | // This layer is not occluded because it is prevented. |
| 4646 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 4647 | occlusion.UnoccludedLayerContentRect( |
| 4648 | prevented, |
| 4649 | gfx::Rect(50, 50), |
| 4650 | &external_occlusion).ToString()); |
| 4651 | EXPECT_FALSE(external_occlusion); |
| 4652 | |
| 4653 | this->LeaveLayer(prevented, &occlusion); |
| 4654 | this->EnterContributingSurface(prevented, &occlusion, true); |
| 4655 | |
| 4656 | // This contributing surface is not occluded because it is prevented. |
| 4657 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 4658 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 4659 | prevented, |
| 4660 | false, // is_replica |
| 4661 | gfx::Rect(50, 50), |
| 4662 | &external_occlusion).ToString()); |
| 4663 | EXPECT_FALSE(external_occlusion); |
| 4664 | |
| 4665 | this->LeaveContributingSurface(prevented, &occlusion); |
| 4666 | this->EnterLayer(unprevented, &occlusion, false); |
| 4667 | |
| 4668 | // This layer is fully occluded from outside its surface. |
| 4669 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4670 | occlusion.UnoccludedLayerContentRect( |
| 4671 | unprevented, |
| 4672 | gfx::Rect(50, 50), |
| 4673 | &external_occlusion).ToString()); |
| 4674 | EXPECT_TRUE(external_occlusion); |
| 4675 | |
| 4676 | this->LeaveLayer(unprevented, &occlusion); |
| 4677 | this->EnterContributingSurface(unprevented, &occlusion, false); |
| 4678 | |
| 4679 | // This contributing surface is fully occluded. |
| 4680 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4681 | occlusion.UnoccludedContributingSurfaceContentRect( |
| 4682 | unprevented, |
| 4683 | false, // is_replica |
| 4684 | gfx::Rect(50, 50), |
| 4685 | &external_occlusion).ToString()); |
| 4686 | EXPECT_FALSE(external_occlusion); |
| 4687 | |
| 4688 | this->LeaveContributingSurface(unprevented, &occlusion); |
| 4689 | } |
| 4690 | }; |
| 4691 | |
| 4692 | ALL_OCCLUSIONTRACKER_TEST( |
| 4693 | OcclusionTrackerTestPreventOcclusionOnContributingSurface) |
| 4694 | |
| 4695 | template <class Types> |
| 4696 | class OcclusionTrackerTestPreventOcclusionByClipping |
| 4697 | : public OcclusionTrackerTest<Types> { |
| 4698 | protected: |
| 4699 | explicit OcclusionTrackerTestPreventOcclusionByClipping(bool opaque_layers) |
| 4700 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4701 | void RunMyTest() { |
| 4702 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4703 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 4704 | typename Types::LayerType* unprevented = this->CreateDrawingLayer( |
| 4705 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false); |
| 4706 | typename Types::LayerType* prevented = this->CreateDrawingLayer( |
| 4707 | parent, this->identity_matrix, gfx::PointF(), gfx::Size(50, 50), false); |
| 4708 | this->CalcDrawEtc(parent); |
| 4709 | |
| 4710 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4711 | typename Types::RenderSurfaceType> occlusion( |
| 4712 | gfx::Rect(0, 0, 10, 10)); |
| 4713 | bool external_occlusion = false; |
| 4714 | |
| 4715 | this->EnterLayer(prevented, &occlusion, true); |
| 4716 | |
| 4717 | // This layer is not occluded because it is prevented. |
| 4718 | EXPECT_FALSE(occlusion.OccludedLayer(prevented, |
| 4719 | gfx::Rect(50, 50), |
| 4720 | &external_occlusion)); |
| 4721 | EXPECT_FALSE(external_occlusion); |
| 4722 | |
| 4723 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 4724 | occlusion.UnoccludedLayerContentRect( |
| 4725 | prevented, |
| 4726 | gfx::Rect(50, 50), |
| 4727 | &external_occlusion).ToString()); |
| 4728 | EXPECT_FALSE(external_occlusion); |
| 4729 | |
| 4730 | this->LeaveLayer(prevented, &occlusion); |
| 4731 | this->EnterLayer(unprevented, &occlusion, false); |
| 4732 | |
| 4733 | // This layer is clipped by the screen space clip rect. |
| 4734 | EXPECT_EQ(gfx::Rect(10, 10).ToString(), |
| 4735 | occlusion.UnoccludedLayerContentRect( |
| 4736 | unprevented, |
| 4737 | gfx::Rect(50, 50), |
| 4738 | &external_occlusion).ToString()); |
| 4739 | EXPECT_TRUE(external_occlusion); |
| 4740 | |
| 4741 | this->LeaveLayer(unprevented, &occlusion); |
| 4742 | } |
| 4743 | }; |
| 4744 | |
| 4745 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestPreventOcclusionByClipping) |
| 4746 | |
[email protected] | 1a5d9ce | 2013-04-30 01:31:09 | [diff] [blame] | 4747 | template <class Types> |
| 4748 | class OcclusionTrackerTestScaledLayerIsClipped |
| 4749 | : public OcclusionTrackerTest<Types> { |
| 4750 | protected: |
| 4751 | explicit OcclusionTrackerTestScaledLayerIsClipped(bool opaque_layers) |
| 4752 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4753 | void RunMyTest() { |
| 4754 | gfx::Transform scale_transform; |
| 4755 | scale_transform.Scale(512.0, 512.0); |
| 4756 | |
| 4757 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4758 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 4759 | typename Types::LayerType* clip = this->CreateLayer(parent, |
| 4760 | this->identity_matrix, |
| 4761 | gfx::PointF(10.f, 10.f), |
| 4762 | gfx::Size(50, 50)); |
| 4763 | clip->SetMasksToBounds(true); |
| 4764 | typename Types::LayerType* scale = this->CreateLayer( |
| 4765 | clip, scale_transform, gfx::PointF(), gfx::Size(1, 1)); |
| 4766 | typename Types::LayerType* scaled = this->CreateDrawingLayer( |
| 4767 | scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true); |
| 4768 | this->CalcDrawEtc(parent); |
| 4769 | |
| 4770 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4771 | typename Types::RenderSurfaceType> occlusion( |
| 4772 | gfx::Rect(0, 0, 1000, 1000)); |
| 4773 | |
| 4774 | this->VisitLayer(scaled, &occlusion); |
| 4775 | |
| 4776 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4777 | occlusion.occlusion_from_outside_target().ToString()); |
| 4778 | EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(), |
| 4779 | occlusion.occlusion_from_inside_target().ToString()); |
| 4780 | } |
| 4781 | }; |
| 4782 | |
| 4783 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerIsClipped) |
| 4784 | |
| 4785 | template <class Types> |
| 4786 | class OcclusionTrackerTestScaledLayerInSurfaceIsClipped |
| 4787 | : public OcclusionTrackerTest<Types> { |
| 4788 | protected: |
| 4789 | explicit OcclusionTrackerTestScaledLayerInSurfaceIsClipped(bool opaque_layers) |
| 4790 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4791 | void RunMyTest() { |
| 4792 | gfx::Transform scale_transform; |
| 4793 | scale_transform.Scale(512.0, 512.0); |
| 4794 | |
| 4795 | typename Types::ContentLayerType* parent = this->CreateRoot( |
| 4796 | this->identity_matrix, gfx::PointF(), gfx::Size(400, 400)); |
| 4797 | typename Types::LayerType* clip = this->CreateLayer(parent, |
| 4798 | this->identity_matrix, |
| 4799 | gfx::PointF(10.f, 10.f), |
| 4800 | gfx::Size(50, 50)); |
| 4801 | clip->SetMasksToBounds(true); |
| 4802 | typename Types::LayerType* surface = this->CreateDrawingSurface( |
| 4803 | clip, this->identity_matrix, gfx::PointF(), gfx::Size(400, 30), false); |
| 4804 | typename Types::LayerType* scale = this->CreateLayer( |
| 4805 | surface, scale_transform, gfx::PointF(), gfx::Size(1, 1)); |
| 4806 | typename Types::LayerType* scaled = this->CreateDrawingLayer( |
| 4807 | scale, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500), true); |
| 4808 | this->CalcDrawEtc(parent); |
| 4809 | |
| 4810 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4811 | typename Types::RenderSurfaceType> occlusion( |
| 4812 | gfx::Rect(0, 0, 1000, 1000)); |
| 4813 | |
| 4814 | this->VisitLayer(scaled, &occlusion); |
| 4815 | this->VisitLayer(surface, &occlusion); |
| 4816 | this->VisitContributingSurface(surface, &occlusion); |
| 4817 | |
| 4818 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4819 | occlusion.occlusion_from_outside_target().ToString()); |
| 4820 | EXPECT_EQ(gfx::Rect(10, 10, 50, 50).ToString(), |
| 4821 | occlusion.occlusion_from_inside_target().ToString()); |
| 4822 | } |
| 4823 | }; |
| 4824 | |
| 4825 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledLayerInSurfaceIsClipped) |
| 4826 | |
[email protected] | 5b54b97 | 2013-07-26 13:25:42 | [diff] [blame^] | 4827 | template <class Types> |
| 4828 | class OcclusionTrackerTestCopyRequestDoesOcclude |
| 4829 | : public OcclusionTrackerTest<Types> { |
| 4830 | protected: |
| 4831 | explicit OcclusionTrackerTestCopyRequestDoesOcclude(bool opaque_layers) |
| 4832 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4833 | void RunMyTest() { |
| 4834 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 4835 | this->identity_matrix, gfx::Point(), gfx::Size(400, 400)); |
| 4836 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 4837 | root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true); |
| 4838 | typename Types::LayerType* copy = this->CreateLayer(parent, |
| 4839 | this->identity_matrix, |
| 4840 | gfx::Point(100, 0), |
| 4841 | gfx::Size(200, 400)); |
| 4842 | this->AddCopyRequest(copy); |
| 4843 | typename Types::LayerType* copy_child = this->CreateDrawingLayer( |
| 4844 | copy, |
| 4845 | this->identity_matrix, |
| 4846 | gfx::PointF(), |
| 4847 | gfx::Size(200, 400), |
| 4848 | true); |
| 4849 | this->CalcDrawEtc(root); |
| 4850 | |
| 4851 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4852 | typename Types::RenderSurfaceType> occlusion( |
| 4853 | gfx::Rect(0, 0, 1000, 1000)); |
| 4854 | |
| 4855 | this->VisitLayer(copy_child, &occlusion); |
| 4856 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4857 | occlusion.occlusion_from_outside_target().ToString()); |
| 4858 | EXPECT_EQ(gfx::Rect(200, 400).ToString(), |
| 4859 | occlusion.occlusion_from_inside_target().ToString()); |
| 4860 | |
| 4861 | // CopyRequests cause the layer to own a surface. |
| 4862 | this->VisitContributingSurface(copy, &occlusion); |
| 4863 | |
| 4864 | // The occlusion from the copy should be kept. |
| 4865 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4866 | occlusion.occlusion_from_outside_target().ToString()); |
| 4867 | EXPECT_EQ(gfx::Rect(100, 0, 200, 400).ToString(), |
| 4868 | occlusion.occlusion_from_inside_target().ToString()); |
| 4869 | } |
| 4870 | }; |
| 4871 | |
| 4872 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude) |
| 4873 | |
| 4874 | template <class Types> |
| 4875 | class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude |
| 4876 | : public OcclusionTrackerTest<Types> { |
| 4877 | protected: |
| 4878 | explicit OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude( |
| 4879 | bool opaque_layers) |
| 4880 | : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 4881 | void RunMyTest() { |
| 4882 | typename Types::ContentLayerType* root = this->CreateRoot( |
| 4883 | this->identity_matrix, gfx::Point(), gfx::Size(400, 400)); |
| 4884 | typename Types::ContentLayerType* parent = this->CreateDrawingLayer( |
| 4885 | root, this->identity_matrix, gfx::Point(), gfx::Size(400, 400), true); |
| 4886 | typename Types::LayerType* hide = this->CreateLayer( |
| 4887 | parent, this->identity_matrix, gfx::Point(), gfx::Size()); |
| 4888 | typename Types::LayerType* copy = this->CreateLayer( |
| 4889 | hide, this->identity_matrix, gfx::Point(100, 0), gfx::Size(200, 400)); |
| 4890 | this->AddCopyRequest(copy); |
| 4891 | typename Types::LayerType* copy_child = this->CreateDrawingLayer( |
| 4892 | copy, this->identity_matrix, gfx::PointF(), gfx::Size(200, 400), true); |
| 4893 | |
| 4894 | // The |copy| layer is hidden but since it is being copied, it will be |
| 4895 | // drawn. |
| 4896 | hide->SetHideLayerAndSubtree(true); |
| 4897 | |
| 4898 | this->CalcDrawEtc(root); |
| 4899 | |
| 4900 | TestOcclusionTrackerWithClip<typename Types::LayerType, |
| 4901 | typename Types::RenderSurfaceType> occlusion( |
| 4902 | gfx::Rect(0, 0, 1000, 1000)); |
| 4903 | |
| 4904 | this->VisitLayer(copy_child, &occlusion); |
| 4905 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4906 | occlusion.occlusion_from_outside_target().ToString()); |
| 4907 | EXPECT_EQ(gfx::Rect(200, 400).ToString(), |
| 4908 | occlusion.occlusion_from_inside_target().ToString()); |
| 4909 | |
| 4910 | // CopyRequests cause the layer to own a surface. |
| 4911 | this->VisitContributingSurface(copy, &occlusion); |
| 4912 | |
| 4913 | // The occlusion from the copy should be dropped since it is hidden. |
| 4914 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4915 | occlusion.occlusion_from_outside_target().ToString()); |
| 4916 | EXPECT_EQ(gfx::Rect().ToString(), |
| 4917 | occlusion.occlusion_from_inside_target().ToString()); |
| 4918 | } |
| 4919 | }; |
| 4920 | |
| 4921 | ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude) |
| 4922 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 4923 | } // namespace |
| 4924 | } // namespace cc |