blob: 8b509082c8c0d3883fbf44baf6d7b0d027fdd3c4 [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 Osman5d034742017-09-11 13:38:55 -040015#include "GrPrepareCallback.h"
Brian Osman32342f02017-03-04 08:12:46 -050016#include "GrResourceProvider.h"
robertphillips@google.com58b20212012-06-27 20:44:52 +000017#include "GrSWMaskHelper.h"
Brian Osmanf9810662017-08-30 10:02:10 -040018#include "SkMakeUnique.h"
19#include "SkSemaphore.h"
20#include "SkTaskGroup.h"
21#include "SkTraceEvent.h"
Robert Phillips009e9af2017-06-15 14:01:04 -040022#include "ops/GrDrawOp.h"
Brian Salomonbaaf4392017-06-15 09:59:23 -040023#include "ops/GrRectOpFactory.h"
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000024
robertphillips@google.comed4155d2012-05-01 14:30:24 +000025////////////////////////////////////////////////////////////////////////////////
Chris Dalton5ed44232017-09-07 13:22:46 -060026GrPathRenderer::CanDrawPath
27GrSoftwarePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
bsalomon8acedde2016-06-24 10:42:16 -070028 // Pass on any style that applies. The caller will apply the style if a suitable renderer is
29 // not found and try again with the new GrShape.
Chris Dalton5ed44232017-09-07 13:22:46 -060030 if (!args.fShape->style().applies() && SkToBool(fResourceProvider) &&
31 (args.fAAType == GrAAType::kCoverage || args.fAAType == GrAAType::kNone)) {
32 // This is the fallback renderer for when a path is too complicated for the GPU ones.
33 return CanDrawPath::kAsBackup;
34 }
35 return CanDrawPath::kNo;
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000036}
37
robertphillips@google.comed4155d2012-05-01 14:30:24 +000038////////////////////////////////////////////////////////////////////////////////
bsalomon39ef7fb2016-09-21 11:16:05 -070039static bool get_unclipped_shape_dev_bounds(const GrShape& shape, const SkMatrix& matrix,
40 SkIRect* devBounds) {
41 SkRect shapeBounds = shape.styledBounds();
42 if (shapeBounds.isEmpty()) {
43 return false;
44 }
45 SkRect shapeDevBounds;
46 matrix.mapRect(&shapeDevBounds, shapeBounds);
Brian Salomonc1c607e2016-12-20 11:41:43 -050047 // Even though these are "unclipped" bounds we still clip to the int32_t range.
48 // This is the largest int32_t that is representable exactly as a float. The next 63 larger ints
49 // would round down to this value when cast to a float, but who really cares.
50 // INT32_MIN is exactly representable.
51 static constexpr int32_t kMaxInt = 2147483520;
52 if (!shapeDevBounds.intersect(SkRect::MakeLTRB(INT32_MIN, INT32_MIN, kMaxInt, kMaxInt))) {
53 return false;
54 }
bsalomon39ef7fb2016-09-21 11:16:05 -070055 shapeDevBounds.roundOut(devBounds);
56 return true;
57}
58
59// Gets the shape bounds, the clip bounds, and the intersection (if any). Returns false if there
60// is no intersection.
61static bool get_shape_and_clip_bounds(int width, int height,
62 const GrClip& clip,
63 const GrShape& shape,
64 const SkMatrix& matrix,
65 SkIRect* unclippedDevShapeBounds,
66 SkIRect* clippedDevShapeBounds,
67 SkIRect* devClipBounds) {
robertphillips@google.comed4155d2012-05-01 14:30:24 +000068 // compute bounds as intersection of rt size, clip, and path
robertphillips0152d732016-05-20 06:38:43 -070069 clip.getConservativeBounds(width, height, devClipBounds);
robertphillips@google.com7b112892012-07-31 15:18:21 +000070
bsalomon39ef7fb2016-09-21 11:16:05 -070071 if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) {
72 *unclippedDevShapeBounds = SkIRect::EmptyIRect();
73 *clippedDevShapeBounds = SkIRect::EmptyIRect();
robertphillips@google.com3e11c0b2012-07-11 18:20:35 +000074 return false;
robertphillips@google.comed4155d2012-05-01 14:30:24 +000075 }
bsalomon39ef7fb2016-09-21 11:16:05 -070076 if (!clippedDevShapeBounds->intersect(*devClipBounds, *unclippedDevShapeBounds)) {
77 *clippedDevShapeBounds = SkIRect::EmptyIRect();
robertphillips@google.comed4155d2012-05-01 14:30:24 +000078 return false;
79 }
80 return true;
81}
82
83////////////////////////////////////////////////////////////////////////////////
robertphillips976f5f02016-06-03 10:59:20 -070084
Brian Osman11052242016-10-27 14:47:55 -040085void GrSoftwarePathRenderer::DrawNonAARect(GrRenderTargetContext* renderTargetContext,
Brian Salomon82f44312017-01-11 13:42:54 -050086 GrPaint&& paint,
robertphillipsd2b6d642016-07-21 08:55:08 -070087 const GrUserStencilSettings& userStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -070088 const GrClip& clip,
robertphillips976f5f02016-06-03 10:59:20 -070089 const SkMatrix& viewMatrix,
90 const SkRect& rect,
91 const SkMatrix& localMatrix) {
Brian Salomonbaaf4392017-06-15 09:59:23 -040092 renderTargetContext->addDrawOp(clip,
93 GrRectOpFactory::MakeNonAAFillWithLocalMatrix(
94 std::move(paint), viewMatrix, localMatrix, rect,
95 GrAAType::kNone, &userStencilSettings));
robertphillips976f5f02016-06-03 10:59:20 -070096}
97
Brian Osman11052242016-10-27 14:47:55 -040098void GrSoftwarePathRenderer::DrawAroundInvPath(GrRenderTargetContext* renderTargetContext,
Brian Salomon82f44312017-01-11 13:42:54 -050099 GrPaint&& paint,
robertphillipsd2b6d642016-07-21 08:55:08 -0700100 const GrUserStencilSettings& userStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -0700101 const GrClip& clip,
robertphillips976f5f02016-06-03 10:59:20 -0700102 const SkMatrix& viewMatrix,
103 const SkIRect& devClipBounds,
104 const SkIRect& devPathBounds) {
joshualittd27f73e2014-12-29 07:43:36 -0800105 SkMatrix invert;
joshualitt8059eb92014-12-29 15:10:07 -0800106 if (!viewMatrix.invert(&invert)) {
bsalomon@google.come3d32162012-07-20 13:37:06 +0000107 return;
108 }
joshualittd27f73e2014-12-29 07:43:36 -0800109
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000110 SkRect rect;
robertphillips@google.com7b112892012-07-31 15:18:21 +0000111 if (devClipBounds.fTop < devPathBounds.fTop) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000112 rect.iset(devClipBounds.fLeft, devClipBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000113 devClipBounds.fRight, devPathBounds.fTop);
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.fLeft < devPathBounds.fLeft) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000118 rect.iset(devClipBounds.fLeft, devPathBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000119 devPathBounds.fLeft, 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.fRight > devPathBounds.fRight) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000124 rect.iset(devPathBounds.fRight, devPathBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000125 devClipBounds.fRight, devPathBounds.fBottom);
Brian Salomonb74ef032017-08-10 12:46:01 -0400126 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
127 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000128 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000129 if (devClipBounds.fBottom > devPathBounds.fBottom) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000130 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000131 devClipBounds.fRight, devClipBounds.fBottom);
Brian Salomon82f44312017-01-11 13:42:54 -0500132 DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip,
robertphillips976f5f02016-06-03 10:59:20 -0700133 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000134 }
135}
136
Brian Osmanc7da1462017-08-17 16:14:25 -0400137void GrSoftwarePathRenderer::DrawToTargetWithShapeMask(
138 sk_sp<GrTextureProxy> proxy,
139 GrRenderTargetContext* renderTargetContext,
140 GrPaint&& paint,
141 const GrUserStencilSettings& userStencilSettings,
142 const GrClip& clip,
143 const SkMatrix& viewMatrix,
144 const SkIPoint& textureOriginInDeviceSpace,
145 const SkIRect& deviceSpaceRectToDraw) {
146 SkMatrix invert;
147 if (!viewMatrix.invert(&invert)) {
148 return;
149 }
150
151 SkRect dstRect = SkRect::Make(deviceSpaceRectToDraw);
152
153 // We use device coords to compute the texture coordinates. We take the device coords and apply
154 // a translation so that the top-left of the device bounds maps to 0,0, and then a scaling
155 // matrix to normalized coords.
156 SkMatrix maskMatrix = SkMatrix::MakeTrans(SkIntToScalar(-textureOriginInDeviceSpace.fX),
157 SkIntToScalar(-textureOriginInDeviceSpace.fY));
158 maskMatrix.preConcat(viewMatrix);
159 paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400160 std::move(proxy), nullptr, maskMatrix, GrSamplerState::Filter::kNearest));
Brian Osmanf9810662017-08-30 10:02:10 -0400161 DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip, SkMatrix::I(),
162 dstRect, invert);
163}
164
165static sk_sp<GrTextureProxy> make_deferred_mask_texture_proxy(GrContext* context, SkBackingFit fit,
166 int width, int height) {
167 GrSurfaceDesc desc;
168 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
169 desc.fWidth = width;
170 desc.fHeight = height;
171 desc.fConfig = kAlpha_8_GrPixelConfig;
Brian Osman33fea052017-09-08 10:37:45 -0400172 return GrSurfaceProxy::MakeDeferred(context->resourceProvider(), desc, fit, SkBudgeted::kYes);
Brian Osmanf9810662017-08-30 10:02:10 -0400173}
174
175namespace {
176
Brian Osman5d034742017-09-11 13:38:55 -0400177/**
178 * Payload class for use with GrMaskUploaderPrepareCallback. The software path renderer only draws
179 * a single path into the mask texture. This stores all of the information needed by the worker
180 * thread's call to drawShape (see below, in onDrawPath).
181 */
182class SoftwarePathData {
Brian Osmanf9810662017-08-30 10:02:10 -0400183public:
Brian Osman5d034742017-09-11 13:38:55 -0400184 SoftwarePathData(const SkIRect& maskBounds, const SkMatrix& viewMatrix, const GrShape& shape,
185 GrAA aa)
186 : fMaskBounds(maskBounds)
Brian Osmanf9810662017-08-30 10:02:10 -0400187 , fViewMatrix(viewMatrix)
188 , fShape(shape)
Brian Osman5d034742017-09-11 13:38:55 -0400189 , fAA(aa) {}
Brian Osmanf9810662017-08-30 10:02:10 -0400190
Brian Osmanf9810662017-08-30 10:02:10 -0400191 const SkIRect& getMaskBounds() const { return fMaskBounds; }
192 const SkMatrix* getViewMatrix() const { return &fViewMatrix; }
193 const GrShape& getShape() const { return fShape; }
194 GrAA getAA() const { return fAA; }
195
196private:
Brian Osmanf9810662017-08-30 10:02:10 -0400197 SkIRect fMaskBounds;
198 SkMatrix fViewMatrix;
199 GrShape fShape;
200 GrAA fAA;
Brian Osmanf9810662017-08-30 10:02:10 -0400201};
202
Brian Osmanc7da1462017-08-17 16:14:25 -0400203}
204
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000205////////////////////////////////////////////////////////////////////////////////
206// return true on success; false on failure
bsalomon0aff2fa2015-07-31 06:48:27 -0700207bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400208 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700209 "GrSoftwarePathRenderer::onDrawPath");
Brian Osman32342f02017-03-04 08:12:46 -0500210 if (!fResourceProvider) {
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000211 return false;
212 }
213
bsalomon8acedde2016-06-24 10:42:16 -0700214 // We really need to know if the shape will be inverse filled or not
215 bool inverseFilled = false;
216 SkTLazy<GrShape> tmpShape;
caryclarkd6562002016-07-27 12:02:07 -0700217 SkASSERT(!args.fShape->style().applies());
Eric Karl5c779752017-05-08 12:02:07 -0700218 // If the path is hairline, ignore inverse fill.
219 inverseFilled = args.fShape->inverseFilled() &&
220 !IsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr);
bsalomon8acedde2016-06-24 10:42:16 -0700221
bsalomon39ef7fb2016-09-21 11:16:05 -0700222 SkIRect unclippedDevShapeBounds, clippedDevShapeBounds, devClipBounds;
223 // To prevent overloading the cache with entries during animations we limit the cache of masks
224 // to cases where the matrix preserves axis alignment.
225 bool useCache = fAllowCaching && !inverseFilled && args.fViewMatrix->preservesAxisAlignment() &&
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500226 args.fShape->hasUnstyledKey() && GrAAType::kCoverage == args.fAAType;
bsalomon39ef7fb2016-09-21 11:16:05 -0700227
Brian Osman11052242016-10-27 14:47:55 -0400228 if (!get_shape_and_clip_bounds(args.fRenderTargetContext->width(),
229 args.fRenderTargetContext->height(),
bsalomon8acedde2016-06-24 10:42:16 -0700230 *args.fClip, *args.fShape,
bsalomon39ef7fb2016-09-21 11:16:05 -0700231 *args.fViewMatrix, &unclippedDevShapeBounds,
232 &clippedDevShapeBounds,
233 &devClipBounds)) {
bsalomon8acedde2016-06-24 10:42:16 -0700234 if (inverseFilled) {
Brian Salomon82f44312017-01-11 13:42:54 -0500235 DrawAroundInvPath(args.fRenderTargetContext, std::move(args.fPaint),
236 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
237 devClipBounds, unclippedDevShapeBounds);
bsalomon@google.com276c1fa2012-06-19 13:22:45 +0000238 }
239 return true;
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000240 }
robertphillips@google.com366f1c62012-06-29 21:38:47 +0000241
bsalomon39ef7fb2016-09-21 11:16:05 -0700242 const SkIRect* boundsForMask = &clippedDevShapeBounds;
243 if (useCache) {
244 // Use the cache only if >50% of the path is visible.
245 int unclippedWidth = unclippedDevShapeBounds.width();
246 int unclippedHeight = unclippedDevShapeBounds.height();
247 int unclippedArea = unclippedWidth * unclippedHeight;
248 int clippedArea = clippedDevShapeBounds.width() * clippedDevShapeBounds.height();
Brian Osman11052242016-10-27 14:47:55 -0400249 int maxTextureSize = args.fRenderTargetContext->caps()->maxTextureSize();
bsalomon39ef7fb2016-09-21 11:16:05 -0700250 if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize ||
251 unclippedHeight > maxTextureSize) {
252 useCache = false;
253 } else {
254 boundsForMask = &unclippedDevShapeBounds;
255 }
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000256 }
257
bsalomon39ef7fb2016-09-21 11:16:05 -0700258 GrUniqueKey maskKey;
bsalomon39ef7fb2016-09-21 11:16:05 -0700259 if (useCache) {
260 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
261 SkScalar sx = args.fViewMatrix->get(SkMatrix::kMScaleX);
262 SkScalar sy = args.fViewMatrix->get(SkMatrix::kMScaleY);
263 SkScalar kx = args.fViewMatrix->get(SkMatrix::kMSkewX);
264 SkScalar ky = args.fViewMatrix->get(SkMatrix::kMSkewY);
Stan Iliev67cd6732017-08-15 17:10:26 -0400265 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
266#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
267 // Fractional translate does not affect caching on Android. This is done for better cache
268 // hit ratio and speed, but it is matching HWUI behavior, which doesn't consider the matrix
269 // at all when caching paths.
270 GrUniqueKey::Builder builder(&maskKey, kDomain, 4 + args.fShape->unstyledKeySize());
271#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700272 SkScalar tx = args.fViewMatrix->get(SkMatrix::kMTransX);
273 SkScalar ty = args.fViewMatrix->get(SkMatrix::kMTransY);
274 // Allow 8 bits each in x and y of subpixel positioning.
275 SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
276 SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
bsalomon39ef7fb2016-09-21 11:16:05 -0700277 GrUniqueKey::Builder builder(&maskKey, kDomain, 5 + args.fShape->unstyledKeySize());
Stan Iliev67cd6732017-08-15 17:10:26 -0400278#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700279 builder[0] = SkFloat2Bits(sx);
280 builder[1] = SkFloat2Bits(sy);
281 builder[2] = SkFloat2Bits(kx);
282 builder[3] = SkFloat2Bits(ky);
Stan Iliev67cd6732017-08-15 17:10:26 -0400283#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
284 args.fShape->writeUnstyledKey(&builder[4]);
285#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700286 builder[4] = fracX | (fracY >> 8);
287 args.fShape->writeUnstyledKey(&builder[5]);
Stan Iliev67cd6732017-08-15 17:10:26 -0400288#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700289 }
290
Robert Phillipsd3749482017-03-14 09:17:43 -0400291 sk_sp<GrTextureProxy> proxy;
bsalomon39ef7fb2016-09-21 11:16:05 -0700292 if (useCache) {
Greg Danielcd871402017-09-26 12:49:26 -0400293 proxy = fResourceProvider->findOrCreateProxyByUniqueKey(maskKey, kTopLeft_GrSurfaceOrigin);
bsalomon39ef7fb2016-09-21 11:16:05 -0700294 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400295 if (!proxy) {
Robert Phillips417b7f42016-12-14 09:12:13 -0500296 SkBackingFit fit = useCache ? SkBackingFit::kExact : SkBackingFit::kApprox;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500297 GrAA aa = GrAAType::kCoverage == args.fAAType ? GrAA::kYes : GrAA::kNo;
Brian Osmanf9810662017-08-30 10:02:10 -0400298
299 SkTaskGroup* taskGroup = args.fContext->contextPriv().getTaskGroup();
300 if (taskGroup) {
301 proxy = make_deferred_mask_texture_proxy(args.fContext, fit,
302 boundsForMask->width(),
303 boundsForMask->height());
304 if (!proxy) {
305 return false;
306 }
307
Robert Phillipscfbbcbe2017-09-21 15:11:03 -0400308 // TODO: I believe the assignUniqueKeyToProxy below used to instantiate the proxy before
309 // before the draw that used the result was being flushed, so the upload was succeeding.
310 // With assignUniqueKeyToProxy no longer forcing an instantiation it will have to happen
311 // explicitly elsewhere.
312 proxy->instantiate(fResourceProvider);
313
Brian Osman5d034742017-09-11 13:38:55 -0400314 auto uploader = skstd::make_unique<GrMaskUploaderPrepareCallback<SoftwarePathData>>(
Brian Osmanf9810662017-08-30 10:02:10 -0400315 proxy, *boundsForMask, *args.fViewMatrix, *args.fShape, aa);
Brian Osman5d034742017-09-11 13:38:55 -0400316 GrMaskUploaderPrepareCallback<SoftwarePathData>* uploaderRaw = uploader.get();
Brian Osmanf9810662017-08-30 10:02:10 -0400317
318 auto drawAndUploadMask = [uploaderRaw] {
319 TRACE_EVENT0("skia", "Threaded SW Mask Render");
320 GrSWMaskHelper helper(uploaderRaw->getPixels());
Brian Osman5d034742017-09-11 13:38:55 -0400321 if (helper.init(uploaderRaw->data().getMaskBounds())) {
322 helper.drawShape(uploaderRaw->data().getShape(),
323 *uploaderRaw->data().getViewMatrix(),
324 SkRegion::kReplace_Op, uploaderRaw->data().getAA(), 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400325 } else {
326 SkDEBUGFAIL("Unable to allocate SW mask.");
327 }
328 uploaderRaw->getSemaphore()->signal();
329 };
330 taskGroup->add(std::move(drawAndUploadMask));
331 args.fRenderTargetContext->getOpList()->addPrepareCallback(std::move(uploader));
332 } else {
333 GrSWMaskHelper helper;
Brian Salomon74077562017-08-30 13:55:35 -0400334 if (!helper.init(*boundsForMask)) {
Brian Osmanf9810662017-08-30 10:02:10 -0400335 return false;
336 }
Brian Salomon74077562017-08-30 13:55:35 -0400337 helper.drawShape(*args.fShape, *args.fViewMatrix, SkRegion::kReplace_Op, aa, 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400338 proxy = helper.toTextureProxy(args.fContext, fit);
339 }
340
Robert Phillipsd3749482017-03-14 09:17:43 -0400341 if (!proxy) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500342 return false;
343 }
344 if (useCache) {
Robert Phillipse44ef102017-07-21 15:37:19 -0400345 SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
Robert Phillipsd3749482017-03-14 09:17:43 -0400346 fResourceProvider->assignUniqueKeyToProxy(maskKey, proxy.get());
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500347 }
bsalomon39ef7fb2016-09-21 11:16:05 -0700348 }
bsalomon8acedde2016-06-24 10:42:16 -0700349 if (inverseFilled) {
Brian Salomonb74ef032017-08-10 12:46:01 -0400350 DrawAroundInvPath(args.fRenderTargetContext, GrPaint::Clone(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500351 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix, devClipBounds,
352 unclippedDevShapeBounds);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000353 }
Brian Osmanc7da1462017-08-17 16:14:25 -0400354 DrawToTargetWithShapeMask(
Robert Phillips296b1cc2017-03-15 10:42:12 -0400355 std::move(proxy), args.fRenderTargetContext, std::move(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500356 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
357 SkIPoint{boundsForMask->fLeft, boundsForMask->fTop}, *boundsForMask);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000358
359 return true;
robertphillips@google.comf4c2c522012-04-27 12:08:47 +0000360}