Skip to content

Commit 1feda71

Browse files
authored
Revert "[Impeller] Optimize scale translate rectangle transforms" (#176061)
Reverts flutter/flutter#171841 There appear to have been some golden file changes that disappeared as the change was further tested and are now causing problems.
1 parent 5e146d4 commit 1feda71

File tree

4 files changed

+2
-161
lines changed

4 files changed

+2
-161
lines changed

engine/src/flutter/display_list/benchmarking/dl_transform_benchmarks.cc

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ class TransformAdapter {
144144
virtual void TransformAndClipRect(const TestTransform& transform,
145145
const TestRect& in,
146146
TestRect& out) const = 0;
147-
virtual void TransformRectScaleTranslate2D(const TestTransform& transform,
148-
const TestRect& in,
149-
TestRect& out) const = 0;
150147
virtual int CountClippedCorners(const TestTransform& transform,
151148
const TestRect& rect) const = 0;
152149
virtual void InvertUnchecked(const TestTransform& transform,
@@ -234,13 +231,6 @@ class SkMatrixAdapter : public SkiaAdapterBase {
234231
transform.sk_matrix.mapRect(in.sk_rect, SkApplyPerspectiveClip::kYes);
235232
}
236233

237-
void TransformRectScaleTranslate2D(const TestTransform& transform,
238-
const TestRect& in,
239-
TestRect& out) const override {
240-
out.sk_rect =
241-
transform.sk_matrix.mapRect(in.sk_rect, SkApplyPerspectiveClip::kNo);
242-
}
243-
244234
int CountClippedCorners(const TestTransform& transform,
245235
const TestRect& rect) const {
246236
SkPoint3 homogenous[4];
@@ -335,16 +325,6 @@ class SkM44Adapter : public SkiaAdapterBase {
335325
// clang-format on
336326
}
337327

338-
void TransformRectScaleTranslate2D(const TestTransform& transform,
339-
const TestRect& in,
340-
TestRect& out) const override {
341-
// clang-format off
342-
out.sk_rect = transform.sk_m44
343-
.asM33()
344-
.mapRect(in.sk_rect, SkApplyPerspectiveClip::kNo);
345-
// clang-format on
346-
}
347-
348328
int CountClippedCorners(const TestTransform& transform,
349329
const TestRect& rect) const {
350330
SkPoint3 homogenous[4];
@@ -456,13 +436,6 @@ class ImpellerMatrixAdapter : public TransformAdapter {
456436
in.impeller_rect.TransformAndClipBounds(transform.impeller_matrix);
457437
}
458438

459-
void TransformRectScaleTranslate2D(const TestTransform& transform,
460-
const TestRect& in,
461-
TestRect& out) const override {
462-
out.impeller_rect = in.impeller_rect.TransformBoundsTranslateScale2D(
463-
transform.impeller_matrix);
464-
}
465-
466439
int CountClippedCorners(const TestTransform& transform,
467440
const TestRect& rect) const {
468441
auto corners = rect.impeller_rect.GetPoints();
@@ -749,19 +722,6 @@ static void BM_TransformAndClipRect(benchmark::State& state,
749722
}
750723
}
751724

752-
static void BM_TransformRectScaleTranslate2D(benchmark::State& state,
753-
AdapterType type,
754-
const SetupFunction& setup) {
755-
auto adapter = GetAdapter(type);
756-
TestTransform transform;
757-
TestRect rect, result;
758-
adapter->InitRectLTRB(rect, 100, 100, 200, 200);
759-
setup(adapter.get(), transform, &rect);
760-
while (state.KeepRunning()) {
761-
adapter->TransformRectScaleTranslate2D(transform, rect, result);
762-
}
763-
}
764-
765725
static void BM_InvertUnchecked(benchmark::State& state,
766726
AdapterType type,
767727
const SetupFunction& setup) {
@@ -887,9 +847,4 @@ BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformAndClipRect, PerspectiveClipTwo);
887847
BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformAndClipRect, PerspectiveClipThree);
888848
BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformAndClipRect, PerspectiveClipFour);
889849

890-
BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformRectScaleTranslate2D, Identity);
891-
BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformRectScaleTranslate2D, Translate);
892-
BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformRectScaleTranslate2D, Scale);
893-
BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformRectScaleTranslate2D, ScaleTranslate);
894-
895850
} // namespace flutter

