| OLD | NEW | 
|---|
| 1 | 1 | 
| 2 /* | 2 /* | 
| 3  * Copyright 2008 The Android Open Source Project | 3  * Copyright 2008 The Android Open Source Project | 
| 4  * | 4  * | 
| 5  * Use of this source code is governed by a BSD-style license that can be | 5  * Use of this source code is governed by a BSD-style license that can be | 
| 6  * found in the LICENSE file. | 6  * found in the LICENSE file. | 
| 7  */ | 7  */ | 
| 8 | 8 | 
| 9 | 9 | 
| 10 #ifndef SkMallocPixelRef_DEFINED | 10 #ifndef SkMallocPixelRef_DEFINED | 
| 11 #define SkMallocPixelRef_DEFINED | 11 #define SkMallocPixelRef_DEFINED | 
| 12 | 12 | 
| 13 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" | 
| 14 | 14 | 
| 15 /** We explicitly use the same allocator for our pixels that SkMask does, | 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. | 16     so that we can freely assign memory allocated by one class to the other. | 
| 17 */ | 17 */ | 
| 18 class SkMallocPixelRef : public SkPixelRef { | 18 class SkMallocPixelRef : public SkPixelRef { | 
| 19 public: | 19 public: | 
| 20     /** | 20     /** Allocate the specified buffer for pixels. The memory is freed when the | 
| 21      *  Return a new SkMallocPixelRef with the provided pixel storage, rowBytes, | 21         last owner of this pixelref is gone. If addr is NULL, sk_malloc_throw() | 
| 22      *  and optional colortable. The caller is responsible for managing the | 22         is called to allocate it. | 
| 23      *  lifetime of the pixel storage buffer, as the pixelref will not try |  | 
| 24      *  to delete the storage. |  | 
| 25      * |  | 
| 26      *  This pixelref will ref() the specified colortable (if not NULL). |  | 
| 27      * |  | 
| 28      *  Returns NULL on failure. |  | 
| 29      */ | 23      */ | 
| 30     static SkMallocPixelRef* NewDirect(const SkImageInfo&, void* addr, | 24     SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixe
    ls = true); | 
| 31                                        size_t rowBytes, SkColorTable*); | 25     virtual ~SkMallocPixelRef(); | 
| 32 |  | 
| 33     /** |  | 
| 34      *  Return a new SkMallocPixelRef, automatically allocating storage for the |  | 
| 35      *  pixels. If rowBytes are 0, an optimal value will be chosen automatically
    . |  | 
| 36      *  If rowBytes is > 0, then it will be respected, or NULL will be returned |  | 
| 37      *  if rowBytes is invalid for the specified info. |  | 
| 38      * |  | 
| 39      *  This pixelref will ref() the specified colortable (if not NULL). |  | 
| 40      * |  | 
| 41      *  Returns NULL on failure. |  | 
| 42      */ |  | 
| 43     static SkMallocPixelRef* NewAllocate(const SkImageInfo& info, |  | 
| 44                                          size_t rowBytes, SkColorTable*); |  | 
| 45 | 26 | 
| 46     void* getAddr() const { return fStorage; } | 27     void* getAddr() const { return fStorage; } | 
| 47 | 28 | 
| 48     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef) | 29     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef) | 
| 49 | 30 | 
| 50 protected: | 31 protected: | 
| 51     virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; | 32     // overrides from SkPixelRef | 
| 52     virtual void onUnlockPixels() SK_OVERRIDE; | 33     virtual void* onLockPixels(SkColorTable**); | 
| 53     virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; | 34     virtual void onUnlockPixels(); | 
| 54     virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE; |  | 
| 55 | 35 | 
| 56     SkMallocPixelRef(SkFlattenableReadBuffer& buffer); | 36     SkMallocPixelRef(SkFlattenableReadBuffer& buffer); | 
| 57     SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*, | 37     virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; | 
| 58                      bool ownsPixels); | 38 | 
| 59     virtual ~SkMallocPixelRef(); | 39     // Returns the allocation size for the pixels | 
|  | 40     virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE { return fSize; } | 
| 60 | 41 | 
| 61 private: | 42 private: | 
| 62     void*               fStorage; | 43     void*           fStorage; | 
| 63     SkColorTable*       fCTable; | 44     size_t          fSize; | 
| 64     size_t              fRB; | 45     SkColorTable*   fCTable; | 
| 65     const bool          fOwnPixels; | 46     bool            fOwnPixels; | 
| 66 | 47 | 
| 67     typedef SkPixelRef INHERITED; | 48     typedef SkPixelRef INHERITED; | 
| 68 }; | 49 }; | 
| 69 | 50 | 
| 70 | 51 | 
| 71 #endif | 52 #endif | 
| OLD | NEW | 
|---|