Chromium Code Reviews| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 | 840 |
| 841 // The CompositorDelegate (us) should have been told to draw for a move. | 841 // The CompositorDelegate (us) should have been told to draw for a move. |
| 842 WaitForDraw(); | 842 WaitForDraw(); |
| 843 | 843 |
| 844 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); | 844 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); |
| 845 | 845 |
| 846 // The CompositorDelegate (us) should have been told to draw for a resize. | 846 // The CompositorDelegate (us) should have been told to draw for a resize. |
| 847 WaitForDraw(); | 847 WaitForDraw(); |
| 848 } | 848 } |
| 849 | 849 |
| 850 void ExpectRgba(int x, int y, SkColor actual_color, SkColor expected_color) { | |
|
danakj
2014/09/03 19:39:05
please pass expected first, to match EXPECT_EQ ord
| |
| 851 EXPECT_EQ(expected_color, actual_color) | |
| 852 << "Pixel error at x=" << x << " y=" << y << "; " | |
| 853 << "actual RGBA=(" | |
| 854 << SkColorGetR(actual_color) << "," | |
| 855 << SkColorGetG(actual_color) << "," | |
| 856 << SkColorGetB(actual_color) << "," | |
| 857 << SkColorGetA(actual_color) << "); " | |
| 858 << "expected RGBA=(" | |
| 859 << SkColorGetR(expected_color) << "," | |
| 860 << SkColorGetG(expected_color) << "," | |
| 861 << SkColorGetB(expected_color) << "," | |
| 862 << SkColorGetA(expected_color) << ")"; | |
| 863 } | |
| 864 | |
| 850 // Checks that pixels are actually drawn to the screen with a read back. | 865 // Checks that pixels are actually drawn to the screen with a read back. |
| 851 TEST_F(LayerWithRealCompositorTest, DrawPixels) { | 866 TEST_F(LayerWithRealCompositorTest, DrawPixels) { |
| 852 gfx::Size viewport_size = GetCompositor()->size(); | 867 gfx::Size viewport_size = GetCompositor()->size(); |
| 853 | 868 |
| 854 // The window should be some non-trivial size but may not be exactly | 869 // The window should be some non-trivial size but may not be exactly |
| 855 // 500x500 on all platforms/bots. | 870 // 500x500 on all platforms/bots. |
| 856 EXPECT_GE(viewport_size.width(), 200); | 871 EXPECT_GE(viewport_size.width(), 200); |
| 857 EXPECT_GE(viewport_size.height(), 200); | 872 EXPECT_GE(viewport_size.height(), 200); |
| 858 | 873 |
| 859 int blue_height = 10; | 874 int blue_height = 10; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 870 | 885 |
| 871 SkBitmap bitmap; | 886 SkBitmap bitmap; |
| 872 ASSERT_TRUE(ReadPixels(&bitmap, gfx::Rect(viewport_size))); | 887 ASSERT_TRUE(ReadPixels(&bitmap, gfx::Rect(viewport_size))); |
| 873 ASSERT_FALSE(bitmap.empty()); | 888 ASSERT_FALSE(bitmap.empty()); |
| 874 | 889 |
| 875 SkAutoLockPixels lock(bitmap); | 890 SkAutoLockPixels lock(bitmap); |
| 876 for (int x = 0; x < viewport_size.width(); x++) { | 891 for (int x = 0; x < viewport_size.width(); x++) { |
| 877 for (int y = 0; y < viewport_size.height(); y++) { | 892 for (int y = 0; y < viewport_size.height(); y++) { |
| 878 SkColor actual_color = bitmap.getColor(x, y); | 893 SkColor actual_color = bitmap.getColor(x, y); |
| 879 SkColor expected_color = y < blue_height ? SK_ColorBLUE : SK_ColorRED; | 894 SkColor expected_color = y < blue_height ? SK_ColorBLUE : SK_ColorRED; |
| 880 EXPECT_EQ(expected_color, actual_color) | 895 ExpectRgba(x, y, actual_color, expected_color); |
| 881 << "Pixel error at x=" << x << " y=" << y << "; " | |
| 882 << "actual RGBA=(" | |
| 883 << SkColorGetR(actual_color) << "," | |
| 884 << SkColorGetG(actual_color) << "," | |
| 885 << SkColorGetB(actual_color) << "," | |
| 886 << SkColorGetA(actual_color) << "); " | |
| 887 << "expected RGBA=(" | |
| 888 << SkColorGetR(expected_color) << "," | |
| 889 << SkColorGetG(expected_color) << "," | |
| 890 << SkColorGetB(expected_color) << "," | |
| 891 << SkColorGetA(expected_color) << ")"; | |
| 892 } | 896 } |
| 893 } | 897 } |
| 894 } | 898 } |
| 899 | |
| 900 // Checks that drawing a layer with transparent pixels is blended correctly | |
| 901 // with the lower layer. | |
| 902 TEST_F(LayerWithRealCompositorTest, DrawAlphaBlendedPixels) { | |
| 903 gfx::Size viewport_size = GetCompositor()->size(); | |
| 904 | |
| 905 int test_size = 200; | |
| 906 EXPECT_GE(viewport_size.width(), test_size); | |
| 907 EXPECT_GE(viewport_size.height(), test_size); | |
| 908 | |
| 909 // Blue with a wee bit of transparency. | |
| 910 SkColor blue_with_alpha = SkColorSetARGBInline(40, 10, 20, 200); | |
| 911 SkColor blend_color = SkColorSetARGBInline(255, 216, 3, 32); | |
| 912 | |
| 913 scoped_ptr<Layer> background_layer( | |
| 914 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); | |
| 915 scoped_ptr<Layer> foreground_layer( | |
| 916 CreateColorLayer(blue_with_alpha, gfx::Rect(viewport_size))); | |
| 917 | |
| 918 // This must be set to false for layers with alpha to be blended correctly. | |
| 919 foreground_layer->SetFillsBoundsOpaquely(false); | |
| 920 | |
| 921 background_layer->Add(foreground_layer.get()); | |
| 922 DrawTree(background_layer.get()); | |
| 923 | |
| 924 SkBitmap bitmap; | |
| 925 ASSERT_TRUE(ReadPixels(&bitmap, gfx::Rect(viewport_size))); | |
| 926 ASSERT_FALSE(bitmap.empty()); | |
| 927 | |
| 928 SkAutoLockPixels lock(bitmap); | |
| 929 for (int x = 0; x < test_size; x++) { | |
| 930 for (int y = 0; y < test_size; y++) { | |
| 931 SkColor actual_color = bitmap.getColor(x, y); | |
| 932 ExpectRgba(x, y, actual_color, blend_color); | |
| 933 } | |
| 934 } | |
| 935 } | |
| 936 | |
| 937 // Checks that using the AlphaShape filter applied to a layer with | |
| 938 // transparency, alpha-blends properly with the layer below. | |
| 939 TEST_F(LayerWithRealCompositorTest, DrawAlphaThresholdFilterPixels) { | |
| 940 gfx::Size viewport_size = GetCompositor()->size(); | |
| 941 | |
| 942 int test_size = 200; | |
| 943 EXPECT_GE(viewport_size.width(), test_size); | |
| 944 EXPECT_GE(viewport_size.height(), test_size); | |
| 945 | |
| 946 int blue_height = 10; | |
| 947 SkColor blue_with_alpha = SkColorSetARGBInline(40, 0, 0, 255); | |
| 948 SkColor blend_color = SkColorSetARGBInline(255, 215, 0, 40); | |
| 949 | |
| 950 scoped_ptr<Layer> background_layer( | |
| 951 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); | |
| 952 scoped_ptr<Layer> foreground_layer( | |
| 953 CreateColorLayer(blue_with_alpha, gfx::Rect(viewport_size))); | |
| 954 | |
| 955 // Add a shape to restrict the visible part of the layer. | |
| 956 SkRegion shape; | |
| 957 shape.setRect(0, 0, viewport_size.width(), blue_height); | |
| 958 foreground_layer->SetAlphaShape(make_scoped_ptr(new SkRegion(shape))); | |
| 959 | |
| 960 foreground_layer->SetFillsBoundsOpaquely(false); | |
| 961 | |
| 962 background_layer->Add(foreground_layer.get()); | |
| 963 DrawTree(background_layer.get()); | |
| 964 | |
| 965 SkBitmap bitmap; | |
| 966 ASSERT_TRUE(ReadPixels(&bitmap, gfx::Rect(viewport_size))); | |
| 967 ASSERT_FALSE(bitmap.empty()); | |
| 968 | |
| 969 SkAutoLockPixels lock(bitmap); | |
| 970 for (int x = 0; x < test_size; x++) { | |
| 971 for (int y = 0; y < test_size; y++) { | |
| 972 SkColor actual_color = bitmap.getColor(x, y); | |
| 973 ExpectRgba(x, y, actual_color, | |
| 974 y < blue_height ? blend_color : SK_ColorRED); | |
| 975 } | |
| 976 } | |
| 977 } | |
| 895 | 978 |
| 896 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. | 979 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. |
| 897 TEST_F(LayerWithRealCompositorTest, SetRootLayer) { | 980 TEST_F(LayerWithRealCompositorTest, SetRootLayer) { |
| 898 Compositor* compositor = GetCompositor(); | 981 Compositor* compositor = GetCompositor(); |
| 899 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 982 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
| 900 gfx::Rect(20, 20, 400, 400))); | 983 gfx::Rect(20, 20, 400, 400))); |
| 901 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 984 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
| 902 gfx::Rect(10, 10, 350, 350))); | 985 gfx::Rect(10, 10, 350, 350))); |
| 903 | 986 |
| 904 EXPECT_EQ(NULL, l1->GetCompositor()); | 987 EXPECT_EQ(NULL, l1->GetCompositor()); |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1639 MakeFrameData(gfx::Size(10, 10)))); | 1722 MakeFrameData(gfx::Size(10, 10)))); |
| 1640 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); | 1723 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); |
| 1641 | 1724 |
| 1642 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 1725 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
| 1643 layer->OnDelegatedFrameDamage(damage_rect); | 1726 layer->OnDelegatedFrameDamage(damage_rect); |
| 1644 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 1727 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
| 1645 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 1728 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
| 1646 } | 1729 } |
| 1647 | 1730 |
| 1648 } // namespace ui | 1731 } // namespace ui |
| OLD | NEW |