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 "GrBatchAtlas.h" | 11 #include "GrBatchAtlas.h" |
12 #include "GrBuffer.h" | 12 #include "GrIndexBuffer.h" |
13 #include "GrTextureProvider.h" | 13 #include "GrTextureProvider.h" |
14 #include "GrPathRange.h" | 14 #include "GrPathRange.h" |
15 | 15 |
16 class GrBatchAtlas; | 16 class GrBatchAtlas; |
| 17 class GrIndexBuffer; |
17 class GrPath; | 18 class GrPath; |
18 class GrRenderTarget; | 19 class GrRenderTarget; |
19 class GrSingleOwner; | 20 class GrSingleOwner; |
20 class GrStencilAttachment; | 21 class GrStencilAttachment; |
21 class GrStrokeInfo; | 22 class GrStrokeInfo; |
| 23 class GrVertexBuffer; |
22 class SkDescriptor; | 24 class SkDescriptor; |
23 class SkPath; | 25 class SkPath; |
24 class SkTypeface; | 26 class SkTypeface; |
25 | 27 |
26 /** | 28 /** |
27 * An extension of the texture provider for arbitrary resource types. This class
is intended for | 29 * An extension of the texture provider for arbitrary resource types. This class
is intended for |
28 * use within the Gr code base, not by clients or extensions (e.g. third party G
rProcessor | 30 * use within the Gr code base, not by clients or extensions (e.g. third party G
rProcessor |
29 * derivatives). | 31 * derivatives). |
30 * | 32 * |
31 * This currently inherits from GrTextureProvider non-publically to force caller
s to provider | 33 * This currently inherits from GrTextureProvider non-publically to force caller
s to provider |
32 * make a flags (pendingIO) decision and not use the GrTP methods that don't tak
e flags. This | 34 * make a flags (pendingIO) decision and not use the GrTP methods that don't tak
e flags. This |
33 * can be relaxed once https://bug.skia.org/4156 is fixed. | 35 * can be relaxed once https://bug.skia.org/4156 is fixed. |
34 */ | 36 */ |
35 class GrResourceProvider : protected GrTextureProvider { | 37 class GrResourceProvider : protected GrTextureProvider { |
36 public: | 38 public: |
37 GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* owner)
; | 39 GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* owner)
; |
38 | 40 |
39 template <typename T> T* findAndRefTByUniqueKey(const GrUniqueKey& key) { | 41 template <typename T> T* findAndRefTByUniqueKey(const GrUniqueKey& key) { |
40 return static_cast<T*>(this->findAndRefResourceByUniqueKey(key)); | 42 return static_cast<T*>(this->findAndRefResourceByUniqueKey(key)); |
41 } | 43 } |
42 | 44 |
43 /** | 45 /** |
44 * Either finds and refs, or creates an index buffer for instanced drawing w
ith a specific | 46 * Either finds and refs, or creates an index buffer for instanced drawing w
ith a specific |
45 * pattern if the index buffer is not found. If the return is non-null, the
caller owns | 47 * pattern if the index buffer is not found. If the return is non-null, the
caller owns |
46 * a ref on the returned GrBuffer. | 48 * a ref on the returned GrIndexBuffer. |
47 * | 49 * |
48 * @param pattern the pattern of indices to repeat | 50 * @param pattern the pattern of indices to repeat |
49 * @param patternSize size in bytes of the pattern | 51 * @param patternSize size in bytes of the pattern |
50 * @param reps number of times to repeat the pattern | 52 * @param reps number of times to repeat the pattern |
51 * @param vertCount number of vertices the pattern references | 53 * @param vertCount number of vertices the pattern references |
52 * @param key Key to be assigned to the index buffer. | 54 * @param key Key to be assigned to the index buffer. |
53 * | 55 * |
54 * @return The index buffer if successful, otherwise nullptr. | 56 * @return The index buffer if successful, otherwise nullptr. |
55 */ | 57 */ |
56 const GrBuffer* findOrCreateInstancedIndexBuffer(const uint16_t* pattern, | 58 const GrIndexBuffer* findOrCreateInstancedIndexBuffer(const uint16_t* patter
n, |
57 int patternSize, | 59 int patternSize, |
58 int reps, | 60 int reps, |
59 int vertCount, | 61 int vertCount, |
60 const GrUniqueKey& key) { | 62 const GrUniqueKey& key
) { |
61 if (GrBuffer* buffer = this->findAndRefTByUniqueKey<GrBuffer>(key)) { | 63 if (GrIndexBuffer* buffer = this->findAndRefTByUniqueKey<GrIndexBuffer>(
key)) { |
62 return buffer; | 64 return buffer; |
63 } | 65 } |
64 return this->createInstancedIndexBuffer(pattern, patternSize, reps, vert
Count, key); | 66 return this->createInstancedIndexBuffer(pattern, patternSize, reps, vert
Count, key); |
65 } | 67 } |
66 | 68 |
67 /** | 69 /** |
68 * Returns an index buffer that can be used to render quads. | 70 * Returns an index buffer that can be used to render quads. |
69 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc. | 71 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc. |
70 * The max number of quads is the buffer's index capacity divided by 6. | 72 * The max number of quads can be queried using GrIndexBuffer::maxQuads(). |
71 * Draw with kTriangles_GrPrimitiveType | 73 * Draw with kTriangles_GrPrimitiveType |
72 * @ return the quad index buffer | 74 * @ return the quad index buffer |
73 */ | 75 */ |
74 const GrBuffer* refQuadIndexBuffer() { | 76 const GrIndexBuffer* refQuadIndexBuffer() { |
75 if (GrBuffer* buffer = | 77 if (GrIndexBuffer* buffer = |
76 this->findAndRefTByUniqueKey<GrBuffer>(fQuadIndexBufferKey)) { | 78 this->findAndRefTByUniqueKey<GrIndexBuffer>(fQuadIndexBufferKey)) { |
77 return buffer; | 79 return buffer; |
78 } | 80 } |
79 return this->createQuadIndexBuffer(); | 81 return this->createQuadIndexBuffer(); |
80 } | 82 } |
81 | 83 |
82 /** | 84 /** |
83 * Factories for GrPath and GrPathRange objects. It's an error to call these
if path rendering | 85 * Factories for GrPath and GrPathRange objects. It's an error to call these
if path rendering |
84 * is not supported. | 86 * is not supported. |
85 */ | 87 */ |
86 GrPath* createPath(const SkPath&, const GrStrokeInfo&); | 88 GrPath* createPath(const SkPath&, const GrStrokeInfo&); |
87 GrPathRange* createPathRange(GrPathRange::PathGenerator*, const GrStrokeInfo
&); | 89 GrPathRange* createPathRange(GrPathRange::PathGenerator*, const GrStrokeInfo
&); |
88 GrPathRange* createGlyphs(const SkTypeface*, const SkDescriptor*, const GrSt
rokeInfo&); | 90 GrPathRange* createGlyphs(const SkTypeface*, const SkDescriptor*, const GrSt
rokeInfo&); |
89 | 91 |
90 using GrTextureProvider::assignUniqueKeyToResource; | 92 using GrTextureProvider::assignUniqueKeyToResource; |
91 using GrTextureProvider::findAndRefResourceByUniqueKey; | 93 using GrTextureProvider::findAndRefResourceByUniqueKey; |
92 using GrTextureProvider::findAndRefTextureByUniqueKey; | 94 using GrTextureProvider::findAndRefTextureByUniqueKey; |
93 using GrTextureProvider::abandon; | 95 using GrTextureProvider::abandon; |
94 | 96 |
95 enum Flags { | 97 enum Flags { |
96 /** If the caller intends to do direct reads/writes to/from the CPU then
this flag must be | 98 /** If the caller intends to do direct reads/writes to/from the CPU then
this flag must be |
97 * set when accessing resources during a GrDrawTarget flush. This inclu
des the execution of | 99 * set when accessing resources during a GrDrawTarget flush. This inclu
des the execution of |
98 * GrBatch objects. The reason is that these memory operations are done
immediately and | 100 * GrBatch objects. The reason is that these memory operations are done
immediately and |
99 * will occur out of order WRT the operations being flushed. | 101 * will occur out of order WRT the operations being flushed. |
100 * Make this automatic: https://bug.skia.org/4156 | 102 * Make this automatic: https://bug.skia.org/4156 |
101 */ | 103 */ |
102 kNoPendingIO_Flag = kNoPendingIO_ScratchTextureFlag, | 104 kNoPendingIO_Flag = kNoPendingIO_ScratchTextureFlag, |
103 }; | 105 }; |
104 | 106 |
105 GrBuffer* createBuffer(GrBufferType, size_t size, GrAccessPattern, uint32_t
flags); | 107 enum BufferUsage { |
| 108 /** Caller intends to specify the buffer data rarely with respect to the
number of draws |
| 109 that read the data. */ |
| 110 kStatic_BufferUsage, |
| 111 /** Caller intends to respecify the buffer data frequently between draws
. */ |
| 112 kDynamic_BufferUsage, |
| 113 }; |
| 114 GrIndexBuffer* createIndexBuffer(size_t size, BufferUsage, uint32_t flags); |
| 115 GrVertexBuffer* createVertexBuffer(size_t size, BufferUsage, uint32_t flags)
; |
| 116 GrTransferBuffer* createTransferBuffer(size_t size, TransferType, uint32_t f
lags); |
106 | 117 |
107 GrTexture* createApproxTexture(const GrSurfaceDesc& desc, uint32_t flags) { | 118 GrTexture* createApproxTexture(const GrSurfaceDesc& desc, uint32_t flags) { |
108 SkASSERT(0 == flags || kNoPendingIO_Flag == flags); | 119 SkASSERT(0 == flags || kNoPendingIO_Flag == flags); |
109 return this->internalCreateApproxTexture(desc, flags); | 120 return this->internalCreateApproxTexture(desc, flags); |
110 } | 121 } |
111 | 122 |
112 /** Returns a GrBatchAtlas. This function can be called anywhere, but the r
eturned atlas should | 123 /** Returns a GrBatchAtlas. This function can be called anywhere, but the r
eturned atlas should |
113 * only be used inside of GrBatch::generateGeometry | 124 * only be used inside of GrBatch::generateGeometry |
114 * @param GrPixelConfig The pixel config which this atlas will store | 125 * @param GrPixelConfig The pixel config which this atlas will store |
115 * @param width width in pixels of the atlas | 126 * @param width width in pixels of the atlas |
(...skipping 23 matching lines...) Expand all Loading... |
139 /** | 150 /** |
140 * Wraps an existing texture with a GrRenderTarget object. This is useful w
hen the provided | 151 * Wraps an existing texture with a GrRenderTarget object. This is useful w
hen the provided |
141 * texture has a format that cannot be textured from by Skia, but we want t
o raster to it. | 152 * texture has a format that cannot be textured from by Skia, but we want t
o raster to it. |
142 * | 153 * |
143 * @return GrRenderTarget object or NULL on failure. | 154 * @return GrRenderTarget object or NULL on failure. |
144 */ | 155 */ |
145 GrRenderTarget* wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc
& desc, | 156 GrRenderTarget* wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc
& desc, |
146 GrWrapOwnership = kBorrow_
GrWrapOwnership); | 157 GrWrapOwnership = kBorrow_
GrWrapOwnership); |
147 | 158 |
148 private: | 159 private: |
149 const GrBuffer* createInstancedIndexBuffer(const uint16_t* pattern, | 160 const GrIndexBuffer* createInstancedIndexBuffer(const uint16_t* pattern, |
150 int patternSize, | 161 int patternSize, |
151 int reps, | 162 int reps, |
152 int vertCount, | 163 int vertCount, |
153 const GrUniqueKey& key); | 164 const GrUniqueKey& key); |
154 | 165 |
155 const GrBuffer* createQuadIndexBuffer(); | 166 const GrIndexBuffer* createQuadIndexBuffer(); |
156 | 167 |
157 GrUniqueKey fQuadIndexBufferKey; | 168 GrUniqueKey fQuadIndexBufferKey; |
158 | 169 |
159 typedef GrTextureProvider INHERITED; | 170 typedef GrTextureProvider INHERITED; |
160 }; | 171 }; |
161 | 172 |
162 #endif | 173 #endif |
OLD | NEW |