OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1605 | 1605 |
1606 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1606 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
1607 int vertexCount, const SkPoint vertices[], | 1607 int vertexCount, const SkPoint vertices[], |
1608 const SkPoint texs[], const SkColor colors[], | 1608 const SkPoint texs[], const SkColor colors[], |
1609 SkXfermode* xmode, | 1609 SkXfermode* xmode, |
1610 const uint16_t indices[], int indexCount, | 1610 const uint16_t indices[], int indexCount, |
1611 const SkPaint& paint) { | 1611 const SkPaint& paint) { |
1612 CHECK_SHOULD_DRAW(draw, false); | 1612 CHECK_SHOULD_DRAW(draw, false); |
1613 | 1613 |
1614 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext); | 1614 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext); |
1615 | |
1616 uint16_t* idx; | |
1617 SkAutoTDeleteArray<uint16_t> idxDeleter(NULL); | |
1618 GrPrimitiveType primType; | |
1619 GrPaint grPaint; | |
1620 | |
1615 // If both textures and vertex-colors are NULL, strokes hairlines with the p aint's color. | 1621 // If both textures and vertex-colors are NULL, strokes hairlines with the p aint's color. |
1616 if ((NULL == texs || NULL == paint.getShader()) && NULL == colors) { | 1622 if ((NULL == texs || NULL == paint.getShader()) && NULL == colors) { |
1623 | |
1617 texs = NULL; | 1624 texs = NULL; |
1625 | |
1618 SkPaint copy(paint); | 1626 SkPaint copy(paint); |
1619 copy.setStyle(SkPaint::kStroke_Style); | 1627 copy.setStyle(SkPaint::kStroke_Style); |
1620 copy.setStrokeWidth(0); | 1628 copy.setStrokeWidth(0); |
1629 | |
1630 // we ignore the shader if texs is null. | |
1631 SkPaint2GrPaintNoShader(this->context(), copy, SkColor2GrColor(copy.getC olor()), | |
1632 NULL == colors, &grPaint); | |
1621 | 1633 |
1634 primType = kLines_GrPrimitiveType; | |
1635 int triangleCount = 0; | |
1636 switch (vmode) { | |
1637 case SkCanvas::kTriangles_VertexMode: | |
1638 triangleCount = indexCount / 3; | |
1639 break; | |
1640 case SkCanvas::kTriangleStrip_VertexMode: | |
1641 case SkCanvas::kTriangleFan_VertexMode: | |
1642 triangleCount = indexCount - 2; | |
1643 break; | |
1644 } | |
1645 | |
1622 VertState state(vertexCount, indices, indexCount); | 1646 VertState state(vertexCount, indices, indexCount); |
1623 VertState::Proc vertProc = state.chooseProc(vmode); | 1647 VertState::Proc vertProc = state.chooseProc(vmode); |
1624 | 1648 |
1625 SkPoint* pts = new SkPoint[vertexCount * 6]; | 1649 //number of indices for lines per triangle with kLines |
1650 indexCount = triangleCount * 6; | |
1651 idx = SkNEW_ARRAY(uint16_t, indexCount); | |
1652 idxDeleter.reset(idx); | |
dandov
2014/07/14 17:36:38
added auto deleter to avoid memory leak
| |
1653 | |
1626 int i = 0; | 1654 int i = 0; |
1627 while (vertProc(&state)) { | 1655 while (vertProc(&state)) { |
1628 pts[i] = vertices[state.f0]; | 1656 idx[i] = state.f0; |
1629 pts[i + 1] = vertices[state.f1]; | 1657 idx[i + 1] = state.f1; |
1630 pts[i + 2] = vertices[state.f1]; | 1658 idx[i + 2] = state.f1; |
1631 pts[i + 3] = vertices[state.f2]; | 1659 idx[i + 3] = state.f2; |
1632 pts[i + 4] = vertices[state.f2]; | 1660 idx[i + 4] = state.f2; |
1633 pts[i + 5] = vertices[state.f0]; | 1661 idx[i + 5] = state.f0; |
1634 i += 6; | 1662 i += 6; |
1635 } | 1663 } |
1636 draw.drawPoints(SkCanvas::kLines_PointMode, i, pts, copy, true); | |
1637 return; | |
1638 } | |
1639 | |
1640 GrPaint grPaint; | |
1641 // we ignore the shader if texs is null. | |
1642 if (NULL == texs) { | |
1643 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColor(paint.ge tColor()), | |
1644 NULL == colors, &grPaint); | |
1645 } else { | 1664 } else { |
1665 idx = (uint16_t*)indices; | |
dandov
2014/07/14 17:36:38
do not copy indices when not needed
| |
1666 primType = gVertexMode2PrimitiveType[vmode]; | |
1646 SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint); | 1667 SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint); |
1647 } | 1668 } |
1669 | |
1670 | |
1648 | 1671 |
1649 #if 0 | 1672 #if 0 |
1650 if (NULL != xmode && NULL != texs && NULL != colors) { | 1673 if (NULL != xmode && NULL != texs && NULL != colors) { |
1651 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { | 1674 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { |
1652 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); | 1675 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); |
1653 return; | 1676 return; |
1654 } | 1677 } |
1655 } | 1678 } |
1656 #endif | 1679 #endif |
1657 | 1680 |
1658 SkAutoSTMalloc<128, GrColor> convertedColors(0); | 1681 SkAutoSTMalloc<128, GrColor> convertedColors(0); |
1659 if (NULL != colors) { | 1682 if (NULL != colors) { |
1660 // need to convert byte order and from non-PM to PM | 1683 // need to convert byte order and from non-PM to PM |
1661 convertedColors.reset(vertexCount); | 1684 convertedColors.reset(vertexCount); |
1662 SkColor color; | 1685 SkColor color; |
1663 for (int i = 0; i < vertexCount; ++i) { | 1686 for (int i = 0; i < vertexCount; ++i) { |
1664 color = colors[i]; | 1687 color = colors[i]; |
1665 if (paint.getAlpha() != 255) { | 1688 if (paint.getAlpha() != 255) { |
1666 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); | 1689 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); |
1667 } | 1690 } |
1668 convertedColors[i] = SkColor2GrColor(color); | 1691 convertedColors[i] = SkColor2GrColor(color); |
1669 } | 1692 } |
1670 colors = convertedColors.get(); | 1693 colors = convertedColors.get(); |
1671 } | 1694 } |
1672 fContext->drawVertices(grPaint, | 1695 fContext->drawVertices(grPaint, |
1673 gVertexMode2PrimitiveType[vmode], | 1696 primType, |
1674 vertexCount, | 1697 vertexCount, |
1675 vertices, | 1698 vertices, |
1676 texs, | 1699 texs, |
1677 colors, | 1700 colors, |
1678 indices, | 1701 idx, |
1679 indexCount); | 1702 indexCount); |
1680 } | 1703 } |
1681 | 1704 |
1682 /////////////////////////////////////////////////////////////////////////////// | 1705 /////////////////////////////////////////////////////////////////////////////// |
1683 | 1706 |
1684 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1707 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1685 size_t byteLength, SkScalar x, SkScalar y, | 1708 size_t byteLength, SkScalar x, SkScalar y, |
1686 const SkPaint& paint) { | 1709 const SkPaint& paint) { |
1687 CHECK_SHOULD_DRAW(draw, false); | 1710 CHECK_SHOULD_DRAW(draw, false); |
1688 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1711 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2031 playback.draw(canvas, NULL); | 2054 playback.draw(canvas, NULL); |
2032 | 2055 |
2033 // unlock the layers | 2056 // unlock the layers |
2034 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 2057 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
2035 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); | 2058 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
2036 fContext->getLayerCache()->unlock(layer); | 2059 fContext->getLayerCache()->unlock(layer); |
2037 } | 2060 } |
2038 | 2061 |
2039 return true; | 2062 return true; |
2040 } | 2063 } |
OLD | NEW |