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.
diff --git a/engine/src/flutter/display_list/benchmarking/dl_transform_benchmarks.cc b/engine/src/flutter/display_list/benchmarking/dl_transform_benchmarks.cc
index 568d7fc..201efaf 100644
--- a/engine/src/flutter/display_list/benchmarking/dl_transform_benchmarks.cc
+++ b/engine/src/flutter/display_list/benchmarking/dl_transform_benchmarks.cc
@@ -144,9 +144,6 @@
   virtual void TransformAndClipRect(const TestTransform& transform,
                                     const TestRect& in,
                                     TestRect& out) const = 0;
-  virtual void TransformRectScaleTranslate2D(const TestTransform& transform,
-                                             const TestRect& in,
-                                             TestRect& out) const = 0;
   virtual int CountClippedCorners(const TestTransform& transform,
                                   const TestRect& rect) const = 0;
   virtual void InvertUnchecked(const TestTransform& transform,
@@ -234,13 +231,6 @@
         transform.sk_matrix.mapRect(in.sk_rect, SkApplyPerspectiveClip::kYes);
   }
 
-  void TransformRectScaleTranslate2D(const TestTransform& transform,
-                                     const TestRect& in,
-                                     TestRect& out) const override {
-    out.sk_rect =
-        transform.sk_matrix.mapRect(in.sk_rect, SkApplyPerspectiveClip::kNo);
-  }
-
   int CountClippedCorners(const TestTransform& transform,
                           const TestRect& rect) const {
     SkPoint3 homogenous[4];
@@ -335,16 +325,6 @@
     // clang-format on
   }
 
-  void TransformRectScaleTranslate2D(const TestTransform& transform,
-                                     const TestRect& in,
-                                     TestRect& out) const override {
-    // clang-format off
-    out.sk_rect = transform.sk_m44
-                      .asM33()
-                      .mapRect(in.sk_rect, SkApplyPerspectiveClip::kNo);
-    // clang-format on
-  }
-
   int CountClippedCorners(const TestTransform& transform,
                           const TestRect& rect) const {
     SkPoint3 homogenous[4];
@@ -456,13 +436,6 @@
         in.impeller_rect.TransformAndClipBounds(transform.impeller_matrix);
   }
 
-  void TransformRectScaleTranslate2D(const TestTransform& transform,
-                                     const TestRect& in,
-                                     TestRect& out) const override {
-    out.impeller_rect = in.impeller_rect.TransformBoundsTranslateScale2D(
-        transform.impeller_matrix);
-  }
-
   int CountClippedCorners(const TestTransform& transform,
                           const TestRect& rect) const {
     auto corners = rect.impeller_rect.GetPoints();
@@ -749,19 +722,6 @@
   }
 }
 
-static void BM_TransformRectScaleTranslate2D(benchmark::State& state,
-                                             AdapterType type,
-                                             const SetupFunction& setup) {
-  auto adapter = GetAdapter(type);
-  TestTransform transform;
-  TestRect rect, result;
-  adapter->InitRectLTRB(rect, 100, 100, 200, 200);
-  setup(adapter.get(), transform, &rect);
-  while (state.KeepRunning()) {
-    adapter->TransformRectScaleTranslate2D(transform, rect, result);
-  }
-}
-
 static void BM_InvertUnchecked(benchmark::State& state,
                                AdapterType type,
                                const SetupFunction& setup) {
@@ -887,9 +847,4 @@
 BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformAndClipRect, PerspectiveClipThree);
 BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformAndClipRect, PerspectiveClipFour);
 
-BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformRectScaleTranslate2D, Identity);
-BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformRectScaleTranslate2D, Translate);
-BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformRectScaleTranslate2D, Scale);
-BENCHMARK_CAPTURE_ALL_SETUP(BM_TransformRectScaleTranslate2D, ScaleTranslate);
-
 }  // namespace flutter