engine/src/flutter/impeller/geometry/matrix.h

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,6 @@ namespace impeller {
3535
/// * This is NOT the same as OpenGL! Be careful.
3636
/// * NDC origin is at (0.0f, 0.0f, 0.5f).
3737
struct Matrix {
38-
/// The transform complexity type for the matrix, targeting the primary
39-
/// optimizable operations that rectangle transforms can take advantage
40-
/// of.
41-
///
42-
/// The caller can query the type of the matrix for either 3D or 2D
43-
/// operations with the 2D query only considering the entries that
44-
/// are involved in transforming 2D coordinates.
45-
///
46-
/// @see Classify
47-
/// @see Classify2D
48-
enum class Type {
49-
/// The matrix contains only values that can scale and transform
50-
/// coordinates. An Identity matrix also qualifies as kScaleTranslate.
51-
kScaleTranslate,
52-
53-
/// The matrix contains only values that can perform affine operations
54-
/// on the coordinates (no perspective).
55-
kAffine,
56-
57-
/// The matrix contains perspective values that require the most general
58-
/// type of transform computations. Any NaN values in the matrix will
59-
/// also result in this classification.
60-
kGeneral,
61-
};
62-
6338
union {
6439
Scalar m[16];
6540
Scalar e[4][4];
@@ -260,35 +235,6 @@ struct Matrix {
260235
// clang-format on
261236
}
262237

263-
/// Classify the |Type| of matrix for a 3D operation on coordinates of the
264-
/// form {x,y,z,1}.
265-
constexpr Type Classify() const {
266-
if (m[3] == 0.0f && m[7] == 0.0f && m[11] == 0.0f && m[15] == 1.0f) {
267-
if (m[1] == 0.0f && m[2] == 0.0f && //
268-
m[4] == 0.0f && m[6] == 0.0f && //
269-
m[8] == 0.0f && m[9] == 0.0f) {
270-
return Type::kScaleTranslate;
271-
}
272-
return Type::kAffine;
273-
} else {
274-
return Type::kGeneral;
275-
}
276-
};
277-
278-
/// Classify the |Type| of matrix for a 2D operation on coordinates of the
279-
/// form {x,y,0,1}. Matrix entries that only affect incoming or outgoing
280-
/// z values are ignored.
281-
constexpr inline Type Classify2D() const {
282-
if (m[3] == 0.0f && m[7] == 0.0f && m[15] == 1.0f) {
283-
if (m[1] == 0.0f && m[4] == 0.0f) {
284-
return Type::kScaleTranslate;
285-
}
286-
return Type::kAffine;
287-
} else {
288-
return Type::kGeneral;
289-
}
290-
};
291-
292238
/// The Matrix without its `w` components (without translation).
293239
constexpr Matrix Basis() const {
294240
// clang-format off

engine/src/flutter/impeller/geometry/rect.h

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,8 @@ struct TRect {
437437
/// necessary.
438438
[[nodiscard]] constexpr TRect TransformAndClipBounds(
439439
const Matrix& transform) const {
440-
switch (transform.Classify2D()) {
441-
case Matrix::Type::kScaleTranslate:
442-
return TransformBoundsTranslateScale2D(transform);
443-
case Matrix::Type::kAffine:
444-
return TransformBounds(transform);
445-
case Matrix::Type::kGeneral:
446-
break;
440+
if (!transform.HasPerspective2D()) {
441+
return TransformBounds(transform);
447442
}
448443

449444
if (IsEmpty()) {
@@ -475,14 +470,6 @@ struct TRect {
475470
/// @brief Creates a new bounding box that contains this transformed
476471
/// rectangle.
477472
[[nodiscard]] constexpr TRect TransformBounds(const Matrix& transform) const {
478-
switch (transform.Classify2D()) {
479-
case Matrix::Type::kScaleTranslate:
480-
return TransformBoundsTranslateScale2D(transform);
481-
case Matrix::Type::kAffine:
482-
case Matrix::Type::kGeneral:
483-
break;
484-
}
485-
486473
if (IsEmpty()) {
487474
return {};
488475
}
@@ -494,33 +481,6 @@ struct TRect {
494481
FML_UNREACHABLE();
495482
}
496483

497-
/// @brief Creates a new bounding box that contains this transformed
498-
/// rectangle.
499-
///
500-
/// [transform] must be a translate-scale only matrix.
501-
[[nodiscard]] constexpr TRect TransformBoundsTranslateScale2D(
502-
const Matrix& transform) const {
503-
if (IsEmpty()) {
504-
return {};
505-
}
506-
507-
Scalar tx = transform.m[12];
508-
Scalar ty = transform.m[13];
509-
Scalar sx = transform.m[0];
510-
Scalar sy = transform.m[5];
511-
512-
Scalar l = GetLeft() * sx + tx;
513-
Scalar r = GetRight() * sx + tx;
514-
Scalar t = GetTop() * sy + ty;
515-
Scalar b = GetBottom() * sy + ty;
516-
517-
return TRect<float>::MakeLTRB(std::min(l, r), //
518-
std::min(t, b), //
519-
std::max(l, r), //
520-
std::max(t, b) //
521-
);
522-
}
523-
524484
/// @brief Constructs a Matrix that will map all points in the coordinate
525485
/// space of the rectangle into a new normalized coordinate space
526486
/// where the upper left corner of the rectangle maps to (0, 0)

engine/src/flutter/impeller/geometry/rect_unittests.cc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,25 +3243,5 @@ TEST(RectTest, TransformAndClipBounds) {
32433243
}
32443244
}
32453245

3246-
TEST(RectTest, TransformBoundsTranslateScale) {
3247-
std::vector<Matrix> matrices = {
3248-
Matrix::MakeTranslateScale({2, 2, 1}, {10, 10, 0}),
3249-
Matrix::MakeTranslateScale({-2, 2, 1}, {10, 10, 0}),
3250-
Matrix::MakeTranslateScale({2, -2, 1}, {10, 10, 0}),
3251-
Matrix::MakeTranslateScale({-2, -2, 1}, {10, 10, 0}),
3252-
};
3253-
std::vector<Rect> rects = {
3254-
Rect::MakeLTRB(0, 0, 10, 10), Rect::MakeLTRB(100, 100, 110, 110),
3255-
Rect::MakeLTRB(0, 0, 0, 0), Rect::MakeLTRB(-10, -10, 10, 10)};
3256-
3257-
for (auto i = 0u; i < matrices.size(); i++) {
3258-
for (auto j = 0u; j < rects.size(); j++) {
3259-
EXPECT_EQ(rects[j].TransformBounds(matrices[i]),
3260-
rects[j].TransformBoundsTranslateScale2D(matrices[i]))
3261-
<< rects[j] << " * " << matrices[i];
3262-
}
3263-
}
3264-
}
3265-
32663246
} // namespace testing
32673247
} // namespace impeller

0 commit comments

Comments
 (0)