1/*
2 * Copyright 2015 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 SkImageShader_DEFINED
9#define SkImageShader_DEFINED
10
11#include "include/core/SkImage.h"
12#include "src/shaders/SkBitmapProcShader.h"
13#include "src/shaders/SkShaderBase.h"
14
15// private subclass of SkStageUpdater
16class SkImageStageUpdater;
17
18class SkImageShader : public SkShaderBase {
19public:
20 static sk_sp<SkShader> Make(sk_sp<SkImage>,
21 SkTileMode tmx,
22 SkTileMode tmy,
23 const SkMatrix* localMatrix,
24 bool clampAsIfUnpremul = false);
25
26 bool isOpaque() const override;
27
28#if SK_SUPPORT_GPU
29 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
30#endif
31
32private:
33 SK_FLATTENABLE_HOOKS(SkImageShader)
34
35 SkImageShader(sk_sp<SkImage>,
36 SkTileMode tmx,
37 SkTileMode tmy,
38 const SkMatrix* localMatrix,
39 bool clampAsIfUnpremul);
40
41 void flatten(SkWriteBuffer&) const override;
42#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
43 Context* onMakeContext(const ContextRec&, SkArenaAlloc* storage) const override;
44#endif
45 SkImage* onIsAImage(SkMatrix*, SkTileMode*) const override;
46
47 bool onAppendStages(const SkStageRec&) const override;
48 SkStageUpdater* onAppendUpdatableStages(const SkStageRec&) const override;
49
50 skvm::Color onProgram(skvm::Builder*, skvm::F32 x, skvm::F32 y, skvm::Color paint,
51 const SkMatrix& ctm, const SkMatrix* localM,
52 SkFilterQuality quality, const SkColorInfo& dst,
53 skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
54
55 bool doStages(const SkStageRec&, SkImageStageUpdater* = nullptr) const;
56
57 sk_sp<SkImage> fImage;
58 const SkTileMode fTileModeX;
59 const SkTileMode fTileModeY;
60 const bool fClampAsIfUnpremul;
61
62 friend class SkShaderBase;
63 typedef SkShaderBase INHERITED;
64};
65
66#endif
67