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 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(const StageRec&) const override; 52 onMakeColorSpace(SkColorSpaceXformer * xformer)53 sk_sp<SkShader> onMakeColorSpace(SkColorSpaceXformer* xformer) const override { 54 return as_SB(fProxyShader)->makeColorSpace(xformer)->makeWithLocalMatrix( 55 this->getLocalMatrix()); 56 } 57 58 #ifdef SK_SUPPORT_LEGACY_SHADER_ISABITMAP onIsABitmap(SkBitmap * bitmap,SkMatrix * matrix,TileMode * mode)59 bool onIsABitmap(SkBitmap* bitmap, SkMatrix* matrix, TileMode* mode) const override { 60 return fProxyShader->isABitmap(bitmap, matrix, mode); 61 } 62 #endif 63 onIsRasterPipelineOnly(const SkMatrix & ctm)64 bool onIsRasterPipelineOnly(const SkMatrix& ctm) const override { 65 return as_SB(fProxyShader)->isRasterPipelineOnly(SkMatrix::Concat(ctm, 66 this->getLocalMatrix())); 67 } 68 69 private: 70 sk_sp<SkShader> fProxyShader; 71 72 typedef SkShaderBase INHERITED; 73 }; 74 75 #endif 76