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 1621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 vertexCount, | 1632 vertexCount, |
1633 vertices, | 1633 vertices, |
1634 texs, | 1634 texs, |
1635 colors, | 1635 colors, |
1636 outIndices, | 1636 outIndices, |
1637 indexCount); | 1637 indexCount); |
1638 } | 1638 } |
1639 | 1639 |
1640 /////////////////////////////////////////////////////////////////////////////// | 1640 /////////////////////////////////////////////////////////////////////////////// |
1641 | 1641 |
| 1642 static void append_quad_indices(uint16_t indices[], int quadIndex) { |
| 1643 int i = quadIndex * 4; |
| 1644 indices[0] = i + 0; indices[1] = i + 1; indices[2] = i + 2; |
| 1645 indices[3] = i + 2; indices[4] = i + 3; indices[5] = i + 0; |
| 1646 } |
| 1647 |
| 1648 void SkGpuDevice::drawAtlas(const SkDraw& d, const SkImage* atlas, const SkRSXfo
rm xform[], |
| 1649 const SkRect texRect[], const SkColor colors[], int
count, |
| 1650 SkXfermode::Mode mode, const SkPaint& paint) { |
| 1651 if (paint.isAntiAlias()) { |
| 1652 this->INHERITED::drawAtlas(d, atlas, xform, texRect, colors, count, mode
, paint); |
| 1653 return; |
| 1654 } |
| 1655 |
| 1656 SkPaint p(paint); |
| 1657 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til
eMode))->unref(); |
| 1658 |
| 1659 const int vertCount = count * 4; |
| 1660 const int indexCount = count * 6; |
| 1661 SkAutoTMalloc<SkPoint> vertStorage(vertCount * 2); |
| 1662 SkPoint* verts = vertStorage.get(); |
| 1663 SkPoint* texs = verts + vertCount; |
| 1664 SkAutoTMalloc<uint16_t> indexStorage(indexCount); |
| 1665 uint16_t* indices = indexStorage.get(); |
| 1666 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode)); |
| 1667 |
| 1668 for (int i = 0; i < count; ++i) { |
| 1669 xform[i].toQuad(texRect[i].width(), texRect[i].height(), verts); |
| 1670 texRect[i].toQuad(texs); |
| 1671 append_quad_indices(indices, i); |
| 1672 verts += 4; |
| 1673 texs += 4; |
| 1674 indices += 6; |
| 1675 } |
| 1676 |
| 1677 verts = vertStorage.get(); |
| 1678 texs = verts + vertCount; |
| 1679 indices = indexStorage.get(); |
| 1680 this->drawVertices(d, SkCanvas::kTriangles_VertexMode, vertCount, verts, tex
s, colors, xfer, |
| 1681 indices, indexCount, p); |
| 1682 } |
| 1683 |
| 1684 /////////////////////////////////////////////////////////////////////////////// |
| 1685 |
1642 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1686 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1643 size_t byteLength, SkScalar x, SkScalar y, | 1687 size_t byteLength, SkScalar x, SkScalar y, |
1644 const SkPaint& paint) { | 1688 const SkPaint& paint) { |
1645 CHECK_SHOULD_DRAW(draw); | 1689 CHECK_SHOULD_DRAW(draw); |
1646 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1690 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
1647 | 1691 |
1648 GrPaint grPaint; | 1692 GrPaint grPaint; |
1649 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t
rue, &grPaint)) { | 1693 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t
rue, &grPaint)) { |
1650 return; | 1694 return; |
1651 } | 1695 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 #endif | 1847 #endif |
1804 } | 1848 } |
1805 | 1849 |
1806 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1850 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1807 // We always return a transient cache, so it is freed after each | 1851 // We always return a transient cache, so it is freed after each |
1808 // filter traversal. | 1852 // filter traversal. |
1809 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1853 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1810 } | 1854 } |
1811 | 1855 |
1812 #endif | 1856 #endif |
OLD | NEW |