code:
/*
 * Copyright (C) 2005 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SkRegion_DEFINED
#define SkRegion_DEFINED

#include "SkRect.h"

class SkPath;
class SkRgnBuilder;

namespace android {
    class Region;
}

#define SkRegion_gEmptyRunHeadPtr   ((SkRegion::RunHead*)-1)
#define SkRegion_gRectRunHeadPtr    0

/** \class SkRegion

    The SkRegion class encapsulates the geometric region used to specify
    clipping areas for drawing.
*/
class SK_API SkRegion {
public:
    typedef int32_t RunType;
    enum {
        kRunTypeSentinel = 0x7FFFFFFF
    };

    SkRegion();
    SkRegion(const SkRegion&);
    explicit SkRegion(const SkIRect&);
    ~SkRegion();

    SkRegion& operator=(const SkRegion&);

    /**
     *  Return true if the two regions are equal. i.e. The enclose exactly
     *  the same area.
     */
    friend bool operator==(const SkRegion& a, const SkRegion& b);

    /**
     *  Return true if the two regions are not equal.
     */
    friend bool operator!=(const SkRegion& a, const SkRegion& b) {
        return !(a == b);
    }

    /**
     *  Replace this region with the specified region, and return true if the
     *  resulting region is non-empty.
     */
    bool set(const SkRegion& src) {
        SkASSERT(&src);
        *this = src;
        return !this->isEmpty();
    }

    /**
     *  Swap the contents of this and the specified region. This operation
     *  is gauarenteed to never fail.
     */
    void swap(SkRegion&);

    /** Return true if this region is empty */
    bool isEmpty() const { return fRunHead == SkRegion_gEmptyRunHeadPtr; }

    /** Return true if this region is a single, non-empty rectangle */
    bool isRect() const { return fRunHead == SkRegion_gRectRunHeadPtr; }

    /** Return true if this region consists of more than 1 rectangular area */
    bool isComplex() const { return !this->isEmpty() && !this->isRect(); }

    /**
     *  Return the bounds of this region. If the region is empty, returns an
     *  empty rectangle.
     */
    const SkIRect& getBounds() const { return fBounds; }

    /**
     *  Returns true if the region is non-empty, and if so, sets the specified
     *  path to the boundary(s) of the region. If the region is empty, then
     *  this returns false, and path is left unmodified.
     */
    bool getBoundaryPath(SkPath* path) const;

    /**
     *  Set the region to be empty, and return false, since the resulting
     *  region is empty
     */
    bool setEmpty();

    /**
     *  If rect is non-empty, set this region to that rectangle and return true,
     *  otherwise set this region to empty and return false.
     */
    bool setRect(const SkIRect&);

    /**
     *  If left < right and top < bottom, set this region to that rectangle and
     *  return true, otherwise set this region to empty and return false.
     */
    bool setRect(int32_t left, int32_t top, int32_t right, int32_t bottom);

    /**
     *  Set this region to the union of an array of rects. This is generally
     *  faster than calling region.op(rect, kUnion_Op) in a loop. If count is
     *  0, then this region is set to the empty region.
     *  @return true if the resulting region is non-empty
     */
    bool setRects(const SkIRect rects[], int count);

    /**
     *  Set this region to the specified region, and return true if it is
     *  non-empty.
     */
    bool setRegion(const SkRegion&);

    /**
     *  Set this region to the area described by the path, clipped.
     *  Return true if the resulting region is non-empty.
     *  This produces a region that is identical to the pixels that would be
     *  drawn by the path (with no antialiasing) with the specified clip.
     */
    bool setPath(const SkPath&, const SkRegion& clip);

    /**
     *  Returns true if the specified rectangle has a non-empty intersection
     *  with this region.
     */
    bool intersects(const SkIRect&) const;

    /**
     *  Returns true if the specified region has a non-empty intersection
     *  with this region.
     */
    bool intersects(const SkRegion&) const;

    /**
     *  Return true if the specified x,y coordinate is inside the region.
     */
    bool contains(int32_t x, int32_t y) const;

    /**
     *  Return true if the specified rectangle is completely inside the region.
     *  This works for simple (rectangular) and complex regions, and always
     *  returns the correct result. Note: if either this region or the rectangle
     *  is empty, contains() returns false.
     */
    bool contains(const SkIRect&) const;

    /**
     *  Return true if the specified region is completely inside the region.
     *  This works for simple (rectangular) and complex regions, and always
     *  returns the correct result. Note: if either region is empty, contains()
     *  returns false.
     */
    bool contains(const SkRegion&) const;

    /**
     *  Return true if this region is a single rectangle (not complex) and the
     *  specified rectangle is contained by this region. Returning false is not
     *  a guarantee that the rectangle is not contained by this region, but
     *  return true is a guarantee that the rectangle is contained by this region.
     */
    bool quickContains(const SkIRect& r) const {
        return this->quickContains(r.fLeft, r.fTop, r.fRight, r.fBottom);
    }

    /**
     *  Return true if this region is a single rectangle (not complex) and the
     *  specified rectangle is contained by this region. Returning false is not
     *  a guarantee that the rectangle is not contained by this region, but
     *  return true is a guarantee that the rectangle is contained by this
     *  region.
     */
    bool quickContains(int32_t left, int32_t top, int32_t right,
                       int32_t bottom) const {
        SkASSERT(this->isEmpty() == fBounds.isEmpty()); // valid region

        return left < right && top < bottom &&
               fRunHead == SkRegion_gRectRunHeadPtr &&  // this->isRect()
               /* fBounds.contains(left, top, right, bottom); */
               fBounds.fLeft <= left && fBounds.fTop <= top &&
               fBounds.fRight >= right && fBounds.fBottom >= bottom;
    }

    /**
     *  Return true if this region is empty, or if the specified rectangle does
     *  not intersect the region. Returning false is not a guarantee that they
     *  intersect, but returning true is a guarantee that they do not.
     */
    bool quickReject(const SkIRect& rect) const {
        return this->isEmpty() || rect.isEmpty() ||
                !SkIRect::Intersects(fBounds, rect);
    }

    /**
     *  Return true if this region, or rgn, is empty, or if their bounds do not
     *  intersect. Returning false is not a guarantee that they intersect, but
     *  returning true is a guarantee that they do not.
     */
    bool quickReject(const SkRegion& rgn) const {
        return this->isEmpty() || rgn.isEmpty() ||
               !SkIRect::Intersects(fBounds, rgn.fBounds);
    }

    /** Translate the region by the specified (dx, dy) amount. */
    void translate(int dx, int dy) { this->translate(dx, dy, this); }

    /**
     *  Translate the region by the specified (dx, dy) amount, writing the
     *  resulting region into dst. Note: it is legal to pass this region as the
     *  dst parameter, effectively translating the region in place. If dst is
     *  null, nothing happens.
     */
    void translate(int dx, int dy, SkRegion* dst) const;

    /**
     *  The logical operations that can be performed when combining two regions.
     */
    enum Op {
        kDifference_Op, //!< subtract the op region from the first region
        kIntersect_Op,  //!< intersect the two regions
        kUnion_Op,      //!< union (inclusive-or) the two regions
        kXOR_Op,        //!< exclusive-or the two regions
        /** subtract the first region from the op region */
        kReverseDifference_Op,
        kReplace_Op     //!< replace the dst region with the op region
    };

    /**
     *  Set this region to the result of applying the Op to this region and the
     *  specified rectangle: this = (this op rect).
     *  Return true if the resulting region is non-empty.
     */
    bool op(const SkIRect& rect, Op op) { return this->op(*this, rect, op); }

    /**
     *  Set this region to the result of applying the Op to this region and the
     *  specified rectangle: this = (this op rect).
     *  Return true if the resulting region is non-empty.
     */
    bool op(int left, int top, int right, int bottom, Op op) {
        SkIRect rect;
        rect.set(left, top, right, bottom);
        return this->op(*this, rect, op);
    }

    /**
     *  Set this region to the result of applying the Op to this region and the
     *  specified region: this = (this op rgn).
     *  Return true if the resulting region is non-empty.
     */
    bool op(const SkRegion& rgn, Op op) { return this->op(*this, rgn, op); }

    /**
     *  Set this region to the result of applying the Op to the specified
     *  rectangle and region: this = (rect op rgn).
     *  Return true if the resulting region is non-empty.
     */
    bool op(const SkIRect& rect, const SkRegion& rgn, Op);

    /**
     *  Set this region to the result of applying the Op to the specified
     *  region and rectangle: this = (rgn op rect).
     *  Return true if the resulting region is non-empty.
     */
    bool op(const SkRegion& rgn, const SkIRect& rect, Op);

    /**
     *  Set this region to the result of applying the Op to the specified
     *  regions: this = (rgna op rgnb).
     *  Return true if the resulting region is non-empty.
     */
    bool op(const SkRegion& rgna, const SkRegion& rgnb, Op op);

#ifdef ANDROID
    /** Returns a new char* containing the list of rectangles in this region
     */
    char* toString();
#endif

    /**
     *  Returns the sequence of rectangles, sorted in Y and X, that make up
     *  this region.
     */
    class SK_API Iterator {
    public:
        Iterator() : fRgn(NULL), fDone(true) {}
        Iterator(const SkRegion&);
        // if we have a region, reset to it and return true, else return false
        bool rewind();
        // reset the iterator, using the new region
        void reset(const SkRegion&);
        bool done() const { return fDone; }
        void next();
        const SkIRect& rect() const { return fRect; }
        // may return null
        const SkRegion* rgn() const { return fRgn; }

    private:
        const SkRegion* fRgn;
        const RunType*  fRuns;
        SkIRect         fRect;
        bool            fDone;
    };

    /**
     *  Returns the sequence of rectangles, sorted in Y and X, that make up
     *  this region intersected with the specified clip rectangle.
     */
    class SK_API Cliperator {
    public:
        Cliperator(const SkRegion&, const SkIRect& clip);
        bool done() { return fDone; }
        void  next();
        const SkIRect& rect() const { return fRect; }

