1 /* 2 * Copyright 2021 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 #ifndef SkTextCoordShader_DEFINED 8 #define SkTextCoordShader_DEFINED 9 10 #include "src/core/SkVM.h" 11 #include "src/shaders/SkShaderBase.h" 12 13 // SkTransformShader applies a matrix transform to the shader coordinates, like a local matrix 14 // shader. The difference with a typical local matrix shader is that this shader's matrix is 15 // not combined with the inverse CTM or other local matrices in order to facilitate modifying the 16 // matrix between uses of the SkVM or SkRasterPipeline. This supports drawVertices and drawAtlas, in 17 // which the mapping from each triangle (when explicit texture coords are used) or atlas quad to 18 // shader space is different. 19 class SkTransformShader : public SkShaderBase { 20 public: 21 explicit SkTransformShader(const SkShaderBase& shader, bool allowPerspective); 22 23 // Adds instructions to use the mapping stored in the uniforms represented by fMatrix. After 24 // generating a new skvm::Coord, it passes the mapped coordinates to fShader's program 25 // along with the identity matrix. 26 skvm::Color program(skvm::Builder* b, 27 skvm::Coord device, 28 skvm::Coord local, 29 skvm::Color color, 30 const MatrixRec& mRec, 31 const SkColorInfo& dst, 32 skvm::Uniforms* uniforms, 33 SkArenaAlloc* alloc) const override; 34 35 // Adds a pipestage to multiply the incoming coords in 'r' and 'g' by the matrix. The child 36 // shader is called with no pending local matrix and the total transform as unknowable. 37 bool appendStages(const SkStageRec& rec, const MatrixRec&) const override; 38 39 // Change the matrix used by the generated SkRasterpipeline or SkVM. 40 bool update(const SkMatrix& matrix); 41 42 // These are never serialized/deserialized getFactory()43 Factory getFactory() const override { 44 SkDEBUGFAIL("SkTransformShader shouldn't be serialized."); 45 return {}; 46 } getTypeName()47 const char* getTypeName() const override { 48 SkDEBUGFAIL("SkTransformShader shouldn't be serialized."); 49 return nullptr; 50 } 51 isOpaque()52 bool isOpaque() const override { return fShader.isOpaque(); } 53 54 private: 55 const SkShaderBase& fShader; 56 SkScalar fMatrixStorage[9]; // actual memory used by generated RP or VM 57 bool fAllowPerspective; 58 }; 59 #endif //SkTextCoordShader_DEFINED 60