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.fInputColorIsOpaque = fInputColorIsOpaque;
32         newArgs.fPreLocalMatrix = fPreLocalMatrix;
33         return newArgs;
34     }
35 
36     GrRecordingContext* fContext;
37     const SkMatrixProvider& fMatrixProvider;
38 
39     const SkMatrix* fPreLocalMatrix  = nullptr;
40 
41     // Make this SkAlphaType?
42     bool fInputColorIsOpaque = false;
43 
44     const GrColorInfo* fDstColorInfo;
45 };
46 
47 class GrFPArgs::WithPreLocalMatrix final : public GrFPArgs {
48 public:
WithPreLocalMatrix(const GrFPArgs & args,const SkMatrix & lm)49     WithPreLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) {
50         if (!lm.isIdentity()) {
51             if (fPreLocalMatrix) {
52                 fStorage.setConcat(lm, *fPreLocalMatrix);
53                 fPreLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage;
54             } else {
55                 fPreLocalMatrix = &lm;
56             }
57         }
58     }
59 
60 private:
61     WithPreLocalMatrix(const WithPreLocalMatrix&) = delete;
62     WithPreLocalMatrix& operator=(const WithPreLocalMatrix&) = delete;
63 
64     SkMatrix fStorage;
65 
66     using INHERITED = GrFPArgs;
67 };
68 
69 #endif
70