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 "GrFragmentProcessor.h" 12 #include "GrColorSpaceXform.h" 13 #include "GrCoordTransform.h" 14 #include "SkMatrix.h" 15 16 class GrTexture; 17 class GrTextureProxy; 18 19 /** 20 * A base class for effects that draw a single texture with a texture matrix. This effect has no 21 * backend implementations. One must be provided by the subclass. 22 */ 23 class GrSingleTextureEffect : public GrFragmentProcessor { 24 public: dumpInfo()25 SkString dumpInfo() const override { 26 SkString str; 27 str.appendf("Texture: %d", fTextureSampler.texture()->uniqueID().asUInt()); 28 return str; 29 } 30 colorSpaceXform()31 GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); } 32 33 protected: 34 /** unfiltered, clamp mode */ 35 GrSingleTextureEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix&, 36 OptimizationFlags optFlags); 37 /** clamp mode */ 38 GrSingleTextureEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix&, 39 GrSamplerParams::FilterMode filterMode, OptimizationFlags optFlags); 40 GrSingleTextureEffect(GrTexture*, 41 sk_sp<GrColorSpaceXform>, 42 const SkMatrix&, 43 const GrSamplerParams&, 44 OptimizationFlags optFlags); 45 46 /** unfiltered, clamp mode */ 47 GrSingleTextureEffect(GrResourceProvider*, OptimizationFlags, sk_sp<GrTextureProxy>, 48 sk_sp<GrColorSpaceXform>, const SkMatrix&); 49 /** clamp mode */ 50 GrSingleTextureEffect(GrResourceProvider*, OptimizationFlags, sk_sp<GrTextureProxy>, 51 sk_sp<GrColorSpaceXform>, const SkMatrix&, 52 GrSamplerParams::FilterMode filterMode); 53 GrSingleTextureEffect(GrResourceProvider*, OptimizationFlags, sk_sp<GrTextureProxy>, 54 sk_sp<GrColorSpaceXform>, const SkMatrix&, const GrSamplerParams&); 55 56 /** 57 * Can be used as a helper to decide which fragment processor OptimizationFlags should be set. 58 * This assumes that the subclass output color will be a modulation of the input color with a 59 * value read from the texture and that the texture contains premultiplied color or alpha values 60 * that are in range. 61 */ ModulationFlags(GrPixelConfig config)62 static OptimizationFlags ModulationFlags(GrPixelConfig config) { 63 if (GrPixelConfigIsOpaque(config)) { 64 return kCompatibleWithCoverageAsAlpha_OptimizationFlag | 65 kPreservesOpaqueInput_OptimizationFlag; 66 } else { 67 return kCompatibleWithCoverageAsAlpha_OptimizationFlag; 68 } 69 } 70 71 private: 72 GrCoordTransform fCoordTransform; 73 TextureSampler fTextureSampler; 74 sk_sp<GrColorSpaceXform> fColorSpaceXform; 75 76 typedef GrFragmentProcessor INHERITED; 77 }; 78 79 #endif 80