Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | #include "GrCCDrawPathsOp.h" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame^] | 9 | #include "GrContext.h" |
| 10 | #include "GrContextPriv.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 11 | #include "GrMemoryPool.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 12 | #include "GrOpFlushState.h" |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 13 | #include "ccpr/GrCCPathCache.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 14 | #include "ccpr/GrCCPerFlushResources.h" |
| 15 | #include "ccpr/GrCoverageCountingPathRenderer.h" |
| 16 | |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 17 | static bool has_coord_transforms(const GrPaint& paint) { |
| 18 | GrFragmentProcessor::Iter iter(paint); |
| 19 | while (const GrFragmentProcessor* fp = iter.next()) { |
| 20 | if (!fp->coordTransforms().empty()) { |
| 21 | return true; |
| 22 | } |
| 23 | } |
| 24 | return false; |
| 25 | } |
| 26 | |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 27 | static int64_t area(const SkIRect& r) { |
| 28 | return sk_64_mul(r.height(), r.width()); |
| 29 | } |
| 30 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 31 | std::unique_ptr<GrCCDrawPathsOp> GrCCDrawPathsOp::Make(GrContext* context, |
| 32 | const SkIRect& clipIBounds, |
| 33 | const SkMatrix& m, |
| 34 | const GrShape& shape, |
| 35 | const SkRect& devBounds, |
| 36 | GrPaint&& paint) { |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 37 | SkIRect shapeDevIBounds; |
| 38 | devBounds.roundOut(&shapeDevIBounds); // GrCCPathParser might find slightly tighter bounds. |
| 39 | |
| 40 | SkIRect maskDevIBounds; |
| 41 | Visibility maskVisibility; |
| 42 | if (clipIBounds.contains(shapeDevIBounds)) { |
| 43 | maskDevIBounds = shapeDevIBounds; |
| 44 | maskVisibility = Visibility::kComplete; |
| 45 | } else { |
| 46 | if (!maskDevIBounds.intersect(clipIBounds, shapeDevIBounds)) { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 47 | return nullptr; |
| 48 | } |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 49 | int64_t unclippedArea = area(shapeDevIBounds); |
| 50 | int64_t clippedArea = area(maskDevIBounds); |
| 51 | maskVisibility = (clippedArea >= unclippedArea/2 || unclippedArea < 100*100) |
| 52 | ? Visibility::kMostlyComplete // i.e., visible enough to justify rendering the |
| 53 | // whole thing if we think we can cache it. |
| 54 | : Visibility::kPartial; |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 55 | } |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 56 | |
| 57 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 58 | |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 59 | return pool->allocate<GrCCDrawPathsOp>(m, shape, shapeDevIBounds, maskDevIBounds, |
| 60 | maskVisibility, devBounds, std::move(paint)); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 61 | } |
| 62 | |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 63 | GrCCDrawPathsOp::GrCCDrawPathsOp(const SkMatrix& m, const GrShape& shape, |
| 64 | const SkIRect& shapeDevIBounds, const SkIRect& maskDevIBounds, |
| 65 | Visibility maskVisibility, const SkRect& devBounds, |
| 66 | GrPaint&& paint) |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 67 | : GrDrawOp(ClassID()) |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 68 | , fViewMatrixIfUsingLocalCoords(has_coord_transforms(paint) ? m : SkMatrix::I()) |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 69 | , fDraws(m, shape, shapeDevIBounds, maskDevIBounds, maskVisibility, paint.getColor()) |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 70 | , fProcessors(std::move(paint)) { // Paint must be moved after fetching its color above. |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 71 | SkDEBUGCODE(fBaseInstance = -1); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 72 | // FIXME: intersect with clip bounds to (hopefully) improve batching. |
| 73 | // (This is nontrivial due to assumptions in generating the octagon cover geometry.) |
| 74 | this->setBounds(devBounds, GrOp::HasAABloat::kYes, GrOp::IsZeroArea::kNo); |
| 75 | } |
| 76 | |
| 77 | GrCCDrawPathsOp::~GrCCDrawPathsOp() { |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 78 | if (fOwningPerOpListPaths) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 79 | // Remove CCPR's dangling pointer to this Op before deleting it. |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 80 | fOwningPerOpListPaths->fDrawOps.remove(this); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 81 | } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 82 | } |
| 83 | |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 84 | GrCCDrawPathsOp::SingleDraw::SingleDraw(const SkMatrix& m, const GrShape& shape, |
| 85 | const SkIRect& shapeDevIBounds, |
| 86 | const SkIRect& maskDevIBounds, Visibility maskVisibility, |
| 87 | GrColor color) |
| 88 | : fMatrix(m) |
Chris Dalton | 644341a | 2018-06-18 19:14:16 -0600 | [diff] [blame] | 89 | , fShape(shape) |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 90 | , fShapeDevIBounds(shapeDevIBounds) |
| 91 | , fMaskDevIBounds(maskDevIBounds) |
| 92 | , fMaskVisibility(maskVisibility) |
| 93 | , fColor(color) { |
Chris Dalton | 644341a | 2018-06-18 19:14:16 -0600 | [diff] [blame] | 94 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 95 | if (fShape.hasUnstyledKey()) { |
| 96 | // On AOSP we round view matrix translates to integer values for cachable paths. We do this |
| 97 | // to match HWUI's cache hit ratio, which doesn't consider the matrix when caching paths. |
| 98 | fMatrix.setTranslateX(SkScalarRoundToScalar(fMatrix.getTranslateX())); |
| 99 | fMatrix.setTranslateY(SkScalarRoundToScalar(fMatrix.getTranslateY())); |
| 100 | } |
| 101 | #endif |
| 102 | } |
| 103 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 104 | GrCCDrawPathsOp::SingleDraw::~SingleDraw() { |
| 105 | if (fCacheEntry) { |
| 106 | // All currFlushAtlas references must be reset back to null before the flush is finished. |
| 107 | fCacheEntry->setCurrFlushAtlas(nullptr); |
| 108 | } |
| 109 | } |
| 110 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 111 | GrDrawOp::RequiresDstTexture GrCCDrawPathsOp::finalize(const GrCaps& caps, |
| 112 | const GrAppliedClip* clip, |
| 113 | GrPixelConfigIsClamped dstIsClamped) { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 114 | SkASSERT(1 == fNumDraws); // There should only be one single path draw in this Op right now. |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 115 | GrProcessorSet::Analysis analysis = |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 116 | fProcessors.finalize(fDraws.head().fColor, GrProcessorAnalysisCoverage::kSingleChannel, |
| 117 | clip, false, caps, dstIsClamped, &fDraws.head().fColor); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 118 | return RequiresDstTexture(analysis.requiresDstTexture()); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 119 | } |
| 120 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 121 | bool GrCCDrawPathsOp::onCombineIfPossible(GrOp* op, const GrCaps&) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 122 | GrCCDrawPathsOp* that = op->cast<GrCCDrawPathsOp>(); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 123 | SkASSERT(fOwningPerOpListPaths); |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 124 | SkASSERT(fNumDraws); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 125 | SkASSERT(!that->fOwningPerOpListPaths || that->fOwningPerOpListPaths == fOwningPerOpListPaths); |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 126 | SkASSERT(that->fNumDraws); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 127 | |
Brian Osman | 9aa30c6 | 2018-07-02 15:21:46 -0400 | [diff] [blame] | 128 | if (fProcessors != that->fProcessors || |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 129 | fViewMatrixIfUsingLocalCoords != that->fViewMatrixIfUsingLocalCoords) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 130 | return false; |
| 131 | } |
| 132 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 133 | fDraws.append(std::move(that->fDraws), &fOwningPerOpListPaths->fAllocator); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 134 | this->joinBounds(*that); |
| 135 | |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 136 | SkDEBUGCODE(fNumDraws += that->fNumDraws); |
| 137 | SkDEBUGCODE(that->fNumDraws = 0); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 138 | return true; |
| 139 | } |
| 140 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 141 | void GrCCDrawPathsOp::wasRecorded(GrCCPerOpListPaths* owningPerOpListPaths) { |
Chris Dalton | f104fec | 2018-05-22 16:17:48 -0600 | [diff] [blame] | 142 | SkASSERT(1 == fNumDraws); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 143 | SkASSERT(!fOwningPerOpListPaths); |
| 144 | owningPerOpListPaths->fDrawOps.addToTail(this); |
| 145 | fOwningPerOpListPaths = owningPerOpListPaths; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 146 | } |
| 147 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 148 | void GrCCDrawPathsOp::accountForOwnPaths(GrCCPathCache* pathCache, |
| 149 | GrOnFlushResourceProvider* onFlushRP, |
| 150 | const GrUniqueKey& stashedAtlasKey, |
| 151 | GrCCPerFlushResourceSpecs* specs) { |
| 152 | using CreateIfAbsent = GrCCPathCache::CreateIfAbsent; |
| 153 | using MaskTransform = GrCCPathCache::MaskTransform; |
| 154 | |
| 155 | for (SingleDraw& draw : fDraws) { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 156 | SkPath path; |
| 157 | draw.fShape.asPath(&path); |
| 158 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 159 | SkASSERT(!draw.fCacheEntry); |
| 160 | |
| 161 | if (pathCache) { |
| 162 | MaskTransform m(draw.fMatrix, &draw.fCachedMaskShift); |
| 163 | bool canStashPathMask = draw.fMaskVisibility >= Visibility::kMostlyComplete; |
| 164 | draw.fCacheEntry = pathCache->find(draw.fShape, m, CreateIfAbsent(canStashPathMask)); |
| 165 | } |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 166 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 167 | if (auto cacheEntry = draw.fCacheEntry.get()) { |
| 168 | SkASSERT(!cacheEntry->currFlushAtlas()); // Shouldn't be set until setupResources(). |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 169 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 170 | if (cacheEntry->atlasKey().isValid()) { |
| 171 | // Does the path already exist in a cached atlas? |
| 172 | if (cacheEntry->hasCachedAtlas() && |
| 173 | (draw.fCachedAtlasProxy = onFlushRP->findOrCreateProxyByUniqueKey( |
| 174 | cacheEntry->atlasKey(), |
| 175 | GrCCAtlas::kTextureOrigin))) { |
| 176 | ++specs->fNumCachedPaths; |
| 177 | continue; |
| 178 | } |
| 179 | |
| 180 | // Does the path exist in the atlas that we stashed away from last flush? If so we |
| 181 | // can copy it into a new 8-bit atlas and keep it in the resource cache. |
| 182 | if (stashedAtlasKey.isValid() && stashedAtlasKey == cacheEntry->atlasKey()) { |
| 183 | SkASSERT(!cacheEntry->hasCachedAtlas()); |
| 184 | ++specs->fNumCopiedPaths; |
| 185 | specs->fCopyPathStats.statPath(path); |
| 186 | specs->fCopyAtlasSpecs.accountForSpace(cacheEntry->width(), |
| 187 | cacheEntry->height()); |
| 188 | continue; |
| 189 | } |
| 190 | |
| 191 | // Whatever atlas the path used to reside in, it no longer exists. |
| 192 | cacheEntry->resetAtlasKeyAndInfo(); |
| 193 | } |
| 194 | |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 195 | if (Visibility::kMostlyComplete == draw.fMaskVisibility && cacheEntry->hitCount() > 1 && |
| 196 | SkTMax(draw.fShapeDevIBounds.height(), |
| 197 | draw.fShapeDevIBounds.width()) <= onFlushRP->caps()->maxRenderTargetSize()) { |
| 198 | // We've seen this path before with a compatible matrix, and it's mostly visible. |
| 199 | // Just render the whole mask so we can try to cache it. |
| 200 | draw.fMaskDevIBounds = draw.fShapeDevIBounds; |
| 201 | draw.fMaskVisibility = Visibility::kComplete; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | ++specs->fNumRenderedPaths; |
| 206 | specs->fRenderedPathStats.statPath(path); |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 207 | specs->fRenderedAtlasSpecs.accountForSpace(draw.fMaskDevIBounds.width(), |
| 208 | draw.fMaskDevIBounds.height()); |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 209 | } |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 210 | } |
| 211 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 212 | void GrCCDrawPathsOp::setupResources(GrOnFlushResourceProvider* onFlushRP, |
| 213 | GrCCPerFlushResources* resources, DoCopiesToCache doCopies) { |
| 214 | using DoEvenOddFill = GrCCPathProcessor::DoEvenOddFill; |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 215 | SkASSERT(fNumDraws > 0); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 216 | SkASSERT(-1 == fBaseInstance); |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 217 | fBaseInstance = resources->nextPathInstanceIdx(); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 218 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 219 | for (SingleDraw& draw : fDraws) { |
| 220 | SkPath path; |
| 221 | draw.fShape.asPath(&path); |
| 222 | |
| 223 | auto doEvenOddFill = DoEvenOddFill(SkPath::kEvenOdd_FillType == path.getFillType()); |
| 224 | SkASSERT(SkPath::kEvenOdd_FillType == path.getFillType() || |
| 225 | SkPath::kWinding_FillType == path.getFillType()); |
| 226 | |
| 227 | if (auto cacheEntry = draw.fCacheEntry.get()) { |
| 228 | // Does the path already exist in a cached atlas texture? |
| 229 | if (auto proxy = draw.fCachedAtlasProxy.get()) { |
| 230 | SkASSERT(!cacheEntry->currFlushAtlas()); |
| 231 | this->recordInstance(proxy, resources->nextPathInstanceIdx()); |
| 232 | resources->appendDrawPathInstance().set(*cacheEntry, draw.fCachedMaskShift, |
| 233 | draw.fColor); |
| 234 | continue; |
| 235 | } |
| 236 | |
| 237 | // Have we already encountered this path during the flush? (i.e. was the same SkPath |
| 238 | // drawn more than once during the same flush, with a compatible matrix?) |
| 239 | if (auto atlas = cacheEntry->currFlushAtlas()) { |
| 240 | this->recordInstance(atlas->textureProxy(), resources->nextPathInstanceIdx()); |
| 241 | resources->appendDrawPathInstance().set( |
| 242 | *cacheEntry, draw.fCachedMaskShift, draw.fColor, |
| 243 | cacheEntry->hasCachedAtlas() ? DoEvenOddFill::kNo : doEvenOddFill); |
| 244 | continue; |
| 245 | } |
| 246 | |
| 247 | // If the cache entry still has a valid atlas key at this point, it means the path |
| 248 | // exists in the atlas that we stashed away from last flush. Copy it into a permanent |
| 249 | // 8-bit atlas in the resource cache. |
| 250 | if (DoCopiesToCache::kYes == doCopies && cacheEntry->atlasKey().isValid()) { |
| 251 | SkIVector newOffset; |
| 252 | GrCCAtlas* atlas = |
| 253 | resources->copyPathToCachedAtlas(*cacheEntry, doEvenOddFill, &newOffset); |
| 254 | cacheEntry->updateToCachedAtlas(atlas->getOrAssignUniqueKey(onFlushRP), |
| 255 | newOffset, atlas->refOrMakeCachedAtlasInfo()); |
| 256 | this->recordInstance(atlas->textureProxy(), resources->nextPathInstanceIdx()); |
| 257 | resources->appendDrawPathInstance().set(*cacheEntry, draw.fCachedMaskShift, |
| 258 | draw.fColor); |
| 259 | // Remember this atlas in case we encounter the path again during the same flush. |
| 260 | cacheEntry->setCurrFlushAtlas(atlas); |
| 261 | continue; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | // Render the raw path into a coverage count atlas. renderPathInAtlas() gives us two tight |
| 266 | // bounding boxes: One in device space, as well as a second one rotated an additional 45 |
| 267 | // degrees. The path vertex shader uses these two bounding boxes to generate an octagon that |
| 268 | // circumscribes the path. |
| 269 | SkASSERT(!draw.fCachedAtlasProxy); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 270 | SkRect devBounds, devBounds45; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 271 | SkIRect devIBounds; |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 272 | SkIVector devToAtlasOffset; |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 273 | if (auto atlas = resources->renderPathInAtlas(draw.fMaskDevIBounds, draw.fMatrix, path, |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 274 | &devBounds, &devBounds45, &devIBounds, |
| 275 | &devToAtlasOffset)) { |
| 276 | this->recordInstance(atlas->textureProxy(), resources->nextPathInstanceIdx()); |
| 277 | resources->appendDrawPathInstance().set(devBounds, devBounds45, devToAtlasOffset, |
| 278 | draw.fColor, doEvenOddFill); |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 279 | |
| 280 | // If we have a spot in the path cache, try to make a note of where this mask is so we |
| 281 | // can reuse it in the future. |
| 282 | if (auto cacheEntry = draw.fCacheEntry.get()) { |
| 283 | SkASSERT(!cacheEntry->hasCachedAtlas()); |
| 284 | |
| 285 | if (Visibility::kComplete != draw.fMaskVisibility || cacheEntry->hitCount() <= 1) { |
| 286 | // Don't cache a path mask unless it's completely visible with a hit count > 1. |
| 287 | // |
| 288 | // NOTE: mostly-visible paths with a hit count > 1 should have been promoted to |
| 289 | // fully visible during accountForOwnPaths(). |
| 290 | continue; |
| 291 | } |
| 292 | |
| 293 | if (resources->nextAtlasToStash() != atlas) { |
| 294 | // This mask does not belong to the atlas that will be stashed for next flush. |
| 295 | continue; |
| 296 | } |
| 297 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 298 | const GrUniqueKey& atlasKey = |
| 299 | resources->nextAtlasToStash()->getOrAssignUniqueKey(onFlushRP); |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 300 | cacheEntry->initAsStashedAtlas(atlasKey, devToAtlasOffset, devBounds, devBounds45, |
| 301 | devIBounds, draw.fCachedMaskShift); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 302 | // Remember this atlas in case we encounter the path again during the same flush. |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 303 | cacheEntry->setCurrFlushAtlas(atlas); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 304 | } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 305 | continue; |
| 306 | } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 307 | } |
| 308 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 309 | if (!fInstanceRanges.empty()) { |
| 310 | fInstanceRanges.back().fEndInstanceIdx = resources->nextPathInstanceIdx(); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | inline void GrCCDrawPathsOp::recordInstance(const GrTextureProxy* atlasProxy, int instanceIdx) { |
| 315 | if (fInstanceRanges.empty()) { |
| 316 | fInstanceRanges.push_back({atlasProxy, instanceIdx}); |
| 317 | return; |
| 318 | } |
| 319 | if (fInstanceRanges.back().fAtlasProxy != atlasProxy) { |
| 320 | fInstanceRanges.back().fEndInstanceIdx = instanceIdx; |
| 321 | fInstanceRanges.push_back({atlasProxy, instanceIdx}); |
| 322 | return; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | void GrCCDrawPathsOp::onExecute(GrOpFlushState* flushState) { |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 327 | SkASSERT(fOwningPerOpListPaths); |
Chris Dalton | f104fec | 2018-05-22 16:17:48 -0600 | [diff] [blame] | 328 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 329 | const GrCCPerFlushResources* resources = fOwningPerOpListPaths->fFlushResources.get(); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 330 | if (!resources) { |
| 331 | return; // Setup failed. |
| 332 | } |
| 333 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 334 | GrPipeline::InitArgs initArgs; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 335 | initArgs.fProxy = flushState->drawOpArgs().fProxy; |
| 336 | initArgs.fCaps = &flushState->caps(); |
| 337 | initArgs.fResourceProvider = flushState->resourceProvider(); |
| 338 | initArgs.fDstProxy = flushState->drawOpArgs().fDstProxy; |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 339 | auto clip = flushState->detachAppliedClip(); |
| 340 | GrPipeline::FixedDynamicState fixedDynamicState(clip.scissorState().rect()); |
| 341 | GrPipeline pipeline(initArgs, std::move(fProcessors), std::move(clip)); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 342 | |
| 343 | int baseInstance = fBaseInstance; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 344 | SkASSERT(baseInstance >= 0); // Make sure setupResources() has been called. |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 345 | |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 346 | for (const InstanceRange& range : fInstanceRanges) { |
| 347 | SkASSERT(range.fEndInstanceIdx > baseInstance); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 348 | |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 349 | GrCCPathProcessor pathProc(flushState->resourceProvider(), sk_ref_sp(range.fAtlasProxy), |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 350 | fViewMatrixIfUsingLocalCoords); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 351 | pathProc.drawPaths(flushState, pipeline, &fixedDynamicState, *resources, baseInstance, |
| 352 | range.fEndInstanceIdx, this->bounds()); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 353 | |
| 354 | baseInstance = range.fEndInstanceIdx; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 355 | } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 356 | } |