Reland "Track quad type on GrQuad directly"
This reverts commit 0dee19bacc00f327dca20cc7e4c0a97bc8082c0e.
Reason for revert: properly remember src quad type
Original change's description:
> Revert "Track quad type on GrQuad directly"
>
> This reverts commit 85766c4cd367596268588f53631a1c43376c929d.
>
> Reason for revert: red - so much red
>
> Original change's description:
> > Track quad type on GrQuad directly
> >
> > This makes subsequent higher-level drawing APIs more compact, and
> > shouldn't come with a performance hit. Everywhere we used to need
> > a GrPerspQuad, we'd also take the GrQuadType as a second argument.
> > The quad list types already deconstruct the quad so there's no
> > extra overhead in the op's memory usage.
> >
> > It also improves usability and decreases the likelihood that an
> > incorrect quad type is ever associated with the quad.
> >
> > Bug: skia:
> > Change-Id: Iba908fb133ad664744a5788a7088d90de0d3a1c2
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214820
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,michaelludwig@google.com
>
> Change-Id: Ied594673116fb901287b334fea41da3c71494fb1
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215607
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,michaelludwig@google.com
Change-Id: Id5fb51218f2ace37086112caa2e43461d2f2b46b
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215640
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/GrQuad.h b/src/gpu/GrQuad.h
index 73b7310..cb2f15d 100644
--- a/src/gpu/GrQuad.h
+++ b/src/gpu/GrQuad.h
@@ -34,19 +34,12 @@
};
static const int kGrQuadTypeCount = static_cast<int>(GrQuadType::kLast) + 1;
-// If an SkRect is transformed by this matrix, what class of quad is required to represent it.
-GrQuadType GrQuadTypeForTransformedRect(const SkMatrix& matrix);
-// Perform minimal analysis of 'pts' (which are suitable for MakeFromSkQuad), and determine a
-// quad type that will be as minimally general as possible.
-GrQuadType GrQuadTypeForPoints(const SkPoint pts[4], const SkMatrix& matrix);
-
// Resolve disagreements between the overall requested AA type and the per-edge quad AA flags.
// knownQuadType must have come from GrQuadTypeForTransformedRect with the matrix that created the
// provided quad. Both outAAType and outEdgeFlags will be updated.
template <typename Q>
void GrResolveAATypeForQuad(GrAAType requestedAAType, GrQuadAAFlags requestedEdgeFlags,
- const Q& quad, GrQuadType knownQuadType,
- GrAAType* outAAtype, GrQuadAAFlags* outEdgeFlags);
+ const Q& quad, GrAAType* outAAtype, GrQuadAAFlags* outEdgeFlags);
/**
* GrQuad is a collection of 4 points which can be used to represent an arbitrary quadrilateral. The
@@ -60,17 +53,15 @@
explicit GrQuad(const SkRect& rect)
: fX{rect.fLeft, rect.fLeft, rect.fRight, rect.fRight}
- , fY{rect.fTop, rect.fBottom, rect.fTop, rect.fBottom} {}
+ , fY{rect.fTop, rect.fBottom, rect.fTop, rect.fBottom}
+ , fType(GrQuadType::kRect) {}
- GrQuad(const skvx::Vec<4, float>& xs, const skvx::Vec<4, float>& ys) {
+ GrQuad(const skvx::Vec<4, float>& xs, const skvx::Vec<4, float>& ys, GrQuadType type)
+ : fType(type) {
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&);
@@ -95,6 +86,8 @@
skvx::Vec<4, float> x4f() const { return skvx::Vec<4, float>::Load(fX); }
skvx::Vec<4, float> y4f() const { return skvx::Vec<4, float>::Load(fY); }
+ GrQuadType quadType() const { return fType; }
+
// True if anti-aliasing affects this quad. Only valid when quadType == kRect_QuadType
bool aaHasEffectOnRect() const;
@@ -104,6 +97,8 @@
float fX[4];
float fY[4];
+
+ GrQuadType fType;
};
class GrPerspQuad {
@@ -113,16 +108,21 @@
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} {}
+ , fW{1.f, 1.f, 1.f, 1.f}
+ , fType(GrQuadType::kRect) {}
- GrPerspQuad(const skvx::Vec<4, float>& xs, const skvx::Vec<4, float>& ys) {
+ GrPerspQuad(const skvx::Vec<4, float>& xs, const skvx::Vec<4, float>& ys,
+ GrQuadType type)
+ : fType(type) {
+ SkASSERT(type != GrQuadType::kPerspective);
xs.store(fX);
ys.store(fY);
fW[0] = fW[1] = fW[2] = fW[3] = 1.f;
}
GrPerspQuad(const skvx::Vec<4, float>& xs, const skvx::Vec<4, float>& ys,
- const skvx::Vec<4, float>& ws) {
+ const skvx::Vec<4, float>& ws, GrQuadType type)
+ : fType(type) {
xs.store(fX);
ys.store(fY);
ws.store(fW);
@@ -139,10 +139,10 @@
SkPoint3 point(int i) const { return {fX[i], fY[i], fW[i]}; }
- SkRect bounds(GrQuadType type) const {
+ SkRect bounds() const {
auto x = this->x4f();
auto y = this->y4f();
- if (type == GrQuadType::kPerspective) {
+ if (fType == GrQuadType::kPerspective) {
auto iw = this->iw4f();
x *= iw;
y *= iw;
@@ -161,7 +161,9 @@
skvx::Vec<4, float> w4f() const { return skvx::Vec<4, float>::Load(fW); }
skvx::Vec<4, float> iw4f() const { return 1.f / this->w4f(); }
- bool hasPerspective() const { return any(w4f() != 1.f); }
+ GrQuadType quadType() const { return fType; }
+
+ bool hasPerspective() const { return fType == GrQuadType::kPerspective; }
// True if anti-aliasing affects this quad. Only valid when quadType == kRect_QuadType
bool aaHasEffectOnRect() const;
@@ -171,11 +173,13 @@
friend class GrQuadListBase;
// Copy 4 values from each of the arrays into the quad's components
- GrPerspQuad(const float xs[4], const float ys[4], const float ws[4]);
+ GrPerspQuad(const float xs[4], const float ys[4], const float ws[4], GrQuadType type);
float fX[4];
float fY[4];
float fW[4];
+
+ GrQuadType fType;
};
// Underlying data used by GrQuadListBase. It is defined outside of GrQuadListBase due to compiler
@@ -205,9 +209,9 @@
GrQuadType quadType() const { return fType; }
- void reserve(int count, GrQuadType forType) {
+ void reserve(int count, bool needsPerspective) {
fXYs.reserve(count);
- if (forType == GrQuadType::kPerspective || fType == GrQuadType::kPerspective) {
+ if (needsPerspective || fType == GrQuadType::kPerspective) {
fWs.reserve(4 * count);
}
}
@@ -219,11 +223,11 @@
const QuadData<T>& item = fXYs[i];
if (fType == GrQuadType::kPerspective) {
// Read the explicit ws
- return GrPerspQuad(item.fX, item.fY, fWs.begin() + 4 * i);
+ return GrPerspQuad(item.fX, item.fY, fWs.begin() + 4 * i, fType);
} else {
// Ws are implicitly 1s.
static constexpr float kNoPerspectiveWs[4] = {1.f, 1.f, 1.f, 1.f};
- return GrPerspQuad(item.fX, item.fY, kNoPerspectiveWs);
+ return GrPerspQuad(item.fX, item.fY, kNoPerspectiveWs, fType);
}
}
@@ -249,8 +253,8 @@
}
// Returns the added item data so that its metadata can be initialized if T is not void
- QuadData<T>& pushBackImpl(const GrQuad& quad, GrQuadType type) {
- this->upgradeType(type);
+ QuadData<T>& pushBackImpl(const GrQuad& quad) {
+ this->upgradeType(quad.quadType());
QuadData<T>& item = fXYs.push_back();
memcpy(item.fX, quad.fX, 4 * sizeof(float));
memcpy(item.fY, quad.fY, 4 * sizeof(float));
@@ -260,8 +264,8 @@
return item;
}
- QuadData<T>& pushBackImpl(const GrPerspQuad& quad, GrQuadType type) {
- this->upgradeType(type);
+ QuadData<T>& pushBackImpl(const GrPerspQuad& quad) {
+ this->upgradeType(quad.quadType());
QuadData<T>& item = fXYs.push_back();
memcpy(item.fX, quad.fX, 4 * sizeof(float));
memcpy(item.fY, quad.fY, 4 * sizeof(float));
@@ -309,12 +313,12 @@
this->concatImpl(that);
}
- void push_back(const GrQuad& quad, GrQuadType type) {
- this->pushBackImpl(quad, type);
+ void push_back(const GrQuad& quad) {
+ this->pushBackImpl(quad);
}
- void push_back(const GrPerspQuad& quad, GrQuadType type) {
- this->pushBackImpl(quad, type);
+ void push_back(const GrPerspQuad& quad) {
+ this->pushBackImpl(quad);
}
private:
@@ -333,13 +337,13 @@
}
// Adding to the list requires metadata
- void push_back(const GrQuad& quad, GrQuadType type, T&& metadata) {
- QuadData<T>& item = this->pushBackImpl(quad, type);
+ void push_back(const GrQuad& quad, T&& metadata) {
+ QuadData<T>& item = this->pushBackImpl(quad);
item.fMetadata = std::move(metadata);
}
- void push_back(const GrPerspQuad& quad, GrQuadType type, T&& metadata) {
- QuadData<T>& item = this->pushBackImpl(quad, type);
+ void push_back(const GrPerspQuad& quad, T&& metadata) {
+ QuadData<T>& item = this->pushBackImpl(quad);
item.fMetadata = std::move(metadata);
}