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

Unified Diff: src/gpu/GrAllocator.h

Issue 99833002: Delay setting initial memory block until it officially exists. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAllocator.h
diff --git a/src/gpu/GrAllocator.h b/src/gpu/GrAllocator.h
index 23bb6b76c9ddb4c83621fc10c36a66d16ab551fd..f2afec8e46787724d3bf53d561d1cd3191925b71 100755
--- a/src/gpu/GrAllocator.h
+++ b/src/gpu/GrAllocator.h
@@ -39,6 +39,22 @@ public:
SkDEBUGCODE(if (!fOwnFirstBlock) {*((char*)initialBlock+fBlockSize-1)='a';} );
}
+ /*
+ * Set first block of memory to write into. Must be called before any other methods.
+ * This requires that you have passed NULL in the constructor.
+ *
+ * @param initialBlock optional memory to use for the first block.
+ * Must be at least itemSize*itemsPerBlock sized.
+ * Caller is responsible for freeing this memory.
+ */
+ void setInitialBlock(void* initialBlock) {
+ SkASSERT(0 == fCount);
+ SkASSERT(1 == fBlocks.count());
+ SkASSERT(NULL == fBlocks.back());
+ fOwnFirstBlock = false;
+ fBlocks.back() = initialBlock;
+ }
+
/**
* Adds an item and returns pointer to it.
*
@@ -145,9 +161,6 @@ public:
* Create an allocator
*
* @param itemsPerBlock the number of items to allocate at once
- * @param initialBlock optional memory to use for the first block.
- * Must be at least size(T)*itemsPerBlock sized.
- * Caller is responsible for freeing this memory.
*/
explicit GrTAllocator(int itemsPerBlock)
: fAllocator(sizeof(T), itemsPerBlock, NULL) {}
@@ -223,8 +236,15 @@ public:
}
protected:
- GrTAllocator(int itemsPerBlock, void* initialBlock)
- : fAllocator(sizeof(T), itemsPerBlock, initialBlock) {
+ /*
+ * Set first block of memory to write into. Must be called before any other methods.
+ *
+ * @param initialBlock optional memory to use for the first block.
+ * Must be at least size(T)*itemsPerBlock sized.
+ * Caller is responsible for freeing this memory.
+ */
+ void setInitialBlock(void* initialBlock) {
+ fAllocator.setInitialBlock(initialBlock);
}
private:
@@ -237,7 +257,8 @@ private:
typedef GrTAllocator<T> INHERITED;
public:
- GrSTAllocator() : INHERITED(N, fStorage.get()) {
+ GrSTAllocator() : INHERITED(N) {
+ this->setInitialBlock(fStorage.get());
}
private:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698