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