aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrSingleTextureEffect.h
blob: 899755c4df99d8c385da0f02568dfe0e3e601e34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrSingleTextureEffect_DEFINED
#define GrSingleTextureEffect_DEFINED

#include "GrProcessor.h"
#include "SkMatrix.h"
#include "GrCoordTransform.h"

class GrTexture;

/**
 * A base class for effects that draw a single texture with a texture matrix. This effect has no
 * backend implementations. One must be provided by the subclass.
 */
class GrSingleTextureEffect : public GrFragmentProcessor {
public:
    virtual ~GrSingleTextureEffect();

protected:
    /** unfiltered, clamp mode */
    GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet);
    /** clamp mode */
    GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode,
                          GrCoordSet = kLocal_GrCoordSet);
    GrSingleTextureEffect(GrTexture*,
                          const SkMatrix&,
                          const GrTextureParams&,
                          GrCoordSet = kLocal_GrCoordSet);

    /**
     * Helper for subclass onIsEqual() functions.
     */
    bool hasSameTextureParamsMatrixAndSourceCoords(const GrSingleTextureEffect& other) const {
        // We don't have to check the accesses' swizzles because they are inferred from the texture.
        return fTextureAccess == other.fTextureAccess &&
               fCoordTransform.getMatrix().cheapEqualTo(other.fCoordTransform.getMatrix()) &&
               fCoordTransform.sourceCoords() == other.fCoordTransform.sourceCoords();
    }

    /**
     * Can be used as a helper to implement subclass onComputeInvariantOutput(). It assumes that
     * the subclass output color will be a modulation of the input color with a value read from the
     * texture.
     */
    void updateInvariantOutputForModulation(InvariantOutput* inout) const {
        if (GrPixelConfigIsOpaque(this->texture(0)->config())) {
            inout->mulByUnknownOpaqueColor();
        } else {
            inout->mulByUnknownColor();
        }
    }

private:
    GrCoordTransform fCoordTransform;
    GrTextureAccess  fTextureAccess;

    typedef GrFragmentProcessor INHERITED;
};

#endif