blob: ed22ba1a0226642b1d216adfa20a4f81fe249727 [file] [log] [blame]
humper@google.com3aad3b02013-09-04 19:23:53 +00001/*
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"
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000012#include "GrTextureDomain.h"
egdaniel64c47282015-11-13 06:54:19 -080013#include "glsl/GrGLSLFragmentProcessor.h"
humper@google.com3aad3b02013-09-04 19:23:53 +000014
egdaniel605dd0f2014-11-12 08:35:25 -080015class GrInvariantOutput;
humper@google.com3aad3b02013-09-04 19:23:53 +000016
17class GrBicubicEffect : public GrSingleTextureEffect {
18public:
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +000019 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 };
humper@google.com3aad3b02013-09-04 19:23:53 +000023 virtual ~GrBicubicEffect();
24
mtklein36352bf2015-03-25 18:17:31 -070025 const char* name() const override { return "Bicubic"; }
humper@google.com3aad3b02013-09-04 19:23:53 +000026
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000027 const GrTextureDomain& domain() const { return fDomain; }
humper@google.com3aad3b02013-09-04 19:23:53 +000028
commit-bot@chromium.orgbc91fd72013-12-10 12:53:39 +000029 /**
30 * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
31 */
brianosman54f30c12016-07-18 10:53:52 -070032 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
33 sk_sp<GrColorSpaceXform> colorSpaceXform,
34 const SkMatrix& matrix,
bungeman06ca8ec2016-06-09 08:01:03 -070035 const SkShader::TileMode tileModes[2]) {
brianosman54f30c12016-07-18 10:53:52 -070036 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, std::move(colorSpaceXform),
Brian Osman08575272016-12-21 15:26:37 -050037 matrix, tileModes));
humper@google.com3aad3b02013-09-04 19:23:53 +000038 }
39
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000040 /**
41 * Create a Mitchell filter effect with a texture matrix and a domain.
42 */
brianosman54f30c12016-07-18 10:53:52 -070043 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
44 sk_sp<GrColorSpaceXform> colorSpaceXform,
45 const SkMatrix& matrix,
bungeman06ca8ec2016-06-09 08:01:03 -070046 const SkRect& domain) {
brianosman54f30c12016-07-18 10:53:52 -070047 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, std::move(colorSpaceXform),
Brian Osman08575272016-12-21 15:26:37 -050048 matrix, domain));
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000049 }
50
commit-bot@chromium.org9927bd32014-05-20 17:51:13 +000051 /**
Robert Phillips40fd7c92017-01-30 08:06:27 -050052 * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
53 */
Robert Phillips296b1cc2017-03-15 10:42:12 -040054 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
55 sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050056 sk_sp<GrColorSpaceXform> colorSpaceXform,
57 const SkMatrix& matrix,
58 const SkShader::TileMode tileModes[2]) {
Robert Phillips296b1cc2017-03-15 10:42:12 -040059 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(resourceProvider, std::move(proxy),
Robert Phillips40fd7c92017-01-30 08:06:27 -050060 std::move(colorSpaceXform),
61 matrix, tileModes));
62 }
63
64 /**
65 * Create a Mitchell filter effect with a texture matrix and a domain.
66 */
Robert Phillips296b1cc2017-03-15 10:42:12 -040067 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
68 sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050069 sk_sp<GrColorSpaceXform> colorSpaceXform,
70 const SkMatrix& matrix,
71 const SkRect& domain) {
Robert Phillips296b1cc2017-03-15 10:42:12 -040072 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(resourceProvider, std::move(proxy),
Robert Phillips40fd7c92017-01-30 08:06:27 -050073 std::move(colorSpaceXform),
74 matrix, domain));
75 }
76
77 /**
commit-bot@chromium.org9927bd32014-05-20 17:51:13 +000078 * Determines whether the bicubic effect should be used based on the transformation from the
79 * local coords to the device. Returns true if the bicubic effect should be used. filterMode
80 * is set to appropriate filtering mode to use regardless of the return result (e.g. when this
81 * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or
82 * kNearest).
83 */
84 static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice,
Brian Salomon514baff2016-11-17 15:17:07 -050085 GrSamplerParams::FilterMode* filterMode);
commit-bot@chromium.org9927bd32014-05-20 17:51:13 +000086
humper@google.com3aad3b02013-09-04 19:23:53 +000087private:
Brian Osman08575272016-12-21 15:26:37 -050088 GrBicubicEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix &matrix,
89 const SkShader::TileMode tileModes[2]);
90 GrBicubicEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix &matrix,
91 const SkRect& domain);
wangyix4b3050b2015-08-04 07:59:37 -070092
Robert Phillips296b1cc2017-03-15 10:42:12 -040093 GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
Robert Phillips40fd7c92017-01-30 08:06:27 -050094 const SkMatrix &matrix, const SkShader::TileMode tileModes[2]);
Robert Phillips296b1cc2017-03-15 10:42:12 -040095 GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
Robert Phillips40fd7c92017-01-30 08:06:27 -050096 const SkMatrix &matrix, const SkRect& domain);
97
egdaniel57d3b032015-11-13 11:57:27 -080098 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070099
Brian Salomon94efbf52016-11-29 13:43:05 -0500100 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -0700101
mtklein36352bf2015-03-25 18:17:31 -0700102 bool onIsEqual(const GrFragmentProcessor&) const override;
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +0000103
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +0000104 GrTextureDomain fDomain;
humper@google.com3aad3b02013-09-04 19:23:53 +0000105
joshualittb0a8a372014-09-23 09:50:21 -0700106 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
skia.committer@gmail.comc3723db2013-09-05 07:01:19 +0000107
humper@google.com3aad3b02013-09-04 19:23:53 +0000108 typedef GrSingleTextureEffect INHERITED;
109};
110
111#endif