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
11#include "src/core/SkReadBuffer.h"
12#include "src/core/SkWriteBuffer.h"
13#include "src/shaders/SkShaderBase.h"
14
15class GrFragmentProcessor;
16class SkArenaAlloc;
17
18class SkLocalMatrixShader final : public SkShaderBase {
19public:
20 SkLocalMatrixShader(sk_sp<SkShader> proxy, const SkMatrix& localMatrix)
21 : INHERITED(&localMatrix)
22 , fProxyShader(std::move(proxy))
23 {}
24
25 GradientType asAGradient(GradientInfo* info) const override {
26 return fProxyShader->asAGradient(info);
27 }
28
29#if SK_SUPPORT_GPU
30 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
31#endif
32
33 sk_sp<SkShader> makeAsALocalMatrixShader(SkMatrix* localMatrix) const override {
34 if (localMatrix) {
35 *localMatrix = this->getLocalMatrix();
36 }
37 return fProxyShader;
38 }
39
40protected:
41 void flatten(SkWriteBuffer&) const override;
42
43#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
44 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
45#endif
46
47 SkImage* onIsAImage(SkMatrix* matrix, SkTileMode* mode) const override;
48
49 bool onAppendStages(const SkStageRec&) const override;
50
51 skvm::Color onProgram(skvm::Builder*, skvm::F32 x, skvm::F32 y, skvm::Color paint,
52 const SkMatrix& ctm, const SkMatrix* localM,
53 SkFilterQuality quality, const SkColorInfo& dst,
54 skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
55
56private:
57 SK_FLATTENABLE_HOOKS(SkLocalMatrixShader)
58
59 sk_sp<SkShader> fProxyShader;
60
61 typedef SkShaderBase INHERITED;
62};
63
64#endif
65