blob: c1a5ef30ab1b266f0624b402b8f2188e6126cf84 [file] [log] [blame]
vandebo@chromium.orgda912d62011-03-08 18:31:02 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
vandebo@chromium.orgda912d62011-03-08 18:31:02 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
vandebo@chromium.orgda912d62011-03-08 18:31:02 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
vandebo@chromium.orgda912d62011-03-08 18:31:02 +00009#ifndef SkPDFShader_DEFINED
10#define SkPDFShader_DEFINED
11
halcanarydabd4f02016-08-03 11:16:56 -070012#include "SkBitmapKey.h"
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000013#include "SkPDFTypes.h"
halcanarydabd4f02016-08-03 11:16:56 -070014#include "SkShader.h"
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000015
halcanary792c80f2015-02-20 07:21:05 -080016class SkPDFCanon;
halcanary989da4a2016-03-21 14:33:17 -070017class SkPDFDocument;
halcanary530ea8e2015-01-23 06:17:35 -080018class SkMatrix;
halcanary530ea8e2015-01-23 06:17:35 -080019struct SkIRect;
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000020
Hal Canaryec257682017-07-06 08:37:02 -040021/** Make a PDF shader for the passed SkShader. If the SkShader is invalid in
22 * some way, returns nullptr.
23 *
24 * In PDF parlance, this is a pattern, used in place of a color when the
25 * pattern color space is selected.
26 *
27 * May cache the shader in the document for later re-use. If this function is
28 * called again with an equivalent shader, a new reference to the cached pdf
29 * shader may be returned.
30 *
31 * @param doc The parent document, must be non-null.
32 * @param shader The SkShader to emulate.
33 * @param ctm The current transform matrix. (PDF shaders are absolutely
34 * positioned, relative to where the page is drawn.)
35 * @param surfceBBox The bounding box of the drawing surface (with matrix
36 * already applied).
Hal Canary7e872ca2017-07-19 15:51:18 -040037 * @param paintColor Color+Alpha of the paint. Color is usually ignored,
38 * unless it is a alpha shader.
Hal Canaryec257682017-07-06 08:37:02 -040039 */
40sk_sp<SkPDFObject> SkPDFMakeShader(SkPDFDocument* doc,
41 SkShader* shader,
42 const SkMatrix& ctm,
Hal Canary7e872ca2017-07-19 15:51:18 -040043 const SkIRect& surfaceBBox,
44 SkColor paintColor);
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000045
Hal Canaryec257682017-07-06 08:37:02 -040046SK_BEGIN_REQUIRE_DENSE
47struct SkPDFImageShaderKey {
48 SkMatrix fCanvasTransform;
49 SkMatrix fShaderTransform;
50 SkIRect fBBox;
51 SkBitmapKey fBitmapKey;
52 SkShader::TileMode fImageTileModes[2];
Hal Canary7e872ca2017-07-19 15:51:18 -040053 SkColor fPaintColor;
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000054};
Hal Canaryec257682017-07-06 08:37:02 -040055SK_END_REQUIRE_DENSE
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000056
Hal Canaryec257682017-07-06 08:37:02 -040057inline bool operator==(const SkPDFImageShaderKey& a, const SkPDFImageShaderKey& b) {
Hal Canary94fd66c2017-07-05 11:25:42 -040058 SkASSERT(a.fBitmapKey.fID != 0);
59 SkASSERT(b.fBitmapKey.fID != 0);
60 return a.fCanvasTransform == b.fCanvasTransform
61 && a.fShaderTransform == b.fShaderTransform
62 && a.fBBox == b.fBBox
63 && a.fBitmapKey == b.fBitmapKey
64 && a.fImageTileModes[0] == b.fImageTileModes[0]
Hal Canary7e872ca2017-07-19 15:51:18 -040065 && a.fImageTileModes[1] == b.fImageTileModes[1]
66 && a.fPaintColor == b.fPaintColor;
Hal Canary94fd66c2017-07-05 11:25:42 -040067}
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000068#endif