SkPictureShader.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef SkPictureShader_DEFINED
  8. #define SkPictureShader_DEFINED
  9. #include "include/core/SkTileMode.h"
  10. #include "src/shaders/SkShaderBase.h"
  11. #include <atomic>
  12. class SkArenaAlloc;
  13. class SkBitmap;
  14. class SkPicture;
  15. /*
  16. * An SkPictureShader can be used to draw SkPicture-based patterns.
  17. *
  18. * The SkPicture is first rendered into a tile, which is then used to shade the area according
  19. * to specified tiling rules.
  20. */
  21. class SkPictureShader : public SkShaderBase {
  22. public:
  23. ~SkPictureShader() override;
  24. static sk_sp<SkShader> Make(sk_sp<SkPicture>, SkTileMode, SkTileMode, const SkMatrix*,
  25. const SkRect*);
  26. #if SK_SUPPORT_GPU
  27. std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
  28. #endif
  29. SkPicture* isAPicture(SkMatrix*, SkTileMode[2], SkRect* tile) const override;
  30. protected:
  31. SkPictureShader(SkReadBuffer&);
  32. void flatten(SkWriteBuffer&) const override;
  33. bool onAppendStages(const SkStageRec&) const override;
  34. #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
  35. Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
  36. #endif
  37. private:
  38. SK_FLATTENABLE_HOOKS(SkPictureShader)
  39. SkPictureShader(sk_sp<SkPicture>, SkTileMode, SkTileMode, const SkMatrix*, const SkRect*);
  40. sk_sp<SkShader> refBitmapShader(const SkMatrix&, SkTCopyOnFirstWrite<SkMatrix>* localMatrix,
  41. SkColorType dstColorType, SkColorSpace* dstColorSpace,
  42. const int maxTextureSize = 0) const;
  43. class PictureShaderContext : public Context {
  44. public:
  45. PictureShaderContext(
  46. const SkPictureShader&, const ContextRec&, sk_sp<SkShader> bitmapShader, SkArenaAlloc*);
  47. uint32_t getFlags() const override;
  48. void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
  49. sk_sp<SkShader> fBitmapShader;
  50. SkShaderBase::Context* fBitmapShaderContext;
  51. void* fBitmapShaderContextStorage;
  52. typedef Context INHERITED;
  53. };
  54. sk_sp<SkPicture> fPicture;
  55. SkRect fTile;
  56. SkTileMode fTmx, fTmy;
  57. const uint32_t fUniqueID;
  58. mutable std::atomic<bool> fAddedToCache;
  59. typedef SkShaderBase INHERITED;
  60. };
  61. #endif // SkPictureShader_DEFINED