• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 #ifndef GrCircleBlurFragmentProcessor_DEFINED
9 #define GrCircleBlurFragmentProcessor_DEFINED
10 
11 #include "SkString.h"
12 #include "SkTypes.h"
13 
14 #if SK_SUPPORT_GPU
15 
16 #include "GrFragmentProcessor.h"
17 #include "GrProcessorUnitTest.h"
18 
19 class GrResourceProvider;
20 
21 // This FP handles the special case of a blurred circle. It uses a 1D
22 // profile that is just rotated about the origin of the circle.
23 class GrCircleBlurFragmentProcessor : public GrFragmentProcessor {
24 public:
~GrCircleBlurFragmentProcessor()25     ~GrCircleBlurFragmentProcessor() override {}
26 
name()27     const char* name() const override { return "CircleBlur"; }
28 
dumpInfo()29     SkString dumpInfo() const override {
30         SkString str;
31         str.appendf("Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f], solidR: %.2f, textureR: %.2f",
32                     fCircle.fLeft, fCircle.fTop, fCircle.fRight, fCircle.fBottom,
33                     fSolidRadius, fTextureRadius);
34         return str;
35     }
36 
37     static sk_sp<GrFragmentProcessor> Make(GrResourceProvider*, const SkRect& circle, float sigma);
38 
39 private:
40     // This nested GLSL processor implementation is defined in the cpp file.
41     class GLSLProcessor;
42 
43     /**
44      * Creates a profile texture for the circle and sigma. The texture will have a height of 1.
45      * The x texture coord should map from 0 to 1 across the radius range of solidRadius to
46      * solidRadius + textureRadius.
47      */
48     GrCircleBlurFragmentProcessor(GrResourceProvider*, const SkRect& circle,
49                                   float textureRadius, float innerRadius,
50                                   sk_sp<GrTextureProxy> blurProfile);
51 
52     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
53 
54     void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
55 
onIsEqual(const GrFragmentProcessor & other)56     bool onIsEqual(const GrFragmentProcessor& other) const override {
57         const GrCircleBlurFragmentProcessor& cbfp = other.cast<GrCircleBlurFragmentProcessor>();
58         return fCircle == cbfp.fCircle && fSolidRadius == cbfp.fSolidRadius &&
59                fTextureRadius == cbfp.fTextureRadius;
60     }
61 
62     SkRect              fCircle;
63     SkScalar            fSolidRadius;
64     float               fTextureRadius;
65     TextureSampler      fBlurProfileSampler;
66 
67     GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
68 
69     typedef GrFragmentProcessor INHERITED;
70 };
71 
72 #endif
73 #endif
74