    private:
        Iterator    fIter;
        SkIRect     fClip;
        SkIRect     fRect;
        bool        fDone;
    };

    /**
     *  Returns the sequence of runs that make up this region for the specified
     *  Y scanline, clipped to the specified left and right X values.
     */
    class Spanerator {
    public:
        Spanerator(const SkRegion&, int y, int left, int right);
        bool next(int* left, int* right);

    private:
        const SkRegion::RunType* fRuns;
        int     fLeft, fRight;
        bool    fDone;
    };

    /**
     *  Write the region to the buffer, and return the number of bytes written.
     *  If buffer is NULL, it still returns the number of bytes.
     */
    uint32_t flatten(void* buffer) const;

    /**
     *  Initialized the region from the buffer, returning the number
     *  of bytes actually read.
     */
    uint32_t unflatten(const void* buffer);

    /**
     *  Returns a reference to a global empty region. Just a convenience for
     *  callers that need a const empty region.
     */
    static const SkRegion& GetEmptyRegion();

    SkDEBUGCODE(void dump() const;)
    SkDEBUGCODE(void validate() const;)
    SkDEBUGCODE(static void UnitTest();)

    // expose this to allow for regression test on complex regions
    SkDEBUGCODE(bool debugSetRuns(const RunType runs[], int count);)

private:
    enum {
        kOpCount = kReplace_Op + 1
    };

    enum {
        kRectRegionRuns = 6 // need to store a region of a rect [T B L R S S]
    };

    friend class android::Region;    // needed for marshalling efficiently
    void allocateRuns(int count); // allocate space for count runs

    struct RunHead;

    SkIRect     fBounds;
    RunHead*    fRunHead;

    void            freeRuns();
    const RunType*  getRuns(RunType tmpStorage[], int* count) const;
    bool            setRuns(RunType runs[], int count);

    int count_runtype_values(int* itop, int* ibot) const;

    static void BuildRectRuns(const SkIRect& bounds,
                              RunType runs[kRectRegionRuns]);
    // returns true if runs are just a rect
    static bool ComputeRunBounds(const RunType runs[], int count,
                                 SkIRect* bounds);

    friend struct RunHead;
    friend class Iterator;
    friend class Spanerator;
    friend class SkRgnBuilder;
    friend class SkFlatRegion;
};

#endif


code:
/* libs/corecg/SkRegionPriv.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkRegionPriv_DEFINED
#define SkRegionPriv_DEFINED

#include "SkRegion.h"
#include "SkThread.h"

#define assert_sentinel(value, isSentinel) \
    SkASSERT(((value) == SkRegion::kRunTypeSentinel) == isSentinel)

//SkDEBUGCODE(extern int32_t gRgnAllocCounter;)

struct SkRegion::RunHead {
    int32_t fRefCnt;
    int32_t fRunCount;

    static RunHead* Alloc(int count)
    {
        //SkDEBUGCODE(sk_atomic_inc(&gRgnAllocCounter);)
        //SkDEBUGF(("************** gRgnAllocCounter::alloc %d\n", gRgnAllocCounter));

        SkASSERT(count >= SkRegion::kRectRegionRuns);

        RunHead* head = (RunHead*)sk_malloc_throw(sizeof(RunHead) + count * sizeof(RunType));
        head->fRefCnt = 1;
        head->fRunCount = count;
        return head;
    }

    bool isComplex() const
    {
        return this != SkRegion_gEmptyRunHeadPtr && this != SkRegion_gRectRunHeadPtr;
    }

    SkRegion::RunType* writable_runs()
    {
        SkASSERT(this->isComplex());
        SkASSERT(fRefCnt == 1);
        return (SkRegion::RunType*)(this + 1);
    }
    const SkRegion::RunType* readonly_runs() const
    {
        SkASSERT(this->isComplex());
        return (const SkRegion::RunType*)(this + 1);
    }

    RunHead* ensureWritable()
    {
        SkASSERT(this->isComplex());

        RunHead* writable = this;
        if (fRefCnt > 1)
        {
            // We need to alloc & copy the current region before we call
            // sk_atomic_dec because it could be freed in the meantime,
            // otherwise.
            writable = Alloc(fRunCount);
            memcpy(writable->writable_runs(), this->readonly_runs(),
                   fRunCount * sizeof(RunType));

            // fRefCount might have changed since we last checked.
            // If we own the last reference at this point, we need to
            // free the memory.
            if (sk_atomic_dec(&fRefCnt) == 1)
            {
                sk_free(this);
            }
        }
        return writable;
    }
};

#endif

license: mit


code:
/*
    Copyright 2010 Google Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 */

#ifndef SkTRelay_DEFINED
#define SkTRelay_DEFINED

#include "SkRefCnt.h"

/**
 *  Similar to a weakptr in java, a Relay allows for a back-ptr to an
 *  object to be "safe", without using a hard reference-count.
 *
 *  Typically, the target creates a Relay with a pointer to itself. Whenever it
 *  wants to have another object maintain a safe-ptr to it, it gives them a
 *  Relay, which they ref()/unref(). Through the Relay each external object can
 *  retrieve a pointer to the Target. However, when the Target goes away, it
 *  clears the Relay pointer to it (relay->set(NULL)) and then unref()s the
 *  Relay. The other objects still have a ref on the Relay, but now when they
 *  call get() the receive a NULL.
 */
template <template T> class SkTRelay : public SkRefCnt {
public:
    SkTRelay(T* ptr) : fPtr(ptr) {}

    // consumers call this
    T* get() const { return fPtr; }

    // producer calls this
    void set(T* ptr) { fPtr = ptr; }

    void clear() { this->set(NULL); }

private:
    T* fPtr;
};

#endif


code:
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SkSVGAttribute_DEFINED
#define SkSVGAttribute_DEFINED

#include "SkTypes.h"

struct SkSVGAttribute {
    const char* fName;
#ifdef SK_DEBUG
    size_t fOffset;
#endif
};

#ifndef SK_OFFSETOF
#define SK_OFFSETOF(a, b) (((size_t) (&(((a*) 1)->b)))-1)
#endif

#ifdef SK_DEBUG
#define SVG_ATTRIBUTE(attr) { #attr, SK_OFFSETOF(BASE_CLASS, f_##attr) }
#define SVG_LITERAL_ATTRIBUTE(svgAttr, cAttr) { #svgAttr, SK_OFFSETOF(BASE_CLASS, cAttr) }
#else
#define SVG_ATTRIBUTE(attr) { #attr }
#define SVG_LITERAL_ATTRIBUTE(svgAttr, cAttr) { #svgAttr }
#endif

