15#include "gtest/gtest.h"
31 const std::vector<std::unique_ptr<DlImage>>&
images) {
32 canvas->
Scale(0.2, 0.2);
41 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
45 auto draw = [](
DlCanvas* canvas,
const std::vector<sk_sp<DlImage>>&
images) {
54 std::vector<sk_sp<DlImage>>
images;
55 images.emplace_back(CreateDlImageForFixture(
"kalimba.jpg"));
58 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
64 Point content_scale = GetContentScale();
65 auto draw = [content_scale](
DlCanvas* canvas,
66 const std::vector<sk_sp<DlImage>>&
images) {
67 canvas->
Scale(content_scale.
x, content_scale.
y);
92 canvas->
SaveLayer(save_layer_bounds,
nullptr, backdrop.get());
108 std::vector<sk_sp<DlImage>>
images;
111 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
115void DrawBlurGrid(
DlCanvas* canvas) {
121 std::vector<Scalar> blur_radii = {10, 30, 50};
122 for (
size_t i = 0;
i < blur_radii.size(); ++
i) {
124 auto blur_filter = std::make_shared<flutter::DlBlurMaskFilter>(
127 Scalar yval = gap +
i * (gap +
height);
142 Point content_scale = GetContentScale();
143 auto draw = [content_scale](
DlCanvas* canvas,
144 const std::vector<sk_sp<DlImage>>&
images) {
145 canvas->
Scale(content_scale.
x, content_scale.
y);
147 DrawBlurGrid(canvas);
151 std::vector<sk_sp<DlImage>>
images;
154 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
158 Point content_scale = GetContentScale();
159 auto draw = [content_scale](
DlCanvas* canvas,
160 const std::vector<sk_sp<DlImage>>&
images) {
161 canvas->
Scale(content_scale.
x, content_scale.
y);
163 canvas->
Scale(0.33, 0.33);
164 DrawBlurGrid(canvas);
168 std::vector<sk_sp<DlImage>>
images;
171 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
175 Point content_scale = GetContentScale();
176 auto draw = [content_scale](
DlCanvas* canvas,
177 const std::vector<sk_sp<DlImage>>&
images) {
178 canvas->
Scale(content_scale.
x, content_scale.
y);
181 canvas->
Scale(0.33, 0.33);
185 DrawBlurGrid(canvas);
189 std::vector<sk_sp<DlImage>>
images;
192 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
197 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
200 auto blur_sigmas = std::array{5.0f, 10.0f, 20.0f};
201 auto blur_colors = std::array{
215 path_builder.
MoveTo(corner + relative_from);
217 path_builder.
LineTo(corner + relative_from);
225 path_builder.
CubicCurveTo(corner + relative_from * magic,
226 corner + relative_to * magic,
227 corner + relative_to);
242 for (
size_t i = 0;
i < blur_sigmas.size();
i++) {
250 rect = rect.
Shift(150.0f, 0.0f);
251 builder.
DrawPath(make_rrect_path(rect, 10.0f, 10.0f), paint);
252 rect = rect.
Shift(-150.0f, 0.0f);
254 rect = rect.
Shift(0.0f, 200.0f);
256 rect = rect.
Shift(150.0f, 0.0f);
257 builder.
DrawPath(make_rrect_path(rect, 10.0f, 20.0f), paint);
258 rect = rect.
Shift(-150.0f, 0.0f);
260 rect = rect.
Shift(0.0f, 200.0f);
262 rect = rect.
Shift(150.0f, 0.0f);
263 builder.
DrawPath(make_rrect_path(rect, 20.0f, 10.0f), paint);
264 rect = rect.
Shift(-150.0f, 0.0f);
267 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
271 Point content_scale = GetContentScale();
272 auto draw = [content_scale](
DlCanvas* canvas,
273 const std::vector<sk_sp<DlImage>>&
images) {
274 canvas->
Scale(content_scale.
x, content_scale.
y);
294 for (
int degrees = 0; degrees < 360; degrees += 30) {
296 canvas->
DrawDashedLine(center + inner * delta, center + outer * delta,
297 dash_on, dash_off, thick_paint);
298 canvas->
DrawDashedLine(center + inner * delta, center + outer * delta,
299 dash_on, dash_off, middle_paint);
300 canvas->
DrawDashedLine(center + inner * delta, center + outer * delta,
301 dash_on, dash_off, thin_paint);
324 std::vector<sk_sp<DlImage>>
images;
327 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
337 builder.
SaveLayer(std::nullopt, &save_paint);
352 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
357 const uint32_t* ptr =
reinterpret_cast<const uint32_t*
>(img->
GetBytes());
360 for (uint32_t j = 0; j < img->
GetWidth(); ++j) {
361 uint32_t pixel = *ptr++;
362 if ((pixel & 0x00ffffff) != 0) {
363 max_y = std::max(max_y,
static_cast<int32_t
>(
i));
371 const uint32_t* ptr =
reinterpret_cast<const uint32_t*
>(img->
GetBytes());
373 std::vector<size_t> boundaries;
374 uint32_t
value = *ptr++;
376 if (((*ptr & 0x00ffffff) != 0) != ((value & 0x00ffffff) != 0)) {
377 boundaries.push_back(
i);
382 assert(boundaries.size() == 6);
383 return boundaries[4] - boundaries[3];
396 builder.
Scale(scale, scale);
402 return builder.
Build();
405 std::unique_ptr<impeller::testing::Screenshot> right =
406 MakeScreenshot(
callback(
"h", 0.444));
408 GTEST_SKIP() <<
"making screenshots not supported.";
410 std::unique_ptr<impeller::testing::Screenshot> left =
411 MakeScreenshot(
callback(
"e", 0.444));
413 int32_t left_max_y = CalculateMaxY(left.get());
414 int32_t right_max_y = CalculateMaxY(right.get());
415 int32_t y_diff = std::abs(left_max_y - right_max_y);
416 EXPECT_TRUE(y_diff <= 2) <<
"y diff: " << y_diff;
428 builder.
Scale(scale, scale);
434 return builder.
Build();
437 std::optional<int32_t> last_space;
438 for (
int i = 0;
i <= 100; ++
i) {
439 Scalar scale = 0.440 +
i / 1000.0;
440 std::unique_ptr<impeller::testing::Screenshot> right =
441 MakeScreenshot(
callback(
"ui", scale));
443 GTEST_SKIP() <<
"making screenshots not supported.";
446 int32_t space = CalculateSpaceBetweenUI(right.get());
447 if (last_space.has_value()) {
448 int32_t diff = abs(space - *last_space);
449 EXPECT_TRUE(diff <= 1)
450 <<
"i:" <<
i <<
" space:" << space <<
" last_space:" << *last_space;
457struct LeftmostIntensity {
464LeftmostIntensity CalculateLeftmostIntensity(
466 LeftmostIntensity result = {.x =
static_cast<int32_t
>(img->
GetWidth()),
468 const uint32_t* ptr =
reinterpret_cast<const uint32_t*
>(img->
GetBytes());
470 for (int32_t j = 0; j < static_cast<int32_t>(img->
GetWidth()); ++j) {
471 if (((*ptr & 0x00ffffff) != 0)) {
474 result.value = (*ptr & 0xff00) >> 8;
475 }
else if (j == result.x) {
477 std::max(
static_cast<int32_t
>(*ptr & 0xff), result.value);
503 return builder.
Build();
506 LeftmostIntensity intensity[5];
507 for (
int i = 0;
i <= 4; ++
i) {
508 Scalar offset = 10 + (
i / 4.0);
509 std::unique_ptr<impeller::testing::Screenshot> right =
512 GTEST_SKIP() <<
"making screenshots not supported.";
514 intensity[
i] = CalculateLeftmostIntensity(right.get());
515 ASSERT_NE(intensity[
i].
value, 0);
517 for (
int i = 1;
i < 5; ++
i) {
518 EXPECT_TRUE(intensity[
i].
x - intensity[
i - 1].
x == 1 ||
522 EXPECT_EQ(intensity[4].
x - intensity[0].
x, 1);
533 builder.
Scale(scalar, scalar);
543 return builder.
Build();
546 LeftmostIntensity intensity[5];
547 Scalar offset_fraction = 0.25 / scalar;
548 for (
int i = 0;
i <= 4; ++
i) {
549 Scalar offset = 10 + (offset_fraction *
i);
550 std::unique_ptr<impeller::testing::Screenshot> right =
553 GTEST_SKIP() <<
"making screenshots not supported.";
555 intensity[
i] = CalculateLeftmostIntensity(right.get());
556 ASSERT_NE(intensity[
i].
value, 0);
558 for (
int i = 1;
i < 5; ++
i) {
559 EXPECT_TRUE(intensity[
i].
x - intensity[
i - 1].
x == 1 ||
563 EXPECT_EQ(intensity[4].
x - intensity[0].
x, 1);
574 builder.
Scale(scalar, scalar);
585 return builder.
Build();
588 LeftmostIntensity intensity[5];
589 Scalar offset_fraction = 0.25 / scalar;
590 for (
int i = 0;
i <= 4; ++
i) {
591 Scalar offset = 10 + (offset_fraction *
i);
592 std::unique_ptr<impeller::testing::Screenshot> right =
595 GTEST_SKIP() <<
"making screenshots not supported.";
597 intensity[
i] = CalculateLeftmostIntensity(right.get());
598 ASSERT_NE(intensity[
i].
value, 0);
600 for (
int i = 1;
i < 5; ++
i) {
601 EXPECT_TRUE(intensity[
i].
x - intensity[
i - 1].
x == 1 ||
605 EXPECT_EQ(intensity[4].
x - intensity[0].
x, 1);
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 Scale(DlScalar sx, DlScalar sy) 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
static std::shared_ptr< DlMaskFilter > Make(DlBlurStyle style, SkScalar sigma, bool respect_ctm=true)
Developer-facing API for rendering anything within the engine.
virtual void DrawPaint(const DlPaint &paint)=0
virtual void DrawCircle(const DlPoint ¢er, DlScalar radius, const DlPaint &paint)=0
virtual void ClipRoundRect(const DlRoundRect &rrect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false)=0
virtual void DrawRoundRect(const DlRoundRect &rrect, const DlPaint &paint)=0
virtual void SaveLayer(const std::optional< DlRect > &bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr, std::optional< int64_t > backdrop_id=std::nullopt)=0
virtual void DrawRect(const DlRect &rect, const DlPaint &paint)=0
virtual void DrawImage(const sk_sp< DlImage > &image, const DlPoint &point, DlImageSampling sampling, const DlPaint *paint=nullptr)=0
virtual void Translate(DlScalar tx, DlScalar ty)=0
virtual void DrawColor(DlColor color, DlBlendMode mode=DlBlendMode::kSrcOver)=0
virtual void Rotate(DlScalar degrees)=0
virtual void DrawDashedLine(const DlPoint &p0, const DlPoint &p1, DlScalar on_length, DlScalar off_length, const DlPaint &paint)=0
virtual void ClipPath(const DlPath &path, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false)=0
virtual void Scale(DlScalar sx, DlScalar sy)=0
static std::shared_ptr< DlImageFilter > MakeMatrix(const DlMatrix &matrix, DlImageSampling sampling)
DlPaint & setColor(DlColor color)
DlPaint & setAntiAlias(bool isAntiAlias)
DlPaint & setStrokeCap(DlStrokeCap cap)
DlPaint & setStrokeWidth(float width)
DlPaint & setAlpha(uint8_t alpha)
DlPaint & setMaskFilter(std::nullptr_t filter)
DlPaint & setDrawStyle(DlDrawStyle style)
DlPathBuilder & LineTo(DlPoint p2)
Draw a line from the current point to the indicated point p2.
static constexpr const DlScalar kArcApproximationMagic
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 & CubicCurveTo(DlPoint cp1, DlPoint cp2, DlPoint p2)
Draw a cubic bezier curve from the current point to the indicated point p2, using the indicated point...
virtual const uint8_t * GetBytes() const =0
Access raw data of the screenshot.
virtual size_t GetHeight() const =0
Returns the height of the image in pixels.
virtual size_t GetWidth() const =0
Returns the width of the image in pixels.
FlutterDesktopBinaryReply callback
#define FML_CHECK(condition)
Vector2 blur_radius
Blur radius in source pixels based on scaled_sigma.
std::array< MockImage, 3 > images
bool RenderTextInCanvasSkia(DlCanvas *canvas, const std::string &text, const std::string_view &font_fixture, DlPoint position, const TextRenderOptions &options)
TEST_P(DlGoldenTest, TextBlurMaskFilterRespectCTM)
impeller::Scalar DlScalar
@ kButt
no stroke extension
@ kStroke
strokes boundary of shapes
@ kNormal
fuzzy inside and outside
impeller::Vector2 DlVector2
#define INSTANTIATE_PLAYGROUND_SUITE(playground)
static constexpr DlColor kMagenta()
static constexpr DlColor kWhite()
static constexpr DlColor kBlue()
static constexpr DlColor kBlack()
static constexpr DlColor kMaroon()
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 kRed()
static constexpr DlColor kGreen()
static constexpr DlColor kCyan()
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 RoundRect MakeRectRadius(const Rect &rect, Scalar radius)
static RoundRect MakeNinePatch(const Rect &rect, Scalar left, Scalar top, Scalar right, Scalar bottom)
static RoundRect MakeOval(const Rect &rect)
static RoundRect MakeRectXY(const Rect &rect, Scalar x_radius, Scalar y_radius)
static constexpr TPoint< Type > MakeXY(Type x, Type y)
constexpr TPoint< T > GetLeftTop() const
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
constexpr TPoint< T > GetRightBottom() const
constexpr TPoint< T > GetLeftBottom() const
constexpr TPoint< T > GetRightTop() const
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)