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 11 #include "SkBitmapProcShader.h" 12 #include "SkColorSpaceXformer.h" 13 #include "SkImage.h" 14 #include "SkShaderBase.h" 15 16 class SkImageShader : public SkShaderBase { 17 public: 18 static sk_sp<SkShader> Make(sk_sp<SkImage>, 19 SkShader::TileMode tx, 20 SkShader::TileMode ty, 21 const SkMatrix* localMatrix, 22 bool clampAsIfUnpremul = false); 23 24 bool isOpaque() const override; 25 26 #if SK_SUPPORT_GPU 27 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override; 28 #endif 29 30 private: 31 SK_FLATTENABLE_HOOKS(SkImageShader) 32 33 SkImageShader(sk_sp<SkImage>, 34 SkShader::TileMode tx, 35 SkShader::TileMode ty, 36 const SkMatrix* localMatrix, 37 bool clampAsIfUnpremul); 38 39 void flatten(SkWriteBuffer&) const override; 40 #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT 41 Context* onMakeContext(const ContextRec&, SkArenaAlloc* storage) const override; 42 #endif 43 SkImage* onIsAImage(SkMatrix*, SkShader::TileMode*) const override; 44 45 bool onAppendStages(const StageRec&) const override; 46 onMakeColorSpace(SkColorSpaceXformer * xformer)47 sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override { 48 return xformer->apply(fImage.get())->makeShader(fTileModeX, fTileModeY, 49 &this->getLocalMatrix()); 50 } 51 52 sk_sp<SkImage> fImage; 53 const SkShader::TileMode fTileModeX; 54 const SkShader::TileMode fTileModeY; 55 const bool fClampAsIfUnpremul; 56 57 friend class SkShaderBase; 58 typedef SkShaderBase INHERITED; 59 }; 60 61 #endif 62