• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkBitmapKey.h"
13 #include "SkMacros.h"
14 #include "SkPDFTypes.h"
15 #include "SkShader.h"
16 
17 
18 class SkPDFDocument;
19 class SkMatrix;
20 struct 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  */
41 SkPDFIndirectReference SkPDFMakeShader(SkPDFDocument* doc,
42                                        SkShader* shader,
43                                        const SkMatrix& ctm,
44                                        const SkIRect& surfaceBBox,
45                                        SkColor paintColor);
46 
47 SK_BEGIN_REQUIRE_DENSE
48 struct SkPDFImageShaderKey {
49     SkMatrix fCanvasTransform;
50     SkMatrix fShaderTransform;
51     SkIRect fBBox;
52     SkBitmapKey fBitmapKey;
53     SkShader::TileMode fImageTileModes[2];
54     SkColor fPaintColor;
55 };
56 SK_END_REQUIRE_DENSE
57 
58 inline bool operator==(const SkPDFImageShaderKey& a, const SkPDFImageShaderKey& b) {
59     SkASSERT(a.fBitmapKey.fID != 0);
60     SkASSERT(b.fBitmapKey.fID != 0);
61     return a.fCanvasTransform   == b.fCanvasTransform
62         && a.fShaderTransform   == b.fShaderTransform
63         && a.fBBox              == b.fBBox
64         && a.fBitmapKey         == b.fBitmapKey
65         && a.fImageTileModes[0] == b.fImageTileModes[0]
66         && a.fImageTileModes[1] == b.fImageTileModes[1]
67         && a.fPaintColor        == b.fPaintColor;
68 }
69 #endif
70