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
14class SkMatrix;
15class SkPDFDocument;
16struct SkIRect;
17
18namespace SkPDFGradientShader {
19
20SkPDFIndirectReference Make(SkPDFDocument* doc,
21 SkShader* shader,
22 const SkMatrix& matrix,
23 const SkIRect& surfaceBBox);
24
25struct 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
36struct KeyHash {
37 uint32_t operator()(const Key& k) const { return k.fHash; }
38};
39
40inline bool operator==(const SkShader::GradientInfo& u, const SkShader::GradientInfo& v) {
41 return u.fColorCount == v.fColorCount
42 && u.fPoint[0] == v.fPoint[0]
43 && u.fPoint[1] == v.fPoint[1]
44 && u.fRadius[0] == v.fRadius[0]
45 && u.fRadius[1] == v.fRadius[1]
46 && u.fTileMode == v.fTileMode
47 && u.fGradientFlags == v.fGradientFlags
48 && SkPackedArrayEqual(u.fColors, v.fColors, u.fColorCount)
49 && SkPackedArrayEqual(u.fColorOffsets, v.fColorOffsets, u.fColorCount);
50}
51
52inline bool operator==(const Key& u, const Key& v) {
53 SkASSERT(u.fInfo.fColors == u.fColors.get());
54 SkASSERT(u.fInfo.fColorOffsets == u.fStops.get());
55 SkASSERT(v.fInfo.fColors == v.fColors.get());
56 SkASSERT(v.fInfo.fColorOffsets == v.fStops.get());
57 return u.fType == v.fType
58 && u.fInfo == v.fInfo
59 && u.fCanvasTransform == v.fCanvasTransform
60 && u.fShaderTransform == v.fShaderTransform
61 && u.fBBox == v.fBBox;
62}
63inline bool operator!=(const Key& u, const Key& v) { return !(u == v); }
64
65} // namespace SkPDFGradientShader
66#endif // SkPDFGradientShader_DEFINED
67