Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrPerlinNoise2Effect.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
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 GrPerlinNoise2Effect_DEFINED
9#define GrPerlinNoise2Effect_DEFINED
10
25
26#include <memory>
27#include <utility>
28
29namespace skgpu {
30class KeyBuilder;
31}
32struct GrShaderCaps;
34
36public:
37 static std::unique_ptr<GrFragmentProcessor> Make(
39 int numOctaves,
40 bool stitchTiles,
41 std::unique_ptr<SkPerlinNoiseShader::PaintingData> paintingData,
42 GrSurfaceProxyView permutationsView,
43 GrSurfaceProxyView noiseView,
44 const GrCaps& caps) {
45 static constexpr GrSamplerState kRepeatXSampler = {GrSamplerState::WrapMode::kRepeat,
47 GrSamplerState::Filter::kNearest};
48 auto permutationsFP = GrTextureEffect::Make(std::move(permutationsView),
51 kRepeatXSampler,
52 caps);
53 auto noiseFP = GrTextureEffect::Make(
54 std::move(noiseView), kPremul_SkAlphaType, SkMatrix::I(), kRepeatXSampler, caps);
55
56 return std::unique_ptr<GrFragmentProcessor>(
60 std::move(paintingData),
61 std::move(permutationsFP),
62 std::move(noiseFP)));
63 }
64
65 const char* name() const override { return "PerlinNoise"; }
66
67 std::unique_ptr<GrFragmentProcessor> clone() const override {
68 return std::unique_ptr<GrFragmentProcessor>(new GrPerlinNoise2Effect(*this));
69 }
70
72 return fPaintingData->fStitchDataInit;
73 }
74
75 SkPerlinNoiseShaderType type() const { return fType; }
76 bool stitchTiles() const { return fStitchTiles; }
77 const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency; }
78 int numOctaves() const { return fNumOctaves; }
79
80private:
81 class Impl : public ProgramImpl {
82 public:
83 SkString emitHelper(EmitArgs& args);
84 void emitCode(EmitArgs&) override;
85
86 private:
87 void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
88
89 GrGLSLProgramDataManager::UniformHandle fStitchDataUni;
90 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni;
91 };
92
93 std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
94 return std::make_unique<Impl>();
95 }
96
97 void onAddToKey(const GrShaderCaps& caps, skgpu::KeyBuilder* b) const override;
98
99 bool onIsEqual(const GrFragmentProcessor& sBase) const override {
101 return fType == s.fType &&
102 fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency &&
103 fNumOctaves == s.fNumOctaves && fStitchTiles == s.fStitchTiles &&
104 fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataInit;
105 }
106
108 int numOctaves,
109 bool stitchTiles,
110 std::unique_ptr<SkPerlinNoiseShader::PaintingData> paintingData,
111 std::unique_ptr<GrFragmentProcessor> permutationsFP,
112 std::unique_ptr<GrFragmentProcessor> noiseFP)
114 , fType(type)
115 , fNumOctaves(numOctaves)
116 , fStitchTiles(stitchTiles)
117 , fPaintingData(std::move(paintingData)) {
118 this->registerChild(std::move(permutationsFP), SkSL::SampleUsage::Explicit());
119 this->registerChild(std::move(noiseFP), SkSL::SampleUsage::Explicit());
121 }
122
124 : GrFragmentProcessor(that)
125 , fType(that.fType)
126 , fNumOctaves(that.fNumOctaves)
127 , fStitchTiles(that.fStitchTiles)
128 , fPaintingData(new SkPerlinNoiseShader::PaintingData(*that.fPaintingData)) {}
129
131
133 int fNumOctaves;
134 bool fStitchTiles;
135
136 std::unique_ptr<SkPerlinNoiseShader::PaintingData> fPaintingData;
137};
138
139#endif
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
SkPerlinNoiseShaderType
void registerChild(std::unique_ptr< GrFragmentProcessor > child, SkSL::SampleUsage sampleUsage=SkSL::SampleUsage::PassThrough())
const char * name() const override
const SkVector & baseFrequency() const
std::unique_ptr< ProgramImpl > onMakeProgramImpl() const override
static std::unique_ptr< GrFragmentProcessor > Make(SkPerlinNoiseShaderType type, int numOctaves, bool stitchTiles, std::unique_ptr< SkPerlinNoiseShader::PaintingData > paintingData, GrSurfaceProxyView permutationsView, GrSurfaceProxyView noiseView, const GrCaps &caps)
void onAddToKey(const GrShaderCaps &caps, skgpu::KeyBuilder *b) const override
std::unique_ptr< GrFragmentProcessor > clone() const override
const SkPerlinNoiseShader::StitchData & stitchData() const
SkPerlinNoiseShaderType type() const
bool onIsEqual(const GrFragmentProcessor &sBase) const override
const T & cast() const
@ kGrPerlinNoise2Effect_ClassID
Definition GrProcessor.h:65
static std::unique_ptr< GrFragmentProcessor > Make(GrSurfaceProxyView, SkAlphaType, const SkMatrix &=SkMatrix::I(), GrSamplerState::Filter=GrSamplerState::Filter::kNearest, GrSamplerState::MipmapMode mipmapMode=GrSamplerState::MipmapMode::kNone)
static const SkMatrix & I()
static SampleUsage Explicit()
static bool b
struct MyStruct s
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition ref_ptr.h:256