blob: ee270ea3afe4cbf3feaec6eeadef556c3921edb5 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkShader.h"
13#include "include/private/SkMacros.h"
14#include "src/pdf/SkBitmapKey.h"
15#include "src/pdf/SkPDFTypes.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,
Hal Canaryfcea9a92019-05-30 09:19:53 -040045 SkColor4f paintColor);
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000046
Hal Canaryec257682017-07-06 08:37:02 -040047SK_BEGIN_REQUIRE_DENSE
48struct SkPDFImageShaderKey {
Hal Canary27a74312019-06-05 10:53:33 -040049 SkMatrix fTransform;
Hal Canaryec257682017-07-06 08:37:02 -040050 SkIRect fBBox;
51 SkBitmapKey fBitmapKey;
Mike Reedfae8fce2019-04-03 10:27:45 -040052 SkTileMode fImageTileModes[2];
Hal Canaryfcea9a92019-05-30 09:19:53 -040053 SkColor4f 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);
Hal Canary27a74312019-06-05 10:53:33 -040060 return a.fTransform == b.fTransform
Hal Canary94fd66c2017-07-05 11:25:42 -040061 && a.fBBox == b.fBBox
62 && a.fBitmapKey == b.fBitmapKey
63 && a.fImageTileModes[0] == b.fImageTileModes[0]
Hal Canary7e872ca2017-07-19 15:51:18 -040064 && a.fImageTileModes[1] == b.fImageTileModes[1]
65 && a.fPaintColor == b.fPaintColor;
Hal Canary94fd66c2017-07-05 11:25:42 -040066}
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000067#endif