reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Matt Sarett | 6cc6ae7 | 2017-04-18 18:29:12 -0400 | [diff] [blame] | 11 | #include "SkBitmapProcShader.h" |
| 12 | #include "SkColorSpaceXformer.h" |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 13 | #include "SkImage.h" |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 14 | #include "SkShaderBase.h" |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 15 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 16 | class SkImageShader : public SkShaderBase { |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 17 | public: |
reed | 6b2d7ac | 2016-08-11 06:42:26 -0700 | [diff] [blame] | 18 | static sk_sp<SkShader> Make(sk_sp<SkImage>, TileMode tx, TileMode ty, |
Herb Derby | bfdc87a | 2017-02-14 15:06:23 +0000 | [diff] [blame] | 19 | const SkMatrix* localMatrix); |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 20 | |
| 21 | bool isOpaque() const override; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 22 | |
| 23 | SK_TO_STRING_OVERRIDE() |
| 24 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageShader) |
| 25 | |
| 26 | #if SK_SUPPORT_GPU |
brianosman | 839345d | 2016-07-22 11:04:53 -0700 | [diff] [blame] | 27 | sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 28 | #endif |
| 29 | |
reed | 6b2d7ac | 2016-08-11 06:42:26 -0700 | [diff] [blame] | 30 | SkImageShader(sk_sp<SkImage>, TileMode tx, TileMode ty, const SkMatrix* localMatrix); |
reed | 320a40d | 2016-08-02 06:12:06 -0700 | [diff] [blame] | 31 | |
Mike Klein | 0fddb2d | 2017-07-20 08:59:19 -0400 | [diff] [blame] | 32 | static bool IsRasterPipelineOnly(SkColorType, SkAlphaType, |
| 33 | SkShader::TileMode tx, SkShader::TileMode ty); |
Mike Reed | 980e279 | 2017-06-21 13:15:58 -0700 | [diff] [blame] | 34 | |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 35 | protected: |
| 36 | void flatten(SkWriteBuffer&) const override; |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 37 | Context* onMakeContext(const ContextRec&, SkArenaAlloc* storage) const override; |
Mike Reed | 627778d | 2016-09-28 17:13:38 -0400 | [diff] [blame] | 38 | #ifdef SK_SUPPORT_LEGACY_SHADER_ISABITMAP |
reed | f1ac182 | 2016-08-01 11:24:14 -0700 | [diff] [blame] | 39 | bool onIsABitmap(SkBitmap*, SkMatrix*, TileMode*) const override; |
Mike Reed | 627778d | 2016-09-28 17:13:38 -0400 | [diff] [blame] | 40 | #endif |
reed | f1ac182 | 2016-08-01 11:24:14 -0700 | [diff] [blame] | 41 | SkImage* onIsAImage(SkMatrix*, TileMode*) const override; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 42 | |
Florin Malita | 5769dd2 | 2017-07-12 13:31:25 -0400 | [diff] [blame] | 43 | bool onIsRasterPipelineOnly() const override; |
| 44 | |
Herb Derby | ac04fef | 2017-01-13 17:34:33 -0500 | [diff] [blame] | 45 | bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*, |
Florin Malita | 882ccaf | 2017-01-27 10:51:58 -0500 | [diff] [blame] | 46 | const SkMatrix& ctm, const SkPaint&, const SkMatrix*) const override; |
Mike Klein | 06a65e2 | 2016-11-17 12:39:09 -0500 | [diff] [blame] | 47 | |
Matt Sarett | 6cc6ae7 | 2017-04-18 18:29:12 -0400 | [diff] [blame] | 48 | sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override { |
| 49 | return xformer->apply(fImage.get())->makeShader(fTileModeX, fTileModeY, |
| 50 | &this->getLocalMatrix()); |
| 51 | } |
| 52 | |
reed | 6b2d7ac | 2016-08-11 06:42:26 -0700 | [diff] [blame] | 53 | sk_sp<SkImage> fImage; |
| 54 | const TileMode fTileModeX; |
| 55 | const TileMode fTileModeY; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 56 | |
| 57 | private: |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 58 | friend class SkShaderBase; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 59 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 60 | typedef SkShaderBase INHERITED; |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | #endif |