blob: 0cc059c5a0fd72327a304550da06d853ccb2a649 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkPDFGradientShader_DEFINED
#define SkPDFGradientShader_DEFINED
#include "SkPDFTypes.h"
#include "SkPDFUtils.h"
#include "SkShader.h"
class SkMatrix;
class SkPDFDocument;
struct SkIRect;
namespace SkPDFGradientShader {
sk_sp<SkPDFObject> Make(SkPDFDocument* doc,
SkShader* shader,
const SkMatrix& matrix,
const SkIRect& surfaceBBox);
struct Key {
SkShader::GradientType fType;
SkShader::GradientInfo fInfo;
std::unique_ptr<SkColor[]> fColors;
std::unique_ptr<SkScalar[]> fStops;
SkMatrix fCanvasTransform;
SkMatrix fShaderTransform;
SkIRect fBBox;
uint32_t fHash;
};
struct KeyHash {
uint32_t operator()(const Key& k) const { return k.fHash; }
};
using HashMap = SkTHashMap<Key, sk_sp<SkPDFObject>, KeyHash>;
inline bool operator==(const SkShader::GradientInfo& u, const SkShader::GradientInfo& v) {
return u.fColorCount == v.fColorCount
&& u.fPoint[0] == v.fPoint[0]
&& u.fPoint[1] == v.fPoint[1]
&& u.fRadius[0] == v.fRadius[0]
&& u.fRadius[1] == v.fRadius[1]
&& u.fTileMode == v.fTileMode
&& u.fGradientFlags == v.fGradientFlags
&& SkPackedArrayEqual(u.fColors, v.fColors, u.fColorCount)
&& SkPackedArrayEqual(u.fColorOffsets, v.fColorOffsets, u.fColorCount);
}
inline bool operator==(const Key& u, const Key& v) {
SkASSERT(u.fInfo.fColors == u.fColors.get());
SkASSERT(u.fInfo.fColorOffsets == u.fStops.get());
SkASSERT(v.fInfo.fColors == v.fColors.get());
SkASSERT(v.fInfo.fColorOffsets == v.fStops.get());
return u.fType == v.fType
&& u.fInfo == v.fInfo
&& u.fCanvasTransform == v.fCanvasTransform
&& u.fShaderTransform == v.fShaderTransform
&& u.fBBox == v.fBBox;
}
inline bool operator!=(const Key& u, const Key& v) { return !(u == v); }
} // namespace SkPDFGradientShader
#endif // SkPDFGradientShader_DEFINED
|