Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 387113002: drawVertices bug on gpu side (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed issue with gm's Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
1652 outAlloc.reset(SkNEW_ARRAY(uint16_t, indexCount));
1653 outIndices = outAlloc.get();
1654 uint16_t* auxIndices = outAlloc.get();
1626 int i = 0; 1655 int i = 0;
1627 while (vertProc(&state)) { 1656 while (vertProc(&state)) {
1628 pts[i] = vertices[state.f0]; 1657 auxIndices[i] = state.f0;
1629 pts[i + 1] = vertices[state.f1]; 1658 auxIndices[i + 1] = state.f1;
1630 pts[i + 2] = vertices[state.f1]; 1659 auxIndices[i + 2] = state.f1;
1631 pts[i + 3] = vertices[state.f2]; 1660 auxIndices[i + 3] = state.f2;
1632 pts[i + 4] = vertices[state.f2]; 1661 auxIndices[i + 4] = state.f2;
1633 pts[i + 5] = vertices[state.f0]; 1662 auxIndices[i + 5] = state.f0;
1634 i += 6; 1663 i += 6;
1635 } 1664 }
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 { 1665 } else {
1646 SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint); 1666 outIndices = indices;
1667 primType = gVertexMode2PrimitiveType[vmode];
1668
1669 if (NULL == texs || NULL == paint.getShader()) {
1670 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColor(pain t.getColor()),
1671 NULL == colors, &grPaint);
1672 } else {
1673 SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPai nt);
1674 }
1647 } 1675 }
1648 1676
1649 #if 0 1677 #if 0
1650 if (NULL != xmode && NULL != texs && NULL != colors) { 1678 if (NULL != xmode && NULL != texs && NULL != colors) {
1651 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { 1679 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) {
1652 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); 1680 SkDebugf("Unsupported vertex-color/texture xfer mode.\n");
1653 return; 1681 return;
1654 } 1682 }
1655 } 1683 }
1656 #endif 1684 #endif
1657 1685
1658 SkAutoSTMalloc<128, GrColor> convertedColors(0); 1686 SkAutoSTMalloc<128, GrColor> convertedColors(0);
1659 if (NULL != colors) { 1687 if (NULL != colors) {
1660 // need to convert byte order and from non-PM to PM 1688 // need to convert byte order and from non-PM to PM
1661 convertedColors.reset(vertexCount); 1689 convertedColors.reset(vertexCount);
1662 SkColor color; 1690 SkColor color;
1663 for (int i = 0; i < vertexCount; ++i) { 1691 for (int i = 0; i < vertexCount; ++i) {
1664 color = colors[i]; 1692 color = colors[i];
1665 if (paint.getAlpha() != 255) { 1693 if (paint.getAlpha() != 255) {
1666 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); 1694 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha()));
1667 } 1695 }
1668 convertedColors[i] = SkColor2GrColor(color); 1696 convertedColors[i] = SkColor2GrColor(color);
1669 } 1697 }
1670 colors = convertedColors.get(); 1698 colors = convertedColors.get();
1671 } 1699 }
1672 fContext->drawVertices(grPaint, 1700 fContext->drawVertices(grPaint,
1673 gVertexMode2PrimitiveType[vmode], 1701 primType,
1674 vertexCount, 1702 vertexCount,
1675 vertices, 1703 vertices,
1676 texs, 1704 texs,
1677 colors, 1705 colors,
1678 indices, 1706 outIndices,
1679 indexCount); 1707 indexCount);
1680 } 1708 }
1681 1709
1682 /////////////////////////////////////////////////////////////////////////////// 1710 ///////////////////////////////////////////////////////////////////////////////
1683 1711
1684 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, 1712 void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
1685 size_t byteLength, SkScalar x, SkScalar y, 1713 size_t byteLength, SkScalar x, SkScalar y,
1686 const SkPaint& paint) { 1714 const SkPaint& paint) {
1687 CHECK_SHOULD_DRAW(draw, false); 1715 CHECK_SHOULD_DRAW(draw, false);
1688 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); 1716 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 playback.draw(canvas, NULL); 2059 playback.draw(canvas, NULL);
2032 2060
2033 // unlock the layers 2061 // unlock the layers
2034 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { 2062 for (int i = 0; i < gpuData->numSaveLayers(); ++i) {
2035 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); 2063 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i);
2036 fContext->getLayerCache()->unlock(layer); 2064 fContext->getLayerCache()->unlock(layer);
2037 } 2065 }
2038 2066
2039 return true; 2067 return true;
2040 } 2068 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698