blob: 7dba5316a4e7afee640b9c4402ca2e1b07129148 [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
joshualitt47bb3822014-10-07 16:43:25 -070010#include "builders/GrGLProgramBuilder.h"
joshualittb0a8a372014-09-23 09:50:21 -070011#include "GrProcessor.h"
12#include "GrGLProcessor.h"
egdaniel8a4c1032014-09-16 07:18:54 -070013#include "GrGLPathRendering.h"
egdaniel170f90b2014-09-16 12:54:40 -070014#include "GrOptDrawState.h"
15#include "SkRTConf.h"
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000016#include "SkTSearch.h"
junov@google.comf93e7172011-03-31 21:26:24 +000017
jvanverth@google.coma2f4b152013-09-16 20:00:46 +000018#ifdef PROGRAM_CACHE_STATS
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000019SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false,
20 "Display program cache usage.");
jvanverth@google.coma2f4b152013-09-16 20:00:46 +000021#endif
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000022
kkinnunen7510b222014-07-30 00:04:16 -070023typedef GrGLProgramDataManager::UniformHandle UniformHandle;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000024
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000025struct GrGpuGL::ProgramCache::Entry {
26 SK_DECLARE_INST_COUNT_ROOT(Entry);
27 Entry() : fProgram(NULL), fLRUStamp(0) {}
28
29 SkAutoTUnref<GrGLProgram> fProgram;
30 unsigned int fLRUStamp;
31};
32
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000033struct GrGpuGL::ProgramCache::ProgDescLess {
34 bool operator() (const GrGLProgramDesc& desc, const Entry* entry) {
bsalomon49f085d2014-09-05 13:34:00 -070035 SkASSERT(entry->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000036 return GrGLProgramDesc::Less(desc, entry->fProgram->getDesc());
37 }
38
39 bool operator() (const Entry* entry, const GrGLProgramDesc& desc) {
bsalomon49f085d2014-09-05 13:34:00 -070040 SkASSERT(entry->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000041 return GrGLProgramDesc::Less(entry->fProgram->getDesc(), desc);
42 }
43};
junov@google.comf93e7172011-03-31 21:26:24 +000044
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000045GrGpuGL::ProgramCache::ProgramCache(GrGpuGL* gpu)
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000046 : fCount(0)
47 , fCurrLRUStamp(0)
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000048 , fGpu(gpu)
jvanverth@google.com94878772013-03-12 16:00:54 +000049#ifdef PROGRAM_CACHE_STATS
50 , fTotalRequests(0)
51 , fCacheMisses(0)
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000052 , fHashMisses(0)
jvanverth@google.com94878772013-03-12 16:00:54 +000053#endif
54{
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000055 for (int i = 0; i < 1 << kHashBits; ++i) {
56 fHashTable[i] = NULL;
57 }
jvanverth@google.com94878772013-03-12 16:00:54 +000058}
59
60GrGpuGL::ProgramCache::~ProgramCache() {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000061 for (int i = 0; i < fCount; ++i){
62 SkDELETE(fEntries[i]);
63 }
jvanverth@google.com94878772013-03-12 16:00:54 +000064 // dump stats
65#ifdef PROGRAM_CACHE_STATS
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000066 if (c_DisplayCache) {
67 SkDebugf("--- Program Cache ---\n");
68 SkDebugf("Total requests: %d\n", fTotalRequests);
69 SkDebugf("Cache misses: %d\n", fCacheMisses);
70 SkDebugf("Cache miss %%: %f\n", (fTotalRequests > 0) ?
71 100.f * fCacheMisses / fTotalRequests :
72 0.f);
73 int cacheHits = fTotalRequests - fCacheMisses;
74 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / cacheHits : 0.f);
75 SkDebugf("---------------------\n");
76 }
jvanverth@google.com94878772013-03-12 16:00:54 +000077#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000078}
junov@google.comf93e7172011-03-31 21:26:24 +000079
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000080void GrGpuGL::ProgramCache::abandon() {
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000081 for (int i = 0; i < fCount; ++i) {
bsalomon49f085d2014-09-05 13:34:00 -070082 SkASSERT(fEntries[i]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000083 fEntries[i]->fProgram->abandon();
bsalomon944bcf02014-07-29 08:01:52 -070084 SkDELETE(fEntries[i]);
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000085 }
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000086 fCount = 0;
87}
88
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000089int GrGpuGL::ProgramCache::search(const GrGLProgramDesc& desc) const {
90 ProgDescLess less;
91 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less);
92}
93
egdaniel307796b2014-10-06 12:13:54 -070094GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState,
95 const GrGLProgramDesc& desc,
joshualitt89c7a2e2014-10-10 14:11:59 -070096 DrawType type,
97 const GrGeometryStage* geometryProcessor,
98 const GrFragmentStage* colorStages[],
99 const GrFragmentStage* coverageStages[]) {
jvanverth@google.com94878772013-03-12 16:00:54 +0000100#ifdef PROGRAM_CACHE_STATS
101 ++fTotalRequests;
102#endif
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000103
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000104 Entry* entry = NULL;
105
106 uint32_t hashIdx = desc.getChecksum();
107 hashIdx ^= hashIdx >> 16;
108 if (kHashBits <= 8) {
109 hashIdx ^= hashIdx >> 8;
110 }
111 hashIdx &=((1 << kHashBits) - 1);
112 Entry* hashedEntry = fHashTable[hashIdx];
bsalomon49f085d2014-09-05 13:34:00 -0700113 if (hashedEntry && hashedEntry->fProgram->getDesc() == desc) {
114 SkASSERT(hashedEntry->fProgram);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000115 entry = hashedEntry;
116 }
117
118 int entryIdx;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000119 if (NULL == entry) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000120 entryIdx = this->search(desc);
121 if (entryIdx >= 0) {
122 entry = fEntries[entryIdx];
123#ifdef PROGRAM_CACHE_STATS
124 ++fHashMisses;
125#endif
126 }
127 }
128
129 if (NULL == entry) {
130 // We have a cache miss
jvanverth@google.com94878772013-03-12 16:00:54 +0000131#ifdef PROGRAM_CACHE_STATS
132 ++fCacheMisses;
133#endif
joshualitt89c7a2e2014-10-10 14:11:59 -0700134 GrGLProgram* program = GrGLProgramBuilder::CreateProgram(optState, desc, type,
135 geometryProcessor, colorStages,
136 coverageStages, fGpu);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000137 if (NULL == program) {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000138 return NULL;
139 }
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000140 int purgeIdx = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000141 if (fCount < kMaxEntries) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000142 entry = SkNEW(Entry);
143 purgeIdx = fCount++;
144 fEntries[purgeIdx] = entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000145 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000146 SkASSERT(fCount == kMaxEntries);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000147 purgeIdx = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000148 for (int i = 1; i < kMaxEntries; ++i) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000149 if (fEntries[i]->fLRUStamp < fEntries[purgeIdx]->fLRUStamp) {
150 purgeIdx = i;
junov@google.comf93e7172011-03-31 21:26:24 +0000151 }
junov@google.comf93e7172011-03-31 21:26:24 +0000152 }
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000153 entry = fEntries[purgeIdx];
154 int purgedHashIdx = entry->fProgram->getDesc().getChecksum() & ((1 << kHashBits) - 1);
155 if (fHashTable[purgedHashIdx] == entry) {
156 fHashTable[purgedHashIdx] = NULL;
157 }
junov@google.comf93e7172011-03-31 21:26:24 +0000158 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000159 SkASSERT(fEntries[purgeIdx] == entry);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000160 entry->fProgram.reset(program);
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +0000161 // We need to shift fEntries around so that the entry currently at purgeIdx is placed
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000162 // just before the entry at ~entryIdx (in order to keep fEntries sorted by descriptor).
163 entryIdx = ~entryIdx;
164 if (entryIdx < purgeIdx) {
165 // Let E and P be the entries at index entryIdx and purgeIdx, respectively.
166 // If the entries array looks like this:
167 // aaaaEbbbbbPccccc
168 // we rearrange it to look like this:
169 // aaaaPEbbbbbccccc
170 size_t copySize = (purgeIdx - entryIdx) * sizeof(Entry*);
171 memmove(fEntries + entryIdx + 1, fEntries + entryIdx, copySize);
172 fEntries[entryIdx] = entry;
173 } else if (purgeIdx < entryIdx) {
174 // If the entries array looks like this:
175 // aaaaPbbbbbEccccc
176 // we rearrange it to look like this:
177 // aaaabbbbbPEccccc
178 size_t copySize = (entryIdx - purgeIdx - 1) * sizeof(Entry*);
179 memmove(fEntries + purgeIdx, fEntries + purgeIdx + 1, copySize);
180 fEntries[entryIdx - 1] = entry;
181 }
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000182#ifdef SK_DEBUG
bsalomon49f085d2014-09-05 13:34:00 -0700183 SkASSERT(fEntries[0]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000184 for (int i = 0; i < fCount - 1; ++i) {
bsalomon49f085d2014-09-05 13:34:00 -0700185 SkASSERT(fEntries[i + 1]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000186 const GrGLProgramDesc& a = fEntries[i]->fProgram->getDesc();
187 const GrGLProgramDesc& b = fEntries[i + 1]->fProgram->getDesc();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000188 SkASSERT(GrGLProgramDesc::Less(a, b));
189 SkASSERT(!GrGLProgramDesc::Less(b, a));
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000190 }
191#endif
junov@google.comf93e7172011-03-31 21:26:24 +0000192 }
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000193
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000194 fHashTable[hashIdx] = entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000195 entry->fLRUStamp = fCurrLRUStamp;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000196
197 if (SK_MaxU32 == fCurrLRUStamp) {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000198 // wrap around! just trash our LRU, one time hit.
199 for (int i = 0; i < fCount; ++i) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000200 fEntries[i]->fLRUStamp = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000201 }
202 }
203 ++fCurrLRUStamp;
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000204 return entry->fProgram;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000205}
junov@google.comf93e7172011-03-31 21:26:24 +0000206
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000207////////////////////////////////////////////////////////////////////////////////
208
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000209#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
210
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000211bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstCopy) {
egdanielb109ac22014-10-07 06:45:44 -0700212 SkAutoTUnref<GrOptDrawState> optState(GrOptDrawState::Create(this->getDrawState(),
213 *this->caps(),
214 type));
215
216 if (!optState) {
217 return false;
218 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000219
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000220 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
egdaniel170f90b2014-09-16 12:54:40 -0700221 SkASSERT(optState->getRenderTarget());
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000222
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000223 if (kStencilPath_DrawType == type) {
egdaniel170f90b2014-09-16 12:54:40 -0700224 const GrRenderTarget* rt = optState->getRenderTarget();
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000225 SkISize size;
226 size.set(rt->width(), rt->height());
egdaniel170f90b2014-09-16 12:54:40 -0700227 this->glPathRendering()->setProjectionMatrix(optState->getViewMatrix(), size, rt->origin());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000228 } else {
egdanield632ea42014-09-24 10:30:12 -0700229 this->flushMiscFixedFunctionState(*optState.get());
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000230
egdaniel170f90b2014-09-16 12:54:40 -0700231 GrBlendCoeff srcCoeff = optState->getSrcBlendCoeff();
232 GrBlendCoeff dstCoeff = optState->getDstBlendCoeff();
233
234 // In these blend coeff's we end up drawing nothing so we can skip draw all together
235 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
236 !optState->getStencil().doesWrite()) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000237 return false;
238 }
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000239
joshualitt89c7a2e2014-10-10 14:11:59 -0700240 const GrGeometryStage* geometryProcessor = NULL;
241 SkSTArray<8, const GrFragmentStage*, true> colorStages;
242 SkSTArray<8, const GrFragmentStage*, true> coverageStages;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000243 GrGLProgramDesc desc;
joshualitt89c7a2e2014-10-10 14:11:59 -0700244 if (!GrGLProgramDesc::Build(*optState.get(),
245 type,
246 srcCoeff,
247 dstCoeff,
248 this,
249 dstCopy,
250 &geometryProcessor,
251 &colorStages,
252 &coverageStages,
253 &desc)) {
bsalomon848faf02014-07-11 10:01:02 -0700254 SkDEBUGFAIL("Failed to generate GL program descriptor");
255 return false;
256 }
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000257
joshualitt89c7a2e2014-10-10 14:11:59 -0700258 fCurrentProgram.reset(fProgramCache->getProgram(*optState.get(),
259 desc,
260 type,
261 geometryProcessor,
262 colorStages.begin(),
263 coverageStages.begin()));
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000264 if (NULL == fCurrentProgram.get()) {
mtklein@google.com330313a2013-08-22 15:37:26 +0000265 SkDEBUGFAIL("Failed to create program!");
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000266 return false;
267 }
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000268
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000269 fCurrentProgram.get()->ref();
junov@google.comf93e7172011-03-31 21:26:24 +0000270
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000271 GrGLuint programID = fCurrentProgram->programID();
272 if (fHWProgramID != programID) {
273 GL_CALL(UseProgram(programID));
274 fHWProgramID = programID;
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000275 }
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000276
egdanield632ea42014-09-24 10:30:12 -0700277 this->flushBlend(*optState.get(), kDrawLines_DrawType == type, srcCoeff, dstCoeff);
junov@google.comf93e7172011-03-31 21:26:24 +0000278
joshualitt89c7a2e2014-10-10 14:11:59 -0700279 fCurrentProgram->setData(*optState.get(),
280 type,
281 geometryProcessor,
282 colorStages.begin(),
283 coverageStages.begin(),
284 dstCopy,
285 &fSharedGLProgramState);
junov@google.comf93e7172011-03-31 21:26:24 +0000286 }
bsalomonb0bd4f62014-09-03 07:19:50 -0700287
egdaniel170f90b2014-09-16 12:54:40 -0700288 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState->getRenderTarget());
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000289 this->flushStencil(type);
bsalomonb0bd4f62014-09-03 07:19:50 -0700290 this->flushScissor(glRT->getViewport(), glRT->origin());
egdanield632ea42014-09-24 10:30:12 -0700291 this->flushAAState(*optState.get(), type);
bsalomon@google.com4c883782012-06-04 19:05:11 +0000292
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000293 SkIRect* devRect = NULL;
294 SkIRect devClipBounds;
egdaniel170f90b2014-09-16 12:54:40 -0700295 if (optState->isClipState()) {
296 this->getClip()->getConservativeBounds(optState->getRenderTarget(), &devClipBounds);
robertphillips@google.com7b112892012-07-31 15:18:21 +0000297 devRect = &devClipBounds;
bsalomon@google.com4c883782012-06-04 19:05:11 +0000298 }
299 // This must come after textures are flushed because a texture may need
300 // to be msaa-resolved (which will modify bound FBO state).
bsalomonb0bd4f62014-09-03 07:19:50 -0700301 this->flushRenderTarget(glRT, devRect);
bsalomon@google.com4c883782012-06-04 19:05:11 +0000302
junov@google.comf93e7172011-03-31 21:26:24 +0000303 return true;
304}
305
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000306void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
egdanielb109ac22014-10-07 06:45:44 -0700307 SkAutoTUnref<GrOptDrawState> optState(
308 GrOptDrawState::Create(this->getDrawState(), *this->caps(),
309 PrimTypeToDrawType(info.primitiveType())));
310
311 // If the optState would is NULL it should have been caught in flushGraphicsState before getting
312 // here.
313 SkASSERT(optState);
junov@google.comf93e7172011-03-31 21:26:24 +0000314
egdaniel170f90b2014-09-16 12:54:40 -0700315 GrGLsizei stride = static_cast<GrGLsizei>(optState->getVertexStride());
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000316
bsalomon@google.com6918d482013-03-07 19:09:11 +0000317 size_t vertexOffsetInBytes = stride * info.startVertex();
318
319 const GeometryPoolState& geoPoolState = this->getGeomPoolState();
320
321 GrGLVertexBuffer* vbuf;
322 switch (this->getGeomSrc().fVertexSrc) {
323 case kBuffer_GeometrySrcType:
324 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
325 break;
326 case kArray_GeometrySrcType:
327 case kReserved_GeometrySrcType:
328 this->finalizeReservedVertices();
329 vertexOffsetInBytes += geoPoolState.fPoolStartVertex * this->getGeomSrc().fVertexSize;
330 vbuf = (GrGLVertexBuffer*) geoPoolState.fPoolVertexBuffer;
331 break;
332 default:
333 vbuf = NULL; // suppress warning
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000334 SkFAIL("Unknown geometry src type!");
bsalomon@google.com6918d482013-03-07 19:09:11 +0000335 }
336
bsalomon49f085d2014-09-05 13:34:00 -0700337 SkASSERT(vbuf);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000338 SkASSERT(!vbuf->isMapped());
bsalomon@google.com6918d482013-03-07 19:09:11 +0000339 vertexOffsetInBytes += vbuf->baseOffset();
340
341 GrGLIndexBuffer* ibuf = NULL;
342 if (info.isIndexed()) {
bsalomon49f085d2014-09-05 13:34:00 -0700343 SkASSERT(indexOffsetInBytes);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000344
345 switch (this->getGeomSrc().fIndexSrc) {
346 case kBuffer_GeometrySrcType:
347 *indexOffsetInBytes = 0;
348 ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
349 break;
350 case kArray_GeometrySrcType:
351 case kReserved_GeometrySrcType:
352 this->finalizeReservedIndices();
353 *indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLushort);
354 ibuf = (GrGLIndexBuffer*) geoPoolState.fPoolIndexBuffer;
355 break;
356 default:
357 ibuf = NULL; // suppress warning
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000358 SkFAIL("Unknown geometry src type!");
bsalomon@google.com6918d482013-03-07 19:09:11 +0000359 }
360
bsalomon49f085d2014-09-05 13:34:00 -0700361 SkASSERT(ibuf);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000362 SkASSERT(!ibuf->isMapped());
bsalomon@google.com6918d482013-03-07 19:09:11 +0000363 *indexOffsetInBytes += ibuf->baseOffset();
364 }
365 GrGLAttribArrayState* attribState =
366 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
junov@google.comf93e7172011-03-31 21:26:24 +0000367
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000368 if (fCurrentProgram->hasVertexShader()) {
egdaniel170f90b2014-09-16 12:54:40 -0700369 int vertexAttribCount = optState->getVertexAttribCount();
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000370 uint32_t usedAttribArraysMask = 0;
egdaniel170f90b2014-09-16 12:54:40 -0700371 const GrVertexAttrib* vertexAttrib = optState->getVertexAttribs();
egdaniel02cafcc2014-07-21 11:37:28 -0700372
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000373 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount;
374 ++vertexAttribIndex, ++vertexAttrib) {
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000375 usedAttribArraysMask |= (1 << vertexAttribIndex);
376 GrVertexAttribType attribType = vertexAttrib->fType;
377 attribState->set(this,
378 vertexAttribIndex,
379 vbuf,
380 GrGLAttribTypeToLayout(attribType).fCount,
381 GrGLAttribTypeToLayout(attribType).fType,
382 GrGLAttribTypeToLayout(attribType).fNormalized,
383 stride,
384 reinterpret_cast<GrGLvoid*>(
commit-bot@chromium.org6ebfbf92014-02-24 12:05:02 +0000385 vertexOffsetInBytes + vertexAttrib->fOffset));
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000386 }
commit-bot@chromium.org6ebfbf92014-02-24 12:05:02 +0000387 attribState->disableUnusedArrays(this, usedAttribArraysMask);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000388 }
junov@google.comf93e7172011-03-31 21:26:24 +0000389}