1 /* 2 * Copyright 2018 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 GrFPArgs_DEFINED 9 #define GrFPArgs_DEFINED 10 11 #include "include/core/SkMatrix.h" 12 13 class GrColorInfo; 14 class GrRecordingContext; 15 class SkMatrixProvider; 16 17 struct GrFPArgs { GrFPArgsGrFPArgs18 GrFPArgs(GrRecordingContext* context, 19 const SkMatrixProvider& matrixProvider, 20 const GrColorInfo* dstColorInfo) 21 : fContext(context) 22 , fMatrixProvider(matrixProvider) 23 , fDstColorInfo(dstColorInfo) { 24 SkASSERT(fContext); 25 } 26 27 class WithPreLocalMatrix; 28 withNewMatrixProviderGrFPArgs29 GrFPArgs withNewMatrixProvider(const SkMatrixProvider& provider) const { 30 GrFPArgs newArgs(fContext, provider, fDstColorInfo); 31 newArgs.fPreLocalMatrix = fPreLocalMatrix; 32 return newArgs; 33 } 34 35 GrRecordingContext* fContext; 36 const SkMatrixProvider& fMatrixProvider; 37 38 const SkMatrix* fPreLocalMatrix = nullptr; 39 40 const GrColorInfo* fDstColorInfo; 41 }; 42 43 class GrFPArgs::WithPreLocalMatrix final : public GrFPArgs { 44 public: WithPreLocalMatrix(const GrFPArgs & args,const SkMatrix & lm)45 WithPreLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) { 46 if (!lm.isIdentity()) { 47 if (fPreLocalMatrix) { 48 fStorage.setConcat(lm, *fPreLocalMatrix); 49 fPreLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage; 50 } else { 51 fPreLocalMatrix = &lm; 52 } 53 } 54 } 55 56 private: 57 WithPreLocalMatrix(const WithPreLocalMatrix&) = delete; 58 WithPreLocalMatrix& operator=(const WithPreLocalMatrix&) = delete; 59 60 SkMatrix fStorage; 61 62 using INHERITED = GrFPArgs; 63 }; 64 65 #endif 66