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