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

Unified Diff: src/gpu/GrBufferAllocPool.cpp

Issue 1825393002: Consolidate GPU buffer implementations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: asserts Created 4 years, 9 months 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 | « src/gpu/GrBufferAllocPool.h ('k') | src/gpu/GrCaps.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrBufferAllocPool.cpp
diff --git a/src/gpu/GrBufferAllocPool.cpp b/src/gpu/GrBufferAllocPool.cpp
index 73b70bf86148b028bacbe02dde6ab5cb623b60b4..ac34b5cfcc1d1d53221ff4cd2b9f299475ba4900 100644
--- a/src/gpu/GrBufferAllocPool.cpp
+++ b/src/gpu/GrBufferAllocPool.cpp
@@ -8,13 +8,12 @@
#include "GrBufferAllocPool.h"
+#include "GrBuffer.h"
#include "GrCaps.h"
#include "GrContext.h"
#include "GrGpu.h"
-#include "GrIndexBuffer.h"
#include "GrResourceProvider.h"
#include "GrTypes.h"
-#include "GrVertexBuffer.h"
#include "SkTraceEvent.h"
@@ -41,7 +40,7 @@ do {
} while (false)
GrBufferAllocPool::GrBufferAllocPool(GrGpu* gpu,
- BufferType bufferType,
+ GrBufferType bufferType,
size_t blockSize)
: fBlocks(8) {
@@ -53,12 +52,12 @@ GrBufferAllocPool::GrBufferAllocPool(GrGpu* gpu,
fBytesInUse = 0;
- fGeometryBufferMapThreshold = gpu->caps()->geometryBufferMapThreshold();
+ fBufferMapThreshold = gpu->caps()->bufferMapThreshold();
}
void GrBufferAllocPool::deleteBlocks() {
if (fBlocks.count()) {
- GrGeometryBuffer* buffer = fBlocks.back().fBuffer;
+ GrBuffer* buffer = fBlocks.back().fBuffer;
if (buffer->isMapped()) {
UNMAP_BUFFER(fBlocks.back());
}
@@ -109,7 +108,7 @@ void GrBufferAllocPool::validate(bool unusedBlockAllowed) const {
if (fBufferPtr) {
SkASSERT(!fBlocks.empty());
if (fBlocks.back().fBuffer->isMapped()) {
- GrGeometryBuffer* buf = fBlocks.back().fBuffer;
+ GrBuffer* buf = fBlocks.back().fBuffer;
SkASSERT(buf->mapPtr() == fBufferPtr);
} else {
SkASSERT(fCpuData == fBufferPtr);
@@ -145,7 +144,7 @@ void GrBufferAllocPool::validate(bool unusedBlockAllowed) const {
void* GrBufferAllocPool::makeSpace(size_t size,
size_t alignment,
- const GrGeometryBuffer** buffer,
+ const GrBuffer** buffer,
size_t* offset) {
VALIDATE();
@@ -252,7 +251,7 @@ bool GrBufferAllocPool::createBlock(size_t requestSize) {
// threshold.
bool attemptMap = block.fBuffer->isCPUBacked();
if (!attemptMap && GrCaps::kNone_MapFlags != fGpu->caps()->mapBufferFlags()) {
- attemptMap = size > fGeometryBufferMapThreshold;
+ attemptMap = size > fBufferMapThreshold;
}
if (attemptMap) {
@@ -295,7 +294,7 @@ void* GrBufferAllocPool::resetCpuData(size_t newSize) {
void GrBufferAllocPool::flushCpuData(const BufferBlock& block, size_t flushSize) {
- GrGeometryBuffer* buffer = block.fBuffer;
+ GrBuffer* buffer = block.fBuffer;
SkASSERT(buffer);
SkASSERT(!buffer->isMapped());
SkASSERT(fCpuData == fBufferPtr);
@@ -303,7 +302,7 @@ void GrBufferAllocPool::flushCpuData(const BufferBlock& block, size_t flushSize)
VALIDATE(true);
if (GrCaps::kNone_MapFlags != fGpu->caps()->mapBufferFlags() &&
- flushSize > fGeometryBufferMapThreshold) {
+ flushSize > fBufferMapThreshold) {
void* data = buffer->map();
if (data) {
memcpy(data, fBufferPtr, flushSize);
@@ -315,30 +314,24 @@ void GrBufferAllocPool::flushCpuData(const BufferBlock& block, size_t flushSize)
VALIDATE(true);
}
-GrGeometryBuffer* GrBufferAllocPool::getBuffer(size_t size) {
+GrBuffer* GrBufferAllocPool::getBuffer(size_t size) {
GrResourceProvider* rp = fGpu->getContext()->resourceProvider();
- static const GrResourceProvider::BufferUsage kUsage = GrResourceProvider::kDynamic_BufferUsage;
// Shouldn't have to use this flag (https://bug.skia.org/4156)
static const uint32_t kFlags = GrResourceProvider::kNoPendingIO_Flag;
- if (kIndex_BufferType == fBufferType) {
- return rp->createIndexBuffer(size, kUsage, kFlags);
- } else {
- SkASSERT(kVertex_BufferType == fBufferType);
- return rp->createVertexBuffer(size, kUsage, kFlags);
- }
+ return rp->createBuffer(fBufferType, size, kDynamic_GrAccessPattern, kFlags);
}
////////////////////////////////////////////////////////////////////////////////
GrVertexBufferAllocPool::GrVertexBufferAllocPool(GrGpu* gpu)
- : GrBufferAllocPool(gpu, kVertex_BufferType, MIN_VERTEX_BUFFER_SIZE) {
+ : GrBufferAllocPool(gpu, kVertex_GrBufferType, MIN_VERTEX_BUFFER_SIZE) {
}
void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
int vertexCount,
- const GrVertexBuffer** buffer,
+ const GrBuffer** buffer,
int* startVertex) {
SkASSERT(vertexCount >= 0);
@@ -346,13 +339,11 @@ void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
SkASSERT(startVertex);
size_t offset = 0; // assign to suppress warning
- const GrGeometryBuffer* geomBuffer = nullptr; // assign to suppress warning
void* ptr = INHERITED::makeSpace(vertexSize * vertexCount,
vertexSize,
- &geomBuffer,
+ buffer,
&offset);
- *buffer = (const GrVertexBuffer*) geomBuffer;
SkASSERT(0 == offset % vertexSize);
*startVertex = static_cast<int>(offset / vertexSize);
return ptr;
@@ -361,11 +352,11 @@ void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
////////////////////////////////////////////////////////////////////////////////
GrIndexBufferAllocPool::GrIndexBufferAllocPool(GrGpu* gpu)
- : GrBufferAllocPool(gpu, kIndex_BufferType, MIN_INDEX_BUFFER_SIZE) {
+ : GrBufferAllocPool(gpu, kIndex_GrBufferType, MIN_INDEX_BUFFER_SIZE) {
}
void* GrIndexBufferAllocPool::makeSpace(int indexCount,
- const GrIndexBuffer** buffer,
+ const GrBuffer** buffer,
int* startIndex) {
SkASSERT(indexCount >= 0);
@@ -373,13 +364,11 @@ void* GrIndexBufferAllocPool::makeSpace(int indexCount,
SkASSERT(startIndex);
size_t offset = 0; // assign to suppress warning
- const GrGeometryBuffer* geomBuffer = nullptr; // assign to suppress warning
void* ptr = INHERITED::makeSpace(indexCount * sizeof(uint16_t),
sizeof(uint16_t),
- &geomBuffer,
+ buffer,
&offset);
- *buffer = (const GrIndexBuffer*) geomBuffer;
SkASSERT(0 == offset % sizeof(uint16_t));
*startIndex = static_cast<int>(offset / sizeof(uint16_t));
return ptr;
« no previous file with comments | « src/gpu/GrBufferAllocPool.h ('k') | src/gpu/GrCaps.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698