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

Side by Side Diff: src/core/SkDraw.cpp

Issue 41213003: Hook in rough distance field support for fonts (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Replace magic number 32 with constant; fix comment in shader; fix Linux compiler error. Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « include/gpu/GrDistanceFieldTextContext.h ('k') | src/core/SkDrawProcs.h » ('j') | 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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkDraw.h" 8 #include "SkDraw.h"
9 #include "SkBlitter.h" 9 #include "SkBlitter.h"
10 #include "SkBounder.h" 10 #include "SkBounder.h"
(...skipping 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 1673
1674 // SkScalarRec doesn't currently have a way of representing hairline stroke and 1674 // SkScalarRec doesn't currently have a way of representing hairline stroke and
1675 // will fill if its frame-width is 0. 1675 // will fill if its frame-width is 0.
1676 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { 1676 if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
1677 this->drawText_asPaths(text, byteLength, x, y, paint); 1677 this->drawText_asPaths(text, byteLength, x, y, paint);
1678 return; 1678 return;
1679 } 1679 }
1680 1680
1681 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 1681 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
1682 1682
1683 #if SK_DISTANCEFIELD_FONTS
1684 const SkMatrix* ctm = fMatrix;
1685 const SkPaint* paintRef = &paint;
1686 SkPaint paintCopy;
1687 uint32_t procFlags = fProcs ? fProcs->fFlags : 0;
1688 if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
1689 paintCopy = paint;
1690 paintCopy.setTextSize(SkDrawProcs::kBaseDFFontSize);
1691 paintCopy.setLCDRenderText(false);
1692 paintRef = &paintCopy;
1693 }
1694 if (procFlags & SkDrawProcs::kSkipBakedGlyphTransform_Flag) {
1695 ctm = NULL;
1696 }
1697 SkAutoGlyphCache autoCache(*paintRef, &fDevice->fLeakyProperties, ctm);
1698 #else
1683 SkAutoGlyphCache autoCache(paint, &fDevice->fLeakyProperties, fMatrix); 1699 SkAutoGlyphCache autoCache(paint, &fDevice->fLeakyProperties, fMatrix);
1700 #endif
1684 SkGlyphCache* cache = autoCache.getCache(); 1701 SkGlyphCache* cache = autoCache.getCache();
1685 1702
1686 // transform our starting point 1703 // transform our starting point
1704 #if SK_DISTANCEFIELD_FONTS
1705 if (!(procFlags & SkDrawProcs::kSkipBakedGlyphTransform_Flag))
1706 #endif
1687 { 1707 {
1688 SkPoint loc; 1708 SkPoint loc;
1689 fMatrix->mapXY(x, y, &loc); 1709 fMatrix->mapXY(x, y, &loc);
1690 x = loc.fX; 1710 x = loc.fX;
1691 y = loc.fY; 1711 y = loc.fY;
1692 } 1712 }
1693 1713
1694 // need to measure first 1714 // need to measure first
1695 if (paint.getTextAlign() != SkPaint::kLeft_Align) { 1715 if (paint.getTextAlign() != SkPaint::kLeft_Align) {
1696 SkVector stop; 1716 SkVector stop;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 d1g.fHalfSampleY = SK_FixedHalf; 1755 d1g.fHalfSampleY = SK_FixedHalf;
1736 } else if (kY_SkAxisAlignment == baseline) { 1756 } else if (kY_SkAxisAlignment == baseline) {
1737 fxMask = 0; 1757 fxMask = 0;
1738 d1g.fHalfSampleX = SK_FixedHalf; 1758 d1g.fHalfSampleX = SK_FixedHalf;
1739 } 1759 }
1740 } 1760 }
1741 1761
1742 SkFixed fx = SkScalarToFixed(x) + d1g.fHalfSampleX; 1762 SkFixed fx = SkScalarToFixed(x) + d1g.fHalfSampleX;
1743 SkFixed fy = SkScalarToFixed(y) + d1g.fHalfSampleY; 1763 SkFixed fy = SkScalarToFixed(y) + d1g.fHalfSampleY;
1744 1764
1765 #if SK_DISTANCEFIELD_FONTS
1766 SkFixed fixedScale;
1767 if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
1768 fixedScale = SkScalarToFixed(paint.getTextSize()/(float)SkDrawProcs::kBa seDFFontSize);
1769 }
1770 #endif
1745 while (text < stop) { 1771 while (text < stop) {
1746 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy Mask); 1772 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy Mask);
1747 1773
1774 #if SK_DISTANCEFIELD_FONTS
1775 if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
1776 fx += SkFixedMul_portable(autokern.adjust(glyph), fixedScale);
1777 } else {
1778 fx += autokern.adjust(glyph);
1779 }
1780 #else
1748 fx += autokern.adjust(glyph); 1781 fx += autokern.adjust(glyph);
1782 #endif
1749 1783
1750 if (glyph.fWidth) { 1784 if (glyph.fWidth) {
1751 proc(d1g, fx, fy, glyph); 1785 proc(d1g, fx, fy, glyph);
1752 } 1786 }
1787
1788 #if SK_DISTANCEFIELD_FONTS
1789 if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
1790 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale);
1791 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale);
1792 } else {
1793 fx += glyph.fAdvanceX;
1794 fy += glyph.fAdvanceY;
1795 }
1796 #else
1753 fx += glyph.fAdvanceX; 1797 fx += glyph.fAdvanceX;
1754 fy += glyph.fAdvanceY; 1798 fy += glyph.fAdvanceY;
1799 #endif
1755 } 1800 }
1756 } 1801 }
1757 1802
1758 // last parameter is interpreted as SkFixed [x, y] 1803 // last parameter is interpreted as SkFixed [x, y]
1759 // return the fixed position, which may be rounded or not by the caller 1804 // return the fixed position, which may be rounded or not by the caller
1760 // e.g. subpixel doesn't round 1805 // e.g. subpixel doesn't round
1761 typedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*); 1806 typedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*);
1762 1807
1763 static void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph, 1808 static void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph,
1764 SkIPoint* dst) { 1809 SkIPoint* dst) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 return; 1947 return;
1903 } 1948 }
1904 1949
1905 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { 1950 if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
1906 this->drawPosText_asPaths(text, byteLength, pos, constY, 1951 this->drawPosText_asPaths(text, byteLength, pos, constY,
1907 scalarsPerPosition, paint); 1952 scalarsPerPosition, paint);
1908 return; 1953 return;
1909 } 1954 }
1910 1955
1911 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 1956 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
1957 #if SK_DISTANCEFIELD_FONTS
1958 const SkMatrix* ctm = fMatrix;
1959 const SkPaint* paintRef = &paint;
1960 SkPaint paintCopy;
1961 uint32_t procFlags = fProcs ? fProcs->fFlags : 0;
1962 if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
1963 paintCopy = paint;
1964 paintCopy.setTextSize(SkDrawProcs::kBaseDFFontSize);
1965 paintRef = &paintCopy;
1966 }
1967 if (procFlags & SkDrawProcs::kSkipBakedGlyphTransform_Flag) {
1968 ctm = NULL;
1969 }
1970 SkAutoGlyphCache autoCache(*paintRef, &fDevice->fLeakyProperties, ctm);
1971 #else
1912 SkAutoGlyphCache autoCache(paint, &fDevice->fLeakyProperties, fMatrix); 1972 SkAutoGlyphCache autoCache(paint, &fDevice->fLeakyProperties, fMatrix);
1973 #endif
1913 SkGlyphCache* cache = autoCache.getCache(); 1974 SkGlyphCache* cache = autoCache.getCache();
1914 1975
1915 SkAAClipBlitterWrapper wrapper; 1976 SkAAClipBlitterWrapper wrapper;
1916 SkAutoBlitterChoose blitterChooser; 1977 SkAutoBlitterChoose blitterChooser;
1917 SkBlitter* blitter = NULL; 1978 SkBlitter* blitter = NULL;
1918 if (needsRasterTextBlit(*this)) { 1979 if (needsRasterTextBlit(*this)) {
1919 blitterChooser.choose(*fBitmap, *fMatrix, paint); 1980 blitterChooser.choose(*fBitmap, *fMatrix, paint);
1920 blitter = blitterChooser.get(); 1981 blitter = blitterChooser.get();
1921 if (fRC->isAA()) { 1982 if (fRC->isAA()) {
1922 wrapper.init(*fRC, blitter); 1983 wrapper.init(*fRC, blitter);
(...skipping 21 matching lines...) Expand all
1944 #endif 2005 #endif
1945 } else if (kY_SkAxisAlignment == baseline) { 2006 } else if (kY_SkAxisAlignment == baseline) {
1946 fxMask = 0; 2007 fxMask = 0;
1947 #ifndef SK_IGNORE_SUBPIXEL_AXIS_ALIGN_FIX 2008 #ifndef SK_IGNORE_SUBPIXEL_AXIS_ALIGN_FIX
1948 d1g.fHalfSampleX = SK_FixedHalf; 2009 d1g.fHalfSampleX = SK_FixedHalf;
1949 #endif 2010 #endif
1950 } 2011 }
1951 2012
1952 if (SkPaint::kLeft_Align == paint.getTextAlign()) { 2013 if (SkPaint::kLeft_Align == paint.getTextAlign()) {
1953 while (text < stop) { 2014 while (text < stop) {
2015 #if SK_DISTANCEFIELD_FONTS
2016 if (procFlags & SkDrawProcs::kSkipBakedGlyphTransform_Flag) {
2017 tms.fLoc.fX = *pos;
2018 tms.fLoc.fY = *(pos+1);
2019 } else {
2020 tmsProc(tms, pos);
2021 }
2022 #else
1954 tmsProc(tms, pos); 2023 tmsProc(tms, pos);
1955 2024 #endif
1956 SkFixed fx = SkScalarToFixed(tms.fLoc.fX) + d1g.fHalfSampleX; 2025 SkFixed fx = SkScalarToFixed(tms.fLoc.fX) + d1g.fHalfSampleX;
1957 SkFixed fy = SkScalarToFixed(tms.fLoc.fY) + d1g.fHalfSampleY; 2026 SkFixed fy = SkScalarToFixed(tms.fLoc.fY) + d1g.fHalfSampleY;
1958 2027
1959 const SkGlyph& glyph = glyphCacheProc(cache, &text, 2028 const SkGlyph& glyph = glyphCacheProc(cache, &text,
1960 fx & fxMask, fy & fyMask); 2029 fx & fxMask, fy & fyMask);
1961 2030
1962 if (glyph.fWidth) { 2031 if (glyph.fWidth) {
1963 proc(d1g, fx, fy, glyph); 2032 proc(d1g, fx, fy, glyph);
1964 } 2033 }
1965 pos += scalarsPerPosition; 2034 pos += scalarsPerPosition;
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
2826 mask->fImage = SkMask::AllocImage(size); 2895 mask->fImage = SkMask::AllocImage(size);
2827 memset(mask->fImage, 0, mask->computeImageSize()); 2896 memset(mask->fImage, 0, mask->computeImageSize());
2828 } 2897 }
2829 2898
2830 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2899 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2831 draw_into_mask(*mask, devPath, style); 2900 draw_into_mask(*mask, devPath, style);
2832 } 2901 }
2833 2902
2834 return true; 2903 return true;
2835 } 2904 }
OLDNEW
« no previous file with comments | « include/gpu/GrDistanceFieldTextContext.h ('k') | src/core/SkDrawProcs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698