Detect simpler quad type when possible
Previously, providing 4 SkPoints to draw as a quad meant the tessellator
used either kStandard or kPerspective, and couldn't use the faster
kRect and kRectilinear options. This had been simple and under the
assumption that most provided quad points would be from BSP splitting.
However, to emulate SkiaRenderer's required content_area clipping, the
content area is sent as the srcRect and the original geometry is stored
in the SkPoints. In these situations, the it is easy to detect that the
4 points make a rectangle and then relying on the CTMs matrix for the
quad type is perfectly safe.
Change-Id: Ib2b599fa9c82d275519e17cf813713806a565afe
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206908
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/GrQuad.cpp b/src/gpu/GrQuad.cpp
index 3032307..c741827 100644
--- a/src/gpu/GrQuad.cpp
+++ b/src/gpu/GrQuad.cpp
@@ -200,6 +200,21 @@
}
}
+GrQuadType GrQuadTypeForPoints(const SkPoint pts[4], const SkMatrix& matrix) {
+ if (matrix.hasPerspective()) {
+ return GrQuadType::kPerspective;
+ }
+ // If 'pts' was formed by SkRect::toQuad() and not transformed further, it is safe to use the
+ // quad type derived from 'matrix'. Otherwise don't waste any more time and assume kStandard
+ // (most general 2D quad).
+ if ((pts[0].fY == pts[3].fY && pts[1].fY == pts[2].fY) &&
+ (pts[0].fX == pts[1].fX && pts[2].fX == pts[3].fX)) {
+ return GrQuadTypeForTransformedRect(matrix);
+ } else {
+ return GrQuadType::kStandard;
+ }
+}
+
GrQuad GrQuad::MakeFromRect(const SkRect& rect, const SkMatrix& m) {
Sk4f x, y;
SkMatrix::TypeMask tm = m.getType();