GrProcessor.h revision a5305a110ab5201d5dadd40cbe711582d5ac4996
1168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com/*
2168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com * Copyright 2012 Google Inc.
3168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com *
4168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com * Use of this source code is governed by a BSD-style license that can be
5168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com * found in the LICENSE file.
6168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com */
7168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com
8b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt#ifndef GrProcessor_DEFINED
9b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt#define GrProcessor_DEFINED
10168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com
11b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt#include "GrBackendProcessorFactory.h"
12371e105da5d9fdfff3b4242b37ff6fc09214c8c8bsalomon@google.com#include "GrColor.h"
13b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt#include "GrProcessorUnitTest.h"
1495740981c36266e4595ddde2264aa38e3c7e2d02bsalomon#include "GrProgramElement.h"
15249af15fb82833d2274850c589812b6e69df0033joshualitt#include "GrShaderVar.h"
16047696c1c67b2e0a73f2b951ce23ff5b155111bbbsalomon@google.com#include "GrTextureAccess.h"
17ff6ea2663f76aa85ec55ddd0f00ca7906f1bc4e3commit-bot@chromium.org#include "GrTypesPriv.h"
18249af15fb82833d2274850c589812b6e69df0033joshualitt#include "SkString.h"
1907eecdca3e331eb4066c53a29305aeea6d692961tomhudson@google.com
20b0a8a377f832c59cee939ad721e1f87d378b7142joshualittclass GrBackendProcessorFactory;
21168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.comclass GrContext;
2277af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.comclass GrCoordTransform;
2395740981c36266e4595ddde2264aa38e3c7e2d02bsalomon
2450db75c871b203081a32190ab173f13c785a147fbsalomon@google.com/** Provides custom vertex shader, fragment shader, uniform data for a particular stage of the
2550db75c871b203081a32190ab173f13c785a147fbsalomon@google.com    Ganesh shading pipeline.
26289efe014ad7628de7cf2c5177a42cacd1e335adbsalomon@google.com    Subclasses must have a function that produces a human-readable name:
27289efe014ad7628de7cf2c5177a42cacd1e335adbsalomon@google.com        static const char* Name();
28b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    GrProcessor objects *must* be immutable: after being constructed, their fields may not change.
290ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com
30b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
3197b9ab72cd5ee0cba4692082737266376425f27cbsalomon    effect must reach 0 before the thread terminates and the pool is destroyed. To create a static
3297b9ab72cd5ee0cba4692082737266376425f27cbsalomon    effect use the macro GR_CREATE_STATIC_EFFECT declared below.
33289efe014ad7628de7cf2c5177a42cacd1e335adbsalomon@google.com  */
34b0a8a377f832c59cee939ad721e1f87d378b7142joshualittclass GrProcessor : public GrProgramElement {
35168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.compublic:
36b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    SK_DECLARE_INST_COUNT(GrProcessor)
3715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
38b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    virtual ~GrProcessor();
39168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com
401a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel    struct InvariantOutput{
411a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        GrColor fColor;
421a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        uint32_t fValidFlags;
431a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        bool fIsSingleComponent;
441a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel
45651713408c5a5d9565665967ad09981250c7a8c9joshualitt        InvariantOutput() : fColor(0), fValidFlags(0), fIsSingleComponent(false) {}
46651713408c5a5d9565665967ad09981250c7a8c9joshualitt
471a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        bool isOpaque() const {
481a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel            return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(fColor));
491a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        }
501a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel
511a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        bool isSolidWhite() const {
521a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel            return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fColor);
531a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        }
541a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel
551a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        /**
561a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel         * If isSingleComponent is true, then the flag values for r, g, b, and a must all be the
571a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel         * same. If the flags are all set then all color components must be equal.
581a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel         */
591a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        SkDEBUGCODE(void validate() const;)
601a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel
611a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel    private:
621a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        SkDEBUGCODE(bool colorComponentsAllEqual() const;)
631a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel
641a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        /**
651a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel         * If alpha is valid, check that any valid R,G,B values are <= A
661a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel         */
671a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        SkDEBUGCODE(bool validPreMulColor() const;)
681a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel    };
691a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel
70371e105da5d9fdfff3b4242b37ff6fc09214c8c8bsalomon@google.com    /**
711a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel     * This function is used to perform optimizations. When called the invarientOuput param
72b8eb2e89edf914caf5479baeffcb670d3e93f496bsalomon@google.com     * indicate whether the input components to this effect in the FS will have known values.
731a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel     * In inout the validFlags member is a bitfield of GrColorComponentFlags. The isSingleComponent
741a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel     * member indicates whether the input will be 1 or 4 bytes. The function updates the members of
751a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel     * inout to indicate known values of its output. A component of the color member only has
761a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel     * meaning if the corresponding bit in validFlags is set.
77371e105da5d9fdfff3b4242b37ff6fc09214c8c8bsalomon@google.com     */
781a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel    void computeInvariantOutput(InvariantOutput* inout) const {
791a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        this->onComputeInvariantOutput(inout);
801a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel#ifdef SK_DEBUG
811a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel        inout->validate();
821a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel#endif
831a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel    }
84168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com
85422e81aeb1f4078367c85efe591c7df8c33874ecbsalomon@google.com    /** This object, besides creating back-end-specific helper objects, is used for run-time-type-
86422e81aeb1f4078367c85efe591c7df8c33874ecbsalomon@google.com        identification. The factory should be an instance of templated class,
87b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        GrTBackendEffectFactory. It is templated on the subclass of GrProcessor. The subclass must
88b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        have a nested type (or typedef) named GLProcessor which will be the subclass of
89b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        GrGLProcessor created by the factory.
90ae4f96a9e06df44f70c3d5f7324f5a7fabcd1026bsalomon@google.com
91ae4f96a9e06df44f70c3d5f7324f5a7fabcd1026bsalomon@google.com        Example:
92b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        class MyCustomEffect : public GrProcessor {
93ae4f96a9e06df44f70c3d5f7324f5a7fabcd1026bsalomon@google.com        ...
94396e61fe440590744345e0c56970b26ab464591dbsalomon@google.com            virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
95396e61fe440590744345e0c56970b26ab464591dbsalomon@google.com                return GrTBackendEffectFactory<MyCustomEffect>::getInstance();
96ae4f96a9e06df44f70c3d5f7324f5a7fabcd1026bsalomon@google.com            }
97ae4f96a9e06df44f70c3d5f7324f5a7fabcd1026bsalomon@google.com        ...
98ae4f96a9e06df44f70c3d5f7324f5a7fabcd1026bsalomon@google.com        };
99ae4f96a9e06df44f70c3d5f7324f5a7fabcd1026bsalomon@google.com     */
100b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    virtual const GrBackendProcessorFactory& getFactory() const = 0;
101b88bbd2a5388ec2a5574d0ef7e43160c0ac37a3btomhudson@google.com
10268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    /** Returns true if this and other effect conservatively draw identically. It can only return
10368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        true when the two effects are of the same subclass (i.e. they return the same object from
10468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        from getFactory()).
10568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
10668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        A return value of true from isEqual() should not be used to test whether the effects would
10763e99f7a03b2ac90ae7a00232674fd39c0bdcc68bsalomon        generate the same shader code. To test for identical code generation use the effects' keys
10863e99f7a03b2ac90ae7a00232674fd39c0bdcc68bsalomon        computed by the GrBackendEffectFactory.
109d0c1a06cb98dd4a009dfa79e37ba6ca23a8c180btomhudson@google.com     */
110b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    bool isEqual(const GrProcessor& other) const {
11197b9ab72cd5ee0cba4692082737266376425f27cbsalomon        if (&this->getFactory() != &other.getFactory()) {
11297b9ab72cd5ee0cba4692082737266376425f27cbsalomon            return false;
11397b9ab72cd5ee0cba4692082737266376425f27cbsalomon        }
11497b9ab72cd5ee0cba4692082737266376425f27cbsalomon        bool result = this->onIsEqual(other);
11597b9ab72cd5ee0cba4692082737266376425f27cbsalomon#ifdef SK_DEBUG
11697b9ab72cd5ee0cba4692082737266376425f27cbsalomon        if (result) {
11797b9ab72cd5ee0cba4692082737266376425f27cbsalomon            this->assertEquality(other);
11897b9ab72cd5ee0cba4692082737266376425f27cbsalomon        }
11997b9ab72cd5ee0cba4692082737266376425f27cbsalomon#endif
12097b9ab72cd5ee0cba4692082737266376425f27cbsalomon        return result;
12168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    }
122d8f856c32b679d9f5a9926feac005e2c0186f83ftomhudson@google.com
123a5e65ec434fed44dc616e4f64950b835b541181btwiz@google.com    /** Human-meaningful string to identify this effect; may be embedded
124a5e65ec434fed44dc616e4f64950b835b541181btwiz@google.com        in generated shader code. */
1252eaaefd7e6a58339b3f93333f1e9cc92252cc303bsalomon@google.com    const char* name() const;
126289efe014ad7628de7cf2c5177a42cacd1e335adbsalomon@google.com
12750db75c871b203081a32190ab173f13c785a147fbsalomon@google.com    int numTextures() const { return fTextureAccesses.count(); }
128168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com
1296d003d1ddced3e71684b8b3785d1e5a16255688dbsalomon@google.com    /** Returns the access pattern for the texture at index. index must be valid according to
1306d003d1ddced3e71684b8b3785d1e5a16255688dbsalomon@google.com        numTextures(). */
13150db75c871b203081a32190ab173f13c785a147fbsalomon@google.com    const GrTextureAccess& textureAccess(int index) const { return *fTextureAccesses[index]; }
1326d003d1ddced3e71684b8b3785d1e5a16255688dbsalomon@google.com
1336d003d1ddced3e71684b8b3785d1e5a16255688dbsalomon@google.com    /** Shortcut for textureAccess(index).texture(); */
1346d003d1ddced3e71684b8b3785d1e5a16255688dbsalomon@google.com    GrTexture* texture(int index) const { return this->textureAccess(index).getTexture(); }
135a5e65ec434fed44dc616e4f64950b835b541181btwiz@google.com
1368d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org    /** Will this effect read the fragment position? */
1378d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org    bool willReadFragmentPosition() const { return fWillReadFragmentPosition; }
138ff6ea2663f76aa85ec55ddd0f00ca7906f1bc4e3commit-bot@chromium.org
139dcba4c2cc30cc64f08def991376c6dab65cfb51ctomhudson@google.com    void* operator new(size_t size);
140dcba4c2cc30cc64f08def991376c6dab65cfb51ctomhudson@google.com    void operator delete(void* target);
141dcba4c2cc30cc64f08def991376c6dab65cfb51ctomhudson@google.com
142d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com    void* operator new(size_t size, void* placement) {
143d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com        return ::operator new(size, placement);
144d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com    }
145d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com    void operator delete(void* target, void* placement) {
146d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com        ::operator delete(target, placement);
147d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com    }
148d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com
14949586bec7383d4ccb81f85f8e2dc4162e2d4f6a8joshualitt    /**
150b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt      * Helper for down-casting to a GrProcessor subclass
15149586bec7383d4ccb81f85f8e2dc4162e2d4f6a8joshualitt      */
15249586bec7383d4ccb81f85f8e2dc4162e2d4f6a8joshualitt    template <typename T> const T& cast() const { return *static_cast<const T*>(this); }
15349586bec7383d4ccb81f85f8e2dc4162e2d4f6a8joshualitt
15450db75c871b203081a32190ab173f13c785a147fbsalomon@google.comprotected:
15550db75c871b203081a32190ab173f13c785a147fbsalomon@google.com    /**
15691274b99722d9be62e077ab979c630c23cdd04b1skia.committer@gmail.com     * Subclasses call this from their constructor to register GrTextureAccesses. The effect
15791a798f121a2238639f8e2d08cc776d4f0236cebcommit-bot@chromium.org     * subclass manages the lifetime of the accesses (this function only stores a pointer). The
158b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     * GrTextureAccess is typically a member field of the GrProcessor subclass. This must only be
159b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     * called from the constructor because GrProcessors are immutable.
16050db75c871b203081a32190ab173f13c785a147fbsalomon@google.com     */
16150db75c871b203081a32190ab173f13c785a147fbsalomon@google.com    void addTextureAccess(const GrTextureAccess* textureAccess);
16250db75c871b203081a32190ab173f13c785a147fbsalomon@google.com
163b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    GrProcessor()
164b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        : fWillReadFragmentPosition(false) {}
1658d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org
1668d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org    /**
1678d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org     * If the effect will generate a backend-specific effect that will read the fragment position
1688d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org     * in the FS then it must call this method from its constructor. Otherwise, the request to
1698d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org     * access the fragment position will be denied.
1708d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org     */
1718d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org    void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; }
17226e18b593ab65e4d92dfbce92579d8bc180d4c2cbsalomon@google.com
173d0c1a06cb98dd4a009dfa79e37ba6ca23a8c180btomhudson@google.comprivate:
174b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    SkDEBUGCODE(void assertEquality(const GrProcessor& other) const;)
17577af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com
17668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    /** Subclass implements this to support isEqual(). It will only be called if it is known that
1776340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com        the two effects are of the same subclass (i.e. they return the same object from
1786340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com        getFactory()).*/
179b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    virtual bool onIsEqual(const GrProcessor& other) const = 0;
18068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
1811a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel    /**
1821a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel     * Subclass implements this to support getConstantColorComponents(...).
1831a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel     */
1841a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel    virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0;
1850ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com
186ff6ea2663f76aa85ec55ddd0f00ca7906f1bc4e3commit-bot@chromium.org    SkSTArray<4, const GrTextureAccess*, true>   fTextureAccesses;
1878d47ddc19a40d1984bf1f384d711d36ab59fd1c0commit-bot@chromium.org    bool                                         fWillReadFragmentPosition;
1880ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com
18995740981c36266e4595ddde2264aa38e3c7e2d02bsalomon    typedef GrProgramElement INHERITED;
190168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com};
191168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com
192b0a8a377f832c59cee939ad721e1f87d378b7142joshualittclass GrFragmentProcessor : public GrProcessor {
193b0a8a377f832c59cee939ad721e1f87d378b7142joshualittpublic:
194b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    GrFragmentProcessor()
195b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        : INHERITED()
196b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        , fWillReadDstColor(false)
197b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        , fWillUseInputColor(true) {}
198b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
199b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0;
200b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
201a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt    int numTransforms() const { return fCoordTransforms.count(); }
202a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt
203a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt    /** Returns the coordinate transformation at index. index must be valid according to
204a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt        numTransforms(). */
205a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt    const GrCoordTransform& coordTransform(int index) const { return *fCoordTransforms[index]; }
206a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt
207b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    /** Will this effect read the destination pixel value? */
208b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    bool willReadDstColor() const { return fWillReadDstColor; }
209b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
210b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    /** Will this effect read the source color value? */
211b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    bool willUseInputColor() const { return fWillUseInputColor; }
212b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
213b0a8a377f832c59cee939ad721e1f87d378b7142joshualittprotected:
214b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    /**
215a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt     * Fragment Processor subclasses call this from their constructor to register coordinate
216a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt     * transformations. The processor subclass manages the lifetime of the transformations (this
217a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt     * function only stores a pointer). The GrCoordTransform is typically a member field of the
218a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt     * GrProcessor subclass. When the matrix has perspective, the transformed coordinates will have
219a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt     * 3 components. Otherwise they'll have 2. This must only be called from the constructor because
220a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt     * GrProcessors are immutable.
221a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt     */
222a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt    void addCoordTransform(const GrCoordTransform*);
223a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt
224a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt    /**
225b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     * If the effect subclass will read the destination pixel value then it must call this function
226b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     * from its constructor. Otherwise, when its generated backend-specific effect class attempts
227b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     * to generate code that reads the destination pixel it will fail.
228b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     */
229b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    void setWillReadDstColor() { fWillReadDstColor = true; }
230b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
231b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    /**
232b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     * If the effect will generate a result that does not depend on the input color value then it
233b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     * must call this function from its constructor. Otherwise, when its generated backend-specific
234b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     * code might fail during variable binding due to unused variables.
235b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt     */
236b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    void setWillNotUseInputColor() { fWillUseInputColor = false; }
237b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
238b0a8a377f832c59cee939ad721e1f87d378b7142joshualittprivate:
239a5305a110ab5201d5dadd40cbe711582d5ac4996joshualitt    SkSTArray<4, const GrCoordTransform*, true>  fCoordTransforms;
240b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    bool                                         fWillReadDstColor;
241b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    bool                                         fWillUseInputColor;
242b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
243b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    typedef GrProcessor INHERITED;
244b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt};
245b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
246d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com/**
247d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com * This creates an effect outside of the effect memory pool. The effect's destructor will be called
248b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt * at global destruction time. NAME will be the name of the created GrProcessor.
249d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com */
250b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt#define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS)                             \
25197b9ab72cd5ee0cba4692082737266376425f27cbsalomonstatic SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;                                \
252b0a8a377f832c59cee939ad721e1f87d378b7142joshualittstatic GrFragmentProcessor*                                                                       \
253b0a8a377f832c59cee939ad721e1f87d378b7142joshualittNAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);                          \
254b0a8a377f832c59cee939ad721e1f87d378b7142joshualittstatic SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME);
255d42aca31b9ddc1cb9a81522b4c73a9fe550450bcbsalomon@google.com
256168e63418cadba4018aadf95c091d40d9deb13b9tomhudson@google.com#endif
257