aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu/include/GrMemory.h
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-14 16:51:21 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-14 16:51:21 +0000
commit1c13c9668a889e56a0c85b51b9f28139c25b76ff (patch)
tree0319884473e77141a574ab07333c6ed4797f7485 /gpu/include/GrMemory.h
parentdd53d91b60e368f1bbff6fb22d796765205ae25d (diff)
Refactor how Gr handles vertex and index data. GrGpu and GrInOrderDrawBuffer both GrBufferAllocPool to manage reserved and set-to-array vertex and index data.
rietveld issue 4188049 git-svn-id: http://skia.googlecode.com/svn/trunk@786 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/include/GrMemory.h')
-rw-r--r--gpu/include/GrMemory.h46
1 files changed, 38 insertions, 8 deletions
diff --git a/gpu/include/GrMemory.h b/gpu/include/GrMemory.h
index 673d0ab43d..be8b1d78e9 100644
--- a/gpu/include/GrMemory.h
+++ b/gpu/include/GrMemory.h
@@ -22,7 +22,10 @@
class GrAutoMalloc : GrNoncopyable {
public:
- GrAutoMalloc(size_t bytes) : fPtr(GrMalloc(bytes)) {}
+ GrAutoMalloc() : fPtr(NULL), fAllocatedBytes(0){
+ }
+
+ GrAutoMalloc(size_t bytes) : fPtr(GrMalloc(bytes)), fAllocatedBytes(bytes) {}
~GrAutoMalloc() { GrFree(fPtr); }
/**
@@ -31,6 +34,8 @@ public:
*/
void* get() const { return fPtr; }
+ size_t size() const { return fAllocatedBytes; }
+
/**
* transfer ownership of the memory to the caller. It must be freed with
* a call to GrFree()
@@ -38,19 +43,44 @@ public:
void* detach() {
void* ptr = fPtr;
fPtr = NULL; // we no longer own the block
+ fAllocatedBytes = 0;
return ptr;
}
-
+
+ /**
+ * Reallocates to a new size. May or may not call malloc. The contents
+ * are not preserved. If growOnly is true it will never reduce the
+ * allocated size.
+ */
+ void* realloc(size_t newSize, bool growOnly = false) {
+ bool alloc;
+ if (growOnly) {
+ alloc = newSize > fAllocatedBytes;
+ } else {
+ alloc = newSize != fAllocatedBytes;
+ }
+ if (alloc) {
+ GrFree(fPtr);
+ fPtr = newSize ? GrMalloc(newSize) : NULL;
+ fAllocatedBytes = newSize;
+ }
+ GrAssert(fAllocatedBytes >= newSize);
+ GR_DEBUGCODE(memset(fPtr, 0xEF, fAllocatedBytes));
+ return fPtr;
+ }
+
/**
* free the block now. get() will now return NULL
*/
void free() {
GrFree(fPtr);
fPtr = NULL;
+ fAllocatedBytes = 0;
}
private:
void* fPtr;
+ size_t fAllocatedBytes;
};
/**
@@ -86,10 +116,10 @@ public:
* detached.
*/
void* get() const { return fPtr; }
-
+
/**
- * Reallocates to a new size. May or may not call malloc. The contents
- * are not preserved. If growOnly is true it will never reduce the
+ * Reallocates to a new size. May or may not call malloc. The contents
+ * are not preserved. If growOnly is true it will never reduce the
* allocated size.
*/
void* realloc(size_t newSize, bool growOnly = false) {
@@ -101,7 +131,7 @@ public:
GrFree(fPtr);
fPtr = fStorage;
fAllocatedBytes = SIZE;
- }
+ }
} else if ((newSize > fAllocatedBytes) ||
(!growOnly && newSize < (fAllocatedBytes >> 1))) {
if (NULL != fPtr && fPtr != (void*)fStorage) {
@@ -115,7 +145,7 @@ public:
GR_DEBUGCODE(memset(fPtr, 0xEF, fAllocatedBytes));
return fPtr;
}
-
+
/**
* free the block now. get() will now return NULL
*/
@@ -126,7 +156,7 @@ public:
fAllocatedBytes = 0;
fPtr = NULL;
}
-
+
private:
void* fPtr;
uint32_t fAllocatedBytes;