Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Convert a dart:ui Paint to a DisplayList DlPaint#36629

Merged
auto-submit[bot] merged 1 commit intoflutter:mainfrom
jason-simmons:dl_convert_to_dlpaint
Oct 7, 2022
Merged

Convert a dart:ui Paint to a DisplayList DlPaint#36629
auto-submit[bot] merged 1 commit intoflutter:mainfrom
jason-simmons:dl_convert_to_dlpaint

Conversation

@jason-simmons
Copy link
Member

No description provided.

@jason-simmons jason-simmons requested a review from flar October 5, 2022 23:24
Copy link
Contributor

@flar flar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments about avoiding attribute->get()->shared() duplicate copies, but otherwise looks good...

if (!Dart_IsNull(color_filter)) {
ColorFilter* decoded =
tonic::DartConverter<ColorFilter*>::FromDart(color_filter);
paint.setColorFilter(decoded->dl_filter());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version of this in the SkPaint method will assume that filter() returns a valid shared ptr (it calls ->skia_object() without any null check). The dl_filter() method will protect against nullptr which seems to be unnecessary based on how the SkPaint version is written, but it will also de-share the pointer - returning DlCF* - which then needs to be re-shared in the setColorFilter method. I think overall that "paint.setColorFilter(decoded->filter())" would be faster as it can transfer the shared ptr without de/re-sharing it and it avoids what seems like an unnecessary null check.

if (Shader* decoded = tonic::DartConverter<Shader*>::FromDart(shader)) {
auto sampling =
ImageFilter::SamplingFromIndex(uint_data[kFilterQualityIndex]);
paint.setColorSource(decoded->shader(sampling).get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove .get() - it un-shares the shared_ptr which requires the method to recreate a shared version. Better to transfer the shared version directly.

if (!Dart_IsNull(image_filter)) {
ImageFilter* decoded =
tonic::DartConverter<ImageFilter*>::FromDart(image_filter);
paint.setImageFilter(decoded->dl_filter());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment to the CF code - probably better to use decoded->filter()

double sigma = float_data[kMaskFilterSigmaIndex];
DlBlurMaskFilter dl_filter(blur_style, sigma);
if (dl_filter.skia_object()) {
paint.setMaskFilter(&dl_filter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a copy. You could construct a shared_ptr using make_shared instead and then just allow that shared ref to be adopted into the paint.

return true;
}

void Paint::toDlPaint(DlPaint& paint) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting a difference here...

The SkPaint version returns a pointer that can be null if there is an issue. That feature doesn't really help in the current usage in text_style, it was mainly useful in the way that Canvas used to use it - and since we deleted the Sk code from the Canvas object, we're left with "might have a null value if the Dart object was null" that doesn't seem to apply to the use in text_style.

So, this call signature makes sense. I just wanted to double check that I went through all of the proper decision-vetting on that difference.

@jason-simmons jason-simmons force-pushed the dl_convert_to_dlpaint branch 3 times, most recently from e43f531 to d7faf6e Compare October 6, 2022 19:48
@jason-simmons
Copy link
Member Author

Done - PTAL

Copy link
Contributor

@flar flar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, modulo suggestion on using == for attribute comparisons.


ASSERT_EQ(dl_paint.getBlendMode(), DlBlendMode::kModulate);
ASSERT_EQ(static_cast<uint32_t>(dl_paint.getColor()), 0x11223344u);
std::shared_ptr<const DlColorFilter> color_filter = dl_paint.getColorFilter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that DlColorFilter and DlMaskFilter support ==. There are also Equals() and NotEquals() templates in dl_comparable.h that make sure the objects are compared regardless of whether they are pointers, shared_ptrs, const or non-const, or you could just do == on the dereferenced pointers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test to compare the filter objects

@jason-simmons jason-simmons force-pushed the dl_convert_to_dlpaint branch from d7faf6e to 44a8d2e Compare October 6, 2022 22:04

ASSERT_EQ(dl_paint.getBlendMode(), DlBlendMode::kModulate);
ASSERT_EQ(static_cast<uint32_t>(dl_paint.getColor()), 0x11223344u);
ASSERT_EQ(*dl_paint.getColorFilter()->asBlend(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need asBlend() and asBlur() here. The base objects support a type-safe ==.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jason-simmons jason-simmons force-pushed the dl_convert_to_dlpaint branch from 44a8d2e to d033b70 Compare October 6, 2022 23:54
@jason-simmons jason-simmons added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 7, 2022
@auto-submit auto-submit bot merged commit 38da11c into flutter:main Oct 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants