Flutter Engine
The Flutter Engine
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
18
19#include <type_traits>
20#include <utility>
21
22class SkArenaAlloc;
23class SkImage;
24class SkReadBuffer;
25class SkWriteBuffer;
26enum class SkTileMode;
27struct SkStageRec;
28
29class SkLocalMatrixShader final : public SkShaderBase {
30public:
31 template <typename T, typename... Args>
32 static std::enable_if_t<std::is_base_of_v<SkShader, T>, sk_sp<SkShader>>
33 MakeWrapped(const SkMatrix* localMatrix, Args&&... args) {
34 auto t = sk_make_sp<T>(std::forward<Args>(args)...);
35 if (localMatrix) {
36 return t->makeWithLocalMatrix(*localMatrix);
37 }
38 return t;
39 }
40
42 : fLocalMatrix(localMatrix), fWrappedShader(std::move(wrapped)) {}
43
44 bool isOpaque() const override { return as_SB(fWrappedShader)->isOpaque(); }
45
46 bool isConstant() const override;
47 GradientType asGradient(GradientInfo* info, SkMatrix* localMatrix) const override;
48 ShaderType type() const override { return ShaderType::kLocalMatrix; }
49
51 if (localMatrix) {
52 *localMatrix = fLocalMatrix;
53 }
54 return fWrappedShader;
55 }
56
57 const SkMatrix& localMatrix() const { return fLocalMatrix; }
58 sk_sp<SkShader> wrappedShader() const { return fWrappedShader; }
59
60protected:
61 void flatten(SkWriteBuffer&) const override;
62
63#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
64 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
65#endif
66
67 SkImage* onIsAImage(SkMatrix* matrix, SkTileMode* mode) const override;
68
69 bool onAsLuminanceColor(SkColor4f*) const override;
70
71 bool appendStages(const SkStageRec&, const SkShaders::MatrixRec&) const override;
72
73private:
75
76 SkMatrix fLocalMatrix;
77 sk_sp<SkShader> fWrappedShader;
78};
79
80/**
81 * Replaces the CTM when used. Created to support clipShaders, which have to be evaluated
82 * using the CTM that was present at the time they were specified (which may be different
83 * from the CTM at the time something is drawn through the clip.
84 */
85class SkCTMShader final : public SkShaderBase {
86public:
88
89 bool isOpaque() const override { return fProxyShader->isOpaque(); }
90
91 bool isConstant() const override;
92 GradientType asGradient(GradientInfo* info, SkMatrix* localMatrix) const override;
93
94 ShaderType type() const override { return ShaderType::kCTM; }
95
96 const SkMatrix& ctm() const { return fCTM; }
97 sk_sp<SkShader> proxyShader() const { return fProxyShader; }
98
99protected:
100 void flatten(SkWriteBuffer&) const override { SkASSERT(false); }
101
102 bool appendStages(const SkStageRec& rec, const SkShaders::MatrixRec&) const override;
103
104private:
106
107 sk_sp<SkShader> fProxyShader;
108 SkMatrix fCTM;
109};
110
111#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)
Definition: SkShaderBase.h:412
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
SkCTMShader(sk_sp< SkShader > proxy, const SkMatrix &ctm)
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 onAsLuminanceColor(SkColor4f *) 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
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
Definition: ref_ptr.h:256
#define T
Definition: precompiler.cc:65