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 (GrSamplerParams). The input
20  * coords are a custom attribute.
21  */
22 class GrBitmapTextGeoProc : public GrGeometryProcessor {
23 public:
Make(GrResourceProvider * resourceProvider,GrColor color,sk_sp<GrTextureProxy> proxy,const GrSamplerParams & p,GrMaskFormat format,const SkMatrix & localMatrix,bool usesLocalCoords)24     static sk_sp<GrGeometryProcessor> Make(GrResourceProvider* resourceProvider, GrColor color,
25                                            sk_sp<GrTextureProxy> proxy, const GrSamplerParams& p,
26                                            GrMaskFormat format, const SkMatrix& localMatrix,
27                                            bool usesLocalCoords) {
28         return sk_sp<GrGeometryProcessor>(
29             new GrBitmapTextGeoProc(resourceProvider, color, std::move(proxy), p, format,
30                                     localMatrix, usesLocalCoords));
31     }
32 
~GrBitmapTextGeoProc()33     ~GrBitmapTextGeoProc() override {}
34 
name()35     const char* name() const override { return "Texture"; }
36 
inPosition()37     const Attribute* inPosition() const { return fInPosition; }
inColor()38     const Attribute* inColor() const { return fInColor; }
inTextureCoords()39     const Attribute* inTextureCoords() const { return fInTextureCoords; }
maskFormat()40     GrMaskFormat maskFormat() const { return fMaskFormat; }
color()41     GrColor color() const { return fColor; }
hasVertexColor()42     bool hasVertexColor() const { return SkToBool(fInColor); }
localMatrix()43     const SkMatrix& localMatrix() const { return fLocalMatrix; }
usesLocalCoords()44     bool usesLocalCoords() const { return fUsesLocalCoords; }
45 
46     void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
47 
48     GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override;
49 
50 private:
51     GrBitmapTextGeoProc(GrResourceProvider*, GrColor, sk_sp<GrTextureProxy>,
52                         const GrSamplerParams& params,
53                         GrMaskFormat format, const SkMatrix& localMatrix, bool usesLocalCoords);
54 
55     GrColor          fColor;
56     SkMatrix         fLocalMatrix;
57     bool             fUsesLocalCoords;
58     TextureSampler   fTextureSampler;
59     const Attribute* fInPosition;
60     const Attribute* fInColor;
61     const Attribute* fInTextureCoords;
62     GrMaskFormat     fMaskFormat;
63 
64     GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
65 
66     typedef GrGeometryProcessor INHERITED;
67 };
68 
69 #endif
70