gfx/skia/trunk/src/gpu/effects/GrSingleTextureEffect.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/effects/GrSingleTextureEffect.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef GrSingleTextureEffect_DEFINED
    1.12 +#define GrSingleTextureEffect_DEFINED
    1.13 +
    1.14 +#include "GrEffect.h"
    1.15 +#include "SkMatrix.h"
    1.16 +#include "GrCoordTransform.h"
    1.17 +
    1.18 +class GrTexture;
    1.19 +
    1.20 +/**
    1.21 + * A base class for effects that draw a single texture with a texture matrix. This effect has no
    1.22 + * backend implementations. One must be provided by the subclass.
    1.23 + */
    1.24 +class GrSingleTextureEffect : public GrEffect {
    1.25 +public:
    1.26 +    virtual ~GrSingleTextureEffect();
    1.27 +
    1.28 +protected:
    1.29 +    /** unfiltered, clamp mode */
    1.30 +    GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet);
    1.31 +    /** clamp mode */
    1.32 +    GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode,
    1.33 +                          GrCoordSet = kLocal_GrCoordSet);
    1.34 +    GrSingleTextureEffect(GrTexture*,
    1.35 +                          const SkMatrix&,
    1.36 +                          const GrTextureParams&,
    1.37 +                          GrCoordSet = kLocal_GrCoordSet);
    1.38 +
    1.39 +    /**
    1.40 +     * Helper for subclass onIsEqual() functions.
    1.41 +     */
    1.42 +    bool hasSameTextureParamsMatrixAndSourceCoords(const GrSingleTextureEffect& other) const {
    1.43 +        // We don't have to check the accesses' swizzles because they are inferred from the texture.
    1.44 +        return fTextureAccess == other.fTextureAccess &&
    1.45 +               fCoordTransform.getMatrix().cheapEqualTo(other.fCoordTransform.getMatrix()) &&
    1.46 +               fCoordTransform.sourceCoords() == other.fCoordTransform.sourceCoords();
    1.47 +    }
    1.48 +
    1.49 +    /**
    1.50 +     * Can be used as a helper to implement subclass getConstantColorComponents(). It assumes that
    1.51 +     * the subclass output color will be a modulation of the input color with a value read from the
    1.52 +     * texture.
    1.53 +     */
    1.54 +    void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* validFlags) const {
    1.55 +        if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
    1.56 +            GrPixelConfigIsOpaque(this->texture(0)->config())) {
    1.57 +            *validFlags = kA_GrColorComponentFlag;
    1.58 +        } else {
    1.59 +            *validFlags = 0;
    1.60 +        }
    1.61 +    }
    1.62 +
    1.63 +private:
    1.64 +    GrCoordTransform fCoordTransform;
    1.65 +    GrTextureAccess  fTextureAccess;
    1.66 +
    1.67 +    typedef GrEffect INHERITED;
    1.68 +};
    1.69 +
    1.70 +#endif

mercurial