Home | History | Annotate | Download | only in core
      1 
      2 /*
      3  * Copyright 2008 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkMallocPixelRef_DEFINED
     11 #define SkMallocPixelRef_DEFINED
     12 
     13 #include "SkPixelRef.h"
     14 
     15 /** We explicitly use the same allocator for our pixels that SkMask does,
     16     so that we can freely assign memory allocated by one class to the other.
     17 */
     18 class SkMallocPixelRef : public SkPixelRef {
     19 public:
     20     /** Allocate the specified buffer for pixels. The memory is freed when the
     21         last owner of this pixelref is gone. If addr is NULL, sk_malloc_throw()
     22         is called to allocate it.
     23      */
     24     SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable);
     25     virtual ~SkMallocPixelRef();
     26 
     27     //! Return the allocation size for the pixels
     28     size_t getSize() const { return fSize; }
     29     void* getAddr() const { return fStorage; }
     30 
     31     // overrides from SkPixelRef
     32     virtual void flatten(SkFlattenableWriteBuffer&) const;
     33     virtual Factory getFactory() const {
     34         return Create;
     35     }
     36     static SkPixelRef* Create(SkFlattenableReadBuffer& buffer) {
     37         return SkNEW_ARGS(SkMallocPixelRef, (buffer));
     38     }
     39 
     40     SK_DECLARE_PIXEL_REF_REGISTRAR()
     41 protected:
     42     // overrides from SkPixelRef
     43     virtual void* onLockPixels(SkColorTable**);
     44     virtual void onUnlockPixels();
     45 
     46     SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
     47 
     48     void*           fStorage;
     49 
     50 private:
     51 
     52     size_t          fSize;
     53     SkColorTable*   fCTable;
     54 
     55     typedef SkPixelRef INHERITED;
     56 };
     57 
     58 
     59 #endif
     60