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 15class GrGLBitmapTextGeoProc; 16class GrInvariantOutput; 17class 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 */ 24class GrBitmapTextGeoProc : public GrGeometryProcessor { 25public: 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 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 48 ~GrBitmapTextGeoProc() override {} 49 50 const char* name() const override { return "BitmapText"; } 51 52 SkString getShaderDfxInfo() const override; 53 54 void addNewViews(const GrSurfaceProxyView*, int numActiveViews, GrSamplerState); 55 56 void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override; 57 58 std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps& caps) const override; 59 60private: 61 class Impl; 62 63 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor, 64 const GrSurfaceProxyView* views, int numViews, GrSamplerState params, 65 GrMaskFormat format, const SkMatrix& localMatrix, bool usesW); 66 67 bool hasVertexColor() const { return fInColor.isInitialized(); } 68 69 const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; } 70 71 SkPMColor4f fColor; 72 SkMatrix fLocalMatrix; 73 bool fUsesW; 74 SkISize fAtlasDimensions; // dimensions for all textures used with fTextureSamplers[]. 75 TextureSampler fTextureSamplers[kMaxTextures]; 76 Attribute fInPosition; 77 Attribute fInColor; 78 Attribute fInTextureCoords; 79 GrMaskFormat fMaskFormat; 80 81 GR_DECLARE_GEOMETRY_PROCESSOR_TEST 82 83 using INHERITED = GrGeometryProcessor; 84}; 85 86#endif 87