1 /* 2 * Copyright 2016 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 SkLinearBitmapPipeline_matrix_DEFINED 9 #define SkLinearBitmapPipeline_matrix_DEFINED 10 11 #include "SkLinearBitmapPipeline_core.h" 12 13 namespace { 14 class TranslateMatrixStrategy { 15 public: 16 TranslateMatrixStrategy(SkVector offset) 17 : fXOffset{X(offset)} 18 , fYOffset{Y(offset)} { } 19 20 void processPoints(Sk4s* xs, Sk4s* ys) const { 21 *xs = *xs + fXOffset; 22 *ys = *ys + fYOffset; 23 } 24 25 template <typename Next> 26 bool maybeProcessSpan(Span span, Next* next) const { 27 SkPoint start; SkScalar length; int count; 28 std::tie(start, length, count) = span; 29 next->pointSpan(Span{start + SkPoint{fXOffset, fYOffset}, length, count}); 30 return true; 31 } 32 33 private: 34 const SkScalar fXOffset, fYOffset; 35 }; 36 37 class ScaleMatrixStrategy { 38 public: 39 ScaleMatrixStrategy(SkVector offset, SkVector scale) 40 : fXOffset{X(offset)}, fYOffset{Y(offset)} 41 , fXScale{X(scale)}, fYScale{Y(scale)} { } 42 void processPoints(Sk4s* xs, Sk4s* ys) const { 43 *xs = *xs * fXScale + fXOffset; 44 *ys = *ys * fYScale + fYOffset; 45 } 46 47 template <typename Next> 48 bool maybeProcessSpan(Span span, Next* next) const { 49 SkPoint start; SkScalar length; int count; 50 std::tie(start, length, count) = span; 51 SkPoint newStart = 52 SkPoint{X(start) * fXScale + fXOffset, Y(start) * fYScale + fYOffset}; 53 SkScalar newLength = length * fXScale; 54 next->pointSpan(Span{newStart, newLength, count}); 55 return true; 56 } 57 58 private: 59 const SkScalar fXOffset, fYOffset; 60 const SkScalar fXScale, fYScale; 61 }; 62 63 class AffineMatrixStrategy { 64 public: 65 AffineMatrixStrategy(SkVector offset, SkVector scale, SkVector skew) 66 : fXOffset{X(offset)}, fYOffset{Y(offset)} 67 , fXScale{X(scale)}, fYScale{Y(scale)} 68 , fXSkew{X(skew)}, fYSkew{Y(skew)} { } 69 void processPoints(Sk4s* xs, Sk4s* ys) const { 70 Sk4s newXs = fXScale * *xs + fXSkew * *ys + fXOffset; 71 Sk4s newYs = fYSkew * *xs + fYScale * *ys + fYOffset; 72 73 *xs = newXs; 74 *ys = newYs; 75 } 76 77 template <typename Next> 78 bool maybeProcessSpan(Span span, Next* next) const { 79 return false; 80 } 81 82 private: 83 const SkScalar fXOffset, fYOffset; 84 const SkScalar fXScale, fYScale; 85 const SkScalar fXSkew, fYSkew; 86 }; 87 88 class PerspectiveMatrixStrategy { 89 public: 90 PerspectiveMatrixStrategy(SkVector offset, SkVector scale, SkVector skew, 91 SkVector zSkew, SkScalar zOffset) 92 : fXOffset{X(offset)}, fYOffset{Y(offset)}, fZOffset{zOffset} 93 , fXScale{X(scale)}, fYScale{Y(scale)} 94 , fXSkew{X(skew)}, fYSkew{Y(skew)}, fZXSkew{X(zSkew)}, fZYSkew{Y(zSkew)} { } 95 void processPoints(Sk4s* xs, Sk4s* ys) const { 96 Sk4s newXs = fXScale * *xs + fXSkew * *ys + fXOffset; 97 Sk4s newYs = fYSkew * *xs + fYScale * *ys + fYOffset; 98 Sk4s newZs = fZXSkew * *xs + fZYSkew * *ys + fZOffset; 99 100 *xs = newXs / newZs; 101 *ys = newYs / newZs; 102 } 103 104 template <typename Next> 105 bool maybeProcessSpan(Span span, Next* next) const { 106 return false; 107 } 108 109 private: 110 const SkScalar fXOffset, fYOffset, fZOffset; 111 const SkScalar fXScale, fYScale; 112 const SkScalar fXSkew, fYSkew, fZXSkew, fZYSkew; 113 }; 114 115 116 } // namespace 117 118 #endif // SkLinearBitmapPipeline_matrix_DEFINED 119