OLD | NEW |
---|---|
(Empty) | |
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 "SkTypes.h" | |
12 | |
13 #if SK_SUPPORT_GPU | |
14 | |
15 #include "GrFragmentProcessor.h" | |
16 #include "GrProcessorUnitTest.h" | |
17 | |
18 class GrTextureProvider; | |
19 | |
20 // This FP handles the special case of a blurred circle. It uses a 1D | |
21 // profile that is just rotated about the origin of the circle. | |
22 class GrCircleBlurFragmentProcessor : public GrFragmentProcessor { | |
23 public: | |
24 ~GrCircleBlurFragmentProcessor() override {}; | |
25 | |
26 const char* name() const override { return "CircleBlur"; } | |
27 | |
28 static GrFragmentProcessor* Create(GrTextureProvider*textureProvider, | |
bsalomon
2015/09/11 13:05:46
const GrFP (most of our factories don't do this bu
robertphillips
2015/09/11 15:55:35
Done.
| |
29 const SkRect& circle, float sigma) { | |
30 float offset; | |
31 | |
32 SkAutoTUnref<GrTexture> blurProfile(CreateCircleBlurProfileTexture(textu reProvider, | |
33 circl e, | |
34 sigma , | |
35 &offs et)); | |
36 if (!blurProfile) { | |
37 return nullptr; | |
38 } | |
39 return new GrCircleBlurFragmentProcessor(circle, sigma, offset, blurProf ile); | |
40 } | |
41 | |
42 const SkRect& circle() const { return fCircle; } | |
43 float sigma() const { return fSigma; } | |
44 float offset() const { return fOffset; } | |
45 int profileSize() const { return fBlurProfileAccess.getTexture()->width(); } | |
46 | |
47 private: | |
48 GrCircleBlurFragmentProcessor(const SkRect& circle, float sigma, | |
49 float offset, GrTexture* blurProfile); | |
50 | |
51 GrGLFragmentProcessor* onCreateGLInstance() const override; | |
52 | |
53 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override; | |
54 | |
55 bool onIsEqual(const GrFragmentProcessor& other) const override { | |
56 const GrCircleBlurFragmentProcessor& cbfp = other.cast<GrCircleBlurFragm entProcessor>(); | |
57 // fOffset is computed from the circle width and the sigma | |
58 return this->circle().width() == cbfp.circle().width() && fSigma == cbfp .fSigma; | |
59 } | |
60 | |
61 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | |
62 | |
63 static GrTexture* CreateCircleBlurProfileTexture(GrTextureProvider*, | |
64 const SkRect& circle, | |
65 float sigma, float* offset) ; | |
66 | |
67 SkRect fCircle; | |
68 float fSigma; | |
69 float fOffset; | |
70 GrTextureAccess fBlurProfileAccess; | |
71 | |
72 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | |
73 | |
74 typedef GrFragmentProcessor INHERITED; | |
75 }; | |
76 | |
77 #endif | |
78 #endif | |
OLD | NEW |