gfx/skia/trunk/src/core/SkPathHeap.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkPathHeap.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +#ifndef SkPathHeap_DEFINED
    1.12 +#define SkPathHeap_DEFINED
    1.13 +
    1.14 +#include "SkRefCnt.h"
    1.15 +#include "SkChunkAlloc.h"
    1.16 +#include "SkTDArray.h"
    1.17 +
    1.18 +class SkPath;
    1.19 +class SkReadBuffer;
    1.20 +class SkWriteBuffer;
    1.21 +
    1.22 +class SkPathHeap : public SkRefCnt {
    1.23 +public:
    1.24 +    SK_DECLARE_INST_COUNT(SkPathHeap)
    1.25 +
    1.26 +    SkPathHeap();
    1.27 +    SkPathHeap(SkReadBuffer&);
    1.28 +    virtual ~SkPathHeap();
    1.29 +
    1.30 +    /** Copy the path into the heap, and return the new total number of paths.
    1.31 +        Thus, the returned value will be index+1, where index is the index of
    1.32 +        this newly added (copied) path.
    1.33 +     */
    1.34 +    int append(const SkPath&);
    1.35 +
    1.36 +    /** Add the specified path to the heap using its gen ID to de-duplicate.
    1.37 +        Returns the path's index in the heap + 1.
    1.38 +     */
    1.39 +    int insert(const SkPath&);
    1.40 +
    1.41 +    // called during picture-playback
    1.42 +    int count() const { return fPaths.count(); }
    1.43 +    const SkPath& operator[](int index) const {
    1.44 +        return *fPaths[index];
    1.45 +    }
    1.46 +
    1.47 +    void flatten(SkWriteBuffer&) const;
    1.48 +
    1.49 +private:
    1.50 +    // we store the paths in the heap (placement new)
    1.51 +    SkChunkAlloc        fHeap;
    1.52 +    // we just store ptrs into fHeap here
    1.53 +    SkTDArray<SkPath*>  fPaths;
    1.54 +
    1.55 +    class LookupEntry {
    1.56 +    public:
    1.57 +        LookupEntry(const SkPath& path);
    1.58 +
    1.59 +        int storageSlot() const { return fStorageSlot; }
    1.60 +        void setStorageSlot(int storageSlot) { fStorageSlot = storageSlot; }
    1.61 +
    1.62 +        static bool Less(const LookupEntry& a, const LookupEntry& b) {
    1.63 +            return a.fGenerationID < b.fGenerationID;
    1.64 +        }
    1.65 +
    1.66 +    private:
    1.67 +        uint32_t fGenerationID;     // the SkPath's generation ID
    1.68 +        // the path's index in the heap + 1. It is 0 if the path is not yet in the heap.
    1.69 +        int      fStorageSlot;
    1.70 +    };
    1.71 +
    1.72 +    SkTDArray<LookupEntry> fLookupTable;
    1.73 +
    1.74 +    SkPathHeap::LookupEntry* addIfNotPresent(const SkPath& path);
    1.75 +
    1.76 +    typedef SkRefCnt INHERITED;
    1.77 +};
    1.78 +
    1.79 +#endif

mercurial