blob: 98eb7617227042ab34ccf7d805d5d992409a72a9 [file] [log] [blame]
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +00001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkTileMode.h"
12#include "src/shaders/SkShaderBase.h"
Mike Klein015c8992018-08-09 12:23:19 -040013#include <atomic>
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000014
Herb Derby83e939b2017-02-07 14:25:11 -050015class SkArenaAlloc;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000016class SkBitmap;
17class 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 Malita4aed1382017-05-25 10:38:07 -040025class SkPictureShader : public SkShaderBase {
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000026public:
Florin Malitab00a3602017-07-13 22:34:04 -040027 ~SkPictureShader() override;
28
Mike Reede25b4472019-04-02 17:49:12 -040029 static sk_sp<SkShader> Make(sk_sp<SkPicture>, SkTileMode, SkTileMode, const SkMatrix*,
reed8a21c9f2016-03-08 18:50:00 -080030 const SkRect*);
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000031
bsalomonc21b09e2015-08-28 18:46:56 -070032#if SK_SUPPORT_GPU
Mike Reede3429e62018-01-19 11:43:34 -050033 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
bsalomonc21b09e2015-08-28 18:46:56 -070034#endif
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000035
36protected:
37 SkPictureShader(SkReadBuffer&);
mtklein36352bf2015-03-25 18:17:31 -070038 void flatten(SkWriteBuffer&) const override;
Mike Reed1386b2d2019-03-13 21:15:05 -040039 bool onAppendStages(const SkStageRec&) const override;
Mike Reedcb1a2df2020-03-21 18:02:58 -040040 skvm::Color onProgram(skvm::Builder*, skvm::F32 x, skvm::F32 y, skvm::Color paint,
Mike Kleine81b1082020-06-19 11:29:13 -050041 const SkMatrixProvider&, const SkMatrix* localM,
Mike Reedcb1a2df2020-03-21 18:02:58 -040042 SkFilterQuality quality, const SkColorInfo& dst,
43 skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override;
44
Mike Reede92aae62018-10-17 10:21:51 -040045#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
Herb Derby83e939b2017-02-07 14:25:11 -050046 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override;
Mike Reede92aae62018-10-17 10:21:51 -040047#endif
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000048
49private:
Mike Klein4fee3232018-10-18 17:27:16 -040050 SK_FLATTENABLE_HOOKS(SkPictureShader)
51
Mike Reedfae8fce2019-04-03 10:27:45 -040052 SkPictureShader(sk_sp<SkPicture>, SkTileMode, SkTileMode, const SkMatrix*, const SkRect*);
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000053
Florin Malita8f88d892018-04-19 21:07:19 -040054 sk_sp<SkShader> refBitmapShader(const SkMatrix&, SkTCopyOnFirstWrite<SkMatrix>* localMatrix,
Brian Osman2e8f48e2018-10-19 13:50:48 -040055 SkColorType dstColorType, SkColorSpace* dstColorSpace,
reed8a21c9f2016-03-08 18:50:00 -080056 const int maxTextureSize = 0) const;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000057
Florin Malita4aed1382017-05-25 10:38:07 -040058 class PictureShaderContext : public Context {
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +000059 public:
Herb Derby83e939b2017-02-07 14:25:11 -050060 PictureShaderContext(
61 const SkPictureShader&, const ContextRec&, sk_sp<SkShader> bitmapShader, SkArenaAlloc*);
skia.committer@gmail.comedda70e2014-05-06 03:06:53 +000062
mtklein36352bf2015-03-25 18:17:31 -070063 uint32_t getFlags() const override;
skia.committer@gmail.comedda70e2014-05-06 03:06:53 +000064
mtklein36352bf2015-03-25 18:17:31 -070065 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
skia.committer@gmail.comedda70e2014-05-06 03:06:53 +000066
Florin Malita4aed1382017-05-25 10:38:07 -040067 sk_sp<SkShader> fBitmapShader;
68 SkShaderBase::Context* fBitmapShaderContext;
69 void* fBitmapShaderContextStorage;
skia.committer@gmail.comedda70e2014-05-06 03:06:53 +000070
Florin Malita4aed1382017-05-25 10:38:07 -040071 typedef Context INHERITED;
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +000072 };
skia.committer@gmail.comedda70e2014-05-06 03:06:53 +000073
Florin Malitab00a3602017-07-13 22:34:04 -040074 sk_sp<SkPicture> fPicture;
75 SkRect fTile;
Mike Reedfae8fce2019-04-03 10:27:45 -040076 SkTileMode fTmx, fTmy;
Florin Malitab00a3602017-07-13 22:34:04 -040077
Mike Klein015c8992018-08-09 12:23:19 -040078 const uint32_t fUniqueID;
79 mutable std::atomic<bool> fAddedToCache;
Matt Sarett28a7ad22017-04-21 15:12:34 -040080
Florin Malita4aed1382017-05-25 10:38:07 -040081 typedef SkShaderBase INHERITED;
commit-bot@chromium.orgc5d9bb02014-04-08 15:19:34 +000082};
83
84#endif // SkPictureShader_DEFINED