| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "flutter/lib/ui/painting/paint.h" |
| 6 | #include "flutter/shell/common/shell_test.h" |
| 7 | #include "flutter/shell/common/thread_host.h" |
| 8 | |
| 9 | #include "flutter/testing/testing.h" |
| 10 | |
| 11 | namespace flutter { |
| 12 | namespace testing { |
| 13 | |
| 14 | TEST_F(ShellTest, ConvertPaintToDlPaint) { |
| 15 | auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>(); |
| 16 | DlPaint dl_paint; |
| 17 | |
| 18 | auto nativeToDlPaint = [message_latch, &dl_paint](Dart_NativeArguments args) { |
| 19 | Dart_Handle dart_paint = Dart_GetNativeArgument(args, index: 0); |
| 20 | Dart_Handle paint_objects = |
| 21 | Dart_GetField(container: dart_paint, name: tonic::ToDart(val: "_objects" )); |
| 22 | Dart_Handle paint_data = Dart_GetField(container: dart_paint, name: tonic::ToDart(val: "_data" )); |
| 23 | Paint ui_paint(paint_objects, paint_data); |
| 24 | ui_paint.toDlPaint(paint&: dl_paint); |
| 25 | message_latch->Signal(); |
| 26 | }; |
| 27 | |
| 28 | Settings settings = CreateSettingsForFixture(); |
| 29 | TaskRunners task_runners("test" , // label |
| 30 | GetCurrentTaskRunner(), // platform |
| 31 | CreateNewThread(), // raster |
| 32 | CreateNewThread(), // ui |
| 33 | CreateNewThread() // io |
| 34 | ); |
| 35 | |
| 36 | AddNativeCallback(name: "ConvertPaintToDlPaint" , |
| 37 | CREATE_NATIVE_ENTRY(nativeToDlPaint)); |
| 38 | |
| 39 | std::unique_ptr<Shell> shell = CreateShell(settings, task_runners); |
| 40 | |
| 41 | ASSERT_TRUE(shell->IsSetup()); |
| 42 | auto configuration = RunConfiguration::InferFromSettings(settings); |
| 43 | configuration.SetEntrypoint("convertPaintToDlPaint" ); |
| 44 | |
| 45 | shell->RunEngine(run_configuration: std::move(configuration), result_callback: [](auto result) { |
| 46 | ASSERT_EQ(result, Engine::RunStatus::Success); |
| 47 | }); |
| 48 | |
| 49 | message_latch->Wait(); |
| 50 | DestroyShell(shell: std::move(shell), task_runners); |
| 51 | |
| 52 | ASSERT_EQ(dl_paint.getBlendMode(), DlBlendMode::kModulate); |
| 53 | ASSERT_EQ(static_cast<uint32_t>(dl_paint.getColor()), 0x11223344u); |
| 54 | ASSERT_EQ(*dl_paint.getColorFilter(), |
| 55 | DlBlendColorFilter(0x55667788, DlBlendMode::kXor)); |
| 56 | ASSERT_EQ(*dl_paint.getMaskFilter(), |
| 57 | DlBlurMaskFilter(DlBlurStyle::kInner, 0.75)); |
| 58 | ASSERT_EQ(dl_paint.getDrawStyle(), DlDrawStyle::kStroke); |
| 59 | } |
| 60 | |
| 61 | } // namespace testing |
| 62 | } // namespace flutter |
| 63 | |