blob: 65e2c3dbbad9e903ee3d423692fa8a9b15c113de [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
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000011#include "GrTextureDomain.h"
egdaniel64c47282015-11-13 06:54:19 -080012#include "glsl/GrGLSLFragmentProcessor.h"
humper@google.com3aad3b02013-09-04 19:23:53 +000013
egdaniel605dd0f2014-11-12 08:35:25 -080014class GrInvariantOutput;
humper@google.com3aad3b02013-09-04 19:23:53 +000015
Brian Salomon6cd51b52017-07-26 19:07:15 -040016class GrBicubicEffect : public GrFragmentProcessor {
humper@google.com3aad3b02013-09-04 19:23:53 +000017public:
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +000018 enum {
19 kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of
20 // surrounding texels are needed by the kernel in x and y.
21 };
humper@google.com3aad3b02013-09-04 19:23:53 +000022
mtklein36352bf2015-03-25 18:17:31 -070023 const char* name() const override { return "Bicubic"; }
humper@google.com3aad3b02013-09-04 19:23:53 +000024
Brian Salomon3f6f9652017-07-28 07:34:05 -040025 sk_sp<GrFragmentProcessor> clone() const override {
26 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(*this));
27 }
28
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000029 const GrTextureDomain& domain() const { return fDomain; }
humper@google.com3aad3b02013-09-04 19:23:53 +000030
Brian Salomon6cd51b52017-07-26 19:07:15 -040031 const GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }
32
commit-bot@chromium.orgbc91fd72013-12-10 12:53:39 +000033 /**
34 * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
35 */
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040036 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050037 sk_sp<GrColorSpaceXform> colorSpaceXform,
38 const SkMatrix& matrix,
39 const SkShader::TileMode tileModes[2]) {
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040040 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy),
Robert Phillips40fd7c92017-01-30 08:06:27 -050041 std::move(colorSpaceXform),
42 matrix, tileModes));
43 }
44
45 /**
46 * Create a Mitchell filter effect with a texture matrix and a domain.
47 */
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040048 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050049 sk_sp<GrColorSpaceXform> colorSpaceXform,
50 const SkMatrix& matrix,
51 const SkRect& domain) {
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040052 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy),
Robert Phillips40fd7c92017-01-30 08:06:27 -050053 std::move(colorSpaceXform),
54 matrix, domain));
55 }
56
57 /**
commit-bot@chromium.org9927bd32014-05-20 17:51:13 +000058 * Determines whether the bicubic effect should be used based on the transformation from the
59 * local coords to the device. Returns true if the bicubic effect should be used. filterMode
60 * is set to appropriate filtering mode to use regardless of the return result (e.g. when this
61 * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or
62 * kNearest).
63 */
64 static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice,
Brian Salomon514baff2016-11-17 15:17:07 -050065 GrSamplerParams::FilterMode* filterMode);
commit-bot@chromium.org9927bd32014-05-20 17:51:13 +000066
humper@google.com3aad3b02013-09-04 19:23:53 +000067private:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040068 GrBicubicEffect(sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
Robert Phillips40fd7c92017-01-30 08:06:27 -050069 const SkMatrix &matrix, const SkShader::TileMode tileModes[2]);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040070 GrBicubicEffect(sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
Robert Phillips40fd7c92017-01-30 08:06:27 -050071 const SkMatrix &matrix, const SkRect& domain);
Brian Salomon3f6f9652017-07-28 07:34:05 -040072 explicit GrBicubicEffect(const GrBicubicEffect&);
Robert Phillips40fd7c92017-01-30 08:06:27 -050073
egdaniel57d3b032015-11-13 11:57:27 -080074 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070075
Brian Salomon94efbf52016-11-29 13:43:05 -050076 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070077
mtklein36352bf2015-03-25 18:17:31 -070078 bool onIsEqual(const GrFragmentProcessor&) const override;
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000079
Brian Salomon6cd51b52017-07-26 19:07:15 -040080 GrCoordTransform fCoordTransform;
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000081 GrTextureDomain fDomain;
Brian Salomon6cd51b52017-07-26 19:07:15 -040082 TextureSampler fTextureSampler;
83 sk_sp<GrColorSpaceXform> fColorSpaceXform;
humper@google.com3aad3b02013-09-04 19:23:53 +000084
Brian Salomon0c26a9d2017-07-06 10:09:38 -040085 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
skia.committer@gmail.comc3723db2013-09-05 07:01:19 +000086
Brian Salomon6cd51b52017-07-26 19:07:15 -040087 typedef GrFragmentProcessor INHERITED;
humper@google.com3aad3b02013-09-04 19:23:53 +000088};
89
90#endif