• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SkPictureShader_DEFINED
9 #define SkPictureShader_DEFINED
10 
11 #include "include/core/SkTileMode.h"
12 #include "src/shaders/SkShaderBase.h"
13 #include <atomic>
14 
15 class SkArenaAlloc;
16 class SkBitmap;
17 class SkPicture;
18 
19 /*
20  * An SkPictureShader can be used to draw SkPicture-based patterns.
21  *
22  * The SkPicture is first rendered into a tile, which is then used to shade the area according
23  * to specified tiling rules.
24  */
25 class SkPictureShader : public SkShaderBase {
26 public:
27     static sk_sp<SkShader> Make(sk_sp<SkPicture>, SkTileMode, SkTileMode, SkFilterMode,
28                                 const SkMatrix*, const SkRect*);
29 
30 #if SK_SUPPORT_GPU
31     std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
32 #endif
33 
34 protected:
35     SkPictureShader(SkReadBuffer&);
36     void flatten(SkWriteBuffer&) const override;
37     bool onAppendStages(const SkStageRec&) const override;
38     skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint,
39                           const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst,
40                           skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override;
41 
42 #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
43     Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
44 #endif
45 
46 private:
47     SK_FLATTENABLE_HOOKS(SkPictureShader)
48 
49     SkPictureShader(sk_sp<SkPicture>, SkTileMode, SkTileMode, SkFilterMode,
50                     const SkMatrix*, const SkRect*);
51 
52     sk_sp<SkShader> rasterShader(const SkMatrix&, SkTCopyOnFirstWrite<SkMatrix>* localMatrix,
53                                  SkColorType dstColorType, SkColorSpace* dstColorSpace) const;
54 
55     class PictureShaderContext : public Context {
56     public:
57         PictureShaderContext(
58             const SkPictureShader&, const ContextRec&, sk_sp<SkShader> bitmapShader, SkArenaAlloc*);
59 
60         uint32_t getFlags() const override;
61 
62         void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
63 
64         sk_sp<SkShader>         fBitmapShader;
65         SkShaderBase::Context*  fBitmapShaderContext;
66         void*                   fBitmapShaderContextStorage;
67 
68         using INHERITED = Context;
69     };
70 
71     sk_sp<SkPicture>    fPicture;
72     SkRect              fTile;
73     SkTileMode          fTmx, fTmy;
74     SkFilterMode        fFilter;
75 
76     using INHERITED = SkShaderBase;
77 };
78 
79 #endif // SkPictureShader_DEFINED
80