#define SVG_ADD_ATTRIBUTE(attr) \
    if (f_##attr.size() > 0) \
        parser._addAttributeLen(#attr, f_##attr.c_str(), f_##attr.size())

#define SVG_ADD_ATTRIBUTE_ALIAS(attr, alias) \
    if (f_##alias.size() > 0) \
        parser._addAttributeLen(#attr, f_##alias.c_str(), f_##alias.size())

#endif // SkSVGAttribute_DEFINED


code:
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SkSVGBase_DEFINED
#define SkSVGBase_DEFINED

#include "SkSVGAttribute.h"

class SkSVGParser;

class SkSVGBase {
public:
    virtual ~SkSVGBase();
    virtual void addAttribute(SkSVGParser& parser, int attrIndex,
        const char* attrValue, size_t attrLength);
    virtual int getAttributes(const SkSVGAttribute** attrPtr) = 0;
};

#endif // SkSVGBase_DEFINEDes(const SkSVGAttribute** attrPtr) = 0;


code:
/* libs/graphics/svg/SkSVGCircle.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGCircle_DEFINED
#define SkSVGCircle_DEFINED

#include "SkSVGElements.h"

class SkSVGCircle : public SkSVGElement {
    DECLARE_SVG_INFO(Circle);
private:
    SkString f_cx;
    SkString f_cy;
    SkString f_r;
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGCircle_DEFINED


code:
/* libs/graphics/svg/SkSVGClipPath.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGClipPath_DEFINED
#define SkSVGClipPath_DEFINED

#include "SkSVGElements.h"

class SkSVGClipPath : public SkSVGElement {
    DECLARE_SVG_INFO(ClipPath);
    virtual bool isDef();
    virtual bool isNotDef();
private:
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGClipPath_DEFINED


code:
/* libs/graphics/svg/SkSVGDefs.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGDefs_DEFINED
#define SkSVGDefs_DEFINED

#include "SkSVGGroup.h"

class SkSVGDefs : public SkSVGGroup {
    DECLARE_SVG_INFO(Defs);
    virtual bool isDef();
    virtual bool isNotDef();
private:
    typedef SkSVGGroup INHERITED;
};

#endif // SkSVGDefs_DEFINED


code:
/* libs/graphics/svg/SkSVGElements.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGElements_DEFINED
#define SkSVGElements_DEFINED

#include "SkSVGPaintState.h"
#include "SkSVGTypes.h"
#include "SkTDArray.h"

class SkSVGParser;

#define DECLARE_SVG_INFO(_type) \
public: \
    virtual ~SkSVG##_type(); \
    static const SkSVGAttribute gAttributes[]; \
    virtual int getAttributes(const SkSVGAttribute** attrPtr); \
    virtual SkSVGTypes getType() const; \
    virtual void translate(SkSVGParser& parser, bool defState); \
    typedef SkSVG##_type BASE_CLASS

#define DEFINE_SVG_INFO(_type) \
    SkSVG##_type::~SkSVG##_type() {} \
    int SkSVG##_type::getAttributes(const SkSVGAttribute** attrPtr) { \
        *attrPtr = gAttributes; \
        return SK_ARRAY_COUNT(gAttributes); \
    } \
    SkSVGTypes SkSVG##_type::getType() const { return SkSVGType_##_type; }

#define DEFINE_SVG_NO_INFO(_type) \
    SkSVG##_type::~SkSVG##_type() {} \
    int SkSVG##_type::getAttributes(const SkSVGAttribute** ) { return 0; } \
    SkSVGTypes SkSVG##_type::getType() const { return SkSVGType_##_type; }

struct SkSVGTypeName {
    const char* fName;
    SkSVGTypes fType;
};

class SkSVGElement : public SkSVGBase {
public:
    SkSVGElement();
    virtual ~SkSVGElement();
    virtual SkSVGElement* getGradient();
    virtual SkSVGTypes getType() const  = 0;
    virtual bool isDef();
    virtual bool isFlushable();
    virtual bool isGroup();
    virtual bool isNotDef();
    virtual bool onEndElement(SkSVGParser& parser);
    virtual bool onStartElement(SkSVGElement* child);
    void setIsDef();
//  void setIsNotDef();
    virtual void translate(SkSVGParser& parser, bool defState);
    virtual void write(SkSVGParser& , SkString& color);
    SkString f_id;
    SkSVGPaint fPaintState;
    SkTDArray<SkSVGElement*> fChildren;
    SkSVGElement* fParent;
    bool fIsDef;
    bool fIsNotDef;
private:
    bool isGroupParent();
};

#endif // SkSVGElements_DEFINED


code:
/* libs/graphics/svg/SkSVGEllipse.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGEllipse_DEFINED
#define SkSVGEllipse_DEFINED

#include "SkSVGElements.h"

class SkSVGEllipse : public SkSVGElement {
    DECLARE_SVG_INFO(Ellipse);
private:
    SkString f_cx;
    SkString f_cy;
    SkString f_rx;
    SkString f_ry;
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGEllipse_DEFINED


code:
/* libs/graphics/svg/SkSVGFeColorMatrix.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGFeColorMatrix_DEFINED
#define SkSVGFeColorMatrix_DEFINED

#include "SkSVGElements.h"

class SkSVGFeColorMatrix : public SkSVGElement {
    DECLARE_SVG_INFO(FeColorMatrix);
protected:
    SkString f_color_interpolation_filters;
    SkString f_result;
    SkString f_type;
    SkString f_values;
private:
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGFeColorMatrix_DEFINED


code:
/* libs/graphics/svg/SkSVGFilter.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGFilter_DEFINED
#define SkSVGFilter_DEFINED

#include "SkSVGElements.h"

class SkSVGFilter : public SkSVGElement {
    DECLARE_SVG_INFO(Filter);
protected:
    SkString f_filterUnits;
    SkString f_height;
    SkString f_width;
    SkString f_x;
    SkString f_y;
private:
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGFilter_DEFINEDRITED;


code:
/* libs/graphics/svg/SkSVGG.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGG_DEFINED
#define SkSVGG_DEFINED

#include "SkSVGGroup.h"

class SkSVGG : public SkSVGGroup {
    DECLARE_SVG_INFO(G);
private:
    typedef SkSVGGroup INHERITED;
};

#endif // SkSVGG_DEFINED


code:
/* libs/graphics/svg/SkSVGGradient.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGGradient_DEFINED
#define SkSVGGradient_DEFINED

#include "SkSVGElements.h"

class SkSVGGradient : public SkSVGElement {
public:
    SkSVGGradient();
    virtual SkSVGElement* getGradient();
    virtual bool isDef();
    virtual bool isNotDef();
    virtual void write(SkSVGParser& , SkString& color);
protected:
    void translate(SkSVGParser& , bool defState);
    void translateGradientUnits(SkString& units);
private:
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGGradient_DEFINED


code:
/* libs/graphics/svg/SkSVGGroup.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGGroup_DEFINED
#define SkSVGGroup_DEFINED

#include "SkSVGElements.h"

class SkSVGGroup : public SkSVGElement {
public:
    SkSVGGroup();
    virtual SkSVGElement* getGradient();
    virtual bool isDef();
    virtual bool isFlushable();
    virtual bool isGroup();
    virtual bool isNotDef();
    void translate(SkSVGParser& , bool defState);
private:
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGGroup_DEFINED


code:
/* libs/graphics/svg/SkSVGImage.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGImage_DEFINED
#define SkSVGImage_DEFINED

#include "SkSVGElements.h"

class SkSVGImage : public SkSVGElement {
public:
    DECLARE_SVG_INFO(Image);
private:
    void translateImage(SkSVGParser& parser);
    SkString f_height;
    SkString f_width;
    SkString f_x;
    SkString f_xlink_href;
    SkString f_y;
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGImage_DEFINED


code:
/* libs/graphics/svg/SkSVGLine.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGLine_DEFINED
#define SkSVGLine_DEFINED

#include "SkSVGElements.h"

class SkSVGLine : public SkSVGElement {
    DECLARE_SVG_INFO(Line);
private:
    SkString f_x1;
    SkString f_x2;
    SkString f_y1;
    SkString f_y2;
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGLine_DEFINED


code:
/* libs/graphics/svg/SkSVGLinearGradient.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGLinearGradient_DEFINED
#define SkSVGLinearGradient_DEFINED

#include "SkSVGGradient.h"

class SkSVGLinearGradient : public SkSVGGradient {
    DECLARE_SVG_INFO(LinearGradient);
private:
    SkString f_gradientTransform;
    SkString f_gradientUnits;
    SkString f_x1;
    SkString f_x2;
    SkString f_y1;
    SkString f_y2;
    SkString fMatrixID;
    typedef SkSVGGradient INHERITED;
};

#endif // SkSVGLinearGradient_DEFINED


code:
/* libs/graphics/svg/SkSVGMask.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGMask_DEFINED
#define SkSVGMask_DEFINED

#include "SkSVGGroup.h"

class SkSVGMask : public SkSVGGroup {
    DECLARE_SVG_INFO(Mask);
    virtual bool isDef();
    virtual bool isNotDef();
protected:
    SkString f_height;
    SkString f_maskUnits;
    SkString f_width;
    SkString f_x;
    SkString f_y;
private:
    typedef SkSVGGroup INHERITED;
};

#endif // SkSVGMask_DEFINED


code:
/* libs/graphics/svg/SkSVGMetadata.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGMetadata_DEFINED
#define SkSVGMetadata_DEFINED

#include "SkSVGElements.h"

class SkSVGMetadata : public SkSVGElement {
    DECLARE_SVG_INFO(Metadata);
    virtual bool isDef();
    virtual bool isNotDef();
private:
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGMetadata_DEFINED


code:
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SkSVGPaintState_DEFINED
#define SkSVGPaintState_DEFINED

#include "SkSVGBase.h"
#include "SkString.h"

class SkSVGPaint : public SkSVGBase {
public:
    enum Field {
        kInitial = -1,
        kClipPath,
        kClipRule,
        kEnableBackground,
        kFill,
        kFillRule,
        kFilter,
        kFontFamily,
        kFontSize,
        kLetterSpacing,
        kMask,
        kOpacity,
        kStopColor,
        kStopOpacity,
        kStroke,
        kStroke_Dasharray,
        kStroke_Linecap,
        kStroke_Linejoin,
        kStroke_Miterlimit,
        kStroke_Width,
        kStyle,
        kTransform,
        kTerminal
    };

    SkSVGPaint();
    virtual void addAttribute(SkSVGParser& parser, int attrIndex,
        const char* attrValue, size_t attrLength);
    bool flush(SkSVGParser& , bool isFlushable, bool isDef);
    virtual int getAttributes(const SkSVGAttribute** attrPtr);
    static void Push(SkSVGPaint** head, SkSVGPaint* add);
    static void Pop(SkSVGPaint** head);
    SkString* operator[](int index);
    SkString fInitial;
    SkString f_clipPath;
    SkString f_clipRule;
    SkString f_enableBackground;
    SkString f_fill;
    SkString f_fillRule;
    SkString f_filter;
    SkString f_fontFamily;
    SkString f_fontSize;
    SkString f_letterSpacing;
    SkString f_mask;
    SkString f_opacity;
    SkString f_stopColor;
    SkString f_stopOpacity;
    SkString f_stroke;
    SkString f_strokeDasharray;
    SkString f_strokeLinecap;
    SkString f_strokeLinejoin;
    SkString f_strokeMiterlimit;
    SkString f_strokeWidth;
    SkString f_style; // unused, but allows array access to the rest
    SkString f_transform;
#ifdef SK_DEBUG
    SkString fTerminal;
#endif
    SkString fTransformID;
    static SkSVGAttribute gAttributes[];
    static const int kAttributesSize;
private:
    void setSave(SkSVGParser& );
    bool writeChangedAttributes(SkSVGParser& , SkSVGPaint& , bool* changed);
    bool writeChangedElements(SkSVGParser& , SkSVGPaint& , bool* changed);
    SkSVGPaint* fNext;
    friend class SkSVGParser;
    typedef SkSVGPaint BASE_CLASS;
};

#endif // SkSVGPaintState_DEFINED


code:
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SkSVGParser_DEFINED
#define SkSVGParser_DEFINED

#include "SkMatrix.h"
#include "SkTDict.h"
#include "SkTDStack.h"
#include "SkSVGPaintState.h"
#include "SkSVGTypes.h"
#include "SkStream.h"
#include "SkString.h"
#include "SkXMLParser.h"
#include "SkXMLWriter.h"

class SkSVGBase;
class SkSVGElement;

class SkSVGParser : public SkXMLParser {
public:
    SkSVGParser(SkXMLParserError* err = NULL);
    virtual ~SkSVGParser();
    void _addAttribute(const char* attrName, const char* attrValue) {
        fXMLWriter.addAttribute(attrName, attrValue); }
    void _addAttribute(const char* attrName, SkString& attrValue) {
        fXMLWriter.addAttribute(attrName, attrValue.c_str()); }
    void _addAttributeLen(const char* attrName, const char* attrValue, size_t len) {
        fXMLWriter.addAttributeLen(attrName, attrValue, len); }
    void _endElement() { fXMLWriter.endElement(); }
    int findAttribute(SkSVGBase* , const char* attrValue, size_t len, bool isPaint);
//    const char* getFinal();
    SkTDict<SkSVGElement*>& getIDs() { return fIDs; }
    SkString& getPaintLast(SkSVGPaint::Field field);
    void _startElement(const char name[]) { fXMLWriter.startElement(name); }
    void translate(SkSVGElement*, bool isDef);
    void translateMatrix(SkString& , SkString* id);
    static void ConvertToArray(SkString& vals);
protected:
    virtual bool onAddAttribute(const char name[], const char value[]);
    bool onAddAttributeLen(const char name[], const char value[], size_t len);
    virtual bool onEndElement(const char elem[]);
    virtual bool onStartElement(const char elem[]);
    bool onStartElementLen(const char elem[], size_t len);
    virtual bool onText(const char text[], int len);
private:
    bool isStrokeAndFill(SkSVGPaint** stroke, SkSVGPaint** fill);
    static SkSVGElement* CreateElement(SkSVGTypes type, SkSVGElement* parent);
    static void Delete(SkTDArray<SkSVGElement*>& fChildren);
    static SkSVGTypes GetType(const char name[], size_t len);
    SkSVGPaint* fHead;
    SkSVGPaint fEmptyPaint;
    SkSVGPaint fLastFlush;
    SkString fLastColor;
    SkMatrix fLastTransform;
    SkTDArray<SkSVGElement*> fChildren;
    SkTDict<SkSVGElement*> fIDs;
    SkTDArray<SkSVGElement*> fParents;
    SkDynamicMemoryWStream fStream;
    SkXMLStreamWriter fXMLWriter;
    SkSVGElement*   fCurrElement;
    SkBool8 fInSVG;
    SkBool8 fSuppressPaint;
    friend class SkSVGPaint;
    friend class SkSVGGradient;
};

#endif // SkSVGParser_DEFINED


code:
/* libs/graphics/svg/SkSVGPath.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGPath_DEFINED
#define SkSVGPath_DEFINED

#include "SkSVGElements.h"

class SkSVGPath : public SkSVGElement {
    DECLARE_SVG_INFO(Path);
private:
    SkString f_d;
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGPath_DEFINED


code:
/* libs/graphics/svg/SkSVGPolygon.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGPolygon_DEFINED
#define SkSVGPolygon_DEFINED

#include "SkSVGPolyline.h"

class SkSVGPolygon : public SkSVGPolyline {
    DECLARE_SVG_INFO(Polygon);
    virtual void addAttribute(SkSVGParser& , int attrIndex,
        const char* attrValue, size_t attrLength);
private:
    typedef SkSVGPolyline INHERITED;
};

#endif // SkSVGPolygon_DEFINED


code:
/* libs/graphics/svg/SkSVGPolyline.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGPolyline_DEFINED
#define SkSVGPolyline_DEFINED

#include "SkSVGElements.h"
#include "SkString.h"

class SkSVGPolyline : public SkSVGElement {
    DECLARE_SVG_INFO(Polyline);
    virtual void addAttribute(SkSVGParser& , int attrIndex,
        const char* attrValue, size_t attrLength);
protected:
    SkString f_clipRule;
    SkString f_fillRule;
    SkString f_points;
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGPolyline_DEFINED


code:
/* libs/graphics/svg/SkSVGRadialGradient.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGRadialGradient_DEFINED
#define SkSVGRadialGradient_DEFINED

#include "SkSVGGradient.h"

class SkSVGRadialGradient : public SkSVGGradient {
    DECLARE_SVG_INFO(RadialGradient);
protected:
    SkString f_cx;
    SkString f_cy;
    SkString f_fx;
    SkString f_fy;
    SkString f_gradientTransform;
    SkString f_gradientUnits;
    SkString f_r;
    SkString fMatrixID;
private:
    typedef SkSVGGradient INHERITED;
};

#endif // SkSVGRadialGradient_DEFINED


code:
/* libs/graphics/svg/SkSVGRect.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGRect_DEFINED
#define SkSVGRect_DEFINED

#include "SkSVGElements.h"

class SkSVGRect : public SkSVGElement {
    DECLARE_SVG_INFO(Rect);
    SkSVGRect();
private:
    SkString f_height;
    SkString f_width;
    SkString f_x;
    SkString f_y;
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGRect_DEFINED


code:
/* libs/graphics/svg/SkSVGSVG.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGSVG_DEFINED
#define SkSVGSVG_DEFINED

#include "SkSVGElements.h"

class SkSVGSVG : public SkSVGElement {
    DECLARE_SVG_INFO(SVG);
    virtual bool isFlushable();
private:
    SkString f_enable_background;
    SkString f_height;
    SkString f_overflow;
    SkString f_width;
    SkString f_version;
    SkString f_viewBox;
	SkString f_x;
    SkString f_xml_space;
    SkString f_xmlns;
    SkString f_xml_xlink;
	SkString f_y;

    typedef SkSVGElement INHERITED;
};

#endif // SkSVGSVG_DEFINED


code:
/* libs/graphics/svg/SkSVGStop.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGStop_DEFINED
#define SkSVGStop_DEFINED

#include "SkSVGElements.h"

class SkSVGStop : public SkSVGElement {
    DECLARE_SVG_INFO(Stop);
private:
    SkString f_offset;
    friend class SkSVGGradient;
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGStop_DEFINED


code:
/* libs/graphics/svg/SkSVGSymbol.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGSymbol_DEFINED
#define SkSVGSymbol_DEFINED

#include "SkSVGElements.h"

class SkSVGSymbol : public SkSVGElement {
    DECLARE_SVG_INFO(Symbol);
private:
    SkString f_viewBox;
    typedef SkSVGElement INHERITED;
};

#endif // SkSVGSymbol_DEFINED


code:
/* libs/graphics/svg/SkSVGText.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGText_DEFINED
#define SkSVGText_DEFINED

#include "SkSVGElements.h"

class SkSVGText : public SkSVGElement {
    DECLARE_SVG_INFO(Text);
protected:
    SkString f_x;
    SkString f_y;
    SkString f_text;    // not an attribute
private:
    typedef SkSVGElement INHERITED;
    friend class SkSVGParser;
};

class SkSVGTspan : public SkSVGText {
    DECLARE_SVG_INFO(Tspan);
private:
    typedef SkSVGText INHERITED;
};

#endif // SkSVGText_DEFINED


code:
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SkSVGTypes_DEFINED
#define SkSVGTypes_DEFINED

enum SkSVGTypes {
    SkSVGType_Circle,
    SkSVGType_ClipPath,
    SkSVGType_Defs,
    SkSVGType_Ellipse,
    SkSVGType_FeColorMatrix,
    SkSVGType_Filter,
    SkSVGType_G,
    SkSVGType_Image,
    SkSVGType_Line,
    SkSVGType_LinearGradient,
    SkSVGType_Mask,
    SkSVGType_Metadata,
    SkSVGType_Path,
    SkSVGType_Polygon,
    SkSVGType_Polyline,
    SkSVGType_RadialGradient,
    SkSVGType_Rect,
    SkSVGType_SVG,
    SkSVGType_Stop,
    SkSVGType_Symbol,
    SkSVGType_Text,
    SkSVGType_Tspan,
	SkSVGType_Unknown,
    SkSVGType_Use
};

#endif // SkSVGTypes_DEFINED


code:
/* libs/graphics/svg/SkSVGUse.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkSVGUse_DEFINED
#define SkSVGUse_DEFINED

#include "SkSVGElements.h"

class SkSVGUse : public SkSVGElement {
    DECLARE_SVG_INFO(Use);
protected:
    SkString f_height;
    SkString f_width;
    SkString f_x;
    SkString f_xlink_href;
    SkString f_y;
private:
    typedef SkSVGElement INHERITED;
    friend class SkSVGClipPath;
};

#endif // SkSVGUse_DEFINED


code:
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SkScalar_DEFINED
#define SkScalar_DEFINED

#include "SkFixed.h"
#include "SkFloatingPoint.h"

/** \file SkScalar.h

    Types and macros for the data type SkScalar. This is the fractional numeric type
    that, depending on the compile-time flag SK_SCALAR_IS_FLOAT, may be implemented
    either as an IEEE float, or as a 16.16 SkFixed. The macros in this file are written
    to allow the calling code to manipulate SkScalar values without knowing which representation
    is in effect.
*/

#ifdef SK_SCALAR_IS_FLOAT

    /** SkScalar is our type for fractional values and coordinates. Depending on
        compile configurations, it is either represented as an IEEE float, or
        as a 16.16 fixed point integer.
    */
    typedef float   SkScalar;
    extern const uint32_t gIEEENotANumber;
    extern const uint32_t gIEEEInfinity;

    /** SK_Scalar1 is defined to be 1.0 represented as an SkScalar
    */
    #define SK_Scalar1              (1.0f)
    /** SK_Scalar1 is defined to be 1/2 represented as an SkScalar
    */
    #define SK_ScalarHalf           (0.5f)
    /** SK_ScalarInfinity is defined to be infinity as an SkScalar
    */
    #define SK_ScalarInfinity           (*(const float*)&gIEEEInfinity)
    /** SK_ScalarMax is defined to be the largest value representable as an SkScalar
    */
    #define SK_ScalarMax            (3.402823466e+38f)
    /** SK_ScalarMin is defined to be the smallest value representable as an SkScalar
    */
    #define SK_ScalarMin            (-SK_ScalarMax)
    /** SK_ScalarNaN is defined to be 'Not a Number' as an SkScalar
    */
    #define SK_ScalarNaN      (*(const float*)(const void*)&gIEEENotANumber)
    /** SkScalarIsNaN(n) returns true if argument is not a number
    */
    static inline bool SkScalarIsNaN(float x) { return x != x; }
    /** Returns true if x is not NaN and not infinite */
    static inline bool SkScalarIsFinite(float x) {
        uint32_t bits = SkFloat2Bits(x);    // need unsigned for our shifts
        int exponent = bits << 1 >> 24;
        return exponent != 0xFF;
    }
#ifdef SK_DEBUG
    /** SkIntToScalar(n) returns its integer argument as an SkScalar
     *
     * If we're compiling in DEBUG mode, and can thus afford some extra runtime
     * cycles, check to make sure that the parameter passed in has not already
     * been converted to SkScalar.  (A double conversion like this is harmless
     * for SK_SCALAR_IS_FLOAT, but for SK_SCALAR_IS_FIXED this causes trouble.)
     *
     * Note that we need all of these method signatures to properly handle the
     * various types that we pass into SkIntToScalar() to date:
     * int, size_t, U8CPU, etc., even though what we really mean is "anything
     * but a float".
     */
    static inline float SkIntToScalar(signed int param) {
        return (float)param;
    }
    static inline float SkIntToScalar(unsigned int param) {
        return (float)param;
    }
    static inline float SkIntToScalar(signed long param) {
        return (float)param;
    }
    static inline float SkIntToScalar(unsigned long param) {
        return (float)param;
    }
    static inline float SkIntToScalar(float param) {
        /* If the parameter passed into SkIntToScalar is a float,
         * one of two things has happened:
         * 1. the parameter was an SkScalar (which is typedef'd to float)
         * 2. the parameter was a float instead of an int
         *
         * Either way, it's not good.
         */
        SkASSERT(!"looks like you passed an SkScalar into SkIntToScalar");
        return (float)0;
    }
#else  // not SK_DEBUG
    /** SkIntToScalar(n) returns its integer argument as an SkScalar
    */
    #define SkIntToScalar(n)        ((float)(n))
#endif // not SK_DEBUG
    /** SkFixedToScalar(n) returns its SkFixed argument as an SkScalar
    */
    #define SkFixedToScalar(x)      SkFixedToFloat(x)
    /** SkScalarToFixed(n) returns its SkScalar argument as an SkFixed
    */
    #define SkScalarToFixed(x)      SkFloatToFixed(x)

    #define SkScalarToFloat(n)      (n)
    #define SkFloatToScalar(n)      (n)

    #define SkScalarToDouble(n)      (double)(n)
    #define SkDoubleToScalar(n)      (float)(n)

    /** SkScalarFraction(x) returns the signed fractional part of the argument
    */
    #define SkScalarFraction(x)     sk_float_mod(x, 1.0f)
    /** Rounds the SkScalar to the nearest integer value
    */
    #define SkScalarRound(x)        sk_float_round2int(x)
    /** Returns the smallest integer that is >= the specified SkScalar
    */
    #define SkScalarCeil(x)         sk_float_ceil2int(x)
    /** Returns the largest integer that is <= the specified SkScalar
    */
    #define SkScalarFloor(x)        sk_float_floor2int(x)
    /** Returns the absolute value of the specified SkScalar
    */
    #define SkScalarAbs(x)          sk_float_abs(x)
    /** Return x with the sign of y
     */
    #define SkScalarCopySign(x, y)  sk_float_copysign(x, y)
    /** Returns the value pinned between 0 and max inclusive
    */
    inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) {
        return x < 0 ? 0 : x > max ? max : x;
    }
    /** Returns the value pinned between min and max inclusive
    */
    inline SkScalar SkScalarPin(SkScalar x, SkScalar min, SkScalar max) {
        return x < min ? min : x > max ? max : x;
    }
    /** Returns the specified SkScalar squared (x*x)
    */
    inline SkScalar SkScalarSquare(SkScalar x) { return x * x; }
    /** Returns the product of two SkScalars
    */
    #define SkScalarMul(a, b)       ((float)(a) * (b))
    /** Returns the product of two SkScalars plus a third SkScalar
    */
    #define SkScalarMulAdd(a, b, c) ((float)(a) * (b) + (c))
    /** Returns the product of a SkScalar and an int rounded to the nearest integer value
    */
    #define SkScalarMulRound(a, b) SkScalarRound((float)(a) * (b))
    /** Returns the product of a SkScalar and an int promoted to the next larger int
    */
    #define SkScalarMulCeil(a, b) SkScalarCeil((float)(a) * (b))
    /** Returns the product of a SkScalar and an int truncated to the next smaller int
    */
    #define SkScalarMulFloor(a, b) SkScalarFloor((float)(a) * (b))
    /** Returns the quotient of two SkScalars (a/b)
    */
    #define SkScalarDiv(a, b)       ((float)(a) / (b))
    /** Returns the mod of two SkScalars (a mod b)
    */
    #define SkScalarMod(x,y)        sk_float_mod(x,y)
    /** Returns the product of the first two arguments, divided by the third argument
    */
    #define SkScalarMulDiv(a, b, c) ((float)(a) * (b) / (c))
    /** Returns the multiplicative inverse of the SkScalar (1/x)
    */
    #define SkScalarInvert(x)       (SK_Scalar1 / (x))
    #define SkScalarFastInvert(x)   (SK_Scalar1 / (x))
    /** Returns the square root of the SkScalar
    */
    #define SkScalarSqrt(x)         sk_float_sqrt(x)
    /** Returns the average of two SkScalars (a+b)/2
    */
    #define SkScalarAve(a, b)       (((a) + (b)) * 0.5f)
    /** Returns the geometric mean of two SkScalars
    */
    #define SkScalarMean(a, b)      sk_float_sqrt((float)(a) * (b))
    /** Returns one half of the specified SkScalar
    */
    #define SkScalarHalf(a)         ((a) * 0.5f)

    #define SK_ScalarSqrt2          1.41421356f
    #define SK_ScalarPI             3.14159265f
    #define SK_ScalarTanPIOver8     0.414213562f
    #define SK_ScalarRoot2Over2     0.707106781f

    #define SkDegreesToRadians(degrees) ((degrees) * (SK_ScalarPI / 180))
    float SkScalarSinCos(SkScalar radians, SkScalar* cosValue);
    #define SkScalarSin(radians)    (float)sk_float_sin(radians)
    #define SkScalarCos(radians)    (float)sk_float_cos(radians)
    #define SkScalarTan(radians)    (float)sk_float_tan(radians)
    #define SkScalarASin(val)   (float)sk_float_asin(val)
    #define SkScalarACos(val)   (float)sk_float_acos(val)
    #define SkScalarATan2(y, x) (float)sk_float_atan2(y,x)
    #define SkScalarExp(x)  (float)sk_float_exp(x)
    #define SkScalarLog(x)  (float)sk_float_log(x)

    inline SkScalar SkMaxScalar(SkScalar a, SkScalar b) { return a > b ? a : b; }
    inline SkScalar SkMinScalar(SkScalar a, SkScalar b) { return a < b ? a : b; }

    static inline bool SkScalarIsInt(SkScalar x) {
        return x == (float)(int)x;
    }
#else
    typedef SkFixed SkScalar;

    #define SK_Scalar1              SK_Fixed1
    #define SK_ScalarHalf           SK_FixedHalf
    #define SK_ScalarInfinity   SK_FixedMax
    #define SK_ScalarMax            SK_FixedMax
    #define SK_ScalarMin            SK_FixedMin
    #define SK_ScalarNaN            SK_FixedNaN
    #define SkScalarIsNaN(x)        ((x) == SK_FixedNaN)
    #define SkScalarIsFinite(x)     ((x) != SK_FixedNaN)

    #define SkIntToScalar(n)        SkIntToFixed(n)
    #define SkFixedToScalar(x)      (x)
    #define SkScalarToFixed(x)      (x)
    #ifdef SK_CAN_USE_FLOAT
        #define SkScalarToFloat(n)  SkFixedToFloat(n)
        #define SkFloatToScalar(n)  SkFloatToFixed(n)

        #define SkScalarToDouble(n) SkFixedToDouble(n)
        #define SkDoubleToScalar(n) SkDoubleToFixed(n)
    #endif
    #define SkScalarFraction(x)     SkFixedFraction(x)
    #define SkScalarRound(x)        SkFixedRound(x)
    #define SkScalarCeil(x)         SkFixedCeil(x)
    #define SkScalarFloor(x)        SkFixedFloor(x)
    #define SkScalarAbs(x)          SkFixedAbs(x)
    #define SkScalarCopySign(x, y)  SkCopySign32(x, y)
    #define SkScalarClampMax(x, max) SkClampMax(x, max)
    #define SkScalarPin(x, min, max) SkPin32(x, min, max)
    #define SkScalarSquare(x)       SkFixedSquare(x)
    #define SkScalarMul(a, b)       SkFixedMul(a, b)
    #define SkScalarMulAdd(a, b, c) SkFixedMulAdd(a, b, c)
    #define SkScalarMulRound(a, b)  SkFixedMulCommon(a, b, SK_FixedHalf)
    #define SkScalarMulCeil(a, b)   SkFixedMulCommon(a, b, SK_Fixed1 - 1)
    #define SkScalarMulFloor(a, b)  SkFixedMulCommon(a, b, 0)
    #define SkScalarDiv(a, b)       SkFixedDiv(a, b)
    #define SkScalarMod(a, b)       SkFixedMod(a, b)
    #define SkScalarMulDiv(a, b, c) SkMulDiv(a, b, c)
    #define SkScalarInvert(x)       SkFixedInvert(x)
    #define SkScalarFastInvert(x)   SkFixedFastInvert(x)
    #define SkScalarSqrt(x)         SkFixedSqrt(x)
    #define SkScalarAve(a, b)       SkFixedAve(a, b)
    #define SkScalarMean(a, b)      SkFixedMean(a, b)
    #define SkScalarHalf(a)         ((a) >> 1)

    #define SK_ScalarSqrt2          SK_FixedSqrt2
    #define SK_ScalarPI             SK_FixedPI
    #define SK_ScalarTanPIOver8     SK_FixedTanPIOver8
    #define SK_ScalarRoot2Over2     SK_FixedRoot2Over2

    #define SkDegreesToRadians(degrees)     SkFractMul(degrees, SK_FractPIOver180)
    #define SkScalarSinCos(radians, cosPtr) SkFixedSinCos(radians, cosPtr)
    #define SkScalarSin(radians)    SkFixedSin(radians)
    #define SkScalarCos(radians)    SkFixedCos(radians)
    #define SkScalarTan(val)        SkFixedTan(val)
    #define SkScalarASin(val)       SkFixedASin(val)
    #define SkScalarACos(val)       SkFixedACos(val)
    #define SkScalarATan2(y, x)     SkFixedATan2(y,x)
    #define SkScalarExp(x)          SkFixedExp(x)
    #define SkScalarLog(x)          SkFixedLog(x)

    #define SkMaxScalar(a, b)       SkMax32(a, b)
    #define SkMinScalar(a, b)       SkMin32(a, b)

    static inline bool SkScalarIsInt(SkFixed x) {
        return 0 == (x & 0xffff);
    }
#endif

#define SK_ScalarNearlyZero         (SK_Scalar1 / (1 << 12))

/*  <= is slower than < for floats, so we use < for our tolerance test
*/

static inline bool SkScalarNearlyZero(SkScalar x,
                                    SkScalar tolerance = SK_ScalarNearlyZero) {
    SkASSERT(tolerance > 0);
    return SkScalarAbs(x) < tolerance;
}

static inline bool SkScalarNearlyEqual(SkScalar x, SkScalar y,
                                     SkScalar tolerance = SK_ScalarNearlyZero) {
    SkASSERT(tolerance > 0);
    return SkScalarAbs(x-y) < tolerance;
}

/** Linearly interpolate between A and B, based on t.
    If t is 0, return A
    If t is 1, return B
    else interpolate.
    t must be [0..SK_Scalar1]
*/
static inline SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t) {
    SkASSERT(t >= 0 && t <= SK_Scalar1);
    return A + SkScalarMul(B - A, t);
}

/** Interpolate along the function described by (keys[length], values[length])
    for the passed searchKey.  SearchKeys outside the range keys[0]-keys[Length]
    clamp to the min or max value.  This function was inspired by a desire
    to change the multiplier for thickness in fakeBold; therefore it assumes
    the number of pairs (length) will be small, and a linear search is used.
    Repeated keys are allowed for discontinuous functions (so long as keys is
    monotonically increasing), and if key is the value of a repeated scalar in
    keys, the first one will be used.  However, that may change if a binary
    search is used.
*/
SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[],
                            const SkScalar values[], int length);

#endif


code:
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SkScalarCompare_DEFINED
#define SkScalarCompare_DEFINED

#include "SkFloatBits.h"
#include "SkRect.h"

/** Skia can spend a lot of time just comparing scalars (e.g. quickReject).
    When scalar==fixed, this is very fast, and when scalar==hardware-float, this
    is also reasonable, but if scalar==software-float, then each compare can be
    a function call and take real time. To account for that, we have the flag
    SK_SCALAR_SLOW_COMPARES.

    If this is defined, we have a special trick where we quickly convert floats
    to a 2's compliment form, and then treat them as signed 32bit integers. In
    this form we lose a few subtlties (e.g. NaNs always comparing false) but
    we gain the speed of integer compares.
 */

#ifdef SK_SCALAR_SLOW_COMPARES
    typedef int32_t SkScalarCompareType;
    typedef SkIRect SkRectCompareType;
    #define SkScalarToCompareType(x)    SkScalarAs2sCompliment(x)
#else
    typedef SkScalar SkScalarCompareType;
    typedef SkRect SkRectCompareType;
    #define SkScalarToCompareType(x)    (x)
#endif

#endif


code:
#ifndef SkScaledBitmapSampler_DEFINED
#define SkScaledBitmapSampler_DEFINED

#include "SkTypes.h"
#include "SkColor.h"

class SkBitmap;

class SkScaledBitmapSampler {
public:
    SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize);

    int scaledWidth() const { return fScaledWidth; }
    int scaledHeight() const { return fScaledHeight; }

    int srcY0() const { return fY0; }
    int srcDY() const { return fDY; }

    enum SrcConfig {
        kGray,  // 1 byte per pixel
        kIndex, // 1 byte per pixel
        kRGB,   // 3 bytes per pixel
        kRGBX,  // 4 byes per pixel (ignore 4th)
        kRGBA,  // 4 bytes per pixel
        kRGB_565 // 2 bytes per pixel
    };

    // Given a dst bitmap (with pixels already allocated) and a src-config,
    // prepares iterator to process the src colors and write them into dst.
    // Returns false if the request cannot be fulfulled.
    bool begin(SkBitmap* dst, SrcConfig sc, bool doDither,
               const SkPMColor* = NULL);
    // call with row of src pixels, for y = 0...scaledHeight-1.
    // returns true if the row had non-opaque alpha in it
    bool next(const uint8_t* SK_RESTRICT src);

private:
    int fScaledWidth;
    int fScaledHeight;

    int fX0;    // first X coord to sample
    int fY0;    // first Y coord (scanline) to sample
    int fDX;    // step between X samples
    int fDY;    // step between Y samples

    typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
                            const uint8_t* SK_RESTRICT src,
                            int width, int deltaSrc, int y,
                            const SkPMColor[]);

    // setup state
    char*   fDstRow; // points into bitmap's pixels
    int     fDstRowBytes;
    int     fCurrY; // used for dithering
    int     fSrcPixelSize;  // 1, 3, 4
    RowProc fRowProc;

    // optional reference to the src colors if the src is a palette model
    const SkPMColor* fCTable;
};

