13aad3b01afc77993ff051c02e49186294e312980humper@google.com/*
23aad3b01afc77993ff051c02e49186294e312980humper@google.com * Copyright 2013 Google Inc.
33aad3b01afc77993ff051c02e49186294e312980humper@google.com *
43aad3b01afc77993ff051c02e49186294e312980humper@google.com * Use of this source code is governed by a BSD-style license that can be
53aad3b01afc77993ff051c02e49186294e312980humper@google.com * found in the LICENSE file.
63aad3b01afc77993ff051c02e49186294e312980humper@google.com */
73aad3b01afc77993ff051c02e49186294e312980humper@google.com
83aad3b01afc77993ff051c02e49186294e312980humper@google.com#ifndef GrBicubicTextureEffect_DEFINED
93aad3b01afc77993ff051c02e49186294e312980humper@google.com#define GrBicubicTextureEffect_DEFINED
103aad3b01afc77993ff051c02e49186294e312980humper@google.com
117d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org#include "GrTextureDomain.h"
1264c4728c70001ed074fecf5c4e083781987b12e9egdaniel#include "glsl/GrGLSLFragmentProcessor.h"
133aad3b01afc77993ff051c02e49186294e312980humper@google.com
14605dd0fbce9dbb2a0d3313e13e161f2bd54870d7egdanielclass GrInvariantOutput;
153aad3b01afc77993ff051c02e49186294e312980humper@google.com
166cd51b51d6603a3100b147c45f38697f2f199fc6Brian Salomonclass GrBicubicEffect : public GrFragmentProcessor {
173aad3b01afc77993ff051c02e49186294e312980humper@google.compublic:
18dec61503d02862760f3c91203a698636a02c882acommit-bot@chromium.org    enum {
19dec61503d02862760f3c91203a698636a02c882acommit-bot@chromium.org        kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of
20dec61503d02862760f3c91203a698636a02c882acommit-bot@chromium.org                             // surrounding texels are needed by the kernel in x and y.
21dec61503d02862760f3c91203a698636a02c882acommit-bot@chromium.org    };
223aad3b01afc77993ff051c02e49186294e312980humper@google.com
2336352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    const char* name() const override { return "Bicubic"; }
243aad3b01afc77993ff051c02e49186294e312980humper@google.com
25aff329b8e9b239bca1d93b13a914fbef45ccf7feBrian Salomon    std::unique_ptr<GrFragmentProcessor> clone() const override {
26aff329b8e9b239bca1d93b13a914fbef45ccf7feBrian Salomon        return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(*this));
273f6f965a5a65415c65fe9e64eb41896c66da771dBrian Salomon    }
283f6f965a5a65415c65fe9e64eb41896c66da771dBrian Salomon
297d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org    const GrTextureDomain& domain() const { return fDomain; }
303aad3b01afc77993ff051c02e49186294e312980humper@google.com
31bc91fd71faa2c5fd14423fecd18e50701c922cedcommit-bot@chromium.org    /**
32bc91fd71faa2c5fd14423fecd18e50701c922cedcommit-bot@chromium.org     * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
33bc91fd71faa2c5fd14423fecd18e50701c922cedcommit-bot@chromium.org     */
34aff329b8e9b239bca1d93b13a914fbef45ccf7feBrian Salomon    static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
35aff329b8e9b239bca1d93b13a914fbef45ccf7feBrian Salomon                                                     const SkMatrix& matrix,
362bbdcc44c63974f29f3743bb58d929601a3f65c6Brian Salomon                                                     const GrSamplerState::WrapMode wrapModes[2]) {
375e34167d53c06c3c4512592bd1477fcf2df97172Brian Osman        return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix,
385e34167d53c06c3c4512592bd1477fcf2df97172Brian Osman                                                                        wrapModes));
3940fd7c94c24bb30d888c3d85a79cbb96c7fbf800Robert Phillips    }
4040fd7c94c24bb30d888c3d85a79cbb96c7fbf800Robert Phillips
4140fd7c94c24bb30d888c3d85a79cbb96c7fbf800Robert Phillips    /**
4240fd7c94c24bb30d888c3d85a79cbb96c7fbf800Robert Phillips     * Create a Mitchell filter effect with a texture matrix and a domain.
4340fd7c94c24bb30d888c3d85a79cbb96c7fbf800Robert Phillips     */
44aff329b8e9b239bca1d93b13a914fbef45ccf7feBrian Salomon    static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
45aff329b8e9b239bca1d93b13a914fbef45ccf7feBrian Salomon                                                     const SkMatrix& matrix,
46aff329b8e9b239bca1d93b13a914fbef45ccf7feBrian Salomon                                                     const SkRect& domain) {
475e34167d53c06c3c4512592bd1477fcf2df97172Brian Osman        return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix,
485e34167d53c06c3c4512592bd1477fcf2df97172Brian Osman                                                                        domain));
4940fd7c94c24bb30d888c3d85a79cbb96c7fbf800Robert Phillips    }
5040fd7c94c24bb30d888c3d85a79cbb96c7fbf800Robert Phillips
5140fd7c94c24bb30d888c3d85a79cbb96c7fbf800Robert Phillips    /**
529927bd355fc1557aa2c98900266ba6f49f806889commit-bot@chromium.org     * Determines whether the bicubic effect should be used based on the transformation from the
539927bd355fc1557aa2c98900266ba6f49f806889commit-bot@chromium.org     * local coords to the device. Returns true if the bicubic effect should be used. filterMode
549927bd355fc1557aa2c98900266ba6f49f806889commit-bot@chromium.org     * is set to appropriate filtering mode to use regardless of the return result (e.g. when this
559927bd355fc1557aa2c98900266ba6f49f806889commit-bot@chromium.org     * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or
569927bd355fc1557aa2c98900266ba6f49f806889commit-bot@chromium.org     * kNearest).
579927bd355fc1557aa2c98900266ba6f49f806889commit-bot@chromium.org     */
589927bd355fc1557aa2c98900266ba6f49f806889commit-bot@chromium.org    static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice,
592bbdcc44c63974f29f3743bb58d929601a3f65c6Brian Salomon                                 GrSamplerState::Filter* filterMode);
609927bd355fc1557aa2c98900266ba6f49f806889commit-bot@chromium.org
613aad3b01afc77993ff051c02e49186294e312980humper@google.comprivate:
625e34167d53c06c3c4512592bd1477fcf2df97172Brian Osman    GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix& matrix,
632bbdcc44c63974f29f3743bb58d929601a3f65c6Brian Salomon                    const GrSamplerState::WrapMode wrapModes[2]);
645e34167d53c06c3c4512592bd1477fcf2df97172Brian Osman    GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix &matrix, const SkRect& domain);
653f6f965a5a65415c65fe9e64eb41896c66da771dBrian Salomon    explicit GrBicubicEffect(const GrBicubicEffect&);
6640fd7c94c24bb30d888c3d85a79cbb96c7fbf800Robert Phillips
6757d3b039c635945e1dc2fcbac3462ed8bfedb068egdaniel    GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
68b1daa86732fe70aa4630c89d75ff0fd619d77c77wangyix
6994efbf51f5a88d9e8aa961d3fbe38c5e335d6108Brian Salomon    void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
704b3050b410254d0cb38df9a30ae2e209124fa1a2wangyix
7136352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    bool onIsEqual(const GrFragmentProcessor&) const override;
727d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org
736cd51b51d6603a3100b147c45f38697f2f199fc6Brian Salomon    GrCoordTransform fCoordTransform;
747d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org    GrTextureDomain fDomain;
756cd51b51d6603a3100b147c45f38697f2f199fc6Brian Salomon    TextureSampler fTextureSampler;
763aad3b01afc77993ff051c02e49186294e312980humper@google.com
770c26a9dbd0b6546731df63c01411cb2aaa5ba236Brian Salomon    GR_DECLARE_FRAGMENT_PROCESSOR_TEST
78c3723db387a257a2b8beba1a515df355cd70d06askia.committer@gmail.com
796cd51b51d6603a3100b147c45f38697f2f199fc6Brian Salomon    typedef GrFragmentProcessor INHERITED;
803aad3b01afc77993ff051c02e49186294e312980humper@google.com};
813aad3b01afc77993ff051c02e49186294e312980humper@google.com
823aad3b01afc77993ff051c02e49186294e312980humper@google.com#endif
83