blob: 6990a4a0dc95f5b63a960ea4be2e053c166514aa [file] [log] [blame]
reed856e9d92015-09-30 12:21:45 -07001/*
2 * Copyright 2015 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 SkImageShader_DEFINED
9#define SkImageShader_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkImage.h"
12#include "src/shaders/SkBitmapProcShader.h"
13#include "src/shaders/SkShaderBase.h"
reed856e9d92015-09-30 12:21:45 -070014
Florin Malita4aed1382017-05-25 10:38:07 -040015class SkImageShader : public SkShaderBase {
reed856e9d92015-09-30 12:21:45 -070016public:
Mike Klein1f313092018-01-03 10:30:21 -050017 static sk_sp<SkShader> Make(sk_sp<SkImage>,
Mike Reede25b4472019-04-02 17:49:12 -040018 SkTileMode tmx,
19 SkTileMode tmy,
Mike Klein1f313092018-01-03 10:30:21 -050020 const SkMatrix* localMatrix,
21 bool clampAsIfUnpremul = false);
reed856e9d92015-09-30 12:21:45 -070022
23 bool isOpaque() const override;
reed856e9d92015-09-30 12:21:45 -070024
reed856e9d92015-09-30 12:21:45 -070025#if SK_SUPPORT_GPU
Mike Reede3429e62018-01-19 11:43:34 -050026 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
reed856e9d92015-09-30 12:21:45 -070027#endif
28
Mike Klein1f313092018-01-03 10:30:21 -050029private:
Mike Klein4fee3232018-10-18 17:27:16 -040030 SK_FLATTENABLE_HOOKS(SkImageShader)
31
Mike Klein1f313092018-01-03 10:30:21 -050032 SkImageShader(sk_sp<SkImage>,
Mike Reede25b4472019-04-02 17:49:12 -040033 SkTileMode tmx,
34 SkTileMode tmy,
Mike Klein1f313092018-01-03 10:30:21 -050035 const SkMatrix* localMatrix,
36 bool clampAsIfUnpremul);
37
reed856e9d92015-09-30 12:21:45 -070038 void flatten(SkWriteBuffer&) const override;
Mike Reede92aae62018-10-17 10:21:51 -040039#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
Herb Derby83e939b2017-02-07 14:25:11 -050040 Context* onMakeContext(const ContextRec&, SkArenaAlloc* storage) const override;
Mike Reede92aae62018-10-17 10:21:51 -040041#endif
Mike Reedfae8fce2019-04-03 10:27:45 -040042 SkImage* onIsAImage(SkMatrix*, SkTileMode*) const override;
reed856e9d92015-09-30 12:21:45 -070043
Mike Reed1386b2d2019-03-13 21:15:05 -040044 bool onAppendStages(const SkStageRec&) const override;
Mike Klein06a65e22016-11-17 12:39:09 -050045
Mike Reedfae8fce2019-04-03 10:27:45 -040046 sk_sp<SkImage> fImage;
47 const SkTileMode fTileModeX;
48 const SkTileMode fTileModeY;
49 const bool fClampAsIfUnpremul;
reed856e9d92015-09-30 12:21:45 -070050
Florin Malita4aed1382017-05-25 10:38:07 -040051 friend class SkShaderBase;
Florin Malita4aed1382017-05-25 10:38:07 -040052 typedef SkShaderBase INHERITED;
reed856e9d92015-09-30 12:21:45 -070053};
54
55#endif