Home | History | Annotate | Download | only in effects
      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 GrRectBlurEffect.fp; do not modify.
     10  **************************************************************************************************/
     11 #ifndef GrRectBlurEffect_DEFINED
     12 #define GrRectBlurEffect_DEFINED
     13 #include "SkTypes.h"
     14 #if SK_SUPPORT_GPU
     15 
     16 #include "GrProxyProvider.h"
     17 #include "../effects/SkBlurMask.h"
     18 #include "GrFragmentProcessor.h"
     19 #include "GrCoordTransform.h"
     20 class GrRectBlurEffect : public GrFragmentProcessor {
     21 public:
     22     static sk_sp<GrTextureProxy> CreateBlurProfileTexture(GrProxyProvider* proxyProvider,
     23                                                           float sigma) {
     24         unsigned int profileSize = SkScalarCeilToInt(6 * sigma);
     25 
     26         static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
     27         GrUniqueKey key;
     28         GrUniqueKey::Builder builder(&key, kDomain, 1);
     29         builder[0] = profileSize;
     30         builder.finish();
     31 
     32         sk_sp<GrTextureProxy> blurProfile(
     33                 proxyProvider->findOrCreateProxyByUniqueKey(key, kTopLeft_GrSurfaceOrigin));
     34         if (!blurProfile) {
     35             GrSurfaceDesc texDesc;
     36             texDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
     37             texDesc.fWidth = profileSize;
     38             texDesc.fHeight = 1;
     39             texDesc.fConfig = kAlpha_8_GrPixelConfig;
     40 
     41             std::unique_ptr<uint8_t[]> profile(SkBlurMask::ComputeBlurProfile(sigma));
     42 
     43             blurProfile =
     44                     proxyProvider->createTextureProxy(texDesc, SkBudgeted::kYes, profile.get(), 0);
     45             if (!blurProfile) {
     46                 return nullptr;
     47             }
     48 
     49             SkASSERT(blurProfile->origin() == kTopLeft_GrSurfaceOrigin);
     50             proxyProvider->assignUniqueKeyToProxy(key, blurProfile.get());
     51         }
     52 
     53         return blurProfile;
     54     }
     55     SkRect rect() const { return fRect; }
     56     float sigma() const { return fSigma; }
     57 
     58     static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider* proxyProvider,
     59                                                      const SkRect& rect, float sigma) {
     60         int doubleProfileSize = SkScalarCeilToInt(12 * sigma);
     61 
     62         if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.height()) {
     63             // if the blur sigma is too large so the gaussian overlaps the whole
     64             // rect in either direction, fall back to CPU path for now.
     65             return nullptr;
     66         }
     67 
     68         sk_sp<GrTextureProxy> blurProfile(CreateBlurProfileTexture(proxyProvider, sigma));
     69         if (!blurProfile) {
     70             return nullptr;
     71         }
     72 
     73         return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(
     74                 rect, sigma, std::move(blurProfile),
     75                 GrSamplerState(GrSamplerState::WrapMode::kClamp, GrSamplerState::Filter::kBilerp)));
     76     }
     77     GrRectBlurEffect(const GrRectBlurEffect& src);
     78     std::unique_ptr<GrFragmentProcessor> clone() const override;
     79     const char* name() const override { return "RectBlurEffect"; }
     80 
     81 private:
     82     GrRectBlurEffect(SkRect rect, float sigma, sk_sp<GrTextureProxy> blurProfile,
     83                      GrSamplerState samplerParams)
     84             : INHERITED(kGrRectBlurEffect_ClassID,
     85                         (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
     86             , fRect(rect)
     87             , fSigma(sigma)
     88             , fBlurProfile(std::move(blurProfile), samplerParams) {
     89         this->addTextureSampler(&fBlurProfile);
     90     }
     91     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
     92     void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
     93     bool onIsEqual(const GrFragmentProcessor&) const override;
     94     GR_DECLARE_FRAGMENT_PROCESSOR_TEST
     95     SkRect fRect;
     96     float fSigma;
     97     TextureSampler fBlurProfile;
     98     typedef GrFragmentProcessor INHERITED;
     99 };
    100 #endif
    101 #endif
    102