vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 9 | #ifndef SkPDFShader_DEFINED |
| 10 | #define SkPDFShader_DEFINED |
| 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #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.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 16 | |
Hal Canary | 4ca9fa3 | 2018-12-21 16:15:01 -0500 | [diff] [blame] | 17 | |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 18 | class SkPDFDocument; |
halcanary | 530ea8e | 2015-01-23 06:17:35 -0800 | [diff] [blame] | 19 | class SkMatrix; |
halcanary | 530ea8e | 2015-01-23 06:17:35 -0800 | [diff] [blame] | 20 | struct SkIRect; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 21 | |
Hal Canary | ec25768 | 2017-07-06 08:37:02 -0400 | [diff] [blame] | 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.) |
Hal Canary | ac907bd | 2019-01-09 14:00:49 -0500 | [diff] [blame] | 36 | * @param surfaceBBox The bounding box of the drawing surface (with matrix |
Hal Canary | ec25768 | 2017-07-06 08:37:02 -0400 | [diff] [blame] | 37 | * already applied). |
Hal Canary | 7e872ca | 2017-07-19 15:51:18 -0400 | [diff] [blame] | 38 | * @param paintColor Color+Alpha of the paint. Color is usually ignored, |
| 39 | * unless it is a alpha shader. |
Hal Canary | ec25768 | 2017-07-06 08:37:02 -0400 | [diff] [blame] | 40 | */ |
Hal Canary | 9a3f554 | 2018-12-10 19:59:07 -0500 | [diff] [blame] | 41 | SkPDFIndirectReference SkPDFMakeShader(SkPDFDocument* doc, |
| 42 | SkShader* shader, |
| 43 | const SkMatrix& ctm, |
| 44 | const SkIRect& surfaceBBox, |
Hal Canary | fcea9a9 | 2019-05-30 09:19:53 -0400 | [diff] [blame] | 45 | SkColor4f paintColor); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 46 | |
Hal Canary | ec25768 | 2017-07-06 08:37:02 -0400 | [diff] [blame] | 47 | SK_BEGIN_REQUIRE_DENSE |
| 48 | struct SkPDFImageShaderKey { |
Hal Canary | 27a7431 | 2019-06-05 10:53:33 -0400 | [diff] [blame] | 49 | SkMatrix fTransform; |
Hal Canary | ec25768 | 2017-07-06 08:37:02 -0400 | [diff] [blame] | 50 | SkIRect fBBox; |
| 51 | SkBitmapKey fBitmapKey; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 52 | SkTileMode fImageTileModes[2]; |
Hal Canary | fcea9a9 | 2019-05-30 09:19:53 -0400 | [diff] [blame] | 53 | SkColor4f fPaintColor; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 54 | }; |
Hal Canary | ec25768 | 2017-07-06 08:37:02 -0400 | [diff] [blame] | 55 | SK_END_REQUIRE_DENSE |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 56 | |
Hal Canary | ec25768 | 2017-07-06 08:37:02 -0400 | [diff] [blame] | 57 | inline bool operator==(const SkPDFImageShaderKey& a, const SkPDFImageShaderKey& b) { |
Hal Canary | 94fd66c | 2017-07-05 11:25:42 -0400 | [diff] [blame] | 58 | SkASSERT(a.fBitmapKey.fID != 0); |
| 59 | SkASSERT(b.fBitmapKey.fID != 0); |
Hal Canary | 27a7431 | 2019-06-05 10:53:33 -0400 | [diff] [blame] | 60 | return a.fTransform == b.fTransform |
Hal Canary | 94fd66c | 2017-07-05 11:25:42 -0400 | [diff] [blame] | 61 | && a.fBBox == b.fBBox |
| 62 | && a.fBitmapKey == b.fBitmapKey |
| 63 | && a.fImageTileModes[0] == b.fImageTileModes[0] |
Hal Canary | 7e872ca | 2017-07-19 15:51:18 -0400 | [diff] [blame] | 64 | && a.fImageTileModes[1] == b.fImageTileModes[1] |
| 65 | && a.fPaintColor == b.fPaintColor; |
Hal Canary | 94fd66c | 2017-07-05 11:25:42 -0400 | [diff] [blame] | 66 | } |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 67 | #endif |