1 /* 2 * Copyright 2018 Google Inc. 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 8 /************************************************************************************************** 9 *** This file was autogenerated from GrRRectBlurEffect.fp; do not modify. 10 **************************************************************************************************/ 11 #ifndef GrRRectBlurEffect_DEFINED 12 #define GrRRectBlurEffect_DEFINED 13 #include "SkTypes.h" 14 15 #include "GrClip.h" 16 #include "GrContext.h" 17 #include "GrContextPriv.h" 18 #include "GrPaint.h" 19 #include "GrProxyProvider.h" 20 #include "GrRenderTargetContext.h" 21 #include "GrStyle.h" 22 #include "SkBlurMaskFilter.h" 23 #include "SkBlurPriv.h" 24 #include "SkGpuBlurUtils.h" 25 #include "SkRRectPriv.h" 26 #include "GrFragmentProcessor.h" 27 #include "GrCoordTransform.h" 28 class GrRRectBlurEffect : public GrFragmentProcessor { 29 public: find_or_create_rrect_blur_mask(GrContext * context,const SkRRect & rrectToDraw,const SkISize & size,float xformedSigma)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; 36 GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask"); 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 49 GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); 50 51 sk_sp<GrTextureProxy> mask( 52 proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin)); 53 if (!mask) { 54 GrBackendFormat format = context->contextPriv().caps()->getBackendFormatFromColorType( 55 kAlpha_8_SkColorType); 56 // TODO: this could be approx but the texture coords will need to be updated 57 sk_sp<GrRenderTargetContext> rtc( 58 context->contextPriv().makeDeferredRenderTargetContextWithFallback( 59 format, SkBackingFit::kExact, size.fWidth, size.fHeight, 60 kAlpha_8_GrPixelConfig, nullptr)); 61 if (!rtc) { 62 return nullptr; 63 } 64 65 GrPaint paint; 66 67 rtc->clear(nullptr, SK_PMColor4fTRANSPARENT, 68 GrRenderTargetContext::CanClearFullscreen::kYes); 69 rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, 70 GrStyle::SimpleFill()); 71 72 sk_sp<GrTextureProxy> srcProxy(rtc->asTextureProxyRef()); 73 if (!srcProxy) { 74 return nullptr; 75 } 76 sk_sp<GrRenderTargetContext> rtc2( 77 SkGpuBlurUtils::GaussianBlur(context, 78 std::move(srcProxy), 79 nullptr, 80 SkIRect::MakeWH(size.fWidth, size.fHeight), 81 SkIRect::EmptyIRect(), 82 xformedSigma, 83 xformedSigma, 84 GrTextureDomain::kIgnore_Mode, 85 kPremul_SkAlphaType, 86 SkBackingFit::kExact)); 87 if (!rtc2) { 88 return nullptr; 89 } 90 91 mask = rtc2->asTextureProxyRef(); 92 if (!mask) { 93 return nullptr; 94 } 95 SkASSERT(mask->origin() == kBottomLeft_GrSurfaceOrigin); 96 proxyProvider->assignUniqueKeyToProxy(key, mask.get()); 97 } 98 99 return mask; 100 } sigma()101 float sigma() const { return fSigma; } rect()102 const SkRect& rect() const { return fRect; } cornerRadius()103 float cornerRadius() const { return fCornerRadius; } 104 105 static std::unique_ptr<GrFragmentProcessor> Make(GrContext* context, float sigma, 106 float xformedSigma, const SkRRect& srcRRect, 107 const SkRRect& devRRect); 108 GrRRectBlurEffect(const GrRRectBlurEffect& src); 109 std::unique_ptr<GrFragmentProcessor> clone() const override; name()110 const char* name() const override { return "RRectBlurEffect"; } 111 112 private: GrRRectBlurEffect(float sigma,SkRect rect,float cornerRadius,sk_sp<GrTextureProxy> ninePatchSampler)113 GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius, 114 sk_sp<GrTextureProxy> ninePatchSampler) 115 : INHERITED(kGrRRectBlurEffect_ClassID, 116 (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag) 117 , fSigma(sigma) 118 , fRect(rect) 119 , fCornerRadius(cornerRadius) 120 , fNinePatchSampler(std::move(ninePatchSampler)) { 121 this->setTextureSamplerCnt(1); 122 } 123 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 124 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; 125 bool onIsEqual(const GrFragmentProcessor&) const override; 126 const TextureSampler& onTextureSampler(int) const override; 127 GR_DECLARE_FRAGMENT_PROCESSOR_TEST 128 float fSigma; 129 SkRect fRect; 130 float fCornerRadius; 131 TextureSampler fNinePatchSampler; 132 typedef GrFragmentProcessor INHERITED; 133 }; 134 #endif 135