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

Commit 590babc

Browse files
authored
[Impeller] libImpeller: Allow creating image color sources. (#55754)
Fixes flutter/flutter#156360 This was missed in the earlier bringup. cc @lyceel I did not expose the solid color source since (as @jonahwilliams [pointed out](flutter/flutter#156360 (comment))) all it does it [clear the current color source and set the color on the paint](https://github.com/flutter/engine/blob/72dca1bca3abe9e74ff74b35404f5c0f0dffe3bb/display_list/dl_builder.cc#L206).
1 parent 3a95d6e commit 590babc

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

impeller/toolkit/interop/color_source.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ ScopedObject<ColorSource> ColorSource::MakeSweepGradient(
102102
return Create<ColorSource>(std::move(dl_filter));
103103
}
104104

105+
ScopedObject<ColorSource> ColorSource::MakeImage(
106+
const Texture& image,
107+
flutter::DlTileMode horizontal_tile_mode,
108+
flutter::DlTileMode vertical_tile_mode,
109+
flutter::DlImageSampling sampling,
110+
const Matrix& transformation) {
111+
const auto sk_transformation = ToSkMatrix(transformation);
112+
auto dl_filter =
113+
std::make_shared<flutter::DlImageColorSource>(image.MakeImage(), //
114+
horizontal_tile_mode, //
115+
vertical_tile_mode, //
116+
sampling, //
117+
&sk_transformation //
118+
);
119+
return Create<ColorSource>(std::move(dl_filter));
120+
}
121+
105122
ColorSource::ColorSource(std::shared_ptr<flutter::DlColorSource> source)
106123
: color_source_(std::move(source)) {}
107124

impeller/toolkit/interop/color_source.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "impeller/toolkit/interop/formats.h"
1515
#include "impeller/toolkit/interop/impeller.h"
1616
#include "impeller/toolkit/interop/object.h"
17+
#include "impeller/toolkit/interop/texture.h"
1718

1819
namespace impeller::interop {
1920

@@ -56,6 +57,13 @@ class ColorSource final
5657
flutter::DlTileMode tile_mode,
5758
const Matrix& transformation);
5859

60+
static ScopedObject<ColorSource> MakeImage(
61+
const Texture& image,
62+
flutter::DlTileMode horizontal_tile_mode,
63+
flutter::DlTileMode vertical_tile_mode,
64+
flutter::DlImageSampling sampling,
65+
const Matrix& transformation);
66+
5967
explicit ColorSource(std::shared_ptr<flutter::DlColorSource> source);
6068

6169
~ColorSource() override;

impeller/toolkit/interop/impeller.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,24 @@ ImpellerColorSource ImpellerColorSourceCreateSweepGradientNew(
778778
.Leak();
779779
}
780780

781+
IMPELLER_EXTERN_C
782+
ImpellerColorSource ImpellerColorSourceCreateImageNew(
783+
ImpellerTexture image,
784+
ImpellerTileMode horizontal_tile_mode,
785+
ImpellerTileMode vertical_tile_mode,
786+
ImpellerTextureSampling sampling,
787+
const ImpellerMatrix* transformation) {
788+
return ColorSource::MakeImage(
789+
*GetPeer(image), //
790+
ToDisplayListType(horizontal_tile_mode), //
791+
ToDisplayListType(vertical_tile_mode), //
792+
ToDisplayListType(sampling), //
793+
transformation == nullptr ? Matrix{}
794+
: ToImpellerType(*transformation) //
795+
)
796+
.Leak();
797+
}
798+
781799
IMPELLER_EXTERN_C
782800
void ImpellerColorFilterRetain(ImpellerColorFilter color_filter) {
783801
ObjectBase::SafeRetain(color_filter);

impeller/toolkit/interop/impeller.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,14 @@ ImpellerColorSourceCreateSweepGradientNew(
552552
ImpellerTileMode tile_mode,
553553
const ImpellerMatrix* IMPELLER_NULLABLE transformation);
554554

555+
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerColorSource IMPELLER_NULLABLE
556+
ImpellerColorSourceCreateImageNew(
557+
ImpellerTexture IMPELLER_NONNULL image,
558+
ImpellerTileMode horizontal_tile_mode,
559+
ImpellerTileMode vertical_tile_mode,
560+
ImpellerTextureSampling sampling,
561+
const ImpellerMatrix* IMPELLER_NULLABLE transformation);
562+
555563
//------------------------------------------------------------------------------
556564
// Color Filters
557565
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)