• 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/core/SkArenaAlloc.h"
12 #include "src/gpu/GrGeometryProcessor.h"
13 #include "src/gpu/GrProcessor.h"
14 
15 class GrGLBitmapTextGeoProc;
16 class GrInvariantOutput;
17 class GrSurfaceProxyView;
18 
19 /**
20  * The output color of this effect is a modulation of the input color and a sample from a texture.
21  * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input
22  * coords are a custom attribute.
23  */
24 class GrBitmapTextGeoProc : public GrGeometryProcessor {
25 public:
26     inline static constexpr int kMaxTextures = 4;
27 
Make(SkArenaAlloc * arena,const GrShaderCaps & caps,const SkPMColor4f & color,bool wideColor,const GrSurfaceProxyView * views,int numActiveViews,GrSamplerState p,GrMaskFormat format,const SkMatrix & localMatrix,bool usesW)28     static GrGeometryProcessor* Make(SkArenaAlloc* arena,
29                                      const GrShaderCaps& caps,
30                                      const SkPMColor4f& color,
31                                      bool wideColor,
32                                      const GrSurfaceProxyView* views,
33                                      int numActiveViews,
34                                      GrSamplerState p,
35                                      GrMaskFormat format,
36                                      const SkMatrix& localMatrix,
37                                      bool usesW) {
38         return arena->make([&](void* ptr) {
39             return new (ptr) GrBitmapTextGeoProc(caps, color, wideColor, views, numActiveViews,
40                                                  p, format, localMatrix, usesW);
41         });
42     }
43 
~GrBitmapTextGeoProc()44     ~GrBitmapTextGeoProc() override {}
45 
name()46     const char* name() const override { return "BitmapText"; }
47 
48     void addNewViews(const GrSurfaceProxyView*, int numActiveViews, GrSamplerState);
49 
50     void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
51 
52     std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps& caps) const override;
53 
54 private:
55     class Impl;
56 
57     GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor,
58                         const GrSurfaceProxyView* views, int numViews, GrSamplerState params,
59                         GrMaskFormat format, const SkMatrix& localMatrix, bool usesW);
60 
hasVertexColor()61     bool hasVertexColor() const { return fInColor.isInitialized(); }
62 
onTextureSampler(int i)63     const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
64 
65     SkPMColor4f      fColor;
66     SkMatrix         fLocalMatrix;
67     bool             fUsesW;
68     SkISize          fAtlasDimensions;  // dimensions 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     using INHERITED = GrGeometryProcessor;
78 };
79 
80 #endif
81