• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 "include/private/SkTo.h"
9 #include "src/core/SkClipOpPriv.h"
10 #include "src/core/SkMakeUnique.h"
11 #include "src/core/SkTaskGroup.h"
12 #include "src/core/SkTraceEvent.h"
13 #include "src/gpu/GrAppliedClip.h"
14 #include "src/gpu/GrClipStackClip.h"
15 #include "src/gpu/GrContextPriv.h"
16 #include "src/gpu/GrDeferredProxyUploader.h"
17 #include "src/gpu/GrDrawingManager.h"
18 #include "src/gpu/GrFixedClip.h"
19 #include "src/gpu/GrGpuResourcePriv.h"
20 #include "src/gpu/GrProxyProvider.h"
21 #include "src/gpu/GrRecordingContextPriv.h"
22 #include "src/gpu/GrRenderTargetContextPriv.h"
23 #include "src/gpu/GrSWMaskHelper.h"
24 #include "src/gpu/GrStencilAttachment.h"
25 #include "src/gpu/GrStyle.h"
26 #include "src/gpu/GrTextureProxy.h"
27 #include "src/gpu/effects/GrConvexPolyEffect.h"
28 #include "src/gpu/effects/GrRRectEffect.h"
29 #include "src/gpu/effects/GrTextureDomain.h"
30 #include "src/gpu/geometry/GrShape.h"
31 
32 typedef SkClipStack::Element Element;
33 typedef GrReducedClip::InitialState InitialState;
34 typedef GrReducedClip::ElementList ElementList;
35 
36 const char GrClipStackClip::kMaskTestTag[] = "clip_mask";
37 
quickContains(const SkRect & rect) const38 bool GrClipStackClip::quickContains(const SkRect& rect) const {
39     if (!fStack || fStack->isWideOpen()) {
40         return true;
41     }
42     return fStack->quickContains(rect);
43 }
44 
quickContains(const SkRRect & rrect) const45 bool GrClipStackClip::quickContains(const SkRRect& rrect) const {
46     if (!fStack || fStack->isWideOpen()) {
47         return true;
48     }
49     return fStack->quickContains(rrect);
50 }
51 
isRRect(const SkRect & origRTBounds,SkRRect * rr,GrAA * aa) const52 bool GrClipStackClip::isRRect(const SkRect& origRTBounds, SkRRect* rr, GrAA* aa) const {
53     if (!fStack) {
54         return false;
55     }
56     const SkRect* rtBounds = &origRTBounds;
57     bool isAA;
58     if (fStack->isRRect(*rtBounds, rr, &isAA)) {
59         *aa = GrAA(isAA);
60         return true;
61     }
62     return false;
63 }
64 
getConservativeBounds(int width,int height,SkIRect * devResult,bool * isIntersectionOfRects) const65 void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult,
66                                             bool* isIntersectionOfRects) const {
67     if (!fStack) {
68         devResult->setXYWH(0, 0, width, height);
69         if (isIntersectionOfRects) {
70             *isIntersectionOfRects = true;
71         }
72         return;
73     }
74     SkRect devBounds;
75     fStack->getConservativeBounds(0, 0, width, height, &devBounds, isIntersectionOfRects);
76     devBounds.roundOut(devResult);
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 // set up the draw state to enable the aa clipping mask.
create_fp_for_mask(sk_sp<GrTextureProxy> mask,const SkIRect & devBound)81 static std::unique_ptr<GrFragmentProcessor> create_fp_for_mask(sk_sp<GrTextureProxy> mask,
82                                                                const SkIRect& devBound) {
83     SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height());
84     return GrDeviceSpaceTextureDecalFragmentProcessor::Make(std::move(mask), domainTexels,
85                                                             {devBound.fLeft, devBound.fTop});
86 }
87 
88 // Does the path in 'element' require SW rendering? If so, return true (and,
89 // optionally, set 'prOut' to NULL. If not, return false (and, optionally, set
90 // 'prOut' to the non-SW path renderer that will do the job).
PathNeedsSWRenderer(GrRecordingContext * context,const SkIRect & scissorRect,bool hasUserStencilSettings,const GrRenderTargetContext * renderTargetContext,const SkMatrix & viewMatrix,const Element * element,GrPathRenderer ** prOut,bool needsStencil)91 bool GrClipStackClip::PathNeedsSWRenderer(GrRecordingContext* context,
92                                           const SkIRect& scissorRect,
93                                           bool hasUserStencilSettings,
94                                           const GrRenderTargetContext* renderTargetContext,
95                                           const SkMatrix& viewMatrix,
96                                           const Element* element,
97                                           GrPathRenderer** prOut,
98                                           bool needsStencil) {
99     if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) {
100         // rects can always be drawn directly w/o using the software path
101         // TODO: skip rrects once we're drawing them directly.
102         if (prOut) {
103             *prOut = nullptr;
104         }
105         return false;
106     } else {
107         // We shouldn't get here with an empty clip element.
108         SkASSERT(Element::DeviceSpaceType::kEmpty != element->getDeviceSpaceType());
109 
110         // the gpu alpha mask will draw the inverse paths as non-inverse to a temp buffer
111         SkPath path;
112         element->asDeviceSpacePath(&path);
113         if (path.isInverseFillType()) {
114             path.toggleInverseFillType();
115         }
116 
117         // We only use this method when rendering coverage clip masks.
118         SkASSERT(renderTargetContext->numSamples() <= 1);
119         auto aaType = (element->isAA()) ? GrAAType::kCoverage : GrAAType::kNone;
120 
121         GrPathRendererChain::DrawType type =
122                 needsStencil ? GrPathRendererChain::DrawType::kStencilAndColor
123                              : GrPathRendererChain::DrawType::kColor;
124 
125         GrShape shape(path, GrStyle::SimpleFill());
126         GrPathRenderer::CanDrawPathArgs canDrawArgs;
127         canDrawArgs.fCaps = context->priv().caps();
128         canDrawArgs.fProxy = renderTargetContext->proxy();
129         canDrawArgs.fClipConservativeBounds = &scissorRect;
130         canDrawArgs.fViewMatrix = &viewMatrix;
131         canDrawArgs.fShape = &shape;
132         canDrawArgs.fAAType = aaType;
133         SkASSERT(!renderTargetContext->wrapsVkSecondaryCB());
134         canDrawArgs.fTargetIsWrappedVkSecondaryCB = false;
135         canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings;
136 
137         // the 'false' parameter disallows use of the SW path renderer
138         GrPathRenderer* pr =
139             context->priv().drawingManager()->getPathRenderer(canDrawArgs, false, type);
140         if (prOut) {
141             *prOut = pr;
142         }
143         return SkToBool(!pr);
144     }
145 }
146 
147 /*
148  * This method traverses the clip stack to see if the GrSoftwarePathRenderer
149  * will be used on any element. If so, it returns true to indicate that the
150  * entire clip should be rendered in SW and then uploaded en masse to the gpu.
151  */
UseSWOnlyPath(GrRecordingContext * context,bool hasUserStencilSettings,const GrRenderTargetContext * renderTargetContext,const GrReducedClip & reducedClip)152 bool GrClipStackClip::UseSWOnlyPath(GrRecordingContext* context,
153                                     bool hasUserStencilSettings,
154                                     const GrRenderTargetContext* renderTargetContext,
155                                     const GrReducedClip& reducedClip) {
156     // TODO: right now it appears that GPU clip masks are strictly slower than software. We may
157     // want to revisit this assumption once we can test with render target sorting.
158     return true;
159 
160     // TODO: generalize this function so that when
161     // a clip gets complex enough it can just be done in SW regardless
162     // of whether it would invoke the GrSoftwarePathRenderer.
163 
164     // If we're avoiding stencils, always use SW. This includes drawing into a wrapped vulkan
165     // secondary command buffer which can't handle stencils.
166     if (context->priv().caps()->avoidStencilBuffers() ||
167         renderTargetContext->wrapsVkSecondaryCB()) {
168         return true;
169     }
170 
171     // Set the matrix so that rendered clip elements are transformed to mask space from clip
172     // space.
173     SkMatrix translate;
174     translate.setTranslate(SkIntToScalar(-reducedClip.left()), SkIntToScalar(-reducedClip.top()));
175 
176     for (ElementList::Iter iter(reducedClip.maskElements()); iter.get(); iter.next()) {
177         const Element* element = iter.get();
178 
179         SkClipOp op = element->getOp();
180         bool invert = element->isInverseFilled();
181         bool needsStencil = invert ||
182                             kIntersect_SkClipOp == op || kReverseDifference_SkClipOp == op;
183 
184         if (PathNeedsSWRenderer(context, reducedClip.scissor(), hasUserStencilSettings,
185                                 renderTargetContext, translate, element, nullptr, needsStencil)) {
186             return true;
187         }
188     }
189     return false;
190 }
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 // sort out what kind of clip mask needs to be created: alpha, stencil,
194 // scissor, or entirely software
apply(GrRecordingContext * context,GrRenderTargetContext * renderTargetContext,bool useHWAA,bool hasUserStencilSettings,GrAppliedClip * out,SkRect * bounds) const195 bool GrClipStackClip::apply(GrRecordingContext* context, GrRenderTargetContext* renderTargetContext,
196                             bool useHWAA, bool hasUserStencilSettings, GrAppliedClip* out,
197                             SkRect* bounds) const {
198     SkRect devBounds = SkRect::MakeIWH(renderTargetContext->width(), renderTargetContext->height());
199     if (!devBounds.intersect(*bounds)) {
200         return false;
201     }
202 
203     if (!fStack || fStack->isWideOpen()) {
204         return true;
205     }
206 
207     // An default count of 4 was chosen because of the common pattern in Blink of:
208     //   isect RR
209     //   diff  RR
210     //   isect convex_poly
211     //   isect convex_poly
212     // when drawing rounded div borders.
213     constexpr int kMaxAnalyticFPs = 4;
214 
215     int maxWindowRectangles = renderTargetContext->priv().maxWindowRectangles();
216     int maxAnalyticFPs = kMaxAnalyticFPs;
217     if (renderTargetContext->numSamples() > 1 || useHWAA || hasUserStencilSettings) {
218         // Disable analytic clips when we have MSAA. In MSAA we never conflate coverage and opacity.
219         maxAnalyticFPs = 0;
220         // We disable MSAA when avoiding stencil.
221         SkASSERT(!context->priv().caps()->avoidStencilBuffers());
222     }
223     auto* ccpr = context->priv().drawingManager()->getCoverageCountingPathRenderer();
224 
225     GrReducedClip reducedClip(*fStack, devBounds, context->priv().caps(),
226                               maxWindowRectangles, maxAnalyticFPs, ccpr ? maxAnalyticFPs : 0);
227     if (InitialState::kAllOut == reducedClip.initialState() &&
228         reducedClip.maskElements().isEmpty()) {
229         return false;
230     }
231 
232     if (reducedClip.hasScissor() && !GrClip::IsInsideClip(reducedClip.scissor(), devBounds)) {
233         out->hardClip().addScissor(reducedClip.scissor(), bounds);
234     }
235 
236     if (!reducedClip.windowRectangles().empty()) {
237         out->hardClip().addWindowRectangles(reducedClip.windowRectangles(),
238                                             GrWindowRectsState::Mode::kExclusive);
239     }
240 
241     if (!reducedClip.maskElements().isEmpty()) {
242         if (!this->applyClipMask(context, renderTargetContext, reducedClip, hasUserStencilSettings,
243                                  out)) {
244             return false;
245         }
246     }
247 
248     // The opList ID must not be looked up until AFTER producing the clip mask (if any). That step
249     // can cause a flush or otherwise change which opList our draw is going into.
250     uint32_t opListID = renderTargetContext->getOpList()->uniqueID();
251     if (auto clipFPs = reducedClip.finishAndDetachAnalyticFPs(ccpr, opListID)) {
252         out->addCoverageFP(std::move(clipFPs));
253     }
254 
255     return true;
256 }
257 
applyClipMask(GrRecordingContext * context,GrRenderTargetContext * renderTargetContext,const GrReducedClip & reducedClip,bool hasUserStencilSettings,GrAppliedClip * out) const258 bool GrClipStackClip::applyClipMask(GrRecordingContext* context,
259                                     GrRenderTargetContext* renderTargetContext,
260                                     const GrReducedClip& reducedClip, bool hasUserStencilSettings,
261                                     GrAppliedClip* out) const {
262 #ifdef SK_DEBUG
263     SkASSERT(reducedClip.hasScissor());
264     SkIRect rtIBounds = SkIRect::MakeWH(renderTargetContext->width(),
265                                         renderTargetContext->height());
266     const SkIRect& scissor = reducedClip.scissor();
267     SkASSERT(rtIBounds.contains(scissor)); // Mask shouldn't be larger than the RT.
268 #endif
269 
270     // MIXED SAMPLES TODO: We may want to explore using the stencil buffer for AA clipping.
271     if ((renderTargetContext->numSamples() <= 1 && reducedClip.maskRequiresAA()) ||
272         context->priv().caps()->avoidStencilBuffers() ||
273         renderTargetContext->wrapsVkSecondaryCB()) {
274         sk_sp<GrTextureProxy> result;
275         if (UseSWOnlyPath(context, hasUserStencilSettings, renderTargetContext, reducedClip)) {
276             // The clip geometry is complex enough that it will be more efficient to create it
277             // entirely in software
278             result = this->createSoftwareClipMask(context, reducedClip, renderTargetContext);
279         } else {
280             result = this->createAlphaClipMask(context, reducedClip);
281         }
282 
283         if (result) {
284             // The mask's top left coord should be pinned to the rounded-out top left corner of
285             // the clip's device space bounds.
286             out->addCoverageFP(create_fp_for_mask(std::move(result), reducedClip.scissor()));
287             return true;
288         }
289 
290         // If alpha or software clip mask creation fails, fall through to the stencil code paths,
291         // unless stencils are disallowed.
292         if (context->priv().caps()->avoidStencilBuffers() ||
293             renderTargetContext->wrapsVkSecondaryCB()) {
294             SkDebugf("WARNING: Clip mask requires stencil, but stencil unavailable. "
295                      "Clip will be ignored.\n");
296             return false;
297         }
298     }
299 
300     // This relies on the property that a reduced sub-rect of the last clip will contain all the
301     // relevant window rectangles that were in the last clip. This subtle requirement will go away
302     // after clipping is overhauled.
303     if (renderTargetContext->priv().mustRenderClip(reducedClip.maskGenID(), reducedClip.scissor(),
304                                                    reducedClip.numAnalyticFPs())) {
305         reducedClip.drawStencilClipMask(context, renderTargetContext);
306         renderTargetContext->priv().setLastClip(reducedClip.maskGenID(), reducedClip.scissor(),
307                                                 reducedClip.numAnalyticFPs());
308     }
309     // GrAppliedClip doesn't need to figure numAnalyticFPs into its key (used by operator==) because
310     // it verifies the FPs are also equal.
311     out->hardClip().addStencilClip(reducedClip.maskGenID());
312     return true;
313 }
314 
315 ////////////////////////////////////////////////////////////////////////////////
316 // Create a 8-bit clip mask in alpha
317 
create_clip_mask_key(uint32_t clipGenID,const SkIRect & bounds,int numAnalyticFPs,GrUniqueKey * key)318 static void create_clip_mask_key(uint32_t clipGenID, const SkIRect& bounds, int numAnalyticFPs,
319                                  GrUniqueKey* key) {
320     static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
321     GrUniqueKey::Builder builder(key, kDomain, 4, GrClipStackClip::kMaskTestTag);
322     builder[0] = clipGenID;
323     // SkToS16 because image filters outset layers to a size indicated by the filter, which can
324     // sometimes result in negative coordinates from device space.
325     builder[1] = SkToS16(bounds.fLeft) | (SkToS16(bounds.fRight) << 16);
326     builder[2] = SkToS16(bounds.fTop) | (SkToS16(bounds.fBottom) << 16);
327     builder[3] = numAnalyticFPs;
328 }
329 
add_invalidate_on_pop_message(GrRecordingContext * context,const SkClipStack & stack,uint32_t clipGenID,const GrUniqueKey & clipMaskKey)330 static void add_invalidate_on_pop_message(GrRecordingContext* context,
331                                           const SkClipStack& stack, uint32_t clipGenID,
332                                           const GrUniqueKey& clipMaskKey) {
333     GrProxyProvider* proxyProvider = context->priv().proxyProvider();
334 
335     SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart);
336     while (const Element* element = iter.prev()) {
337         if (element->getGenID() == clipGenID) {
338             element->addResourceInvalidationMessage(proxyProvider, clipMaskKey);
339             return;
340         }
341     }
342     SkDEBUGFAIL("Gen ID was not found in stack.");
343 }
344 
createAlphaClipMask(GrRecordingContext * context,const GrReducedClip & reducedClip) const345 sk_sp<GrTextureProxy> GrClipStackClip::createAlphaClipMask(GrRecordingContext* context,
346                                                            const GrReducedClip& reducedClip) const {
347     GrProxyProvider* proxyProvider = context->priv().proxyProvider();
348     GrUniqueKey key;
349     create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(),
350                          reducedClip.numAnalyticFPs(), &key);
351 
352     sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey(
353             key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin));
354     if (proxy) {
355         return proxy;
356     }
357 
358     auto isProtected = proxy->isProtected() ? GrProtected::kYes : GrProtected::kNo;
359     sk_sp<GrRenderTargetContext> rtc(
360             context->priv().makeDeferredRenderTargetContextWithFallback(SkBackingFit::kApprox,
361                                                                         reducedClip.width(),
362                                                                         reducedClip.height(),
363                                                                         GrColorType::kAlpha_8,
364                                                                         nullptr,
365                                                                         1,
366                                                                         GrMipMapped::kNo,
367                                                                         kTopLeft_GrSurfaceOrigin,
368                                                                         nullptr,
369                                                                         SkBudgeted::kYes,
370                                                                         isProtected));
371     if (!rtc) {
372         return nullptr;
373     }
374 
375     if (!reducedClip.drawAlphaClipMask(rtc.get())) {
376         return nullptr;
377     }
378 
379     sk_sp<GrTextureProxy> result(rtc->asTextureProxyRef());
380     if (!result) {
381         return nullptr;
382     }
383 
384     SkASSERT(result->origin() == kTopLeft_GrSurfaceOrigin);
385     proxyProvider->assignUniqueKeyToProxy(key, result.get());
386     add_invalidate_on_pop_message(context, *fStack, reducedClip.maskGenID(), key);
387 
388     return result;
389 }
390 
391 namespace {
392 
393 /**
394  * Payload class for use with GrTDeferredProxyUploader. The clip mask code renders multiple
395  * elements, each storing their own AA setting (and already transformed into device space). This
396  * stores all of the information needed by the worker thread to draw all clip elements (see below,
397  * in createSoftwareClipMask).
398  */
399 class ClipMaskData {
400 public:
ClipMaskData(const GrReducedClip & reducedClip)401     ClipMaskData(const GrReducedClip& reducedClip)
402             : fScissor(reducedClip.scissor())
403             , fInitialState(reducedClip.initialState()) {
404         for (ElementList::Iter iter(reducedClip.maskElements()); iter.get(); iter.next()) {
405             fElements.addToTail(*iter.get());
406         }
407     }
408 
scissor() const409     const SkIRect& scissor() const { return fScissor; }
initialState() const410     InitialState initialState() const { return fInitialState; }
elements() const411     const ElementList& elements() const { return fElements; }
412 
413 private:
414     SkIRect fScissor;
415     InitialState fInitialState;
416     ElementList fElements;
417 };
418 
419 }
420 
draw_clip_elements_to_mask_helper(GrSWMaskHelper & helper,const ElementList & elements,const SkIRect & scissor,InitialState initialState)421 static void draw_clip_elements_to_mask_helper(GrSWMaskHelper& helper, const ElementList& elements,
422                                               const SkIRect& scissor, InitialState initialState) {
423     // Set the matrix so that rendered clip elements are transformed to mask space from clip space.
424     SkMatrix translate;
425     translate.setTranslate(SkIntToScalar(-scissor.left()), SkIntToScalar(-scissor.top()));
426 
427     helper.clear(InitialState::kAllIn == initialState ? 0xFF : 0x00);
428 
429     for (ElementList::Iter iter(elements); iter.get(); iter.next()) {
430         const Element* element = iter.get();
431         SkClipOp op = element->getOp();
432         GrAA aa = GrAA(element->isAA());
433 
434         if (kIntersect_SkClipOp == op || kReverseDifference_SkClipOp == op) {
435             // Intersect and reverse difference require modifying pixels outside of the geometry
436             // that is being "drawn". In both cases we erase all the pixels outside of the geometry
437             // but leave the pixels inside the geometry alone. For reverse difference we invert all
438             // the pixels before clearing the ones outside the geometry.
439             if (kReverseDifference_SkClipOp == op) {
440                 SkRect temp = SkRect::Make(scissor);
441                 // invert the entire scene
442                 helper.drawRect(temp, translate, SkRegion::kXOR_Op, GrAA::kNo, 0xFF);
443             }
444             SkPath clipPath;
445             element->asDeviceSpacePath(&clipPath);
446             clipPath.toggleInverseFillType();
447             GrShape shape(clipPath, GrStyle::SimpleFill());
448             helper.drawShape(shape, translate, SkRegion::kReplace_Op, aa, 0x00);
449             continue;
450         }
451 
452         // The other ops (union, xor, diff) only affect pixels inside
453         // the geometry so they can just be drawn normally
454         if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) {
455             helper.drawRect(element->getDeviceSpaceRect(), translate, (SkRegion::Op)op, aa, 0xFF);
456         } else {
457             SkPath path;
458             element->asDeviceSpacePath(&path);
459             GrShape shape(path, GrStyle::SimpleFill());
460             helper.drawShape(shape, translate, (SkRegion::Op)op, aa, 0xFF);
461         }
462     }
463 }
464 
createSoftwareClipMask(GrRecordingContext * context,const GrReducedClip & reducedClip,GrRenderTargetContext * renderTargetContext) const465 sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask(
466         GrRecordingContext* context, const GrReducedClip& reducedClip,
467         GrRenderTargetContext* renderTargetContext) const {
468     GrUniqueKey key;
469     create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(),
470                          reducedClip.numAnalyticFPs(), &key);
471 
472     GrProxyProvider* proxyProvider = context->priv().proxyProvider();
473     const GrCaps* caps = context->priv().caps();
474 
475     sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey(
476             key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin));
477     if (proxy) {
478         return proxy;
479     }
480 
481     // The mask texture may be larger than necessary. We round out the clip bounds and pin the top
482     // left corner of the resulting rect to the top left of the texture.
483     SkIRect maskSpaceIBounds = SkIRect::MakeWH(reducedClip.width(), reducedClip.height());
484 
485     SkTaskGroup* taskGroup = nullptr;
486     if (auto direct = context->priv().asDirectContext()) {
487         taskGroup = direct->priv().getTaskGroup();
488     }
489 
490     if (taskGroup && renderTargetContext) {
491         // Create our texture proxy
492         GrSurfaceDesc desc;
493         desc.fWidth = maskSpaceIBounds.width();
494         desc.fHeight = maskSpaceIBounds.height();
495         desc.fConfig = kAlpha_8_GrPixelConfig;
496 
497         GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kAlpha_8,
498                                                                GrRenderable::kNo);
499 
500         // MDB TODO: We're going to fill this proxy with an ASAP upload (which is out of order wrt
501         // to ops), so it can't have any pending IO.
502         proxy = proxyProvider->createProxy(format, desc, GrRenderable::kNo, 1,
503                                            kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox,
504                                            SkBudgeted::kYes, GrProtected::kNo);
505 
506         auto uploader = skstd::make_unique<GrTDeferredProxyUploader<ClipMaskData>>(reducedClip);
507         GrTDeferredProxyUploader<ClipMaskData>* uploaderRaw = uploader.get();
508         auto drawAndUploadMask = [uploaderRaw, maskSpaceIBounds] {
509             TRACE_EVENT0("skia.gpu", "Threaded SW Clip Mask Render");
510             GrSWMaskHelper helper(uploaderRaw->getPixels());
511             if (helper.init(maskSpaceIBounds)) {
512                 draw_clip_elements_to_mask_helper(helper, uploaderRaw->data().elements(),
513                                                   uploaderRaw->data().scissor(),
514                                                   uploaderRaw->data().initialState());
515             } else {
516                 SkDEBUGFAIL("Unable to allocate SW clip mask.");
517             }
518             uploaderRaw->signalAndFreeData();
519         };
520 
521         taskGroup->add(std::move(drawAndUploadMask));
522         proxy->texPriv().setDeferredUploader(std::move(uploader));
523     } else {
524         GrSWMaskHelper helper;
525         if (!helper.init(maskSpaceIBounds)) {
526             return nullptr;
527         }
528 
529         draw_clip_elements_to_mask_helper(helper, reducedClip.maskElements(), reducedClip.scissor(),
530                                           reducedClip.initialState());
531 
532         proxy = helper.toTextureProxy(context, SkBackingFit::kApprox);
533     }
534 
535     SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
536     proxyProvider->assignUniqueKeyToProxy(key, proxy.get());
537     add_invalidate_on_pop_message(context, *fStack, reducedClip.maskGenID(), key);
538     return proxy;
539 }
540