blob: 228625f4fb6b65289823f195660ce6901899d2c9 [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;
Brian Osmanf9810662017-08-30 10:02:10 -0400175 desc.fWidth = width;
176 desc.fHeight = height;
177 desc.fConfig = kAlpha_8_GrPixelConfig;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500178
Brian Osmand140fe92017-10-03 12:17:26 -0400179 // MDB TODO: We're going to fill this proxy with an ASAP upload (which is out of order wrt to
180 // ops), so it can't have any pending IO.
Brian Salomon2a4f9832018-03-03 22:43:43 -0500181 return proxyProvider->createProxy(desc, kTopLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes,
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400182 GrInternalSurfaceFlags::kNoPendingIO);
Brian Osmanf9810662017-08-30 10:02:10 -0400183}
184
185namespace {
186
Brian Osman5d034742017-09-11 13:38:55 -0400187/**
Brian Osman099fa0f2017-10-02 16:38:32 -0400188 * Payload class for use with GrTDeferredProxyUploader. The software path renderer only draws
Brian Osman5d034742017-09-11 13:38:55 -0400189 * a single path into the mask texture. This stores all of the information needed by the worker
190 * thread's call to drawShape (see below, in onDrawPath).
191 */
192class SoftwarePathData {
Brian Osmanf9810662017-08-30 10:02:10 -0400193public:
Brian Osman5d034742017-09-11 13:38:55 -0400194 SoftwarePathData(const SkIRect& maskBounds, const SkMatrix& viewMatrix, const GrShape& shape,
195 GrAA aa)
196 : fMaskBounds(maskBounds)
Brian Osmanf9810662017-08-30 10:02:10 -0400197 , fViewMatrix(viewMatrix)
198 , fShape(shape)
Brian Osman5d034742017-09-11 13:38:55 -0400199 , fAA(aa) {}
Brian Osmanf9810662017-08-30 10:02:10 -0400200
Brian Osmanf9810662017-08-30 10:02:10 -0400201 const SkIRect& getMaskBounds() const { return fMaskBounds; }
202 const SkMatrix* getViewMatrix() const { return &fViewMatrix; }
203 const GrShape& getShape() const { return fShape; }
204 GrAA getAA() const { return fAA; }
205
206private:
Brian Osmanf9810662017-08-30 10:02:10 -0400207 SkIRect fMaskBounds;
208 SkMatrix fViewMatrix;
209 GrShape fShape;
210 GrAA fAA;
Brian Osmanf9810662017-08-30 10:02:10 -0400211};
212
Brian Osmane9242ca2017-09-26 14:05:19 -0400213// When the SkPathRef genID changes, invalidate a corresponding GrResource described by key.
214class PathInvalidator : public SkPathRef::GenIDChangeListener {
215public:
216 explicit PathInvalidator(const GrUniqueKey& key) : fMsg(key) {}
217private:
218 GrUniqueKeyInvalidatedMessage fMsg;
219
220 void onChange() override {
221 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg);
222 }
223};
224
Brian Osmanc7da1462017-08-17 16:14:25 -0400225}
226
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000227////////////////////////////////////////////////////////////////////////////////
228// return true on success; false on failure
bsalomon0aff2fa2015-07-31 06:48:27 -0700229bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400230 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700231 "GrSoftwarePathRenderer::onDrawPath");
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500232 if (!fProxyProvider) {
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000233 return false;
234 }
235
bsalomon8acedde2016-06-24 10:42:16 -0700236 // We really need to know if the shape will be inverse filled or not
237 bool inverseFilled = false;
238 SkTLazy<GrShape> tmpShape;
caryclarkd6562002016-07-27 12:02:07 -0700239 SkASSERT(!args.fShape->style().applies());
Eric Karl5c779752017-05-08 12:02:07 -0700240 // If the path is hairline, ignore inverse fill.
241 inverseFilled = args.fShape->inverseFilled() &&
242 !IsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr);
bsalomon8acedde2016-06-24 10:42:16 -0700243
bsalomon39ef7fb2016-09-21 11:16:05 -0700244 SkIRect unclippedDevShapeBounds, clippedDevShapeBounds, devClipBounds;
245 // To prevent overloading the cache with entries during animations we limit the cache of masks
246 // to cases where the matrix preserves axis alignment.
247 bool useCache = fAllowCaching && !inverseFilled && args.fViewMatrix->preservesAxisAlignment() &&
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500248 args.fShape->hasUnstyledKey() && GrAAType::kCoverage == args.fAAType;
bsalomon39ef7fb2016-09-21 11:16:05 -0700249
Brian Osman11052242016-10-27 14:47:55 -0400250 if (!get_shape_and_clip_bounds(args.fRenderTargetContext->width(),
251 args.fRenderTargetContext->height(),
bsalomon8acedde2016-06-24 10:42:16 -0700252 *args.fClip, *args.fShape,
bsalomon39ef7fb2016-09-21 11:16:05 -0700253 *args.fViewMatrix, &unclippedDevShapeBounds,
254 &clippedDevShapeBounds,
255 &devClipBounds)) {
bsalomon8acedde2016-06-24 10:42:16 -0700256 if (inverseFilled) {
Brian Salomon82f44312017-01-11 13:42:54 -0500257 DrawAroundInvPath(args.fRenderTargetContext, std::move(args.fPaint),
258 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
259 devClipBounds, unclippedDevShapeBounds);
bsalomon@google.com276c1fa2012-06-19 13:22:45 +0000260 }
261 return true;
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000262 }
robertphillips@google.com366f1c62012-06-29 21:38:47 +0000263
bsalomon39ef7fb2016-09-21 11:16:05 -0700264 const SkIRect* boundsForMask = &clippedDevShapeBounds;
265 if (useCache) {
266 // Use the cache only if >50% of the path is visible.
267 int unclippedWidth = unclippedDevShapeBounds.width();
268 int unclippedHeight = unclippedDevShapeBounds.height();
Brian Osman1a0ea732017-09-28 11:53:03 -0400269 int64_t unclippedArea = sk_64_mul(unclippedWidth, unclippedHeight);
270 int64_t clippedArea = sk_64_mul(clippedDevShapeBounds.width(),
271 clippedDevShapeBounds.height());
Brian Osman11052242016-10-27 14:47:55 -0400272 int maxTextureSize = args.fRenderTargetContext->caps()->maxTextureSize();
bsalomon39ef7fb2016-09-21 11:16:05 -0700273 if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize ||
274 unclippedHeight > maxTextureSize) {
275 useCache = false;
276 } else {
277 boundsForMask = &unclippedDevShapeBounds;
278 }
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000279 }
280
bsalomon39ef7fb2016-09-21 11:16:05 -0700281 GrUniqueKey maskKey;
bsalomon39ef7fb2016-09-21 11:16:05 -0700282 if (useCache) {
283 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
284 SkScalar sx = args.fViewMatrix->get(SkMatrix::kMScaleX);
285 SkScalar sy = args.fViewMatrix->get(SkMatrix::kMScaleY);
286 SkScalar kx = args.fViewMatrix->get(SkMatrix::kMSkewX);
287 SkScalar ky = args.fViewMatrix->get(SkMatrix::kMSkewY);
Stan Iliev67cd6732017-08-15 17:10:26 -0400288 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
289#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
290 // Fractional translate does not affect caching on Android. This is done for better cache
291 // hit ratio and speed, but it is matching HWUI behavior, which doesn't consider the matrix
292 // at all when caching paths.
293 GrUniqueKey::Builder builder(&maskKey, kDomain, 4 + args.fShape->unstyledKeySize());
294#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700295 SkScalar tx = args.fViewMatrix->get(SkMatrix::kMTransX);
296 SkScalar ty = args.fViewMatrix->get(SkMatrix::kMTransY);
297 // Allow 8 bits each in x and y of subpixel positioning.
298 SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
299 SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
bsalomon39ef7fb2016-09-21 11:16:05 -0700300 GrUniqueKey::Builder builder(&maskKey, kDomain, 5 + args.fShape->unstyledKeySize());
Stan Iliev67cd6732017-08-15 17:10:26 -0400301#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700302 builder[0] = SkFloat2Bits(sx);
303 builder[1] = SkFloat2Bits(sy);
304 builder[2] = SkFloat2Bits(kx);
305 builder[3] = SkFloat2Bits(ky);
Stan Iliev67cd6732017-08-15 17:10:26 -0400306#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
307 args.fShape->writeUnstyledKey(&builder[4]);
308#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700309 builder[4] = fracX | (fracY >> 8);
310 args.fShape->writeUnstyledKey(&builder[5]);
Stan Iliev67cd6732017-08-15 17:10:26 -0400311#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700312 }
313
Robert Phillipsd3749482017-03-14 09:17:43 -0400314 sk_sp<GrTextureProxy> proxy;
bsalomon39ef7fb2016-09-21 11:16:05 -0700315 if (useCache) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500316 proxy = fProxyProvider->findOrCreateProxyByUniqueKey(maskKey, kTopLeft_GrSurfaceOrigin);
bsalomon39ef7fb2016-09-21 11:16:05 -0700317 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400318 if (!proxy) {
Robert Phillips417b7f42016-12-14 09:12:13 -0500319 SkBackingFit fit = useCache ? SkBackingFit::kExact : SkBackingFit::kApprox;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500320 GrAA aa = GrAAType::kCoverage == args.fAAType ? GrAA::kYes : GrAA::kNo;
Brian Osmanf9810662017-08-30 10:02:10 -0400321
322 SkTaskGroup* taskGroup = args.fContext->contextPriv().getTaskGroup();
323 if (taskGroup) {
324 proxy = make_deferred_mask_texture_proxy(args.fContext, fit,
325 boundsForMask->width(),
326 boundsForMask->height());
327 if (!proxy) {
328 return false;
329 }
330
Brian Osman099fa0f2017-10-02 16:38:32 -0400331 auto uploader = skstd::make_unique<GrTDeferredProxyUploader<SoftwarePathData>>(
332 *boundsForMask, *args.fViewMatrix, *args.fShape, aa);
333 GrTDeferredProxyUploader<SoftwarePathData>* uploaderRaw = uploader.get();
Brian Osmanf9810662017-08-30 10:02:10 -0400334
335 auto drawAndUploadMask = [uploaderRaw] {
336 TRACE_EVENT0("skia", "Threaded SW Mask Render");
337 GrSWMaskHelper helper(uploaderRaw->getPixels());
Brian Osman5d034742017-09-11 13:38:55 -0400338 if (helper.init(uploaderRaw->data().getMaskBounds())) {
339 helper.drawShape(uploaderRaw->data().getShape(),
340 *uploaderRaw->data().getViewMatrix(),
341 SkRegion::kReplace_Op, uploaderRaw->data().getAA(), 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400342 } else {
343 SkDEBUGFAIL("Unable to allocate SW mask.");
344 }
Brian Osman099fa0f2017-10-02 16:38:32 -0400345 uploaderRaw->signalAndFreeData();
Brian Osmanf9810662017-08-30 10:02:10 -0400346 };
347 taskGroup->add(std::move(drawAndUploadMask));
Brian Osman099fa0f2017-10-02 16:38:32 -0400348 proxy->texPriv().setDeferredUploader(std::move(uploader));
Brian Osmanf9810662017-08-30 10:02:10 -0400349 } else {
350 GrSWMaskHelper helper;
Brian Salomon74077562017-08-30 13:55:35 -0400351 if (!helper.init(*boundsForMask)) {
Brian Osmanf9810662017-08-30 10:02:10 -0400352 return false;
353 }
Brian Salomon74077562017-08-30 13:55:35 -0400354 helper.drawShape(*args.fShape, *args.fViewMatrix, SkRegion::kReplace_Op, aa, 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400355 proxy = helper.toTextureProxy(args.fContext, fit);
356 }
357
Robert Phillipsd3749482017-03-14 09:17:43 -0400358 if (!proxy) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500359 return false;
360 }
361 if (useCache) {
Robert Phillipse44ef102017-07-21 15:37:19 -0400362 SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500363 fProxyProvider->assignUniqueKeyToProxy(maskKey, proxy.get());
Brian Osmane9242ca2017-09-26 14:05:19 -0400364 args.fShape->addGenIDChangeListener(new PathInvalidator(maskKey));
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500365 }
bsalomon39ef7fb2016-09-21 11:16:05 -0700366 }
bsalomon8acedde2016-06-24 10:42:16 -0700367 if (inverseFilled) {
Brian Salomonb74ef032017-08-10 12:46:01 -0400368 DrawAroundInvPath(args.fRenderTargetContext, GrPaint::Clone(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500369 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix, devClipBounds,
370 unclippedDevShapeBounds);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000371 }
Brian Osmanc7da1462017-08-17 16:14:25 -0400372 DrawToTargetWithShapeMask(
Robert Phillips296b1cc2017-03-15 10:42:12 -0400373 std::move(proxy), args.fRenderTargetContext, std::move(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500374 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
375 SkIPoint{boundsForMask->fLeft, boundsForMask->fTop}, *boundsForMask);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000376
377 return true;
robertphillips@google.comf4c2c522012-04-27 12:08:47 +0000378}