2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkPictureShader_DEFINED
9 #define SkPictureShader_DEFINED
17 * An SkPictureShader can be used to draw SkPicture-based patterns.
19 * The SkPicture is first rendered into a tile, which is then used to shade the area according
20 * to specified tiling rules.
22 class SkPictureShader : public SkShader {
24 static SkPictureShader* Create(const SkPicture*, TileMode, TileMode, const SkMatrix*,
26 virtual ~SkPictureShader();
28 size_t contextSize() const override;
30 SK_TO_STRING_OVERRIDE()
31 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
33 bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM, const SkMatrix*,
34 GrColor*, GrFragmentProcessor**) const override;
37 SkPictureShader(SkReadBuffer&);
38 void flatten(SkWriteBuffer&) const override;
39 Context* onCreateContext(const ContextRec&, void* storage) const override;
42 SkPictureShader(const SkPicture*, TileMode, TileMode, const SkMatrix*, const SkRect*);
44 SkShader* refBitmapShader(const SkMatrix&, const SkMatrix* localMatrix) const;
46 const SkPicture* fPicture;
50 class PictureShaderContext : public SkShader::Context {
52 static Context* Create(void* storage, const SkPictureShader&, const ContextRec&,
53 SkShader* bitmapShader);
55 virtual ~PictureShaderContext();
57 uint32_t getFlags() const override;
59 ShadeProc asAShadeProc(void** ctx) override;
60 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
61 void shadeSpan16(int x, int y, uint16_t dstC[], int count) override;
64 PictureShaderContext(const SkPictureShader&, const ContextRec&, SkShader* bitmapShader);
66 SkAutoTUnref<SkShader> fBitmapShader;
67 SkShader::Context* fBitmapShaderContext;
68 void* fBitmapShaderContextStorage;
70 typedef SkShader::Context INHERITED;
73 typedef SkShader INHERITED;
76 #endif // SkPictureShader_DEFINED