joshualitt | ae5b2c6 | 2015-08-19 08:48:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrQuad_DEFINED |
| 9 | #define GrQuad_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkMatrix.h" |
| 12 | #include "include/core/SkPoint.h" |
| 13 | #include "include/core/SkPoint3.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/private/SkTArray.h" |
Michael Ludwig | b3461fa | 2019-04-30 11:50:55 -0400 | [diff] [blame] | 15 | #include "include/private/SkVx.h" |
joshualitt | ae5b2c6 | 2015-08-19 08:48:41 -0700 | [diff] [blame] | 16 | |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 17 | enum class GrAAType : unsigned; |
| 18 | enum class GrQuadAAFlags; |
| 19 | |
Michael Ludwig | 1f7e438 | 2018-10-19 09:36:57 -0400 | [diff] [blame] | 20 | // Rectangles transformed by matrices (view or local) can be classified in three ways: |
| 21 | // 1. Stays a rectangle - the matrix rectStaysRect() is true, or x(0) == x(1) && x(2) == x(3) |
| 22 | // and y(0) == y(2) && y(1) == y(3). Or under mirrors, x(0) == x(2) && x(1) == x(3) and |
| 23 | // y(0) == y(1) && y(2) == y(3). |
Michael Ludwig | f995c05 | 2018-11-26 15:24:29 -0500 | [diff] [blame] | 24 | // 2. Is rectilinear - the matrix does not have skew or perspective, but may rotate (unlike #1) |
| 25 | // 3. Is a quadrilateral - the matrix does not have perspective, but may rotate or skew, or |
Michael Ludwig | 1f7e438 | 2018-10-19 09:36:57 -0400 | [diff] [blame] | 26 | // ws() == all ones. |
Michael Ludwig | f995c05 | 2018-11-26 15:24:29 -0500 | [diff] [blame] | 27 | // 4. Is a perspective quad - the matrix has perspective, subsuming all previous quad types. |
Michael Ludwig | 1f7e438 | 2018-10-19 09:36:57 -0400 | [diff] [blame] | 28 | enum class GrQuadType { |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 29 | kRect, |
Michael Ludwig | f995c05 | 2018-11-26 15:24:29 -0500 | [diff] [blame] | 30 | kRectilinear, |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 31 | kStandard, |
| 32 | kPerspective, |
| 33 | kLast = kPerspective |
Michael Ludwig | 1f7e438 | 2018-10-19 09:36:57 -0400 | [diff] [blame] | 34 | }; |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 35 | static const int kGrQuadTypeCount = static_cast<int>(GrQuadType::kLast) + 1; |
Michael Ludwig | 1f7e438 | 2018-10-19 09:36:57 -0400 | [diff] [blame] | 36 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 37 | // If an SkRect is transformed by this matrix, what class of quad is required to represent it. |
| 38 | GrQuadType GrQuadTypeForTransformedRect(const SkMatrix& matrix); |
| 39 | // Perform minimal analysis of 'pts' (which are suitable for MakeFromSkQuad), and determine a |
| 40 | // quad type that will be as minimally general as possible. |
| 41 | GrQuadType GrQuadTypeForPoints(const SkPoint pts[4], const SkMatrix& matrix); |
| 42 | |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 43 | // Resolve disagreements between the overall requested AA type and the per-edge quad AA flags. |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 44 | // knownQuadType must have come from GrQuadTypeForTransformedRect with the matrix that created the |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 45 | // provided quad. Both outAAType and outEdgeFlags will be updated. |
| 46 | template <typename Q> |
| 47 | void GrResolveAATypeForQuad(GrAAType requestedAAType, GrQuadAAFlags requestedEdgeFlags, |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 48 | const Q& quad, GrQuadType knownQuadType, |
| 49 | GrAAType* outAAtype, GrQuadAAFlags* outEdgeFlags); |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 50 | |
joshualitt | ae5b2c6 | 2015-08-19 08:48:41 -0700 | [diff] [blame] | 51 | /** |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 52 | * GrQuad is a collection of 4 points which can be used to represent an arbitrary quadrilateral. The |
| 53 | * points make a triangle strip with CCW triangles (top-left, bottom-left, top-right, bottom-right). |
joshualitt | ae5b2c6 | 2015-08-19 08:48:41 -0700 | [diff] [blame] | 54 | */ |
| 55 | class GrQuad { |
| 56 | public: |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 57 | GrQuad() = default; |
joshualitt | 8cce8f1 | 2015-08-26 06:23:39 -0700 | [diff] [blame] | 58 | |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 59 | GrQuad(const GrQuad& that) = default; |
| 60 | |
| 61 | explicit GrQuad(const SkRect& rect) |
| 62 | : fX{rect.fLeft, rect.fLeft, rect.fRight, rect.fRight} |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 63 | , fY{rect.fTop, rect.fBottom, rect.fTop, rect.fBottom} {} |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 64 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 65 | GrQuad(const skvx::Vec<4, float>& xs, const skvx::Vec<4, float>& ys) { |
Michael Ludwig | e9c57d3 | 2019-02-13 13:39:39 -0500 | [diff] [blame] | 66 | xs.store(fX); |
| 67 | ys.store(fY); |
| 68 | } |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 69 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 70 | explicit GrQuad(const SkPoint pts[4]) |
| 71 | : fX{pts[0].fX, pts[1].fX, pts[2].fX, pts[3].fX} |
| 72 | , fY{pts[0].fY, pts[1].fY, pts[2].fY, pts[3].fY} {} |
| 73 | |
Michael Ludwig | e9c57d3 | 2019-02-13 13:39:39 -0500 | [diff] [blame] | 74 | /** Sets the quad to the rect as transformed by the matrix. */ |
| 75 | static GrQuad MakeFromRect(const SkRect&, const SkMatrix&); |
| 76 | |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 77 | // Creates a GrQuad from the quadrilateral 'pts', transformed by the matrix. Unlike the explicit |
| 78 | // constructor, the input points array is arranged as per SkRect::toQuad (top-left, top-right, |
| 79 | // bottom-right, bottom-left). The returned instance's point order will still be CCW tri-strip |
| 80 | // order. |
| 81 | static GrQuad MakeFromSkQuad(const SkPoint pts[4], const SkMatrix&); |
| 82 | |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 83 | GrQuad& operator=(const GrQuad& that) = default; |
| 84 | |
| 85 | SkPoint point(int i) const { return {fX[i], fY[i]}; } |
| 86 | |
| 87 | SkRect bounds() const { |
| 88 | auto x = this->x4f(), y = this->y4f(); |
Michael Ludwig | b3461fa | 2019-04-30 11:50:55 -0400 | [diff] [blame] | 89 | return {min(x), min(y), max(x), max(y)}; |
joshualitt | ae5b2c6 | 2015-08-19 08:48:41 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 92 | float x(int i) const { return fX[i]; } |
| 93 | float y(int i) const { return fY[i]; } |
joshualitt | ae5b2c6 | 2015-08-19 08:48:41 -0700 | [diff] [blame] | 94 | |
Michael Ludwig | b3461fa | 2019-04-30 11:50:55 -0400 | [diff] [blame] | 95 | skvx::Vec<4, float> x4f() const { return skvx::Vec<4, float>::Load(fX); } |
| 96 | skvx::Vec<4, float> y4f() const { return skvx::Vec<4, float>::Load(fY); } |
joshualitt | 8cce8f1 | 2015-08-26 06:23:39 -0700 | [diff] [blame] | 97 | |
Michael Ludwig | 9bf37f6 | 2019-04-12 14:24:38 -0400 | [diff] [blame] | 98 | // True if anti-aliasing affects this quad. Only valid when quadType == kRect_QuadType |
Michael Ludwig | 1f7e438 | 2018-10-19 09:36:57 -0400 | [diff] [blame] | 99 | bool aaHasEffectOnRect() const; |
| 100 | |
joshualitt | ae5b2c6 | 2015-08-19 08:48:41 -0700 | [diff] [blame] | 101 | private: |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 102 | template<typename T> |
| 103 | friend class GrQuadListBase; |
| 104 | |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 105 | float fX[4]; |
| 106 | float fY[4]; |
joshualitt | ae5b2c6 | 2015-08-19 08:48:41 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 109 | class GrPerspQuad { |
| 110 | public: |
| 111 | GrPerspQuad() = default; |
| 112 | |
Michael Ludwig | e9c57d3 | 2019-02-13 13:39:39 -0500 | [diff] [blame] | 113 | explicit GrPerspQuad(const SkRect& rect) |
| 114 | : fX{rect.fLeft, rect.fLeft, rect.fRight, rect.fRight} |
| 115 | , fY{rect.fTop, rect.fBottom, rect.fTop, rect.fBottom} |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 116 | , fW{1.f, 1.f, 1.f, 1.f} {} |
Michael Ludwig | e9c57d3 | 2019-02-13 13:39:39 -0500 | [diff] [blame] | 117 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 118 | GrPerspQuad(const skvx::Vec<4, float>& xs, const skvx::Vec<4, float>& ys) { |
Michael Ludwig | e9c57d3 | 2019-02-13 13:39:39 -0500 | [diff] [blame] | 119 | xs.store(fX); |
| 120 | ys.store(fY); |
| 121 | fW[0] = fW[1] = fW[2] = fW[3] = 1.f; |
| 122 | } |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 123 | |
Michael Ludwig | b3461fa | 2019-04-30 11:50:55 -0400 | [diff] [blame] | 124 | GrPerspQuad(const skvx::Vec<4, float>& xs, const skvx::Vec<4, float>& ys, |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 125 | const skvx::Vec<4, float>& ws) { |
Michael Ludwig | e9c57d3 | 2019-02-13 13:39:39 -0500 | [diff] [blame] | 126 | xs.store(fX); |
| 127 | ys.store(fY); |
| 128 | ws.store(fW); |
| 129 | } |
| 130 | |
| 131 | static GrPerspQuad MakeFromRect(const SkRect&, const SkMatrix&); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 132 | |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 133 | // Creates a GrPerspQuad from the quadrilateral 'pts', transformed by the matrix. The input |
| 134 | // points array is arranged as per SkRect::toQuad (top-left, top-right, bottom-right, |
| 135 | // bottom-left). The returned instance's point order will still be CCW tri-strip order. |
| 136 | static GrPerspQuad MakeFromSkQuad(const SkPoint pts[4], const SkMatrix&); |
| 137 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 138 | GrPerspQuad& operator=(const GrPerspQuad&) = default; |
| 139 | |
| 140 | SkPoint3 point(int i) const { return {fX[i], fY[i], fW[i]}; } |
| 141 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 142 | SkRect bounds(GrQuadType type) const { |
Michael Ludwig | b3461fa | 2019-04-30 11:50:55 -0400 | [diff] [blame] | 143 | auto x = this->x4f(); |
| 144 | auto y = this->y4f(); |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 145 | if (type == GrQuadType::kPerspective) { |
Michael Ludwig | b3461fa | 2019-04-30 11:50:55 -0400 | [diff] [blame] | 146 | auto iw = this->iw4f(); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 147 | x *= iw; |
| 148 | y *= iw; |
| 149 | } |
| 150 | |
Michael Ludwig | b3461fa | 2019-04-30 11:50:55 -0400 | [diff] [blame] | 151 | return {min(x), min(y), max(x), max(y)}; |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | float x(int i) const { return fX[i]; } |
| 155 | float y(int i) const { return fY[i]; } |
| 156 | float w(int i) const { return fW[i]; } |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 157 | float iw(int i) const { return sk_ieee_float_divide(1.f, fW[i]); } |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 158 | |
Michael Ludwig | b3461fa | 2019-04-30 11:50:55 -0400 | [diff] [blame] | 159 | skvx::Vec<4, float> x4f() const { return skvx::Vec<4, float>::Load(fX); } |
| 160 | skvx::Vec<4, float> y4f() const { return skvx::Vec<4, float>::Load(fY); } |
| 161 | skvx::Vec<4, float> w4f() const { return skvx::Vec<4, float>::Load(fW); } |
| 162 | skvx::Vec<4, float> iw4f() const { return 1.f / this->w4f(); } |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 163 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 164 | bool hasPerspective() const { return any(w4f() != 1.f); } |
Michael Ludwig | 1f7e438 | 2018-10-19 09:36:57 -0400 | [diff] [blame] | 165 | |
Michael Ludwig | 9bf37f6 | 2019-04-12 14:24:38 -0400 | [diff] [blame] | 166 | // True if anti-aliasing affects this quad. Only valid when quadType == kRect_QuadType |
Michael Ludwig | 1f7e438 | 2018-10-19 09:36:57 -0400 | [diff] [blame] | 167 | bool aaHasEffectOnRect() const; |
| 168 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 169 | private: |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 170 | template<typename T> |
| 171 | friend class GrQuadListBase; |
| 172 | |
| 173 | // Copy 4 values from each of the arrays into the quad's components |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 174 | GrPerspQuad(const float xs[4], const float ys[4], const float ws[4]); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 175 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 176 | float fX[4]; |
| 177 | float fY[4]; |
| 178 | float fW[4]; |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | // Underlying data used by GrQuadListBase. It is defined outside of GrQuadListBase due to compiler |
| 182 | // issues related to specializing member types. |
| 183 | template<typename T> |
| 184 | struct QuadData { |
| 185 | float fX[4]; |
| 186 | float fY[4]; |
| 187 | T fMetadata; |
| 188 | }; |
| 189 | |
| 190 | template<> |
| 191 | struct QuadData<void> { |
| 192 | float fX[4]; |
| 193 | float fY[4]; |
| 194 | }; |
| 195 | |
| 196 | // A dynamic list of (possibly) perspective quads that tracks the most general quad type of all |
| 197 | // added quads. It avoids storing the 3rd component if the quad type never becomes perspective. |
| 198 | // Use GrQuadList subclass when only storing quads. Use GrTQuadList subclass when storing quads |
| 199 | // and per-quad templated metadata (such as color or domain). |
| 200 | template<typename T> |
| 201 | class GrQuadListBase { |
| 202 | public: |
| 203 | |
| 204 | int count() const { return fXYs.count(); } |
| 205 | |
| 206 | GrQuadType quadType() const { return fType; } |
| 207 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 208 | void reserve(int count, GrQuadType forType) { |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 209 | fXYs.reserve(count); |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 210 | if (forType == GrQuadType::kPerspective || fType == GrQuadType::kPerspective) { |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 211 | fWs.reserve(4 * count); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | GrPerspQuad operator[] (int i) const { |
| 216 | SkASSERT(i < this->count()); |
| 217 | SkASSERT(i >= 0); |
| 218 | |
| 219 | const QuadData<T>& item = fXYs[i]; |
| 220 | if (fType == GrQuadType::kPerspective) { |
| 221 | // Read the explicit ws |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 222 | return GrPerspQuad(item.fX, item.fY, fWs.begin() + 4 * i); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 223 | } else { |
| 224 | // Ws are implicitly 1s. |
| 225 | static constexpr float kNoPerspectiveWs[4] = {1.f, 1.f, 1.f, 1.f}; |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 226 | return GrPerspQuad(item.fX, item.fY, kNoPerspectiveWs); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | // Subclasses expose push_back(const GrQuad|GrPerspQuad&, GrQuadType, [const T&]), where |
| 231 | // the metadata argument is only present in GrTQuadList's push_back definition. |
| 232 | |
| 233 | protected: |
| 234 | GrQuadListBase() : fType(GrQuadType::kRect) {} |
| 235 | |
| 236 | void concatImpl(const GrQuadListBase<T>& that) { |
| 237 | this->upgradeType(that.fType); |
| 238 | fXYs.push_back_n(that.fXYs.count(), that.fXYs.begin()); |
| 239 | if (fType == GrQuadType::kPerspective) { |
| 240 | if (that.fType == GrQuadType::kPerspective) { |
| 241 | // Copy the other's ws into the end of this list's data |
| 242 | fWs.push_back_n(that.fWs.count(), that.fWs.begin()); |
| 243 | } else { |
| 244 | // This list stores ws but the appended list had implicit 1s, so add explicit 1s to |
| 245 | // fill out the total list |
| 246 | fWs.push_back_n(4 * that.count(), 1.f); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // Returns the added item data so that its metadata can be initialized if T is not void |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 252 | QuadData<T>& pushBackImpl(const GrQuad& quad, GrQuadType type) { |
| 253 | this->upgradeType(type); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 254 | QuadData<T>& item = fXYs.push_back(); |
| 255 | memcpy(item.fX, quad.fX, 4 * sizeof(float)); |
| 256 | memcpy(item.fY, quad.fY, 4 * sizeof(float)); |
| 257 | if (fType == GrQuadType::kPerspective) { |
| 258 | fWs.push_back_n(4, 1.f); |
| 259 | } |
| 260 | return item; |
| 261 | } |
| 262 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 263 | QuadData<T>& pushBackImpl(const GrPerspQuad& quad, GrQuadType type) { |
| 264 | this->upgradeType(type); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 265 | QuadData<T>& item = fXYs.push_back(); |
| 266 | memcpy(item.fX, quad.fX, 4 * sizeof(float)); |
| 267 | memcpy(item.fY, quad.fY, 4 * sizeof(float)); |
| 268 | if (fType == GrQuadType::kPerspective) { |
| 269 | fWs.push_back_n(4, quad.fW); |
| 270 | } |
| 271 | return item; |
| 272 | } |
| 273 | |
| 274 | const QuadData<T>& item(int i) const { |
| 275 | return fXYs[i]; |
| 276 | } |
| 277 | |
| 278 | QuadData<T>& item(int i) { |
| 279 | return fXYs[i]; |
| 280 | } |
| 281 | |
| 282 | private: |
| 283 | void upgradeType(GrQuadType type) { |
| 284 | // Possibly upgrade the overall type tracked by the list |
| 285 | if (type > fType) { |
| 286 | fType = type; |
| 287 | if (type == GrQuadType::kPerspective) { |
| 288 | // All existing quads were 2D, so the ws array just needs to be filled with 1s |
| 289 | fWs.push_back_n(4 * this->count(), 1.f); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | // Interleaves xs, ys, and per-quad metadata so that all data for a single quad is together |
| 295 | // (barring ws, which can be dropped entirely if the quad type allows it). |
| 296 | SkSTArray<1, QuadData<T>, true> fXYs; |
| 297 | // The w channel is kept separate so that it can remain empty when only dealing with 2D quads. |
| 298 | SkTArray<float, true> fWs; |
| 299 | |
| 300 | GrQuadType fType; |
| 301 | }; |
| 302 | |
| 303 | // This list only stores the quad data itself. |
| 304 | class GrQuadList : public GrQuadListBase<void> { |
| 305 | public: |
| 306 | GrQuadList() : INHERITED() {} |
| 307 | |
| 308 | void concat(const GrQuadList& that) { |
| 309 | this->concatImpl(that); |
| 310 | } |
| 311 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 312 | void push_back(const GrQuad& quad, GrQuadType type) { |
| 313 | this->pushBackImpl(quad, type); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 314 | } |
| 315 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 316 | void push_back(const GrPerspQuad& quad, GrQuadType type) { |
| 317 | this->pushBackImpl(quad, type); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | private: |
| 321 | typedef GrQuadListBase<void> INHERITED; |
| 322 | }; |
| 323 | |
| 324 | // This variant of the list allows simple metadata to be stored per quad as well, such as color |
| 325 | // or texture domain. |
| 326 | template<typename T> |
| 327 | class GrTQuadList : public GrQuadListBase<T> { |
| 328 | public: |
| 329 | GrTQuadList() : INHERITED() {} |
| 330 | |
| 331 | void concat(const GrTQuadList<T>& that) { |
| 332 | this->concatImpl(that); |
| 333 | } |
| 334 | |
| 335 | // Adding to the list requires metadata |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 336 | void push_back(const GrQuad& quad, GrQuadType type, T&& metadata) { |
| 337 | QuadData<T>& item = this->pushBackImpl(quad, type); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 338 | item.fMetadata = std::move(metadata); |
| 339 | } |
| 340 | |
Robert Phillips | 0dee19b | 2019-05-23 17:22:19 +0000 | [diff] [blame] | 341 | void push_back(const GrPerspQuad& quad, GrQuadType type, T&& metadata) { |
| 342 | QuadData<T>& item = this->pushBackImpl(quad, type); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 343 | item.fMetadata = std::move(metadata); |
| 344 | } |
| 345 | |
| 346 | // And provide access to the metadata per quad |
| 347 | const T& metadata(int i) const { |
| 348 | return this->item(i).fMetadata; |
| 349 | } |
| 350 | |
| 351 | T& metadata(int i) { |
| 352 | return this->item(i).fMetadata; |
| 353 | } |
| 354 | |
| 355 | private: |
| 356 | typedef GrQuadListBase<T> INHERITED; |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 357 | }; |
| 358 | |
joshualitt | ae5b2c6 | 2015-08-19 08:48:41 -0700 | [diff] [blame] | 359 | #endif |