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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrBlurUtils.h" |
Robert Phillips | c7c2baf | 2018-03-08 09:51:04 -0500 | [diff] [blame] | 9 | |
Robert Phillips | 7cef678 | 2021-07-01 13:21:37 -0400 | [diff] [blame] | 10 | #if SK_GPU_V1 |
Robert Phillips | 11bc305 | 2021-06-21 09:25:11 -0400 | [diff] [blame] | 11 | |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 12 | #include "include/gpu/GrDirectContext.h" |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 13 | #include "include/gpu/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrCaps.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrFixedClip.h" |
| 17 | #include "src/gpu/GrProxyProvider.h" |
| 18 | #include "src/gpu/GrRecordingContextPriv.h" |
Robert Phillips | 1a82a4e | 2021-07-01 10:27:44 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrResourceProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrStyle.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrTextureProxy.h" |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrThreadSafeCache.h" |
Robert Phillips | 62214f7 | 2021-06-15 10:12:51 -0400 | [diff] [blame] | 23 | #include "src/gpu/GrUtil.h" |
Brian Salomon | 27c4202 | 2021-04-28 12:39:21 -0400 | [diff] [blame] | 24 | #include "src/gpu/SkGr.h" |
Brian Salomon | b8f098d | 2020-01-07 11:15:44 -0500 | [diff] [blame] | 25 | #include "src/gpu/effects/GrTextureEffect.h" |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 26 | #include "src/gpu/geometry/GrStyledShape.h" |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 27 | #include "src/gpu/v1/SurfaceDrawContext_v1.h" |
Robert Phillips | c7c2baf | 2018-03-08 09:51:04 -0500 | [diff] [blame] | 28 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 29 | #include "include/core/SkPaint.h" |
| 30 | #include "src/core/SkDraw.h" |
| 31 | #include "src/core/SkMaskFilterBase.h" |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 32 | #include "src/core/SkMatrixProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 33 | #include "src/core/SkTLazy.h" |
| 34 | #include "src/gpu/SkGr.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 35 | |
| 36 | static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& rect) { |
| 37 | return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBounds, rect); |
| 38 | } |
| 39 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 40 | static constexpr auto kMaskOrigin = kTopLeft_GrSurfaceOrigin; |
| 41 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 42 | // Draw a mask using the supplied paint. Since the coverage/geometry |
| 43 | // is already burnt into the mask this boils down to a rect draw. |
| 44 | // Return true if the mask was successfully drawn. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 45 | static bool draw_mask(skgpu::v1::SurfaceDrawContext* sdc, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 46 | const GrClip* clip, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 47 | const SkMatrix& viewMatrix, |
Chris Dalton | 3561955 | 2021-03-10 19:20:43 -0700 | [diff] [blame] | 48 | const SkIRect& maskBounds, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 49 | GrPaint&& paint, |
Greg Daniel | 5c08249 | 2020-01-29 15:06:49 -0500 | [diff] [blame] | 50 | GrSurfaceProxyView mask) { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 51 | SkMatrix inverse; |
| 52 | if (!viewMatrix.invert(&inverse)) { |
| 53 | return false; |
| 54 | } |
Robert Phillips | 4a24da5 | 2016-12-14 09:00:07 -0500 | [diff] [blame] | 55 | |
Brian Salomon | b43d699 | 2021-01-05 14:37:40 -0500 | [diff] [blame] | 56 | mask.concatSwizzle(GrSwizzle("aaaa")); |
| 57 | |
Chris Dalton | 3561955 | 2021-03-10 19:20:43 -0700 | [diff] [blame] | 58 | SkMatrix matrix = SkMatrix::Translate(-SkIntToScalar(maskBounds.fLeft), |
| 59 | -SkIntToScalar(maskBounds.fTop)); |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 60 | matrix.preConcat(viewMatrix); |
John Stiles | 41d91b6 | 2020-07-21 14:39:40 -0400 | [diff] [blame] | 61 | paint.setCoverageFragmentProcessor( |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 62 | GrTextureEffect::Make(std::move(mask), kUnknown_SkAlphaType, matrix)); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 63 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 64 | sdc->fillPixelsWithLocalMatrix(clip, std::move(paint), maskBounds, inverse); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 65 | return true; |
| 66 | } |
| 67 | |
Robert Phillips | c7c2baf | 2018-03-08 09:51:04 -0500 | [diff] [blame] | 68 | static void mask_release_proc(void* addr, void* /*context*/) { |
| 69 | SkMask::FreeImage(addr); |
| 70 | } |
| 71 | |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 72 | // This stores the mapping from an unclipped, integerized, device-space, shape bounds to |
| 73 | // the filtered mask's draw rect. |
| 74 | struct DrawRectData { |
| 75 | SkIVector fOffset; |
| 76 | SkISize fSize; |
| 77 | }; |
| 78 | |
| 79 | static sk_sp<SkData> create_data(const SkIRect& drawRect, const SkIRect& origDevBounds) { |
| 80 | |
| 81 | DrawRectData drawRectData { {drawRect.fLeft - origDevBounds.fLeft, |
| 82 | drawRect.fTop - origDevBounds.fTop}, |
| 83 | drawRect.size() }; |
| 84 | |
| 85 | return SkData::MakeWithCopy(&drawRectData, sizeof(drawRectData)); |
| 86 | } |
| 87 | |
| 88 | static SkIRect extract_draw_rect_from_data(SkData* data, const SkIRect& origDevBounds) { |
| 89 | auto drawRectData = static_cast<const DrawRectData*>(data->data()); |
| 90 | |
| 91 | return SkIRect::MakeXYWH(origDevBounds.fLeft + drawRectData->fOffset.fX, |
| 92 | origDevBounds.fTop + drawRectData->fOffset.fY, |
| 93 | drawRectData->fSize.fWidth, |
| 94 | drawRectData->fSize.fHeight); |
| 95 | } |
| 96 | |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 97 | static GrSurfaceProxyView sw_create_filtered_mask(GrRecordingContext* rContext, |
| 98 | const SkMatrix& viewMatrix, |
| 99 | const GrStyledShape& shape, |
| 100 | const SkMaskFilter* filter, |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 101 | const SkIRect& unclippedDevShapeBounds, |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 102 | const SkIRect& clipBounds, |
| 103 | SkIRect* drawRect, |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 104 | GrUniqueKey* key) { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 105 | SkASSERT(filter); |
| 106 | SkASSERT(!shape.style().applies()); |
| 107 | |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 108 | auto threadSafeCache = rContext->priv().threadSafeCache(); |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 109 | |
Greg Daniel | 5c08249 | 2020-01-29 15:06:49 -0500 | [diff] [blame] | 110 | GrSurfaceProxyView filteredMaskView; |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 111 | sk_sp<SkData> data; |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 112 | |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 113 | if (key->isValid()) { |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 114 | std::tie(filteredMaskView, data) = threadSafeCache->findWithData(*key); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 117 | if (filteredMaskView) { |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 118 | SkASSERT(data); |
Robert Phillips | c73c1af | 2020-09-29 13:47:39 -0400 | [diff] [blame] | 119 | SkASSERT(kMaskOrigin == filteredMaskView.origin()); |
| 120 | |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 121 | *drawRect = extract_draw_rect_from_data(data.get(), unclippedDevShapeBounds); |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 122 | } else { |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 123 | SkStrokeRec::InitStyle fillOrHairline = shape.style().isSimpleHairline() |
| 124 | ? SkStrokeRec::kHairline_InitStyle |
| 125 | : SkStrokeRec::kFill_InitStyle; |
| 126 | |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 127 | // TODO: it seems like we could create an SkDraw here and set its fMatrix field rather |
| 128 | // than explicitly transforming the path to device space. |
| 129 | SkPath devPath; |
| 130 | |
| 131 | shape.asPath(&devPath); |
| 132 | |
| 133 | devPath.transform(viewMatrix); |
| 134 | |
| 135 | SkMask srcM, dstM; |
| 136 | if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM, |
| 137 | SkMask::kComputeBoundsAndRenderImage_CreateMode, fillOrHairline)) { |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 138 | return {}; |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 139 | } |
| 140 | SkAutoMaskFreeImage autoSrc(srcM.fImage); |
| 141 | |
| 142 | SkASSERT(SkMask::kA8_Format == srcM.fFormat); |
| 143 | |
| 144 | if (!as_MFB(filter)->filterMask(&dstM, srcM, viewMatrix, nullptr)) { |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 145 | return {}; |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 146 | } |
| 147 | // this will free-up dstM when we're done (allocated in filterMask()) |
| 148 | SkAutoMaskFreeImage autoDst(dstM.fImage); |
| 149 | |
| 150 | if (clip_bounds_quick_reject(clipBounds, dstM.fBounds)) { |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 151 | return {}; |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | // we now have a device-aligned 8bit mask in dstM, ready to be drawn using |
| 155 | // the current clip (and identity matrix) and GrPaint settings |
| 156 | SkBitmap bm; |
| 157 | if (!bm.installPixels(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.height()), |
| 158 | autoDst.release(), dstM.fRowBytes, mask_release_proc, nullptr)) { |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 159 | return {}; |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 160 | } |
| 161 | bm.setImmutable(); |
| 162 | |
Brian Salomon | 27c4202 | 2021-04-28 12:39:21 -0400 | [diff] [blame] | 163 | std::tie(filteredMaskView, std::ignore) = GrMakeUncachedBitmapProxyView( |
| 164 | rContext, |
| 165 | bm, |
| 166 | GrMipmapped::kNo, |
| 167 | SkBackingFit::kApprox); |
| 168 | if (!filteredMaskView) { |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 169 | return {}; |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 172 | SkASSERT(kMaskOrigin == filteredMaskView.origin()); |
Robert Phillips | 59b39e7 | 2018-08-30 11:51:25 -0400 | [diff] [blame] | 173 | |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 174 | *drawRect = dstM.fBounds; |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 175 | |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 176 | if (key->isValid()) { |
| 177 | key->setCustomData(create_data(*drawRect, unclippedDevShapeBounds)); |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 178 | std::tie(filteredMaskView, data) = threadSafeCache->addWithData(*key, filteredMaskView); |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 179 | // If we got a different view back from 'addWithData' it could have a different drawRect |
| 180 | *drawRect = extract_draw_rect_from_data(data.get(), unclippedDevShapeBounds); |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 181 | } |
Robert Phillips | 48ce22b | 2018-03-23 10:33:12 -0400 | [diff] [blame] | 182 | } |
Robert Phillips | c7c2baf | 2018-03-08 09:51:04 -0500 | [diff] [blame] | 183 | |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 184 | return filteredMaskView; |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Brian Salomon | 1aa1f5f | 2020-12-11 17:25:17 -0500 | [diff] [blame] | 187 | // Create a mask of 'shape' and return the resulting surfaceDrawContext |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 188 | static std::unique_ptr<skgpu::v1::SurfaceDrawContext> create_mask_GPU( |
| 189 | GrRecordingContext* rContext, |
| 190 | const SkIRect& maskRect, |
| 191 | const SkMatrix& origViewMatrix, |
| 192 | const GrStyledShape& shape, |
| 193 | int sampleCnt) { |
Chris Dalton | 92934d7 | 2021-04-23 09:08:53 -0600 | [diff] [blame] | 194 | // We cache blur masks. Use default surface props here so we can use the same cached mask |
| 195 | // regardless of the final dst surface. |
| 196 | SkSurfaceProps defaultSurfaceProps; |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 197 | |
Chris Dalton | 0493fbd | 2019-09-18 15:49:46 -0600 | [diff] [blame] | 198 | // Use GrResourceProvider::MakeApprox to implement our own approximate size matching, but demand |
| 199 | // a "SkBackingFit::kExact" size match on the actual render target. We do this because the |
| 200 | // filter will reach outside the src bounds, so we need to pre-clear these values to ensure a |
| 201 | // "decal" sampling effect (i.e., ensure reads outside the src bounds return alpha=0). |
| 202 | // |
| 203 | // FIXME: Reads outside the left and top edges will actually clamp to the edge pixel. And in the |
| 204 | // event that MakeApprox does not change the size, reads outside the right and/or bottom will do |
| 205 | // the same. We should offset our filter within the render target and expand the size as needed |
| 206 | // to guarantee at least 1px of padding on all sides. |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 207 | auto approxSize = GrResourceProvider::MakeApprox(maskRect.size()); |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 208 | auto sdc = skgpu::v1::SurfaceDrawContext::MakeWithFallback(rContext, |
| 209 | GrColorType::kAlpha_8, |
| 210 | nullptr, |
| 211 | SkBackingFit::kExact, |
| 212 | approxSize, |
| 213 | defaultSurfaceProps, |
| 214 | sampleCnt, |
| 215 | GrMipmapped::kNo, |
| 216 | GrProtected::kNo, |
| 217 | kMaskOrigin); |
| 218 | if (!sdc) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 219 | return nullptr; |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 222 | sdc->clear(SK_PMColor4fTRANSPARENT); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 223 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 224 | GrPaint maskPaint; |
| 225 | maskPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 226 | |
| 227 | // setup new clip |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 228 | GrFixedClip clip(sdc->dimensions(), SkIRect::MakeWH(maskRect.width(), maskRect.height())); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 229 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 230 | // Draw the mask into maskTexture with the path's integerized top-left at the origin using |
| 231 | // maskPaint. |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 232 | SkMatrix viewMatrix = origViewMatrix; |
| 233 | viewMatrix.postTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop)); |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 234 | sdc->drawShape(&clip, std::move(maskPaint), GrAA::kYes, viewMatrix, GrStyledShape(shape)); |
| 235 | return sdc; |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 238 | static bool get_unclipped_shape_dev_bounds(const GrStyledShape& shape, const SkMatrix& matrix, |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 239 | SkIRect* devBounds) { |
| 240 | SkRect shapeBounds = shape.styledBounds(); |
| 241 | if (shapeBounds.isEmpty()) { |
| 242 | return false; |
| 243 | } |
| 244 | SkRect shapeDevBounds; |
| 245 | matrix.mapRect(&shapeDevBounds, shapeBounds); |
| 246 | // Even though these are "unclipped" bounds we still clip to the int32_t range. |
| 247 | // This is the largest int32_t that is representable exactly as a float. The next 63 larger ints |
| 248 | // would round down to this value when cast to a float, but who really cares. |
| 249 | // INT32_MIN is exactly representable. |
| 250 | static constexpr int32_t kMaxInt = 2147483520; |
| 251 | if (!shapeDevBounds.intersect(SkRect::MakeLTRB(INT32_MIN, INT32_MIN, kMaxInt, kMaxInt))) { |
| 252 | return false; |
| 253 | } |
| 254 | // Make sure that the resulting SkIRect can have representable width and height |
| 255 | if (SkScalarRoundToInt(shapeDevBounds.width()) > kMaxInt || |
| 256 | SkScalarRoundToInt(shapeDevBounds.height()) > kMaxInt) { |
| 257 | return false; |
| 258 | } |
| 259 | shapeDevBounds.roundOut(devBounds); |
| 260 | return true; |
| 261 | } |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 262 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 263 | // Gets the shape bounds, the clip bounds, and the intersection (if any). Returns false if there |
| 264 | // is no intersection. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 265 | static bool get_shape_and_clip_bounds(skgpu::v1::SurfaceDrawContext* sdc, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 266 | const GrClip* clip, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 267 | const GrStyledShape& shape, |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 268 | const SkMatrix& matrix, |
| 269 | SkIRect* unclippedDevShapeBounds, |
| 270 | SkIRect* devClipBounds) { |
| 271 | // compute bounds as intersection of rt size, clip, and path |
Michael Ludwig | e06a897 | 2020-06-11 10:29:00 -0400 | [diff] [blame] | 272 | *devClipBounds = clip ? clip->getConservativeBounds() |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 273 | : SkIRect::MakeWH(sdc->width(), sdc->height()); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 274 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 275 | if (!get_unclipped_shape_dev_bounds(shape, matrix, unclippedDevShapeBounds)) { |
Brian Salomon | 44207f3 | 2020-01-06 15:20:18 -0500 | [diff] [blame] | 276 | *unclippedDevShapeBounds = SkIRect::MakeEmpty(); |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 277 | return false; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 280 | return true; |
| 281 | } |
| 282 | |
Robert Phillips | 52c17c4 | 2020-10-05 11:55:59 -0400 | [diff] [blame] | 283 | // The key and clip-bounds are computed together because the caching decision can impact the |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 284 | // clip-bound - since we only cache un-clipped masks the clip can be removed entirely. |
Robert Phillips | 52c17c4 | 2020-10-05 11:55:59 -0400 | [diff] [blame] | 285 | // A 'false' return value indicates that the shape is known to be clipped away. |
| 286 | static bool compute_key_and_clip_bounds(GrUniqueKey* maskKey, |
| 287 | SkIRect* boundsForClip, |
| 288 | const GrCaps* caps, |
| 289 | const SkMatrix& viewMatrix, |
| 290 | bool inverseFilled, |
| 291 | const SkMaskFilterBase* maskFilter, |
| 292 | const GrStyledShape& shape, |
| 293 | const SkIRect& unclippedDevShapeBounds, |
| 294 | const SkIRect& devClipBounds) { |
| 295 | *boundsForClip = devClipBounds; |
| 296 | |
| 297 | #ifndef SK_DISABLE_MASKFILTERED_MASK_CACHING |
| 298 | // To prevent overloading the cache with entries during animations we limit the cache of masks |
Robert Phillips | abf0353 | 2021-05-05 18:39:26 +0000 | [diff] [blame] | 299 | // to cases where the matrix preserves axis alignment. |
| 300 | bool useCache = !inverseFilled && viewMatrix.preservesAxisAlignment() && |
| 301 | shape.hasUnstyledKey() && as_MFB(maskFilter)->asABlur(nullptr); |
Robert Phillips | 52c17c4 | 2020-10-05 11:55:59 -0400 | [diff] [blame] | 302 | |
| 303 | if (useCache) { |
| 304 | SkIRect clippedMaskRect, unClippedMaskRect; |
| 305 | maskFilter->canFilterMaskGPU(shape, unclippedDevShapeBounds, devClipBounds, |
| 306 | viewMatrix, &clippedMaskRect); |
| 307 | maskFilter->canFilterMaskGPU(shape, unclippedDevShapeBounds, unclippedDevShapeBounds, |
| 308 | viewMatrix, &unClippedMaskRect); |
| 309 | if (clippedMaskRect.isEmpty()) { |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | // Use the cache only if >50% of the filtered mask is visible. |
| 314 | int unclippedWidth = unClippedMaskRect.width(); |
| 315 | int unclippedHeight = unClippedMaskRect.height(); |
| 316 | int64_t unclippedArea = sk_64_mul(unclippedWidth, unclippedHeight); |
| 317 | int64_t clippedArea = sk_64_mul(clippedMaskRect.width(), clippedMaskRect.height()); |
| 318 | int maxTextureSize = caps->maxTextureSize(); |
| 319 | if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize || |
| 320 | unclippedHeight > maxTextureSize) { |
| 321 | useCache = false; |
| 322 | } else { |
| 323 | // Make the clip not affect the mask |
| 324 | *boundsForClip = unclippedDevShapeBounds; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | if (useCache) { |
| 329 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 330 | GrUniqueKey::Builder builder(maskKey, kDomain, 5 + 2 + shape.unstyledKeySize(), |
| 331 | "Mask Filtered Masks"); |
| 332 | |
| 333 | // We require the upper left 2x2 of the matrix to match exactly for a cache hit. |
| 334 | SkScalar sx = viewMatrix.get(SkMatrix::kMScaleX); |
| 335 | SkScalar sy = viewMatrix.get(SkMatrix::kMScaleY); |
| 336 | SkScalar kx = viewMatrix.get(SkMatrix::kMSkewX); |
| 337 | SkScalar ky = viewMatrix.get(SkMatrix::kMSkewY); |
| 338 | SkScalar tx = viewMatrix.get(SkMatrix::kMTransX); |
| 339 | SkScalar ty = viewMatrix.get(SkMatrix::kMTransY); |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 340 | // Allow 8 bits each in x and y of subpixel positioning. But, note that we're allowing |
| 341 | // reuse for integer translations. |
Robert Phillips | 52c17c4 | 2020-10-05 11:55:59 -0400 | [diff] [blame] | 342 | SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00; |
| 343 | SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00; |
| 344 | |
| 345 | builder[0] = SkFloat2Bits(sx); |
| 346 | builder[1] = SkFloat2Bits(sy); |
| 347 | builder[2] = SkFloat2Bits(kx); |
| 348 | builder[3] = SkFloat2Bits(ky); |
| 349 | // Distinguish between hairline and filled paths. For hairlines, we also need to include |
| 350 | // the cap. (SW grows hairlines by 0.5 pixel with round and square caps). Note that |
| 351 | // stroke-and-fill of hairlines is turned into pure fill by SkStrokeRec, so this covers |
| 352 | // all cases we might see. |
| 353 | uint32_t styleBits = shape.style().isSimpleHairline() |
| 354 | ? ((shape.style().strokeRec().getCap() << 1) | 1) |
| 355 | : 0; |
| 356 | builder[4] = fracX | (fracY >> 8) | (styleBits << 16); |
| 357 | |
| 358 | SkMaskFilterBase::BlurRec rec; |
| 359 | SkAssertResult(as_MFB(maskFilter)->asABlur(&rec)); |
| 360 | |
| 361 | builder[5] = rec.fStyle; // TODO: we could put this with the other style bits |
| 362 | builder[6] = SkFloat2Bits(rec.fSigma); |
| 363 | shape.writeUnstyledKey(&builder[7]); |
| 364 | } |
| 365 | #endif |
| 366 | |
| 367 | return true; |
| 368 | } |
| 369 | |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 370 | static GrSurfaceProxyView hw_create_filtered_mask(GrDirectContext* dContext, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 371 | skgpu::v1::SurfaceDrawContext* sdc, |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 372 | const SkMatrix& viewMatrix, |
| 373 | const GrStyledShape& shape, |
| 374 | const SkMaskFilterBase* filter, |
| 375 | const SkIRect& unclippedDevShapeBounds, |
| 376 | const SkIRect& clipBounds, |
| 377 | SkIRect* maskRect, |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 378 | GrUniqueKey* key) { |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 379 | if (!filter->canFilterMaskGPU(shape, |
| 380 | unclippedDevShapeBounds, |
| 381 | clipBounds, |
| 382 | viewMatrix, |
| 383 | maskRect)) { |
| 384 | return {}; |
| 385 | } |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 386 | |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 387 | if (clip_bounds_quick_reject(clipBounds, *maskRect)) { |
| 388 | // clipped out |
| 389 | return {}; |
| 390 | } |
| 391 | |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 392 | auto threadSafeCache = dContext->priv().threadSafeCache(); |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 393 | |
| 394 | GrSurfaceProxyView lazyView; |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 395 | sk_sp<GrThreadSafeCache::Trampoline> trampoline; |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 396 | |
| 397 | if (key->isValid()) { |
| 398 | // In this case, we want GPU-filtered masks to have priority over SW-generated ones so |
| 399 | // we pre-emptively add a lazy-view to the cache and fill it in later. |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 400 | std::tie(lazyView, trampoline) = GrThreadSafeCache::CreateLazyView( |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 401 | dContext, GrColorType::kAlpha_8, maskRect->size(), |
| 402 | kMaskOrigin, SkBackingFit::kApprox); |
| 403 | if (!lazyView) { |
| 404 | return {}; // fall back to a SW-created mask - 'create_mask_GPU' probably won't succeed |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 405 | } |
| 406 | |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 407 | key->setCustomData(create_data(*maskRect, unclippedDevShapeBounds)); |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 408 | auto [cachedView, data] = threadSafeCache->findOrAddWithData(*key, lazyView); |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 409 | if (cachedView != lazyView) { |
| 410 | // In this case, the gpu-thread lost out to a recording thread - use its result. |
| 411 | SkASSERT(data); |
| 412 | SkASSERT(cachedView.asTextureProxy()); |
| 413 | SkASSERT(cachedView.origin() == kMaskOrigin); |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 414 | |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 415 | *maskRect = extract_draw_rect_from_data(data.get(), unclippedDevShapeBounds); |
| 416 | return cachedView; |
| 417 | } |
| 418 | } |
| 419 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 420 | std::unique_ptr<skgpu::v1::SurfaceDrawContext> maskSDC(create_mask_GPU(dContext, |
| 421 | *maskRect, |
| 422 | viewMatrix, |
| 423 | shape, |
| 424 | sdc->numSamples())); |
| 425 | if (!maskSDC) { |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 426 | if (key->isValid()) { |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 427 | // It is very unlikely that 'create_mask_GPU' will fail after 'CreateLazyView' |
| 428 | // succeeded but, if it does, remove the lazy-view from the cache and fallback to |
| 429 | // a SW-created mask. Note that any recording threads that glommed onto the |
| 430 | // lazy-view will have to, later, drop those draws. |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 431 | threadSafeCache->remove(*key); |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 432 | } |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 433 | return {}; |
| 434 | } |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 435 | |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 436 | auto filteredMaskView = filter->filterMaskGPU(dContext, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 437 | maskSDC->readSurfaceView(), |
| 438 | maskSDC->colorInfo().colorType(), |
| 439 | maskSDC->colorInfo().alphaType(), |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 440 | viewMatrix, |
| 441 | *maskRect); |
| 442 | if (!filteredMaskView) { |
| 443 | if (key->isValid()) { |
| 444 | // Remove the lazy-view from the cache and fallback to a SW-created mask. Note that |
| 445 | // any recording threads that glommed onto the lazy-view will have to, later, drop |
| 446 | // those draws. |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 447 | threadSafeCache->remove(*key); |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 448 | } |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 449 | return {}; |
| 450 | } |
| 451 | |
| 452 | if (key->isValid()) { |
| 453 | SkASSERT(filteredMaskView.dimensions() == lazyView.dimensions()); |
| 454 | SkASSERT(filteredMaskView.swizzle() == lazyView.swizzle()); |
| 455 | SkASSERT(filteredMaskView.origin() == lazyView.origin()); |
| 456 | |
| 457 | trampoline->fProxy = filteredMaskView.asTextureProxyRef(); |
| 458 | return lazyView; |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | return filteredMaskView; |
| 462 | } |
| 463 | |
| 464 | static void draw_shape_with_mask_filter(GrRecordingContext* rContext, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 465 | skgpu::v1::SurfaceDrawContext* sdc, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 466 | const GrClip* clip, |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 467 | GrPaint&& paint, |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 468 | const SkMatrix& viewMatrix, |
| 469 | const SkMaskFilterBase* maskFilter, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 470 | const GrStyledShape& origShape) { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 471 | SkASSERT(maskFilter); |
| 472 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 473 | const GrStyledShape* shape = &origShape; |
| 474 | SkTLazy<GrStyledShape> tmpShape; |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 475 | |
| 476 | if (origShape.style().applies()) { |
| 477 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); |
Robert Phillips | 2735837 | 2021-02-10 12:28:38 -0500 | [diff] [blame] | 478 | if (styleScale == 0) { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 479 | return; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 480 | } |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 481 | |
| 482 | tmpShape.init(origShape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale)); |
John Stiles | a008b0f | 2020-08-16 08:48:02 -0400 | [diff] [blame] | 483 | if (tmpShape->isEmpty()) { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 484 | return; |
| 485 | } |
| 486 | |
| 487 | shape = tmpShape.get(); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 488 | } |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 489 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 490 | if (maskFilter->directFilterMaskGPU(rContext, sdc, std::move(paint), clip, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 491 | viewMatrix, *shape)) { |
Robert Phillips | b889f20 | 2018-08-17 19:55:59 +0000 | [diff] [blame] | 492 | // the mask filter was able to draw itself directly, so there's nothing |
| 493 | // left to do. |
| 494 | return; |
| 495 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 496 | assert_alive(paint); |
Robert Phillips | b889f20 | 2018-08-17 19:55:59 +0000 | [diff] [blame] | 497 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 498 | // If the path is hairline, ignore inverse fill. |
| 499 | bool inverseFilled = shape->inverseFilled() && |
Robert Phillips | 62214f7 | 2021-06-15 10:12:51 -0400 | [diff] [blame] | 500 | !GrIsStrokeHairlineOrEquivalent(shape->style(), viewMatrix, nullptr); |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 501 | |
| 502 | SkIRect unclippedDevShapeBounds, devClipBounds; |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 503 | if (!get_shape_and_clip_bounds(sdc, clip, *shape, viewMatrix, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 504 | &unclippedDevShapeBounds, &devClipBounds)) { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 505 | // TODO: just cons up an opaque mask here |
| 506 | if (!inverseFilled) { |
| 507 | return; |
| 508 | } |
| 509 | } |
| 510 | |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 511 | GrUniqueKey maskKey; |
Robert Phillips | 52c17c4 | 2020-10-05 11:55:59 -0400 | [diff] [blame] | 512 | SkIRect boundsForClip; |
| 513 | if (!compute_key_and_clip_bounds(&maskKey, &boundsForClip, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 514 | sdc->caps(), |
Robert Phillips | 52c17c4 | 2020-10-05 11:55:59 -0400 | [diff] [blame] | 515 | viewMatrix, inverseFilled, |
| 516 | maskFilter, *shape, |
| 517 | unclippedDevShapeBounds, |
| 518 | devClipBounds)) { |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 519 | return; // 'shape' was entirely clipped out |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 520 | } |
| 521 | |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 522 | GrSurfaceProxyView filteredMaskView; |
Robert Phillips | 31c080b | 2018-08-23 10:45:32 -0400 | [diff] [blame] | 523 | SkIRect maskRect; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 524 | |
Robert Phillips | fde67e4 | 2020-10-07 15:33:43 -0400 | [diff] [blame] | 525 | if (auto dContext = rContext->asDirectContext()) { |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 526 | filteredMaskView = hw_create_filtered_mask(dContext, sdc, |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 527 | viewMatrix, *shape, maskFilter, |
| 528 | unclippedDevShapeBounds, boundsForClip, |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 529 | &maskRect, &maskKey); |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 530 | if (filteredMaskView) { |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 531 | if (draw_mask(sdc, clip, viewMatrix, maskRect, std::move(paint), |
Greg Daniel | 5c08249 | 2020-01-29 15:06:49 -0500 | [diff] [blame] | 532 | std::move(filteredMaskView))) { |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 533 | // This path is completely drawn |
| 534 | return; |
| 535 | } |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 536 | assert_alive(paint); |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 537 | } |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 540 | // Either HW mask rendering failed or we're in a DDL recording thread |
| 541 | filteredMaskView = sw_create_filtered_mask(rContext, |
| 542 | viewMatrix, *shape, maskFilter, |
Robert Phillips | 6e17ffe | 2020-10-06 14:52:11 -0400 | [diff] [blame] | 543 | unclippedDevShapeBounds, boundsForClip, |
| 544 | &maskRect, &maskKey); |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 545 | if (filteredMaskView) { |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 546 | if (draw_mask(sdc, clip, viewMatrix, maskRect, std::move(paint), |
Robert Phillips | c3bdd1c | 2020-10-05 13:17:09 -0400 | [diff] [blame] | 547 | std::move(filteredMaskView))) { |
| 548 | return; |
| 549 | } |
| 550 | assert_alive(paint); |
| 551 | } |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 554 | void GrBlurUtils::drawShapeWithMaskFilter(GrRecordingContext* rContext, |
| 555 | skgpu::v1::SurfaceDrawContext* sdc, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 556 | const GrClip* clip, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 557 | const GrStyledShape& shape, |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 558 | GrPaint&& paint, |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 559 | const SkMatrix& viewMatrix, |
| 560 | const SkMaskFilter* mf) { |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 561 | draw_shape_with_mask_filter(rContext, sdc, clip, std::move(paint), |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 562 | viewMatrix, as_MFB(mf), shape); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 565 | void GrBlurUtils::drawShapeWithMaskFilter(GrRecordingContext* rContext, |
| 566 | skgpu::v1::SurfaceDrawContext* sdc, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 567 | const GrClip* clip, |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 568 | const SkPaint& paint, |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 569 | const SkMatrixProvider& matrixProvider, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 570 | const GrStyledShape& shape) { |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 571 | if (rContext->abandoned()) { |
Robert Phillips | bebfd41 | 2018-03-08 11:07:23 -0500 | [diff] [blame] | 572 | return; |
| 573 | } |
| 574 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 575 | GrPaint grPaint; |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 576 | if (!SkPaintToGrPaint(rContext, sdc->colorInfo(), paint, matrixProvider, &grPaint)) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 577 | return; |
| 578 | } |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 579 | |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 580 | const SkMatrix& viewMatrix(matrixProvider.localToDevice()); |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 581 | SkMaskFilterBase* mf = as_MFB(paint.getMaskFilter()); |
Mike Reed | bfadcf0 | 2018-01-20 22:24:21 +0000 | [diff] [blame] | 582 | if (mf && !mf->hasFragmentProcessor()) { |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 583 | // The MaskFilter wasn't already handled in SkPaintToGrPaint |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 584 | draw_shape_with_mask_filter(rContext, sdc, clip, std::move(grPaint), viewMatrix, mf, shape); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 585 | } else { |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 586 | sdc->drawShape(clip, std::move(grPaint), sdc->chooseAA(paint), viewMatrix, |
| 587 | GrStyledShape(shape)); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 588 | } |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 589 | } |
Robert Phillips | 11bc305 | 2021-06-21 09:25:11 -0400 | [diff] [blame] | 590 | |
Robert Phillips | 7cef678 | 2021-07-01 13:21:37 -0400 | [diff] [blame] | 591 | #else // SK_GPU_V1 |
Robert Phillips | 11bc305 | 2021-06-21 09:25:11 -0400 | [diff] [blame] | 592 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 593 | void GrBlurUtils::drawShapeWithMaskFilter(GrRecordingContext*, |
| 594 | skgpu::v1::SurfaceDrawContext*, |
| 595 | const GrClip*, |
| 596 | const GrStyledShape&, |
| 597 | GrPaint&&, |
Robert Phillips | 11bc305 | 2021-06-21 09:25:11 -0400 | [diff] [blame] | 598 | const SkMatrix& viewMatrix, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 599 | const SkMaskFilter*) { |
Robert Phillips | 11bc305 | 2021-06-21 09:25:11 -0400 | [diff] [blame] | 600 | } |
| 601 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 602 | void GrBlurUtils::drawShapeWithMaskFilter(GrRecordingContext*, |
| 603 | skgpu::v1::SurfaceDrawContext*, |
| 604 | const GrClip*, |
| 605 | const SkPaint&, |
| 606 | const SkMatrixProvider&, |
| 607 | const GrStyledShape&) { |
Robert Phillips | 11bc305 | 2021-06-21 09:25:11 -0400 | [diff] [blame] | 608 | } |
| 609 | |
Robert Phillips | 7cef678 | 2021-07-01 13:21:37 -0400 | [diff] [blame] | 610 | #endif // SK_GPU_V1 |