• 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 // private subclass of SkStageUpdater
16 class SkImageStageUpdater;
17 
18 class SkImageShader : public SkShaderBase {
19 public:
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 
32 private:
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     bool doStages(const SkStageRec&, SkImageStageUpdater* = nullptr) const;
51 
52     sk_sp<SkImage>   fImage;
53     const SkTileMode fTileModeX;
54     const SkTileMode fTileModeY;
55     const bool       fClampAsIfUnpremul;
56 
57     friend class SkShaderBase;
58     typedef SkShaderBase INHERITED;
59 };
60 
61 #endif
62