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 <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
15 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/ptr_util.h" |
18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
22 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
23 #include "cc/layers/layer.h" | 24 #include "cc/layers/layer.h" |
24 #include "cc/output/copy_output_request.h" | 25 #include "cc/output/copy_output_request.h" |
25 #include "cc/output/copy_output_result.h" | 26 #include "cc/output/copy_output_result.h" |
26 #include "cc/surfaces/surface_id.h" | 27 #include "cc/surfaces/surface_id.h" |
27 #include "cc/surfaces/surface_sequence.h" | 28 #include "cc/surfaces/surface_sequence.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 GetCompositor()->ScheduleDraw(); | 145 GetCompositor()->ScheduleDraw(); |
145 WaitForSwap(); | 146 WaitForSwap(); |
146 } | 147 } |
147 | 148 |
148 void ReadPixels(SkBitmap* bitmap) { | 149 void ReadPixels(SkBitmap* bitmap) { |
149 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); | 150 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); |
150 } | 151 } |
151 | 152 |
152 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { | 153 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { |
153 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder); | 154 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder); |
154 scoped_ptr<cc::CopyOutputRequest> request = | 155 std::unique_ptr<cc::CopyOutputRequest> request = |
155 cc::CopyOutputRequest::CreateBitmapRequest( | 156 cc::CopyOutputRequest::CreateBitmapRequest( |
156 base::Bind(&ReadbackHolder::OutputRequestCallback, holder)); | 157 base::Bind(&ReadbackHolder::OutputRequestCallback, holder)); |
157 request->set_area(source_rect); | 158 request->set_area(source_rect); |
158 | 159 |
159 GetCompositor()->root_layer()->RequestCopyOfOutput(std::move(request)); | 160 GetCompositor()->root_layer()->RequestCopyOfOutput(std::move(request)); |
160 | 161 |
161 // Wait for copy response. This needs to wait as the compositor could | 162 // Wait for copy response. This needs to wait as the compositor could |
162 // be in the middle of a draw right now, and the commit with the | 163 // be in the middle of a draw right now, and the commit with the |
163 // copy output request may not be done on the first draw. | 164 // copy output request may not be done on the first draw. |
164 for (int i = 0; i < 2; i++) { | 165 for (int i = 0; i < 2; i++) { |
(...skipping 27 matching lines...) Expand all Loading... |
192 | 193 |
193 const base::FilePath& test_data_directory() const { | 194 const base::FilePath& test_data_directory() const { |
194 return test_data_directory_; | 195 return test_data_directory_; |
195 } | 196 } |
196 | 197 |
197 private: | 198 private: |
198 class ReadbackHolder : public base::RefCountedThreadSafe<ReadbackHolder> { | 199 class ReadbackHolder : public base::RefCountedThreadSafe<ReadbackHolder> { |
199 public: | 200 public: |
200 ReadbackHolder() : run_loop_(new base::RunLoop) {} | 201 ReadbackHolder() : run_loop_(new base::RunLoop) {} |
201 | 202 |
202 void OutputRequestCallback(scoped_ptr<cc::CopyOutputResult> result) { | 203 void OutputRequestCallback(std::unique_ptr<cc::CopyOutputResult> result) { |
203 result_ = result->TakeBitmap(); | 204 result_ = result->TakeBitmap(); |
204 run_loop_->Quit(); | 205 run_loop_->Quit(); |
205 } | 206 } |
206 | 207 |
207 void WaitForReadback() { run_loop_->Run(); } | 208 void WaitForReadback() { run_loop_->Run(); } |
208 | 209 |
209 const SkBitmap& result() const { return *result_; } | 210 const SkBitmap& result() const { return *result_; } |
210 | 211 |
211 private: | 212 private: |
212 friend class base::RefCountedThreadSafe<ReadbackHolder>; | 213 friend class base::RefCountedThreadSafe<ReadbackHolder>; |
213 | 214 |
214 virtual ~ReadbackHolder() {} | 215 virtual ~ReadbackHolder() {} |
215 | 216 |
216 scoped_ptr<SkBitmap> result_; | 217 std::unique_ptr<SkBitmap> result_; |
217 scoped_ptr<base::RunLoop> run_loop_; | 218 std::unique_ptr<base::RunLoop> run_loop_; |
218 }; | 219 }; |
219 | 220 |
220 scoped_ptr<TestCompositorHost> compositor_host_; | 221 std::unique_ptr<TestCompositorHost> compositor_host_; |
221 | 222 |
222 // The root directory for test files. | 223 // The root directory for test files. |
223 base::FilePath test_data_directory_; | 224 base::FilePath test_data_directory_; |
224 | 225 |
225 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest); | 226 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest); |
226 }; | 227 }; |
227 | 228 |
228 // LayerDelegate that paints colors to the layer. | 229 // LayerDelegate that paints colors to the layer. |
229 class TestLayerDelegate : public LayerDelegate { | 230 class TestLayerDelegate : public LayerDelegate { |
230 public: | 231 public: |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 ui::Compositor* compositor_; | 405 ui::Compositor* compositor_; |
405 size_t animation_step_count_; | 406 size_t animation_step_count_; |
406 bool shutdown_; | 407 bool shutdown_; |
407 | 408 |
408 DISALLOW_COPY_AND_ASSIGN(TestCompositorAnimationObserver); | 409 DISALLOW_COPY_AND_ASSIGN(TestCompositorAnimationObserver); |
409 }; | 410 }; |
410 | 411 |
411 } // namespace | 412 } // namespace |
412 | 413 |
413 TEST_F(LayerWithRealCompositorTest, Draw) { | 414 TEST_F(LayerWithRealCompositorTest, Draw) { |
414 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, | 415 std::unique_ptr<Layer> layer( |
415 gfx::Rect(20, 20, 50, 50))); | 416 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 50, 50))); |
416 DrawTree(layer.get()); | 417 DrawTree(layer.get()); |
417 } | 418 } |
418 | 419 |
419 // Create this hierarchy: | 420 // Create this hierarchy: |
420 // L1 - red | 421 // L1 - red |
421 // +-- L2 - blue | 422 // +-- L2 - blue |
422 // | +-- L3 - yellow | 423 // | +-- L3 - yellow |
423 // +-- L4 - magenta | 424 // +-- L4 - magenta |
424 // | 425 // |
425 TEST_F(LayerWithRealCompositorTest, Hierarchy) { | 426 TEST_F(LayerWithRealCompositorTest, Hierarchy) { |
426 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 427 std::unique_ptr<Layer> l1( |
427 gfx::Rect(20, 20, 400, 400))); | 428 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); |
428 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 429 std::unique_ptr<Layer> l2( |
429 gfx::Rect(10, 10, 350, 350))); | 430 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350))); |
430 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, | 431 std::unique_ptr<Layer> l3( |
431 gfx::Rect(5, 5, 25, 25))); | 432 CreateColorLayer(SK_ColorYELLOW, gfx::Rect(5, 5, 25, 25))); |
432 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA, | 433 std::unique_ptr<Layer> l4( |
433 gfx::Rect(300, 300, 100, 100))); | 434 CreateColorLayer(SK_ColorMAGENTA, gfx::Rect(300, 300, 100, 100))); |
434 | 435 |
435 l1->Add(l2.get()); | 436 l1->Add(l2.get()); |
436 l1->Add(l4.get()); | 437 l1->Add(l4.get()); |
437 l2->Add(l3.get()); | 438 l2->Add(l3.get()); |
438 | 439 |
439 DrawTree(l1.get()); | 440 DrawTree(l1.get()); |
440 } | 441 } |
441 | 442 |
442 class LayerWithDelegateTest : public testing::Test { | 443 class LayerWithDelegateTest : public testing::Test { |
443 public: | 444 public: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 499 |
499 void WaitForDraw() { | 500 void WaitForDraw() { |
500 DrawWaiterForTest::WaitForCompositingStarted(compositor()); | 501 DrawWaiterForTest::WaitForCompositingStarted(compositor()); |
501 } | 502 } |
502 | 503 |
503 void WaitForCommit() { | 504 void WaitForCommit() { |
504 DrawWaiterForTest::WaitForCommit(compositor()); | 505 DrawWaiterForTest::WaitForCommit(compositor()); |
505 } | 506 } |
506 | 507 |
507 private: | 508 private: |
508 scoped_ptr<TestCompositorHost> compositor_host_; | 509 std::unique_ptr<TestCompositorHost> compositor_host_; |
509 | 510 |
510 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); | 511 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); |
511 }; | 512 }; |
512 | 513 |
513 void ReturnMailbox(bool* run, const gpu::SyncToken& sync_token, bool is_lost) { | 514 void ReturnMailbox(bool* run, const gpu::SyncToken& sync_token, bool is_lost) { |
514 *run = true; | 515 *run = true; |
515 } | 516 } |
516 | 517 |
517 TEST(LayerStandaloneTest, ReleaseMailboxOnDestruction) { | 518 TEST(LayerStandaloneTest, ReleaseMailboxOnDestruction) { |
518 scoped_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); | 519 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); |
519 bool callback_run = false; | 520 bool callback_run = false; |
520 cc::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); | 521 cc::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), 0); |
521 layer->SetTextureMailbox(mailbox, | 522 layer->SetTextureMailbox(mailbox, |
522 cc::SingleReleaseCallback::Create( | 523 cc::SingleReleaseCallback::Create( |
523 base::Bind(ReturnMailbox, &callback_run)), | 524 base::Bind(ReturnMailbox, &callback_run)), |
524 gfx::Size(10, 10)); | 525 gfx::Size(10, 10)); |
525 EXPECT_FALSE(callback_run); | 526 EXPECT_FALSE(callback_run); |
526 layer.reset(); | 527 layer.reset(); |
527 EXPECT_TRUE(callback_run); | 528 EXPECT_TRUE(callback_run); |
528 } | 529 } |
529 | 530 |
530 // L1 | 531 // L1 |
531 // +-- L2 | 532 // +-- L2 |
532 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) { | 533 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) { |
533 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 534 std::unique_ptr<Layer> l1( |
534 gfx::Rect(20, 20, 400, 400))); | 535 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); |
535 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 536 std::unique_ptr<Layer> l2( |
536 gfx::Rect(10, 10, 350, 350))); | 537 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350))); |
537 l1->Add(l2.get()); | 538 l1->Add(l2.get()); |
538 DrawTree(l1.get()); | 539 DrawTree(l1.get()); |
539 | 540 |
540 gfx::Point point1_in_l2_coords(5, 5); | 541 gfx::Point point1_in_l2_coords(5, 5); |
541 Layer::ConvertPointToLayer(l2.get(), l1.get(), &point1_in_l2_coords); | 542 Layer::ConvertPointToLayer(l2.get(), l1.get(), &point1_in_l2_coords); |
542 gfx::Point point1_in_l1_coords(15, 15); | 543 gfx::Point point1_in_l1_coords(15, 15); |
543 EXPECT_EQ(point1_in_l1_coords, point1_in_l2_coords); | 544 EXPECT_EQ(point1_in_l1_coords, point1_in_l2_coords); |
544 | 545 |
545 gfx::Point point2_in_l1_coords(5, 5); | 546 gfx::Point point2_in_l1_coords(5, 5); |
546 Layer::ConvertPointToLayer(l1.get(), l2.get(), &point2_in_l1_coords); | 547 Layer::ConvertPointToLayer(l1.get(), l2.get(), &point2_in_l1_coords); |
547 gfx::Point point2_in_l2_coords(-5, -5); | 548 gfx::Point point2_in_l2_coords(-5, -5); |
548 EXPECT_EQ(point2_in_l2_coords, point2_in_l1_coords); | 549 EXPECT_EQ(point2_in_l2_coords, point2_in_l1_coords); |
549 } | 550 } |
550 | 551 |
551 // L1 | 552 // L1 |
552 // +-- L2 | 553 // +-- L2 |
553 // +-- L3 | 554 // +-- L3 |
554 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Medium) { | 555 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Medium) { |
555 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 556 std::unique_ptr<Layer> l1( |
556 gfx::Rect(20, 20, 400, 400))); | 557 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); |
557 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 558 std::unique_ptr<Layer> l2( |
558 gfx::Rect(10, 10, 350, 350))); | 559 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350))); |
559 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, | 560 std::unique_ptr<Layer> l3( |
560 gfx::Rect(10, 10, 100, 100))); | 561 CreateColorLayer(SK_ColorYELLOW, gfx::Rect(10, 10, 100, 100))); |
561 l1->Add(l2.get()); | 562 l1->Add(l2.get()); |
562 l2->Add(l3.get()); | 563 l2->Add(l3.get()); |
563 DrawTree(l1.get()); | 564 DrawTree(l1.get()); |
564 | 565 |
565 gfx::Point point1_in_l3_coords(5, 5); | 566 gfx::Point point1_in_l3_coords(5, 5); |
566 Layer::ConvertPointToLayer(l3.get(), l1.get(), &point1_in_l3_coords); | 567 Layer::ConvertPointToLayer(l3.get(), l1.get(), &point1_in_l3_coords); |
567 gfx::Point point1_in_l1_coords(25, 25); | 568 gfx::Point point1_in_l1_coords(25, 25); |
568 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords); | 569 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords); |
569 | 570 |
570 gfx::Point point2_in_l1_coords(5, 5); | 571 gfx::Point point2_in_l1_coords(5, 5); |
571 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); | 572 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); |
572 gfx::Point point2_in_l3_coords(-15, -15); | 573 gfx::Point point2_in_l3_coords(-15, -15); |
573 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); | 574 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); |
574 } | 575 } |
575 | 576 |
576 TEST_F(LayerWithRealCompositorTest, Delegate) { | 577 TEST_F(LayerWithRealCompositorTest, Delegate) { |
577 // This test makes sure that whenever paint happens at a layer, its layer | 578 // This test makes sure that whenever paint happens at a layer, its layer |
578 // delegate gets the paint, which in this test update its color and | 579 // delegate gets the paint, which in this test update its color and |
579 // |color_index|. | 580 // |color_index|. |
580 scoped_ptr<Layer> l1( | 581 std::unique_ptr<Layer> l1( |
581 CreateColorLayer(SK_ColorBLACK, gfx::Rect(20, 20, 400, 400))); | 582 CreateColorLayer(SK_ColorBLACK, gfx::Rect(20, 20, 400, 400))); |
582 GetCompositor()->SetRootLayer(l1.get()); | 583 GetCompositor()->SetRootLayer(l1.get()); |
583 WaitForDraw(); | 584 WaitForDraw(); |
584 | 585 |
585 TestLayerDelegate delegate; | 586 TestLayerDelegate delegate; |
586 l1->set_delegate(&delegate); | 587 l1->set_delegate(&delegate); |
587 delegate.set_layer_bounds(l1->bounds()); | 588 delegate.set_layer_bounds(l1->bounds()); |
588 delegate.AddColor(SK_ColorWHITE); | 589 delegate.AddColor(SK_ColorWHITE); |
589 delegate.AddColor(SK_ColorYELLOW); | 590 delegate.AddColor(SK_ColorYELLOW); |
590 delegate.AddColor(SK_ColorGREEN); | 591 delegate.AddColor(SK_ColorGREEN); |
591 | 592 |
592 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); | 593 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); |
593 WaitForDraw(); | 594 WaitForDraw(); |
594 // Test that paint happened at layer delegate. | 595 // Test that paint happened at layer delegate. |
595 EXPECT_EQ(1, delegate.color_index()); | 596 EXPECT_EQ(1, delegate.color_index()); |
596 | 597 |
597 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); | 598 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); |
598 WaitForDraw(); | 599 WaitForDraw(); |
599 // Test that paint happened at layer delegate. | 600 // Test that paint happened at layer delegate. |
600 EXPECT_EQ(2, delegate.color_index()); | 601 EXPECT_EQ(2, delegate.color_index()); |
601 | 602 |
602 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); | 603 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); |
603 WaitForDraw(); | 604 WaitForDraw(); |
604 // Test that paint happened at layer delegate. | 605 // Test that paint happened at layer delegate. |
605 EXPECT_EQ(0, delegate.color_index()); | 606 EXPECT_EQ(0, delegate.color_index()); |
606 } | 607 } |
607 | 608 |
608 TEST_F(LayerWithRealCompositorTest, DrawTree) { | 609 TEST_F(LayerWithRealCompositorTest, DrawTree) { |
609 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 610 std::unique_ptr<Layer> l1( |
610 gfx::Rect(20, 20, 400, 400))); | 611 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); |
611 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 612 std::unique_ptr<Layer> l2( |
612 gfx::Rect(10, 10, 350, 350))); | 613 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350))); |
613 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, | 614 std::unique_ptr<Layer> l3( |
614 gfx::Rect(10, 10, 100, 100))); | 615 CreateColorLayer(SK_ColorYELLOW, gfx::Rect(10, 10, 100, 100))); |
615 l1->Add(l2.get()); | 616 l1->Add(l2.get()); |
616 l2->Add(l3.get()); | 617 l2->Add(l3.get()); |
617 | 618 |
618 GetCompositor()->SetRootLayer(l1.get()); | 619 GetCompositor()->SetRootLayer(l1.get()); |
619 WaitForDraw(); | 620 WaitForDraw(); |
620 | 621 |
621 DrawTreeLayerDelegate d1(l1->bounds()); | 622 DrawTreeLayerDelegate d1(l1->bounds()); |
622 l1->set_delegate(&d1); | 623 l1->set_delegate(&d1); |
623 DrawTreeLayerDelegate d2(l2->bounds()); | 624 DrawTreeLayerDelegate d2(l2->bounds()); |
624 l2->set_delegate(&d2); | 625 l2->set_delegate(&d2); |
625 DrawTreeLayerDelegate d3(l3->bounds()); | 626 DrawTreeLayerDelegate d3(l3->bounds()); |
626 l3->set_delegate(&d3); | 627 l3->set_delegate(&d3); |
627 | 628 |
628 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); | 629 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); |
629 WaitForDraw(); | 630 WaitForDraw(); |
630 EXPECT_FALSE(d1.painted()); | 631 EXPECT_FALSE(d1.painted()); |
631 EXPECT_TRUE(d2.painted()); | 632 EXPECT_TRUE(d2.painted()); |
632 EXPECT_FALSE(d3.painted()); | 633 EXPECT_FALSE(d3.painted()); |
633 } | 634 } |
634 | 635 |
635 // Tests no-texture Layers. | 636 // Tests no-texture Layers. |
636 // Create this hierarchy: | 637 // Create this hierarchy: |
637 // L1 - red | 638 // L1 - red |
638 // +-- L2 - NO TEXTURE | 639 // +-- L2 - NO TEXTURE |
639 // | +-- L3 - yellow | 640 // | +-- L3 - yellow |
640 // +-- L4 - magenta | 641 // +-- L4 - magenta |
641 // | 642 // |
642 TEST_F(LayerWithRealCompositorTest, HierarchyNoTexture) { | 643 TEST_F(LayerWithRealCompositorTest, HierarchyNoTexture) { |
643 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 644 std::unique_ptr<Layer> l1( |
644 gfx::Rect(20, 20, 400, 400))); | 645 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); |
645 scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350))); | 646 std::unique_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350))); |
646 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, | 647 std::unique_ptr<Layer> l3( |
647 gfx::Rect(5, 5, 25, 25))); | 648 CreateColorLayer(SK_ColorYELLOW, gfx::Rect(5, 5, 25, 25))); |
648 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA, | 649 std::unique_ptr<Layer> l4( |
649 gfx::Rect(300, 300, 100, 100))); | 650 CreateColorLayer(SK_ColorMAGENTA, gfx::Rect(300, 300, 100, 100))); |
650 | 651 |
651 l1->Add(l2.get()); | 652 l1->Add(l2.get()); |
652 l1->Add(l4.get()); | 653 l1->Add(l4.get()); |
653 l2->Add(l3.get()); | 654 l2->Add(l3.get()); |
654 | 655 |
655 GetCompositor()->SetRootLayer(l1.get()); | 656 GetCompositor()->SetRootLayer(l1.get()); |
656 WaitForDraw(); | 657 WaitForDraw(); |
657 | 658 |
658 DrawTreeLayerDelegate d2(l2->bounds()); | 659 DrawTreeLayerDelegate d2(l2->bounds()); |
659 l2->set_delegate(&d2); | 660 l2->set_delegate(&d2); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 return layer; | 699 return layer; |
699 } | 700 } |
700 | 701 |
701 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) override { | 702 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) override { |
702 Layer* layer = CreateLayer(LAYER_NOT_DRAWN); | 703 Layer* layer = CreateLayer(LAYER_NOT_DRAWN); |
703 layer->SetBounds(bounds); | 704 layer->SetBounds(bounds); |
704 return layer; | 705 return layer; |
705 } | 706 } |
706 | 707 |
707 private: | 708 private: |
708 scoped_ptr<NullLayerDelegate> default_layer_delegate_; | 709 std::unique_ptr<NullLayerDelegate> default_layer_delegate_; |
709 | 710 |
710 DISALLOW_COPY_AND_ASSIGN(LayerWithNullDelegateTest); | 711 DISALLOW_COPY_AND_ASSIGN(LayerWithNullDelegateTest); |
711 }; | 712 }; |
712 | 713 |
713 TEST_F(LayerWithNullDelegateTest, EscapedDebugNames) { | 714 TEST_F(LayerWithNullDelegateTest, EscapedDebugNames) { |
714 scoped_ptr<Layer> layer(CreateLayer(LAYER_NOT_DRAWN)); | 715 std::unique_ptr<Layer> layer(CreateLayer(LAYER_NOT_DRAWN)); |
715 std::string name = "\"\'\\/\b\f\n\r\t\n"; | 716 std::string name = "\"\'\\/\b\f\n\r\t\n"; |
716 layer->set_name(name); | 717 layer->set_name(name); |
717 scoped_ptr<base::trace_event::ConvertableToTraceFormat> debug_info( | 718 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info( |
718 layer->TakeDebugInfo(layer->cc_layer_for_testing())); | 719 layer->TakeDebugInfo(layer->cc_layer_for_testing())); |
719 EXPECT_TRUE(debug_info.get()); | 720 EXPECT_TRUE(debug_info.get()); |
720 std::string json; | 721 std::string json; |
721 debug_info->AppendAsTraceFormat(&json); | 722 debug_info->AppendAsTraceFormat(&json); |
722 base::JSONReader json_reader; | 723 base::JSONReader json_reader; |
723 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(json)); | 724 std::unique_ptr<base::Value> debug_info_value(json_reader.ReadToValue(json)); |
724 EXPECT_TRUE(debug_info_value); | 725 EXPECT_TRUE(debug_info_value); |
725 EXPECT_TRUE(debug_info_value->IsType(base::Value::TYPE_DICTIONARY)); | 726 EXPECT_TRUE(debug_info_value->IsType(base::Value::TYPE_DICTIONARY)); |
726 base::DictionaryValue* dictionary = 0; | 727 base::DictionaryValue* dictionary = 0; |
727 EXPECT_TRUE(debug_info_value->GetAsDictionary(&dictionary)); | 728 EXPECT_TRUE(debug_info_value->GetAsDictionary(&dictionary)); |
728 std::string roundtrip; | 729 std::string roundtrip; |
729 EXPECT_TRUE(dictionary->GetString("layer_name", &roundtrip)); | 730 EXPECT_TRUE(dictionary->GetString("layer_name", &roundtrip)); |
730 EXPECT_EQ(name, roundtrip); | 731 EXPECT_EQ(name, roundtrip); |
731 } | 732 } |
732 | 733 |
733 TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { | 734 TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { |
734 scoped_ptr<Layer> l1(CreateLayer(LAYER_SOLID_COLOR)); | 735 std::unique_ptr<Layer> l1(CreateLayer(LAYER_SOLID_COLOR)); |
735 l1->SetFillsBoundsOpaquely(true); | 736 l1->SetFillsBoundsOpaquely(true); |
736 l1->SetForceRenderSurface(true); | 737 l1->SetForceRenderSurface(true); |
737 l1->SetVisible(false); | 738 l1->SetVisible(false); |
738 l1->SetBounds(gfx::Rect(4, 5)); | 739 l1->SetBounds(gfx::Rect(4, 5)); |
739 | 740 |
740 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); | 741 EXPECT_EQ(gfx::Point3F(), l1->cc_layer_for_testing()->transform_origin()); |
741 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); | 742 EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); |
742 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); | 743 EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); |
743 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); | 744 EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); |
744 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 745 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 799 EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
799 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); | 800 EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); |
800 EXPECT_FALSE(callback3_run); | 801 EXPECT_FALSE(callback3_run); |
801 | 802 |
802 // Release the on |l1| mailbox to clean up the test. | 803 // Release the on |l1| mailbox to clean up the test. |
803 l1->SetShowSolidColorContent(); | 804 l1->SetShowSolidColorContent(); |
804 } | 805 } |
805 | 806 |
806 // Various visibile/drawn assertions. | 807 // Various visibile/drawn assertions. |
807 TEST_F(LayerWithNullDelegateTest, Visibility) { | 808 TEST_F(LayerWithNullDelegateTest, Visibility) { |
808 scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); | 809 std::unique_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); |
809 scoped_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); | 810 std::unique_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); |
810 scoped_ptr<Layer> l3(new Layer(LAYER_TEXTURED)); | 811 std::unique_ptr<Layer> l3(new Layer(LAYER_TEXTURED)); |
811 l1->Add(l2.get()); | 812 l1->Add(l2.get()); |
812 l2->Add(l3.get()); | 813 l2->Add(l3.get()); |
813 | 814 |
814 NullLayerDelegate delegate; | 815 NullLayerDelegate delegate; |
815 l1->set_delegate(&delegate); | 816 l1->set_delegate(&delegate); |
816 l2->set_delegate(&delegate); | 817 l2->set_delegate(&delegate); |
817 l3->set_delegate(&delegate); | 818 l3->set_delegate(&delegate); |
818 | 819 |
819 // Layers should initially be drawn. | 820 // Layers should initially be drawn. |
820 EXPECT_TRUE(l1->IsDrawn()); | 821 EXPECT_TRUE(l1->IsDrawn()); |
(...skipping 27 matching lines...) Expand all Loading... |
848 EXPECT_TRUE(l1->IsDrawn()); | 849 EXPECT_TRUE(l1->IsDrawn()); |
849 EXPECT_TRUE(l2->IsDrawn()); | 850 EXPECT_TRUE(l2->IsDrawn()); |
850 EXPECT_FALSE(l3->IsDrawn()); | 851 EXPECT_FALSE(l3->IsDrawn()); |
851 EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); | 852 EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
852 EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); | 853 EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); |
853 EXPECT_TRUE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); | 854 EXPECT_TRUE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); |
854 } | 855 } |
855 | 856 |
856 // Checks that stacking-related methods behave as advertised. | 857 // Checks that stacking-related methods behave as advertised. |
857 TEST_F(LayerWithNullDelegateTest, Stacking) { | 858 TEST_F(LayerWithNullDelegateTest, Stacking) { |
858 scoped_ptr<Layer> root(new Layer(LAYER_NOT_DRAWN)); | 859 std::unique_ptr<Layer> root(new Layer(LAYER_NOT_DRAWN)); |
859 scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); | 860 std::unique_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); |
860 scoped_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); | 861 std::unique_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); |
861 scoped_ptr<Layer> l3(new Layer(LAYER_TEXTURED)); | 862 std::unique_ptr<Layer> l3(new Layer(LAYER_TEXTURED)); |
862 l1->set_name("1"); | 863 l1->set_name("1"); |
863 l2->set_name("2"); | 864 l2->set_name("2"); |
864 l3->set_name("3"); | 865 l3->set_name("3"); |
865 root->Add(l3.get()); | 866 root->Add(l3.get()); |
866 root->Add(l2.get()); | 867 root->Add(l2.get()); |
867 root->Add(l1.get()); | 868 root->Add(l1.get()); |
868 | 869 |
869 // Layers' children are stored in bottom-to-top order. | 870 // Layers' children are stored in bottom-to-top order. |
870 EXPECT_EQ("3 2 1", test::ChildLayerNamesAsString(*root.get())); | 871 EXPECT_EQ("3 2 1", test::ChildLayerNamesAsString(*root.get())); |
871 | 872 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 | 908 |
908 root->StackBelow(l3.get(), l2.get()); | 909 root->StackBelow(l3.get(), l2.get()); |
909 EXPECT_EQ("3 2 1", test::ChildLayerNamesAsString(*root.get())); | 910 EXPECT_EQ("3 2 1", test::ChildLayerNamesAsString(*root.get())); |
910 | 911 |
911 root->StackBelow(l3.get(), l1.get()); | 912 root->StackBelow(l3.get(), l1.get()); |
912 EXPECT_EQ("2 3 1", test::ChildLayerNamesAsString(*root.get())); | 913 EXPECT_EQ("2 3 1", test::ChildLayerNamesAsString(*root.get())); |
913 } | 914 } |
914 | 915 |
915 // Verifies SetBounds triggers the appropriate painting/drawing. | 916 // Verifies SetBounds triggers the appropriate painting/drawing. |
916 TEST_F(LayerWithNullDelegateTest, SetBoundsSchedulesPaint) { | 917 TEST_F(LayerWithNullDelegateTest, SetBoundsSchedulesPaint) { |
917 scoped_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200))); | 918 std::unique_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200))); |
918 compositor()->SetRootLayer(l1.get()); | 919 compositor()->SetRootLayer(l1.get()); |
919 | 920 |
920 Draw(); | 921 Draw(); |
921 | 922 |
922 l1->SetBounds(gfx::Rect(5, 5, 200, 200)); | 923 l1->SetBounds(gfx::Rect(5, 5, 200, 200)); |
923 | 924 |
924 // The CompositorDelegate (us) should have been told to draw for a move. | 925 // The CompositorDelegate (us) should have been told to draw for a move. |
925 WaitForDraw(); | 926 WaitForDraw(); |
926 | 927 |
927 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); | 928 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); |
(...skipping 21 matching lines...) Expand all Loading... |
949 TEST_F(LayerWithRealCompositorTest, DrawPixels) { | 950 TEST_F(LayerWithRealCompositorTest, DrawPixels) { |
950 gfx::Size viewport_size = GetCompositor()->size(); | 951 gfx::Size viewport_size = GetCompositor()->size(); |
951 | 952 |
952 // The window should be some non-trivial size but may not be exactly | 953 // The window should be some non-trivial size but may not be exactly |
953 // 500x500 on all platforms/bots. | 954 // 500x500 on all platforms/bots. |
954 EXPECT_GE(viewport_size.width(), 200); | 955 EXPECT_GE(viewport_size.width(), 200); |
955 EXPECT_GE(viewport_size.height(), 200); | 956 EXPECT_GE(viewport_size.height(), 200); |
956 | 957 |
957 int blue_height = 10; | 958 int blue_height = 10; |
958 | 959 |
959 scoped_ptr<Layer> layer( | 960 std::unique_ptr<Layer> layer( |
960 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); | 961 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); |
961 scoped_ptr<Layer> layer2( | 962 std::unique_ptr<Layer> layer2(CreateColorLayer( |
962 CreateColorLayer(SK_ColorBLUE, | 963 SK_ColorBLUE, gfx::Rect(0, 0, viewport_size.width(), blue_height))); |
963 gfx::Rect(0, 0, viewport_size.width(), blue_height))); | |
964 | 964 |
965 layer->Add(layer2.get()); | 965 layer->Add(layer2.get()); |
966 | 966 |
967 DrawTree(layer.get()); | 967 DrawTree(layer.get()); |
968 | 968 |
969 SkBitmap bitmap; | 969 SkBitmap bitmap; |
970 ReadPixels(&bitmap, gfx::Rect(viewport_size)); | 970 ReadPixels(&bitmap, gfx::Rect(viewport_size)); |
971 ASSERT_FALSE(bitmap.empty()); | 971 ASSERT_FALSE(bitmap.empty()); |
972 | 972 |
973 SkAutoLockPixels lock(bitmap); | 973 SkAutoLockPixels lock(bitmap); |
(...skipping 12 matching lines...) Expand all Loading... |
986 gfx::Size viewport_size = GetCompositor()->size(); | 986 gfx::Size viewport_size = GetCompositor()->size(); |
987 | 987 |
988 int test_size = 200; | 988 int test_size = 200; |
989 EXPECT_GE(viewport_size.width(), test_size); | 989 EXPECT_GE(viewport_size.width(), test_size); |
990 EXPECT_GE(viewport_size.height(), test_size); | 990 EXPECT_GE(viewport_size.height(), test_size); |
991 | 991 |
992 // Blue with a wee bit of transparency. | 992 // Blue with a wee bit of transparency. |
993 SkColor blue_with_alpha = SkColorSetARGBInline(40, 10, 20, 200); | 993 SkColor blue_with_alpha = SkColorSetARGBInline(40, 10, 20, 200); |
994 SkColor blend_color = SkColorSetARGBInline(255, 216, 3, 32); | 994 SkColor blend_color = SkColorSetARGBInline(255, 216, 3, 32); |
995 | 995 |
996 scoped_ptr<Layer> background_layer( | 996 std::unique_ptr<Layer> background_layer( |
997 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); | 997 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); |
998 scoped_ptr<Layer> foreground_layer( | 998 std::unique_ptr<Layer> foreground_layer( |
999 CreateColorLayer(blue_with_alpha, gfx::Rect(viewport_size))); | 999 CreateColorLayer(blue_with_alpha, gfx::Rect(viewport_size))); |
1000 | 1000 |
1001 // This must be set to false for layers with alpha to be blended correctly. | 1001 // This must be set to false for layers with alpha to be blended correctly. |
1002 foreground_layer->SetFillsBoundsOpaquely(false); | 1002 foreground_layer->SetFillsBoundsOpaquely(false); |
1003 | 1003 |
1004 background_layer->Add(foreground_layer.get()); | 1004 background_layer->Add(foreground_layer.get()); |
1005 DrawTree(background_layer.get()); | 1005 DrawTree(background_layer.get()); |
1006 | 1006 |
1007 SkBitmap bitmap; | 1007 SkBitmap bitmap; |
1008 ReadPixels(&bitmap, gfx::Rect(viewport_size)); | 1008 ReadPixels(&bitmap, gfx::Rect(viewport_size)); |
(...skipping 14 matching lines...) Expand all Loading... |
1023 gfx::Size viewport_size = GetCompositor()->size(); | 1023 gfx::Size viewport_size = GetCompositor()->size(); |
1024 | 1024 |
1025 int test_size = 200; | 1025 int test_size = 200; |
1026 EXPECT_GE(viewport_size.width(), test_size); | 1026 EXPECT_GE(viewport_size.width(), test_size); |
1027 EXPECT_GE(viewport_size.height(), test_size); | 1027 EXPECT_GE(viewport_size.height(), test_size); |
1028 | 1028 |
1029 int blue_height = 10; | 1029 int blue_height = 10; |
1030 SkColor blue_with_alpha = SkColorSetARGBInline(40, 0, 0, 255); | 1030 SkColor blue_with_alpha = SkColorSetARGBInline(40, 0, 0, 255); |
1031 SkColor blend_color = SkColorSetARGBInline(255, 215, 0, 40); | 1031 SkColor blend_color = SkColorSetARGBInline(255, 215, 0, 40); |
1032 | 1032 |
1033 scoped_ptr<Layer> background_layer( | 1033 std::unique_ptr<Layer> background_layer( |
1034 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); | 1034 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); |
1035 scoped_ptr<Layer> foreground_layer( | 1035 std::unique_ptr<Layer> foreground_layer( |
1036 CreateColorLayer(blue_with_alpha, gfx::Rect(viewport_size))); | 1036 CreateColorLayer(blue_with_alpha, gfx::Rect(viewport_size))); |
1037 | 1037 |
1038 // Add a shape to restrict the visible part of the layer. | 1038 // Add a shape to restrict the visible part of the layer. |
1039 SkRegion shape; | 1039 SkRegion shape; |
1040 shape.setRect(0, 0, viewport_size.width(), blue_height); | 1040 shape.setRect(0, 0, viewport_size.width(), blue_height); |
1041 foreground_layer->SetAlphaShape(make_scoped_ptr(new SkRegion(shape))); | 1041 foreground_layer->SetAlphaShape(base::WrapUnique(new SkRegion(shape))); |
1042 | 1042 |
1043 foreground_layer->SetFillsBoundsOpaquely(false); | 1043 foreground_layer->SetFillsBoundsOpaquely(false); |
1044 | 1044 |
1045 background_layer->Add(foreground_layer.get()); | 1045 background_layer->Add(foreground_layer.get()); |
1046 DrawTree(background_layer.get()); | 1046 DrawTree(background_layer.get()); |
1047 | 1047 |
1048 SkBitmap bitmap; | 1048 SkBitmap bitmap; |
1049 ReadPixels(&bitmap, gfx::Rect(viewport_size)); | 1049 ReadPixels(&bitmap, gfx::Rect(viewport_size)); |
1050 ASSERT_FALSE(bitmap.empty()); | 1050 ASSERT_FALSE(bitmap.empty()); |
1051 | 1051 |
1052 SkAutoLockPixels lock(bitmap); | 1052 SkAutoLockPixels lock(bitmap); |
1053 for (int x = 0; x < test_size; x++) { | 1053 for (int x = 0; x < test_size; x++) { |
1054 for (int y = 0; y < test_size; y++) { | 1054 for (int y = 0; y < test_size; y++) { |
1055 SkColor actual_color = bitmap.getColor(x, y); | 1055 SkColor actual_color = bitmap.getColor(x, y); |
1056 ExpectRgba(x, y, actual_color, | 1056 ExpectRgba(x, y, actual_color, |
1057 y < blue_height ? blend_color : SK_ColorRED); | 1057 y < blue_height ? blend_color : SK_ColorRED); |
1058 } | 1058 } |
1059 } | 1059 } |
1060 } | 1060 } |
1061 | 1061 |
1062 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. | 1062 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. |
1063 TEST_F(LayerWithRealCompositorTest, SetRootLayer) { | 1063 TEST_F(LayerWithRealCompositorTest, SetRootLayer) { |
1064 Compositor* compositor = GetCompositor(); | 1064 Compositor* compositor = GetCompositor(); |
1065 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 1065 std::unique_ptr<Layer> l1( |
1066 gfx::Rect(20, 20, 400, 400))); | 1066 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); |
1067 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 1067 std::unique_ptr<Layer> l2( |
1068 gfx::Rect(10, 10, 350, 350))); | 1068 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350))); |
1069 | 1069 |
1070 EXPECT_EQ(NULL, l1->GetCompositor()); | 1070 EXPECT_EQ(NULL, l1->GetCompositor()); |
1071 EXPECT_EQ(NULL, l2->GetCompositor()); | 1071 EXPECT_EQ(NULL, l2->GetCompositor()); |
1072 | 1072 |
1073 compositor->SetRootLayer(l1.get()); | 1073 compositor->SetRootLayer(l1.get()); |
1074 EXPECT_EQ(compositor, l1->GetCompositor()); | 1074 EXPECT_EQ(compositor, l1->GetCompositor()); |
1075 | 1075 |
1076 l1->Add(l2.get()); | 1076 l1->Add(l2.get()); |
1077 EXPECT_EQ(compositor, l2->GetCompositor()); | 1077 EXPECT_EQ(compositor, l2->GetCompositor()); |
1078 | 1078 |
1079 l1->Remove(l2.get()); | 1079 l1->Remove(l2.get()); |
1080 EXPECT_EQ(NULL, l2->GetCompositor()); | 1080 EXPECT_EQ(NULL, l2->GetCompositor()); |
1081 | 1081 |
1082 l1->Add(l2.get()); | 1082 l1->Add(l2.get()); |
1083 EXPECT_EQ(compositor, l2->GetCompositor()); | 1083 EXPECT_EQ(compositor, l2->GetCompositor()); |
1084 | 1084 |
1085 compositor->SetRootLayer(NULL); | 1085 compositor->SetRootLayer(NULL); |
1086 EXPECT_EQ(NULL, l1->GetCompositor()); | 1086 EXPECT_EQ(NULL, l1->GetCompositor()); |
1087 EXPECT_EQ(NULL, l2->GetCompositor()); | 1087 EXPECT_EQ(NULL, l2->GetCompositor()); |
1088 } | 1088 } |
1089 | 1089 |
1090 // Checks that compositor observers are notified when: | 1090 // Checks that compositor observers are notified when: |
1091 // - DrawTree is called, | 1091 // - DrawTree is called, |
1092 // - After ScheduleDraw is called, or | 1092 // - After ScheduleDraw is called, or |
1093 // - Whenever SetBounds, SetOpacity or SetTransform are called. | 1093 // - Whenever SetBounds, SetOpacity or SetTransform are called. |
1094 // TODO(vollick): could be reorganized into compositor_unittest.cc | 1094 // TODO(vollick): could be reorganized into compositor_unittest.cc |
1095 TEST_F(LayerWithRealCompositorTest, CompositorObservers) { | 1095 TEST_F(LayerWithRealCompositorTest, CompositorObservers) { |
1096 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 1096 std::unique_ptr<Layer> l1( |
1097 gfx::Rect(20, 20, 400, 400))); | 1097 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); |
1098 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 1098 std::unique_ptr<Layer> l2( |
1099 gfx::Rect(10, 10, 350, 350))); | 1099 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350))); |
1100 l1->Add(l2.get()); | 1100 l1->Add(l2.get()); |
1101 TestCompositorObserver observer; | 1101 TestCompositorObserver observer; |
1102 GetCompositor()->AddObserver(&observer); | 1102 GetCompositor()->AddObserver(&observer); |
1103 | 1103 |
1104 // Explicitly called DrawTree should cause the observers to be notified. | 1104 // Explicitly called DrawTree should cause the observers to be notified. |
1105 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer. | 1105 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer. |
1106 DrawTree(l1.get()); | 1106 DrawTree(l1.get()); |
1107 EXPECT_TRUE(observer.notified()); | 1107 EXPECT_TRUE(observer.notified()); |
1108 | 1108 |
1109 // ScheduleDraw without any visible change should cause a commit. | 1109 // ScheduleDraw without any visible change should cause a commit. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 } | 1166 } |
1167 | 1167 |
1168 // Checks that modifying the hierarchy correctly affects final composite. | 1168 // Checks that modifying the hierarchy correctly affects final composite. |
1169 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { | 1169 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { |
1170 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); | 1170 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); |
1171 | 1171 |
1172 // l0 | 1172 // l0 |
1173 // +-l11 | 1173 // +-l11 |
1174 // | +-l21 | 1174 // | +-l21 |
1175 // +-l12 | 1175 // +-l12 |
1176 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, | 1176 std::unique_ptr<Layer> l0( |
1177 gfx::Rect(0, 0, 50, 50))); | 1177 CreateColorLayer(SK_ColorRED, gfx::Rect(0, 0, 50, 50))); |
1178 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, | 1178 std::unique_ptr<Layer> l11( |
1179 gfx::Rect(0, 0, 25, 25))); | 1179 CreateColorLayer(SK_ColorGREEN, gfx::Rect(0, 0, 25, 25))); |
1180 scoped_ptr<Layer> l21(CreateColorLayer(SK_ColorMAGENTA, | 1180 std::unique_ptr<Layer> l21( |
1181 gfx::Rect(0, 0, 15, 15))); | 1181 CreateColorLayer(SK_ColorMAGENTA, gfx::Rect(0, 0, 15, 15))); |
1182 scoped_ptr<Layer> l12(CreateColorLayer(SK_ColorBLUE, | 1182 std::unique_ptr<Layer> l12( |
1183 gfx::Rect(10, 10, 25, 25))); | 1183 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 25, 25))); |
1184 | 1184 |
1185 base::FilePath ref_img1 = | 1185 base::FilePath ref_img1 = |
1186 test_data_directory().AppendASCII("ModifyHierarchy1.png"); | 1186 test_data_directory().AppendASCII("ModifyHierarchy1.png"); |
1187 base::FilePath ref_img2 = | 1187 base::FilePath ref_img2 = |
1188 test_data_directory().AppendASCII("ModifyHierarchy2.png"); | 1188 test_data_directory().AppendASCII("ModifyHierarchy2.png"); |
1189 SkBitmap bitmap; | 1189 SkBitmap bitmap; |
1190 | 1190 |
1191 l0->Add(l11.get()); | 1191 l0->Add(l11.get()); |
1192 l11->Add(l21.get()); | 1192 l11->Add(l21.get()); |
1193 l0->Add(l12.get()); | 1193 l0->Add(l12.get()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); | 1233 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); |
1234 } | 1234 } |
1235 | 1235 |
1236 // Opacity is rendered correctly. | 1236 // Opacity is rendered correctly. |
1237 // Checks that modifying the hierarchy correctly affects final composite. | 1237 // Checks that modifying the hierarchy correctly affects final composite. |
1238 TEST_F(LayerWithRealCompositorTest, Opacity) { | 1238 TEST_F(LayerWithRealCompositorTest, Opacity) { |
1239 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); | 1239 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); |
1240 | 1240 |
1241 // l0 | 1241 // l0 |
1242 // +-l11 | 1242 // +-l11 |
1243 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, | 1243 std::unique_ptr<Layer> l0( |
1244 gfx::Rect(0, 0, 50, 50))); | 1244 CreateColorLayer(SK_ColorRED, gfx::Rect(0, 0, 50, 50))); |
1245 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, | 1245 std::unique_ptr<Layer> l11( |
1246 gfx::Rect(0, 0, 25, 25))); | 1246 CreateColorLayer(SK_ColorGREEN, gfx::Rect(0, 0, 25, 25))); |
1247 | 1247 |
1248 base::FilePath ref_img = test_data_directory().AppendASCII("Opacity.png"); | 1248 base::FilePath ref_img = test_data_directory().AppendASCII("Opacity.png"); |
1249 | 1249 |
1250 l11->SetOpacity(0.75); | 1250 l11->SetOpacity(0.75); |
1251 l0->Add(l11.get()); | 1251 l0->Add(l11.get()); |
1252 DrawTree(l0.get()); | 1252 DrawTree(l0.get()); |
1253 SkBitmap bitmap; | 1253 SkBitmap bitmap; |
1254 ReadPixels(&bitmap); | 1254 ReadPixels(&bitmap); |
1255 ASSERT_FALSE(bitmap.empty()); | 1255 ASSERT_FALSE(bitmap.empty()); |
1256 // WritePNGFile(bitmap, ref_img); | 1256 // WritePNGFile(bitmap, ref_img); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 gfx::Rect last_clip_rect_; | 1307 gfx::Rect last_clip_rect_; |
1308 | 1308 |
1309 DISALLOW_COPY_AND_ASSIGN(SchedulePaintLayerDelegate); | 1309 DISALLOW_COPY_AND_ASSIGN(SchedulePaintLayerDelegate); |
1310 }; | 1310 }; |
1311 | 1311 |
1312 } // namespace | 1312 } // namespace |
1313 | 1313 |
1314 // Verifies that if SchedulePaint is invoked during painting the layer is still | 1314 // Verifies that if SchedulePaint is invoked during painting the layer is still |
1315 // marked dirty. | 1315 // marked dirty. |
1316 TEST_F(LayerWithDelegateTest, SchedulePaintFromOnPaintLayer) { | 1316 TEST_F(LayerWithDelegateTest, SchedulePaintFromOnPaintLayer) { |
1317 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorRED, | 1317 std::unique_ptr<Layer> root( |
1318 gfx::Rect(0, 0, 500, 500))); | 1318 CreateColorLayer(SK_ColorRED, gfx::Rect(0, 0, 500, 500))); |
1319 SchedulePaintLayerDelegate child_delegate; | 1319 SchedulePaintLayerDelegate child_delegate; |
1320 scoped_ptr<Layer> child(CreateColorLayer(SK_ColorBLUE, | 1320 std::unique_ptr<Layer> child( |
1321 gfx::Rect(0, 0, 200, 200))); | 1321 CreateColorLayer(SK_ColorBLUE, gfx::Rect(0, 0, 200, 200))); |
1322 child_delegate.set_layer(child.get()); | 1322 child_delegate.set_layer(child.get()); |
1323 | 1323 |
1324 root->Add(child.get()); | 1324 root->Add(child.get()); |
1325 | 1325 |
1326 SchedulePaintForLayer(root.get()); | 1326 SchedulePaintForLayer(root.get()); |
1327 DrawTree(root.get()); | 1327 DrawTree(root.get()); |
1328 child->SchedulePaint(gfx::Rect(0, 0, 20, 20)); | 1328 child->SchedulePaint(gfx::Rect(0, 0, 20, 20)); |
1329 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); | 1329 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); |
1330 | 1330 |
1331 // Set a rect so that when OnPaintLayer() is invoked SchedulePaint is invoked | 1331 // Set a rect so that when OnPaintLayer() is invoked SchedulePaint is invoked |
1332 // again. | 1332 // again. |
1333 child_delegate.SetSchedulePaintRect(gfx::Rect(10, 10, 30, 30)); | 1333 child_delegate.SetSchedulePaintRect(gfx::Rect(10, 10, 30, 30)); |
1334 WaitForCommit(); | 1334 WaitForCommit(); |
1335 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); | 1335 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); |
1336 | 1336 |
1337 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should | 1337 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should |
1338 // still need to be painted. | 1338 // still need to be painted. |
1339 WaitForCommit(); | 1339 WaitForCommit(); |
1340 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); | 1340 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); |
1341 EXPECT_TRUE(child_delegate.last_clip_rect().Contains( | 1341 EXPECT_TRUE(child_delegate.last_clip_rect().Contains( |
1342 gfx::Rect(10, 10, 30, 30))); | 1342 gfx::Rect(10, 10, 30, 30))); |
1343 } | 1343 } |
1344 | 1344 |
1345 TEST_F(LayerWithRealCompositorTest, ScaleUpDown) { | 1345 TEST_F(LayerWithRealCompositorTest, ScaleUpDown) { |
1346 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, | 1346 std::unique_ptr<Layer> root( |
1347 gfx::Rect(10, 20, 200, 220))); | 1347 CreateColorLayer(SK_ColorWHITE, gfx::Rect(10, 20, 200, 220))); |
1348 TestLayerDelegate root_delegate; | 1348 TestLayerDelegate root_delegate; |
1349 root_delegate.AddColor(SK_ColorWHITE); | 1349 root_delegate.AddColor(SK_ColorWHITE); |
1350 root->set_delegate(&root_delegate); | 1350 root->set_delegate(&root_delegate); |
1351 root_delegate.set_layer_bounds(root->bounds()); | 1351 root_delegate.set_layer_bounds(root->bounds()); |
1352 | 1352 |
1353 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, | 1353 std::unique_ptr<Layer> l1( |
1354 gfx::Rect(10, 20, 140, 180))); | 1354 CreateColorLayer(SK_ColorWHITE, gfx::Rect(10, 20, 140, 180))); |
1355 TestLayerDelegate l1_delegate; | 1355 TestLayerDelegate l1_delegate; |
1356 l1_delegate.AddColor(SK_ColorWHITE); | 1356 l1_delegate.AddColor(SK_ColorWHITE); |
1357 l1->set_delegate(&l1_delegate); | 1357 l1->set_delegate(&l1_delegate); |
1358 l1_delegate.set_layer_bounds(l1->bounds()); | 1358 l1_delegate.set_layer_bounds(l1->bounds()); |
1359 | 1359 |
1360 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1360 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
1361 GetCompositor()->SetRootLayer(root.get()); | 1361 GetCompositor()->SetRootLayer(root.get()); |
1362 root->Add(l1.get()); | 1362 root->Add(l1.get()); |
1363 WaitForDraw(); | 1363 WaitForDraw(); |
1364 | 1364 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 l1_delegate.reset(); | 1404 l1_delegate.reset(); |
1405 // Just changing the size shouldn't notify the scale change nor | 1405 // Just changing the size shouldn't notify the scale change nor |
1406 // trigger repaint. | 1406 // trigger repaint. |
1407 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); | 1407 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); |
1408 // No scale change, so no scale notification. | 1408 // No scale change, so no scale notification. |
1409 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); | 1409 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); |
1410 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1410 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
1411 } | 1411 } |
1412 | 1412 |
1413 TEST_F(LayerWithRealCompositorTest, ScaleReparent) { | 1413 TEST_F(LayerWithRealCompositorTest, ScaleReparent) { |
1414 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, | 1414 std::unique_ptr<Layer> root( |
1415 gfx::Rect(10, 20, 200, 220))); | 1415 CreateColorLayer(SK_ColorWHITE, gfx::Rect(10, 20, 200, 220))); |
1416 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, | 1416 std::unique_ptr<Layer> l1( |
1417 gfx::Rect(10, 20, 140, 180))); | 1417 CreateColorLayer(SK_ColorWHITE, gfx::Rect(10, 20, 140, 180))); |
1418 TestLayerDelegate l1_delegate; | 1418 TestLayerDelegate l1_delegate; |
1419 l1_delegate.AddColor(SK_ColorWHITE); | 1419 l1_delegate.AddColor(SK_ColorWHITE); |
1420 l1->set_delegate(&l1_delegate); | 1420 l1->set_delegate(&l1_delegate); |
1421 l1_delegate.set_layer_bounds(l1->bounds()); | 1421 l1_delegate.set_layer_bounds(l1->bounds()); |
1422 | 1422 |
1423 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1423 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
1424 GetCompositor()->SetRootLayer(root.get()); | 1424 GetCompositor()->SetRootLayer(root.get()); |
1425 | 1425 |
1426 root->Add(l1.get()); | 1426 root->Add(l1.get()); |
1427 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1427 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
(...skipping 16 matching lines...) Expand all Loading... |
1444 cc_bounds_size = l1->cc_layer_for_testing()->bounds(); | 1444 cc_bounds_size = l1->cc_layer_for_testing()->bounds(); |
1445 EXPECT_EQ("140x180", cc_bounds_size.ToString()); | 1445 EXPECT_EQ("140x180", cc_bounds_size.ToString()); |
1446 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); | 1446 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
1447 } | 1447 } |
1448 | 1448 |
1449 // Verifies that when changing bounds on a layer that is invisible, and then | 1449 // Verifies that when changing bounds on a layer that is invisible, and then |
1450 // made visible, the right thing happens: | 1450 // made visible, the right thing happens: |
1451 // - if just a move, then no painting should happen. | 1451 // - if just a move, then no painting should happen. |
1452 // - if a resize, the layer should be repainted. | 1452 // - if a resize, the layer should be repainted. |
1453 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { | 1453 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { |
1454 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1454 std::unique_ptr<Layer> root( |
| 1455 CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); |
1455 | 1456 |
1456 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1457 std::unique_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); |
1457 child->SetBounds(gfx::Rect(0, 0, 500, 500)); | 1458 child->SetBounds(gfx::Rect(0, 0, 500, 500)); |
1458 DrawTreeLayerDelegate delegate(child->bounds()); | 1459 DrawTreeLayerDelegate delegate(child->bounds()); |
1459 child->set_delegate(&delegate); | 1460 child->set_delegate(&delegate); |
1460 root->Add(child.get()); | 1461 root->Add(child.get()); |
1461 | 1462 |
1462 // Paint once for initial damage. | 1463 // Paint once for initial damage. |
1463 child->SetVisible(true); | 1464 child->SetVisible(true); |
1464 DrawTree(root.get()); | 1465 DrawTree(root.get()); |
1465 | 1466 |
1466 // Reset into invisible state. | 1467 // Reset into invisible state. |
(...skipping 21 matching lines...) Expand all Loading... |
1488 | 1489 |
1489 namespace { | 1490 namespace { |
1490 | 1491 |
1491 void FakeSatisfyCallback(cc::SurfaceSequence) {} | 1492 void FakeSatisfyCallback(cc::SurfaceSequence) {} |
1492 | 1493 |
1493 void FakeRequireCallback(cc::SurfaceId, cc::SurfaceSequence) {} | 1494 void FakeRequireCallback(cc::SurfaceId, cc::SurfaceSequence) {} |
1494 | 1495 |
1495 } // namespace | 1496 } // namespace |
1496 | 1497 |
1497 TEST_F(LayerWithDelegateTest, ExternalContent) { | 1498 TEST_F(LayerWithDelegateTest, ExternalContent) { |
1498 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1499 std::unique_ptr<Layer> root( |
1499 scoped_ptr<Layer> child(CreateLayer(LAYER_SOLID_COLOR)); | 1500 CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); |
| 1501 std::unique_ptr<Layer> child(CreateLayer(LAYER_SOLID_COLOR)); |
1500 | 1502 |
1501 child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1503 child->SetBounds(gfx::Rect(0, 0, 10, 10)); |
1502 child->SetVisible(true); | 1504 child->SetVisible(true); |
1503 root->Add(child.get()); | 1505 root->Add(child.get()); |
1504 | 1506 |
1505 // The layer is already showing solid color content, so the cc layer won't | 1507 // The layer is already showing solid color content, so the cc layer won't |
1506 // change. | 1508 // change. |
1507 scoped_refptr<cc::Layer> before = child->cc_layer_for_testing(); | 1509 scoped_refptr<cc::Layer> before = child->cc_layer_for_testing(); |
1508 child->SetShowSolidColorContent(); | 1510 child->SetShowSolidColorContent(); |
1509 EXPECT_TRUE(child->cc_layer_for_testing()); | 1511 EXPECT_TRUE(child->cc_layer_for_testing()); |
(...skipping 10 matching lines...) Expand all Loading... |
1520 // Changing to painted content should change the underlying cc layer. | 1522 // Changing to painted content should change the underlying cc layer. |
1521 before = child->cc_layer_for_testing(); | 1523 before = child->cc_layer_for_testing(); |
1522 child->SetShowSolidColorContent(); | 1524 child->SetShowSolidColorContent(); |
1523 EXPECT_TRUE(child->cc_layer_for_testing()); | 1525 EXPECT_TRUE(child->cc_layer_for_testing()); |
1524 EXPECT_NE(before.get(), child->cc_layer_for_testing()); | 1526 EXPECT_NE(before.get(), child->cc_layer_for_testing()); |
1525 } | 1527 } |
1526 | 1528 |
1527 // Verifies that layer filters still attached after changing implementation | 1529 // Verifies that layer filters still attached after changing implementation |
1528 // layer. | 1530 // layer. |
1529 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { | 1531 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { |
1530 scoped_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED)); | 1532 std::unique_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED)); |
1531 layer->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1533 layer->SetBounds(gfx::Rect(0, 0, 10, 10)); |
1532 EXPECT_TRUE(layer->cc_layer_for_testing()); | 1534 EXPECT_TRUE(layer->cc_layer_for_testing()); |
1533 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size()); | 1535 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size()); |
1534 | 1536 |
1535 layer->SetLayerGrayscale(0.5f); | 1537 layer->SetLayerGrayscale(0.5f); |
1536 EXPECT_EQ(layer->layer_grayscale(), 0.5f); | 1538 EXPECT_EQ(layer->layer_grayscale(), 0.5f); |
1537 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); | 1539 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); |
1538 | 1540 |
1539 // Showing surface content changes the underlying cc layer. | 1541 // Showing surface content changes the underlying cc layer. |
1540 scoped_refptr<cc::Layer> before = layer->cc_layer_for_testing(); | 1542 scoped_refptr<cc::Layer> before = layer->cc_layer_for_testing(); |
1541 layer->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), | 1543 layer->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), |
1542 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), | 1544 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), |
1543 1.0, gfx::Size(10, 10)); | 1545 1.0, gfx::Size(10, 10)); |
1544 EXPECT_EQ(layer->layer_grayscale(), 0.5f); | 1546 EXPECT_EQ(layer->layer_grayscale(), 0.5f); |
1545 EXPECT_TRUE(layer->cc_layer_for_testing()); | 1547 EXPECT_TRUE(layer->cc_layer_for_testing()); |
1546 EXPECT_NE(before.get(), layer->cc_layer_for_testing()); | 1548 EXPECT_NE(before.get(), layer->cc_layer_for_testing()); |
1547 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); | 1549 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); |
1548 } | 1550 } |
1549 | 1551 |
1550 // Tests Layer::AddThreadedAnimation and Layer::RemoveThreadedAnimation. | 1552 // Tests Layer::AddThreadedAnimation and Layer::RemoveThreadedAnimation. |
1551 TEST_F(LayerWithRealCompositorTest, AddRemoveThreadedAnimations) { | 1553 TEST_F(LayerWithRealCompositorTest, AddRemoveThreadedAnimations) { |
1552 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1554 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1553 scoped_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); | 1555 std::unique_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); |
1554 scoped_ptr<Layer> l2(CreateLayer(LAYER_TEXTURED)); | 1556 std::unique_ptr<Layer> l2(CreateLayer(LAYER_TEXTURED)); |
1555 | 1557 |
1556 l1->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1558 l1->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1557 l2->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1559 l2->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1558 | 1560 |
1559 EXPECT_FALSE(l1->HasPendingThreadedAnimationsForTesting()); | 1561 EXPECT_FALSE(l1->HasPendingThreadedAnimationsForTesting()); |
1560 | 1562 |
1561 // Trigger a threaded animation. | 1563 // Trigger a threaded animation. |
1562 l1->SetOpacity(0.5f); | 1564 l1->SetOpacity(0.5f); |
1563 | 1565 |
1564 EXPECT_TRUE(l1->HasPendingThreadedAnimationsForTesting()); | 1566 EXPECT_TRUE(l1->HasPendingThreadedAnimationsForTesting()); |
(...skipping 24 matching lines...) Expand all Loading... |
1589 l2->SetOpacity(0.5f); | 1591 l2->SetOpacity(0.5f); |
1590 EXPECT_TRUE(l2->HasPendingThreadedAnimationsForTesting()); | 1592 EXPECT_TRUE(l2->HasPendingThreadedAnimationsForTesting()); |
1591 | 1593 |
1592 l1->Add(l2.get()); | 1594 l1->Add(l2.get()); |
1593 EXPECT_FALSE(l2->HasPendingThreadedAnimationsForTesting()); | 1595 EXPECT_FALSE(l2->HasPendingThreadedAnimationsForTesting()); |
1594 } | 1596 } |
1595 | 1597 |
1596 // Tests that in-progress threaded animations complete when a Layer's | 1598 // Tests that in-progress threaded animations complete when a Layer's |
1597 // cc::Layer changes. | 1599 // cc::Layer changes. |
1598 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerAnimations) { | 1600 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerAnimations) { |
1599 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1601 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1600 scoped_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); | 1602 std::unique_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); |
1601 GetCompositor()->SetRootLayer(root.get()); | 1603 GetCompositor()->SetRootLayer(root.get()); |
1602 root->Add(l1.get()); | 1604 root->Add(l1.get()); |
1603 | 1605 |
1604 l1->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1606 l1->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1605 | 1607 |
1606 EXPECT_FLOAT_EQ(l1->opacity(), 1.0f); | 1608 EXPECT_FLOAT_EQ(l1->opacity(), 1.0f); |
1607 | 1609 |
1608 // Trigger a threaded animation. | 1610 // Trigger a threaded animation. |
1609 l1->SetOpacity(0.5f); | 1611 l1->SetOpacity(0.5f); |
1610 | 1612 |
1611 // Change l1's cc::Layer. | 1613 // Change l1's cc::Layer. |
1612 l1->SwitchCCLayerForTest(); | 1614 l1->SwitchCCLayerForTest(); |
1613 | 1615 |
1614 // Ensure that the opacity animation completed. | 1616 // Ensure that the opacity animation completed. |
1615 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); | 1617 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); |
1616 } | 1618 } |
1617 | 1619 |
1618 // Tests that when a LAYER_SOLID_COLOR has its CC layer switched, that | 1620 // Tests that when a LAYER_SOLID_COLOR has its CC layer switched, that |
1619 // opaqueness and color set while not animating, are maintained. | 1621 // opaqueness and color set while not animating, are maintained. |
1620 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerSolidColorNotAnimating) { | 1622 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerSolidColorNotAnimating) { |
1621 SkColor transparent = SK_ColorTRANSPARENT; | 1623 SkColor transparent = SK_ColorTRANSPARENT; |
1622 scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); | 1624 std::unique_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); |
1623 GetCompositor()->SetRootLayer(root.get()); | 1625 GetCompositor()->SetRootLayer(root.get()); |
1624 root->SetFillsBoundsOpaquely(false); | 1626 root->SetFillsBoundsOpaquely(false); |
1625 root->SetColor(transparent); | 1627 root->SetColor(transparent); |
1626 | 1628 |
1627 EXPECT_FALSE(root->fills_bounds_opaquely()); | 1629 EXPECT_FALSE(root->fills_bounds_opaquely()); |
1628 EXPECT_FALSE( | 1630 EXPECT_FALSE( |
1629 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); | 1631 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); |
1630 EXPECT_EQ(transparent, root->background_color()); | 1632 EXPECT_EQ(transparent, root->background_color()); |
1631 EXPECT_EQ(transparent, root->GetTargetColor()); | 1633 EXPECT_EQ(transparent, root->GetTargetColor()); |
1632 | 1634 |
1633 // Changing the underlying layer should not affect targets. | 1635 // Changing the underlying layer should not affect targets. |
1634 root->SwitchCCLayerForTest(); | 1636 root->SwitchCCLayerForTest(); |
1635 | 1637 |
1636 EXPECT_FALSE(root->fills_bounds_opaquely()); | 1638 EXPECT_FALSE(root->fills_bounds_opaquely()); |
1637 EXPECT_FALSE( | 1639 EXPECT_FALSE( |
1638 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); | 1640 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); |
1639 EXPECT_EQ(transparent, root->background_color()); | 1641 EXPECT_EQ(transparent, root->background_color()); |
1640 EXPECT_EQ(transparent, root->GetTargetColor()); | 1642 EXPECT_EQ(transparent, root->GetTargetColor()); |
1641 } | 1643 } |
1642 | 1644 |
1643 // Tests that when a LAYER_SOLID_COLOR has its CC layer switched during an | 1645 // Tests that when a LAYER_SOLID_COLOR has its CC layer switched during an |
1644 // animation of its opaquness and color, that both the current values, and the | 1646 // animation of its opaquness and color, that both the current values, and the |
1645 // targets are maintained. | 1647 // targets are maintained. |
1646 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerSolidColorWhileAnimating) { | 1648 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerSolidColorWhileAnimating) { |
1647 SkColor transparent = SK_ColorTRANSPARENT; | 1649 SkColor transparent = SK_ColorTRANSPARENT; |
1648 scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); | 1650 std::unique_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); |
1649 GetCompositor()->SetRootLayer(root.get()); | 1651 GetCompositor()->SetRootLayer(root.get()); |
1650 root->SetColor(SK_ColorBLACK); | 1652 root->SetColor(SK_ColorBLACK); |
1651 | 1653 |
1652 EXPECT_TRUE(root->fills_bounds_opaquely()); | 1654 EXPECT_TRUE(root->fills_bounds_opaquely()); |
1653 EXPECT_EQ(SK_ColorBLACK, root->GetTargetColor()); | 1655 EXPECT_EQ(SK_ColorBLACK, root->GetTargetColor()); |
1654 | 1656 |
1655 scoped_ptr<ui::ScopedAnimationDurationScaleMode> long_duration_animation( | 1657 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> long_duration_animation( |
1656 new ui::ScopedAnimationDurationScaleMode( | 1658 new ui::ScopedAnimationDurationScaleMode( |
1657 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | 1659 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); |
1658 { | 1660 { |
1659 ui::ScopedLayerAnimationSettings animation(root->GetAnimator()); | 1661 ui::ScopedLayerAnimationSettings animation(root->GetAnimator()); |
1660 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | 1662 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); |
1661 root->SetFillsBoundsOpaquely(false); | 1663 root->SetFillsBoundsOpaquely(false); |
1662 root->SetColor(transparent); | 1664 root->SetColor(transparent); |
1663 } | 1665 } |
1664 | 1666 |
1665 EXPECT_TRUE(root->fills_bounds_opaquely()); | 1667 EXPECT_TRUE(root->fills_bounds_opaquely()); |
(...skipping 16 matching lines...) Expand all Loading... |
1682 EXPECT_FALSE(root->fills_bounds_opaquely()); | 1684 EXPECT_FALSE(root->fills_bounds_opaquely()); |
1683 EXPECT_FALSE( | 1685 EXPECT_FALSE( |
1684 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); | 1686 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); |
1685 EXPECT_EQ(transparent, root->background_color()); | 1687 EXPECT_EQ(transparent, root->background_color()); |
1686 EXPECT_EQ(transparent, root->GetTargetColor()); | 1688 EXPECT_EQ(transparent, root->GetTargetColor()); |
1687 } | 1689 } |
1688 | 1690 |
1689 // Tests that the animators in the layer tree is added to the | 1691 // Tests that the animators in the layer tree is added to the |
1690 // animator-collection when the root-layer is set to the compositor. | 1692 // animator-collection when the root-layer is set to the compositor. |
1691 TEST_F(LayerWithDelegateTest, RootLayerAnimatorsInCompositor) { | 1693 TEST_F(LayerWithDelegateTest, RootLayerAnimatorsInCompositor) { |
1692 scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); | 1694 std::unique_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); |
1693 scoped_ptr<Layer> child(CreateColorLayer(SK_ColorRED, gfx::Rect(10, 10))); | 1695 std::unique_ptr<Layer> child( |
| 1696 CreateColorLayer(SK_ColorRED, gfx::Rect(10, 10))); |
1694 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1697 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1695 child->SetOpacity(0.5f); | 1698 child->SetOpacity(0.5f); |
1696 root->Add(child.get()); | 1699 root->Add(child.get()); |
1697 | 1700 |
1698 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1701 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
1699 compositor()->SetRootLayer(root.get()); | 1702 compositor()->SetRootLayer(root.get()); |
1700 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1703 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
1701 } | 1704 } |
1702 | 1705 |
1703 // Tests that adding/removing a layer adds/removes the animator from its entire | 1706 // Tests that adding/removing a layer adds/removes the animator from its entire |
1704 // subtree from the compositor's animator-collection. | 1707 // subtree from the compositor's animator-collection. |
1705 TEST_F(LayerWithDelegateTest, AddRemoveLayerUpdatesAnimatorsFromSubtree) { | 1708 TEST_F(LayerWithDelegateTest, AddRemoveLayerUpdatesAnimatorsFromSubtree) { |
1706 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1709 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1707 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1710 std::unique_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); |
1708 scoped_ptr<Layer> grandchild(CreateColorLayer(SK_ColorRED, | 1711 std::unique_ptr<Layer> grandchild( |
1709 gfx::Rect(10, 10))); | 1712 CreateColorLayer(SK_ColorRED, gfx::Rect(10, 10))); |
1710 root->Add(child.get()); | 1713 root->Add(child.get()); |
1711 child->Add(grandchild.get()); | 1714 child->Add(grandchild.get()); |
1712 compositor()->SetRootLayer(root.get()); | 1715 compositor()->SetRootLayer(root.get()); |
1713 | 1716 |
1714 grandchild->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1717 grandchild->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1715 grandchild->SetOpacity(0.5f); | 1718 grandchild->SetOpacity(0.5f); |
1716 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1719 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
1717 | 1720 |
1718 root->Remove(child.get()); | 1721 root->Remove(child.get()); |
1719 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1722 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
1720 | 1723 |
1721 root->Add(child.get()); | 1724 root->Add(child.get()); |
1722 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1725 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
1723 } | 1726 } |
1724 | 1727 |
1725 TEST_F(LayerWithDelegateTest, DestroyingLayerRemovesTheAnimatorFromCollection) { | 1728 TEST_F(LayerWithDelegateTest, DestroyingLayerRemovesTheAnimatorFromCollection) { |
1726 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1729 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1727 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1730 std::unique_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); |
1728 root->Add(child.get()); | 1731 root->Add(child.get()); |
1729 compositor()->SetRootLayer(root.get()); | 1732 compositor()->SetRootLayer(root.get()); |
1730 | 1733 |
1731 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1734 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1732 child->SetOpacity(0.5f); | 1735 child->SetOpacity(0.5f); |
1733 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1736 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
1734 | 1737 |
1735 child.reset(); | 1738 child.reset(); |
1736 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1739 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
1737 } | 1740 } |
(...skipping 19 matching lines...) Expand all Loading... |
1757 private: | 1760 private: |
1758 Layer* root_; | 1761 Layer* root_; |
1759 Layer* child_; | 1762 Layer* child_; |
1760 | 1763 |
1761 DISALLOW_COPY_AND_ASSIGN(LayerRemovingLayerAnimationObserver); | 1764 DISALLOW_COPY_AND_ASSIGN(LayerRemovingLayerAnimationObserver); |
1762 }; | 1765 }; |
1763 | 1766 |
1764 // Verifies that empty LayerAnimators are not left behind when removing child | 1767 // Verifies that empty LayerAnimators are not left behind when removing child |
1765 // Layers that own an empty LayerAnimator. See http://crbug.com/552037. | 1768 // Layers that own an empty LayerAnimator. See http://crbug.com/552037. |
1766 TEST_F(LayerWithDelegateTest, NonAnimatingAnimatorsAreRemovedFromCollection) { | 1769 TEST_F(LayerWithDelegateTest, NonAnimatingAnimatorsAreRemovedFromCollection) { |
1767 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1770 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1768 scoped_ptr<Layer> parent(CreateLayer(LAYER_TEXTURED)); | 1771 std::unique_ptr<Layer> parent(CreateLayer(LAYER_TEXTURED)); |
1769 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); | 1772 std::unique_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); |
1770 root->Add(parent.get()); | 1773 root->Add(parent.get()); |
1771 parent->Add(child.get()); | 1774 parent->Add(child.get()); |
1772 compositor()->SetRootLayer(root.get()); | 1775 compositor()->SetRootLayer(root.get()); |
1773 | 1776 |
1774 child->SetAnimator(LayerAnimator::CreateDefaultAnimator()); | 1777 child->SetAnimator(LayerAnimator::CreateDefaultAnimator()); |
1775 | 1778 |
1776 LayerRemovingLayerAnimationObserver observer(root.get(), parent.get()); | 1779 LayerRemovingLayerAnimationObserver observer(root.get(), parent.get()); |
1777 child->GetAnimator()->AddObserver(&observer); | 1780 child->GetAnimator()->AddObserver(&observer); |
1778 | 1781 |
1779 LayerAnimationElement* element = | 1782 LayerAnimationElement* element = |
(...skipping 11 matching lines...) Expand all Loading... |
1791 | 1794 |
1792 namespace { | 1795 namespace { |
1793 | 1796 |
1794 std::string Vector2dFTo100thPercisionString(const gfx::Vector2dF& vector) { | 1797 std::string Vector2dFTo100thPercisionString(const gfx::Vector2dF& vector) { |
1795 return base::StringPrintf("%.2f %0.2f", vector.x(), vector.y()); | 1798 return base::StringPrintf("%.2f %0.2f", vector.x(), vector.y()); |
1796 } | 1799 } |
1797 | 1800 |
1798 } // namespace | 1801 } // namespace |
1799 | 1802 |
1800 TEST_F(LayerWithRealCompositorTest, SnapLayerToPixels) { | 1803 TEST_F(LayerWithRealCompositorTest, SnapLayerToPixels) { |
1801 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1804 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1802 scoped_ptr<Layer> c1(CreateLayer(LAYER_TEXTURED)); | 1805 std::unique_ptr<Layer> c1(CreateLayer(LAYER_TEXTURED)); |
1803 scoped_ptr<Layer> c11(CreateLayer(LAYER_TEXTURED)); | 1806 std::unique_ptr<Layer> c11(CreateLayer(LAYER_TEXTURED)); |
1804 | 1807 |
1805 GetCompositor()->SetScaleAndSize(1.25f, gfx::Size(100, 100)); | 1808 GetCompositor()->SetScaleAndSize(1.25f, gfx::Size(100, 100)); |
1806 GetCompositor()->SetRootLayer(root.get()); | 1809 GetCompositor()->SetRootLayer(root.get()); |
1807 root->Add(c1.get()); | 1810 root->Add(c1.get()); |
1808 c1->Add(c11.get()); | 1811 c1->Add(c11.get()); |
1809 | 1812 |
1810 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1813 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1811 c1->SetBounds(gfx::Rect(1, 1, 10, 10)); | 1814 c1->SetBounds(gfx::Rect(1, 1, 10, 10)); |
1812 c11->SetBounds(gfx::Rect(1, 1, 10, 10)); | 1815 c11->SetBounds(gfx::Rect(1, 1, 10, 10)); |
1813 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); | 1816 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 } | 1849 } |
1847 | 1850 |
1848 private: | 1851 private: |
1849 gfx::Rect delegated_frame_damage_rect_; | 1852 gfx::Rect delegated_frame_damage_rect_; |
1850 bool delegated_frame_damage_called_; | 1853 bool delegated_frame_damage_called_; |
1851 | 1854 |
1852 DISALLOW_COPY_AND_ASSIGN(FrameDamageCheckingDelegate); | 1855 DISALLOW_COPY_AND_ASSIGN(FrameDamageCheckingDelegate); |
1853 }; | 1856 }; |
1854 | 1857 |
1855 TEST(LayerDelegateTest, DelegatedFrameDamage) { | 1858 TEST(LayerDelegateTest, DelegatedFrameDamage) { |
1856 scoped_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); | 1859 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); |
1857 gfx::Rect damage_rect(2, 1, 5, 3); | 1860 gfx::Rect damage_rect(2, 1, 5, 3); |
1858 | 1861 |
1859 FrameDamageCheckingDelegate delegate; | 1862 FrameDamageCheckingDelegate delegate; |
1860 layer->set_delegate(&delegate); | 1863 layer->set_delegate(&delegate); |
1861 layer->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), | 1864 layer->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), |
1862 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), | 1865 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), |
1863 1.0, gfx::Size(10, 10)); | 1866 1.0, gfx::Size(10, 10)); |
1864 | 1867 |
1865 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 1868 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
1866 layer->OnDelegatedFrameDamage(damage_rect); | 1869 layer->OnDelegatedFrameDamage(damage_rect); |
1867 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 1870 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
1868 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 1871 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
1869 } | 1872 } |
1870 | 1873 |
1871 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { | 1874 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { |
1872 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1875 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1873 | 1876 |
1874 root->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1877 root->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1875 | 1878 |
1876 TestCompositorAnimationObserver animation_observer(GetCompositor()); | 1879 TestCompositorAnimationObserver animation_observer(GetCompositor()); |
1877 EXPECT_EQ(0u, animation_observer.animation_step_count()); | 1880 EXPECT_EQ(0u, animation_observer.animation_step_count()); |
1878 | 1881 |
1879 root->SetOpacity(0.5f); | 1882 root->SetOpacity(0.5f); |
1880 WaitForSwap(); | 1883 WaitForSwap(); |
1881 EXPECT_EQ(1u, animation_observer.animation_step_count()); | 1884 EXPECT_EQ(1u, animation_observer.animation_step_count()); |
1882 | 1885 |
1883 EXPECT_FALSE(animation_observer.shutdown()); | 1886 EXPECT_FALSE(animation_observer.shutdown()); |
1884 ResetCompositor(); | 1887 ResetCompositor(); |
1885 EXPECT_TRUE(animation_observer.shutdown()); | 1888 EXPECT_TRUE(animation_observer.shutdown()); |
1886 } | 1889 } |
1887 | 1890 |
1888 } // namespace ui | 1891 } // namespace ui |
OLD | NEW |