Home | History | Annotate | Download | only in effects
      1 /*
      2  * Copyright 2012 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 GrSingleTextureEffect_DEFINED
      9 #define GrSingleTextureEffect_DEFINED
     10 
     11 #include "GrEffect.h"
     12 #include "SkMatrix.h"
     13 
     14 class GrTexture;
     15 
     16 /**
     17  * A base class for effects that draw a single texture with a texture matrix. This effect has no
     18  * backend implementations. One must be provided by the subclass.
     19  */
     20 class GrSingleTextureEffect : public GrEffect {
     21 public:
     22     virtual ~GrSingleTextureEffect();
     23 
     24     const SkMatrix& getMatrix() const { return fMatrix; }
     25 
     26     /** Indicates whether the matrix operates on local coords or positions */
     27     CoordsType coordsType() const { return fCoordsType; }
     28 
     29 protected:
     30     /** unfiltered, clamp mode */
     31     GrSingleTextureEffect(GrTexture*, const SkMatrix&, CoordsType = kLocal_CoordsType);
     32     /** clamp mode */
     33     GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode,
     34                           CoordsType = kLocal_CoordsType);
     35     GrSingleTextureEffect(GrTexture*,
     36                           const SkMatrix&,
     37                           const GrTextureParams&,
     38                           CoordsType = kLocal_CoordsType);
     39 
     40     /**
     41      * Helper for subclass onIsEqual() functions.
     42      */
     43     bool hasSameTextureParamsMatrixAndCoordsType(const GrSingleTextureEffect& other) const {
     44         const GrTextureAccess& otherAccess = other.fTextureAccess;
     45         // We don't have to check the accesses' swizzles because they are inferred from the texture.
     46         return fTextureAccess.getTexture() == otherAccess.getTexture() &&
     47                fTextureAccess.getParams() == otherAccess.getParams() &&
     48                this->getMatrix().cheapEqualTo(other.getMatrix()) &&
     49                fCoordsType == other.fCoordsType;
     50     }
     51 
     52     /**
     53      * Can be used as a helper to implement subclass getConstantColorComponents(). It assumes that
     54      * the subclass output color will be a modulation of the input color with a value read from the
     55      * texture.
     56      */
     57     void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* validFlags) const {
     58         if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
     59             GrPixelConfigIsOpaque(this->texture(0)->config())) {
     60             *validFlags = kA_GrColorComponentFlag;
     61         } else {
     62             *validFlags = 0;
     63         }
     64     }
     65 
     66 private:
     67     GrTextureAccess fTextureAccess;
     68     SkMatrix        fMatrix;
     69     CoordsType      fCoordsType;
     70 
     71     typedef GrEffect INHERITED;
     72 };
     73 
     74 #endif
     75