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 GrBitmapTextGeoProc_DEFINED
      9 #define GrBitmapTextGeoProc_DEFINED
     10 
     11 #include "GrProcessor.h"
     12 #include "GrGeometryProcessor.h"
     13 
     14 class GrGLBitmapTextGeoProc;
     15 class GrInvariantOutput;
     16 
     17 /**
     18  * The output color of this effect is a modulation of the input color and a sample from a texture.
     19  * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input
     20  * coords are a custom attribute.
     21  */
     22 class GrBitmapTextGeoProc : public GrGeometryProcessor {
     23 public:
     24     static constexpr int kMaxTextures = 4;
     25 
     26     static sk_sp<GrGeometryProcessor> Make(const GrShaderCaps& caps,
     27                                            const SkPMColor4f& color, bool wideColor,
     28                                            const sk_sp<GrTextureProxy>* proxies,
     29                                            int numActiveProxies,
     30                                            const GrSamplerState& p, GrMaskFormat format,
     31                                            const SkMatrix& localMatrix, bool usesW) {
     32         return sk_sp<GrGeometryProcessor>(
     33             new GrBitmapTextGeoProc(caps, color, wideColor, proxies, numActiveProxies, p, format,
     34                                     localMatrix, usesW));
     35     }
     36 
     37     ~GrBitmapTextGeoProc() override {}
     38 
     39     const char* name() const override { return "Texture"; }
     40 
     41     const Attribute& inPosition() const { return fInPosition; }
     42     const Attribute& inColor() const { return fInColor; }
     43     const Attribute& inTextureCoords() const { return fInTextureCoords; }
     44     GrMaskFormat maskFormat() const { return fMaskFormat; }
     45     const SkPMColor4f& color() const { return fColor; }
     46     bool hasVertexColor() const { return fInColor.isInitialized(); }
     47     const SkMatrix& localMatrix() const { return fLocalMatrix; }
     48     bool usesW() const { return fUsesW; }
     49     const SkISize& atlasSize() const { return fAtlasSize; }
     50 
     51     void addNewProxies(const sk_sp<GrTextureProxy>*, int numActiveProxies, const GrSamplerState&);
     52 
     53     void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
     54 
     55     GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override;
     56 
     57 private:
     58     GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor,
     59                         const sk_sp<GrTextureProxy>* proxies, int numProxies,
     60                         const GrSamplerState& params, GrMaskFormat format,
     61                         const SkMatrix& localMatrix, bool usesW);
     62 
     63     const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
     64 
     65     SkPMColor4f      fColor;
     66     SkMatrix         fLocalMatrix;
     67     bool             fUsesW;
     68     SkISize          fAtlasSize;  // size for all textures used with fTextureSamplers[].
     69     TextureSampler   fTextureSamplers[kMaxTextures];
     70     Attribute        fInPosition;
     71     Attribute        fInColor;
     72     Attribute        fInTextureCoords;
     73     GrMaskFormat     fMaskFormat;
     74 
     75     GR_DECLARE_GEOMETRY_PROCESSOR_TEST
     76 
     77     typedef GrGeometryProcessor INHERITED;
     78 };
     79 
     80 #endif
     81