Use preallocated space for default vertex and index buffer sizes
Change-Id: I64450701f51621347f613251d082e159a04ec7b3
Reviewed-on: https://skia-review.googlesource.com/c/163720
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrBufferAllocPool.h b/src/gpu/GrBufferAllocPool.h
index 23759ca..9e502c6 100644
--- a/src/gpu/GrBufferAllocPool.h
+++ b/src/gpu/GrBufferAllocPool.h
@@ -31,6 +31,8 @@
*/
class GrBufferAllocPool : SkNoncopyable {
public:
+ static constexpr size_t kDefaultBufferSize = 1 << 15;
+
/**
* Ensures all buffers are unmapped and have all data written to them.
* Call before drawing using buffers from the pool.
@@ -53,15 +55,13 @@
*
* @param gpu The GrGpu used to create the buffers.
* @param bufferType The type of buffers to create.
- * @param bufferSize The minimum size of created buffers.
- * This value will be clamped to some
- * reasonable minimum.
+ * @param initialBuffer If non-null this should be a kDefaultBufferSize byte allocation.
+ * This parameter can be used to avoid malloc/free when all
+ * usages can be satisfied with default-sized buffers.
*/
- GrBufferAllocPool(GrGpu* gpu,
- GrBufferType bufferType,
- size_t bufferSize = 0);
+ GrBufferAllocPool(GrGpu* gpu, GrBufferType bufferType, void* initialBuffer);
- virtual ~GrBufferAllocPool();
+ virtual ~GrBufferAllocPool();
/**
* Returns a block of memory to hold data. A buffer designated to hold the
@@ -135,16 +135,15 @@
#ifdef SK_DEBUG
void validate(bool unusedBlockAllowed = false) const;
#endif
- size_t fBytesInUse;
+ size_t fBytesInUse = 0;
- GrGpu* fGpu;
- size_t fMinBlockSize;
- GrBufferType fBufferType;
-
- SkTArray<BufferBlock> fBlocks;
- void* fCpuData;
- void* fBufferPtr;
- size_t fBufferMapThreshold;
+ SkTArray<BufferBlock> fBlocks;
+ GrGpu* fGpu;
+ GrBufferType fBufferType;
+ void* fInitialCpuData = nullptr;
+ void* fCpuData = nullptr;
+ size_t fCpuDataSize = 0;
+ void* fBufferPtr = nullptr;
};
/**
@@ -156,8 +155,11 @@
* Constructor
*
* @param gpu The GrGpu used to create the vertex buffers.
+ * @param initialBuffer If non-null this should be a kDefaultBufferSize byte allocation.
+ * This parameter can be used to avoid malloc/free when all
+ * usages can be satisfied with default-sized buffers.
*/
- GrVertexBufferAllocPool(GrGpu* gpu);
+ GrVertexBufferAllocPool(GrGpu* gpu, void* initialBuffer);
/**
* Returns a block of memory to hold vertices. A buffer designated to hold
@@ -232,8 +234,11 @@
* Constructor
*
* @param gpu The GrGpu used to create the index buffers.
+ * @param initialBuffer If non-null this should be a kDefaultBufferSize byte allocation.
+ * This parameter can be used to avoid malloc/free when all
+ * usages can be satisfied with default-sized buffers.
*/
- GrIndexBufferAllocPool(GrGpu* gpu);
+ GrIndexBufferAllocPool(GrGpu* gpu, void* initialBuffer);
/**
* Returns a block of memory to hold indices. A buffer designated to hold