OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) { | 157 GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) { |
158 this->handleDirtyContext(); | 158 this->handleDirtyContext(); |
159 return this->onCreateVertexBuffer(size, dynamic); | 159 return this->onCreateVertexBuffer(size, dynamic); |
160 } | 160 } |
161 | 161 |
162 GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { | 162 GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { |
163 this->handleDirtyContext(); | 163 this->handleDirtyContext(); |
164 return this->onCreateIndexBuffer(size, dynamic); | 164 return this->onCreateIndexBuffer(size, dynamic); |
165 } | 165 } |
166 | 166 |
167 GrIndexBuffer* GrGpu::createInstancedIndexBuffer(const uint16_t* pattern, | |
bsalomon
2014/10/22 20:23:11
I take it that the const change is to support the
| |
168 int patternSize, | |
169 int reps, | |
170 int vertCount, | |
171 bool isDynamic) const { | |
172 size_t bufferSize = patternSize * reps * sizeof(uint16_t); | |
173 GrGpu* me = const_cast<GrGpu*>(this); | |
174 GrIndexBuffer* buffer = me->createIndexBuffer(bufferSize, isDynamic); | |
175 if (buffer) { | |
176 uint16_t* data = (uint16_t*) buffer->map(); | |
177 bool useTempData = (NULL == data); | |
178 if (useTempData) { | |
179 data = SkNEW_ARRAY(uint16_t, reps * patternSize); | |
180 } | |
181 for (int i = 0; i < reps; ++i) { | |
182 // Each AA filled rect is drawn with 8 vertices and 10 triangles (8 around | |
bsalomon
2014/10/22 20:23:11
this comment should go
| |
183 // the inner rect (for AA) and 2 for the inner rect. | |
184 int baseIdx = i * patternSize; | |
185 uint16_t baseVert = (uint16_t)(i * vertCount); | |
186 for (int j = 0; j < patternSize; ++j) { | |
187 data[baseIdx+j] = baseVert + pattern[j]; | |
188 } | |
189 } | |
190 if (useTempData) { | |
191 if (!buffer->updateData(data, bufferSize)) { | |
192 SkFAIL("Can't get indices into buffer!"); | |
193 } | |
194 SkDELETE_ARRAY(data); | |
195 } else { | |
196 buffer->unmap(); | |
197 } | |
198 } | |
199 return buffer; | |
200 } | |
201 | |
167 void GrGpu::clear(const SkIRect* rect, | 202 void GrGpu::clear(const SkIRect* rect, |
168 GrColor color, | 203 GrColor color, |
169 bool canIgnoreRect, | 204 bool canIgnoreRect, |
170 GrRenderTarget* renderTarget) { | 205 GrRenderTarget* renderTarget) { |
171 if (NULL == renderTarget) { | 206 if (NULL == renderTarget) { |
172 renderTarget = this->getDrawState().getRenderTarget(); | 207 renderTarget = this->getDrawState().getRenderTarget(); |
173 } | 208 } |
174 if (NULL == renderTarget) { | 209 if (NULL == renderTarget) { |
175 SkASSERT(0); | 210 SkASSERT(0); |
176 return; | 211 return; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 fClipMaskManager.adjustPathStencilParams(outStencilSettings); | 274 fClipMaskManager.adjustPathStencilParams(outStencilSettings); |
240 } | 275 } |
241 | 276 |
242 | 277 |
243 //////////////////////////////////////////////////////////////////////////////// | 278 //////////////////////////////////////////////////////////////////////////////// |
244 | 279 |
245 static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1; | 280 static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1; |
246 | 281 |
247 GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535); | 282 GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535); |
248 | 283 |
249 static inline void fill_indices(uint16_t* indices, int quadCount) { | 284 static const uint16_t gQuadIndexPattern[] = { |
250 for (int i = 0; i < quadCount; ++i) { | 285 0, 1, 2, 0, 2, 3 |
251 indices[6 * i + 0] = 4 * i + 0; | 286 }; |
252 indices[6 * i + 1] = 4 * i + 1; | |
253 indices[6 * i + 2] = 4 * i + 2; | |
254 indices[6 * i + 3] = 4 * i + 0; | |
255 indices[6 * i + 4] = 4 * i + 2; | |
256 indices[6 * i + 5] = 4 * i + 3; | |
257 } | |
258 } | |
259 | 287 |
260 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { | 288 const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { |
261 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) { | 289 if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) { |
262 SkSafeUnref(fQuadIndexBuffer); | 290 SkSafeUnref(fQuadIndexBuffer); |
263 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS; | 291 fQuadIndexBuffer = this->createInstancedIndexBuffer(gQuadIndexPattern, |
264 GrGpu* me = const_cast<GrGpu*>(this); | 292 6, |
265 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false); | 293 MAX_QUADS, |
266 if (fQuadIndexBuffer) { | 294 4); |
267 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->map(); | |
268 if (indices) { | |
269 fill_indices(indices, MAX_QUADS); | |
270 fQuadIndexBuffer->unmap(); | |
271 } else { | |
272 indices = (uint16_t*)sk_malloc_throw(SIZE); | |
273 fill_indices(indices, MAX_QUADS); | |
274 if (!fQuadIndexBuffer->updateData(indices, SIZE)) { | |
275 fQuadIndexBuffer->unref(); | |
276 fQuadIndexBuffer = NULL; | |
277 SkFAIL("Can't get indices into buffer!"); | |
278 } | |
279 sk_free(indices); | |
280 } | |
281 } | |
282 } | 295 } |
283 | 296 |
284 return fQuadIndexBuffer; | 297 return fQuadIndexBuffer; |
285 } | 298 } |
286 | 299 |
287 //////////////////////////////////////////////////////////////////////////////// | 300 //////////////////////////////////////////////////////////////////////////////// |
288 | 301 |
289 bool GrGpu::setupClipAndFlushState(DrawType type, const GrDeviceCoordTexture* ds tCopy, | 302 bool GrGpu::setupClipAndFlushState(DrawType type, const GrDeviceCoordTexture* ds tCopy, |
290 GrDrawState::AutoRestoreEffects* are, | 303 GrDrawState::AutoRestoreEffects* are, |
291 const SkRect* devBounds) { | 304 const SkRect* devBounds) { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 } | 525 } |
513 | 526 |
514 void GrGpu::releaseIndexArray() { | 527 void GrGpu::releaseIndexArray() { |
515 // if index source was array, we stowed data in the pool | 528 // if index source was array, we stowed data in the pool |
516 const GeometrySrcState& geoSrc = this->getGeomSrc(); | 529 const GeometrySrcState& geoSrc = this->getGeomSrc(); |
517 SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc); | 530 SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc); |
518 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); | 531 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); |
519 fIndexPool->putBack(bytes); | 532 fIndexPool->putBack(bytes); |
520 --fIndexPoolUseCnt; | 533 --fIndexPoolUseCnt; |
521 } | 534 } |
OLD | NEW |