OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #ifndef SkMallocPixelRef_DEFINED | 9 #ifndef SkMallocPixelRef_DEFINED |
10 #define SkMallocPixelRef_DEFINED | 10 #define SkMallocPixelRef_DEFINED |
(...skipping 25 matching lines...) Expand all Loading... |
36 * if rowBytes is invalid for the specified info. | 36 * if rowBytes is invalid for the specified info. |
37 * | 37 * |
38 * This pixelref will ref() the specified colortable (if not NULL). | 38 * This pixelref will ref() the specified colortable (if not NULL). |
39 * | 39 * |
40 * Returns NULL on failure. | 40 * Returns NULL on failure. |
41 */ | 41 */ |
42 static SkMallocPixelRef* NewAllocate(const SkImageInfo& info, | 42 static SkMallocPixelRef* NewAllocate(const SkImageInfo& info, |
43 size_t rowBytes, SkColorTable*); | 43 size_t rowBytes, SkColorTable*); |
44 | 44 |
45 /** | 45 /** |
| 46 * Identical to NewAllocate, except all pixel bytes are zeroed. |
| 47 */ |
| 48 static SkMallocPixelRef* NewZeroed(const SkImageInfo& info, |
| 49 size_t rowBytes, SkColorTable*); |
| 50 |
| 51 /** |
46 * Return a new SkMallocPixelRef with the provided pixel storage, | 52 * Return a new SkMallocPixelRef with the provided pixel storage, |
47 * rowBytes, and optional colortable. On destruction, ReleaseProc | 53 * rowBytes, and optional colortable. On destruction, ReleaseProc |
48 * will be called. | 54 * will be called. |
49 * | 55 * |
50 * This pixelref will ref() the specified colortable (if not NULL). | 56 * This pixelref will ref() the specified colortable (if not NULL). |
51 * | 57 * |
52 * If ReleaseProc is NULL, the pixels will never be released. This | 58 * If ReleaseProc is NULL, the pixels will never be released. This |
53 * can be useful if the pixels were stack allocated. However, such an | 59 * can be useful if the pixels were stack allocated. However, such an |
54 * SkMallocPixelRef must not live beyond its pixels (e.g. by copying | 60 * SkMallocPixelRef must not live beyond its pixels (e.g. by copying |
55 * an SkBitmap pointing to it, or drawing to an SkPicture). | 61 * an SkBitmap pointing to it, or drawing to an SkPicture). |
(...skipping 18 matching lines...) Expand all Loading... |
74 */ | 80 */ |
75 static SkMallocPixelRef* NewWithData(const SkImageInfo& info, | 81 static SkMallocPixelRef* NewWithData(const SkImageInfo& info, |
76 size_t rowBytes, | 82 size_t rowBytes, |
77 SkColorTable* ctable, | 83 SkColorTable* ctable, |
78 SkData* data); | 84 SkData* data); |
79 | 85 |
80 void* getAddr() const { return fStorage; } | 86 void* getAddr() const { return fStorage; } |
81 | 87 |
82 class PRFactory : public SkPixelRefFactory { | 88 class PRFactory : public SkPixelRefFactory { |
83 public: | 89 public: |
84 virtual SkPixelRef* create(const SkImageInfo&, | 90 SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) o
verride; |
85 size_t rowBytes, | 91 }; |
86 SkColorTable*) override; | 92 |
| 93 class ZeroedPRFactory : public SkPixelRefFactory { |
| 94 public: |
| 95 SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) o
verride; |
87 }; | 96 }; |
88 | 97 |
89 protected: | 98 protected: |
90 // The ownPixels version of this constructor is deprecated. | 99 // The ownPixels version of this constructor is deprecated. |
91 SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*, | 100 SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*, |
92 bool ownPixels); | 101 bool ownPixels); |
93 virtual ~SkMallocPixelRef(); | 102 virtual ~SkMallocPixelRef(); |
94 | 103 |
95 bool onNewLockPixels(LockRec*) override; | 104 bool onNewLockPixels(LockRec*) override; |
96 void onUnlockPixels() override; | 105 void onUnlockPixels() override; |
97 size_t getAllocatedSizeInBytes() const override; | 106 size_t getAllocatedSizeInBytes() const override; |
98 | 107 |
99 private: | 108 private: |
| 109 // Uses alloc to implement NewAllocate or NewZeroed. |
| 110 static SkMallocPixelRef* NewUsing(void*(*alloc)(size_t), |
| 111 const SkImageInfo&, |
| 112 size_t rowBytes, |
| 113 SkColorTable*); |
| 114 |
100 void* fStorage; | 115 void* fStorage; |
101 SkColorTable* fCTable; | 116 SkColorTable* fCTable; |
102 size_t fRB; | 117 size_t fRB; |
103 ReleaseProc fReleaseProc; | 118 ReleaseProc fReleaseProc; |
104 void* fReleaseProcContext; | 119 void* fReleaseProcContext; |
105 | 120 |
106 SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*, | 121 SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*, |
107 ReleaseProc proc, void* context); | 122 ReleaseProc proc, void* context); |
108 | 123 |
109 typedef SkPixelRef INHERITED; | 124 typedef SkPixelRef INHERITED; |
110 }; | 125 }; |
111 | 126 |
112 | 127 |
113 #endif | 128 #endif |
OLD | NEW |