1 /* 2 * Copyright 2017 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 #ifndef SkPDFGradientShader_DEFINED 8 #define SkPDFGradientShader_DEFINED 9 10 #include "include/core/SkShader.h" 11 #include "src/pdf/SkPDFTypes.h" 12 #include "src/pdf/SkPDFUtils.h" 13 #include "src/shaders/SkShaderBase.h" 14 15 class SkMatrix; 16 class SkPDFDocument; 17 struct SkIRect; 18 19 namespace SkPDFGradientShader { 20 21 SkPDFIndirectReference Make(SkPDFDocument* doc, 22 SkShader* shader, 23 const SkMatrix& matrix, 24 const SkIRect& surfaceBBox); 25 26 struct Key { 27 SkShaderBase::GradientType fType; 28 SkShaderBase::GradientInfo fInfo; 29 std::unique_ptr<SkColor[]> fColors; 30 std::unique_ptr<SkScalar[]> fStops; 31 SkMatrix fCanvasTransform; 32 SkMatrix fShaderTransform; 33 SkIRect fBBox; 34 uint32_t fHash; 35 }; 36 37 struct KeyHash { operatorKeyHash38 uint32_t operator()(const Key& k) const { return k.fHash; } 39 }; 40 41 inline bool operator==(const SkShaderBase::GradientInfo& u, const SkShaderBase::GradientInfo& v) { 42 return u.fColorCount == v.fColorCount 43 && u.fPoint[0] == v.fPoint[0] 44 && u.fPoint[1] == v.fPoint[1] 45 && u.fRadius[0] == v.fRadius[0] 46 && u.fRadius[1] == v.fRadius[1] 47 && u.fTileMode == v.fTileMode 48 && u.fGradientFlags == v.fGradientFlags 49 && SkPackedArrayEqual(u.fColors, v.fColors, u.fColorCount) 50 && SkPackedArrayEqual(u.fColorOffsets, v.fColorOffsets, u.fColorCount); 51 } 52 53 inline bool operator==(const Key& u, const Key& v) { 54 SkASSERT(u.fInfo.fColors == u.fColors.get()); 55 SkASSERT(u.fInfo.fColorOffsets == u.fStops.get()); 56 SkASSERT(v.fInfo.fColors == v.fColors.get()); 57 SkASSERT(v.fInfo.fColorOffsets == v.fStops.get()); 58 return u.fType == v.fType 59 && u.fInfo == v.fInfo 60 && u.fCanvasTransform == v.fCanvasTransform 61 && u.fShaderTransform == v.fShaderTransform 62 && u.fBBox == v.fBBox; 63 } 64 inline bool operator!=(const Key& u, const Key& v) { return !(u == v); } 65 66 } // namespace SkPDFGradientShader 67 #endif // SkPDFGradientShader_DEFINED 68