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 18 matching lines...) Expand all Loading... | |
29 #include "ui/compositor/layer_animator.h" | 29 #include "ui/compositor/layer_animator.h" |
30 #include "ui/compositor/test/context_factories_for_test.h" | 30 #include "ui/compositor/test/context_factories_for_test.h" |
31 #include "ui/compositor/test/draw_waiter_for_test.h" | 31 #include "ui/compositor/test/draw_waiter_for_test.h" |
32 #include "ui/compositor/test/test_compositor_host.h" | 32 #include "ui/compositor/test/test_compositor_host.h" |
33 #include "ui/compositor/test/test_layers.h" | 33 #include "ui/compositor/test/test_layers.h" |
34 #include "ui/gfx/canvas.h" | 34 #include "ui/gfx/canvas.h" |
35 #include "ui/gfx/codec/png_codec.h" | 35 #include "ui/gfx/codec/png_codec.h" |
36 #include "ui/gfx/gfx_paths.h" | 36 #include "ui/gfx/gfx_paths.h" |
37 #include "ui/gfx/skia_util.h" | 37 #include "ui/gfx/skia_util.h" |
38 | 38 |
39 #if defined(OS_WIN) | |
40 #include "ui/base/win/shell.h" | |
41 #endif | |
42 | |
39 using cc::MatchesPNGFile; | 43 using cc::MatchesPNGFile; |
40 | 44 |
41 namespace ui { | 45 namespace ui { |
42 | 46 |
43 namespace { | 47 namespace { |
44 | 48 |
45 // There are three test classes in here that configure the Compositor and | 49 // There are three test classes in here that configure the Compositor and |
46 // Layer's slightly differently: | 50 // Layer's slightly differently: |
47 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This | 51 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This |
48 // is typically the base class you want to use. | 52 // is typically the base class you want to use. |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
878 << SkColorGetA(actual_color) << "); " | 882 << SkColorGetA(actual_color) << "); " |
879 << "expected RGBA=(" | 883 << "expected RGBA=(" |
880 << SkColorGetR(expected_color) << "," | 884 << SkColorGetR(expected_color) << "," |
881 << SkColorGetG(expected_color) << "," | 885 << SkColorGetG(expected_color) << "," |
882 << SkColorGetB(expected_color) << "," | 886 << SkColorGetB(expected_color) << "," |
883 << SkColorGetA(expected_color) << ")"; | 887 << SkColorGetA(expected_color) << ")"; |
884 } | 888 } |
885 } | 889 } |
886 } | 890 } |
887 | 891 |
892 // Checks that pixels are actually drawn to the screen with a read back. | |
danakj
2014/08/25 17:17:37
This test is checking something about filters, not
garykac
2014/08/26 01:44:38
Done.
| |
893 TEST_F(LayerWithRealCompositorTest, DrawAlphaThresholdFilterPixels) { | |
894 gfx::Size viewport_size = GetCompositor()->size(); | |
895 | |
896 // The window should be some non-trivial size but may not be exactly | |
danakj
2014/08/25 17:17:37
drop this copy pasta
garykac
2014/08/26 01:44:38
Done.
| |
897 // 500x500 on all platforms/bots. | |
898 int test_size = 200; | |
899 EXPECT_GE(viewport_size.width(), test_size); | |
900 EXPECT_GE(viewport_size.height(), test_size); | |
901 | |
902 int blue_height = 10; | |
903 // Blue with a wee bit of transparency. | |
904 SkColor bluish = SkColorSetARGBInline(40, 0, 0, 255); | |
905 | |
906 bool alpha_blend = false; | |
907 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | |
danakj
2014/08/25 17:17:37
use_aura is always true in this test file, no?
danakj
2014/08/25 17:17:37
why is alpha_blend false on chromeos?
garykac
2014/08/26 01:44:38
I would have loved for that to have been true, but
garykac
2014/08/26 01:44:38
Because the CrOS bots apparently don't alpha blend
| |
908 alpha_blend = true; | |
909 #if defined(OS_WIN) | |
910 if (!ui::win::IsAeroGlassEnabled()) { | |
danakj
2014/08/25 17:17:37
what does aero glass have to do with the composito
garykac
2014/08/26 01:44:38
https://code.google.com/p/chromium/codesearch#chro
| |
911 alpha_blend = false; | |
912 } | |
913 #endif // OS_WIN | |
914 #endif // USE_AURA && SK_SUPPORT_GPU | |
danakj
2014/08/25 17:17:37
this comment does not match your #if
garykac
2014/08/26 01:44:38
Done.
| |
915 | |
916 SkColor blue_over_red; | |
917 if (alpha_blend) { | |
918 // Transparent blue blended with red. | |
919 blue_over_red = SkColorSetARGBInline(255, 143, 143, 183); | |
920 } else { | |
921 // Transparent blue overwriting lower layer. | |
922 blue_over_red = SkColorSetARGBInline(255, 0, 0, 40); | |
923 } | |
924 | |
925 scoped_ptr<Layer> layer( | |
926 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); | |
927 scoped_ptr<Layer> layer2( | |
928 CreateColorLayer(bluish, gfx::Rect(viewport_size))); | |
929 | |
930 SkRegion shape; | |
931 shape.setRect(0, 0, viewport_size.width(), blue_height); | |
932 layer2->SetAlphaShape(make_scoped_ptr(new SkRegion(shape))); | |
933 | |
934 layer->Add(layer2.get()); | |
935 | |
936 DrawTree(layer.get()); | |
937 | |
938 SkBitmap bitmap; | |
939 ASSERT_TRUE(ReadPixels(&bitmap, gfx::Rect(viewport_size))); | |
940 ASSERT_FALSE(bitmap.empty()); | |
941 | |
942 SkAutoLockPixels lock(bitmap); | |
943 // Ignore the edge pixels since the blending can vary on some platforms. | |
944 for (int x = 1; x < test_size; x++) { | |
945 for (int y = 1; y < test_size; y++) { | |
946 SkColor actual_color = bitmap.getColor(x, y); | |
947 SkColor expected_color = y < blue_height ? blue_over_red : SK_ColorRED; | |
948 EXPECT_EQ(expected_color, actual_color) | |
949 << "Pixel error at x=" << x << " y=" << y << "; " | |
950 << "actual RGBA=(" | |
951 << SkColorGetR(actual_color) << "," | |
952 << SkColorGetG(actual_color) << "," | |
953 << SkColorGetB(actual_color) << "," | |
954 << SkColorGetA(actual_color) << "); " | |
955 << "expected RGBA=(" | |
956 << SkColorGetR(expected_color) << "," | |
957 << SkColorGetG(expected_color) << "," | |
958 << SkColorGetB(expected_color) << "," | |
959 << SkColorGetA(expected_color) << ")"; | |
960 } | |
961 } | |
962 } | |
963 | |
888 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. | 964 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. |
889 TEST_F(LayerWithRealCompositorTest, SetRootLayer) { | 965 TEST_F(LayerWithRealCompositorTest, SetRootLayer) { |
890 Compositor* compositor = GetCompositor(); | 966 Compositor* compositor = GetCompositor(); |
891 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 967 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
892 gfx::Rect(20, 20, 400, 400))); | 968 gfx::Rect(20, 20, 400, 400))); |
893 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 969 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
894 gfx::Rect(10, 10, 350, 350))); | 970 gfx::Rect(10, 10, 350, 350))); |
895 | 971 |
896 EXPECT_EQ(NULL, l1->GetCompositor()); | 972 EXPECT_EQ(NULL, l1->GetCompositor()); |
897 EXPECT_EQ(NULL, l2->GetCompositor()); | 973 EXPECT_EQ(NULL, l2->GetCompositor()); |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1585 | 1661 |
1586 c11->SetBounds(gfx::Rect(2, 2, 10, 10)); | 1662 c11->SetBounds(gfx::Rect(2, 2, 10, 10)); |
1587 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); | 1663 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); |
1588 // c11 is now off the pixel. | 1664 // c11 is now off the pixel. |
1589 // 0.5 / 1.5 = 0.333... | 1665 // 0.5 / 1.5 = 0.333... |
1590 EXPECT_EQ("0.33 0.33", | 1666 EXPECT_EQ("0.33 0.33", |
1591 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); | 1667 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); |
1592 } | 1668 } |
1593 | 1669 |
1594 } // namespace ui | 1670 } // namespace ui |
OLD | NEW |