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 GrPrimitiveType primType; | |
1618 SkPaint copy(paint); | |
jvanverth1
2014/07/14 14:29:19
I don't think we'd want to copy the paint all the
dandov
2014/07/14 15:31:33
Done.
| |
1619 | |
1615 // If both textures and vertex-colors are NULL, strokes hairlines with the p aint's color. | 1620 // 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) { | 1621 if ((NULL == texs || NULL == paint.getShader()) && NULL == colors) { |
1622 | |
1617 texs = NULL; | 1623 texs = NULL; |
1618 SkPaint copy(paint); | 1624 |
1619 copy.setStyle(SkPaint::kStroke_Style); | 1625 copy.setStyle(SkPaint::kStroke_Style); |
1620 copy.setStrokeWidth(0); | 1626 copy.setStrokeWidth(0); |
1621 | 1627 |
1628 primType = kLines_GrPrimitiveType; | |
1629 int triangleCount = 0; | |
1630 switch (vmode) { | |
1631 case SkCanvas::kTriangles_VertexMode: | |
1632 triangleCount = indexCount / 3; | |
1633 break; | |
1634 case SkCanvas::kTriangleStrip_VertexMode: | |
1635 case SkCanvas::kTriangleFan_VertexMode: | |
1636 triangleCount = indexCount - 2; | |
1637 break; | |
1638 } | |
1639 | |
1622 VertState state(vertexCount, indices, indexCount); | 1640 VertState state(vertexCount, indices, indexCount); |
1623 VertState::Proc vertProc = state.chooseProc(vmode); | 1641 VertState::Proc vertProc = state.chooseProc(vmode); |
1624 | 1642 |
1625 SkPoint* pts = new SkPoint[vertexCount * 6]; | 1643 //number of lines per triangle with kLines |
1644 indexCount = triangleCount * 6; | |
1645 idx = SkNEW_ARRAY(uint16_t, indexCount); | |
1626 int i = 0; | 1646 int i = 0; |
1627 while (vertProc(&state)) { | 1647 while (vertProc(&state)) { |
1628 pts[i] = vertices[state.f0]; | 1648 idx[i] = state.f0; |
1629 pts[i + 1] = vertices[state.f1]; | 1649 idx[i + 1] = state.f1; |
1630 pts[i + 2] = vertices[state.f1]; | 1650 idx[i + 2] = state.f1; |
1631 pts[i + 3] = vertices[state.f2]; | 1651 idx[i + 3] = state.f2; |
1632 pts[i + 4] = vertices[state.f2]; | 1652 idx[i + 4] = state.f2; |
1633 pts[i + 5] = vertices[state.f0]; | 1653 idx[i + 5] = state.f0; |
1634 i += 6; | 1654 i += 6; |
1635 } | 1655 } |
1636 draw.drawPoints(SkCanvas::kLines_PointMode, i, pts, copy, true); | 1656 } else { |
1637 return; | 1657 idx = SkNEW_ARRAY(uint16_t, indexCount); |
1658 memcpy(idx, indices, indexCount * sizeof(uint16_t)); | |
1659 primType = gVertexMode2PrimitiveType[vmode]; | |
1638 } | 1660 } |
1639 | 1661 |
1662 | |
1663 // we ignore the shader if texs is null. | |
1640 GrPaint grPaint; | 1664 GrPaint grPaint; |
1641 // we ignore the shader if texs is null. | |
1642 if (NULL == texs) { | 1665 if (NULL == texs) { |
1643 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColor(paint.ge tColor()), | 1666 SkPaint2GrPaintNoShader(this->context(), copy, SkColor2GrColor(copy.getC olor()), |
1644 NULL == colors, &grPaint); | 1667 NULL == colors, &grPaint); |
1645 } else { | 1668 } else { |
1646 SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint); | 1669 SkPaint2GrPaintShader(this->context(), copy, NULL == colors, &grPaint); |
1647 } | 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 (copy.getAlpha() != 255) { |
jvanverth1
2014/07/14 14:29:20
The paint color doesn't change in the hairline cas
dandov
2014/07/14 15:31:33
Done.
| |
1666 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); | 1689 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), copy.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); |
1703 | |
1680 } | 1704 } |
1681 | 1705 |
1682 /////////////////////////////////////////////////////////////////////////////// | 1706 /////////////////////////////////////////////////////////////////////////////// |
1683 | 1707 |
1684 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1708 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1685 size_t byteLength, SkScalar x, SkScalar y, | 1709 size_t byteLength, SkScalar x, SkScalar y, |
1686 const SkPaint& paint) { | 1710 const SkPaint& paint) { |
1687 CHECK_SHOULD_DRAW(draw, false); | 1711 CHECK_SHOULD_DRAW(draw, false); |
1688 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1712 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
1689 | 1713 |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2031 playback.draw(canvas, NULL); | 2055 playback.draw(canvas, NULL); |
2032 | 2056 |
2033 // unlock the layers | 2057 // unlock the layers |
2034 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 2058 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
2035 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); | 2059 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
2036 fContext->getLayerCache()->unlock(layer); | 2060 fContext->getLayerCache()->unlock(layer); |
2037 } | 2061 } |
2038 | 2062 |
2039 return true; | 2063 return true; |
2040 } | 2064 } |
OLD | NEW |