aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Salomon <bsalomon@google.com>2019-01-29 14:38:50 -0500
committerSkia Commit-Bot <skia-commit-bot@chromium.org>2019-01-29 21:11:27 +0000
commit12d2264c26cd43beea34c5431526f5644c5db91b (patch)
tree8c12d8ff7e9e3ec87153ee6a8f19a0475bd04dd0
parent8f388ceadd79496a482c6a239e794f50ccde64c7 (diff)
downloadskqp-12d2264c26cd43beea34c5431526f5644c5db91b.tar.gz
Convert GrBuffer owners to sk_sp
Change-Id: Id49d775c30f01f4de05f385227c5ed5d90d6839e Reviewed-on: https://skia-review.googlesource.com/c/187920 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
-rw-r--r--bench/VertexColorSpaceBench.cpp4
-rw-r--r--gm/clockwise.cpp4
-rw-r--r--gm/fwidth_squircle.cpp4
-rw-r--r--samplecode/SampleCCPRGeometry.cpp4
-rw-r--r--src/gpu/GrBuffer.cpp6
-rw-r--r--src/gpu/GrBuffer.h5
-rw-r--r--src/gpu/GrBufferAllocPool.cpp32
-rw-r--r--src/gpu/GrBufferAllocPool.h23
-rw-r--r--src/gpu/GrGpu.cpp6
-rw-r--r--src/gpu/GrGpu.h8
-rw-r--r--src/gpu/GrMesh.h43
-rw-r--r--src/gpu/GrOpFlushState.cpp11
-rw-r--r--src/gpu/GrOpFlushState.h12
-rw-r--r--src/gpu/GrPendingIOResource.h15
-rw-r--r--src/gpu/GrResourceProvider.cpp12
-rw-r--r--src/gpu/GrResourceProvider.h5
-rw-r--r--src/gpu/ccpr/GrCCCoverageProcessor.h10
-rw-r--r--src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp4
-rw-r--r--src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp6
-rw-r--r--src/gpu/ccpr/GrCCFiller.cpp6
-rw-r--r--src/gpu/ccpr/GrCCPathProcessor.cpp8
-rw-r--r--src/gpu/ccpr/GrCCPerFlushResources.h15
-rw-r--r--src/gpu/ccpr/GrCCStroker.cpp8
-rw-r--r--src/gpu/gl/GrGLBuffer.cpp6
-rw-r--r--src/gpu/gl/GrGLBuffer.h4
-rw-r--r--src/gpu/gl/GrGLGpu.cpp15
-rw-r--r--src/gpu/gl/GrGLGpu.h4
-rw-r--r--src/gpu/mock/GrMockGpu.cpp6
-rw-r--r--src/gpu/mock/GrMockGpu.h4
-rw-r--r--src/gpu/mtl/GrMtlBuffer.h4
-rw-r--r--src/gpu/mtl/GrMtlBuffer.mm6
-rw-r--r--src/gpu/mtl/GrMtlCopyManager.mm4
-rw-r--r--src/gpu/mtl/GrMtlGpu.h2
-rw-r--r--src/gpu/mtl/GrMtlGpu.mm6
-rw-r--r--src/gpu/mtl/GrMtlPipelineState.h4
-rw-r--r--src/gpu/mtl/GrMtlPipelineState.mm12
-rw-r--r--src/gpu/mtl/GrMtlPipelineStateBuilder.mm16
-rw-r--r--src/gpu/ops/GrAAConvexPathRenderer.cpp4
-rw-r--r--src/gpu/ops/GrAAFillRRectOp.cpp4
-rw-r--r--src/gpu/ops/GrAAFillRRectOp.h2
-rw-r--r--src/gpu/ops/GrAAHairLinePathRenderer.cpp16
-rw-r--r--src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp8
-rw-r--r--src/gpu/ops/GrAtlasTextOp.cpp10
-rw-r--r--src/gpu/ops/GrDefaultPathRenderer.cpp11
-rw-r--r--src/gpu/ops/GrDrawVerticesOp.cpp37
-rw-r--r--src/gpu/ops/GrDrawVerticesOp.h4
-rw-r--r--src/gpu/ops/GrFillRectOp.cpp4
-rw-r--r--src/gpu/ops/GrLatticeOp.cpp10
-rw-r--r--src/gpu/ops/GrMeshDrawOp.cpp12
-rw-r--r--src/gpu/ops/GrMeshDrawOp.h12
-rw-r--r--src/gpu/ops/GrOvalOpFactory.cpp32
-rw-r--r--src/gpu/ops/GrQuadPerEdgeAA.cpp6
-rw-r--r--src/gpu/ops/GrRegionOp.cpp9
-rw-r--r--src/gpu/ops/GrShadowRRectOp.cpp8
-rw-r--r--src/gpu/ops/GrSmallPathRenderer.cpp11
-rw-r--r--src/gpu/ops/GrStrokeRectOp.cpp15
-rw-r--r--src/gpu/ops/GrTessellatingPathRenderer.cpp32
-rw-r--r--src/gpu/ops/GrTextureOp.cpp2
-rw-r--r--src/gpu/vk/GrVkBuffer.cpp7
-rw-r--r--src/gpu/vk/GrVkCopyManager.cpp2
-rw-r--r--src/gpu/vk/GrVkGpu.cpp36
-rw-r--r--src/gpu/vk/GrVkGpu.h4
-rw-r--r--src/gpu/vk/GrVkIndexBuffer.cpp4
-rw-r--r--src/gpu/vk/GrVkIndexBuffer.h2
-rw-r--r--src/gpu/vk/GrVkTransferBuffer.cpp6
-rw-r--r--src/gpu/vk/GrVkTransferBuffer.h2
-rw-r--r--src/gpu/vk/GrVkVertexBuffer.cpp4
-rw-r--r--src/gpu/vk/GrVkVertexBuffer.h2
-rw-r--r--tests/GrMeshTest.cpp23
-rw-r--r--tests/GrPipelineDynamicStateTest.cpp2
-rw-r--r--tests/OnFlushCallbackTest.cpp4
-rw-r--r--tests/TraceMemoryDumpTest.cpp4
72 files changed, 357 insertions, 338 deletions
diff --git a/bench/VertexColorSpaceBench.cpp b/bench/VertexColorSpaceBench.cpp
index c00a8065bf..278c4e0c7d 100644
--- a/bench/VertexColorSpaceBench.cpp
+++ b/bench/VertexColorSpaceBench.cpp
@@ -163,7 +163,7 @@ private:
size_t vertexStride = gp->vertexStride();
const int kVertexCount = 1024;
- const GrBuffer* vertexBuffer = nullptr;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex = 0;
void* verts = target->makeVertexSpace(vertexStride, kVertexCount, &vertexBuffer,
&firstVertex);
@@ -221,7 +221,7 @@ private:
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangleStrip);
mesh->setNonIndexedNonInstanced(kVertexCount);
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
auto pipe = target->makePipeline(0, GrProcessorSet::MakeEmptySet(),
target->detachAppliedClip());
target->draw(gp, pipe.fPipeline, pipe.fFixedDynamicState, mesh);
diff --git a/gm/clockwise.cpp b/gm/clockwise.cpp
index df1dcf1e55..608c12e473 100644
--- a/gm/clockwise.cpp
+++ b/gm/clockwise.cpp
@@ -115,7 +115,7 @@ private:
{0, fY},
{100, fY+100},
};
- sk_sp<GrBuffer> vertexBuffer(flushState->resourceProvider()->createBuffer(
+ sk_sp<const GrBuffer> vertexBuffer(flushState->resourceProvider()->createBuffer(
sizeof(vertices), kVertex_GrBufferType, kStatic_GrAccessPattern,
GrResourceProvider::Flags::kNone, vertices));
if (!vertexBuffer) {
@@ -125,7 +125,7 @@ private:
SkBlendMode::kPlus);
GrMesh mesh(GrPrimitiveType::kTriangleStrip);
mesh.setNonIndexedNonInstanced(4);
- mesh.setVertexData(vertexBuffer.get());
+ mesh.setVertexData(std::move(vertexBuffer));
flushState->rtCommandBuffer()->draw(ClockwiseTestProcessor(fReadSkFragCoord), pipeline,
nullptr, nullptr, &mesh, 1, SkRect::MakeIWH(100, 100));
}
diff --git a/gm/fwidth_squircle.cpp b/gm/fwidth_squircle.cpp
index 0d140e9619..e9aa9f84cc 100644
--- a/gm/fwidth_squircle.cpp
+++ b/gm/fwidth_squircle.cpp
@@ -140,7 +140,7 @@ private:
{-1, +1},
{+1, +1},
};
- sk_sp<GrBuffer> vertexBuffer(flushState->resourceProvider()->createBuffer(
+ sk_sp<const GrBuffer> vertexBuffer(flushState->resourceProvider()->createBuffer(
sizeof(vertices), kVertex_GrBufferType, kStatic_GrAccessPattern,
GrResourceProvider::Flags::kNone, vertices));
if (!vertexBuffer) {
@@ -150,7 +150,7 @@ private:
SkBlendMode::kSrcOver);
GrMesh mesh(GrPrimitiveType::kTriangleStrip);
mesh.setNonIndexedNonInstanced(4);
- mesh.setVertexData(vertexBuffer.get());
+ mesh.setVertexData(std::move(vertexBuffer));
flushState->rtCommandBuffer()->draw(FwidthSquircleTestProcessor(fViewMatrix), pipeline,
nullptr, nullptr, &mesh, 1, SkRect::MakeIWH(100, 100));
}
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp
index b2c546d4bb..6de506f656 100644
--- a/samplecode/SampleCCPRGeometry.cpp
+++ b/samplecode/SampleCCPRGeometry.cpp
@@ -349,7 +349,7 @@ void CCPRGeometryView::DrawCoverageCountOp::onExecute(GrOpFlushState* state,
GrResourceProvider::Flags::kRequireGpuMemory,
fView->fQuadPointInstances.begin()));
if (!fView->fQuadPointInstances.empty() && instBuff) {
- proc.appendMesh(instBuff.get(), fView->fQuadPointInstances.count(), 0, &mesh);
+ proc.appendMesh(std::move(instBuff), fView->fQuadPointInstances.count(), 0, &mesh);
}
} else {
sk_sp<GrBuffer> instBuff(rp->createBuffer(
@@ -358,7 +358,7 @@ void CCPRGeometryView::DrawCoverageCountOp::onExecute(GrOpFlushState* state,
GrResourceProvider::Flags::kNoPendingIO |
GrResourceProvider::Flags::kRequireGpuMemory, fView->fTriPointInstances.begin()));
if (!fView->fTriPointInstances.empty() && instBuff) {
- proc.appendMesh(instBuff.get(), fView->fTriPointInstances.count(), 0, &mesh);
+ proc.appendMesh(std::move(instBuff), fView->fTriPointInstances.count(), 0, &mesh);
}
}
diff --git a/src/gpu/GrBuffer.cpp b/src/gpu/GrBuffer.cpp
index cd7862a226..25e7ab08b6 100644
--- a/src/gpu/GrBuffer.cpp
+++ b/src/gpu/GrBuffer.cpp
@@ -9,8 +9,8 @@
#include "GrGpu.h"
#include "GrCaps.h"
-GrBuffer* GrBuffer::CreateCPUBacked(GrGpu* gpu, size_t sizeInBytes, GrBufferType intendedType,
- const void* data) {
+sk_sp<GrBuffer> GrBuffer::MakeCPUBacked(GrGpu* gpu, size_t sizeInBytes, GrBufferType intendedType,
+ const void* data) {
SkASSERT(GrBufferTypeIsVertexOrIndex(intendedType));
void* cpuData;
if (gpu->caps()->mustClearUploadedBufferData()) {
@@ -21,7 +21,7 @@ GrBuffer* GrBuffer::CreateCPUBacked(GrGpu* gpu, size_t sizeInBytes, GrBufferType
if (data) {
memcpy(cpuData, data, sizeInBytes);
}
- return new GrBuffer(gpu, sizeInBytes, intendedType, cpuData);
+ return sk_sp<GrBuffer>(new GrBuffer(gpu, sizeInBytes, intendedType, cpuData));
}
GrBuffer::GrBuffer(GrGpu* gpu, size_t sizeInBytes, GrBufferType type, void* cpuData)
diff --git a/src/gpu/GrBuffer.h b/src/gpu/GrBuffer.h
index db9b1aee36..8b0d551176 100644
--- a/src/gpu/GrBuffer.h
+++ b/src/gpu/GrBuffer.h
@@ -17,8 +17,9 @@ public:
/**
* Creates a client-side buffer.
*/
- static SK_WARN_UNUSED_RESULT GrBuffer* CreateCPUBacked(GrGpu*, size_t sizeInBytes, GrBufferType,
- const void* data = nullptr);
+ static SK_WARN_UNUSED_RESULT sk_sp<GrBuffer> MakeCPUBacked(GrGpu*, size_t sizeInBytes,
+ GrBufferType,
+ const void* data = nullptr);
/**
* Computes a scratch key for a GPU-side buffer with a "dynamic" access pattern. (Buffers with
diff --git a/src/gpu/GrBufferAllocPool.cpp b/src/gpu/GrBufferAllocPool.cpp
index 65dc01f656..1349d886a5 100644
--- a/src/gpu/GrBufferAllocPool.cpp
+++ b/src/gpu/GrBufferAllocPool.cpp
@@ -46,7 +46,7 @@ GrBufferAllocPool::GrBufferAllocPool(GrGpu* gpu, GrBufferType bufferType, void*
void GrBufferAllocPool::deleteBlocks() {
if (fBlocks.count()) {
- GrBuffer* buffer = fBlocks.back().fBuffer;
+ GrBuffer* buffer = fBlocks.back().fBuffer.get();
if (buffer->isMapped()) {
UNMAP_BUFFER(fBlocks.back());
}
@@ -128,7 +128,7 @@ void GrBufferAllocPool::validate(bool unusedBlockAllowed) const {
void* GrBufferAllocPool::makeSpace(size_t size,
size_t alignment,
- const GrBuffer** buffer,
+ sk_sp<const GrBuffer>* buffer,
size_t* offset) {
VALIDATE();
@@ -181,7 +181,7 @@ void* GrBufferAllocPool::makeSpace(size_t size,
void* GrBufferAllocPool::makeSpaceAtLeast(size_t minSize,
size_t fallbackSize,
size_t alignment,
- const GrBuffer** buffer,
+ sk_sp<const GrBuffer>* buffer,
size_t* offset,
size_t* actualSize) {
VALIDATE();
@@ -321,11 +321,7 @@ bool GrBufferAllocPool::createBlock(size_t requestSize) {
void GrBufferAllocPool::destroyBlock() {
SkASSERT(!fBlocks.empty());
-
- BufferBlock& block = fBlocks.back();
-
- SkASSERT(!block.fBuffer->isMapped());
- block.fBuffer->unref();
+ SkASSERT(!fBlocks.back().fBuffer->isMapped());
fBlocks.pop_back();
fBufferPtr = nullptr;
}
@@ -349,7 +345,7 @@ void* GrBufferAllocPool::resetCpuData(size_t newSize) {
void GrBufferAllocPool::flushCpuData(const BufferBlock& block, size_t flushSize) {
- GrBuffer* buffer = block.fBuffer;
+ GrBuffer* buffer = block.fBuffer.get();
SkASSERT(buffer);
SkASSERT(!buffer->isMapped());
SkASSERT(fCpuData == fBufferPtr);
@@ -369,8 +365,7 @@ void GrBufferAllocPool::flushCpuData(const BufferBlock& block, size_t flushSize)
VALIDATE(true);
}
-GrBuffer* GrBufferAllocPool::getBuffer(size_t size) {
-
+sk_sp<GrBuffer> GrBufferAllocPool::getBuffer(size_t size) {
auto resourceProvider = fGpu->getContext()->contextPriv().resourceProvider();
// Shouldn't have to use this flag (https://bug.skia.org/4156)
@@ -385,9 +380,8 @@ GrVertexBufferAllocPool::GrVertexBufferAllocPool(GrGpu* gpu, void* initialCpuBuf
void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
int vertexCount,
- const GrBuffer** buffer,
+ sk_sp<const GrBuffer>* buffer,
int* startVertex) {
-
SkASSERT(vertexCount >= 0);
SkASSERT(buffer);
SkASSERT(startVertex);
@@ -404,9 +398,9 @@ void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
}
void* GrVertexBufferAllocPool::makeSpaceAtLeast(size_t vertexSize, int minVertexCount,
- int fallbackVertexCount, const GrBuffer** buffer,
- int* startVertex, int* actualVertexCount) {
-
+ int fallbackVertexCount,
+ sk_sp<const GrBuffer>* buffer, int* startVertex,
+ int* actualVertexCount) {
SkASSERT(minVertexCount >= 0);
SkASSERT(fallbackVertexCount >= minVertexCount);
SkASSERT(buffer);
@@ -437,10 +431,8 @@ void* GrVertexBufferAllocPool::makeSpaceAtLeast(size_t vertexSize, int minVertex
GrIndexBufferAllocPool::GrIndexBufferAllocPool(GrGpu* gpu, void* initialCpuBuffer)
: GrBufferAllocPool(gpu, kIndex_GrBufferType, initialCpuBuffer) {}
-void* GrIndexBufferAllocPool::makeSpace(int indexCount,
- const GrBuffer** buffer,
+void* GrIndexBufferAllocPool::makeSpace(int indexCount, sk_sp<const GrBuffer>* buffer,
int* startIndex) {
-
SkASSERT(indexCount >= 0);
SkASSERT(buffer);
SkASSERT(startIndex);
@@ -457,7 +449,7 @@ void* GrIndexBufferAllocPool::makeSpace(int indexCount,
}
void* GrIndexBufferAllocPool::makeSpaceAtLeast(int minIndexCount, int fallbackIndexCount,
- const GrBuffer** buffer, int* startIndex,
+ sk_sp<const GrBuffer>* buffer, int* startIndex,
int* actualIndexCount) {
SkASSERT(minIndexCount >= 0);
SkASSERT(fallbackIndexCount >= minIndexCount);
diff --git a/src/gpu/GrBufferAllocPool.h b/src/gpu/GrBufferAllocPool.h
index 9e502c6047..ca1a896d67 100644
--- a/src/gpu/GrBufferAllocPool.h
+++ b/src/gpu/GrBufferAllocPool.h
@@ -82,10 +82,7 @@ protected:
* @param offset returns the offset into buffer of the data.
* @return pointer to where the client should write the data.
*/
- void* makeSpace(size_t size,
- size_t alignment,
- const GrBuffer** buffer,
- size_t* offset);
+ void* makeSpace(size_t size, size_t alignment, sk_sp<const GrBuffer>* buffer, size_t* offset);
/**
* Returns a block of memory to hold data. A buffer designated to hold the
@@ -115,16 +112,16 @@ protected:
void* makeSpaceAtLeast(size_t minSize,
size_t fallbackSize,
size_t alignment,
- const GrBuffer** buffer,
+ sk_sp<const GrBuffer>* buffer,
size_t* offset,
size_t* actualSize);
- GrBuffer* getBuffer(size_t size);
+ sk_sp<GrBuffer> getBuffer(size_t size);
private:
struct BufferBlock {
- size_t fBytesFree;
- GrBuffer* fBuffer;
+ size_t fBytesFree;
+ sk_sp<GrBuffer> fBuffer;
};
bool createBlock(size_t requestSize);
@@ -184,7 +181,7 @@ public:
*/
void* makeSpace(size_t vertexSize,
int vertexCount,
- const GrBuffer** buffer,
+ sk_sp<const GrBuffer>* buffer,
int* startVertex);
/**
@@ -217,7 +214,7 @@ public:
void* makeSpaceAtLeast(size_t vertexSize,
int minVertexCount,
int fallbackVertexCount,
- const GrBuffer** buffer,
+ sk_sp<const GrBuffer>* buffer,
int* startVertex,
int* actualVertexCount);
@@ -258,9 +255,7 @@ public:
* @param startIndex returns the offset into buffer of the first index.
* @return pointer to first index.
*/
- void* makeSpace(int indexCount,
- const GrBuffer** buffer,
- int* startIndex);
+ void* makeSpace(int indexCount, sk_sp<const GrBuffer>* buffer, int* startIndex);
/**
* Returns a block of memory to hold indices. A buffer designated to hold
@@ -289,7 +284,7 @@ public:
*/
void* makeSpaceAtLeast(int minIndexCount,
int fallbackIndexCount,
- const GrBuffer** buffer,
+ sk_sp<const GrBuffer>* buffer,
int* startIndex,
int* actualIndexCount);
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 260ba29ac2..af801cac89 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -217,10 +217,10 @@ sk_sp<GrRenderTarget> GrGpu::onWrapVulkanSecondaryCBAsRenderTarget(const SkImage
return nullptr;
}
-GrBuffer* GrGpu::createBuffer(size_t size, GrBufferType intendedType,
- GrAccessPattern accessPattern, const void* data) {
+sk_sp<GrBuffer> GrGpu::createBuffer(size_t size, GrBufferType intendedType,
+ GrAccessPattern accessPattern, const void* data) {
this->handleDirtyContext();
- GrBuffer* buffer = this->onCreateBuffer(size, intendedType, accessPattern, data);
+ sk_sp<GrBuffer> buffer = this->onCreateBuffer(size, intendedType, accessPattern, data);
if (!this->caps()->reuseScratchBuffers()) {
buffer->resourcePriv().removeScratchKey();
}
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 04a34f728f..64e1978aa1 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -140,8 +140,8 @@ public:
*
* @return the buffer if successful, otherwise nullptr.
*/
- GrBuffer* createBuffer(size_t size, GrBufferType intendedType, GrAccessPattern accessPattern,
- const void* data = nullptr);
+ sk_sp<GrBuffer> createBuffer(size_t size, GrBufferType intendedType,
+ GrAccessPattern accessPattern, const void* data = nullptr);
/**
* Resolves MSAA.
@@ -467,8 +467,8 @@ private:
virtual sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&);
- virtual GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
- const void* data) = 0;
+ virtual sk_sp<GrBuffer> onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
+ const void* data) = 0;
// overridden by backend-specific derived class to perform the surface read
virtual bool onReadPixels(GrSurface*, int left, int top, int width, int height, GrColorType,
diff --git a/src/gpu/GrMesh.h b/src/gpu/GrMesh.h
index e8a3f5cec3..b2c72f896d 100644
--- a/src/gpu/GrMesh.h
+++ b/src/gpu/GrMesh.h
@@ -35,18 +35,17 @@ public:
void setNonIndexedNonInstanced(int vertexCount);
- void setIndexed(const GrBuffer* indexBuffer, int indexCount, int baseIndex,
+ void setIndexed(sk_sp<const GrBuffer> indexBuffer, int indexCount, int baseIndex,
uint16_t minIndexValue, uint16_t maxIndexValue, GrPrimitiveRestart);
- void setIndexedPatterned(const GrBuffer* indexBuffer, int indexCount, int vertexCount,
+ void setIndexedPatterned(sk_sp<const GrBuffer> indexBuffer, int indexCount, int vertexCount,
int patternRepeatCount, int maxPatternRepetitionsInIndexBuffer);
- void setInstanced(const GrBuffer* instanceBuffer, int instanceCount, int baseInstance,
+ void setInstanced(sk_sp<const GrBuffer> instanceBuffer, int instanceCount, int baseInstance,
int vertexCount);
- void setIndexedInstanced(const GrBuffer* indexBuffer, int indexCount,
- const GrBuffer* instanceBuffer, int instanceCount, int baseInstance,
- GrPrimitiveRestart);
+ void setIndexedInstanced(sk_sp<const GrBuffer>, int indexCount, sk_sp<const GrBuffer>,
+ int instanceCount, int baseInstance, GrPrimitiveRestart);
- void setVertexData(const GrBuffer* vertexBuffer, int baseVertex = 0);
+ void setVertexData(sk_sp<const GrBuffer> vertexBuffer, int baseVertex = 0);
class SendToGpuImpl {
public:
@@ -136,15 +135,15 @@ inline void GrMesh::setNonIndexedNonInstanced(int vertexCount) {
fPrimitiveRestart = GrPrimitiveRestart::kNo;
}
-inline void GrMesh::setIndexed(const GrBuffer* indexBuffer, int indexCount, int baseIndex,
+inline void GrMesh::setIndexed(sk_sp<const GrBuffer> indexBuffer, int indexCount, int baseIndex,
uint16_t minIndexValue, uint16_t maxIndexValue,
GrPrimitiveRestart primitiveRestart) {
SkASSERT(indexBuffer);
SkASSERT(indexCount >= 1);
SkASSERT(baseIndex >= 0);
SkASSERT(maxIndexValue >= minIndexValue);
- fIndexBuffer.reset(indexBuffer);
- fInstanceBuffer.reset(nullptr);
+ fIndexBuffer = std::move(indexBuffer);
+ fInstanceBuffer.reset();
fIndexData.fIndexCount = indexCount;
fIndexData.fPatternRepeatCount = 0;
fNonPatternIndexData.fBaseIndex = baseIndex;
@@ -153,7 +152,7 @@ inline void GrMesh::setIndexed(const GrBuffer* indexBuffer, int indexCount, int
fPrimitiveRestart = primitiveRestart;
}
-inline void GrMesh::setIndexedPatterned(const GrBuffer* indexBuffer, int indexCount,
+inline void GrMesh::setIndexedPatterned(sk_sp<const GrBuffer> indexBuffer, int indexCount,
int vertexCount, int patternRepeatCount,
int maxPatternRepetitionsInIndexBuffer) {
SkASSERT(indexBuffer);
@@ -161,8 +160,8 @@ inline void GrMesh::setIndexedPatterned(const GrBuffer* indexBuffer, int indexCo
SkASSERT(vertexCount >= 1);
SkASSERT(patternRepeatCount >= 1);
SkASSERT(maxPatternRepetitionsInIndexBuffer >= 1);
- fIndexBuffer.reset(indexBuffer);
- fInstanceBuffer.reset(nullptr);
+ fIndexBuffer = std::move(indexBuffer);
+ fInstanceBuffer.reset();
fIndexData.fIndexCount = indexCount;
fIndexData.fPatternRepeatCount = patternRepeatCount;
fPatternData.fVertexCount = vertexCount;
@@ -170,38 +169,38 @@ inline void GrMesh::setIndexedPatterned(const GrBuffer* indexBuffer, int indexCo
fPrimitiveRestart = GrPrimitiveRestart::kNo;
}
-inline void GrMesh::setInstanced(const GrBuffer* instanceBuffer, int instanceCount,
+inline void GrMesh::setInstanced(sk_sp<const GrBuffer> instanceBuffer, int instanceCount,
int baseInstance, int vertexCount) {
SkASSERT(instanceBuffer);
SkASSERT(instanceCount >= 1);
SkASSERT(baseInstance >= 0);
- fIndexBuffer.reset(nullptr);
- fInstanceBuffer.reset(instanceBuffer);
+ fIndexBuffer.reset();
+ fInstanceBuffer = std::move(instanceBuffer);
fInstanceData.fInstanceCount = instanceCount;
fInstanceData.fBaseInstance = baseInstance;
fInstanceNonIndexData.fVertexCount = vertexCount;
fPrimitiveRestart = GrPrimitiveRestart::kNo;
}
-inline void GrMesh::setIndexedInstanced(const GrBuffer* indexBuffer, int indexCount,
- const GrBuffer* instanceBuffer, int instanceCount,
+inline void GrMesh::setIndexedInstanced(sk_sp<const GrBuffer> indexBuffer, int indexCount,
+ sk_sp<const GrBuffer> instanceBuffer, int instanceCount,
int baseInstance, GrPrimitiveRestart primitiveRestart) {
SkASSERT(indexBuffer);
SkASSERT(indexCount >= 1);
SkASSERT(instanceBuffer);
SkASSERT(instanceCount >= 1);
SkASSERT(baseInstance >= 0);
- fIndexBuffer.reset(indexBuffer);
- fInstanceBuffer.reset(instanceBuffer);
+ fIndexBuffer = std::move(indexBuffer);
+ fInstanceBuffer = std::move(instanceBuffer);
fInstanceData.fInstanceCount = instanceCount;
fInstanceData.fBaseInstance = baseInstance;
fInstanceIndexData.fIndexCount = indexCount;
fPrimitiveRestart = primitiveRestart;
}
-inline void GrMesh::setVertexData(const GrBuffer* vertexBuffer, int baseVertex) {
+inline void GrMesh::setVertexData(sk_sp<const GrBuffer> vertexBuffer, int baseVertex) {
SkASSERT(baseVertex >= 0);
- fVertexBuffer.reset(vertexBuffer);
+ fVertexBuffer = std::move(vertexBuffer);
fBaseVertex = baseVertex;
}
diff --git a/src/gpu/GrOpFlushState.cpp b/src/gpu/GrOpFlushState.cpp
index 55328a135b..81920e697d 100644
--- a/src/gpu/GrOpFlushState.cpp
+++ b/src/gpu/GrOpFlushState.cpp
@@ -130,24 +130,25 @@ void GrOpFlushState::draw(sk_sp<const GrGeometryProcessor> gp, const GrPipeline*
}
}
-void* GrOpFlushState::makeVertexSpace(size_t vertexSize, int vertexCount, const GrBuffer** buffer,
- int* startVertex) {
+void* GrOpFlushState::makeVertexSpace(size_t vertexSize, int vertexCount,
+ sk_sp<const GrBuffer>* buffer, int* startVertex) {
return fVertexPool.makeSpace(vertexSize, vertexCount, buffer, startVertex);
}
-uint16_t* GrOpFlushState::makeIndexSpace(int indexCount, const GrBuffer** buffer, int* startIndex) {
+uint16_t* GrOpFlushState::makeIndexSpace(int indexCount, sk_sp<const GrBuffer>* buffer,
+ int* startIndex) {
return reinterpret_cast<uint16_t*>(fIndexPool.makeSpace(indexCount, buffer, startIndex));
}
void* GrOpFlushState::makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount,
- int fallbackVertexCount, const GrBuffer** buffer,
+ int fallbackVertexCount, sk_sp<const GrBuffer>* buffer,
int* startVertex, int* actualVertexCount) {
return fVertexPool.makeSpaceAtLeast(vertexSize, minVertexCount, fallbackVertexCount, buffer,
startVertex, actualVertexCount);
}
uint16_t* GrOpFlushState::makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount,
- const GrBuffer** buffer, int* startIndex,
+ sk_sp<const GrBuffer>* buffer, int* startIndex,
int* actualIndexCount) {
return reinterpret_cast<uint16_t*>(fIndexPool.makeSpaceAtLeast(
minIndexCount, fallbackIndexCount, buffer, startIndex, actualIndexCount));
diff --git a/src/gpu/GrOpFlushState.h b/src/gpu/GrOpFlushState.h
index 65c86445b5..c26ea68811 100644
--- a/src/gpu/GrOpFlushState.h
+++ b/src/gpu/GrOpFlushState.h
@@ -83,13 +83,15 @@ public:
const GrPipeline::DynamicStateArrays*,
const GrMesh[],
int meshCnt) final;
- void* makeVertexSpace(size_t vertexSize, int vertexCount, const GrBuffer**,
+ void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*,
int* startVertex) final;
- uint16_t* makeIndexSpace(int indexCount, const GrBuffer**, int* startIndex) final;
+ uint16_t* makeIndexSpace(int indexCount, sk_sp<const GrBuffer>*, int* startIndex) final;
void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount,
- const GrBuffer**, int* startVertex, int* actualVertexCount) final;
- uint16_t* makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount, const GrBuffer**,
- int* startIndex, int* actualIndexCount) final;
+ sk_sp<const GrBuffer>*, int* startVertex,
+ int* actualVertexCount) final;
+ uint16_t* makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount,
+ sk_sp<const GrBuffer>*, int* startIndex,
+ int* actualIndexCount) final;
void putBackIndices(int indexCount) final;
void putBackVertices(int vertices, size_t vertexStride) final;
GrRenderTargetProxy* proxy() const final { return fOpArgs->fProxy; }
diff --git a/src/gpu/GrPendingIOResource.h b/src/gpu/GrPendingIOResource.h
index 9aeb65a2d3..e56fa091b0 100644
--- a/src/gpu/GrPendingIOResource.h
+++ b/src/gpu/GrPendingIOResource.h
@@ -19,9 +19,16 @@
template <typename T, GrIOType IO_TYPE>
class GrPendingIOResource : SkNoncopyable {
public:
- GrPendingIOResource(T* resource = nullptr) : fResource(nullptr) { this->reset(resource); }
-
+ GrPendingIOResource() = default;
+ explicit GrPendingIOResource(T* resource) { this->reset(resource); }
+ GrPendingIOResource(sk_sp<T> resource) { *this = std::move(resource); }
GrPendingIOResource(const GrPendingIOResource& that) : GrPendingIOResource(that.get()) {}
+ ~GrPendingIOResource() { this->release(); }
+
+ GrPendingIOResource& operator=(sk_sp<T> resource) {
+ this->reset(resource.get());
+ return *this;
+ }
void reset(T* resource = nullptr) {
if (resource) {
@@ -42,8 +49,6 @@ public:
fResource = resource;
}
- ~GrPendingIOResource() { this->release(); }
-
explicit operator bool() const { return SkToBool(fResource); }
bool operator==(const GrPendingIOResource& other) const { return fResource == other.fResource; }
@@ -68,7 +73,7 @@ private:
}
}
- T* fResource;
+ T* fResource = nullptr;
};
#endif
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 3e7d2c7142..3f7ed3525e 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -360,9 +360,9 @@ sk_sp<GrPath> GrResourceProvider::createPath(const SkPath& path, const GrStyle&
return this->gpu()->pathRendering()->createPath(path, style);
}
-GrBuffer* GrResourceProvider::createBuffer(size_t size, GrBufferType intendedType,
- GrAccessPattern accessPattern, Flags flags,
- const void* data) {
+sk_sp<GrBuffer> GrResourceProvider::createBuffer(size_t size, GrBufferType intendedType,
+ GrAccessPattern accessPattern, Flags flags,
+ const void* data) {
if (this->isAbandoned()) {
return nullptr;
}
@@ -373,7 +373,7 @@ GrBuffer* GrResourceProvider::createBuffer(size_t size, GrBufferType intendedTyp
this->gpu()->caps()->preferClientSideDynamicBuffers() &&
GrBufferTypeIsVertexOrIndex(intendedType) &&
kDynamic_GrAccessPattern == accessPattern) {
- return GrBuffer::CreateCPUBacked(this->gpu(), size, intendedType, data);
+ return GrBuffer::MakeCPUBacked(this->gpu(), size, intendedType, data);
}
// bin by pow2 with a reasonable min
@@ -388,8 +388,8 @@ GrBuffer* GrResourceProvider::createBuffer(size_t size, GrBufferType intendedTyp
} else {
scratchFlags = GrResourceCache::ScratchFlags::kPreferNoPendingIO;
}
- GrBuffer* buffer = static_cast<GrBuffer*>(
- this->cache()->findAndRefScratchResource(key, allocSize, scratchFlags));
+ auto buffer = sk_sp<GrBuffer>(static_cast<GrBuffer*>(
+ this->cache()->findAndRefScratchResource(key, allocSize, scratchFlags)));
if (!buffer) {
buffer = this->gpu()->createBuffer(allocSize, intendedType, kDynamic_GrAccessPattern);
if (!buffer) {
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index 37d094c9cf..6803ddd44b 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -205,9 +205,8 @@ public:
*
* @return the buffer if successful, otherwise nullptr.
*/
- GrBuffer* createBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, Flags,
- const void* data = nullptr);
-
+ sk_sp<GrBuffer> createBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, Flags,
+ const void* data = nullptr);
/**
* If passed in render target already has a stencil buffer, return true. Otherwise attempt to
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor.h b/src/gpu/ccpr/GrCCCoverageProcessor.h
index 7650a8c791..5871fa15a0 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor.h
+++ b/src/gpu/ccpr/GrCCCoverageProcessor.h
@@ -100,12 +100,12 @@ public:
// Appends a GrMesh that will draw the provided instances. The instanceBuffer must be an array
// of either TriPointInstance or QuadPointInstance, depending on this processor's RendererPass,
// with coordinates in the desired shape's final atlas-space position.
- void appendMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance,
+ void appendMesh(sk_sp<GrBuffer> instanceBuffer, int instanceCount, int baseInstance,
SkTArray<GrMesh>* out) const {
if (Impl::kGeometryShader == fImpl) {
- this->appendGSMesh(instanceBuffer, instanceCount, baseInstance, out);
+ this->appendGSMesh(std::move(instanceBuffer), instanceCount, baseInstance, out);
} else {
- this->appendVSMesh(instanceBuffer, instanceCount, baseInstance, out);
+ this->appendVSMesh(std::move(instanceBuffer), instanceCount, baseInstance, out);
}
}
@@ -250,9 +250,9 @@ private:
void initGS();
void initVS(GrResourceProvider*);
- void appendGSMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance,
+ void appendGSMesh(sk_sp<const GrBuffer> instanceBuffer, int instanceCount, int baseInstance,
SkTArray<GrMesh>* out) const;
- void appendVSMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance,
+ void appendVSMesh(sk_sp<const GrBuffer> instanceBuffer, int instanceCount, int baseInstance,
SkTArray<GrMesh>* out) const;
GrGLSLPrimitiveProcessor* createGSImpl(std::unique_ptr<Shader>) const;
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp b/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp
index 1d79d007a1..e3fbb74fd1 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp
+++ b/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp
@@ -396,7 +396,7 @@ void GrCCCoverageProcessor::initGS() {
this->setWillUseGeoShader();
}
-void GrCCCoverageProcessor::appendGSMesh(GrBuffer* instanceBuffer, int instanceCount,
+void GrCCCoverageProcessor::appendGSMesh(sk_sp<const GrBuffer> instanceBuffer, int instanceCount,
int baseInstance, SkTArray<GrMesh>* out) const {
// GSImpl doesn't actually make instanced draw calls. Instead, we feed transposed x,y point
// values to the GPU in a regular vertex array and draw kLines (see initGS). Then, each vertex
@@ -405,7 +405,7 @@ void GrCCCoverageProcessor::appendGSMesh(GrBuffer* instanceBuffer, int instanceC
SkASSERT(Impl::kGeometryShader == fImpl);
GrMesh& mesh = out->emplace_back(GrPrimitiveType::kLines);
mesh.setNonIndexedNonInstanced(instanceCount * 2);
- mesh.setVertexData(instanceBuffer, baseInstance * 2);
+ mesh.setVertexData(std::move(instanceBuffer), baseInstance * 2);
}
GrGLSLPrimitiveProcessor* GrCCCoverageProcessor::createGSImpl(std::unique_ptr<Shader> shadr) const {
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp b/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp
index 1588a51cca..59fe5836a7 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp
+++ b/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp
@@ -527,14 +527,14 @@ void GrCCCoverageProcessor::initVS(GrResourceProvider* rp) {
}
}
-void GrCCCoverageProcessor::appendVSMesh(GrBuffer* instanceBuffer, int instanceCount,
+void GrCCCoverageProcessor::appendVSMesh(sk_sp<const GrBuffer> instanceBuffer, int instanceCount,
int baseInstance, SkTArray<GrMesh>* out) const {
SkASSERT(Impl::kVertexShader == fImpl);
GrMesh& mesh = out->emplace_back(fVSTriangleType);
auto primitiveRestart = GrPrimitiveRestart(GrPrimitiveType::kTriangleStrip == fVSTriangleType);
- mesh.setIndexedInstanced(fVSIndexBuffer.get(), fVSNumIndicesPerInstance, instanceBuffer,
+ mesh.setIndexedInstanced(fVSIndexBuffer, fVSNumIndicesPerInstance, std::move(instanceBuffer),
instanceCount, baseInstance, primitiveRestart);
- mesh.setVertexData(fVSVertexBuffer.get(), 0);
+ mesh.setVertexData(fVSVertexBuffer, 0);
}
GrGLSLPrimitiveProcessor* GrCCCoverageProcessor::createVSImpl(std::unique_ptr<Shader> shadr) const {
diff --git a/src/gpu/ccpr/GrCCFiller.cpp b/src/gpu/ccpr/GrCCFiller.cpp
index 146007711f..486a1a1414 100644
--- a/src/gpu/ccpr/GrCCFiller.cpp
+++ b/src/gpu/ccpr/GrCCFiller.cpp
@@ -519,7 +519,7 @@ void GrCCFiller::drawPrimitives(GrOpFlushState* flushState, const GrPipeline& pi
SkASSERT(instanceCount > 0);
int baseInstance = fBaseInstances[(int)GrScissorTest::kDisabled].*instanceType +
previousBatch.fEndNonScissorIndices.*instanceType;
- proc.appendMesh(fInstanceBuffer.get(), instanceCount, baseInstance, &fMeshesScratchBuffer);
+ proc.appendMesh(fInstanceBuffer, instanceCount, baseInstance, &fMeshesScratchBuffer);
fScissorRectScratchBuffer.push_back().setXYWH(0, 0, drawBounds.width(),
drawBounds.height());
SkDEBUGCODE(totalInstanceCount += instanceCount);
@@ -537,8 +537,8 @@ void GrCCFiller::drawPrimitives(GrOpFlushState* flushState, const GrPipeline& pi
continue;
}
SkASSERT(instanceCount > 0);
- proc.appendMesh(fInstanceBuffer.get(), instanceCount,
- baseScissorInstance + startIndex, &fMeshesScratchBuffer);
+ proc.appendMesh(fInstanceBuffer, instanceCount, baseScissorInstance + startIndex,
+ &fMeshesScratchBuffer);
fScissorRectScratchBuffer.push_back() = scissorSubBatch.fScissor;
SkDEBUGCODE(totalInstanceCount += instanceCount);
}
diff --git a/src/gpu/ccpr/GrCCPathProcessor.cpp b/src/gpu/ccpr/GrCCPathProcessor.cpp
index 8ea06bd7dc..81c57dde87 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.cpp
+++ b/src/gpu/ccpr/GrCCPathProcessor.cpp
@@ -130,10 +130,10 @@ void GrCCPathProcessor::drawPaths(GrOpFlushState* flushState, const GrPipeline&
GrMesh mesh(primitiveType);
auto enablePrimitiveRestart = GrPrimitiveRestart(flushState->caps().usePrimitiveRestart());
- mesh.setIndexedInstanced(resources.indexBuffer(), numIndicesPerInstance,
- resources.instanceBuffer(), endInstance - baseInstance, baseInstance,
- enablePrimitiveRestart);
- mesh.setVertexData(resources.vertexBuffer());
+ mesh.setIndexedInstanced(resources.refIndexBuffer(), numIndicesPerInstance,
+ resources.refInstanceBuffer(), endInstance - baseInstance,
+ baseInstance, enablePrimitiveRestart);
+ mesh.setVertexData(resources.refVertexBuffer());
flushState->rtCommandBuffer()->draw(*this, pipeline, fixedDynamicState, nullptr, &mesh, 1,
bounds);
diff --git a/src/gpu/ccpr/GrCCPerFlushResources.h b/src/gpu/ccpr/GrCCPerFlushResources.h
index f363c160ee..fc69cee0ec 100644
--- a/src/gpu/ccpr/GrCCPerFlushResources.h
+++ b/src/gpu/ccpr/GrCCPerFlushResources.h
@@ -105,9 +105,18 @@ public:
// Accessors used by draw calls, once the resources have been finalized.
const GrCCFiller& filler() const { SkASSERT(!this->isMapped()); return fFiller; }
const GrCCStroker& stroker() const { SkASSERT(!this->isMapped()); return fStroker; }
- const GrBuffer* indexBuffer() const { SkASSERT(!this->isMapped()); return fIndexBuffer.get(); }
- const GrBuffer* vertexBuffer() const { SkASSERT(!this->isMapped()); return fVertexBuffer.get();}
- GrBuffer* instanceBuffer() const { SkASSERT(!this->isMapped()); return fInstanceBuffer.get(); }
+ sk_sp<const GrBuffer> refIndexBuffer() const {
+ SkASSERT(!this->isMapped());
+ return fIndexBuffer;
+ }
+ sk_sp<const GrBuffer> refVertexBuffer() const {
+ SkASSERT(!this->isMapped());
+ return fVertexBuffer;
+ }
+ sk_sp<const GrBuffer> refInstanceBuffer() const {
+ SkASSERT(!this->isMapped());
+ return fInstanceBuffer;
+ }
private:
void recordCopyPathInstance(const GrCCPathCacheEntry&, const SkIVector& newAtlasOffset,
diff --git a/src/gpu/ccpr/GrCCStroker.cpp b/src/gpu/ccpr/GrCCStroker.cpp
index f836774067..a4905b37c5 100644
--- a/src/gpu/ccpr/GrCCStroker.cpp
+++ b/src/gpu/ccpr/GrCCStroker.cpp
@@ -735,7 +735,7 @@ void GrCCStroker::appendStrokeMeshesToBuffers(int numSegmentsLog2, const Batch&
SkASSERT(endIdx >= startIdx);
if (int instanceCount = endIdx - startIdx) {
GrMesh& mesh = fMeshesBuffer.emplace_back(GrPrimitiveType::kTriangleStrip);
- mesh.setInstanced(fInstanceBuffer.get(), instanceCount, baseInstance + startIdx,
+ mesh.setInstanced(fInstanceBuffer, instanceCount, baseInstance + startIdx,
numStripVertices);
fScissorsBuffer.push_back(drawBounds);
}
@@ -749,7 +749,7 @@ void GrCCStroker::appendStrokeMeshesToBuffers(int numSegmentsLog2, const Batch&
SkASSERT(endIdx >= startIdx);
if (int instanceCount = endIdx - startIdx) {
GrMesh& mesh = fMeshesBuffer.emplace_back(GrPrimitiveType::kTriangleStrip);
- mesh.setInstanced(fInstanceBuffer.get(), instanceCount, baseInstance + startIdx,
+ mesh.setInstanced(fInstanceBuffer, instanceCount, baseInstance + startIdx,
numStripVertices);
fScissorsBuffer.push_back(subBatch.fScissor);
startIdx = endIdx;
@@ -784,7 +784,7 @@ void GrCCStroker::drawConnectingGeometry(GrOpFlushState* flushState, const GrPip
int endIdx = batch.fNonScissorEndInstances->*InstanceType;
SkASSERT(endIdx >= startIdx);
if (int instanceCount = endIdx - startIdx) {
- processor.appendMesh(fInstanceBuffer.get(), instanceCount, baseInstance + startIdx,
+ processor.appendMesh(fInstanceBuffer, instanceCount, baseInstance + startIdx,
&fMeshesBuffer);
fScissorsBuffer.push_back(drawBounds);
}
@@ -797,7 +797,7 @@ void GrCCStroker::drawConnectingGeometry(GrOpFlushState* flushState, const GrPip
endIdx = subBatch.fEndInstances->*InstanceType;
SkASSERT(endIdx >= startIdx);
if (int instanceCount = endIdx - startIdx) {
- processor.appendMesh(fInstanceBuffer.get(), instanceCount, baseInstance + startIdx,
+ processor.appendMesh(fInstanceBuffer, instanceCount, baseInstance + startIdx,
&fMeshesBuffer);
fScissorsBuffer.push_back(subBatch.fScissor);
startIdx = endIdx;
diff --git a/src/gpu/gl/GrGLBuffer.cpp b/src/gpu/gl/GrGLBuffer.cpp
index 6f47bbb1dd..fdfc45ccd6 100644
--- a/src/gpu/gl/GrGLBuffer.cpp
+++ b/src/gpu/gl/GrGLBuffer.cpp
@@ -29,8 +29,8 @@
#define VALIDATE() do {} while(false)
#endif
-GrGLBuffer* GrGLBuffer::Create(GrGLGpu* gpu, size_t size, GrBufferType intendedType,
- GrAccessPattern accessPattern, const void* data) {
+sk_sp<GrGLBuffer> GrGLBuffer::Make(GrGLGpu* gpu, size_t size, GrBufferType intendedType,
+ GrAccessPattern accessPattern, const void* data) {
if (gpu->glCaps().transferBufferType() == GrGLCaps::kNone_TransferBufferType &&
(kXferCpuToGpu_GrBufferType == intendedType ||
kXferGpuToCpu_GrBufferType == intendedType)) {
@@ -41,7 +41,7 @@ GrGLBuffer* GrGLBuffer::Create(GrGLGpu* gpu, size_t size, GrBufferType intendedT
if (0 == buffer->bufferID()) {
return nullptr;
}
- return buffer.release();
+ return buffer;
}
// GL_STREAM_DRAW triggers an optimization in Chromium's GPU process where a client's vertex buffer
diff --git a/src/gpu/gl/GrGLBuffer.h b/src/gpu/gl/GrGLBuffer.h
index 3400819a5d..889c4e9b7f 100644
--- a/src/gpu/gl/GrGLBuffer.h
+++ b/src/gpu/gl/GrGLBuffer.h
@@ -16,8 +16,8 @@ class GrGLCaps;
class GrGLBuffer : public GrBuffer {
public:
- static GrGLBuffer* Create(GrGLGpu*, size_t size, GrBufferType intendedType, GrAccessPattern,
- const void* data = nullptr);
+ static sk_sp<GrGLBuffer> Make(GrGLGpu*, size_t size, GrBufferType intendedType, GrAccessPattern,
+ const void* data = nullptr);
~GrGLBuffer() override {
// either release or abandon should have been called by the owner of this object.
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 94cdfe2be5..bccf8f3066 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -1856,9 +1856,9 @@ GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen
// objects are implemented as client-side-arrays on tile-deferred architectures.
#define DYNAMIC_USAGE_PARAM GR_GL_STREAM_DRAW
-GrBuffer* GrGLGpu::onCreateBuffer(size_t size, GrBufferType intendedType,
- GrAccessPattern accessPattern, const void* data) {
- return GrGLBuffer::Create(this, size, intendedType, accessPattern, data);
+sk_sp<GrBuffer> GrGLGpu::onCreateBuffer(size_t size, GrBufferType intendedType,
+ GrAccessPattern accessPattern, const void* data) {
+ return GrGLBuffer::Make(this, size, intendedType, accessPattern, data);
}
void GrGLGpu::flushScissor(const GrScissorState& scissorState,
@@ -3321,8 +3321,8 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
1, 0,
1, 1
};
- fCopyProgramArrayBuffer.reset(GrGLBuffer::Create(this, sizeof(vdata), kVertex_GrBufferType,
- kStatic_GrAccessPattern, vdata));
+ fCopyProgramArrayBuffer = GrGLBuffer::Make(this, sizeof(vdata), kVertex_GrBufferType,
+ kStatic_GrAccessPattern, vdata);
}
if (!fCopyProgramArrayBuffer) {
return false;
@@ -3809,9 +3809,8 @@ bool GrGLGpu::onRegenerateMipMapLevels(GrTexture* texture) {
1, 0,
1, 1
};
- fMipmapProgramArrayBuffer.reset(GrGLBuffer::Create(this, sizeof(vdata),
- kVertex_GrBufferType,
- kStatic_GrAccessPattern, vdata));
+ fMipmapProgramArrayBuffer = GrGLBuffer::Make(this, sizeof(vdata), kVertex_GrBufferType,
+ kStatic_GrAccessPattern, vdata);
}
if (!fMipmapProgramArrayBuffer) {
return false;
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 3a91ea27a4..4daf0241a5 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -186,8 +186,8 @@ private:
sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
const GrMipLevel texels[], int mipLevelCount) override;
- GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
- const void* data) override;
+ sk_sp<GrBuffer> onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
+ const void* data) override;
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
GrIOType) override;
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index 8ac7684657..b221eed28c 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -183,9 +183,9 @@ sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendTextureAsRenderTarget(const GrBack
new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc, rtInfo));
}
-GrBuffer* GrMockGpu::onCreateBuffer(size_t sizeInBytes, GrBufferType type,
- GrAccessPattern accessPattern, const void*) {
- return new GrMockBuffer(this, sizeInBytes, type, accessPattern);
+sk_sp<GrBuffer> GrMockGpu::onCreateBuffer(size_t sizeInBytes, GrBufferType type,
+ GrAccessPattern accessPattern, const void*) {
+ return sk_sp<GrBuffer>(new GrMockBuffer(this, sizeInBytes, type, accessPattern));
}
GrStencilAttachment* GrMockGpu::createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 2a79eb05a3..0a230d9969 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -72,8 +72,8 @@ private:
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
- GrBuffer* onCreateBuffer(size_t sizeInBytes, GrBufferType, GrAccessPattern,
- const void*) override;
+ sk_sp<GrBuffer> onCreateBuffer(size_t sizeInBytes, GrBufferType, GrAccessPattern,
+ const void*) override;
bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
void* buffer, size_t rowBytes) override {
diff --git a/src/gpu/mtl/GrMtlBuffer.h b/src/gpu/mtl/GrMtlBuffer.h
index 651cf1a059..e0c580b2b5 100644
--- a/src/gpu/mtl/GrMtlBuffer.h
+++ b/src/gpu/mtl/GrMtlBuffer.h
@@ -17,8 +17,8 @@ class GrMtlGpu;
class GrMtlBuffer: public GrBuffer {
public:
- static GrMtlBuffer* Create(GrMtlGpu*, size_t size, GrBufferType intendedType, GrAccessPattern,
- const void* data = nullptr);
+ static sk_sp<GrMtlBuffer> Make(GrMtlGpu*, size_t size, GrBufferType intendedType,
+ GrAccessPattern, const void* data = nullptr);
~GrMtlBuffer() override;
diff --git a/src/gpu/mtl/GrMtlBuffer.mm b/src/gpu/mtl/GrMtlBuffer.mm
index 0fb6cdc7c2..0e24da6964 100644
--- a/src/gpu/mtl/GrMtlBuffer.mm
+++ b/src/gpu/mtl/GrMtlBuffer.mm
@@ -16,8 +16,8 @@
#define VALIDATE() do {} while(false)
#endif
-GrMtlBuffer* GrMtlBuffer::Create(GrMtlGpu* gpu, size_t size, GrBufferType intendedType,
- GrAccessPattern accessPattern, const void* data) {
+sk_sp<GrMtlBuffer> GrMtlBuffer::Make(GrMtlGpu* gpu, size_t size, GrBufferType intendedType,
+ GrAccessPattern accessPattern, const void* data) {
// TODO: DrawIndirect buffers aren't actually supported yet because we don't have a way of
// uploading data to them.
SkASSERT(intendedType != kDrawIndirect_GrBufferType);
@@ -25,7 +25,7 @@ GrMtlBuffer* GrMtlBuffer::Create(GrMtlGpu* gpu, size_t size, GrBufferType intend
if (data && !buffer->onUpdateData(data, size)) {
return nullptr;
}
- return buffer.release();
+ return buffer;
}
GrMtlBuffer::GrMtlBuffer(GrMtlGpu* gpu, size_t size, GrBufferType intendedType,
diff --git a/src/gpu/mtl/GrMtlCopyManager.mm b/src/gpu/mtl/GrMtlCopyManager.mm
index 84f8f396ca..4a39452db0 100644
--- a/src/gpu/mtl/GrMtlCopyManager.mm
+++ b/src/gpu/mtl/GrMtlCopyManager.mm
@@ -29,8 +29,8 @@ void GrMtlCopyManager::createCopyProgramBuffer() {
{1, 0},
{1, 1},
};
- sk_sp<GrMtlBuffer> mtlBuffer(GrMtlBuffer::Create(fGpu, sizeof(vdata), kVertex_GrBufferType,
- kStatic_GrAccessPattern, vdata));
+ sk_sp<GrMtlBuffer> mtlBuffer = GrMtlBuffer::Make(fGpu, sizeof(vdata), kVertex_GrBufferType,
+ kStatic_GrAccessPattern, vdata);
fVertexAttributeBuffer = mtlBuffer->mtlBuffer();
}
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index 8ab60b7c19..ab6c46a0d8 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -143,7 +143,7 @@ private:
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
- GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override;
+ sk_sp<GrBuffer> onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override;
bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
void* buffer, size_t rowBytes) override;
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index c0273e4ef1..2350e0afa0 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -131,9 +131,9 @@ void GrMtlGpu::submitCommandBuffer(SyncQueue sync) {
fCmdBuffer = [fQueue commandBuffer];
}
-GrBuffer* GrMtlGpu::onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern accessPattern,
- const void* data) {
- return GrMtlBuffer::Create(this, size, type, accessPattern, data);
+sk_sp<GrBuffer> GrMtlGpu::onCreateBuffer(size_t size, GrBufferType type,
+ GrAccessPattern accessPattern, const void* data) {
+ return GrMtlBuffer::Make(this, size, type, accessPattern, data);
}
static bool check_max_blit_width(int widthInPixels) {
diff --git a/src/gpu/mtl/GrMtlPipelineState.h b/src/gpu/mtl/GrMtlPipelineState.h
index acc4e1c54a..a6afbdd427 100644
--- a/src/gpu/mtl/GrMtlPipelineState.h
+++ b/src/gpu/mtl/GrMtlPipelineState.h
@@ -37,8 +37,8 @@ public:
MTLPixelFormat pixelFormat,
const GrGLSLBuiltinUniformHandles& builtinUniformHandles,
const UniformInfoArray& uniforms,
- GrMtlBuffer* geometryUniformBuffer,
- GrMtlBuffer* fragmentUniformBuffer,
+ sk_sp<GrMtlBuffer> geometryUniformBuffer,
+ sk_sp<GrMtlBuffer> fragmentUniformBuffer,
uint32_t numSamplers,
std::unique_ptr<GrGLSLPrimitiveProcessor> geometryProcessor,
std::unique_ptr<GrGLSLXferProcessor> xferPRocessor,
diff --git a/src/gpu/mtl/GrMtlPipelineState.mm b/src/gpu/mtl/GrMtlPipelineState.mm
index 1d9562e10c..9eb36d0ae8 100644
--- a/src/gpu/mtl/GrMtlPipelineState.mm
+++ b/src/gpu/mtl/GrMtlPipelineState.mm
@@ -37,8 +37,8 @@ GrMtlPipelineState::GrMtlPipelineState(
MTLPixelFormat pixelFormat,
const GrGLSLBuiltinUniformHandles& builtinUniformHandles,
const UniformInfoArray& uniforms,
- GrMtlBuffer* geometryUniformBuffer,
- GrMtlBuffer* fragmentUniformBuffer,
+ sk_sp<GrMtlBuffer> geometryUniformBuffer,
+ sk_sp<GrMtlBuffer> fragmentUniformBuffer,
uint32_t numSamplers,
std::unique_ptr<GrGLSLPrimitiveProcessor> geometryProcessor,
std::unique_ptr<GrGLSLXferProcessor> xferProcessor,
@@ -48,15 +48,15 @@ GrMtlPipelineState::GrMtlPipelineState(
, fPipelineState(pipelineState)
, fPixelFormat(pixelFormat)
, fBuiltinUniformHandles(builtinUniformHandles)
- , fGeometryUniformBuffer(geometryUniformBuffer)
- , fFragmentUniformBuffer(fragmentUniformBuffer)
+ , fGeometryUniformBuffer(std::move(geometryUniformBuffer))
+ , fFragmentUniformBuffer(std::move(fragmentUniformBuffer))
, fNumSamplers(numSamplers)
, fGeometryProcessor(std::move(geometryProcessor))
, fXferProcessor(std::move(xferProcessor))
, fFragmentProcessors(std::move(fragmentProcessors))
, fFragmentProcessorCnt(fragmentProcessorCnt)
- , fDataManager(uniforms, geometryUniformBuffer->sizeInBytes(),
- fragmentUniformBuffer->sizeInBytes()) {
+ , fDataManager(uniforms, fGeometryUniformBuffer->sizeInBytes(),
+ fFragmentUniformBuffer->sizeInBytes()) {
(void) fPixelFormat; // Suppress unused-var warning.
}
diff --git a/src/gpu/mtl/GrMtlPipelineStateBuilder.mm b/src/gpu/mtl/GrMtlPipelineStateBuilder.mm
index 6954f105ef..add32ce393 100644
--- a/src/gpu/mtl/GrMtlPipelineStateBuilder.mm
+++ b/src/gpu/mtl/GrMtlPipelineStateBuilder.mm
@@ -362,14 +362,14 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(const GrPrimitiveProcess
pipelineDescriptor.colorAttachments[0].pixelFormat,
fUniformHandles,
fUniformHandler.fUniforms,
- GrMtlBuffer::Create(fGpu,
- fUniformHandler.fCurrentGeometryUBOOffset,
- kVertex_GrBufferType,
- kStatic_GrAccessPattern),
- GrMtlBuffer::Create(fGpu,
- fUniformHandler.fCurrentFragmentUBOOffset,
- kVertex_GrBufferType,
- kStatic_GrAccessPattern),
+ GrMtlBuffer::Make(fGpu,
+ fUniformHandler.fCurrentGeometryUBOOffset,
+ kVertex_GrBufferType,
+ kStatic_GrAccessPattern),
+ GrMtlBuffer::Make(fGpu,
+ fUniformHandler.fCurrentFragmentUBOOffset,
+ kVertex_GrBufferType,
+ kStatic_GrAccessPattern),
(uint32_t)fUniformHandler.numSamplers(),
std::move(fGeometryProcessor),
std::move(fXferProcessor),
diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp
index 8d7316e0cd..39a8d5fe86 100644
--- a/src/gpu/ops/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp
@@ -761,7 +761,7 @@ private:
continue;
}
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
GrVertexWriter verts{target->makeVertexSpace(kVertexStride, vertexCount,
@@ -772,7 +772,7 @@ private:
return;
}
- const GrBuffer* indexBuffer;
+ sk_sp<const GrBuffer> indexBuffer;
int firstIndex;
uint16_t *idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
diff --git a/src/gpu/ops/GrAAFillRRectOp.cpp b/src/gpu/ops/GrAAFillRRectOp.cpp
index 513c15ba2b..351f518333 100644
--- a/src/gpu/ops/GrAAFillRRectOp.cpp
+++ b/src/gpu/ops/GrAAFillRRectOp.cpp
@@ -469,9 +469,9 @@ void GrAAFillRRectOp::onExecute(GrOpFlushState* flushState, const SkRect& chainB
GrPipeline pipeline(initArgs, std::move(fProcessors), std::move(clip));
GrMesh mesh(GrPrimitiveType::kTriangles);
- mesh.setIndexedInstanced(indexBuffer.get(), SK_ARRAY_COUNT(kIndexData), fInstanceBuffer,
+ mesh.setIndexedInstanced(std::move(indexBuffer), SK_ARRAY_COUNT(kIndexData), fInstanceBuffer,
fInstanceCount, fBaseInstance, GrPrimitiveRestart::kNo);
- mesh.setVertexData(vertexBuffer.get());
+ mesh.setVertexData(std::move(vertexBuffer));
flushState->rtCommandBuffer()->draw(proc, pipeline, &fixedDynamicState, nullptr, &mesh, 1,
this->bounds());
}
diff --git a/src/gpu/ops/GrAAFillRRectOp.h b/src/gpu/ops/GrAAFillRRectOp.h
index b934fb01cb..cb29b91ad9 100644
--- a/src/gpu/ops/GrAAFillRRectOp.h
+++ b/src/gpu/ops/GrAAFillRRectOp.h
@@ -66,7 +66,7 @@ private:
int fInstanceCount = 1;
int fInstanceStride = 0;
- const GrBuffer* fInstanceBuffer = nullptr;
+ sk_sp<const GrBuffer> fInstanceBuffer;
int fBaseInstance;
friend class GrOpMemoryPool;
diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
index 052e98f2dd..578eea8120 100644
--- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
@@ -973,7 +973,7 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
sk_sp<const GrBuffer> linesIndexBuffer = get_lines_index_buffer(target->resourceProvider());
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
SkASSERT(sizeof(LineVertex) == lineGP->vertexStride());
@@ -991,9 +991,9 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
}
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
- mesh->setIndexedPatterned(linesIndexBuffer.get(), kIdxsPerLineSeg, kLineSegNumVertices,
+ mesh->setIndexedPatterned(std::move(linesIndexBuffer), kIdxsPerLineSeg, kLineSegNumVertices,
lineCount, kLineSegsNumInIdxBuffer);
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
target->draw(std::move(lineGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
@@ -1014,7 +1014,7 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
fHelper.usesLocalCoords(),
this->coverage()));
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
sk_sp<const GrBuffer> quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider());
@@ -1046,8 +1046,8 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
if (quadCount > 0) {
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
- mesh->setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
- quadCount, kQuadsNumInIdxBuffer);
+ mesh->setIndexedPatterned(quadsIndexBuffer, kIdxsPerQuad, kQuadNumVertices, quadCount,
+ kQuadsNumInIdxBuffer);
mesh->setVertexData(vertexBuffer, firstVertex);
target->draw(std::move(quadGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
firstVertex += quadCount * kQuadNumVertices;
@@ -1055,9 +1055,9 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
if (conicCount > 0) {
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
- mesh->setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
+ mesh->setIndexedPatterned(std::move(quadsIndexBuffer), kIdxsPerQuad, kQuadNumVertices,
conicCount, kQuadsNumInIdxBuffer);
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
target->draw(std::move(conicGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
}
diff --git a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
index f15bbc899c..3d1020d774 100644
--- a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
@@ -199,7 +199,7 @@ private:
if (vertexCount == 0 || indexCount == 0) {
return;
}
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
&firstVertex);
@@ -209,7 +209,7 @@ private:
}
memcpy(verts, vertices, vertexCount * vertexStride);
- const GrBuffer* indexBuffer;
+ sk_sp<const GrBuffer> indexBuffer;
int firstIndex;
uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
if (!idxs) {
@@ -218,9 +218,9 @@ private:
}
memcpy(idxs, indices, indexCount * sizeof(uint16_t));
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
- mesh->setIndexed(indexBuffer, indexCount, firstIndex, 0, vertexCount - 1,
+ mesh->setIndexed(std::move(indexBuffer), indexCount, firstIndex, 0, vertexCount - 1,
GrPrimitiveRestart::kNo);
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
target->draw(std::move(gp), pipeline, fixedDynamicState, mesh);
}
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index c55abce386..667e230251 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -325,11 +325,9 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) {
size_t vertexStride = flushInfo.fGeometryProcessor->vertexStride();
int glyphCount = this->numGlyphs();
- const GrBuffer* vertexBuffer;
- void* vertices = target->makeVertexSpace(
- vertexStride, glyphCount * kVerticesPerGlyph, &vertexBuffer, &flushInfo.fVertexOffset);
- flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer));
+ void* vertices = target->makeVertexSpace(vertexStride, glyphCount * kVerticesPerGlyph,
+ &flushInfo.fVertexBuffer, &flushInfo.fVertexOffset);
flushInfo.fIndexBuffer = target->resourceProvider()->refQuadIndexBuffer();
if (!vertices || !flushInfo.fVertexBuffer) {
SkDebugf("Could not allocate vertices\n");
@@ -428,9 +426,9 @@ void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) co
int maxGlyphsPerDraw =
static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6);
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
- mesh->setIndexedPatterned(flushInfo->fIndexBuffer.get(), kIndicesPerGlyph, kVerticesPerGlyph,
+ mesh->setIndexedPatterned(flushInfo->fIndexBuffer, kIndicesPerGlyph, kVerticesPerGlyph,
flushInfo->fGlyphsToFlush, maxGlyphsPerDraw);
- mesh->setVertexData(flushInfo->fVertexBuffer.get(), flushInfo->fVertexOffset);
+ mesh->setVertexData(flushInfo->fVertexBuffer, flushInfo->fVertexOffset);
target->draw(flushInfo->fGeometryProcessor, flushInfo->fPipeline, flushInfo->fFixedDynamicState,
mesh);
flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush;
diff --git a/src/gpu/ops/GrDefaultPathRenderer.cpp b/src/gpu/ops/GrDefaultPathRenderer.cpp
index d62d22a817..c8a7966845 100644
--- a/src/gpu/ops/GrDefaultPathRenderer.cpp
+++ b/src/gpu/ops/GrDefaultPathRenderer.cpp
@@ -73,7 +73,6 @@ public:
, fGeometryProcessor(std::move(geometryProcessor))
, fPipeline(pipeline)
, fFixedDynamicState(fixedDynamicState)
- , fIndexBuffer(nullptr)
, fFirstIndex(0)
, fIndicesInChunk(0)
, fIndices(nullptr) {
@@ -275,10 +274,10 @@ private:
if (!this->isIndexed()) {
mesh->setNonIndexedNonInstanced(vertexCount);
} else {
- mesh->setIndexed(fIndexBuffer, indexCount, fFirstIndex, 0, vertexCount - 1,
- GrPrimitiveRestart::kNo);
+ mesh->setIndexed(std::move(fIndexBuffer), indexCount, fFirstIndex, 0,
+ vertexCount - 1, GrPrimitiveRestart::kNo);
}
- mesh->setVertexData(fVertexBuffer, fFirstVertex);
+ mesh->setVertexData(std::move(fVertexBuffer), fFirstVertex);
fTarget->draw(fGeometryProcessor, fPipeline, fFixedDynamicState, mesh);
}
@@ -319,13 +318,13 @@ private:
const GrPipeline* fPipeline;
const GrPipeline::FixedDynamicState* fFixedDynamicState;
- const GrBuffer* fVertexBuffer;
+ sk_sp<const GrBuffer> fVertexBuffer;
int fFirstVertex;
int fVerticesInChunk;
SkPoint* fVertices;
SkPoint* fCurVert;
- const GrBuffer* fIndexBuffer;
+ sk_sp<const GrBuffer> fIndexBuffer;
int fFirstIndex;
int fIndicesInChunk;
uint16_t* fIndices;
diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp
index 3a4219da3f..6a84c3fa96 100644
--- a/src/gpu/ops/GrDrawVerticesOp.cpp
+++ b/src/gpu/ops/GrDrawVerticesOp.cpp
@@ -227,7 +227,7 @@ void GrDrawVerticesOp::drawVolatile(Target* target) {
// Allocate buffers.
size_t vertexStride = gp->vertexStride();
- const GrBuffer* vertexBuffer = nullptr;
+ sk_sp<const GrBuffer> vertexBuffer = nullptr;
int firstVertex = 0;
void* verts = target->makeVertexSpace(vertexStride, fVertexCount, &vertexBuffer, &firstVertex);
if (!verts) {
@@ -235,7 +235,7 @@ void GrDrawVerticesOp::drawVolatile(Target* target) {
return;
}
- const GrBuffer* indexBuffer = nullptr;
+ sk_sp<const GrBuffer> indexBuffer = nullptr;
int firstIndex = 0;
uint16_t* indices = nullptr;
if (this->isIndexed()) {
@@ -255,7 +255,8 @@ void GrDrawVerticesOp::drawVolatile(Target* target) {
indices);
// Draw the vertices.
- this->drawVertices(target, std::move(gp), vertexBuffer, firstVertex, indexBuffer, firstIndex);
+ this->drawVertices(target, std::move(gp), std::move(vertexBuffer), firstVertex, indexBuffer,
+ firstIndex);
}
void GrDrawVerticesOp::drawNonVolatile(Target* target) {
@@ -292,16 +293,17 @@ void GrDrawVerticesOp::drawNonVolatile(Target* target) {
// Draw using the cached buffers if possible.
if (vertexBuffer && (!this->isIndexed() || indexBuffer)) {
- this->drawVertices(target, std::move(gp), vertexBuffer.get(), 0, indexBuffer.get(), 0);
+ this->drawVertices(target, std::move(gp), std::move(vertexBuffer), 0,
+ std::move(indexBuffer), 0);
return;
}
// Allocate vertex buffer.
size_t vertexStride = gp->vertexStride();
- vertexBuffer.reset(rp->createBuffer(fVertexCount * vertexStride,
- kVertex_GrBufferType,
- kStatic_GrAccessPattern,
- GrResourceProvider::Flags::kNone));
+ vertexBuffer = rp->createBuffer(fVertexCount * vertexStride,
+ kVertex_GrBufferType,
+ kStatic_GrAccessPattern,
+ GrResourceProvider::Flags::kNone);
void* verts = vertexBuffer ? vertexBuffer->map() : nullptr;
if (!verts) {
SkDebugf("Could not allocate vertices\n");
@@ -311,10 +313,10 @@ void GrDrawVerticesOp::drawNonVolatile(Target* target) {
// Allocate index buffer.
uint16_t* indices = nullptr;
if (this->isIndexed()) {
- indexBuffer.reset(rp->createBuffer(fIndexCount * sizeof(uint16_t),
- kIndex_GrBufferType,
- kStatic_GrAccessPattern,
- GrResourceProvider::Flags::kNone));
+ indexBuffer = rp->createBuffer(fIndexCount * sizeof(uint16_t),
+ kIndex_GrBufferType,
+ kStatic_GrAccessPattern,
+ GrResourceProvider::Flags::kNone);
indices = indexBuffer ? static_cast<uint16_t*>(indexBuffer->map()) : nullptr;
if (!indices) {
SkDebugf("Could not allocate indices\n");
@@ -341,7 +343,8 @@ void GrDrawVerticesOp::drawNonVolatile(Target* target) {
rp->assignUniqueKeyToResource(indexKey, indexBuffer.get());
// Draw the vertices.
- this->drawVertices(target, std::move(gp), vertexBuffer.get(), 0, indexBuffer.get(), 0);
+ this->drawVertices(target, std::move(gp), std::move(vertexBuffer), 0, std::move(indexBuffer),
+ 0);
}
void GrDrawVerticesOp::fillBuffers(bool hasColorAttribute,
@@ -457,18 +460,18 @@ void GrDrawVerticesOp::fillBuffers(bool hasColorAttribute,
void GrDrawVerticesOp::drawVertices(Target* target,
sk_sp<const GrGeometryProcessor> gp,
- const GrBuffer* vertexBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
int firstVertex,
- const GrBuffer* indexBuffer,
+ sk_sp<const GrBuffer> indexBuffer,
int firstIndex) {
GrMesh* mesh = target->allocMesh(this->primitiveType());
if (this->isIndexed()) {
- mesh->setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertexCount - 1,
+ mesh->setIndexed(std::move(indexBuffer), fIndexCount, firstIndex, 0, fVertexCount - 1,
GrPrimitiveRestart::kNo);
} else {
mesh->setNonIndexedNonInstanced(fVertexCount);
}
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
auto pipe = fHelper.makePipeline(target);
target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
diff --git a/src/gpu/ops/GrDrawVerticesOp.h b/src/gpu/ops/GrDrawVerticesOp.h
index 6ecdf0ca50..c72bb36eea 100644
--- a/src/gpu/ops/GrDrawVerticesOp.h
+++ b/src/gpu/ops/GrDrawVerticesOp.h
@@ -83,9 +83,9 @@ private:
void drawVertices(Target*,
sk_sp<const GrGeometryProcessor>,
- const GrBuffer* vertexBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
int firstVertex,
- const GrBuffer* indexBuffer,
+ sk_sp<const GrBuffer> indexBuffer,
int firstIndex);
sk_sp<GrGeometryProcessor> makeGP(const GrShaderCaps* shaderCaps,
diff --git a/src/gpu/ops/GrFillRectOp.cpp b/src/gpu/ops/GrFillRectOp.cpp
index d784e96636..a54e0d63cf 100644
--- a/src/gpu/ops/GrFillRectOp.cpp
+++ b/src/gpu/ops/GrFillRectOp.cpp
@@ -186,7 +186,7 @@ private:
sk_sp<GrGeometryProcessor> gp = GrQuadPerEdgeAA::MakeProcessor(vertexSpec);
size_t vertexSize = gp->vertexStride();
- const GrBuffer* vbuffer;
+ sk_sp<const GrBuffer> vbuffer;
int vertexOffsetInBuffer = 0;
// Fill the allocated vertex data
@@ -223,7 +223,7 @@ private:
SkDebugf("Could not allocate indices\n");
return;
}
- mesh->setVertexData(vbuffer, vertexOffsetInBuffer);
+ mesh->setVertexData(std::move(vbuffer), vertexOffsetInBuffer);
auto pipe = fHelper.makePipeline(target);
target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
diff --git a/src/gpu/ops/GrLatticeOp.cpp b/src/gpu/ops/GrLatticeOp.cpp
index 154a03923c..6b9a4485e0 100644
--- a/src/gpu/ops/GrLatticeOp.cpp
+++ b/src/gpu/ops/GrLatticeOp.cpp
@@ -225,10 +225,14 @@ private:
const size_t kVertexStride = gp->vertexStride();
sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
- PatternHelper helper(target, GrPrimitiveType::kTriangles, kVertexStride, indexBuffer.get(),
- kVertsPerRect, kIndicesPerRect, numRects);
+ if (!indexBuffer) {
+ SkDebugf("Could not allocate indices\n");
+ return;
+ }
+ PatternHelper helper(target, GrPrimitiveType::kTriangles, kVertexStride,
+ std::move(indexBuffer), kVertsPerRect, kIndicesPerRect, numRects);
GrVertexWriter vertices{helper.vertices()};
- if (!vertices.fPtr || !indexBuffer) {
+ if (!vertices.fPtr) {
SkDebugf("Could not allocate vertices\n");
return;
}
diff --git a/src/gpu/ops/GrMeshDrawOp.cpp b/src/gpu/ops/GrMeshDrawOp.cpp
index f5c0e3917b..abf67e0a6b 100644
--- a/src/gpu/ops/GrMeshDrawOp.cpp
+++ b/src/gpu/ops/GrMeshDrawOp.cpp
@@ -21,22 +21,22 @@ void GrMeshDrawOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
//////////////////////////////////////////////////////////////////////////////
GrMeshDrawOp::PatternHelper::PatternHelper(Target* target, GrPrimitiveType primitiveType,
- size_t vertexStride, const GrBuffer* indexBuffer,
+ size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
int verticesPerRepetition, int indicesPerRepetition,
int repeatCount) {
- this->init(target, primitiveType, vertexStride, indexBuffer, verticesPerRepetition,
+ this->init(target, primitiveType, vertexStride, std::move(indexBuffer), verticesPerRepetition,
indicesPerRepetition, repeatCount);
}
void GrMeshDrawOp::PatternHelper::init(Target* target, GrPrimitiveType primitiveType,
- size_t vertexStride, const GrBuffer* indexBuffer,
+ size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
int verticesPerRepetition, int indicesPerRepetition,
int repeatCount) {
SkASSERT(target);
if (!indexBuffer) {
return;
}
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
int vertexCount = verticesPerRepetition * repeatCount;
fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex);
@@ -50,7 +50,7 @@ void GrMeshDrawOp::PatternHelper::init(Target* target, GrPrimitiveType primitive
fMesh = target->allocMesh(primitiveType);
fMesh->setIndexedPatterned(indexBuffer, indicesPerRepetition, verticesPerRepetition,
repeatCount, maxRepetitions);
- fMesh->setVertexData(vertexBuffer, firstVertex);
+ fMesh->setVertexData(std::move(vertexBuffer), firstVertex);
}
void GrMeshDrawOp::PatternHelper::recordDraw(
@@ -67,7 +67,7 @@ GrMeshDrawOp::QuadHelper::QuadHelper(Target* target, size_t vertexStride, int qu
SkDebugf("Could not get quad index buffer.");
return;
}
- this->init(target, GrPrimitiveType::kTriangles, vertexStride, quadIndexBuffer.get(),
+ this->init(target, GrPrimitiveType::kTriangles, vertexStride, std::move(quadIndexBuffer),
kVerticesPerQuad, kIndicesPerQuad, quadsToDraw);
}
diff --git a/src/gpu/ops/GrMeshDrawOp.h b/src/gpu/ops/GrMeshDrawOp.h
index d851fc02a3..bba173d601 100644
--- a/src/gpu/ops/GrMeshDrawOp.h
+++ b/src/gpu/ops/GrMeshDrawOp.h
@@ -34,7 +34,7 @@ protected:
space for the vertices and flushes the draws to the GrMeshDrawOp::Target. */
class PatternHelper {
public:
- PatternHelper(Target*, GrPrimitiveType, size_t vertexStride, const GrBuffer*,
+ PatternHelper(Target*, GrPrimitiveType, size_t vertexStride, sk_sp<const GrBuffer>,
int verticesPerRepetition, int indicesPerRepetition, int repeatCount);
/** Called to issue draws to the GrMeshDrawOp::Target.*/
@@ -45,7 +45,7 @@ protected:
protected:
PatternHelper() = default;
- void init(Target*, GrPrimitiveType, size_t vertexStride, const GrBuffer*,
+ void init(Target*, GrPrimitiveType, size_t vertexStride, sk_sp<const GrBuffer>,
int verticesPerRepetition, int indicesPerRepetition, int repeatCount);
private:
@@ -100,7 +100,7 @@ public:
* should be written. On return the buffer that will hold the data as well as an offset into
* the buffer (in 'vertexSize' units) where the data will be placed.
*/
- virtual void* makeVertexSpace(size_t vertexSize, int vertexCount, const GrBuffer**,
+ virtual void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*,
int* startVertex) = 0;
/**
@@ -108,7 +108,7 @@ public:
* should be written. On return the buffer that will hold the data as well as an offset into
* the buffer (in uint16_t units) where the data will be placed.
*/
- virtual uint16_t* makeIndexSpace(int indexCount, const GrBuffer**, int* startIndex) = 0;
+ virtual uint16_t* makeIndexSpace(int indexCount, sk_sp<const GrBuffer>*, int* startIndex) = 0;
/**
* This is similar to makeVertexSpace. It allows the caller to use up to 'actualVertexCount'
@@ -117,7 +117,7 @@ public:
* buffer is allocated on behalf of this request.
*/
virtual void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount,
- int fallbackVertexCount, const GrBuffer**,
+ int fallbackVertexCount, sk_sp<const GrBuffer>*,
int* startVertex, int* actualVertexCount) = 0;
/**
@@ -127,7 +127,7 @@ public:
* buffer is allocated on behalf of this request.
*/
virtual uint16_t* makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount,
- const GrBuffer**, int* startIndex,
+ sk_sp<const GrBuffer>*, int* startIndex,
int* actualIndexCount) = 0;
/** Helpers for ops which over-allocate and then return excess data to the pool. */
diff --git a/src/gpu/ops/GrOvalOpFactory.cpp b/src/gpu/ops/GrOvalOpFactory.cpp
index feeef4f6eb..c840cfc4c2 100644
--- a/src/gpu/ops/GrOvalOpFactory.cpp
+++ b/src/gpu/ops/GrOvalOpFactory.cpp
@@ -1166,7 +1166,7 @@ private:
!fAllFill, fClipPlane, fClipPlaneIsect, fClipPlaneUnion, fRoundCaps, fWideColor,
localMatrix));
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
GrVertexWriter vertices{target->makeVertexSpace(gp->vertexStride(), fVertCount,
&vertexBuffer, &firstVertex)};
@@ -1175,7 +1175,7 @@ private:
return;
}
- const GrBuffer* indexBuffer = nullptr;
+ sk_sp<const GrBuffer> indexBuffer = nullptr;
int firstIndex = 0;
uint16_t* indices = target->makeIndexSpace(fIndexCount, &indexBuffer, &firstIndex);
if (!indices) {
@@ -1283,9 +1283,9 @@ private:
}
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
- mesh->setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertCount - 1,
+ mesh->setIndexed(std::move(indexBuffer), fIndexCount, firstIndex, 0, fVertCount - 1,
GrPrimitiveRestart::kNo);
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
auto pipe = fHelper.makePipeline(target);
target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
@@ -1491,7 +1491,7 @@ private:
sk_sp<GrGeometryProcessor> gp(new ButtCapDashedCircleGeometryProcessor(fWideColor,
localMatrix));
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
GrVertexWriter vertices{target->makeVertexSpace(gp->vertexStride(), fVertCount,
&vertexBuffer, &firstVertex)};
@@ -1500,7 +1500,7 @@ private:
return;
}
- const GrBuffer* indexBuffer = nullptr;
+ sk_sp<const GrBuffer> indexBuffer;
int firstIndex = 0;
uint16_t* indices = target->makeIndexSpace(fIndexCount, &indexBuffer, &firstIndex);
if (!indices) {
@@ -1567,9 +1567,9 @@ private:
}
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
- mesh->setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertCount - 1,
+ mesh->setIndexed(std::move(indexBuffer), fIndexCount, firstIndex, 0, fVertCount - 1,
GrPrimitiveRestart::kNo);
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
auto pipe = fHelper.makePipeline(target);
target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
@@ -2358,7 +2358,7 @@ private:
new CircleGeometryProcessor(!fAllFill, false, false, false, false, fWideColor,
localMatrix));
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
GrVertexWriter verts{target->makeVertexSpace(gp->vertexStride(), fVertCount,
@@ -2368,7 +2368,7 @@ private:
return;
}
- const GrBuffer* indexBuffer = nullptr;
+ sk_sp<const GrBuffer> indexBuffer;
int firstIndex = 0;
uint16_t* indices = target->makeIndexSpace(fIndexCount, &indexBuffer, &firstIndex);
if (!indices) {
@@ -2442,9 +2442,9 @@ private:
}
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
- mesh->setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertCount - 1,
+ mesh->setIndexed(std::move(indexBuffer), fIndexCount, firstIndex, 0, fVertCount - 1,
GrPrimitiveRestart::kNo);
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
auto pipe = fHelper.makePipeline(target);
target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
@@ -2646,11 +2646,15 @@ private:
sk_sp<const GrBuffer> indexBuffer = get_rrect_index_buffer(
fStroked ? kStroke_RRectType : kFill_RRectType, target->resourceProvider());
+ if (!indexBuffer) {
+ SkDebugf("Could not allocate indices\n");
+ return;
+ }
PatternHelper helper(target, GrPrimitiveType::kTriangles, gp->vertexStride(),
- indexBuffer.get(), kVertsPerStandardRRect, indicesPerInstance,
+ std::move(indexBuffer), kVertsPerStandardRRect, indicesPerInstance,
fRRects.count());
GrVertexWriter verts{helper.vertices()};
- if (!verts.fPtr || !indexBuffer) {
+ if (!verts.fPtr) {
SkDebugf("Could not allocate vertices\n");
return;
}
diff --git a/src/gpu/ops/GrQuadPerEdgeAA.cpp b/src/gpu/ops/GrQuadPerEdgeAA.cpp
index 8fa067fedc..9329bc471b 100644
--- a/src/gpu/ops/GrQuadPerEdgeAA.cpp
+++ b/src/gpu/ops/GrQuadPerEdgeAA.cpp
@@ -473,8 +473,8 @@ bool ConfigureMeshIndices(GrMeshDrawOp::Target* target, GrMesh* mesh, const Vert
}
mesh->setPrimitiveType(GrPrimitiveType::kTriangles);
- mesh->setIndexedPatterned(ibuffer.get(), kIndicesPerAAFillRect, kVertsPerAAFillRect,
- quadCount, kNumAAQuadsInIndexBuffer);
+ mesh->setIndexedPatterned(std::move(ibuffer), kIndicesPerAAFillRect, kVertsPerAAFillRect,
+ quadCount, kNumAAQuadsInIndexBuffer);
} else {
// Non-AA quads use 4 vertices, and regular triangle strip layout
if (quadCount > 1) {
@@ -484,7 +484,7 @@ bool ConfigureMeshIndices(GrMeshDrawOp::Target* target, GrMesh* mesh, const Vert
}
mesh->setPrimitiveType(GrPrimitiveType::kTriangles);
- mesh->setIndexedPatterned(ibuffer.get(), 6, 4, quadCount,
+ mesh->setIndexedPatterned(std::move(ibuffer), 6, 4, quadCount,
GrResourceProvider::QuadCountOfQuadBuffer());
} else {
mesh->setPrimitiveType(GrPrimitiveType::kTriangleStrip);
diff --git a/src/gpu/ops/GrRegionOp.cpp b/src/gpu/ops/GrRegionOp.cpp
index e57b62bd90..17254355c3 100644
--- a/src/gpu/ops/GrRegionOp.cpp
+++ b/src/gpu/ops/GrRegionOp.cpp
@@ -110,10 +110,15 @@ private:
return;
}
sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
+ if (!indexBuffer) {
+ SkDebugf("Could not allocate indices\n");
+ return;
+ }
PatternHelper helper(target, GrPrimitiveType::kTriangles, gp->vertexStride(),
- indexBuffer.get(), kVertsPerInstance, kIndicesPerInstance, numRects);
+ std::move(indexBuffer), kVertsPerInstance, kIndicesPerInstance,
+ numRects);
GrVertexWriter vertices{helper.vertices()};
- if (!vertices.fPtr || !indexBuffer) {
+ if (!vertices.fPtr) {
SkDebugf("Could not allocate vertices\n");
return;
}
diff --git a/src/gpu/ops/GrShadowRRectOp.cpp b/src/gpu/ops/GrShadowRRectOp.cpp
index c7ef699cb5..fdbb82d0b2 100644
--- a/src/gpu/ops/GrShadowRRectOp.cpp
+++ b/src/gpu/ops/GrShadowRRectOp.cpp
@@ -543,7 +543,7 @@ private:
int instanceCount = fGeoData.count();
SkASSERT(sizeof(CircleVertex) == gp->vertexStride());
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
CircleVertex* verts = (CircleVertex*)target->makeVertexSpace(
sizeof(CircleVertex), fVertCount, &vertexBuffer, &firstVertex);
@@ -552,7 +552,7 @@ private:
return;
}
- const GrBuffer* indexBuffer = nullptr;
+ sk_sp<const GrBuffer> indexBuffer;
int firstIndex = 0;
uint16_t* indices = target->makeIndexSpace(fIndexCount, &indexBuffer, &firstIndex);
if (!indices) {
@@ -594,9 +594,9 @@ private:
target->detachAppliedClip());
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
- mesh->setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertCount - 1,
+ mesh->setIndexed(std::move(indexBuffer), fIndexCount, firstIndex, 0, fVertCount - 1,
GrPrimitiveRestart::kNo);
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index ea27e7b9ad..c1c92f30a5 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -370,7 +370,6 @@ private:
// allocate vertices
const size_t kVertexStride = flushInfo.fGeometryProcessor->vertexStride();
- const GrBuffer* vertexBuffer;
// We need to make sure we don't overflow a 32 bit int when we request space in the
// makeVertexSpace call below.
@@ -379,9 +378,8 @@ private:
}
GrVertexWriter vertices{target->makeVertexSpace(kVertexStride,
kVerticesPerQuad * instanceCount,
- &vertexBuffer,
+ &flushInfo.fVertexBuffer,
&flushInfo.fVertexOffset)};
- flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer));
flushInfo.fIndexBuffer = target->resourceProvider()->refQuadIndexBuffer();
if (!vertices.fPtr || !flushInfo.fIndexBuffer) {
SkDebugf("Could not allocate vertices\n");
@@ -797,10 +795,9 @@ private:
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
int maxInstancesPerDraw =
static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6);
- mesh->setIndexedPatterned(flushInfo->fIndexBuffer.get(), kIndicesPerQuad,
- kVerticesPerQuad, flushInfo->fInstancesToFlush,
- maxInstancesPerDraw);
- mesh->setVertexData(flushInfo->fVertexBuffer.get(), flushInfo->fVertexOffset);
+ mesh->setIndexedPatterned(flushInfo->fIndexBuffer, kIndicesPerQuad, kVerticesPerQuad,
+ flushInfo->fInstancesToFlush, maxInstancesPerDraw);
+ mesh->setVertexData(flushInfo->fVertexBuffer, flushInfo->fVertexOffset);
target->draw(flushInfo->fGeometryProcessor, flushInfo->fPipeline,
flushInfo->fFixedDynamicState, mesh);
flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFlush;
diff --git a/src/gpu/ops/GrStrokeRectOp.cpp b/src/gpu/ops/GrStrokeRectOp.cpp
index 541c8a532a..949533312a 100644
--- a/src/gpu/ops/GrStrokeRectOp.cpp
+++ b/src/gpu/ops/GrStrokeRectOp.cpp
@@ -186,7 +186,7 @@ private:
vertexCount = kVertsPerStrokeRect;
}
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
void* verts =
@@ -215,7 +215,7 @@ private:
GrMesh* mesh = target->allocMesh(primType);
mesh->setNonIndexedNonInstanced(vertexCount);
- mesh->setVertexData(vertexBuffer, firstVertex);
+ mesh->setVertexData(std::move(vertexBuffer), firstVertex);
auto pipe = fHelper.makePipeline(target);
target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
@@ -474,10 +474,15 @@ void AAStrokeRectOp::onPrepareDraws(Target* target) {
sk_sp<const GrBuffer> indexBuffer =
GetIndexBuffer(target->resourceProvider(), this->miterStroke());
- PatternHelper helper(target, GrPrimitiveType::kTriangles, gp->vertexStride(), indexBuffer.get(),
- verticesPerInstance, indicesPerInstance, instanceCount);
+ if (!indexBuffer) {
+ SkDebugf("Could not allocate indices\n");
+ return;
+ }
+ PatternHelper helper(target, GrPrimitiveType::kTriangles, gp->vertexStride(),
+ std::move(indexBuffer), verticesPerInstance, indicesPerInstance,
+ instanceCount);
GrVertexWriter vertices{ helper.vertices() };
- if (!vertices.fPtr || !indexBuffer) {
+ if (!vertices.fPtr) {
SkDebugf("Could not allocate vertices\n");
return;
}
diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp
index 3690c7c6e6..7dbfa6b482 100644
--- a/src/gpu/ops/GrTessellatingPathRenderer.cpp
+++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp
@@ -77,8 +77,9 @@ public:
}
void* lock(int vertexCount) override {
size_t size = vertexCount * stride();
- fVertexBuffer.reset(fResourceProvider->createBuffer(
- size, kVertex_GrBufferType, kStatic_GrAccessPattern, GrResourceProvider::Flags::kNone));
+ fVertexBuffer =
+ fResourceProvider->createBuffer(size, kVertex_GrBufferType, kStatic_GrAccessPattern,
+ GrResourceProvider::Flags::kNone);
if (!fVertexBuffer.get()) {
return nullptr;
}
@@ -98,7 +99,8 @@ public:
}
fVertices = nullptr;
}
- GrBuffer* vertexBuffer() { return fVertexBuffer.get(); }
+ sk_sp<GrBuffer> detachVertexBuffer() { return std::move(fVertexBuffer); }
+
private:
sk_sp<GrBuffer> fVertexBuffer;
GrResourceProvider* fResourceProvider;
@@ -122,11 +124,12 @@ public:
fTarget->putBackVertices(fVertexCount - actualCount, stride());
fVertices = nullptr;
}
- const GrBuffer* vertexBuffer() const { return fVertexBuffer; }
+ sk_sp<const GrBuffer> detachVertexBuffer() const { return std::move(fVertexBuffer); }
int firstVertex() const { return fFirstVertex; }
+
private:
GrMeshDrawOp::Target* fTarget;
- const GrBuffer* fVertexBuffer;
+ sk_sp<const GrBuffer> fVertexBuffer;
int fVertexCount;
int fFirstVertex;
void* fVertices;
@@ -263,7 +266,8 @@ private:
SkScalar tol = GrPathUtils::kDefaultTolerance;
tol = GrPathUtils::scaleToleranceToSrc(tol, fViewMatrix, fShape.bounds());
if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) {
- this->drawVertices(target, std::move(gp), cachedVertexBuffer.get(), 0, actualCount);
+ this->drawVertices(target, std::move(gp), std::move(cachedVertexBuffer), 0,
+ actualCount);
return;
}
@@ -282,13 +286,15 @@ private:
if (count == 0) {
return;
}
- this->drawVertices(target, std::move(gp), allocator.vertexBuffer(), 0, count);
+ sk_sp<GrBuffer> vb = allocator.detachVertexBuffer();
TessInfo info;
info.fTolerance = isLinear ? 0 : tol;
info.fCount = count;
- key.setCustomData(SkData::MakeWithCopy(&info, sizeof(info)));
- rp->assignUniqueKeyToResource(key, allocator.vertexBuffer());
fShape.addGenIDChangeListener(sk_make_sp<PathInvalidator>(key, target->contextUniqueID()));
+ key.setCustomData(SkData::MakeWithCopy(&info, sizeof(info)));
+ rp->assignUniqueKeyToResource(key, vb.get());
+
+ this->drawVertices(target, std::move(gp), std::move(vb), 0, count);
}
void drawAA(Target* target, sk_sp<const GrGeometryProcessor> gp, size_t vertexStride) {
@@ -307,8 +313,8 @@ private:
if (count == 0) {
return;
}
- this->drawVertices(target, std::move(gp), allocator.vertexBuffer(), allocator.firstVertex(),
- count);
+ this->drawVertices(target, std::move(gp), allocator.detachVertexBuffer(),
+ allocator.firstVertex(), count);
}
void onPrepareDraws(Target* target) override {
@@ -351,12 +357,12 @@ private:
}
}
- void drawVertices(Target* target, sk_sp<const GrGeometryProcessor> gp, const GrBuffer* vb,
+ void drawVertices(Target* target, sk_sp<const GrGeometryProcessor> gp, sk_sp<const GrBuffer> vb,
int firstVertex, int count) {
GrMesh* mesh = target->allocMesh(TESSELLATOR_WIREFRAME ? GrPrimitiveType::kLines
: GrPrimitiveType::kTriangles);
mesh->setNonIndexedNonInstanced(count);
- mesh->setVertexData(vb, firstVertex);
+ mesh->setVertexData(std::move(vb), firstVertex);
auto pipe = fHelper.makePipeline(target);
target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp
index e3594d3929..a5f7c58e6f 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -396,7 +396,7 @@ private:
size_t vertexSize = gp->vertexStride();
GrMesh* meshes = target->allocMeshes(numProxies);
- const GrBuffer* vbuffer;
+ sk_sp<const GrBuffer> vbuffer;
int vertexOffsetInBuffer = 0;
int numQuadVerticesLeft = numTotalQuads * vertexSpec.verticesPerQuad();
int numAllocatedVertices = 0;
diff --git a/src/gpu/vk/GrVkBuffer.cpp b/src/gpu/vk/GrVkBuffer.cpp
index f8c120d96c..2ce5d8b81e 100644
--- a/src/gpu/vk/GrVkBuffer.cpp
+++ b/src/gpu/vk/GrVkBuffer.cpp
@@ -203,8 +203,8 @@ void GrVkBuffer::internalUnmap(GrVkGpu* gpu, size_t size) {
if (size <= 65536 && 0 == (size & 0x3)) {
gpu->updateBuffer(this, fMapPtr, this->offset(), size);
} else {
- GrVkTransferBuffer* transferBuffer =
- GrVkTransferBuffer::Create(gpu, size, GrVkBuffer::kCopyRead_Type);
+ sk_sp<GrVkTransferBuffer> transferBuffer =
+ GrVkTransferBuffer::Make(gpu, size, GrVkBuffer::kCopyRead_Type);
if (!transferBuffer) {
return;
}
@@ -213,8 +213,7 @@ void GrVkBuffer::internalUnmap(GrVkGpu* gpu, size_t size) {
memcpy (buffer, fMapPtr, size);
transferBuffer->unmap();
- gpu->copyBuffer(transferBuffer, this, 0, this->offset(), size);
- transferBuffer->unref();
+ gpu->copyBuffer(transferBuffer.get(), this, 0, this->offset(), size);
}
this->addMemoryBarrier(gpu,
VK_ACCESS_TRANSFER_WRITE_BIT,
diff --git a/src/gpu/vk/GrVkCopyManager.cpp b/src/gpu/vk/GrVkCopyManager.cpp
index 09fe216c6b..a41d2b64db 100644
--- a/src/gpu/vk/GrVkCopyManager.cpp
+++ b/src/gpu/vk/GrVkCopyManager.cpp
@@ -137,7 +137,7 @@ bool GrVkCopyManager::createCopyProgram(GrVkGpu* gpu) {
1, 0,
1, 1
};
- fVertexBuffer.reset(GrVkVertexBuffer::Create(gpu, sizeof(vdata), false));
+ fVertexBuffer = GrVkVertexBuffer::Make(gpu, sizeof(vdata), false);
SkASSERT(fVertexBuffer.get());
fVertexBuffer->updateData(vdata, sizeof(vdata));
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 0c0c5cd0da..2f668051e3 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -343,29 +343,29 @@ void GrVkGpu::submitCommandBuffer(SyncQueue sync) {
}
///////////////////////////////////////////////////////////////////////////////
-GrBuffer* GrVkGpu::onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern accessPattern,
- const void* data) {
- GrBuffer* buff;
+sk_sp<GrBuffer> GrVkGpu::onCreateBuffer(size_t size, GrBufferType type,
+ GrAccessPattern accessPattern, const void* data) {
+ sk_sp<GrBuffer> buff;
switch (type) {
case kVertex_GrBufferType:
SkASSERT(kDynamic_GrAccessPattern == accessPattern ||
kStatic_GrAccessPattern == accessPattern);
- buff = GrVkVertexBuffer::Create(this, size, kDynamic_GrAccessPattern == accessPattern);
+ buff = GrVkVertexBuffer::Make(this, size, kDynamic_GrAccessPattern == accessPattern);
break;
case kIndex_GrBufferType:
SkASSERT(kDynamic_GrAccessPattern == accessPattern ||
kStatic_GrAccessPattern == accessPattern);
- buff = GrVkIndexBuffer::Create(this, size, kDynamic_GrAccessPattern == accessPattern);
+ buff = GrVkIndexBuffer::Make(this, size, kDynamic_GrAccessPattern == accessPattern);
break;
case kXferCpuToGpu_GrBufferType:
SkASSERT(kDynamic_GrAccessPattern == accessPattern ||
kStream_GrAccessPattern == accessPattern);
- buff = GrVkTransferBuffer::Create(this, size, GrVkBuffer::kCopyRead_Type);
+ buff = GrVkTransferBuffer::Make(this, size, GrVkBuffer::kCopyRead_Type);
break;
case kXferGpuToCpu_GrBufferType:
SkASSERT(kDynamic_GrAccessPattern == accessPattern ||
kStream_GrAccessPattern == accessPattern);
- buff = GrVkTransferBuffer::Create(this, size, GrVkBuffer::kCopyWrite_Type);
+ buff = GrVkTransferBuffer::Make(this, size, GrVkBuffer::kCopyWrite_Type);
break;
case kDrawIndirect_GrBufferType:
SK_ABORT("DrawIndirect Buffers not supported in vulkan backend.");
@@ -672,8 +672,8 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, int left, int top, int widt
}
// allocate buffer to hold our mip data
- GrVkTransferBuffer* transferBuffer =
- GrVkTransferBuffer::Create(this, combinedBufferSize, GrVkBuffer::kCopyRead_Type);
+ sk_sp<GrVkTransferBuffer> transferBuffer =
+ GrVkTransferBuffer::Make(this, combinedBufferSize, GrVkBuffer::kCopyRead_Type);
if (!transferBuffer) {
return false;
}
@@ -762,12 +762,11 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, int left, int top, int widt
// Copy the buffer to the image
fCurrentCmdBuffer->copyBufferToImage(this,
- transferBuffer,
+ transferBuffer.get(),
uploadTexture,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
regions.count(),
regions.begin());
- transferBuffer->unref();
// If we copied the data into a temporary image first, copy that image into our main texture
// now.
@@ -842,8 +841,8 @@ bool GrVkGpu::uploadTexDataCompressed(GrVkTexture* tex, int left, int top, int w
}
// allocate buffer to hold our mip data
- GrVkTransferBuffer* transferBuffer =
- GrVkTransferBuffer::Create(this, combinedBufferSize, GrVkBuffer::kCopyRead_Type);
+ sk_sp<GrVkTransferBuffer> transferBuffer =
+ GrVkTransferBuffer::Make(this, combinedBufferSize, GrVkBuffer::kCopyRead_Type);
if (!transferBuffer) {
return false;
}
@@ -898,12 +897,11 @@ bool GrVkGpu::uploadTexDataCompressed(GrVkTexture* tex, int left, int top, int w
// Copy the buffer to the image
fCurrentCmdBuffer->copyBufferToImage(this,
- transferBuffer,
+ transferBuffer.get(),
uploadTexture,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
regions.count(),
regions.begin());
- transferBuffer->unref();
if (1 == mipLevelCount) {
tex->texturePriv().markMipMapsDirty();
@@ -2152,10 +2150,11 @@ bool GrVkGpu::onReadPixels(GrSurface* surface, int left, int top, int width, int
size_t transBufferRowBytes = bpp * region.imageExtent.width;
size_t imageRows = region.imageExtent.height;
- GrVkTransferBuffer* transferBuffer =
+ auto transferBuffer = sk_sp<GrVkTransferBuffer>(
static_cast<GrVkTransferBuffer*>(this->createBuffer(transBufferRowBytes * imageRows,
kXferGpuToCpu_GrBufferType,
- kStream_GrAccessPattern));
+ kStream_GrAccessPattern)
+ .release()));
// Copy the image to a buffer so we can map it to cpu memory
region.bufferOffset = transferBuffer->offset();
@@ -2166,7 +2165,7 @@ bool GrVkGpu::onReadPixels(GrSurface* surface, int left, int top, int width, int
fCurrentCmdBuffer->copyImageToBuffer(this,
image,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
- transferBuffer,
+ transferBuffer.get(),
1,
&region);
@@ -2193,7 +2192,6 @@ bool GrVkGpu::onReadPixels(GrSurface* surface, int left, int top, int width, int
SkRectMemcpy(buffer, rowBytes, mappedMemory, transBufferRowBytes, tightRowBytes, height);
transferBuffer->unmap();
- transferBuffer->unref();
return true;
}
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 7888557844..944126aa4c 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -198,8 +198,8 @@ private:
sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&) override;
- GrBuffer* onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern,
- const void* data) override;
+ sk_sp<GrBuffer> onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern,
+ const void* data) override;
bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
void* buffer, size_t rowBytes) override;
diff --git a/src/gpu/vk/GrVkIndexBuffer.cpp b/src/gpu/vk/GrVkIndexBuffer.cpp
index e56a525be9..cf4fe98e1a 100644
--- a/src/gpu/vk/GrVkIndexBuffer.cpp
+++ b/src/gpu/vk/GrVkIndexBuffer.cpp
@@ -16,7 +16,7 @@ GrVkIndexBuffer::GrVkIndexBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
this->registerWithCache(SkBudgeted::kYes);
}
-GrVkIndexBuffer* GrVkIndexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) {
+sk_sp<GrVkIndexBuffer> GrVkIndexBuffer::Make(GrVkGpu* gpu, size_t size, bool dynamic) {
GrVkBuffer::Desc desc;
desc.fDynamic = dynamic;
desc.fType = GrVkBuffer::kIndex_Type;
@@ -32,7 +32,7 @@ GrVkIndexBuffer* GrVkIndexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic
if (!buffer) {
bufferResource->unref(gpu);
}
- return buffer;
+ return sk_sp<GrVkIndexBuffer>(buffer);
}
void GrVkIndexBuffer::onRelease() {
diff --git a/src/gpu/vk/GrVkIndexBuffer.h b/src/gpu/vk/GrVkIndexBuffer.h
index cd945ac5b3..ab5c349c82 100644
--- a/src/gpu/vk/GrVkIndexBuffer.h
+++ b/src/gpu/vk/GrVkIndexBuffer.h
@@ -16,7 +16,7 @@ class GrVkGpu;
class GrVkIndexBuffer : public GrBuffer, public GrVkBuffer {
public:
- static GrVkIndexBuffer* Create(GrVkGpu* gpu, size_t size, bool dynamic);
+ static sk_sp<GrVkIndexBuffer> Make(GrVkGpu* gpu, size_t size, bool dynamic);
protected:
void onAbandon() override;
diff --git a/src/gpu/vk/GrVkTransferBuffer.cpp b/src/gpu/vk/GrVkTransferBuffer.cpp
index 9adfeaf75b..cb98d2b901 100644
--- a/src/gpu/vk/GrVkTransferBuffer.cpp
+++ b/src/gpu/vk/GrVkTransferBuffer.cpp
@@ -9,8 +9,8 @@
#include "GrVkGpu.h"
#include "SkTraceMemoryDump.h"
-
-GrVkTransferBuffer* GrVkTransferBuffer::Create(GrVkGpu* gpu, size_t size, GrVkBuffer::Type type) {
+sk_sp<GrVkTransferBuffer> GrVkTransferBuffer::Make(GrVkGpu* gpu, size_t size,
+ GrVkBuffer::Type type) {
GrVkBuffer::Desc desc;
desc.fDynamic = true;
SkASSERT(GrVkBuffer::kCopyRead_Type == type || GrVkBuffer::kCopyWrite_Type == type);
@@ -26,7 +26,7 @@ GrVkTransferBuffer* GrVkTransferBuffer::Create(GrVkGpu* gpu, size_t size, GrVkBu
if (!buffer) {
bufferResource->unref(gpu);
}
- return buffer;
+ return sk_sp<GrVkTransferBuffer>(buffer);
}
GrVkTransferBuffer::GrVkTransferBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
diff --git a/src/gpu/vk/GrVkTransferBuffer.h b/src/gpu/vk/GrVkTransferBuffer.h
index af9ed1bc7c..036f4f7ff3 100644
--- a/src/gpu/vk/GrVkTransferBuffer.h
+++ b/src/gpu/vk/GrVkTransferBuffer.h
@@ -17,7 +17,7 @@ class GrVkGpu;
class GrVkTransferBuffer : public GrBuffer, public GrVkBuffer {
public:
- static GrVkTransferBuffer* Create(GrVkGpu* gpu, size_t size, GrVkBuffer::Type type);
+ static sk_sp<GrVkTransferBuffer> Make(GrVkGpu* gpu, size_t size, GrVkBuffer::Type type);
protected:
void onAbandon() override;
diff --git a/src/gpu/vk/GrVkVertexBuffer.cpp b/src/gpu/vk/GrVkVertexBuffer.cpp
index de7f3c2201..d94f11d187 100644
--- a/src/gpu/vk/GrVkVertexBuffer.cpp
+++ b/src/gpu/vk/GrVkVertexBuffer.cpp
@@ -16,7 +16,7 @@ GrVkVertexBuffer::GrVkVertexBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
this->registerWithCache(SkBudgeted::kYes);
}
-GrVkVertexBuffer* GrVkVertexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) {
+sk_sp<GrVkVertexBuffer> GrVkVertexBuffer::Make(GrVkGpu* gpu, size_t size, bool dynamic) {
GrVkBuffer::Desc desc;
desc.fDynamic = dynamic;
desc.fType = GrVkBuffer::kVertex_Type;
@@ -31,7 +31,7 @@ GrVkVertexBuffer* GrVkVertexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynam
if (!buffer) {
bufferResource->unref(gpu);
}
- return buffer;
+ return sk_sp<GrVkVertexBuffer>(buffer);
}
void GrVkVertexBuffer::onRelease() {
diff --git a/src/gpu/vk/GrVkVertexBuffer.h b/src/gpu/vk/GrVkVertexBuffer.h
index cae781e311..af65a7eed0 100644
--- a/src/gpu/vk/GrVkVertexBuffer.h
+++ b/src/gpu/vk/GrVkVertexBuffer.h
@@ -15,7 +15,7 @@ class GrVkGpu;
class GrVkVertexBuffer : public GrBuffer, public GrVkBuffer {
public:
- static GrVkVertexBuffer* Create(GrVkGpu* gpu, size_t size, bool dynamic);
+ static sk_sp<GrVkVertexBuffer> Make(GrVkGpu* gpu, size_t size, bool dynamic);
protected:
void onAbandon() override;
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 3648514071..fc8bca8f8d 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -158,7 +158,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
for (int y = 0; y < kBoxCountY; ++y) {
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setNonIndexedNonInstanced(kBoxCountX * 6);
- mesh.setVertexData(vbuff.get(), y * kBoxCountX * 6);
+ mesh.setVertexData(vbuff, y * kBoxCountX * 6);
helper->drawMesh(mesh);
}
});
@@ -177,10 +177,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
int repetitionCount = SkTMin(3 - baseRepetition, kBoxCount - i);
GrMesh mesh(GrPrimitiveType::kTriangles);
- mesh.setIndexed(ibuff.get(), repetitionCount * 6, baseRepetition * 6,
- baseRepetition * 4, (baseRepetition + repetitionCount) * 4 - 1,
- GrPrimitiveRestart::kNo);
- mesh.setVertexData(vbuff.get(), (i - baseRepetition) * 4);
+ mesh.setIndexed(ibuff, repetitionCount * 6, baseRepetition * 6, baseRepetition * 4,
+ (baseRepetition + repetitionCount) * 4 - 1, GrPrimitiveRestart::kNo);
+ mesh.setVertexData(vbuff, (i - baseRepetition) * 4);
helper->drawMesh(mesh);
baseRepetition = (baseRepetition + 1) % 3;
@@ -198,8 +197,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
// support a base index.
for (int y = 0; y < kBoxCountY; ++y) {
GrMesh mesh(GrPrimitiveType::kTriangles);
- mesh.setIndexedPatterned(ibuff.get(), 6, 4, kBoxCountX, kIndexPatternRepeatCount);
- mesh.setVertexData(vbuff.get(), y * kBoxCountX * 4);
+ mesh.setIndexedPatterned(ibuff, 6, 4, kBoxCountX, kIndexPatternRepeatCount);
+ mesh.setVertexData(vbuff, y * kBoxCountX * 4);
helper->drawMesh(mesh);
}
});
@@ -227,10 +226,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
: GrPrimitiveType::kTriangleStrip);
if (indexed) {
VALIDATE(idxbuff);
- mesh.setIndexedInstanced(idxbuff.get(), 6, instbuff.get(), kBoxCountX,
- y * kBoxCountX, GrPrimitiveRestart::kNo);
+ mesh.setIndexedInstanced(idxbuff, 6, instbuff, kBoxCountX, y * kBoxCountX,
+ GrPrimitiveRestart::kNo);
} else {
- mesh.setInstanced(instbuff.get(), kBoxCountX, y * kBoxCountX, 4);
+ mesh.setInstanced(instbuff, kBoxCountX, y * kBoxCountX, 4);
}
switch (y % 3) {
case 0:
@@ -243,10 +242,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
}
// Fallthru.
case 1:
- mesh.setVertexData(vbuff.get());
+ mesh.setVertexData(vbuff);
break;
case 2:
- mesh.setVertexData(vbuff2.get(), 2);
+ mesh.setVertexData(vbuff2, 2);
break;
}
helper->drawMesh(mesh);
diff --git a/tests/GrPipelineDynamicStateTest.cpp b/tests/GrPipelineDynamicStateTest.cpp
index c5044811a9..edc833a14b 100644
--- a/tests/GrPipelineDynamicStateTest.cpp
+++ b/tests/GrPipelineDynamicStateTest.cpp
@@ -142,7 +142,7 @@ private:
for (int i = 0; i < kNumMeshes; ++i) {
GrMesh& mesh = meshes.emplace_back(GrPrimitiveType::kTriangleStrip);
mesh.setNonIndexedNonInstanced(4);
- mesh.setVertexData(fVertexBuffer.get(), 4 * i);
+ mesh.setVertexData(fVertexBuffer, 4 * i);
}
GrPipeline::DynamicStateArrays dynamicState;
dynamicState.fScissorRects = kDynamicScissors;
diff --git a/tests/OnFlushCallbackTest.cpp b/tests/OnFlushCallbackTest.cpp
index d23b04702c..35ff57462c 100644
--- a/tests/OnFlushCallbackTest.cpp
+++ b/tests/OnFlushCallbackTest.cpp
@@ -110,7 +110,7 @@ private:
size_t vertexStride = gp->vertexStride();
- const GrBuffer* indexBuffer;
+ sk_sp<const GrBuffer> indexBuffer;
int firstIndex;
uint16_t* indices = target->makeIndexSpace(6, &indexBuffer, &firstIndex);
if (!indices) {
@@ -118,7 +118,7 @@ private:
return;
}
- const GrBuffer* vertexBuffer;
+ sk_sp<const GrBuffer> vertexBuffer;
int firstVertex;
void* vertices = target->makeVertexSpace(vertexStride, 4, &vertexBuffer, &firstVertex);
if (!vertices) {
diff --git a/tests/TraceMemoryDumpTest.cpp b/tests/TraceMemoryDumpTest.cpp
index 0a532492db..f3de350979 100644
--- a/tests/TraceMemoryDumpTest.cpp
+++ b/tests/TraceMemoryDumpTest.cpp
@@ -75,8 +75,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLBuffer, reporter,
GrContext* context = ctxInfo.grContext();
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->contextPriv().getGpu());
const size_t kMemorySize = 1024;
- sk_sp<GrGLBuffer> buffer(
- GrGLBuffer::Create(gpu, kMemorySize, kVertex_GrBufferType, kDynamic_GrAccessPattern));
+ sk_sp<GrGLBuffer> buffer =
+ GrGLBuffer::Make(gpu, kMemorySize, kVertex_GrBufferType, kDynamic_GrAccessPattern);
ValidateMemoryDumps(reporter, context, kMemorySize, true /* isOwned */);
}