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