blob: 3535df9c1ae42d17cd672c7de82e228d0ba267ec [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) {
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500178 sk_sp<GrRenderTargetContext> rtContext(
179 context->contextPriv().makeDeferredRenderTargetContextWithFallback(
180 SkBackingFit::kApprox, maskRect.width(), maskRect.height(), kAlpha_8_GrPixelConfig,
Robert Phillips59b39e72018-08-30 11:51:25 -0400181 nullptr, sampleCnt, GrMipMapped::kNo, kTopLeft_GrSurfaceOrigin));
robertphillipsd728f0c2016-11-21 11:05:03 -0800182 if (!rtContext) {
halcanary96fcdcc2015-08-27 07:41:13 -0700183 return nullptr;
robertphillipsccb1b572015-05-27 11:02:55 -0700184 }
185
Robert Phillips784b7bf2016-12-09 13:35:02 -0500186 rtContext->priv().absClear(nullptr, 0x0);
robertphillipsccb1b572015-05-27 11:02:55 -0700187
Brian Salomon82f44312017-01-11 13:42:54 -0500188 GrPaint maskPaint;
189 maskPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
robertphillipsccb1b572015-05-27 11:02:55 -0700190
191 // setup new clip
cdalton846c0512016-05-13 10:25:00 -0700192 const SkIRect clipRect = SkIRect::MakeWH(maskRect.width(), maskRect.height());
193 GrFixedClip clip(clipRect);
robertphillipsccb1b572015-05-27 11:02:55 -0700194
robertphillips3833daa2015-09-14 11:18:13 -0700195 // Draw the mask into maskTexture with the path's integerized top-left at
Brian Salomon82f44312017-01-11 13:42:54 -0500196 // the origin using maskPaint.
Robert Phillips27927a52018-08-20 13:18:12 -0400197 SkMatrix viewMatrix = origViewMatrix;
198 viewMatrix.postTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop));
Robert Phillips793324c2018-08-24 13:53:56 -0400199 rtContext->drawShape(clip, std::move(maskPaint), GrAA::kYes, viewMatrix, shape);
Robert Phillipsf200a902017-01-30 13:27:37 -0500200 return rtContext->asTextureProxyRef();
robertphillipsccb1b572015-05-27 11:02:55 -0700201}
202
Robert Phillips27927a52018-08-20 13:18:12 -0400203static bool get_unclipped_shape_dev_bounds(const GrShape& shape, const SkMatrix& matrix,
204 SkIRect* devBounds) {
205 SkRect shapeBounds = shape.styledBounds();
206 if (shapeBounds.isEmpty()) {
207 return false;
208 }
209 SkRect shapeDevBounds;
210 matrix.mapRect(&shapeDevBounds, shapeBounds);
211 // Even though these are "unclipped" bounds we still clip to the int32_t range.
212 // This is the largest int32_t that is representable exactly as a float. The next 63 larger ints
213 // would round down to this value when cast to a float, but who really cares.
214 // INT32_MIN is exactly representable.
215 static constexpr int32_t kMaxInt = 2147483520;
216 if (!shapeDevBounds.intersect(SkRect::MakeLTRB(INT32_MIN, INT32_MIN, kMaxInt, kMaxInt))) {
217 return false;
218 }
219 // Make sure that the resulting SkIRect can have representable width and height
220 if (SkScalarRoundToInt(shapeDevBounds.width()) > kMaxInt ||
221 SkScalarRoundToInt(shapeDevBounds.height()) > kMaxInt) {
222 return false;
223 }
224 shapeDevBounds.roundOut(devBounds);
225 return true;
226}
bsalomonc55271f2015-11-09 11:55:57 -0800227
Robert Phillips27927a52018-08-20 13:18:12 -0400228// Gets the shape bounds, the clip bounds, and the intersection (if any). Returns false if there
229// is no intersection.
230static bool get_shape_and_clip_bounds(GrRenderTargetContext* renderTargetContext,
231 const GrClip& clip,
232 const GrShape& shape,
233 const SkMatrix& matrix,
234 SkIRect* unclippedDevShapeBounds,
235 SkIRect* devClipBounds) {
236 // compute bounds as intersection of rt size, clip, and path
Robert Phillips784b7bf2016-12-09 13:35:02 -0500237 clip.getConservativeBounds(renderTargetContext->width(),
238 renderTargetContext->height(),
Robert Phillips27927a52018-08-20 13:18:12 -0400239 devClipBounds);
bsalomonc55271f2015-11-09 11:55:57 -0800240
Robert Phillips27927a52018-08-20 13:18:12 -0400241 if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) {
242 *unclippedDevShapeBounds = SkIRect::EmptyIRect();
243 return false;
bsalomonc55271f2015-11-09 11:55:57 -0800244 }
245
Robert Phillips27927a52018-08-20 13:18:12 -0400246 return true;
247}
248
249static void draw_shape_with_mask_filter(GrContext* context,
250 GrRenderTargetContext* renderTargetContext,
251 const GrClip& clip,
252 GrPaint&& paint,
Robert Phillips27927a52018-08-20 13:18:12 -0400253 const SkMatrix& viewMatrix,
254 const SkMaskFilterBase* maskFilter,
255 const GrShape& origShape) {
256 SkASSERT(maskFilter);
257
258 const GrShape* shape = &origShape;
259 SkTLazy<GrShape> tmpShape;
260
261 if (origShape.style().applies()) {
262 SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix);
263 if (0 == styleScale) {
264 return;
bsalomon6663acf2016-05-10 09:14:17 -0700265 }
Robert Phillips27927a52018-08-20 13:18:12 -0400266
267 tmpShape.init(origShape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale));
268 if (tmpShape.get()->isEmpty()) {
269 return;
270 }
271
272 shape = tmpShape.get();
bsalomon6663acf2016-05-10 09:14:17 -0700273 }
bsalomonc55271f2015-11-09 11:55:57 -0800274
Robert Phillipsb889f202018-08-17 19:55:59 +0000275 if (maskFilter->directFilterMaskGPU(context,
276 renderTargetContext,
277 std::move(paint),
278 clip,
279 viewMatrix,
Robert Phillips27927a52018-08-20 13:18:12 -0400280 *shape)) {
Robert Phillipsb889f202018-08-17 19:55:59 +0000281 // the mask filter was able to draw itself directly, so there's nothing
282 // left to do.
283 return;
284 }
285
Robert Phillips27927a52018-08-20 13:18:12 -0400286 // If the path is hairline, ignore inverse fill.
287 bool inverseFilled = shape->inverseFilled() &&
288 !GrPathRenderer::IsStrokeHairlineOrEquivalent(shape->style(),
289 viewMatrix, nullptr);
290
291 SkIRect unclippedDevShapeBounds, devClipBounds;
Robert Phillips31c080b2018-08-23 10:45:32 -0400292 if (!get_shape_and_clip_bounds(renderTargetContext, clip, *shape, viewMatrix,
Robert Phillips27927a52018-08-20 13:18:12 -0400293 &unclippedDevShapeBounds,
294 &devClipBounds)) {
295 // TODO: just cons up an opaque mask here
296 if (!inverseFilled) {
297 return;
298 }
299 }
300
Robert Phillips31c080b2018-08-23 10:45:32 -0400301 // To prevent overloading the cache with entries during animations we limit the cache of masks
302 // to cases where the matrix preserves axis alignment.
Robert Phillipsde479282018-08-28 11:20:08 -0400303#ifdef SK_DISABLE_MASKFILTERED_MASK_CACHING
304 bool useCache = false;
305#else
Robert Phillips31c080b2018-08-23 10:45:32 -0400306 bool useCache = !inverseFilled && viewMatrix.preservesAxisAlignment() &&
307 shape->hasUnstyledKey() && as_MFB(maskFilter)->asABlur(nullptr);
Robert Phillipsde479282018-08-28 11:20:08 -0400308#endif
Robert Phillips31c080b2018-08-23 10:45:32 -0400309
310 const SkIRect* boundsForClip = &devClipBounds;
311 if (useCache) {
312 SkIRect clippedMaskRect, unClippedMaskRect;
313 maskFilter->canFilterMaskGPU(*shape, unclippedDevShapeBounds, devClipBounds,
314 viewMatrix, &clippedMaskRect);
315 maskFilter->canFilterMaskGPU(*shape, unclippedDevShapeBounds, unclippedDevShapeBounds,
316 viewMatrix, &unClippedMaskRect);
317 if (clippedMaskRect.isEmpty()) {
318 return;
319 }
320
321 // Use the cache only if >50% of the filtered mask is visible.
322 int unclippedWidth = unClippedMaskRect.width();
323 int unclippedHeight = unClippedMaskRect.height();
324 int64_t unclippedArea = sk_64_mul(unclippedWidth, unclippedHeight);
325 int64_t clippedArea = sk_64_mul(clippedMaskRect.width(), clippedMaskRect.height());
326 int maxTextureSize = renderTargetContext->caps()->maxTextureSize();
327 if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize ||
328 unclippedHeight > maxTextureSize) {
329 useCache = false;
330 } else {
331 // Make the clip not affect the mask
332 boundsForClip = &unclippedDevShapeBounds;
333 }
334 }
335
336 GrUniqueKey maskKey;
337 if (useCache) {
338 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
339 GrUniqueKey::Builder builder(&maskKey, kDomain, 5 + 2 + shape->unstyledKeySize(),
340 "Mask Filtered Masks");
341
342 // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
343 SkScalar sx = viewMatrix.get(SkMatrix::kMScaleX);
344 SkScalar sy = viewMatrix.get(SkMatrix::kMScaleY);
345 SkScalar kx = viewMatrix.get(SkMatrix::kMSkewX);
346 SkScalar ky = viewMatrix.get(SkMatrix::kMSkewY);
347 SkScalar tx = viewMatrix.get(SkMatrix::kMTransX);
348 SkScalar ty = viewMatrix.get(SkMatrix::kMTransY);
349 // Allow 8 bits each in x and y of subpixel positioning.
350 SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
351 SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
352
353 builder[0] = SkFloat2Bits(sx);
354 builder[1] = SkFloat2Bits(sy);
355 builder[2] = SkFloat2Bits(kx);
356 builder[3] = SkFloat2Bits(ky);
357 // Distinguish between hairline and filled paths. For hairlines, we also need to include
358 // the cap. (SW grows hairlines by 0.5 pixel with round and square caps). Note that
359 // stroke-and-fill of hairlines is turned into pure fill by SkStrokeRec, so this covers
360 // all cases we might see.
361 uint32_t styleBits = shape->style().isSimpleHairline()
362 ? ((shape->style().strokeRec().getCap() << 1) | 1)
363 : 0;
364 builder[4] = fracX | (fracY >> 8) | (styleBits << 16);
365
366 SkMaskFilterBase::BlurRec rec;
367 SkAssertResult(as_MFB(maskFilter)->asABlur(&rec));
368
369 builder[5] = rec.fStyle; // TODO: we could put this with the other style bits
370 builder[6] = rec.fSigma;
371 shape->writeUnstyledKey(&builder[7]);
372 }
373
374 SkIRect maskRect;
Robert Phillips27927a52018-08-20 13:18:12 -0400375 if (maskFilter->canFilterMaskGPU(*shape,
Robert Phillips31c080b2018-08-23 10:45:32 -0400376 unclippedDevShapeBounds,
377 *boundsForClip,
bsalomonc55271f2015-11-09 11:55:57 -0800378 viewMatrix,
379 &maskRect)) {
Robert Phillips31c080b2018-08-23 10:45:32 -0400380 if (clip_bounds_quick_reject(*boundsForClip, maskRect)) {
bsalomonc55271f2015-11-09 11:55:57 -0800381 // clipped out
382 return;
383 }
384
Robert Phillips20390c32018-08-17 11:01:03 -0400385 sk_sp<GrTextureProxy> filteredMask;
386
Robert Phillips31c080b2018-08-23 10:45:32 -0400387 GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
388
389 if (maskKey.isValid()) {
390 // TODO: this cache look up is duplicated in sw_draw_with_mask_filter for raster
391 filteredMask = proxyProvider->findOrCreateProxyByUniqueKey(
Robert Phillips59b39e72018-08-30 11:51:25 -0400392 maskKey, kTopLeft_GrSurfaceOrigin);
Robert Phillips31c080b2018-08-23 10:45:32 -0400393 }
394
Robert Phillips20390c32018-08-17 11:01:03 -0400395 if (!filteredMask) {
396 sk_sp<GrTextureProxy> maskProxy(create_mask_GPU(
397 context,
Robert Phillips31c080b2018-08-23 10:45:32 -0400398 maskRect,
Robert Phillips27927a52018-08-20 13:18:12 -0400399 viewMatrix,
400 *shape,
robertphillipsd728f0c2016-11-21 11:05:03 -0800401 renderTargetContext->numColorSamples()));
Robert Phillips20390c32018-08-17 11:01:03 -0400402 if (maskProxy) {
403 filteredMask = maskFilter->filterMaskGPU(context,
404 std::move(maskProxy),
405 viewMatrix,
Robert Phillips31c080b2018-08-23 10:45:32 -0400406 maskRect);
Robert Phillips59b39e72018-08-30 11:51:25 -0400407 SkASSERT(kTopLeft_GrSurfaceOrigin == filteredMask->origin());
408
Robert Phillips31c080b2018-08-23 10:45:32 -0400409 if (filteredMask && maskKey.isValid()) {
410 proxyProvider->assignUniqueKeyToProxy(maskKey, filteredMask.get());
411 }
bsalomonc55271f2015-11-09 11:55:57 -0800412 }
413 }
Robert Phillips20390c32018-08-17 11:01:03 -0400414
415 if (filteredMask) {
416 if (draw_mask(renderTargetContext, clip, viewMatrix,
Robert Phillips31c080b2018-08-23 10:45:32 -0400417 maskRect, std::move(paint), std::move(filteredMask))) {
Robert Phillips20390c32018-08-17 11:01:03 -0400418 // This path is completely drawn
419 return;
420 }
421 }
bsalomonc55271f2015-11-09 11:55:57 -0800422 }
423
Robert Phillips27927a52018-08-20 13:18:12 -0400424 sw_draw_with_mask_filter(context, renderTargetContext, clip, viewMatrix, *shape,
Robert Phillips31c080b2018-08-23 10:45:32 -0400425 maskFilter, *boundsForClip, std::move(paint), maskKey);
bsalomon6663acf2016-05-10 09:14:17 -0700426}
427
Robert Phillips27927a52018-08-20 13:18:12 -0400428void GrBlurUtils::drawShapeWithMaskFilter(GrContext* context,
429 GrRenderTargetContext* renderTargetContext,
430 const GrClip& clip,
431 const GrShape& shape,
432 GrPaint&& paint,
Robert Phillips27927a52018-08-20 13:18:12 -0400433 const SkMatrix& viewMatrix,
434 const SkMaskFilter* mf) {
Robert Phillips793324c2018-08-24 13:53:56 -0400435 draw_shape_with_mask_filter(context, renderTargetContext, clip, std::move(paint),
Robert Phillips27927a52018-08-20 13:18:12 -0400436 viewMatrix, as_MFB(mf), shape);
bsalomonc55271f2015-11-09 11:55:57 -0800437}
438
Robert Phillips27927a52018-08-20 13:18:12 -0400439void GrBlurUtils::drawShapeWithMaskFilter(GrContext* context,
440 GrRenderTargetContext* renderTargetContext,
441 const GrClip& clip,
442 const SkPaint& paint,
443 const SkMatrix& viewMatrix,
444 const GrShape& shape) {
Khushalc421ca12018-06-26 14:38:34 -0700445 if (context->abandoned()) {
Robert Phillipsbebfd412018-03-08 11:07:23 -0500446 return;
447 }
448
robertphillipsccb1b572015-05-27 11:02:55 -0700449 GrPaint grPaint;
Brian Salomonf3569f02017-10-24 12:52:33 -0400450 if (!SkPaintToGrPaint(context, renderTargetContext->colorSpaceInfo(), paint, viewMatrix,
451 &grPaint)) {
robertphillipsccb1b572015-05-27 11:02:55 -0700452 return;
453 }
Robert Phillips27927a52018-08-20 13:18:12 -0400454
Mike Reed80747ef2018-01-23 15:29:32 -0500455 SkMaskFilterBase* mf = as_MFB(paint.getMaskFilter());
Mike Reedbfadcf02018-01-20 22:24:21 +0000456 if (mf && !mf->hasFragmentProcessor()) {
Robert Phillipsa29a9562016-10-20 09:40:55 -0400457 // The MaskFilter wasn't already handled in SkPaintToGrPaint
Robert Phillips793324c2018-08-24 13:53:56 -0400458 draw_shape_with_mask_filter(context, renderTargetContext, clip, std::move(grPaint),
Robert Phillips27927a52018-08-20 13:18:12 -0400459 viewMatrix, mf, shape);
bsalomonc55271f2015-11-09 11:55:57 -0800460 } else {
Robert Phillips793324c2018-08-24 13:53:56 -0400461 GrAA aa = GrAA(paint.isAntiAlias());
Robert Phillips27927a52018-08-20 13:18:12 -0400462 renderTargetContext->drawShape(clip, std::move(grPaint), aa, viewMatrix, shape);
robertphillipsccb1b572015-05-27 11:02:55 -0700463 }
robertphillipsccb1b572015-05-27 11:02:55 -0700464}