• Home
  • History
  • Annotate
  • 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 "SkShader.h"
12 
13 class SkArenaAlloc;
14 class SkBitmap;
15 class SkPicture;
16 
17 /*
18  * An SkPictureShader can be used to draw SkPicture-based patterns.
19  *
20  * The SkPicture is first rendered into a tile, which is then used to shade the area according
21  * to specified tiling rules.
22  */
23 class SkPictureShader : public SkShader {
24 public:
25     static sk_sp<SkShader> Make(sk_sp<SkPicture>, TileMode, TileMode, const SkMatrix*,
26                                 const SkRect*);
27 
28     SK_TO_STRING_OVERRIDE()
29     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
30 
31 #if SK_SUPPORT_GPU
32     sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override;
33 #endif
34 
35 protected:
36     SkPictureShader(SkReadBuffer&);
37     void flatten(SkWriteBuffer&) const override;
38     bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
39                         const SkMatrix&, const SkPaint&, const SkMatrix*) const override;
40     Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
41 
42 private:
43     SkPictureShader(sk_sp<SkPicture>, TileMode, TileMode, const SkMatrix*, const SkRect*);
44 
45     sk_sp<SkShader> refBitmapShader(const SkMatrix&, const SkMatrix* localMatrix,
46                                     SkColorSpace* dstColorSpace,
47                                     const int maxTextureSize = 0) const;
48 
49     sk_sp<SkPicture>    fPicture;
50     SkRect              fTile;
51     TileMode            fTmx, fTmy;
52 
53     class PictureShaderContext : public SkShader::Context {
54     public:
55         PictureShaderContext(
56             const SkPictureShader&, const ContextRec&, sk_sp<SkShader> bitmapShader, SkArenaAlloc*);
57 
58         uint32_t getFlags() const override;
59 
60         ShadeProc asAShadeProc(void** ctx) override;
61         void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
62 
63         sk_sp<SkShader>     fBitmapShader;
64         SkShader::Context*  fBitmapShaderContext;
65         void*               fBitmapShaderContextStorage;
66 
67         typedef SkShader::Context INHERITED;
68     };
69 
70     typedef SkShader INHERITED;
71 };
72 
73 #endif // SkPictureShader_DEFINED
74