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

Side by Side Diff: views/view_unittest.cc

Issue 8222028: Use WebKit compositor in ui::Layer (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebase Created 9 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 | « views/run_all_unittests.cc ('k') | views/views.gyp » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <map> 5 #include <map>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 2559 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 #if defined(USE_AURA) 2570 #if defined(USE_AURA)
2571 ui::Layer* root_layer = NULL; 2571 ui::Layer* root_layer = NULL;
2572 gfx::Point origin; 2572 gfx::Point origin;
2573 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer); 2573 widget()->CalculateOffsetToAncestorWithLayer(&origin, &root_layer);
2574 #else 2574 #else
2575 ui::Layer* root_layer = widget()->GetRootView()->layer(); 2575 ui::Layer* root_layer = widget()->GetRootView()->layer();
2576 #endif 2576 #endif
2577 View* content_view = new View; 2577 View* content_view = new View;
2578 widget()->SetContentsView(content_view); 2578 widget()->SetContentsView(content_view);
2579 2579
2580 #if !defined(USE_WEBKIT_COMPOSITOR)
2581 // TODO(piman): with the webkit compositor, we don't create Textures on
2582 // Layers. We're not supposed to be calling Layer::DrawTree. This test needs
2583 // refactoring to fully work in that case.
2580 root_layer->DrawTree(); 2584 root_layer->DrawTree();
2581 ui::TestTexture::reset_live_count(); 2585 ui::TestTexture::reset_live_count();
2586 #endif
2582 2587
2583 // Create v1, give it a bounds and verify everything is set up correctly. 2588 // Create v1, give it a bounds and verify everything is set up correctly.
2584 View* v1 = new View; 2589 View* v1 = new View;
2585 v1->SetPaintToLayer(true); 2590 v1->SetPaintToLayer(true);
2591 #if !defined(USE_WEBKIT_COMPOSITOR)
2586 root_layer->DrawTree(); 2592 root_layer->DrawTree();
2587 EXPECT_EQ(0, ui::TestTexture::live_count()); 2593 EXPECT_EQ(0, ui::TestTexture::live_count());
2594 #endif
2588 EXPECT_TRUE(v1->layer() != NULL); 2595 EXPECT_TRUE(v1->layer() != NULL);
2589 v1->SetBounds(20, 30, 140, 150); 2596 v1->SetBounds(20, 30, 140, 150);
2590 content_view->AddChildView(v1); 2597 content_view->AddChildView(v1);
2598 #if !defined(USE_WEBKIT_COMPOSITOR)
2591 root_layer->DrawTree(); 2599 root_layer->DrawTree();
2592 EXPECT_EQ(1, ui::TestTexture::live_count()); 2600 EXPECT_EQ(1, ui::TestTexture::live_count());
2601 #endif
2593 ASSERT_TRUE(v1->layer() != NULL); 2602 ASSERT_TRUE(v1->layer() != NULL);
2594 EXPECT_EQ(root_layer, v1->layer()->parent()); 2603 EXPECT_EQ(root_layer, v1->layer()->parent());
2595 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds()); 2604 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds());
2596 2605
2597 // Create v2 as a child of v1 and do basic assertion testing. 2606 // Create v2 as a child of v1 and do basic assertion testing.
2598 View* v2 = new View; 2607 View* v2 = new View;
2599 v1->AddChildView(v2); 2608 v1->AddChildView(v2);
2600 EXPECT_TRUE(v2->layer() == NULL); 2609 EXPECT_TRUE(v2->layer() == NULL);
2601 v2->SetBounds(10, 20, 30, 40); 2610 v2->SetBounds(10, 20, 30, 40);
2602 v2->SetPaintToLayer(true); 2611 v2->SetPaintToLayer(true);
2612 #if !defined(USE_WEBKIT_COMPOSITOR)
2603 root_layer->DrawTree(); 2613 root_layer->DrawTree();
2604 EXPECT_EQ(2, ui::TestTexture::live_count()); 2614 EXPECT_EQ(2, ui::TestTexture::live_count());
2615 #endif
2605 ASSERT_TRUE(v2->layer() != NULL); 2616 ASSERT_TRUE(v2->layer() != NULL);
2606 EXPECT_EQ(v1->layer(), v2->layer()->parent()); 2617 EXPECT_EQ(v1->layer(), v2->layer()->parent());
2607 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); 2618 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
2608 2619
2609 // Turn off v1s layer. v2 should still have a layer but its parent should have 2620 // Turn off v1s layer. v2 should still have a layer but its parent should have
2610 // changed. 2621 // changed.
2611 v1->SetPaintToLayer(false); 2622 v1->SetPaintToLayer(false);
2623 #if !defined(USE_WEBKIT_COMPOSITOR)
2612 root_layer->DrawTree(); 2624 root_layer->DrawTree();
2613 EXPECT_EQ(1, ui::TestTexture::live_count()); 2625 EXPECT_EQ(1, ui::TestTexture::live_count());
2626 #endif
2614 EXPECT_TRUE(v1->layer() == NULL); 2627 EXPECT_TRUE(v1->layer() == NULL);
2615 EXPECT_TRUE(v2->layer() != NULL); 2628 EXPECT_TRUE(v2->layer() != NULL);
2616 EXPECT_EQ(root_layer, v2->layer()->parent()); 2629 EXPECT_EQ(root_layer, v2->layer()->parent());
2617 ASSERT_EQ(1u, root_layer->children().size()); 2630 ASSERT_EQ(1u, root_layer->children().size());
2618 EXPECT_EQ(root_layer->children()[0], v2->layer()); 2631 EXPECT_EQ(root_layer->children()[0], v2->layer());
2619 // The bounds of the layer should have changed to be relative to the root view 2632 // The bounds of the layer should have changed to be relative to the root view
2620 // now. 2633 // now.
2621 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds()); 2634 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds());
2622 2635
2623 // Make v1 have a layer again and verify v2s layer is wired up correctly. 2636 // Make v1 have a layer again and verify v2s layer is wired up correctly.
2624 ui::Transform transform; 2637 ui::Transform transform;
2625 transform.SetScale(2.0f, 2.0f); 2638 transform.SetScale(2.0f, 2.0f);
2626 v1->SetTransform(transform); 2639 v1->SetTransform(transform);
2640 #if !defined(USE_WEBKIT_COMPOSITOR)
2627 root_layer->DrawTree(); 2641 root_layer->DrawTree();
2628 EXPECT_EQ(2, ui::TestTexture::live_count()); 2642 EXPECT_EQ(2, ui::TestTexture::live_count());
2643 #endif
2629 EXPECT_TRUE(v1->layer() != NULL); 2644 EXPECT_TRUE(v1->layer() != NULL);
2630 EXPECT_TRUE(v2->layer() != NULL); 2645 EXPECT_TRUE(v2->layer() != NULL);
2631 EXPECT_EQ(root_layer, v1->layer()->parent()); 2646 EXPECT_EQ(root_layer, v1->layer()->parent());
2632 EXPECT_EQ(v1->layer(), v2->layer()->parent()); 2647 EXPECT_EQ(v1->layer(), v2->layer()->parent());
2633 ASSERT_EQ(1u, root_layer->children().size()); 2648 ASSERT_EQ(1u, root_layer->children().size());
2634 EXPECT_EQ(root_layer->children()[0], v1->layer()); 2649 EXPECT_EQ(root_layer->children()[0], v1->layer());
2635 ASSERT_EQ(1u, v1->layer()->children().size()); 2650 ASSERT_EQ(1u, v1->layer()->children().size());
2636 EXPECT_EQ(v1->layer()->children()[0], v2->layer()); 2651 EXPECT_EQ(v1->layer()->children()[0], v2->layer());
2637 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); 2652 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
2638 } 2653 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2969 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 2984 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
2970 painted_ = true; 2985 painted_ = true;
2971 } 2986 }
2972 2987
2973 private: 2988 private:
2974 bool painted_; 2989 bool painted_;
2975 2990
2976 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); 2991 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView);
2977 }; 2992 };
2978 2993
2994 #if !defined(USE_WEBKIT_COMPOSITOR)
2995 // TODO(piman): this test relies on the way the non-webkit compositor works.
2996 // Layer::DrawTree should not be called with the webkit compositor. In the
2997 // WebKit case, it needs to go through the "real" compositor (not the test one)
2998 // to do the paints on the layer/views.
2999
2979 // Makes sure child views with layers aren't painted when paint starts at an 3000 // Makes sure child views with layers aren't painted when paint starts at an
2980 // ancestor. 3001 // ancestor.
2981 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { 3002 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) {
2982 PaintTrackingView* content_view = new PaintTrackingView; 3003 PaintTrackingView* content_view = new PaintTrackingView;
2983 widget()->SetContentsView(content_view); 3004 widget()->SetContentsView(content_view);
2984 content_view->SetPaintToLayer(true); 3005 content_view->SetPaintToLayer(true);
2985 GetRootLayer()->DrawTree(); 3006 GetRootLayer()->DrawTree();
2986 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); 3007 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10));
2987 content_view->set_painted(false); 3008 content_view->set_painted(false);
2988 // content_view no longer has a dirty rect. Paint from the root and make sure 3009 // content_view no longer has a dirty rect. Paint from the root and make sure
2989 // PaintTrackingView isn't painted. 3010 // PaintTrackingView isn't painted.
2990 GetRootLayer()->DrawTree(); 3011 GetRootLayer()->DrawTree();
2991 EXPECT_FALSE(content_view->painted()); 3012 EXPECT_FALSE(content_view->painted());
2992 3013
2993 // Make content_view have a dirty rect, paint the layers and make sure 3014 // Make content_view have a dirty rect, paint the layers and make sure
2994 // PaintTrackingView is painted. 3015 // PaintTrackingView is painted.
2995 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); 3016 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10));
2996 GetRootLayer()->DrawTree(); 3017 GetRootLayer()->DrawTree();
2997 EXPECT_TRUE(content_view->painted()); 3018 EXPECT_TRUE(content_view->painted());
2998 } 3019 }
3020 #endif
2999 3021
3000 // Tests that the visibility of child layers are updated correctly when a View's 3022 // Tests that the visibility of child layers are updated correctly when a View's
3001 // visibility changes. 3023 // visibility changes.
3002 TEST_F(ViewLayerTest, VisibilityChildLayers) { 3024 TEST_F(ViewLayerTest, VisibilityChildLayers) {
3003 View* v1 = new View; 3025 View* v1 = new View;
3004 v1->SetPaintToLayer(true); 3026 v1->SetPaintToLayer(true);
3005 widget()->SetContentsView(v1); 3027 widget()->SetContentsView(v1);
3006 3028
3007 View* v2 = new View; 3029 View* v2 = new View;
3008 v1->AddChildView(v2); 3030 v1->AddChildView(v2);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3061 ScrambleTree(content); 3083 ScrambleTree(content);
3062 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); 3084 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer()));
3063 3085
3064 ScrambleTree(content); 3086 ScrambleTree(content);
3065 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); 3087 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer()));
3066 } 3088 }
3067 3089
3068 #endif // VIEWS_COMPOSITOR 3090 #endif // VIEWS_COMPOSITOR
3069 3091
3070 } // namespace views 3092 } // namespace views
OLDNEW
« no previous file with comments | « views/run_all_unittests.cc ('k') | views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698