Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 141863005: Add standalone drawText for GrTextContext. (Closed) Base URL: https://skia.googlesource.com/skia.git@issue2018-factory
Patch Set: One more Mac compile error. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrTextContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 vertexCount, 1759 vertexCount,
1760 (GrPoint*) vertices, 1760 (GrPoint*) vertices,
1761 (GrPoint*) texs, 1761 (GrPoint*) texs,
1762 colors, 1762 colors,
1763 indices, 1763 indices,
1764 indexCount); 1764 indexCount);
1765 } 1765 }
1766 1766
1767 /////////////////////////////////////////////////////////////////////////////// 1767 ///////////////////////////////////////////////////////////////////////////////
1768 1768
1769 static void GlyphCacheAuxProc(void* data) {
1770 GrFontScaler* scaler = (GrFontScaler*)data;
1771 SkSafeUnref(scaler);
1772 }
1773
1774 static GrFontScaler* get_gr_font_scaler(SkGlyphCache* cache) {
1775 void* auxData;
1776 GrFontScaler* scaler = NULL;
1777 if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) {
1778 scaler = (GrFontScaler*)auxData;
1779 }
1780 if (NULL == scaler) {
1781 scaler = SkNEW_ARGS(SkGrFontScaler, (cache));
1782 cache->setAuxProc(GlyphCacheAuxProc, scaler);
1783 }
1784 return scaler;
1785 }
1786
1787 static void SkGPU_Draw1Glyph(const SkDraw1Glyph& state,
1788 SkFixed fx, SkFixed fy,
1789 const SkGlyph& glyph) {
1790 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0);
1791
1792 GrSkDrawProcs* procs = static_cast<GrSkDrawProcs*>(state.fDraw->fProcs);
1793
1794 if (NULL == procs->fFontScaler) {
1795 procs->fFontScaler = get_gr_font_scaler(state.fCache);
1796 }
1797
1798 procs->fTextContext->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(),
1799 glyph.getSubXFixed(),
1800 glyph.getSubYFixed()),
1801 SkFixedFloorToFixed(fx),
1802 SkFixedFloorToFixed(fy),
1803 procs->fFontScaler);
1804 }
1805
1806 SkDrawProcs* SkGpuDevice::initDrawForText(GrTextContext* context) {
1807
1808 // deferred allocation
1809 if (NULL == fDrawProcs) {
1810 fDrawProcs = SkNEW(GrSkDrawProcs);
1811 fDrawProcs->fD1GProc = SkGPU_Draw1Glyph;
1812 fDrawProcs->fContext = fContext;
1813 }
1814
1815 // init our (and GL's) state
1816 fDrawProcs->fTextContext = context;
1817 fDrawProcs->fFontScaler = NULL;
1818 return fDrawProcs;
1819 }
1820
1821 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, 1769 void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
1822 size_t byteLength, SkScalar x, SkScalar y, 1770 size_t byteLength, SkScalar x, SkScalar y,
1823 const SkPaint& paint) { 1771 const SkPaint& paint) {
1824 CHECK_SHOULD_DRAW(draw, false); 1772 CHECK_SHOULD_DRAW(draw, false);
1825 1773
1826 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { 1774 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) {
1827 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); 1775 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint);
1828 #if SK_DISTANCEFIELD_FONTS 1776 } else {
1829 } else if (!paint.getRasterizer()) {
1830 GrPaint grPaint; 1777 GrPaint grPaint;
1831 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1778 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
1832 return; 1779 return;
1833 } 1780 }
1834 1781
1835 SkDEBUGCODE(this->validate();) 1782 SkDEBUGCODE(this->validate();)
1836 1783
1837 SkAutoTDelete<GrTextContext> context(fTextContextManager->create(fContex t, grPaint, paint)); 1784 SkAutoTDelete<GrTextContext> ctx(fTextContextManager->create(this->conte xt(),
1838 GrDistanceFieldTextContext* dfContext = 1785 grPaint, pa int,
1839 static_cast<GrDistanceFieldTextConte xt*>(context.get()); 1786 this->getDe viceProperties()));
1840 1787 ctx->drawText((const char *)text, byteLength, x, y);
1841 SkAutoGlyphCache autoCache(dfContext->getSkPaint(), &this->fLeakyProp erties, NULL);
1842 SkGlyphCache* cache = autoCache.getCache();
1843 GrFontScaler* fontScaler = get_gr_font_scaler(cache);
1844
1845 dfContext->drawText((const char *)text, byteLength, x, y, cache, fontSca ler);
1846 #endif
1847 } else {
1848 SkDraw myDraw(draw);
1849
1850 GrPaint grPaint;
1851 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
1852 return;
1853 }
1854
1855 SkAutoTDelete<GrTextContext> context(fTextContextManager->create(fContex t, grPaint, paint));
1856 myDraw.fProcs = this->initDrawForText(context.get());
1857 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint);
1858 } 1788 }
1859 } 1789 }
1860 1790
1861 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, 1791 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
1862 size_t byteLength, const SkScalar pos[], 1792 size_t byteLength, const SkScalar pos[],
1863 SkScalar constY, int scalarsPerPos, 1793 SkScalar constY, int scalarsPerPos,
1864 const SkPaint& paint) { 1794 const SkPaint& paint) {
1865 CHECK_SHOULD_DRAW(draw, false); 1795 CHECK_SHOULD_DRAW(draw, false);
1866 1796
1867 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { 1797 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) {
1868 // this guy will just call our drawPath() 1798 // this guy will just call our drawPath()
1869 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, 1799 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY,
1870 scalarsPerPos, paint); 1800 scalarsPerPos, paint);
1871 #if SK_DISTANCEFIELD_FONTS 1801 } else {
1872 } else if (!paint.getRasterizer()) {
1873 GrPaint grPaint; 1802 GrPaint grPaint;
1874 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1803 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
1875 return; 1804 return;
1876 } 1805 }
1877 1806
1878 SkDEBUGCODE(this->validate();) 1807 SkDEBUGCODE(this->validate();)
1879 1808
1880 SkAutoTDelete<GrTextContext> context(fTextContextManager->create(fContex t, grPaint, paint)); 1809 SkAutoTDelete<GrTextContext> ctx(fTextContextManager->create(this->conte xt(),
1881 GrDistanceFieldTextContext* dfContext = 1810 grPaint, pa int,
1882 static_cast<GrDistanceFieldTextConte xt*>(context.get()); 1811 this->getDe viceProperties()));
1883 1812 ctx->drawPosText((const char *)text, byteLength, pos, constY, scalarsPer Pos);
1884 SkAutoGlyphCache autoCache(dfContext->getSkPaint(), &this->fLeakyProp erties, NULL);
1885 SkGlyphCache* cache = autoCache.getCache();
1886 GrFontScaler* fontScaler = get_gr_font_scaler(cache);
1887
1888 dfContext->drawPosText((const char *)text, byteLength, pos, constY, scal arsPerPos,
1889 cache, fontScaler);
1890 #endif
1891 } else {
1892 SkDraw myDraw(draw);
1893
1894 GrPaint grPaint;
1895 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
1896 return;
1897 }
1898
1899 SkAutoTDelete<GrTextContext> context(fTextContextManager->create(fContex t, grPaint, paint));
1900 myDraw.fProcs = this->initDrawForText(context.get());
1901 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY,
1902 scalarsPerPos, paint);
1903 } 1813 }
1904 } 1814 }
1905 1815
1906 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, 1816 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text,
1907 size_t len, const SkPath& path, 1817 size_t len, const SkPath& path,
1908 const SkMatrix* m, const SkPaint& paint) { 1818 const SkMatrix* m, const SkPaint& paint) {
1909 CHECK_SHOULD_DRAW(draw, false); 1819 CHECK_SHOULD_DRAW(draw, false);
1910 1820
1911 SkASSERT(draw.fDevice == this); 1821 SkASSERT(draw.fDevice == this);
1912 draw.drawTextOnPath((const char*)text, len, path, m, paint); 1822 draw.drawTextOnPath((const char*)text, len, path, m, paint);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 GrTexture* texture, 1891 GrTexture* texture,
1982 bool needClear) 1892 bool needClear)
1983 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { 1893 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) {
1984 1894
1985 SkASSERT(texture && texture->asRenderTarget()); 1895 SkASSERT(texture && texture->asRenderTarget());
1986 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture 1896 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture
1987 // cache. We pass true for the third argument so that it will get unlocked. 1897 // cache. We pass true for the third argument so that it will get unlocked.
1988 this->initFromRenderTarget(context, texture->asRenderTarget(), true); 1898 this->initFromRenderTarget(context, texture->asRenderTarget(), true);
1989 fNeedClear = needClear; 1899 fNeedClear = needClear;
1990 } 1900 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698