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

Side by Side 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, 7 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 unified diff | Download patch
« no previous file with comments | « src/gpu/GrOvalRenderer.cpp ('k') | src/gpu/GrResourceProvider.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrResourceProvider_DEFINED 8 #ifndef GrResourceProvider_DEFINED
9 #define GrResourceProvider_DEFINED 9 #define GrResourceProvider_DEFINED
10 10
11 #include "GrTextureProvider.h" 11 #include "GrTextureProvider.h"
12 12
13 class GrIndexBuffer;
14 class GrVertexBuffer;
15
13 /** 16 /**
14 * An extension of the texture provider for arbitrary resource types. This class is intended for 17 * An extension of the texture provider for arbitrary resource types. This class is intended for
15 * use within the Gr code base, not by clients or extensions (e.g. third party G rProcessor 18 * use within the Gr code base, not by clients or extensions (e.g. third party G rProcessor
16 * derivatives). 19 * derivatives).
17 */ 20 */
18 class GrResourceProvider : public GrTextureProvider { 21 class GrResourceProvider : public GrTextureProvider {
19 public: 22 public:
20 23
21 GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INHERITED(gpu, cach e) {} 24 GrResourceProvider(GrGpu* gpu, GrResourceCache* cache);
25
26 template <typename T> T* findAndRefTByUniqueKey(const GrUniqueKey& key) {
27 return static_cast<T*>(this->findAndRefResourceByUniqueKey(key));
28 }
29
30 /**
31 * Either finds and refs, or creates an index buffer for instanced drawing w ith a specific
32 * pattern if the index buffer is not found. If the return is non-null, the caller owns
33 * a ref on the returned GrIndexBuffer.
34 *
35 * @param pattern the pattern of indices to repeat
36 * @param patternSize size in bytes of the pattern
37 * @param reps number of times to repeat the pattern
38 * @param vertCount number of vertices the pattern references
39 * @param key Key to be assigned to the index buffer.
40 *
41 * @return The index buffer if successful, otherwise NULL.
42 */
43 const GrIndexBuffer* refOrCreateInstancedIndexBuffer(const uint16_t* pattern ,
44 int patternSize,
45 int reps,
46 int vertCount,
47 const GrUniqueKey& key) {
48 if (GrIndexBuffer* buffer = this->findAndRefTByUniqueKey<GrIndexBuffer>( key)) {
49 return buffer;
50 }
51 return this->createInstancedIndexBuffer(pattern, patternSize, reps, vert Count, key);
52 }
53
54 /**
55 * Returns an index buffer that can be used to render quads.
56 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
57 * The max number of quads can be queried using GrIndexBuffer::maxQuads().
58 * Draw with kTriangles_GrPrimitiveType
59 * @ return the quad index buffer
60 */
61 const GrIndexBuffer* refQuadIndexBuffer() {
62 if (GrIndexBuffer* buffer =
63 this->findAndRefTByUniqueKey<GrIndexBuffer>(fQuadIndexBufferKey)) {
64 return buffer;
65 }
66 return this->createQuadIndexBuffer();
67 }
68
22 69
23 using GrTextureProvider::assignUniqueKeyToResource; 70 using GrTextureProvider::assignUniqueKeyToResource;
24 using GrTextureProvider::findAndRefResourceByUniqueKey; 71 using GrTextureProvider::findAndRefResourceByUniqueKey;
25 using GrTextureProvider::abandon; 72 using GrTextureProvider::abandon;
26 73
74 private:
75 const GrIndexBuffer* createInstancedIndexBuffer(const uint16_t* pattern,
76 int patternSize,
77 int reps,
78 int vertCount,
79 const GrUniqueKey& key);
80
81 const GrIndexBuffer* createQuadIndexBuffer();
82
83 GrUniqueKey fQuadIndexBufferKey;
84
27 typedef GrTextureProvider INHERITED; 85 typedef GrTextureProvider INHERITED;
28 }; 86 };
29 87
30 #endif 88 #endif
OLDNEW
« 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