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

Side by Side Diff: views/view_unittest.cc

Issue 8360018: Revert 106606 - Use WebKit compositor in ui::Layer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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.
2584 root_layer->DrawTree(); 2580 root_layer->DrawTree();
2585 ui::TestTexture::reset_live_count(); 2581 ui::TestTexture::reset_live_count();
2586 #endif
2587 2582
2588 // Create v1, give it a bounds and verify everything is set up correctly. 2583 // Create v1, give it a bounds and verify everything is set up correctly.
2589 View* v1 = new View; 2584 View* v1 = new View;
2590 v1->SetPaintToLayer(true); 2585 v1->SetPaintToLayer(true);
2591 #if !defined(USE_WEBKIT_COMPOSITOR)
2592 root_layer->DrawTree(); 2586 root_layer->DrawTree();
2593 EXPECT_EQ(0, ui::TestTexture::live_count()); 2587 EXPECT_EQ(0, ui::TestTexture::live_count());
2594 #endif
2595 EXPECT_TRUE(v1->layer() != NULL); 2588 EXPECT_TRUE(v1->layer() != NULL);
2596 v1->SetBounds(20, 30, 140, 150); 2589 v1->SetBounds(20, 30, 140, 150);
2597 content_view->AddChildView(v1); 2590 content_view->AddChildView(v1);
2598 #if !defined(USE_WEBKIT_COMPOSITOR)
2599 root_layer->DrawTree(); 2591 root_layer->DrawTree();
2600 EXPECT_EQ(1, ui::TestTexture::live_count()); 2592 EXPECT_EQ(1, ui::TestTexture::live_count());
2601 #endif
2602 ASSERT_TRUE(v1->layer() != NULL); 2593 ASSERT_TRUE(v1->layer() != NULL);
2603 EXPECT_EQ(root_layer, v1->layer()->parent()); 2594 EXPECT_EQ(root_layer, v1->layer()->parent());
2604 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds()); 2595 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds());
2605 2596
2606 // Create v2 as a child of v1 and do basic assertion testing. 2597 // Create v2 as a child of v1 and do basic assertion testing.
2607 View* v2 = new View; 2598 View* v2 = new View;
2608 v1->AddChildView(v2); 2599 v1->AddChildView(v2);
2609 EXPECT_TRUE(v2->layer() == NULL); 2600 EXPECT_TRUE(v2->layer() == NULL);
2610 v2->SetBounds(10, 20, 30, 40); 2601 v2->SetBounds(10, 20, 30, 40);
2611 v2->SetPaintToLayer(true); 2602 v2->SetPaintToLayer(true);
2612 #if !defined(USE_WEBKIT_COMPOSITOR)
2613 root_layer->DrawTree(); 2603 root_layer->DrawTree();
2614 EXPECT_EQ(2, ui::TestTexture::live_count()); 2604 EXPECT_EQ(2, ui::TestTexture::live_count());
2615 #endif
2616 ASSERT_TRUE(v2->layer() != NULL); 2605 ASSERT_TRUE(v2->layer() != NULL);
2617 EXPECT_EQ(v1->layer(), v2->layer()->parent()); 2606 EXPECT_EQ(v1->layer(), v2->layer()->parent());
2618 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); 2607 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
2619 2608
2620 // Turn off v1s layer. v2 should still have a layer but its parent should have 2609 // Turn off v1s layer. v2 should still have a layer but its parent should have
2621 // changed. 2610 // changed.
2622 v1->SetPaintToLayer(false); 2611 v1->SetPaintToLayer(false);
2623 #if !defined(USE_WEBKIT_COMPOSITOR)
2624 root_layer->DrawTree(); 2612 root_layer->DrawTree();
2625 EXPECT_EQ(1, ui::TestTexture::live_count()); 2613 EXPECT_EQ(1, ui::TestTexture::live_count());
2626 #endif
2627 EXPECT_TRUE(v1->layer() == NULL); 2614 EXPECT_TRUE(v1->layer() == NULL);
2628 EXPECT_TRUE(v2->layer() != NULL); 2615 EXPECT_TRUE(v2->layer() != NULL);
2629 EXPECT_EQ(root_layer, v2->layer()->parent()); 2616 EXPECT_EQ(root_layer, v2->layer()->parent());
2630 ASSERT_EQ(1u, root_layer->children().size()); 2617 ASSERT_EQ(1u, root_layer->children().size());
2631 EXPECT_EQ(root_layer->children()[0], v2->layer()); 2618 EXPECT_EQ(root_layer->children()[0], v2->layer());
2632 // The bounds of the layer should have changed to be relative to the root view 2619 // The bounds of the layer should have changed to be relative to the root view
2633 // now. 2620 // now.
2634 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds()); 2621 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds());
2635 2622
2636 // Make v1 have a layer again and verify v2s layer is wired up correctly. 2623 // Make v1 have a layer again and verify v2s layer is wired up correctly.
2637 ui::Transform transform; 2624 ui::Transform transform;
2638 transform.SetScale(2.0f, 2.0f); 2625 transform.SetScale(2.0f, 2.0f);
2639 v1->SetTransform(transform); 2626 v1->SetTransform(transform);
2640 #if !defined(USE_WEBKIT_COMPOSITOR)
2641 root_layer->DrawTree(); 2627 root_layer->DrawTree();
2642 EXPECT_EQ(2, ui::TestTexture::live_count()); 2628 EXPECT_EQ(2, ui::TestTexture::live_count());
2643 #endif
2644 EXPECT_TRUE(v1->layer() != NULL); 2629 EXPECT_TRUE(v1->layer() != NULL);
2645 EXPECT_TRUE(v2->layer() != NULL); 2630 EXPECT_TRUE(v2->layer() != NULL);
2646 EXPECT_EQ(root_layer, v1->layer()->parent()); 2631 EXPECT_EQ(root_layer, v1->layer()->parent());
2647 EXPECT_EQ(v1->layer(), v2->layer()->parent()); 2632 EXPECT_EQ(v1->layer(), v2->layer()->parent());
2648 ASSERT_EQ(1u, root_layer->children().size()); 2633 ASSERT_EQ(1u, root_layer->children().size());
2649 EXPECT_EQ(root_layer->children()[0], v1->layer()); 2634 EXPECT_EQ(root_layer->children()[0], v1->layer());
2650 ASSERT_EQ(1u, v1->layer()->children().size()); 2635 ASSERT_EQ(1u, v1->layer()->children().size());
2651 EXPECT_EQ(v1->layer()->children()[0], v2->layer()); 2636 EXPECT_EQ(v1->layer()->children()[0], v2->layer());
2652 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); 2637 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
2653 } 2638 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2984 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 2969 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
2985 painted_ = true; 2970 painted_ = true;
2986 } 2971 }
2987 2972
2988 private: 2973 private:
2989 bool painted_; 2974 bool painted_;
2990 2975
2991 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); 2976 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView);
2992 }; 2977 };
2993 2978
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
3000 // Makes sure child views with layers aren't painted when paint starts at an 2979 // Makes sure child views with layers aren't painted when paint starts at an
3001 // ancestor. 2980 // ancestor.
3002 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { 2981 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) {
3003 PaintTrackingView* content_view = new PaintTrackingView; 2982 PaintTrackingView* content_view = new PaintTrackingView;
3004 widget()->SetContentsView(content_view); 2983 widget()->SetContentsView(content_view);
3005 content_view->SetPaintToLayer(true); 2984 content_view->SetPaintToLayer(true);
3006 GetRootLayer()->DrawTree(); 2985 GetRootLayer()->DrawTree();
3007 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); 2986 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10));
3008 content_view->set_painted(false); 2987 content_view->set_painted(false);
3009 // content_view no longer has a dirty rect. Paint from the root and make sure 2988 // content_view no longer has a dirty rect. Paint from the root and make sure
3010 // PaintTrackingView isn't painted. 2989 // PaintTrackingView isn't painted.
3011 GetRootLayer()->DrawTree(); 2990 GetRootLayer()->DrawTree();
3012 EXPECT_FALSE(content_view->painted()); 2991 EXPECT_FALSE(content_view->painted());
3013 2992
3014 // Make content_view have a dirty rect, paint the layers and make sure 2993 // Make content_view have a dirty rect, paint the layers and make sure
3015 // PaintTrackingView is painted. 2994 // PaintTrackingView is painted.
3016 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); 2995 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10));
3017 GetRootLayer()->DrawTree(); 2996 GetRootLayer()->DrawTree();
3018 EXPECT_TRUE(content_view->painted()); 2997 EXPECT_TRUE(content_view->painted());
3019 } 2998 }
3020 #endif
3021 2999
3022 // Tests that the visibility of child layers are updated correctly when a View's 3000 // Tests that the visibility of child layers are updated correctly when a View's
3023 // visibility changes. 3001 // visibility changes.
3024 TEST_F(ViewLayerTest, VisibilityChildLayers) { 3002 TEST_F(ViewLayerTest, VisibilityChildLayers) {
3025 View* v1 = new View; 3003 View* v1 = new View;
3026 v1->SetPaintToLayer(true); 3004 v1->SetPaintToLayer(true);
3027 widget()->SetContentsView(v1); 3005 widget()->SetContentsView(v1);
3028 3006
3029 View* v2 = new View; 3007 View* v2 = new View;
3030 v1->AddChildView(v2); 3008 v1->AddChildView(v2);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3083 ScrambleTree(content); 3061 ScrambleTree(content);
3084 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); 3062 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer()));
3085 3063
3086 ScrambleTree(content); 3064 ScrambleTree(content);
3087 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); 3065 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer()));
3088 } 3066 }
3089 3067
3090 #endif // VIEWS_COMPOSITOR 3068 #endif // VIEWS_COMPOSITOR
3091 3069
3092 } // namespace views 3070 } // 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