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 "include/core/SkRefCnt.h" 12 #include "src/base/SkArenaAlloc.h" 13 #include "src/gpu/AtlasTypes.h" 14 #include "src/gpu/ganesh/GrColorSpaceXform.h" 15 #include "src/gpu/ganesh/GrGeometryProcessor.h" 16 #include "src/gpu/ganesh/GrProcessor.h" 17 #include "src/gpu/ganesh/GrProcessorUnitTest.h" 18 19 #include <utility> 20 21 class GrGLBitmapTextGeoProc; 22 class GrInvariantOutput; 23 class GrSurfaceProxyView; 24 25 /** 26 * The output color of this effect is a modulation of the input color and a sample from a texture. 27 * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input 28 * coords are a custom attribute. 29 */ 30 class GrBitmapTextGeoProc : public GrGeometryProcessor { 31 public: 32 inline static constexpr int kMaxTextures = 4; 33 Make(SkArenaAlloc * arena,const GrShaderCaps & caps,const SkPMColor4f & color,bool wideColor,sk_sp<GrColorSpaceXform> colorSpaceXform,const GrSurfaceProxyView * views,int numActiveViews,GrSamplerState p,skgpu::MaskFormat format,const SkMatrix & localMatrix,bool usesW)34 static GrGeometryProcessor* Make(SkArenaAlloc* arena, 35 const GrShaderCaps& caps, 36 const SkPMColor4f& color, 37 bool wideColor, 38 sk_sp<GrColorSpaceXform> colorSpaceXform, 39 const GrSurfaceProxyView* views, 40 int numActiveViews, 41 GrSamplerState p, 42 skgpu::MaskFormat format, 43 const SkMatrix& localMatrix, 44 bool usesW) { 45 return arena->make([&](void* ptr) { 46 return new (ptr) GrBitmapTextGeoProc(caps, color, wideColor, std::move(colorSpaceXform), 47 views, numActiveViews, 48 p, format, localMatrix, usesW); 49 }); 50 } 51 ~GrBitmapTextGeoProc()52 ~GrBitmapTextGeoProc() override {} 53 name()54 const char* name() const override { return "BitmapText"; } 55 56 void addNewViews(const GrSurfaceProxyView*, int numActiveViews, GrSamplerState); 57 58 void addToKey(const GrShaderCaps& caps, skgpu::KeyBuilder* b) const override; 59 60 std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps& caps) const override; 61 62 private: 63 class Impl; 64 65 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor, 66 sk_sp<GrColorSpaceXform> colorSpaceXform, 67 const GrSurfaceProxyView* views, int numViews, GrSamplerState params, 68 skgpu::MaskFormat format, const SkMatrix& localMatrix, bool usesW); 69 hasVertexColor()70 bool hasVertexColor() const { return fInColor.isInitialized(); } 71 onTextureSampler(int i)72 const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; } 73 74 SkPMColor4f fColor; 75 sk_sp<GrColorSpaceXform> fColorSpaceXform; 76 SkMatrix fLocalMatrix; 77 bool fUsesW; 78 SkISize fAtlasDimensions; // dims for all textures used with fTextureSamplers 79 TextureSampler fTextureSamplers[kMaxTextures]; 80 Attribute fInPosition; 81 Attribute fInColor; 82 Attribute fInTextureCoords; 83 skgpu::MaskFormat fMaskFormat; 84 85 GR_DECLARE_GEOMETRY_PROCESSOR_TEST 86 87 using INHERITED = GrGeometryProcessor; 88 }; 89 90 #endif 91