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

Commit 5565cbc

Browse files
authored
[Impeller] libImpeller: Allow appending to the transformation stack. (#56072)
Currently @lyceel has a workaround where they get the transform, create a new one, and call SetTransform. They would like to avoid this. Fixes flutter/flutter#156604
1 parent b4ef615 commit 5565cbc

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

impeller/toolkit/interop/dl_builder.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ void DisplayListBuilder::SetTransform(const Matrix& matrix) {
5555
builder_.SetTransform(&sk_matrix);
5656
}
5757

58+
void DisplayListBuilder::Transform(const Matrix& matrix) {
59+
const auto sk_matrix = SkM44::ColMajor(matrix.m);
60+
builder_.Transform(&sk_matrix);
61+
}
62+
5863
void DisplayListBuilder::ResetTransform() {
5964
builder_.TransformReset();
6065
}

impeller/toolkit/interop/dl_builder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class DisplayListBuilder final
5151

5252
void SetTransform(const Matrix& matrix);
5353

54+
void Transform(const Matrix& matrix);
55+
5456
void ResetTransform();
5557

5658
uint32_t GetSaveCount() const;

impeller/toolkit/interop/impeller.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ void ImpellerDisplayListBuilderSetTransform(ImpellerDisplayListBuilder builder,
167167
GetPeer(builder)->SetTransform(ToImpellerType(*transform));
168168
}
169169

170+
IMPELLER_EXTERN_C
171+
void ImpellerDisplayListBuilderTransform(ImpellerDisplayListBuilder builder,
172+
const ImpellerMatrix* transform) {
173+
GetPeer(builder)->Transform(ToImpellerType(*transform));
174+
}
175+
170176
IMPELLER_EXTERN_C
171177
void ImpellerDisplayListBuilderGetTransform(ImpellerDisplayListBuilder builder,
172178
ImpellerMatrix* out_transform) {

impeller/toolkit/interop/impeller.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,18 @@ void ImpellerDisplayListBuilderTranslate(
16431643
float x_translation,
16441644
float y_translation);
16451645

1646+
//------------------------------------------------------------------------------
1647+
/// @brief Appends the the provided transformation to the transformation
1648+
/// already on the save stack.
1649+
///
1650+
/// @param[in] builder The builder.
1651+
/// @param[in] transform The transform to append.
1652+
///
1653+
IMPELLER_EXPORT
1654+
void ImpellerDisplayListBuilderTransform(
1655+
ImpellerDisplayListBuilder IMPELLER_NONNULL builder,
1656+
const ImpellerMatrix* IMPELLER_NONNULL transform);
1657+
16461658
//------------------------------------------------------------------------------
16471659
/// @brief Clear the transformation on top of the save stack and replace it
16481660
/// with a new value.

impeller/toolkit/interop/impeller_unittests.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ TEST_P(InteropPlaygroundTest, CanDrawRect) {
6969
color = {1.0, 0.0, 0.0, 1.0};
7070
ImpellerPaintSetColor(paint.GetC(), &color);
7171
ImpellerDisplayListBuilderTranslate(builder.GetC(), 110, 210);
72+
ImpellerMatrix scale_transform = {
73+
// clang-format off
74+
2.0, 0.0, 0.0, 0.0, //
75+
0.0, 2.0, 0.0, 0.0, //
76+
0.0, 0.0, 1.0, 0.0, //
77+
0.0, 0.0, 0.0, 1.0, //
78+
// clang-format on
79+
};
80+
ImpellerDisplayListBuilderTransform(builder.GetC(), &scale_transform);
7281
ImpellerDisplayListBuilderDrawRect(builder.GetC(), &rect, paint.GetC());
7382
auto dl = Adopt<DisplayList>(
7483
ImpellerDisplayListBuilderCreateDisplayListNew(builder.GetC()));

0 commit comments

Comments
 (0)