Debian Codegraph @

src/shaders/SkTransformShader.h

raw
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 "include/core/SkScalar.h"
11 #include "include/private/base/SkAssert.h"
12 #include "src/shaders/SkShaderBase.h"
13
14 class SkMatrix;
15 struct SkStageRec;
16
17 // SkTransformShader applies a matrix transform to the shader coordinates, like a local matrix
18 // shader. The difference with a typical local matrix shader is that this shader's matrix is
19 // not combined with the inverse CTM or other local matrices in order to facilitate modifying the
20 // matrix between uses of the SkVM or SkRasterPipeline. This supports drawVertices and drawAtlas, in
21 // which the mapping from each triangle (when explicit texture coords are used) or atlas quad to
22 // shader space is different.
23 class SkTransformShader : public SkShaderBase {
24 public:
25 explicit SkTransformShader(const SkShaderBase& shader, bool allowPerspective);
26
27 // Adds a pipestage to multiply the incoming coords in 'r' and 'g' by the matrix. The child
28 // shader is called with no pending local matrix and the total transform as unknowable.
29 bool appendStages(const SkStageRec& rec, const SkShaders::MatrixRec&) const override;
30
31 // Change the matrix used by the generated SkRasterPipeline.
32 bool update(const SkMatrix& matrix);
33
34 ShaderType type() const override { return ShaderType::kTransform; }
35
36 // These are never serialized/deserialized
37 Factory getFactory() const override {
38 SkDEBUGFAIL("SkTransformShader shouldn't be serialized.");
39 return {};
40 }
41 const char* getTypeName() const override {
42 SkDEBUGFAIL("SkTransformShader shouldn't be serialized.");
43 return nullptr;
44 }
45
46 bool isOpaque() const override { return fShader.isOpaque(); }
47
48 private:
49 const SkShaderBase& fShader;
50 SkScalar fMatrixStorage[9]; // actual memory used by generated RP or VM
51 bool fAllowPerspective;
52 };
53 #endif //SkTextCoordShader_DEFINED