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 to_quad(SkPoint quad[], const SkRect& r) { | |
bsalomon
2015/06/25 21:31:38
SkRect already has toQuad().
reed1
2015/06/25 21:47:51
Done.
| |
1643 quad[0].set(r.fLeft, r.fTop); | |
1644 quad[1].set(r.fRight, r.fTop); | |
1645 quad[2].set(r.fRight, r.fBottom); | |
1646 quad[3].set(r.fLeft, r.fBottom); | |
1647 } | |
1648 | |
1649 static void append_quad_indices(uint16_t indices[], int quadIndex) { | |
1650 int i = quadIndex * 4; | |
1651 indices[0] = i + 0; indices[1] = i + 1; indices[2] = i + 2; | |
1652 indices[3] = i + 2; indices[4] = i + 3; indices[5] = i + 0; | |
1653 } | |
1654 | |
1655 void SkGpuDevice::drawAtlas(const SkDraw& d, const SkImage* atlas, const SkRSXfo rm xform[], | |
1656 const SkRect texRect[], const SkColor colors[], int count, | |
1657 SkXfermode::Mode mode, const SkPaint& paint) { | |
1658 if (paint.isAntiAlias()) { | |
1659 this->INHERITED::drawAtlas(d, atlas, xform, texRect, colors, count, mode , paint); | |
1660 return; | |
1661 } | |
1662 | |
1663 SkPaint p(paint); | |
1664 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til eMode))->unref(); | |
1665 | |
1666 const int vertCount = count * 4; | |
1667 const int indexCount = count * 6; | |
1668 SkAutoTMalloc<SkPoint> vertStorage(vertCount * 2); | |
1669 SkPoint* verts = vertStorage.get(); | |
1670 SkPoint* texs = verts + vertCount; | |
1671 SkAutoTMalloc<uint16_t> indexStorage(indexCount); | |
1672 uint16_t* indices = indexStorage.get(); | |
1673 SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode)); | |
1674 | |
1675 for (int i = 0; i < count; ++i) { | |
1676 xform[i].toQuad(texRect[i].width(), texRect[i].height(), verts); | |
1677 to_quad(texs, texRect[i]); | |
1678 append_quad_indices(indices, i); | |
1679 verts += 4; | |
1680 texs += 4; | |
1681 indices += 6; | |
1682 } | |
1683 | |
1684 verts = vertStorage.get(); | |
1685 texs = verts + vertCount; | |
1686 indices = indexStorage.get(); | |
1687 this->drawVertices(d, SkCanvas::kTriangles_VertexMode, vertCount, verts, tex s, colors, xfer, | |
1688 indices, indexCount, p); | |
1689 } | |
1690 | |
1691 /////////////////////////////////////////////////////////////////////////////// | |
1692 | |
1642 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1693 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1643 size_t byteLength, SkScalar x, SkScalar y, | 1694 size_t byteLength, SkScalar x, SkScalar y, |
1644 const SkPaint& paint) { | 1695 const SkPaint& paint) { |
1645 CHECK_SHOULD_DRAW(draw); | 1696 CHECK_SHOULD_DRAW(draw); |
1646 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1697 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
1647 | 1698 |
1648 GrPaint grPaint; | 1699 GrPaint grPaint; |
1649 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) { | 1700 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) { |
1650 return; | 1701 return; |
1651 } | 1702 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1803 #endif | 1854 #endif |
1804 } | 1855 } |
1805 | 1856 |
1806 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1857 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1807 // We always return a transient cache, so it is freed after each | 1858 // We always return a transient cache, so it is freed after each |
1808 // filter traversal. | 1859 // filter traversal. |
1809 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1860 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1810 } | 1861 } |
1811 | 1862 |
1812 #endif | 1863 #endif |
OLD | NEW |