blob: d1be0591824e27e1f28962b665c7f33ba40995af [file] [log] [blame]
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +00001/*
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
13class SkBitmap;
14class SkPicture;
15
16/*
17 * An SkPictureShader can be used to draw SkPicture-based patterns.
18 *
19 * The SkPicture is first rendered into a tile, which is then used to shade the area according
20 * to specified tiling rules.
21 */
22class SkPictureShader : public SkShader {
23public:
24 static SkPictureShader* Create(SkPicture*, TileMode, TileMode);
25 virtual ~SkPictureShader();
26
commit-bot@chromium.orgbc2f1dc2014-04-23 09:11:58 +000027 virtual bool validContext(const SkBitmap&, const SkPaint&,
28 const SkMatrix&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE;
29 virtual SkShader::Context* createContext(const SkBitmap& device, const SkPaint& paint,
30 const SkMatrix& matrix, void* storage) const
31 SK_OVERRIDE;
32 virtual size_t contextSize() const SK_OVERRIDE;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000033
commit-bot@chromium.orgbc2f1dc2014-04-23 09:11:58 +000034 class PictureShaderContext : public SkShader::Context {
35 public:
36 PictureShaderContext(const SkPictureShader& shader, const SkBitmap& device,
37 const SkPaint& paint, const SkMatrix& matrix,
38 SkShader* bitmapShader);
39 virtual ~PictureShaderContext();
40
41 virtual uint32_t getFlags() const SK_OVERRIDE;
42
43 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
44 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
45 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
46
47 private:
48 SkAutoTUnref<SkShader> fBitmapShader;
49 SkShader::Context* fBitmapShaderContext;
50 void* fBitmapShaderContextStorage;
51
52 typedef SkShader::Context INHERITED;
53 };
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000054
55 SK_TO_STRING_OVERRIDE()
56 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
57
58#if SK_SUPPORT_GPU
59 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
60#endif
61
62protected:
63 SkPictureShader(SkReadBuffer&);
64 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
65
66private:
67 SkPictureShader(SkPicture*, TileMode, TileMode);
68
commit-bot@chromium.orgbc2f1dc2014-04-23 09:11:58 +000069 SkShader* validInternal(const SkBitmap& device, const SkPaint& paint,
70 const SkMatrix& matrix, SkMatrix* totalInverse) const;
71
72 SkShader* refBitmapShader(const SkMatrix&) const;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000073
74 SkPicture* fPicture;
75 TileMode fTmx, fTmy;
76
commit-bot@chromium.orgbc2f1dc2014-04-23 09:11:58 +000077 mutable SkMutex fCachedBitmapShaderMutex;
78 mutable SkAutoTUnref<SkShader> fCachedBitmapShader;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000079 mutable SkSize fCachedTileScale;
commit-bot@chromium.orgbc2f1dc2014-04-23 09:11:58 +000080 mutable SkMatrix fCachedLocalMatrix;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000081
82 typedef SkShader INHERITED;
83};
84
85#endif // SkPictureShader_DEFINED