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.
     18  */
     19 class GrSingleTextureEffect : public GrEffect {
     20 public:
     21     virtual ~GrSingleTextureEffect();
     22 
     23     const SkMatrix& getMatrix() const { return fMatrix; }
     24 
     25 protected:
     26     GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */
     27     GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */
     28     GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&);
     29 
     30     /**
     31      * Helper for subclass onIsEqual() functions.
     32      */
     33     bool hasSameTextureParamsAndMatrix(const GrSingleTextureEffect& other) const {
     34         const GrTextureAccess& otherAccess = other.fTextureAccess;
     35         // We don't have to check the accesses' swizzles because they are inferred from the texture.
     36         return fTextureAccess.getTexture() == otherAccess.getTexture() &&
     37                fTextureAccess.getParams() == otherAccess.getParams() &&
     38                this->getMatrix().cheapEqualTo(other.getMatrix());
     39     }
     40 
     41     /**
     42      * Can be used as a helper to implement subclass getConstantColorComponents(). It assumes that
     43      * the subclass output color will be a modulation of the input color with a value read from the
     44      * texture.
     45      */
     46     void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* validFlags) const {
     47         if ((*validFlags & kA_ValidComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
     48             GrPixelConfigIsOpaque(this->texture(0)->config())) {
     49             *validFlags = kA_ValidComponentFlag;
     50         } else {
     51             *validFlags = 0;
     52         }
     53     }
     54 
     55 private:
     56     GrTextureAccess fTextureAccess;
     57     SkMatrix        fMatrix;
     58 
     59     typedef GrEffect INHERITED;
     60 };
     61 
     62 #endif
     63