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