Debian Codegraph @

src/pdf/SkPDFShader.h

raw
1 /*
2 * Copyright 2011 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 SkPDFShader_DEFINED
8 #define SkPDFShader_DEFINED
9
10 #include "include/core/SkColor.h"
11 #include "include/core/SkMatrix.h"
12 #include "include/core/SkRect.h"
13 #include "include/private/base/SkAssert.h"
14 #include "include/private/base/SkMacros.h"
15 #include "src/core/SkChecksum.h"
16 #include "src/pdf/SkBitmapKey.h"
17 #include "src/pdf/SkPDFTypes.h"
18
19 class SkPDFDocument;
20 class SkShader;
21 enum class SkTileMode;
22
23 /** Make a PDF shader for the passed SkShader. If the SkShader is invalid in
24 * some way, returns nullptr.
25 *
26 * In PDF parlance, this is a pattern, used in place of a color when the
27 * pattern color space is selected.
28 *
29 * May cache the shader in the document for later re-use. If this function is
30 * called again with an equivalent shader, a new reference to the cached pdf
31 * shader may be returned.
32 *
33 * @param doc The parent document, must be non-null.
34 * @param shader The SkShader to emulate.
35 * @param ctm The current transform matrix. (PDF shaders are absolutely
36 * positioned, relative to where the page is drawn.)
37 * @param surfaceBBox The bounding box of the drawing surface (with matrix
38 * already applied).
39 * @param paintColor Color+Alpha of the paint. Color is usually ignored,
40 * unless it is a alpha shader.
41 */
42 SkPDFIndirectReference SkPDFMakeShader(SkPDFDocument* doc,
43 SkShader* shader,
44 const SkMatrix& ctm,
45 const SkIRect& surfaceBBox,
46 SkColor4f paintColor);
47
48 SK_BEGIN_REQUIRE_DENSE
49 struct SkPDFImageShaderKey {
50 SkMatrix fTransform;
51 SkIRect fBBox;
52 SkBitmapKey fBitmapKey;
53 SkTileMode fImageTileModes[2];
54 SkColor4f fPaintColor;
55
56 using Hash = SkForceDirectHash<SkPDFImageShaderKey>;
57 };
58 SK_END_REQUIRE_DENSE
59
60 inline bool operator==(const SkPDFImageShaderKey& a, const SkPDFImageShaderKey& b) {
61 SkASSERT(a.fBitmapKey.fID != 0);
62 SkASSERT(b.fBitmapKey.fID != 0);
63 return a.fTransform == b.fTransform
64 && a.fBBox == b.fBBox
65 && a.fBitmapKey == b.fBitmapKey
66 && a.fImageTileModes[0] == b.fImageTileModes[0]
67 && a.fImageTileModes[1] == b.fImageTileModes[1]
68 && a.fPaintColor == b.fPaintColor;
69 }
70 #endif