Flutter Engine
 
Loading...
Searching...
No Matches
paint_unittests.cc
Go to the documentation of this file.
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
9
11
12namespace flutter {
13namespace testing {
14
15TEST_F(ShellTest, ConvertPaintToDlPaint) {
16 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
17 DlPaint dl_paint;
18
19 auto nativeToDlPaint = [message_latch, &dl_paint](Dart_NativeArguments args) {
20 Dart_Handle dart_paint = Dart_GetNativeArgument(args, 0);
21 Dart_Handle paint_objects =
22 Dart_GetField(dart_paint, tonic::ToDart("_objects"));
23 Dart_Handle paint_data = Dart_GetField(dart_paint, tonic::ToDart("_data"));
24 Paint ui_paint(paint_objects, paint_data);
25
26 ui_paint.paint(dl_paint, DisplayListOpFlags::kDrawRectFlags,
28 message_latch->Signal();
29 };
30
31 Settings settings = CreateSettingsForFixture();
32 TaskRunners task_runners("test", // label
33 GetCurrentTaskRunner(), // platform
34 CreateNewThread(), // raster
35 CreateNewThread(), // ui
36 CreateNewThread() // io
37 );
38
39 AddNativeCallback("ConvertPaintToDlPaint",
40 CREATE_NATIVE_ENTRY(nativeToDlPaint));
41
42 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
43
44 ASSERT_TRUE(shell->IsSetup());
45 auto configuration = RunConfiguration::InferFromSettings(settings);
46 configuration.SetEntrypoint("convertPaintToDlPaint");
47
48 shell->RunEngine(std::move(configuration), [](auto result) {
49 ASSERT_EQ(result, Engine::RunStatus::Success);
50 });
51
52 message_latch->Wait();
53 DestroyShell(std::move(shell), task_runners);
54
55 EXPECT_EQ(dl_paint.getBlendMode(), DlBlendMode::kModulate);
56 EXPECT_EQ(static_cast<uint32_t>(dl_paint.getColor().argb()), 0x11223344u);
57 if (dl_paint.getColorFilter()) {
58 std::shared_ptr<const DlColorFilter> expected_filter =
59 DlColorFilter::MakeBlend(DlColor(0x55667788), DlBlendMode::kXor);
60 EXPECT_EQ(*dl_paint.getColorFilter(), *expected_filter);
61 } else {
62 FAIL() << "color filter was nullptr";
63 }
64 if (dl_paint.getMaskFilter()) {
65 EXPECT_EQ(*dl_paint.getMaskFilter(),
67 } else {
68 FAIL() << "mask filter was nullptr";
69 }
70 EXPECT_EQ(dl_paint.getDrawStyle(), DlDrawStyle::kStroke);
71}
72
73} // namespace testing
74} // namespace flutter
static constexpr DisplayListAttributeFlags kDrawRectFlags
static std::shared_ptr< const DlColorFilter > MakeBlend(DlColor color, DlBlendMode mode)
DlColor getColor() const
Definition dl_paint.h:69
DlBlendMode getBlendMode() const
Definition dl_paint.h:82
const std::shared_ptr< const DlMaskFilter > & getMaskFilter() const
Definition dl_paint.h:180
DlDrawStyle getDrawStyle() const
Definition dl_paint.h:90
const std::shared_ptr< const DlColorFilter > & getColorFilter() const
Definition dl_paint.h:144
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
TEST_F(DisplayListTest, Defaults)
@ kStroke
strokes boundary of shapes
@ kInner
fuzzy inside, nothing outside
Dart_Handle ToDart(const T &object)
uint32_t argb() const
Definition dl_color.h:158
#define CREATE_NATIVE_ENTRY(native_entry)