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