#endif


code:
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SkScalerContext_DEFINED
#define SkScalerContext_DEFINED

#include "SkMask.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkPoint.h"

class SkDescriptor;
class SkMaskFilter;
class SkPathEffect;
class SkRasterizer;

// needs to be != to any valid SkMask::Format
#define MASK_FORMAT_UNKNOWN         (0xFF)
#define MASK_FORMAT_JUST_ADVANCE    MASK_FORMAT_UNKNOWN

#define kMaxGlyphWidth (1<<13)

struct SkGlyph {
    void*       fImage;
    SkPath*     fPath;
    SkFixed     fAdvanceX, fAdvanceY;

    uint32_t    fID;
    uint16_t    fWidth, fHeight;
    int16_t     fTop, fLeft;

    uint8_t     fMaskFormat;
    int8_t      fRsbDelta, fLsbDelta;  // used by auto-kerning

    void init(uint32_t id) {
        fID             = id;
        fImage          = NULL;
        fPath           = NULL;
        fMaskFormat     = MASK_FORMAT_UNKNOWN;
    }

    /**
     *  Compute the rowbytes for the specified width and mask-format.
     */
    static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) {
        unsigned rb = width;
        if (SkMask::kBW_Format == format) {
            rb = (rb + 7) >> 3;
		} else if (SkMask::kARGB32_Format == format ||
                   SkMask::kLCD32_Format == format)
        {
			rb <<= 2;
		} else if (SkMask::kLCD16_Format == format) {
			rb = SkAlign4(rb << 1);
        } else {
            rb = SkAlign4(rb);
        }
        return rb;
    }

    unsigned rowBytes() const {
        return ComputeRowBytes(fWidth, (SkMask::Format)fMaskFormat);
    }

    bool isJustAdvance() const {
        return MASK_FORMAT_JUST_ADVANCE == fMaskFormat;
    }

    bool isFullMetrics() const {
        return MASK_FORMAT_JUST_ADVANCE != fMaskFormat;
    }

    uint16_t getGlyphID() const {
        return ID2Code(fID);
    }

    unsigned getGlyphID(unsigned baseGlyphCount) const {
        unsigned code = ID2Code(fID);
        SkASSERT(code >= baseGlyphCount);
        return code - baseGlyphCount;
    }

    unsigned getSubX() const {
        return ID2SubX(fID);
    }

    SkFixed getSubXFixed() const {
        return SubToFixed(ID2SubX(fID));
    }

    SkFixed getSubYFixed() const {
        return SubToFixed(ID2SubY(fID));
    }

    size_t computeImageSize() const;

    /** Call this to set all of the metrics fields to 0 (e.g. if the scaler
        encounters an error measuring a glyph). Note: this does not alter the
        fImage, fPath, fID, fMaskFormat fields.
     */
    void zeroMetrics();

    enum {
        kSubBits = 2,
        kSubMask = ((1 << kSubBits) - 1),
        kSubShift = 24, // must be large enough for glyphs and unichars
        kCodeMask = ((1 << kSubShift) - 1),
        // relative offsets for X and Y subpixel bits
        kSubShiftX = kSubBits,
        kSubShiftY = 0
    };

    static unsigned ID2Code(uint32_t id) {
        return id & kCodeMask;
    }

    static unsigned ID2SubX(uint32_t id) {
        return id >> (kSubShift + kSubShiftX);
    }

    static unsigned ID2SubY(uint32_t id) {
        return (id >> (kSubShift + kSubShiftY)) & kSubMask;
    }

    static unsigned FixedToSub(SkFixed n) {
        return (n >> (16 - kSubBits)) & kSubMask;
    }

    static SkFixed SubToFixed(unsigned sub) {
        SkASSERT(sub <= kSubMask);
        return sub << (16 - kSubBits);
    }

    static uint32_t MakeID(unsigned code) {
        return code;
    }

    static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) {
        SkASSERT(code <= kCodeMask);
        x = FixedToSub(x);
        y = FixedToSub(y);
        return (x << (kSubShift + kSubShiftX)) |
               (y << (kSubShift + kSubShiftY)) |
               code;
    }

    void toMask(SkMask* mask) const;
};

