| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkPictureShader_DEFINED | 8 #ifndef SkPictureShader_DEFINED |
| 9 #define SkPictureShader_DEFINED | 9 #define SkPictureShader_DEFINED |
| 10 | 10 |
| 11 #include "SkShader.h" | 11 #include "SkShader.h" |
| 12 | 12 |
| 13 class SkBitmap; | 13 class SkBitmap; |
| 14 class SkPicture; | 14 class SkPicture; |
| 15 | 15 |
| 16 /* | 16 /* |
| 17 * An SkPictureShader can be used to draw SkPicture-based patterns. | 17 * An SkPictureShader can be used to draw SkPicture-based patterns. |
| 18 * | 18 * |
| 19 * The SkPicture is first rendered into a tile, which is then used to shade the
area according | 19 * The SkPicture is first rendered into a tile, which is then used to shade the
area according |
| 20 * to specified tiling rules. | 20 * to specified tiling rules. |
| 21 */ | 21 */ |
| 22 class SkPictureShader : public SkShader { | 22 class SkPictureShader : public SkShader { |
| 23 public: | 23 public: |
| 24 static SkPictureShader* Create(SkPicture*, TileMode, TileMode, const SkMatri
x* = NULL); | 24 static SkPictureShader* Create(SkPicture*, TileMode, TileMode, const SkMatri
x* = NULL); |
| 25 virtual ~SkPictureShader(); | 25 virtual ~SkPictureShader(); |
| 26 | 26 |
| 27 virtual bool validContext(const ContextRec&, SkMatrix* totalInverse) const S
K_OVERRIDE; | |
| 28 virtual SkShader::Context* createContext(const ContextRec&, void* storage) c
onst SK_OVERRIDE; | |
| 29 virtual size_t contextSize() const SK_OVERRIDE; | 27 virtual size_t contextSize() const SK_OVERRIDE; |
| 30 | 28 |
| 31 class PictureShaderContext : public SkShader::Context { | |
| 32 public: | |
| 33 PictureShaderContext(const SkPictureShader&, const ContextRec&, SkShader
* bitmapShader); | |
| 34 virtual ~PictureShaderContext(); | |
| 35 | |
| 36 virtual uint32_t getFlags() const SK_OVERRIDE; | |
| 37 | |
| 38 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE; | |
| 39 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVE
RRIDE; | |
| 40 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OV
ERRIDE; | |
| 41 | |
| 42 private: | |
| 43 SkAutoTUnref<SkShader> fBitmapShader; | |
| 44 SkShader::Context* fBitmapShaderContext; | |
| 45 void* fBitmapShaderContextStorage; | |
| 46 | |
| 47 typedef SkShader::Context INHERITED; | |
| 48 }; | |
| 49 | |
| 50 SK_TO_STRING_OVERRIDE() | 29 SK_TO_STRING_OVERRIDE() |
| 51 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader) | 30 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader) |
| 52 | 31 |
| 53 #if SK_SUPPORT_GPU | 32 #if SK_SUPPORT_GPU |
| 54 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE; | 33 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE; |
| 55 #endif | 34 #endif |
| 56 | 35 |
| 57 protected: | 36 protected: |
| 58 SkPictureShader(SkReadBuffer&); | 37 SkPictureShader(SkReadBuffer&); |
| 59 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 38 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 39 virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_
OVERRIDE; |
| 60 | 40 |
| 61 private: | 41 private: |
| 62 SkPictureShader(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL); | 42 SkPictureShader(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL); |
| 63 | 43 |
| 64 SkShader* validInternal(const ContextRec&, SkMatrix* totalInverse) const; | |
| 65 SkShader* refBitmapShader(const SkMatrix&) const; | 44 SkShader* refBitmapShader(const SkMatrix&) const; |
| 66 | 45 |
| 67 SkPicture* fPicture; | 46 SkPicture* fPicture; |
| 68 TileMode fTmx, fTmy; | 47 TileMode fTmx, fTmy; |
| 69 | 48 |
| 70 mutable SkMutex fCachedBitmapShaderMutex; | 49 mutable SkMutex fCachedBitmapShaderMutex; |
| 71 mutable SkAutoTUnref<SkShader> fCachedBitmapShader; | 50 mutable SkAutoTUnref<SkShader> fCachedBitmapShader; |
| 72 mutable SkSize fCachedTileScale; | 51 mutable SkSize fCachedTileScale; |
| 73 mutable SkMatrix fCachedLocalMatrix; | 52 mutable SkMatrix fCachedLocalMatrix; |
| 74 | 53 |
| 54 class PictureShaderContext : public SkShader::Context { |
| 55 public: |
| 56 static Context* Create(void* storage, const SkPictureShader&, const Cont
extRec&, |
| 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_OVE
RRIDE; |
| 65 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OV
ERRIDE; |
| 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 |
| 75 typedef SkShader INHERITED; | 77 typedef SkShader INHERITED; |
| 76 }; | 78 }; |
| 77 | 79 |
| 78 #endif // SkPictureShader_DEFINED | 80 #endif // SkPictureShader_DEFINED |
| OLD | NEW |