Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 1 | /* |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 2 | * Copyright 2018 Google Inc. |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 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 | |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 8 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrRRectBlurEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 11 | #ifndef GrRRectBlurEffect_DEFINED |
| 12 | #define GrRRectBlurEffect_DEFINED |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame] | 13 | |
Mike Reed | 46f5c5f | 2020-02-20 15:42:29 -0500 | [diff] [blame] | 14 | #include "include/core/SkM44.h" |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame] | 15 | #include "include/core/SkTypes.h" |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 16 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "include/gpu/GrContext.h" |
| 18 | #include "include/private/GrRecordingContext.h" |
| 19 | #include "src/core/SkBlurPriv.h" |
| 20 | #include "src/core/SkGpuBlurUtils.h" |
| 21 | #include "src/core/SkRRectPriv.h" |
| 22 | #include "src/gpu/GrCaps.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrPaint.h" |
| 24 | #include "src/gpu/GrProxyProvider.h" |
| 25 | #include "src/gpu/GrRecordingContextPriv.h" |
| 26 | #include "src/gpu/GrRenderTargetContext.h" |
| 27 | #include "src/gpu/GrStyle.h" |
| 28 | |
| 29 | #include "src/gpu/GrCoordTransform.h" |
| 30 | #include "src/gpu/GrFragmentProcessor.h" |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame] | 31 | |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 32 | class GrRRectBlurEffect : public GrFragmentProcessor { |
| 33 | public: |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 34 | static GrSurfaceProxyView find_or_create_rrect_blur_mask(GrRecordingContext* context, |
| 35 | const SkRRect& rrectToDraw, |
| 36 | const SkISize& dimensions, |
| 37 | float xformedSigma) { |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 38 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 39 | GrUniqueKey key; |
| 40 | GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask"); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 41 | builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f); |
| 42 | |
| 43 | int index = 1; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 44 | for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner, |
| 45 | SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) { |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 46 | SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) && |
| 47 | SkScalarIsInt(rrectToDraw.radii(c).fY)); |
| 48 | builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX); |
| 49 | builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY); |
| 50 | } |
| 51 | builder.finish(); |
| 52 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 53 | static constexpr auto kMaskOrigin = kBottomLeft_GrSurfaceOrigin; |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 54 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 55 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 56 | if (auto view = proxyProvider->findCachedProxyWithColorTypeFallback( |
Brian Salomon | 0029db0 | 2020-04-03 10:41:24 -0400 | [diff] [blame] | 57 | key, kMaskOrigin, GrColorType::kAlpha_8, 1)) { |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 58 | return view; |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 61 | auto rtc = GrRenderTargetContext::MakeWithFallback( |
| 62 | context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions, 1, |
| 63 | GrMipMapped::kNo, GrProtected::kNo, kMaskOrigin); |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 64 | if (!rtc) { |
| 65 | return {}; |
| 66 | } |
| 67 | |
| 68 | GrPaint paint; |
| 69 | |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 70 | rtc->clear(SK_PMColor4fTRANSPARENT); |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 71 | rtc->drawRRect(nullptr, std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 72 | GrStyle::SimpleFill()); |
| 73 | |
| 74 | GrSurfaceProxyView srcView = rtc->readSurfaceView(); |
| 75 | if (!srcView) { |
| 76 | return {}; |
| 77 | } |
| 78 | SkASSERT(srcView.asTextureProxy()); |
| 79 | auto rtc2 = SkGpuBlurUtils::GaussianBlur(context, |
| 80 | std::move(srcView), |
| 81 | rtc->colorInfo().colorType(), |
| 82 | rtc->colorInfo().alphaType(), |
| 83 | nullptr, |
| 84 | SkIRect::MakeSize(dimensions), |
| 85 | SkIRect::MakeSize(dimensions), |
| 86 | xformedSigma, |
| 87 | xformedSigma, |
| 88 | SkTileMode::kClamp, |
| 89 | SkBackingFit::kExact); |
| 90 | if (!rtc2) { |
| 91 | return {}; |
| 92 | } |
| 93 | |
| 94 | GrSurfaceProxyView mask = rtc2->readSurfaceView(); |
| 95 | if (!mask) { |
| 96 | return {}; |
| 97 | } |
| 98 | SkASSERT(mask.asTextureProxy()); |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 99 | SkASSERT(mask.origin() == kMaskOrigin); |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 100 | proxyProvider->assignUniqueKeyToProxy(key, mask.asTextureProxy()); |
| 101 | |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 102 | return mask; |
| 103 | } |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 104 | |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 105 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP, |
| 106 | GrRecordingContext* context, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 107 | float sigma, |
| 108 | float xformedSigma, |
| 109 | const SkRRect& srcRRect, |
| 110 | const SkRRect& devRRect); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 111 | GrRRectBlurEffect(const GrRRectBlurEffect& src); |
| 112 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 113 | const char* name() const override { return "RRectBlurEffect"; } |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 114 | int inputFP_index = -1; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 115 | float sigma; |
| 116 | SkRect rect; |
| 117 | float cornerRadius; |
| 118 | TextureSampler ninePatchSampler; |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 119 | |
| 120 | private: |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 121 | GrRRectBlurEffect(std::unique_ptr<GrFragmentProcessor> inputFP, |
| 122 | float sigma, |
Brian Osman | ff0717f | 2020-03-27 11:08:38 -0400 | [diff] [blame] | 123 | SkRect rect, |
| 124 | float cornerRadius, |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 125 | GrSurfaceProxyView ninePatchSampler) |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 126 | : INHERITED(kGrRRectBlurEffect_ClassID, |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 127 | (OptimizationFlags)(inputFP ? ProcessorOptimizationFlags(inputFP.get()) |
| 128 | : kAll_OptimizationFlags) & |
| 129 | kCompatibleWithCoverageAsAlpha_OptimizationFlag) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 130 | , sigma(sigma) |
| 131 | , rect(rect) |
| 132 | , cornerRadius(cornerRadius) |
| 133 | , ninePatchSampler(std::move(ninePatchSampler)) { |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 134 | if (inputFP) { |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame] | 135 | inputFP_index = this->registerChildProcessor(std::move(inputFP)); |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 136 | } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 137 | this->setTextureSamplerCnt(1); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 138 | } |
| 139 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 140 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 141 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 142 | const TextureSampler& onTextureSampler(int) const override; |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 143 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 144 | typedef GrFragmentProcessor INHERITED; |
| 145 | }; |
| 146 | #endif |