huangcm
2024-12-18 9d29be7f7249789d6ffd0440067187a9f040c2cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright 2018 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
 
#ifndef GrFPArgs_DEFINED
#define GrFPArgs_DEFINED
 
#include "SkFilterQuality.h"
#include "SkMatrix.h"
 
class GrContext;
class GrColorSpaceInfo;
 
struct GrFPArgs {
    GrFPArgs(GrContext* context,
             const SkMatrix* viewMatrix,
             SkFilterQuality filterQuality,
             const GrColorSpaceInfo* dstColorSpaceInfo)
    : fContext(context)
    , fViewMatrix(viewMatrix)
    , fFilterQuality(filterQuality)
    , fDstColorSpaceInfo(dstColorSpaceInfo) {
        SkASSERT(fContext);
        SkASSERT(fViewMatrix);
    }
 
    class WithPreLocalMatrix;
    class WithPostLocalMatrix;
 
    GrContext* fContext;
    const SkMatrix* fViewMatrix;
 
    // We track both pre and post local matrix adjustments.  For a given FP:
    //
    //   total_local_matrix = postLocalMatrix x FP_localMatrix x preLocalMatrix
    //
    // Use the helpers above to create pre/post GrFPArgs wrappers.
    //
    const SkMatrix* fPreLocalMatrix  = nullptr;
    const SkMatrix* fPostLocalMatrix = nullptr;
 
    SkFilterQuality fFilterQuality;
    const GrColorSpaceInfo* fDstColorSpaceInfo;
};
 
class GrFPArgs::WithPreLocalMatrix final : public GrFPArgs {
public:
    WithPreLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) {
        if (!lm.isIdentity()) {
            if (fPreLocalMatrix) {
                fStorage.setConcat(lm, *fPreLocalMatrix);
                fPreLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage;
            } else {
                fPreLocalMatrix = &lm;
            }
        }
    }
 
private:
    WithPreLocalMatrix(const WithPreLocalMatrix&) = delete;
    WithPreLocalMatrix& operator=(const WithPreLocalMatrix&) = delete;
 
    SkMatrix fStorage;
 
    using INHERITED = GrFPArgs;
};
 
class GrFPArgs::WithPostLocalMatrix final : public GrFPArgs {
public:
    WithPostLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) {
        if (!lm.isIdentity()) {
            if (fPostLocalMatrix) {
                fStorage.setConcat(*fPostLocalMatrix, lm);
                fPostLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage;
            } else {
                fPostLocalMatrix = &lm;
            }
        }
    }
 
private:
    WithPostLocalMatrix(const WithPostLocalMatrix&) = delete;
    WithPostLocalMatrix& operator=(const WithPostLocalMatrix&) = delete;
 
    SkMatrix fStorage;
 
    using INHERITED = GrFPArgs;
};
 
#endif