| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 | 728 |
| 729 gfx::Transform transform; | 729 gfx::Transform transform; |
| 730 transform.Scale(2, 1); | 730 transform.Scale(2, 1); |
| 731 transform.Translate(10, 5); | 731 transform.Translate(10, 5); |
| 732 | 732 |
| 733 layer->SetTransform(transform); | 733 layer->SetTransform(transform); |
| 734 layer->SetColor(SK_ColorRED); | 734 layer->SetColor(SK_ColorRED); |
| 735 layer->SetLayerInverted(true); | 735 layer->SetLayerInverted(true); |
| 736 const float temperature = 0.8f; | 736 const float temperature = 0.8f; |
| 737 layer->SetLayerTemperature(temperature); | 737 layer->SetLayerTemperature(temperature); |
| 738 layer->SetCacheRenderSurface(true); |
| 738 | 739 |
| 739 auto clone = layer->Clone(); | 740 auto clone = layer->Clone(); |
| 740 | 741 |
| 741 // Cloning preserves layer state. | 742 // Cloning preserves layer state. |
| 742 EXPECT_EQ(transform, clone->GetTargetTransform()); | 743 EXPECT_EQ(transform, clone->GetTargetTransform()); |
| 743 EXPECT_EQ(SK_ColorRED, clone->background_color()); | 744 EXPECT_EQ(SK_ColorRED, clone->background_color()); |
| 744 EXPECT_EQ(SK_ColorRED, clone->GetTargetColor()); | 745 EXPECT_EQ(SK_ColorRED, clone->GetTargetColor()); |
| 745 EXPECT_TRUE(clone->layer_inverted()); | 746 EXPECT_TRUE(clone->layer_inverted()); |
| 746 EXPECT_FLOAT_EQ(temperature, clone->GetTargetTemperature()); | 747 EXPECT_FLOAT_EQ(temperature, clone->GetTargetTemperature()); |
| 748 // Cloning should not preserve cache_render_surface flag. |
| 749 EXPECT_NE(layer->cc_layer_for_testing()->cache_render_surface(), |
| 750 clone->cc_layer_for_testing()->cache_render_surface()); |
| 747 | 751 |
| 748 layer->SetTransform(gfx::Transform()); | 752 layer->SetTransform(gfx::Transform()); |
| 749 layer->SetColor(SK_ColorGREEN); | 753 layer->SetColor(SK_ColorGREEN); |
| 750 layer->SetLayerInverted(false); | 754 layer->SetLayerInverted(false); |
| 751 | 755 |
| 752 // The clone is an independent copy, so state changes do not propagate. | 756 // The clone is an independent copy, so state changes do not propagate. |
| 753 EXPECT_EQ(transform, clone->GetTargetTransform()); | 757 EXPECT_EQ(transform, clone->GetTargetTransform()); |
| 754 EXPECT_EQ(SK_ColorRED, clone->background_color()); | 758 EXPECT_EQ(SK_ColorRED, clone->background_color()); |
| 755 EXPECT_EQ(SK_ColorRED, clone->GetTargetColor()); | 759 EXPECT_EQ(SK_ColorRED, clone->GetTargetColor()); |
| 756 EXPECT_TRUE(clone->layer_inverted()); | 760 EXPECT_TRUE(clone->layer_inverted()); |
| (...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1990 | 1994 |
| 1991 // End all animations. | 1995 // End all animations. |
| 1992 root->GetAnimator()->StopAnimating(); | 1996 root->GetAnimator()->StopAnimating(); |
| 1993 EXPECT_FALSE(root->fills_bounds_opaquely()); | 1997 EXPECT_FALSE(root->fills_bounds_opaquely()); |
| 1994 EXPECT_FALSE( | 1998 EXPECT_FALSE( |
| 1995 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); | 1999 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); |
| 1996 EXPECT_EQ(transparent, root->background_color()); | 2000 EXPECT_EQ(transparent, root->background_color()); |
| 1997 EXPECT_EQ(transparent, root->GetTargetColor()); | 2001 EXPECT_EQ(transparent, root->GetTargetColor()); |
| 1998 } | 2002 } |
| 1999 | 2003 |
| 2004 // Tests that when a layer with cache_render_surface flag has its CC layer |
| 2005 // switched, that the cache_render_surface flag is maintained. |
| 2006 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerCacheRenderSurface) { |
| 2007 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
| 2008 std::unique_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); |
| 2009 GetCompositor()->SetRootLayer(root.get()); |
| 2010 root->Add(l1.get()); |
| 2011 |
| 2012 l1->SetCacheRenderSurface(true); |
| 2013 |
| 2014 // Change l1's cc::Layer. |
| 2015 l1->SwitchCCLayerForTest(); |
| 2016 |
| 2017 // Ensure that the cache_render_surface flag is maintained. |
| 2018 EXPECT_TRUE(l1->cc_layer_for_testing()->cache_render_surface()); |
| 2019 } |
| 2020 |
| 2000 // Tests that the animators in the layer tree is added to the | 2021 // Tests that the animators in the layer tree is added to the |
| 2001 // animator-collection when the root-layer is set to the compositor. | 2022 // animator-collection when the root-layer is set to the compositor. |
| 2002 TEST_F(LayerWithDelegateTest, RootLayerAnimatorsInCompositor) { | 2023 TEST_F(LayerWithDelegateTest, RootLayerAnimatorsInCompositor) { |
| 2003 std::unique_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); | 2024 std::unique_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); |
| 2004 std::unique_ptr<Layer> child( | 2025 std::unique_ptr<Layer> child( |
| 2005 CreateColorLayer(SK_ColorRED, gfx::Rect(10, 10))); | 2026 CreateColorLayer(SK_ColorRED, gfx::Rect(10, 10))); |
| 2006 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 2027 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
| 2007 child->SetOpacity(0.5f); | 2028 child->SetOpacity(0.5f); |
| 2008 root->Add(child.get()); | 2029 root->Add(child.get()); |
| 2009 | 2030 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 layer.set_name("foo"); | 2271 layer.set_name("foo"); |
| 2251 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = | 2272 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = |
| 2252 layer.TakeDebugInfo(nullptr); | 2273 layer.TakeDebugInfo(nullptr); |
| 2253 std::string trace_format("bar,"); | 2274 std::string trace_format("bar,"); |
| 2254 debug_info->AppendAsTraceFormat(&trace_format); | 2275 debug_info->AppendAsTraceFormat(&trace_format); |
| 2255 std::string expected("bar,{\"layer_name\":\"foo\"}"); | 2276 std::string expected("bar,{\"layer_name\":\"foo\"}"); |
| 2256 EXPECT_EQ(expected, trace_format); | 2277 EXPECT_EQ(expected, trace_format); |
| 2257 } | 2278 } |
| 2258 | 2279 |
| 2259 } // namespace ui | 2280 } // namespace ui |
| OLD | NEW |