Debian Codegraph @

src/shaders/SkPictureShader.h

raw
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/SkFlattenable.h"
12 #include "include/core/SkImageInfo.h"
13 #include "include/core/SkMatrix.h"
14 #include "include/core/SkPicture.h"
15 #include "include/core/SkRect.h"
16 #include "include/core/SkRefCnt.h"
17 #include "include/core/SkSize.h"
18 #include "include/core/SkSurfaceProps.h"
19 #include "include/core/SkTypes.h"
20 #include "src/shaders/SkShaderBase.h"
21
22 class SkArenaAlloc;
23 class SkColorSpace;
24 class SkImage;
25 class SkReadBuffer;
26 class SkShader;
27 class SkSurface;
28 class SkWriteBuffer;
29 enum SkColorType : int;
30 enum class SkFilterMode;
31 enum class SkTileMode;
32 struct SkStageRec;
33
34 /*
35 * An SkPictureShader can be used to draw SkPicture-based patterns.
36 *
37 * The SkPicture is first rendered into a tile, which is then used to shade the area according
38 * to specified tiling rules.
39 */
40 class SkPictureShader : public SkShaderBase {
41 public:
42 static sk_sp<SkShader> Make(sk_sp<SkPicture>, SkTileMode, SkTileMode, SkFilterMode,
43 const SkMatrix*, const SkRect*);
44
45 SkPictureShader(sk_sp<SkPicture>, SkTileMode, SkTileMode, SkFilterMode, const SkRect*);
46
47 ShaderType type() const override { return ShaderType::kPicture; }
48
49 sk_sp<SkPicture> picture() const { return fPicture; }
50 SkRect tile() const { return fTile; }
51 SkTileMode tileModeX() const { return fTmx; }
52 SkTileMode tileModeY() const { return fTmy; }
53 SkFilterMode filter() const { return fFilter; }
54
55 struct CachedImageInfo {
56 bool success;
57 SkSize tileScale; // Additional scale factors to apply when sampling image.
58 SkMatrix matrixForDraw; // Matrix used to produce an image from the picture
59 SkImageInfo imageInfo;
60 SkSurfaceProps props;
61
62 static CachedImageInfo Make(const SkRect& bounds,
63 const SkMatrix& totalM,
64 SkColorType dstColorType,
65 SkColorSpace* dstColorSpace,
66 const int maxTextureSize,
67 const SkSurfaceProps& propsIn);
68
69 // Returns a temporary image created from the surface
70 sk_sp<SkImage> makeImage(sk_sp<SkSurface> surf, const SkPicture* pict) const;
71 };
72
73 protected:
74 SkPictureShader(SkReadBuffer&);
75 void flatten(SkWriteBuffer&) const override;
76 bool appendStages(const SkStageRec&, const SkShaders::MatrixRec&) const override;
77 #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
78 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
79 #endif
80
81 private:
82 SK_FLATTENABLE_HOOKS(SkPictureShader)
83
84 sk_sp<SkShader> rasterShader(const SkMatrix&,
85 SkColorType dstColorType,
86 SkColorSpace* dstColorSpace,
87 const SkSurfaceProps& props) const;
88
89 sk_sp<SkPicture> fPicture;
90 SkRect fTile;
91 SkTileMode fTmx, fTmy;
92 SkFilterMode fFilter;
93 };
94
95 #endif // SkPictureShader_DEFINED