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(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL);
25 virtual ~SkPictureShader();
27 virtual size_t contextSize() const SK_OVERRIDE;
29 SK_TO_STRING_OVERRIDE()
30 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
33 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
37 SkPictureShader(SkReadBuffer&);
38 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
39 virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
42 SkPictureShader(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL);
44 SkShader* refBitmapShader(const SkMatrix&, const SkMatrix* localMatrix) const;
49 mutable SkMutex fCachedBitmapShaderMutex;
50 mutable SkAutoTUnref<SkShader> fCachedBitmapShader;
51 mutable SkSize fCachedTileScale;
52 mutable SkMatrix fCachedLocalMatrix;
54 class PictureShaderContext : public SkShader::Context {
56 static Context* Create(void* storage, const SkPictureShader&, const ContextRec&,
57 SkShader* bitmapShader);
59 virtual ~PictureShaderContext();
61 virtual uint32_t getFlags() const SK_OVERRIDE;
63 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
64 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
65 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
68 PictureShaderContext(const SkPictureShader&, const ContextRec&, SkShader* bitmapShader);
70 SkAutoTUnref<SkShader> fBitmapShader;
71 SkShader::Context* fBitmapShaderContext;
72 void* fBitmapShaderContextStorage;
74 typedef SkShader::Context INHERITED;
77 typedef SkShader INHERITED;
80 #endif // SkPictureShader_DEFINED