diff --git a/engine/src/flutter/impeller/geometry/matrix.h b/engine/src/flutter/impeller/geometry/matrix.h
index 18b6a21..90598fe 100644
--- a/engine/src/flutter/impeller/geometry/matrix.h
+++ b/engine/src/flutter/impeller/geometry/matrix.h
@@ -35,31 +35,6 @@
 ///                 * This is NOT the same as OpenGL! Be careful.
 ///               * NDC origin is at (0.0f, 0.0f, 0.5f).
 struct Matrix {
-  /// The transform complexity type for the matrix, targeting the primary
-  /// optimizable operations that rectangle transforms can take advantage
-  /// of.
-  ///
-  /// The caller can query the type of the matrix for either 3D or 2D
-  /// operations with the 2D query only considering the entries that
-  /// are involved in transforming 2D coordinates.
-  ///
-  /// @see Classify
-  /// @see Classify2D
-  enum class Type {
-    /// The matrix contains only values that can scale and transform
-    /// coordinates. An Identity matrix also qualifies as kScaleTranslate.
-    kScaleTranslate,
-
-    /// The matrix contains only values that can perform affine operations
-    /// on the coordinates (no perspective).
-    kAffine,
-
-    /// The matrix contains perspective values that require the most general
-    /// type of transform computations. Any NaN values in the matrix will
-    /// also result in this classification.
-    kGeneral,
-  };
-
   union {
     Scalar m[16];
     Scalar e[4][4];
@@ -260,35 +235,6 @@
     // clang-format on
   }
 
-  /// Classify the |Type| of matrix for a 3D operation on coordinates of the
-  /// form {x,y,z,1}.
-  constexpr Type Classify() const {
-    if (m[3] == 0.0f && m[7] == 0.0f && m[11] == 0.0f && m[15] == 1.0f) {
-      if (m[1] == 0.0f && m[2] == 0.0f &&  //
-          m[4] == 0.0f && m[6] == 0.0f &&  //
-          m[8] == 0.0f && m[9] == 0.0f) {
-        return Type::kScaleTranslate;
-      }
-      return Type::kAffine;
-    } else {
-      return Type::kGeneral;
-    }
-  };
-
-  /// Classify the |Type| of matrix for a 2D operation on coordinates of the
-  /// form {x,y,0,1}. Matrix entries that only affect incoming or outgoing
-  /// z values are ignored.
-  constexpr inline Type Classify2D() const {
-    if (m[3] == 0.0f && m[7] == 0.0f && m[15] == 1.0f) {
-      if (m[1] == 0.0f && m[4] == 0.0f) {
-        return Type::kScaleTranslate;
-      }
-      return Type::kAffine;
-    } else {
-      return Type::kGeneral;
-    }
-  };
-
   /// The Matrix without its `w` components (without translation).
   constexpr Matrix Basis() const {
     // clang-format off
diff --git a/engine/src/flutter/impeller/geometry/rect.h b/engine/src/flutter/impeller/geometry/rect.h
index 057c10d..9789d21 100644
--- a/engine/src/flutter/impeller/geometry/rect.h
+++ b/engine/src/flutter/impeller/geometry/rect.h
@@ -437,13 +437,8 @@
   ///         necessary.
   [[nodiscard]] constexpr TRect TransformAndClipBounds(
       const Matrix& transform) const {
-    switch (transform.Classify2D()) {
-      case Matrix::Type::kScaleTranslate:
-        return TransformBoundsTranslateScale2D(transform);
-      case Matrix::Type::kAffine:
-        return TransformBounds(transform);
-      case Matrix::Type::kGeneral:
-        break;
+    if (!transform.HasPerspective2D()) {
+      return TransformBounds(transform);
     }
 
     if (IsEmpty()) {
@@ -475,14 +470,6 @@
   /// @brief  Creates a new bounding box that contains this transformed
   ///         rectangle.
   [[nodiscard]] constexpr TRect TransformBounds(const Matrix& transform) const {
-    switch (transform.Classify2D()) {
-      case Matrix::Type::kScaleTranslate:
-        return TransformBoundsTranslateScale2D(transform);
-      case Matrix::Type::kAffine:
-      case Matrix::Type::kGeneral:
-        break;
-    }
-
     if (IsEmpty()) {
       return {};
     }
@@ -494,33 +481,6 @@
     FML_UNREACHABLE();
   }
 
-  /// @brief  Creates a new bounding box that contains this transformed
-  ///         rectangle.
-  ///
-  /// [transform] must be a translate-scale only matrix.
-  [[nodiscard]] constexpr TRect TransformBoundsTranslateScale2D(
-      const Matrix& transform) const {
-    if (IsEmpty()) {
-      return {};
-    }
-
-    Scalar tx = transform.m[12];
-    Scalar ty = transform.m[13];
-    Scalar sx = transform.m[0];
-    Scalar sy = transform.m[5];
-
-    Scalar l = GetLeft() * sx + tx;
-    Scalar r = GetRight() * sx + tx;
-    Scalar t = GetTop() * sy + ty;
-    Scalar b = GetBottom() * sy + ty;
-
-    return TRect<float>::MakeLTRB(std::min(l, r),  //
-                                  std::min(t, b),  //
-                                  std::max(l, r),  //
-                                  std::max(t, b)   //
-    );
-  }
-
   /// @brief  Constructs a Matrix that will map all points in the coordinate
   ///         space of the rectangle into a new normalized coordinate space
   ///         where the upper left corner of the rectangle maps to (0, 0)
diff --git a/engine/src/flutter/impeller/geometry/rect_unittests.cc b/engine/src/flutter/impeller/geometry/rect_unittests.cc
index 24b6601..cb33c7d 100644
--- a/engine/src/flutter/impeller/geometry/rect_unittests.cc
+++ b/engine/src/flutter/impeller/geometry/rect_unittests.cc
@@ -3243,25 +3243,5 @@
   }
 }
 
-TEST(RectTest, TransformBoundsTranslateScale) {
-  std::vector<Matrix> matrices = {
-      Matrix::MakeTranslateScale({2, 2, 1}, {10, 10, 0}),
-      Matrix::MakeTranslateScale({-2, 2, 1}, {10, 10, 0}),
-      Matrix::MakeTranslateScale({2, -2, 1}, {10, 10, 0}),
-      Matrix::MakeTranslateScale({-2, -2, 1}, {10, 10, 0}),
-  };
-  std::vector<Rect> rects = {
-      Rect::MakeLTRB(0, 0, 10, 10), Rect::MakeLTRB(100, 100, 110, 110),
-      Rect::MakeLTRB(0, 0, 0, 0), Rect::MakeLTRB(-10, -10, 10, 10)};
-
-  for (auto i = 0u; i < matrices.size(); i++) {
-    for (auto j = 0u; j < rects.size(); j++) {
-      EXPECT_EQ(rects[j].TransformBounds(matrices[i]),
-                rects[j].TransformBoundsTranslateScale2D(matrices[i]))
-          << rects[j] << " * " << matrices[i];
-    }
-  }
-}
-
 }  // namespace testing
 }  // namespace impeller