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 |
| 13 | #include "SkTypes.h" |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 14 | |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 15 | #include "GrCaps.h" |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 16 | #include "GrClip.h" |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 17 | #include "GrPaint.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 18 | #include "GrProxyProvider.h" |
Robert Phillips | 7af8fe5 | 2019-02-14 17:27:00 -0500 | [diff] [blame] | 19 | #include "GrRecordingContext.h" |
| 20 | #include "GrRecordingContextPriv.h" |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 21 | #include "GrRenderTargetContext.h" |
| 22 | #include "GrStyle.h" |
| 23 | #include "SkBlurMaskFilter.h" |
Mike Reed | 28d4773 | 2018-03-05 16:56:52 -0500 | [diff] [blame] | 24 | #include "SkBlurPriv.h" |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 25 | #include "SkGpuBlurUtils.h" |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 26 | #include "SkRRectPriv.h" |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 27 | #include "GrFragmentProcessor.h" |
| 28 | #include "GrCoordTransform.h" |
| 29 | class GrRRectBlurEffect : public GrFragmentProcessor { |
| 30 | public: |
Robert Phillips | 7af8fe5 | 2019-02-14 17:27:00 -0500 | [diff] [blame] | 31 | static sk_sp<GrTextureProxy> find_or_create_rrect_blur_mask(GrRecordingContext* context, |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 32 | const SkRRect& rrectToDraw, |
| 33 | const SkISize& size, |
| 34 | float xformedSigma) { |
| 35 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 36 | GrUniqueKey key; |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 37 | GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask"); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 38 | builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f); |
| 39 | |
| 40 | int index = 1; |
| 41 | for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner, |
| 42 | SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) { |
| 43 | SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) && |
| 44 | SkScalarIsInt(rrectToDraw.radii(c).fY)); |
| 45 | builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX); |
| 46 | builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY); |
| 47 | } |
| 48 | builder.finish(); |
| 49 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 50 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 51 | |
Robert Phillips | 579f094 | 2018-01-08 14:53:35 -0500 | [diff] [blame] | 52 | sk_sp<GrTextureProxy> mask( |
| 53 | proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin)); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 54 | if (!mask) { |
Robert Phillips | f7c6dfa | 2019-02-05 07:46:49 -0500 | [diff] [blame] | 55 | GrBackendFormat format = |
| 56 | context->priv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 57 | // TODO: this could be approx but the texture coords will need to be updated |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 58 | sk_sp<GrRenderTargetContext> rtc( |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 59 | context->priv().makeDeferredRenderTargetContextWithFallback( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 60 | format, SkBackingFit::kExact, size.fWidth, size.fHeight, |
| 61 | kAlpha_8_GrPixelConfig, nullptr)); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 62 | if (!rtc) { |
| 63 | return nullptr; |
| 64 | } |
| 65 | |
| 66 | GrPaint paint; |
| 67 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 68 | rtc->clear(nullptr, SK_PMColor4fTRANSPARENT, |
| 69 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 70 | rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, |
| 71 | GrStyle::SimpleFill()); |
| 72 | |
| 73 | sk_sp<GrTextureProxy> srcProxy(rtc->asTextureProxyRef()); |
| 74 | if (!srcProxy) { |
| 75 | return nullptr; |
| 76 | } |
| 77 | sk_sp<GrRenderTargetContext> rtc2( |
| 78 | SkGpuBlurUtils::GaussianBlur(context, |
| 79 | std::move(srcProxy), |
| 80 | nullptr, |
| 81 | SkIRect::MakeWH(size.fWidth, size.fHeight), |
| 82 | SkIRect::EmptyIRect(), |
| 83 | xformedSigma, |
| 84 | xformedSigma, |
| 85 | GrTextureDomain::kIgnore_Mode, |
Robert Phillips | 213ce18 | 2018-04-25 09:13:28 -0400 | [diff] [blame] | 86 | kPremul_SkAlphaType, |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 87 | SkBackingFit::kExact)); |
| 88 | if (!rtc2) { |
| 89 | return nullptr; |
| 90 | } |
| 91 | |
| 92 | mask = rtc2->asTextureProxyRef(); |
| 93 | if (!mask) { |
| 94 | return nullptr; |
| 95 | } |
| 96 | SkASSERT(mask->origin() == kBottomLeft_GrSurfaceOrigin); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 97 | proxyProvider->assignUniqueKeyToProxy(key, mask.get()); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | return mask; |
| 101 | } |
| 102 | float sigma() const { return fSigma; } |
Michael Ludwig | a427559 | 2018-08-31 10:52:47 -0400 | [diff] [blame] | 103 | const SkRect& rect() const { return fRect; } |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 104 | float cornerRadius() const { return fCornerRadius; } |
| 105 | |
Robert Phillips | 7af8fe5 | 2019-02-14 17:27:00 -0500 | [diff] [blame] | 106 | static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context, |
| 107 | float sigma, |
| 108 | float xformedSigma, |
| 109 | const SkRRect& srcRRect, |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 110 | const SkRRect& devRRect); |
| 111 | GrRRectBlurEffect(const GrRRectBlurEffect& src); |
| 112 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
| 113 | const char* name() const override { return "RRectBlurEffect"; } |
| 114 | |
| 115 | private: |
| 116 | GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius, |
| 117 | sk_sp<GrTextureProxy> ninePatchSampler) |
| 118 | : INHERITED(kGrRRectBlurEffect_ClassID, |
| 119 | (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag) |
| 120 | , fSigma(sigma) |
| 121 | , fRect(rect) |
| 122 | , fCornerRadius(cornerRadius) |
| 123 | , fNinePatchSampler(std::move(ninePatchSampler)) { |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 124 | this->setTextureSamplerCnt(1); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 125 | } |
| 126 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 127 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 128 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 129 | const TextureSampler& onTextureSampler(int) const override; |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 130 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
| 131 | float fSigma; |
| 132 | SkRect fRect; |
| 133 | float fCornerRadius; |
| 134 | TextureSampler fNinePatchSampler; |
| 135 | typedef GrFragmentProcessor INHERITED; |
| 136 | }; |
| 137 | #endif |