blob: ea74b56d73d857394f9c20b227d41368f1623fa0 [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.org6e5671d2014-04-23 16:16:55 +000027 virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK_OVERRIDE;
28 virtual void endContext() SK_OVERRIDE;
29 virtual uint32_t getFlags() SK_OVERRIDE;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000030
commit-bot@chromium.org6e5671d2014-04-23 16:16:55 +000031 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
32 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
33 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000034
35 SK_TO_STRING_OVERRIDE()
36 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
37
38#if SK_SUPPORT_GPU
39 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
40#endif
41
42protected:
43 SkPictureShader(SkReadBuffer&);
44 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
45
46private:
47 SkPictureShader(SkPicture*, TileMode, TileMode);
48
commit-bot@chromium.org6e5671d2014-04-23 16:16:55 +000049 bool buildBitmapShader(const SkMatrix&) const;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000050
51 SkPicture* fPicture;
52 TileMode fTmx, fTmy;
53
commit-bot@chromium.org6e5671d2014-04-23 16:16:55 +000054 mutable SkAutoTUnref<SkShader> fCachedShader;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000055 mutable SkSize fCachedTileScale;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000056
57 typedef SkShader INHERITED;
58};
59
60#endif // SkPictureShader_DEFINED