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 | |
| 11 | #include "SkFilterQuality.h" |
Florin Malita | c6c5ead | 2018-04-11 15:33:40 -0400 | [diff] [blame] | 12 | #include "SkMatrix.h" |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 13 | |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 14 | class GrContext; |
| 15 | class GrColorSpaceInfo; |
| 16 | |
| 17 | struct GrFPArgs { |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 18 | GrFPArgs(GrContext* context, |
| 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 | |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 33 | GrContext* fContext; |
| 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 | |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 45 | SkFilterQuality fFilterQuality; |
| 46 | const GrColorSpaceInfo* fDstColorSpaceInfo; |
| 47 | }; |
| 48 | |
Florin Malita | c6c5ead | 2018-04-11 15:33:40 -0400 | [diff] [blame] | 49 | class GrFPArgs::WithPreLocalMatrix final : public GrFPArgs { |
| 50 | public: |
| 51 | WithPreLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) { |
| 52 | if (!lm.isIdentity()) { |
| 53 | if (fPreLocalMatrix) { |
| 54 | fStorage.setConcat(lm, *fPreLocalMatrix); |
| 55 | fPreLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage; |
| 56 | } else { |
| 57 | fPreLocalMatrix = &lm; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | WithPreLocalMatrix(const WithPreLocalMatrix&) = delete; |
| 64 | WithPreLocalMatrix& operator=(const WithPreLocalMatrix&) = delete; |
| 65 | |
| 66 | SkMatrix fStorage; |
| 67 | |
| 68 | using INHERITED = GrFPArgs; |
| 69 | }; |
| 70 | |
| 71 | class GrFPArgs::WithPostLocalMatrix final : public GrFPArgs { |
| 72 | public: |
| 73 | WithPostLocalMatrix(const GrFPArgs& args, const SkMatrix& lm) : INHERITED(args) { |
| 74 | if (!lm.isIdentity()) { |
| 75 | if (fPostLocalMatrix) { |
| 76 | fStorage.setConcat(*fPostLocalMatrix, lm); |
| 77 | fPostLocalMatrix = fStorage.isIdentity() ? nullptr : &fStorage; |
| 78 | } else { |
| 79 | fPostLocalMatrix = &lm; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | WithPostLocalMatrix(const WithPostLocalMatrix&) = delete; |
| 86 | WithPostLocalMatrix& operator=(const WithPostLocalMatrix&) = delete; |
| 87 | |
| 88 | SkMatrix fStorage; |
| 89 | |
| 90 | using INHERITED = GrFPArgs; |
| 91 | }; |
| 92 | |
Mike Reed | e3429e6 | 2018-01-19 11:43:34 -0500 | [diff] [blame] | 93 | #endif |
| 94 | |