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 | |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 12 | #include "SkBitmapKey.h" |
Hal Canary | 50dbc09 | 2018-06-12 14:50:37 -0400 | [diff] [blame] | 13 | #include "SkMacros.h" |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 14 | #include "SkPDFTypes.h" |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 15 | #include "SkShader.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, |
| 45 | SkColor 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 { |
| 49 | SkMatrix fCanvasTransform; |
| 50 | SkMatrix fShaderTransform; |
| 51 | SkIRect fBBox; |
| 52 | SkBitmapKey fBitmapKey; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame^] | 53 | SkTileMode fImageTileModes[2]; |
Hal Canary | 7e872ca | 2017-07-19 15:51:18 -0400 | [diff] [blame] | 54 | SkColor fPaintColor; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 55 | }; |
Hal Canary | ec25768 | 2017-07-06 08:37:02 -0400 | [diff] [blame] | 56 | SK_END_REQUIRE_DENSE |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 57 | |
Hal Canary | ec25768 | 2017-07-06 08:37:02 -0400 | [diff] [blame] | 58 | inline bool operator==(const SkPDFImageShaderKey& a, const SkPDFImageShaderKey& b) { |
Hal Canary | 94fd66c | 2017-07-05 11:25:42 -0400 | [diff] [blame] | 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] |
Hal Canary | 7e872ca | 2017-07-19 15:51:18 -0400 | [diff] [blame] | 66 | && a.fImageTileModes[1] == b.fImageTileModes[1] |
| 67 | && a.fPaintColor == b.fPaintColor; |
Hal Canary | 94fd66c | 2017-07-05 11:25:42 -0400 | [diff] [blame] | 68 | } |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 69 | #endif |