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