gfx/skia/trunk/src/pdf/SkPDFGraphicState.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/pdf/SkPDFGraphicState.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2010 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkPDFGraphicState_DEFINED
    1.14 +#define SkPDFGraphicState_DEFINED
    1.15 +
    1.16 +#include "SkPaint.h"
    1.17 +#include "SkPDFTypes.h"
    1.18 +#include "SkTemplates.h"
    1.19 +#include "SkThread.h"
    1.20 +
    1.21 +class SkPDFFormXObject;
    1.22 +
    1.23 +/** \class SkPDFGraphicState
    1.24 +    SkPaint objects roughly correspond to graphic state dictionaries that can
    1.25 +    be installed. So that a given dictionary is only output to the pdf file
    1.26 +    once, we want to canonicalize them. Static methods in this class manage
    1.27 +    a weakly referenced set of SkPDFGraphicState objects: when the last
    1.28 +    reference to a SkPDFGraphicState is removed, it removes itself from the
    1.29 +    static set of objects.
    1.30 +
    1.31 +*/
    1.32 +class SkPDFGraphicState : public SkPDFDict {
    1.33 +    SK_DECLARE_INST_COUNT(SkPDFGraphicState)
    1.34 +public:
    1.35 +    enum SkPDFSMaskMode {
    1.36 +        kAlpha_SMaskMode,
    1.37 +        kLuminosity_SMaskMode
    1.38 +    };
    1.39 +
    1.40 +    virtual ~SkPDFGraphicState();
    1.41 +
    1.42 +    virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
    1.43 +                              SkTSet<SkPDFObject*>* newResourceObjects);
    1.44 +
    1.45 +    // Override emitObject and getOutputSize so that we can populate
    1.46 +    // the dictionary on demand.
    1.47 +    virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
    1.48 +                            bool indirect);
    1.49 +    virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
    1.50 +
    1.51 +    /** Get the graphic state for the passed SkPaint. The reference count of
    1.52 +     *  the object is incremented and it is the caller's responsibility to
    1.53 +     *  unreference it when done. This is needed to accommodate the weak
    1.54 +     *  reference pattern used when the returned object is new and has no
    1.55 +     *  other references.
    1.56 +     *  @param paint  The SkPaint to emulate.
    1.57 +     */
    1.58 +    static SkPDFGraphicState* GetGraphicStateForPaint(const SkPaint& paint);
    1.59 +
    1.60 +    /** Make a graphic state that only sets the passed soft mask. The
    1.61 +     *  reference count of the object is incremented and it is the caller's
    1.62 +     *  responsibility to unreference it when done.
    1.63 +     *  @param sMask     The form xobject to use as a soft mask.
    1.64 +     *  @param invert    Indicates if the alpha of the sMask should be inverted.
    1.65 +     *  @param sMaskMode Whether to use alpha or luminosity for the sMask.
    1.66 +     */
    1.67 +    static SkPDFGraphicState* GetSMaskGraphicState(SkPDFFormXObject* sMask,
    1.68 +                                                   bool invert,
    1.69 +                                                   SkPDFSMaskMode sMaskMode);
    1.70 +
    1.71 +    /** Get a graphic state that only unsets the soft mask. The reference
    1.72 +     *  count of the object is incremented and it is the caller's responsibility
    1.73 +     *  to unreference it when done. This is needed to accommodate the weak
    1.74 +     *  reference pattern used when the returned object is new and has no
    1.75 +     *  other references.
    1.76 +     */
    1.77 +    static SkPDFGraphicState* GetNoSMaskGraphicState();
    1.78 +
    1.79 +private:
    1.80 +    const SkPaint fPaint;
    1.81 +    SkTDArray<SkPDFObject*> fResources;
    1.82 +    bool fPopulated;
    1.83 +    bool fSMask;
    1.84 +
    1.85 +    class GSCanonicalEntry {
    1.86 +    public:
    1.87 +        SkPDFGraphicState* fGraphicState;
    1.88 +        const SkPaint* fPaint;
    1.89 +
    1.90 +        bool operator==(const GSCanonicalEntry& b) const;
    1.91 +        explicit GSCanonicalEntry(SkPDFGraphicState* gs)
    1.92 +            : fGraphicState(gs),
    1.93 +              fPaint(&gs->fPaint) {}
    1.94 +        explicit GSCanonicalEntry(const SkPaint* paint)
    1.95 +            : fGraphicState(NULL),
    1.96 +              fPaint(paint) {}
    1.97 +    };
    1.98 +
    1.99 +    // This should be made a hash table if performance is a problem.
   1.100 +    static SkTDArray<GSCanonicalEntry>& CanonicalPaints();
   1.101 +    static SkBaseMutex& CanonicalPaintsMutex();
   1.102 +
   1.103 +    SkPDFGraphicState();
   1.104 +    explicit SkPDFGraphicState(const SkPaint& paint);
   1.105 +
   1.106 +    void populateDict();
   1.107 +
   1.108 +    static SkPDFObject* GetInvertFunction();
   1.109 +
   1.110 +    static int Find(const SkPaint& paint);
   1.111 +    typedef SkPDFDict INHERITED;
   1.112 +};
   1.113 +
   1.114 +#endif

mercurial