| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "cc/delegated_frame_data.h" | 7 #include "cc/delegated_frame_data.h" |
| 8 #include "cc/delegated_renderer_layer.h" | 8 #include "cc/delegated_renderer_layer.h" |
| 9 #include "cc/delegated_renderer_layer_impl.h" | 9 #include "cc/delegated_renderer_layer_impl.h" |
| 10 #include "cc/layer_tree_impl.h" | 10 #include "cc/layer_tree_impl.h" |
| 11 #include "cc/shared_quad_state.h" |
| 12 #include "cc/test/fake_delegated_renderer_layer.h" |
| 13 #include "cc/test/fake_delegated_renderer_layer_impl.h" |
| 11 #include "cc/test/layer_tree_test_common.h" | 14 #include "cc/test/layer_tree_test_common.h" |
| 15 #include "cc/texture_draw_quad.h" |
| 12 #include "gpu/GLES2/gl2extchromium.h" | 16 #include "gpu/GLES2/gl2extchromium.h" |
| 13 | 17 |
| 14 namespace cc { | 18 namespace cc { |
| 15 namespace { | 19 namespace { |
| 16 | 20 |
| 17 // These tests deal with delegated renderer layers. | 21 // These tests deal with delegated renderer layers. |
| 18 class LayerTreeHostDelegatedTest : public ThreadedTest { | 22 class LayerTreeHostDelegatedTest : public ThreadedTest { |
| 19 protected: | 23 protected: |
| 20 scoped_ptr<DelegatedFrameData> CreateFrameData(gfx::Rect root_output_rect, | 24 scoped_ptr<DelegatedFrameData> CreateFrameData(gfx::Rect root_output_rect, |
| 21 gfx::Rect root_damage_rect) { | 25 gfx::Rect root_damage_rect) { |
| 22 scoped_ptr<DelegatedFrameData> frame(new DelegatedFrameData); | 26 scoped_ptr<DelegatedFrameData> frame(new DelegatedFrameData); |
| 23 | 27 |
| 24 scoped_ptr<RenderPass> root_pass(RenderPass::Create()); | 28 scoped_ptr<RenderPass> root_pass(RenderPass::Create()); |
| 25 root_pass->SetNew(RenderPass::Id(1, 1), | 29 root_pass->SetNew(RenderPass::Id(1, 1), |
| 26 root_output_rect, | 30 root_output_rect, |
| 27 root_damage_rect, | 31 root_damage_rect, |
| 28 gfx::Transform()); | 32 gfx::Transform()); |
| 29 frame->render_pass_list.push_back(root_pass.Pass()); | 33 frame->render_pass_list.push_back(root_pass.Pass()); |
| 30 return frame.Pass(); | 34 return frame.Pass(); |
| 31 } | 35 } |
| 32 | 36 |
| 37 void AddTransferableResource(DelegatedFrameData* frame, |
| 38 ResourceProvider::ResourceId resource_id) { |
| 39 TransferableResource resource; |
| 40 resource.id = resource_id; |
| 41 frame->resource_list.push_back(resource); |
| 42 } |
| 43 |
| 44 void AddTextureQuad(DelegatedFrameData* frame, |
| 45 ResourceProvider::ResourceId resource_id) { |
| 46 scoped_ptr<SharedQuadState> sqs = SharedQuadState::Create(); |
| 47 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
| 48 float vertex_opacity[4] = { 1.f, 1.f, 1.f, 1.f }; |
| 49 quad->SetNew(sqs.get(), |
| 50 gfx::Rect(0, 0, 10, 10), |
| 51 gfx::Rect(0, 0, 10, 10), |
| 52 resource_id, |
| 53 false, |
| 54 gfx::PointF(0.f, 0.f), |
| 55 gfx::PointF(1.f, 1.f), |
| 56 vertex_opacity, |
| 57 false); |
| 58 frame->render_pass_list[0]->shared_quad_state_list.push_back(sqs.Pass()); |
| 59 frame->render_pass_list[0]->quad_list.push_back(quad.PassAs<DrawQuad>()); |
| 60 } |
| 61 |
| 33 scoped_ptr<DelegatedFrameData> CreateEmptyFrameData() { | 62 scoped_ptr<DelegatedFrameData> CreateEmptyFrameData() { |
| 34 scoped_ptr<DelegatedFrameData> frame(new DelegatedFrameData); | 63 scoped_ptr<DelegatedFrameData> frame(new DelegatedFrameData); |
| 35 return frame.Pass(); | 64 return frame.Pass(); |
| 36 } | 65 } |
| 37 }; | 66 }; |
| 38 | 67 |
| 39 class LayerTreeHostDelegatedTestCaseSingleDelegatedLayer | 68 class LayerTreeHostDelegatedTestCaseSingleDelegatedLayer |
| 40 : public LayerTreeHostDelegatedTest { | 69 : public LayerTreeHostDelegatedTest { |
| 41 public: | 70 public: |
| 42 virtual void setupTree() OVERRIDE { | 71 virtual void setupTree() OVERRIDE { |
| 43 root_ = Layer::create(); | 72 root_ = Layer::create(); |
| 44 root_->setAnchorPoint(gfx::PointF()); | 73 root_->setAnchorPoint(gfx::PointF()); |
| 45 root_->setBounds(gfx::Size(10, 10)); | 74 root_->setBounds(gfx::Size(10, 10)); |
| 46 | 75 |
| 47 delegated_ = DelegatedRendererLayer::Create(); | 76 delegated_ = FakeDelegatedRendererLayer::Create(); |
| 48 delegated_->setAnchorPoint(gfx::PointF()); | 77 delegated_->setAnchorPoint(gfx::PointF()); |
| 49 delegated_->setBounds(gfx::Size(10, 10)); | 78 delegated_->setBounds(gfx::Size(10, 10)); |
| 50 delegated_->setIsDrawable(true); | 79 delegated_->setIsDrawable(true); |
| 51 | 80 |
| 52 root_->addChild(delegated_); | 81 root_->addChild(delegated_); |
| 53 m_layerTreeHost->setRootLayer(root_); | 82 m_layerTreeHost->setRootLayer(root_); |
| 54 LayerTreeHostDelegatedTest::setupTree(); | 83 LayerTreeHostDelegatedTest::setupTree(); |
| 55 } | 84 } |
| 56 | 85 |
| 57 virtual void beginTest() OVERRIDE { | 86 virtual void beginTest() OVERRIDE { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 75 | 104 |
| 76 virtual void didCommit() OVERRIDE { | 105 virtual void didCommit() OVERRIDE { |
| 77 if (testEnded()) | 106 if (testEnded()) |
| 78 return; | 107 return; |
| 79 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1), | 108 delegated_->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1), |
| 80 gfx::Rect(0, 0, 1, 1))); | 109 gfx::Rect(0, 0, 1, 1))); |
| 81 } | 110 } |
| 82 | 111 |
| 83 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 112 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 84 LayerImpl* root_impl = host_impl->activeTree()->RootLayer(); | 113 LayerImpl* root_impl = host_impl->activeTree()->RootLayer(); |
| 85 DelegatedRendererLayerImpl* delegated_impl = | 114 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 86 static_cast<DelegatedRendererLayerImpl*>(root_impl->children()[0]); | 115 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 87 | 116 |
| 88 ++num_activates_; | 117 ++num_activates_; |
| 89 switch(num_activates_) { | 118 switch(num_activates_) { |
| 90 case 2: | 119 case 2: |
| 91 EXPECT_TRUE(delegated_impl->child_id()); | 120 EXPECT_TRUE(delegated_impl->ChildId()); |
| 92 EXPECT_FALSE(did_reset_child_id_); | 121 EXPECT_FALSE(did_reset_child_id_); |
| 93 | 122 |
| 94 host_impl->resourceProvider()->graphicsContext3D()->loseContextCHROMIUM( | 123 host_impl->resourceProvider()->graphicsContext3D()->loseContextCHROMIUM( |
| 95 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 124 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 96 break; | 125 break; |
| 97 case 3: | 126 case 3: |
| 98 EXPECT_TRUE(delegated_impl->child_id()); | 127 EXPECT_TRUE(delegated_impl->ChildId()); |
| 99 EXPECT_TRUE(did_reset_child_id_); | 128 EXPECT_TRUE(did_reset_child_id_); |
| 100 endTest(); | 129 endTest(); |
| 101 break; | 130 break; |
| 102 } | 131 } |
| 103 } | 132 } |
| 104 | 133 |
| 105 virtual void initializedRendererOnThread(LayerTreeHostImpl* host_impl, | 134 virtual void initializedRendererOnThread(LayerTreeHostImpl* host_impl, |
| 106 bool success) OVERRIDE { | 135 bool success) OVERRIDE { |
| 107 EXPECT_TRUE(success); | 136 EXPECT_TRUE(success); |
| 108 | 137 |
| 109 if (num_activates_ < 2) | 138 if (num_activates_ < 2) |
| 110 return; | 139 return; |
| 111 | 140 |
| 112 LayerImpl* root_impl = host_impl->activeTree()->RootLayer(); | 141 LayerImpl* root_impl = host_impl->activeTree()->RootLayer(); |
| 113 DelegatedRendererLayerImpl* delegated_impl = | 142 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 114 static_cast<DelegatedRendererLayerImpl*>(root_impl->children()[0]); | 143 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 115 | 144 |
| 116 EXPECT_EQ(2, num_activates_); | 145 EXPECT_EQ(2, num_activates_); |
| 117 EXPECT_FALSE(delegated_impl->child_id()); | 146 EXPECT_FALSE(delegated_impl->ChildId()); |
| 118 did_reset_child_id_ = true; | 147 did_reset_child_id_ = true; |
| 119 } | 148 } |
| 120 | 149 |
| 121 virtual void afterTest() OVERRIDE {} | 150 virtual void afterTest() OVERRIDE {} |
| 122 | 151 |
| 123 protected: | 152 protected: |
| 124 int num_activates_; | 153 int num_activates_; |
| 125 bool did_reset_child_id_; | 154 bool did_reset_child_id_; |
| 126 }; | 155 }; |
| 127 | 156 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 319 |
| 291 return result; | 320 return result; |
| 292 } | 321 } |
| 293 | 322 |
| 294 protected: | 323 protected: |
| 295 bool first_draw_for_source_frame_; | 324 bool first_draw_for_source_frame_; |
| 296 }; | 325 }; |
| 297 | 326 |
| 298 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestLayerUsesFrameDamage) | 327 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestLayerUsesFrameDamage) |
| 299 | 328 |
| 329 class LayerTreeHostDelegatedTestMergeResources |
| 330 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 331 public: |
| 332 virtual void beginTest() OVERRIDE { |
| 333 // Push two frames to the delegated renderer layer with no commit between. |
| 334 |
| 335 // The first frame has resource 999. |
| 336 scoped_ptr<DelegatedFrameData> frame1 = |
| 337 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 338 AddTextureQuad(frame1.get(), 999); |
| 339 AddTransferableResource(frame1.get(), 999); |
| 340 delegated_->SetFrameData(frame1.Pass()); |
| 341 |
| 342 // The second frame uses resource 999 still. |
| 343 scoped_ptr<DelegatedFrameData> frame2 = |
| 344 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 345 AddTextureQuad(frame2.get(), 999); |
| 346 AddTextureQuad(frame2.get(), 555); |
| 347 AddTransferableResource(frame2.get(), 555); |
| 348 delegated_->SetFrameData(frame2.Pass()); |
| 349 |
| 350 postSetNeedsCommitToMainThread(); |
| 351 } |
| 352 |
| 353 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 354 LayerImpl* root_impl = host_impl->activeTree()->RootLayer(); |
| 355 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 356 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 357 |
| 358 const ResourceProvider::ResourceIdMap& map = |
| 359 host_impl->resourceProvider()->getChildToParentMap( |
| 360 delegated_impl->ChildId()); |
| 361 |
| 362 // Both frames' resources should be in the parent's resource provider. |
| 363 EXPECT_EQ(2u, map.size()); |
| 364 EXPECT_EQ(1u, map.count(999)); |
| 365 EXPECT_EQ(1u, map.count(555)); |
| 366 |
| 367 // Both frames' resources should be saved on the layer. |
| 368 EXPECT_EQ(2u, delegated_impl->Resources().size()); |
| 369 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second)); |
| 370 EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second)); |
| 371 |
| 372 endTest(); |
| 373 } |
| 374 |
| 375 virtual void afterTest() OVERRIDE {} |
| 376 }; |
| 377 |
| 378 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestMergeResources) |
| 379 |
| 380 class LayerTreeHostDelegatedTestRemapResourcesInQuads |
| 381 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { |
| 382 public: |
| 383 virtual void beginTest() OVERRIDE { |
| 384 // Generate a frame with a resource in it. |
| 385 scoped_ptr<DelegatedFrameData> frame = |
| 386 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); |
| 387 AddTextureQuad(frame.get(), 999); |
| 388 AddTransferableResource(frame.get(), 999); |
| 389 AddTextureQuad(frame.get(), 555); |
| 390 AddTransferableResource(frame.get(), 555); |
| 391 delegated_->SetFrameData(frame.Pass()); |
| 392 |
| 393 postSetNeedsCommitToMainThread(); |
| 394 } |
| 395 |
| 396 virtual void treeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 397 LayerImpl* root_impl = host_impl->activeTree()->RootLayer(); |
| 398 FakeDelegatedRendererLayerImpl* delegated_impl = |
| 399 static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]); |
| 400 |
| 401 const ResourceProvider::ResourceIdMap& map = |
| 402 host_impl->resourceProvider()->getChildToParentMap( |
| 403 delegated_impl->ChildId()); |
| 404 |
| 405 // The frame's resource should be in the parent's resource provider. |
| 406 EXPECT_EQ(2u, map.size()); |
| 407 EXPECT_EQ(1u, map.count(999)); |
| 408 EXPECT_EQ(1u, map.count(555)); |
| 409 |
| 410 ResourceProvider::ResourceId parent_resource_id1 = map.find(999)->second; |
| 411 EXPECT_NE(parent_resource_id1, 999); |
| 412 ResourceProvider::ResourceId parent_resource_id2 = map.find(555)->second; |
| 413 EXPECT_NE(parent_resource_id2, 555); |
| 414 |
| 415 // The resources in the quads should be remapped to the parent's namespace. |
| 416 const TextureDrawQuad* quad1 = TextureDrawQuad::MaterialCast( |
| 417 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list[0]); |
| 418 EXPECT_EQ(parent_resource_id1, quad1->resource_id); |
| 419 const TextureDrawQuad* quad2 = TextureDrawQuad::MaterialCast( |
| 420 delegated_impl->RenderPassesInDrawOrder()[0]->quad_list[1]); |
| 421 EXPECT_EQ(parent_resource_id2, quad2->resource_id); |
| 422 |
| 423 endTest(); |
| 424 } |
| 425 |
| 426 virtual void afterTest() OVERRIDE {} |
| 427 }; |
| 428 |
| 429 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestRemapResourcesInQuads) |
| 430 |
| 300 } // namespace | 431 } // namespace |
| 301 } // namespace cc | 432 } // namespace cc |
| OLD | NEW |