1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2013 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef GrBitmapTextGeoProc_DEFINED 9cb93a386Sopenharmony_ci#define GrBitmapTextGeoProc_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "src/core/SkArenaAlloc.h" 12cb93a386Sopenharmony_ci#include "src/gpu/GrGeometryProcessor.h" 13cb93a386Sopenharmony_ci#include "src/gpu/GrProcessor.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ciclass GrGLBitmapTextGeoProc; 16cb93a386Sopenharmony_ciclass GrInvariantOutput; 17cb93a386Sopenharmony_ciclass GrSurfaceProxyView; 18cb93a386Sopenharmony_ci 19cb93a386Sopenharmony_ci/** 20cb93a386Sopenharmony_ci * The output color of this effect is a modulation of the input color and a sample from a texture. 21cb93a386Sopenharmony_ci * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input 22cb93a386Sopenharmony_ci * coords are a custom attribute. 23cb93a386Sopenharmony_ci */ 24cb93a386Sopenharmony_ciclass GrBitmapTextGeoProc : public GrGeometryProcessor { 25cb93a386Sopenharmony_cipublic: 26cb93a386Sopenharmony_ci#ifdef SK_ENABLE_SMALL_PAGE 27cb93a386Sopenharmony_ci inline static constexpr int kMaxTextures = 16; 28cb93a386Sopenharmony_ci#else 29cb93a386Sopenharmony_ci inline static constexpr int kMaxTextures = 4; 30cb93a386Sopenharmony_ci#endif 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci static GrGeometryProcessor* Make(SkArenaAlloc* arena, 33cb93a386Sopenharmony_ci const GrShaderCaps& caps, 34cb93a386Sopenharmony_ci const SkPMColor4f& color, 35cb93a386Sopenharmony_ci bool wideColor, 36cb93a386Sopenharmony_ci const GrSurfaceProxyView* views, 37cb93a386Sopenharmony_ci int numActiveViews, 38cb93a386Sopenharmony_ci GrSamplerState p, 39cb93a386Sopenharmony_ci GrMaskFormat format, 40cb93a386Sopenharmony_ci const SkMatrix& localMatrix, 41cb93a386Sopenharmony_ci bool usesW) { 42cb93a386Sopenharmony_ci return arena->make([&](void* ptr) { 43cb93a386Sopenharmony_ci return new (ptr) GrBitmapTextGeoProc(caps, color, wideColor, views, numActiveViews, 44cb93a386Sopenharmony_ci p, format, localMatrix, usesW); 45cb93a386Sopenharmony_ci }); 46cb93a386Sopenharmony_ci } 47cb93a386Sopenharmony_ci 48cb93a386Sopenharmony_ci ~GrBitmapTextGeoProc() override {} 49cb93a386Sopenharmony_ci 50cb93a386Sopenharmony_ci const char* name() const override { return "BitmapText"; } 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_ci SkString getShaderDfxInfo() const override; 53cb93a386Sopenharmony_ci 54cb93a386Sopenharmony_ci void addNewViews(const GrSurfaceProxyView*, int numActiveViews, GrSamplerState); 55cb93a386Sopenharmony_ci 56cb93a386Sopenharmony_ci void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override; 57cb93a386Sopenharmony_ci 58cb93a386Sopenharmony_ci std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps& caps) const override; 59cb93a386Sopenharmony_ci 60cb93a386Sopenharmony_ciprivate: 61cb93a386Sopenharmony_ci class Impl; 62cb93a386Sopenharmony_ci 63cb93a386Sopenharmony_ci GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor, 64cb93a386Sopenharmony_ci const GrSurfaceProxyView* views, int numViews, GrSamplerState params, 65cb93a386Sopenharmony_ci GrMaskFormat format, const SkMatrix& localMatrix, bool usesW); 66cb93a386Sopenharmony_ci 67cb93a386Sopenharmony_ci bool hasVertexColor() const { return fInColor.isInitialized(); } 68cb93a386Sopenharmony_ci 69cb93a386Sopenharmony_ci const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; } 70cb93a386Sopenharmony_ci 71cb93a386Sopenharmony_ci SkPMColor4f fColor; 72cb93a386Sopenharmony_ci SkMatrix fLocalMatrix; 73cb93a386Sopenharmony_ci bool fUsesW; 74cb93a386Sopenharmony_ci SkISize fAtlasDimensions; // dimensions for all textures used with fTextureSamplers[]. 75cb93a386Sopenharmony_ci TextureSampler fTextureSamplers[kMaxTextures]; 76cb93a386Sopenharmony_ci Attribute fInPosition; 77cb93a386Sopenharmony_ci Attribute fInColor; 78cb93a386Sopenharmony_ci Attribute fInTextureCoords; 79cb93a386Sopenharmony_ci GrMaskFormat fMaskFormat; 80cb93a386Sopenharmony_ci 81cb93a386Sopenharmony_ci GR_DECLARE_GEOMETRY_PROCESSOR_TEST 82cb93a386Sopenharmony_ci 83cb93a386Sopenharmony_ci using INHERITED = GrGeometryProcessor; 84cb93a386Sopenharmony_ci}; 85cb93a386Sopenharmony_ci 86cb93a386Sopenharmony_ci#endif 87