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/SkFilterQuality.h"
12 #include "include/core/SkMatrix.h"
13 
14 class GrColorInfo;
15 class GrRecordingContext;
16 class SkMatrixProvider;
17 
18 struct GrFPArgs {
GrFPArgsGrFPArgs19     GrFPArgs(GrRecordingContext* context,
20              const SkMatrixProvider& matrixProvider,
21              SkFilterQuality filterQuality,
22              const GrColorInfo* dstColorInfo)
23             : fContext(context)
24             , fMatrixProvider(matrixProvider)
25             , fFilterQuality(filterQuality)
26             , fDstColorInfo(dstColorInfo) {
27         SkASSERT(fContext);
28     }
29 
30     class WithPreLocalMatrix;
31 
withNewMatrixProviderGrFPArgs32     GrFPArgs withNewMatrixProvider(const SkMatrixProvider& provider) const {
33         GrFPArgs newArgs(fContext, provider, fFilterQuality, fDstColorInfo);
34         newArgs.fInputColorIsOpaque = fInputColorIsOpaque;
35         newArgs.fPreLocalMatrix = fPreLocalMatrix;
36         return newArgs;
37     }
38 
39     GrRecordingContext* fContext;
40     const SkMatrixProvider& fMatrixProvider;
41 
42     const SkMatrix* fPreLocalMatrix  = nullptr;
43 
44     // Make this SkAlphaType?
45     bool fInputColorIsOpaque = false;
46 
47     SkFilterQuality fFilterQuality;
48     bool fAllowFilterQualityReduction = true;
49     const GrColorInfo* fDstColorInfo;
50 };
51 
52 class GrFPArgs::WithPreLocalMatrix final : public GrFPArgs {
53 public:
WithPreLocalMatrix(const GrFPArgs & args,const SkMatrix & lm)54     WithPreLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) {
55         if (!lm.isIdentity()) {
56             if (fPreLocalMatrix) {
57                 fStorage.setConcat(lm, *fPreLocalMatrix);
58                 fPreLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage;
59             } else {
60                 fPreLocalMatrix = &lm;
61             }
62         }
63     }
64 
65 private:
66     WithPreLocalMatrix(const WithPreLocalMatrix&) = delete;
67     WithPreLocalMatrix& operator=(const WithPreLocalMatrix&) = delete;
68 
69     SkMatrix fStorage;
70 
71     using INHERITED = GrFPArgs;
72 };
73 
74 #endif
75