Flutter Engine
The 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
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
11namespace flutter {
12namespace testing {
13
14TEST_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) {
20 Dart_Handle paint_objects =
21 Dart_GetField(dart_paint, tonic::ToDart("_objects"));
22 Dart_Handle paint_data = Dart_GetField(dart_paint, tonic::ToDart("_data"));
23 Paint ui_paint(paint_objects, paint_data);
24 ui_paint.toDlPaint(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("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(std::move(configuration), [](auto result) {
47 });
48
49 message_latch->Wait();
50 DestroyShell(std::move(shell), task_runners);
51
52 ASSERT_EQ(dl_paint.getBlendMode(), DlBlendMode::kModulate);
53 ASSERT_EQ(static_cast<uint32_t>(dl_paint.getColor().argb()), 0x11223344u);
54 ASSERT_EQ(*dl_paint.getColorFilter(),
56 ASSERT_EQ(*dl_paint.getMaskFilter(),
58 ASSERT_EQ(dl_paint.getDrawStyle(), DlDrawStyle::kStroke);
59}
60
61} // namespace testing
62} // namespace flutter
DlColor getColor() const
Definition dl_paint.h:70
DlBlendMode getBlendMode() const
Definition dl_paint.h:84
DlDrawStyle getDrawStyle() const
Definition dl_paint.h:92
std::shared_ptr< const DlMaskFilter > getMaskFilter() const
Definition dl_paint.h:167
std::shared_ptr< const DlColorFilter > getColorFilter() const
Definition dl_paint.h:141
void toDlPaint(DlPaint &paint) const
Definition paint.cc:197
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...
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
TEST_F(DisplayListTest, Defaults)
@ kStroke
strokes boundary of shapes
@ kInner
fuzzy inside, nothing outside
@ kXor
r = s*(1-da) + d*(1-sa)
Dart_Handle ToDart(const T &object)
constexpr uint32_t argb() const
Definition dl_color.h:78
#define CREATE_NATIVE_ENTRY(native_entry)