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