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" |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 14 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "include/gpu/GrContext.h" |
| 16 | #include "include/private/GrRecordingContext.h" |
| 17 | #include "src/core/SkBlurPriv.h" |
| 18 | #include "src/core/SkGpuBlurUtils.h" |
| 19 | #include "src/core/SkRRectPriv.h" |
| 20 | #include "src/gpu/GrCaps.h" |
| 21 | #include "src/gpu/GrClip.h" |
| 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: |
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, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 33 | const SkRRect& rrectToDraw, |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 34 | const SkISize& dimensions, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 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 | |
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 | |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame] | 53 | sk_sp<GrTextureProxy> mask(proxyProvider->findOrCreateProxyByUniqueKey( |
| 54 | key, GrColorType::kAlpha_8, kBottomLeft_GrSurfaceOrigin)); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 55 | if (!mask) { |
Chris Dalton | 0493fbd | 2019-09-18 15:49:46 -0600 | [diff] [blame] | 56 | // TODO: this could be SkBackingFit::kApprox, but: |
| 57 | // 1) The texture coords would need to be updated. |
| 58 | // 2) We would have to use GrTextureDomain::kClamp_Mode for the GaussianBlur. |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 59 | auto rtc = context->priv().makeDeferredRenderTargetContextWithFallback( |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 60 | SkBackingFit::kExact, dimensions.fWidth, dimensions.fHeight, |
| 61 | GrColorType::kAlpha_8, 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 | |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 68 | rtc->clear(nullptr, SK_PMColor4fTRANSPARENT, |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 69 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 70 | rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 71 | GrStyle::SimpleFill()); |
| 72 | |
| 73 | sk_sp<GrTextureProxy> srcProxy(rtc->asTextureProxyRef()); |
| 74 | if (!srcProxy) { |
| 75 | return nullptr; |
| 76 | } |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 77 | auto rtc2 = SkGpuBlurUtils::GaussianBlur(context, |
| 78 | std::move(srcProxy), |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 79 | rtc->colorInfo().colorType(), |
| 80 | rtc->colorInfo().alphaType(), |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 81 | SkIPoint::Make(0, 0), |
| 82 | nullptr, |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 83 | SkIRect::MakeSize(dimensions), |
Brian Salomon | 44207f3 | 2020-01-06 15:20:18 -0500 | [diff] [blame^] | 84 | SkIRect::MakeEmpty(), |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 85 | xformedSigma, |
| 86 | xformedSigma, |
| 87 | GrTextureDomain::kIgnore_Mode, |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 88 | SkBackingFit::kExact); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 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 | } |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 103 | |
Robert Phillips | 7af8fe5 | 2019-02-14 17:27:00 -0500 | [diff] [blame] | 104 | static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 105 | float sigma, |
| 106 | float xformedSigma, |
| 107 | const SkRRect& srcRRect, |
| 108 | const SkRRect& devRRect); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 109 | GrRRectBlurEffect(const GrRRectBlurEffect& src); |
| 110 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 111 | const char* name() const override { return "RRectBlurEffect"; } |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 112 | float sigma; |
| 113 | SkRect rect; |
| 114 | float cornerRadius; |
| 115 | TextureSampler ninePatchSampler; |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 116 | |
| 117 | private: |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 118 | GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius, |
Michael Ludwig | 8fa469d | 2019-11-25 16:08:44 -0500 | [diff] [blame] | 119 | sk_sp<GrSurfaceProxy> ninePatchSampler) |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 120 | : INHERITED(kGrRRectBlurEffect_ClassID, |
| 121 | (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 122 | , sigma(sigma) |
| 123 | , rect(rect) |
| 124 | , cornerRadius(cornerRadius) |
| 125 | , ninePatchSampler(std::move(ninePatchSampler)) { |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 126 | this->setTextureSamplerCnt(1); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 127 | } |
| 128 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 129 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 130 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 131 | const TextureSampler& onTextureSampler(int) const override; |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 132 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 133 | typedef GrFragmentProcessor INHERITED; |
| 134 | }; |
| 135 | #endif |