Make GrResourceProvider more sk_spified

Change-Id: If191553093031705756358f4551a5b1e96439742
Reviewed-on: https://skia-review.googlesource.com/60000
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Salomon 2017-10-16 13:01:07 -04:00 committed by Skia Commit-Bot
parent 1bd76c468c
commit d28a79d495
20 changed files with 73 additions and 94 deletions

View File

@ -76,7 +76,7 @@ sk_sp<GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(const GrUnique
GrBufferType intendedType, GrBufferType intendedType,
size_t size, const void* data) { size_t size, const void* data) {
GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider(); GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider();
sk_sp<GrBuffer> buffer(rp->findAndRefTByUniqueKey<GrBuffer>(key)); sk_sp<GrBuffer> buffer(rp->findByUniqueKey<GrBuffer>(key));
if (!buffer) { if (!buffer) {
buffer.reset(rp->createBuffer(size, intendedType, kStatic_GrAccessPattern, 0, data)); buffer.reset(rp->createBuffer(size, intendedType, kStatic_GrAccessPattern, 0, data));
if (!buffer) { if (!buffer) {

View File

@ -70,13 +70,13 @@ void GrRenderTarget::onAbandon() {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) { bool GrRenderTargetPriv::attachStencilAttachment(sk_sp<GrStencilAttachment> stencil) {
if (!stencil && !fRenderTarget->fStencilAttachment) { if (!stencil && !fRenderTarget->fStencilAttachment) {
// No need to do any work since we currently don't have a stencil attachment and // No need to do any work since we currently don't have a stencil attachment and
// we're not actually adding one. // we're not actually adding one.
return true; return true;
} }
fRenderTarget->fStencilAttachment = stencil; fRenderTarget->fStencilAttachment = stencil.release();
if (!fRenderTarget->completeStencilAttachment()) { if (!fRenderTarget->completeStencilAttachment()) {
SkSafeSetNull(fRenderTarget->fStencilAttachment); SkSafeSetNull(fRenderTarget->fStencilAttachment);
return false; return false;

View File

@ -28,7 +28,7 @@ public:
* currently attached GrStencilAttachment will be removed if one was previously attached. This * currently attached GrStencilAttachment will be removed if one was previously attached. This
* function returns false if there were any failure in attaching the GrStencilAttachment. * function returns false if there were any failure in attaching the GrStencilAttachment.
*/ */
bool attachStencilAttachment(GrStencilAttachment* stencil); bool attachStencilAttachment(sk_sp<GrStencilAttachment> stencil);
int numStencilBits() const; int numStencilBits() const;

View File

@ -284,20 +284,10 @@ void GrResourceProvider::removeUniqueKeyFromProxy(const GrUniqueKey& key, GrText
fCache->processInvalidProxyUniqueKey(key, proxy, true); fCache->processInvalidProxyUniqueKey(key, proxy, true);
} }
GrGpuResource* GrResourceProvider::findAndRefResourceByUniqueKey(const GrUniqueKey& key) { sk_sp<GrGpuResource> GrResourceProvider::findResourceByUniqueKey(const GrUniqueKey& key) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key); return this->isAbandoned() ? nullptr
} : sk_sp<GrGpuResource>(fCache->findAndRefUniqueResource(key));
GrTexture* GrResourceProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& key) {
ASSERT_SINGLE_OWNER
GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key);
if (resource) {
GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
SkASSERT(texture);
return texture;
}
return nullptr;
} }
void GrResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) { void GrResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) {
@ -322,11 +312,11 @@ sk_sp<GrTextureProxy> GrResourceProvider::findOrCreateProxyByUniqueKey(const GrU
return this->isAbandoned() ? nullptr : fCache->findOrCreateProxyByUniqueKey(key, origin); return this->isAbandoned() ? nullptr : fCache->findOrCreateProxyByUniqueKey(key, origin);
} }
const GrBuffer* GrResourceProvider::createPatternedIndexBuffer(const uint16_t* pattern, sk_sp<const GrBuffer> GrResourceProvider::createPatternedIndexBuffer(const uint16_t* pattern,
int patternSize, int patternSize,
int reps, int reps,
int vertCount, int vertCount,
const GrUniqueKey& key) { const GrUniqueKey& key) {
size_t bufferSize = patternSize * reps * sizeof(uint16_t); size_t bufferSize = patternSize * reps * sizeof(uint16_t);
// This is typically used in GrMeshDrawOps, so we assume kNoPendingIO. // This is typically used in GrMeshDrawOps, so we assume kNoPendingIO.
@ -356,15 +346,14 @@ const GrBuffer* GrResourceProvider::createPatternedIndexBuffer(const uint16_t* p
buffer->unmap(); buffer->unmap();
} }
this->assignUniqueKeyToResource(key, buffer.get()); this->assignUniqueKeyToResource(key, buffer.get());
return buffer.release(); return std::move(buffer);
} }
static constexpr int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1; static constexpr int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1;
const GrBuffer* GrResourceProvider::createQuadIndexBuffer() { sk_sp<const GrBuffer> GrResourceProvider::createQuadIndexBuffer() {
GR_STATIC_ASSERT(4 * kMaxQuads <= 65535); GR_STATIC_ASSERT(4 * kMaxQuads <= 65535);
static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 }; static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 };
return this->createPatternedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadIndexBufferKey); return this->createPatternedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadIndexBufferKey);
} }
@ -461,24 +450,23 @@ bool GrResourceProvider::attachStencilAttachment(GrRenderTarget* rt) {
SkDEBUGCODE(bool newStencil = false;) SkDEBUGCODE(bool newStencil = false;)
GrStencilAttachment::ComputeSharedStencilAttachmentKey(width, height, GrStencilAttachment::ComputeSharedStencilAttachmentKey(width, height,
rt->numStencilSamples(), &sbKey); rt->numStencilSamples(), &sbKey);
GrStencilAttachment* stencil = static_cast<GrStencilAttachment*>( auto stencil = this->findByUniqueKey<GrStencilAttachment>(sbKey);
this->findAndRefResourceByUniqueKey(sbKey));
if (!stencil) { if (!stencil) {
// Need to try and create a new stencil // Need to try and create a new stencil
stencil = this->gpu()->createStencilAttachmentForRenderTarget(rt, width, height); stencil.reset(this->gpu()->createStencilAttachmentForRenderTarget(rt, width, height));
if (stencil) { if (stencil) {
this->assignUniqueKeyToResource(sbKey, stencil); this->assignUniqueKeyToResource(sbKey, stencil.get());
SkDEBUGCODE(newStencil = true;) SkDEBUGCODE(newStencil = true;)
} }
} }
if (rt->renderTargetPriv().attachStencilAttachment(stencil)) { if (rt->renderTargetPriv().attachStencilAttachment(std::move(stencil))) {
#ifdef SK_DEBUG #ifdef SK_DEBUG
// Fill the SB with an inappropriate value. opLists that use the // Fill the SB with an inappropriate value. opLists that use the
// SB should clear it properly. // SB should clear it properly.
if (newStencil) { if (newStencil) {
SkASSERT(stencil->isDirty()); SkASSERT(rt->renderTargetPriv().getStencilAttachment()->isDirty());
this->gpu()->clearStencil(rt, 0xFFFF); this->gpu()->clearStencil(rt, 0xFFFF);
SkASSERT(stencil->isDirty()); SkASSERT(rt->renderTargetPriv().getStencilAttachment()->isDirty());
} }
#endif #endif
} }

View File

@ -41,8 +41,14 @@ class GrResourceProvider {
public: public:
GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* owner); GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* owner);
template <typename T> T* findAndRefTByUniqueKey(const GrUniqueKey& key) { /**
return static_cast<T*>(this->findAndRefResourceByUniqueKey(key)); * Finds a resource in the cache, based on the specified key. Prior to calling this, the caller
* must be sure that if a resource of exists in the cache with the given unique key then it is
* of type T.
*/
template <typename T>
sk_sp<T> findByUniqueKey(const GrUniqueKey& key) {
return sk_sp<T>(static_cast<T*>(this->findResourceByUniqueKey(key).release()));
} }
/* /*
@ -138,12 +144,12 @@ public:
* *
* @return The index buffer if successful, otherwise nullptr. * @return The index buffer if successful, otherwise nullptr.
*/ */
const GrBuffer* findOrCreatePatternedIndexBuffer(const uint16_t* pattern, sk_sp<const GrBuffer> findOrCreatePatternedIndexBuffer(const uint16_t* pattern,
int patternSize, int patternSize,
int reps, int reps,
int vertCount, int vertCount,
const GrUniqueKey& key) { const GrUniqueKey& key) {
if (GrBuffer* buffer = this->findAndRefTByUniqueKey<GrBuffer>(key)) { if (auto buffer = this->findByUniqueKey<GrBuffer>(key)) {
return buffer; return buffer;
} }
return this->createPatternedIndexBuffer(pattern, patternSize, reps, vertCount, key); return this->createPatternedIndexBuffer(pattern, patternSize, reps, vertCount, key);
@ -156,9 +162,8 @@ public:
* Draw with GrPrimitiveType::kTriangles * Draw with GrPrimitiveType::kTriangles
* @ return the quad index buffer * @ return the quad index buffer
*/ */
const GrBuffer* refQuadIndexBuffer() { sk_sp<const GrBuffer> refQuadIndexBuffer() {
if (GrBuffer* buffer = if (auto buffer = this->findByUniqueKey<const GrBuffer>(fQuadIndexBufferKey)) {
this->findAndRefTByUniqueKey<GrBuffer>(fQuadIndexBufferKey)) {
return buffer; return buffer;
} }
return this->createQuadIndexBuffer(); return this->createQuadIndexBuffer();
@ -230,13 +235,6 @@ public:
*/ */
void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*); void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*);
/**
* Finds a resource in the cache, based on the specified key. This is intended for use in
* conjunction with addResourceToCache(). The return value will be NULL if not found. The
* caller must balance with a call to unref().
*/
GrGpuResource* findAndRefResourceByUniqueKey(const GrUniqueKey&);
sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true); sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true);
sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&, sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&,
@ -263,7 +261,7 @@ public:
const GrCaps* caps() const { return fCaps.get(); } const GrCaps* caps() const { return fCaps.get(); }
private: private:
GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key); sk_sp<GrGpuResource> findResourceByUniqueKey(const GrUniqueKey&);
// Attempts to find a resource in the cache that exactly matches the GrSurfaceDesc. Failing that // Attempts to find a resource in the cache that exactly matches the GrSurfaceDesc. Failing that
// it returns null. If non-null, the resulting texture is always budgeted. // it returns null. If non-null, the resulting texture is always budgeted.
@ -286,13 +284,13 @@ private:
return !SkToBool(fCache); return !SkToBool(fCache);
} }
const GrBuffer* createPatternedIndexBuffer(const uint16_t* pattern, sk_sp<const GrBuffer> createPatternedIndexBuffer(const uint16_t* pattern,
int patternSize, int patternSize,
int reps, int reps,
int vertCount, int vertCount,
const GrUniqueKey& key); const GrUniqueKey& key);
const GrBuffer* createQuadIndexBuffer(); sk_sp<const GrBuffer> createQuadIndexBuffer();
GrResourceCache* fCache; GrResourceCache* fCache;
GrGpu* fGpu; GrGpu* fGpu;

