aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFShader.h
blob: b003e34d0b49b0a873a50a4c9c48f5dc9ac1c433 (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
69
/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#ifndef SkPDFShader_DEFINED
#define SkPDFShader_DEFINED

#include "SkBitmapKey.h"
#include "SkMacros.h"
#include "SkPDFTypes.h"
#include "SkShader.h"

class SkPDFCanon;
class SkPDFDocument;
class SkMatrix;
struct SkIRect;

/** Make a PDF shader for the passed SkShader. If the SkShader is invalid in
 *  some way, returns nullptr.
 *
 *  In PDF parlance, this is a pattern, used in place of a color when the
 *  pattern color space is selected.
 *
 *  May cache the shader in the document for later re-use.  If this function is
 *  called again with an equivalent shader,  a new reference to the cached pdf
 *  shader may be returned.
 *
 *  @param doc         The parent document, must be non-null.
 *  @param shader      The SkShader to emulate.
 *  @param ctm         The current transform matrix. (PDF shaders are absolutely
 *                     positioned, relative to where the page is drawn.)
 *  @param surfceBBox  The bounding box of the drawing surface (with matrix
 *                     already applied).
 *  @param paintColor  Color+Alpha of the paint.  Color is usually ignored,
 *                     unless it is a alpha shader.
 */
sk_sp<SkPDFObject> SkPDFMakeShader(SkPDFDocument* doc,
                                  SkShader* shader,
                                  const SkMatrix& ctm,
                                  const SkIRect& surfaceBBox,
                                  SkColor paintColor);

SK_BEGIN_REQUIRE_DENSE
struct SkPDFImageShaderKey {
    SkMatrix fCanvasTransform;
    SkMatrix fShaderTransform;
    SkIRect fBBox;
    SkBitmapKey fBitmapKey;
    SkShader::TileMode fImageTileModes[2];
    SkColor fPaintColor;
};
SK_END_REQUIRE_DENSE

inline bool operator==(const SkPDFImageShaderKey& a, const SkPDFImageShaderKey& b) {
    SkASSERT(a.fBitmapKey.fID != 0);
    SkASSERT(b.fBitmapKey.fID != 0);
    return a.fCanvasTransform   == b.fCanvasTransform
        && a.fShaderTransform   == b.fShaderTransform
        && a.fBBox              == b.fBBox
        && a.fBitmapKey         == b.fBitmapKey
        && a.fImageTileModes[0] == b.fImageTileModes[0]
        && a.fImageTileModes[1] == b.fImageTileModes[1]
        && a.fPaintColor        == b.fPaintColor;
}
#endif