Clean up GrQuad ctors
Refactor Sk4f transformations into reusable internal function.
Switches the SkRect+SkMatrix ctor to a factory method.
Adds simple constructors for Sk4fs and SkRects w/o transforms.
Bug: skia:
Change-Id: I88a4a5f7304b1cf00d68c7772bb0fc19c97abee3
Reviewed-on: https://skia-review.googlesource.com/c/191569
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/GrQuad.h b/src/gpu/GrQuad.h
index 33fd326..c754d5a 100644
--- a/src/gpu/GrQuad.h
+++ b/src/gpu/GrQuad.h
@@ -61,13 +61,18 @@
: fX{rect.fLeft, rect.fLeft, rect.fRight, rect.fRight}
, fY{rect.fTop, rect.fBottom, rect.fTop, rect.fBottom} {}
- /** Sets the quad to the rect as transformed by the matrix. */
- GrQuad(const SkRect&, const SkMatrix&);
+ GrQuad(const Sk4f& xs, const Sk4f& ys) {
+ xs.store(fX);
+ ys.store(fY);
+ }
explicit GrQuad(const SkPoint pts[4])
: fX{pts[0].fX, pts[1].fX, pts[2].fX, pts[3].fX}
, fY{pts[0].fY, pts[1].fY, pts[2].fY, pts[3].fY} {}
+ /** Sets the quad to the rect as transformed by the matrix. */
+ static GrQuad MakeFromRect(const SkRect&, const SkMatrix&);
+
GrQuad& operator=(const GrQuad& that) = default;
SkPoint point(int i) const { return {fX[i], fY[i]}; }
@@ -102,7 +107,23 @@
public:
GrPerspQuad() = default;
- GrPerspQuad(const SkRect&, const SkMatrix&);
+ explicit GrPerspQuad(const SkRect& rect)
+ : fX{rect.fLeft, rect.fLeft, rect.fRight, rect.fRight}
+ , fY{rect.fTop, rect.fBottom, rect.fTop, rect.fBottom}
+ , fW{1.f, 1.f, 1.f, 1.f} {}
+
+ GrPerspQuad(const Sk4f& xs, const Sk4f& ys) {
+ xs.store(fX);
+ ys.store(fY);
+ fW[0] = fW[1] = fW[2] = fW[3] = 1.f;
+ }
+ GrPerspQuad(const Sk4f& xs, const Sk4f& ys, const Sk4f& ws) {
+ xs.store(fX);
+ ys.store(fY);
+ ws.store(fW);
+ }
+
+ static GrPerspQuad MakeFromRect(const SkRect&, const SkMatrix&);
GrPerspQuad& operator=(const GrPerspQuad&) = default;