Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkPurgeableMemoryBlock_DEFINED | |
| 9 #define SkPurgeableMemoryBlock_DEFINED | |
| 10 | |
| 11 #include "SkTypes.h" | |
| 12 | |
| 13 class SkPurgeableMemoryBlock : public SkNoncopyable { | |
| 14 | |
| 15 public: | |
| 16 /** | |
| 17 * Whether or not this platform has an implementation for purgeable memory. | |
| 18 */ | |
| 19 static bool PlatformSupportsPurgeableMemory(); | |
| 20 | |
| 21 /** | |
| 22 * Create a new purgeable memory block with size >= size. Returns NULL if n ot supported on this | |
|
reed1
2013/03/13 20:41:34
size >= size is a funny statement. How about
Crea
scroggo
2013/03/13 22:06:42
Done.
| |
| 23 * platform or on failure. | |
| 24 * @param size Number of bytes requested. The resulting data will be at lea st this large. | |
| 25 * @return A new block, or NULL on failure. On success, the memory will alr eady be pinned. | |
|
reed1
2013/03/13 20:41:34
Why should it already be pinned?
scroggo
2013/03/13 22:06:42
Currently, the only client (allocAndPinCache) want
| |
| 26 */ | |
| 27 static SkPurgeableMemoryBlock* CreatePurgeableMemoryBlock(size_t size); | |
| 28 | |
| 29 #ifdef SK_DEBUG | |
| 30 /** | |
| 31 * Whether the platform supports one shot purge of all unpinned blocks. If so, | |
| 32 * PurgeAllUnpinnedBlocks will be used to test a purge. Otherwise, purge wi ll be called on | |
| 33 * individual blocks. | |
| 34 */ | |
| 35 static bool PlatformSupportsPurgingAllUnpinnedBlocks(); | |
| 36 | |
| 37 /** | |
| 38 * Purge all unpinned blocks at once, if the platform supports it. | |
| 39 */ | |
| 40 static bool PurgeAllUnpinnedBlocks(); | |
| 41 | |
| 42 // If PlatformSupportsPurgingAllUnpinnedBlocks returns true, this will not b e called, so it can | |
| 43 // simply return false. | |
| 44 bool purge(); | |
| 45 | |
| 46 bool isPinned() const { return fPinned; } | |
| 47 | |
| 48 #ifdef SK_BUILD_FOR_ANDROID | |
| 49 int getFD() const { return fFD; } | |
| 50 #endif | |
| 51 | |
| 52 #endif | |
| 53 | |
| 54 ~SkPurgeableMemoryBlock(); | |
| 55 | |
| 56 /** | |
| 57 * Result of a call to pin(). | |
| 58 */ | |
| 59 enum PinResult { | |
| 60 /** | |
| 61 * The pin succeeded, and the data has been purged. It will need to be rewritten to the | |
| 62 * memory. | |
| 63 */ | |
| 64 kUninitialized_PinResult, | |
| 65 | |
| 66 /** | |
| 67 * The pin succeeded, and the data has been retained. The memory contai ns the same data it | |
| 68 * held when unpin() was called. | |
| 69 */ | |
| 70 kRetained_PinResult, | |
| 71 | |
| 72 /** | |
| 73 * The pin failed. This object should be discarded. | |
| 74 */ | |
| 75 kFailed_PinResult, | |
| 76 }; | |
| 77 | |
| 78 /** | |
| 79 * Pin the memory for use. Must not be called while already pinned. | |
|
reed1
2013/03/13 20:41:34
Why is this api different from the decoder, in tha
scroggo
2013/03/13 22:06:42
In the implementation from this patch, it starts o
| |
| 80 */ | |
| 81 PinResult pin(); | |
| 82 | |
| 83 /** | |
| 84 * Unpin the data so it can be purged if necessary. | |
| 85 */ | |
| 86 void unpin(); | |
| 87 | |
| 88 /** | |
| 89 * Pointer to the data. Should only be used after a call to pin which succe eds. | |
| 90 */ | |
| 91 void* data() { return fAddr; } | |
| 92 | |
| 93 private: | |
| 94 void* fAddr; | |
| 95 size_t fSize; | |
| 96 bool fPinned; | |
| 97 #ifdef SK_BUILD_FOR_ANDROID | |
| 98 int fFD; | |
| 99 #endif | |
| 100 | |
| 101 // Unimplemented default constructor is private, to prevent manual creation. | |
| 102 SkPurgeableMemoryBlock(); | |
| 103 | |
| 104 // The correct way to create a new one is from the static CreatePurgeableMem oryBlock. | |
| 105 SkPurgeableMemoryBlock(size_t); | |
| 106 }; | |
| 107 | |
| 108 #endif // SkPurgeableMemoryBlock_DEFINED | |
| OLD | NEW |