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 "SkAtomics.h" 12 #include "SkShaderBase.h" 13 14 class SkArenaAlloc; 15 class SkBitmap; 16 class SkPicture; 17 18 /* 19 * An SkPictureShader can be used to draw SkPicture-based patterns. 20 * 21 * The SkPicture is first rendered into a tile, which is then used to shade the area according 22 * to specified tiling rules. 23 */ 24 class SkPictureShader : public SkShaderBase { 25 public: 26 ~SkPictureShader() override; 27 28 static sk_sp<SkShader> Make(sk_sp<SkPicture>, TileMode, TileMode, const SkMatrix*, 29 const SkRect*); 30 31 SK_TO_STRING_OVERRIDE() 32 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader) 33 34 #if SK_SUPPORT_GPU 35 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override; 36 #endif 37 38 protected: 39 SkPictureShader(SkReadBuffer&); 40 void flatten(SkWriteBuffer&) const override; 41 bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*, 42 const SkMatrix&, const SkPaint&, const SkMatrix*) const override; 43 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override; 44 sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override; 45 bool onIsRasterPipelineOnly() const override; 46 47 private: 48 SkPictureShader(sk_sp<SkPicture>, TileMode, TileMode, const SkMatrix*, const SkRect*, 49 sk_sp<SkColorSpace>); 50 51 sk_sp<SkShader> refBitmapShader(const SkMatrix&, const SkMatrix* localMatrix, 52 SkColorSpace* dstColorSpace, 53 const int maxTextureSize = 0) const; 54 55 class PictureShaderContext : public Context { 56 public: 57 PictureShaderContext( 58 const SkPictureShader&, const ContextRec&, sk_sp<SkShader> bitmapShader, SkArenaAlloc*); 59 60 uint32_t getFlags() const override; 61 62 ShadeProc asAShadeProc(void** ctx) override; 63 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override; 64 65 sk_sp<SkShader> fBitmapShader; 66 SkShaderBase::Context* fBitmapShaderContext; 67 void* fBitmapShaderContextStorage; 68 69 typedef Context INHERITED; 70 }; 71 72 sk_sp<SkPicture> fPicture; 73 SkRect fTile; 74 TileMode fTmx, fTmy; 75 76 // Should never be set by a public constructor. This is only used when onMakeColorSpace() 77 // forces a deferred color space xform. 78 sk_sp<SkColorSpace> fColorSpace; 79 80 const uint32_t fUniqueID; 81 mutable SkAtomic<bool> fAddedToCache; 82 83 typedef SkShaderBase INHERITED; 84 }; 85 86 #endif // SkPictureShader_DEFINED 87