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 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) 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 SK_TO_STRING_OVERRIDE() 42 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) 43 44 protected: 45 void flatten(SkWriteBuffer&) const override; 46 47 Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override; 48 49 SkImage* onIsAImage(SkMatrix* matrix, TileMode* mode) const override; 50 51 bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*, 52 const SkMatrix&, const SkPaint&, const SkMatrix*) const override; 53 onMakeColorSpace(SkColorSpaceXformer * xformer)54 sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override { 55 return as_SB(fProxyShader)->makeColorSpace(xformer)->makeWithLocalMatrix( 56 this->getLocalMatrix()); 57 } 58 59 #ifdef SK_SUPPORT_LEGACY_SHADER_ISABITMAP onIsABitmap(SkBitmap * bitmap,SkMatrix * matrix,TileMode * mode)60 bool onIsABitmap(SkBitmap* bitmap, SkMatrix* matrix, TileMode* mode) const override { 61 return fProxyShader->isABitmap(bitmap, matrix, mode); 62 } 63 #endif 64 onIsRasterPipelineOnly()65 bool onIsRasterPipelineOnly() const override { 66 return as_SB(fProxyShader)->isRasterPipelineOnly(); 67 } 68 69 private: 70 sk_sp<SkShader> fProxyShader; 71 72 typedef SkShaderBase INHERITED; 73 }; 74 75 #endif 76