SkPDFGraphicState.h revision bf799cd228282431e6311900dd383083f8af7164
1 2/* 3 * Copyright 2010 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 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 18class SkPDFFormXObject; 19 20/** \class SkPDFGraphicState 21 SkPaint objects roughly correspond to graphic state dictionaries that can 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 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*/ 29class SkPDFGraphicState : public SkPDFDict { 30 SK_DECLARE_INST_COUNT(SkPDFGraphicState) 31public: 32 enum SkPDFSMaskMode { 33 kAlpha_SMaskMode, 34 kLuminosity_SMaskMode 35 }; 36 37 virtual ~SkPDFGraphicState(); 38 39 // Override emitObject so that we can populate the dictionary on 40 // demand. 41 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog); 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 45 * unreference it when done. This is needed to accommodate the weak 46 * reference pattern used when the returned object is new and has no 47 * other references. 48 * @param paint The SkPaint to emulate. 49 */ 50 static SkPDFGraphicState* GetGraphicStateForPaint(const SkPaint& paint); 51 52 /** Make a graphic state that only sets the passed soft mask. The 53 * reference count of the object is incremented and it is the caller's 54 * responsibility to unreference it when done. 55 * @param sMask The form xobject to use as a soft mask. 56 * @param invert Indicates if the alpha of the sMask should be inverted. 57 * @param sMaskMode Whether to use alpha or luminosity for the sMask. 58 */ 59 static SkPDFGraphicState* GetSMaskGraphicState(SkPDFFormXObject* sMask, 60 bool invert, 61 SkPDFSMaskMode sMaskMode); 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. 68 */ 69 static SkPDFGraphicState* GetNoSMaskGraphicState(); 70 71 bool equals(const SkPaint&) const; 72 73 // Only public for SK_DECLARE_STATIC_LAZY_PTR 74 static SkPDFGraphicState* CreateNoSMaskGraphicState(); 75 76private: 77 const SkPaint fPaint; 78 bool fPopulated; 79 bool fSMask; 80 81 SkPDFGraphicState(); 82 explicit SkPDFGraphicState(const SkPaint& paint); 83 84 void populateDict(); 85 86 typedef SkPDFDict INHERITED; 87}; 88 89#endif 90