| 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/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "cc/layers/layer.h" | 13 #include "cc/layers/layer.h" |
| 14 #include "cc/output/delegated_frame_data.h" | 14 #include "cc/output/delegated_frame_data.h" |
| 15 #include "cc/test/pixel_test_utils.h" | 15 #include "cc/test/pixel_test_utils.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/compositor/compositor_observer.h" | 17 #include "ui/compositor/compositor_observer.h" |
| 18 #include "ui/compositor/compositor_setup.h" | 18 #include "ui/compositor/compositor_setup.h" |
| 19 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
| 20 #include "ui/compositor/layer_animation_sequence.h" | 20 #include "ui/compositor/layer_animation_sequence.h" |
| 21 #include "ui/compositor/layer_animator.h" | 21 #include "ui/compositor/layer_animator.h" |
| 22 #include "ui/compositor/test/test_compositor_host.h" | 22 #include "ui/compositor/test/test_compositor_host.h" |
| 23 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 24 #include "ui/gfx/codec/png_codec.h" | 24 #include "ui/gfx/codec/png_codec.h" |
| 25 #include "ui/gfx/gfx_paths.h" | 25 #include "ui/gfx/gfx_paths.h" |
| 26 #include "ui/gfx/skia_util.h" | 26 #include "ui/gfx/skia_util.h" |
| 27 | 27 |
| 28 using cc::IsSameAsPNGFile; | 28 using cc::MatchesPNGFile; |
| 29 | 29 |
| 30 namespace ui { | 30 namespace ui { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Returns a comma-separated list of the names of |layer|'s children in | 34 // Returns a comma-separated list of the names of |layer|'s children in |
| 35 // bottom-to-top stacking order. | 35 // bottom-to-top stacking order. |
| 36 std::string GetLayerChildrenNames(const Layer& layer) { | 36 std::string GetLayerChildrenNames(const Layer& layer) { |
| 37 std::string names; | 37 std::string names; |
| 38 for (std::vector<Layer*>::const_iterator it = layer.children().begin(); | 38 for (std::vector<Layer*>::const_iterator it = layer.children().begin(); |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 test_data_directory().AppendASCII("ModifyHierarchy2.png"); | 912 test_data_directory().AppendASCII("ModifyHierarchy2.png"); |
| 913 SkBitmap bitmap; | 913 SkBitmap bitmap; |
| 914 | 914 |
| 915 l0->Add(l11.get()); | 915 l0->Add(l11.get()); |
| 916 l11->Add(l21.get()); | 916 l11->Add(l21.get()); |
| 917 l0->Add(l12.get()); | 917 l0->Add(l12.get()); |
| 918 DrawTree(l0.get()); | 918 DrawTree(l0.get()); |
| 919 ASSERT_TRUE(ReadPixels(&bitmap)); | 919 ASSERT_TRUE(ReadPixels(&bitmap)); |
| 920 ASSERT_FALSE(bitmap.empty()); | 920 ASSERT_FALSE(bitmap.empty()); |
| 921 // WritePNGFile(bitmap, ref_img1); | 921 // WritePNGFile(bitmap, ref_img1); |
| 922 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img1, true)); | 922 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1, cc::ExactPixelComparator(true))); |
| 923 | 923 |
| 924 l0->StackAtTop(l11.get()); | 924 l0->StackAtTop(l11.get()); |
| 925 DrawTree(l0.get()); | 925 DrawTree(l0.get()); |
| 926 ASSERT_TRUE(ReadPixels(&bitmap)); | 926 ASSERT_TRUE(ReadPixels(&bitmap)); |
| 927 ASSERT_FALSE(bitmap.empty()); | 927 ASSERT_FALSE(bitmap.empty()); |
| 928 // WritePNGFile(bitmap, ref_img2); | 928 // WritePNGFile(bitmap, ref_img2); |
| 929 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img2, true)); | 929 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); |
| 930 | 930 |
| 931 // l11 is already at the front, should have no effect. | 931 // l11 is already at the front, should have no effect. |
| 932 l0->StackAtTop(l11.get()); | 932 l0->StackAtTop(l11.get()); |
| 933 DrawTree(l0.get()); | 933 DrawTree(l0.get()); |
| 934 ASSERT_TRUE(ReadPixels(&bitmap)); | 934 ASSERT_TRUE(ReadPixels(&bitmap)); |
| 935 ASSERT_FALSE(bitmap.empty()); | 935 ASSERT_FALSE(bitmap.empty()); |
| 936 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img2, true)); | 936 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); |
| 937 | 937 |
| 938 // l11 is already at the front, should have no effect. | 938 // l11 is already at the front, should have no effect. |
| 939 l0->StackAbove(l11.get(), l12.get()); | 939 l0->StackAbove(l11.get(), l12.get()); |
| 940 DrawTree(l0.get()); | 940 DrawTree(l0.get()); |
| 941 ASSERT_TRUE(ReadPixels(&bitmap)); | 941 ASSERT_TRUE(ReadPixels(&bitmap)); |
| 942 ASSERT_FALSE(bitmap.empty()); | 942 ASSERT_FALSE(bitmap.empty()); |
| 943 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img2, true)); | 943 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); |
| 944 | 944 |
| 945 // should restore to original configuration | 945 // should restore to original configuration |
| 946 l0->StackAbove(l12.get(), l11.get()); | 946 l0->StackAbove(l12.get(), l11.get()); |
| 947 DrawTree(l0.get()); | 947 DrawTree(l0.get()); |
| 948 ASSERT_TRUE(ReadPixels(&bitmap)); | 948 ASSERT_TRUE(ReadPixels(&bitmap)); |
| 949 ASSERT_FALSE(bitmap.empty()); | 949 ASSERT_FALSE(bitmap.empty()); |
| 950 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img1, true)); | 950 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1, cc::ExactPixelComparator(true))); |
| 951 } | 951 } |
| 952 | 952 |
| 953 // Opacity is rendered correctly. | 953 // Opacity is rendered correctly. |
| 954 // Checks that modifying the hierarchy correctly affects final composite. | 954 // Checks that modifying the hierarchy correctly affects final composite. |
| 955 TEST_F(LayerWithRealCompositorTest, MAYBE_Opacity) { | 955 TEST_F(LayerWithRealCompositorTest, MAYBE_Opacity) { |
| 956 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); | 956 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); |
| 957 | 957 |
| 958 // l0 | 958 // l0 |
| 959 // +-l11 | 959 // +-l11 |
| 960 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, | 960 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, |
| 961 gfx::Rect(0, 0, 50, 50))); | 961 gfx::Rect(0, 0, 50, 50))); |
| 962 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, | 962 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, |
| 963 gfx::Rect(0, 0, 25, 25))); | 963 gfx::Rect(0, 0, 25, 25))); |
| 964 | 964 |
| 965 base::FilePath ref_img = test_data_directory().AppendASCII("Opacity.png"); | 965 base::FilePath ref_img = test_data_directory().AppendASCII("Opacity.png"); |
| 966 | 966 |
| 967 l11->SetOpacity(0.75); | 967 l11->SetOpacity(0.75); |
| 968 l0->Add(l11.get()); | 968 l0->Add(l11.get()); |
| 969 DrawTree(l0.get()); | 969 DrawTree(l0.get()); |
| 970 SkBitmap bitmap; | 970 SkBitmap bitmap; |
| 971 ASSERT_TRUE(ReadPixels(&bitmap)); | 971 ASSERT_TRUE(ReadPixels(&bitmap)); |
| 972 ASSERT_FALSE(bitmap.empty()); | 972 ASSERT_FALSE(bitmap.empty()); |
| 973 // WritePNGFile(bitmap, ref_img); | 973 // WritePNGFile(bitmap, ref_img); |
| 974 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img, true)); | 974 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img, cc::ExactPixelComparator(true))); |
| 975 } | 975 } |
| 976 | 976 |
| 977 namespace { | 977 namespace { |
| 978 | 978 |
| 979 class SchedulePaintLayerDelegate : public LayerDelegate { | 979 class SchedulePaintLayerDelegate : public LayerDelegate { |
| 980 public: | 980 public: |
| 981 SchedulePaintLayerDelegate() : paint_count_(0), layer_(NULL) {} | 981 SchedulePaintLayerDelegate() : paint_count_(0), layer_(NULL) {} |
| 982 | 982 |
| 983 virtual ~SchedulePaintLayerDelegate() {} | 983 virtual ~SchedulePaintLayerDelegate() {} |
| 984 | 984 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 l1->SetOpacity(0.5f); | 1376 l1->SetOpacity(0.5f); |
| 1377 | 1377 |
| 1378 // Change l1's cc::Layer. | 1378 // Change l1's cc::Layer. |
| 1379 l1->SwitchCCLayerForTest(); | 1379 l1->SwitchCCLayerForTest(); |
| 1380 | 1380 |
| 1381 // Ensure that the opacity animation completed. | 1381 // Ensure that the opacity animation completed. |
| 1382 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); | 1382 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); |
| 1383 } | 1383 } |
| 1384 | 1384 |
| 1385 } // namespace ui | 1385 } // namespace ui |
| OLD | NEW |