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
5 changes: 5 additions & 0 deletions impeller/toolkit/interop/dl_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ void DisplayListBuilder::SetTransform(const Matrix& matrix) {
builder_.SetTransform(&sk_matrix);
}

void DisplayListBuilder::Transform(const Matrix& matrix) {
const auto sk_matrix = SkM44::ColMajor(matrix.m);
builder_.Transform(&sk_matrix);
}

void DisplayListBuilder::ResetTransform() {
builder_.TransformReset();
}
Expand Down
2 changes: 2 additions & 0 deletions impeller/toolkit/interop/dl_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class DisplayListBuilder final

void SetTransform(const Matrix& matrix);

void Transform(const Matrix& matrix);

void ResetTransform();

uint32_t GetSaveCount() const;
Expand Down
6 changes: 6 additions & 0 deletions impeller/toolkit/interop/impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ void ImpellerDisplayListBuilderSetTransform(ImpellerDisplayListBuilder builder,
GetPeer(builder)->SetTransform(ToImpellerType(*transform));
}

IMPELLER_EXTERN_C
void ImpellerDisplayListBuilderTransform(ImpellerDisplayListBuilder builder,
const ImpellerMatrix* transform) {
GetPeer(builder)->Transform(ToImpellerType(*transform));
}

IMPELLER_EXTERN_C
void ImpellerDisplayListBuilderGetTransform(ImpellerDisplayListBuilder builder,
ImpellerMatrix* out_transform) {
Expand Down
12 changes: 12 additions & 0 deletions impeller/toolkit/interop/impeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,18 @@ void ImpellerDisplayListBuilderTranslate(
float x_translation,
float y_translation);

//------------------------------------------------------------------------------
/// @brief Appends the the provided transformation to the transformation
/// already on the save stack.
///
/// @param[in] builder The builder.
/// @param[in] transform The transform to append.
///
IMPELLER_EXPORT
void ImpellerDisplayListBuilderTransform(
ImpellerDisplayListBuilder IMPELLER_NONNULL builder,
const ImpellerMatrix* IMPELLER_NONNULL transform);

//------------------------------------------------------------------------------
/// @brief Clear the transformation on top of the save stack and replace it
/// with a new value.
Expand Down
9 changes: 9 additions & 0 deletions impeller/toolkit/interop/impeller_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ TEST_P(InteropPlaygroundTest, CanDrawRect) {
color = {1.0, 0.0, 0.0, 1.0};
ImpellerPaintSetColor(paint.GetC(), &color);
ImpellerDisplayListBuilderTranslate(builder.GetC(), 110, 210);
ImpellerMatrix scale_transform = {
// clang-format off
2.0, 0.0, 0.0, 0.0, //
0.0, 2.0, 0.0, 0.0, //
0.0, 0.0, 1.0, 0.0, //
0.0, 0.0, 0.0, 1.0, //
// clang-format on
};
ImpellerDisplayListBuilderTransform(builder.GetC(), &scale_transform);
ImpellerDisplayListBuilderDrawRect(builder.GetC(), &rect, paint.GetC());
auto dl = Adopt<DisplayList>(
ImpellerDisplayListBuilderCreateDisplayListNew(builder.GetC()));
Expand Down