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 protected: 41 void flatten(SkWriteBuffer&) const override; 42 43 #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT 44 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override; 45 #endif 46 47 SkImage* onIsAImage(SkMatrix* matrix, SkTileMode* mode) const override; 48 49 bool onAppendStages(const SkStageRec&) const override; 50 51 skvm::Color onProgram(skvm::Builder*, skvm::Coord device, skvm::Coord local, skvm::Color paint, 52 const SkMatrixProvider&, const SkMatrix* localM, const SkColorInfo& dst, 53 skvm::Uniforms* uniforms, SkArenaAlloc*) const override; 54 55 private: 56 SK_FLATTENABLE_HOOKS(SkLocalMatrixShader) 57 58 sk_sp<SkShader> fProxyShader; 59 60 using INHERITED = SkShaderBase; 61 }; 62 63 #endif 64