Index: src/ports/SkDiscardableMemory_none.cpp |
diff --git a/src/ports/SkDiscardableMemory_none.cpp b/src/ports/SkDiscardableMemory_none.cpp |
index 6559097e625aa2646caee81e370c0b6687db2781..700713ba4816631dfc7d7e2f3bb69558d5eedbee 100644 |
--- a/src/ports/SkDiscardableMemory_none.cpp |
+++ b/src/ports/SkDiscardableMemory_none.cpp |
@@ -6,7 +6,56 @@ |
*/ |
#include "SkDiscardableMemory.h" |
+#include "SkTypes.h" |
+ |
+namespace { |
+//////////////////////////////////////////////////////////////////////////////// |
+/** |
+ * Always successful, never purges. Useful for testing. |
+ */ |
+class SkMockDiscardableMemory : public SkDiscardableMemory { |
+public: |
+ SkMockDiscardableMemory(void*); |
+ virtual ~SkMockDiscardableMemory(); |
+ virtual bool lock() SK_OVERRIDE; |
+ virtual void* data() SK_OVERRIDE; |
+ virtual void unlock() SK_OVERRIDE; |
+private: |
+ bool fLocked; |
+ void* fPointer; |
+}; |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+ |
+SkMockDiscardableMemory::SkMockDiscardableMemory(void* ptr) |
+ : fLocked(true) |
+ , fPointer(ptr) { // Takes ownership of ptr. |
+ SkASSERT(fPointer != NULL); |
+} |
+ |
+SkMockDiscardableMemory::~SkMockDiscardableMemory() { |
+ SkASSERT(!fLocked); |
+ sk_free(fPointer); |
+} |
+ |
+bool SkMockDiscardableMemory::lock() { |
+ SkASSERT(!fLocked); |
+ return fLocked = true; |
+} |
+ |
+void* SkMockDiscardableMemory::data() { |
+ SkASSERT(fLocked); |
+ return fLocked ? fPointer : NULL; |
+} |
+ |
+void SkMockDiscardableMemory::unlock() { |
+ SkASSERT(fLocked); |
+ fLocked = false; |
+} |
+//////////////////////////////////////////////////////////////////////////////// |
+} // namespace |
SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) { |
- return NULL; |
+ void* ptr = sk_malloc_throw(bytes); |
+ return (ptr != NULL) ? SkNEW_ARGS(SkMockDiscardableMemory, (ptr)) : NULL; |
} |