OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 The Android Open Source Project | 3 * Copyright 2010 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkPDFGraphicState_DEFINED | 10 #ifndef SkPDFGraphicState_DEFINED |
11 #define SkPDFGraphicState_DEFINED | 11 #define SkPDFGraphicState_DEFINED |
12 | 12 |
13 #include "SkPaint.h" | 13 #include "SkPaint.h" |
14 #include "SkPDFTypes.h" | 14 #include "SkPDFTypes.h" |
15 #include "SkTemplates.h" | 15 #include "SkTemplates.h" |
| 16 #include "SkChecksum.h" |
16 | 17 |
| 18 class SkPDFCanon; |
17 class SkPDFFormXObject; | 19 class SkPDFFormXObject; |
18 | 20 |
19 /** \class SkPDFGraphicState | 21 /** \class SkPDFGraphicState |
20 SkPaint objects roughly correspond to graphic state dictionaries that can | 22 SkPaint objects roughly correspond to graphic state dictionaries that can |
21 be installed. So that a given dictionary is only output to the pdf file | 23 be installed. So that a given dictionary is only output to the pdf file |
22 once, we want to canonicalize them. Static methods in this class manage | 24 once, we want to canonicalize them. |
23 a weakly referenced set of SkPDFGraphicState objects: when the last | |
24 reference to a SkPDFGraphicState is removed, it removes itself from the | |
25 static set of objects. | |
26 | |
27 */ | 25 */ |
28 class SkPDFGraphicState : public SkPDFDict { | 26 class SkPDFGraphicState : public SkPDFObject { |
29 SK_DECLARE_INST_COUNT(SkPDFGraphicState) | 27 SK_DECLARE_INST_COUNT(SkPDFGraphicState) |
30 public: | 28 public: |
31 enum SkPDFSMaskMode { | 29 enum SkPDFSMaskMode { |
32 kAlpha_SMaskMode, | 30 kAlpha_SMaskMode, |
33 kLuminosity_SMaskMode | 31 kLuminosity_SMaskMode |
34 }; | 32 }; |
35 | 33 |
36 virtual ~SkPDFGraphicState(); | |
37 | |
38 // Override emitObject so that we can populate the dictionary on | 34 // Override emitObject so that we can populate the dictionary on |
39 // demand. | 35 // demand. |
40 virtual void emitObject(SkWStream* stream, | 36 virtual void emitObject(SkWStream* stream, |
41 const SkPDFObjNumMap& objNumMap, | 37 const SkPDFObjNumMap& objNumMap, |
42 const SkPDFSubstituteMap& substitutes); | 38 const SkPDFSubstituteMap& substitutes); |
43 | 39 |
44 /** Get the graphic state for the passed SkPaint. The reference count of | 40 /** Get the graphic state for the passed SkPaint. The reference count of |
45 * the object is incremented and it is the caller's responsibility to | 41 * the object is incremented and it is the caller's responsibility to |
46 * unreference it when done. This is needed to accommodate the weak | 42 * unreference it when done. This is needed to accommodate the weak |
47 * reference pattern used when the returned object is new and has no | 43 * reference pattern used when the returned object is new and has no |
48 * other references. | 44 * other references. |
49 * @param paint The SkPaint to emulate. | 45 * @param paint The SkPaint to emulate. |
50 */ | 46 */ |
51 static SkPDFGraphicState* GetGraphicStateForPaint(SkPDFCanon* canon, | 47 static SkPDFGraphicState* GetGraphicStateForPaint(SkPDFCanon* canon, |
52 const SkPaint& paint); | 48 const SkPaint& paint); |
53 | 49 |
54 /** Make a graphic state that only sets the passed soft mask. The | 50 /** Make a graphic state that only sets the passed soft mask. The |
55 * reference count of the object is incremented and it is the caller's | 51 * reference count of the object is incremented and it is the caller's |
56 * responsibility to unreference it when done. | 52 * responsibility to unreference it when done. |
57 * @param sMask The form xobject to use as a soft mask. | 53 * @param sMask The form xobject to use as a soft mask. |
58 * @param invert Indicates if the alpha of the sMask should be inverted. | 54 * @param invert Indicates if the alpha of the sMask should be inverted. |
59 * @param sMaskMode Whether to use alpha or luminosity for the sMask. | 55 * @param sMaskMode Whether to use alpha or luminosity for the sMask. |
| 56 * |
| 57 * These are not de-duped. |
60 */ | 58 */ |
61 static SkPDFGraphicState* GetSMaskGraphicState(SkPDFFormXObject* sMask, | 59 static SkPDFDict* GetSMaskGraphicState(SkPDFFormXObject* sMask, |
62 bool invert, | 60 bool invert, |
63 SkPDFSMaskMode sMaskMode); | 61 SkPDFSMaskMode sMaskMode); |
64 | 62 |
65 /** Get a graphic state that only unsets the soft mask. The reference | 63 /** Get a graphic state that only unsets the soft mask. The reference |
66 * count of the object is incremented and it is the caller's responsibility | 64 * count of the object is incremented and it is the caller's responsibility |
67 * to unreference it when done. This is needed to accommodate the weak | 65 * to unreference it when done. This is needed to accommodate the weak |
68 * reference pattern used when the returned object is new and has no | 66 * reference pattern used when the returned object is new and has no |
69 * other references. | 67 * other references. |
| 68 * |
| 69 * The returned object is a singleton. |
70 */ | 70 */ |
71 static SkPDFGraphicState* GetNoSMaskGraphicState(); | 71 static SkPDFDict* GetNoSMaskGraphicState(); |
72 | 72 |
73 bool equals(const SkPaint&) const; | 73 bool operator==(const SkPDFGraphicState& rhs) const { |
74 | 74 return 0 == memcmp(&fStrokeWidth, &rhs.fStrokeWidth, 12); |
75 // Only public for SK_DECLARE_STATIC_LAZY_PTR | 75 } |
76 static SkPDFGraphicState* CreateNoSMaskGraphicState(); | 76 uint32_t hash() const { return SkChecksum::Murmur3(&fStrokeWidth, 12); } |
77 | 77 |
78 private: | 78 private: |
79 const SkPaint fPaint; | 79 const SkScalar fStrokeWidth; |
80 bool fPopulated; | 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 |
81 | 85 |
82 SkPDFGraphicState(); | 86 SkPDFGraphicState(const SkPaint&); |
83 SkPDFGraphicState(const SkPaint& paint); | |
84 | |
85 void populateDict(); | |
86 | 87 |
87 typedef SkPDFDict INHERITED; | 88 typedef SkPDFDict INHERITED; |
88 }; | 89 }; |
89 | 90 |
90 #endif | 91 #endif |
OLD | NEW |