blob: 363d87fbfbf1089ccfe2f0007209d6b086c1e9f4 [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
joshualittb0a8a372014-09-23 09:50:21 -070010#include "GrProcessor.h"
11#include "GrGLProcessor.h"
egdaniel8a4c1032014-09-16 07:18:54 -070012#include "GrGLPathRendering.h"
egdaniel170f90b2014-09-16 12:54:40 -070013#include "GrOptDrawState.h"
14#include "SkRTConf.h"
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000015#include "SkTSearch.h"
junov@google.comf93e7172011-03-31 21:26:24 +000016
jvanverth@google.coma2f4b152013-09-16 20:00:46 +000017#ifdef PROGRAM_CACHE_STATS
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000018SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false,
19 "Display program cache usage.");
jvanverth@google.coma2f4b152013-09-16 20:00:46 +000020#endif
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000021
kkinnunen7510b222014-07-30 00:04:16 -070022typedef GrGLProgramDataManager::UniformHandle UniformHandle;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000023
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000024struct GrGpuGL::ProgramCache::Entry {
25 SK_DECLARE_INST_COUNT_ROOT(Entry);
26 Entry() : fProgram(NULL), fLRUStamp(0) {}
27
28 SkAutoTUnref<GrGLProgram> fProgram;
29 unsigned int fLRUStamp;
30};
31
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000032struct GrGpuGL::ProgramCache::ProgDescLess {
33 bool operator() (const GrGLProgramDesc& desc, const Entry* entry) {
bsalomon49f085d2014-09-05 13:34:00 -070034 SkASSERT(entry->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000035 return GrGLProgramDesc::Less(desc, entry->fProgram->getDesc());
36 }
37
38 bool operator() (const Entry* entry, const GrGLProgramDesc& desc) {
bsalomon49f085d2014-09-05 13:34:00 -070039 SkASSERT(entry->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000040 return GrGLProgramDesc::Less(entry->fProgram->getDesc(), desc);
41 }
42};
junov@google.comf93e7172011-03-31 21:26:24 +000043
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000044GrGpuGL::ProgramCache::ProgramCache(GrGpuGL* gpu)
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000045 : fCount(0)
46 , fCurrLRUStamp(0)
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000047 , fGpu(gpu)
jvanverth@google.com94878772013-03-12 16:00:54 +000048#ifdef PROGRAM_CACHE_STATS
49 , fTotalRequests(0)
50 , fCacheMisses(0)
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000051 , fHashMisses(0)
jvanverth@google.com94878772013-03-12 16:00:54 +000052#endif
53{
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000054 for (int i = 0; i < 1 << kHashBits; ++i) {
55 fHashTable[i] = NULL;
56 }
jvanverth@google.com94878772013-03-12 16:00:54 +000057}
58
59GrGpuGL::ProgramCache::~ProgramCache() {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000060 for (int i = 0; i < fCount; ++i){
61 SkDELETE(fEntries[i]);
62 }
jvanverth@google.com94878772013-03-12 16:00:54 +000063 // dump stats
64#ifdef PROGRAM_CACHE_STATS
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000065 if (c_DisplayCache) {
66 SkDebugf("--- Program Cache ---\n");
67 SkDebugf("Total requests: %d\n", fTotalRequests);
68 SkDebugf("Cache misses: %d\n", fCacheMisses);
69 SkDebugf("Cache miss %%: %f\n", (fTotalRequests > 0) ?
70 100.f * fCacheMisses / fTotalRequests :
71 0.f);
72 int cacheHits = fTotalRequests - fCacheMisses;
73 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / cacheHits : 0.f);
74 SkDebugf("---------------------\n");
75 }
jvanverth@google.com94878772013-03-12 16:00:54 +000076#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000077}
junov@google.comf93e7172011-03-31 21:26:24 +000078
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000079void GrGpuGL::ProgramCache::abandon() {
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000080 for (int i = 0; i < fCount; ++i) {
bsalomon49f085d2014-09-05 13:34:00 -070081 SkASSERT(fEntries[i]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000082 fEntries[i]->fProgram->abandon();
bsalomon944bcf02014-07-29 08:01:52 -070083 SkDELETE(fEntries[i]);
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000084 }
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000085 fCount = 0;
86}
87
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000088int GrGpuGL::ProgramCache::search(const GrGLProgramDesc& desc) const {
89 ProgDescLess less;
90 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less);
91}
92
egdaniel307796b2014-10-06 12:13:54 -070093GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState,
94 const GrGLProgramDesc& desc,
joshualittb0a8a372014-09-23 09:50:21 -070095 const GrGeometryStage* geometryProcessor,
96 const GrFragmentStage* colorStages[],
97 const GrFragmentStage* coverageStages[]) {
jvanverth@google.com94878772013-03-12 16:00:54 +000098#ifdef PROGRAM_CACHE_STATS
99 ++fTotalRequests;
100#endif
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000101
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000102 Entry* entry = NULL;
103
104 uint32_t hashIdx = desc.getChecksum();
105 hashIdx ^= hashIdx >> 16;
106 if (kHashBits <= 8) {
107 hashIdx ^= hashIdx >> 8;
108 }
109 hashIdx &=((1 << kHashBits) - 1);
110 Entry* hashedEntry = fHashTable[hashIdx];
bsalomon49f085d2014-09-05 13:34:00 -0700111 if (hashedEntry && hashedEntry->fProgram->getDesc() == desc) {
112 SkASSERT(hashedEntry->fProgram);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000113 entry = hashedEntry;
114 }
115
116 int entryIdx;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000117 if (NULL == entry) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000118 entryIdx = this->search(desc);
119 if (entryIdx >= 0) {
120 entry = fEntries[entryIdx];
121#ifdef PROGRAM_CACHE_STATS
122 ++fHashMisses;
123#endif
124 }
125 }
126
127 if (NULL == entry) {
128 // We have a cache miss
jvanverth@google.com94878772013-03-12 16:00:54 +0000129#ifdef PROGRAM_CACHE_STATS
130 ++fCacheMisses;
131#endif
egdaniel307796b2014-10-06 12:13:54 -0700132 GrGLProgram* program = GrGLProgram::Create(fGpu, optState, desc, geometryProcessor,
133 colorStages, coverageStages);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000134 if (NULL == program) {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000135 return NULL;
136 }
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000137 int purgeIdx = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000138 if (fCount < kMaxEntries) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000139 entry = SkNEW(Entry);
140 purgeIdx = fCount++;
141 fEntries[purgeIdx] = entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000142 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000143 SkASSERT(fCount == kMaxEntries);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000144 purgeIdx = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000145 for (int i = 1; i < kMaxEntries; ++i) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000146 if (fEntries[i]->fLRUStamp < fEntries[purgeIdx]->fLRUStamp) {
147 purgeIdx = i;
junov@google.comf93e7172011-03-31 21:26:24 +0000148 }
junov@google.comf93e7172011-03-31 21:26:24 +0000149 }
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000150 entry = fEntries[purgeIdx];
151 int purgedHashIdx = entry->fProgram->getDesc().getChecksum() & ((1 << kHashBits) - 1);
152 if (fHashTable[purgedHashIdx] == entry) {
153 fHashTable[purgedHashIdx] = NULL;
154 }
junov@google.comf93e7172011-03-31 21:26:24 +0000155 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000156 SkASSERT(fEntries[purgeIdx] == entry);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000157 entry->fProgram.reset(program);
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +0000158 // We need to shift fEntries around so that the entry currently at purgeIdx is placed
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000159 // just before the entry at ~entryIdx (in order to keep fEntries sorted by descriptor).
160 entryIdx = ~entryIdx;
161 if (entryIdx < purgeIdx) {
162 // Let E and P be the entries at index entryIdx and purgeIdx, respectively.
163 // If the entries array looks like this:
164 // aaaaEbbbbbPccccc
165 // we rearrange it to look like this:
166 // aaaaPEbbbbbccccc
167 size_t copySize = (purgeIdx - entryIdx) * sizeof(Entry*);
168 memmove(fEntries + entryIdx + 1, fEntries + entryIdx, copySize);
169 fEntries[entryIdx] = entry;
170 } else if (purgeIdx < entryIdx) {
171 // If the entries array looks like this:
172 // aaaaPbbbbbEccccc
173 // we rearrange it to look like this:
174 // aaaabbbbbPEccccc
175 size_t copySize = (entryIdx - purgeIdx - 1) * sizeof(Entry*);
176 memmove(fEntries + purgeIdx, fEntries + purgeIdx + 1, copySize);
177 fEntries[entryIdx - 1] = entry;
178 }
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000179#ifdef SK_DEBUG
bsalomon49f085d2014-09-05 13:34:00 -0700180 SkASSERT(fEntries[0]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000181 for (int i = 0; i < fCount - 1; ++i) {
bsalomon49f085d2014-09-05 13:34:00 -0700182 SkASSERT(fEntries[i + 1]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000183 const GrGLProgramDesc& a = fEntries[i]->fProgram->getDesc();
184 const GrGLProgramDesc& b = fEntries[i + 1]->fProgram->getDesc();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000185 SkASSERT(GrGLProgramDesc::Less(a, b));
186 SkASSERT(!GrGLProgramDesc::Less(b, a));
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000187 }
188#endif
junov@google.comf93e7172011-03-31 21:26:24 +0000189 }
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000190
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000191 fHashTable[hashIdx] = entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000192 entry->fLRUStamp = fCurrLRUStamp;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000193
194 if (SK_MaxU32 == fCurrLRUStamp) {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000195 // wrap around! just trash our LRU, one time hit.
196 for (int i = 0; i < fCount; ++i) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000197 fEntries[i]->fLRUStamp = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000198 }
199 }
200 ++fCurrLRUStamp;
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000201 return entry->fProgram;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000202}
junov@google.comf93e7172011-03-31 21:26:24 +0000203
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000204////////////////////////////////////////////////////////////////////////////////
205
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000206#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
207
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000208bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstCopy) {
egdanielc0648242014-09-22 13:17:02 -0700209 SkAutoTUnref<GrOptDrawState> optState(this->getDrawState().createOptState(*this->caps()));
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000210
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000211 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
egdaniel170f90b2014-09-16 12:54:40 -0700212 SkASSERT(optState->getRenderTarget());
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000213
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000214 if (kStencilPath_DrawType == type) {
egdaniel170f90b2014-09-16 12:54:40 -0700215 const GrRenderTarget* rt = optState->getRenderTarget();
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000216 SkISize size;
217 size.set(rt->width(), rt->height());
egdaniel170f90b2014-09-16 12:54:40 -0700218 this->glPathRendering()->setProjectionMatrix(optState->getViewMatrix(), size, rt->origin());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000219 } else {
egdanield632ea42014-09-24 10:30:12 -0700220 this->flushMiscFixedFunctionState(*optState.get());
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000221
egdaniel170f90b2014-09-16 12:54:40 -0700222 GrBlendCoeff srcCoeff = optState->getSrcBlendCoeff();
223 GrBlendCoeff dstCoeff = optState->getDstBlendCoeff();
224
225 // In these blend coeff's we end up drawing nothing so we can skip draw all together
226 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
227 !optState->getStencil().doesWrite()) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000228 return false;
229 }
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000230
joshualittb0a8a372014-09-23 09:50:21 -0700231 const GrGeometryStage* geometryProcessor = NULL;
232 SkSTArray<8, const GrFragmentStage*, true> colorStages;
233 SkSTArray<8, const GrFragmentStage*, true> coverageStages;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000234 GrGLProgramDesc desc;
egdaniel170f90b2014-09-16 12:54:40 -0700235 if (!GrGLProgramDesc::Build(*optState.get(),
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000236 type,
bsalomon@google.com91207482013-02-12 21:45:24 +0000237 srcCoeff,
238 dstCoeff,
239 this,
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000240 dstCopy,
joshualittbd769d02014-09-04 08:56:46 -0700241 &geometryProcessor,
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000242 &colorStages,
243 &coverageStages,
bsalomon848faf02014-07-11 10:01:02 -0700244 &desc)) {
245 SkDEBUGFAIL("Failed to generate GL program descriptor");
246 return false;
247 }
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000248
egdaniel307796b2014-10-06 12:13:54 -0700249 fCurrentProgram.reset(fProgramCache->getProgram(*optState.get(),
250 desc,
joshualittbd769d02014-09-04 08:56:46 -0700251 geometryProcessor,
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000252 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
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000259 fCurrentProgram.get()->ref();
junov@google.comf93e7172011-03-31 21:26:24 +0000260
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000261 GrGLuint programID = fCurrentProgram->programID();
262 if (fHWProgramID != programID) {
263 GL_CALL(UseProgram(programID));
264 fHWProgramID = programID;
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000265 }
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000266
egdanield632ea42014-09-24 10:30:12 -0700267 this->flushBlend(*optState.get(), kDrawLines_DrawType == type, srcCoeff, dstCoeff);
junov@google.comf93e7172011-03-31 21:26:24 +0000268
egdaniel170f90b2014-09-16 12:54:40 -0700269 fCurrentProgram->setData(*optState.get(),
270 type,
joshualittbd769d02014-09-04 08:56:46 -0700271 geometryProcessor,
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000272 colorStages.begin(),
273 coverageStages.begin(),
274 dstCopy,
275 &fSharedGLProgramState);
junov@google.comf93e7172011-03-31 21:26:24 +0000276 }
bsalomonb0bd4f62014-09-03 07:19:50 -0700277
egdaniel170f90b2014-09-16 12:54:40 -0700278 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState->getRenderTarget());
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000279 this->flushStencil(type);
bsalomonb0bd4f62014-09-03 07:19:50 -0700280 this->flushScissor(glRT->getViewport(), glRT->origin());
egdanield632ea42014-09-24 10:30:12 -0700281 this->flushAAState(*optState.get(), 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;
egdaniel170f90b2014-09-16 12:54:40 -0700285 if (optState->isClipState()) {
286 this->getClip()->getConservativeBounds(optState->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).
bsalomonb0bd4f62014-09-03 07:19:50 -0700291 this->flushRenderTarget(glRT, 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) {
egdanielc0648242014-09-22 13:17:02 -0700297 SkAutoTUnref<GrOptDrawState> optState(this->getDrawState().createOptState(*this->caps()));
junov@google.comf93e7172011-03-31 21:26:24 +0000298
egdaniel170f90b2014-09-16 12:54:40 -0700299 GrGLsizei stride = static_cast<GrGLsizei>(optState->getVertexStride());
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000300
bsalomon@google.com6918d482013-03-07 19:09:11 +0000301 size_t vertexOffsetInBytes = stride * info.startVertex();
302
303 const GeometryPoolState& geoPoolState = this->getGeomPoolState();
304
305 GrGLVertexBuffer* vbuf;
306 switch (this->getGeomSrc().fVertexSrc) {
307 case kBuffer_GeometrySrcType:
308 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
309 break;
310 case kArray_GeometrySrcType:
311 case kReserved_GeometrySrcType:
312 this->finalizeReservedVertices();
313 vertexOffsetInBytes += geoPoolState.fPoolStartVertex * this->getGeomSrc().fVertexSize;
314 vbuf = (GrGLVertexBuffer*) geoPoolState.fPoolVertexBuffer;
315 break;
316 default:
317 vbuf = NULL; // suppress warning
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000318 SkFAIL("Unknown geometry src type!");
bsalomon@google.com6918d482013-03-07 19:09:11 +0000319 }
320
bsalomon49f085d2014-09-05 13:34:00 -0700321 SkASSERT(vbuf);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000322 SkASSERT(!vbuf->isMapped());
bsalomon@google.com6918d482013-03-07 19:09:11 +0000323 vertexOffsetInBytes += vbuf->baseOffset();
324
325 GrGLIndexBuffer* ibuf = NULL;
326 if (info.isIndexed()) {
bsalomon49f085d2014-09-05 13:34:00 -0700327 SkASSERT(indexOffsetInBytes);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000328
329 switch (this->getGeomSrc().fIndexSrc) {
330 case kBuffer_GeometrySrcType:
331 *indexOffsetInBytes = 0;
332 ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
333 break;
334 case kArray_GeometrySrcType:
335 case kReserved_GeometrySrcType:
336 this->finalizeReservedIndices();
337 *indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLushort);
338 ibuf = (GrGLIndexBuffer*) geoPoolState.fPoolIndexBuffer;
339 break;
340 default:
341 ibuf = NULL; // suppress warning
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000342 SkFAIL("Unknown geometry src type!");
bsalomon@google.com6918d482013-03-07 19:09:11 +0000343 }
344
bsalomon49f085d2014-09-05 13:34:00 -0700345 SkASSERT(ibuf);
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000346 SkASSERT(!ibuf->isMapped());
bsalomon@google.com6918d482013-03-07 19:09:11 +0000347 *indexOffsetInBytes += ibuf->baseOffset();
348 }
349 GrGLAttribArrayState* attribState =
350 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
junov@google.comf93e7172011-03-31 21:26:24 +0000351
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +0000352 if (fCurrentProgram->hasVertexShader()) {
egdaniel170f90b2014-09-16 12:54:40 -0700353 int vertexAttribCount = optState->getVertexAttribCount();
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000354 uint32_t usedAttribArraysMask = 0;
egdaniel170f90b2014-09-16 12:54:40 -0700355 const GrVertexAttrib* vertexAttrib = optState->getVertexAttribs();
egdaniel02cafcc2014-07-21 11:37:28 -0700356
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000357 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount;
358 ++vertexAttribIndex, ++vertexAttrib) {
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}