blob: 9e1b6f5c2ba294aa10f75244a47de8ba1983b1d1 [file] [log] [blame]
junov@google.comf93e7172011-03-31 21:26:24 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
junov@google.comf93e7172011-03-31 21:26:24 +00006 */
7
bsalomon@google.com5739d2c2012-05-31 15:07:19 +00008#include "GrGpuGL.h"
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
bsalomon@google.coma469c282012-10-24 18:28:34 +000010#include "GrEffect.h"
bsalomon@google.comd698f772012-10-25 13:22:00 +000011#include "GrGLEffect.h"
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000012#include "SkRTConf.h"
cdalton51192342014-06-09 11:16:58 -070013#include "GrGLNameAllocator.h"
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000014#include "SkTSearch.h"
junov@google.comf93e7172011-03-31 21:26:24 +000015
jvanverth@google.coma2f4b152013-09-16 20:00:46 +000016#ifdef PROGRAM_CACHE_STATS
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000017SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false,
18 "Display program cache usage.");
jvanverth@google.coma2f4b152013-09-16 20:00:46 +000019#endif
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000020
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000021typedef GrGLUniformManager::UniformHandle UniformHandle;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000022
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000023struct GrGpuGL::ProgramCache::Entry {
24 SK_DECLARE_INST_COUNT_ROOT(Entry);
25 Entry() : fProgram(NULL), fLRUStamp(0) {}
26
27 SkAutoTUnref<GrGLProgram> fProgram;
28 unsigned int fLRUStamp;
29};
30
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000031struct GrGpuGL::ProgramCache::ProgDescLess {
32 bool operator() (const GrGLProgramDesc& desc, const Entry* entry) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000033 SkASSERT(NULL != entry->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000034 return GrGLProgramDesc::Less(desc, entry->fProgram->getDesc());
35 }
36
37 bool operator() (const Entry* entry, const GrGLProgramDesc& desc) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000038 SkASSERT(NULL != entry->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000039 return GrGLProgramDesc::Less(entry->fProgram->getDesc(), desc);
40 }
41};
junov@google.comf93e7172011-03-31 21:26:24 +000042
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000043GrGpuGL::ProgramCache::ProgramCache(GrGpuGL* gpu)
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000044 : fCount(0)
45 , fCurrLRUStamp(0)
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000046 , fGpu(gpu)
jvanverth@google.com94878772013-03-12 16:00:54 +000047#ifdef PROGRAM_CACHE_STATS
48 , fTotalRequests(0)
49 , fCacheMisses(0)
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000050 , fHashMisses(0)
jvanverth@google.com94878772013-03-12 16:00:54 +000051#endif
52{
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000053 for (int i = 0; i < 1 << kHashBits; ++i) {
54 fHashTable[i] = NULL;
55 }
jvanverth@google.com94878772013-03-12 16:00:54 +000056}
57
58GrGpuGL::ProgramCache::~ProgramCache() {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000059 for (int i = 0; i < fCount; ++i){
60 SkDELETE(fEntries[i]);
61 }
jvanverth@google.com94878772013-03-12 16:00:54 +000062 // dump stats
63#ifdef PROGRAM_CACHE_STATS
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000064 if (c_DisplayCache) {
65 SkDebugf("--- Program Cache ---\n");
66 SkDebugf("Total requests: %d\n", fTotalRequests);
67 SkDebugf("Cache misses: %d\n", fCacheMisses);
68 SkDebugf("Cache miss %%: %f\n", (fTotalRequests > 0) ?
69 100.f * fCacheMisses / fTotalRequests :
70 0.f);
71 int cacheHits = fTotalRequests - fCacheMisses;
72 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / cacheHits : 0.f);
73 SkDebugf("---------------------\n");
74 }
jvanverth@google.com94878772013-03-12 16:00:54 +000075#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000076}
junov@google.comf93e7172011-03-31 21:26:24 +000077
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000078void GrGpuGL::ProgramCache::abandon() {
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000079 for (int i = 0; i < fCount; ++i) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000080 SkASSERT(NULL != fEntries[i]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000081 fEntries[i]->fProgram->abandon();
82 fEntries[i]->fProgram.reset(NULL);
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000083 }
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000084 fCount = 0;
85}
86
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000087int GrGpuGL::ProgramCache::search(const GrGLProgramDesc& desc) const {
88 ProgDescLess less;
89 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less);
90}
91
bsalomon@google.com31ec7982013-03-27 18:14:57 +000092GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrGLProgramDesc& desc,
bsalomon@google.com2c84aa32013-06-06 20:28:57 +000093 const GrEffectStage* colorStages[],
94 const GrEffectStage* coverageStages[]) {
jvanverth@google.com94878772013-03-12 16:00:54 +000095#ifdef PROGRAM_CACHE_STATS
96 ++fTotalRequests;
97#endif
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +000098
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000099 Entry* entry = NULL;
100
101 uint32_t hashIdx = desc.getChecksum();
102 hashIdx ^= hashIdx >> 16;
103 if (kHashBits <= 8) {
104 hashIdx ^= hashIdx >> 8;
105 }
106 hashIdx &=((1 << kHashBits) - 1);
107 Entry* hashedEntry = fHashTable[hashIdx];
108 if (NULL != hashedEntry && hashedEntry->fProgram->getDesc() == desc) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000109 SkASSERT(NULL != hashedEntry->fProgram);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000110 entry = hashedEntry;
111 }
112
113 int entryIdx;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000114 if (NULL == entry) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000115 entryIdx = this->search(desc);
116 if (entryIdx >= 0) {
117 entry = fEntries[entryIdx];
118#ifdef PROGRAM_CACHE_STATS
119 ++fHashMisses;
120#endif
121 }
122 }
123
124 if (NULL == entry) {
125 // We have a cache miss
jvanverth@google.com94878772013-03-12 16:00:54 +0000126#ifdef PROGRAM_CACHE_STATS
127 ++fCacheMisses;
128#endif
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000129 GrGLProgram* program = GrGLProgram::Create(fGpu, desc, colorStages, coverageStages);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000130 if (NULL == program) {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000131 return NULL;
132 }
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000133 int purgeIdx = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000134 if (fCount < kMaxEntries) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000135 entry = SkNEW(Entry);
136 purgeIdx = fCount++;
137 fEntries[purgeIdx] = entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000138 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000139 SkASSERT(fCount == kMaxEntries);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000140 purgeIdx = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000141 for (int i = 1; i < kMaxEntries; ++i) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000142 if (fEntries[i]->fLRUStamp < fEntries[purgeIdx]->fLRUStamp) {
143 purgeIdx = i;
junov@google.comf93e7172011-03-31 21:26:24 +0000144 }
junov@google.comf93e7172011-03-31 21:26:24 +0000145 }
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000146 entry = fEntries[purgeIdx];
147 int purgedHashIdx = entry->fProgram->getDesc().getChecksum() & ((1 << kHashBits) - 1);
148 if (fHashTable[purgedHashIdx] == entry) {
149 fHashTable[purgedHashIdx] = NULL;
150 }
junov@google.comf93e7172011-03-31 21:26:24 +0000151 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000152 SkASSERT(fEntries[purgeIdx] == entry);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000153 entry->fProgram.reset(program);
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +0000154 // We need to shift fEntries around so that the entry currently at purgeIdx is placed
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000155 // just before the entry at ~entryIdx (in order to keep fEntries sorted by descriptor).
156 entryIdx = ~entryIdx;
157 if (entryIdx < purgeIdx) {
158 // Let E and P be the entries at index entryIdx and purgeIdx, respectively.
159 // If the entries array looks like this:
160 // aaaaEbbbbbPccccc
161 // we rearrange it to look like this:
162 // aaaaPEbbbbbccccc
163 size_t copySize = (purgeIdx - entryIdx) * sizeof(Entry*);
164 memmove(fEntries + entryIdx + 1, fEntries + entryIdx, copySize);
165 fEntries[entryIdx] = entry;
166 } else if (purgeIdx < entryIdx) {
167 // If the entries array looks like this:
168 // aaaaPbbbbbEccccc
169 // we rearrange it to look like this:
170 // aaaabbbbbPEccccc
171 size_t copySize = (entryIdx - purgeIdx - 1) * sizeof(Entry*);
172 memmove(fEntries + purgeIdx, fEntries + purgeIdx + 1, copySize);
173 fEntries[entryIdx - 1] = entry;
174 }
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000175#ifdef SK_DEBUG
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000176 SkASSERT(NULL != fEntries[0]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000177 for (int i = 0; i < fCount - 1; ++i) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000178 SkASSERT(NULL != fEntries[i + 1]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000179 const GrGLProgramDesc& a = fEntries[i]->fProgram->getDesc();
180 const GrGLProgramDesc& b = fEntries[i + 1]->fProgram->getDesc();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000181 SkASSERT(GrGLProgramDesc::Less(a, b));
182 SkASSERT(!GrGLProgramDesc::Less(b, a));
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000183 }
184#endif
junov@google.comf93e7172011-03-31 21:26:24 +0000185 }
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000186
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000187 fHashTable[hashIdx] = entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000188 entry->fLRUStamp = fCurrLRUStamp;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000189
190 if (SK_MaxU32 == fCurrLRUStamp) {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000191 // wrap around! just trash our LRU, one time hit.
192 for (int i = 0; i < fCount; ++i) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000193 fEntries[i]->fLRUStamp = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000194 }
195 }
196 ++fCurrLRUStamp;
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000197 return entry->fProgram;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000198}
junov@google.comf93e7172011-03-31 21:26:24 +0000199
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000200////////////////////////////////////////////////////////////////////////////////
201
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000202void GrGpuGL::abandonResources(){
203 INHERITED::abandonResources();
204 fProgramCache->abandon();
205 fHWProgramID = 0;
cdalton51192342014-06-09 11:16:58 -0700206 fPathNameAllocator.reset(NULL);
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000207}
208
209////////////////////////////////////////////////////////////////////////////////
210
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000211#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
212
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000213bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstCopy) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000214 const GrDrawState& drawState = this->getDrawState();
215
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000216 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000217 SkASSERT(NULL != drawState.getRenderTarget());
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000218
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000219 if (kStencilPath_DrawType == type) {
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000220 const GrRenderTarget* rt = this->getDrawState().getRenderTarget();
221 SkISize size;
222 size.set(rt->width(), rt->height());
223 this->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000224 } else {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000225 this->flushMiscFixedFunctionState();
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000226
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000227 GrBlendCoeff srcCoeff;
228 GrBlendCoeff dstCoeff;
bsalomon@google.com2b446732013-02-12 16:47:41 +0000229 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &srcCoeff, &dstCoeff);
230 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000231 return false;
232 }
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000233
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000234 SkSTArray<8, const GrEffectStage*, true> colorStages;
235 SkSTArray<8, const GrEffectStage*, true> coverageStages;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000236 GrGLProgramDesc desc;
bsalomon848faf02014-07-11 10:01:02 -0700237 if (!GrGLProgramDesc::Build(this->getDrawState(),
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000238 type,
bsalomon@google.com91207482013-02-12 21:45:24 +0000239 blendOpts,
240 srcCoeff,
241 dstCoeff,
242 this,
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000243 dstCopy,
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000244 &colorStages,
245 &coverageStages,
bsalomon848faf02014-07-11 10:01:02 -0700246 &desc)) {
247 SkDEBUGFAIL("Failed to generate GL program descriptor");
248 return false;
249 }
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000250
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000251 fCurrentProgram.reset(fProgramCache->getProgram(desc,
252 colorStages.begin(),
253 coverageStages.begin()));
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000254 if (NULL == fCurrentProgram.get()) {
mtklein@google.com330313a2013-08-22 15:37:26 +0000255 SkDEBUGFAIL("Failed to create program!");
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000256 return false;
257 }
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000258
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000259 SkASSERT((kDrawPath_DrawType != type && kDrawPaths_DrawType != type)
260 || !fCurrentProgram->hasVertexShader());
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000261
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000262 fCurrentProgram.get()->ref();
junov@google.comf93e7172011-03-31 21:26:24 +0000263
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000264 GrGLuint programID = fCurrentProgram->programID();
265 if (fHWProgramID != programID) {
266 GL_CALL(UseProgram(programID));
267 fHWProgramID = programID;
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000268 }
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000269
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000270 fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000271 this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff);
junov@google.comf93e7172011-03-31 21:26:24 +0000272
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000273 fCurrentProgram->setData(blendOpts,
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000274 colorStages.begin(),
275 coverageStages.begin(),
276 dstCopy,
277 &fSharedGLProgramState);
junov@google.comf93e7172011-03-31 21:26:24 +0000278 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000279 this->flushStencil(type);
bsalomon@google.coma3201942012-06-21 19:58:20 +0000280 this->flushScissor();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000281 this->flushAAState(type);
bsalomon@google.com4c883782012-06-04 19:05:11 +0000282
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000283 SkIRect* devRect = NULL;
284 SkIRect devClipBounds;
robertphillips@google.com3e11c0b2012-07-11 18:20:35 +0000285 if (drawState.isClipState()) {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000286 this->getClip()->getConservativeBounds(drawState.getRenderTarget(), &devClipBounds);
robertphillips@google.com7b112892012-07-31 15:18:21 +0000287 devRect = &devClipBounds;
bsalomon@google.com4c883782012-06-04 19:05:11 +0000288 }
289 // This must come after textures are flushed because a texture may need
290 // to be msaa-resolved (which will modify bound FBO state).
robertphillips@google.com7b112892012-07-31 15:18:21 +0000291 this->flushRenderTarget(devRect);
bsalomon@google.com4c883782012-06-04 19:05:11 +0000292
junov@google.comf93e7172011-03-31 21:26:24 +0000293 return true;
294}
295
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000296void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
junov@google.comf93e7172011-03-31 21:26:24 +0000297
robertphillips@google.coma4662862013-11-21 14:24:16 +0000298 GrGLsizei stride = static_cast<GrGLsizei>(this->getDrawState().getVertexSize());
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000299
bsalomon@google.com6918d482013-03-07 19:09:11 +0000300 size_t vertexOffsetInBytes = stride * info.startVertex();
301
302 const GeometryPoolState& geoPoolState = this->getGeomPoolState();
303
304 GrGLVertexBuffer* vbuf;
305 switch (this->getGeomSrc().fVertexSrc) {
306 case kBuffer_GeometrySrcType:
307 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
308 break;
309 case kArray_GeometrySrcType:
310 case kReserved_GeometrySrcType:
311 this->finalizeReservedVertices();
312 vertexOffsetInBytes += geoPoolState.fPoolStartVertex * this->getGeomSrc().fVertexSize;
313 vbuf = (GrGLVertexBuffer*) geoPoolState.fPoolVertexBuffer;
314 break;
315 default:
316 vbuf = NULL; // suppress warning
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000317 SkFAIL("Unknown geometry src type!");
bsalomon@google.com6918d482013-03-07 19:09:11 +0000318 }
319
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000320 SkASSERT(NULL != vbuf);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000321 SkASSERT(!vbuf->isMapped());
bsalomon@google.com6918d482013-03-07 19:09:11 +0000322 vertexOffsetInBytes += vbuf->baseOffset();
323
324 GrGLIndexBuffer* ibuf = NULL;
325 if (info.isIndexed()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000326 SkASSERT(NULL != indexOffsetInBytes);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000327
328 switch (this->getGeomSrc().fIndexSrc) {
329 case kBuffer_GeometrySrcType:
330 *indexOffsetInBytes = 0;
331 ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
332 break;
333 case kArray_GeometrySrcType:
334 case kReserved_GeometrySrcType:
335 this->finalizeReservedIndices();
336 *indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLushort);
337 ibuf = (GrGLIndexBuffer*) geoPoolState.fPoolIndexBuffer;
338 break;
339 default:
340 ibuf = NULL; // suppress warning
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000341 SkFAIL("Unknown geometry src type!");
bsalomon@google.com6918d482013-03-07 19:09:11 +0000342 }
343
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000344 SkASSERT(NULL != ibuf);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000345 SkASSERT(!ibuf->isMapped());
bsalomon@google.com6918d482013-03-07 19:09:11 +0000346 *indexOffsetInBytes += ibuf->baseOffset();
347 }
348 GrGLAttribArrayState* attribState =
349 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
junov@google.comf93e7172011-03-31 21:26:24 +0000350
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000351 if (fCurrentProgram->hasVertexShader()) {
commit-bot@chromium.org6ebfbf92014-02-24 12:05:02 +0000352 int vertexAttribCount = this->getDrawState().getVertexAttribCount();
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000353 uint32_t usedAttribArraysMask = 0;
354 const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttribs();
commit-bot@chromium.org6ebfbf92014-02-24 12:05:02 +0000355
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000356 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount;
357 ++vertexAttribIndex, ++vertexAttrib) {
robertphillips@google.comaf3a3b92013-02-28 23:08:28 +0000358
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000359 usedAttribArraysMask |= (1 << vertexAttribIndex);
360 GrVertexAttribType attribType = vertexAttrib->fType;
361 attribState->set(this,
362 vertexAttribIndex,
363 vbuf,
364 GrGLAttribTypeToLayout(attribType).fCount,
365 GrGLAttribTypeToLayout(attribType).fType,
366 GrGLAttribTypeToLayout(attribType).fNormalized,
367 stride,
368 reinterpret_cast<GrGLvoid*>(
commit-bot@chromium.org6ebfbf92014-02-24 12:05:02 +0000369 vertexOffsetInBytes + vertexAttrib->fOffset));
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000370 }
commit-bot@chromium.org6ebfbf92014-02-24 12:05:02 +0000371 attribState->disableUnusedArrays(this, usedAttribArraysMask);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000372 }
junov@google.comf93e7172011-03-31 21:26:24 +0000373}