• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class SkImageShader : public SkShaderBase {
16 public:
17     static sk_sp<SkShader> Make(sk_sp<SkImage>,
18                                 SkTileMode tmx,
19                                 SkTileMode tmy,
20                                 const SkSamplingOptions&,
21                                 const SkMatrix* localMatrix,
22                                 bool clampAsIfUnpremul = false);
23 
24     bool isOpaque() const override;
25 
26 #if SK_SUPPORT_GPU
27     std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
28 #endif
29 
30     static SkM44 CubicResamplerMatrix(float B, float C);
31 
32 private:
33     SK_FLATTENABLE_HOOKS(SkImageShader)
34 
35     SkImageShader(sk_sp<SkImage>,
36                   SkTileMode tmx,
37                   SkTileMode tmy,
38                   const SkSamplingOptions&,
39                   const SkMatrix* localMatrix,
40                   bool clampAsIfUnpremul = false);
41 
42     void flatten(SkWriteBuffer&) const override;
43 #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
44     Context* onMakeContext(const ContextRec&, SkArenaAlloc* storage) const override;
45 #endif
46     SkImage* onIsAImage(SkMatrix*, SkTileMode*) const override;
47 
48     bool onAppendStages(const SkStageRec&) const override;
49     SkStageUpdater* onAppendUpdatableStages(const SkStageRec&) const override;
50 
51     SkUpdatableShader* onUpdatableShader(SkArenaAlloc* alloc) const override;
52 
53     skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
54                           const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
55                           skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
56 
57     class TransformShader;
58     skvm::Color makeProgram(
59             skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
60             const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
61             skvm::Uniforms* uniforms, const TransformShader* coordShader, SkArenaAlloc*) const;
62 
63     bool doStages(const SkStageRec&, TransformShader* = nullptr) const;
64 
65     sk_sp<SkImage>          fImage;
66     const SkSamplingOptions fSampling;
67     const SkTileMode        fTileModeX;
68     const SkTileMode        fTileModeY;
69     const bool              fClampAsIfUnpremul;
70 
71     friend class SkShaderBase;
72     using INHERITED = SkShaderBase;
73 };
74 
75 #endif
76