| OLD | NEW |
| (Empty) |
| 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 | |
| 5 #include "cc/trees/layer_tree_host.h" | |
| 6 | |
| 7 #include "cc/layers/layer.h" | |
| 8 #include "cc/layers/picture_layer.h" | |
| 9 #include "cc/test/fake_content_layer_client.h" | |
| 10 #include "cc/test/layer_tree_test.h" | |
| 11 #include "cc/trees/layer_tree_impl.h" | |
| 12 | |
| 13 namespace cc { | |
| 14 namespace { | |
| 15 | |
| 16 #define EXPECT_OCCLUSION_EQ(expected, actual) \ | |
| 17 EXPECT_TRUE(expected.IsEqual(actual)) \ | |
| 18 << " Expected: " << expected.ToString() << std::endl \ | |
| 19 << " Actual: " << actual.ToString(); | |
| 20 | |
| 21 class LayerTreeHostOcclusionTest : public LayerTreeTest { | |
| 22 protected: | |
| 23 void InitializeSettings(LayerTreeSettings* settings) override { | |
| 24 settings->minimum_occlusion_tracking_size = gfx::Size(); | |
| 25 } | |
| 26 }; | |
| 27 | |
| 28 // Verify occlusion is set on the layer draw properties. | |
| 29 class LayerTreeHostOcclusionTestDrawPropertiesOnLayer | |
| 30 : public LayerTreeHostOcclusionTest { | |
| 31 public: | |
| 32 void SetupTree() override { | |
| 33 scoped_refptr<Layer> root = Layer::Create(); | |
| 34 root->SetBounds(gfx::Size(100, 100)); | |
| 35 root->SetIsDrawable(true); | |
| 36 | |
| 37 scoped_refptr<Layer> child = Layer::Create(); | |
| 38 child->SetBounds(gfx::Size(50, 60)); | |
| 39 child->SetPosition(gfx::PointF(10.f, 5.5f)); | |
| 40 child->SetContentsOpaque(true); | |
| 41 child->SetIsDrawable(true); | |
| 42 root->AddChild(child); | |
| 43 | |
| 44 layer_tree_host()->SetRootLayer(root); | |
| 45 LayerTreeTest::SetupTree(); | |
| 46 } | |
| 47 | |
| 48 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 49 | |
| 50 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | |
| 51 LayerImpl* root = impl->active_tree()->root_layer(); | |
| 52 LayerImpl* child = root->children()[0]; | |
| 53 | |
| 54 // Verify the draw properties are valid. | |
| 55 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); | |
| 56 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); | |
| 57 | |
| 58 EXPECT_OCCLUSION_EQ( | |
| 59 Occlusion(child->draw_transform(), SimpleEnclosedRegion(), | |
| 60 SimpleEnclosedRegion()), | |
| 61 child->draw_properties().occlusion_in_content_space); | |
| 62 EXPECT_OCCLUSION_EQ( | |
| 63 Occlusion(root->draw_transform(), SimpleEnclosedRegion(), | |
| 64 SimpleEnclosedRegion(gfx::Rect(10, 6, 50, 59))), | |
| 65 root->draw_properties().occlusion_in_content_space); | |
| 66 EndTest(); | |
| 67 } | |
| 68 | |
| 69 void AfterTest() override {} | |
| 70 }; | |
| 71 | |
| 72 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestDrawPropertiesOnLayer); | |
| 73 | |
| 74 // Verify occlusion is set on the render surfaces. | |
| 75 class LayerTreeHostOcclusionTestDrawPropertiesOnSurface | |
| 76 : public LayerTreeHostOcclusionTest { | |
| 77 public: | |
| 78 void SetupTree() override { | |
| 79 scoped_refptr<Layer> root = Layer::Create(); | |
| 80 root->SetBounds(gfx::Size(100, 100)); | |
| 81 root->SetIsDrawable(true); | |
| 82 | |
| 83 scoped_refptr<Layer> child = Layer::Create(); | |
| 84 child->SetBounds(gfx::Size(1, 1)); | |
| 85 child->SetPosition(gfx::PointF(10.f, 5.5f)); | |
| 86 child->SetIsDrawable(true); | |
| 87 child->SetForceRenderSurface(true); | |
| 88 root->AddChild(child); | |
| 89 | |
| 90 scoped_refptr<Layer> child2 = Layer::Create(); | |
| 91 child2->SetBounds(gfx::Size(10, 12)); | |
| 92 child2->SetPosition(gfx::PointF(13.f, 8.5f)); | |
| 93 child2->SetContentsOpaque(true); | |
| 94 child2->SetIsDrawable(true); | |
| 95 root->AddChild(child2); | |
| 96 | |
| 97 layer_tree_host()->SetRootLayer(root); | |
| 98 LayerTreeTest::SetupTree(); | |
| 99 } | |
| 100 | |
| 101 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 102 | |
| 103 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | |
| 104 LayerImpl* root = impl->active_tree()->root_layer(); | |
| 105 LayerImpl* child = root->children()[0]; | |
| 106 RenderSurfaceImpl* surface = child->render_surface(); | |
| 107 | |
| 108 // Verify the draw properties are valid. | |
| 109 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); | |
| 110 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); | |
| 111 EXPECT_EQ(child, child->render_target()); | |
| 112 | |
| 113 EXPECT_OCCLUSION_EQ( | |
| 114 Occlusion(surface->draw_transform(), SimpleEnclosedRegion(), | |
| 115 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))), | |
| 116 surface->occlusion_in_content_space()); | |
| 117 EndTest(); | |
| 118 } | |
| 119 | |
| 120 void AfterTest() override {} | |
| 121 }; | |
| 122 | |
| 123 SINGLE_AND_MULTI_THREAD_TEST_F( | |
| 124 LayerTreeHostOcclusionTestDrawPropertiesOnSurface); | |
| 125 | |
| 126 // Verify occlusion is set on mask layers. | |
| 127 class LayerTreeHostOcclusionTestDrawPropertiesOnMask | |
| 128 : public LayerTreeHostOcclusionTest { | |
| 129 public: | |
| 130 void SetupTree() override { | |
| 131 scoped_refptr<Layer> root = Layer::Create(); | |
| 132 root->SetBounds(gfx::Size(100, 100)); | |
| 133 root->SetIsDrawable(true); | |
| 134 | |
| 135 scoped_refptr<Layer> child = Layer::Create(); | |
| 136 child->SetBounds(gfx::Size(30, 40)); | |
| 137 child->SetPosition(gfx::PointF(10.f, 5.5f)); | |
| 138 child->SetIsDrawable(true); | |
| 139 root->AddChild(child); | |
| 140 | |
| 141 scoped_refptr<Layer> make_surface_bigger = Layer::Create(); | |
| 142 make_surface_bigger->SetBounds(gfx::Size(100, 100)); | |
| 143 make_surface_bigger->SetPosition(gfx::PointF(-10.f, -15.f)); | |
| 144 make_surface_bigger->SetIsDrawable(true); | |
| 145 child->AddChild(make_surface_bigger); | |
| 146 | |
| 147 scoped_refptr<Layer> mask = PictureLayer::Create(&client_); | |
| 148 mask->SetBounds(gfx::Size(30, 40)); | |
| 149 mask->SetIsDrawable(true); | |
| 150 child->SetMaskLayer(mask.get()); | |
| 151 | |
| 152 scoped_refptr<Layer> child2 = Layer::Create(); | |
| 153 child2->SetBounds(gfx::Size(10, 12)); | |
| 154 child2->SetPosition(gfx::PointF(13.f, 8.5f)); | |
| 155 child2->SetContentsOpaque(true); | |
| 156 child2->SetIsDrawable(true); | |
| 157 root->AddChild(child2); | |
| 158 | |
| 159 layer_tree_host()->SetRootLayer(root); | |
| 160 LayerTreeTest::SetupTree(); | |
| 161 } | |
| 162 | |
| 163 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 164 | |
| 165 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | |
| 166 LayerImpl* root = impl->active_tree()->root_layer(); | |
| 167 LayerImpl* child = root->children()[0]; | |
| 168 RenderSurfaceImpl* surface = child->render_surface(); | |
| 169 LayerImpl* mask = child->mask_layer(); | |
| 170 | |
| 171 // Verify the draw properties are valid. | |
| 172 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); | |
| 173 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); | |
| 174 EXPECT_EQ(child, child->render_target()); | |
| 175 | |
| 176 gfx::Transform transform = surface->draw_transform(); | |
| 177 transform.PreconcatTransform(child->draw_transform()); | |
| 178 | |
| 179 EXPECT_OCCLUSION_EQ( | |
| 180 Occlusion(transform, SimpleEnclosedRegion(), | |
| 181 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))), | |
| 182 mask->draw_properties().occlusion_in_content_space); | |
| 183 EndTest(); | |
| 184 } | |
| 185 | |
| 186 void AfterTest() override {} | |
| 187 | |
| 188 FakeContentLayerClient client_; | |
| 189 }; | |
| 190 | |
| 191 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestDrawPropertiesOnMask); | |
| 192 | |
| 193 // Verify occlusion is set to empty inside the subtree of a replica. This is | |
| 194 // done because the tile system does not know about replicas, and so would not | |
| 195 // know that something is unoccluded on the replica even though it's occluded on | |
| 196 // the original. | |
| 197 class LayerTreeHostOcclusionTestDrawPropertiesInsideReplica | |
| 198 : public LayerTreeHostOcclusionTest { | |
| 199 public: | |
| 200 void SetupTree() override { | |
| 201 scoped_refptr<Layer> root = Layer::Create(); | |
| 202 root->SetBounds(gfx::Size(100, 100)); | |
| 203 root->SetIsDrawable(true); | |
| 204 | |
| 205 scoped_refptr<Layer> child = Layer::Create(); | |
| 206 child->SetBounds(gfx::Size(1, 1)); | |
| 207 child->SetPosition(gfx::PointF(10.f, 5.5f)); | |
| 208 child->SetIsDrawable(true); | |
| 209 child->SetForceRenderSurface(true); | |
| 210 root->AddChild(child); | |
| 211 | |
| 212 scoped_refptr<Layer> replica = Layer::Create(); | |
| 213 gfx::Transform translate; | |
| 214 translate.Translate(20.f, 4.f); | |
| 215 replica->SetTransform(translate); | |
| 216 child->SetReplicaLayer(replica.get()); | |
| 217 | |
| 218 scoped_refptr<Layer> mask = PictureLayer::Create(&client_); | |
| 219 mask->SetBounds(gfx::Size(30, 40)); | |
| 220 mask->SetIsDrawable(true); | |
| 221 child->SetMaskLayer(mask.get()); | |
| 222 | |
| 223 scoped_refptr<Layer> child2 = Layer::Create(); | |
| 224 child2->SetBounds(gfx::Size(10, 12)); | |
| 225 child2->SetPosition(gfx::PointF(13.f, 8.5f)); | |
| 226 child2->SetContentsOpaque(true); | |
| 227 child2->SetIsDrawable(true); | |
| 228 root->AddChild(child2); | |
| 229 | |
| 230 layer_tree_host()->SetRootLayer(root); | |
| 231 LayerTreeTest::SetupTree(); | |
| 232 } | |
| 233 | |
| 234 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 235 | |
| 236 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | |
| 237 LayerImpl* root = impl->active_tree()->root_layer(); | |
| 238 LayerImpl* child = root->children()[0]; | |
| 239 RenderSurfaceImpl* surface = child->render_surface(); | |
| 240 LayerImpl* mask = child->mask_layer(); | |
| 241 | |
| 242 // Verify the draw properties are valid. | |
| 243 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); | |
| 244 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); | |
| 245 EXPECT_EQ(child, child->render_target()); | |
| 246 | |
| 247 // No occlusion from on child, which is part of the replica. | |
| 248 EXPECT_OCCLUSION_EQ(Occlusion(), | |
| 249 child->draw_properties().occlusion_in_content_space); | |
| 250 // Occlusion on the surface is okay. | |
| 251 EXPECT_OCCLUSION_EQ( | |
| 252 Occlusion(surface->draw_transform(), SimpleEnclosedRegion(), | |
| 253 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))), | |
| 254 surface->occlusion_in_content_space()); | |
| 255 // No occlusion on the replica'd mask. | |
| 256 EXPECT_OCCLUSION_EQ(Occlusion(), | |
| 257 mask->draw_properties().occlusion_in_content_space); | |
| 258 EndTest(); | |
| 259 } | |
| 260 | |
| 261 void AfterTest() override {} | |
| 262 | |
| 263 FakeContentLayerClient client_; | |
| 264 }; | |
| 265 | |
| 266 SINGLE_AND_MULTI_THREAD_TEST_F( | |
| 267 LayerTreeHostOcclusionTestDrawPropertiesInsideReplica); | |
| 268 | |
| 269 } // namespace | |
| 270 } // namespace cc | |
| OLD | NEW |