blob: c22d0f0e01511fda9baecd6a6cc00f62601ac9d0 [file] [log] [blame]
robertphillipsccb1b572015-05-27 11:02:55 -07001/*
2 * Copyright 2015 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrBlurUtils.h"
Robert Phillipsc7c2baf2018-03-08 09:51:04 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/private/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrCaps.h"
12#include "src/gpu/GrFixedClip.h"
13#include "src/gpu/GrProxyProvider.h"
14#include "src/gpu/GrRecordingContextPriv.h"
15#include "src/gpu/GrRenderTargetContext.h"
16#include "src/gpu/GrRenderTargetContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrSoftwarePathRenderer.h"
18#include "src/gpu/GrStyle.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040019#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/effects/generated/GrSimpleTextureEffect.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040021#include "src/gpu/geometry/GrShape.h"
Robert Phillipsc7c2baf2018-03-08 09:51:04 -050022
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "include/core/SkPaint.h"
24#include "src/core/SkDraw.h"
25#include "src/core/SkMaskFilterBase.h"
26#include "src/core/SkTLazy.h"
27#include "src/gpu/SkGr.h"
robertphillipsccb1b572015-05-27 11:02:55 -070028
29static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& rect) {
30 return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBounds, rect);
31}
32
33// Draw a mask using the supplied paint. Since the coverage/geometry
34// is already burnt into the mask this boils down to a rect draw.
35// Return true if the mask was successfully drawn.
Robert Phillips296b1cc2017-03-15 10:42:12 -040036static bool draw_mask(GrRenderTargetContext* renderTargetContext,
robertphillipsccb1b572015-05-27 11:02:55 -070037 const GrClip& clip,
38 const SkMatrix& viewMatrix,
robertphillipsf054b172016-05-13 05:06:19 -070039 const SkIRect& maskRect,
Brian Salomon82f44312017-01-11 13:42:54 -050040 GrPaint&& paint,
Robert Phillips4a24da52016-12-14 09:00:07 -050041 sk_sp<GrTextureProxy> mask) {
Brian Salomon82f44312017-01-11 13:42:54 -050042 SkMatrix inverse;
43 if (!viewMatrix.invert(&inverse)) {
44 return false;
45 }
Robert Phillips4a24da52016-12-14 09:00:07 -050046
Robert Phillips67c18d62017-01-20 12:44:06 -050047 SkMatrix matrix = SkMatrix::MakeTrans(-SkIntToScalar(maskRect.fLeft),
48 -SkIntToScalar(maskRect.fTop));
Brian Salomon2ebd0c82016-10-03 17:15:28 -040049 matrix.preConcat(viewMatrix);
Brian Osman2240be92017-10-18 13:15:13 -040050 paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(mask), matrix));
robertphillipsccb1b572015-05-27 11:02:55 -070051
Brian Salomon82f44312017-01-11 13:42:54 -050052 renderTargetContext->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(),
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050053 SkRect::Make(maskRect), inverse);
robertphillipsccb1b572015-05-27 11:02:55 -070054 return true;
55}
56
Robert Phillipsc7c2baf2018-03-08 09:51:04 -050057static void mask_release_proc(void* addr, void* /*context*/) {
58 SkMask::FreeImage(addr);
59}
60
Robert Phillips7af8fe52019-02-14 17:27:00 -050061static bool sw_draw_with_mask_filter(GrRecordingContext* context,
Robert Phillips4a24da52016-12-14 09:00:07 -050062 GrRenderTargetContext* renderTargetContext,
robertphillips0e7029e2015-11-30 05:45:06 -080063 const GrClip& clipData,
64 const SkMatrix& viewMatrix,
Robert Phillips27927a52018-08-20 13:18:12 -040065 const GrShape& shape,
robertphillips0e7029e2015-11-30 05:45:06 -080066 const SkMaskFilter* filter,
67 const SkIRect& clipBounds,
Robert Phillips31c080b2018-08-23 10:45:32 -040068 GrPaint&& paint,
69 const GrUniqueKey& key) {
Robert Phillips27927a52018-08-20 13:18:12 -040070 SkASSERT(filter);
71 SkASSERT(!shape.style().applies());
72
Robert Phillips9da87e02019-02-04 13:26:26 -050073 auto proxyProvider = context->priv().proxyProvider();
Robert Phillips27927a52018-08-20 13:18:12 -040074
Robert Phillips31c080b2018-08-23 10:45:32 -040075 sk_sp<GrTextureProxy> filteredMask;
Robert Phillips27927a52018-08-20 13:18:12 -040076
77 SkStrokeRec::InitStyle fillOrHairline = shape.style().isSimpleHairline()
78 ? SkStrokeRec::kHairline_InitStyle
79 : SkStrokeRec::kFill_InitStyle;
80
Robert Phillips31c080b2018-08-23 10:45:32 -040081 if (key.isValid()) {
82 // TODO: this cache look up is duplicated in draw_shape_with_mask_filter for gpu
Brian Salomon2af3e702019-08-11 19:10:31 -040083 filteredMask = proxyProvider->findOrCreateProxyByUniqueKey(key, GrColorType::kAlpha_8,
84 kTopLeft_GrSurfaceOrigin);
robertphillipsccb1b572015-05-27 11:02:55 -070085 }
86
Robert Phillips31c080b2018-08-23 10:45:32 -040087 SkIRect drawRect;
88 if (filteredMask) {
89 SkRect devBounds = shape.bounds();
90 viewMatrix.mapRect(&devBounds);
Robert Phillips4a24da52016-12-14 09:00:07 -050091
Robert Phillips31c080b2018-08-23 10:45:32 -040092 // Here we need to recompute the destination bounds in order to draw the mask correctly
93 SkMask srcM, dstM;
94 if (!SkDraw::ComputeMaskBounds(devBounds, &clipBounds, filter, &viewMatrix,
95 &srcM.fBounds)) {
96 return false;
97 }
98
99 srcM.fFormat = SkMask::kA8_Format;
100
101 if (!as_MFB(filter)->filterMask(&dstM, srcM, viewMatrix, nullptr)) {
102 return false;
103 }
104
105 // Unfortunately, we cannot double check that the computed bounds (i.e., dstM.fBounds)
106 // match the stored bounds of the mask bc the proxy may have been recreated and,
107 // when it is recreated, it just gets the bounds of the underlying GrTexture (which
108 // might be a loose fit).
109 drawRect = dstM.fBounds;
110 } else {
111 // TODO: it seems like we could create an SkDraw here and set its fMatrix field rather
112 // than explicitly transforming the path to device space.
113 SkPath devPath;
114
115 shape.asPath(&devPath);
116
117 devPath.transform(viewMatrix);
118
119 SkMask srcM, dstM;
120 if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM,
121 SkMask::kComputeBoundsAndRenderImage_CreateMode, fillOrHairline)) {
122 return false;
123 }
124 SkAutoMaskFreeImage autoSrc(srcM.fImage);
125
126 SkASSERT(SkMask::kA8_Format == srcM.fFormat);
127
128 if (!as_MFB(filter)->filterMask(&dstM, srcM, viewMatrix, nullptr)) {
129 return false;
130 }
131 // this will free-up dstM when we're done (allocated in filterMask())
132 SkAutoMaskFreeImage autoDst(dstM.fImage);
133
134 if (clip_bounds_quick_reject(clipBounds, dstM.fBounds)) {
135 return false;
136 }
137
138 // we now have a device-aligned 8bit mask in dstM, ready to be drawn using
139 // the current clip (and identity matrix) and GrPaint settings
140 SkBitmap bm;
141 if (!bm.installPixels(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.height()),
142 autoDst.release(), dstM.fRowBytes, mask_release_proc, nullptr)) {
143 return false;
144 }
145 bm.setImmutable();
146
147 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm);
148 if (!image) {
149 return false;
150 }
151
Brian Salomon96b383a2019-08-13 16:55:41 -0400152 filteredMask = proxyProvider->createTextureProxy(std::move(image), 1, SkBudgeted::kYes,
153 SkBackingFit::kApprox);
Robert Phillips31c080b2018-08-23 10:45:32 -0400154 if (!filteredMask) {
155 return false;
156 }
157
Robert Phillips59b39e72018-08-30 11:51:25 -0400158 SkASSERT(kTopLeft_GrSurfaceOrigin == filteredMask->origin());
159
Robert Phillips31c080b2018-08-23 10:45:32 -0400160 drawRect = dstM.fBounds;
161
162 if (key.isValid()) {
163 proxyProvider->assignUniqueKeyToProxy(key, filteredMask.get());
164 }
Robert Phillips48ce22b2018-03-23 10:33:12 -0400165 }
Robert Phillipsc7c2baf2018-03-08 09:51:04 -0500166
Robert Phillips31c080b2018-08-23 10:45:32 -0400167 return draw_mask(renderTargetContext, clipData, viewMatrix, drawRect,
168 std::move(paint), std::move(filteredMask));
robertphillipsccb1b572015-05-27 11:02:55 -0700169}
170
Robert Phillips27927a52018-08-20 13:18:12 -0400171// Create a mask of 'shape' and place the result in 'mask'.
Robert Phillips7af8fe52019-02-14 17:27:00 -0500172static sk_sp<GrTextureProxy> create_mask_GPU(GrRecordingContext* context,
robertphillipsd728f0c2016-11-21 11:05:03 -0800173 const SkIRect& maskRect,
Robert Phillips27927a52018-08-20 13:18:12 -0400174 const SkMatrix& origViewMatrix,
175 const GrShape& shape,
robertphillipsd728f0c2016-11-21 11:05:03 -0800176 int sampleCnt) {
Chris Dalton0493fbd2019-09-18 15:49:46 -0600177 // Use GrResourceProvider::MakeApprox to implement our own approximate size matching, but demand
178 // a "SkBackingFit::kExact" size match on the actual render target. We do this because the
179 // filter will reach outside the src bounds, so we need to pre-clear these values to ensure a
180 // "decal" sampling effect (i.e., ensure reads outside the src bounds return alpha=0).
181 //
182 // FIXME: Reads outside the left and top edges will actually clamp to the edge pixel. And in the
183 // event that MakeApprox does not change the size, reads outside the right and/or bottom will do
184 // the same. We should offset our filter within the render target and expand the size as needed
185 // to guarantee at least 1px of padding on all sides.
Brian Salomonbf6b9792019-08-21 09:38:10 -0400186 auto rtContext = context->priv().makeDeferredRenderTargetContextWithFallback(
Chris Dalton0493fbd2019-09-18 15:49:46 -0600187 SkBackingFit::kExact, GrResourceProvider::MakeApprox(maskRect.width()),
188 GrResourceProvider::MakeApprox(maskRect.height()), GrColorType::kAlpha_8, nullptr,
189 sampleCnt, GrMipMapped::kNo, kTopLeft_GrSurfaceOrigin);
robertphillipsd728f0c2016-11-21 11:05:03 -0800190 if (!rtContext) {
halcanary96fcdcc2015-08-27 07:41:13 -0700191 return nullptr;
robertphillipsccb1b572015-05-27 11:02:55 -0700192 }
193
Chris Dalton0493fbd2019-09-18 15:49:46 -0600194 rtContext->clear(SK_PMColor4fTRANSPARENT);
robertphillipsccb1b572015-05-27 11:02:55 -0700195
Brian Salomon82f44312017-01-11 13:42:54 -0500196 GrPaint maskPaint;
197 maskPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
robertphillipsccb1b572015-05-27 11:02:55 -0700198
199 // setup new clip
cdalton846c0512016-05-13 10:25:00 -0700200 const SkIRect clipRect = SkIRect::MakeWH(maskRect.width(), maskRect.height());
201 GrFixedClip clip(clipRect);
robertphillipsccb1b572015-05-27 11:02:55 -0700202
robertphillips3833daa2015-09-14 11:18:13 -0700203 // Draw the mask into maskTexture with the path's integerized top-left at
Brian Salomon82f44312017-01-11 13:42:54 -0500204 // the origin using maskPaint.
Robert Phillips27927a52018-08-20 13:18:12 -0400205 SkMatrix viewMatrix = origViewMatrix;
206 viewMatrix.postTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop));
Robert Phillips793324c2018-08-24 13:53:56 -0400207 rtContext->drawShape(clip, std::move(maskPaint), GrAA::kYes, viewMatrix, shape);
Robert Phillipsf200a902017-01-30 13:27:37 -0500208 return rtContext->asTextureProxyRef();
robertphillipsccb1b572015-05-27 11:02:55 -0700209}
210
Robert Phillips27927a52018-08-20 13:18:12 -0400211static bool get_unclipped_shape_dev_bounds(const GrShape& shape, const SkMatrix& matrix,
212 SkIRect* devBounds) {
213 SkRect shapeBounds = shape.styledBounds();
214 if (shapeBounds.isEmpty()) {
215 return false;
216 }
217 SkRect shapeDevBounds;
218 matrix.mapRect(&shapeDevBounds, shapeBounds);
219 // Even though these are "unclipped" bounds we still clip to the int32_t range.
220 // This is the largest int32_t that is representable exactly as a float. The next 63 larger ints
221 // would round down to this value when cast to a float, but who really cares.
222 // INT32_MIN is exactly representable.
223 static constexpr int32_t kMaxInt = 2147483520;
224 if (!shapeDevBounds.intersect(SkRect::MakeLTRB(INT32_MIN, INT32_MIN, kMaxInt, kMaxInt))) {
225 return false;
226 }
227 // Make sure that the resulting SkIRect can have representable width and height
228 if (SkScalarRoundToInt(shapeDevBounds.width()) > kMaxInt ||
229 SkScalarRoundToInt(shapeDevBounds.height()) > kMaxInt) {
230 return false;
231 }
232 shapeDevBounds.roundOut(devBounds);
233 return true;
234}
bsalomonc55271f2015-11-09 11:55:57 -0800235
Robert Phillips27927a52018-08-20 13:18:12 -0400236// Gets the shape bounds, the clip bounds, and the intersection (if any). Returns false if there
237// is no intersection.
238static bool get_shape_and_clip_bounds(GrRenderTargetContext* renderTargetContext,
239 const GrClip& clip,
240 const GrShape& shape,
241 const SkMatrix& matrix,
242 SkIRect* unclippedDevShapeBounds,
243 SkIRect* devClipBounds) {
244 // compute bounds as intersection of rt size, clip, and path
Robert Phillips784b7bf2016-12-09 13:35:02 -0500245 clip.getConservativeBounds(renderTargetContext->width(),
246 renderTargetContext->height(),
Robert Phillips27927a52018-08-20 13:18:12 -0400247 devClipBounds);
bsalomonc55271f2015-11-09 11:55:57 -0800248
Robert Phillips27927a52018-08-20 13:18:12 -0400249 if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) {
250 *unclippedDevShapeBounds = SkIRect::EmptyIRect();
251 return false;
bsalomonc55271f2015-11-09 11:55:57 -0800252 }
253
Robert Phillips27927a52018-08-20 13:18:12 -0400254 return true;
255}
256
Robert Phillips7af8fe52019-02-14 17:27:00 -0500257static void draw_shape_with_mask_filter(GrRecordingContext* context,
Robert Phillips27927a52018-08-20 13:18:12 -0400258 GrRenderTargetContext* renderTargetContext,
259 const GrClip& clip,
260 GrPaint&& paint,
Robert Phillips27927a52018-08-20 13:18:12 -0400261 const SkMatrix& viewMatrix,
262 const SkMaskFilterBase* maskFilter,
263 const GrShape& origShape) {
264 SkASSERT(maskFilter);
265
266 const GrShape* shape = &origShape;
267 SkTLazy<GrShape> tmpShape;
268
269 if (origShape.style().applies()) {
270 SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix);
271 if (0 == styleScale) {
272 return;
bsalomon6663acf2016-05-10 09:14:17 -0700273 }
Robert Phillips27927a52018-08-20 13:18:12 -0400274
275 tmpShape.init(origShape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale));
276 if (tmpShape.get()->isEmpty()) {
277 return;
278 }
279
280 shape = tmpShape.get();
bsalomon6663acf2016-05-10 09:14:17 -0700281 }
bsalomonc55271f2015-11-09 11:55:57 -0800282
Robert Phillipsb889f202018-08-17 19:55:59 +0000283 if (maskFilter->directFilterMaskGPU(context,
284 renderTargetContext,
285 std::move(paint),
286 clip,
287 viewMatrix,
Robert Phillips27927a52018-08-20 13:18:12 -0400288 *shape)) {
Robert Phillipsb889f202018-08-17 19:55:59 +0000289 // the mask filter was able to draw itself directly, so there's nothing
290 // left to do.
291 return;
292 }
Mike Klein16885072018-12-11 09:54:31 -0500293 assert_alive(paint);
Robert Phillipsb889f202018-08-17 19:55:59 +0000294
Robert Phillips27927a52018-08-20 13:18:12 -0400295 // If the path is hairline, ignore inverse fill.
296 bool inverseFilled = shape->inverseFilled() &&
297 !GrPathRenderer::IsStrokeHairlineOrEquivalent(shape->style(),
298 viewMatrix, nullptr);
299
300 SkIRect unclippedDevShapeBounds, devClipBounds;
Robert Phillips31c080b2018-08-23 10:45:32 -0400301 if (!get_shape_and_clip_bounds(renderTargetContext, clip, *shape, viewMatrix,
Robert Phillips27927a52018-08-20 13:18:12 -0400302 &unclippedDevShapeBounds,
303 &devClipBounds)) {
304 // TODO: just cons up an opaque mask here
305 if (!inverseFilled) {
306 return;
307 }
308 }
309
Robert Phillips31c080b2018-08-23 10:45:32 -0400310 // To prevent overloading the cache with entries during animations we limit the cache of masks
311 // to cases where the matrix preserves axis alignment.
Robert Phillipsde479282018-08-28 11:20:08 -0400312#ifdef SK_DISABLE_MASKFILTERED_MASK_CACHING
313 bool useCache = false;
314#else
Robert Phillips31c080b2018-08-23 10:45:32 -0400315 bool useCache = !inverseFilled && viewMatrix.preservesAxisAlignment() &&
316 shape->hasUnstyledKey() && as_MFB(maskFilter)->asABlur(nullptr);
Robert Phillipsde479282018-08-28 11:20:08 -0400317#endif
Robert Phillips31c080b2018-08-23 10:45:32 -0400318
319 const SkIRect* boundsForClip = &devClipBounds;
320 if (useCache) {
321 SkIRect clippedMaskRect, unClippedMaskRect;
322 maskFilter->canFilterMaskGPU(*shape, unclippedDevShapeBounds, devClipBounds,
323 viewMatrix, &clippedMaskRect);
324 maskFilter->canFilterMaskGPU(*shape, unclippedDevShapeBounds, unclippedDevShapeBounds,
325 viewMatrix, &unClippedMaskRect);
326 if (clippedMaskRect.isEmpty()) {
327 return;
328 }
329
330 // Use the cache only if >50% of the filtered mask is visible.
331 int unclippedWidth = unClippedMaskRect.width();
332 int unclippedHeight = unClippedMaskRect.height();
333 int64_t unclippedArea = sk_64_mul(unclippedWidth, unclippedHeight);
334 int64_t clippedArea = sk_64_mul(clippedMaskRect.width(), clippedMaskRect.height());
335 int maxTextureSize = renderTargetContext->caps()->maxTextureSize();
336 if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize ||
337 unclippedHeight > maxTextureSize) {
338 useCache = false;
339 } else {
340 // Make the clip not affect the mask
341 boundsForClip = &unclippedDevShapeBounds;
342 }
343 }
344
345 GrUniqueKey maskKey;
346 if (useCache) {
347 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
348 GrUniqueKey::Builder builder(&maskKey, kDomain, 5 + 2 + shape->unstyledKeySize(),
349 "Mask Filtered Masks");
350
351 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
352 SkScalar sx = viewMatrix.get(SkMatrix::kMScaleX);
353 SkScalar sy = viewMatrix.get(SkMatrix::kMScaleY);
354 SkScalar kx = viewMatrix.get(SkMatrix::kMSkewX);
355 SkScalar ky = viewMatrix.get(SkMatrix::kMSkewY);
356 SkScalar tx = viewMatrix.get(SkMatrix::kMTransX);
357 SkScalar ty = viewMatrix.get(SkMatrix::kMTransY);
358 // Allow 8 bits each in x and y of subpixel positioning.
359 SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
360 SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
361
362 builder[0] = SkFloat2Bits(sx);
363 builder[1] = SkFloat2Bits(sy);
364 builder[2] = SkFloat2Bits(kx);
365 builder[3] = SkFloat2Bits(ky);
366 // Distinguish between hairline and filled paths. For hairlines, we also need to include
367 // the cap. (SW grows hairlines by 0.5 pixel with round and square caps). Note that
368 // stroke-and-fill of hairlines is turned into pure fill by SkStrokeRec, so this covers
369 // all cases we might see.
370 uint32_t styleBits = shape->style().isSimpleHairline()
371 ? ((shape->style().strokeRec().getCap() << 1) | 1)
372 : 0;
373 builder[4] = fracX | (fracY >> 8) | (styleBits << 16);
374
375 SkMaskFilterBase::BlurRec rec;
376 SkAssertResult(as_MFB(maskFilter)->asABlur(&rec));
377
378 builder[5] = rec.fStyle; // TODO: we could put this with the other style bits
Robert Phillips55ff5d32019-01-07 16:11:36 -0500379 builder[6] = SkFloat2Bits(rec.fSigma);
Robert Phillips31c080b2018-08-23 10:45:32 -0400380 shape->writeUnstyledKey(&builder[7]);
381 }
382
383 SkIRect maskRect;
Robert Phillips27927a52018-08-20 13:18:12 -0400384 if (maskFilter->canFilterMaskGPU(*shape,
Robert Phillips31c080b2018-08-23 10:45:32 -0400385 unclippedDevShapeBounds,
386 *boundsForClip,
bsalomonc55271f2015-11-09 11:55:57 -0800387 viewMatrix,
388 &maskRect)) {
Robert Phillips31c080b2018-08-23 10:45:32 -0400389 if (clip_bounds_quick_reject(*boundsForClip, maskRect)) {
bsalomonc55271f2015-11-09 11:55:57 -0800390 // clipped out
391 return;
392 }
393
Robert Phillips20390c32018-08-17 11:01:03 -0400394 sk_sp<GrTextureProxy> filteredMask;
395
Robert Phillips9da87e02019-02-04 13:26:26 -0500396 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
Robert Phillips31c080b2018-08-23 10:45:32 -0400397
398 if (maskKey.isValid()) {
399 // TODO: this cache look up is duplicated in sw_draw_with_mask_filter for raster
400 filteredMask = proxyProvider->findOrCreateProxyByUniqueKey(
Brian Salomon2af3e702019-08-11 19:10:31 -0400401 maskKey, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin);
Robert Phillips31c080b2018-08-23 10:45:32 -0400402 }
403
Robert Phillips20390c32018-08-17 11:01:03 -0400404 if (!filteredMask) {
405 sk_sp<GrTextureProxy> maskProxy(create_mask_GPU(
406 context,
Robert Phillips31c080b2018-08-23 10:45:32 -0400407 maskRect,
Robert Phillips27927a52018-08-20 13:18:12 -0400408 viewMatrix,
409 *shape,
Chris Dalton6ce447a2019-06-23 18:07:38 -0600410 renderTargetContext->numSamples()));
Robert Phillips20390c32018-08-17 11:01:03 -0400411 if (maskProxy) {
412 filteredMask = maskFilter->filterMaskGPU(context,
413 std::move(maskProxy),
414 viewMatrix,
Robert Phillips31c080b2018-08-23 10:45:32 -0400415 maskRect);
Robert Phillips59b39e72018-08-30 11:51:25 -0400416 SkASSERT(kTopLeft_GrSurfaceOrigin == filteredMask->origin());
417
Robert Phillips31c080b2018-08-23 10:45:32 -0400418 if (filteredMask && maskKey.isValid()) {
419 proxyProvider->assignUniqueKeyToProxy(maskKey, filteredMask.get());
420 }
bsalomonc55271f2015-11-09 11:55:57 -0800421 }
422 }
Robert Phillips20390c32018-08-17 11:01:03 -0400423
424 if (filteredMask) {
425 if (draw_mask(renderTargetContext, clip, viewMatrix,
Robert Phillips31c080b2018-08-23 10:45:32 -0400426 maskRect, std::move(paint), std::move(filteredMask))) {
Robert Phillips20390c32018-08-17 11:01:03 -0400427 // This path is completely drawn
428 return;
429 }
Mike Klein16885072018-12-11 09:54:31 -0500430 assert_alive(paint);
Robert Phillips20390c32018-08-17 11:01:03 -0400431 }
bsalomonc55271f2015-11-09 11:55:57 -0800432 }
433
Robert Phillips27927a52018-08-20 13:18:12 -0400434 sw_draw_with_mask_filter(context, renderTargetContext, clip, viewMatrix, *shape,
Robert Phillips31c080b2018-08-23 10:45:32 -0400435 maskFilter, *boundsForClip, std::move(paint), maskKey);
bsalomon6663acf2016-05-10 09:14:17 -0700436}
437
Robert Phillips7af8fe52019-02-14 17:27:00 -0500438void GrBlurUtils::drawShapeWithMaskFilter(GrRecordingContext* context,
Robert Phillips27927a52018-08-20 13:18:12 -0400439 GrRenderTargetContext* renderTargetContext,
440 const GrClip& clip,
441 const GrShape& shape,
442 GrPaint&& paint,
Robert Phillips27927a52018-08-20 13:18:12 -0400443 const SkMatrix& viewMatrix,
444 const SkMaskFilter* mf) {
Robert Phillips793324c2018-08-24 13:53:56 -0400445 draw_shape_with_mask_filter(context, renderTargetContext, clip, std::move(paint),
Robert Phillips27927a52018-08-20 13:18:12 -0400446 viewMatrix, as_MFB(mf), shape);
bsalomonc55271f2015-11-09 11:55:57 -0800447}
448
Robert Phillips69893702019-02-22 11:16:30 -0500449void GrBlurUtils::drawShapeWithMaskFilter(GrRecordingContext* context,
Robert Phillips27927a52018-08-20 13:18:12 -0400450 GrRenderTargetContext* renderTargetContext,
451 const GrClip& clip,
452 const SkPaint& paint,
453 const SkMatrix& viewMatrix,
454 const GrShape& shape) {
Robert Phillips6a6de562019-02-15 15:19:15 -0500455 if (context->priv().abandoned()) {
Robert Phillipsbebfd412018-03-08 11:07:23 -0500456 return;
457 }
458
robertphillipsccb1b572015-05-27 11:02:55 -0700459 GrPaint grPaint;
Brian Salomonf3569f02017-10-24 12:52:33 -0400460 if (!SkPaintToGrPaint(context, renderTargetContext->colorSpaceInfo(), paint, viewMatrix,
461 &grPaint)) {
robertphillipsccb1b572015-05-27 11:02:55 -0700462 return;
463 }
Robert Phillips27927a52018-08-20 13:18:12 -0400464
Mike Reed80747ef2018-01-23 15:29:32 -0500465 SkMaskFilterBase* mf = as_MFB(paint.getMaskFilter());
Mike Reedbfadcf02018-01-20 22:24:21 +0000466 if (mf && !mf->hasFragmentProcessor()) {
Robert Phillipsa29a9562016-10-20 09:40:55 -0400467 // The MaskFilter wasn't already handled in SkPaintToGrPaint
Robert Phillips793324c2018-08-24 13:53:56 -0400468 draw_shape_with_mask_filter(context, renderTargetContext, clip, std::move(grPaint),
Robert Phillips27927a52018-08-20 13:18:12 -0400469 viewMatrix, mf, shape);
bsalomonc55271f2015-11-09 11:55:57 -0800470 } else {
Robert Phillips793324c2018-08-24 13:53:56 -0400471 GrAA aa = GrAA(paint.isAntiAlias());
Robert Phillips27927a52018-08-20 13:18:12 -0400472 renderTargetContext->drawShape(clip, std::move(grPaint), aa, viewMatrix, shape);
robertphillipsccb1b572015-05-27 11:02:55 -0700473 }
robertphillipsccb1b572015-05-27 11:02:55 -0700474}