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 #ifdef SK_ENABLE_SMALL_PAGE 27 inline static constexpr int kMaxTextures = 16; 28 #else 29 inline static constexpr int kMaxTextures = 4; 30 #endif 31 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)32 static GrGeometryProcessor* Make(SkArenaAlloc* arena, 33 const GrShaderCaps& caps, 34 const SkPMColor4f& color, 35 bool wideColor, 36 const GrSurfaceProxyView* views, 37 int numActiveViews, 38 GrSamplerState p, 39 GrMaskFormat format, 40 const SkMatrix& localMatrix, 41 bool usesW) { 42 return arena->make([&](void* ptr) { 43 return new (ptr) GrBitmapTextGeoProc(caps, color, wideColor, views, numActiveViews, 44 p, format, localMatrix, usesW); 45 }); 46 } 47 ~GrBitmapTextGeoProc()48 ~GrBitmapTextGeoProc() override {} 49 name()50 const char* name() const override { return "BitmapText"; } 51 52 void addNewViews(const GrSurfaceProxyView*, int numActiveViews, GrSamplerState); 53 54 void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override; 55 56 std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps& caps) const override; 57 58 private: 59 class Impl; 60 61 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor, 62 const GrSurfaceProxyView* views, int numViews, GrSamplerState params, 63 GrMaskFormat format, const SkMatrix& localMatrix, bool usesW); 64 hasVertexColor()65 bool hasVertexColor() const { return fInColor.isInitialized(); } 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 fAtlasDimensions; // dimensions 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 using INHERITED = GrGeometryProcessor; 82 }; 83 84 #endif 85