Index: src/gpu/GrGpu.cpp |
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp |
index 1f01e124bf74a973348ad62706454482aaef2af6..489e51f4ad741e5dacb7bd85e06dcfa770650bc5 100644 |
--- a/src/gpu/GrGpu.cpp |
+++ b/src/gpu/GrGpu.cpp |
@@ -164,6 +164,40 @@ GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { |
return this->onCreateIndexBuffer(size, dynamic); |
} |
+GrIndexBuffer* GrGpu::createIndexBufferPattern(const uint16_t* pattern, |
+ int patternSize, |
+ int reps, |
+ int vertCount, |
+ bool isDynamic) { |
+ size_t bufferSize = patternSize * reps * sizeof(uint16_t); |
+ GrIndexBuffer* buffer = this->createIndexBuffer(bufferSize, isDynamic); |
+ if (buffer) { |
+ uint16_t* data = (uint16_t*) buffer->map(); |
+ bool useTempData = (NULL == data); |
+ if (useTempData) { |
+ data = SkNEW_ARRAY(uint16_t, reps * patternSize); |
+ } |
+ for (int i = 0; i < reps; ++i) { |
robertphillips
2014/10/21 19:12:37
Fix comment ?
|
+ // Each AA filled rect is drawn with 8 vertices and 10 triangles (8 around |
+ // the inner rect (for AA) and 2 for the inner rect. |
+ int baseIdx = i * patternSize; |
+ uint16_t baseVert = (uint16_t)(i * vertCount); |
+ for (int j = 0; j < patternSize; ++j) { |
+ data[baseIdx+j] = baseVert + pattern[j]; |
+ } |
+ } |
+ if (useTempData) { |
+ if (!buffer->updateData(data, bufferSize)) { |
+ SkFAIL("Can't get indices into buffer!"); |
+ } |
+ SkDELETE_ARRAY(data); |
+ } else { |
+ buffer->unmap(); |
+ } |
+ } |
+ return buffer; |
+} |
+ |
void GrGpu::clear(const SkIRect* rect, |
GrColor color, |
bool canIgnoreRect, |