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 "SkShader.h" 12 #include "SkReadBuffer.h" 13 #include "SkWriteBuffer.h" 14 15 class GrFragmentProcessor; 16 class SkArenaAlloc; 17 18 class SkLocalMatrixShader : public SkShader { 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 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) 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 SK_TO_STRING_OVERRIDE() 41 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) 42 43 protected: 44 void flatten(SkWriteBuffer&) const override; 45 46 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override; 47 48 SkImage* onIsAImage(SkMatrix* matrix, TileMode* mode) const override; 49 50 bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*, 51 const SkMatrix&, const SkPaint&, const SkMatrix*) const override; 52 53 #ifdef SK_SUPPORT_LEGACY_SHADER_ISABITMAP onIsABitmap(SkBitmap * bitmap,SkMatrix * matrix,TileMode * mode)54 bool onIsABitmap(SkBitmap* bitmap, SkMatrix* matrix, TileMode* mode) const override { 55 return fProxyShader->isABitmap(bitmap, matrix, mode); 56 } 57 #endif 58 59 private: 60 sk_sp<SkShader> fProxyShader; 61 62 typedef SkShader INHERITED; 63 }; 64 65 #endif 66