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

Side by Side Diff: src/gpu/GrResourceProvider.h

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