Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / core / SkPictureShader.h
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 "SkShader.h"
12
13 class SkBitmap;
14 class 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  */
22 class SkPictureShader : public SkShader {
23 public:
24     static SkPictureShader* Create(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL);
25     virtual ~SkPictureShader();
26
27     virtual size_t contextSize() const SK_OVERRIDE;
28
29     SK_TO_STRING_OVERRIDE()
30     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
31
32 #if SK_SUPPORT_GPU
33     GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
34 #endif
35
36 protected:
37     SkPictureShader(SkReadBuffer&);
38     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
39     virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
40
41 private:
42     SkPictureShader(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL);
43
44     SkShader* refBitmapShader(const SkMatrix&, const SkMatrix* localMatrix) const;
45
46     SkPicture*  fPicture;
47     TileMode    fTmx, fTmy;
48
49     mutable SkMutex                 fCachedBitmapShaderMutex;
50     mutable SkAutoTUnref<SkShader>  fCachedBitmapShader;
51     mutable SkSize                  fCachedTileScale;
52     mutable SkMatrix                fCachedLocalMatrix;
53
54     class PictureShaderContext : public SkShader::Context {
55     public:
56         static Context* Create(void* storage, const SkPictureShader&, const ContextRec&,
57                                SkShader* bitmapShader);
58
59         virtual ~PictureShaderContext();
60
61         virtual uint32_t getFlags() const SK_OVERRIDE;
62
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;
66
67     private:
68         PictureShaderContext(const SkPictureShader&, const ContextRec&, SkShader* bitmapShader);
69
70         SkAutoTUnref<SkShader>  fBitmapShader;
71         SkShader::Context*      fBitmapShaderContext;
72         void*                   fBitmapShaderContextStorage;
73
74         typedef SkShader::Context INHERITED;
75     };
76
77     typedef SkShader INHERITED;
78 };
79
80 #endif // SkPictureShader_DEFINED