OLD | NEW |
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 | |
16 /** | 13 /** |
17 * An extension of the texture provider for arbitrary resource types. This class
is intended for | 14 * An extension of the texture provider for arbitrary resource types. This class
is intended for |
18 * use within the Gr code base, not by clients or extensions (e.g. third party G
rProcessor | 15 * use within the Gr code base, not by clients or extensions (e.g. third party G
rProcessor |
19 * derivatives). | 16 * derivatives). |
20 */ | 17 */ |
21 class GrResourceProvider : public GrTextureProvider { | 18 class GrResourceProvider : public GrTextureProvider { |
22 public: | 19 public: |
23 | 20 |
24 GrResourceProvider(GrGpu* gpu, GrResourceCache* cache); | 21 GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INHERITED(gpu, cach
e) {} |
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 | |
69 | 22 |
70 using GrTextureProvider::assignUniqueKeyToResource; | 23 using GrTextureProvider::assignUniqueKeyToResource; |
71 using GrTextureProvider::findAndRefResourceByUniqueKey; | 24 using GrTextureProvider::findAndRefResourceByUniqueKey; |
72 using GrTextureProvider::abandon; | 25 using GrTextureProvider::abandon; |
73 | 26 |
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 | |
85 typedef GrTextureProvider INHERITED; | 27 typedef GrTextureProvider INHERITED; |
86 }; | 28 }; |
87 | 29 |
88 #endif | 30 #endif |
OLD | NEW |