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