| 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 <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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 3060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3071 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); | 3071 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); |
| 3072 }; | 3072 }; |
| 3073 | 3073 |
| 3074 // Makes sure child views with layers aren't painted when paint starts at an | 3074 // Makes sure child views with layers aren't painted when paint starts at an |
| 3075 // ancestor. | 3075 // ancestor. |
| 3076 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { | 3076 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { |
| 3077 PaintTrackingView* content_view = new PaintTrackingView; | 3077 PaintTrackingView* content_view = new PaintTrackingView; |
| 3078 widget()->SetContentsView(content_view); | 3078 widget()->SetContentsView(content_view); |
| 3079 content_view->SetPaintToLayer(true); | 3079 content_view->SetPaintToLayer(true); |
| 3080 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3080 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3081 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3081 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3082 GetRootLayer()->GetCompositor()); | |
| 3083 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3082 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
| 3084 content_view->set_painted(false); | 3083 content_view->set_painted(false); |
| 3085 // content_view no longer has a dirty rect. Paint from the root and make sure | 3084 // content_view no longer has a dirty rect. Paint from the root and make sure |
| 3086 // PaintTrackingView isn't painted. | 3085 // PaintTrackingView isn't painted. |
| 3087 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3086 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3088 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3087 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3089 GetRootLayer()->GetCompositor()); | |
| 3090 EXPECT_FALSE(content_view->painted()); | 3088 EXPECT_FALSE(content_view->painted()); |
| 3091 | 3089 |
| 3092 // Make content_view have a dirty rect, paint the layers and make sure | 3090 // Make content_view have a dirty rect, paint the layers and make sure |
| 3093 // PaintTrackingView is painted. | 3091 // PaintTrackingView is painted. |
| 3094 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3092 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
| 3095 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3093 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3096 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3094 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3097 GetRootLayer()->GetCompositor()); | |
| 3098 EXPECT_TRUE(content_view->painted()); | 3095 EXPECT_TRUE(content_view->painted()); |
| 3099 } | 3096 } |
| 3100 | 3097 |
| 3101 // Tests that the visibility of child layers are updated correctly when a View's | 3098 // Tests that the visibility of child layers are updated correctly when a View's |
| 3102 // visibility changes. | 3099 // visibility changes. |
| 3103 TEST_F(ViewLayerTest, VisibilityChildLayers) { | 3100 TEST_F(ViewLayerTest, VisibilityChildLayers) { |
| 3104 View* v1 = new View; | 3101 View* v1 = new View; |
| 3105 v1->SetPaintToLayer(true); | 3102 v1->SetPaintToLayer(true); |
| 3106 widget()->SetContentsView(v1); | 3103 widget()->SetContentsView(v1); |
| 3107 | 3104 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3326 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); | 3323 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); |
| 3327 test_view->AddChildView(v1); | 3324 test_view->AddChildView(v1); |
| 3328 | 3325 |
| 3329 View* v2 = new View(); | 3326 View* v2 = new View(); |
| 3330 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3327 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
| 3331 v1->AddChildView(v2); | 3328 v1->AddChildView(v2); |
| 3332 | 3329 |
| 3333 // Schedule a full-view paint to get everyone's rectangles updated. | 3330 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3334 test_view->SchedulePaintInRect(test_view->bounds()); | 3331 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3335 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3332 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3336 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3333 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3337 GetRootLayer()->GetCompositor()); | |
| 3338 | 3334 |
| 3339 // Now we have test_view - v1 - v2. Damage to only test_view should only | 3335 // Now we have test_view - v1 - v2. Damage to only test_view should only |
| 3340 // return root_view and test_view. | 3336 // return root_view and test_view. |
| 3341 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); | 3337 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); |
| 3342 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3338 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3343 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3339 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3344 GetRootLayer()->GetCompositor()); | |
| 3345 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3340 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3346 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3341 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3347 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3342 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3348 | 3343 |
| 3349 // Damage to v1 only should only return root_view, test_view, and v1. | 3344 // Damage to v1 only should only return root_view, test_view, and v1. |
| 3350 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); | 3345 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); |
| 3351 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3346 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3352 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3347 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3353 GetRootLayer()->GetCompositor()); | |
| 3354 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3348 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
| 3355 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3349 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3356 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3350 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3357 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3351 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3358 | 3352 |
| 3359 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| | 3353 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| |
| 3360 // on call to TestView::Paint(), along with the widget root view. | 3354 // on call to TestView::Paint(), along with the widget root view. |
| 3361 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); | 3355 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); |
| 3362 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3356 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3363 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3357 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3364 GetRootLayer()->GetCompositor()); | |
| 3365 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3358 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
| 3366 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3359 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3367 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3360 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3368 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3361 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3369 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3362 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
| 3370 } | 3363 } |
| 3371 | 3364 |
| 3372 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { | 3365 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { |
| 3373 std::string locale = l10n_util::GetApplicationLocale(std::string()); | 3366 std::string locale = l10n_util::GetApplicationLocale(std::string()); |
| 3374 base::i18n::SetICUDefaultLocale("ar"); | 3367 base::i18n::SetICUDefaultLocale("ar"); |
| 3375 | 3368 |
| 3376 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3369 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
| 3377 widget()->SetContentsView(test_view); | 3370 widget()->SetContentsView(test_view); |
| 3378 | 3371 |
| 3379 // Add child views, which should be in RTL coordinate space of parent view. | 3372 // Add child views, which should be in RTL coordinate space of parent view. |
| 3380 View* v1 = new View; | 3373 View* v1 = new View; |
| 3381 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); | 3374 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); |
| 3382 test_view->AddChildView(v1); | 3375 test_view->AddChildView(v1); |
| 3383 | 3376 |
| 3384 View* v2 = new View; | 3377 View* v2 = new View; |
| 3385 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); | 3378 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); |
| 3386 v1->AddChildView(v2); | 3379 v1->AddChildView(v2); |
| 3387 | 3380 |
| 3388 // Schedule a full-view paint to get everyone's rectangles updated. | 3381 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3389 test_view->SchedulePaintInRect(test_view->bounds()); | 3382 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3390 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3383 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3391 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3384 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3392 GetRootLayer()->GetCompositor()); | |
| 3393 | 3385 |
| 3394 // Damage to the right side of the parent view should touch both child views. | 3386 // Damage to the right side of the parent view should touch both child views. |
| 3395 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); | 3387 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); |
| 3396 test_view->SchedulePaintInRect(rtl_damage); | 3388 test_view->SchedulePaintInRect(rtl_damage); |
| 3397 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3389 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3398 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3390 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3399 GetRootLayer()->GetCompositor()); | |
| 3400 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3391 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
| 3401 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3392 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3402 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3393 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3403 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3394 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3404 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3395 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
| 3405 | 3396 |
| 3406 // Damage to the left side of the parent view should only touch the | 3397 // Damage to the left side of the parent view should only touch the |
| 3407 // container views. | 3398 // container views. |
| 3408 gfx::Rect ltr_damage(16, 18, 1, 1); | 3399 gfx::Rect ltr_damage(16, 18, 1, 1); |
| 3409 test_view->SchedulePaintInRect(ltr_damage); | 3400 test_view->SchedulePaintInRect(ltr_damage); |
| 3410 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3401 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3411 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3402 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3412 GetRootLayer()->GetCompositor()); | |
| 3413 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3403 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3414 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3404 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3415 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3405 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3416 | 3406 |
| 3417 // Reset locale. | 3407 // Reset locale. |
| 3418 base::i18n::SetICUDefaultLocale(locale); | 3408 base::i18n::SetICUDefaultLocale(locale); |
| 3419 } | 3409 } |
| 3420 | 3410 |
| 3421 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { | 3411 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { |
| 3422 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3412 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
| 3423 widget()->SetContentsView(test_view); | 3413 widget()->SetContentsView(test_view); |
| 3424 | 3414 |
| 3425 View* v1 = new View; | 3415 View* v1 = new View; |
| 3426 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); | 3416 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); |
| 3427 test_view->AddChildView(v1); | 3417 test_view->AddChildView(v1); |
| 3428 | 3418 |
| 3429 View* v2 = new View; | 3419 View* v2 = new View; |
| 3430 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3420 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
| 3431 v1->AddChildView(v2); | 3421 v1->AddChildView(v2); |
| 3432 | 3422 |
| 3433 // Schedule a full-view paint to get everyone's rectangles updated. | 3423 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3434 test_view->SchedulePaintInRect(test_view->bounds()); | 3424 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3435 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3425 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3436 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3426 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3437 GetRootLayer()->GetCompositor()); | |
| 3438 | 3427 |
| 3439 // Move v1 to a new origin out of the way of our next query. | 3428 // Move v1 to a new origin out of the way of our next query. |
| 3440 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); | 3429 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); |
| 3441 // The move will force a repaint. | 3430 // The move will force a repaint. |
| 3442 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3431 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3443 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3432 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3444 GetRootLayer()->GetCompositor()); | |
| 3445 | 3433 |
| 3446 // Schedule a paint with damage rect where v1 used to be. | 3434 // Schedule a paint with damage rect where v1 used to be. |
| 3447 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); | 3435 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); |
| 3448 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3436 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3449 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3437 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3450 GetRootLayer()->GetCompositor()); | |
| 3451 | 3438 |
| 3452 // Should only have picked up root_view and test_view. | 3439 // Should only have picked up root_view and test_view. |
| 3453 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3440 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3454 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3441 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3455 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3442 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3456 } | 3443 } |
| 3457 | 3444 |
| 3458 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { | 3445 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { |
| 3459 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3446 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
| 3460 widget()->SetContentsView(test_view); | 3447 widget()->SetContentsView(test_view); |
| 3461 | 3448 |
| 3462 View* v1 = new View; | 3449 View* v1 = new View; |
| 3463 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3450 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
| 3464 test_view->AddChildView(v1); | 3451 test_view->AddChildView(v1); |
| 3465 | 3452 |
| 3466 View* v2 = new View; | 3453 View* v2 = new View; |
| 3467 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3454 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
| 3468 v1->AddChildView(v2); | 3455 v1->AddChildView(v2); |
| 3469 | 3456 |
| 3470 // Schedule a full-view paint to get everyone's rectangles updated. | 3457 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3471 test_view->SchedulePaintInRect(test_view->bounds()); | 3458 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3472 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3459 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3473 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3460 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3474 GetRootLayer()->GetCompositor()); | |
| 3475 | 3461 |
| 3476 // Set v1 to paint to its own layer, it should remove itself from the | 3462 // Set v1 to paint to its own layer, it should remove itself from the |
| 3477 // test_view heiarchy and no longer intersect with damage rects in that cull | 3463 // test_view heiarchy and no longer intersect with damage rects in that cull |
| 3478 // set. | 3464 // set. |
| 3479 v1->SetPaintToLayer(true); | 3465 v1->SetPaintToLayer(true); |
| 3480 | 3466 |
| 3481 // Schedule another full-view paint. | 3467 // Schedule another full-view paint. |
| 3482 test_view->SchedulePaintInRect(test_view->bounds()); | 3468 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3483 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3469 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3484 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3470 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3485 GetRootLayer()->GetCompositor()); | |
| 3486 // v1 and v2 should no longer be present in the test_view cull_set. | 3471 // v1 and v2 should no longer be present in the test_view cull_set. |
| 3487 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3472 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3488 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3473 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
| 3489 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3474 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
| 3490 | 3475 |
| 3491 // Now set v1 back to not painting to a layer. | 3476 // Now set v1 back to not painting to a layer. |
| 3492 v1->SetPaintToLayer(false); | 3477 v1->SetPaintToLayer(false); |
| 3493 // Schedule another full-view paint. | 3478 // Schedule another full-view paint. |
| 3494 test_view->SchedulePaintInRect(test_view->bounds()); | 3479 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3495 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3480 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3496 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3481 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3497 GetRootLayer()->GetCompositor()); | |
| 3498 // We should be back to the full cull set including v1 and v2. | 3482 // We should be back to the full cull set including v1 and v2. |
| 3499 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3483 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
| 3500 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3484 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3501 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3485 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3502 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3486 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3503 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3487 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
| 3504 } | 3488 } |
| 3505 | 3489 |
| 3506 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { | 3490 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { |
| 3507 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3491 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
| 3508 widget()->SetContentsView(test_view); | 3492 widget()->SetContentsView(test_view); |
| 3509 | 3493 |
| 3510 View* v1 = new View; | 3494 View* v1 = new View; |
| 3511 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3495 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
| 3512 test_view->AddChildView(v1); | 3496 test_view->AddChildView(v1); |
| 3513 | 3497 |
| 3514 View* v2 = new View; | 3498 View* v2 = new View; |
| 3515 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3499 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
| 3516 v1->AddChildView(v2); | 3500 v1->AddChildView(v2); |
| 3517 | 3501 |
| 3518 // Schedule a full-view paint to get everyone's rectangles updated. | 3502 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3519 test_view->SchedulePaintInRect(test_view->bounds()); | 3503 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3520 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3504 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3521 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3505 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3522 GetRootLayer()->GetCompositor()); | |
| 3523 | 3506 |
| 3524 // Now remove v1 from the root view. | 3507 // Now remove v1 from the root view. |
| 3525 test_view->RemoveChildView(v1); | 3508 test_view->RemoveChildView(v1); |
| 3526 | 3509 |
| 3527 // Schedule another full-view paint. | 3510 // Schedule another full-view paint. |
| 3528 test_view->SchedulePaintInRect(test_view->bounds()); | 3511 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3529 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3512 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3530 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3513 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3531 GetRootLayer()->GetCompositor()); | |
| 3532 // v1 and v2 should no longer be present in the test_view cull_set. | 3514 // v1 and v2 should no longer be present in the test_view cull_set. |
| 3533 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3515 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3534 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3516 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
| 3535 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3517 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
| 3536 | 3518 |
| 3537 // View v1 and v2 are no longer part of view hierarchy and therefore won't be | 3519 // View v1 and v2 are no longer part of view hierarchy and therefore won't be |
| 3538 // deleted with that hierarchy. | 3520 // deleted with that hierarchy. |
| 3539 delete v1; | 3521 delete v1; |
| 3540 } | 3522 } |
| 3541 | 3523 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3552 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); | 3534 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); |
| 3553 v1->AddChildView(v2); | 3535 v1->AddChildView(v2); |
| 3554 | 3536 |
| 3555 View* v3 = new View; | 3537 View* v3 = new View; |
| 3556 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3538 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
| 3557 v2->AddChildView(v3); | 3539 v2->AddChildView(v3); |
| 3558 | 3540 |
| 3559 // Schedule a full-view paint and ensure all views are present in the cull. | 3541 // Schedule a full-view paint and ensure all views are present in the cull. |
| 3560 test_view->SchedulePaintInRect(test_view->bounds()); | 3542 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3561 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3543 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3562 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3544 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3563 GetRootLayer()->GetCompositor()); | |
| 3564 EXPECT_EQ(5U, test_view->last_cull_set_.size()); | 3545 EXPECT_EQ(5U, test_view->last_cull_set_.size()); |
| 3565 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3546 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3566 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3547 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3567 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3548 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3568 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3549 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
| 3569 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); | 3550 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); |
| 3570 | 3551 |
| 3571 // Build an unrelated view hierarchy and move v2 in to it. | 3552 // Build an unrelated view hierarchy and move v2 in to it. |
| 3572 scoped_ptr<Widget> test_widget(new Widget); | 3553 scoped_ptr<Widget> test_widget(new Widget); |
| 3573 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 3554 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 3574 params.bounds = gfx::Rect(10, 10, 500, 500); | 3555 params.bounds = gfx::Rect(10, 10, 500, 500); |
| 3575 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 3556 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 3576 test_widget->Init(params); | 3557 test_widget->Init(params); |
| 3577 test_widget->Show(); | 3558 test_widget->Show(); |
| 3578 BoundsTreeTestView* widget_view = new BoundsTreeTestView; | 3559 BoundsTreeTestView* widget_view = new BoundsTreeTestView; |
| 3579 test_widget->SetContentsView(widget_view); | 3560 test_widget->SetContentsView(widget_view); |
| 3580 widget_view->AddChildView(v2); | 3561 widget_view->AddChildView(v2); |
| 3581 | 3562 |
| 3582 // Now schedule full-view paints in both widgets. | 3563 // Now schedule full-view paints in both widgets. |
| 3583 test_view->SchedulePaintInRect(test_view->bounds()); | 3564 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3584 widget_view->SchedulePaintInRect(widget_view->bounds()); | 3565 widget_view->SchedulePaintInRect(widget_view->bounds()); |
| 3585 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3566 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3586 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3567 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3587 GetRootLayer()->GetCompositor()); | |
| 3588 | 3568 |
| 3589 // Only v1 should be present in the first cull set. | 3569 // Only v1 should be present in the first cull set. |
| 3590 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3570 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
| 3591 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3571 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3592 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3572 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3593 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3573 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3594 | 3574 |
| 3595 // We should find v2 and v3 in the widget_view cull_set. | 3575 // We should find v2 and v3 in the widget_view cull_set. |
| 3596 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); | 3576 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); |
| 3597 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); | 3577 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3708 // notification. | 3688 // notification. |
| 3709 TestView* test_view_child_2 = new TestView(); | 3689 TestView* test_view_child_2 = new TestView(); |
| 3710 test_view->AddChildView(test_view_child_2); | 3690 test_view->AddChildView(test_view_child_2); |
| 3711 EXPECT_TRUE(test_view_child_2->native_theme_); | 3691 EXPECT_TRUE(test_view_child_2->native_theme_); |
| 3712 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 3692 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
| 3713 | 3693 |
| 3714 widget->CloseNow(); | 3694 widget->CloseNow(); |
| 3715 } | 3695 } |
| 3716 | 3696 |
| 3717 } // namespace views | 3697 } // namespace views |
| OLD | NEW |