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" |
| 16 | #include "SkThread.h" |
| 17 | |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 18 | class SkPDFFormXObject; |
| 19 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 20 | /** \class SkPDFGraphicState |
| 21 | SkPaint objects roughly correspond to graphic state dictionaries that can |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 22 | be installed. So that a given dictionary is only output to the pdf file |
| 23 | once, we want to canonicalize them. Static methods in this class manage |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 24 | a weakly referenced set of SkPDFGraphicState objects: when the last |
| 25 | reference to a SkPDFGraphicState is removed, it removes itself from the |
| 26 | static set of objects. |
| 27 | |
| 28 | */ |
| 29 | class SkPDFGraphicState : public SkPDFDict { |
commit-bot@chromium.org | ab1c138 | 2013-12-05 12:08:12 +0000 | [diff] [blame] | 30 | SK_DECLARE_INST_COUNT(SkPDFGraphicState) |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 31 | public: |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 32 | enum SkPDFSMaskMode { |
| 33 | kAlpha_SMaskMode, |
| 34 | kLuminosity_SMaskMode |
| 35 | }; |
| 36 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 37 | virtual ~SkPDFGraphicState(); |
| 38 | |
halcanary | f361b71 | 2015-01-13 07:12:57 -0800 | [diff] [blame] | 39 | // Override emitObject so that we can populate the dictionary on |
| 40 | // demand. |
halcanary | 4fc48af | 2015-01-12 10:07:50 -0800 | [diff] [blame] | 41 | virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 42 | |
| 43 | /** Get the graphic state for the passed SkPaint. The reference count of |
| 44 | * 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] | 45 | * unreference it when done. This is needed to accommodate the weak |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 46 | * reference pattern used when the returned object is new and has no |
| 47 | * other references. |
| 48 | * @param paint The SkPaint to emulate. |
| 49 | */ |
halcanary | 792c80f | 2015-02-20 07:21:05 -0800 | [diff] [blame^] | 50 | static SkPDFGraphicState* GetGraphicStateForPaint(SkPDFCanon* canon, |
| 51 | const SkPaint& paint); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 52 | |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 53 | /** Make a graphic state that only sets the passed soft mask. The |
| 54 | * reference count of the object is incremented and it is the caller's |
| 55 | * responsibility to unreference it when done. |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 56 | * @param sMask The form xobject to use as a soft mask. |
| 57 | * @param invert Indicates if the alpha of the sMask should be inverted. |
| 58 | * @param sMaskMode Whether to use alpha or luminosity for the sMask. |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 59 | */ |
reed@google.com | f6c3ebd | 2011-07-20 17:20:28 +0000 | [diff] [blame] | 60 | static SkPDFGraphicState* GetSMaskGraphicState(SkPDFFormXObject* sMask, |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 61 | bool invert, |
| 62 | SkPDFSMaskMode sMaskMode); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 63 | |
| 64 | /** Get a graphic state that only unsets the soft mask. The reference |
| 65 | * count of the object is incremented and it is the caller's responsibility |
| 66 | * to unreference it when done. This is needed to accommodate the weak |
| 67 | * reference pattern used when the returned object is new and has no |
| 68 | * other references. |
| 69 | */ |
reed@google.com | f6c3ebd | 2011-07-20 17:20:28 +0000 | [diff] [blame] | 70 | static SkPDFGraphicState* GetNoSMaskGraphicState(); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 71 | |
halcanary | fb62b3d | 2015-01-21 09:59:14 -0800 | [diff] [blame] | 72 | bool equals(const SkPaint&) const; |
| 73 | |
halcanary | e6ea244 | 2015-01-21 13:13:22 -0800 | [diff] [blame] | 74 | // Only public for SK_DECLARE_STATIC_LAZY_PTR |
| 75 | static SkPDFGraphicState* CreateNoSMaskGraphicState(); |
| 76 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 77 | private: |
halcanary | 792c80f | 2015-02-20 07:21:05 -0800 | [diff] [blame^] | 78 | SkPDFCanon* const fCanon; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 79 | const SkPaint fPaint; |
| 80 | bool fPopulated; |
| 81 | |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 82 | SkPDFGraphicState(); |
halcanary | 792c80f | 2015-02-20 07:21:05 -0800 | [diff] [blame^] | 83 | SkPDFGraphicState(SkPDFCanon* canon, const SkPaint& paint); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 84 | |
| 85 | void populateDict(); |
| 86 | |
commit-bot@chromium.org | ab1c138 | 2013-12-05 12:08:12 +0000 | [diff] [blame] | 87 | typedef SkPDFDict INHERITED; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | #endif |