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