Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(817)

Unified Diff: src/ports/SkDiscardableMemory_none.cpp

Issue 74793011: Add SkImageGenerator Interface (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: whitespace Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.cpp ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.cpp ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698