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 const uint16_t* outIndices; | |
1617 SkAutoTDeleteArray<uint16_t> outAlloc(NULL); | |
1618 GrPrimitiveType primType; | |
1619 GrPaint grPaint; | |
1620 | |
1621 // If both textures and vertex-colors are NULL, strokes hairlines with the p
aint's color. | 1615 // If both textures and vertex-colors are NULL, strokes hairlines with the p
aint's color. |
1622 if ((NULL == texs || NULL == paint.getShader()) && NULL == colors) { | 1616 if ((NULL == texs || NULL == paint.getShader()) && NULL == colors) { |
1623 | |
1624 texs = NULL; | 1617 texs = NULL; |
1625 | |
1626 SkPaint copy(paint); | 1618 SkPaint copy(paint); |
1627 copy.setStyle(SkPaint::kStroke_Style); | 1619 copy.setStyle(SkPaint::kStroke_Style); |
1628 copy.setStrokeWidth(0); | 1620 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); | |
1633 | 1621 |
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 | |
1646 VertState state(vertexCount, indices, indexCount); | 1622 VertState state(vertexCount, indices, indexCount); |
1647 VertState::Proc vertProc = state.chooseProc(vmode); | 1623 VertState::Proc vertProc = state.chooseProc(vmode); |
1648 | 1624 |
1649 //number of indices for lines per triangle with kLines | 1625 SkPoint* pts = new SkPoint[vertexCount * 6]; |
1650 indexCount = triangleCount * 6; | |
1651 | |
1652 outAlloc.reset(SkNEW_ARRAY(uint16_t, indexCount)); | |
1653 outIndices = outAlloc.get(); | |
1654 uint16_t* auxIndices = outAlloc.get(); | |
1655 int i = 0; | 1626 int i = 0; |
1656 while (vertProc(&state)) { | 1627 while (vertProc(&state)) { |
1657 auxIndices[i] = state.f0; | 1628 pts[i] = vertices[state.f0]; |
1658 auxIndices[i + 1] = state.f1; | 1629 pts[i + 1] = vertices[state.f1]; |
1659 auxIndices[i + 2] = state.f1; | 1630 pts[i + 2] = vertices[state.f1]; |
1660 auxIndices[i + 3] = state.f2; | 1631 pts[i + 3] = vertices[state.f2]; |
1661 auxIndices[i + 4] = state.f2; | 1632 pts[i + 4] = vertices[state.f2]; |
1662 auxIndices[i + 5] = state.f0; | 1633 pts[i + 5] = vertices[state.f0]; |
1663 i += 6; | 1634 i += 6; |
1664 } | 1635 } |
| 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); |
1665 } else { | 1645 } else { |
1666 outIndices = indices; | |
1667 primType = gVertexMode2PrimitiveType[vmode]; | |
1668 SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint); | 1646 SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint); |
1669 } | 1647 } |
1670 | 1648 |
1671 #if 0 | 1649 #if 0 |
1672 if (NULL != xmode && NULL != texs && NULL != colors) { | 1650 if (NULL != xmode && NULL != texs && NULL != colors) { |
1673 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { | 1651 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { |
1674 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); | 1652 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); |
1675 return; | 1653 return; |
1676 } | 1654 } |
1677 } | 1655 } |
1678 #endif | 1656 #endif |
1679 | 1657 |
1680 SkAutoSTMalloc<128, GrColor> convertedColors(0); | 1658 SkAutoSTMalloc<128, GrColor> convertedColors(0); |
1681 if (NULL != colors) { | 1659 if (NULL != colors) { |
1682 // need to convert byte order and from non-PM to PM | 1660 // need to convert byte order and from non-PM to PM |
1683 convertedColors.reset(vertexCount); | 1661 convertedColors.reset(vertexCount); |
1684 SkColor color; | 1662 SkColor color; |
1685 for (int i = 0; i < vertexCount; ++i) { | 1663 for (int i = 0; i < vertexCount; ++i) { |
1686 color = colors[i]; | 1664 color = colors[i]; |
1687 if (paint.getAlpha() != 255) { | 1665 if (paint.getAlpha() != 255) { |
1688 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color),
paint.getAlpha())); | 1666 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color),
paint.getAlpha())); |
1689 } | 1667 } |
1690 convertedColors[i] = SkColor2GrColor(color); | 1668 convertedColors[i] = SkColor2GrColor(color); |
1691 } | 1669 } |
1692 colors = convertedColors.get(); | 1670 colors = convertedColors.get(); |
1693 } | 1671 } |
1694 fContext->drawVertices(grPaint, | 1672 fContext->drawVertices(grPaint, |
1695 primType, | 1673 gVertexMode2PrimitiveType[vmode], |
1696 vertexCount, | 1674 vertexCount, |
1697 vertices, | 1675 vertices, |
1698 texs, | 1676 texs, |
1699 colors, | 1677 colors, |
1700 outIndices, | 1678 indices, |
1701 indexCount); | 1679 indexCount); |
1702 } | 1680 } |
1703 | 1681 |
1704 /////////////////////////////////////////////////////////////////////////////// | 1682 /////////////////////////////////////////////////////////////////////////////// |
1705 | 1683 |
1706 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1684 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1707 size_t byteLength, SkScalar x, SkScalar y, | 1685 size_t byteLength, SkScalar x, SkScalar y, |
1708 const SkPaint& paint) { | 1686 const SkPaint& paint) { |
1709 CHECK_SHOULD_DRAW(draw, false); | 1687 CHECK_SHOULD_DRAW(draw, false); |
1710 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1688 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2053 playback.draw(canvas, NULL); | 2031 playback.draw(canvas, NULL); |
2054 | 2032 |
2055 // unlock the layers | 2033 // unlock the layers |
2056 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 2034 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
2057 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); | 2035 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
2058 fContext->getLayerCache()->unlock(layer); | 2036 fContext->getLayerCache()->unlock(layer); |
2059 } | 2037 } |
2060 | 2038 |
2061 return true; | 2039 return true; |
2062 } | 2040 } |
OLD | NEW |