| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "cc/layers/layer.h" | 7 #include "cc/layers/layer.h" |
| 8 #include "cc/layers/picture_layer.h" | 8 #include "cc/layers/picture_layer.h" |
| 9 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
| 10 #include "cc/test/layer_tree_test.h" | 10 #include "cc/test/layer_tree_test.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 // Verify occlusion is set on the layer draw properties. | 28 // Verify occlusion is set on the layer draw properties. |
| 29 class LayerTreeHostOcclusionTestDrawPropertiesOnLayer | 29 class LayerTreeHostOcclusionTestDrawPropertiesOnLayer |
| 30 : public LayerTreeHostOcclusionTest { | 30 : public LayerTreeHostOcclusionTest { |
| 31 public: | 31 public: |
| 32 void SetupTree() override { | 32 void SetupTree() override { |
| 33 scoped_refptr<Layer> root = Layer::Create(); | 33 scoped_refptr<Layer> root = Layer::Create(); |
| 34 root->SetBounds(gfx::Size(100, 100)); | 34 root->SetBounds(gfx::Size(100, 100)); |
| 35 root->SetIsDrawable(true); | 35 root->SetIsDrawable(true); |
| 36 | 36 |
| 37 scoped_refptr<Layer> child = Layer::Create(); | 37 child_ = Layer::Create(); |
| 38 child->SetBounds(gfx::Size(50, 60)); | 38 child_->SetBounds(gfx::Size(50, 60)); |
| 39 child->SetPosition(gfx::PointF(10.f, 5.5f)); | 39 child_->SetPosition(gfx::PointF(10.f, 5.5f)); |
| 40 child->SetContentsOpaque(true); | 40 child_->SetContentsOpaque(true); |
| 41 child->SetIsDrawable(true); | 41 child_->SetIsDrawable(true); |
| 42 root->AddChild(child); | 42 root->AddChild(child_); |
| 43 | 43 |
| 44 layer_tree_host()->SetRootLayer(root); | 44 layer_tree_host()->SetRootLayer(root); |
| 45 LayerTreeTest::SetupTree(); | 45 LayerTreeTest::SetupTree(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 48 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 49 | 49 |
| 50 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 50 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 51 LayerImpl* root = impl->active_tree()->root_layer(); | 51 LayerImpl* root = impl->active_tree()->root_layer(); |
| 52 LayerImpl* child = root->children()[0]; | 52 LayerImpl* child = impl->active_tree()->LayerById(child_->id()); |
| 53 | 53 |
| 54 // Verify the draw properties are valid. | 54 // Verify the draw properties are valid. |
| 55 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); | 55 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); |
| 56 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); | 56 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); |
| 57 | 57 |
| 58 EXPECT_OCCLUSION_EQ( | 58 EXPECT_OCCLUSION_EQ( |
| 59 Occlusion(child->DrawTransform(), SimpleEnclosedRegion(), | 59 Occlusion(child->DrawTransform(), SimpleEnclosedRegion(), |
| 60 SimpleEnclosedRegion()), | 60 SimpleEnclosedRegion()), |
| 61 child->draw_properties().occlusion_in_content_space); | 61 child->draw_properties().occlusion_in_content_space); |
| 62 EXPECT_OCCLUSION_EQ( | 62 EXPECT_OCCLUSION_EQ( |
| 63 Occlusion(root->DrawTransform(), SimpleEnclosedRegion(), | 63 Occlusion(root->DrawTransform(), SimpleEnclosedRegion(), |
| 64 SimpleEnclosedRegion(gfx::Rect(10, 6, 50, 59))), | 64 SimpleEnclosedRegion(gfx::Rect(10, 6, 50, 59))), |
| 65 root->draw_properties().occlusion_in_content_space); | 65 root->draw_properties().occlusion_in_content_space); |
| 66 EndTest(); | 66 EndTest(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void AfterTest() override {} | 69 void AfterTest() override {} |
| 70 |
| 71 private: |
| 72 scoped_refptr<Layer> child_; |
| 70 }; | 73 }; |
| 71 | 74 |
| 72 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestDrawPropertiesOnLayer); | 75 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestDrawPropertiesOnLayer); |
| 73 | 76 |
| 74 // Verify occlusion is set on the render surfaces. | 77 // Verify occlusion is set on the render surfaces. |
| 75 class LayerTreeHostOcclusionTestDrawPropertiesOnSurface | 78 class LayerTreeHostOcclusionTestDrawPropertiesOnSurface |
| 76 : public LayerTreeHostOcclusionTest { | 79 : public LayerTreeHostOcclusionTest { |
| 77 public: | 80 public: |
| 78 void SetupTree() override { | 81 void SetupTree() override { |
| 79 scoped_refptr<Layer> root = Layer::Create(); | 82 scoped_refptr<Layer> root = Layer::Create(); |
| 80 root->SetBounds(gfx::Size(100, 100)); | 83 root->SetBounds(gfx::Size(100, 100)); |
| 81 root->SetIsDrawable(true); | 84 root->SetIsDrawable(true); |
| 82 | 85 |
| 83 scoped_refptr<Layer> child = Layer::Create(); | 86 child_ = Layer::Create(); |
| 84 child->SetBounds(gfx::Size(1, 1)); | 87 child_->SetBounds(gfx::Size(1, 1)); |
| 85 child->SetPosition(gfx::PointF(10.f, 5.5f)); | 88 child_->SetPosition(gfx::PointF(10.f, 5.5f)); |
| 86 child->SetIsDrawable(true); | 89 child_->SetIsDrawable(true); |
| 87 child->SetForceRenderSurface(true); | 90 child_->SetForceRenderSurface(true); |
| 88 root->AddChild(child); | 91 root->AddChild(child_); |
| 89 | 92 |
| 90 scoped_refptr<Layer> child2 = Layer::Create(); | 93 scoped_refptr<Layer> child2 = Layer::Create(); |
| 91 child2->SetBounds(gfx::Size(10, 12)); | 94 child2->SetBounds(gfx::Size(10, 12)); |
| 92 child2->SetPosition(gfx::PointF(13.f, 8.5f)); | 95 child2->SetPosition(gfx::PointF(13.f, 8.5f)); |
| 93 child2->SetContentsOpaque(true); | 96 child2->SetContentsOpaque(true); |
| 94 child2->SetIsDrawable(true); | 97 child2->SetIsDrawable(true); |
| 95 root->AddChild(child2); | 98 root->AddChild(child2); |
| 96 | 99 |
| 97 layer_tree_host()->SetRootLayer(root); | 100 layer_tree_host()->SetRootLayer(root); |
| 98 LayerTreeTest::SetupTree(); | 101 LayerTreeTest::SetupTree(); |
| 99 } | 102 } |
| 100 | 103 |
| 101 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 104 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 102 | 105 |
| 103 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 106 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 104 LayerImpl* root = impl->active_tree()->root_layer(); | 107 LayerImpl* root = impl->active_tree()->root_layer(); |
| 105 LayerImpl* child = root->children()[0]; | 108 LayerImpl* child = impl->active_tree()->LayerById(child_->id()); |
| 106 RenderSurfaceImpl* surface = child->render_surface(); | 109 RenderSurfaceImpl* surface = child->render_surface(); |
| 107 | 110 |
| 108 // Verify the draw properties are valid. | 111 // Verify the draw properties are valid. |
| 109 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); | 112 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); |
| 110 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); | 113 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); |
| 111 EXPECT_TRUE(child->has_render_surface()); | 114 EXPECT_TRUE(child->has_render_surface()); |
| 112 EXPECT_EQ(child->render_surface(), child->render_target()); | 115 EXPECT_EQ(child->render_surface(), child->render_target()); |
| 113 | 116 |
| 114 EXPECT_OCCLUSION_EQ( | 117 EXPECT_OCCLUSION_EQ( |
| 115 Occlusion(surface->draw_transform(), SimpleEnclosedRegion(), | 118 Occlusion(surface->draw_transform(), SimpleEnclosedRegion(), |
| 116 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))), | 119 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))), |
| 117 surface->occlusion_in_content_space()); | 120 surface->occlusion_in_content_space()); |
| 118 EndTest(); | 121 EndTest(); |
| 119 } | 122 } |
| 120 | 123 |
| 121 void AfterTest() override {} | 124 void AfterTest() override {} |
| 125 |
| 126 private: |
| 127 scoped_refptr<Layer> child_; |
| 122 }; | 128 }; |
| 123 | 129 |
| 124 SINGLE_AND_MULTI_THREAD_TEST_F( | 130 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 125 LayerTreeHostOcclusionTestDrawPropertiesOnSurface); | 131 LayerTreeHostOcclusionTestDrawPropertiesOnSurface); |
| 126 | 132 |
| 127 // Verify occlusion is set on mask layers. | 133 // Verify occlusion is set on mask layers. |
| 128 class LayerTreeHostOcclusionTestDrawPropertiesOnMask | 134 class LayerTreeHostOcclusionTestDrawPropertiesOnMask |
| 129 : public LayerTreeHostOcclusionTest { | 135 : public LayerTreeHostOcclusionTest { |
| 130 public: | 136 public: |
| 131 void SetupTree() override { | 137 void SetupTree() override { |
| 132 scoped_refptr<Layer> root = Layer::Create(); | 138 scoped_refptr<Layer> root = Layer::Create(); |
| 133 root->SetBounds(gfx::Size(100, 100)); | 139 root->SetBounds(gfx::Size(100, 100)); |
| 134 root->SetIsDrawable(true); | 140 root->SetIsDrawable(true); |
| 135 | 141 |
| 136 scoped_refptr<Layer> child = Layer::Create(); | 142 child_ = Layer::Create(); |
| 137 child->SetBounds(gfx::Size(30, 40)); | 143 child_->SetBounds(gfx::Size(30, 40)); |
| 138 child->SetPosition(gfx::PointF(10.f, 5.5f)); | 144 child_->SetPosition(gfx::PointF(10.f, 5.5f)); |
| 139 child->SetIsDrawable(true); | 145 child_->SetIsDrawable(true); |
| 140 root->AddChild(child); | 146 root->AddChild(child_); |
| 141 | 147 |
| 142 scoped_refptr<Layer> make_surface_bigger = Layer::Create(); | 148 scoped_refptr<Layer> make_surface_bigger = Layer::Create(); |
| 143 make_surface_bigger->SetBounds(gfx::Size(100, 100)); | 149 make_surface_bigger->SetBounds(gfx::Size(100, 100)); |
| 144 make_surface_bigger->SetPosition(gfx::PointF(-10.f, -15.f)); | 150 make_surface_bigger->SetPosition(gfx::PointF(-10.f, -15.f)); |
| 145 make_surface_bigger->SetIsDrawable(true); | 151 make_surface_bigger->SetIsDrawable(true); |
| 146 child->AddChild(make_surface_bigger); | 152 child_->AddChild(make_surface_bigger); |
| 147 | 153 |
| 148 scoped_refptr<Layer> mask = PictureLayer::Create(&client_); | 154 scoped_refptr<Layer> mask = PictureLayer::Create(&client_); |
| 149 mask->SetBounds(gfx::Size(30, 40)); | 155 mask->SetBounds(gfx::Size(30, 40)); |
| 150 mask->SetIsDrawable(true); | 156 mask->SetIsDrawable(true); |
| 151 child->SetMaskLayer(mask.get()); | 157 child_->SetMaskLayer(mask.get()); |
| 152 | 158 |
| 153 scoped_refptr<Layer> child2 = Layer::Create(); | 159 scoped_refptr<Layer> child2 = Layer::Create(); |
| 154 child2->SetBounds(gfx::Size(10, 12)); | 160 child2->SetBounds(gfx::Size(10, 12)); |
| 155 child2->SetPosition(gfx::PointF(13.f, 8.5f)); | 161 child2->SetPosition(gfx::PointF(13.f, 8.5f)); |
| 156 child2->SetContentsOpaque(true); | 162 child2->SetContentsOpaque(true); |
| 157 child2->SetIsDrawable(true); | 163 child2->SetIsDrawable(true); |
| 158 root->AddChild(child2); | 164 root->AddChild(child2); |
| 159 | 165 |
| 160 layer_tree_host()->SetRootLayer(root); | 166 layer_tree_host()->SetRootLayer(root); |
| 161 LayerTreeTest::SetupTree(); | 167 LayerTreeTest::SetupTree(); |
| 162 client_.set_bounds(root->bounds()); | 168 client_.set_bounds(root->bounds()); |
| 163 } | 169 } |
| 164 | 170 |
| 165 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 171 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 166 | 172 |
| 167 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 173 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 168 LayerImpl* root = impl->active_tree()->root_layer(); | 174 LayerImpl* root = impl->active_tree()->root_layer(); |
| 169 LayerImpl* child = root->children()[0]; | 175 LayerImpl* child = impl->active_tree()->LayerById(child_->id()); |
| 170 RenderSurfaceImpl* surface = child->render_surface(); | 176 RenderSurfaceImpl* surface = child->render_surface(); |
| 171 LayerImpl* mask = child->mask_layer(); | 177 LayerImpl* mask = child->mask_layer(); |
| 172 | 178 |
| 173 // Verify the draw properties are valid. | 179 // Verify the draw properties are valid. |
| 174 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); | 180 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); |
| 175 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); | 181 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); |
| 176 EXPECT_TRUE(child->has_render_surface()); | 182 EXPECT_TRUE(child->has_render_surface()); |
| 177 EXPECT_EQ(child->render_surface(), child->render_target()); | 183 EXPECT_EQ(child->render_surface(), child->render_target()); |
| 178 | 184 |
| 179 gfx::Transform transform = surface->draw_transform(); | 185 gfx::Transform transform = surface->draw_transform(); |
| 180 transform.PreconcatTransform(child->DrawTransform()); | 186 transform.PreconcatTransform(child->DrawTransform()); |
| 181 | 187 |
| 182 EXPECT_OCCLUSION_EQ( | 188 EXPECT_OCCLUSION_EQ( |
| 183 Occlusion(transform, SimpleEnclosedRegion(), | 189 Occlusion(transform, SimpleEnclosedRegion(), |
| 184 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))), | 190 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))), |
| 185 mask->draw_properties().occlusion_in_content_space); | 191 mask->draw_properties().occlusion_in_content_space); |
| 186 EndTest(); | 192 EndTest(); |
| 187 } | 193 } |
| 188 | 194 |
| 189 void AfterTest() override {} | 195 void AfterTest() override {} |
| 190 | 196 |
| 197 private: |
| 191 FakeContentLayerClient client_; | 198 FakeContentLayerClient client_; |
| 199 scoped_refptr<Layer> child_; |
| 192 }; | 200 }; |
| 193 | 201 |
| 194 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestDrawPropertiesOnMask); | 202 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestDrawPropertiesOnMask); |
| 195 | 203 |
| 196 // Verify occlusion is correctly set on scaled mask layers. | 204 // Verify occlusion is correctly set on scaled mask layers. |
| 197 class LayerTreeHostOcclusionTestDrawPropertiesOnScaledMask | 205 class LayerTreeHostOcclusionTestDrawPropertiesOnScaledMask |
| 198 : public LayerTreeHostOcclusionTest { | 206 : public LayerTreeHostOcclusionTest { |
| 199 public: | 207 public: |
| 200 void SetupTree() override { | 208 void SetupTree() override { |
| 201 scoped_refptr<Layer> root = Layer::Create(); | 209 scoped_refptr<Layer> root = Layer::Create(); |
| 202 root->SetBounds(gfx::Size(100, 100)); | 210 root->SetBounds(gfx::Size(100, 100)); |
| 203 root->SetIsDrawable(true); | 211 root->SetIsDrawable(true); |
| 204 | 212 |
| 205 gfx::Transform scale; | 213 gfx::Transform scale; |
| 206 scale.Scale(2, 2); | 214 scale.Scale(2, 2); |
| 207 | 215 |
| 208 scoped_refptr<Layer> child = Layer::Create(); | 216 child_ = Layer::Create(); |
| 209 child->SetBounds(gfx::Size(30, 40)); | 217 child_->SetBounds(gfx::Size(30, 40)); |
| 210 child->SetTransform(scale); | 218 child_->SetTransform(scale); |
| 211 root->AddChild(child); | 219 root->AddChild(child_); |
| 212 | 220 |
| 213 scoped_refptr<Layer> grand_child = Layer::Create(); | 221 scoped_refptr<Layer> grand_child = Layer::Create(); |
| 214 grand_child->SetBounds(gfx::Size(100, 100)); | 222 grand_child->SetBounds(gfx::Size(100, 100)); |
| 215 grand_child->SetPosition(gfx::PointF(-10.f, -15.f)); | 223 grand_child->SetPosition(gfx::PointF(-10.f, -15.f)); |
| 216 grand_child->SetIsDrawable(true); | 224 grand_child->SetIsDrawable(true); |
| 217 child->AddChild(grand_child); | 225 child_->AddChild(grand_child); |
| 218 | 226 |
| 219 scoped_refptr<Layer> mask = PictureLayer::Create(&client_); | 227 scoped_refptr<Layer> mask = PictureLayer::Create(&client_); |
| 220 mask->SetBounds(gfx::Size(30, 40)); | 228 mask->SetBounds(gfx::Size(30, 40)); |
| 221 mask->SetIsDrawable(true); | 229 mask->SetIsDrawable(true); |
| 222 child->SetMaskLayer(mask.get()); | 230 child_->SetMaskLayer(mask.get()); |
| 223 | 231 |
| 224 scoped_refptr<Layer> child2 = Layer::Create(); | 232 scoped_refptr<Layer> child2 = Layer::Create(); |
| 225 child2->SetBounds(gfx::Size(10, 11)); | 233 child2->SetBounds(gfx::Size(10, 11)); |
| 226 child2->SetPosition(gfx::PointF(13.f, 15.f)); | 234 child2->SetPosition(gfx::PointF(13.f, 15.f)); |
| 227 child2->SetContentsOpaque(true); | 235 child2->SetContentsOpaque(true); |
| 228 child2->SetIsDrawable(true); | 236 child2->SetIsDrawable(true); |
| 229 root->AddChild(child2); | 237 root->AddChild(child2); |
| 230 | 238 |
| 231 layer_tree_host()->SetRootLayer(root); | 239 layer_tree_host()->SetRootLayer(root); |
| 232 LayerTreeTest::SetupTree(); | 240 LayerTreeTest::SetupTree(); |
| 233 client_.set_bounds(root->bounds()); | 241 client_.set_bounds(root->bounds()); |
| 234 } | 242 } |
| 235 | 243 |
| 236 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 244 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 237 | 245 |
| 238 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 246 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 239 LayerImpl* root = impl->active_tree()->root_layer(); | 247 LayerImpl* child = impl->active_tree()->LayerById(child_->id()); |
| 240 LayerImpl* child = root->children()[0]; | |
| 241 LayerImpl* mask = child->mask_layer(); | 248 LayerImpl* mask = child->mask_layer(); |
| 242 | 249 |
| 243 gfx::Transform scale; | 250 gfx::Transform scale; |
| 244 scale.Scale(2, 2); | 251 scale.Scale(2, 2); |
| 245 | 252 |
| 246 EXPECT_OCCLUSION_EQ( | 253 EXPECT_OCCLUSION_EQ( |
| 247 Occlusion(scale, SimpleEnclosedRegion(), | 254 Occlusion(scale, SimpleEnclosedRegion(), |
| 248 SimpleEnclosedRegion(gfx::Rect(13, 15, 10, 11))), | 255 SimpleEnclosedRegion(gfx::Rect(13, 15, 10, 11))), |
| 249 mask->draw_properties().occlusion_in_content_space); | 256 mask->draw_properties().occlusion_in_content_space); |
| 250 EndTest(); | 257 EndTest(); |
| 251 } | 258 } |
| 252 | 259 |
| 253 void AfterTest() override {} | 260 void AfterTest() override {} |
| 254 | 261 |
| 262 private: |
| 255 FakeContentLayerClient client_; | 263 FakeContentLayerClient client_; |
| 264 scoped_refptr<Layer> child_; |
| 256 }; | 265 }; |
| 257 | 266 |
| 258 SINGLE_AND_MULTI_THREAD_TEST_F( | 267 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 259 LayerTreeHostOcclusionTestDrawPropertiesOnScaledMask); | 268 LayerTreeHostOcclusionTestDrawPropertiesOnScaledMask); |
| 260 | 269 |
| 261 // Verify occlusion is set to empty inside the subtree of a replica. This is | 270 // Verify occlusion is set to empty inside the subtree of a replica. This is |
| 262 // done because the tile system does not know about replicas, and so would not | 271 // done because the tile system does not know about replicas, and so would not |
| 263 // know that something is unoccluded on the replica even though it's occluded on | 272 // know that something is unoccluded on the replica even though it's occluded on |
| 264 // the original. | 273 // the original. |
| 265 class LayerTreeHostOcclusionTestDrawPropertiesInsideReplica | 274 class LayerTreeHostOcclusionTestDrawPropertiesInsideReplica |
| 266 : public LayerTreeHostOcclusionTest { | 275 : public LayerTreeHostOcclusionTest { |
| 267 public: | 276 public: |
| 268 void SetupTree() override { | 277 void SetupTree() override { |
| 269 scoped_refptr<Layer> root = Layer::Create(); | 278 scoped_refptr<Layer> root = Layer::Create(); |
| 270 root->SetBounds(gfx::Size(100, 100)); | 279 root->SetBounds(gfx::Size(100, 100)); |
| 271 root->SetIsDrawable(true); | 280 root->SetIsDrawable(true); |
| 272 | 281 |
| 273 scoped_refptr<Layer> child = Layer::Create(); | 282 child_ = Layer::Create(); |
| 274 child->SetBounds(gfx::Size(1, 1)); | 283 child_->SetBounds(gfx::Size(1, 1)); |
| 275 child->SetPosition(gfx::PointF(10.f, 5.5f)); | 284 child_->SetPosition(gfx::PointF(10.f, 5.5f)); |
| 276 child->SetIsDrawable(true); | 285 child_->SetIsDrawable(true); |
| 277 child->SetForceRenderSurface(true); | 286 child_->SetForceRenderSurface(true); |
| 278 root->AddChild(child); | 287 root->AddChild(child_); |
| 279 | 288 |
| 280 scoped_refptr<Layer> replica = Layer::Create(); | 289 scoped_refptr<Layer> replica = Layer::Create(); |
| 281 gfx::Transform translate; | 290 gfx::Transform translate; |
| 282 translate.Translate(20.f, 4.f); | 291 translate.Translate(20.f, 4.f); |
| 283 replica->SetTransform(translate); | 292 replica->SetTransform(translate); |
| 284 child->SetReplicaLayer(replica.get()); | 293 child_->SetReplicaLayer(replica.get()); |
| 285 | 294 |
| 286 scoped_refptr<Layer> mask = PictureLayer::Create(&client_); | 295 scoped_refptr<Layer> mask = PictureLayer::Create(&client_); |
| 287 mask->SetBounds(gfx::Size(30, 40)); | 296 mask->SetBounds(gfx::Size(30, 40)); |
| 288 mask->SetIsDrawable(true); | 297 mask->SetIsDrawable(true); |
| 289 child->SetMaskLayer(mask.get()); | 298 child_->SetMaskLayer(mask.get()); |
| 290 | 299 |
| 291 scoped_refptr<Layer> child2 = Layer::Create(); | 300 scoped_refptr<Layer> child2 = Layer::Create(); |
| 292 child2->SetBounds(gfx::Size(10, 12)); | 301 child2->SetBounds(gfx::Size(10, 12)); |
| 293 child2->SetPosition(gfx::PointF(13.f, 8.5f)); | 302 child2->SetPosition(gfx::PointF(13.f, 8.5f)); |
| 294 child2->SetContentsOpaque(true); | 303 child2->SetContentsOpaque(true); |
| 295 child2->SetIsDrawable(true); | 304 child2->SetIsDrawable(true); |
| 296 root->AddChild(child2); | 305 root->AddChild(child2); |
| 297 | 306 |
| 298 layer_tree_host()->SetRootLayer(root); | 307 layer_tree_host()->SetRootLayer(root); |
| 299 LayerTreeTest::SetupTree(); | 308 LayerTreeTest::SetupTree(); |
| 300 client_.set_bounds(root->bounds()); | 309 client_.set_bounds(root->bounds()); |
| 301 } | 310 } |
| 302 | 311 |
| 303 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 312 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 304 | 313 |
| 305 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 314 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 306 LayerImpl* root = impl->active_tree()->root_layer(); | 315 LayerImpl* root = impl->active_tree()->root_layer(); |
| 307 LayerImpl* child = root->children()[0]; | 316 LayerImpl* child = impl->active_tree()->LayerById(child_->id()); |
| 308 RenderSurfaceImpl* surface = child->render_surface(); | 317 RenderSurfaceImpl* surface = child->render_surface(); |
| 309 LayerImpl* mask = child->mask_layer(); | 318 LayerImpl* mask = child->mask_layer(); |
| 310 | 319 |
| 311 // Verify the draw properties are valid. | 320 // Verify the draw properties are valid. |
| 312 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); | 321 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember()); |
| 313 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); | 322 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember()); |
| 314 EXPECT_TRUE(child->has_render_surface()); | 323 EXPECT_TRUE(child->has_render_surface()); |
| 315 EXPECT_EQ(child->render_surface(), child->render_target()); | 324 EXPECT_EQ(child->render_surface(), child->render_target()); |
| 316 | 325 |
| 317 // No occlusion from on child, which is part of the replica. | 326 // No occlusion from on child, which is part of the replica. |
| 318 EXPECT_OCCLUSION_EQ(Occlusion(), | 327 EXPECT_OCCLUSION_EQ(Occlusion(), |
| 319 child->draw_properties().occlusion_in_content_space); | 328 child->draw_properties().occlusion_in_content_space); |
| 320 // Occlusion on the surface is okay. | 329 // Occlusion on the surface is okay. |
| 321 EXPECT_OCCLUSION_EQ( | 330 EXPECT_OCCLUSION_EQ( |
| 322 Occlusion(surface->draw_transform(), SimpleEnclosedRegion(), | 331 Occlusion(surface->draw_transform(), SimpleEnclosedRegion(), |
| 323 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))), | 332 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))), |
| 324 surface->occlusion_in_content_space()); | 333 surface->occlusion_in_content_space()); |
| 325 // No occlusion on the replica'd mask. | 334 // No occlusion on the replica'd mask. |
| 326 EXPECT_OCCLUSION_EQ(Occlusion(), | 335 EXPECT_OCCLUSION_EQ(Occlusion(), |
| 327 mask->draw_properties().occlusion_in_content_space); | 336 mask->draw_properties().occlusion_in_content_space); |
| 328 EndTest(); | 337 EndTest(); |
| 329 } | 338 } |
| 330 | 339 |
| 331 void AfterTest() override {} | 340 void AfterTest() override {} |
| 332 | 341 |
| 342 private: |
| 333 FakeContentLayerClient client_; | 343 FakeContentLayerClient client_; |
| 344 scoped_refptr<Layer> child_; |
| 334 }; | 345 }; |
| 335 | 346 |
| 336 SINGLE_AND_MULTI_THREAD_TEST_F( | 347 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 337 LayerTreeHostOcclusionTestDrawPropertiesInsideReplica); | 348 LayerTreeHostOcclusionTestDrawPropertiesInsideReplica); |
| 338 | 349 |
| 339 } // namespace | 350 } // namespace |
| 340 } // namespace cc | 351 } // namespace cc |
| OLD | NEW |