• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 allows the transform used by the shader to change without regenerating the
14 // jitted code. This supports the drawVertices call to change the mapping as the texture
15 // coordinates associated with each vertex change with each new triangle.
16 class SkTransformShader : public SkUpdatableShader {
17 public:
18     explicit SkTransformShader(const SkShaderBase& shader);
19 
20     // Adds instructions to use the mapping stored in the uniforms represented by fMatrix. After
21     // generating a new skvm::Coord, it passes the mapped coordinates to fShader's onProgram
22     // along with the identity matrix.
23     skvm::Color onProgram(skvm::Builder* b,
24                           skvm::Coord device, skvm::Coord local, skvm::Color color,
25                           const SkMatrixProvider& matrices, const SkMatrix* localM,
26                           const SkColorInfo& dst,
27                           skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override;
28 
29     // Add code to calculate a new coordinate given local using the mapping in fMatrix.
30     skvm::Coord applyMatrix(
31             skvm::Builder* b, const SkMatrix& matrix, skvm::Coord local,
32             skvm::Uniforms* uniforms) const;
33     void appendMatrix(const SkMatrix& matrix, SkRasterPipeline* p) const;
34 
35     // Change the values represented by the uniforms in fMatrix.
36     bool update(const SkMatrix& ctm) const override;
37     bool onAppendStages(const SkStageRec& rec) const override;
38 
39 private:
40     const SkShaderBase& fShader;
41     mutable SkScalar fMatrixStorage[9];
42     mutable skvm::Uniform fMatrix;
43     mutable bool fProcessingAsPerspective{false};
44 
45 };
46 #endif  //SkTextCoordShader_DEFINED
47