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

Unified Diff: src/gpu/GrResourceProvider.h

Issue 1116943004: Move instanced index buffer creation to flush time (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix missing assignment of keys to index buffers Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrOvalRenderer.cpp ('k') | src/gpu/GrResourceProvider.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrResourceProvider.h
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index f560afa0fd509ff4e47a6d2910941474c8bda955..0d80cdd2a086f45941aba8c838ef9d7cc49de8fe 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -10,6 +10,9 @@
#include "GrTextureProvider.h"
+class GrIndexBuffer;
+class GrVertexBuffer;
+
/**
* An extension of the texture provider for arbitrary resource types. This class is intended for
* use within the Gr code base, not by clients or extensions (e.g. third party GrProcessor
@@ -18,12 +21,67 @@
class GrResourceProvider : public GrTextureProvider {
public:
- GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INHERITED(gpu, cache) {}
+ GrResourceProvider(GrGpu* gpu, GrResourceCache* cache);
+
+ template <typename T> T* findAndRefTByUniqueKey(const GrUniqueKey& key) {
+ return static_cast<T*>(this->findAndRefResourceByUniqueKey(key));
+ }
+
+ /**
+ * Either finds and refs, or creates an index buffer for instanced drawing with a specific
+ * pattern if the index buffer is not found. If the return is non-null, the caller owns
+ * a ref on the returned GrIndexBuffer.
+ *
+ * @param pattern the pattern of indices to repeat
+ * @param patternSize size in bytes of the pattern
+ * @param reps number of times to repeat the pattern
+ * @param vertCount number of vertices the pattern references
+ * @param key Key to be assigned to the index buffer.
+ *
+ * @return The index buffer if successful, otherwise NULL.
+ */
+ const GrIndexBuffer* refOrCreateInstancedIndexBuffer(const uint16_t* pattern,
+ int patternSize,
+ int reps,
+ int vertCount,
+ const GrUniqueKey& key) {
+ if (GrIndexBuffer* buffer = this->findAndRefTByUniqueKey<GrIndexBuffer>(key)) {
+ return buffer;
+ }
+ return this->createInstancedIndexBuffer(pattern, patternSize, reps, vertCount, key);
+ }
+
+ /**
+ * Returns an index buffer that can be used to render quads.
+ * Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
+ * The max number of quads can be queried using GrIndexBuffer::maxQuads().
+ * Draw with kTriangles_GrPrimitiveType
+ * @ return the quad index buffer
+ */
+ const GrIndexBuffer* refQuadIndexBuffer() {
+ if (GrIndexBuffer* buffer =
+ this->findAndRefTByUniqueKey<GrIndexBuffer>(fQuadIndexBufferKey)) {
+ return buffer;
+ }
+ return this->createQuadIndexBuffer();
+ }
+
using GrTextureProvider::assignUniqueKeyToResource;
using GrTextureProvider::findAndRefResourceByUniqueKey;
using GrTextureProvider::abandon;
+private:
+ const GrIndexBuffer* createInstancedIndexBuffer(const uint16_t* pattern,
+ int patternSize,
+ int reps,
+ int vertCount,
+ const GrUniqueKey& key);
+
+ const GrIndexBuffer* createQuadIndexBuffer();
+
+ GrUniqueKey fQuadIndexBufferKey;
+
typedef GrTextureProvider INHERITED;
};
« no previous file with comments | « src/gpu/GrOvalRenderer.cpp ('k') | src/gpu/GrResourceProvider.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698