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

Side by Side Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 26112002: cc: Fix hit-testing in zero-opacity layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test Created 7 years, 2 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 | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »
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/trees/layer_tree_host_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "cc/animation/layer_animation_controller.h" 9 #include "cc/animation/layer_animation_controller.h"
10 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
(...skipping 5398 matching lines...) Expand 10 before | Expand all | Expand 10 after
5409 EXPECT_EQ(3, result_layer->id()); 5409 EXPECT_EQ(3, result_layer->id());
5410 5410
5411 // Hit testing for a point inside the mousewheel layer should return it. 5411 // Hit testing for a point inside the mousewheel layer should return it.
5412 test_point = gfx::Point(75, 75); 5412 test_point = gfx::Point(75, 75);
5413 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( 5413 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5414 test_point, render_surface_layer_list); 5414 test_point, render_surface_layer_list);
5415 ASSERT_TRUE(result_layer); 5415 ASSERT_TRUE(result_layer);
5416 EXPECT_EQ(4, result_layer->id()); 5416 EXPECT_EQ(4, result_layer->id());
5417 } 5417 }
5418 5418
5419 TEST_F(LayerTreeHostCommonTest, ZeroOpacityLayersWithEventHandlerChild) {
5420 FakeImplProxy proxy;
5421 FakeLayerTreeHostImpl host_impl(&proxy);
5422 const int kRootId = 1;
5423 const int kNoHandlerChildId = 4;
5424 const int kGrandChildWithEventId = 5;
5425 const int kGrandChildWithoutEventId = 6;
5426
5427 scoped_ptr<LayerImpl> root =
5428 LayerImpl::Create(host_impl.active_tree(), 1);
5429 gfx::Transform identity_matrix;
5430 gfx::PointF anchor;
5431 gfx::PointF position;
5432 gfx::Size bounds(100, 100);
5433 SetLayerPropertiesForTesting(root.get(),
5434 identity_matrix,
5435 identity_matrix,
5436 anchor,
5437 position,
5438 bounds,
5439 false);
5440 root->SetDrawsContent(true);
5441
5442 // Child - Zero opacity, without any event handler.
5443 scoped_ptr<LayerImpl> child =
5444 LayerImpl::Create(host_impl.active_tree(), kNoHandlerChildId);
5445 SetLayerPropertiesForTesting(child.get(),
5446 identity_matrix,
5447 identity_matrix,
5448 anchor,
5449 gfx::PointF(10.f, 10.f),
5450 gfx::Size(30, 30),
5451 false);
5452 child->SetOpacity(0.f);
5453 child->SetDrawsContent(true);
5454
5455 // Grandchild - with a wheel handler.
5456 {
5457 scoped_ptr<LayerImpl> grand_child =
5458 LayerImpl::Create(host_impl.active_tree(), kGrandChildWithEventId);
5459 SetLayerPropertiesForTesting(grand_child.get(),
5460 identity_matrix,
5461 identity_matrix,
5462 gfx::PointF(),
5463 gfx::PointF(10, 10),
5464 gfx::Size(10, 10),
5465 false);
5466 grand_child->SetHaveWheelEventHandlers(true);
5467 grand_child->SetDrawsContent(true);
5468 child->AddChild(grand_child.Pass());
5469 }
5470
5471 // Grandchild - without any event handlers.
5472 {
5473 scoped_ptr<LayerImpl> grand_child =
5474 LayerImpl::Create(host_impl.active_tree(), kGrandChildWithoutEventId);
5475 SetLayerPropertiesForTesting(grand_child.get(),
5476 identity_matrix,
5477 identity_matrix,
5478 gfx::PointF(),
5479 gfx::PointF(20, 10),
5480 gfx::Size(10, 10),
5481 false);
5482 grand_child->SetDrawsContent(true);
5483 child->AddChild(grand_child.Pass());
5484 }
5485
5486 root->AddChild(child.Pass());
5487
5488 LayerImplList render_surface_layer_list;
5489 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5490 root.get(), root->bounds(), &render_surface_layer_list);
5491 inputs.can_adjust_raster_scales = true;
5492 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5493
5494 // Verify that both the root layer and zero-opacity child layer are in the
5495 // RSLL (since the child layer has multiple drawing children).
5496 ASSERT_EQ(2u, render_surface_layer_list.size());
5497 EXPECT_EQ(kRootId, render_surface_layer_list[0]->id());
5498 EXPECT_EQ(kNoHandlerChildId, render_surface_layer_list[1]->id());
5499
5500 // The zero-opacity child layer should not be in the layer-list of the root's
5501 // surface.
5502 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5503 EXPECT_EQ(kRootId, root->render_surface()->layer_list().at(0)->id());
5504
5505 ASSERT_EQ(2u, root->children()[0]->render_surface()->layer_list().size());
5506 EXPECT_EQ(kNoHandlerChildId,
danakj 2013/10/09 19:14:59 This shouldn't be present, it doesn't have a handl
5507 root->children()[0]->render_surface()->layer_list().at(0)->id());
5508 EXPECT_EQ(kGrandChildWithEventId,
5509 root->children()[0]->render_surface()->layer_list().at(1)->id());
5510 }
5511
5512 TEST_F(LayerTreeHostCommonTest,
5513 ZeroOpacityLayerRenderSurfaceChildEventHandlerGrandChild) {
5514 FakeImplProxy proxy;
5515 FakeLayerTreeHostImpl host_impl(&proxy);
5516 const int kRootId = 1;
5517 const int kForceSurfaceLayer = 4;
5518 const int kZeroOpacityLayer = 5;
5519 const int kTouchHandlerLayer = 6;
5520
5521 scoped_ptr<LayerImpl> root =
5522 LayerImpl::Create(host_impl.active_tree(), 1);
5523 gfx::Transform identity_matrix;
5524 gfx::PointF anchor;
5525 gfx::PointF position;
5526 gfx::Size bounds(100, 100);
5527 SetLayerPropertiesForTesting(root.get(),
5528 identity_matrix,
5529 identity_matrix,
5530 anchor,
5531 position,
5532 bounds,
5533 false);
5534 root->SetDrawsContent(true);
5535
5536 // Layer with zero opacity.
5537 scoped_ptr<LayerImpl> zero_opacity_layer =
5538 LayerImpl::Create(host_impl.active_tree(), kZeroOpacityLayer);
5539 SetLayerPropertiesForTesting(zero_opacity_layer.get(),
5540 identity_matrix,
5541 identity_matrix,
5542 anchor,
5543 gfx::PointF(10.f, 10.f),
5544 gfx::Size(50, 50),
5545 false);
5546 zero_opacity_layer->SetOpacity(0.f);
5547
5548 // Child with a render surface.
5549 scoped_ptr<LayerImpl> render_surface_layer =
5550 LayerImpl::Create(host_impl.active_tree(), kForceSurfaceLayer);
5551 SetLayerPropertiesForTesting(render_surface_layer.get(),
5552 identity_matrix,
5553 identity_matrix,
5554 gfx::PointF(),
5555 gfx::PointF(10, 10),
5556 gfx::Size(40, 40),
5557 false);
5558 render_surface_layer->SetForceRenderSurface(true);
5559 render_surface_layer->SetDrawsContent(true);
5560
5561 // Grandchild with a touch handler.
5562 scoped_ptr<LayerImpl> touch_handler_layer =
5563 LayerImpl::Create(host_impl.active_tree(), kTouchHandlerLayer);
5564 SetLayerPropertiesForTesting(touch_handler_layer.get(),
5565 identity_matrix,
5566 identity_matrix,
5567 gfx::PointF(),
5568 gfx::PointF(10, 10),
5569 gfx::Size(10, 10),
5570 false);
5571 touch_handler_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 10, 10));
5572 touch_handler_layer->SetDrawsContent(true);
5573
5574 render_surface_layer->AddChild(touch_handler_layer.Pass());
5575 zero_opacity_layer->AddChild(render_surface_layer.Pass());
5576 root->AddChild(zero_opacity_layer.Pass());
5577
5578 LayerImplList render_surface_layer_list;
5579 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5580 root.get(), root->bounds(), &render_surface_layer_list);
5581 inputs.can_adjust_raster_scales = true;
5582 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5583
5584 // Verify that both the root layer and child layer are in the RSLL (since both
5585 // own surfaces).
5586 ASSERT_EQ(3u, render_surface_layer_list.size());
5587 EXPECT_EQ(kRootId, render_surface_layer_list[0]->id());
sadrul 2013/10/10 18:01:31 The other issue I am hitting is, when we get kRoot
enne (OOO) 2013/10/15 17:56:49 Yes. The front-to-back iterator that the LayerTre
5588 EXPECT_EQ(kZeroOpacityLayer, render_surface_layer_list[1]->id());
5589 EXPECT_EQ(kForceSurfaceLayer, render_surface_layer_list[2]->id());
5590
5591 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5592 EXPECT_EQ(kRootId, root->render_surface()->layer_list().at(0)->id());
5593
5594 LayerImpl* zero_opacity_raw = root->children()[0];
5595 ASSERT_EQ(0u,
5596 zero_opacity_raw->render_surface()->layer_list().size());
sadrul 2013/10/10 17:08:46 One of the issues I ran into is that RemoveSurface
danakj 2013/10/10 17:16:38 Hm... Maybe it's okay and better to not have thos
sadrul 2013/10/10 17:41:39 |RemoveSurfaceForEarlyExit()| also removes all sur
enne (OOO) 2013/10/15 17:56:49 Ack. That's really unfortunate. As the comment s
5597
5598 LayerImpl* render_surface_raw = zero_opacity_raw->children()[0];
5599 ASSERT_EQ(1u,
5600 render_surface_raw->render_surface()->layer_list().size());
5601 EXPECT_EQ(kTouchHandlerLayer,
5602 render_surface_raw->render_surface()->layer_list().at(0)->id());
5603 }
5604
5419 TEST_F(LayerTreeHostCommonTest, 5605 TEST_F(LayerTreeHostCommonTest,
5420 HitCheckingTouchHandlerRegionsForEmptyLayerList) { 5606 HitCheckingTouchHandlerRegionsForEmptyLayerList) {
5421 // Hit checking on an empty render_surface_layer_list should return a null 5607 // Hit checking on an empty render_surface_layer_list should return a null
5422 // pointer. 5608 // pointer.
5423 LayerImplList render_surface_layer_list; 5609 LayerImplList render_surface_layer_list;
5424 5610
5425 gfx::Point test_point(0, 0); 5611 gfx::Point test_point(0, 0);
5426 LayerImpl* result_layer = 5612 LayerImpl* result_layer =
5427 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( 5613 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5428 test_point, render_surface_layer_list); 5614 test_point, render_surface_layer_list);
(...skipping 4110 matching lines...) Expand 10 before | Expand all | Expand 10 after
9539 // due to layer sorting). 9725 // due to layer sorting).
9540 EXPECT_EQ(4u, root->render_surface()->layer_list().size()); 9726 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
9541 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id()); 9727 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
9542 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id()); 9728 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
9543 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id()); 9729 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
9544 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id()); 9730 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
9545 } 9731 }
9546 9732
9547 } // namespace 9733 } // namespace
9548 } // namespace cc 9734 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698