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). |
halcanary | 530ea8e | 2015-01-23 06:17:35 -0800 | [diff] [blame] | 40 | * @param rasterScale Additional scale to be applied for early |
| 41 | * rasterization. |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 42 | */ |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 43 | static sk_sp<SkPDFObject> GetPDFShader(SkPDFDocument* doc, |
| 44 | SkScalar dpi, |
| 45 | SkShader* shader, |
| 46 | const SkMatrix& matrix, |
| 47 | const SkIRect& surfaceBBox, |
| 48 | SkScalar rasterScale); |
halcanary | 1437c1e | 2016-03-13 18:30:24 -0700 | [diff] [blame] | 49 | |
| 50 | static sk_sp<SkPDFArray> MakeRangeObject(); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 51 | |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 52 | class State { |
| 53 | public: |
| 54 | SkShader::GradientType fType; |
| 55 | SkShader::GradientInfo fInfo; |
| 56 | std::unique_ptr<SkColor[]> fColors; |
| 57 | std::unique_ptr<SkScalar[]> fStops; |
| 58 | SkMatrix fCanvasTransform; |
| 59 | SkMatrix fShaderTransform; |
| 60 | SkIRect fBBox; |
halcanary | 530ea8e | 2015-01-23 06:17:35 -0800 | [diff] [blame] | 61 | |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 62 | SkBitmapKey fBitmapKey; |
| 63 | SkShader::TileMode fImageTileModes[2]; |
halcanary | 530ea8e | 2015-01-23 06:17:35 -0800 | [diff] [blame] | 64 | |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 65 | State(SkShader* shader, const SkMatrix& canvasTransform, |
| 66 | const SkIRect& bbox, SkScalar rasterScale, |
| 67 | SkBitmap* dstImage); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 68 | |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 69 | bool operator==(const State& b) const; |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 70 | |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 71 | State MakeAlphaToLuminosityState() const; |
| 72 | State MakeOpaqueState() const; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 73 | |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 74 | bool GradientHasAlpha() const; |
| 75 | |
| 76 | State(State&&) = default; |
| 77 | State& operator=(State&&) = default; |
| 78 | |
| 79 | private: |
| 80 | State(const State& other); |
| 81 | State& operator=(const State& rhs); |
| 82 | void allocateGradientInfoStorage(); |
| 83 | }; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | #endif |