robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 1 | /* |
| 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" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 9 | #include "GrRenderTargetContext.h" |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 11 | #include "GrContext.h" |
Robert Phillips | c949ce9 | 2017-01-19 16:59:04 -0500 | [diff] [blame] | 12 | #include "GrContextPriv.h" |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 13 | #include "GrFixedClip.h" |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 14 | #include "GrRenderTargetContextPriv.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 15 | #include "GrResourceProvider.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 16 | #include "effects/GrSimpleTextureEffect.h" |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 17 | #include "GrStyle.h" |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 18 | #include "GrTextureProxy.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 19 | #include "SkDraw.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 20 | #include "SkGr.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 21 | #include "SkMaskFilter.h" |
| 22 | #include "SkPaint.h" |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 23 | #include "SkTLazy.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 24 | |
| 25 | static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& rect) { |
| 26 | return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBounds, rect); |
| 27 | } |
| 28 | |
| 29 | // Draw a mask using the supplied paint. Since the coverage/geometry |
| 30 | // is already burnt into the mask this boils down to a rect draw. |
| 31 | // Return true if the mask was successfully drawn. |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 32 | static bool draw_mask(GrRenderTargetContext* renderTargetContext, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 33 | const GrClip& clip, |
| 34 | const SkMatrix& viewMatrix, |
robertphillips | f054b17 | 2016-05-13 05:06:19 -0700 | [diff] [blame] | 35 | const SkIRect& maskRect, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 36 | GrPaint&& paint, |
Robert Phillips | 4a24da5 | 2016-12-14 09:00:07 -0500 | [diff] [blame] | 37 | sk_sp<GrTextureProxy> mask) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 38 | SkMatrix inverse; |
| 39 | if (!viewMatrix.invert(&inverse)) { |
| 40 | return false; |
| 41 | } |
Robert Phillips | 4a24da5 | 2016-12-14 09:00:07 -0500 | [diff] [blame] | 42 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 43 | GrResourceProvider* resourceProvider = renderTargetContext->resourceProvider(); |
| 44 | |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 45 | SkMatrix matrix = SkMatrix::MakeTrans(-SkIntToScalar(maskRect.fLeft), |
| 46 | -SkIntToScalar(maskRect.fTop)); |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 47 | matrix.preConcat(viewMatrix); |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 48 | paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(resourceProvider, |
| 49 | std::move(mask), |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 50 | nullptr, matrix)); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 51 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 52 | renderTargetContext->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 53 | SkRect::Make(maskRect), inverse); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 54 | return true; |
| 55 | } |
| 56 | |
Robert Phillips | 4a24da5 | 2016-12-14 09:00:07 -0500 | [diff] [blame] | 57 | static bool sw_draw_with_mask_filter(GrContext* context, |
| 58 | GrRenderTargetContext* renderTargetContext, |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 59 | const GrClip& clipData, |
| 60 | const SkMatrix& viewMatrix, |
| 61 | const SkPath& devPath, |
| 62 | const SkMaskFilter* filter, |
| 63 | const SkIRect& clipBounds, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 64 | GrPaint&& paint, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 65 | SkStrokeRec::InitStyle fillOrHairline) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 66 | SkMask srcM, dstM; |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 67 | if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 68 | SkMask::kComputeBoundsAndRenderImage_CreateMode, fillOrHairline)) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 69 | return false; |
| 70 | } |
| 71 | SkAutoMaskFreeImage autoSrc(srcM.fImage); |
| 72 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 73 | if (!filter->filterMask(&dstM, srcM, viewMatrix, nullptr)) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 74 | return false; |
| 75 | } |
| 76 | // this will free-up dstM when we're done (allocated in filterMask()) |
| 77 | SkAutoMaskFreeImage autoDst(dstM.fImage); |
| 78 | |
| 79 | if (clip_bounds_quick_reject(clipBounds, dstM.fBounds)) { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | // we now have a device-aligned 8bit mask in dstM, ready to be drawn using |
| 84 | // the current clip (and identity matrix) and GrPaint settings |
| 85 | GrSurfaceDesc desc; |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 86 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 87 | desc.fWidth = dstM.fBounds.width(); |
| 88 | desc.fHeight = dstM.fBounds.height(); |
| 89 | desc.fConfig = kAlpha_8_GrPixelConfig; |
| 90 | |
Robert Phillips | c949ce9 | 2017-01-19 16:59:04 -0500 | [diff] [blame] | 91 | sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeDeferredSurfaceContext( |
| 92 | desc, |
| 93 | SkBackingFit::kApprox, |
| 94 | SkBudgeted::kYes); |
| 95 | if (!sContext) { |
Robert Phillips | 4a24da5 | 2016-12-14 09:00:07 -0500 | [diff] [blame] | 96 | return false; |
| 97 | } |
| 98 | |
Robert Phillips | c949ce9 | 2017-01-19 16:59:04 -0500 | [diff] [blame] | 99 | SkImageInfo ii = SkImageInfo::MakeA8(desc.fWidth, desc.fHeight); |
| 100 | if (!sContext->writePixels(ii, dstM.fImage, dstM.fRowBytes, 0, 0)) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 101 | return false; |
| 102 | } |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 103 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 104 | return draw_mask(renderTargetContext, clipData, viewMatrix, |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 105 | dstM.fBounds, std::move(paint), sContext->asTextureProxyRef()); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | // Create a mask of 'devPath' and place the result in 'mask'. |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 109 | static sk_sp<GrTextureProxy> create_mask_GPU(GrContext* context, |
| 110 | const SkIRect& maskRect, |
| 111 | const SkPath& devPath, |
| 112 | SkStrokeRec::InitStyle fillOrHairline, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 113 | GrAA aa, |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 114 | int sampleCnt) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 115 | if (GrAA::kNo == aa) { |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 116 | // Don't need MSAA if mask isn't AA |
| 117 | sampleCnt = 0; |
| 118 | } |
| 119 | |
Robert Phillips | 55360b1 | 2016-12-05 13:18:47 +0000 | [diff] [blame] | 120 | sk_sp<GrRenderTargetContext> rtContext(context->makeDeferredRenderTargetContextWithFallback( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 121 | SkBackingFit::kApprox, maskRect.width(), maskRect.height(), kAlpha_8_GrPixelConfig, nullptr, |
| 122 | sampleCnt)); |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 123 | if (!rtContext) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 124 | return nullptr; |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 127 | rtContext->priv().absClear(nullptr, 0x0); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 128 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 129 | GrPaint maskPaint; |
| 130 | maskPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 131 | |
| 132 | // setup new clip |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 133 | const SkIRect clipRect = SkIRect::MakeWH(maskRect.width(), maskRect.height()); |
| 134 | GrFixedClip clip(clipRect); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 135 | |
robertphillips | 3833daa | 2015-09-14 11:18:13 -0700 | [diff] [blame] | 136 | // Draw the mask into maskTexture with the path's integerized top-left at |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 137 | // the origin using maskPaint. |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 138 | SkMatrix translate; |
robertphillips | f054b17 | 2016-05-13 05:06:19 -0700 | [diff] [blame] | 139 | translate.setTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop)); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 140 | rtContext->drawPath(clip, std::move(maskPaint), aa, translate, devPath, |
| 141 | GrStyle(fillOrHairline)); |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 142 | return rtContext->asTextureProxyRef(); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 143 | } |
| 144 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 145 | static void draw_path_with_mask_filter(GrContext* context, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 146 | GrRenderTargetContext* renderTargetContext, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 147 | const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 148 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 149 | GrAA aa, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 150 | const SkMatrix& viewMatrix, |
| 151 | const SkMaskFilter* maskFilter, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 152 | const GrStyle& style, |
| 153 | const SkPath* path, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 154 | bool pathIsMutable) { |
| 155 | SkASSERT(maskFilter); |
| 156 | |
| 157 | SkIRect clipBounds; |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 158 | clip.getConservativeBounds(renderTargetContext->width(), |
| 159 | renderTargetContext->height(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 160 | &clipBounds); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 161 | SkTLazy<SkPath> tmpPath; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 162 | SkStrokeRec::InitStyle fillOrHairline; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 163 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 164 | // We just fully apply the style here. |
| 165 | if (style.applies()) { |
senorblanco | b6a40b8 | 2016-08-19 08:07:22 -0700 | [diff] [blame] | 166 | SkScalar scale = GrStyle::MatrixToScaleFactor(viewMatrix); |
| 167 | if (0 == scale || !style.applyToPath(tmpPath.init(), &fillOrHairline, *path, scale)) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 168 | return; |
| 169 | } |
| 170 | pathIsMutable = true; |
| 171 | path = tmpPath.get(); |
| 172 | } else if (style.isSimpleHairline()) { |
| 173 | fillOrHairline = SkStrokeRec::kHairline_InitStyle; |
bsalomon | 055e192 | 2016-05-06 07:22:58 -0700 | [diff] [blame] | 174 | } else { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 175 | SkASSERT(style.isSimpleFill()); |
| 176 | fillOrHairline = SkStrokeRec::kFill_InitStyle; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // transform the path into device space |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 180 | if (!viewMatrix.isIdentity()) { |
| 181 | SkPath* result; |
| 182 | if (pathIsMutable) { |
| 183 | result = const_cast<SkPath*>(path); |
| 184 | } else { |
| 185 | if (!tmpPath.isValid()) { |
| 186 | tmpPath.init(); |
| 187 | } |
| 188 | result = tmpPath.get(); |
| 189 | } |
| 190 | path->transform(viewMatrix, result); |
| 191 | path = result; |
| 192 | result->setIsVolatile(true); |
| 193 | pathIsMutable = true; |
| 194 | } |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 195 | |
| 196 | SkRect maskRect; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 197 | if (maskFilter->canFilterMaskGPU(SkRRect::MakeRect(path->getBounds()), |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 198 | clipBounds, |
| 199 | viewMatrix, |
| 200 | &maskRect)) { |
robertphillips | f054b17 | 2016-05-13 05:06:19 -0700 | [diff] [blame] | 201 | // This mask will ultimately be drawn as a non-AA rect (see draw_mask). |
| 202 | // Non-AA rects have a bad habit of snapping arbitrarily. Integerize here |
| 203 | // so the mask draws in a reproducible manner. |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 204 | SkIRect finalIRect; |
| 205 | maskRect.roundOut(&finalIRect); |
| 206 | if (clip_bounds_quick_reject(clipBounds, finalIRect)) { |
| 207 | // clipped out |
| 208 | return; |
| 209 | } |
| 210 | |
Robert Phillips | d374948 | 2017-03-14 09:17:43 -0400 | [diff] [blame] | 211 | if (maskFilter->directFilterMaskGPU(context, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 212 | renderTargetContext, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 213 | std::move(paint), |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 214 | clip, |
| 215 | viewMatrix, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 216 | SkStrokeRec(fillOrHairline), |
| 217 | *path)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 218 | // the mask filter was able to draw itself directly, so there's nothing |
| 219 | // left to do. |
| 220 | return; |
| 221 | } |
| 222 | |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 223 | sk_sp<GrTextureProxy> maskProxy(create_mask_GPU(context, |
| 224 | finalIRect, |
| 225 | *path, |
| 226 | fillOrHairline, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 227 | aa, |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 228 | renderTargetContext->numColorSamples())); |
| 229 | if (maskProxy) { |
Robert Phillips | 4a24da5 | 2016-12-14 09:00:07 -0500 | [diff] [blame] | 230 | sk_sp<GrTextureProxy> filtered = maskFilter->filterMaskGPU(context, |
| 231 | std::move(maskProxy), |
| 232 | viewMatrix, |
| 233 | finalIRect); |
| 234 | if (filtered) { |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 235 | if (draw_mask(renderTargetContext, clip, viewMatrix, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 236 | finalIRect, std::move(paint), std::move(filtered))) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 237 | // This path is completely drawn |
| 238 | return; |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 244 | sw_draw_with_mask_filter(context, renderTargetContext, clip, viewMatrix, *path, maskFilter, |
| 245 | clipBounds, std::move(paint), fillOrHairline); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 249 | GrRenderTargetContext* renderTargetContext, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 250 | const GrClip& clip, |
| 251 | const SkPath& path, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 252 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 253 | GrAA aa, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 254 | const SkMatrix& viewMatrix, |
| 255 | const SkMaskFilter* mf, |
| 256 | const GrStyle& style, |
| 257 | bool pathIsMutable) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 258 | draw_path_with_mask_filter(context, renderTargetContext, clip, std::move(paint), aa, viewMatrix, |
| 259 | mf, style, &path, pathIsMutable); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 263 | GrRenderTargetContext* renderTargetContext, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 264 | const GrClip& clip, |
| 265 | const SkPath& origPath, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 266 | const SkPaint& paint, |
| 267 | const SkMatrix& origViewMatrix, |
| 268 | const SkMatrix* prePathMatrix, |
| 269 | const SkIRect& clipBounds, |
| 270 | bool pathIsMutable) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 271 | SkASSERT(!pathIsMutable || origPath.isVolatile()); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 272 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 273 | GrStyle style(paint); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 274 | // If we have a prematrix, apply it to the path, optimizing for the case |
| 275 | // where the original path can in fact be modified in place (even though |
| 276 | // its parameter type is const). |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 277 | |
| 278 | const SkPath* path = &origPath; |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 279 | SkTLazy<SkPath> tmpPath; |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 280 | |
| 281 | SkMatrix viewMatrix = origViewMatrix; |
| 282 | |
| 283 | if (prePathMatrix) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 284 | // Styling, blurs, and shading are supposed to be applied *after* the prePathMatrix. |
| 285 | if (!paint.getMaskFilter() && !paint.getShader() && !style.applies()) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 286 | viewMatrix.preConcat(*prePathMatrix); |
| 287 | } else { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 288 | SkPath* result = pathIsMutable ? const_cast<SkPath*>(path) : tmpPath.init(); |
| 289 | pathIsMutable = true; |
| 290 | path->transform(*prePathMatrix, result); |
| 291 | path = result; |
| 292 | result->setIsVolatile(true); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | // at this point we're done with prePathMatrix |
| 296 | SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) |
| 297 | |
| 298 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 299 | if (!SkPaintToGrPaint(context, renderTargetContext, paint, viewMatrix, &grPaint)) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 300 | return; |
| 301 | } |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 302 | GrAA aa = GrBoolToAA(paint.isAntiAlias()); |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 303 | SkMaskFilter* mf = paint.getMaskFilter(); |
Robert Phillips | d9d8485 | 2017-06-09 10:48:29 -0400 | [diff] [blame^] | 304 | if (mf && !mf->asFragmentProcessor(nullptr)) { |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 305 | // The MaskFilter wasn't already handled in SkPaintToGrPaint |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 306 | draw_path_with_mask_filter(context, renderTargetContext, clip, std::move(grPaint), aa, |
| 307 | viewMatrix, mf, style, path, pathIsMutable); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 308 | } else { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 309 | renderTargetContext->drawPath(clip, std::move(grPaint), aa, viewMatrix, *path, style); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 310 | } |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 311 | } |