commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkTileMode.h" |
| 12 | #include "src/shaders/SkShaderBase.h" |
Mike Klein | 015c899 | 2018-08-09 12:23:19 -0400 | [diff] [blame] | 13 | #include <atomic> |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 14 | |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 15 | class SkArenaAlloc; |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 16 | class SkBitmap; |
| 17 | class SkPicture; |
| 18 | |
| 19 | /* |
| 20 | * An SkPictureShader can be used to draw SkPicture-based patterns. |
| 21 | * |
| 22 | * The SkPicture is first rendered into a tile, which is then used to shade the area according |
| 23 | * to specified tiling rules. |
| 24 | */ |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 25 | class SkPictureShader : public SkShaderBase { |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 26 | public: |
Florin Malita | b00a360 | 2017-07-13 22:34:04 -0400 | [diff] [blame] | 27 | ~SkPictureShader() override; |
| 28 | |
Mike Reed | e25b447 | 2019-04-02 17:49:12 -0400 | [diff] [blame] | 29 | static sk_sp<SkShader> Make(sk_sp<SkPicture>, SkTileMode, SkTileMode, const SkMatrix*, |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 30 | const SkRect*); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 31 | |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame] | 32 | #if SK_SUPPORT_GPU |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 33 | std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override; |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame] | 34 | #endif |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 35 | |
| 36 | protected: |
| 37 | SkPictureShader(SkReadBuffer&); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 38 | void flatten(SkWriteBuffer&) const override; |
Mike Reed | 1386b2d | 2019-03-13 21:15:05 -0400 | [diff] [blame] | 39 | bool onAppendStages(const SkStageRec&) const override; |
Mike Reed | cb1a2df | 2020-03-21 18:02:58 -0400 | [diff] [blame] | 40 | skvm::Color onProgram(skvm::Builder*, skvm::F32 x, skvm::F32 y, skvm::Color paint, |
Mike Klein | e81b108 | 2020-06-19 11:29:13 -0500 | [diff] [blame^] | 41 | const SkMatrixProvider&, const SkMatrix* localM, |
Mike Reed | cb1a2df | 2020-03-21 18:02:58 -0400 | [diff] [blame] | 42 | SkFilterQuality quality, const SkColorInfo& dst, |
| 43 | skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override; |
| 44 | |
Mike Reed | e92aae6 | 2018-10-17 10:21:51 -0400 | [diff] [blame] | 45 | #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 46 | Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override; |
Mike Reed | e92aae6 | 2018-10-17 10:21:51 -0400 | [diff] [blame] | 47 | #endif |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 48 | |
| 49 | private: |
Mike Klein | 4fee323 | 2018-10-18 17:27:16 -0400 | [diff] [blame] | 50 | SK_FLATTENABLE_HOOKS(SkPictureShader) |
| 51 | |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 52 | SkPictureShader(sk_sp<SkPicture>, SkTileMode, SkTileMode, const SkMatrix*, const SkRect*); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 53 | |
Florin Malita | 8f88d89 | 2018-04-19 21:07:19 -0400 | [diff] [blame] | 54 | sk_sp<SkShader> refBitmapShader(const SkMatrix&, SkTCopyOnFirstWrite<SkMatrix>* localMatrix, |
Brian Osman | 2e8f48e | 2018-10-19 13:50:48 -0400 | [diff] [blame] | 55 | SkColorType dstColorType, SkColorSpace* dstColorSpace, |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 56 | const int maxTextureSize = 0) const; |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 57 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 58 | class PictureShaderContext : public Context { |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 59 | public: |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 60 | PictureShaderContext( |
| 61 | const SkPictureShader&, const ContextRec&, sk_sp<SkShader> bitmapShader, SkArenaAlloc*); |
skia.committer@gmail.com | edda70e | 2014-05-06 03:06:53 +0000 | [diff] [blame] | 62 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 63 | uint32_t getFlags() const override; |
skia.committer@gmail.com | edda70e | 2014-05-06 03:06:53 +0000 | [diff] [blame] | 64 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 65 | void shadeSpan(int x, int y, SkPMColor dstC[], int count) override; |
skia.committer@gmail.com | edda70e | 2014-05-06 03:06:53 +0000 | [diff] [blame] | 66 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 67 | sk_sp<SkShader> fBitmapShader; |
| 68 | SkShaderBase::Context* fBitmapShaderContext; |
| 69 | void* fBitmapShaderContextStorage; |
skia.committer@gmail.com | edda70e | 2014-05-06 03:06:53 +0000 | [diff] [blame] | 70 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 71 | typedef Context INHERITED; |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 72 | }; |
skia.committer@gmail.com | edda70e | 2014-05-06 03:06:53 +0000 | [diff] [blame] | 73 | |
Florin Malita | b00a360 | 2017-07-13 22:34:04 -0400 | [diff] [blame] | 74 | sk_sp<SkPicture> fPicture; |
| 75 | SkRect fTile; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 76 | SkTileMode fTmx, fTmy; |
Florin Malita | b00a360 | 2017-07-13 22:34:04 -0400 | [diff] [blame] | 77 | |
Mike Klein | 015c899 | 2018-08-09 12:23:19 -0400 | [diff] [blame] | 78 | const uint32_t fUniqueID; |
| 79 | mutable std::atomic<bool> fAddedToCache; |
Matt Sarett | 28a7ad2 | 2017-04-21 15:12:34 -0400 | [diff] [blame] | 80 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 81 | typedef SkShaderBase INHERITED; |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | #endif // SkPictureShader_DEFINED |