• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/gpu/GrGeometryProcessor.h"
12 #include "src/gpu/GrProcessor.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 #ifdef SK_ENABLE_SMALL_PAGE
25     static constexpr int kMaxTextures = 16;
26 #else
27     static constexpr int kMaxTextures = 4;
28 #endif
29 
Make(const GrShaderCaps & caps,const SkPMColor4f & color,bool wideColor,const sk_sp<GrTextureProxy> * proxies,int numActiveProxies,const GrSamplerState & p,GrMaskFormat format,const SkMatrix & localMatrix,bool usesW)30     static sk_sp<GrGeometryProcessor> Make(const GrShaderCaps& caps,
31                                            const SkPMColor4f& color, bool wideColor,
32                                            const sk_sp<GrTextureProxy>* proxies,
33                                            int numActiveProxies,
34                                            const GrSamplerState& p, GrMaskFormat format,
35                                            const SkMatrix& localMatrix, bool usesW) {
36         return sk_sp<GrGeometryProcessor>(
37             new GrBitmapTextGeoProc(caps, color, wideColor, proxies, numActiveProxies, p, format,
38                                     localMatrix, usesW));
39     }
40 
~GrBitmapTextGeoProc()41     ~GrBitmapTextGeoProc() override {}
42 
name()43     const char* name() const override { return "Texture"; }
44 
inPosition()45     const Attribute& inPosition() const { return fInPosition; }
inColor()46     const Attribute& inColor() const { return fInColor; }
inTextureCoords()47     const Attribute& inTextureCoords() const { return fInTextureCoords; }
maskFormat()48     GrMaskFormat maskFormat() const { return fMaskFormat; }
color()49     const SkPMColor4f& color() const { return fColor; }
hasVertexColor()50     bool hasVertexColor() const { return fInColor.isInitialized(); }
localMatrix()51     const SkMatrix& localMatrix() const { return fLocalMatrix; }
usesW()52     bool usesW() const { return fUsesW; }
atlasSize()53     const SkISize& atlasSize() const { return fAtlasSize; }
54 
55     void addNewProxies(const sk_sp<GrTextureProxy>*, int numActiveProxies, const GrSamplerState&);
56 
57     void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
58 
59     GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override;
60 
61 private:
62     GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor,
63                         const sk_sp<GrTextureProxy>* proxies, int numProxies,
64                         const GrSamplerState& params, GrMaskFormat format,
65                         const SkMatrix& localMatrix, bool usesW);
66 
onTextureSampler(int i)67     const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
68 
69     SkPMColor4f      fColor;
70     SkMatrix         fLocalMatrix;
71     bool             fUsesW;
72     SkISize          fAtlasSize;  // size for all textures used with fTextureSamplers[].
73     TextureSampler   fTextureSamplers[kMaxTextures];
74     Attribute        fInPosition;
75     Attribute        fInColor;
76     Attribute        fInTextureCoords;
77     GrMaskFormat     fMaskFormat;
78 
79     GR_DECLARE_GEOMETRY_PROCESSOR_TEST
80 
81     typedef GrGeometryProcessor INHERITED;
82 };
83 
84 #endif
85