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/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
(...skipping 1731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1742 procs->fFontScaler); | 1742 procs->fFontScaler); |
1743 } | 1743 } |
1744 | 1744 |
1745 SkDrawProcs* SkGpuDevice::initDrawForText(GrTextContext* context) { | 1745 SkDrawProcs* SkGpuDevice::initDrawForText(GrTextContext* context) { |
1746 | 1746 |
1747 // deferred allocation | 1747 // deferred allocation |
1748 if (NULL == fDrawProcs) { | 1748 if (NULL == fDrawProcs) { |
1749 fDrawProcs = SkNEW(GrSkDrawProcs); | 1749 fDrawProcs = SkNEW(GrSkDrawProcs); |
1750 fDrawProcs->fD1GProc = SkGPU_Draw1Glyph; | 1750 fDrawProcs->fD1GProc = SkGPU_Draw1Glyph; |
1751 fDrawProcs->fContext = fContext; | 1751 fDrawProcs->fContext = fContext; |
1752 #if SK_DISTANCEFIELD_FONTS | |
1753 fDrawProcs->fFlags = 0; | |
1754 #endif | |
1755 } | 1752 } |
1756 | 1753 |
1757 // init our (and GL's) state | 1754 // init our (and GL's) state |
1758 fDrawProcs->fTextContext = context; | 1755 fDrawProcs->fTextContext = context; |
1759 fDrawProcs->fFontScaler = NULL; | 1756 fDrawProcs->fFontScaler = NULL; |
1760 return fDrawProcs; | 1757 return fDrawProcs; |
1761 } | 1758 } |
1762 | 1759 |
1763 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1760 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1764 size_t byteLength, SkScalar x, SkScalar y, | 1761 size_t byteLength, SkScalar x, SkScalar y, |
1765 const SkPaint& paint) { | 1762 const SkPaint& paint) { |
1766 CHECK_SHOULD_DRAW(draw, false); | 1763 CHECK_SHOULD_DRAW(draw, false); |
1767 | 1764 |
1768 if (fContext->getMatrix().hasPerspective()) { | 1765 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { |
1769 // this guy will just call our drawPath() | 1766 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); |
1770 draw.drawText((const char*)text, byteLength, x, y, paint); | 1767 #if SK_DISTANCEFIELD_FONTS |
| 1768 } else if (!paint.getRasterizer()) { |
| 1769 GrPaint grPaint; |
| 1770 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
| 1771 return; |
| 1772 } |
| 1773 |
| 1774 SkDEBUGCODE(this->validate();) |
| 1775 |
| 1776 GrDistanceFieldTextContext context(fContext, grPaint, paint); |
| 1777 |
| 1778 SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyPropert
ies, NULL); |
| 1779 SkGlyphCache* cache = autoCache.getCache(); |
| 1780 GrFontScaler* fontScaler = get_gr_font_scaler(cache); |
| 1781 |
| 1782 context.drawText((const char *)text, byteLength, x, y, cache, fontScaler
); |
| 1783 #endif |
1771 } else { | 1784 } else { |
1772 SkDraw myDraw(draw); | 1785 SkDraw myDraw(draw); |
1773 | 1786 |
1774 GrPaint grPaint; | 1787 GrPaint grPaint; |
1775 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1788 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1776 return; | 1789 return; |
1777 } | 1790 } |
1778 #if SK_DISTANCEFIELD_FONTS | 1791 |
1779 if (paint.getRasterizer()) { | 1792 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); |
1780 #endif | 1793 myDraw.fProcs = this->initDrawForText(&context); |
1781 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); | 1794 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); |
1782 myDraw.fProcs = this->initDrawForText(&context); | |
1783 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); | |
1784 #if SK_DISTANCEFIELD_FONTS | |
1785 } else { | |
1786 GrDistanceFieldTextContext context(fContext, grPaint, paint.getColor
(), | |
1787 paint.getTextSize()/SkDrawProcs::
kBaseDFFontSize); | |
1788 myDraw.fProcs = this->initDrawForText(&context); | |
1789 fDrawProcs->fFlags |= SkDrawProcs::kSkipBakedGlyphTransform_Flag; | |
1790 fDrawProcs->fFlags |= SkDrawProcs::kUseScaledGlyphs_Flag; | |
1791 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); | |
1792 fDrawProcs->fFlags = 0; | |
1793 } | |
1794 #endif | |
1795 } | 1795 } |
1796 } | 1796 } |
1797 | 1797 |
1798 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, | 1798 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, |
1799 size_t byteLength, const SkScalar pos[], | 1799 size_t byteLength, const SkScalar pos[], |
1800 SkScalar constY, int scalarsPerPos, | 1800 SkScalar constY, int scalarsPerPos, |
1801 const SkPaint& paint) { | 1801 const SkPaint& paint) { |
1802 CHECK_SHOULD_DRAW(draw, false); | 1802 CHECK_SHOULD_DRAW(draw, false); |
1803 | 1803 |
1804 if (fContext->getMatrix().hasPerspective()) { | 1804 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { |
1805 // this guy will just call our drawPath() | 1805 // this guy will just call our drawPath() |
1806 draw.drawPosText((const char*)text, byteLength, pos, constY, | 1806 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, |
1807 scalarsPerPos, paint); | 1807 scalarsPerPos, paint); |
| 1808 #if SK_DISTANCEFIELD_FONTS |
| 1809 } else if (!paint.getRasterizer()) { |
| 1810 GrPaint grPaint; |
| 1811 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
| 1812 return; |
| 1813 } |
| 1814 |
| 1815 SkDEBUGCODE(this->validate();) |
| 1816 |
| 1817 GrDistanceFieldTextContext context(fContext, grPaint, paint); |
| 1818 |
| 1819 SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyPropert
ies, NULL); |
| 1820 SkGlyphCache* cache = autoCache.getCache(); |
| 1821 GrFontScaler* fontScaler = get_gr_font_scaler(cache); |
| 1822 |
| 1823 context.drawPosText((const char *)text, byteLength, pos, constY, scalars
PerPos, |
| 1824 cache, fontScaler); |
| 1825 #endif |
1808 } else { | 1826 } else { |
1809 SkDraw myDraw(draw); | 1827 SkDraw myDraw(draw); |
1810 | 1828 |
1811 GrPaint grPaint; | 1829 GrPaint grPaint; |
1812 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1830 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1813 return; | 1831 return; |
1814 } | 1832 } |
1815 #if SK_DISTANCEFIELD_FONTS | 1833 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); |
1816 if (paint.getRasterizer()) { | 1834 myDraw.fProcs = this->initDrawForText(&context); |
1817 #endif | 1835 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, |
1818 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); | 1836 scalarsPerPos, paint); |
1819 myDraw.fProcs = this->initDrawForText(&context); | |
1820 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, | |
1821 scalarsPerPos, paint); | |
1822 #if SK_DISTANCEFIELD_FONTS | |
1823 } else { | |
1824 GrDistanceFieldTextContext context(fContext, grPaint, paint.getColor
(), | |
1825 paint.getTextSize()/SkDrawProcs::
kBaseDFFontSize); | |
1826 myDraw.fProcs = this->initDrawForText(&context); | |
1827 fDrawProcs->fFlags |= SkDrawProcs::kSkipBakedGlyphTransform_Flag; | |
1828 fDrawProcs->fFlags |= SkDrawProcs::kUseScaledGlyphs_Flag; | |
1829 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, | |
1830 scalarsPerPos, paint); | |
1831 fDrawProcs->fFlags = 0; | |
1832 } | |
1833 #endif | |
1834 } | 1837 } |
1835 } | 1838 } |
1836 | 1839 |
1837 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, | 1840 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, |
1838 size_t len, const SkPath& path, | 1841 size_t len, const SkPath& path, |
1839 const SkMatrix* m, const SkPaint& paint) { | 1842 const SkMatrix* m, const SkPaint& paint) { |
1840 CHECK_SHOULD_DRAW(draw, false); | 1843 CHECK_SHOULD_DRAW(draw, false); |
1841 | 1844 |
1842 SkASSERT(draw.fDevice == this); | 1845 SkASSERT(draw.fDevice == this); |
1843 draw.drawTextOnPath((const char*)text, len, path, m, paint); | 1846 draw.drawTextOnPath((const char*)text, len, path, m, paint); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1912 GrTexture* texture, | 1915 GrTexture* texture, |
1913 bool needClear) | 1916 bool needClear) |
1914 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1917 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1915 | 1918 |
1916 SkASSERT(texture && texture->asRenderTarget()); | 1919 SkASSERT(texture && texture->asRenderTarget()); |
1917 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1920 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1918 // cache. We pass true for the third argument so that it will get unlocked. | 1921 // cache. We pass true for the third argument so that it will get unlocked. |
1919 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1922 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1920 fNeedClear = needClear; | 1923 fNeedClear = needClear; |
1921 } | 1924 } |
OLD | NEW |