class SkScalerContext {
public:
    enum Flags {
        kFrameAndFill_Flag  = 0x01,
        kDevKernText_Flag   = 0x02,
        kGammaForBlack_Flag = 0x04, // illegal to set both Gamma flags
        kGammaForWhite_Flag = 0x08, // illegal to set both Gamma flags
        // together, these two flags resulting in a two bit value which matches
        // up with the SkPaint::Hinting enum.
        kHintingBit1_Flag   = 0x10,
        kHintingBit2_Flag   = 0x20,
        kEmbeddedBitmapText_Flag = 0x40,
        kEmbolden_Flag      = 0x80,
        kSubpixelPositioning_Flag = 0x100,
        kAutohinting_Flag   = 0x200,

        // these should only ever be set if fMaskFormat is LCD16 or LCD32
        kLCD_Vertical_Flag  = 0x400,    // else Horizontal
        kLCD_BGROrder_Flag  = 0x800,    // else RGB order
    };
private:
    enum {
        kHintingMask = kHintingBit1_Flag | kHintingBit2_Flag
    };
public:
    struct Rec {
        uint32_t    fOrigFontID;
        uint32_t    fFontID;
        SkScalar    fTextSize, fPreScaleX, fPreSkewX;
        SkScalar    fPost2x2[2][2];
        SkScalar    fFrameWidth, fMiterLimit;
        uint8_t     fMaskFormat;
        uint8_t     fStrokeJoin;
        uint16_t    fFlags;
        // Warning: when adding members note that the size of this structure
        // must be a multiple of 4. SkDescriptor requires that its arguments be
        // multiples of four and this structure is put in an SkDescriptor in
        // SkPaint::MakeRec.

