Index: src/gpu/GrResourceProvider.cpp |
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp |
index 4b9d265129849698f92a161abf9f237cc2b7173e..3c447bded6d3d173610352e66e2638db455c7a66 100644 |
--- a/src/gpu/GrResourceProvider.cpp |
+++ b/src/gpu/GrResourceProvider.cpp |
@@ -28,7 +28,7 @@ const GrIndexBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16 |
const GrUniqueKey& key) { |
size_t bufferSize = patternSize * reps * sizeof(uint16_t); |
- GrIndexBuffer* buffer = this->gpu()->createIndexBuffer(bufferSize, /* dynamic = */ false); |
+ GrIndexBuffer* buffer = this->getIndexBuffer(bufferSize, /* dynamic = */ false, true); |
if (!buffer) { |
return NULL; |
} |
@@ -83,3 +83,58 @@ GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc |
return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); |
} |
+GrIndexBuffer* GrResourceProvider::getIndexBuffer(size_t size, bool dynamic, |
+ bool calledDuringFlush) { |
+ if (this->isAbandoned()) { |
+ return NULL; |
+ } |
+ |
+ if (dynamic) { |
+ // bin by pow2 with a reasonable min |
+ static const uint32_t MIN_SIZE = 1 << 12; |
+ size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); |
+ |
+ GrScratchKey key; |
+ GrIndexBuffer::ComputeScratchKey(size, dynamic, &key); |
+ uint32_t scratchFlags = 0; |
+ if (calledDuringFlush) { |
+ scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
+ } else { |
+ scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
+ } |
+ GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, scratchFlags); |
+ if (resource) { |
+ return static_cast<GrIndexBuffer*>(resource); |
+ } |
+ } |
+ |
+ return this->gpu()->createIndexBuffer(size, dynamic); |
+} |
+ |
+GrVertexBuffer* GrResourceProvider::getVertexBuffer(size_t size, bool dynamic, |
+ bool calledDuringFlush) { |
+ if (this->isAbandoned()) { |
+ return NULL; |
+ } |
+ |
+ if (dynamic) { |
+ // bin by pow2 with a reasonable min |
+ static const uint32_t MIN_SIZE = 1 << 15; |
+ size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); |
+ |
+ GrScratchKey key; |
+ GrVertexBuffer::ComputeScratchKey(size, dynamic, &key); |
+ uint32_t scratchFlags = 0; |
+ if (calledDuringFlush) { |
+ scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
+ } else { |
+ scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
+ } |
+ GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, scratchFlags); |
+ if (resource) { |
+ return static_cast<GrVertexBuffer*>(resource); |
+ } |
+ } |
+ |
+ return this->gpu()->createVertexBuffer(size, dynamic); |
+} |