Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkFilterQuality.h" |
| 12 | #include "include/core/SkMatrix.h" |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 13 | |
Robert Phillips | a7f0013 | 2019-02-15 21:54:11 +0000 | [diff] [blame] | 14 | class GrColorSpaceInfo; |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 15 | class GrRecordingContext; |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 16 | |
| 17 | struct GrFPArgs { |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 18 | GrFPArgs(GrRecordingContext* context, |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 19 | const SkMatrix* viewMatrix, |
Mike Reed | 3bc266b | 2018-01-20 22:24:41 +0000 | [diff] [blame] | 20 | SkFilterQuality filterQuality, |
| 21 | const GrColorSpaceInfo* dstColorSpaceInfo) |
| 22 | : fContext(context) |
| 23 | , fViewMatrix(viewMatrix) |
Mike Reed | 3bc266b | 2018-01-20 22:24:41 +0000 | [diff] [blame] | 24 | , fFilterQuality(filterQuality) |
Florin Malita | c6c5ead | 2018-04-11 15:33:40 -0400 | [diff] [blame] | 25 | , fDstColorSpaceInfo(dstColorSpaceInfo) { |
| 26 | SkASSERT(fContext); |
| 27 | SkASSERT(fViewMatrix); |
| 28 | } |
| 29 | |
| 30 | class WithPreLocalMatrix; |
| 31 | class WithPostLocalMatrix; |
Mike Reed | 3bc266b | 2018-01-20 22:24:41 +0000 | [diff] [blame] | 32 | |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 33 | GrRecordingContext* fContext; |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 34 | const SkMatrix* fViewMatrix; |
Florin Malita | c6c5ead | 2018-04-11 15:33:40 -0400 | [diff] [blame] | 35 | |
| 36 | // We track both pre and post local matrix adjustments. For a given FP: |
| 37 | // |
| 38 | // total_local_matrix = postLocalMatrix x FP_localMatrix x preLocalMatrix |
| 39 | // |
| 40 | // Use the helpers above to create pre/post GrFPArgs wrappers. |
| 41 | // |
| 42 | const SkMatrix* fPreLocalMatrix = nullptr; |
| 43 | const SkMatrix* fPostLocalMatrix = nullptr; |
| 44 | |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 45 | // Make this SkAlphaType? |
| 46 | bool fInputColorIsOpaque = false; |
| 47 | |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 48 | SkFilterQuality fFilterQuality; |
| 49 | const GrColorSpaceInfo* fDstColorSpaceInfo; |
| 50 | }; |
| 51 | |
Florin Malita | c6c5ead | 2018-04-11 15:33:40 -0400 | [diff] [blame] | 52 | class GrFPArgs::WithPreLocalMatrix final : public GrFPArgs { |
| 53 | public: |
| 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 | class GrFPArgs::WithPostLocalMatrix final : public GrFPArgs { |
| 75 | public: |
| 76 | WithPostLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) { |
| 77 | if (!lm.isIdentity()) { |
| 78 | if (fPostLocalMatrix) { |
| 79 | fStorage.setConcat(*fPostLocalMatrix, lm); |
| 80 | fPostLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage; |
| 81 | } else { |
| 82 | fPostLocalMatrix = &lm; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | private: |
| 88 | WithPostLocalMatrix(const WithPostLocalMatrix&) = delete; |
| 89 | WithPostLocalMatrix& operator=(const WithPostLocalMatrix&) = delete; |
| 90 | |
| 91 | SkMatrix fStorage; |
| 92 | |
| 93 | using INHERITED = GrFPArgs; |
| 94 | }; |
| 95 | |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 96 | #endif |
| 97 | |