| 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "mojo/public/cpp/bindings/binding_set.h" | 6 #include "mojo/public/cpp/bindings/binding_set.h" |
| 7 #include "skia/public/interfaces/test/traits_test_service.mojom.h" | 7 #include "skia/public/interfaces/test/traits_test_service.mojom.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/core/SkColorFilter.h" | 9 #include "third_party/skia/include/core/SkColorFilter.h" |
| 10 #include "third_party/skia/include/core/SkString.h" | 10 #include "third_party/skia/include/core/SkString.h" |
| 11 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" | 11 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" |
| 12 #include "ui/gfx/skia_util.h" |
| 12 | 13 |
| 13 namespace skia { | 14 namespace skia { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { | 18 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { |
| 18 public: | 19 public: |
| 19 StructTraitsTest() {} | 20 StructTraitsTest() {} |
| 20 | 21 |
| 21 protected: | 22 protected: |
| 22 mojom::TraitsTestServicePtr GetTraitsTestProxy() { | 23 mojom::TraitsTestServicePtr GetTraitsTestProxy() { |
| 23 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | 24 return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
| 24 } | 25 } |
| 25 | 26 |
| 26 private: | 27 private: |
| 27 // TraitsTestService: | 28 // TraitsTestService: |
| 29 void EchoBitmap(const SkBitmap& b, |
| 30 const EchoBitmapCallback& callback) override { |
| 31 callback.Run(b); |
| 32 } |
| 28 void EchoImageFilter(const sk_sp<SkImageFilter>& i, | 33 void EchoImageFilter(const sk_sp<SkImageFilter>& i, |
| 29 const EchoImageFilterCallback& callback) override { | 34 const EchoImageFilterCallback& callback) override { |
| 30 callback.Run(i); | 35 callback.Run(i); |
| 31 } | 36 } |
| 32 | 37 |
| 33 base::MessageLoop loop_; | 38 base::MessageLoop loop_; |
| 34 mojo::BindingSet<TraitsTestService> traits_test_bindings_; | 39 mojo::BindingSet<TraitsTestService> traits_test_bindings_; |
| 35 | 40 |
| 36 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest); | 41 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest); |
| 37 }; | 42 }; |
| 38 | 43 |
| 39 static sk_sp<SkImageFilter> make_scale(float amount, | 44 static sk_sp<SkImageFilter> make_scale(float amount, |
| 40 sk_sp<SkImageFilter> input) { | 45 sk_sp<SkImageFilter> input) { |
| 41 SkScalar s = amount; | 46 SkScalar s = amount; |
| 42 SkScalar matrix[20] = {s, 0, 0, 0, 0, 0, s, 0, 0, 0, | 47 SkScalar matrix[20] = {s, 0, 0, 0, 0, 0, s, 0, 0, 0, |
| 43 0, 0, s, 0, 0, 0, 0, 0, s, 0}; | 48 0, 0, s, 0, 0, 0, 0, 0, s, 0}; |
| 44 sk_sp<SkColorFilter> filter( | 49 sk_sp<SkColorFilter> filter( |
| 45 SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); | 50 SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); |
| 46 return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); | 51 return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); |
| 47 } | 52 } |
| 48 | 53 |
| 49 } // namespace | 54 } // namespace |
| 50 | 55 |
| 56 TEST_F(StructTraitsTest, Bitmap) { |
| 57 SkBitmap input; |
| 58 input.allocN32Pixels(10, 5); |
| 59 input.eraseColor(SK_ColorYELLOW); |
| 60 input.erase(SK_ColorTRANSPARENT, SkIRect::MakeXYWH(0, 1, 2, 3)); |
| 61 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 62 SkBitmap output; |
| 63 proxy->EchoBitmap(input, &output); |
| 64 EXPECT_EQ(input.colorType(), output.colorType()); |
| 65 EXPECT_EQ(input.alphaType(), output.alphaType()); |
| 66 EXPECT_EQ(input.profileType(), output.profileType()); |
| 67 EXPECT_EQ(input.width(), output.width()); |
| 68 EXPECT_EQ(input.height(), output.height()); |
| 69 EXPECT_TRUE(gfx::BitmapsAreEqual(input, output)); |
| 70 } |
| 71 |
| 51 TEST_F(StructTraitsTest, ImageFilter) { | 72 TEST_F(StructTraitsTest, ImageFilter) { |
| 52 sk_sp<SkImageFilter> input(make_scale(0.5f, nullptr)); | 73 sk_sp<SkImageFilter> input(make_scale(0.5f, nullptr)); |
| 53 SkString input_str; | 74 SkString input_str; |
| 54 input->toString(&input_str); | 75 input->toString(&input_str); |
| 55 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 76 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 56 sk_sp<SkImageFilter> output; | 77 sk_sp<SkImageFilter> output; |
| 57 proxy->EchoImageFilter(input, &output); | 78 proxy->EchoImageFilter(input, &output); |
| 58 SkString output_str; | 79 SkString output_str; |
| 59 output->toString(&output_str); | 80 output->toString(&output_str); |
| 60 EXPECT_EQ(input_str, output_str); | 81 EXPECT_EQ(input_str, output_str); |
| 61 } | 82 } |
| 62 | 83 |
| 63 } // namespace skia | 84 } // namespace skia |
| OLD | NEW |