vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 The Android Open Source Project |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +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 | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 9 | #ifndef SkPDFGraphicState_DEFINED |
| 10 | #define SkPDFGraphicState_DEFINED |
| 11 | |
halcanary | fa25106 | 2016-07-29 10:13:18 -0700 | [diff] [blame] | 12 | #include "SkPDFTypes.h" |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 13 | #include "SkOpts.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 14 | |
martina.kollarova | b8d6af1 | 2016-06-29 05:12:31 -0700 | [diff] [blame] | 15 | class SkPaint; |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 16 | class SkPDFCanon; |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 17 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 18 | /** \class SkPDFGraphicState |
| 19 | SkPaint objects roughly correspond to graphic state dictionaries that can |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 20 | be installed. So that a given dictionary is only output to the pdf file |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 21 | once, we want to canonicalize them. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 22 | */ |
halcanary | 70d1554 | 2015-11-22 12:55:04 -0800 | [diff] [blame] | 23 | class SkPDFGraphicState final : public SkPDFObject { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 24 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 25 | public: |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 26 | enum SkPDFSMaskMode { |
| 27 | kAlpha_SMaskMode, |
| 28 | kLuminosity_SMaskMode |
| 29 | }; |
| 30 | |
halcanary | f361b71 | 2015-01-13 07:12:57 -0800 | [diff] [blame] | 31 | // Override emitObject so that we can populate the dictionary on |
| 32 | // demand. |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 33 | void emitObject(SkWStream* stream, |
halcanary | 530032a | 2016-08-18 14:22:52 -0700 | [diff] [blame] | 34 | const SkPDFObjNumMap& objNumMap) const override; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 35 | |
| 36 | /** Get the graphic state for the passed SkPaint. The reference count of |
| 37 | * the object is incremented and it is the caller's responsibility to |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 38 | * unreference it when done. This is needed to accommodate the weak |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 39 | * reference pattern used when the returned object is new and has no |
| 40 | * other references. |
| 41 | * @param paint The SkPaint to emulate. |
| 42 | */ |
halcanary | 792c80f | 2015-02-20 07:21:05 -0800 | [diff] [blame] | 43 | static SkPDFGraphicState* GetGraphicStateForPaint(SkPDFCanon* canon, |
| 44 | const SkPaint& paint); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 45 | |
halcanary | 1437c1e | 2016-03-13 18:30:24 -0700 | [diff] [blame] | 46 | /** Make a graphic state that only sets the passed soft mask. |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 47 | * @param sMask The form xobject to use as a soft mask. |
| 48 | * @param invert Indicates if the alpha of the sMask should be inverted. |
| 49 | * @param sMaskMode Whether to use alpha or luminosity for the sMask. |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 50 | * |
| 51 | * These are not de-duped. |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 52 | */ |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 53 | static sk_sp<SkPDFDict> GetSMaskGraphicState(sk_sp<SkPDFObject> sMask, |
halcanary | 1437c1e | 2016-03-13 18:30:24 -0700 | [diff] [blame] | 54 | bool invert, |
| 55 | SkPDFSMaskMode sMaskMode, |
| 56 | SkPDFCanon* canon); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 57 | |
halcanary | 1437c1e | 2016-03-13 18:30:24 -0700 | [diff] [blame] | 58 | /** Make a graphic state that only unsets the soft mask. */ |
| 59 | static sk_sp<SkPDFDict> MakeNoSmaskGraphicState(); |
| 60 | static sk_sp<SkPDFStream> MakeInvertFunction(); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 61 | |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 62 | bool operator==(const SkPDFGraphicState& rhs) const { |
| 63 | return 0 == memcmp(&fStrokeWidth, &rhs.fStrokeWidth, 12); |
| 64 | } |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 65 | uint32_t hash() const { return SkOpts::hash(&fStrokeWidth, 12); } |
halcanary | e6ea244 | 2015-01-21 13:13:22 -0800 | [diff] [blame] | 66 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 67 | private: |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 68 | const SkScalar fStrokeWidth; |
| 69 | const SkScalar fStrokeMiter; |
| 70 | const uint8_t fAlpha; |
| 71 | const uint8_t fStrokeCap; // SkPaint::Cap |
| 72 | const uint8_t fStrokeJoin; // SkPaint::Join |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 73 | const uint8_t fMode; // SkBlendMode |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 74 | |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 75 | SkPDFGraphicState(const SkPaint&); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 76 | |
commit-bot@chromium.org | ab1c138 | 2013-12-05 12:08:12 +0000 | [diff] [blame] | 77 | typedef SkPDFDict INHERITED; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | #endif |