| 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/delegated_renderer_layer_impl.h" | 5 #include "cc/delegated_renderer_layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/append_quads_data.h" | 7 #include "cc/append_quads_data.h" |
| 8 #include "cc/layer_tree_host_impl.h" | 8 #include "cc/layer_tree_host_impl.h" |
| 9 #include "cc/layer_tree_impl.h" | 9 #include "cc/layer_tree_impl.h" |
| 10 #include "cc/quad_sink.h" | 10 #include "cc/quad_sink.h" |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 369 |
| 370 TEST_F(DelegatedRendererLayerImplTestOwnSurface, QuadsFromRootRenderPassAreNotMo
difiedForTheTarget) | 370 TEST_F(DelegatedRendererLayerImplTestOwnSurface, QuadsFromRootRenderPassAreNotMo
difiedForTheTarget) |
| 371 { | 371 { |
| 372 LayerTreeHostImpl::FrameData frame; | 372 LayerTreeHostImpl::FrameData frame; |
| 373 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 373 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 374 | 374 |
| 375 // Each non-DelegatedRendererLayer added one RenderPass. The DelegatedRender
erLayer added two contributing passes and its owned surface added one pass. | 375 // Each non-DelegatedRendererLayer added one RenderPass. The DelegatedRender
erLayer added two contributing passes and its owned surface added one pass. |
| 376 ASSERT_EQ(6u, frame.renderPasses.size()); | 376 ASSERT_EQ(6u, frame.renderPasses.size()); |
| 377 | 377 |
| 378 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root Ren
derPass' quads do not need to be | 378 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root Ren
derPass' quads do not need to be |
| 379 // modified at all. | 379 // translated at all. However, they are scaled from the frame's size (8x8) t
o the layer's bounds (10x10). |
| 380 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), frame.renderPasses[3]->qua
d_list[0]->quadTransform()); | 380 gfx::Transform transform; |
| 381 transform.Scale(10.0 / 8.0, 10.0 / 8.0); |
| 382 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, frame.renderPasses[3]->quad_list[
0]->quadTransform()); |
| 381 | 383 |
| 382 // Quads from non-root RenderPasses should not be shifted though. | 384 // Quads from non-root RenderPasses should not be shifted either. |
| 383 ASSERT_EQ(2u, frame.renderPasses[2]->quad_list.size()); | 385 ASSERT_EQ(2u, frame.renderPasses[2]->quad_list.size()); |
| 384 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), frame.renderPasses[2]->qua
d_list[0]->quadTransform()); | 386 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), frame.renderPasses[2]->qua
d_list[0]->quadTransform()); |
| 385 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), frame.renderPasses[2]->qua
d_list[1]->quadTransform()); | 387 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), frame.renderPasses[2]->qua
d_list[1]->quadTransform()); |
| 386 ASSERT_EQ(1u, frame.renderPasses[1]->quad_list.size()); | 388 ASSERT_EQ(1u, frame.renderPasses[1]->quad_list.size()); |
| 387 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), frame.renderPasses[1]->qua
d_list[0]->quadTransform()); | 389 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), frame.renderPasses[1]->qua
d_list[0]->quadTransform()); |
| 388 | 390 |
| 389 m_hostImpl->drawLayers(frame); | 391 m_hostImpl->drawLayers(frame); |
| 390 m_hostImpl->didDrawAllLayers(frame); | 392 m_hostImpl->didDrawAllLayers(frame); |
| 391 } | 393 } |
| 392 | 394 |
| 393 class DelegatedRendererLayerImplTestSharedData : public DelegatedRendererLayerIm
plTest { | 395 class DelegatedRendererLayerImplTestTransform : public DelegatedRendererLayerImp
lTest { |
| 394 public: | 396 public: |
| 395 DelegatedRendererLayerImplTestSharedData() | 397 void setUpTest() |
| 396 : DelegatedRendererLayerImplTest() | |
| 397 { | 398 { |
| 398 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(m_hostImpl->activeTr
ee(), 1); | 399 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(m_hostImpl->activeTr
ee(), 1); |
| 399 scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer = Delegate
dRendererLayerImpl::create(m_hostImpl->activeTree(), 2); | 400 scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer = Delegate
dRendererLayerImpl::create(m_hostImpl->activeTree(), 2); |
| 400 | 401 |
| 401 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); | 402 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); |
| 402 rootLayer->setBounds(gfx::Size(100, 100)); | 403 rootLayer->setBounds(gfx::Size(100, 100)); |
| 403 | 404 |
| 404 delegatedRendererLayer->setPosition(gfx::Point(20, 20)); | 405 delegatedRendererLayer->setPosition(gfx::Point(20, 20)); |
| 405 delegatedRendererLayer->setBounds(gfx::Size(30, 30)); | 406 delegatedRendererLayer->setBounds(gfx::Size(30, 30)); |
| 406 delegatedRendererLayer->setContentBounds(gfx::Size(30, 30)); | 407 delegatedRendererLayer->setContentBounds(gfx::Size(30, 30)); |
| 407 delegatedRendererLayer->setDrawsContent(true); | 408 delegatedRendererLayer->setDrawsContent(true); |
| 408 gfx::Transform transform; | 409 gfx::Transform transform; |
| 409 transform.Scale(2.0, 2.0); | 410 transform.Scale(2.0, 2.0); |
| 410 transform.Translate(8.0, 8.0); | 411 transform.Translate(8.0, 8.0); |
| 411 delegatedRendererLayer->setTransform(transform); | 412 delegatedRendererLayer->setTransform(transform); |
| 412 | 413 |
| 413 ScopedPtrVector<RenderPass> delegatedRenderPasses; | 414 ScopedPtrVector<RenderPass> delegatedRenderPasses; |
| 414 | 415 |
| 415 gfx::Rect childPassRect(20, 20, 7, 7); | 416 gfx::Rect childPassRect(20, 20, 7, 7); |
| 416 gfx::Transform childPassTransform; | 417 gfx::Transform childPassTransform; |
| 417 childPassTransform.Scale(0.8, 0.8); | 418 childPassTransform.Scale(0.8, 0.8); |
| 418 childPassTransform.Translate(9.0, 9.0); | 419 childPassTransform.Translate(9.0, 9.0); |
| 420 gfx::Rect childPassClipRect(21, 21, 3, 3); |
| 421 bool childPassClipped = false; |
| 419 | 422 |
| 420 { | 423 { |
| 421 TestRenderPass* pass = addRenderPass(delegatedRenderPasses, RenderPa
ss::Id(10, 7), childPassRect, gfx::Transform()); | 424 TestRenderPass* pass = addRenderPass(delegatedRenderPasses, RenderPa
ss::Id(10, 7), childPassRect, gfx::Transform()); |
| 422 MockQuadCuller quadSink(pass->quad_list, pass->shared_quad_state_lis
t); | 425 MockQuadCuller quadSink(pass->quad_list, pass->shared_quad_state_lis
t); |
| 423 AppendQuadsData data(pass->id); | 426 AppendQuadsData data(pass->id); |
| 424 SharedQuadState* sharedState = quadSink.useSharedQuadState(SharedQua
dState::Create()); | 427 SharedQuadState* sharedState = quadSink.useSharedQuadState(SharedQua
dState::Create()); |
| 425 sharedState->SetAll(childPassTransform, childPassRect, childPassRect
, false, 1); | 428 sharedState->SetAll(childPassTransform, childPassRect, childPassClip
Rect, childPassClipped, 1); |
| 426 scoped_ptr<SolidColorDrawQuad> colorQuad; | 429 scoped_ptr<SolidColorDrawQuad> colorQuad; |
| 427 | 430 |
| 428 colorQuad = SolidColorDrawQuad::Create(); | 431 colorQuad = SolidColorDrawQuad::Create(); |
| 429 colorQuad->SetNew(sharedState, gfx::Rect(20, 20, 3, 7), 1u); | 432 colorQuad->SetNew(sharedState, gfx::Rect(20, 20, 3, 7), 1u); |
| 430 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); | 433 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); |
| 431 | 434 |
| 432 colorQuad = SolidColorDrawQuad::Create(); | 435 colorQuad = SolidColorDrawQuad::Create(); |
| 433 colorQuad->SetNew(sharedState, gfx::Rect(23, 20, 4, 7), 1u); | 436 colorQuad->SetNew(sharedState, gfx::Rect(23, 20, 4, 7), 1u); |
| 434 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); | 437 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); |
| 435 } | 438 } |
| 436 | 439 |
| 437 gfx::Rect passRect(0, 0, 50, 50); | 440 gfx::Rect passRect(0, 0, 50, 50); |
| 438 gfx::Transform passTransform; | 441 gfx::Transform passTransform; |
| 439 passTransform.Scale(1.5, 1.5); | 442 passTransform.Scale(1.5, 1.5); |
| 440 passTransform.Translate(7.0, 7.0); | 443 passTransform.Translate(7.0, 7.0); |
| 444 gfx::Rect passClipRect(10, 10, 35, 35); |
| 445 bool passClipped = m_rootDelegatedRenderPassIsClipped; |
| 441 | 446 |
| 442 TestRenderPass* pass = addRenderPass(delegatedRenderPasses, RenderPass::
Id(9, 6), passRect, gfx::Transform()); | 447 TestRenderPass* pass = addRenderPass(delegatedRenderPasses, RenderPass::
Id(9, 6), passRect, gfx::Transform()); |
| 443 MockQuadCuller quadSink(pass->quad_list, pass->shared_quad_state_list); | 448 MockQuadCuller quadSink(pass->quad_list, pass->shared_quad_state_list); |
| 444 AppendQuadsData data(pass->id); | 449 AppendQuadsData data(pass->id); |
| 445 SharedQuadState* sharedState = quadSink.useSharedQuadState(SharedQuadSta
te::Create()); | 450 SharedQuadState* sharedState = quadSink.useSharedQuadState(SharedQuadSta
te::Create()); |
| 446 sharedState->SetAll(passTransform, passRect, passRect, false, 1); | 451 sharedState->SetAll(passTransform, passRect, passClipRect, passClipped,
1); |
| 447 scoped_ptr<SolidColorDrawQuad> colorQuad; | 452 scoped_ptr<SolidColorDrawQuad> colorQuad; |
| 448 | 453 |
| 449 scoped_ptr<RenderPassDrawQuad> renderPassQuad = RenderPassDrawQuad::Crea
te(); | 454 scoped_ptr<RenderPassDrawQuad> renderPassQuad = RenderPassDrawQuad::Crea
te(); |
| 450 renderPassQuad->SetNew( | 455 renderPassQuad->SetNew( |
| 451 sharedState, | 456 sharedState, |
| 452 gfx::Rect(5, 5, 7, 7), | 457 gfx::Rect(5, 5, 7, 7), |
| 453 RenderPass::Id(10, 7), | 458 RenderPass::Id(10, 7), |
| 454 false, // is_replica | 459 false, // is_replica |
| 455 0, // mask_resource_id | 460 0, // mask_resource_id |
| 456 childPassRect, // contents_changed_since_last_frame | 461 childPassRect, // contents_changed_since_last_frame |
| (...skipping 25 matching lines...) Expand all Loading... |
| 482 EXPECT_EQ(0u, delegatedRenderPasses.size()); | 487 EXPECT_EQ(0u, delegatedRenderPasses.size()); |
| 483 | 488 |
| 484 m_rootLayerPtr = rootLayer.get(); | 489 m_rootLayerPtr = rootLayer.get(); |
| 485 m_delegatedRendererLayerPtr = delegatedRendererLayer.get(); | 490 m_delegatedRendererLayerPtr = delegatedRendererLayer.get(); |
| 486 | 491 |
| 487 rootLayer->addChild(delegatedRendererLayer.PassAs<LayerImpl>()); | 492 rootLayer->addChild(delegatedRendererLayer.PassAs<LayerImpl>()); |
| 488 | 493 |
| 489 m_hostImpl->activeTree()->SetRootLayer(rootLayer.Pass()); | 494 m_hostImpl->activeTree()->SetRootLayer(rootLayer.Pass()); |
| 490 } | 495 } |
| 491 | 496 |
| 497 void verifyRenderPasses( |
| 498 const LayerTreeHostImpl::FrameData& frame, |
| 499 size_t numRenderPasses, |
| 500 const SharedQuadState** rootSharedState, |
| 501 const SharedQuadState** contribSharedState) |
| 502 { |
| 503 ASSERT_EQ(numRenderPasses, frame.renderPasses.size()); |
| 504 // The contributing render pass in the DelegatedRendererLayer. |
| 505 EXPECT_EQ(2, frame.renderPasses[0]->id.layer_id); |
| 506 EXPECT_EQ(1, frame.renderPasses[0]->id.index); |
| 507 // The root render pass. |
| 508 EXPECT_EQ(1, frame.renderPasses.back()->id.layer_id); |
| 509 EXPECT_EQ(0, frame.renderPasses.back()->id.index); |
| 510 |
| 511 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; |
| 512 ASSERT_EQ(2u, contribQuadList.size()); |
| 513 |
| 514 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; |
| 515 ASSERT_EQ(5u, rootQuadList.size()); |
| 516 |
| 517 // All quads in a render pass should share the same state. |
| 518 *contribSharedState = contribQuadList[0]->shared_quad_state; |
| 519 EXPECT_EQ(*contribSharedState, contribQuadList[1]->shared_quad_state); |
| 520 |
| 521 *rootSharedState = rootQuadList[0]->shared_quad_state; |
| 522 EXPECT_EQ(*rootSharedState, rootQuadList[1]->shared_quad_state); |
| 523 EXPECT_EQ(*rootSharedState, rootQuadList[2]->shared_quad_state); |
| 524 EXPECT_EQ(*rootSharedState, rootQuadList[3]->shared_quad_state); |
| 525 EXPECT_EQ(*rootSharedState, rootQuadList[4]->shared_quad_state); |
| 526 |
| 527 EXPECT_NE(*contribSharedState, *rootSharedState); |
| 528 } |
| 529 |
| 492 protected: | 530 protected: |
| 493 LayerImpl* m_rootLayerPtr; | 531 LayerImpl* m_rootLayerPtr; |
| 494 DelegatedRendererLayerImpl* m_delegatedRendererLayerPtr; | 532 DelegatedRendererLayerImpl* m_delegatedRendererLayerPtr; |
| 533 bool m_rootDelegatedRenderPassIsClipped; |
| 495 }; | 534 }; |
| 496 | 535 |
| 497 TEST_F(DelegatedRendererLayerImplTestSharedData, SharedData) | 536 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) |
| 498 { | 537 { |
| 538 m_rootDelegatedRenderPassIsClipped = false; |
| 539 setUpTest(); |
| 540 |
| 499 LayerTreeHostImpl::FrameData frame; | 541 LayerTreeHostImpl::FrameData frame; |
| 500 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 542 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 501 | 543 |
| 502 ASSERT_EQ(2u, frame.renderPasses.size()); | 544 const SharedQuadState* rootSharedState = NULL; |
| 503 // The contributing render pass in the DelegatedRendererLayer. | 545 const SharedQuadState* contribSharedState = NULL; |
| 504 EXPECT_EQ(2, frame.renderPasses[0]->id.layer_id); | 546 verifyRenderPasses(frame, 2, &rootSharedState, &contribSharedState); |
| 505 EXPECT_EQ(1, frame.renderPasses[0]->id.index); | |
| 506 // The root render pass. | |
| 507 EXPECT_EQ(1, frame.renderPasses[1]->id.layer_id); | |
| 508 EXPECT_EQ(0, frame.renderPasses[1]->id.index); | |
| 509 | 547 |
| 510 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; | 548 // When the quads don't have a clip of their own, the clip rect is set to |
| 511 ASSERT_EQ(2u, contribQuadList.size()); | 549 // the drawableContentRect of the delegated renderer layer. |
| 550 EXPECT_RECT_EQ(gfx::Rect(21, 21, 60, 60), rootSharedState->clip_rect); |
| 512 | 551 |
| 513 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; | 552 // Even though the quads in the root pass have no clip of their own, they |
| 514 ASSERT_EQ(5u, rootQuadList.size()); | 553 // inherit the clip rect from the delegated renderer layer if it does not |
| 554 // own a surface. |
| 555 EXPECT_TRUE(rootSharedState->is_clipped); |
| 515 | 556 |
| 516 // All quads in a render pass should share the same state. | |
| 517 const SharedQuadState* contribSharedState = contribQuadList[0]->shared_quad_
state; | |
| 518 EXPECT_EQ(contribSharedState, contribQuadList[1]->shared_quad_state); | |
| 519 | |
| 520 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; | |
| 521 EXPECT_EQ(rootSharedState, rootQuadList[1]->shared_quad_state); | |
| 522 EXPECT_EQ(rootSharedState, rootQuadList[2]->shared_quad_state); | |
| 523 EXPECT_EQ(rootSharedState, rootQuadList[3]->shared_quad_state); | |
| 524 EXPECT_EQ(rootSharedState, rootQuadList[4]->shared_quad_state); | |
| 525 | |
| 526 EXPECT_NE(rootQuadList[0]->shared_quad_state, contribQuadList[0]->shared_qua
d_state); | |
| 527 | |
| 528 // The state should be transformed only once. | |
| 529 | |
| 530 // The x/y values are: position (20) + transform (8 * 2) = 36 | |
| 531 // 36 - (width / 2) = 36 - 30 / 2 = 21 | |
| 532 // The size is 100 scaled to fit inside the layer's bounds at 30x30 from a f
rame at 50x50. | |
| 533 // 100 * 30 / 50 = 60. | |
| 534 EXPECT_RECT_EQ(gfx::Rect(21, 21, 60, 60), rootSharedState->clip_rect); | |
| 535 gfx::Transform expected; | 557 gfx::Transform expected; |
| 536 // This is the transform from the layer's space to its target. | 558 // This is the transform from the layer's space to its target. |
| 537 // The position (20) - the width / scale (30 / 2) = 20 - 15 = 5 | 559 // The position (20) - the width / scale (30 / 2) = 20 - 15 = 5 |
| 538 expected.Translate(5.0, 5.0); | 560 expected.Translate(5.0, 5.0); |
| 539 expected.Scale(2.0, 2.0); | 561 expected.Scale(2.0, 2.0); |
| 540 expected.Translate(8.0, 8.0); | 562 expected.Translate(8.0, 8.0); |
| 541 // The frame has size 50x50 but the layer's bounds are 30x30. | 563 // The frame has size 50x50 but the layer's bounds are 30x30. |
| 542 expected.Scale(30.0 / 50.0, 30.0 / 50.0); | 564 expected.Scale(30.0 / 50.0, 30.0 / 50.0); |
| 543 // This is the transform within the source frame. | 565 // This is the transform within the source frame. |
| 544 expected.Scale(1.5, 1.5); | 566 expected.Scale(1.5, 1.5); |
| 545 expected.Translate(7.0, 7.0); | 567 expected.Translate(7.0, 7.0); |
| 546 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, rootSharedState->content_to_target
_transform); | 568 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, rootSharedState->content_to_target
_transform); |
| 547 | 569 |
| 548 // The contributing render pass should not be transformed from its input. | 570 // The contributing render pass should not be transformed from its input. |
| 549 EXPECT_RECT_EQ(gfx::Rect(20, 20, 7, 7), contribSharedState->clip_rect); | 571 EXPECT_RECT_EQ(gfx::Rect(21, 21, 3, 3), contribSharedState->clip_rect); |
| 572 EXPECT_FALSE(contribSharedState->is_clipped); |
| 550 expected.MakeIdentity(); | 573 expected.MakeIdentity(); |
| 551 expected.Scale(0.8, 0.8); | 574 expected.Scale(0.8, 0.8); |
| 552 expected.Translate(9.0, 9.0); | 575 expected.Translate(9.0, 9.0); |
| 553 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, contribSharedState->content_to_tar
get_transform); | 576 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, contribSharedState->content_to_tar
get_transform); |
| 554 | 577 |
| 555 m_hostImpl->drawLayers(frame); | 578 m_hostImpl->drawLayers(frame); |
| 556 m_hostImpl->didDrawAllLayers(frame); | 579 m_hostImpl->didDrawAllLayers(frame); |
| 557 } | 580 } |
| 558 | 581 |
| 559 TEST_F(DelegatedRendererLayerImplTestSharedData, DisplaySize) | 582 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_NoSurface) |
| 560 { | 583 { |
| 561 // Cause the layer to scale its output to be larger than its bounds. | 584 m_rootDelegatedRenderPassIsClipped = true; |
| 562 m_delegatedRendererLayerPtr->setDisplaySize(gfx::Size(40, 40)); | 585 setUpTest(); |
| 563 EXPECT_LT(m_delegatedRendererLayerPtr->bounds().width(), 40); | |
| 564 EXPECT_LT(m_delegatedRendererLayerPtr->bounds().height(), 40); | |
| 565 | 586 |
| 566 LayerTreeHostImpl::FrameData frame; | 587 LayerTreeHostImpl::FrameData frame; |
| 567 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 588 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 568 | 589 |
| 569 ASSERT_EQ(2u, frame.renderPasses.size()); | 590 const SharedQuadState* rootSharedState = NULL; |
| 591 const SharedQuadState* contribSharedState = NULL; |
| 592 verifyRenderPasses(frame, 2, &rootSharedState, &contribSharedState); |
| 570 | 593 |
| 571 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; | 594 // Since the quads have a clip_rect it should be modified by delegated |
| 572 ASSERT_EQ(5u, rootQuadList.size()); | 595 // renderer layer's drawTransform. |
| 596 // The position of the resulting clip_rect is: |
| 597 // (clip rect position (10) * scale to layer (30/50) + translate (8)) * laye
r scale (2) + layer position (20) = 48 |
| 598 // 48 - (width / 2) = 48 - 30 / 2 = 33 |
| 599 // The size is 35x35 scaled to fit inside the layer's bounds at 30x30 from |
| 600 // a frame at 50x50: |
| 601 // 35 * 2 (layer's scale) * 30 / 50 = 42. |
| 602 EXPECT_RECT_EQ(gfx::Rect(33, 33, 42, 42), rootSharedState->clip_rect); |
| 573 | 603 |
| 574 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; | 604 // The quads had a clip and it should be preserved. |
| 605 EXPECT_TRUE(rootSharedState->is_clipped); |
| 575 | 606 |
| 576 // The results are similar to the SharedData test, but are scaled up by disp
laySize/bounds, which is 40/30. | |
| 577 EXPECT_RECT_EQ(gfx::Rect(21, 21, 80, 80), rootSharedState->clip_rect); | |
| 578 gfx::Transform expected; | 607 gfx::Transform expected; |
| 579 // This is the transform from the layer's space to its target. | 608 // This is the transform from the layer's space to its target. |
| 580 // The position (20) - the width / scale (30 / 2) = 20 - 15 = 5 | 609 // The position (20) - the width / scale (30 / 2) = 20 - 15 = 5 |
| 581 expected.Translate(5.0, 5.0); | 610 expected.Translate(5.0, 5.0); |
| 582 expected.Scale(2.0, 2.0); | 611 expected.Scale(2.0, 2.0); |
| 583 expected.Translate(8.0, 8.0); | 612 expected.Translate(8.0, 8.0); |
| 584 // The frame has size 50x50 but the layer's bounds are 30x30. | 613 // The frame has size 50x50 but the layer's bounds are 30x30. |
| 585 expected.Scale(30.0 / 50.0, 30.0 / 50.0); | 614 expected.Scale(30.0 / 50.0, 30.0 / 50.0); |
| 586 // The display size is 40x40 but the bounds are 30x30. | |
| 587 expected.Scale(40.0 / 30.0, 40.0 / 30.0); | |
| 588 // This is the transform within the source frame. | 615 // This is the transform within the source frame. |
| 589 expected.Scale(1.5, 1.5); | 616 expected.Scale(1.5, 1.5); |
| 590 expected.Translate(7.0, 7.0); | 617 expected.Translate(7.0, 7.0); |
| 591 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, rootSharedState->content_to_target
_transform); | 618 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, rootSharedState->content_to_target
_transform); |
| 592 | 619 |
| 593 m_hostImpl->drawLayers(frame); | 620 // The contributing render pass should not be transformed from its input. |
| 594 m_hostImpl->didDrawAllLayers(frame); | 621 EXPECT_RECT_EQ(gfx::Rect(21, 21, 3, 3), contribSharedState->clip_rect); |
| 595 } | 622 EXPECT_FALSE(contribSharedState->is_clipped); |
| 623 expected.MakeIdentity(); |
| 624 expected.Scale(0.8, 0.8); |
| 625 expected.Translate(9.0, 9.0); |
| 626 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, contribSharedState->content_to_tar
get_transform); |
| 627 |
| 628 m_hostImpl->drawLayers(frame); |
| 629 m_hostImpl->didDrawAllLayers(frame); |
| 630 } |
| 631 |
| 632 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_Surface) |
| 633 { |
| 634 m_rootDelegatedRenderPassIsClipped = false; |
| 635 setUpTest(); |
| 636 |
| 637 m_delegatedRendererLayerPtr->setForceRenderSurface(true); |
| 638 |
| 639 LayerTreeHostImpl::FrameData frame; |
| 640 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 641 |
| 642 const SharedQuadState* rootSharedState = NULL; |
| 643 const SharedQuadState* contribSharedState = NULL; |
| 644 verifyRenderPasses(frame, 3, &rootSharedState, &contribSharedState); |
| 645 |
| 646 // When the layer owns a surface, then its position and translation are not |
| 647 // a part of its draw transform. |
| 648 // The position of the resulting clip_rect is: |
| 649 // (clip rect position (10) * scale to layer (30/50)) * layer scale (2) = 12 |
| 650 // The size is 35x35 scaled to fit inside the layer's bounds at 30x30 from |
| 651 // a frame at 50x50: |
| 652 // 35 * 2 (layer's scale) * 30 / 50 = 42. |
| 653 EXPECT_RECT_EQ(gfx::Rect(12, 12, 42, 42), rootSharedState->clip_rect); |
| 654 |
| 655 // Since the layer owns a surface it doesn't need to clip its quads, so |
| 656 // unclipped quads remain unclipped. |
| 657 EXPECT_FALSE(rootSharedState->is_clipped); |
| 658 |
| 659 gfx::Transform expected; |
| 660 expected.Scale(2.0, 2.0); |
| 661 // The frame has size 50x50 but the layer's bounds are 30x30. |
| 662 expected.Scale(30.0 / 50.0, 30.0 / 50.0); |
| 663 // This is the transform within the source frame. |
| 664 expected.Scale(1.5, 1.5); |
| 665 expected.Translate(7.0, 7.0); |
| 666 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, rootSharedState->content_to_target
_transform); |
| 667 |
| 668 // The contributing render pass should not be transformed from its input. |
| 669 EXPECT_RECT_EQ(gfx::Rect(21, 21, 3, 3), contribSharedState->clip_rect); |
| 670 EXPECT_FALSE(contribSharedState->is_clipped); |
| 671 expected.MakeIdentity(); |
| 672 expected.Scale(0.8, 0.8); |
| 673 expected.Translate(9.0, 9.0); |
| 674 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, contribSharedState->content_to_tar
get_transform); |
| 675 |
| 676 m_hostImpl->drawLayers(frame); |
| 677 m_hostImpl->didDrawAllLayers(frame); |
| 678 } |
| 679 |
| 680 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_Surface) |
| 681 { |
| 682 m_rootDelegatedRenderPassIsClipped = true; |
| 683 setUpTest(); |
| 684 |
| 685 m_delegatedRendererLayerPtr->setForceRenderSurface(true); |
| 686 |
| 687 LayerTreeHostImpl::FrameData frame; |
| 688 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 689 |
| 690 const SharedQuadState* rootSharedState = NULL; |
| 691 const SharedQuadState* contribSharedState = NULL; |
| 692 verifyRenderPasses(frame, 3, &rootSharedState, &contribSharedState); |
| 693 |
| 694 // When the layer owns a surface, then its position and translation are not |
| 695 // a part of its draw transform. |
| 696 // The position of the resulting clip_rect is: |
| 697 // (clip rect position (10) * scale to layer (30/50)) * layer scale (2) = 12 |
| 698 // The size is 35x35 scaled to fit inside the layer's bounds at 30x30 from |
| 699 // a frame at 50x50: |
| 700 // 35 * 2 (layer's scale) * 30 / 50 = 42. |
| 701 EXPECT_RECT_EQ(gfx::Rect(12, 12, 42, 42), rootSharedState->clip_rect); |
| 702 |
| 703 // The quads had a clip and it should be preserved. |
| 704 EXPECT_TRUE(rootSharedState->is_clipped); |
| 705 |
| 706 gfx::Transform expected; |
| 707 expected.Scale(2.0, 2.0); |
| 708 // The frame has size 50x50 but the layer's bounds are 30x30. |
| 709 expected.Scale(30.0 / 50.0, 30.0 / 50.0); |
| 710 // This is the transform within the source frame. |
| 711 expected.Scale(1.5, 1.5); |
| 712 expected.Translate(7.0, 7.0); |
| 713 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, rootSharedState->content_to_target
_transform); |
| 714 |
| 715 // The contributing render pass should not be transformed from its input. |
| 716 EXPECT_RECT_EQ(gfx::Rect(21, 21, 3, 3), contribSharedState->clip_rect); |
| 717 EXPECT_FALSE(contribSharedState->is_clipped); |
| 718 expected.MakeIdentity(); |
| 719 expected.Scale(0.8, 0.8); |
| 720 expected.Translate(9.0, 9.0); |
| 721 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, contribSharedState->content_to_tar
get_transform); |
| 722 |
| 723 m_hostImpl->drawLayers(frame); |
| 724 m_hostImpl->didDrawAllLayers(frame); |
| 725 } |
| 726 |
| 727 class DelegatedRendererLayerImplTestClip : public DelegatedRendererLayerImplTest
{ |
| 728 public: |
| 729 void setUpTest() |
| 730 { |
| 731 scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(m_hostImpl->activeTr
ee(), 1); |
| 732 scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer = Delegate
dRendererLayerImpl::create(m_hostImpl->activeTree(), 2); |
| 733 scoped_ptr<LayerImpl> clipLayer = LayerImpl::create(m_hostImpl->activeTr
ee(), 3); |
| 734 scoped_ptr<LayerImpl> originLayer = LayerImpl::create(m_hostImpl->active
Tree(), 4); |
| 735 |
| 736 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); |
| 737 rootLayer->setBounds(gfx::Size(100, 100)); |
| 738 |
| 739 delegatedRendererLayer->setPosition(gfx::Point(20, 20)); |
| 740 delegatedRendererLayer->setBounds(gfx::Size(50, 50)); |
| 741 delegatedRendererLayer->setContentBounds(gfx::Size(50, 50)); |
| 742 delegatedRendererLayer->setDrawsContent(true); |
| 743 |
| 744 ScopedPtrVector<RenderPass> delegatedRenderPasses; |
| 745 |
| 746 gfx::Rect childPassRect(20, 20, 7, 7); |
| 747 gfx::Transform childPassTransform; |
| 748 gfx::Rect childPassClipRect(21, 21, 3, 3); |
| 749 bool childPassClipped = false; |
| 750 |
| 751 { |
| 752 TestRenderPass* pass = addRenderPass(delegatedRenderPasses, RenderPa
ss::Id(10, 7), childPassRect, gfx::Transform()); |
| 753 MockQuadCuller quadSink(pass->quad_list, pass->shared_quad_state_lis
t); |
| 754 AppendQuadsData data(pass->id); |
| 755 SharedQuadState* sharedState = quadSink.useSharedQuadState(SharedQua
dState::Create()); |
| 756 sharedState->SetAll(childPassTransform, childPassRect, childPassClip
Rect, childPassClipped, 1); |
| 757 scoped_ptr<SolidColorDrawQuad> colorQuad; |
| 758 |
| 759 colorQuad = SolidColorDrawQuad::Create(); |
| 760 colorQuad->SetNew(sharedState, gfx::Rect(20, 20, 3, 7), 1u); |
| 761 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); |
| 762 |
| 763 colorQuad = SolidColorDrawQuad::Create(); |
| 764 colorQuad->SetNew(sharedState, gfx::Rect(23, 20, 4, 7), 1u); |
| 765 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); |
| 766 } |
| 767 |
| 768 gfx::Rect passRect(0, 0, 50, 50); |
| 769 gfx::Transform passTransform; |
| 770 gfx::Rect passClipRect(5, 5, 40, 40); |
| 771 bool passClipped = m_rootDelegatedRenderPassIsClipped; |
| 772 |
| 773 TestRenderPass* pass = addRenderPass(delegatedRenderPasses, RenderPass::
Id(9, 6), passRect, gfx::Transform()); |
| 774 MockQuadCuller quadSink(pass->quad_list, pass->shared_quad_state_list); |
| 775 AppendQuadsData data(pass->id); |
| 776 SharedQuadState* sharedState = quadSink.useSharedQuadState(SharedQuadSta
te::Create()); |
| 777 sharedState->SetAll(passTransform, passRect, passClipRect, passClipped,
1); |
| 778 scoped_ptr<SolidColorDrawQuad> colorQuad; |
| 779 |
| 780 scoped_ptr<RenderPassDrawQuad> renderPassQuad = RenderPassDrawQuad::Crea
te(); |
| 781 renderPassQuad->SetNew( |
| 782 sharedState, |
| 783 gfx::Rect(5, 5, 7, 7), |
| 784 RenderPass::Id(10, 7), |
| 785 false, // is_replica |
| 786 0, // mask_resource_id |
| 787 childPassRect, // contents_changed_since_last_frame |
| 788 gfx::RectF(), // mask_uv_rect |
| 789 WebKit::WebFilterOperations(), // filters |
| 790 skia::RefPtr<SkImageFilter>(), // filter |
| 791 WebKit::WebFilterOperations()); // background_filters |
| 792 quadSink.append(renderPassQuad.PassAs<DrawQuad>(), data); |
| 793 |
| 794 colorQuad = SolidColorDrawQuad::Create(); |
| 795 colorQuad->SetNew(sharedState, gfx::Rect(0, 0, 10, 10), 1u); |
| 796 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); |
| 797 |
| 798 colorQuad = SolidColorDrawQuad::Create(); |
| 799 colorQuad->SetNew(sharedState, gfx::Rect(0, 10, 10, 10), 2u); |
| 800 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); |
| 801 |
| 802 colorQuad = SolidColorDrawQuad::Create(); |
| 803 colorQuad->SetNew(sharedState, gfx::Rect(10, 0, 10, 10), 3u); |
| 804 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); |
| 805 |
| 806 colorQuad = SolidColorDrawQuad::Create(); |
| 807 colorQuad->SetNew(sharedState, gfx::Rect(10, 10, 10, 10), 4u); |
| 808 quadSink.append(colorQuad.PassAs<DrawQuad>(), data); |
| 809 |
| 810 delegatedRendererLayer->setRenderPasses(delegatedRenderPasses); |
| 811 |
| 812 // The RenderPasses should be taken by the layer. |
| 813 EXPECT_EQ(0u, delegatedRenderPasses.size()); |
| 814 |
| 815 m_rootLayerPtr = rootLayer.get(); |
| 816 m_delegatedRendererLayerPtr = delegatedRendererLayer.get(); |
| 817 |
| 818 if (m_clipDelegatedRendererLayer) { |
| 819 gfx::Rect clipRect(21, 27, 23, 21); |
| 820 |
| 821 clipLayer->setPosition(clipRect.origin()); |
| 822 clipLayer->setBounds(clipRect.size()); |
| 823 clipLayer->setContentBounds(clipRect.size()); |
| 824 clipLayer->setMasksToBounds(true); |
| 825 clipLayer->setAnchorPoint(gfx::PointF()); |
| 826 |
| 827 originLayer->setPosition(gfx::PointAtOffsetFromOrigin(-clipRect.Offs
etFromOrigin())); |
| 828 originLayer->setAnchorPoint(gfx::PointF()); |
| 829 |
| 830 originLayer->addChild(delegatedRendererLayer.PassAs<LayerImpl>()); |
| 831 clipLayer->addChild(originLayer.Pass()); |
| 832 rootLayer->addChild(clipLayer.Pass()); |
| 833 } else { |
| 834 rootLayer->addChild(delegatedRendererLayer.PassAs<LayerImpl>()); |
| 835 } |
| 836 |
| 837 m_hostImpl->activeTree()->SetRootLayer(rootLayer.Pass()); |
| 838 } |
| 839 |
| 840 protected: |
| 841 LayerImpl* m_rootLayerPtr; |
| 842 DelegatedRendererLayerImpl* m_delegatedRendererLayerPtr; |
| 843 bool m_rootDelegatedRenderPassIsClipped; |
| 844 bool m_clipDelegatedRendererLayer; |
| 845 }; |
| 846 |
| 847 TEST_F(DelegatedRendererLayerImplTestClip, QuadsUnclipped_LayerUnclipped_NoSurfa
ce) |
| 848 { |
| 849 m_rootDelegatedRenderPassIsClipped = false; |
| 850 m_clipDelegatedRendererLayer = false; |
| 851 setUpTest(); |
| 852 |
| 853 LayerTreeHostImpl::FrameData frame; |
| 854 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 855 |
| 856 ASSERT_EQ(2u, frame.renderPasses.size()); |
| 857 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; |
| 858 ASSERT_EQ(2u, contribQuadList.size()); |
| 859 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; |
| 860 ASSERT_EQ(5u, rootQuadList.size()); |
| 861 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; |
| 862 const SharedQuadState* contribSharedState = contribQuadList[0]->shared_quad_
state; |
| 863 |
| 864 // When the quads don't have a clip of their own, the clip rect is set to |
| 865 // the drawableContentRect of the delegated renderer layer. |
| 866 EXPECT_RECT_EQ(gfx::Rect(20, 20, 50, 50), rootSharedState->clip_rect); |
| 867 // Quads are clipped to the delegated renderer layer. |
| 868 EXPECT_TRUE(rootSharedState->is_clipped); |
| 869 |
| 870 m_hostImpl->drawLayers(frame); |
| 871 m_hostImpl->didDrawAllLayers(frame); |
| 872 } |
| 873 |
| 874 TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerUnclipped_NoSurface
) |
| 875 { |
| 876 m_rootDelegatedRenderPassIsClipped = true; |
| 877 m_clipDelegatedRendererLayer = false; |
| 878 setUpTest(); |
| 879 |
| 880 LayerTreeHostImpl::FrameData frame; |
| 881 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 882 |
| 883 ASSERT_EQ(2u, frame.renderPasses.size()); |
| 884 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; |
| 885 ASSERT_EQ(2u, contribQuadList.size()); |
| 886 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; |
| 887 ASSERT_EQ(5u, rootQuadList.size()); |
| 888 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; |
| 889 const SharedQuadState* contribSharedState = contribQuadList[0]->shared_quad_
state; |
| 890 |
| 891 // When the quads have a clip of their own, it is used. |
| 892 EXPECT_RECT_EQ(gfx::Rect(25, 25, 40, 40), rootSharedState->clip_rect); |
| 893 // Quads came with a clip rect. |
| 894 EXPECT_TRUE(rootSharedState->is_clipped); |
| 895 |
| 896 m_hostImpl->drawLayers(frame); |
| 897 m_hostImpl->didDrawAllLayers(frame); |
| 898 } |
| 899 |
| 900 TEST_F(DelegatedRendererLayerImplTestClip, QuadsUnclipped_LayerClipped_NoSurface
) |
| 901 { |
| 902 m_rootDelegatedRenderPassIsClipped = false; |
| 903 m_clipDelegatedRendererLayer = true; |
| 904 setUpTest(); |
| 905 |
| 906 LayerTreeHostImpl::FrameData frame; |
| 907 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 908 |
| 909 ASSERT_EQ(2u, frame.renderPasses.size()); |
| 910 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; |
| 911 ASSERT_EQ(2u, contribQuadList.size()); |
| 912 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; |
| 913 ASSERT_EQ(5u, rootQuadList.size()); |
| 914 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; |
| 915 const SharedQuadState* contribSharedState = contribQuadList[0]->shared_quad_
state; |
| 916 |
| 917 // When the quads don't have a clip of their own, the clip rect is set to |
| 918 // the drawableContentRect of the delegated renderer layer. When the layer |
| 919 // is clipped, that should be seen in the quads' clip_rect. |
| 920 EXPECT_RECT_EQ(gfx::Rect(21, 27, 23, 21), rootSharedState->clip_rect); |
| 921 // Quads are clipped to the delegated renderer layer. |
| 922 EXPECT_TRUE(rootSharedState->is_clipped); |
| 923 |
| 924 m_hostImpl->drawLayers(frame); |
| 925 m_hostImpl->didDrawAllLayers(frame); |
| 926 } |
| 927 |
| 928 TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerClipped_NoSurface) |
| 929 { |
| 930 m_rootDelegatedRenderPassIsClipped = true; |
| 931 m_clipDelegatedRendererLayer = true; |
| 932 setUpTest(); |
| 933 |
| 934 LayerTreeHostImpl::FrameData frame; |
| 935 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 936 |
| 937 ASSERT_EQ(2u, frame.renderPasses.size()); |
| 938 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; |
| 939 ASSERT_EQ(2u, contribQuadList.size()); |
| 940 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; |
| 941 ASSERT_EQ(5u, rootQuadList.size()); |
| 942 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; |
| 943 const SharedQuadState* contribSharedState = contribQuadList[0]->shared_quad_
state; |
| 944 |
| 945 // When the quads have a clip of their own, it is used, but it is |
| 946 // combined with the clip rect of the delegated renderer layer. |
| 947 EXPECT_RECT_EQ(gfx::Rect(25, 27, 19, 21), rootSharedState->clip_rect); |
| 948 // Quads came with a clip rect. |
| 949 EXPECT_TRUE(rootSharedState->is_clipped); |
| 950 |
| 951 m_hostImpl->drawLayers(frame); |
| 952 m_hostImpl->didDrawAllLayers(frame); |
| 953 } |
| 954 |
| 955 TEST_F(DelegatedRendererLayerImplTestClip, QuadsUnclipped_LayerUnclipped_Surface
) |
| 956 { |
| 957 m_rootDelegatedRenderPassIsClipped = false; |
| 958 m_clipDelegatedRendererLayer = false; |
| 959 setUpTest(); |
| 960 |
| 961 m_delegatedRendererLayerPtr->setForceRenderSurface(true); |
| 962 |
| 963 LayerTreeHostImpl::FrameData frame; |
| 964 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 965 |
| 966 ASSERT_EQ(3u, frame.renderPasses.size()); |
| 967 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; |
| 968 ASSERT_EQ(2u, contribQuadList.size()); |
| 969 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; |
| 970 ASSERT_EQ(5u, rootQuadList.size()); |
| 971 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; |
| 972 const SharedQuadState* contribSharedState = contribQuadList[0]->shared_quad_
state; |
| 973 |
| 974 // When the layer owns a surface, the quads don't need to be clipped |
| 975 // further than they already specify. If they aren't clipped, then their |
| 976 // clip rect is ignored, and they are not set as clipped. |
| 977 EXPECT_FALSE(rootSharedState->is_clipped); |
| 978 |
| 979 m_hostImpl->drawLayers(frame); |
| 980 m_hostImpl->didDrawAllLayers(frame); |
| 981 } |
| 982 |
| 983 TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerUnclipped_Surface) |
| 984 { |
| 985 m_rootDelegatedRenderPassIsClipped = true; |
| 986 m_clipDelegatedRendererLayer = false; |
| 987 setUpTest(); |
| 988 |
| 989 m_delegatedRendererLayerPtr->setForceRenderSurface(true); |
| 990 |
| 991 LayerTreeHostImpl::FrameData frame; |
| 992 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 993 |
| 994 ASSERT_EQ(3u, frame.renderPasses.size()); |
| 995 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; |
| 996 ASSERT_EQ(2u, contribQuadList.size()); |
| 997 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; |
| 998 ASSERT_EQ(5u, rootQuadList.size()); |
| 999 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; |
| 1000 const SharedQuadState* contribSharedState = contribQuadList[0]->shared_quad_
state; |
| 1001 |
| 1002 // When the quads have a clip of their own, it is used. |
| 1003 EXPECT_RECT_EQ(gfx::Rect(5, 5, 40, 40), rootSharedState->clip_rect); |
| 1004 // Quads came with a clip rect. |
| 1005 EXPECT_TRUE(rootSharedState->is_clipped); |
| 1006 |
| 1007 m_hostImpl->drawLayers(frame); |
| 1008 m_hostImpl->didDrawAllLayers(frame); |
| 1009 } |
| 1010 |
| 1011 TEST_F(DelegatedRendererLayerImplTestClip, QuadsUnclipped_LayerClipped_Surface) |
| 1012 { |
| 1013 m_rootDelegatedRenderPassIsClipped = false; |
| 1014 m_clipDelegatedRendererLayer = true; |
| 1015 setUpTest(); |
| 1016 |
| 1017 m_delegatedRendererLayerPtr->setForceRenderSurface(true); |
| 1018 |
| 1019 LayerTreeHostImpl::FrameData frame; |
| 1020 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1021 |
| 1022 ASSERT_EQ(3u, frame.renderPasses.size()); |
| 1023 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; |
| 1024 ASSERT_EQ(2u, contribQuadList.size()); |
| 1025 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; |
| 1026 ASSERT_EQ(5u, rootQuadList.size()); |
| 1027 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; |
| 1028 const SharedQuadState* contribSharedState = contribQuadList[0]->shared_quad_
state; |
| 1029 |
| 1030 // When the layer owns a surface, the quads don't need to be clipped |
| 1031 // further than they already specify. If they aren't clipped, then their |
| 1032 // clip rect is ignored, and they are not set as clipped. |
| 1033 EXPECT_FALSE(rootSharedState->is_clipped); |
| 1034 |
| 1035 m_hostImpl->drawLayers(frame); |
| 1036 m_hostImpl->didDrawAllLayers(frame); |
| 1037 } |
| 1038 |
| 1039 TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerClipped_Surface) |
| 1040 { |
| 1041 m_rootDelegatedRenderPassIsClipped = true; |
| 1042 m_clipDelegatedRendererLayer = true; |
| 1043 setUpTest(); |
| 1044 |
| 1045 m_delegatedRendererLayerPtr->setForceRenderSurface(true); |
| 1046 |
| 1047 LayerTreeHostImpl::FrameData frame; |
| 1048 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 1049 |
| 1050 ASSERT_EQ(3u, frame.renderPasses.size()); |
| 1051 const QuadList& contribQuadList = frame.renderPasses[0]->quad_list; |
| 1052 ASSERT_EQ(2u, contribQuadList.size()); |
| 1053 const QuadList& rootQuadList = frame.renderPasses[1]->quad_list; |
| 1054 ASSERT_EQ(5u, rootQuadList.size()); |
| 1055 const SharedQuadState* rootSharedState = rootQuadList[0]->shared_quad_state; |
| 1056 const SharedQuadState* contribSharedState = contribQuadList[0]->shared_quad_
state; |
| 1057 |
| 1058 // When the quads have a clip of their own, it is used, but it is |
| 1059 // combined with the clip rect of the delegated renderer layer. If the |
| 1060 // layer owns a surface, then it does not have a clip rect of its own. |
| 1061 EXPECT_RECT_EQ(gfx::Rect(5, 5, 40, 40), rootSharedState->clip_rect); |
| 1062 // Quads came with a clip rect. |
| 1063 EXPECT_TRUE(rootSharedState->is_clipped); |
| 1064 |
| 1065 m_hostImpl->drawLayers(frame); |
| 1066 m_hostImpl->didDrawAllLayers(frame); |
| 1067 } |
| 596 | 1068 |
| 597 } // namespace | 1069 } // namespace |
| 598 } // namespace cc | 1070 } // namespace cc |
| OLD | NEW |