blob: ee52122840704dcc8d085c141f47487a5b4d17e4 [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 Salomon653f42f2018-07-10 10:07:31 -040018#include "GrShape.h"
19#include "GrSurfaceContextPriv.h"
Brian Osmanf9810662017-08-30 10:02:10 -040020#include "SkMakeUnique.h"
21#include "SkSemaphore.h"
22#include "SkTaskGroup.h"
23#include "SkTraceEvent.h"
Robert Phillips009e9af2017-06-15 14:01:04 -040024#include "ops/GrDrawOp.h"
Brian Salomonbaaf4392017-06-15 09:59:23 -040025#include "ops/GrRectOpFactory.h"
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000026
robertphillips@google.comed4155d2012-05-01 14:30:24 +000027////////////////////////////////////////////////////////////////////////////////
Chris Dalton5ed44232017-09-07 13:22:46 -060028GrPathRenderer::CanDrawPath
29GrSoftwarePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
bsalomon8acedde2016-06-24 10:42:16 -070030 // Pass on any style that applies. The caller will apply the style if a suitable renderer is
31 // not found and try again with the new GrShape.
Robert Phillips1afd4cd2018-01-08 13:40:32 -050032 if (!args.fShape->style().applies() && SkToBool(fProxyProvider) &&
Chris Dalton5ed44232017-09-07 13:22:46 -060033 (args.fAAType == GrAAType::kCoverage || args.fAAType == GrAAType::kNone)) {
34 // This is the fallback renderer for when a path is too complicated for the GPU ones.
35 return CanDrawPath::kAsBackup;
36 }
37 return CanDrawPath::kNo;
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000038}
39
robertphillips@google.comed4155d2012-05-01 14:30:24 +000040////////////////////////////////////////////////////////////////////////////////
bsalomon39ef7fb2016-09-21 11:16:05 -070041static bool get_unclipped_shape_dev_bounds(const GrShape& shape, const SkMatrix& matrix,
42 SkIRect* devBounds) {
43 SkRect shapeBounds = shape.styledBounds();
44 if (shapeBounds.isEmpty()) {
45 return false;
46 }
47 SkRect shapeDevBounds;
48 matrix.mapRect(&shapeDevBounds, shapeBounds);
Brian Salomonc1c607e2016-12-20 11:41:43 -050049 // Even though these are "unclipped" bounds we still clip to the int32_t range.
50 // This is the largest int32_t that is representable exactly as a float. The next 63 larger ints
51 // would round down to this value when cast to a float, but who really cares.
52 // INT32_MIN is exactly representable.
53 static constexpr int32_t kMaxInt = 2147483520;
54 if (!shapeDevBounds.intersect(SkRect::MakeLTRB(INT32_MIN, INT32_MIN, kMaxInt, kMaxInt))) {
55 return false;
56 }
Jim Van Verthba7cf292017-11-02 20:18:56 +000057 // Make sure that the resulting SkIRect can have representable width and height
58 if (SkScalarRoundToInt(shapeDevBounds.width()) > kMaxInt ||
59 SkScalarRoundToInt(shapeDevBounds.height()) > kMaxInt) {
60 return false;
61 }
bsalomon39ef7fb2016-09-21 11:16:05 -070062 shapeDevBounds.roundOut(devBounds);
63 return true;
64}
65
66// Gets the shape bounds, the clip bounds, and the intersection (if any). Returns false if there
67// is no intersection.
68static bool get_shape_and_clip_bounds(int width, int height,
69 const GrClip& clip,
70 const GrShape& shape,
71 const SkMatrix& matrix,
72 SkIRect* unclippedDevShapeBounds,
73 SkIRect* clippedDevShapeBounds,
74 SkIRect* devClipBounds) {
robertphillips@google.comed4155d2012-05-01 14:30:24 +000075 // compute bounds as intersection of rt size, clip, and path
robertphillips0152d732016-05-20 06:38:43 -070076 clip.getConservativeBounds(width, height, devClipBounds);
robertphillips@google.com7b112892012-07-31 15:18:21 +000077
bsalomon39ef7fb2016-09-21 11:16:05 -070078 if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) {
79 *unclippedDevShapeBounds = SkIRect::EmptyIRect();
80 *clippedDevShapeBounds = SkIRect::EmptyIRect();
robertphillips@google.com3e11c0b2012-07-11 18:20:35 +000081 return false;
robertphillips@google.comed4155d2012-05-01 14:30:24 +000082 }
bsalomon39ef7fb2016-09-21 11:16:05 -070083 if (!clippedDevShapeBounds->intersect(*devClipBounds, *unclippedDevShapeBounds)) {
84 *clippedDevShapeBounds = SkIRect::EmptyIRect();
robertphillips@google.comed4155d2012-05-01 14:30:24 +000085 return false;
86 }
87 return true;
88}
89
90////////////////////////////////////////////////////////////////////////////////
robertphillips976f5f02016-06-03 10:59:20 -070091
Brian Osman11052242016-10-27 14:47:55 -040092void GrSoftwarePathRenderer::DrawNonAARect(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 SkRect& rect,
98 const SkMatrix& localMatrix) {
Robert Phillips7c525e62018-06-12 10:11:12 -040099 GrContext* context = renderTargetContext->surfPriv().getContext();
Brian Salomonbaaf4392017-06-15 09:59:23 -0400100 renderTargetContext->addDrawOp(clip,
101 GrRectOpFactory::MakeNonAAFillWithLocalMatrix(
Robert Phillips7c525e62018-06-12 10:11:12 -0400102 context, std::move(paint), viewMatrix, localMatrix, rect,
Brian Salomonbaaf4392017-06-15 09:59:23 -0400103 GrAAType::kNone, &userStencilSettings));
robertphillips976f5f02016-06-03 10:59:20 -0700104}
105
Brian Osman11052242016-10-27 14:47:55 -0400106void GrSoftwarePathRenderer::DrawAroundInvPath(GrRenderTargetContext* renderTargetContext,
Brian Salomon82f44312017-01-11 13:42:54 -0500107 GrPaint&& paint,
robertphillipsd2b6d642016-07-21 08:55:08 -0700108 const GrUserStencilSettings& userStencilSettings,
robertphillips976f5f02016-06-03 10:59:20 -0700109 const GrClip& clip,
robertphillips976f5f02016-06-03 10:59:20 -0700110 const SkMatrix& viewMatrix,
111 const SkIRect& devClipBounds,
112 const SkIRect& devPathBounds) {
joshualittd27f73e2014-12-29 07:43:36 -0800113 SkMatrix invert;
joshualitt8059eb92014-12-29 15:10:07 -0800114 if (!viewMatrix.invert(&invert)) {
bsalomon@google.come3d32162012-07-20 13:37:06 +0000115 return;
116 }
joshualittd27f73e2014-12-29 07:43:36 -0800117
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000118 SkRect rect;
robertphillips@google.com7b112892012-07-31 15:18:21 +0000119 if (devClipBounds.fTop < devPathBounds.fTop) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000120 rect.iset(devClipBounds.fLeft, devClipBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000121 devClipBounds.fRight, devPathBounds.fTop);
Brian Salomonb74ef032017-08-10 12:46:01 -0400122 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
123 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000124 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000125 if (devClipBounds.fLeft < devPathBounds.fLeft) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000126 rect.iset(devClipBounds.fLeft, devPathBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000127 devPathBounds.fLeft, devPathBounds.fBottom);
Brian Salomonb74ef032017-08-10 12:46:01 -0400128 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
129 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000130 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000131 if (devClipBounds.fRight > devPathBounds.fRight) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000132 rect.iset(devPathBounds.fRight, devPathBounds.fTop,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000133 devClipBounds.fRight, devPathBounds.fBottom);
Brian Salomonb74ef032017-08-10 12:46:01 -0400134 DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip,
135 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000136 }
robertphillips@google.com7b112892012-07-31 15:18:21 +0000137 if (devClipBounds.fBottom > devPathBounds.fBottom) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000138 rect.iset(devClipBounds.fLeft, devPathBounds.fBottom,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000139 devClipBounds.fRight, devClipBounds.fBottom);
Brian Salomon82f44312017-01-11 13:42:54 -0500140 DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip,
robertphillips976f5f02016-06-03 10:59:20 -0700141 SkMatrix::I(), rect, invert);
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000142 }
143}
144
Brian Osmanc7da1462017-08-17 16:14:25 -0400145void GrSoftwarePathRenderer::DrawToTargetWithShapeMask(
146 sk_sp<GrTextureProxy> proxy,
147 GrRenderTargetContext* renderTargetContext,
148 GrPaint&& paint,
149 const GrUserStencilSettings& userStencilSettings,
150 const GrClip& clip,
151 const SkMatrix& viewMatrix,
152 const SkIPoint& textureOriginInDeviceSpace,
153 const SkIRect& deviceSpaceRectToDraw) {
154 SkMatrix invert;
155 if (!viewMatrix.invert(&invert)) {
156 return;
157 }
158
159 SkRect dstRect = SkRect::Make(deviceSpaceRectToDraw);
160
161 // We use device coords to compute the texture coordinates. We take the device coords and apply
162 // a translation so that the top-left of the device bounds maps to 0,0, and then a scaling
163 // matrix to normalized coords.
164 SkMatrix maskMatrix = SkMatrix::MakeTrans(SkIntToScalar(-textureOriginInDeviceSpace.fX),
165 SkIntToScalar(-textureOriginInDeviceSpace.fY));
166 maskMatrix.preConcat(viewMatrix);
167 paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(
Brian Osman2240be92017-10-18 13:15:13 -0400168 std::move(proxy), maskMatrix, GrSamplerState::Filter::kNearest));
Brian Osmanf9810662017-08-30 10:02:10 -0400169 DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip, SkMatrix::I(),
170 dstRect, invert);
171}
172
173static sk_sp<GrTextureProxy> make_deferred_mask_texture_proxy(GrContext* context, SkBackingFit fit,
174 int width, int height) {
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500175 GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
176
Brian Osmanf9810662017-08-30 10:02:10 -0400177 GrSurfaceDesc desc;
Brian Osmanf9810662017-08-30 10:02:10 -0400178 desc.fWidth = width;
179 desc.fHeight = height;
180 desc.fConfig = kAlpha_8_GrPixelConfig;
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500181
Brian Osmand140fe92017-10-03 12:17:26 -0400182 // MDB TODO: We're going to fill this proxy with an ASAP upload (which is out of order wrt to
183 // ops), so it can't have any pending IO.
Brian Salomon2a4f9832018-03-03 22:43:43 -0500184 return proxyProvider->createProxy(desc, kTopLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes,
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400185 GrInternalSurfaceFlags::kNoPendingIO);
Brian Osmanf9810662017-08-30 10:02:10 -0400186}
187
188namespace {
189
Brian Osman5d034742017-09-11 13:38:55 -0400190/**
Brian Osman099fa0f2017-10-02 16:38:32 -0400191 * Payload class for use with GrTDeferredProxyUploader. The software path renderer only draws
Brian Osman5d034742017-09-11 13:38:55 -0400192 * a single path into the mask texture. This stores all of the information needed by the worker
193 * thread's call to drawShape (see below, in onDrawPath).
194 */
195class SoftwarePathData {
Brian Osmanf9810662017-08-30 10:02:10 -0400196public:
Brian Osman5d034742017-09-11 13:38:55 -0400197 SoftwarePathData(const SkIRect& maskBounds, const SkMatrix& viewMatrix, const GrShape& shape,
198 GrAA aa)
199 : fMaskBounds(maskBounds)
Brian Osmanf9810662017-08-30 10:02:10 -0400200 , fViewMatrix(viewMatrix)
201 , fShape(shape)
Brian Osman5d034742017-09-11 13:38:55 -0400202 , fAA(aa) {}
Brian Osmanf9810662017-08-30 10:02:10 -0400203
Brian Osmanf9810662017-08-30 10:02:10 -0400204 const SkIRect& getMaskBounds() const { return fMaskBounds; }
205 const SkMatrix* getViewMatrix() const { return &fViewMatrix; }
206 const GrShape& getShape() const { return fShape; }
207 GrAA getAA() const { return fAA; }
208
209private:
Brian Osmanf9810662017-08-30 10:02:10 -0400210 SkIRect fMaskBounds;
211 SkMatrix fViewMatrix;
212 GrShape fShape;
213 GrAA fAA;
Brian Osmanf9810662017-08-30 10:02:10 -0400214};
215
Brian Osmane9242ca2017-09-26 14:05:19 -0400216// When the SkPathRef genID changes, invalidate a corresponding GrResource described by key.
217class PathInvalidator : public SkPathRef::GenIDChangeListener {
218public:
219 explicit PathInvalidator(const GrUniqueKey& key) : fMsg(key) {}
220private:
221 GrUniqueKeyInvalidatedMessage fMsg;
222
223 void onChange() override {
224 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg);
225 }
226};
227
Brian Osmanc7da1462017-08-17 16:14:25 -0400228}
229
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000230////////////////////////////////////////////////////////////////////////////////
231// return true on success; false on failure
bsalomon0aff2fa2015-07-31 06:48:27 -0700232bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -0400233 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -0700234 "GrSoftwarePathRenderer::onDrawPath");
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500235 if (!fProxyProvider) {
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000236 return false;
237 }
238
bsalomon8acedde2016-06-24 10:42:16 -0700239 // We really need to know if the shape will be inverse filled or not
240 bool inverseFilled = false;
241 SkTLazy<GrShape> tmpShape;
caryclarkd6562002016-07-27 12:02:07 -0700242 SkASSERT(!args.fShape->style().applies());
Eric Karl5c779752017-05-08 12:02:07 -0700243 // If the path is hairline, ignore inverse fill.
244 inverseFilled = args.fShape->inverseFilled() &&
245 !IsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr);
bsalomon8acedde2016-06-24 10:42:16 -0700246
bsalomon39ef7fb2016-09-21 11:16:05 -0700247 SkIRect unclippedDevShapeBounds, clippedDevShapeBounds, devClipBounds;
248 // To prevent overloading the cache with entries during animations we limit the cache of masks
249 // to cases where the matrix preserves axis alignment.
250 bool useCache = fAllowCaching && !inverseFilled && args.fViewMatrix->preservesAxisAlignment() &&
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500251 args.fShape->hasUnstyledKey() && GrAAType::kCoverage == args.fAAType;
bsalomon39ef7fb2016-09-21 11:16:05 -0700252
Brian Osman11052242016-10-27 14:47:55 -0400253 if (!get_shape_and_clip_bounds(args.fRenderTargetContext->width(),
254 args.fRenderTargetContext->height(),
bsalomon8acedde2016-06-24 10:42:16 -0700255 *args.fClip, *args.fShape,
bsalomon39ef7fb2016-09-21 11:16:05 -0700256 *args.fViewMatrix, &unclippedDevShapeBounds,
257 &clippedDevShapeBounds,
258 &devClipBounds)) {
bsalomon8acedde2016-06-24 10:42:16 -0700259 if (inverseFilled) {
Brian Salomon82f44312017-01-11 13:42:54 -0500260 DrawAroundInvPath(args.fRenderTargetContext, std::move(args.fPaint),
261 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
262 devClipBounds, unclippedDevShapeBounds);
bsalomon@google.com276c1fa2012-06-19 13:22:45 +0000263 }
264 return true;
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000265 }
robertphillips@google.com366f1c62012-06-29 21:38:47 +0000266
bsalomon39ef7fb2016-09-21 11:16:05 -0700267 const SkIRect* boundsForMask = &clippedDevShapeBounds;
268 if (useCache) {
269 // Use the cache only if >50% of the path is visible.
270 int unclippedWidth = unclippedDevShapeBounds.width();
271 int unclippedHeight = unclippedDevShapeBounds.height();
Brian Osman1a0ea732017-09-28 11:53:03 -0400272 int64_t unclippedArea = sk_64_mul(unclippedWidth, unclippedHeight);
273 int64_t clippedArea = sk_64_mul(clippedDevShapeBounds.width(),
274 clippedDevShapeBounds.height());
Brian Osman11052242016-10-27 14:47:55 -0400275 int maxTextureSize = args.fRenderTargetContext->caps()->maxTextureSize();
bsalomon39ef7fb2016-09-21 11:16:05 -0700276 if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize ||
277 unclippedHeight > maxTextureSize) {
278 useCache = false;
279 } else {
280 boundsForMask = &unclippedDevShapeBounds;
281 }
robertphillips@google.comed4155d2012-05-01 14:30:24 +0000282 }
283
bsalomon39ef7fb2016-09-21 11:16:05 -0700284 GrUniqueKey maskKey;
bsalomon39ef7fb2016-09-21 11:16:05 -0700285 if (useCache) {
286 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
287 SkScalar sx = args.fViewMatrix->get(SkMatrix::kMScaleX);
288 SkScalar sy = args.fViewMatrix->get(SkMatrix::kMScaleY);
289 SkScalar kx = args.fViewMatrix->get(SkMatrix::kMSkewX);
290 SkScalar ky = args.fViewMatrix->get(SkMatrix::kMSkewY);
Stan Iliev67cd6732017-08-15 17:10:26 -0400291 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
292#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
293 // Fractional translate does not affect caching on Android. This is done for better cache
294 // hit ratio and speed, but it is matching HWUI behavior, which doesn't consider the matrix
295 // at all when caching paths.
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -0400296 GrUniqueKey::Builder builder(&maskKey, kDomain, 4 + args.fShape->unstyledKeySize(),
297 "SW Path Mask");
Stan Iliev67cd6732017-08-15 17:10:26 -0400298#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700299 SkScalar tx = args.fViewMatrix->get(SkMatrix::kMTransX);
300 SkScalar ty = args.fViewMatrix->get(SkMatrix::kMTransY);
301 // Allow 8 bits each in x and y of subpixel positioning.
302 SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
303 SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -0400304 GrUniqueKey::Builder builder(&maskKey, kDomain, 5 + args.fShape->unstyledKeySize(),
305 "SW Path Mask");
Stan Iliev67cd6732017-08-15 17:10:26 -0400306#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700307 builder[0] = SkFloat2Bits(sx);
308 builder[1] = SkFloat2Bits(sy);
309 builder[2] = SkFloat2Bits(kx);
310 builder[3] = SkFloat2Bits(ky);
Stan Iliev67cd6732017-08-15 17:10:26 -0400311#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
312 args.fShape->writeUnstyledKey(&builder[4]);
313#else
bsalomon39ef7fb2016-09-21 11:16:05 -0700314 builder[4] = fracX | (fracY >> 8);
315 args.fShape->writeUnstyledKey(&builder[5]);
Stan Iliev67cd6732017-08-15 17:10:26 -0400316#endif
bsalomon39ef7fb2016-09-21 11:16:05 -0700317 }
318
Robert Phillipsd3749482017-03-14 09:17:43 -0400319 sk_sp<GrTextureProxy> proxy;
bsalomon39ef7fb2016-09-21 11:16:05 -0700320 if (useCache) {
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500321 proxy = fProxyProvider->findOrCreateProxyByUniqueKey(maskKey, kTopLeft_GrSurfaceOrigin);
bsalomon39ef7fb2016-09-21 11:16:05 -0700322 }
Robert Phillipsd3749482017-03-14 09:17:43 -0400323 if (!proxy) {
Robert Phillips417b7f42016-12-14 09:12:13 -0500324 SkBackingFit fit = useCache ? SkBackingFit::kExact : SkBackingFit::kApprox;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500325 GrAA aa = GrAAType::kCoverage == args.fAAType ? GrAA::kYes : GrAA::kNo;
Brian Osmanf9810662017-08-30 10:02:10 -0400326
327 SkTaskGroup* taskGroup = args.fContext->contextPriv().getTaskGroup();
328 if (taskGroup) {
329 proxy = make_deferred_mask_texture_proxy(args.fContext, fit,
330 boundsForMask->width(),
331 boundsForMask->height());
332 if (!proxy) {
333 return false;
334 }
335
Brian Osman099fa0f2017-10-02 16:38:32 -0400336 auto uploader = skstd::make_unique<GrTDeferredProxyUploader<SoftwarePathData>>(
337 *boundsForMask, *args.fViewMatrix, *args.fShape, aa);
338 GrTDeferredProxyUploader<SoftwarePathData>* uploaderRaw = uploader.get();
Brian Osmanf9810662017-08-30 10:02:10 -0400339
340 auto drawAndUploadMask = [uploaderRaw] {
341 TRACE_EVENT0("skia", "Threaded SW Mask Render");
342 GrSWMaskHelper helper(uploaderRaw->getPixels());
Brian Osman5d034742017-09-11 13:38:55 -0400343 if (helper.init(uploaderRaw->data().getMaskBounds())) {
344 helper.drawShape(uploaderRaw->data().getShape(),
345 *uploaderRaw->data().getViewMatrix(),
346 SkRegion::kReplace_Op, uploaderRaw->data().getAA(), 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400347 } else {
348 SkDEBUGFAIL("Unable to allocate SW mask.");
349 }
Brian Osman099fa0f2017-10-02 16:38:32 -0400350 uploaderRaw->signalAndFreeData();
Brian Osmanf9810662017-08-30 10:02:10 -0400351 };
352 taskGroup->add(std::move(drawAndUploadMask));
Brian Osman099fa0f2017-10-02 16:38:32 -0400353 proxy->texPriv().setDeferredUploader(std::move(uploader));
Brian Osmanf9810662017-08-30 10:02:10 -0400354 } else {
355 GrSWMaskHelper helper;
Brian Salomon74077562017-08-30 13:55:35 -0400356 if (!helper.init(*boundsForMask)) {
Brian Osmanf9810662017-08-30 10:02:10 -0400357 return false;
358 }
Brian Salomon74077562017-08-30 13:55:35 -0400359 helper.drawShape(*args.fShape, *args.fViewMatrix, SkRegion::kReplace_Op, aa, 0xFF);
Brian Osmanf9810662017-08-30 10:02:10 -0400360 proxy = helper.toTextureProxy(args.fContext, fit);
361 }
362
Robert Phillipsd3749482017-03-14 09:17:43 -0400363 if (!proxy) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500364 return false;
365 }
366 if (useCache) {
Robert Phillipse44ef102017-07-21 15:37:19 -0400367 SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500368 fProxyProvider->assignUniqueKeyToProxy(maskKey, proxy.get());
Chris Daltonafa11582018-06-08 12:00:44 -0600369 args.fShape->addGenIDChangeListener(sk_make_sp<PathInvalidator>(maskKey));
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500370 }
bsalomon39ef7fb2016-09-21 11:16:05 -0700371 }
bsalomon8acedde2016-06-24 10:42:16 -0700372 if (inverseFilled) {
Brian Salomonb74ef032017-08-10 12:46:01 -0400373 DrawAroundInvPath(args.fRenderTargetContext, GrPaint::Clone(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500374 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix, devClipBounds,
375 unclippedDevShapeBounds);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000376 }
Brian Osmanc7da1462017-08-17 16:14:25 -0400377 DrawToTargetWithShapeMask(
Robert Phillips296b1cc2017-03-15 10:42:12 -0400378 std::move(proxy), args.fRenderTargetContext, std::move(args.fPaint),
Brian Salomon82f44312017-01-11 13:42:54 -0500379 *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix,
380 SkIPoint{boundsForMask->fLeft, boundsForMask->fTop}, *boundsForMask);
robertphillips@google.com5dfb6722012-07-09 16:32:28 +0000381
382 return true;
robertphillips@google.comf4c2c522012-04-27 12:08:47 +0000383}