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> {
202 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> {
231 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> {
259 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> {
289 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;
332 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()));
494 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
504 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
505 "Roboto-Regular.ttf"));
507 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
516 0.0, 0.0, 0.0, 1.0) *
522 "Roboto-Regular.ttf"));
523 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
532 0.0, 0.0, 0.0, 1.0) *
539 builder.
SaveLayer(window_bounds, &save_paint);
543 "Roboto-Regular.ttf"));
546 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
556 builder.
SaveLayer(std::nullopt, &save_paint);
564 "Roboto-Regular.ttf"));
565 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
571 "Roboto-Regular.ttf"));
572 auto text_display_list = text_builder.
Build();
579 0.0, 0.002, 0.0, 1.0);
584 builder.
SaveLayer(window_bounds, &save_paint);
589 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
597 ASSERT_NE(mapping,
nullptr);
601 SkFont sk_font(font_mgr->makeFromData(mapping),
font_size);
606 std::vector<DlColor> colors = {
DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
608 std::vector<Scalar> stops = {
625 auto blob = SkTextBlob::MakeFromString(
"Hello", sk_font);
626 ASSERT_NE(blob,
nullptr);
630 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
638 DlColor clear_color(1.0, 0.5, 0.5, 0.5, DlColorSpace::kSRGB);
643 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
644 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
650 DlColor white(1.0, 1.0, 1.0, 1.0, DlColorSpace::kSRGB);
655 builder.
ClipRect(frame, DlClipOp::kIntersect);
658 0.8241262, 0.56640625, 0.0, 0.0, -0.56640625, 0.8241262, 0.0, 0.0,
659 0.0, 0.0, 1.0, 0.0, 271.1137, 489.4733, 0.0, 1.0,
665 DlColor bluish(1.0, 0.184, 0.501, 0.929, DlColorSpace::kSRGB);
671 builder.
ClipRect(rect, DlClipOp::kIntersect);
677 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
678 0.0, 0.0, 1.0, 0.0, 675.0, 279.5, 0.0, 1.0,
689 path_builder.
Close();
692 DlColor fill_color(1.0, 1.0, 0.0, 0.0, DlColorSpace::kSRGB);
693 DlColor stroke_color(1.0, 0.0, 0.0, 0.0, DlColorSpace::kSRGB);
707 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
712 std::make_shared<TypographerContextSkia>());
716 constexpr const char* font_fixture =
"Roboto-Regular.ttf";
719 auto c_font_fixture = std::string(font_fixture);
721 ASSERT_TRUE(mapping);
724 SkFont sk_font(font_mgr->makeFromData(mapping), 16);
726 auto blob = SkTextBlob::MakeFromString(
"Hello World", sk_font);
748 ->CreateOffscreenMSAA(*aiks_context.
GetContext(), {100, 100}, 1);
756 Matrix not_preroll_matrix =
763 aiks_context.
GetContext()->CreateCommandBuffer();
779 ASSERT_TRUE(mapping);
783 SkFontArguments::VariationPosition::Coordinate weight_coord{
784 SkSetFourByteTag(
'w',
'g',
'h',
't'), 100.0f};
785 SkFontArguments
args;
786 args.setVariationDesignPosition({&weight_coord, 1});
788 SkFont thin_font(font_mgr->makeFromData(mapping)->makeClone(
args), 25);
792 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
793 "RobotoSlab-VariableFont_wght.ttf",
795 .position =
DlPoint(100, 200)},
799 DlPaint dart_text_background_paint;
802 dart_text_background_paint);
804 GetContext(), builder,
"the quick brown fox jumped over the lazy dog!.?",
805 "RobotoSlab-VariableFont_wght.ttf",
807 .position =
DlPoint(100, 300)},
810 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
815 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
821 std::make_shared<TypographerContextSkia>());
845 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
851 std::make_shared<TypographerContextSkia>());
858 for (
auto i = 0;
i < 5;
i++) {
878 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
884 std::make_shared<TypographerContextSkia>());
895 for (
const auto& color : colors) {
916 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
922 std::make_shared<TypographerContextSkia>());
932 ASSERT_TRUE(mapping);
934 SkFont sk_font(font_mgr->makeFromData(mapping), 50);
936 for (
auto i = 0;
i < 10;
i++) {
959 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
961 std::vector<Scalar> scales = {4, 8, 16, 24, 32};
962 std::vector<Scalar> spacing = {8, 8, 8, 8, 8};
965 for (
auto i = 0u;
i < scales.size();
i++) {
967 builder.
Scale(scales[
i], scales[
i]);
969 GetContext(), builder,
"lo",
"Roboto-Regular.ttf",
978 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
982std::shared_ptr<TextFrame> MakeDefaultTextFrame(
const std::string&
text,
986 if (mapping ==
nullptr) {
991 SkFont sk_font(font_mgr->makeFromData(mapping),
font_size);
992 sk_sp<SkTextBlob> blob = SkTextBlob::MakeFromString(
"Hi", sk_font);
998void DrawTextFramesMultipleScalesWithReuse(
AiksTest* test,
1002 builder.
Scale(test->GetContentScale().x, test->GetContentScale().y);
1005 std::shared_ptr<TextFrame> reuse_frame = MakeDefaultTextFrame(
"Hi", 20.0f);
1006 ASSERT_NE(reuse_frame,
nullptr);
1010 builder.
Scale(first_scale, first_scale);
1017 builder.
Scale(second_scale, second_scale);
1024 builder.
Scale(first_scale, first_scale);
1025 std::shared_ptr<TextFrame> single_use_frame1 =
1026 MakeDefaultTextFrame(
"Hi", 20.0f);
1033 builder.
Scale(second_scale, second_scale);
1034 std::shared_ptr<TextFrame> single_use_frame2 =
1035 MakeDefaultTextFrame(
"Hi", 20.0f);
1040 ASSERT_TRUE(test->OpenPlaygroundHere(builder.
Build()));
1045 DrawTextFramesMultipleScalesWithReuse(
this,
1051 DrawTextFramesMultipleScalesWithReuse(
this,
1068 builder.
Scale(2, 2);
1070 GetContext(), builder,
"Uniform 2x2",
"Roboto-Regular.ttf",
1076 builder.
Scale(1, 2);
1078 GetContext(), builder,
"ScaleY 1x2",
"Roboto-Regular.ttf",
1084 builder.
Scale(3, 1);
1086 GetContext(), builder,
"ScaleX 3x1",
"Roboto-Regular.ttf",
1092 builder.
Scale(2, 2.2);
1094 GetContext(), builder,
"Near-uniform 2x2.2",
"Roboto-Regular.ttf",
1098 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
1102 constexpr const char* font_fixture =
"Roboto-Regular.ttf";
1103 auto c_font_fixture = std::string(font_fixture);
1105 ASSERT_TRUE(mapping);
1108 SkFont sk_font(font_mgr->makeFromData(mapping), 60);
1109 sk_font.setSubpixel(
true);
1111 auto blob_corrected =
1112 SkTextBlob::MakeFromString(
"Gamma Corrected (true)", sk_font);
1113 ASSERT_TRUE(blob_corrected);
1115 text_frame_corrected->SetEnableGammaCorrection(
true);
1117 auto blob_uncorrected =
1118 SkTextBlob::MakeFromString(
"Gamma Corrected (false)", sk_font);
1119 ASSERT_TRUE(blob_uncorrected);
1121 text_frame_uncorrected->SetEnableGammaCorrection(
false);
1123 auto callback = [&]() -> sk_sp<flutter::DisplayList> {
1134 50, 100, text_paint);
1136 50, 200, text_paint);
1139 50, 300, text_paint);
1140 DlPaint diff_paint = text_paint;
1143 50, 300, diff_paint);
1145 return builder.
Build();
1148 ASSERT_TRUE(OpenPlaygroundHere(
callback));
1153 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
1156 auto frame = MakeDefaultTextFrame(
"Hello", 25.0f);
1165 builder.
Scale(4, 4);
1166 for (
int x = 10;
x <= 100;
x += 30) {
1174 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
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
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)
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