Line data Source code
1 : /*
2 : * Copyright 2013 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 GrBicubicTextureEffect_DEFINED
9 : #define GrBicubicTextureEffect_DEFINED
10 :
11 : #include "GrSingleTextureEffect.h"
12 : #include "GrTextureDomain.h"
13 : #include "glsl/GrGLSLFragmentProcessor.h"
14 :
15 : class GrInvariantOutput;
16 :
17 : class GrBicubicEffect : public GrSingleTextureEffect {
18 : public:
19 : enum {
20 : kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of
21 : // surrounding texels are needed by the kernel in x and y.
22 : };
23 : ~GrBicubicEffect() override;
24 :
25 0 : const char* name() const override { return "Bicubic"; }
26 :
27 0 : const GrTextureDomain& domain() const { return fDomain; }
28 :
29 : /**
30 : * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
31 : */
32 0 : static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
33 : sk_sp<GrTextureProxy> proxy,
34 : sk_sp<GrColorSpaceXform> colorSpaceXform,
35 : const SkMatrix& matrix,
36 : const SkShader::TileMode tileModes[2]) {
37 0 : return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(resourceProvider, std::move(proxy),
38 0 : std::move(colorSpaceXform),
39 0 : matrix, tileModes));
40 : }
41 :
42 : /**
43 : * Create a Mitchell filter effect with a texture matrix and a domain.
44 : */
45 0 : static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
46 : sk_sp<GrTextureProxy> proxy,
47 : sk_sp<GrColorSpaceXform> colorSpaceXform,
48 : const SkMatrix& matrix,
49 : const SkRect& domain) {
50 0 : return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(resourceProvider, std::move(proxy),
51 0 : std::move(colorSpaceXform),
52 0 : matrix, domain));
53 : }
54 :
55 : /**
56 : * Determines whether the bicubic effect should be used based on the transformation from the
57 : * local coords to the device. Returns true if the bicubic effect should be used. filterMode
58 : * is set to appropriate filtering mode to use regardless of the return result (e.g. when this
59 : * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or
60 : * kNearest).
61 : */
62 : static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice,
63 : GrSamplerParams::FilterMode* filterMode);
64 :
65 : private:
66 : GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
67 : const SkMatrix &matrix, const SkShader::TileMode tileModes[2]);
68 : GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
69 : const SkMatrix &matrix, const SkRect& domain);
70 :
71 : GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
72 :
73 : void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
74 :
75 : bool onIsEqual(const GrFragmentProcessor&) const override;
76 :
77 : GrTextureDomain fDomain;
78 :
79 : GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
80 :
81 : typedef GrSingleTextureEffect INHERITED;
82 : };
83 :
84 : #endif
|