ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2015 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "GrAALinearizingConvexPathRenderer.h" |
| 10 | |
| 11 | #include "GrAAConvexTessellator.h" |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 12 | #include "GrBatchFlushState.h" |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 13 | #include "GrBatchTest.h" |
| 14 | #include "GrContext.h" |
| 15 | #include "GrDefaultGeoProcFactory.h" |
| 16 | #include "GrGeometryProcessor.h" |
| 17 | #include "GrInvariantOutput.h" |
| 18 | #include "GrPathUtils.h" |
| 19 | #include "GrProcessor.h" |
| 20 | #include "GrPipelineBuilder.h" |
| 21 | #include "GrStrokeInfo.h" |
| 22 | #include "SkGeometry.h" |
| 23 | #include "SkString.h" |
| 24 | #include "SkTraceEvent.h" |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 25 | #include "SkPathPriv.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 26 | #include "batches/GrVertexBatch.h" |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 27 | #include "gl/GrGLProcessor.h" |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 28 | #include "gl/GrGLGeometryProcessor.h" |
| 29 | #include "gl/builders/GrGLProgramBuilder.h" |
| 30 | |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 31 | static const int DEFAULT_BUFFER_SIZE = 100; |
| 32 | |
| 33 | // The thicker the stroke, the harder it is to produce high-quality results using tessellation. For |
| 34 | // the time being, we simply drop back to software rendering above this stroke width. |
| 35 | static const SkScalar kMaxStrokeWidth = 20.0; |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 36 | |
| 37 | GrAALinearizingConvexPathRenderer::GrAALinearizingConvexPathRenderer() { |
| 38 | } |
| 39 | |
| 40 | /////////////////////////////////////////////////////////////////////////////// |
| 41 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 42 | bool GrAALinearizingConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
| 43 | if (!args.fAntiAlias) { |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 44 | return false; |
| 45 | } |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 46 | if (args.fPath->isInverseFillType()) { |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 47 | return false; |
| 48 | } |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 49 | if (!args.fPath->isConvex()) { |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 50 | return false; |
| 51 | } |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 52 | if (args.fStroke->getStyle() == SkStrokeRec::kStroke_Style) { |
ethannicholas | fea7763 | 2015-08-19 12:09:12 -0700 | [diff] [blame] | 53 | if (!args.fViewMatrix->isSimilarity()) { |
| 54 | return false; |
| 55 | } |
| 56 | SkScalar strokeWidth = args.fViewMatrix->getMaxScale() * args.fStroke->getWidth(); |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 57 | return strokeWidth >= 1.0f && strokeWidth <= kMaxStrokeWidth && !args.fStroke->isDashed() && |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 58 | SkPathPriv::LastVerbIsClose(*args.fPath) && |
| 59 | args.fStroke->getJoin() != SkPaint::Join::kRound_Join; |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 60 | } |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 61 | return args.fStroke->getStyle() == SkStrokeRec::kFill_Style; |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | // extract the result vertices and indices from the GrAAConvexTessellator |
| 65 | static void extract_verts(const GrAAConvexTessellator& tess, |
| 66 | void* vertices, |
| 67 | size_t vertexStride, |
| 68 | GrColor color, |
| 69 | uint16_t firstIndex, |
| 70 | uint16_t* idxs, |
| 71 | bool tweakAlphaForCoverage) { |
| 72 | intptr_t verts = reinterpret_cast<intptr_t>(vertices); |
| 73 | |
| 74 | for (int i = 0; i < tess.numPts(); ++i) { |
| 75 | *((SkPoint*)((intptr_t)verts + i * vertexStride)) = tess.point(i); |
| 76 | } |
| 77 | |
| 78 | // Make 'verts' point to the colors |
| 79 | verts += sizeof(SkPoint); |
| 80 | for (int i = 0; i < tess.numPts(); ++i) { |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 81 | if (tweakAlphaForCoverage) { |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 82 | SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255); |
| 83 | unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i)); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 84 | GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale); |
| 85 | *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor; |
| 86 | } else { |
| 87 | *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color; |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 88 | *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) = |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 89 | tess.coverage(i); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
| 93 | for (int i = 0; i < tess.numIndices(); ++i) { |
| 94 | idxs[i] = tess.index(i) + firstIndex; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage, |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 99 | const SkMatrix& viewMatrix, |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 100 | bool usesLocalCoords, |
| 101 | bool coverageIgnored) { |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 102 | using namespace GrDefaultGeoProcFactory; |
joshualitt | e494a58 | 2015-08-03 09:32:36 -0700 | [diff] [blame] | 103 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 104 | Color color(Color::kAttribute_Type); |
| 105 | Coverage::Type coverageType; |
| 106 | // TODO remove coverage if coverage is ignored |
| 107 | /*if (coverageIgnored) { |
| 108 | coverageType = Coverage::kNone_Type; |
| 109 | } else*/ if (tweakAlphaForCoverage) { |
| 110 | coverageType = Coverage::kSolid_Type; |
| 111 | } else { |
| 112 | coverageType = Coverage::kAttribute_Type; |
| 113 | } |
| 114 | Coverage coverage(coverageType); |
| 115 | LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type : |
| 116 | LocalCoords::kUnused_Type); |
| 117 | return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 118 | } |
| 119 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 120 | class AAFlatteningConvexPathBatch : public GrVertexBatch { |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 121 | public: |
| 122 | struct Geometry { |
| 123 | GrColor fColor; |
| 124 | SkMatrix fViewMatrix; |
| 125 | SkPath fPath; |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 126 | SkScalar fStrokeWidth; |
| 127 | SkPaint::Join fJoin; |
| 128 | SkScalar fMiterLimit; |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 131 | static GrDrawBatch* Create(const Geometry& geometry) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame^] | 132 | return new AAFlatteningConvexPathBatch(geometry); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | const char* name() const override { return "AAConvexBatch"; } |
| 136 | |
| 137 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 138 | // When this is called on a batch, there is only one geometry bundle |
| 139 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 140 | } |
| 141 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 142 | out->setUnknownSingleComponent(); |
| 143 | } |
| 144 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 145 | private: |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 146 | void initBatchTracker(const GrPipelineOptimizations& opt) override { |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 147 | // Handle any color overrides |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 148 | if (!opt.readsColor()) { |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 149 | fGeoData[0].fColor = GrColor_ILLEGAL; |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 150 | } |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 151 | opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 152 | |
| 153 | // setup batch properties |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 154 | fBatch.fColorIgnored = !opt.readsColor(); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 155 | fBatch.fColor = fGeoData[0].fColor; |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 156 | fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
| 157 | fBatch.fCoverageIgnored = !opt.readsCoverage(); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 158 | fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSegmentMasks(); |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 159 | fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 160 | } |
| 161 | |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 162 | void draw(GrVertexBatch::Target* target, const GrPipeline* pipeline, int vertexCount, |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 163 | size_t vertexStride, void* vertices, int indexCount, uint16_t* indices) { |
| 164 | if (vertexCount == 0 || indexCount == 0) { |
| 165 | return; |
| 166 | } |
| 167 | const GrVertexBuffer* vertexBuffer; |
| 168 | GrVertices info; |
| 169 | int firstVertex; |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 170 | void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 171 | &firstVertex); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 172 | if (!verts) { |
| 173 | SkDebugf("Could not allocate vertices\n"); |
| 174 | return; |
| 175 | } |
| 176 | memcpy(verts, vertices, vertexCount * vertexStride); |
| 177 | |
| 178 | const GrIndexBuffer* indexBuffer; |
| 179 | int firstIndex; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 180 | uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 181 | if (!idxs) { |
| 182 | SkDebugf("Could not allocate indices\n"); |
| 183 | return; |
| 184 | } |
| 185 | memcpy(idxs, indices, indexCount * sizeof(uint16_t)); |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 186 | info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, firstVertex, |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 187 | firstIndex, vertexCount, indexCount); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 188 | target->draw(info); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 189 | } |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 190 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 191 | void onPrepareDraws(Target* target) override { |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 192 | bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 193 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 194 | // Setup GrGeometryProcessor |
| 195 | SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaForCoverage, |
| 196 | this->viewMatrix(), |
| 197 | this->usesLocalCoords(), |
| 198 | this->coverageIgnored())); |
| 199 | if (!gp) { |
| 200 | SkDebugf("Couldn't create a GrGeometryProcessor\n"); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 201 | return; |
| 202 | } |
| 203 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 204 | target->initDraw(gp, this->pipeline()); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 205 | |
| 206 | size_t vertexStride = gp->getVertexStride(); |
| 207 | |
| 208 | SkASSERT(canTweakAlphaForCoverage ? |
| 209 | vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) : |
| 210 | vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); |
| 211 | |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 212 | int instanceCount = fGeoData.count(); |
| 213 | |
| 214 | int vertexCount = 0; |
| 215 | int indexCount = 0; |
| 216 | int maxVertices = DEFAULT_BUFFER_SIZE; |
| 217 | int maxIndices = DEFAULT_BUFFER_SIZE; |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 218 | uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStride); |
| 219 | uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint16_t)); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 220 | for (int i = 0; i < instanceCount; i++) { |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 221 | Geometry& args = fGeoData[i]; |
fmalita | bd5d7e7 | 2015-06-26 07:18:24 -0700 | [diff] [blame] | 222 | GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMiterLimit); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 223 | |
| 224 | if (!tess.tessellate(args.fViewMatrix, args.fPath)) { |
| 225 | continue; |
| 226 | } |
| 227 | |
| 228 | int currentIndices = tess.numIndices(); |
| 229 | SkASSERT(currentIndices <= UINT16_MAX); |
| 230 | if (indexCount + currentIndices > UINT16_MAX) { |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 231 | // if we added the current instance, we would overflow the indices we can store in a |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 232 | // uint16_t. Draw what we've got so far and reset. |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 233 | draw(target, this->pipeline(), vertexCount, vertexStride, vertices, indexCount, |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 234 | indices); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 235 | vertexCount = 0; |
| 236 | indexCount = 0; |
| 237 | } |
| 238 | int currentVertices = tess.numPts(); |
| 239 | if (vertexCount + currentVertices > maxVertices) { |
| 240 | maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2); |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 241 | vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * vertexStride); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 242 | } |
| 243 | if (indexCount + currentIndices > maxIndices) { |
| 244 | maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2); |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 245 | indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t)); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 246 | } |
| 247 | |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 248 | extract_verts(tess, vertices + vertexStride * vertexCount, vertexStride, args.fColor, |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 249 | vertexCount, indices + indexCount, canTweakAlphaForCoverage); |
| 250 | vertexCount += currentVertices; |
| 251 | indexCount += currentIndices; |
| 252 | } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 253 | draw(target, this->pipeline(), vertexCount, vertexStride, vertices, indexCount, |
bsalomon | fb1141a | 2015-08-06 08:52:49 -0700 | [diff] [blame] | 254 | indices); |
mtklein | 002c2ce | 2015-08-26 05:43:22 -0700 | [diff] [blame] | 255 | sk_free(vertices); |
| 256 | sk_free(indices); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 260 | |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 261 | AAFlatteningConvexPathBatch(const Geometry& geometry) { |
| 262 | this->initClassID<AAFlatteningConvexPathBatch>(); |
| 263 | fGeoData.push_back(geometry); |
| 264 | |
| 265 | // compute bounds |
| 266 | fBounds = geometry.fPath.getBounds(); |
| 267 | geometry.fViewMatrix.mapRect(&fBounds); |
| 268 | } |
| 269 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 270 | bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 271 | AAFlatteningConvexPathBatch* that = t->cast<AAFlatteningConvexPathBatch>(); |
| 272 | if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), |
| 273 | that->bounds(), caps)) { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 274 | return false; |
| 275 | } |
| 276 | |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 277 | SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 278 | if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 279 | return false; |
| 280 | } |
| 281 | |
| 282 | // In the event of two batches, one who can tweak, one who cannot, we just fall back to |
| 283 | // not tweaking |
| 284 | if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()) { |
| 285 | fBatch.fCanTweakAlphaForCoverage = false; |
| 286 | } |
| 287 | |
| 288 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
| 289 | this->joinBounds(that->bounds()); |
| 290 | return true; |
| 291 | } |
| 292 | |
| 293 | GrColor color() const { return fBatch.fColor; } |
| 294 | bool linesOnly() const { return fBatch.fLinesOnly; } |
| 295 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 296 | bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCoverage; } |
| 297 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 298 | bool coverageIgnored() const { return fBatch.fCoverageIgnored; } |
| 299 | |
| 300 | struct BatchTracker { |
| 301 | GrColor fColor; |
| 302 | bool fUsesLocalCoords; |
| 303 | bool fColorIgnored; |
| 304 | bool fCoverageIgnored; |
| 305 | bool fLinesOnly; |
| 306 | bool fCanTweakAlphaForCoverage; |
| 307 | }; |
| 308 | |
| 309 | BatchTracker fBatch; |
| 310 | SkSTArray<1, Geometry, true> fGeoData; |
| 311 | }; |
| 312 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 313 | bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 314 | if (args.fPath->isEmpty()) { |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 315 | return true; |
| 316 | } |
| 317 | AAFlatteningConvexPathBatch::Geometry geometry; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 318 | geometry.fColor = args.fColor; |
| 319 | geometry.fViewMatrix = *args.fViewMatrix; |
| 320 | geometry.fPath = *args.fPath; |
| 321 | geometry.fStrokeWidth = args.fStroke->isFillStyle() ? -1.0f : args.fStroke->getWidth(); |
| 322 | geometry.fJoin = args.fStroke->isFillStyle() ? SkPaint::Join::kMiter_Join : |
| 323 | args.fStroke->getJoin(); |
| 324 | geometry.fMiterLimit = args.fStroke->getMiter(); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 325 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 326 | SkAutoTUnref<GrDrawBatch> batch(AAFlatteningConvexPathBatch::Create(geometry)); |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 327 | args.fTarget->drawBatch(*args.fPipelineBuilder, batch); |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 328 | |
| 329 | return true; |
| 330 | } |
| 331 | |
| 332 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 333 | |
| 334 | #ifdef GR_TEST_UTILS |
| 335 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 336 | DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { |
ethannicholas | 1a1b3ac | 2015-06-10 12:11:17 -0700 | [diff] [blame] | 337 | AAFlatteningConvexPathBatch::Geometry geometry; |
| 338 | geometry.fColor = GrRandomColor(random); |
| 339 | geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); |
| 340 | geometry.fPath = GrTest::TestPathConvex(random); |
| 341 | |
| 342 | return AAFlatteningConvexPathBatch::Create(geometry); |
| 343 | } |
| 344 | |
| 345 | #endif |