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