michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrSingleTextureEffect_DEFINED michael@0: #define GrSingleTextureEffect_DEFINED michael@0: michael@0: #include "GrEffect.h" michael@0: #include "SkMatrix.h" michael@0: #include "GrCoordTransform.h" michael@0: michael@0: class GrTexture; michael@0: michael@0: /** michael@0: * A base class for effects that draw a single texture with a texture matrix. This effect has no michael@0: * backend implementations. One must be provided by the subclass. michael@0: */ michael@0: class GrSingleTextureEffect : public GrEffect { michael@0: public: michael@0: virtual ~GrSingleTextureEffect(); michael@0: michael@0: protected: michael@0: /** unfiltered, clamp mode */ michael@0: GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet); michael@0: /** clamp mode */ michael@0: GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode, michael@0: GrCoordSet = kLocal_GrCoordSet); michael@0: GrSingleTextureEffect(GrTexture*, michael@0: const SkMatrix&, michael@0: const GrTextureParams&, michael@0: GrCoordSet = kLocal_GrCoordSet); michael@0: michael@0: /** michael@0: * Helper for subclass onIsEqual() functions. michael@0: */ michael@0: bool hasSameTextureParamsMatrixAndSourceCoords(const GrSingleTextureEffect& other) const { michael@0: // We don't have to check the accesses' swizzles because they are inferred from the texture. michael@0: return fTextureAccess == other.fTextureAccess && michael@0: fCoordTransform.getMatrix().cheapEqualTo(other.fCoordTransform.getMatrix()) && michael@0: fCoordTransform.sourceCoords() == other.fCoordTransform.sourceCoords(); michael@0: } michael@0: michael@0: /** michael@0: * Can be used as a helper to implement subclass getConstantColorComponents(). It assumes that michael@0: * the subclass output color will be a modulation of the input color with a value read from the michael@0: * texture. michael@0: */ michael@0: void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* validFlags) const { michael@0: if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) && michael@0: GrPixelConfigIsOpaque(this->texture(0)->config())) { michael@0: *validFlags = kA_GrColorComponentFlag; michael@0: } else { michael@0: *validFlags = 0; michael@0: } michael@0: } michael@0: michael@0: private: michael@0: GrCoordTransform fCoordTransform; michael@0: GrTextureAccess fTextureAccess; michael@0: michael@0: typedef GrEffect INHERITED; michael@0: }; michael@0: michael@0: #endif