| 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 3006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3017 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); | 3017 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); |
| 3018 }; | 3018 }; |
| 3019 | 3019 |
| 3020 // Makes sure child views with layers aren't painted when paint starts at an | 3020 // Makes sure child views with layers aren't painted when paint starts at an |
| 3021 // ancestor. | 3021 // ancestor. |
| 3022 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { | 3022 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { |
| 3023 PaintTrackingView* content_view = new PaintTrackingView; | 3023 PaintTrackingView* content_view = new PaintTrackingView; |
| 3024 widget()->SetContentsView(content_view); | 3024 widget()->SetContentsView(content_view); |
| 3025 content_view->SetPaintToLayer(true); | 3025 content_view->SetPaintToLayer(true); |
| 3026 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3026 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3027 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3027 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3028 GetRootLayer()->GetCompositor()); | |
| 3029 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3028 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
| 3030 content_view->set_painted(false); | 3029 content_view->set_painted(false); |
| 3031 // content_view no longer has a dirty rect. Paint from the root and make sure | 3030 // content_view no longer has a dirty rect. Paint from the root and make sure |
| 3032 // PaintTrackingView isn't painted. | 3031 // PaintTrackingView isn't painted. |
| 3033 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3032 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3034 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3033 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3035 GetRootLayer()->GetCompositor()); | |
| 3036 EXPECT_FALSE(content_view->painted()); | 3034 EXPECT_FALSE(content_view->painted()); |
| 3037 | 3035 |
| 3038 // Make content_view have a dirty rect, paint the layers and make sure | 3036 // Make content_view have a dirty rect, paint the layers and make sure |
| 3039 // PaintTrackingView is painted. | 3037 // PaintTrackingView is painted. |
| 3040 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3038 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
| 3041 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3039 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3042 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3040 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3043 GetRootLayer()->GetCompositor()); | |
| 3044 EXPECT_TRUE(content_view->painted()); | 3041 EXPECT_TRUE(content_view->painted()); |
| 3045 } | 3042 } |
| 3046 | 3043 |
| 3047 // Tests that the visibility of child layers are updated correctly when a View's | 3044 // Tests that the visibility of child layers are updated correctly when a View's |
| 3048 // visibility changes. | 3045 // visibility changes. |
| 3049 TEST_F(ViewLayerTest, VisibilityChildLayers) { | 3046 TEST_F(ViewLayerTest, VisibilityChildLayers) { |
| 3050 View* v1 = new View; | 3047 View* v1 = new View; |
| 3051 v1->SetPaintToLayer(true); | 3048 v1->SetPaintToLayer(true); |
| 3052 widget()->SetContentsView(v1); | 3049 widget()->SetContentsView(v1); |
| 3053 | 3050 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3273 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); | 3270 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); |
| 3274 test_view->AddChildView(v1); | 3271 test_view->AddChildView(v1); |
| 3275 | 3272 |
| 3276 View* v2 = new View(); | 3273 View* v2 = new View(); |
| 3277 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3274 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
| 3278 v1->AddChildView(v2); | 3275 v1->AddChildView(v2); |
| 3279 | 3276 |
| 3280 // Schedule a full-view paint to get everyone's rectangles updated. | 3277 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3281 test_view->SchedulePaintInRect(test_view->bounds()); | 3278 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3282 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3279 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3283 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3280 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3284 GetRootLayer()->GetCompositor()); | |
| 3285 | 3281 |
| 3286 // Now we have test_view - v1 - v2. Damage to only test_view should only | 3282 // Now we have test_view - v1 - v2. Damage to only test_view should only |
| 3287 // return root_view and test_view. | 3283 // return root_view and test_view. |
| 3288 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); | 3284 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); |
| 3289 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3285 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3290 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3286 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3291 GetRootLayer()->GetCompositor()); | |
| 3292 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3287 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3293 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3288 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3294 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3289 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3295 | 3290 |
| 3296 // Damage to v1 only should only return root_view, test_view, and v1. | 3291 // Damage to v1 only should only return root_view, test_view, and v1. |
| 3297 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); | 3292 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); |
| 3298 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3293 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3299 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3294 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3300 GetRootLayer()->GetCompositor()); | |
| 3301 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3295 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
| 3302 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3296 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3303 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3297 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3304 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3298 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3305 | 3299 |
| 3306 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| | 3300 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| |
| 3307 // on call to TestView::Paint(), along with the widget root view. | 3301 // on call to TestView::Paint(), along with the widget root view. |
| 3308 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); | 3302 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); |
| 3309 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3303 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3310 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3304 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3311 GetRootLayer()->GetCompositor()); | |
| 3312 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3305 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
| 3313 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3306 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3314 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3307 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3315 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3308 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3316 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3309 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
| 3317 } | 3310 } |
| 3318 | 3311 |
| 3319 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { | 3312 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { |
| 3320 std::string locale = l10n_util::GetApplicationLocale(std::string()); | 3313 std::string locale = l10n_util::GetApplicationLocale(std::string()); |
| 3321 base::i18n::SetICUDefaultLocale("ar"); | 3314 base::i18n::SetICUDefaultLocale("ar"); |
| 3322 | 3315 |
| 3323 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3316 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
| 3324 widget()->SetContentsView(test_view); | 3317 widget()->SetContentsView(test_view); |
| 3325 | 3318 |
| 3326 // Add child views, which should be in RTL coordinate space of parent view. | 3319 // Add child views, which should be in RTL coordinate space of parent view. |
| 3327 View* v1 = new View; | 3320 View* v1 = new View; |
| 3328 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); | 3321 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); |
| 3329 test_view->AddChildView(v1); | 3322 test_view->AddChildView(v1); |
| 3330 | 3323 |
| 3331 View* v2 = new View; | 3324 View* v2 = new View; |
| 3332 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); | 3325 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); |
| 3333 v1->AddChildView(v2); | 3326 v1->AddChildView(v2); |
| 3334 | 3327 |
| 3335 // Schedule a full-view paint to get everyone's rectangles updated. | 3328 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3336 test_view->SchedulePaintInRect(test_view->bounds()); | 3329 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3337 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3330 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3338 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3331 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3339 GetRootLayer()->GetCompositor()); | |
| 3340 | 3332 |
| 3341 // Damage to the right side of the parent view should touch both child views. | 3333 // Damage to the right side of the parent view should touch both child views. |
| 3342 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); | 3334 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); |
| 3343 test_view->SchedulePaintInRect(rtl_damage); | 3335 test_view->SchedulePaintInRect(rtl_damage); |
| 3344 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3336 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3345 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3337 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3346 GetRootLayer()->GetCompositor()); | |
| 3347 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3338 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
| 3348 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3339 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3349 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3340 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3350 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3341 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3351 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3342 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
| 3352 | 3343 |
| 3353 // Damage to the left side of the parent view should only touch the | 3344 // Damage to the left side of the parent view should only touch the |
| 3354 // container views. | 3345 // container views. |
| 3355 gfx::Rect ltr_damage(16, 18, 1, 1); | 3346 gfx::Rect ltr_damage(16, 18, 1, 1); |
| 3356 test_view->SchedulePaintInRect(ltr_damage); | 3347 test_view->SchedulePaintInRect(ltr_damage); |
| 3357 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3348 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3358 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3349 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3359 GetRootLayer()->GetCompositor()); | |
| 3360 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3350 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3361 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3351 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3362 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3352 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3363 | 3353 |
| 3364 // Reset locale. | 3354 // Reset locale. |
| 3365 base::i18n::SetICUDefaultLocale(locale); | 3355 base::i18n::SetICUDefaultLocale(locale); |
| 3366 } | 3356 } |
| 3367 | 3357 |
| 3368 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { | 3358 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { |
| 3369 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3359 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
| 3370 widget()->SetContentsView(test_view); | 3360 widget()->SetContentsView(test_view); |
| 3371 | 3361 |
| 3372 View* v1 = new View; | 3362 View* v1 = new View; |
| 3373 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); | 3363 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); |
| 3374 test_view->AddChildView(v1); | 3364 test_view->AddChildView(v1); |
| 3375 | 3365 |
| 3376 View* v2 = new View; | 3366 View* v2 = new View; |
| 3377 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3367 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
| 3378 v1->AddChildView(v2); | 3368 v1->AddChildView(v2); |
| 3379 | 3369 |
| 3380 // Schedule a full-view paint to get everyone's rectangles updated. | 3370 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3381 test_view->SchedulePaintInRect(test_view->bounds()); | 3371 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3382 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3372 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3383 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3373 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3384 GetRootLayer()->GetCompositor()); | |
| 3385 | 3374 |
| 3386 // Move v1 to a new origin out of the way of our next query. | 3375 // Move v1 to a new origin out of the way of our next query. |
| 3387 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); | 3376 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); |
| 3388 // The move will force a repaint. | 3377 // The move will force a repaint. |
| 3389 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3378 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3390 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3379 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3391 GetRootLayer()->GetCompositor()); | |
| 3392 | 3380 |
| 3393 // Schedule a paint with damage rect where v1 used to be. | 3381 // Schedule a paint with damage rect where v1 used to be. |
| 3394 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); | 3382 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); |
| 3395 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3383 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3396 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3384 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3397 GetRootLayer()->GetCompositor()); | |
| 3398 | 3385 |
| 3399 // Should only have picked up root_view and test_view. | 3386 // Should only have picked up root_view and test_view. |
| 3400 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3387 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3401 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3388 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3402 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3389 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3403 } | 3390 } |
| 3404 | 3391 |
| 3405 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { | 3392 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { |
| 3406 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3393 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
| 3407 widget()->SetContentsView(test_view); | 3394 widget()->SetContentsView(test_view); |
| 3408 | 3395 |
| 3409 View* v1 = new View; | 3396 View* v1 = new View; |
| 3410 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3397 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
| 3411 test_view->AddChildView(v1); | 3398 test_view->AddChildView(v1); |
| 3412 | 3399 |
| 3413 View* v2 = new View; | 3400 View* v2 = new View; |
| 3414 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3401 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
| 3415 v1->AddChildView(v2); | 3402 v1->AddChildView(v2); |
| 3416 | 3403 |
| 3417 // Schedule a full-view paint to get everyone's rectangles updated. | 3404 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3418 test_view->SchedulePaintInRect(test_view->bounds()); | 3405 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3419 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3406 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3420 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3407 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3421 GetRootLayer()->GetCompositor()); | |
| 3422 | 3408 |
| 3423 // Set v1 to paint to its own layer, it should remove itself from the | 3409 // Set v1 to paint to its own layer, it should remove itself from the |
| 3424 // test_view heiarchy and no longer intersect with damage rects in that cull | 3410 // test_view heiarchy and no longer intersect with damage rects in that cull |
| 3425 // set. | 3411 // set. |
| 3426 v1->SetPaintToLayer(true); | 3412 v1->SetPaintToLayer(true); |
| 3427 | 3413 |
| 3428 // Schedule another full-view paint. | 3414 // Schedule another full-view paint. |
| 3429 test_view->SchedulePaintInRect(test_view->bounds()); | 3415 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3430 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3416 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3431 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3417 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3432 GetRootLayer()->GetCompositor()); | |
| 3433 // v1 and v2 should no longer be present in the test_view cull_set. | 3418 // v1 and v2 should no longer be present in the test_view cull_set. |
| 3434 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3419 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3435 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3420 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
| 3436 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3421 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
| 3437 | 3422 |
| 3438 // Now set v1 back to not painting to a layer. | 3423 // Now set v1 back to not painting to a layer. |
| 3439 v1->SetPaintToLayer(false); | 3424 v1->SetPaintToLayer(false); |
| 3440 // Schedule another full-view paint. | 3425 // Schedule another full-view paint. |
| 3441 test_view->SchedulePaintInRect(test_view->bounds()); | 3426 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3442 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3427 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3443 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3428 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3444 GetRootLayer()->GetCompositor()); | |
| 3445 // We should be back to the full cull set including v1 and v2. | 3429 // We should be back to the full cull set including v1 and v2. |
| 3446 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3430 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
| 3447 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3431 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3448 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3432 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3449 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3433 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3450 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3434 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
| 3451 } | 3435 } |
| 3452 | 3436 |
| 3453 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { | 3437 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { |
| 3454 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3438 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
| 3455 widget()->SetContentsView(test_view); | 3439 widget()->SetContentsView(test_view); |
| 3456 | 3440 |
| 3457 View* v1 = new View; | 3441 View* v1 = new View; |
| 3458 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3442 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
| 3459 test_view->AddChildView(v1); | 3443 test_view->AddChildView(v1); |
| 3460 | 3444 |
| 3461 View* v2 = new View; | 3445 View* v2 = new View; |
| 3462 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3446 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
| 3463 v1->AddChildView(v2); | 3447 v1->AddChildView(v2); |
| 3464 | 3448 |
| 3465 // Schedule a full-view paint to get everyone's rectangles updated. | 3449 // Schedule a full-view paint to get everyone's rectangles updated. |
| 3466 test_view->SchedulePaintInRect(test_view->bounds()); | 3450 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3467 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3451 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3468 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3452 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3469 GetRootLayer()->GetCompositor()); | |
| 3470 | 3453 |
| 3471 // Now remove v1 from the root view. | 3454 // Now remove v1 from the root view. |
| 3472 test_view->RemoveChildView(v1); | 3455 test_view->RemoveChildView(v1); |
| 3473 | 3456 |
| 3474 // Schedule another full-view paint. | 3457 // Schedule another full-view paint. |
| 3475 test_view->SchedulePaintInRect(test_view->bounds()); | 3458 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3476 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3459 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3477 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3460 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3478 GetRootLayer()->GetCompositor()); | |
| 3479 // v1 and v2 should no longer be present in the test_view cull_set. | 3461 // v1 and v2 should no longer be present in the test_view cull_set. |
| 3480 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3462 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
| 3481 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3463 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
| 3482 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3464 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
| 3483 | 3465 |
| 3484 // View v1 and v2 are no longer part of view hierarchy and therefore won't be | 3466 // View v1 and v2 are no longer part of view hierarchy and therefore won't be |
| 3485 // deleted with that hierarchy. | 3467 // deleted with that hierarchy. |
| 3486 delete v1; | 3468 delete v1; |
| 3487 } | 3469 } |
| 3488 | 3470 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3499 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); | 3481 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); |
| 3500 v1->AddChildView(v2); | 3482 v1->AddChildView(v2); |
| 3501 | 3483 |
| 3502 View* v3 = new View; | 3484 View* v3 = new View; |
| 3503 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3485 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
| 3504 v2->AddChildView(v3); | 3486 v2->AddChildView(v3); |
| 3505 | 3487 |
| 3506 // Schedule a full-view paint and ensure all views are present in the cull. | 3488 // Schedule a full-view paint and ensure all views are present in the cull. |
| 3507 test_view->SchedulePaintInRect(test_view->bounds()); | 3489 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3508 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3490 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3509 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3491 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3510 GetRootLayer()->GetCompositor()); | |
| 3511 EXPECT_EQ(5U, test_view->last_cull_set_.size()); | 3492 EXPECT_EQ(5U, test_view->last_cull_set_.size()); |
| 3512 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3493 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3513 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3494 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3514 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3495 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3515 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3496 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
| 3516 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); | 3497 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); |
| 3517 | 3498 |
| 3518 // Build an unrelated view hierarchy and move v2 in to it. | 3499 // Build an unrelated view hierarchy and move v2 in to it. |
| 3519 scoped_ptr<Widget> test_widget(new Widget); | 3500 scoped_ptr<Widget> test_widget(new Widget); |
| 3520 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 3501 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 3521 params.bounds = gfx::Rect(10, 10, 500, 500); | 3502 params.bounds = gfx::Rect(10, 10, 500, 500); |
| 3522 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 3503 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 3523 test_widget->Init(params); | 3504 test_widget->Init(params); |
| 3524 test_widget->Show(); | 3505 test_widget->Show(); |
| 3525 BoundsTreeTestView* widget_view = new BoundsTreeTestView; | 3506 BoundsTreeTestView* widget_view = new BoundsTreeTestView; |
| 3526 test_widget->SetContentsView(widget_view); | 3507 test_widget->SetContentsView(widget_view); |
| 3527 widget_view->AddChildView(v2); | 3508 widget_view->AddChildView(v2); |
| 3528 | 3509 |
| 3529 // Now schedule full-view paints in both widgets. | 3510 // Now schedule full-view paints in both widgets. |
| 3530 test_view->SchedulePaintInRect(test_view->bounds()); | 3511 test_view->SchedulePaintInRect(test_view->bounds()); |
| 3531 widget_view->SchedulePaintInRect(widget_view->bounds()); | 3512 widget_view->SchedulePaintInRect(widget_view->bounds()); |
| 3532 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3513 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
| 3533 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3514 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
| 3534 GetRootLayer()->GetCompositor()); | |
| 3535 | 3515 |
| 3536 // Only v1 should be present in the first cull set. | 3516 // Only v1 should be present in the first cull set. |
| 3537 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3517 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
| 3538 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3518 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
| 3539 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3519 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
| 3540 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3520 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
| 3541 | 3521 |
| 3542 // We should find v2 and v3 in the widget_view cull_set. | 3522 // We should find v2 and v3 in the widget_view cull_set. |
| 3543 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); | 3523 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); |
| 3544 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); | 3524 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... |
| 3655 // notification. | 3635 // notification. |
| 3656 TestView* test_view_child_2 = new TestView(); | 3636 TestView* test_view_child_2 = new TestView(); |
| 3657 test_view->AddChildView(test_view_child_2); | 3637 test_view->AddChildView(test_view_child_2); |
| 3658 EXPECT_TRUE(test_view_child_2->native_theme_); | 3638 EXPECT_TRUE(test_view_child_2->native_theme_); |
| 3659 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 3639 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
| 3660 | 3640 |
| 3661 widget->CloseNow(); | 3641 widget->CloseNow(); |
| 3662 } | 3642 } |
| 3663 | 3643 |
| 3664 } // namespace views | 3644 } // namespace views |
| OLD | NEW |