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" |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 13 | #include "SkPDFTypes.h" |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 14 | #include "SkShader.h" |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 15 | |
halcanary | 792c80f | 2015-02-20 07:21:05 -0800 | [diff] [blame] | 16 | class SkPDFCanon; |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 17 | class SkPDFDocument; |
halcanary | 530ea8e | 2015-01-23 06:17:35 -0800 | [diff] [blame] | 18 | class SkMatrix; |
halcanary | 530ea8e | 2015-01-23 06:17:35 -0800 | [diff] [blame] | 19 | struct SkIRect; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 20 | |
| 21 | /** \class SkPDFShader |
| 22 | |
| 23 | In PDF parlance, this is a pattern, used in place of a color when the |
| 24 | pattern color space is selected. |
| 25 | */ |
| 26 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 27 | class SkPDFShader { |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 28 | public: |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 29 | /** Get the PDF shader for the passed SkShader. If the SkShader is |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 30 | * invalid in some way, returns nullptr. The reference count of |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 31 | * the object is incremented and it is the caller's responsibility to |
| 32 | * unreference it when done. This is needed to accommodate the weak |
| 33 | * reference pattern used when the returned object is new and has no |
| 34 | * other references. |
fmalita | c3796c7 | 2015-01-13 08:06:11 -0800 | [diff] [blame] | 35 | * @param shader The SkShader to emulate. |
| 36 | * @param matrix The current transform. (PDF shaders are absolutely |
| 37 | * positioned, relative to where the page is drawn.) |
| 38 | * @param surfceBBox The bounding box of the drawing surface (with matrix |
| 39 | * already applied). |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 40 | */ |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 41 | static sk_sp<SkPDFObject> GetPDFShader(SkPDFDocument* doc, |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 42 | SkShader* shader, |
| 43 | const SkMatrix& matrix, |
Hal Canary | a062258 | 2017-06-29 18:51:35 -0400 | [diff] [blame] | 44 | const SkIRect& surfaceBBox); |
halcanary | 1437c1e | 2016-03-13 18:30:24 -0700 | [diff] [blame] | 45 | |
| 46 | static sk_sp<SkPDFArray> MakeRangeObject(); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 47 | |
Hal Canary | 94fd66c | 2017-07-05 11:25:42 -0400 | [diff] [blame^] | 48 | SK_BEGIN_REQUIRE_DENSE |
| 49 | struct State { |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 50 | SkMatrix fCanvasTransform; |
| 51 | SkMatrix fShaderTransform; |
| 52 | SkIRect fBBox; |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 53 | SkBitmapKey fBitmapKey; |
| 54 | SkShader::TileMode fImageTileModes[2]; |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 55 | }; |
Hal Canary | 94fd66c | 2017-07-05 11:25:42 -0400 | [diff] [blame^] | 56 | SK_END_REQUIRE_DENSE |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Hal Canary | 94fd66c | 2017-07-05 11:25:42 -0400 | [diff] [blame^] | 59 | inline bool operator==(const SkPDFShader::State& a, const SkPDFShader::State& b) { |
| 60 | SkASSERT(a.fBitmapKey.fID != 0); |
| 61 | SkASSERT(b.fBitmapKey.fID != 0); |
| 62 | return a.fCanvasTransform == b.fCanvasTransform |
| 63 | && a.fShaderTransform == b.fShaderTransform |
| 64 | && a.fBBox == b.fBBox |
| 65 | && a.fBitmapKey == b.fBitmapKey |
| 66 | && a.fImageTileModes[0] == b.fImageTileModes[0] |
| 67 | && a.fImageTileModes[1] == b.fImageTileModes[1]; |
| 68 | } |
| 69 | |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 70 | #endif |