blob: ff6a20fbe7a72f904399eef00f7683a4f08ca4a5 [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"
Brian Osman099fa0f2017-10-02 16:38:32 -040012#include "GrDeferredProxyUploader.h"
bsalomon39ef7fb2016-09-21 11:16:05 -070013#include "GrGpuResourcePriv.h"
Brian Osmanf9810662017-08-30 10:02:10 -040014#include "GrOpFlushState.h"
15#include "GrOpList.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050016#include "GrProxyProvider.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.
Robert Phillips1afd4cd2018-01-08 13:40:32 -050030 if (!args.fShape->style().applies() && SkToBool(fProxyProvider) &&
Chris Dalton5ed44232017-09-07 13:22:46 -060031 (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 }
Jim Van Verthba7cf292017-11-02 20:18:56 +000055 // Make sure that the resulting SkIRect can have representable width and height
56 if (SkScalarRoundToInt(shapeDevBounds.width()) > kMaxInt ||
57 SkScalarRoundToInt(shapeDevBounds.height()) > kMaxInt) {
58 return false;
59 }
bsalomon39ef7fb2016-09-21 11:16:05 -070060 shapeDevBounds.roundOut(devBounds);
61 return true;
62}
63
64// Gets the shape bounds, the clip bounds, and the intersection (if any). Returns false if there
65// is no intersection.
66static bool get_shape_and_clip_bounds(int width, int height,
67 const GrClip& clip,
68 const GrShape& shape,
69 const SkMatrix& matrix,
70 SkIRect* unclippedDevShapeBounds,
71 SkIRect* clippedDevShapeBounds,
72 SkIRect* devClipBounds) {
robertphillips@google.comed4155d2012-05-01 14:30:24 +000073 // compute bounds as intersection of rt size, clip, and path
robertphillips0152d732016-05-20 06:38:43 -070074 clip.getConservativeBounds(width, height, devClipBounds);
robertphillips@google.com7b112892012-07-31 15:18:21 +000075
bsalomon39ef7fb2016-09-21 11:16:05 -070076 if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) {
77 *unclippedDevShapeBounds = SkIRect::EmptyIRect();
78 *clippedDevShapeBounds = SkIRect::EmptyIRect();
robertphillips@google.com3e11c0b2012-07-11 18:20:35 +000079 return false;
robertphillips@google.comed4155d2012-05-01 14:30:24 +000080 }
bsalomon39ef7fb2016-09-21 11:16:05 -070081 if (!clippedDevShapeBounds->intersect(*devClipBounds, *unclippedDevShapeBounds)) {
82 *clippedDevShapeBounds = SkIRect::EmptyIRect();
robertphillips@google.comed4155d2012-05-01 14:30:24 +000083 return false;
84 }
85 return true;
86}
87
88////////////////////////////////////////////////////////////////////////////////
robertphillips976f5f02016-06-03 10:59:20 -070089
Brian Osman11052242016-10-27 14:47:55 -040090void GrSoftwarePathRenderer::DrawNonAARect(GrRenderTargetContext* renderTargetContext,
Brian Salomon82f44312017-01-11 13:42:54 -050091 GrPaint&& paint,
robertphillipsd2b6d642016-07-21 08:55:08 -070092 const GrUserStencilSettings& userStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -070093 const GrClip& clip,
robertphillips976f5f02016-06-03 10:59:20 -070094 const SkMatrix& viewMatrix,
95 const SkRect& rect,
96 const SkMatrix& localMatrix) {
Brian Salomonbaaf4392017-06-15 09:59:23 -040097 renderTargetContext->addDrawOp(clip,
98 GrRectOpFactory::MakeNonAAFillWithLocalMatrix(
99 std::move(paint), viewMatrix, localMatrix, rect,
100 GrAAType::kNone, &userStencilSettings));
robertphillips976f5f02016-06-03 10:59:20 -0700101}
102
Brian Osman11052242016-10-27 14:47:55 -0400103void GrSoftwarePathRenderer::DrawAroundInvPath(GrRenderTargetContext* renderTargetContext,
Brian Salomon82f44312017-01-11 13:42:54 -0500104 GrPaint&& paint,
robertphillipsd2b6d642016-07-21 08:55:08 -0700105 const GrUserStencilSettings& userStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -0700106 const GrClip& clip,
robertphillips976f5f02016-06-03 10:59:20 -0700107 const SkMatrix& viewMatrix,
108 const SkIRect& devClipBounds,
109 const SkIRect& devPathBounds) {
joshualittd27f73e2014-12-29 07:43:36 -0800110 SkMatrix invert;
joshualitt8059eb92014-12-29 15:10:07 -0800111 if (!viewMatrix.invert(&invert)) {
bsalomon@google.come3d32162012-07-20 13:37:06 +0000112 return;
113 }
joshualittd27f73e2014-12-29 07:43:36 -0800114
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000115 SkRect rect;
robertphillips@google.com7b112892012-07-31 15:18:21 +0000116 if (devClipBounds.fTop < devPathBounds.fTop) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000117 rect.iset(devClipBounds.fLeft, devClipBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000118 devClipBounds.fRight, devPathBounds.fTop);
Brian Salomonb74ef032017-08-10 12:46:01 -0400119 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
120 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000121 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000122 if (devClipBounds.fLeft < devPathBounds.fLeft) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000123 rect.iset(devClipBounds.fLeft, devPathBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000124 devPathBounds.fLeft, devPathBounds.fBottom);
Brian Salomonb74ef032017-08-10 12:46:01 -0400125 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
126 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000127 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000128 if (devClipBounds.fRight > devPathBounds.fRight) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000129 rect.iset(devPathBounds.fRight, devPathBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000130 devClipBounds.fRight, devPathBounds.fBottom);
Brian Salomonb74ef032017-08-10 12:46:01 -0400131 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
132 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000133 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000134 if (devClipBounds.fBottom > devPathBounds.fBottom) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000135 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000136 devClipBounds.fRight, devClipBounds.fBottom);
Brian Salomon82f44312017-01-11 13:42:54 -0500137 DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip,
robertphillips976f5f02016-06-03 10:59:20 -0700138 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000139 }
140}
141
Brian Osmanc7da1462017-08-17 16:14:25 -0400142void GrSoftwarePathRenderer::DrawToTargetWithShapeMask(
143 sk_sp<GrTextureProxy> proxy,
144 GrRenderTargetContext* renderTargetContext,
145 GrPaint&& paint,
146 const GrUserStencilSettings& userStencilSettings,
147 const GrClip& clip,
148 const SkMatrix& viewMatrix,
149 const SkIPoint& textureOriginInDeviceSpace,
150 const SkIRect& deviceSpaceRectToDraw) {
151 SkMatrix invert;
152 if (!viewMatrix.invert(&invert)) {
153 return;
154 }
155
156 SkRect dstRect = SkRect::Make(deviceSpaceRectToDraw);
157
158 // We use device coords to compute the texture coordinates. We take the device coords and apply
159 // a translation so that the top-left of the device bounds maps to 0,0, and then a scaling
160 // matrix to normalized coords.
161 SkMatrix maskMatrix = SkMatrix::MakeTrans(SkIntToScalar(-textureOriginInDeviceSpace.fX),
162 SkIntToScalar(-textureOriginInDeviceSpace.fY));
163 maskMatrix.preConcat(viewMatrix);
164 paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(
Brian Osman2240be92017-10-18 13:15:13 -0400165 std::move(proxy), maskMatrix, GrSamplerState::Filter::kNearest));
Brian Osmanf9810662017-08-30 10:02:10 -0400166 DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip, SkMatrix::I(),
167 dstRect, invert);
168}
169
170static sk_sp<GrTextureProxy> make_deferred_mask_texture_proxy(GrContext* context, SkBackingFit fit,
171 int width, int height) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500172 GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
173
Brian Osmanf9810662017-08-30 10:02:10 -0400174 GrSurfaceDesc desc;
175 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
176 desc.fWidth = width;
177 desc.fHeight = height;
178 desc.fConfig = kAlpha_8_GrPixelConfig;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500179
Brian Osmand140fe92017-10-03 12:17:26 -0400180 // MDB TODO: We're going to fill this proxy with an ASAP upload (which is out of order wrt to
181 // ops), so it can't have any pending IO.
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500182 return proxyProvider->createProxy(desc, fit, SkBudgeted::kYes,
183 GrResourceProvider::kNoPendingIO_Flag);
Brian Osmanf9810662017-08-30 10:02:10 -0400184}
185
186namespace {
187
Brian Osman5d034742017-09-11 13:38:55 -0400188/**
Brian Osman099fa0f2017-10-02 16:38:32 -0400189 * Payload class for use with GrTDeferredProxyUploader. The software path renderer only draws
Brian Osman5d034742017-09-11 13:38:55 -0400190 * a single path into the mask texture. This stores all of the information needed by the worker
191 * thread's call to drawShape (see below, in onDrawPath).
192 */
193class SoftwarePathData {
Brian Osmanf9810662017-08-30 10:02:10 -0400194public:
Brian Osman5d034742017-09-11 13:38:55 -0400195 SoftwarePathData(const SkIRect& maskBounds, const SkMatrix& viewMatrix, const GrShape& shape,
196 GrAA aa)
197 : fMaskBounds(maskBounds)
Brian Osmanf9810662017-08-30 10:02:10 -0400198 , fViewMatrix(viewMatrix)
199 , fShape(shape)
Brian Osman5d034742017-09-11 13:38:55 -0400200 , fAA(aa) {}
Brian Osmanf9810662017-08-30 10:02:10 -0400201
Brian Osmanf9810662017-08-30 10:02:10 -0400202 const SkIRect& getMaskBounds() const { return fMaskBounds; }
203 const SkMatrix* getViewMatrix() const { return &fViewMatrix; }
204 const GrShape& getShape() const { return fShape; }
205 GrAA getAA() const { return fAA; }
206
207private:
Brian Osmanf9810662017-08-30 10:02:10 -0400208 SkIRect fMaskBounds;
209 SkMatrix fViewMatrix;
210 GrShape fShape;
211 GrAA fAA;
Brian Osmanf9810662017-08-30 10:02:10 -0400212};
213
Brian Osmane9242ca2017-09-26 14:05:19 -0400214// When the SkPathRef genID changes, invalidate a corresponding GrResource described by key.
215class PathInvalidator : public SkPathRef::GenIDChangeListener {
216public:
217 explicit PathInvalidator(const GrUniqueKey& key) : fMsg(key) {}
218private:
219 GrUniqueKeyInvalidatedMessage fMsg;
220
221 void onChange() override {
222 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg);
223 }
224};
225
Brian Osmanc7da1462017-08-17 16:14:25 -0400226}
227
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000228////////////////////////////////////////////////////////////////////////////////
229// return true on success; false on failure
bsalomon0aff2fa2015-07-31 06:48:27 -0700230bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400231 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700232 "GrSoftwarePathRenderer::onDrawPath");
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500233 if (!fProxyProvider) {
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000234 return false;
235 }
236
bsalomon8acedde2016-06-24 10:42:16 -0700237 // We really need to know if the shape will be inverse filled or not
238 bool inverseFilled = false;
239 SkTLazy<GrShape> tmpShape;
caryclarkd6562002016-07-27 12:02:07 -0700240 SkASSERT(!args.fShape->style().applies());
Eric Karl5c779752017-05-08 12:02:07 -0700241 // If the path is hairline, ignore inverse fill.
242 inverseFilled = args.fShape->inverseFilled() &&
243 !IsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr);
bsalomon8acedde2016-06-24 10:42:16 -0700244
bsalomon39ef7fb2016-09-21 11:16:05 -0700245 SkIRect unclippedDevShapeBounds, clippedDevShapeBounds, devClipBounds;
246 // To prevent overloading the cache with entries during animations we limit the cache of masks
247 // to cases where the matrix preserves axis alignment.
248 bool useCache = fAllowCaching && !inverseFilled && args.fViewMatrix->preservesAxisAlignment() &&
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500249 args.fShape->hasUnstyledKey() && GrAAType::kCoverage == args.fAAType;
bsalomon39ef7fb2016-09-21 11:16:05 -0700250
Brian Osman11052242016-10-27 14:47:55 -0400251 if (!get_shape_and_clip_bounds(args.fRenderTargetContext->width(),
252 args.fRenderTargetContext->height(),
bsalomon8acedde2016-06-24 10:42:16 -0700253 *args.fClip, *args.fShape,
bsalomon39ef7fb2016-09-21 11:16:05 -0700254 *args.fViewMatrix, &unclippedDevShapeBounds,
255 &clippedDevShapeBounds,
256 &devClipBounds)) {
bsalomon8acedde2016-06-24 10:42:16 -0700257 if (inverseFilled) {
Brian Salomon82f44312017-01-11 13:42:54 -0500258 DrawAroundInvPath(args.fRenderTargetContext, std::move(args.fPaint),
259 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
260 devClipBounds, unclippedDevShapeBounds);
bsalomon@google.com276c1fa2012-06-19 13:22:45 +0000261 }
262 return true;
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000263 }
robertphillips@google.com366f1c62012-06-29 21:38:47 +0000264
bsalomon39ef7fb2016-09-21 11:16:05 -0700265 const SkIRect* boundsForMask = &clippedDevShapeBounds;
266 if (useCache) {
267 // Use the cache only if >50% of the path is visible.
268 int unclippedWidth = unclippedDevShapeBounds.width();
269 int unclippedHeight = unclippedDevShapeBounds.height();
Brian Osman1a0ea732017-09-28 11:53:03 -0400270 int64_t unclippedArea = sk_64_mul(unclippedWidth, unclippedHeight);
271 int64_t clippedArea = sk_64_mul(clippedDevShapeBounds.width(),
272 clippedDevShapeBounds.height());
Brian Osman11052242016-10-27 14:47:55 -0400273 int maxTextureSize = args.fRenderTargetContext->caps()->maxTextureSize();
bsalomon39ef7fb2016-09-21 11:16:05 -0700274 if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize ||
275 unclippedHeight > maxTextureSize) {
276 useCache = false;
277 } else {
278 boundsForMask = &unclippedDevShapeBounds;
279 }
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000280 }
281
bsalomon39ef7fb2016-09-21 11:16:05 -0700282 GrUniqueKey maskKey;
bsalomon39ef7fb2016-09-21 11:16:05 -0700283 if (useCache) {
284 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
285 SkScalar sx = args.fViewMatrix->get(SkMatrix::kMScaleX);
286 SkScalar sy = args.fViewMatrix->get(SkMatrix::kMScaleY);
287 SkScalar kx = args.fViewMatrix->get(SkMatrix::kMSkewX);
288 SkScalar ky = args.fViewMatrix->get(SkMatrix::kMSkewY);
Stan Iliev67cd6732017-08-15 17:10:26 -0400289 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
290#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
291 // Fractional translate does not affect caching on Android. This is done for better cache
292 // hit ratio and speed, but it is matching HWUI behavior, which doesn't consider the matrix
293 // at all when caching paths.
294 GrUniqueKey::Builder builder(&maskKey, kDomain, 4 + args.fShape->unstyledKeySize());
295#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700296 SkScalar tx = args.fViewMatrix->get(SkMatrix::kMTransX);
297 SkScalar ty = args.fViewMatrix->get(SkMatrix::kMTransY);
298 // Allow 8 bits each in x and y of subpixel positioning.
299 SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
300 SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
bsalomon39ef7fb2016-09-21 11:16:05 -0700301 GrUniqueKey::Builder builder(&maskKey, kDomain, 5 + args.fShape->unstyledKeySize());
Stan Iliev67cd6732017-08-15 17:10:26 -0400302#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700303 builder[0] = SkFloat2Bits(sx);
304 builder[1] = SkFloat2Bits(sy);
305 builder[2] = SkFloat2Bits(kx);
306 builder[3] = SkFloat2Bits(ky);
Stan Iliev67cd6732017-08-15 17:10:26 -0400307#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
308 args.fShape->writeUnstyledKey(&builder[4]);
309#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700310 builder[4] = fracX | (fracY >> 8);
311 args.fShape->writeUnstyledKey(&builder[5]);
Stan Iliev67cd6732017-08-15 17:10:26 -0400312#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700313 }
314
Robert Phillipsd3749482017-03-14 09:17:43 -0400315 sk_sp<GrTextureProxy> proxy;
bsalomon39ef7fb2016-09-21 11:16:05 -0700316 if (useCache) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500317 proxy = fProxyProvider->findOrCreateProxyByUniqueKey(maskKey, kTopLeft_GrSurfaceOrigin);
bsalomon39ef7fb2016-09-21 11:16:05 -0700318 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400319 if (!proxy) {
Robert Phillips417b7f42016-12-14 09:12:13 -0500320 SkBackingFit fit = useCache ? SkBackingFit::kExact : SkBackingFit::kApprox;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500321 GrAA aa = GrAAType::kCoverage == args.fAAType ? GrAA::kYes : GrAA::kNo;
Brian Osmanf9810662017-08-30 10:02:10 -0400322
323 SkTaskGroup* taskGroup = args.fContext->contextPriv().getTaskGroup();
324 if (taskGroup) {
325 proxy = make_deferred_mask_texture_proxy(args.fContext, fit,
326 boundsForMask->width(),
327 boundsForMask->height());
328 if (!proxy) {
329 return false;
330 }
331
Brian Osman099fa0f2017-10-02 16:38:32 -0400332 auto uploader = skstd::make_unique<GrTDeferredProxyUploader<SoftwarePathData>>(
333 *boundsForMask, *args.fViewMatrix, *args.fShape, aa);
334 GrTDeferredProxyUploader<SoftwarePathData>* uploaderRaw = uploader.get();
Brian Osmanf9810662017-08-30 10:02:10 -0400335
336 auto drawAndUploadMask = [uploaderRaw] {
337 TRACE_EVENT0("skia", "Threaded SW Mask Render");
338 GrSWMaskHelper helper(uploaderRaw->getPixels());
Brian Osman5d034742017-09-11 13:38:55 -0400339 if (helper.init(uploaderRaw->data().getMaskBounds())) {
340 helper.drawShape(uploaderRaw->data().getShape(),
341 *uploaderRaw->data().getViewMatrix(),
342 SkRegion::kReplace_Op, uploaderRaw->data().getAA(), 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400343 } else {
344 SkDEBUGFAIL("Unable to allocate SW mask.");
345 }
Brian Osman099fa0f2017-10-02 16:38:32 -0400346 uploaderRaw->signalAndFreeData();
Brian Osmanf9810662017-08-30 10:02:10 -0400347 };
348 taskGroup->add(std::move(drawAndUploadMask));
Brian Osman099fa0f2017-10-02 16:38:32 -0400349 proxy->texPriv().setDeferredUploader(std::move(uploader));
Brian Osmanf9810662017-08-30 10:02:10 -0400350 } else {
351 GrSWMaskHelper helper;
Brian Salomon74077562017-08-30 13:55:35 -0400352 if (!helper.init(*boundsForMask)) {
Brian Osmanf9810662017-08-30 10:02:10 -0400353 return false;
354 }
Brian Salomon74077562017-08-30 13:55:35 -0400355 helper.drawShape(*args.fShape, *args.fViewMatrix, SkRegion::kReplace_Op, aa, 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400356 proxy = helper.toTextureProxy(args.fContext, fit);
357 }
358
Robert Phillipsd3749482017-03-14 09:17:43 -0400359 if (!proxy) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500360 return false;
361 }
362 if (useCache) {
Robert Phillipse44ef102017-07-21 15:37:19 -0400363 SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500364 fProxyProvider->assignUniqueKeyToProxy(maskKey, proxy.get());
Brian Osmane9242ca2017-09-26 14:05:19 -0400365 args.fShape->addGenIDChangeListener(new PathInvalidator(maskKey));
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500366 }
bsalomon39ef7fb2016-09-21 11:16:05 -0700367 }
bsalomon8acedde2016-06-24 10:42:16 -0700368 if (inverseFilled) {
Brian Salomonb74ef032017-08-10 12:46:01 -0400369 DrawAroundInvPath(args.fRenderTargetContext, GrPaint::Clone(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500370 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix, devClipBounds,
371 unclippedDevShapeBounds);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000372 }
Brian Osmanc7da1462017-08-17 16:14:25 -0400373 DrawToTargetWithShapeMask(
Robert Phillips296b1cc2017-03-15 10:42:12 -0400374 std::move(proxy), args.fRenderTargetContext, std::move(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500375 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
376 SkIPoint{boundsForMask->fLeft, boundsForMask->fTop}, *boundsForMask);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000377
378 return true;
robertphillips@google.comf4c2c522012-04-27 12:08:47 +0000379}