• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/core/SkTypes.h"
14 
15 #include "include/core/SkScalar.h"
16 #include "src/core/SkBlurMask.h"
17 #include "src/gpu/GrProxyProvider.h"
18 #include "src/gpu/GrShaderCaps.h"
19 
20 #include "src/gpu/GrCoordTransform.h"
21 #include "src/gpu/GrFragmentProcessor.h"
22 class GrRectBlurEffect : public GrFragmentProcessor {
23 public:
Make(GrProxyProvider * proxyProvider,const GrShaderCaps & caps,const SkRect & rect,float sigma)24     static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider* proxyProvider,
25                                                      const GrShaderCaps& caps, const SkRect& rect,
26                                                      float sigma) {
27         float doubleProfileSize = (12 * sigma);
28         if (!caps.floatIs32Bits()) {
29             // We promote the math that gets us into the Gaussian space to full float when the rect
30             // coords are large. If we don't have full float then fail. We could probably clip the
31             // rect to an outset device bounds instead.
32             if (SkScalarAbs(rect.fLeft) > 16000.f || SkScalarAbs(rect.fTop) > 16000.f ||
33                 SkScalarAbs(rect.fRight) > 16000.f || SkScalarAbs(rect.fBottom) > 16000.f) {
34                 return nullptr;
35             }
36         }
37         // Sigma is always a half.
38         SkASSERT(sigma > 0);
39         if (sigma > 16000.f) {
40             return nullptr;
41         }
42 
43         if (doubleProfileSize >= (float)rect.width() || doubleProfileSize >= (float)rect.height()) {
44             // if the blur sigma is too large so the gaussian overlaps the whole
45             // rect in either direction, fall back to CPU path for now.
46             return nullptr;
47         }
48 
49         return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(rect, sigma));
50     }
51     GrRectBlurEffect(const GrRectBlurEffect& src);
52     std::unique_ptr<GrFragmentProcessor> clone() const override;
name()53     const char* name() const override { return "RectBlurEffect"; }
54     SkRect rect;
55     float sigma;
56 
57 private:
GrRectBlurEffect(SkRect rect,float sigma)58     GrRectBlurEffect(SkRect rect, float sigma)
59             : INHERITED(kGrRectBlurEffect_ClassID,
60                         (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
61             , rect(rect)
62             , sigma(sigma) {}
63     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
64     void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
65     bool onIsEqual(const GrFragmentProcessor&) const override;
66     GR_DECLARE_FRAGMENT_PROCESSOR_TEST
67     typedef GrFragmentProcessor INHERITED;
68 };
69 #endif
70