blob: 45c416f3f151f46af1a45e15817a0ffe7aead7f1 [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 Salomonaff329b2017-08-11 09:40:37 -040025 std::unique_ptr<GrFragmentProcessor> clone() const override {
26 return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(*this));
Brian Salomon3f6f9652017-07-28 07:34:05 -040027 }
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
commit-bot@chromium.orgbc91fd72013-12-10 12:53:39 +000031 /**
32 * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
33 */
Brian Salomonaff329b2017-08-11 09:40:37 -040034 static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Brian Salomonaff329b2017-08-11 09:40:37 -040035 const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040036 const GrSamplerState::WrapMode wrapModes[2]) {
Brian Osman5e341672017-10-18 10:23:18 -040037 return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix,
38 wrapModes));
Robert Phillips40fd7c92017-01-30 08:06:27 -050039 }
40
41 /**
42 * Create a Mitchell filter effect with a texture matrix and a domain.
43 */
Brian Salomonaff329b2017-08-11 09:40:37 -040044 static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Brian Salomonaff329b2017-08-11 09:40:37 -040045 const SkMatrix& matrix,
46 const SkRect& domain) {
Brian Osman5e341672017-10-18 10:23:18 -040047 return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix,
48 domain));
Robert Phillips40fd7c92017-01-30 08:06:27 -050049 }
50
51 /**
commit-bot@chromium.org9927bd32014-05-20 17:51:13 +000052 * Determines whether the bicubic effect should be used based on the transformation from the
53 * local coords to the device. Returns true if the bicubic effect should be used. filterMode
54 * is set to appropriate filtering mode to use regardless of the return result (e.g. when this
55 * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or
56 * kNearest).
57 */
58 static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040059 GrSamplerState::Filter* filterMode);
commit-bot@chromium.org9927bd32014-05-20 17:51:13 +000060
humper@google.com3aad3b02013-09-04 19:23:53 +000061private:
Brian Osman5e341672017-10-18 10:23:18 -040062 GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040063 const GrSamplerState::WrapMode wrapModes[2]);
Brian Osman5e341672017-10-18 10:23:18 -040064 GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix &matrix, const SkRect& domain);
Brian Salomon3f6f9652017-07-28 07:34:05 -040065 explicit GrBicubicEffect(const GrBicubicEffect&);
Robert Phillips40fd7c92017-01-30 08:06:27 -050066
egdaniel57d3b032015-11-13 11:57:27 -080067 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070068
Brian Salomon94efbf52016-11-29 13:43:05 -050069 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070070
mtklein36352bf2015-03-25 18:17:31 -070071 bool onIsEqual(const GrFragmentProcessor&) const override;
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000072
Brian Salomonf7dcd762018-07-30 14:48:15 -040073 const TextureSampler& onTextureSampler(int) const override { return fTextureSampler; }
74
Brian Salomon6cd51b52017-07-26 19:07:15 -040075 GrCoordTransform fCoordTransform;
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +000076 GrTextureDomain fDomain;
Brian Salomon6cd51b52017-07-26 19:07:15 -040077 TextureSampler fTextureSampler;
humper@google.com3aad3b02013-09-04 19:23:53 +000078
Brian Salomon0c26a9d2017-07-06 10:09:38 -040079 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
skia.committer@gmail.comc3723db2013-09-05 07:01:19 +000080
Brian Salomon6cd51b52017-07-26 19:07:15 -040081 typedef GrFragmentProcessor INHERITED;
humper@google.com3aad3b02013-09-04 19:23:53 +000082};
83
84#endif