Use different classes for client side arrays and GPU buffer objects.
GrBuffer is a base class for GrGpuBuffer and GrCpuBuffer. GrGpuBuffer is a
GrGpuResource and the others are not. This allows GrCpuBuffers to exist
outside of the GrGpuResourceCache.
Also removes flags from GrResourceProvider buffer factory function. The
only flag still in use was kRequireGpuMemory. Now CPU buffers are made
without using GrResourceProvider.
Change-Id: I82670d1316e28fd6331ca36b26c8c4ead33846f9
Reviewed-on: https://skia-review.googlesource.com/c/188823
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index d4ffc7c..b10c637 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -423,8 +423,7 @@
samplerState);
}
}
- int maxGlyphsPerDraw =
- static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6);
+ int maxGlyphsPerDraw = static_cast<int>(flushInfo->fIndexBuffer->size() / sizeof(uint16_t) / 6);
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
mesh->setIndexedPatterned(flushInfo->fIndexBuffer, kIndicesPerGlyph, kVerticesPerGlyph,
flushInfo->fGlyphsToFlush, maxGlyphsPerDraw);
diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp
index 2b368fe..660d640 100644
--- a/src/gpu/ops/GrDrawVerticesOp.cpp
+++ b/src/gpu/ops/GrDrawVerticesOp.cpp
@@ -227,7 +227,7 @@
// Allocate buffers.
size_t vertexStride = gp->vertexStride();
- sk_sp<const GrBuffer> vertexBuffer = nullptr;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex = 0;
void* verts = target->makeVertexSpace(vertexStride, fVertexCount, &vertexBuffer, &firstVertex);
if (!verts) {
@@ -235,7 +235,7 @@
return;
}
- sk_sp<const GrBuffer> indexBuffer = nullptr;
+ sk_sp<const GrBuffer> indexBuffer;
int firstIndex = 0;
uint16_t* indices = nullptr;
if (this->isIndexed()) {
@@ -286,10 +286,9 @@
indexKeyBuilder.finish();
// Try to grab data from the cache.
- sk_sp<GrBuffer> vertexBuffer = rp->findByUniqueKey<GrBuffer>(vertexKey);
- sk_sp<GrBuffer> indexBuffer = this->isIndexed() ?
- rp->findByUniqueKey<GrBuffer>(indexKey) :
- nullptr;
+ sk_sp<GrGpuBuffer> vertexBuffer = rp->findByUniqueKey<GrGpuBuffer>(vertexKey);
+ sk_sp<GrGpuBuffer> indexBuffer =
+ this->isIndexed() ? rp->findByUniqueKey<GrGpuBuffer>(indexKey) : nullptr;
// Draw using the cached buffers if possible.
if (vertexBuffer && (!this->isIndexed() || indexBuffer)) {
@@ -300,10 +299,8 @@
// Allocate vertex buffer.
size_t vertexStride = gp->vertexStride();
- vertexBuffer = rp->createBuffer(fVertexCount * vertexStride,
- GrGpuBufferType::kVertex,
- kStatic_GrAccessPattern,
- GrResourceProvider::Flags::kNone);
+ vertexBuffer = rp->createBuffer(
+ fVertexCount * vertexStride, GrGpuBufferType::kVertex, kStatic_GrAccessPattern);
void* verts = vertexBuffer ? vertexBuffer->map() : nullptr;
if (!verts) {
SkDebugf("Could not allocate vertices\n");
@@ -313,10 +310,8 @@
// Allocate index buffer.
uint16_t* indices = nullptr;
if (this->isIndexed()) {
- indexBuffer = rp->createBuffer(fIndexCount * sizeof(uint16_t),
- GrGpuBufferType::kIndex,
- kStatic_GrAccessPattern,
- GrResourceProvider::Flags::kNone);
+ indexBuffer = rp->createBuffer(
+ fIndexCount * sizeof(uint16_t), GrGpuBufferType::kIndex, kStatic_GrAccessPattern);
indices = indexBuffer ? static_cast<uint16_t*>(indexBuffer->map()) : nullptr;
if (!indices) {
SkDebugf("Could not allocate indices\n");
diff --git a/src/gpu/ops/GrMeshDrawOp.cpp b/src/gpu/ops/GrMeshDrawOp.cpp
index d467a6b..ac019f3 100644
--- a/src/gpu/ops/GrMeshDrawOp.cpp
+++ b/src/gpu/ops/GrMeshDrawOp.cpp
@@ -45,10 +45,10 @@
return;
}
SkASSERT(vertexBuffer);
- size_t ibSize = indexBuffer->gpuMemorySize();
+ size_t ibSize = indexBuffer->size();
int maxRepetitions = static_cast<int>(ibSize / (sizeof(uint16_t) * indicesPerRepetition));
fMesh = target->allocMesh(primitiveType);
- fMesh->setIndexedPatterned(indexBuffer, indicesPerRepetition, verticesPerRepetition,
+ fMesh->setIndexedPatterned(std::move(indexBuffer), indicesPerRepetition, verticesPerRepetition,
repeatCount, maxRepetitions);
fMesh->setVertexData(std::move(vertexBuffer), firstVertex);
}
@@ -62,7 +62,7 @@
//////////////////////////////////////////////////////////////////////////////
GrMeshDrawOp::QuadHelper::QuadHelper(Target* target, size_t vertexStride, int quadsToDraw) {
- sk_sp<const GrBuffer> quadIndexBuffer = target->resourceProvider()->refQuadIndexBuffer();
+ sk_sp<const GrGpuBuffer> quadIndexBuffer = target->resourceProvider()->refQuadIndexBuffer();
if (!quadIndexBuffer) {
SkDebugf("Could not get quad index buffer.");
return;
diff --git a/src/gpu/ops/GrMeshDrawOp.h b/src/gpu/ops/GrMeshDrawOp.h
index bba173d..170fee0 100644
--- a/src/gpu/ops/GrMeshDrawOp.h
+++ b/src/gpu/ops/GrMeshDrawOp.h
@@ -34,8 +34,9 @@
space for the vertices and flushes the draws to the GrMeshDrawOp::Target. */
class PatternHelper {
public:
- PatternHelper(Target*, GrPrimitiveType, size_t vertexStride, sk_sp<const GrBuffer>,
- int verticesPerRepetition, int indicesPerRepetition, int repeatCount);
+ PatternHelper(Target*, GrPrimitiveType, size_t vertexStride,
+ sk_sp<const GrBuffer> indexBuffer, int verticesPerRepetition,
+ int indicesPerRepetition, int repeatCount);
/** Called to issue draws to the GrMeshDrawOp::Target.*/
void recordDraw(Target*, sk_sp<const GrGeometryProcessor>, const GrPipeline*,
@@ -45,7 +46,7 @@
protected:
PatternHelper() = default;
- void init(Target*, GrPrimitiveType, size_t vertexStride, sk_sp<const GrBuffer>,
+ void init(Target*, GrPrimitiveType, size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
int verticesPerRepetition, int indicesPerRepetition, int repeatCount);
private:
diff --git a/src/gpu/ops/GrQuadPerEdgeAA.cpp b/src/gpu/ops/GrQuadPerEdgeAA.cpp
index 70caf55..de2641f 100644
--- a/src/gpu/ops/GrQuadPerEdgeAA.cpp
+++ b/src/gpu/ops/GrQuadPerEdgeAA.cpp
@@ -374,7 +374,7 @@
static const int kVertsPerAAFillRect = 8;
static const int kIndicesPerAAFillRect = 30;
-static sk_sp<const GrBuffer> get_index_buffer(GrResourceProvider* resourceProvider) {
+static sk_sp<const GrGpuBuffer> get_index_buffer(GrResourceProvider* resourceProvider) {
GR_DEFINE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey);
// clang-format off
@@ -467,7 +467,7 @@
int quadCount) {
if (spec.usesCoverageAA()) {
// AA quads use 8 vertices, basically nested rectangles
- sk_sp<const GrBuffer> ibuffer = get_index_buffer(target->resourceProvider());
+ sk_sp<const GrGpuBuffer> ibuffer = get_index_buffer(target->resourceProvider());
if (!ibuffer) {
return false;
}
@@ -478,7 +478,7 @@
} else {
// Non-AA quads use 4 vertices, and regular triangle strip layout
if (quadCount > 1) {
- sk_sp<const GrBuffer> ibuffer = target->resourceProvider()->refQuadIndexBuffer();
+ sk_sp<const GrGpuBuffer> ibuffer = target->resourceProvider()->refQuadIndexBuffer();
if (!ibuffer) {
return false;
}
diff --git a/src/gpu/ops/GrRegionOp.cpp b/src/gpu/ops/GrRegionOp.cpp
index 1725435..9db1fec 100644
--- a/src/gpu/ops/GrRegionOp.cpp
+++ b/src/gpu/ops/GrRegionOp.cpp
@@ -109,7 +109,7 @@
if (!numRects) {
return;
}
- sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
+ sk_sp<const GrGpuBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
if (!indexBuffer) {
SkDebugf("Could not allocate indices\n");
return;
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index 5132319..13bdec1 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -794,7 +794,7 @@
if (flushInfo->fInstancesToFlush) {
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
int maxInstancesPerDraw =
- static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6);
+ static_cast<int>(flushInfo->fIndexBuffer->size() / sizeof(uint16_t) / 6);
mesh->setIndexedPatterned(flushInfo->fIndexBuffer, kIndicesPerQuad, kVerticesPerQuad,
flushInfo->fInstancesToFlush, maxInstancesPerDraw);
mesh->setVertexData(flushInfo->fVertexBuffer, flushInfo->fVertexOffset);
diff --git a/src/gpu/ops/GrStrokeRectOp.cpp b/src/gpu/ops/GrStrokeRectOp.cpp
index 9495333..30242cc 100644
--- a/src/gpu/ops/GrStrokeRectOp.cpp
+++ b/src/gpu/ops/GrStrokeRectOp.cpp
@@ -420,7 +420,7 @@
static const int kBevelVertexCnt = 24;
static const int kNumBevelRectsInIndexBuffer = 256;
- static sk_sp<const GrBuffer> GetIndexBuffer(GrResourceProvider*, bool miterStroke);
+ static sk_sp<const GrGpuBuffer> GetIndexBuffer(GrResourceProvider*, bool miterStroke);
const SkMatrix& viewMatrix() const { return fViewMatrix; }
bool miterStroke() const { return fMiterStroke; }
@@ -472,7 +472,7 @@
int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIndexCnt;
int instanceCount = fRects.count();
- sk_sp<const GrBuffer> indexBuffer =
+ sk_sp<const GrGpuBuffer> indexBuffer =
GetIndexBuffer(target->resourceProvider(), this->miterStroke());
if (!indexBuffer) {
SkDebugf("Could not allocate indices\n");
@@ -503,8 +503,8 @@
helper.recordDraw(target, std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState);
}
-sk_sp<const GrBuffer> AAStrokeRectOp::GetIndexBuffer(GrResourceProvider* resourceProvider,
- bool miterStroke) {
+sk_sp<const GrGpuBuffer> AAStrokeRectOp::GetIndexBuffer(GrResourceProvider* resourceProvider,
+ bool miterStroke) {
if (miterStroke) {
// clang-format off
static const uint16_t gMiterIndices[] = {
diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp
index 0314e4a..c29b7bf 100644
--- a/src/gpu/ops/GrTessellatingPathRenderer.cpp
+++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp
@@ -53,7 +53,7 @@
}
};
-bool cache_match(GrBuffer* vertexBuffer, SkScalar tol, int* actualCount) {
+bool cache_match(GrGpuBuffer* vertexBuffer, SkScalar tol, int* actualCount) {
if (!vertexBuffer) {
return false;
}
@@ -78,8 +78,7 @@
void* lock(int vertexCount) override {
size_t size = vertexCount * stride();
fVertexBuffer = fResourceProvider->createBuffer(size, GrGpuBufferType::kVertex,
- kStatic_GrAccessPattern,
- GrResourceProvider::Flags::kNone);
+ kStatic_GrAccessPattern);
if (!fVertexBuffer.get()) {
return nullptr;
}
@@ -99,10 +98,10 @@
}
fVertices = nullptr;
}
- sk_sp<GrBuffer> detachVertexBuffer() { return std::move(fVertexBuffer); }
+ sk_sp<GrGpuBuffer> detachVertexBuffer() { return std::move(fVertexBuffer); }
private:
- sk_sp<GrBuffer> fVertexBuffer;
+ sk_sp<GrGpuBuffer> fVertexBuffer;
GrResourceProvider* fResourceProvider;
bool fCanMapVB;
void* fVertices;
@@ -261,7 +260,7 @@
memset(&builder[shapeKeyDataCnt], 0, sizeof(fDevClipBounds));
}
builder.finish();
- sk_sp<GrBuffer> cachedVertexBuffer(rp->findByUniqueKey<GrBuffer>(key));
+ sk_sp<GrGpuBuffer> cachedVertexBuffer(rp->findByUniqueKey<GrGpuBuffer>(key));
int actualCount;
SkScalar tol = GrPathUtils::kDefaultTolerance;
tol = GrPathUtils::scaleToleranceToSrc(tol, fViewMatrix, fShape.bounds());
@@ -286,7 +285,7 @@
if (count == 0) {
return;
}
- sk_sp<GrBuffer> vb = allocator.detachVertexBuffer();
+ sk_sp<GrGpuBuffer> vb = allocator.detachVertexBuffer();
TessInfo info;
info.fTolerance = isLinear ? 0 : tol;
info.fCount = count;