Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,17 @@ void Canvas::DrawPaint(const Paint& paint) {
bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
Scalar corner_radius,
const Paint& paint) {
// TODO(114184): This should return false when the paint's ColorSource is not
// color.
if (!paint.mask_blur_descriptor.has_value() ||
paint.mask_blur_descriptor->style != FilterContents::BlurStyle::kNormal ||
if (paint.color_source == nullptr ||
paint.color_source_type != Paint::ColorSourceType::kColor ||
paint.style != Paint::Style::kFill) {
return false;
}

if (!paint.mask_blur_descriptor.has_value() ||
paint.mask_blur_descriptor->style != FilterContents::BlurStyle::kNormal) {
return false;
}

Paint new_paint = paint;

// For symmetrically mask blurred solid RRects, absorb the mask blur and use
Expand Down
11 changes: 11 additions & 0 deletions impeller/aiks/paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ struct Paint {
kStroke,
};

enum class ColorSourceType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like with the enum + closure that the current color source abstraction is stretched a little thin. Perhaps we should collect both into a new object on paint?

I'm not sure where we are on re-using DLtypes but that seems like the best candidate

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree and have some ideas about this -- mind if I resolve it in a followup patch? I think it's time we wrap up all these factories in setColorSource and ditch the two-step conversion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine with me!

kColor,
kImage,
kLinearGradient,
kRadialGradient,
kConicalGradient,
kSweepGradient,
kRuntimeEffect,
};

struct MaskBlurDescriptor {
FilterContents::BlurStyle style;
Sigma sigma;
Expand All @@ -48,6 +58,7 @@ struct Paint {

Color color = Color::Black();
std::optional<ColorSourceProc> color_source;
ColorSourceType color_source_type = ColorSourceType::kColor;

Scalar stroke_width = 0.0;
Cap stroke_cap = Cap::kButt;
Expand Down
57 changes: 44 additions & 13 deletions impeller/display_list/display_list_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,23 +320,58 @@ static void ConvertStops(T* gradient,
}
}

static std::optional<Paint::ColorSourceType> ToColorSourceType(
flutter::DlColorSourceType type) {
switch (type) {
case flutter::DlColorSourceType::kColor:
return Paint::ColorSourceType::kColor;
case flutter::DlColorSourceType::kImage:
return Paint::ColorSourceType::kImage;
case flutter::DlColorSourceType::kLinearGradient:
return Paint::ColorSourceType::kLinearGradient;
case flutter::DlColorSourceType::kRadialGradient:
return Paint::ColorSourceType::kRadialGradient;
case flutter::DlColorSourceType::kConicalGradient:
return Paint::ColorSourceType::kConicalGradient;
case flutter::DlColorSourceType::kSweepGradient:
return Paint::ColorSourceType::kSweepGradient;
case flutter::DlColorSourceType::kRuntimeEffect:
return Paint::ColorSourceType::kRuntimeEffect;
case flutter::DlColorSourceType::kUnknown:
return std::nullopt;
}
}

// |flutter::Dispatcher|
void DisplayListDispatcher::setColorSource(
const flutter::DlColorSource* source) {
if (!source) {
paint_.color_source = std::nullopt;
paint_.color_source_type = Paint::ColorSourceType::kColor;
return;
}

switch (source->type()) {
case flutter::DlColorSourceType::kColor: {
std::optional<Paint::ColorSourceType> type =
ToColorSourceType(source->type());

if (!type.has_value()) {
FML_LOG(ERROR) << "Requested ColorSourceType::kUnknown";
paint_.color_source = std::nullopt;
paint_.color_source_type = Paint::ColorSourceType::kColor;
return;
}

paint_.color_source_type = type.value();

switch (type.value()) {
case Paint::ColorSourceType::kColor: {
const flutter::DlColorColorSource* color = source->asColor();
paint_.color_source = std::nullopt;
setColor(color->color());
FML_DCHECK(color);
return;
}
case flutter::DlColorSourceType::kLinearGradient: {
case Paint::ColorSourceType::kLinearGradient: {
const flutter::DlLinearGradientColorSource* linear =
source->asLinearGradient();
FML_DCHECK(linear);
Expand All @@ -360,7 +395,7 @@ void DisplayListDispatcher::setColorSource(
};
return;
}
case flutter::DlColorSourceType::kRadialGradient: {
case Paint::ColorSourceType::kRadialGradient: {
const flutter::DlRadialGradientColorSource* radialGradient =
source->asRadialGradient();
FML_DCHECK(radialGradient);
Expand All @@ -384,7 +419,7 @@ void DisplayListDispatcher::setColorSource(
};
return;
}
case flutter::DlColorSourceType::kSweepGradient: {
case Paint::ColorSourceType::kSweepGradient: {
const flutter::DlSweepGradientColorSource* sweepGradient =
source->asSweepGradient();
FML_DCHECK(sweepGradient);
Expand All @@ -411,7 +446,7 @@ void DisplayListDispatcher::setColorSource(
};
return;
}
case flutter::DlColorSourceType::kImage: {
case Paint::ColorSourceType::kImage: {
const flutter::DlImageColorSource* image_color_source = source->asImage();
FML_DCHECK(image_color_source &&
image_color_source->image()->impeller_texture());
Expand All @@ -431,7 +466,7 @@ void DisplayListDispatcher::setColorSource(
};
return;
}
case flutter::DlColorSourceType::kRuntimeEffect: {
case Paint::ColorSourceType::kRuntimeEffect: {
const flutter::DlRuntimeEffectColorSource* runtime_effect_color_source =
source->asRuntimeEffect();
auto runtime_stage =
Expand Down Expand Up @@ -466,14 +501,10 @@ void DisplayListDispatcher::setColorSource(
};
return;
}
case flutter::DlColorSourceType::kConicalGradient:
case flutter::DlColorSourceType::kUnknown:
case Paint::ColorSourceType::kConicalGradient:
UNIMPLEMENTED;
break;
}

// Needs https://github.com/flutter/flutter/issues/95434
UNIMPLEMENTED;
}

static std::optional<Paint::ColorFilterProc> ToColorFilterProc(
Expand Down Expand Up @@ -509,7 +540,7 @@ static std::optional<Paint::ColorFilterProc> ToColorFilterProc(
return ColorFilterContents::MakeLinearToSrgbFilter({std::move(input)});
};
case flutter::DlColorFilterType::kUnknown:
FML_LOG(ERROR) << "requested DlColorFilterType::kUnknown";
FML_LOG(ERROR) << "Requested DlColorFilterType::kUnknown";
UNIMPLEMENTED;
}
return std::nullopt;
Expand Down