skia: Added SkDiscardableMemory interface.

Chrome's implementation of SkDiscardableMemory is provided here:
https://codereview.chromium.org/23206002. SkDiscardableMemory is
intended to be used for image caching.

R=reed@google.com, scroggo@google.com, hclam@chromium.org, jamesr@chromium.org
BUG=229120

Author=ernstm@chromium.org

Submitted on behalf of ernstm@chromium.org due to commit queue bug.

Review URL: https://codereview.chromium.org/22950012

git-svn-id: http://skia.googlecode.com/svn/trunk@10797 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
scroggo@google.com 2013-08-19 18:38:08 +00:00
parent cb9445de82
commit 8b71ef16ec
3 changed files with 67 additions and 0 deletions

View File

@ -37,6 +37,7 @@
'../src/ports/SkOSFile_posix.cpp',
'../src/ports/SkOSFile_stdio.cpp',
'../src/ports/SkOSFile_win.cpp',
'../src/ports/SkDiscardableMemory_none.cpp',
'../src/ports/SkPurgeableMemoryBlock_none.cpp',
#'../src/ports/SkThread_none.cpp',
'../src/ports/SkThread_pthread.cpp',

View File

@ -0,0 +1,54 @@
/*
* 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 SkDiscardableMemory_DEFINED
#define SkDiscardableMemory_DEFINED
#include "SkTypes.h"
/**
* Interface for discardable memory. Implementation is provided by the
* embedder.
*/
class SkDiscardableMemory {
public:
/**
* Factory method that creates, initializes and locks an SkDiscardableMemory
* object. If either of these steps fails, a NULL pointer will be returned.
*/
static SkDiscardableMemory* Create(size_t bytes);
/** Must not be called while locked.
*/
virtual ~SkDiscardableMemory() {}
/**
* Locks the memory, prevent it from being discarded. Once locked. you may
* obtain a pointer to that memory using the data() method.
*
* lock() may return false, indicating that the underlying memory was
* discarded and that the lock failed.
*
* Nested calls to lock are not allowed.
*/
virtual bool lock() = 0;
/**
* Returns the current pointer for the discardable memory. This call is ONLY
* valid when the discardable memory object is locked.
*/
virtual void* data() = 0;
/**
* Unlock the memory so that it can be purged by the system. Must be called
* after every successful lock call.
*/
virtual void unlock() = 0;
};
#endif

View File

@ -0,0 +1,12 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkDiscardableMemory.h"
SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) {
return NULL;
}