Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: cc/layer_tree_host_impl_unittest.cc

Issue 11883027: Fix masks when scaling is in the tree (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | cc/render_surface_impl.cc » ('j') | cc/render_surface_impl.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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_impl.h" 5 #include "cc/layer_tree_host_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 4409 matching lines...) Expand 10 before | Expand all | Expand 10 after
4420 { 4420 {
4421 // Draw a frame. In the first frame, the entire viewport should be damaged. 4421 // Draw a frame. In the first frame, the entire viewport should be damaged.
4422 gfx::Rect fullFrameDamage = gfx::Rect(m_hostImpl->deviceViewportSize()); 4422 gfx::Rect fullFrameDamage = gfx::Rect(m_hostImpl->deviceViewportSize());
4423 drawFrameAndTestDamage(fullFrameDamage); 4423 drawFrameAndTestDamage(fullFrameDamage);
4424 4424
4425 // The second frame should have no damage, but the quads should still be gen erated. 4425 // The second frame should have no damage, but the quads should still be gen erated.
4426 gfx::Rect noDamage = gfx::Rect(m_hostImpl->deviceViewportSize()); 4426 gfx::Rect noDamage = gfx::Rect(m_hostImpl->deviceViewportSize());
4427 drawFrameAndTestDamage(noDamage); 4427 drawFrameAndTestDamage(noDamage);
4428 } 4428 }
4429 4429
4430 class FakeMaskLayerImpl : public LayerImpl {
4431 public:
4432 static scoped_ptr<FakeMaskLayerImpl> create(LayerTreeImpl* treeImpl, int id)
4433 {
4434 return make_scoped_ptr(new FakeMaskLayerImpl(treeImpl, id));
4435 }
4436
4437 virtual ResourceProvider::ResourceId contentsResourceId() const { return 0; }
4438
4439 private:
4440 FakeMaskLayerImpl(LayerTreeImpl* treeImpl, int id) : LayerImpl(treeImpl, id) { }
4441 };
4442
4443 TEST_P(LayerTreeHostImplTest, maskLayerWithScaling)
4444 {
4445 // Root
4446 // |
4447 // +-- Scaling Layer (adds a 2x scale)
4448 // |
4449 // +-- Content Layer
4450 // +--Mask
4451 scoped_ptr<LayerImpl> scopedRoot = LayerImpl::create(m_hostImpl->activeTree( ), 1);
4452 LayerImpl* root = scopedRoot.get();
4453 m_hostImpl->activeTree()->SetRootLayer(scopedRoot.Pass());
4454
4455 scoped_ptr<LayerImpl> scopedScalingLayer = LayerImpl::create(m_hostImpl->act iveTree(), 2);
4456 LayerImpl* scalingLayer = scopedScalingLayer.get();
4457 root->addChild(scopedScalingLayer.Pass());
4458
4459 scoped_ptr<LayerImpl> scopedContentLayer = LayerImpl::create(m_hostImpl->act iveTree(), 3);
4460 LayerImpl* contentLayer = scopedContentLayer.get();
4461 scalingLayer->addChild(scopedContentLayer.Pass());
4462
4463 scoped_ptr<FakeMaskLayerImpl> scopedMaskLayer = FakeMaskLayerImpl::create(m_ hostImpl->activeTree(), 4);
4464 FakeMaskLayerImpl* maskLayer = scopedMaskLayer.get();
4465 contentLayer->setMaskLayer(scopedMaskLayer.PassAs<LayerImpl>());
4466
4467 gfx::Size rootSize(100, 100);
4468 root->setBounds(rootSize);
4469 root->setContentBounds(rootSize);
4470 root->setPosition(gfx::PointF());
4471 root->setAnchorPoint(gfx::PointF());
4472
4473 gfx::Size scalingLayerSize(50, 50);
4474 scalingLayer->setBounds(scalingLayerSize);
4475 scalingLayer->setContentBounds(scalingLayerSize);
4476 scalingLayer->setPosition(gfx::PointF());
4477 scalingLayer->setAnchorPoint(gfx::PointF());
4478 gfx::Transform scale;
4479 scale.Scale(2.0, 2.0);
4480 scalingLayer->setTransform(scale);
4481
4482 contentLayer->setBounds(scalingLayerSize);
4483 contentLayer->setContentBounds(scalingLayerSize);
4484 contentLayer->setPosition(gfx::PointF());
4485 contentLayer->setAnchorPoint(gfx::PointF());
4486 contentLayer->setDrawsContent(true);
4487
4488 maskLayer->setBounds(scalingLayerSize);
4489 maskLayer->setContentBounds(scalingLayerSize);
4490 maskLayer->setPosition(gfx::PointF());
4491 maskLayer->setAnchorPoint(gfx::PointF());
4492 maskLayer->setDrawsContent(true);
4493
4494
4495 // Check that the tree scaling is correctly taken into account for the mask,
4496 // that should fully map onto the quad.
4497 float deviceScaleFactor = 1.f;
4498 m_hostImpl->setViewportSize(rootSize, rootSize);
4499 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor);
4500 {
4501 LayerTreeHostImpl::FrameData frame;
4502 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame));
4503
4504 ASSERT_EQ(1u, frame.renderPasses.size());
4505 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size());
4506 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial);
4507 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]);
4508 EXPECT_EQ(renderPassQuad->rect.ToString(), gfx::Rect(0, 0, 100, 100).ToS tring());
4509 EXPECT_EQ(renderPassQuad->mask_uv_rect.ToString(), gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString());
4510
4511 m_hostImpl->drawLayers(frame);
4512 m_hostImpl->didDrawAllLayers(frame);
4513 }
4514
4515
4516 // Applying a DSF should change the render surface size, but won't affect
4517 // which part of the mask is used.
4518 deviceScaleFactor = 2.f;
4519 gfx::Size deviceViewport(gfx::ToFlooredSize(gfx::ScaleSize(rootSize, deviceS caleFactor)));
4520 m_hostImpl->setViewportSize(rootSize, deviceViewport);
4521 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor);
4522 m_hostImpl->setNeedsUpdateDrawProperties();
4523 {
4524 LayerTreeHostImpl::FrameData frame;
4525 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame));
4526
4527 ASSERT_EQ(1u, frame.renderPasses.size());
4528 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size());
4529 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial);
4530 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]);
4531 EXPECT_EQ(renderPassQuad->rect.ToString(), gfx::Rect(0, 0, 200, 200).ToS tring());
4532 EXPECT_EQ(renderPassQuad->mask_uv_rect.ToString(), gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString());
4533
4534 m_hostImpl->drawLayers(frame);
4535 m_hostImpl->didDrawAllLayers(frame);
4536 }
4537
4538
4539 // Applying an equivalent content scale on the content layer and the mask
4540 // should still result in the same part of the mask being used.
4541 gfx::Size contentsBounds(gfx::ToRoundedSize(gfx::ScaleSize(scalingLayerSize, deviceScaleFactor)));
4542 contentLayer->setContentBounds(contentsBounds);
4543 contentLayer->setContentsScale(deviceScaleFactor, deviceScaleFactor);
4544 maskLayer->setContentBounds(contentsBounds);
4545 maskLayer->setContentsScale(deviceScaleFactor, deviceScaleFactor);
4546 m_hostImpl->setNeedsUpdateDrawProperties();
4547 {
4548 LayerTreeHostImpl::FrameData frame;
4549 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame));
4550
4551 ASSERT_EQ(1u, frame.renderPasses.size());
4552 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size());
4553 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial);
4554 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]);
4555 EXPECT_EQ(renderPassQuad->rect.ToString(), gfx::Rect(0, 0, 200, 200).ToS tring());
4556 EXPECT_EQ(renderPassQuad->mask_uv_rect.ToString(), gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString());
4557
4558 m_hostImpl->drawLayers(frame);
4559 m_hostImpl->didDrawAllLayers(frame);
4560 }
4561 }
4562
4430 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, 4563 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests,
4431 LayerTreeHostImplTest, 4564 LayerTreeHostImplTest,
4432 ::testing::Values(false, true)); 4565 ::testing::Values(false, true));
4433 4566
4434 } // namespace 4567 } // namespace
4435 } // namespace cc 4568 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/render_surface_impl.cc » ('j') | cc/render_surface_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698