43 std::shared_ptr<DlMaskFilter>
filter;
49 const std::string&
text,
50 const std::string_view& font_fixture,
52 const std::optional<SkFont>& font = std::nullopt) {
62 canvas.
DrawCircle(options.position, 5.0, paint);
66 if (!font.has_value()) {
67 auto c_font_fixture = std::string(font_fixture);
74 selected_font = SkFont(font_mgr->makeFromData(mapping), options.font_size);
75 if (options.is_subpixel) {
76 selected_font.setSubpixel(
true);
79 selected_font = font.value();
81 auto blob = SkTextBlob::MakeFromString(
text.c_str(), selected_font);
93 text_paint.
setDrawStyle(options.stroke ? DlDrawStyle::kStroke
96 options.position.y, text_paint);
107 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
108 "Roboto-Regular.ttf"));
110 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
120 builder.
Scale(-1, 1);
123 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
124 "Roboto-Regular.ttf"));
126 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
137 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
138 "Roboto-Regular.ttf",
142 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
158 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
167 builder.
Scale(0.5, 0.5);
170 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
171 "Roboto-Regular.ttf"));
172 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
181 for (
int i = 0;
i < 6; ++
i) {
184 Scalar scale = 0.445 - (
i / 1000.f);
185 builder.
Scale(scale, scale);
187 GetContext(), builder,
"k",
"Roboto-Regular.ttf",
190 GetContext(), builder,
"k",
"Roboto-Regular.ttf",
194 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
200 auto callback = [&]() -> sk_sp<DisplayList> {
201 if (IsPlaygroundEnabled()) {
202 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
203 ImGui::SliderFloat(
"Scale", &scale, 4, 20);
212 builder.
Scale(scale, scale);
214 GetContext(), builder,
"HELLO",
"Roboto-Regular.ttf",
219 return builder.
Build();
222 ASSERT_TRUE(OpenPlaygroundHere(
callback));
229 auto callback = [&]() -> sk_sp<DisplayList> {
230 if (IsPlaygroundEnabled()) {
231 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
232 ImGui::SliderFloat(
"scale", &scale, 1.f, 300.f);
233 ImGui::SliderFloat(
"offsetx", &offsetx, -600.f, 100.f);
234 ImGui::SliderFloat(
"offsety", &offsety, 600.f, 2048.f);
238 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
242 builder.
Scale(scale, scale);
245 GetContext(), builder,
"test",
"Roboto-Regular.ttf",
249 return builder.
Build();
251 ASSERT_TRUE(OpenPlaygroundHere(
callback));
257 auto callback = [&]() -> sk_sp<DisplayList> {
258 if (IsPlaygroundEnabled()) {
259 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
260 ImGui::SliderFloat(
"Fine Scale", &fine_scale, -1, 1);
269 Scalar scale = 2.625 + fine_scale;
270 builder.
Scale(scale, scale);
272 "the quick brown fox jumped over the lazy dog!.?",
273 "Roboto-Regular.ttf",
275 return builder.
Build();
278 ASSERT_TRUE(OpenPlaygroundHere(
callback));
283 float fpivot[2] = {200 + 30, 200 - 20};
284 float rotation = 180;
285 float foffset[2] = {200, 200};
287 auto callback = [&]() -> sk_sp<DisplayList> {
288 if (IsPlaygroundEnabled()) {
289 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
290 ImGui::SliderFloat(
"pivotx", &fpivot[0], 0, 300);
291 ImGui::SliderFloat(
"pivoty", &fpivot[1], 0, 300);
292 ImGui::SliderFloat(
"rotation", &rotation, 0, 360);
293 ImGui::SliderFloat(
"foffsetx", &foffset[0], 0, 300);
294 ImGui::SliderFloat(
"foffsety", &foffset[1], 0, 300);
298 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
310 .position =
DlPoint(foffset[0], foffset[1]),
314 return builder.
Build();
316 ASSERT_TRUE(OpenPlaygroundHere(
callback));
321 std::array<Scalar, 20> phase_offsets = {
322 7.82637e-06, 0.131538, 0.755605, 0.45865, 0.532767,
323 0.218959, 0.0470446, 0.678865, 0.679296, 0.934693,
324 0.383502, 0.519416, 0.830965, 0.0345721, 0.0534616,
325 0.5297, 0.671149, 0.00769819, 0.383416, 0.0668422};
326 auto callback = [&]() -> sk_sp<DisplayList> {
328 static float phase_variation = 0.2;
329 static float speed = 0.5;
330 static float magnitude = 100;
331 if (IsPlaygroundEnabled()) {
332 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
333 ImGui::SliderFloat(
"Font size", &
font_size, 5, 50);
334 ImGui::SliderFloat(
"Phase variation", &phase_variation, 0, 1);
335 ImGui::SliderFloat(
"Oscillation speed", &speed, 0, 2);
336 ImGui::SliderFloat(
"Oscillation magnitude", &magnitude, 0, 300);
341 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
343 for (
size_t i = 0;
i < phase_offsets.size();
i++) {
346 magnitude * std::sin((-phase_offsets[
i] *
k2Pi * phase_variation +
347 GetSecondsElapsed() * speed)),
351 GetContext(), builder,
352 "the quick brown fox jumped over "
354 "Roboto-Regular.ttf",
355 {.font_size =
font_size, .position = position})) {
359 return builder.
Build();
362 ASSERT_TRUE(OpenPlaygroundHere(
callback));
373 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
374 "HomemadeApple.ttf"));
375 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
380 "Apple Color Emoji.ttc";
382 "NotoColorEmoji.ttf";
393 GetContext(), builder,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
kFontFixture));
394 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
400 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
406 GetContext(), builder,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
kFontFixture,
410 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
421 GetContext(), builder,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
kFontFixture,
423 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
434 builder.
Scale(0.5, 0.5);
440 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
441 "Roboto-Regular.ttf"));
446 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
447 "Roboto-Regular.ttf"));
449 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
458 ASSERT_NE(mapping,
nullptr);
462 SkFont sk_font(font_mgr->makeFromData(mapping),
font_size);
475 for (
auto& t :
text) {
480 auto blob = SkTextBlob::MakeFromString(t.text, sk_font);
481 ASSERT_NE(blob,
nullptr);
488 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
504 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
514 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
515 "Roboto-Regular.ttf"));
517 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
526 0.0, 0.0, 0.0, 1.0) *
532 "Roboto-Regular.ttf"));
533 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
542 0.0, 0.0, 0.0, 1.0) *
549 builder.
SaveLayer(window_bounds, &save_paint);
553 "Roboto-Regular.ttf"));
556 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
566 builder.
SaveLayer(std::nullopt, &save_paint);
574 "Roboto-Regular.ttf"));
575 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
581 "Roboto-Regular.ttf"));
582 auto text_display_list = text_builder.
Build();
589 0.0, 0.002, 0.0, 1.0);
594 builder.
SaveLayer(window_bounds, &save_paint);
599 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
607 ASSERT_NE(mapping,
nullptr);
611 SkFont sk_font(font_mgr->makeFromData(mapping),
font_size);
616 std::vector<DlColor> colors = {
DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
618 std::vector<Scalar> stops = {
635 auto blob = SkTextBlob::MakeFromString(
"Hello", sk_font);
636 ASSERT_NE(blob,
nullptr);
640 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
648 DlColor clear_color(1.0, 0.5, 0.5, 0.5, DlColorSpace::kSRGB);
653 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
654 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
660 DlColor white(1.0, 1.0, 1.0, 1.0, DlColorSpace::kSRGB);
665 builder.
ClipRect(frame, DlClipOp::kIntersect);
668 0.8241262, 0.56640625, 0.0, 0.0, -0.56640625, 0.8241262, 0.0, 0.0,
669 0.0, 0.0, 1.0, 0.0, 271.1137, 489.4733, 0.0, 1.0,
675 DlColor bluish(1.0, 0.184, 0.501, 0.929, DlColorSpace::kSRGB);
681 builder.
ClipRect(rect, DlClipOp::kIntersect);
687 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
688 0.0, 0.0, 1.0, 0.0, 675.0, 279.5, 0.0, 1.0,
699 path_builder.
Close();
702 DlColor fill_color(1.0, 1.0, 0.0, 0.0, DlColorSpace::kSRGB);
703 DlColor stroke_color(1.0, 0.0, 0.0, 0.0, DlColorSpace::kSRGB);
717 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
722 std::make_shared<TypographerContextSkia>());
726 constexpr const char* font_fixture =
"Roboto-Regular.ttf";
729 auto c_font_fixture = std::string(font_fixture);
731 ASSERT_TRUE(mapping);
734 SkFont sk_font(font_mgr->makeFromData(mapping), 16);
736 auto blob = SkTextBlob::MakeFromString(
"Hello World", sk_font);
758 ->CreateOffscreenMSAA(*aiks_context.
GetContext(), {100, 100}, 1);
766 Matrix not_preroll_matrix =
773 aiks_context.
GetContext()->CreateCommandBuffer();
789 ASSERT_TRUE(mapping);
793 SkFontArguments::VariationPosition::Coordinate weight_coord{
794 SkSetFourByteTag(
'w',
'g',
'h',
't'), 100.0f};
795 SkFontArguments
args;
796 args.setVariationDesignPosition({&weight_coord, 1});
798 SkFont thin_font(font_mgr->makeFromData(mapping)->makeClone(
args), 25);
802 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
803 "RobotoSlab-VariableFont_wght.ttf",
805 .position =
DlPoint(100, 200)},
809 DlPaint dart_text_background_paint;
812 dart_text_background_paint);
814 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
815 "RobotoSlab-VariableFont_wght.ttf",
817 .position =
DlPoint(100, 300)},
820 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
825 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
831 std::make_shared<TypographerContextSkia>());
855 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
861 std::make_shared<TypographerContextSkia>());
868 for (
auto i = 0;
i < 5;
i++) {
888 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
894 std::make_shared<TypographerContextSkia>());
905 for (
const auto& color : colors) {
926 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
932 std::make_shared<TypographerContextSkia>());
942 ASSERT_TRUE(mapping);
944 SkFont sk_font(font_mgr->makeFromData(mapping), 50);
946 for (
auto i = 0;
i < 10;
i++) {
969 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
971 std::vector<Scalar> scales = {4, 8, 16, 24, 32};
972 std::vector<Scalar> spacing = {8, 8, 8, 8, 8};
975 for (
auto i = 0u;
i < scales.size();
i++) {
977 builder.
Scale(scales[
i], scales[
i]);
979 GetContext(), builder,
"lo",
"Roboto-Regular.ttf",
988 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
992std::shared_ptr<TextFrame> MakeDefaultTextFrame(
const std::string&
text,
996 if (mapping ==
nullptr) {
1001 SkFont sk_font(font_mgr->makeFromData(mapping),
font_size);
1002 sk_sp<SkTextBlob> blob = SkTextBlob::MakeFromString(
"Hi", sk_font);
1008void DrawTextFramesMultipleScalesWithReuse(
AiksTest* test,
1012 builder.
Scale(test->GetContentScale().x, test->GetContentScale().y);
1015 std::shared_ptr<TextFrame> reuse_frame = MakeDefaultTextFrame(
"Hi", 20.0f);
1016 ASSERT_NE(reuse_frame,
nullptr);
1020 builder.
Scale(first_scale, first_scale);
1027 builder.
Scale(second_scale, second_scale);
1034 builder.
Scale(first_scale, first_scale);
1035 std::shared_ptr<TextFrame> single_use_frame1 =
1036 MakeDefaultTextFrame(
"Hi", 20.0f);
1043 builder.
Scale(second_scale, second_scale);
1044 std::shared_ptr<TextFrame> single_use_frame2 =
1045 MakeDefaultTextFrame(
"Hi", 20.0f);
1050 ASSERT_TRUE(test->OpenPlaygroundHere(builder.
Build()));
1055 DrawTextFramesMultipleScalesWithReuse(
this,
1061 DrawTextFramesMultipleScalesWithReuse(
this,
1078 builder.
Scale(2, 2);
1080 GetContext(), builder,
"Uniform 2x2",
"Roboto-Regular.ttf",
1086 builder.
Scale(1, 2);
1088 GetContext(), builder,
"ScaleY 1x2",
"Roboto-Regular.ttf",
1094 builder.
Scale(3, 1);
1096 GetContext(), builder,
"ScaleX 3x1",
"Roboto-Regular.ttf",
1102 builder.
Scale(2, 2.2);
1104 GetContext(), builder,
"Near-uniform 2x2.2",
"Roboto-Regular.ttf",
1108 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
1112 constexpr const char* font_fixture =
"Roboto-Regular.ttf";
1113 auto c_font_fixture = std::string(font_fixture);
1115 ASSERT_TRUE(mapping);
1118 SkFont sk_font(font_mgr->makeFromData(mapping), 60);
1119 sk_font.setSubpixel(
true);
1121 auto blob_corrected =
1122 SkTextBlob::MakeFromString(
"Gamma Corrected (true)", sk_font);
1123 ASSERT_TRUE(blob_corrected);
1125 text_frame_corrected->SetEnableGammaCorrection(
true);
1127 auto blob_uncorrected =
1128 SkTextBlob::MakeFromString(
"Gamma Corrected (false)", sk_font);
1129 ASSERT_TRUE(blob_uncorrected);
1131 text_frame_uncorrected->SetEnableGammaCorrection(
false);
1133 auto callback = [&]() -> sk_sp<flutter::DisplayList> {
1144 50, 100, text_paint);
1146 50, 200, text_paint);
1149 50, 300, text_paint);
1150 DlPaint diff_paint = text_paint;
1153 50, 300, diff_paint);
1155 return builder.
Build();
1158 ASSERT_TRUE(OpenPlaygroundHere(
callback));
1163 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
1166 auto frame = MakeDefaultTextFrame(
"Hello", 25.0f);
1175 builder.
Scale(4, 4);
1176 for (
int x = 10;
x <= 100;
x += 30) {
1184 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
void ClipRect(const DlRect &rect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false) override
void DrawRoundRect(const DlRoundRect &rrect, const DlPaint &paint) override
void DrawColor(DlColor color, DlBlendMode mode) override
void DrawCircle(const DlPoint ¢er, DlScalar radius, const DlPaint &paint) override
void SaveLayer(const std::optional< DlRect > &bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr, std::optional< int64_t > backdrop_id=std::nullopt) override
void Rotate(DlScalar degrees) override
void DrawText(const std::shared_ptr< DlText > &text, DlScalar x, DlScalar y, const DlPaint &paint) override
void Scale(DlScalar sx, DlScalar sy) override
void DrawDisplayList(const sk_sp< DisplayList > display_list, DlScalar opacity=SK_Scalar1) override
void Translate(DlScalar tx, DlScalar ty) override
void DrawPaint(const DlPaint &paint) override
sk_sp< DisplayList > Build()
void DrawPath(const DlPath &path, const DlPaint &paint) override
void Transform(const DlMatrix &matrix) override
void DrawRect(const DlRect &rect, const DlPaint &paint) override
static std::shared_ptr< DlMaskFilter > Make(DlBlurStyle style, SkScalar sigma, bool respect_ctm=true)
void Clear(DlColor color)
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
DlPaint & setColor(DlColor color)
DlPaint & setStrokeWidth(float width)
DlPaint & setBlendMode(DlBlendMode mode)
DlPaint & setMaskFilter(std::nullptr_t filter)
DlPaint & setDrawStyle(DlDrawStyle style)
DlPaint & setColorSource(std::nullptr_t source)
DlPathBuilder & LineTo(DlPoint p2)
Draw a line from the current point to the indicated point p2.
DlPathBuilder & MoveTo(DlPoint p2)
Start a new contour that will originate at the indicated point p2.
const DlPath TakePath()
Returns the path constructed by this path builder and resets its internal state to the default state ...
DlPathBuilder & Close()
The path is closed back to the location of the most recent MoveTo call. Contours that are filled are ...
static std::shared_ptr< DlTextImpeller > Make(const std::shared_ptr< impeller::TextFrame > &frame)
ContentContext & GetContentContext() const
std::shared_ptr< Context > GetContext() const
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
const std::shared_ptr< LazyGlyphAtlas > & GetLazyGlyphAtlas() const
TextShadowCache & GetTextShadowCache() const
void SetTransform(const Matrix &transform)
Set the global transform matrix for this Entity.
void SetPosition(Point position)
void SetScreenTransform(const Matrix &transform)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
void SetColor(Color color)
size_t GetCacheSizeForTesting() const
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlutterDesktopBinaryReply callback
SkFont CreateTestFontOfSize(DlScalar scalar)
sk_sp< SkData > OpenFixtureAsSkData(const std::string &fixture_name)
Opens a fixture of the given file name and returns a Skia SkData holding its contents.
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
@ kFill
fills interior of shapes
bool RenderTextInCanvasSkia(const std::shared_ptr< Context > &context, DisplayListBuilder &canvas, const std::string &text, const std::string_view &font_fixture, const TextRenderOptions &options={}, const std::optional< SkFont > &font=std::nullopt)
TEST_P(AiksTest, DrawAtlasNoColor)
AiksPlaygroundWithGoldens AiksTest
static constexpr std::string_view kFontFixture
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips, std::optional< PixelFormat > target_pixel_format)
Render the provided display list to a texture with the given size.
std::shared_ptr< TextFrame > MakeTextFrameFromTextBlobSkia(const sk_sp< SkTextBlob > &blob)
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
std::shared_ptr< ContextGLES > context
std::shared_ptr< RenderPass > render_pass
std::shared_ptr< CommandBuffer > command_buffer
static constexpr DlColor kMagenta()
static constexpr DlColor kWhite()
static constexpr DlColor kBlue()
static constexpr DlColor RGBA(DlScalar r, DlScalar g, DlScalar b, DlScalar a)
Construct a 32 bit color from floating point R, G, B, and A color channels.
static constexpr DlColor kBlack()
static constexpr DlColor ARGB(DlScalar a, DlScalar r, DlScalar g, DlScalar b)
Construct a 32 bit color from floating point A, R, G, and B color channels.
static constexpr DlColor kAqua()
static constexpr DlColor kYellow()
static constexpr DlColor kPurple()
static constexpr DlColor kDarkGreen()
static constexpr DlColor kRed()
static constexpr DlColor kGreen()
static constexpr DlColor kOrange()
constexpr DlColor modulateOpacity(DlScalar opacity) const
static constexpr Color Aqua()
A 4x4 matrix using column-major storage.
static Matrix MakeRotationY(Radians r)
static constexpr Matrix MakeRow(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
static constexpr Matrix MakeTranslateScale(const Vector3 &s, const Vector3 &t)
static constexpr Matrix MakeScale(const Vector3 &s)
static RoundRect MakeRectRadius(const Rect &rect, Scalar radius)
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
std::shared_ptr< DlMaskFilter > filter