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 "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
(...skipping 1647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 vertexCount, | 1658 vertexCount, |
1659 vertices, | 1659 vertices, |
1660 texs, | 1660 texs, |
1661 colors, | 1661 colors, |
1662 outIndices, | 1662 outIndices, |
1663 indexCount); | 1663 indexCount); |
1664 } | 1664 } |
1665 | 1665 |
1666 /////////////////////////////////////////////////////////////////////////////// | 1666 /////////////////////////////////////////////////////////////////////////////// |
1667 | 1667 |
1668 static void append_quad_indices(uint16_t indices[], int quadIndex) { | 1668 void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS
Xform xform[], |
1669 int i = quadIndex * 4; | |
1670 indices[0] = i + 0; indices[1] = i + 1; indices[2] = i + 2; | |
1671 indices[3] = i + 2; indices[4] = i + 3; indices[5] = i + 0; | |
1672 } | |
1673 | |
1674 void SkGpuDevice::drawAtlas(const SkDraw& d, const SkImage* atlas, const SkRSXfo
rm xform[], | |
1675 const SkRect texRect[], const SkColor colors[], int
count, | 1669 const SkRect texRect[], const SkColor colors[], int
count, |
1676 SkXfermode::Mode mode, const SkPaint& paint) { | 1670 SkXfermode::Mode mode, const SkPaint& paint) { |
1677 if (paint.isAntiAlias()) { | 1671 if (paint.isAntiAlias()) { |
1678 this->INHERITED::drawAtlas(d, atlas, xform, texRect, colors, count, mode
, paint); | 1672 this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, m
ode, paint); |
1679 return; | 1673 return; |
1680 } | 1674 } |
1681 | 1675 |
| 1676 CHECK_SHOULD_DRAW(draw); |
| 1677 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
| 1678 |
1682 SkPaint p(paint); | 1679 SkPaint p(paint); |
1683 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til
eMode))->unref(); | 1680 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til
eMode))->unref(); |
1684 | 1681 |
1685 const int vertCount = count * 4; | 1682 GrPaint grPaint; |
1686 const int indexCount = count * 6; | 1683 if (!SkPaint2GrPaint(this->context(), fRenderTarget, p, *draw.fMatrix, !colo
rs, &grPaint)) { |
1687 SkAutoTMalloc<SkPoint> vertStorage(vertCount * 2); | 1684 return; |
1688 SkPoint* verts = vertStorage.get(); | |
1689 SkPoint* texs = verts + vertCount; | |
1690 SkAutoTMalloc<uint16_t> indexStorage(indexCount); | |
1691 uint16_t* indices = indexStorage.get(); | |
1692 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode)); | |
1693 | |
1694 for (int i = 0; i < count; ++i) { | |
1695 xform[i].toQuad(texRect[i].width(), texRect[i].height(), verts); | |
1696 texRect[i].toQuad(texs); | |
1697 append_quad_indices(indices, i); | |
1698 verts += 4; | |
1699 texs += 4; | |
1700 indices += 6; | |
1701 } | 1685 } |
1702 | 1686 |
1703 SkAutoTMalloc<SkColor> colorStorage; | 1687 SkDEBUGCODE(this->validate();) |
1704 SkColor* vertCols = NULL; | 1688 |
| 1689 #if 0 |
1705 if (colors) { | 1690 if (colors) { |
1706 colorStorage.reset(vertCount); | 1691 if (SkXfermode::kModulate_Mode != mode) { |
1707 vertCols = colorStorage.get(); | 1692 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); |
1708 | 1693 return; |
1709 for (int i = 0; i < count; ++i) { | |
1710 vertCols[0] = vertCols[1] = vertCols[2] = vertCols[3] = colors[i]; | |
1711 vertCols += 4; | |
1712 } | 1694 } |
1713 } | 1695 } |
1714 | 1696 #endif |
1715 verts = vertStorage.get(); | 1697 |
1716 texs = verts + vertCount; | 1698 fDrawContext->drawAtlas(fRenderTarget, fClip, grPaint, *draw.fMatrix, |
1717 vertCols = colorStorage.get(); | 1699 count, xform, texRect, colors); |
1718 indices = indexStorage.get(); | |
1719 this->drawVertices(d, SkCanvas::kTriangles_VertexMode, vertCount, verts, tex
s, vertCols, xfer, | |
1720 indices, indexCount, p); | |
1721 } | 1700 } |
1722 | 1701 |
1723 /////////////////////////////////////////////////////////////////////////////// | 1702 /////////////////////////////////////////////////////////////////////////////// |
1724 | 1703 |
1725 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1704 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1726 size_t byteLength, SkScalar x, SkScalar y, | 1705 size_t byteLength, SkScalar x, SkScalar y, |
1727 const SkPaint& paint) { | 1706 const SkPaint& paint) { |
1728 CHECK_SHOULD_DRAW(draw); | 1707 CHECK_SHOULD_DRAW(draw); |
1729 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1708 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
1730 | 1709 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1887 #endif | 1866 #endif |
1888 } | 1867 } |
1889 | 1868 |
1890 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1869 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1891 // We always return a transient cache, so it is freed after each | 1870 // We always return a transient cache, so it is freed after each |
1892 // filter traversal. | 1871 // filter traversal. |
1893 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1872 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1894 } | 1873 } |
1895 | 1874 |
1896 #endif | 1875 #endif |
OLD | NEW |