blob: 331e4156f39ad4f0e6bf72cd8851a88b55f7e742 [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
8#include "GrBlurUtils.h"
Robert Phillipsc7c2baf2018-03-08 09:51:04 -05009
bsalomon76228632015-05-29 08:02:10 -070010#include "GrCaps.h"
robertphillipsccb1b572015-05-27 11:02:55 -070011#include "GrContext.h"
Robert Phillipsc949ce92017-01-19 16:59:04 -050012#include "GrContextPriv.h"
csmartdalton02fa32c2016-08-19 13:29:27 -070013#include "GrFixedClip.h"
Robert Phillipsc7c2baf2018-03-08 09:51:04 -050014#include "GrProxyProvider.h"
15#include "GrRenderTargetContext.h"
Robert Phillips784b7bf2016-12-09 13:35:02 -050016#include "GrRenderTargetContextPriv.h"
Robert Phillips27927a52018-08-20 13:18:12 -040017#include "GrShape.h"
18#include "GrSoftwarePathRenderer.h"
bsalomon6663acf2016-05-10 09:14:17 -070019#include "GrStyle.h"
robertphillipsd728f0c2016-11-21 11:05:03 -080020#include "GrTextureProxy.h"
Robert Phillipsc7c2baf2018-03-08 09:51:04 -050021#include "effects/GrSimpleTextureEffect.h"
22
robertphillipsccb1b572015-05-27 11:02:55 -070023#include "SkDraw.h"
Brian Osman3b655982017-03-07 16:58:08 -050024#include "SkGr.h"
Mike Reed80747ef2018-01-23 15:29:32 -050025#include "SkMaskFilterBase.h"
robertphillipsccb1b572015-05-27 11:02:55 -070026#include "SkPaint.h"
csmartdaltonc6f411e2016-08-05 22:32:12 -070027#include "SkTLazy.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 Phillips4a24da52016-12-14 09:00:07 -050061static bool sw_draw_with_mask_filter(GrContext* context,
62 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
73 auto proxyProvider = context->contextPriv().proxyProvider();
74
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
83 filteredMask = proxyProvider->findOrCreateProxyByUniqueKey(key, kTopLeft_GrSurfaceOrigin);
robertphillipsccb1b572015-05-27 11:02:55 -070084 }
85
Robert Phillips31c080b2018-08-23 10:45:32 -040086 SkIRect drawRect;
87 if (filteredMask) {
88 SkRect devBounds = shape.bounds();
89 viewMatrix.mapRect(&devBounds);
Robert Phillips4a24da52016-12-14 09:00:07 -050090
Robert Phillips31c080b2018-08-23 10:45:32 -040091 // Here we need to recompute the destination bounds in order to draw the mask correctly
92 SkMask srcM, dstM;
93 if (!SkDraw::ComputeMaskBounds(devBounds, &clipBounds, filter, &viewMatrix,
94 &srcM.fBounds)) {
95 return false;
96 }
97
98 srcM.fFormat = SkMask::kA8_Format;
99
100 if (!as_MFB(filter)->filterMask(&dstM, srcM, viewMatrix, nullptr)) {
101 return false;
102 }
103
104 // Unfortunately, we cannot double check that the computed bounds (i.e., dstM.fBounds)
105 // match the stored bounds of the mask bc the proxy may have been recreated and,
106 // when it is recreated, it just gets the bounds of the underlying GrTexture (which
107 // might be a loose fit).
108 drawRect = dstM.fBounds;
109 } else {
110 // TODO: it seems like we could create an SkDraw here and set its fMatrix field rather
111 // than explicitly transforming the path to device space.
112 SkPath devPath;
113
114 shape.asPath(&devPath);
115
116 devPath.transform(viewMatrix);
117
118 SkMask srcM, dstM;
119 if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM,
120 SkMask::kComputeBoundsAndRenderImage_CreateMode, fillOrHairline)) {
121 return false;
122 }
123 SkAutoMaskFreeImage autoSrc(srcM.fImage);
124
125 SkASSERT(SkMask::kA8_Format == srcM.fFormat);
126
127 if (!as_MFB(filter)->filterMask(&dstM, srcM, viewMatrix, nullptr)) {
128 return false;
129 }
130 // this will free-up dstM when we're done (allocated in filterMask())
131 SkAutoMaskFreeImage autoDst(dstM.fImage);
132
133 if (clip_bounds_quick_reject(clipBounds, dstM.fBounds)) {
134 return false;
135 }
136
137 // we now have a device-aligned 8bit mask in dstM, ready to be drawn using
138 // the current clip (and identity matrix) and GrPaint settings
139 SkBitmap bm;
140 if (!bm.installPixels(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.height()),
141 autoDst.release(), dstM.fRowBytes, mask_release_proc, nullptr)) {
142 return false;
143 }
144 bm.setImmutable();
145
146 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm);
147 if (!image) {
148 return false;
149 }
150
151 filteredMask = proxyProvider->createTextureProxy(std::move(image),
152 kNone_GrSurfaceFlags,
153 1, SkBudgeted::kYes,
154 SkBackingFit::kApprox);
155 if (!filteredMask) {
156 return false;
157 }
158
Robert Phillips59b39e72018-08-30 11:51:25 -0400159 SkASSERT(kTopLeft_GrSurfaceOrigin == filteredMask->origin());
160
Robert Phillips31c080b2018-08-23 10:45:32 -0400161 drawRect = dstM.fBounds;
162
163 if (key.isValid()) {
164 proxyProvider->assignUniqueKeyToProxy(key, filteredMask.get());
165 }
Robert Phillips48ce22b2018-03-23 10:33:12 -0400166 }
Robert Phillipsc7c2baf2018-03-08 09:51:04 -0500167
Robert Phillips31c080b2018-08-23 10:45:32 -0400168 return draw_mask(renderTargetContext, clipData, viewMatrix, drawRect,
169 std::move(paint), std::move(filteredMask));
robertphillipsccb1b572015-05-27 11:02:55 -0700170}
171
Robert Phillips27927a52018-08-20 13:18:12 -0400172// Create a mask of 'shape' and place the result in 'mask'.
robertphillipsd728f0c2016-11-21 11:05:03 -0800173static sk_sp<GrTextureProxy> create_mask_GPU(GrContext* context,
174 const SkIRect& maskRect,
Robert Phillips27927a52018-08-20 13:18:12 -0400175 const SkMatrix& origViewMatrix,
176 const GrShape& shape,
robertphillipsd728f0c2016-11-21 11:05:03 -0800177 int sampleCnt) {
Greg Daniel4065d452018-11-16 15:43:41 -0500178 GrBackendFormat format =
179 context->contextPriv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500180 sk_sp<GrRenderTargetContext> rtContext(
181 context->contextPriv().makeDeferredRenderTargetContextWithFallback(
Greg Daniel4065d452018-11-16 15:43:41 -0500182 format, SkBackingFit::kApprox, maskRect.width(), maskRect.height(),
183 kAlpha_8_GrPixelConfig, nullptr, sampleCnt, GrMipMapped::kNo,
184 kTopLeft_GrSurfaceOrigin));
robertphillipsd728f0c2016-11-21 11:05:03 -0800185 if (!rtContext) {
halcanary96fcdcc2015-08-27 07:41:13 -0700186 return nullptr;
robertphillipsccb1b572015-05-27 11:02:55 -0700187 }
188
Brian Osman9a9baae2018-11-05 15:06:26 -0500189 rtContext->priv().absClear(nullptr, SK_PMColor4fTRANSPARENT);
robertphillipsccb1b572015-05-27 11:02:55 -0700190
Brian Salomon82f44312017-01-11 13:42:54 -0500191 GrPaint maskPaint;
192 maskPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
robertphillipsccb1b572015-05-27 11:02:55 -0700193
194 // setup new clip
cdalton846c0512016-05-13 10:25:00 -0700195 const SkIRect clipRect = SkIRect::MakeWH(maskRect.width(), maskRect.height());
196 GrFixedClip clip(clipRect);
robertphillipsccb1b572015-05-27 11:02:55 -0700197
robertphillips3833daa2015-09-14 11:18:13 -0700198 // Draw the mask into maskTexture with the path's integerized top-left at
Brian Salomon82f44312017-01-11 13:42:54 -0500199 // the origin using maskPaint.
Robert Phillips27927a52018-08-20 13:18:12 -0400200 SkMatrix viewMatrix = origViewMatrix;
201 viewMatrix.postTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop));
Robert Phillips793324c2018-08-24 13:53:56 -0400202 rtContext->drawShape(clip, std::move(maskPaint), GrAA::kYes, viewMatrix, shape);
Robert Phillipsf200a902017-01-30 13:27:37 -0500203 return rtContext->asTextureProxyRef();
robertphillipsccb1b572015-05-27 11:02:55 -0700204}
205
Robert Phillips27927a52018-08-20 13:18:12 -0400206static bool get_unclipped_shape_dev_bounds(const GrShape& shape, const SkMatrix& matrix,
207 SkIRect* devBounds) {
208 SkRect shapeBounds = shape.styledBounds();
209 if (shapeBounds.isEmpty()) {
210 return false;
211 }
212 SkRect shapeDevBounds;
213 matrix.mapRect(&shapeDevBounds, shapeBounds);
214 // Even though these are "unclipped" bounds we still clip to the int32_t range.
215 // This is the largest int32_t that is representable exactly as a float. The next 63 larger ints
216 // would round down to this value when cast to a float, but who really cares.
217 // INT32_MIN is exactly representable.
218 static constexpr int32_t kMaxInt = 2147483520;
219 if (!shapeDevBounds.intersect(SkRect::MakeLTRB(INT32_MIN, INT32_MIN, kMaxInt, kMaxInt))) {
220 return false;
221 }
222 // Make sure that the resulting SkIRect can have representable width and height
223 if (SkScalarRoundToInt(shapeDevBounds.width()) > kMaxInt ||
224 SkScalarRoundToInt(shapeDevBounds.height()) > kMaxInt) {
225 return false;
226 }
227 shapeDevBounds.roundOut(devBounds);
228 return true;
229}
bsalomonc55271f2015-11-09 11:55:57 -0800230
Robert Phillips27927a52018-08-20 13:18:12 -0400231// Gets the shape bounds, the clip bounds, and the intersection (if any). Returns false if there
232// is no intersection.
233static bool get_shape_and_clip_bounds(GrRenderTargetContext* renderTargetContext,
234 const GrClip& clip,
235 const GrShape& shape,
236 const SkMatrix& matrix,
237 SkIRect* unclippedDevShapeBounds,
238 SkIRect* devClipBounds) {
239 // compute bounds as intersection of rt size, clip, and path
Robert Phillips784b7bf2016-12-09 13:35:02 -0500240 clip.getConservativeBounds(renderTargetContext->width(),
241 renderTargetContext->height(),
Robert Phillips27927a52018-08-20 13:18:12 -0400242 devClipBounds);
bsalomonc55271f2015-11-09 11:55:57 -0800243
Robert Phillips27927a52018-08-20 13:18:12 -0400244 if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) {
245 *unclippedDevShapeBounds = SkIRect::EmptyIRect();
246 return false;
bsalomonc55271f2015-11-09 11:55:57 -0800247 }
248
Robert Phillips27927a52018-08-20 13:18:12 -0400249 return true;
250}
251
252static void draw_shape_with_mask_filter(GrContext* context,
253 GrRenderTargetContext* renderTargetContext,
254 const GrClip& clip,
255 GrPaint&& paint,
Robert Phillips27927a52018-08-20 13:18:12 -0400256 const SkMatrix& viewMatrix,
257 const SkMaskFilterBase* maskFilter,
258 const GrShape& origShape) {
259 SkASSERT(maskFilter);
260
261 const GrShape* shape = &origShape;
262 SkTLazy<GrShape> tmpShape;
263
264 if (origShape.style().applies()) {
265 SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix);
266 if (0 == styleScale) {
267 return;
bsalomon6663acf2016-05-10 09:14:17 -0700268 }
Robert Phillips27927a52018-08-20 13:18:12 -0400269
270 tmpShape.init(origShape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale));
271 if (tmpShape.get()->isEmpty()) {
272 return;
273 }
274
275 shape = tmpShape.get();
bsalomon6663acf2016-05-10 09:14:17 -0700276 }
bsalomonc55271f2015-11-09 11:55:57 -0800277
Robert Phillipsb889f202018-08-17 19:55:59 +0000278 if (maskFilter->directFilterMaskGPU(context,
279 renderTargetContext,
280 std::move(paint),
281 clip,
282 viewMatrix,
Robert Phillips27927a52018-08-20 13:18:12 -0400283 *shape)) {
Robert Phillipsb889f202018-08-17 19:55:59 +0000284 // the mask filter was able to draw itself directly, so there's nothing
285 // left to do.
286 return;
287 }
Mike Klein16885072018-12-11 09:54:31 -0500288 assert_alive(paint);
Robert Phillipsb889f202018-08-17 19:55:59 +0000289
Robert Phillips27927a52018-08-20 13:18:12 -0400290 // If the path is hairline, ignore inverse fill.
291 bool inverseFilled = shape->inverseFilled() &&
292 !GrPathRenderer::IsStrokeHairlineOrEquivalent(shape->style(),
293 viewMatrix, nullptr);
294
295 SkIRect unclippedDevShapeBounds, devClipBounds;
Robert Phillips31c080b2018-08-23 10:45:32 -0400296 if (!get_shape_and_clip_bounds(renderTargetContext, clip, *shape, viewMatrix,
Robert Phillips27927a52018-08-20 13:18:12 -0400297 &unclippedDevShapeBounds,
298 &devClipBounds)) {
299 // TODO: just cons up an opaque mask here
300 if (!inverseFilled) {
301 return;
302 }
303 }
304
Robert Phillips31c080b2018-08-23 10:45:32 -0400305 // To prevent overloading the cache with entries during animations we limit the cache of masks
306 // to cases where the matrix preserves axis alignment.
Robert Phillipsde479282018-08-28 11:20:08 -0400307#ifdef SK_DISABLE_MASKFILTERED_MASK_CACHING
308 bool useCache = false;
309#else
Robert Phillips31c080b2018-08-23 10:45:32 -0400310 bool useCache = !inverseFilled && viewMatrix.preservesAxisAlignment() &&
311 shape->hasUnstyledKey() && as_MFB(maskFilter)->asABlur(nullptr);
Robert Phillipsde479282018-08-28 11:20:08 -0400312#endif
Robert Phillips31c080b2018-08-23 10:45:32 -0400313
314 const SkIRect* boundsForClip = &devClipBounds;
315 if (useCache) {
316 SkIRect clippedMaskRect, unClippedMaskRect;
317 maskFilter->canFilterMaskGPU(*shape, unclippedDevShapeBounds, devClipBounds,
318 viewMatrix, &clippedMaskRect);
319 maskFilter->canFilterMaskGPU(*shape, unclippedDevShapeBounds, unclippedDevShapeBounds,
320 viewMatrix, &unClippedMaskRect);
321 if (clippedMaskRect.isEmpty()) {
322 return;
323 }
324
325 // Use the cache only if >50% of the filtered mask is visible.
326 int unclippedWidth = unClippedMaskRect.width();
327 int unclippedHeight = unClippedMaskRect.height();
328 int64_t unclippedArea = sk_64_mul(unclippedWidth, unclippedHeight);
329 int64_t clippedArea = sk_64_mul(clippedMaskRect.width(), clippedMaskRect.height());
330 int maxTextureSize = renderTargetContext->caps()->maxTextureSize();
331 if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize ||
332 unclippedHeight > maxTextureSize) {
333 useCache = false;
334 } else {
335 // Make the clip not affect the mask
336 boundsForClip = &unclippedDevShapeBounds;
337 }
338 }
339
340 GrUniqueKey maskKey;
341 if (useCache) {
342 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
343 GrUniqueKey::Builder builder(&maskKey, kDomain, 5 + 2 + shape->unstyledKeySize(),
344 "Mask Filtered Masks");
345
346 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
347 SkScalar sx = viewMatrix.get(SkMatrix::kMScaleX);
348 SkScalar sy = viewMatrix.get(SkMatrix::kMScaleY);
349 SkScalar kx = viewMatrix.get(SkMatrix::kMSkewX);
350 SkScalar ky = viewMatrix.get(SkMatrix::kMSkewY);
351 SkScalar tx = viewMatrix.get(SkMatrix::kMTransX);
352 SkScalar ty = viewMatrix.get(SkMatrix::kMTransY);
353 // Allow 8 bits each in x and y of subpixel positioning.
354 SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
355 SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
356
357 builder[0] = SkFloat2Bits(sx);
358 builder[1] = SkFloat2Bits(sy);
359 builder[2] = SkFloat2Bits(kx);
360 builder[3] = SkFloat2Bits(ky);
361 // Distinguish between hairline and filled paths. For hairlines, we also need to include
362 // the cap. (SW grows hairlines by 0.5 pixel with round and square caps). Note that
363 // stroke-and-fill of hairlines is turned into pure fill by SkStrokeRec, so this covers
364 // all cases we might see.
365 uint32_t styleBits = shape->style().isSimpleHairline()
366 ? ((shape->style().strokeRec().getCap() << 1) | 1)
367 : 0;
368 builder[4] = fracX | (fracY >> 8) | (styleBits << 16);
369
370 SkMaskFilterBase::BlurRec rec;
371 SkAssertResult(as_MFB(maskFilter)->asABlur(&rec));
372
373 builder[5] = rec.fStyle; // TODO: we could put this with the other style bits
Robert Phillips55ff5d32019-01-07 16:11:36 -0500374 builder[6] = SkFloat2Bits(rec.fSigma);
Robert Phillips31c080b2018-08-23 10:45:32 -0400375 shape->writeUnstyledKey(&builder[7]);
376 }
377
378 SkIRect maskRect;
Robert Phillips27927a52018-08-20 13:18:12 -0400379 if (maskFilter->canFilterMaskGPU(*shape,
Robert Phillips31c080b2018-08-23 10:45:32 -0400380 unclippedDevShapeBounds,
381 *boundsForClip,
bsalomonc55271f2015-11-09 11:55:57 -0800382 viewMatrix,
383 &maskRect)) {
Robert Phillips31c080b2018-08-23 10:45:32 -0400384 if (clip_bounds_quick_reject(*boundsForClip, maskRect)) {
bsalomonc55271f2015-11-09 11:55:57 -0800385 // clipped out
386 return;
387 }
388
Robert Phillips20390c32018-08-17 11:01:03 -0400389 sk_sp<GrTextureProxy> filteredMask;
390
Robert Phillips31c080b2018-08-23 10:45:32 -0400391 GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
392
393 if (maskKey.isValid()) {
394 // TODO: this cache look up is duplicated in sw_draw_with_mask_filter for raster
395 filteredMask = proxyProvider->findOrCreateProxyByUniqueKey(
Robert Phillips59b39e72018-08-30 11:51:25 -0400396 maskKey, kTopLeft_GrSurfaceOrigin);
Robert Phillips31c080b2018-08-23 10:45:32 -0400397 }
398
Robert Phillips20390c32018-08-17 11:01:03 -0400399 if (!filteredMask) {
400 sk_sp<GrTextureProxy> maskProxy(create_mask_GPU(
401 context,
Robert Phillips31c080b2018-08-23 10:45:32 -0400402 maskRect,
Robert Phillips27927a52018-08-20 13:18:12 -0400403 viewMatrix,
404 *shape,
robertphillipsd728f0c2016-11-21 11:05:03 -0800405 renderTargetContext->numColorSamples()));
Robert Phillips20390c32018-08-17 11:01:03 -0400406 if (maskProxy) {
407 filteredMask = maskFilter->filterMaskGPU(context,
408 std::move(maskProxy),
409 viewMatrix,
Robert Phillips31c080b2018-08-23 10:45:32 -0400410 maskRect);
Robert Phillips59b39e72018-08-30 11:51:25 -0400411 SkASSERT(kTopLeft_GrSurfaceOrigin == filteredMask->origin());
412
Robert Phillips31c080b2018-08-23 10:45:32 -0400413 if (filteredMask && maskKey.isValid()) {
414 proxyProvider->assignUniqueKeyToProxy(maskKey, filteredMask.get());
415 }
bsalomonc55271f2015-11-09 11:55:57 -0800416 }
417 }
Robert Phillips20390c32018-08-17 11:01:03 -0400418
419 if (filteredMask) {
420 if (draw_mask(renderTargetContext, clip, viewMatrix,
Robert Phillips31c080b2018-08-23 10:45:32 -0400421 maskRect, std::move(paint), std::move(filteredMask))) {
Robert Phillips20390c32018-08-17 11:01:03 -0400422 // This path is completely drawn
423 return;
424 }
Mike Klein16885072018-12-11 09:54:31 -0500425 assert_alive(paint);
Robert Phillips20390c32018-08-17 11:01:03 -0400426 }
bsalomonc55271f2015-11-09 11:55:57 -0800427 }
428
Robert Phillips27927a52018-08-20 13:18:12 -0400429 sw_draw_with_mask_filter(context, renderTargetContext, clip, viewMatrix, *shape,
Robert Phillips31c080b2018-08-23 10:45:32 -0400430 maskFilter, *boundsForClip, std::move(paint), maskKey);
bsalomon6663acf2016-05-10 09:14:17 -0700431}
432
Robert Phillips27927a52018-08-20 13:18:12 -0400433void GrBlurUtils::drawShapeWithMaskFilter(GrContext* context,
434 GrRenderTargetContext* renderTargetContext,
435 const GrClip& clip,
436 const GrShape& shape,
437 GrPaint&& paint,
Robert Phillips27927a52018-08-20 13:18:12 -0400438 const SkMatrix& viewMatrix,
439 const SkMaskFilter* mf) {
Robert Phillips793324c2018-08-24 13:53:56 -0400440 draw_shape_with_mask_filter(context, renderTargetContext, clip, std::move(paint),
Robert Phillips27927a52018-08-20 13:18:12 -0400441 viewMatrix, as_MFB(mf), shape);
bsalomonc55271f2015-11-09 11:55:57 -0800442}
443
Robert Phillips27927a52018-08-20 13:18:12 -0400444void GrBlurUtils::drawShapeWithMaskFilter(GrContext* context,
445 GrRenderTargetContext* renderTargetContext,
446 const GrClip& clip,
447 const SkPaint& paint,
448 const SkMatrix& viewMatrix,
449 const GrShape& shape) {
Khushalc421ca12018-06-26 14:38:34 -0700450 if (context->abandoned()) {
Robert Phillipsbebfd412018-03-08 11:07:23 -0500451 return;
452 }
453
robertphillipsccb1b572015-05-27 11:02:55 -0700454 GrPaint grPaint;
Brian Salomonf3569f02017-10-24 12:52:33 -0400455 if (!SkPaintToGrPaint(context, renderTargetContext->colorSpaceInfo(), paint, viewMatrix,
456 &grPaint)) {
robertphillipsccb1b572015-05-27 11:02:55 -0700457 return;
458 }
Robert Phillips27927a52018-08-20 13:18:12 -0400459
Mike Reed80747ef2018-01-23 15:29:32 -0500460 SkMaskFilterBase* mf = as_MFB(paint.getMaskFilter());
Mike Reedbfadcf02018-01-20 22:24:21 +0000461 if (mf && !mf->hasFragmentProcessor()) {
Robert Phillipsa29a9562016-10-20 09:40:55 -0400462 // The MaskFilter wasn't already handled in SkPaintToGrPaint
Robert Phillips793324c2018-08-24 13:53:56 -0400463 draw_shape_with_mask_filter(context, renderTargetContext, clip, std::move(grPaint),
Robert Phillips27927a52018-08-20 13:18:12 -0400464 viewMatrix, mf, shape);
bsalomonc55271f2015-11-09 11:55:57 -0800465 } else {
Robert Phillips793324c2018-08-24 13:53:56 -0400466 GrAA aa = GrAA(paint.isAntiAlias());
Robert Phillips27927a52018-08-20 13:18:12 -0400467 renderTargetContext->drawShape(clip, std::move(grPaint), aa, viewMatrix, shape);
robertphillipsccb1b572015-05-27 11:02:55 -0700468 }
robertphillipsccb1b572015-05-27 11:02:55 -0700469}