joshualitt | 2771b56 | 2015-08-07 12:46:26 -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 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 8 | #include "GrDrawVerticesOp.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 9 | #include "GrCaps.h" |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 10 | #include "GrDefaultGeoProcFactory.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 11 | #include "GrOpFlushState.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 12 | #include "SkGr.h" |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 13 | #include "SkRectPriv.h" |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 14 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 15 | std::unique_ptr<GrDrawOp> GrDrawVerticesOp::Make(GrContext* context, |
| 16 | GrPaint&& paint, |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 17 | sk_sp<SkVertices> vertices, |
| 18 | const SkMatrix& viewMatrix, |
| 19 | GrAAType aaType, |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 20 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 21 | GrPrimitiveType* overridePrimType) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 22 | SkASSERT(vertices); |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 23 | GrPrimitiveType primType = overridePrimType ? *overridePrimType |
| 24 | : SkVertexModeToGrPrimitiveType(vertices->mode()); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 25 | return Helper::FactoryHelper<GrDrawVerticesOp>(context, std::move(paint), std::move(vertices), |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 26 | primType, aaType, std::move(colorSpaceXform), |
| 27 | viewMatrix); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 28 | } |
| 29 | |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 30 | GrDrawVerticesOp::GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor color, |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 31 | sk_sp<SkVertices> vertices, GrPrimitiveType primitiveType, |
| 32 | GrAAType aaType, sk_sp<GrColorSpaceXform> colorSpaceXform, |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 33 | const SkMatrix& viewMatrix) |
| 34 | : INHERITED(ClassID()) |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 35 | , fHelper(helperArgs, aaType) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 36 | , fPrimitiveType(primitiveType) |
| 37 | , fColorSpaceXform(std::move(colorSpaceXform)) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 38 | SkASSERT(vertices); |
| 39 | |
| 40 | fVertexCount = vertices->vertexCount(); |
| 41 | fIndexCount = vertices->indexCount(); |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 42 | fColorArrayType = vertices->hasColors() ? ColorArrayType::kSkColor |
| 43 | : ColorArrayType::kPremulGrColor; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 44 | |
bsalomon | d92b419 | 2016-06-30 07:59:23 -0700 | [diff] [blame] | 45 | Mesh& mesh = fMeshes.push_back(); |
| 46 | mesh.fColor = color; |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 47 | mesh.fViewMatrix = viewMatrix; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 48 | mesh.fVertices = std::move(vertices); |
Brian Osman | 8a03055 | 2017-05-23 15:03:18 -0400 | [diff] [blame] | 49 | mesh.fIgnoreTexCoords = false; |
| 50 | mesh.fIgnoreColors = false; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 51 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 52 | fFlags = 0; |
| 53 | if (mesh.hasPerVertexColors()) { |
| 54 | fFlags |= kRequiresPerVertexColors_Flag; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 55 | } |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 56 | if (mesh.hasExplicitLocalCoords()) { |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 57 | fFlags |= kAnyMeshHasExplicitLocalCoords_Flag; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 58 | } |
| 59 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 60 | IsZeroArea zeroArea; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 61 | if (GrIsPrimTypeLines(primitiveType) || GrPrimitiveType::kPoints == primitiveType) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 62 | zeroArea = IsZeroArea::kYes; |
| 63 | } else { |
| 64 | zeroArea = IsZeroArea::kNo; |
| 65 | } |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 66 | |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 67 | this->setTransformedBounds(mesh.fVertices->bounds(), |
| 68 | mesh.fViewMatrix, |
| 69 | HasAABloat::kNo, |
| 70 | zeroArea); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 73 | SkString GrDrawVerticesOp::dumpInfo() const { |
| 74 | SkString string; |
| 75 | string.appendf("PrimType: %d, MeshCount %d, VCount: %d, ICount: %d\n", (int)fPrimitiveType, |
| 76 | fMeshes.count(), fVertexCount, fIndexCount); |
| 77 | string += fHelper.dumpInfo(); |
| 78 | string += INHERITED::dumpInfo(); |
| 79 | return string; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 82 | GrDrawOp::FixedFunctionFlags GrDrawVerticesOp::fixedFunctionFlags() const { |
| 83 | return fHelper.fixedFunctionFlags(); |
| 84 | } |
| 85 | |
| 86 | GrDrawOp::RequiresDstTexture GrDrawVerticesOp::finalize(const GrCaps& caps, |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 87 | const GrAppliedClip* clip, |
| 88 | GrPixelConfigIsClamped dstIsClamped) { |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 89 | GrProcessorAnalysisColor gpColor; |
| 90 | if (this->requiresPerVertexColors()) { |
| 91 | gpColor.setToUnknown(); |
| 92 | } else { |
| 93 | gpColor.setToConstant(fMeshes.front().fColor); |
| 94 | } |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 95 | auto result = fHelper.xpRequiresDstTexture(caps, clip, dstIsClamped, |
| 96 | GrProcessorAnalysisCoverage::kNone, &gpColor); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 97 | if (gpColor.isConstant(&fMeshes.front().fColor)) { |
| 98 | fMeshes.front().fIgnoreColors = true; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 99 | fFlags &= ~kRequiresPerVertexColors_Flag; |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 100 | fColorArrayType = ColorArrayType::kPremulGrColor; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 101 | } |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 102 | if (!fHelper.usesLocalCoords()) { |
Brian Osman | 8a03055 | 2017-05-23 15:03:18 -0400 | [diff] [blame] | 103 | fMeshes[0].fIgnoreTexCoords = true; |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 104 | fFlags &= ~kAnyMeshHasExplicitLocalCoords_Flag; |
bsalomon | 14eaaa6 | 2015-09-24 07:01:26 -0700 | [diff] [blame] | 105 | } |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 106 | return result; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 109 | sk_sp<GrGeometryProcessor> GrDrawVerticesOp::makeGP(bool* hasColorAttribute, |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 110 | bool* hasLocalCoordAttribute) const { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 111 | using namespace GrDefaultGeoProcFactory; |
| 112 | LocalCoords::Type localCoordsType; |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 113 | if (fHelper.usesLocalCoords()) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 114 | // If we have multiple view matrices we will transform the positions into device space. We |
| 115 | // must then also provide untransformed positions as local coords. |
| 116 | if (this->anyMeshHasExplicitLocalCoords() || this->hasMultipleViewMatrices()) { |
| 117 | *hasLocalCoordAttribute = true; |
| 118 | localCoordsType = LocalCoords::kHasExplicit_Type; |
| 119 | } else { |
| 120 | *hasLocalCoordAttribute = false; |
| 121 | localCoordsType = LocalCoords::kUsePosition_Type; |
| 122 | } |
| 123 | } else { |
| 124 | localCoordsType = LocalCoords::kUnused_Type; |
| 125 | *hasLocalCoordAttribute = false; |
| 126 | } |
| 127 | |
| 128 | Color color(fMeshes[0].fColor); |
| 129 | if (this->requiresPerVertexColors()) { |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 130 | if (fColorArrayType == ColorArrayType::kPremulGrColor) { |
| 131 | color.fType = Color::kPremulGrColorAttribute_Type; |
| 132 | } else { |
| 133 | color.fType = Color::kUnpremulSkColorAttribute_Type; |
| 134 | color.fColorSpaceXform = fColorSpaceXform; |
| 135 | } |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 136 | *hasColorAttribute = true; |
| 137 | } else { |
| 138 | *hasColorAttribute = false; |
| 139 | }; |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 140 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 141 | const SkMatrix& vm = this->hasMultipleViewMatrices() ? SkMatrix::I() : fMeshes[0].fViewMatrix; |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 142 | |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 143 | return GrDefaultGeoProcFactory::Make(color, |
| 144 | Coverage::kSolid_Type, |
| 145 | localCoordsType, |
| 146 | vm); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 149 | void GrDrawVerticesOp::onPrepareDraws(Target* target) { |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 150 | if (fMeshes[0].fVertices->isVolatile()) { |
| 151 | this->drawVolatile(target); |
| 152 | } else { |
| 153 | this->drawNonVolatile(target); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | void GrDrawVerticesOp::drawVolatile(Target* target) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 158 | bool hasColorAttribute; |
| 159 | bool hasLocalCoordsAttribute; |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 160 | sk_sp<GrGeometryProcessor> gp = this->makeGP(&hasColorAttribute, |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 161 | &hasLocalCoordsAttribute); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 162 | |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 163 | // Calculate the stride. |
| 164 | size_t vertexStride = sizeof(SkPoint) + |
| 165 | (hasColorAttribute ? sizeof(uint32_t) : 0) + |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 166 | (hasLocalCoordsAttribute ? sizeof(SkPoint) : 0); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 167 | SkASSERT(vertexStride == gp->debugOnly_vertexStride()); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 168 | |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 169 | // Allocate buffers. |
| 170 | const GrBuffer* vertexBuffer = nullptr; |
| 171 | int firstVertex = 0; |
bsalomon | 14eaaa6 | 2015-09-24 07:01:26 -0700 | [diff] [blame] | 172 | void* verts = target->makeVertexSpace(vertexStride, fVertexCount, &vertexBuffer, &firstVertex); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 173 | if (!verts) { |
| 174 | SkDebugf("Could not allocate vertices\n"); |
| 175 | return; |
| 176 | } |
| 177 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 178 | const GrBuffer* indexBuffer = nullptr; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 179 | int firstIndex = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 180 | uint16_t* indices = nullptr; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 181 | if (this->isIndexed()) { |
bsalomon | 14eaaa6 | 2015-09-24 07:01:26 -0700 | [diff] [blame] | 182 | indices = target->makeIndexSpace(fIndexCount, &indexBuffer, &firstIndex); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 183 | if (!indices) { |
| 184 | SkDebugf("Could not allocate indices\n"); |
| 185 | return; |
| 186 | } |
| 187 | } |
| 188 | |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 189 | // Fill the buffers. |
| 190 | this->fillBuffers(hasColorAttribute, |
| 191 | hasLocalCoordsAttribute, |
| 192 | vertexStride, |
| 193 | verts, |
| 194 | indices); |
| 195 | |
| 196 | // Draw the vertices. |
| 197 | this->drawVertices(target, gp.get(), vertexBuffer, firstVertex, indexBuffer, firstIndex); |
| 198 | } |
| 199 | |
| 200 | void GrDrawVerticesOp::drawNonVolatile(Target* target) { |
| 201 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 202 | |
| 203 | bool hasColorAttribute; |
| 204 | bool hasLocalCoordsAttribute; |
| 205 | sk_sp<GrGeometryProcessor> gp = this->makeGP(&hasColorAttribute, |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 206 | &hasLocalCoordsAttribute); |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 207 | |
| 208 | SkASSERT(fMeshes.count() == 1); // Non-volatile meshes should never combine. |
| 209 | |
| 210 | // Get the resource provider. |
| 211 | GrResourceProvider* rp = target->resourceProvider(); |
| 212 | |
| 213 | // Generate keys for the buffers. |
| 214 | GrUniqueKey vertexKey, indexKey; |
| 215 | GrUniqueKey::Builder vertexKeyBuilder(&vertexKey, kDomain, 2); |
| 216 | GrUniqueKey::Builder indexKeyBuilder(&indexKey, kDomain, 2); |
| 217 | vertexKeyBuilder[0] = indexKeyBuilder[0] = fMeshes[0].fVertices->uniqueID(); |
| 218 | vertexKeyBuilder[1] = 0; |
| 219 | indexKeyBuilder[1] = 1; |
| 220 | vertexKeyBuilder.finish(); |
| 221 | indexKeyBuilder.finish(); |
| 222 | |
| 223 | // Try to grab data from the cache. |
| 224 | sk_sp<GrBuffer> vertexBuffer = rp->findByUniqueKey<GrBuffer>(vertexKey); |
| 225 | sk_sp<GrBuffer> indexBuffer = this->isIndexed() ? |
| 226 | rp->findByUniqueKey<GrBuffer>(indexKey) : |
| 227 | nullptr; |
| 228 | |
| 229 | // Draw using the cached buffers if possible. |
| 230 | if (vertexBuffer && (!this->isIndexed() || indexBuffer)) { |
| 231 | this->drawVertices(target, gp.get(), vertexBuffer.get(), 0, indexBuffer.get(), 0); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | // Calculate the stride. |
| 236 | size_t vertexStride = sizeof(SkPoint) + |
| 237 | (hasColorAttribute ? sizeof(uint32_t) : 0) + |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 238 | (hasLocalCoordsAttribute ? sizeof(SkPoint) : 0); |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 239 | SkASSERT(vertexStride == gp->debugOnly_vertexStride()); |
| 240 | |
| 241 | // Allocate vertex buffer. |
| 242 | vertexBuffer.reset(rp->createBuffer(fVertexCount * vertexStride, |
| 243 | kVertex_GrBufferType, |
| 244 | kStatic_GrAccessPattern, |
| 245 | 0)); |
| 246 | void* verts = vertexBuffer ? vertexBuffer->map() : nullptr; |
| 247 | if (!verts) { |
| 248 | SkDebugf("Could not allocate vertices\n"); |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | // Allocate index buffer. |
| 253 | uint16_t* indices = nullptr; |
| 254 | if (this->isIndexed()) { |
| 255 | indexBuffer.reset(rp->createBuffer(fIndexCount * sizeof(uint16_t), |
| 256 | kIndex_GrBufferType, |
| 257 | kStatic_GrAccessPattern, |
| 258 | 0)); |
| 259 | indices = indexBuffer ? static_cast<uint16_t*>(indexBuffer->map()) : nullptr; |
| 260 | if (!indices) { |
| 261 | SkDebugf("Could not allocate indices\n"); |
| 262 | return; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | // Fill the buffers. |
| 267 | this->fillBuffers(hasColorAttribute, |
| 268 | hasLocalCoordsAttribute, |
| 269 | vertexStride, |
| 270 | verts, |
| 271 | indices); |
| 272 | |
| 273 | // Unmap the buffers. |
| 274 | vertexBuffer->unmap(); |
| 275 | if (indexBuffer) { |
| 276 | indexBuffer->unmap(); |
| 277 | } |
| 278 | |
| 279 | // Cache the buffers. |
| 280 | rp->assignUniqueKeyToResource(vertexKey, vertexBuffer.get()); |
| 281 | rp->assignUniqueKeyToResource(indexKey, indexBuffer.get()); |
| 282 | |
| 283 | // Draw the vertices. |
| 284 | this->drawVertices(target, gp.get(), vertexBuffer.get(), 0, indexBuffer.get(), 0); |
| 285 | } |
| 286 | |
| 287 | void GrDrawVerticesOp::fillBuffers(bool hasColorAttribute, |
| 288 | bool hasLocalCoordsAttribute, |
| 289 | size_t vertexStride, |
| 290 | void* verts, |
| 291 | uint16_t* indices) const { |
| 292 | int instanceCount = fMeshes.count(); |
| 293 | |
| 294 | // Copy data into the buffers. |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 295 | int vertexOffset = 0; |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 296 | // We have a fast case below for uploading the vertex data when the matrix is translate |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 297 | // only and there are colors but not local coords. Fast case does not apply when there are bone |
| 298 | // transformations. |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 299 | bool fastAttrs = hasColorAttribute && !hasLocalCoordsAttribute; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 300 | for (int i = 0; i < instanceCount; i++) { |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 301 | // Get each mesh. |
bsalomon | d92b419 | 2016-06-30 07:59:23 -0700 | [diff] [blame] | 302 | const Mesh& mesh = fMeshes[i]; |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 303 | |
| 304 | // Copy data into the index buffer. |
bsalomon | 14eaaa6 | 2015-09-24 07:01:26 -0700 | [diff] [blame] | 305 | if (indices) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 306 | int indexCount = mesh.fVertices->indexCount(); |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 307 | for (int j = 0; j < indexCount; ++j) { |
| 308 | *indices++ = mesh.fVertices->indices()[j] + vertexOffset; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 311 | |
| 312 | // Copy data into the vertex buffer. |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 313 | int vertexCount = mesh.fVertices->vertexCount(); |
| 314 | const SkPoint* positions = mesh.fVertices->positions(); |
| 315 | const SkColor* colors = mesh.fVertices->colors(); |
| 316 | const SkPoint* localCoords = mesh.fVertices->texCoords(); |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 317 | bool fastMesh = (!this->hasMultipleViewMatrices() || |
| 318 | mesh.fViewMatrix.getType() <= SkMatrix::kTranslate_Mask) && |
| 319 | mesh.hasPerVertexColors(); |
| 320 | if (fastAttrs && fastMesh) { |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 321 | // Fast case. |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 322 | struct V { |
| 323 | SkPoint fPos; |
| 324 | uint32_t fColor; |
| 325 | }; |
| 326 | SkASSERT(sizeof(V) == vertexStride); |
| 327 | V* v = (V*)verts; |
| 328 | Sk2f t(0, 0); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 329 | if (this->hasMultipleViewMatrices()) { |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 330 | t = Sk2f(mesh.fViewMatrix.getTranslateX(), mesh.fViewMatrix.getTranslateY()); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 331 | } |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 332 | for (int j = 0; j < vertexCount; ++j) { |
| 333 | Sk2f p = Sk2f::Load(positions++) + t; |
| 334 | p.store(&v[j].fPos); |
| 335 | v[j].fColor = colors[j]; |
| 336 | } |
| 337 | verts = v + vertexCount; |
| 338 | } else { |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 339 | // Normal case. |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 340 | static constexpr size_t kColorOffset = sizeof(SkPoint); |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 341 | size_t offset = kColorOffset; |
| 342 | if (hasColorAttribute) { |
| 343 | offset += sizeof(uint32_t); |
| 344 | } |
| 345 | size_t localCoordOffset = offset; |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 346 | |
| 347 | for (int j = 0; j < vertexCount; ++j) { |
| 348 | if (this->hasMultipleViewMatrices()) { |
| 349 | mesh.fViewMatrix.mapPoints(((SkPoint*)verts), &positions[j], 1); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 350 | } else { |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 351 | *((SkPoint*)verts) = positions[j]; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 352 | } |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 353 | if (hasColorAttribute) { |
| 354 | if (mesh.hasPerVertexColors()) { |
| 355 | *(uint32_t*)((intptr_t)verts + kColorOffset) = colors[j]; |
| 356 | } else { |
| 357 | *(uint32_t*)((intptr_t)verts + kColorOffset) = mesh.fColor; |
| 358 | } |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 359 | } |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 360 | if (hasLocalCoordsAttribute) { |
| 361 | if (mesh.hasExplicitLocalCoords()) { |
| 362 | *(SkPoint*)((intptr_t)verts + localCoordOffset) = localCoords[j]; |
| 363 | } else { |
| 364 | *(SkPoint*)((intptr_t)verts + localCoordOffset) = positions[j]; |
| 365 | } |
| 366 | } |
| 367 | verts = (void*)((intptr_t)verts + vertexStride); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 368 | } |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 369 | } |
Brian Salomon | fab30a3 | 2017-02-06 19:06:22 -0500 | [diff] [blame] | 370 | vertexOffset += vertexCount; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 371 | } |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 372 | } |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 373 | |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 374 | void GrDrawVerticesOp::drawVertices(Target* target, |
| 375 | GrGeometryProcessor* gp, |
| 376 | const GrBuffer* vertexBuffer, |
| 377 | int firstVertex, |
| 378 | const GrBuffer* indexBuffer, |
| 379 | int firstIndex) { |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 380 | GrMesh mesh(this->primitiveType()); |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 381 | if (this->isIndexed()) { |
| 382 | mesh.setIndexed(indexBuffer, fIndexCount, |
| 383 | firstIndex, 0, fVertexCount - 1, |
Ruiqi Mao | c05aa7d | 2018-07-03 21:18:07 +0000 | [diff] [blame] | 384 | GrPrimitiveRestart::kNo); |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 385 | } else { |
| 386 | mesh.setNonIndexedNonInstanced(fVertexCount); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 387 | } |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 388 | mesh.setVertexData(vertexBuffer, firstVertex); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 389 | auto pipe = fHelper.makePipeline(target); |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 390 | target->draw(gp, pipe.fPipeline, pipe.fFixedDynamicState, mesh); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 393 | bool GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { |
| 394 | GrDrawVerticesOp* that = t->cast<GrDrawVerticesOp>(); |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 395 | |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 396 | if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 397 | return false; |
| 398 | } |
| 399 | |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 400 | // Non-volatile meshes cannot batch, because if a non-volatile mesh batches with another mesh, |
| 401 | // then on the next frame, if that non-volatile mesh is drawn, it will draw the other mesh |
| 402 | // that was saved in its vertex buffer, which is not necessarily there anymore. |
| 403 | if (!this->fMeshes[0].fVertices->isVolatile() || !that->fMeshes[0].fVertices->isVolatile()) { |
| 404 | return false; |
| 405 | } |
| 406 | |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 407 | if (!this->combinablePrimitive() || this->primitiveType() != that->primitiveType()) { |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 408 | return false; |
| 409 | } |
| 410 | |
Mike Reed | aa9e332 | 2017-03-16 14:38:48 -0400 | [diff] [blame] | 411 | if (fMeshes[0].fVertices->hasIndices() != that->fMeshes[0].fVertices->hasIndices()) { |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 412 | return false; |
| 413 | } |
| 414 | |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 415 | if (fColorArrayType != that->fColorArrayType) { |
| 416 | return false; |
| 417 | } |
| 418 | |
Ben Wagner | 9bc36fd | 2018-06-15 14:23:36 -0400 | [diff] [blame] | 419 | if (fVertexCount + that->fVertexCount > SkTo<int>(UINT16_MAX)) { |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 420 | return false; |
| 421 | } |
| 422 | |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 423 | // NOTE: For SkColor vertex colors, the source color space is always sRGB, and the destination |
| 424 | // gamut is determined by the render target context. A mis-match should be impossible. |
| 425 | SkASSERT(GrColorSpaceXform::Equals(fColorSpaceXform.get(), that->fColorSpaceXform.get())); |
| 426 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 427 | // If either op required explicit local coords or per-vertex colors the combined mesh does. Same |
| 428 | // with multiple view matrices. |
| 429 | fFlags |= that->fFlags; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 430 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 431 | if (!this->requiresPerVertexColors() && this->fMeshes[0].fColor != that->fMeshes[0].fColor) { |
| 432 | fFlags |= kRequiresPerVertexColors_Flag; |
| 433 | } |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 434 | // Check whether we are about to acquire a mesh with a different view matrix. |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 435 | if (!this->hasMultipleViewMatrices() && |
| 436 | !this->fMeshes[0].fViewMatrix.cheapEqualTo(that->fMeshes[0].fViewMatrix)) { |
| 437 | fFlags |= kHasMultipleViewMatrices_Flag; |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 438 | } |
| 439 | |
bsalomon | d92b419 | 2016-06-30 07:59:23 -0700 | [diff] [blame] | 440 | fMeshes.push_back_n(that->fMeshes.count(), that->fMeshes.begin()); |
bsalomon | 14eaaa6 | 2015-09-24 07:01:26 -0700 | [diff] [blame] | 441 | fVertexCount += that->fVertexCount; |
| 442 | fIndexCount += that->fIndexCount; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 443 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 444 | this->joinBounds(*that); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 445 | return true; |
| 446 | } |
| 447 | |
| 448 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 449 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 450 | #if GR_TEST_UTILS |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 451 | |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 452 | #include "GrDrawOpTest.h" |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 453 | |
| 454 | static uint32_t seed_vertices(GrPrimitiveType type) { |
| 455 | switch (type) { |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 456 | case GrPrimitiveType::kTriangles: |
| 457 | case GrPrimitiveType::kTriangleStrip: |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 458 | return 3; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 459 | case GrPrimitiveType::kPoints: |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 460 | return 1; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 461 | case GrPrimitiveType::kLines: |
| 462 | case GrPrimitiveType::kLineStrip: |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 463 | return 2; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 464 | case GrPrimitiveType::kLinesAdjacency: |
| 465 | return 4; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 466 | } |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 467 | SK_ABORT("Incomplete switch\n"); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static uint32_t primitive_vertices(GrPrimitiveType type) { |
| 472 | switch (type) { |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 473 | case GrPrimitiveType::kTriangles: |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 474 | return 3; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 475 | case GrPrimitiveType::kLines: |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 476 | return 2; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 477 | case GrPrimitiveType::kTriangleStrip: |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 478 | case GrPrimitiveType::kPoints: |
| 479 | case GrPrimitiveType::kLineStrip: |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 480 | return 1; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 481 | case GrPrimitiveType::kLinesAdjacency: |
| 482 | return 4; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 483 | } |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 484 | SK_ABORT("Incomplete switch\n"); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static SkPoint random_point(SkRandom* random, SkScalar min, SkScalar max) { |
| 489 | SkPoint p; |
| 490 | p.fX = random->nextRangeScalar(min, max); |
| 491 | p.fY = random->nextRangeScalar(min, max); |
| 492 | return p; |
| 493 | } |
| 494 | |
| 495 | static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkScalar max, |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 496 | SkRandom* random, SkTArray<SkPoint>* positions, |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 497 | SkTArray<SkPoint>* texCoords, bool hasTexCoords, |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 498 | SkTArray<uint32_t>* colors, bool hasColors, |
| 499 | SkTArray<uint16_t>* indices, bool hasIndices) { |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 500 | for (uint32_t v = 0; v < count; v++) { |
| 501 | positions->push_back(random_point(random, min, max)); |
| 502 | if (hasTexCoords) { |
| 503 | texCoords->push_back(random_point(random, min, max)); |
| 504 | } |
| 505 | if (hasColors) { |
| 506 | colors->push_back(GrRandomColor(random)); |
| 507 | } |
| 508 | if (hasIndices) { |
Ben Wagner | b089765 | 2018-06-15 15:37:57 +0000 | [diff] [blame] | 509 | SkASSERT(maxVertex <= UINT16_MAX); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 510 | indices->push_back(random->nextULessThan((uint16_t)maxVertex)); |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 515 | GR_DRAW_OP_TEST_DEFINE(GrDrawVerticesOp) { |
Chris Dalton | b894c2b | 2017-06-14 12:39:19 -0600 | [diff] [blame] | 516 | GrPrimitiveType type; |
| 517 | do { |
| 518 | type = GrPrimitiveType(random->nextULessThan(kNumGrPrimitiveTypes)); |
| 519 | } while (GrPrimTypeRequiresGeometryShaderSupport(type) && |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 520 | !context->contextPriv().caps()->shaderCaps()->geometryShaderSupport()); |
Chris Dalton | b894c2b | 2017-06-14 12:39:19 -0600 | [diff] [blame] | 521 | |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 522 | uint32_t primitiveCount = random->nextRangeU(1, 100); |
| 523 | |
| 524 | // TODO make 'sensible' indexbuffers |
| 525 | SkTArray<SkPoint> positions; |
| 526 | SkTArray<SkPoint> texCoords; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 527 | SkTArray<uint32_t> colors; |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 528 | SkTArray<uint16_t> indices; |
| 529 | |
| 530 | bool hasTexCoords = random->nextBool(); |
| 531 | bool hasIndices = random->nextBool(); |
| 532 | bool hasColors = random->nextBool(); |
| 533 | |
| 534 | uint32_t vertexCount = seed_vertices(type) + (primitiveCount - 1) * primitive_vertices(type); |
| 535 | |
| 536 | static const SkScalar kMinVertExtent = -100.f; |
| 537 | static const SkScalar kMaxVertExtent = 100.f; |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 538 | randomize_params(seed_vertices(type), vertexCount, kMinVertExtent, kMaxVertExtent, random, |
| 539 | &positions, &texCoords, hasTexCoords, &colors, hasColors, &indices, |
| 540 | hasIndices); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 541 | |
| 542 | for (uint32_t i = 1; i < primitiveCount; i++) { |
| 543 | randomize_params(primitive_vertices(type), vertexCount, kMinVertExtent, kMaxVertExtent, |
Brian Salomon | fc527d2 | 2016-12-14 21:07:01 -0500 | [diff] [blame] | 544 | random, &positions, &texCoords, hasTexCoords, &colors, hasColors, &indices, |
| 545 | hasIndices); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 549 | |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 550 | sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(random); |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 551 | |
| 552 | static constexpr SkVertices::VertexMode kIgnoredMode = SkVertices::kTriangles_VertexMode; |
| 553 | sk_sp<SkVertices> vertices = SkVertices::MakeCopy(kIgnoredMode, vertexCount, positions.begin(), |
| 554 | texCoords.begin(), colors.begin(), |
| 555 | hasIndices ? indices.count() : 0, |
| 556 | indices.begin()); |
Brian Salomon | c2f4254 | 2017-07-12 14:11:22 -0400 | [diff] [blame] | 557 | GrAAType aaType = GrAAType::kNone; |
| 558 | if (GrFSAAType::kUnifiedMSAA == fsaaType && random->nextBool()) { |
| 559 | aaType = GrAAType::kMSAA; |
| 560 | } |
Joe Gregorio | 383c9bb | 2018-07-10 20:35:19 +0000 | [diff] [blame] | 561 | return GrDrawVerticesOp::Make(context, std::move(paint), std::move(vertices), |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 562 | viewMatrix, aaType, std::move(colorSpaceXform), &type); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | #endif |