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 #ifdef SK_ENABLE_SMALL_PAGE 40 inline static constexpr int kMaxTextures = 16; 41 #else 42 inline static constexpr int kMaxTextures = 4; 43 #endif 44 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)45 static GrGeometryProcessor* Make(SkArenaAlloc* arena, 46 const GrShaderCaps& caps, 47 const SkPMColor4f& color, 48 bool wideColor, 49 sk_sp<GrColorSpaceXform> colorSpaceXform, 50 const GrSurfaceProxyView* views, 51 int numActiveViews, 52 GrSamplerState p, 53 skgpu::MaskFormat format, 54 const SkMatrix& localMatrix, 55 bool usesW) { 56 return arena->make([&](void* ptr) { 57 return new (ptr) GrBitmapTextGeoProc(caps, color, wideColor, std::move(colorSpaceXform), 58 views, numActiveViews, 59 p, format, localMatrix, usesW); 60 }); 61 } 62 ~GrBitmapTextGeoProc()63 ~GrBitmapTextGeoProc() override {} 64 name()65 const char* name() const override { return "BitmapText"; } 66 67 void addNewViews(const GrSurfaceProxyView*, int numActiveViews, GrSamplerState); 68 69 void addToKey(const GrShaderCaps& caps, skgpu::KeyBuilder* b) const override; 70 71 std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps& caps) const override; 72 73 private: 74 class Impl; 75 76 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor, 77 sk_sp<GrColorSpaceXform> colorSpaceXform, 78 const GrSurfaceProxyView* views, int numViews, GrSamplerState params, 79 skgpu::MaskFormat format, const SkMatrix& localMatrix, bool usesW); 80 hasVertexColor()81 bool hasVertexColor() const { return fInColor.isInitialized(); } 82 onTextureSampler(int i)83 const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; } 84 85 SkPMColor4f fColor; 86 sk_sp<GrColorSpaceXform> fColorSpaceXform; 87 SkMatrix fLocalMatrix; 88 bool fUsesW; 89 SkISize fAtlasDimensions; // dims for all textures used with fTextureSamplers 90 TextureSampler fTextureSamplers[kMaxTextures]; 91 Attribute fInPosition; 92 Attribute fInColor; 93 Attribute fInTextureCoords; 94 skgpu::MaskFormat fMaskFormat; 95 96 GR_DECLARE_GEOMETRY_PROCESSOR_TEST 97 98 using INHERITED = GrGeometryProcessor; 99 }; 100 101 #endif 102