        void    getMatrixFrom2x2(SkMatrix*) const;
        void    getLocalMatrix(SkMatrix*) const;
        void    getSingleMatrix(SkMatrix*) const;

        SkPaint::Hinting getHinting() const {
            return static_cast<SkPaint::Hinting>((fFlags & kHintingMask) >> 4);
        }

        void setHinting(SkPaint::Hinting hinting) {
            fFlags = (fFlags & ~kHintingMask) | (hinting << 4);
        }

        SkMask::Format getFormat() const {
            return static_cast<SkMask::Format>(fMaskFormat);
        }
    };

    SkScalerContext(const SkDescriptor* desc);
    virtual ~SkScalerContext();

    SkMask::Format getMaskFormat() const {
        return (SkMask::Format)fRec.fMaskFormat;
    }

    // remember our glyph offset/base
    void setBaseGlyphCount(unsigned baseGlyphCount) {
        fBaseGlyphCount = baseGlyphCount;
    }

    /** Return the corresponding glyph for the specified unichar. Since contexts
        may be chained (under the hood), the glyphID that is returned may in
        fact correspond to a different font/context. In that case, we use the
        base-glyph-count to know how to translate back into local glyph space.
     */
    uint16_t    charToGlyphID(SkUnichar uni);

    /** Map the glyphID to its glyph index, and then to its char code. Unmapped
        glyphs return zero.
    */
    SkUnichar glyphIDToChar(uint16_t glyphID);

