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 | b26b4e7 | 2020-01-22 14:31:21 -0500 | [diff] [blame] | 14 | #include "include/private/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" |
| 22 | #include "src/gpu/GrClip.h" |
| 23 | #include "src/gpu/GrPaint.h" |
| 24 | #include "src/gpu/GrProxyProvider.h" |
| 25 | #include "src/gpu/GrRecordingContextPriv.h" |
| 26 | #include "src/gpu/GrRenderTargetContext.h" |
| 27 | #include "src/gpu/GrStyle.h" |
| 28 | |
| 29 | #include "src/gpu/GrCoordTransform.h" |
| 30 | #include "src/gpu/GrFragmentProcessor.h" |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 31 | class GrRRectBlurEffect : public GrFragmentProcessor { |
| 32 | public: |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 33 | static GrSurfaceProxyView find_or_create_rrect_blur_mask(GrRecordingContext* context, |
| 34 | const SkRRect& rrectToDraw, |
| 35 | const SkISize& dimensions, |
| 36 | float xformedSigma) { |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 37 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 38 | GrUniqueKey key; |
| 39 | GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask"); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 40 | builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f); |
| 41 | |
| 42 | int index = 1; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 43 | for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner, |
| 44 | SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) { |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 45 | SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) && |
| 46 | SkScalarIsInt(rrectToDraw.radii(c).fY)); |
| 47 | builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX); |
| 48 | builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY); |
| 49 | } |
| 50 | builder.finish(); |
| 51 | |
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 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame^] | 54 | if (sk_sp<GrTextureProxy> mask = |
| 55 | proxyProvider->findOrCreateProxyByUniqueKey(key, GrColorType::kAlpha_8)) { |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 56 | GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(mask->backendFormat(), |
| 57 | GrColorType::kAlpha_8); |
| 58 | return {std::move(mask), kBottomLeft_GrSurfaceOrigin, swizzle}; |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Greg Daniel | 4395612 | 2020-02-11 15:49:27 -0500 | [diff] [blame] | 61 | auto rtc = GrRenderTargetContext::MakeWithFallback(context, GrColorType::kAlpha_8, nullptr, |
| 62 | SkBackingFit::kExact, dimensions); |
| 63 | if (!rtc) { |
| 64 | return {}; |
| 65 | } |
| 66 | |
| 67 | GrPaint paint; |
| 68 | |
| 69 | rtc->clear(nullptr, SK_PMColor4fTRANSPARENT, |
| 70 | GrRenderTargetContext::CanClearFullscreen::kYes); |
| 71 | rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, |
| 72 | GrStyle::SimpleFill()); |
| 73 | |
| 74 | GrSurfaceProxyView srcView = rtc->readSurfaceView(); |
| 75 | if (!srcView) { |
| 76 | return {}; |
| 77 | } |
| 78 | SkASSERT(srcView.asTextureProxy()); |
| 79 | auto rtc2 = SkGpuBlurUtils::GaussianBlur(context, |
| 80 | std::move(srcView), |
| 81 | rtc->colorInfo().colorType(), |
| 82 | rtc->colorInfo().alphaType(), |
| 83 | nullptr, |
| 84 | SkIRect::MakeSize(dimensions), |
| 85 | SkIRect::MakeSize(dimensions), |
| 86 | xformedSigma, |
| 87 | xformedSigma, |
| 88 | SkTileMode::kClamp, |
| 89 | SkBackingFit::kExact); |
| 90 | if (!rtc2) { |
| 91 | return {}; |
| 92 | } |
| 93 | |
| 94 | GrSurfaceProxyView mask = rtc2->readSurfaceView(); |
| 95 | if (!mask) { |
| 96 | return {}; |
| 97 | } |
| 98 | SkASSERT(mask.asTextureProxy()); |
| 99 | SkASSERT(mask.origin() == kBottomLeft_GrSurfaceOrigin); |
| 100 | proxyProvider->assignUniqueKeyToProxy(key, mask.asTextureProxy()); |
| 101 | |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 102 | return mask; |
| 103 | } |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 104 | |
Robert Phillips | 7af8fe5 | 2019-02-14 17:27:00 -0500 | [diff] [blame] | 105 | static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 106 | float sigma, |
| 107 | float xformedSigma, |
| 108 | const SkRRect& srcRRect, |
| 109 | const SkRRect& devRRect); |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 110 | GrRRectBlurEffect(const GrRRectBlurEffect& src); |
| 111 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 112 | const char* name() const override { return "RRectBlurEffect"; } |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 113 | float sigma; |
| 114 | SkRect rect; |
| 115 | float cornerRadius; |
| 116 | TextureSampler ninePatchSampler; |
Ethan Nicholas | 297d6ef | 2017-12-20 12:00:11 -0500 | [diff] [blame] | 117 | |
| 118 | private: |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 119 | GrRRectBlurEffect(float sigma, SkRect rect, 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 |