aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrAllocator.h
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-02 22:32:58 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-02 22:32:58 +0000
commit845da77bc04de38e3c410ee1e26d9df70ab7d0ee (patch)
tree9777e641ac3ecbab0fd7a558d6050ae7a441b2d2 /src/gpu/GrAllocator.h
parentdd59799cf8eeb8e4263689e993a020b370d77991 (diff)
Delay setting initial memory block until it officially exists.
BUG=323017 R=robertphillips@google.com Author: mtklein@google.com Review URL: https://codereview.chromium.org/99833002 git-svn-id: http://skia.googlecode.com/svn/trunk@12446 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrAllocator.h')
-rwxr-xr-xsrc/gpu/GrAllocator.h33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/gpu/GrAllocator.h b/src/gpu/GrAllocator.h
index 23bb6b76c9..f2afec8e46 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: