Chromium Code Reviews| Index: src/gpu/SkGpuDevice.cpp |
| diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp |
| index 3f1908be20f9d3dc191082369af97a064f50118c..4eeff0390595ac7c9343b37dbc95fde39c2fcfaf 100644 |
| --- a/src/gpu/SkGpuDevice.cpp |
| +++ b/src/gpu/SkGpuDevice.cpp |
| @@ -1612,39 +1612,62 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| CHECK_SHOULD_DRAW(draw, false); |
| GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext); |
| + |
| + uint16_t* idx; |
| + SkAutoTDeleteArray<uint16_t> idxDeleter(NULL); |
| + GrPrimitiveType primType; |
| + GrPaint grPaint; |
| + |
| // If both textures and vertex-colors are NULL, strokes hairlines with the paint's color. |
| if ((NULL == texs || NULL == paint.getShader()) && NULL == colors) { |
| + |
| texs = NULL; |
| + |
| SkPaint copy(paint); |
| copy.setStyle(SkPaint::kStroke_Style); |
| copy.setStrokeWidth(0); |
| + |
| + // we ignore the shader if texs is null. |
| + SkPaint2GrPaintNoShader(this->context(), copy, SkColor2GrColor(copy.getColor()), |
| + NULL == colors, &grPaint); |
| + primType = kLines_GrPrimitiveType; |
| + int triangleCount = 0; |
| + switch (vmode) { |
| + case SkCanvas::kTriangles_VertexMode: |
| + triangleCount = indexCount / 3; |
| + break; |
| + case SkCanvas::kTriangleStrip_VertexMode: |
| + case SkCanvas::kTriangleFan_VertexMode: |
| + triangleCount = indexCount - 2; |
| + break; |
| + } |
| + |
| VertState state(vertexCount, indices, indexCount); |
| VertState::Proc vertProc = state.chooseProc(vmode); |
| - |
| - SkPoint* pts = new SkPoint[vertexCount * 6]; |
| + |
| + //number of indices for lines per triangle with kLines |
| + indexCount = triangleCount * 6; |
| + idx = SkNEW_ARRAY(uint16_t, indexCount); |
| + idxDeleter.reset(idx); |
|
dandov
2014/07/14 17:36:38
added auto deleter to avoid memory leak
|
| + |
| int i = 0; |
| while (vertProc(&state)) { |
| - pts[i] = vertices[state.f0]; |
| - pts[i + 1] = vertices[state.f1]; |
| - pts[i + 2] = vertices[state.f1]; |
| - pts[i + 3] = vertices[state.f2]; |
| - pts[i + 4] = vertices[state.f2]; |
| - pts[i + 5] = vertices[state.f0]; |
| + idx[i] = state.f0; |
| + idx[i + 1] = state.f1; |
| + idx[i + 2] = state.f1; |
| + idx[i + 3] = state.f2; |
| + idx[i + 4] = state.f2; |
| + idx[i + 5] = state.f0; |
| i += 6; |
| } |
| - draw.drawPoints(SkCanvas::kLines_PointMode, i, pts, copy, true); |
| - return; |
| - } |
| - |
| - GrPaint grPaint; |
| - // we ignore the shader if texs is null. |
| - if (NULL == texs) { |
| - SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColor(paint.getColor()), |
| - NULL == colors, &grPaint); |
| } else { |
| + idx = (uint16_t*)indices; |
|
dandov
2014/07/14 17:36:38
do not copy indices when not needed
|
| + primType = gVertexMode2PrimitiveType[vmode]; |
| SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint); |
| } |
| + |
| + |
| #if 0 |
| if (NULL != xmode && NULL != texs && NULL != colors) { |
| @@ -1670,12 +1693,12 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| colors = convertedColors.get(); |
| } |
| fContext->drawVertices(grPaint, |
| - gVertexMode2PrimitiveType[vmode], |
| + primType, |
| vertexCount, |
| vertices, |
| texs, |
| colors, |
| - indices, |
| + idx, |
| indexCount); |
| } |