Chromium Code Reviews| 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 /** Allocate the specified buffer for pixels. The memory is freed when the | 20 /** |
| 21 last owner of this pixelref is gone. If addr is NULL, sk_malloc_throw() | 21 * Return a new SkMallocPixelRef with the provided pixel storage, rowBytes, |
| 22 is called to allocate it. | 22 * and optional colortable. The caller is responsible for managing the |
| 23 * lifetime of the pixel storage buffer. This pixelref will ref() the | |
| 24 * specified colortable (if not NULL). | |
|
scroggo
2013/11/20 21:04:28
Can you add a comment that this does not take owne
reed1
2013/11/20 21:27:18
"The caller is responsible for managing the lifet
scroggo
2013/11/20 21:35:19
D'oh! No, that's clear.
| |
| 25 * | |
| 26 * Returns NULL on failure. | |
| 23 */ | 27 */ |
| 24 SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixe ls = true); | 28 static SkMallocPixelRef* Create(const SkImageInfo&, void* addr, |
|
scroggo
2013/11/20 21:04:28
Maybe a better name for this would be Wrap or Wrap
reed1
2013/11/20 21:27:18
Hmmm
| |
| 25 virtual ~SkMallocPixelRef(); | 29 size_t rowBytes, SkColorTable*); |
| 30 /** | |
| 31 * Return a new SkMallocPixelRef, automatically allocating storage for the | |
| 32 * pixels. If rowBytes are 0, an optimal value will be chosen automatically . | |
| 33 * If rowBytes is > 0, then it will be respected, or NULL will be returned | |
| 34 * if rowBytes is invalid for the specified info. | |
| 35 * | |
| 36 * Returns NULL on failure. | |
| 37 */ | |
| 38 static SkMallocPixelRef* Allocate(const SkImageInfo& info, | |
| 39 size_t rowBytes, SkColorTable*); | |
| 26 | 40 |
| 27 //! Return the allocation size for the pixels | |
| 28 size_t getSize() const { return fSize; } | |
| 29 void* getAddr() const { return fStorage; } | 41 void* getAddr() const { return fStorage; } |
| 30 | 42 |
| 31 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef) | 43 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef) |
| 32 | 44 |
| 33 protected: | 45 protected: |
| 34 // overrides from SkPixelRef | 46 virtual void* onLockPixels(SkImageInfo*, size_t*, SkColorTable**) SK_OVERRID E; |
| 35 virtual void* onLockPixels(SkColorTable**); | 47 virtual void onUnlockPixels() SK_OVERRIDE; |
| 36 virtual void onUnlockPixels(); | 48 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
| 37 | 49 |
| 38 SkMallocPixelRef(SkFlattenableReadBuffer& buffer); | 50 SkMallocPixelRef(SkFlattenableReadBuffer& buffer); |
| 39 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; | 51 SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*, |
| 52 bool ownsPixels); | |
| 53 virtual ~SkMallocPixelRef(); | |
| 40 | 54 |
| 41 private: | 55 private: |
| 42 void* fStorage; | 56 void* fStorage; |
| 43 size_t fSize; | 57 SkColorTable* fCTable; |
| 44 SkColorTable* fCTable; | 58 size_t fRB; |
| 45 bool fOwnPixels; | 59 SkImageInfo fInfo; |
| 60 const bool fOwnPixels; | |
| 61 | |
| 62 size_t computeMinSize() const { | |
| 63 if (fInfo.fHeight == 0) { | |
| 64 return 0; | |
| 65 } | |
| 66 return (fInfo.fHeight - 1) * fRB + fInfo.minRowBytes(); | |
| 67 } | |
| 46 | 68 |
| 47 typedef SkPixelRef INHERITED; | 69 typedef SkPixelRef INHERITED; |
| 48 }; | 70 }; |
| 49 | 71 |
| 50 | 72 |
| 51 #endif | 73 #endif |
| OLD | NEW |