View File

@ -32,7 +32,7 @@ static const int kNumAAFillRectsInIndexBuffer = 256;
static const int kVertsPerAAFillRect = 8; static const int kVertsPerAAFillRect = 8;
static const int kIndicesPerAAFillRect = 30; static const int kIndicesPerAAFillRect = 30;
const GrBuffer* get_index_buffer(GrResourceProvider* resourceProvider) { static sk_sp<const GrBuffer> get_index_buffer(GrResourceProvider* resourceProvider) {
GR_DEFINE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); GR_DEFINE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey);
// clang-format off // clang-format off
@ -251,7 +251,7 @@ private:
size_t vertexStride = gp->getVertexStride(); size_t vertexStride = gp->getVertexStride();
sk_sp<const GrBuffer> indexBuffer(get_index_buffer(target->resourceProvider())); sk_sp<const GrBuffer> indexBuffer = get_index_buffer(target->resourceProvider());
PatternHelper helper(GrPrimitiveType::kTriangles); PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices = void* vertices =
helper.init(target, vertexStride, indexBuffer.get(), kVertsPerAAFillRect, helper.init(target, vertexStride, indexBuffer.get(), kVertsPerAAFillRect,

View File

@ -62,7 +62,7 @@ static const int kQuadNumVertices = 5;
static const int kQuadsNumInIdxBuffer = 256; static const int kQuadsNumInIdxBuffer = 256;
GR_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); GR_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
static const GrBuffer* ref_quads_index_buffer(GrResourceProvider* resourceProvider) { static sk_sp<const GrBuffer> get_quads_index_buffer(GrResourceProvider* resourceProvider) {
GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
return resourceProvider->findOrCreatePatternedIndexBuffer( return resourceProvider->findOrCreatePatternedIndexBuffer(
kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices, kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices,
@ -96,7 +96,7 @@ static const int kLineSegsNumInIdxBuffer = 256;
GR_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); GR_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
static const GrBuffer* ref_lines_index_buffer(GrResourceProvider* resourceProvider) { static sk_sp<const GrBuffer> get_lines_index_buffer(GrResourceProvider* resourceProvider) {
GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
return resourceProvider->findOrCreatePatternedIndexBuffer( return resourceProvider->findOrCreatePatternedIndexBuffer(
kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineSegNumVertices, kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineSegNumVertices,
@ -945,8 +945,7 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
*geometryProcessorViewM); *geometryProcessorViewM);
} }
sk_sp<const GrBuffer> linesIndexBuffer( sk_sp<const GrBuffer> linesIndexBuffer = get_lines_index_buffer(target->resourceProvider());
ref_lines_index_buffer(target->resourceProvider()));
const GrBuffer* vertexBuffer; const GrBuffer* vertexBuffer;
int firstVertex; int firstVertex;
@ -994,8 +993,7 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
const GrBuffer* vertexBuffer; const GrBuffer* vertexBuffer;
int firstVertex; int firstVertex;
sk_sp<const GrBuffer> quadsIndexBuffer( sk_sp<const GrBuffer> quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider());
ref_quads_index_buffer(target->resourceProvider()));
size_t vertexStride = sizeof(BezierVertex); size_t vertexStride = sizeof(BezierVertex);
int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * conicCount; int vertexCount = kQuadNumVertices * quadCount + kQuadNumVertices * conicCount;

View File

@ -213,7 +213,7 @@ private:
static const int kBevelVertexCnt = 24; static const int kBevelVertexCnt = 24;
static const int kNumBevelRectsInIndexBuffer = 256; static const int kNumBevelRectsInIndexBuffer = 256;
static const GrBuffer* GetIndexBuffer(GrResourceProvider* resourceProvider, bool miterStroke); static sk_sp<const GrBuffer> GetIndexBuffer(GrResourceProvider*, bool miterStroke);
const SkMatrix& viewMatrix() const { return fViewMatrix; } const SkMatrix& viewMatrix() const { return fViewMatrix; }
bool miterStroke() const { return fMiterStroke; } bool miterStroke() const { return fMiterStroke; }
@ -272,8 +272,7 @@ void AAStrokeRectOp::onPrepareDraws(Target* target) {
int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIndexCnt; int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIndexCnt;
int instanceCount = fRects.count(); int instanceCount = fRects.count();
const sk_sp<const GrBuffer> indexBuffer( sk_sp<const GrBuffer> indexBuffer = GetIndexBuffer(target->resourceProvider(), this->miterStroke());
GetIndexBuffer(target->resourceProvider(), this->miterStroke()));
PatternHelper helper(GrPrimitiveType::kTriangles); PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices = void* vertices =
helper.init(target, vertexStride, indexBuffer.get(), helper.init(target, vertexStride, indexBuffer.get(),
@ -301,8 +300,8 @@ void AAStrokeRectOp::onPrepareDraws(Target* target) {
helper.recordDraw(target, gp.get(), fHelper.makePipeline(target)); helper.recordDraw(target, gp.get(), fHelper.makePipeline(target));
} }
const GrBuffer* AAStrokeRectOp::GetIndexBuffer(GrResourceProvider* resourceProvider, sk_sp<const GrBuffer> AAStrokeRectOp::GetIndexBuffer(GrResourceProvider* resourceProvider,
bool miterStroke) { bool miterStroke) {
if (miterStroke) { if (miterStroke) {
// clang-format off // clang-format off
static const uint16_t gMiterIndices[] = { static const uint16_t gMiterIndices[] = {

View File

@ -117,7 +117,7 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) {
void* vertices = target->makeVertexSpace( void* vertices = target->makeVertexSpace(
vertexStride, glyphCount * kVerticesPerGlyph, &vertexBuffer, &flushInfo.fVertexOffset); vertexStride, glyphCount * kVerticesPerGlyph, &vertexBuffer, &flushInfo.fVertexOffset);
flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer));
flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuffer()); flushInfo.fIndexBuffer = target->resourceProvider()->refQuadIndexBuffer();
if (!vertices || !flushInfo.fVertexBuffer) { if (!vertices || !flushInfo.fVertexBuffer) {
SkDebugf("Could not allocate vertices\n"); SkDebugf("Could not allocate vertices\n");
return; return;

View File

@ -106,7 +106,7 @@ private:
return; return;
} }
sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer()); sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
PatternHelper helper(GrPrimitiveType::kTriangles); PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect, void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect,
kIndicesPerRect, numRects); kIndicesPerRect, numRects);

View File

@ -50,7 +50,7 @@ void GrMeshDrawOp::PatternHelper::recordDraw(Target* target, const GrGeometryPro
} }
void* GrMeshDrawOp::QuadHelper::init(Target* target, size_t vertexStride, int quadsToDraw) { void* GrMeshDrawOp::QuadHelper::init(Target* target, size_t vertexStride, int quadsToDraw) {
sk_sp<const GrBuffer> quadIndexBuffer(target->resourceProvider()->refQuadIndexBuffer()); sk_sp<const GrBuffer> quadIndexBuffer = target->resourceProvider()->refQuadIndexBuffer();
if (!quadIndexBuffer) { if (!quadIndexBuffer) {
SkDebugf("Could not get quad index buffer."); SkDebugf("Could not get quad index buffer.");
return nullptr; return nullptr;

View File

@ -182,7 +182,7 @@ private:
size_t vertexStride = gp->getVertexStride(); size_t vertexStride = gp->getVertexStride();
int rectCount = fRects.count(); int rectCount = fRects.count();
sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer()); sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
PatternHelper helper(GrPrimitiveType::kTriangles); PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect, void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect,
kIndicesPerRect, rectCount); kIndicesPerRect, rectCount);
@ -310,7 +310,7 @@ private:
size_t vertexStride = gp->getVertexStride(); size_t vertexStride = gp->getVertexStride();
int rectCount = fRects.count(); int rectCount = fRects.count();
sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer()); sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
PatternHelper helper(GrPrimitiveType::kTriangles); PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect, void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect,
kIndicesPerRect, rectCount); kIndicesPerRect, rectCount);

View File

@ -2063,8 +2063,8 @@ static const int kNumRRectsInIndexBuffer = 256;
GR_DECLARE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey); GR_DECLARE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey);
GR_DECLARE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey); GR_DECLARE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey);
static const GrBuffer* ref_rrect_index_buffer(RRectType type, static sk_sp<const GrBuffer> get_rrect_index_buffer(RRectType type,
GrResourceProvider* resourceProvider) { GrResourceProvider* resourceProvider) {
GR_DEFINE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey); GR_DEFINE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey);
GR_DEFINE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey); GR_DEFINE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey);
switch (type) { switch (type) {
@ -2203,8 +2203,8 @@ private:
// drop out the middle quad if we're stroked // drop out the middle quad if we're stroked
int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPerFillRRect; int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPerFillRRect;
sk_sp<const GrBuffer> indexBuffer(ref_rrect_index_buffer( sk_sp<const GrBuffer> indexBuffer = get_rrect_index_buffer(
fStroked ? kStroke_RRectType : kFill_RRectType, target->resourceProvider())); fStroked ? kStroke_RRectType : kFill_RRectType, target->resourceProvider());
PatternHelper helper(GrPrimitiveType::kTriangles); PatternHelper helper(GrPrimitiveType::kTriangles);
EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(

View File

@ -123,7 +123,7 @@ private:
return; return;
} }
size_t vertexStride = gp->getVertexStride(); size_t vertexStride = gp->getVertexStride();
sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer()); sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
PatternHelper helper(GrPrimitiveType::kTriangles); PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices = void* vertices =
helper.init(target, vertexStride, indexBuffer.get(), kVertsPerInstance, helper.init(target, vertexStride, indexBuffer.get(), kVertsPerInstance,

View File

@ -276,7 +276,7 @@ private:
&vertexBuffer, &vertexBuffer,
&flushInfo.fVertexOffset); &flushInfo.fVertexOffset);
flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer));
flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuffer()); flushInfo.fIndexBuffer = target->resourceProvider()->refQuadIndexBuffer();
if (!vertices || !flushInfo.fIndexBuffer) { if (!vertices || !flushInfo.fIndexBuffer) {
SkDebugf("Could not allocate vertices\n"); SkDebugf("Could not allocate vertices\n");
return; return;

View File

@ -49,14 +49,13 @@ GrStencilAndCoverPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const
return CanDrawPath::kYes; return CanDrawPath::kYes;
} }
static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const GrShape& shape) { static sk_sp<GrPath> get_gr_path(GrResourceProvider* resourceProvider, const GrShape& shape) {
GrUniqueKey key; GrUniqueKey key;
bool isVolatile; bool isVolatile;
GrPath::ComputeKey(shape, &key, &isVolatile); GrPath::ComputeKey(shape, &key, &isVolatile);
sk_sp<GrPath> path; sk_sp<GrPath> path;
if (!isVolatile) { if (!isVolatile) {
path.reset( path = resourceProvider->findByUniqueKey<GrPath>(key);
static_cast<GrPath*>(resourceProvider->findAndRefResourceByUniqueKey(key)));
} }
if (!path) { if (!path) {
SkPath skPath; SkPath skPath;
@ -72,7 +71,7 @@ static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const GrShape&
SkASSERT(path->isEqualTo(skPath, shape.style())); SkASSERT(path->isEqualTo(skPath, shape.style()));
#endif #endif
} }
return path.release(); return path;
} }
void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) {

View File

@ -250,7 +250,7 @@ private:
memset(&builder[shapeKeyDataCnt], 0, sizeof(fDevClipBounds)); memset(&builder[shapeKeyDataCnt], 0, sizeof(fDevClipBounds));
} }
builder.finish(); builder.finish();
sk_sp<GrBuffer> cachedVertexBuffer(rp->findAndRefTByUniqueKey<GrBuffer>(key)); sk_sp<GrBuffer> cachedVertexBuffer(rp->findByUniqueKey<GrBuffer>(key));
int actualCount; int actualCount;
SkScalar tol = GrPathUtils::kDefaultTolerance; SkScalar tol = GrPathUtils::kDefaultTolerance;
tol = GrPathUtils::scaleToleranceToSrc(tol, fViewMatrix, fShape.bounds()); tol = GrPathUtils::scaleToleranceToSrc(tol, fViewMatrix, fShape.bounds());

