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