| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <AVFoundation/AVFoundation.h> | 5 #include <AVFoundation/AVFoundation.h> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
| 9 #include "gpu/GLES2/gl2extchromium.h" | 9 #include "gpu/GLES2/gl2extchromium.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/gtest_mac.h" | 11 #include "testing/gtest_mac.h" |
| 12 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 13 #include "ui/accelerated_widget_mac/ca_renderer_layer_tree.h" | 13 #include "ui/accelerated_widget_mac/ca_renderer_layer_tree.h" |
| 14 #include "ui/gfx/geometry/dip_util.h" | 14 #include "ui/gfx/geometry/dip_util.h" |
| 15 #include "ui/gfx/mac/io_surface.h" | 15 #include "ui/gfx/mac/io_surface.h" |
| 16 #include "ui/gl/ca_renderer_layer_params.h" | 16 #include "ui/gl/ca_renderer_layer_params.h" |
| 17 #include "ui/gl/gl_image_io_surface.h" | 17 #include "ui/gl/gl_image_io_surface.h" |
| 18 | 18 |
| 19 namespace gpu { | 19 namespace gpu { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 struct CALayerProperties { | 23 struct CALayerProperties { |
| 24 CALayerProperties() {} | 24 CALayerProperties() {} |
| 25 ~CALayerProperties() { | 25 ~CALayerProperties() {} |
| 26 if (gl_image) | |
| 27 gl_image->Destroy(true); | |
| 28 } | |
| 29 | 26 |
| 30 bool is_clipped = true; | 27 bool is_clipped = true; |
| 31 gfx::Rect clip_rect; | 28 gfx::Rect clip_rect; |
| 32 int sorting_context_id = 0; | 29 int sorting_context_id = 0; |
| 33 gfx::Transform transform; | 30 gfx::Transform transform; |
| 34 gfx::RectF contents_rect = gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f); | 31 gfx::RectF contents_rect = gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f); |
| 35 gfx::Rect rect = gfx::Rect(0, 0, 256, 256); | 32 gfx::Rect rect = gfx::Rect(0, 0, 256, 256); |
| 36 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); | 33 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); |
| 37 unsigned edge_aa_mask = 0; | 34 unsigned edge_aa_mask = 0; |
| 38 float opacity = 1.0f; | 35 float opacity = 1.0f; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 258 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
| 262 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 259 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 263 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 260 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
| 264 | 261 |
| 265 // Validate the content layer. Note that top and bottom edges flip. | 262 // Validate the content layer. Note that top and bottom edges flip. |
| 266 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); | 263 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); |
| 267 } | 264 } |
| 268 | 265 |
| 269 // Change the contents and commit. | 266 // Change the contents and commit. |
| 270 { | 267 { |
| 271 properties.gl_image->Destroy(true); | |
| 272 properties.gl_image = nullptr; | 268 properties.gl_image = nullptr; |
| 273 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); | 269 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
| 274 | 270 |
| 275 // Validate the tree structure. | 271 // Validate the tree structure. |
| 276 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 272 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 277 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 273 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
| 278 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 274 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 279 EXPECT_EQ(clip_and_sorting_layer, | 275 EXPECT_EQ(clip_and_sorting_layer, |
| 280 [[root_layer sublayers] objectAtIndex:0]); | 276 [[root_layer sublayers] objectAtIndex:0]); |
| 281 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 277 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 properties.rect.origin()), | 458 properties.rect.origin()), |
| 463 gfx::Point([content_layer position])); | 459 gfx::Point([content_layer position])); |
| 464 EXPECT_EQ(gfx::ConvertRectToDIP(properties.scale_factor, | 460 EXPECT_EQ(gfx::ConvertRectToDIP(properties.scale_factor, |
| 465 gfx::Rect(properties.rect.size())), | 461 gfx::Rect(properties.rect.size())), |
| 466 gfx::Rect([content_layer bounds])); | 462 gfx::Rect([content_layer bounds])); |
| 467 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); | 463 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); |
| 468 EXPECT_EQ(properties.opacity, [content_layer opacity]); | 464 EXPECT_EQ(properties.opacity, [content_layer opacity]); |
| 469 if ([content_layer respondsToSelector:(@selector(contentsScale))]) | 465 if ([content_layer respondsToSelector:(@selector(contentsScale))]) |
| 470 EXPECT_EQ(properties.scale_factor, [content_layer contentsScale]); | 466 EXPECT_EQ(properties.scale_factor, [content_layer contentsScale]); |
| 471 } | 467 } |
| 472 | |
| 473 properties.gl_image->Destroy(true); | |
| 474 } | 468 } |
| 475 }; | 469 }; |
| 476 | 470 |
| 477 TEST_F(CALayerTreePropertyUpdatesTest, AllowSolidColors) { | 471 TEST_F(CALayerTreePropertyUpdatesTest, AllowSolidColors) { |
| 478 RunTest(true); | 472 RunTest(true); |
| 479 } | 473 } |
| 480 | 474 |
| 481 TEST_F(CALayerTreePropertyUpdatesTest, DisallowSolidColors) { | 475 TEST_F(CALayerTreePropertyUpdatesTest, DisallowSolidColors) { |
| 482 RunTest(false); | 476 RunTest(false); |
| 483 } | 477 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 EXPECT_EQ(static_cast<id>(gl_images[0]->io_surface().get()), | 556 EXPECT_EQ(static_cast<id>(gl_images[0]->io_surface().get()), |
| 563 [content_layer_0 contents]); | 557 [content_layer_0 contents]); |
| 564 EXPECT_EQ(static_cast<id>(gl_images[1]->io_surface().get()), | 558 EXPECT_EQ(static_cast<id>(gl_images[1]->io_surface().get()), |
| 565 [content_layer_1 contents]); | 559 [content_layer_1 contents]); |
| 566 EXPECT_EQ(static_cast<id>(gl_images[2]->io_surface().get()), | 560 EXPECT_EQ(static_cast<id>(gl_images[2]->io_surface().get()), |
| 567 [content_layer_2 contents]); | 561 [content_layer_2 contents]); |
| 568 EXPECT_EQ(static_cast<id>(gl_images[3]->io_surface().get()), | 562 EXPECT_EQ(static_cast<id>(gl_images[3]->io_surface().get()), |
| 569 [content_layer_3 contents]); | 563 [content_layer_3 contents]); |
| 570 EXPECT_EQ(static_cast<id>(gl_images[4]->io_surface().get()), | 564 EXPECT_EQ(static_cast<id>(gl_images[4]->io_surface().get()), |
| 571 [content_layer_4 contents]); | 565 [content_layer_4 contents]); |
| 572 | |
| 573 for (size_t i = 0; i < 5; ++i) | |
| 574 gl_images[i]->Destroy(true); | |
| 575 } | 566 } |
| 576 | 567 |
| 577 // Verify that sorting contexts are allocated appropriately. | 568 // Verify that sorting contexts are allocated appropriately. |
| 578 TEST_F(CALayerTreeTest, SortingContexts) { | 569 TEST_F(CALayerTreeTest, SortingContexts) { |
| 579 CALayerProperties properties; | 570 CALayerProperties properties; |
| 580 properties.is_clipped = false; | 571 properties.is_clipped = false; |
| 581 properties.clip_rect = gfx::Rect(); | 572 properties.clip_rect = gfx::Rect(); |
| 582 properties.rect = gfx::Rect(0, 0, 256, 256); | 573 properties.rect = gfx::Rect(0, 0, 256, 256); |
| 583 | 574 |
| 584 // We'll use the IOSurface contents to identify the content layers. | 575 // We'll use the IOSurface contents to identify the content layers. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 EXPECT_EQ(1u, [[transform_layer_2 sublayers] count]); | 622 EXPECT_EQ(1u, [[transform_layer_2 sublayers] count]); |
| 632 CALayer* content_layer_2 = [[transform_layer_2 sublayers] objectAtIndex:0]; | 623 CALayer* content_layer_2 = [[transform_layer_2 sublayers] objectAtIndex:0]; |
| 633 | 624 |
| 634 // Validate that the layers come out in order. | 625 // Validate that the layers come out in order. |
| 635 EXPECT_EQ(static_cast<id>(gl_images[0]->io_surface().get()), | 626 EXPECT_EQ(static_cast<id>(gl_images[0]->io_surface().get()), |
| 636 [content_layer_0 contents]); | 627 [content_layer_0 contents]); |
| 637 EXPECT_EQ(static_cast<id>(gl_images[1]->io_surface().get()), | 628 EXPECT_EQ(static_cast<id>(gl_images[1]->io_surface().get()), |
| 638 [content_layer_1 contents]); | 629 [content_layer_1 contents]); |
| 639 EXPECT_EQ(static_cast<id>(gl_images[2]->io_surface().get()), | 630 EXPECT_EQ(static_cast<id>(gl_images[2]->io_surface().get()), |
| 640 [content_layer_2 contents]); | 631 [content_layer_2 contents]); |
| 641 | |
| 642 for (size_t i = 0; i < 3; ++i) | |
| 643 gl_images[i]->Destroy(true); | |
| 644 } | 632 } |
| 645 | 633 |
| 646 // Verify that sorting contexts must all have the same clipping properties. | 634 // Verify that sorting contexts must all have the same clipping properties. |
| 647 TEST_F(CALayerTreeTest, SortingContextMustHaveConsistentClip) { | 635 TEST_F(CALayerTreeTest, SortingContextMustHaveConsistentClip) { |
| 648 CALayerProperties properties; | 636 CALayerProperties properties; |
| 649 | 637 |
| 650 // Vary the clipping parameters within sorting contexts. | 638 // Vary the clipping parameters within sorting contexts. |
| 651 bool is_clippeds[3] = { true, true, false}; | 639 bool is_clippeds[3] = { true, true, false}; |
| 652 gfx::Rect clip_rects[3] = { | 640 gfx::Rect clip_rects[3] = { |
| 653 gfx::Rect(0, 0, 16, 16), | 641 gfx::Rect(0, 0, 16, 16), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 705 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 718 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 706 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 719 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 707 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 720 content_layer1 = [[transform_layer sublayers] objectAtIndex:0]; | 708 content_layer1 = [[transform_layer sublayers] objectAtIndex:0]; |
| 721 | 709 |
| 722 // Validate the content layer. | 710 // Validate the content layer. |
| 723 EXPECT_FALSE([content_layer1 | 711 EXPECT_FALSE([content_layer1 |
| 724 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 712 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 725 } | 713 } |
| 726 | 714 |
| 727 properties.gl_image->Destroy(true); | |
| 728 properties.gl_image = CreateGLImage( | 715 properties.gl_image = CreateGLImage( |
| 729 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR, false); | 716 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR, false); |
| 730 | 717 |
| 731 // Pass another frame. This will automatically create a CVPixelBuffer | 718 // Pass another frame. This will automatically create a CVPixelBuffer |
| 732 // behind the scenes, because the underlying buffer is YUV 420. | 719 // behind the scenes, because the underlying buffer is YUV 420. |
| 733 { | 720 { |
| 734 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); | 721 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
| 735 | 722 |
| 736 // Validate the tree structure. | 723 // Validate the tree structure. |
| 737 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 724 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 738 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 725 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 739 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 726 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 740 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 727 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 741 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 728 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 742 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 729 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 743 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 730 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 744 content_layer2 = [[transform_layer sublayers] objectAtIndex:0]; | 731 content_layer2 = [[transform_layer sublayers] objectAtIndex:0]; |
| 745 | 732 |
| 746 // Validate the content layer. | 733 // Validate the content layer. |
| 747 EXPECT_TRUE([content_layer2 | 734 EXPECT_TRUE([content_layer2 |
| 748 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 735 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 749 EXPECT_NE(content_layer2, content_layer1); | 736 EXPECT_NE(content_layer2, content_layer1); |
| 750 } | 737 } |
| 751 | 738 |
| 752 properties.gl_image->Destroy(true); | |
| 753 properties.gl_image = CreateGLImage( | 739 properties.gl_image = CreateGLImage( |
| 754 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR, true); | 740 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR, true); |
| 755 | 741 |
| 756 // Pass a frame with a CVPixelBuffer. | 742 // Pass a frame with a CVPixelBuffer. |
| 757 { | 743 { |
| 758 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); | 744 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
| 759 | 745 |
| 760 // Validate the tree structure. | 746 // Validate the tree structure. |
| 761 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 747 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 762 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 748 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 763 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 749 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 764 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 750 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 765 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 751 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 766 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 752 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 767 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 753 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 768 content_layer3 = [[transform_layer sublayers] objectAtIndex:0]; | 754 content_layer3 = [[transform_layer sublayers] objectAtIndex:0]; |
| 769 | 755 |
| 770 // Validate the content layer. | 756 // Validate the content layer. |
| 771 EXPECT_TRUE([content_layer3 | 757 EXPECT_TRUE([content_layer3 |
| 772 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 758 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 773 EXPECT_EQ(content_layer3, content_layer2); | 759 EXPECT_EQ(content_layer3, content_layer2); |
| 774 } | 760 } |
| 775 | 761 |
| 776 properties.gl_image->Destroy(true); | |
| 777 properties.gl_image = CreateGLImage( | 762 properties.gl_image = CreateGLImage( |
| 778 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR, false); | 763 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR, false); |
| 779 | 764 |
| 780 // Pass a frame that is clipped. | 765 // Pass a frame that is clipped. |
| 781 properties.contents_rect = gfx::RectF(0, 0, 1, 0.9); | 766 properties.contents_rect = gfx::RectF(0, 0, 1, 0.9); |
| 782 { | 767 { |
| 783 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); | 768 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
| 784 | 769 |
| 785 // Validate the tree structure. | 770 // Validate the tree structure. |
| 786 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 771 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; | 973 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; |
| 989 | 974 |
| 990 // Validate the content layer and fullscreen low power mode. | 975 // Validate the content layer and fullscreen low power mode. |
| 991 EXPECT_TRUE([content_layer | 976 EXPECT_TRUE([content_layer |
| 992 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 977 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 993 EXPECT_FALSE(fullscreen_low_power_valid); | 978 EXPECT_FALSE(fullscreen_low_power_valid); |
| 994 } | 979 } |
| 995 } | 980 } |
| 996 | 981 |
| 997 } // namespace gpu | 982 } // namespace gpu |
| OLD | NEW |