blob: 73c21f718de65f868c38bc2194d6e75dab9f157f [file] [log] [blame]
Mike Reede3429e62018-01-19 11:43:34 -05001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkMatrix.h"
Mike Reede3429e62018-01-19 11:43:34 -050012
Brian Salomon4bc0c1f2019-09-30 15:12:27 -040013class GrColorInfo;
Robert Phillips9338c602019-02-19 12:52:29 -050014class GrRecordingContext;
Brian Osman449b1152020-04-15 16:43:00 -040015class SkMatrixProvider;
Mike Reede3429e62018-01-19 11:43:34 -050016
17struct GrFPArgs {
Robert Phillips9338c602019-02-19 12:52:29 -050018 GrFPArgs(GrRecordingContext* context,
Brian Osman449b1152020-04-15 16:43:00 -040019 const SkMatrixProvider& matrixProvider,
Brian Salomon4bc0c1f2019-09-30 15:12:27 -040020 const GrColorInfo* dstColorInfo)
21 : fContext(context)
Brian Osman449b1152020-04-15 16:43:00 -040022 , fMatrixProvider(matrixProvider)
Brian Salomon4bc0c1f2019-09-30 15:12:27 -040023 , fDstColorInfo(dstColorInfo) {
Florin Malitac6c5ead2018-04-11 15:33:40 -040024 SkASSERT(fContext);
Florin Malitac6c5ead2018-04-11 15:33:40 -040025 }
26
27 class WithPreLocalMatrix;
Michael Ludwig4e221bd2020-06-05 11:29:36 -040028
29 GrFPArgs withNewMatrixProvider(const SkMatrixProvider& provider) const {
Mike Reed12a75582021-03-20 10:49:02 -040030 GrFPArgs newArgs(fContext, provider, fDstColorInfo);
Michael Ludwig4e221bd2020-06-05 11:29:36 -040031 newArgs.fInputColorIsOpaque = fInputColorIsOpaque;
32 newArgs.fPreLocalMatrix = fPreLocalMatrix;
33 return newArgs;
34 }
Mike Reed3bc266b2018-01-20 22:24:41 +000035
Robert Phillips9338c602019-02-19 12:52:29 -050036 GrRecordingContext* fContext;
Brian Osman449b1152020-04-15 16:43:00 -040037 const SkMatrixProvider& fMatrixProvider;
Florin Malitac6c5ead2018-04-11 15:33:40 -040038
Florin Malitac6c5ead2018-04-11 15:33:40 -040039 const SkMatrix* fPreLocalMatrix = nullptr;
Florin Malitac6c5ead2018-04-11 15:33:40 -040040
Brian Salomonc0d79e52019-04-10 15:02:11 -040041 // Make this SkAlphaType?
42 bool fInputColorIsOpaque = false;
43
Brian Salomon4bc0c1f2019-09-30 15:12:27 -040044 const GrColorInfo* fDstColorInfo;
Mike Reede3429e62018-01-19 11:43:34 -050045};
46
Florin Malitac6c5ead2018-04-11 15:33:40 -040047class GrFPArgs::WithPreLocalMatrix final : public GrFPArgs {
48public:
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
60private:
61 WithPreLocalMatrix(const WithPreLocalMatrix&) = delete;
62 WithPreLocalMatrix& operator=(const WithPreLocalMatrix&) = delete;
63
64 SkMatrix fStorage;
65
66 using INHERITED = GrFPArgs;
67};
68
Mike Reede3429e62018-01-19 11:43:34 -050069#endif