Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkLocalMatrixShader.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 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 SkLocalMatrixShader_DEFINED
9#define SkLocalMatrixShader_DEFINED
10
17
18#include <type_traits>
19#include <utility>
20
21class SkArenaAlloc;
22class SkImage;
23class SkReadBuffer;
24class SkWriteBuffer;
25enum class SkTileMode;
26struct SkStageRec;
27
28class SkLocalMatrixShader final : public SkShaderBase {
29public:
30 template <typename T, typename... Args>
31 static std::enable_if_t<std::is_base_of_v<SkShader, T>, sk_sp<SkShader>>
32 MakeWrapped(const SkMatrix* localMatrix, Args&&... args) {
33 auto t = sk_make_sp<T>(std::forward<Args>(args)...);
34 if (localMatrix) {
35 return t->makeWithLocalMatrix(*localMatrix);
36 }
37 return t;
38 }
39
41 : fLocalMatrix(localMatrix), fWrappedShader(std::move(wrapped)) {}
42
43 bool isOpaque() const override { return as_SB(fWrappedShader)->isOpaque(); }
44
45 bool isConstant() const override;
46 GradientType asGradient(GradientInfo* info, SkMatrix* localMatrix) const override;
47 ShaderType type() const override { return ShaderType::kLocalMatrix; }
48
50 if (localMatrix) {
51 *localMatrix = fLocalMatrix;
52 }
53 return fWrappedShader;
54 }
55
56 const SkMatrix& localMatrix() const { return fLocalMatrix; }
57 sk_sp<SkShader> wrappedShader() const { return fWrappedShader; }
58
59protected:
60 void flatten(SkWriteBuffer&) const override;
61
62#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
63 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
64#endif
65
66 SkImage* onIsAImage(SkMatrix* matrix, SkTileMode* mode) const override;
67
68 bool appendStages(const SkStageRec&, const SkShaders::MatrixRec&) const override;
69
70private:
72
73 SkMatrix fLocalMatrix;
74 sk_sp<SkShader> fWrappedShader;
75};
76
77/**
78 * Replaces the CTM when used. Created to support clipShaders, which have to be evaluated
79 * using the CTM that was present at the time they were specified (which may be different
80 * from the CTM at the time something is drawn through the clip.
81 */
82class SkCTMShader final : public SkShaderBase {
83public:
85
86 bool isOpaque() const override { return fProxyShader->isOpaque(); }
87
88 bool isConstant() const override;
89 GradientType asGradient(GradientInfo* info, SkMatrix* localMatrix) const override;
90
91 ShaderType type() const override { return ShaderType::kCTM; }
92
93 const SkMatrix& ctm() const { return fCTM; }
94 sk_sp<SkShader> proxyShader() const { return fProxyShader; }
95
96protected:
97 void flatten(SkWriteBuffer&) const override { SkASSERT(false); }
98
99 bool appendStages(const SkStageRec& rec, const SkShaders::MatrixRec&) const override;
100
101private:
103
104 sk_sp<SkShader> fProxyShader;
105 SkMatrix fCTM;
106};
107
108#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SK_FLATTENABLE_HOOKS(type)
SkShaderBase * as_SB(SkShader *shader)
SkTileMode
Definition SkTileMode.h:13
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
void flatten(SkWriteBuffer &) const override
bool isOpaque() const override
const SkMatrix & ctm() const
bool appendStages(const SkStageRec &rec, const SkShaders::MatrixRec &) const override
bool isConstant() const override
GradientType asGradient(GradientInfo *info, SkMatrix *localMatrix) const override
sk_sp< SkShader > proxyShader() const
ShaderType type() const override
bool isConstant() const override
const SkMatrix & localMatrix() const
bool appendStages(const SkStageRec &, const SkShaders::MatrixRec &) const override
bool isOpaque() const override
sk_sp< SkShader > makeAsALocalMatrixShader(SkMatrix *localMatrix) const override
SkImage * onIsAImage(SkMatrix *matrix, SkTileMode *mode) const override
SkLocalMatrixShader(sk_sp< SkShader > wrapped, const SkMatrix &localMatrix)
static std::enable_if_t< std::is_base_of_v< SkShader, T >, sk_sp< SkShader > > MakeWrapped(const SkMatrix *localMatrix, Args &&... args)
void flatten(SkWriteBuffer &) const override
GradientType asGradient(GradientInfo *info, SkMatrix *localMatrix) const override
ShaderType type() const override
sk_sp< SkShader > wrappedShader() const
virtual bool isOpaque() const
Definition SkShader.h:44
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition ref_ptr.h:256
#define T