blob: 722039569a43bc23fcae8ba2ea2c207bb85b9a22 [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"
Hal Canary50dbc092018-06-12 14:50:37 -040013#include "SkMacros.h"
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000014#include "SkPDFTypes.h"
halcanarydabd4f02016-08-03 11:16:56 -070015#include "SkShader.h"
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000016
Hal Canary4ca9fa32018-12-21 16:15:01 -050017
halcanary989da4a2016-03-21 14:33:17 -070018class SkPDFDocument;
halcanary530ea8e2015-01-23 06:17:35 -080019class SkMatrix;
halcanary530ea8e2015-01-23 06:17:35 -080020struct SkIRect;
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000021
Hal Canaryec257682017-07-06 08:37:02 -040022/** 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.)
Hal Canaryac907bd2019-01-09 14:00:49 -050036 * @param surfaceBBox The bounding box of the drawing surface (with matrix
Hal Canaryec257682017-07-06 08:37:02 -040037 * already applied).
Hal Canary7e872ca2017-07-19 15:51:18 -040038 * @param paintColor Color+Alpha of the paint. Color is usually ignored,
39 * unless it is a alpha shader.
Hal Canaryec257682017-07-06 08:37:02 -040040 */
Hal Canary9a3f5542018-12-10 19:59:07 -050041SkPDFIndirectReference SkPDFMakeShader(SkPDFDocument* doc,
42 SkShader* shader,
43 const SkMatrix& ctm,
44 const SkIRect& surfaceBBox,
45 SkColor paintColor);
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000046
Hal Canaryec257682017-07-06 08:37:02 -040047SK_BEGIN_REQUIRE_DENSE
48struct SkPDFImageShaderKey {
49 SkMatrix fCanvasTransform;
50 SkMatrix fShaderTransform;
51 SkIRect fBBox;
52 SkBitmapKey fBitmapKey;
Mike Reedfae8fce2019-04-03 10:27:45 -040053 SkTileMode fImageTileModes[2];
Hal Canary7e872ca2017-07-19 15:51:18 -040054 SkColor fPaintColor;
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000055};
Hal Canaryec257682017-07-06 08:37:02 -040056SK_END_REQUIRE_DENSE
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000057
Hal Canaryec257682017-07-06 08:37:02 -040058inline bool operator==(const SkPDFImageShaderKey& a, const SkPDFImageShaderKey& b) {
Hal Canary94fd66c2017-07-05 11:25:42 -040059 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]
Hal Canary7e872ca2017-07-19 15:51:18 -040066 && a.fImageTileModes[1] == b.fImageTileModes[1]
67 && a.fPaintColor == b.fPaintColor;
Hal Canary94fd66c2017-07-05 11:25:42 -040068}
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000069#endif