[Impeller] libImpeller: Allow creating image color sources. (flutter/engine#55754)

Fixes https://github.com/flutter/flutter/issues/156360

This was missed in the earlier bringup.

cc @lyceel I did not expose the solid color source since (as @jonahwilliams [pointed out](https://github.com/flutter/flutter/issues/156360#issuecomment-2398005436)) all it does it [clear the current color source and set the color on the paint](a01daf5555/display_list/dl_builder.cc (L206)).
This commit is contained in:
Chinmay Garde
2024-10-09 13:11:49 -07:00
committed by GitHub
parent 5c2733f600
commit 57e4161fd8
4 changed files with 51 additions and 0 deletions

View File

@@ -102,6 +102,23 @@ ScopedObject<ColorSource> ColorSource::MakeSweepGradient(
return Create<ColorSource>(std::move(dl_filter));
}
ScopedObject<ColorSource> ColorSource::MakeImage(
const Texture& image,
flutter::DlTileMode horizontal_tile_mode,
flutter::DlTileMode vertical_tile_mode,
flutter::DlImageSampling sampling,
const Matrix& transformation) {
const auto sk_transformation = ToSkMatrix(transformation);
auto dl_filter =
std::make_shared<flutter::DlImageColorSource>(image.MakeImage(), //
horizontal_tile_mode, //
vertical_tile_mode, //
sampling, //
&sk_transformation //
);
return Create<ColorSource>(std::move(dl_filter));
}
ColorSource::ColorSource(std::shared_ptr<flutter::DlColorSource> source)
: color_source_(std::move(source)) {}

View File

@@ -14,6 +14,7 @@
#include "impeller/toolkit/interop/formats.h"
#include "impeller/toolkit/interop/impeller.h"
#include "impeller/toolkit/interop/object.h"
#include "impeller/toolkit/interop/texture.h"
namespace impeller::interop {
@@ -56,6 +57,13 @@ class ColorSource final
flutter::DlTileMode tile_mode,
const Matrix& transformation);
static ScopedObject<ColorSource> MakeImage(
const Texture& image,
flutter::DlTileMode horizontal_tile_mode,
flutter::DlTileMode vertical_tile_mode,
flutter::DlImageSampling sampling,
const Matrix& transformation);
explicit ColorSource(std::shared_ptr<flutter::DlColorSource> source);
~ColorSource() override;

View File

@@ -778,6 +778,24 @@ ImpellerColorSource ImpellerColorSourceCreateSweepGradientNew(
.Leak();
}
IMPELLER_EXTERN_C
ImpellerColorSource ImpellerColorSourceCreateImageNew(
ImpellerTexture image,
ImpellerTileMode horizontal_tile_mode,
ImpellerTileMode vertical_tile_mode,
ImpellerTextureSampling sampling,
const ImpellerMatrix* transformation) {
return ColorSource::MakeImage(
*GetPeer(image), //
ToDisplayListType(horizontal_tile_mode), //
ToDisplayListType(vertical_tile_mode), //
ToDisplayListType(sampling), //
transformation == nullptr ? Matrix{}
: ToImpellerType(*transformation) //
)
.Leak();
}
IMPELLER_EXTERN_C
void ImpellerColorFilterRetain(ImpellerColorFilter color_filter) {
ObjectBase::SafeRetain(color_filter);

View File

@@ -552,6 +552,14 @@ ImpellerColorSourceCreateSweepGradientNew(
ImpellerTileMode tile_mode,
const ImpellerMatrix* IMPELLER_NULLABLE transformation);
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerColorSource IMPELLER_NULLABLE
ImpellerColorSourceCreateImageNew(
ImpellerTexture IMPELLER_NONNULL image,
ImpellerTileMode horizontal_tile_mode,
ImpellerTileMode vertical_tile_mode,
ImpellerTextureSampling sampling,
const ImpellerMatrix* IMPELLER_NULLABLE transformation);
//------------------------------------------------------------------------------
// Color Filters
//------------------------------------------------------------------------------