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 |
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 |
OLD | NEW |