Home | History | Annotate | Download | only in effects
      1 /*
      2  * Copyright 2013 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 GrSimpleTextureEffect_DEFINED
      9 #define GrSimpleTextureEffect_DEFINED
     10 
     11 #include "GrSingleTextureEffect.h"
     12 
     13 class GrInvariantOutput;
     14 
     15 /**
     16  * The output color of this effect is a modulation of the input color and a sample from a texture.
     17  * It allows explicit specification of the filtering and wrap modes (GrTextureParams). It can use
     18  * local coords or device space coords as input texture coords. The input coords may be transformed
     19  * by a matrix.
     20  */
     21 class GrSimpleTextureEffect : public GrSingleTextureEffect {
     22 public:
     23     /* unfiltered, clamp mode */
     24     static const GrFragmentProcessor* Create(GrTexture* tex,
     25                                              const SkMatrix& matrix,
     26                                              GrCoordSet coordSet = kLocal_GrCoordSet) {
     27         return new GrSimpleTextureEffect(tex, matrix, GrTextureParams::kNone_FilterMode, coordSet);
     28     }
     29 
     30     /* clamp mode */
     31     static GrFragmentProcessor* Create(GrTexture* tex,
     32                                        const SkMatrix& matrix,
     33                                        GrTextureParams::FilterMode filterMode,
     34                                        GrCoordSet coordSet = kLocal_GrCoordSet) {
     35         return new GrSimpleTextureEffect(tex, matrix, filterMode, coordSet);
     36     }
     37 
     38     static GrFragmentProcessor* Create(GrTexture* tex,
     39                                        const SkMatrix& matrix,
     40                                        const GrTextureParams& p,
     41                                        GrCoordSet coordSet = kLocal_GrCoordSet) {
     42         return new GrSimpleTextureEffect(tex, matrix, p, coordSet);
     43     }
     44 
     45     virtual ~GrSimpleTextureEffect() {}
     46 
     47     const char* name() const override { return "SimpleTexture"; }
     48 
     49 private:
     50     GrSimpleTextureEffect(GrTexture* texture,
     51                           const SkMatrix& matrix,
     52                           GrTextureParams::FilterMode filterMode,
     53                           GrCoordSet coordSet)
     54         : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) {
     55         this->initClassID<GrSimpleTextureEffect>();
     56     }
     57 
     58     GrSimpleTextureEffect(GrTexture* texture,
     59                           const SkMatrix& matrix,
     60                           const GrTextureParams& params,
     61                           GrCoordSet coordSet)
     62         : GrSingleTextureEffect(texture, matrix, params, coordSet) {
     63         this->initClassID<GrSimpleTextureEffect>();
     64     }
     65 
     66     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
     67 
     68     void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override;
     69 
     70     bool onIsEqual(const GrFragmentProcessor& other) const override { return true; }
     71 
     72     void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
     73 
     74     GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
     75 
     76     typedef GrSingleTextureEffect INHERITED;
     77 };
     78 
     79 #endif
     80