blob: b74c31548065f453a2e8f4809caf352f77e369bf [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
Matt Sarett6cc6ae72017-04-18 18:29:12 -040011#include "SkBitmapProcShader.h"
12#include "SkColorSpaceXformer.h"
reed856e9d92015-09-30 12:21:45 -070013#include "SkImage.h"
Florin Malita4aed1382017-05-25 10:38:07 -040014#include "SkShaderBase.h"
reed856e9d92015-09-30 12:21:45 -070015
Florin Malita4aed1382017-05-25 10:38:07 -040016class SkImageShader : public SkShaderBase {
reed856e9d92015-09-30 12:21:45 -070017public:
reed6b2d7ac2016-08-11 06:42:26 -070018 static sk_sp<SkShader> Make(sk_sp<SkImage>, TileMode tx, TileMode ty,
Herb Derbybfdc87a2017-02-14 15:06:23 +000019 const SkMatrix* localMatrix);
reed856e9d92015-09-30 12:21:45 -070020
21 bool isOpaque() const override;
reed856e9d92015-09-30 12:21:45 -070022
23 SK_TO_STRING_OVERRIDE()
24 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageShader)
25
26#if SK_SUPPORT_GPU
brianosman839345d2016-07-22 11:04:53 -070027 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override;
reed856e9d92015-09-30 12:21:45 -070028#endif
29
reed6b2d7ac2016-08-11 06:42:26 -070030 SkImageShader(sk_sp<SkImage>, TileMode tx, TileMode ty, const SkMatrix* localMatrix);
reed320a40d2016-08-02 06:12:06 -070031
Mike Klein0fddb2d2017-07-20 08:59:19 -040032 static bool IsRasterPipelineOnly(SkColorType, SkAlphaType,
33 SkShader::TileMode tx, SkShader::TileMode ty);
Mike Reed980e2792017-06-21 13:15:58 -070034
reed856e9d92015-09-30 12:21:45 -070035protected:
36 void flatten(SkWriteBuffer&) const override;
Herb Derby83e939b2017-02-07 14:25:11 -050037 Context* onMakeContext(const ContextRec&, SkArenaAlloc* storage) const override;
Mike Reed627778d2016-09-28 17:13:38 -040038#ifdef SK_SUPPORT_LEGACY_SHADER_ISABITMAP
reedf1ac1822016-08-01 11:24:14 -070039 bool onIsABitmap(SkBitmap*, SkMatrix*, TileMode*) const override;
Mike Reed627778d2016-09-28 17:13:38 -040040#endif
reedf1ac1822016-08-01 11:24:14 -070041 SkImage* onIsAImage(SkMatrix*, TileMode*) const override;
reed856e9d92015-09-30 12:21:45 -070042
Florin Malita5769dd22017-07-12 13:31:25 -040043 bool onIsRasterPipelineOnly() const override;
44
Herb Derbyac04fef2017-01-13 17:34:33 -050045 bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
Florin Malita882ccaf2017-01-27 10:51:58 -050046 const SkMatrix& ctm, const SkPaint&, const SkMatrix*) const override;
Mike Klein06a65e22016-11-17 12:39:09 -050047
Matt Sarett6cc6ae72017-04-18 18:29:12 -040048 sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override {
49 return xformer->apply(fImage.get())->makeShader(fTileModeX, fTileModeY,
50 &this->getLocalMatrix());
51 }
52
reed6b2d7ac2016-08-11 06:42:26 -070053 sk_sp<SkImage> fImage;
54 const TileMode fTileModeX;
55 const TileMode fTileModeY;
reed856e9d92015-09-30 12:21:45 -070056
57private:
Florin Malita4aed1382017-05-25 10:38:07 -040058 friend class SkShaderBase;
reed856e9d92015-09-30 12:21:45 -070059
Florin Malita4aed1382017-05-25 10:38:07 -040060 typedef SkShaderBase INHERITED;
reed856e9d92015-09-30 12:21:45 -070061};
62
63#endif