    unsigned    getGlyphCount() { return this->generateGlyphCount(); }
    void        getAdvance(SkGlyph*);
    void        getMetrics(SkGlyph*);
    void        getImage(const SkGlyph&);
    void        getPath(const SkGlyph&, SkPath*);
    void        getFontMetrics(SkPaint::FontMetrics* mX,
                               SkPaint::FontMetrics* mY);

    static inline void MakeRec(const SkPaint&, const SkMatrix*, Rec* rec);
    static SkScalerContext* Create(const SkDescriptor*);

protected:
    Rec         fRec;
    unsigned    fBaseGlyphCount;

    virtual unsigned generateGlyphCount() = 0;
    virtual uint16_t generateCharToGlyph(SkUnichar) = 0;
    virtual void generateAdvance(SkGlyph*) = 0;
    virtual void generateMetrics(SkGlyph*) = 0;
    virtual void generateImage(const SkGlyph&) = 0;
    virtual void generatePath(const SkGlyph&, SkPath*) = 0;
    virtual void generateFontMetrics(SkPaint::FontMetrics* mX,
                                     SkPaint::FontMetrics* mY) = 0;
    // default impl returns 0, indicating failure.
    virtual SkUnichar generateGlyphToChar(uint16_t);

private:
    SkPathEffect*   fPathEffect;
    SkMaskFilter*   fMaskFilter;
    SkRasterizer*   fRasterizer;
    SkScalar        fDevFrameWidth;

    void internalGetPath(const SkGlyph& glyph, SkPath* fillPath,
                         SkPath* devPath, SkMatrix* fillToDevMatrix);

    // return the next context, treating fNextContext as a cache of the answer
    SkScalerContext* getNextContext();

    // returns the right context from our link-list for this glyph. If no match
    // is found, just returns the original context (this)
    SkScalerContext* getGlyphContext(const SkGlyph& glyph);

    // link-list of context, to handle missing chars. null-terminated.
    SkScalerContext* fNextContext;
};

#define kRec_SkDescriptorTag            SkSetFourByteTag('s', 'r', 'e', 'c')
#define kPathEffect_SkDescriptorTag     SkSetFourByteTag('p', 't', 'h', 'e')
#define kMaskFilter_SkDescriptorTag     SkSetFourByteTag('m', 's', 'k', 'f')
#define kRasterizer_SkDescriptorTag     SkSetFourByteTag('r', 'a', 's', 't')

#endif


code:
/* libs/graphics/sgl/SkScan.h
**
** Copyright 2011, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkScan_DEFINED
#define SkScan_DEFINED

#include "SkRect.h"

class SkRegion;
class SkBlitter;
class SkPath;

/** Defines a fixed-point rectangle, identical to the integer SkIRect, but its
    coordinates are treated as SkFixed rather than int32_t.
*/
typedef SkIRect SkXRect;

class SkScan {
public:
    static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
    static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);

#ifdef SK_SCALAR_IS_FIXED
    static void FillRect(const SkRect& rect, const SkRegion* clip,
                         SkBlitter* blitter) {
        SkScan::FillXRect(*(const SkXRect*)&rect, clip, blitter);
    }
#else
    static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
#endif
    static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);

    static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
    static void FillTriangle(const SkPoint& a, const SkPoint& b,
                             const SkPoint& c, const SkRegion* clip,
                             SkBlitter* blitter) {
        SkPoint pts[3];
        pts[0] = a;
        pts[1] = b;
        pts[2] = c;
        FillTriangle(pts, clip, blitter);
    }

    static void HairLine(const SkPoint&, const SkPoint&, const SkRegion*,
                         SkBlitter*);
    static void HairRect(const SkRect&, const SkRegion* clip, SkBlitter*);
    static void HairPath(const SkPath&, const SkRegion* clip, SkBlitter*);

    static void AntiFillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
#ifdef SK_SCALAR_IS_FIXED
    static void AntiFillRect(const SkRect& rect, const SkRegion* clip,
                         SkBlitter* blitter) {
        SkScan::AntiFillXRect(*(const SkXRect*)&rect, clip, blitter);
    }
#else
    static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
#endif

    static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*);

    static void AntiHairLine(const SkPoint&, const SkPoint&, const SkRegion*,
                             SkBlitter*);
    static void AntiHairRect(const SkRect&, const SkRegion* clip, SkBlitter*);
    static void AntiHairPath(const SkPath&, const SkRegion* clip, SkBlitter*);

    // draws with a miter-join
    static void FrameRect(const SkRect&, const SkPoint& strokeSize,
                          const SkRegion*, SkBlitter*);
    static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
                              const SkRegion*, SkBlitter*);
};

/** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
    from int to SkFixed. Does not check for overflow if the src coordinates
    exceed 32K
*/
static inline void XRect_set(SkXRect* xr, const SkIRect& src) {
    xr->fLeft = SkIntToFixed(src.fLeft);
    xr->fTop = SkIntToFixed(src.fTop);
    xr->fRight = SkIntToFixed(src.fRight);
    xr->fBottom = SkIntToFixed(src.fBottom);
}

/** Assign an SkXRect from a SkRect, by promoting the src rect's coordinates
    from SkScalar to SkFixed. Does not check for overflow if the src coordinates
    exceed 32K
*/
static inline void XRect_set(SkXRect* xr, const SkRect& src) {
    xr->fLeft = SkScalarToFixed(src.fLeft);
    xr->fTop = SkScalarToFixed(src.fTop);
    xr->fRight = SkScalarToFixed(src.fRight);
    xr->fBottom = SkScalarToFixed(src.fBottom);
}

/** Round the SkXRect coordinates, and store the result in the SkIRect.
*/
static inline void XRect_round(const SkXRect& xr, SkIRect* dst) {
    dst->fLeft = SkFixedRound(xr.fLeft);
    dst->fTop = SkFixedRound(xr.fTop);
    dst->fRight = SkFixedRound(xr.fRight);
    dst->fBottom = SkFixedRound(xr.fBottom);
}

/** Round the SkXRect coordinates out (i.e. use floor for left/top, and ceiling
    for right/bottom), and store the result in the SkIRect.
*/
static inline void XRect_roundOut(const SkXRect& xr, SkIRect* dst) {
    dst->fLeft = SkFixedFloor(xr.fLeft);
    dst->fTop = SkFixedFloor(xr.fTop);
    dst->fRight = SkFixedCeil(xr.fRight);
    dst->fBottom = SkFixedCeil(xr.fBottom);
}

#endif


