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/GrTextureDomainEffect.h" | 10 #include "effects/GrTextureDomainEffect.h" |
(...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 | 1692 |
1693 SkDrawProcs* SkGpuDevice::initDrawForText(GrTextContext* context) { | 1693 SkDrawProcs* SkGpuDevice::initDrawForText(GrTextContext* context) { |
1694 | 1694 |
1695 // deferred allocation | 1695 // deferred allocation |
1696 if (NULL == fDrawProcs) { | 1696 if (NULL == fDrawProcs) { |
1697 fDrawProcs = SkNEW(GrSkDrawProcs); | 1697 fDrawProcs = SkNEW(GrSkDrawProcs); |
1698 fDrawProcs->fD1GProc = SkGPU_Draw1Glyph; | 1698 fDrawProcs->fD1GProc = SkGPU_Draw1Glyph; |
1699 fDrawProcs->fContext = fContext; | 1699 fDrawProcs->fContext = fContext; |
1700 #if SK_DISTANCEFIELD_FONTS | 1700 #if SK_DISTANCEFIELD_FONTS |
1701 fDrawProcs->fFlags = 0; | 1701 fDrawProcs->fFlags = 0; |
1702 fDrawProcs->fFlags |= SkDrawProcs::kSkipBakedGlyphTransform_Flag; | |
1703 fDrawProcs->fFlags |= SkDrawProcs::kUseScaledGlyphs_Flag; | |
1704 #endif | 1702 #endif |
1705 } | 1703 } |
1706 | 1704 |
1707 // init our (and GL's) state | 1705 // init our (and GL's) state |
1708 fDrawProcs->fTextContext = context; | 1706 fDrawProcs->fTextContext = context; |
1709 fDrawProcs->fFontScaler = NULL; | 1707 fDrawProcs->fFontScaler = NULL; |
1710 return fDrawProcs; | 1708 return fDrawProcs; |
1711 } | 1709 } |
1712 | 1710 |
1713 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1711 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1714 size_t byteLength, SkScalar x, SkScalar y, | 1712 size_t byteLength, SkScalar x, SkScalar y, |
1715 const SkPaint& paint) { | 1713 const SkPaint& paint) { |
1716 CHECK_SHOULD_DRAW(draw, false); | 1714 CHECK_SHOULD_DRAW(draw, false); |
1717 | 1715 |
1718 if (fContext->getMatrix().hasPerspective()) { | 1716 if (fContext->getMatrix().hasPerspective()) { |
1719 // this guy will just call our drawPath() | 1717 // this guy will just call our drawPath() |
1720 draw.drawText((const char*)text, byteLength, x, y, paint); | 1718 draw.drawText((const char*)text, byteLength, x, y, paint); |
1721 } else { | 1719 } else { |
1722 SkDraw myDraw(draw); | 1720 SkDraw myDraw(draw); |
1723 | 1721 |
1724 GrPaint grPaint; | 1722 GrPaint grPaint; |
1725 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1723 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1726 return; | 1724 return; |
1727 } | 1725 } |
1728 #if SK_DISTANCEFIELD_FONTS | 1726 #if SK_DISTANCEFIELD_FONTS |
1729 GrDistanceFieldTextContext context(fContext, grPaint, paint.getColor(), | 1727 if (paint.getRasterizer()) { |
1730 paint.getTextSize()); | |
1731 #else | |
1732 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); | |
1733 #endif | 1728 #endif |
1734 myDraw.fProcs = this->initDrawForText(&context); | 1729 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); |
1735 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); | 1730 myDraw.fProcs = this->initDrawForText(&context); |
| 1731 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); |
| 1732 #if SK_DISTANCEFIELD_FONTS |
| 1733 } else { |
| 1734 GrDistanceFieldTextContext context(fContext, grPaint, paint.getColor
(), |
| 1735 paint.getTextSize()/SkDrawProcs::
kBaseDFFontSize); |
| 1736 myDraw.fProcs = this->initDrawForText(&context); |
| 1737 fDrawProcs->fFlags |= SkDrawProcs::kSkipBakedGlyphTransform_Flag; |
| 1738 fDrawProcs->fFlags |= SkDrawProcs::kUseScaledGlyphs_Flag; |
| 1739 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); |
| 1740 fDrawProcs->fFlags = 0; |
| 1741 } |
| 1742 #endif |
1736 } | 1743 } |
1737 } | 1744 } |
1738 | 1745 |
1739 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, | 1746 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, |
1740 size_t byteLength, const SkScalar pos[], | 1747 size_t byteLength, const SkScalar pos[], |
1741 SkScalar constY, int scalarsPerPos, | 1748 SkScalar constY, int scalarsPerPos, |
1742 const SkPaint& paint) { | 1749 const SkPaint& paint) { |
1743 CHECK_SHOULD_DRAW(draw, false); | 1750 CHECK_SHOULD_DRAW(draw, false); |
1744 | 1751 |
1745 if (fContext->getMatrix().hasPerspective()) { | 1752 if (fContext->getMatrix().hasPerspective()) { |
1746 // this guy will just call our drawPath() | 1753 // this guy will just call our drawPath() |
1747 draw.drawPosText((const char*)text, byteLength, pos, constY, | 1754 draw.drawPosText((const char*)text, byteLength, pos, constY, |
1748 scalarsPerPos, paint); | 1755 scalarsPerPos, paint); |
1749 } else { | 1756 } else { |
1750 SkDraw myDraw(draw); | 1757 SkDraw myDraw(draw); |
1751 | 1758 |
1752 GrPaint grPaint; | 1759 GrPaint grPaint; |
1753 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1760 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1754 return; | 1761 return; |
1755 } | 1762 } |
1756 #if SK_DISTANCEFIELD_FONTS | 1763 #if SK_DISTANCEFIELD_FONTS |
1757 GrDistanceFieldTextContext context(fContext, grPaint, paint.getColor(), | 1764 if (paint.getRasterizer()) { |
1758 paint.getTextSize()/SkDrawProcs::kBas
eDFFontSize); | |
1759 #else | |
1760 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); | |
1761 #endif | 1765 #endif |
1762 myDraw.fProcs = this->initDrawForText(&context); | 1766 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); |
1763 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, | 1767 myDraw.fProcs = this->initDrawForText(&context); |
1764 scalarsPerPos, paint); | 1768 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, |
| 1769 scalarsPerPos, paint); |
| 1770 #if SK_DISTANCEFIELD_FONTS |
| 1771 } else { |
| 1772 GrDistanceFieldTextContext context(fContext, grPaint, paint.getColor
(), |
| 1773 paint.getTextSize()/SkDrawProcs::
kBaseDFFontSize); |
| 1774 myDraw.fProcs = this->initDrawForText(&context); |
| 1775 fDrawProcs->fFlags |= SkDrawProcs::kSkipBakedGlyphTransform_Flag; |
| 1776 fDrawProcs->fFlags |= SkDrawProcs::kUseScaledGlyphs_Flag; |
| 1777 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, |
| 1778 scalarsPerPos, paint); |
| 1779 fDrawProcs->fFlags = 0; |
| 1780 } |
| 1781 #endif |
1765 } | 1782 } |
1766 } | 1783 } |
1767 | 1784 |
1768 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, | 1785 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, |
1769 size_t len, const SkPath& path, | 1786 size_t len, const SkPath& path, |
1770 const SkMatrix* m, const SkPaint& paint) { | 1787 const SkMatrix* m, const SkPaint& paint) { |
1771 CHECK_SHOULD_DRAW(draw, false); | 1788 CHECK_SHOULD_DRAW(draw, false); |
1772 | 1789 |
1773 SkASSERT(draw.fDevice == this); | 1790 SkASSERT(draw.fDevice == this); |
1774 draw.drawTextOnPath((const char*)text, len, path, m, paint); | 1791 draw.drawTextOnPath((const char*)text, len, path, m, paint); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1843 GrTexture* texture, | 1860 GrTexture* texture, |
1844 bool needClear) | 1861 bool needClear) |
1845 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1862 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1846 | 1863 |
1847 SkASSERT(texture && texture->asRenderTarget()); | 1864 SkASSERT(texture && texture->asRenderTarget()); |
1848 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1865 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1849 // cache. We pass true for the third argument so that it will get unlocked. | 1866 // cache. We pass true for the third argument so that it will get unlocked. |
1850 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1867 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1851 fNeedClear = needClear; | 1868 fNeedClear = needClear; |
1852 } | 1869 } |
OLD | NEW |