View File

@ -346,7 +346,7 @@ private:
} }
sk_sp<const GrBuffer> ibuffer; sk_sp<const GrBuffer> ibuffer;
if (fDraws.count() > 1) { if (fDraws.count() > 1) {
ibuffer.reset(target->resourceProvider()->refQuadIndexBuffer()); ibuffer = target->resourceProvider()->refQuadIndexBuffer();
if (!ibuffer) { if (!ibuffer) {
SkDebugf("Could not allocate quad indices\n"); SkDebugf("Could not allocate quad indices\n");
return; return;

View File

@ -528,10 +528,8 @@ void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t
sk_sp<GrPathRange> GrStencilAndCoverTextContext::TextRun::createGlyphs( sk_sp<GrPathRange> GrStencilAndCoverTextContext::TextRun::createGlyphs(
GrResourceProvider* resourceProvider) const { GrResourceProvider* resourceProvider) const {
sk_sp<GrPathRange> glyphs; sk_sp<GrPathRange> glyphs =
resourceProvider->findByUniqueKey<GrPathRange>(fGlyphPathsKey);
glyphs.reset(static_cast<GrPathRange*>(
resourceProvider->findAndRefResourceByUniqueKey(fGlyphPathsKey)));
if (!glyphs) { if (!glyphs) {
if (fUsingRawGlyphPaths) { if (fUsingRawGlyphPaths) {
SkScalerContextEffects noeffects; SkScalerContextEffects noeffects;

View File

@ -362,9 +362,8 @@ sk_sp<const GrBuffer> DrawMeshHelper::makeVertexBuffer(const T* data, int count)
sk_sp<const GrBuffer> DrawMeshHelper::getIndexBuffer() { sk_sp<const GrBuffer> DrawMeshHelper::getIndexBuffer() {
GR_DEFINE_STATIC_UNIQUE_KEY(gIndexBufferKey); GR_DEFINE_STATIC_UNIQUE_KEY(gIndexBufferKey);
return sk_sp<const GrBuffer>( return fState->resourceProvider()->findOrCreatePatternedIndexBuffer(
fState->resourceProvider()->findOrCreatePatternedIndexBuffer( kIndexPattern, 6, kIndexPatternRepeatCount, 4, gIndexBufferKey);
kIndexPattern, 6, kIndexPatternRepeatCount, 4, gIndexBufferKey));
} }
void DrawMeshHelper::drawMesh(const GrMesh& mesh) { void DrawMeshHelper::drawMesh(const GrMesh& mesh) {