code:
/* libs/graphics/sgl/SkScanPriv.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkScanPriv_DEFINED
#define SkScanPriv_DEFINED

#include "SkScan.h"
#include "SkBlitter.h"

class SkScanClipper {
public:
    SkScanClipper(SkBlitter* blitter, const SkRegion* clip, const SkIRect& bounds);

    SkBlitter*      getBlitter() const { return fBlitter; }
    const SkIRect*  getClipRect() const { return fClipRect; }

private:
    SkRectClipBlitter   fRectBlitter;
    SkRgnClipBlitter    fRgnBlitter;
    SkBlitter*          fBlitter;
    const SkIRect*      fClipRect;
};

// clipRect == null means path is entirely inside the clip
void sk_fill_path(const SkPath& path, const SkIRect* clipRect,
                  SkBlitter* blitter, int start_y, int stop_y, int shiftEdgesUp,
                  const SkRegion& clipRgn);

// blit the rects above and below avoid, clipped to clip
void sk_blit_above(SkBlitter*, const SkIRect& avoid, const SkRegion& clip);
void sk_blit_below(SkBlitter*, const SkIRect& avoid, const SkRegion& clip);

#endif


code:
/* libs/graphics/animator/SkScript.h
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#ifndef SkScript_DEFINED
#define SkScript_DEFINED

#include "SkOperand.h"
#include "SkIntArray.h"
#include "SkTDict.h"
#include "SkTDStack.h"

class SkAnimateMaker;

class SkScriptEngine {
public:
    enum Error {
        kNoError,
        kArrayIndexOutOfBounds,
        kCouldNotFindReferencedID,
        kDotOperatorExpectsObject,
        kErrorInArrrayIndex,
        kErrorInFunctionParameters,
        kExpectedArray,
        kExpectedBooleanExpression,
        kExpectedFieldName,
        kExpectedHex,
        kExpectedIntForConditionOperator,
        kExpectedNumber,
        kExpectedNumberForArrayIndex,
        kExpectedOperator,
        kExpectedToken,
        kExpectedTokenBeforeDotOperator,
        kExpectedValue,
        kHandleMemberFailed,
        kHandleMemberFunctionFailed,
        kHandleUnboxFailed,
        kIndexOutOfRange,
        kMismatchedArrayBrace,
        kMismatchedBrackets,
        kNoFunctionHandlerFound,
        kPrematureEnd,
        kTooManyParameters,
        kTypeConversionFailed,
        kUnterminatedString
    };

    enum SkOpType {
        kNoType,
        kInt = 1,
        kScalar = 2,
        kString = 4,
        kArray = 8,
        kObject = 16
//      kStruct = 32
    };

    typedef bool (*_boxCallBack)(void* userStorage, SkScriptValue* result);
    typedef bool (*_functionCallBack)(const char* func, size_t len, SkTDArray<SkScriptValue>& params,
        void* userStorage, SkScriptValue* result);
    typedef bool (*_memberCallBack)(const char* member, size_t len, void* object,
        void* userStorage, SkScriptValue* result);
    typedef bool (*_memberFunctionCallBack)(const char* member, size_t len, void* object,
        SkTDArray<SkScriptValue>& params, void* userStorage, SkScriptValue* result);
//  typedef bool (*_objectToStringCallBack)(void* object, void* userStorage, SkScriptValue* result);
    typedef bool (*_propertyCallBack)(const char* prop, size_t len, void* userStorage, SkScriptValue* result);
    typedef bool (*_unboxCallBack)(void* userStorage, SkScriptValue* result);
    SkScriptEngine(SkOpType returnType);
    ~SkScriptEngine();
    void boxCallBack(_boxCallBack func, void* userStorage);
    bool convertTo(SkDisplayTypes , SkScriptValue* );
    bool evaluateScript(const char** script, SkScriptValue* value);
    void forget(SkTypedArray* array);
    void functionCallBack(_functionCallBack func, void* userStorage);
    Error getError() const { return fError; }
#ifdef SK_DEBUG
    bool getErrorString(SkString* err) const;
#endif
    void memberCallBack(_memberCallBack , void* userStorage);
    void memberFunctionCallBack(_memberFunctionCallBack , void* userStorage);
//  void objectToStringCallBack(_objectToStringCallBack , void* userStorage);
    void propertyCallBack(_propertyCallBack prop, void* userStorage);
    void track(SkTypedArray* array);
    void track(SkString* string);
    void unboxCallBack(_unboxCallBack func, void* userStorage);
    static bool ConvertTo(SkScriptEngine* , SkDisplayTypes toType, SkScriptValue* value);
    static SkScalar IntToScalar(int32_t );
    static SkDisplayTypes ToDisplayType(SkOpType type);
    static SkOpType ToOpType(SkDisplayTypes type);
    static bool ValueToString(SkScriptValue value, SkString* string);

    enum CallBackType {
        kBox,
        kFunction,
        kMember,
        kMemberFunction,
    //  kObjectToString,
        kProperty,
        kUnbox
    };

    struct UserCallBack {
        CallBackType fCallBackType;
        void* fUserStorage;
        union {
            _boxCallBack fBoxCallBack;
            _functionCallBack fFunctionCallBack;
            _memberCallBack fMemberCallBack;
            _memberFunctionCallBack fMemberFunctionCallBack;
    //      _objectToStringCallBack fObjectToStringCallBack;
            _propertyCallBack fPropertyCallBack;
            _unboxCallBack fUnboxCallBack;
        };
    };

    enum SkOp {
        kUnassigned,
        kAdd,
        kAddInt = kAdd,
        kAddScalar,
        kAddString, // string concat
        kArrayOp,
        kBitAnd,
        kBitNot,
        kBitOr,
        kDivide,
        kDivideInt = kDivide,
        kDivideScalar,
        kElse,
        kEqual,
        kEqualInt = kEqual,
        kEqualScalar,
        kEqualString,
        kFlipOps,
        kGreaterEqual,
        kGreaterEqualInt = kGreaterEqual,
        kGreaterEqualScalar,
        kGreaterEqualString,
        kIf,
        kLogicalAnd,
        kLogicalNot,
        kLogicalOr,
        kMinus,
        kMinusInt = kMinus,
        kMinusScalar,
        kModulo,
        kModuloInt = kModulo,
        kModuloScalar,
        kMultiply,
        kMultiplyInt = kMultiply,
        kMultiplyScalar,
        kParen,
        kShiftLeft,
        kShiftRight,    // signed
        kSubtract,
        kSubtractInt = kSubtract,
        kSubtractScalar,
        kXor,
        kArtificialOp = 0x40
    };

    enum SkOpBias {
        kNoBias,
        kTowardsNumber = 0,
        kTowardsString
    };

protected:

    struct SkOperatorAttributes {
        unsigned int fLeftType : 3; // SkOpType, but only lower values
        unsigned int fRightType : 3;     // SkOpType, but only lower values
        SkOpBias fBias : 1;
    };

    struct SkSuppress { // !!! could be compressed to a long
        SkOp fOperator; // operand which enabled suppression
        int fOpStackDepth; // depth when suppression operator was found
        SkBool8 fSuppress; // set if suppression happens now, as opposed to later
        SkBool8 fElse; // set on the : half of ? :
    };

    static const SkOperatorAttributes gOpAttributes[];
    static const signed char gPrecedence[];
    int arithmeticOp(char ch, char nextChar, bool lastPush);
    void commonCallBack(CallBackType type, UserCallBack& callBack, void* userStorage);
    bool convertParams(SkTDArray<SkScriptValue>&, const SkFunctionParamType* ,
                                    int paramTypeCount);
    void convertToString(SkOperand& operand, SkDisplayTypes type) {
        SkScriptValue scriptValue;
        scriptValue.fOperand = operand;
        scriptValue.fType = type;
        convertTo(SkType_String, &scriptValue);
        operand = scriptValue.fOperand;
    }
    bool evaluateDot(const char*& script, bool suppressed);
    bool evaluateDotParam(const char*& script, bool suppressed, const char* field, size_t fieldLength);
    bool functionParams(const char** scriptPtr, SkTDArray<SkScriptValue>& params);
    bool handleArrayIndexer(const char** scriptPtr, bool suppressed);
    bool handleBox(SkScriptValue* value);
    bool handleFunction(const char** scriptPtr, bool suppressed);
    bool handleMember(const char* field, size_t len, void* object);
    bool handleMemberFunction(const char* field, size_t len, void* object, SkTDArray<SkScriptValue>& params);
//  bool handleObjectToString(void* object);
    bool handleProperty(bool suppressed);
    bool handleUnbox(SkScriptValue* scriptValue);
    bool innerScript(const char** scriptPtr, SkScriptValue* value);
    int logicalOp(char ch, char nextChar);
    Error opError();
    bool processOp();
    void setAnimateMaker(SkAnimateMaker* maker) { fMaker = maker; }
    bool setError(Error , const char* pos);
    enum SkBraceStyle {
    //  kStructBrace,
        kArrayBrace,
        kFunctionBrace
    };

#if 0
    SkIntArray(SkBraceStyle) fBraceStack;       // curly, square, function paren
    SkIntArray(SkOp) fOpStack;
    SkIntArray(SkOpType) fTypeStack;
    SkTDOperandArray fOperandStack;
    SkTDArray<SkSuppress> fSuppressStack;
#else
    SkTDStack<SkBraceStyle> fBraceStack;        // curly, square, function paren
    SkTDStack<SkOp> fOpStack;
    SkTDStack<SkOpType> fTypeStack;
    SkTDStack<SkOperand> fOperandStack;
    SkTDStack<SkSuppress> fSuppressStack;
#endif
    SkAnimateMaker* fMaker;
    SkTDTypedArrayArray fTrackArray;
    SkTDStringArray fTrackString;
    const char* fToken; // one-deep stack
    size_t fTokenLength;
    SkTDArray<UserCallBack> fUserCallBacks;
    SkOpType fReturnType;
    Error fError;
    int fErrorPosition;
private:
    friend class SkTypedArray;
#ifdef SK_SUPPORT_UNITTEST
public:
    static void UnitTest();
#endif
};

#ifdef SK_SUPPORT_UNITTEST

struct SkScriptNAnswer {
    const char* fScript;
    SkDisplayTypes fType;
    int32_t fIntAnswer;
    SkScalar fScalarAnswer;
    const char* fStringAnswer;
};

#endif

#endif // SkScript_DEFINED