blob: 5780cee4e8af649d9cc72793def916608848be11 [file] [log] [blame]
robertphillips@google.comf4c2c522012-04-27 12:08:47 +00001/*
2 * Copyright 2012 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 "GrSoftwarePathRenderer.h"
robertphillips976f5f02016-06-03 10:59:20 -07009#include "GrAuditTrail.h"
10#include "GrClip.h"
Brian Osmanf9810662017-08-30 10:02:10 -040011#include "GrContextPriv.h"
bsalomon39ef7fb2016-09-21 11:16:05 -070012#include "GrGpuResourcePriv.h"
Brian Osmanf9810662017-08-30 10:02:10 -040013#include "GrOpFlushState.h"
14#include "GrOpList.h"
Brian Osman32342f02017-03-04 08:12:46 -050015#include "GrResourceProvider.h"
robertphillips@google.com58b20212012-06-27 20:44:52 +000016#include "GrSWMaskHelper.h"
Brian Osmanf9810662017-08-30 10:02:10 -040017#include "SkMakeUnique.h"
18#include "SkSemaphore.h"
19#include "SkTaskGroup.h"
20#include "SkTraceEvent.h"
Robert Phillips009e9af2017-06-15 14:01:04 -040021#include "ops/GrDrawOp.h"
Brian Salomonbaaf4392017-06-15 09:59:23 -040022#include "ops/GrRectOpFactory.h"
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000023
robertphillips@google.comed4155d2012-05-01 14:30:24 +000024////////////////////////////////////////////////////////////////////////////////
bsalomon0aff2fa2015-07-31 06:48:27 -070025bool GrSoftwarePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
bsalomon8acedde2016-06-24 10:42:16 -070026 // Pass on any style that applies. The caller will apply the style if a suitable renderer is
27 // not found and try again with the new GrShape.
Brian Osman32342f02017-03-04 08:12:46 -050028 return !args.fShape->style().applies() && SkToBool(fResourceProvider) &&
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050029 (args.fAAType == GrAAType::kCoverage || args.fAAType == GrAAType::kNone);
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000030}
31
robertphillips@google.comed4155d2012-05-01 14:30:24 +000032////////////////////////////////////////////////////////////////////////////////
bsalomon39ef7fb2016-09-21 11:16:05 -070033static bool get_unclipped_shape_dev_bounds(const GrShape& shape, const SkMatrix& matrix,
34 SkIRect* devBounds) {
35 SkRect shapeBounds = shape.styledBounds();
36 if (shapeBounds.isEmpty()) {
37 return false;
38 }
39 SkRect shapeDevBounds;
40 matrix.mapRect(&shapeDevBounds, shapeBounds);
Brian Salomonc1c607e2016-12-20 11:41:43 -050041 // Even though these are "unclipped" bounds we still clip to the int32_t range.
42 // This is the largest int32_t that is representable exactly as a float. The next 63 larger ints
43 // would round down to this value when cast to a float, but who really cares.
44 // INT32_MIN is exactly representable.
45 static constexpr int32_t kMaxInt = 2147483520;
46 if (!shapeDevBounds.intersect(SkRect::MakeLTRB(INT32_MIN, INT32_MIN, kMaxInt, kMaxInt))) {
47 return false;
48 }
bsalomon39ef7fb2016-09-21 11:16:05 -070049 shapeDevBounds.roundOut(devBounds);
50 return true;
51}
52
53// Gets the shape bounds, the clip bounds, and the intersection (if any). Returns false if there
54// is no intersection.
55static bool get_shape_and_clip_bounds(int width, int height,
56 const GrClip& clip,
57 const GrShape& shape,
58 const SkMatrix& matrix,
59 SkIRect* unclippedDevShapeBounds,
60 SkIRect* clippedDevShapeBounds,
61 SkIRect* devClipBounds) {
robertphillips@google.comed4155d2012-05-01 14:30:24 +000062 // compute bounds as intersection of rt size, clip, and path
robertphillips0152d732016-05-20 06:38:43 -070063 clip.getConservativeBounds(width, height, devClipBounds);
robertphillips@google.com7b112892012-07-31 15:18:21 +000064
bsalomon39ef7fb2016-09-21 11:16:05 -070065 if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) {
66 *unclippedDevShapeBounds = SkIRect::EmptyIRect();
67 *clippedDevShapeBounds = SkIRect::EmptyIRect();
robertphillips@google.com3e11c0b2012-07-11 18:20:35 +000068 return false;
robertphillips@google.comed4155d2012-05-01 14:30:24 +000069 }
bsalomon39ef7fb2016-09-21 11:16:05 -070070 if (!clippedDevShapeBounds->intersect(*devClipBounds, *unclippedDevShapeBounds)) {
71 *clippedDevShapeBounds = SkIRect::EmptyIRect();
robertphillips@google.comed4155d2012-05-01 14:30:24 +000072 return false;
73 }
74 return true;
75}
76
77////////////////////////////////////////////////////////////////////////////////
robertphillips976f5f02016-06-03 10:59:20 -070078
Brian Osman11052242016-10-27 14:47:55 -040079void GrSoftwarePathRenderer::DrawNonAARect(GrRenderTargetContext* renderTargetContext,
Brian Salomon82f44312017-01-11 13:42:54 -050080 GrPaint&& paint,
robertphillipsd2b6d642016-07-21 08:55:08 -070081 const GrUserStencilSettings& userStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -070082 const GrClip& clip,
robertphillips976f5f02016-06-03 10:59:20 -070083 const SkMatrix& viewMatrix,
84 const SkRect& rect,
85 const SkMatrix& localMatrix) {
Brian Salomonbaaf4392017-06-15 09:59:23 -040086 renderTargetContext->addDrawOp(clip,
87 GrRectOpFactory::MakeNonAAFillWithLocalMatrix(
88 std::move(paint), viewMatrix, localMatrix, rect,
89 GrAAType::kNone, &userStencilSettings));
robertphillips976f5f02016-06-03 10:59:20 -070090}
91
Brian Osman11052242016-10-27 14:47:55 -040092void GrSoftwarePathRenderer::DrawAroundInvPath(GrRenderTargetContext* renderTargetContext,
Brian Salomon82f44312017-01-11 13:42:54 -050093 GrPaint&& paint,
robertphillipsd2b6d642016-07-21 08:55:08 -070094 const GrUserStencilSettings& userStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -070095 const GrClip& clip,
robertphillips976f5f02016-06-03 10:59:20 -070096 const SkMatrix& viewMatrix,
97 const SkIRect& devClipBounds,
98 const SkIRect& devPathBounds) {
joshualittd27f73e2014-12-29 07:43:36 -080099 SkMatrix invert;
joshualitt8059eb92014-12-29 15:10:07 -0800100 if (!viewMatrix.invert(&invert)) {
bsalomon@google.come3d32162012-07-20 13:37:06 +0000101 return;
102 }
joshualittd27f73e2014-12-29 07:43:36 -0800103
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000104 SkRect rect;
robertphillips@google.com7b112892012-07-31 15:18:21 +0000105 if (devClipBounds.fTop < devPathBounds.fTop) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000106 rect.iset(devClipBounds.fLeft, devClipBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000107 devClipBounds.fRight, devPathBounds.fTop);
Brian Salomonb74ef032017-08-10 12:46:01 -0400108 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
109 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000110 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000111 if (devClipBounds.fLeft < devPathBounds.fLeft) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000112 rect.iset(devClipBounds.fLeft, devPathBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000113 devPathBounds.fLeft, devPathBounds.fBottom);
Brian Salomonb74ef032017-08-10 12:46:01 -0400114 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
115 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000116 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000117 if (devClipBounds.fRight > devPathBounds.fRight) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000118 rect.iset(devPathBounds.fRight, devPathBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000119 devClipBounds.fRight, devPathBounds.fBottom);
Brian Salomonb74ef032017-08-10 12:46:01 -0400120 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
121 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000122 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000123 if (devClipBounds.fBottom > devPathBounds.fBottom) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000124 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000125 devClipBounds.fRight, devClipBounds.fBottom);
Brian Salomon82f44312017-01-11 13:42:54 -0500126 DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip,
robertphillips976f5f02016-06-03 10:59:20 -0700127 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000128 }
129}
130
Brian Osmanc7da1462017-08-17 16:14:25 -0400131void GrSoftwarePathRenderer::DrawToTargetWithShapeMask(
132 sk_sp<GrTextureProxy> proxy,
133 GrRenderTargetContext* renderTargetContext,
134 GrPaint&& paint,
135 const GrUserStencilSettings& userStencilSettings,
136 const GrClip& clip,
137 const SkMatrix& viewMatrix,
138 const SkIPoint& textureOriginInDeviceSpace,
139 const SkIRect& deviceSpaceRectToDraw) {
140 SkMatrix invert;
141 if (!viewMatrix.invert(&invert)) {
142 return;
143 }
144
145 SkRect dstRect = SkRect::Make(deviceSpaceRectToDraw);
146
147 // We use device coords to compute the texture coordinates. We take the device coords and apply
148 // a translation so that the top-left of the device bounds maps to 0,0, and then a scaling
149 // matrix to normalized coords.
150 SkMatrix maskMatrix = SkMatrix::MakeTrans(SkIntToScalar(-textureOriginInDeviceSpace.fX),
151 SkIntToScalar(-textureOriginInDeviceSpace.fY));
152 maskMatrix.preConcat(viewMatrix);
153 paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400154 std::move(proxy), nullptr, maskMatrix, GrSamplerState::Filter::kNearest));
Brian Osmanf9810662017-08-30 10:02:10 -0400155 DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip, SkMatrix::I(),
156 dstRect, invert);
157}
158
159static sk_sp<GrTextureProxy> make_deferred_mask_texture_proxy(GrContext* context, SkBackingFit fit,
160 int width, int height) {
161 GrSurfaceDesc desc;
162 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
163 desc.fWidth = width;
164 desc.fHeight = height;
165 desc.fConfig = kAlpha_8_GrPixelConfig;
166
167 sk_sp<GrSurfaceContext> sContext =
168 context->contextPriv().makeDeferredSurfaceContext(desc, fit, SkBudgeted::kYes);
169 if (!sContext || !sContext->asTextureProxy()) {
170 return nullptr;
171 }
172 return sContext->asTextureProxyRef();
173}
174
175namespace {
176
177class GrMaskUploaderPrepareCallback : public GrPrepareCallback {
178public:
179 GrMaskUploaderPrepareCallback(sk_sp<GrTextureProxy> proxy, const SkIRect& maskBounds,
180 const SkMatrix& viewMatrix, const GrShape& shape, GrAA aa)
181 : fProxy(std::move(proxy))
182 , fMaskBounds(maskBounds)
183 , fViewMatrix(viewMatrix)
184 , fShape(shape)
185 , fAA(aa)
186 , fWaited(false) {}
187
188 ~GrMaskUploaderPrepareCallback() override {
189 if (!fWaited) {
190 // This can happen if our owning op list fails to instantiate (so it never prepares)
191 fPixelsReady.wait();
192 }
193 }
194
195 void operator()(GrOpFlushState* flushState) override {
196 TRACE_EVENT0("skia", "Mask Uploader Pre Flush Callback");
197 auto uploadMask = [this](GrDrawOp::WritePixelsFn& writePixelsFn) {
198 TRACE_EVENT0("skia", "Mask Upload");
199 this->fPixelsReady.wait();
200 this->fWaited = true;
201 // If the worker thread was unable to allocate pixels, this check will fail, and we'll
202 // end up drawing with an uninitialized mask texture, but at least we won't crash.
203 if (this->fPixels.addr()) {
204 writePixelsFn(this->fProxy.get(), 0, 0,
205 this->fPixels.width(), this->fPixels.height(),
206 kAlpha_8_GrPixelConfig,
207 this->fPixels.addr(), this->fPixels.rowBytes());
Brian Osmand41dc172017-09-01 11:40:08 -0400208 // Free this memory immediately, so it can be recycled. This avoids memory pressure
209 // when there is a large amount of threaded work still running during flush.
210 this->fPixels.reset();
Brian Osmanf9810662017-08-30 10:02:10 -0400211 }
212 };
213 flushState->addASAPUpload(std::move(uploadMask));
214 }
215
216 SkAutoPixmapStorage* getPixels() { return &fPixels; }
217 SkSemaphore* getSemaphore() { return &fPixelsReady; }
218 const SkIRect& getMaskBounds() const { return fMaskBounds; }
219 const SkMatrix* getViewMatrix() const { return &fViewMatrix; }
220 const GrShape& getShape() const { return fShape; }
221 GrAA getAA() const { return fAA; }
222
223private:
224 // NOTE: This ref cnt isn't thread safe!
225 sk_sp<GrTextureProxy> fProxy;
226 SkAutoPixmapStorage fPixels;
227 SkSemaphore fPixelsReady;
228
229 SkIRect fMaskBounds;
230 SkMatrix fViewMatrix;
231 GrShape fShape;
232 GrAA fAA;
233 bool fWaited;
234};
235
Brian Osmanc7da1462017-08-17 16:14:25 -0400236}
237
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000238////////////////////////////////////////////////////////////////////////////////
239// return true on success; false on failure
bsalomon0aff2fa2015-07-31 06:48:27 -0700240bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400241 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700242 "GrSoftwarePathRenderer::onDrawPath");
Brian Osman32342f02017-03-04 08:12:46 -0500243 if (!fResourceProvider) {
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000244 return false;
245 }
246
bsalomon8acedde2016-06-24 10:42:16 -0700247 // We really need to know if the shape will be inverse filled or not
248 bool inverseFilled = false;
249 SkTLazy<GrShape> tmpShape;
caryclarkd6562002016-07-27 12:02:07 -0700250 SkASSERT(!args.fShape->style().applies());
Eric Karl5c779752017-05-08 12:02:07 -0700251 // If the path is hairline, ignore inverse fill.
252 inverseFilled = args.fShape->inverseFilled() &&
253 !IsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr);
bsalomon8acedde2016-06-24 10:42:16 -0700254
bsalomon39ef7fb2016-09-21 11:16:05 -0700255 SkIRect unclippedDevShapeBounds, clippedDevShapeBounds, devClipBounds;
256 // To prevent overloading the cache with entries during animations we limit the cache of masks
257 // to cases where the matrix preserves axis alignment.
258 bool useCache = fAllowCaching && !inverseFilled && args.fViewMatrix->preservesAxisAlignment() &&
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500259 args.fShape->hasUnstyledKey() && GrAAType::kCoverage == args.fAAType;
bsalomon39ef7fb2016-09-21 11:16:05 -0700260
Brian Osman11052242016-10-27 14:47:55 -0400261 if (!get_shape_and_clip_bounds(args.fRenderTargetContext->width(),
262 args.fRenderTargetContext->height(),
bsalomon8acedde2016-06-24 10:42:16 -0700263 *args.fClip, *args.fShape,
bsalomon39ef7fb2016-09-21 11:16:05 -0700264 *args.fViewMatrix, &unclippedDevShapeBounds,
265 &clippedDevShapeBounds,
266 &devClipBounds)) {
bsalomon8acedde2016-06-24 10:42:16 -0700267 if (inverseFilled) {
Brian Salomon82f44312017-01-11 13:42:54 -0500268 DrawAroundInvPath(args.fRenderTargetContext, std::move(args.fPaint),
269 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
270 devClipBounds, unclippedDevShapeBounds);
bsalomon@google.com276c1fa2012-06-19 13:22:45 +0000271 }
272 return true;
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000273 }
robertphillips@google.com366f1c62012-06-29 21:38:47 +0000274
bsalomon39ef7fb2016-09-21 11:16:05 -0700275 const SkIRect* boundsForMask = &clippedDevShapeBounds;
276 if (useCache) {
277 // Use the cache only if >50% of the path is visible.
278 int unclippedWidth = unclippedDevShapeBounds.width();
279 int unclippedHeight = unclippedDevShapeBounds.height();
280 int unclippedArea = unclippedWidth * unclippedHeight;
281 int clippedArea = clippedDevShapeBounds.width() * clippedDevShapeBounds.height();
Brian Osman11052242016-10-27 14:47:55 -0400282 int maxTextureSize = args.fRenderTargetContext->caps()->maxTextureSize();
bsalomon39ef7fb2016-09-21 11:16:05 -0700283 if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize ||
284 unclippedHeight > maxTextureSize) {
285 useCache = false;
286 } else {
287 boundsForMask = &unclippedDevShapeBounds;
288 }
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000289 }
290
bsalomon39ef7fb2016-09-21 11:16:05 -0700291 GrUniqueKey maskKey;
bsalomon39ef7fb2016-09-21 11:16:05 -0700292 if (useCache) {
293 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
294 SkScalar sx = args.fViewMatrix->get(SkMatrix::kMScaleX);
295 SkScalar sy = args.fViewMatrix->get(SkMatrix::kMScaleY);
296 SkScalar kx = args.fViewMatrix->get(SkMatrix::kMSkewX);
297 SkScalar ky = args.fViewMatrix->get(SkMatrix::kMSkewY);
Stan Iliev67cd6732017-08-15 17:10:26 -0400298 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
299#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
300 // Fractional translate does not affect caching on Android. This is done for better cache
301 // hit ratio and speed, but it is matching HWUI behavior, which doesn't consider the matrix
302 // at all when caching paths.
303 GrUniqueKey::Builder builder(&maskKey, kDomain, 4 + args.fShape->unstyledKeySize());
304#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700305 SkScalar tx = args.fViewMatrix->get(SkMatrix::kMTransX);
306 SkScalar ty = args.fViewMatrix->get(SkMatrix::kMTransY);
307 // Allow 8 bits each in x and y of subpixel positioning.
308 SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
309 SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
bsalomon39ef7fb2016-09-21 11:16:05 -0700310 GrUniqueKey::Builder builder(&maskKey, kDomain, 5 + args.fShape->unstyledKeySize());
Stan Iliev67cd6732017-08-15 17:10:26 -0400311#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700312 builder[0] = SkFloat2Bits(sx);
313 builder[1] = SkFloat2Bits(sy);
314 builder[2] = SkFloat2Bits(kx);
315 builder[3] = SkFloat2Bits(ky);
Stan Iliev67cd6732017-08-15 17:10:26 -0400316#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
317 args.fShape->writeUnstyledKey(&builder[4]);
318#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700319 builder[4] = fracX | (fracY >> 8);
320 args.fShape->writeUnstyledKey(&builder[5]);
Stan Iliev67cd6732017-08-15 17:10:26 -0400321#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700322 }
323
Robert Phillipsd3749482017-03-14 09:17:43 -0400324 sk_sp<GrTextureProxy> proxy;
bsalomon39ef7fb2016-09-21 11:16:05 -0700325 if (useCache) {
Robert Phillips066f0202017-07-25 10:16:35 -0400326 proxy = fResourceProvider->findProxyByUniqueKey(maskKey, kTopLeft_GrSurfaceOrigin);
bsalomon39ef7fb2016-09-21 11:16:05 -0700327 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400328 if (!proxy) {
Robert Phillips417b7f42016-12-14 09:12:13 -0500329 SkBackingFit fit = useCache ? SkBackingFit::kExact : SkBackingFit::kApprox;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500330 GrAA aa = GrAAType::kCoverage == args.fAAType ? GrAA::kYes : GrAA::kNo;
Brian Osmanf9810662017-08-30 10:02:10 -0400331
332 SkTaskGroup* taskGroup = args.fContext->contextPriv().getTaskGroup();
333 if (taskGroup) {
334 proxy = make_deferred_mask_texture_proxy(args.fContext, fit,
335 boundsForMask->width(),
336 boundsForMask->height());
337 if (!proxy) {
338 return false;
339 }
340
341 auto uploader = skstd::make_unique<GrMaskUploaderPrepareCallback>(
342 proxy, *boundsForMask, *args.fViewMatrix, *args.fShape, aa);
343 GrMaskUploaderPrepareCallback* uploaderRaw = uploader.get();
344
345 auto drawAndUploadMask = [uploaderRaw] {
346 TRACE_EVENT0("skia", "Threaded SW Mask Render");
347 GrSWMaskHelper helper(uploaderRaw->getPixels());
Brian Salomon74077562017-08-30 13:55:35 -0400348 if (helper.init(uploaderRaw->getMaskBounds())) {
349 helper.drawShape(uploaderRaw->getShape(), *uploaderRaw->getViewMatrix(),
350 SkRegion::kReplace_Op, uploaderRaw->getAA(), 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400351 } else {
352 SkDEBUGFAIL("Unable to allocate SW mask.");
353 }
354 uploaderRaw->getSemaphore()->signal();
355 };
356 taskGroup->add(std::move(drawAndUploadMask));
357 args.fRenderTargetContext->getOpList()->addPrepareCallback(std::move(uploader));
358 } else {
359 GrSWMaskHelper helper;
Brian Salomon74077562017-08-30 13:55:35 -0400360 if (!helper.init(*boundsForMask)) {
Brian Osmanf9810662017-08-30 10:02:10 -0400361 return false;
362 }
Brian Salomon74077562017-08-30 13:55:35 -0400363 helper.drawShape(*args.fShape, *args.fViewMatrix, SkRegion::kReplace_Op, aa, 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400364 proxy = helper.toTextureProxy(args.fContext, fit);
365 }
366
Robert Phillipsd3749482017-03-14 09:17:43 -0400367 if (!proxy) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500368 return false;
369 }
370 if (useCache) {
Robert Phillipse44ef102017-07-21 15:37:19 -0400371 SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
Robert Phillipsd3749482017-03-14 09:17:43 -0400372 fResourceProvider->assignUniqueKeyToProxy(maskKey, proxy.get());
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500373 }
bsalomon39ef7fb2016-09-21 11:16:05 -0700374 }
bsalomon8acedde2016-06-24 10:42:16 -0700375 if (inverseFilled) {
Brian Salomonb74ef032017-08-10 12:46:01 -0400376 DrawAroundInvPath(args.fRenderTargetContext, GrPaint::Clone(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500377 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix, devClipBounds,
378 unclippedDevShapeBounds);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000379 }
Brian Osmanc7da1462017-08-17 16:14:25 -0400380 DrawToTargetWithShapeMask(
Robert Phillips296b1cc2017-03-15 10:42:12 -0400381 std::move(proxy), args.fRenderTargetContext, std::move(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500382 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
383 SkIPoint{boundsForMask->fLeft, boundsForMask->fTop}, *boundsForMask);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000384
385 return true;
robertphillips@google.comf4c2c522012-04-27 12:08:47 +0000386}