Index: src/lazy/SkPurgeableMemoryBlock.h |
diff --git a/src/lazy/SkPurgeableMemoryBlock.h b/src/lazy/SkPurgeableMemoryBlock.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6cef72db607f676457c4a7b034827790de68f966 |
--- /dev/null |
+++ b/src/lazy/SkPurgeableMemoryBlock.h |
@@ -0,0 +1,99 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef SkPurgeableMemoryBlock_DEFINED |
+#define SkPurgeableMemoryBlock_DEFINED |
+ |
+#include "SkTypes.h" |
+ |
+class SkPurgeableMemoryBlock : public SkNoncopyable { |
+ |
+public: |
+ /** |
+ * Whether or not this platform has an implementation for purgeable memory. |
+ */ |
+ static bool PlatformSupportsPurgeableMemory(); |
djsollen
2013/03/14 13:56:31
writing SkPurgeableMemoryBlock::PlatformSupportsPu
scroggo
2013/03/14 15:36:13
Done.
|
+ |
+ /** |
+ * Create a new purgeable memory block of 'size' bytes. Returns NULL if not supported on this |
+ * platform or on failure. |
+ * @param size Number of bytes requested. |
+ * @return A new block, or NULL on failure. |
+ */ |
+ static SkPurgeableMemoryBlock* CreatePurgeableMemoryBlock(size_t size); |
djsollen
2013/03/14 13:56:31
following the naming of other factories like SkBlu
scroggo
2013/03/14 15:36:13
Done.
|
+ |
+#ifdef SK_DEBUG |
+ /** |
+ * Whether the platform supports one shot purge of all unpinned blocks. If so, |
+ * PurgeAllUnpinnedBlocks will be used to test a purge. Otherwise, purge will be called on |
+ * individual blocks. |
+ */ |
+ static bool PlatformSupportsPurgingAllUnpinnedBlocks(); |
+ |
+ /** |
+ * Purge all unpinned blocks at once, if the platform supports it. |
+ */ |
+ static bool PurgeAllUnpinnedBlocks(); |
+ |
+ // If PlatformSupportsPurgingAllUnpinnedBlocks returns true, this will not be called, so it can |
+ // simply return false. |
+ bool purge(); |
+ |
+ bool isPinned() const { return fPinned; } |
+ |
+#ifdef SK_BUILD_FOR_ANDROID |
+ int getFD() const { return fFD; } |
djsollen
2013/03/14 13:56:31
Is this really needed? Who calls this?
scroggo
2013/03/14 15:36:13
This is a debug only function just for debugging.
scroggo
2013/03/14 18:05:32
Removed! Thanks for adding the purge function!
|
+#endif |
+ |
+#endif |
+ |
+ ~SkPurgeableMemoryBlock(); |
+ |
+ /** |
+ * Output parameter for pin(), stating whether the data has been retained. |
+ */ |
+ enum PinResult { |
+ /** |
+ * The data has been purged, or this is the first call to pin. |
+ */ |
+ kUninitialized_PinResult, |
+ |
+ /** |
+ * The data has been retained. The memory contains the same data it held when unpin() was |
+ * called. |
+ */ |
+ kRetained_PinResult, |
+ }; |
+ |
+ /** |
+ * Pin the memory for use. Must not be called while already pinned. |
+ * @param PinResult Whether the data was retained. Ignored on failure. |
+ * @return Pointer to the pinned data on success. NULL on failure. |
+ */ |
+ void* pin(PinResult*); |
+ |
+ /** |
+ * Unpin the data so it can be purged if necessary. |
+ */ |
+ void unpin(); |
+ |
+private: |
+ void* fAddr; |
+ size_t fSize; |
+ bool fPinned; |
+#ifdef SK_BUILD_FOR_ANDROID |
+ int fFD; |
+#endif |
+ |
+ // Unimplemented default constructor is private, to prevent manual creation. |
+ SkPurgeableMemoryBlock(); |
+ |
+ // The correct way to create a new one is from the static CreatePurgeableMemoryBlock. |
+ SkPurgeableMemoryBlock(size_t); |
+}; |
+ |
+#endif // SkPurgeableMemoryBlock_DEFINED |