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 "GrIndexBuffer.h" | 11 #include "GrIndexBuffer.h" |
12 #include "GrTextureProvider.h" | 12 #include "GrTextureProvider.h" |
13 #include "GrPathRange.h" | 13 #include "GrPathRange.h" |
14 | 14 |
15 class GrIndexBuffer; | 15 class GrIndexBuffer; |
16 class GrPath; | 16 class GrPath; |
17 class GrStrokeInfo; | 17 class GrStrokeInfo; |
18 class GrVertexBuffer; | 18 class GrVertexBuffer; |
19 class SkDescriptor; | 19 class SkDescriptor; |
20 class SkPath; | 20 class SkPath; |
21 class SkTypeface; | 21 class SkTypeface; |
22 | 22 |
23 /** | 23 /** |
24 * An extension of the texture provider for arbitrary resource types. This class
is intended for | 24 * An extension of the texture provider for arbitrary resource types. This class
is intended for |
25 * use within the Gr code base, not by clients or extensions (e.g. third party G
rProcessor | 25 * use within the Gr code base, not by clients or extensions (e.g. third party G
rProcessor |
26 * derivatives). | 26 * derivatives). |
| 27 * |
| 28 * This currently inherits from GrTextureProvider non-publically to force caller
s to provider |
| 29 * make a flags (pendingIO) decision and not use the GrTP methods that don't tak
e flags. This |
| 30 * can be relaxed once http://skbug.com/4156 is fixed. |
27 */ | 31 */ |
28 class GrResourceProvider : public GrTextureProvider { | 32 class GrResourceProvider : protected GrTextureProvider { |
29 public: | 33 public: |
30 | |
31 GrResourceProvider(GrGpu* gpu, GrResourceCache* cache); | 34 GrResourceProvider(GrGpu* gpu, GrResourceCache* cache); |
32 | 35 |
33 template <typename T> T* findAndRefTByUniqueKey(const GrUniqueKey& key) { | 36 template <typename T> T* findAndRefTByUniqueKey(const GrUniqueKey& key) { |
34 return static_cast<T*>(this->findAndRefResourceByUniqueKey(key)); | 37 return static_cast<T*>(this->findAndRefResourceByUniqueKey(key)); |
35 } | 38 } |
36 | 39 |
37 /** | 40 /** |
38 * Either finds and refs, or creates an index buffer for instanced drawing w
ith a specific | 41 * Either finds and refs, or creates an index buffer for instanced drawing w
ith a specific |
39 * pattern if the index buffer is not found. If the return is non-null, the
caller owns | 42 * pattern if the index buffer is not found. If the return is non-null, the
caller owns |
40 * a ref on the returned GrIndexBuffer. | 43 * a ref on the returned GrIndexBuffer. |
41 * | 44 * |
42 * @param pattern the pattern of indices to repeat | 45 * @param pattern the pattern of indices to repeat |
43 * @param patternSize size in bytes of the pattern | 46 * @param patternSize size in bytes of the pattern |
44 * @param reps number of times to repeat the pattern | 47 * @param reps number of times to repeat the pattern |
45 * @param vertCount number of vertices the pattern references | 48 * @param vertCount number of vertices the pattern references |
46 * @param key Key to be assigned to the index buffer. | 49 * @param key Key to be assigned to the index buffer. |
47 * | 50 * |
48 * @return The index buffer if successful, otherwise NULL. | 51 * @return The index buffer if successful, otherwise NULL. |
49 */ | 52 */ |
50 const GrIndexBuffer* refOrCreateInstancedIndexBuffer(const uint16_t* pattern
, | 53 const GrIndexBuffer* findOrCreateInstancedIndexBuffer(const uint16_t* patter
n, |
51 int patternSize, | 54 int patternSize, |
52 int reps, | 55 int reps, |
53 int vertCount, | 56 int vertCount, |
54 const GrUniqueKey& key)
{ | 57 const GrUniqueKey& key
) { |
55 if (GrIndexBuffer* buffer = this->findAndRefTByUniqueKey<GrIndexBuffer>(
key)) { | 58 if (GrIndexBuffer* buffer = this->findAndRefTByUniqueKey<GrIndexBuffer>(
key)) { |
56 return buffer; | 59 return buffer; |
57 } | 60 } |
58 return this->createInstancedIndexBuffer(pattern, patternSize, reps, vert
Count, key); | 61 return this->createInstancedIndexBuffer(pattern, patternSize, reps, vert
Count, key); |
59 } | 62 } |
60 | 63 |
61 /** | 64 /** |
62 * Returns an index buffer that can be used to render quads. | 65 * Returns an index buffer that can be used to render quads. |
63 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc. | 66 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc. |
64 * The max number of quads can be queried using GrIndexBuffer::maxQuads(). | 67 * The max number of quads can be queried using GrIndexBuffer::maxQuads(). |
65 * Draw with kTriangles_GrPrimitiveType | 68 * Draw with kTriangles_GrPrimitiveType |
66 * @ return the quad index buffer | 69 * @ return the quad index buffer |
67 */ | 70 */ |
68 const GrIndexBuffer* refQuadIndexBuffer() { | 71 const GrIndexBuffer* refQuadIndexBuffer() { |
69 if (GrIndexBuffer* buffer = | 72 if (GrIndexBuffer* buffer = |
70 this->findAndRefTByUniqueKey<GrIndexBuffer>(fQuadIndexBufferKey)) { | 73 this->findAndRefTByUniqueKey<GrIndexBuffer>(fQuadIndexBufferKey)) { |
71 return buffer; | 74 return buffer; |
72 } | 75 } |
73 return this->createQuadIndexBuffer(); | 76 return this->createQuadIndexBuffer(); |
74 } | 77 } |
75 | 78 |
76 /** | 79 /** |
77 * Factories for GrPath and GrPathRange objects. It's an error to call these
if path rendering | 80 * Factories for GrPath and GrPathRange objects. It's an error to call these
if path rendering |
78 * is not supported. | 81 * is not supported. |
79 */ | 82 */ |
80 GrPath* createPath(const SkPath&, const GrStrokeInfo&); | 83 GrPath* createPath(const SkPath&, const GrStrokeInfo&); |
81 GrPathRange* createPathRange(GrPathRange::PathGenerator*, const GrStrokeInfo
&); | 84 GrPathRange* createPathRange(GrPathRange::PathGenerator*, const GrStrokeInfo
&); |
82 GrPathRange* createGlyphs(const SkTypeface*, const SkDescriptor*, const GrSt
rokeInfo&); | 85 GrPathRange* createGlyphs(const SkTypeface*, const SkDescriptor*, const GrSt
rokeInfo&); |
83 | 86 |
84 | |
85 using GrTextureProvider::assignUniqueKeyToResource; | 87 using GrTextureProvider::assignUniqueKeyToResource; |
86 using GrTextureProvider::findAndRefResourceByUniqueKey; | 88 using GrTextureProvider::findAndRefResourceByUniqueKey; |
87 using GrTextureProvider::abandon; | 89 using GrTextureProvider::abandon; |
88 | 90 |
89 GrIndexBuffer* getIndexBuffer(size_t size, bool dynamic, bool calledDuringFl
ush); | 91 enum Flags { |
90 GrVertexBuffer* getVertexBuffer(size_t size, bool dynamic, bool calledDuring
Flush); | 92 /** If the caller intends to do direct reads/writes to/from the CPU then
this flag must be |
| 93 * set when accessing resources during a GrDrawTarget flush. This inclu
des the execution of |
| 94 * GrBatch objects. The reason is that these memory operations are done
immediately and |
| 95 * will occur out of order WRT the operations being flushed. |
| 96 * Make this automatic: http://skbug.com/4156 |
| 97 */ |
| 98 kNoPendingIO_Flag = kNoPendingIO_ScratchTextureFlag, |
| 99 }; |
| 100 |
| 101 enum BufferUsage { |
| 102 /** Caller intends to specify the buffer data rarely with respect to the
number of draws |
| 103 that read the data. */ |
| 104 kStatic_BufferUsage, |
| 105 /** Caller intends to respecify the buffer data frequently between draws
. */ |
| 106 kDynamic_BufferUsage, |
| 107 }; |
| 108 GrIndexBuffer* createIndexBuffer(size_t size, BufferUsage, uint32_t flags); |
| 109 GrVertexBuffer* createVertexBuffer(size_t size, BufferUsage, uint32_t flags)
; |
| 110 |
| 111 GrTexture* createApproxTexture(const GrSurfaceDesc& desc, uint32_t flags) { |
| 112 SkASSERT(0 == flags || kNoPendingIO_Flag == flags); |
| 113 return this->internalCreateApproxTexture(desc, flags); |
| 114 } |
91 | 115 |
92 private: | 116 private: |
93 const GrIndexBuffer* createInstancedIndexBuffer(const uint16_t* pattern, | 117 const GrIndexBuffer* createInstancedIndexBuffer(const uint16_t* pattern, |
94 int patternSize, | 118 int patternSize, |
95 int reps, | 119 int reps, |
96 int vertCount, | 120 int vertCount, |
97 const GrUniqueKey& key); | 121 const GrUniqueKey& key); |
98 | 122 |
99 const GrIndexBuffer* createQuadIndexBuffer(); | 123 const GrIndexBuffer* createQuadIndexBuffer(); |
100 | 124 |
101 GrUniqueKey fQuadIndexBufferKey; | 125 GrUniqueKey fQuadIndexBufferKey; |
102 | 126 |
103 typedef GrTextureProvider INHERITED; | 127 typedef GrTextureProvider INHERITED; |
104 }; | 128 }; |
105 | 129 |
106 #endif | 130 #endif |
OLD | NEW |