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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkMallocPixelRef.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     1.4 +/*
     1.5 + * Copyright 2008 The Android Open Source Project
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +
    1.12 +#ifndef SkMallocPixelRef_DEFINED
    1.13 +#define SkMallocPixelRef_DEFINED
    1.14 +
    1.15 +#include "SkPixelRef.h"
    1.16 +
    1.17 +/** We explicitly use the same allocator for our pixels that SkMask does,
    1.18 +    so that we can freely assign memory allocated by one class to the other.
    1.19 +*/
    1.20 +class SK_API SkMallocPixelRef : public SkPixelRef {
    1.21 +public:
    1.22 +    SK_DECLARE_INST_COUNT(SkMallocPixelRef)
    1.23 +    /**
    1.24 +     *  Return a new SkMallocPixelRef with the provided pixel storage, rowBytes,
    1.25 +     *  and optional colortable. The caller is responsible for managing the
    1.26 +     *  lifetime of the pixel storage buffer, as this pixelref will not try
    1.27 +     *  to delete it.
    1.28 +     *
    1.29 +     *  The pixelref will ref() the colortable (if not NULL).
    1.30 +     *
    1.31 +     *  Returns NULL on failure.
    1.32 +     */
    1.33 +    static SkMallocPixelRef* NewDirect(const SkImageInfo&, void* addr,
    1.34 +                                       size_t rowBytes, SkColorTable*);
    1.35 +
    1.36 +    /**
    1.37 +     *  Return a new SkMallocPixelRef, automatically allocating storage for the
    1.38 +     *  pixels. If rowBytes are 0, an optimal value will be chosen automatically.
    1.39 +     *  If rowBytes is > 0, then it will be respected, or NULL will be returned
    1.40 +     *  if rowBytes is invalid for the specified info.
    1.41 +     *
    1.42 +     *  This pixelref will ref() the specified colortable (if not NULL).
    1.43 +     *
    1.44 +     *  Returns NULL on failure.
    1.45 +     */
    1.46 +    static SkMallocPixelRef* NewAllocate(const SkImageInfo& info,
    1.47 +                                         size_t rowBytes, SkColorTable*);
    1.48 +
    1.49 +    /**
    1.50 +     *  Return a new SkMallocPixelRef with the provided pixel storage,
    1.51 +     *  rowBytes, and optional colortable. On destruction, ReleaseProc
    1.52 +     *  will be called.
    1.53 +     *
    1.54 +     *  This pixelref will ref() the specified colortable (if not NULL).
    1.55 +     *
    1.56 +     *  Returns NULL on failure.
    1.57 +     */
    1.58 +    typedef void (*ReleaseProc)(void* addr, void* context);
    1.59 +    static SkMallocPixelRef* NewWithProc(const SkImageInfo& info,
    1.60 +                                         size_t rowBytes, SkColorTable*,
    1.61 +                                         void* addr, ReleaseProc proc,
    1.62 +                                         void* context);
    1.63 +
    1.64 +    /**
    1.65 +     *  Return a new SkMallocPixelRef that will use the provided
    1.66 +     *  SkData, rowBytes, and optional colortable as pixel storage.
    1.67 +     *  The SkData will be ref()ed and on destruction of the PielRef,
    1.68 +     *  the SkData will be unref()ed.
    1.69 +     *
    1.70 +     *  @param offset (in bytes) into the provided SkData that the
    1.71 +     *         first pixel is located at.
    1.72 +     *
    1.73 +     *  This pixelref will ref() the specified colortable (if not NULL).
    1.74 +     *
    1.75 +     *  Returns NULL on failure.
    1.76 +     */
    1.77 +    static SkMallocPixelRef* NewWithData(const SkImageInfo& info,
    1.78 +                                         size_t rowBytes,
    1.79 +                                         SkColorTable* ctable,
    1.80 +                                         SkData* data,
    1.81 +                                         size_t offset = 0);
    1.82 +
    1.83 +    void* getAddr() const { return fStorage; }
    1.84 +
    1.85 +    class PRFactory : public SkPixelRefFactory {
    1.86 +    public:
    1.87 +        virtual SkPixelRef* create(const SkImageInfo&,
    1.88 +                                   SkColorTable*) SK_OVERRIDE;
    1.89 +    };
    1.90 +
    1.91 +    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef)
    1.92 +
    1.93 +protected:
    1.94 +    // The ownPixels version of this constructor is deprecated.
    1.95 +    SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
    1.96 +                     bool ownPixels);
    1.97 +    SkMallocPixelRef(SkReadBuffer& buffer);
    1.98 +    virtual ~SkMallocPixelRef();
    1.99 +
   1.100 +    virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
   1.101 +    virtual void onUnlockPixels() SK_OVERRIDE;
   1.102 +    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
   1.103 +    virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE;
   1.104 +
   1.105 +private:
   1.106 +    void*           fStorage;
   1.107 +    SkColorTable*   fCTable;
   1.108 +    size_t          fRB;
   1.109 +    ReleaseProc     fReleaseProc;
   1.110 +    void*           fReleaseProcContext;
   1.111 +
   1.112 +    SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
   1.113 +                     ReleaseProc proc, void* context);
   1.114 +
   1.115 +    typedef SkPixelRef INHERITED;
   1.116 +};
   1.117 +
   1.118 +
   1.119 +#endif

mercurial