1 /* 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 SkLocalMatrixShader_DEFINED 9 #define SkLocalMatrixShader_DEFINED 10 11 #include "src/core/SkReadBuffer.h" 12 #include "src/core/SkWriteBuffer.h" 13 #include "src/shaders/SkShaderBase.h" 14 15 class GrFragmentProcessor; 16 class SkArenaAlloc; 17 18 class SkLocalMatrixShader final : public SkShaderBase { 19 public: SkLocalMatrixShader(sk_sp<SkShader> proxy,const SkMatrix & localMatrix)20 SkLocalMatrixShader(sk_sp<SkShader> proxy, const SkMatrix& localMatrix) 21 : INHERITED(&localMatrix) 22 , fProxyShader(std::move(proxy)) 23 {} 24 asAGradient(GradientInfo * info)25 GradientType asAGradient(GradientInfo* info) const override { 26 return fProxyShader->asAGradient(info); 27 } 28 29 #if SK_SUPPORT_GPU 30 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override; 31 #endif 32 makeAsALocalMatrixShader(SkMatrix * localMatrix)33 sk_sp<SkShader> makeAsALocalMatrixShader(SkMatrix* localMatrix) const override { 34 if (localMatrix) { 35 *localMatrix = this->getLocalMatrix(); 36 } 37 return fProxyShader; 38 } 39 40 SkPicture* isAPicture(SkMatrix*, SkTileMode[2], SkRect* tile) const override; 41 42 protected: 43 void flatten(SkWriteBuffer&) const override; 44 45 #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT 46 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override; 47 #endif 48 49 SkImage* onIsAImage(SkMatrix* matrix, SkTileMode* mode) const override; 50 51 bool onAppendStages(const SkStageRec&) const override; 52 53 private: 54 SK_FLATTENABLE_HOOKS(SkLocalMatrixShader) 55 56 sk_sp<SkShader> fProxyShader; 57 58 typedef SkShaderBase INHERITED; 59 }; 60 61 #endif 62