gfx/skia/trunk/include/core/SkChunkAlloc.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkChunkAlloc.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2006 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkChunkAlloc_DEFINED
    1.14 +#define SkChunkAlloc_DEFINED
    1.15 +
    1.16 +#include "SkTypes.h"
    1.17 +
    1.18 +class SkChunkAlloc : SkNoncopyable {
    1.19 +public:
    1.20 +    SkChunkAlloc(size_t minSize);
    1.21 +    ~SkChunkAlloc();
    1.22 +
    1.23 +    /**
    1.24 +     *  Free up all allocated blocks. This invalidates all returned
    1.25 +     *  pointers.
    1.26 +     */
    1.27 +    void reset();
    1.28 +
    1.29 +    enum AllocFailType {
    1.30 +        kReturnNil_AllocFailType,
    1.31 +        kThrow_AllocFailType
    1.32 +    };
    1.33 +
    1.34 +    void* alloc(size_t bytes, AllocFailType);
    1.35 +    void* allocThrow(size_t bytes) {
    1.36 +        return this->alloc(bytes, kThrow_AllocFailType);
    1.37 +    }
    1.38 +
    1.39 +    /** Call this to unalloc the most-recently allocated ptr by alloc(). On
    1.40 +        success, the number of bytes freed is returned, or 0 if the block could
    1.41 +        not be unallocated. This is a hint to the underlying allocator that
    1.42 +        the previous allocation may be reused, but the implementation is free
    1.43 +        to ignore this call (and return 0).
    1.44 +     */
    1.45 +    size_t unalloc(void* ptr);
    1.46 +
    1.47 +    size_t totalCapacity() const { return fTotalCapacity; }
    1.48 +    size_t totalUsed() const { return fTotalUsed; }
    1.49 +    int blockCount() const { return fBlockCount; }
    1.50 +
    1.51 +    /**
    1.52 +     *  Returns true if the specified address is within one of the chunks, and
    1.53 +     *  has at least 1-byte following the address (i.e. if addr points to the
    1.54 +     *  end of a chunk, then contains() will return false).
    1.55 +     */
    1.56 +    bool contains(const void* addr) const;
    1.57 +
    1.58 +private:
    1.59 +    struct Block;
    1.60 +
    1.61 +    Block*  fBlock;
    1.62 +    size_t  fMinSize;
    1.63 +    size_t  fChunkSize;
    1.64 +    size_t  fTotalCapacity;
    1.65 +    size_t  fTotalUsed;     // will be <= fTotalCapacity
    1.66 +    int     fBlockCount;
    1.67 +
    1.68 +    Block* newBlock(size_t bytes, AllocFailType ftype);
    1.69 +};
    1.70 +
    1.71 +#endif

mercurial