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

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

Issue 1831133004: Revert of Consolidate GPU buffer implementations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/GrResourceProvider.h ('k') | src/gpu/GrSoftwarePathRenderer.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 #include "GrResourceProvider.h" 8 #include "GrResourceProvider.h"
9 9
10 #include "GrBuffer.h"
11 #include "GrGpu.h" 10 #include "GrGpu.h"
11 #include "GrIndexBuffer.h"
12 #include "GrPathRendering.h" 12 #include "GrPathRendering.h"
13 #include "GrRenderTarget.h" 13 #include "GrRenderTarget.h"
14 #include "GrRenderTargetPriv.h" 14 #include "GrRenderTargetPriv.h"
15 #include "GrResourceCache.h" 15 #include "GrResourceCache.h"
16 #include "GrResourceKey.h" 16 #include "GrResourceKey.h"
17 #include "GrStencilAttachment.h" 17 #include "GrStencilAttachment.h"
18 #include "GrVertexBuffer.h"
18 19
19 GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); 20 GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
20 21
21 GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSin gleOwner* owner) 22 GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSin gleOwner* owner)
22 : INHERITED(gpu, cache, owner) { 23 : INHERITED(gpu, cache, owner) {
23 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); 24 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
24 fQuadIndexBufferKey = gQuadIndexBufferKey; 25 fQuadIndexBufferKey = gQuadIndexBufferKey;
25 } 26 }
26 27
27 const GrBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16_t* p attern, 28 const GrIndexBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16 _t* pattern,
28 int patternSize, 29 int patternS ize,
29 int reps, 30 int reps,
30 int vertCount, 31 int vertCoun t,
31 const GrUniqueKey & key) { 32 const GrUniq ueKey& key) {
32 size_t bufferSize = patternSize * reps * sizeof(uint16_t); 33 size_t bufferSize = patternSize * reps * sizeof(uint16_t);
33 34
34 // This is typically used in GrBatchs, so we assume kNoPendingIO. 35 // This is typically used in GrBatchs, so we assume kNoPendingIO.
35 GrBuffer* buffer = this->createBuffer(kIndex_GrBufferType, bufferSize, kStat ic_GrAccessPattern, 36 GrIndexBuffer* buffer = this->createIndexBuffer(bufferSize, kStatic_BufferUs age,
36 kNoPendingIO_Flag); 37 kNoPendingIO_Flag);
37 if (!buffer) { 38 if (!buffer) {
38 return nullptr; 39 return nullptr;
39 } 40 }
40 uint16_t* data = (uint16_t*) buffer->map(); 41 uint16_t* data = (uint16_t*) buffer->map();
41 bool useTempData = (nullptr == data); 42 bool useTempData = (nullptr == data);
42 if (useTempData) { 43 if (useTempData) {
43 data = new uint16_t[reps * patternSize]; 44 data = new uint16_t[reps * patternSize];
44 } 45 }
45 for (int i = 0; i < reps; ++i) { 46 for (int i = 0; i < reps; ++i) {
46 int baseIdx = i * patternSize; 47 int baseIdx = i * patternSize;
47 uint16_t baseVert = (uint16_t)(i * vertCount); 48 uint16_t baseVert = (uint16_t)(i * vertCount);
48 for (int j = 0; j < patternSize; ++j) { 49 for (int j = 0; j < patternSize; ++j) {
49 data[baseIdx+j] = baseVert + pattern[j]; 50 data[baseIdx+j] = baseVert + pattern[j];
50 } 51 }
51 } 52 }
52 if (useTempData) { 53 if (useTempData) {
53 if (!buffer->updateData(data, bufferSize)) { 54 if (!buffer->updateData(data, bufferSize)) {
54 buffer->unref(); 55 buffer->unref();
55 return nullptr; 56 return nullptr;
56 } 57 }
57 delete[] data; 58 delete[] data;
58 } else { 59 } else {
59 buffer->unmap(); 60 buffer->unmap();
60 } 61 }
61 this->assignUniqueKeyToResource(key, buffer); 62 this->assignUniqueKeyToResource(key, buffer);
62 return buffer; 63 return buffer;
63 } 64 }
64 65
65 const GrBuffer* GrResourceProvider::createQuadIndexBuffer() { 66 const GrIndexBuffer* GrResourceProvider::createQuadIndexBuffer() {
66 static const int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1; 67 static const int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1;
67 GR_STATIC_ASSERT(4 * kMaxQuads <= 65535); 68 GR_STATIC_ASSERT(4 * kMaxQuads <= 65535);
68 static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 }; 69 static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 };
69 70
70 return this->createInstancedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadInde xBufferKey); 71 return this->createInstancedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadInde xBufferKey);
71 } 72 }
72 73
73 GrPath* GrResourceProvider::createPath(const SkPath& path, const GrStrokeInfo& s troke) { 74 GrPath* GrResourceProvider::createPath(const SkPath& path, const GrStrokeInfo& s troke) {
74 SkASSERT(this->gpu()->pathRendering()); 75 SkASSERT(this->gpu()->pathRendering());
75 return this->gpu()->pathRendering()->createPath(path, stroke); 76 return this->gpu()->pathRendering()->createPath(path, stroke);
76 } 77 }
77 78
78 GrPathRange* GrResourceProvider::createPathRange(GrPathRange::PathGenerator* gen , 79 GrPathRange* GrResourceProvider::createPathRange(GrPathRange::PathGenerator* gen ,
79 const GrStrokeInfo& stroke) { 80 const GrStrokeInfo& stroke) {
80 SkASSERT(this->gpu()->pathRendering()); 81 SkASSERT(this->gpu()->pathRendering());
81 return this->gpu()->pathRendering()->createPathRange(gen, stroke); 82 return this->gpu()->pathRendering()->createPathRange(gen, stroke);
82 } 83 }
83 84
84 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc riptor* desc, 85 GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDesc riptor* desc,
85 const GrStrokeInfo& stroke) { 86 const GrStrokeInfo& stroke) {
86 87
87 SkASSERT(this->gpu()->pathRendering()); 88 SkASSERT(this->gpu()->pathRendering());
88 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke); 89 return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke);
89 } 90 }
90 91
91 GrBuffer* GrResourceProvider::createBuffer(GrBufferType type, size_t size, 92 GrIndexBuffer* GrResourceProvider::createIndexBuffer(size_t size, BufferUsage us age,
92 GrAccessPattern accessPattern, uint32 _t flags) { 93 uint32_t flags) {
93 if (this->isAbandoned()) { 94 if (this->isAbandoned()) {
94 return nullptr; 95 return nullptr;
95 } 96 }
96 97
97 if (kDynamic_GrAccessPattern == accessPattern) { 98 bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag);
99 bool dynamic = kDynamic_BufferUsage == usage;
100 if (dynamic) {
98 // bin by pow2 with a reasonable min 101 // bin by pow2 with a reasonable min
99 static const uint32_t MIN_SIZE = 1 << 12; 102 static const uint32_t MIN_SIZE = 1 << 12;
100 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size))); 103 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size)));
101 104
102 GrScratchKey key; 105 GrScratchKey key;
103 GrBuffer::ComputeScratchKeyForDynamicBuffer(type, size, &key); 106 GrIndexBuffer::ComputeScratchKey(size, true, &key);
104 uint32_t scratchFlags = 0; 107 uint32_t scratchFlags = 0;
105 if (flags & kNoPendingIO_Flag) { 108 if (noPendingIO) {
106 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; 109 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
107 } else { 110 } else {
108 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; 111 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
109 } 112 }
110 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, size, scratchFlags); 113 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, size, scratchFlags);
111 if (resource) { 114 if (resource) {
112 return static_cast<GrBuffer*>(resource); 115 return static_cast<GrIndexBuffer*>(resource);
113 } 116 }
114 } 117 }
115 return this->gpu()->createBuffer(type, size, accessPattern); 118 return this->gpu()->createIndexBuffer(size, dynamic);
119 }
120
121 GrVertexBuffer* GrResourceProvider::createVertexBuffer(size_t size, BufferUsage usage,
122 uint32_t flags) {
123 if (this->isAbandoned()) {
124 return nullptr;
125 }
126
127 bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag);
128 bool dynamic = kDynamic_BufferUsage == usage;
129 if (dynamic) {
130 // bin by pow2 with a reasonable min
131 static const uint32_t MIN_SIZE = 1 << 12;
132 size = SkTMax(MIN_SIZE, GrNextPow2(SkToUInt(size)));
133
134 GrScratchKey key;
135 GrVertexBuffer::ComputeScratchKey(size, true, &key);
136 uint32_t scratchFlags = 0;
137 if (noPendingIO) {
138 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
139 } else {
140 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
141 }
142 GrGpuResource* resource = this->cache()->findAndRefScratchResource(key, size, scratchFlags);
143 if (resource) {
144 return static_cast<GrVertexBuffer*>(resource);
145 }
146 }
147 return this->gpu()->createVertexBuffer(size, dynamic);
148 }
149
150 GrTransferBuffer* GrResourceProvider::createTransferBuffer(size_t size, Transfer Type type,
151 uint32_t flags) {
152 if (this->isAbandoned()) {
153 return nullptr;
154 }
155
156 //bool noPendingIO = SkToBool(flags & kNoPendingIO_Flag);
157 return this->gpu()->createTransferBuffer(size, type);
116 } 158 }
117 159
118 GrBatchAtlas* GrResourceProvider::createAtlas(GrPixelConfig config, 160 GrBatchAtlas* GrResourceProvider::createAtlas(GrPixelConfig config,
119 int width, int height, 161 int width, int height,
120 int numPlotsX, int numPlotsY, 162 int numPlotsX, int numPlotsY,
121 GrBatchAtlas::EvictionFunc func, v oid* data) { 163 GrBatchAtlas::EvictionFunc func, v oid* data) {
122 GrSurfaceDesc desc; 164 GrSurfaceDesc desc;
123 desc.fFlags = kNone_GrSurfaceFlags; 165 desc.fFlags = kNone_GrSurfaceFlags;
124 desc.fWidth = width; 166 desc.fWidth = width;
125 desc.fHeight = height; 167 desc.fHeight = height;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 228 }
187 229
188 GrRenderTarget* GrResourceProvider::wrapBackendTextureAsRenderTarget( 230 GrRenderTarget* GrResourceProvider::wrapBackendTextureAsRenderTarget(
189 const GrBackendTextureDesc& desc, GrWrapOwnership ownership) { 231 const GrBackendTextureDesc& desc, GrWrapOwnership ownership) {
190 if (this->isAbandoned()) { 232 if (this->isAbandoned()) {
191 return nullptr; 233 return nullptr;
192 } 234 }
193 return this->gpu()->wrapBackendTextureAsRenderTarget(desc, ownership); 235 return this->gpu()->wrapBackendTextureAsRenderTarget(desc, ownership);
194 } 236 }
195 237
OLDNEW
« no previous file with comments | « src/gpu/GrResourceProvider.h ('k') | src/gpu/GrSoftwarePathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698