epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 The Android Open Source Project |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 10 | #ifndef SkPDFGraphicState_DEFINED |
| 11 | #define SkPDFGraphicState_DEFINED |
| 12 | |
| 13 | #include "SkPaint.h" |
| 14 | #include "SkPDFTypes.h" |
| 15 | #include "SkTemplates.h" |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 16 | #include "SkChecksum.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 17 | |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 18 | class SkPDFCanon; |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 19 | class SkPDFFormXObject; |
| 20 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 21 | /** \class SkPDFGraphicState |
| 22 | SkPaint objects roughly correspond to graphic state dictionaries that can |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 23 | 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^] | 24 | once, we want to canonicalize them. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 25 | */ |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 26 | class SkPDFGraphicState : public SkPDFObject { |
commit-bot@chromium.org | ab1c138 | 2013-12-05 12:08:12 +0000 | [diff] [blame] | 27 | SK_DECLARE_INST_COUNT(SkPDFGraphicState) |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 28 | public: |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 29 | enum SkPDFSMaskMode { |
| 30 | kAlpha_SMaskMode, |
| 31 | kLuminosity_SMaskMode |
| 32 | }; |
| 33 | |
halcanary | f361b71 | 2015-01-13 07:12:57 -0800 | [diff] [blame] | 34 | // Override emitObject so that we can populate the dictionary on |
| 35 | // demand. |
halcanary | 37c46ca | 2015-03-31 12:30:20 -0700 | [diff] [blame] | 36 | virtual void emitObject(SkWStream* stream, |
| 37 | const SkPDFObjNumMap& objNumMap, |
| 38 | const SkPDFSubstituteMap& substitutes); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 39 | |
| 40 | /** Get the graphic state for the passed SkPaint. The reference count of |
| 41 | * 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] | 42 | * unreference it when done. This is needed to accommodate the weak |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 43 | * reference pattern used when the returned object is new and has no |
| 44 | * other references. |
| 45 | * @param paint The SkPaint to emulate. |
| 46 | */ |
halcanary | 792c80f | 2015-02-20 07:21:05 -0800 | [diff] [blame] | 47 | static SkPDFGraphicState* GetGraphicStateForPaint(SkPDFCanon* canon, |
| 48 | const SkPaint& paint); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 49 | |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 50 | /** Make a graphic state that only sets the passed soft mask. The |
| 51 | * reference count of the object is incremented and it is the caller's |
| 52 | * responsibility to unreference it when done. |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 53 | * @param sMask The form xobject to use as a soft mask. |
| 54 | * @param invert Indicates if the alpha of the sMask should be inverted. |
| 55 | * @param sMaskMode Whether to use alpha or luminosity for the sMask. |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 56 | * |
| 57 | * These are not de-duped. |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 58 | */ |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 59 | static SkPDFDict* GetSMaskGraphicState(SkPDFFormXObject* sMask, |
| 60 | bool invert, |
| 61 | SkPDFSMaskMode sMaskMode); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 62 | |
| 63 | /** Get a graphic state that only unsets the soft mask. The reference |
| 64 | * count of the object is incremented and it is the caller's responsibility |
| 65 | * to unreference it when done. This is needed to accommodate the weak |
| 66 | * reference pattern used when the returned object is new and has no |
| 67 | * other references. |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 68 | * |
| 69 | * The returned object is a singleton. |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 70 | */ |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 71 | static SkPDFDict* GetNoSMaskGraphicState(); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 72 | |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 73 | bool operator==(const SkPDFGraphicState& rhs) const { |
| 74 | return 0 == memcmp(&fStrokeWidth, &rhs.fStrokeWidth, 12); |
| 75 | } |
| 76 | uint32_t hash() const { return SkChecksum::Murmur3(&fStrokeWidth, 12); } |
halcanary | e6ea244 | 2015-01-21 13:13:22 -0800 | [diff] [blame] | 77 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 78 | private: |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 79 | const SkScalar fStrokeWidth; |
| 80 | const SkScalar fStrokeMiter; |
| 81 | const uint8_t fAlpha; |
| 82 | const uint8_t fStrokeCap; // SkPaint::Cap |
| 83 | const uint8_t fStrokeJoin; // SkPaint::Join |
| 84 | const uint8_t fMode; // SkXfermode::Mode |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 85 | |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame^] | 86 | SkPDFGraphicState(const SkPaint&); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 87 | |
commit-bot@chromium.org | ab1c138 | 2013-12-05 12:08:12 +0000 | [diff] [blame] | 88 | typedef SkPDFDict INHERITED; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | #endif |