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" |
Brian Salomon | 99b0470 | 2020-06-18 10:12:47 -0400 | [diff] [blame^] | 28 | #include "src/gpu/effects/GrTextureEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 29 | |
| 30 | #include "src/gpu/GrCoordTransform.h" |
| 31 | #include "src/gpu/GrFragmentProcessor.h" |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame] | 32 | |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 33 | class GrRRectBlurEffect : public GrFragmentProcessor { |
| 34 | public: |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 35 | static std::unique_ptr<GrFragmentProcessor> find_or_create_rrect_blur_mask_fp( |
| 36 | GrRecordingContext* context, |
| 37 | const SkRRect& rrectToDraw, |
| 38 | const SkISize& dimensions, |
| 39 | float xformedSigma) { |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 40 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 41 | GrUniqueKey key; |
| 42 | GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask"); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 43 | builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f); |
| 44 | |
| 45 | int index = 1; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 46 | for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner, |
| 47 | SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) { |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 48 | SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) && |
| 49 | SkScalarIsInt(rrectToDraw.radii(c).fY)); |
| 50 | builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX); |
| 51 | builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY); |
| 52 | } |
| 53 | builder.finish(); |
| 54 | |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 55 | // It seems like we could omit this matrix and modify the shader code to not normalize |
| 56 | // the coords used to sample the texture effect. However, the "proxyDims" value in the |
| 57 | // shader is not always the actual the proxy dimensions. This is because 'dimensions' here |
| 58 | // was computed using integer corner radii as determined in |
| 59 | // SkComputeBlurredRRectParams whereas the shader code uses the float radius to compute |
| 60 | // 'proxyDims'. Why it draws correctly with these unequal values is a mystery for the ages. |
| 61 | auto m = SkMatrix::Scale(dimensions.width(), dimensions.height()); |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 62 | static constexpr auto kMaskOrigin = kBottomLeft_GrSurfaceOrigin; |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 63 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 64 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 65 | if (auto view = proxyProvider->findCachedProxyWithColorTypeFallback( |
Brian Salomon | 0029db0 | 2020-04-03 10:41:24 -0400 | [diff] [blame] | 66 | key, kMaskOrigin, GrColorType::kAlpha_8, 1)) { |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 67 | return GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, m); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Brian Salomon | d005b69 | 2020-04-01 15:47:05 -0400 | [diff] [blame] | 70 | auto rtc = GrRenderTargetContext::MakeWithFallback( |
| 71 | context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions, 1, |
| 72 | GrMipMapped::kNo, GrProtected::kNo, kMaskOrigin); |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 73 | if (!rtc) { |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 74 | return nullptr; |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | GrPaint paint; |
| 78 | |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 79 | rtc->clear(SK_PMColor4fTRANSPARENT); |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 80 | rtc->drawRRect(nullptr, std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 81 | GrStyle::SimpleFill()); |
| 82 | |
| 83 | GrSurfaceProxyView srcView = rtc->readSurfaceView(); |
| 84 | if (!srcView) { |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 85 | return nullptr; |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 86 | } |
| 87 | SkASSERT(srcView.asTextureProxy()); |
| 88 | auto rtc2 = SkGpuBlurUtils::GaussianBlur(context, |
| 89 | std::move(srcView), |
| 90 | rtc->colorInfo().colorType(), |
| 91 | rtc->colorInfo().alphaType(), |
| 92 | nullptr, |
| 93 | SkIRect::MakeSize(dimensions), |
| 94 | SkIRect::MakeSize(dimensions), |
| 95 | xformedSigma, |
| 96 | xformedSigma, |
| 97 | SkTileMode::kClamp, |
| 98 | SkBackingFit::kExact); |
| 99 | if (!rtc2) { |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 100 | return nullptr; |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | GrSurfaceProxyView mask = rtc2->readSurfaceView(); |
| 104 | if (!mask) { |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 105 | return nullptr; |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 106 | } |
| 107 | SkASSERT(mask.asTextureProxy()); |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 108 | SkASSERT(mask.origin() == kMaskOrigin); |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 109 | proxyProvider->assignUniqueKeyToProxy(key, mask.asTextureProxy()); |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 110 | return GrTextureEffect::Make(std::move(mask), kPremul_SkAlphaType, m); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 111 | } |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 112 | |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 113 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP, |
| 114 | GrRecordingContext* context, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 115 | float sigma, |
| 116 | float xformedSigma, |
| 117 | const SkRRect& srcRRect, |
| 118 | const SkRRect& devRRect); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 119 | GrRRectBlurEffect(const GrRRectBlurEffect& src); |
| 120 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 121 | const char* name() const override { return "RRectBlurEffect"; } |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 122 | int inputFP_index = -1; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 123 | float sigma; |
| 124 | SkRect rect; |
| 125 | float cornerRadius; |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 126 | int ninePatchFP_index = -1; |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 127 | |
| 128 | private: |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 129 | GrRRectBlurEffect(std::unique_ptr<GrFragmentProcessor> inputFP, |
| 130 | float sigma, |
Brian Osman | ff0717f | 2020-03-27 11:08:38 -0400 | [diff] [blame] | 131 | SkRect rect, |
| 132 | float cornerRadius, |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 133 | std::unique_ptr<GrFragmentProcessor> ninePatchFP) |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 134 | : INHERITED(kGrRRectBlurEffect_ClassID, |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 135 | (OptimizationFlags)(inputFP ? ProcessorOptimizationFlags(inputFP.get()) |
| 136 | : kAll_OptimizationFlags) & |
| 137 | kCompatibleWithCoverageAsAlpha_OptimizationFlag) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 138 | , sigma(sigma) |
| 139 | , rect(rect) |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 140 | , cornerRadius(cornerRadius) { |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 141 | if (inputFP) { |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame] | 142 | inputFP_index = this->registerChildProcessor(std::move(inputFP)); |
John Stiles | 4ca8884 | 2020-06-08 17:20:01 -0400 | [diff] [blame] | 143 | } |
Brian Salomon | 71f6cfd | 2020-06-17 17:14:12 -0400 | [diff] [blame] | 144 | SkASSERT(ninePatchFP); |
| 145 | ninePatchFP->setSampledWithExplicitCoords(); |
| 146 | ninePatchFP_index = this->registerChildProcessor(std::move(ninePatchFP)); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 147 | } |
| 148 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 149 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 150 | bool onIsEqual(const GrFragmentProcessor&) const override; |
| 151 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 152 | typedef GrFragmentProcessor INHERITED; |
| 153 | }; |
| 154 | #endif |