[Impeller] libImpeller: Allow appending to the transformation stack. (flutter/engine#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 https://github.com/flutter/flutter/issues/156604
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ class DisplayListBuilder final
|
||||
|
||||
void SetTransform(const Matrix& matrix);
|
||||
|
||||
void Transform(const Matrix& matrix);
|
||||
|
||||
void ResetTransform();
|
||||
|
||||
uint32_t GetSaveCount() const;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()));
|
||||
|
||||
Reference in New Issue
Block a user