Enable use of distance fields via SkPaint flag.

Now that distance field generation is fast enough to make it practical, this makes distances field fonts easily available to anyone who wants to try them out (i.e Chromium).

BUG=skia:2173
R=reed@google.com, bsalomon@google.com

Author: jvanverth@google.com

Review URL: https://codereview.chromium.org/193163003

git-svn-id: http://skia.googlecode.com/svn/trunk@13741 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-03-11 17:07:15 +00:00
parent 8065ec50f1
commit b97c3ffddf
12 changed files with 25 additions and 54 deletions

View File

@ -5,7 +5,6 @@
'SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=<(skia_static_initializers)',
'SK_SUPPORT_GPU=<(skia_gpu)',
'SK_SUPPORT_OPENCL=<(skia_opencl)',
'SK_DISTANCEFIELD_FONTS=<(skia_distancefield_fonts)',
],
'conditions' : [
[ 'skia_os == "win"',

View File

@ -142,7 +142,6 @@
'skia_win_debuggers_path%': '',
'skia_shared_lib%': 0,
'skia_opencl%': 0,
'skia_distancefield_fonts%': 0,
# These variables determine the default optimization level for different
# compilers.
@ -211,7 +210,6 @@
'skia_profile_enabled%': '<(skia_profile_enabled)',
'skia_shared_lib%': '<(skia_shared_lib)',
'skia_opencl%': '<(skia_opencl)',
'skia_distancefield_fonts%': '<(skia_distancefield_fonts)',
'skia_static_initializers%': '<(skia_static_initializers)',
'ios_sdk_version%': '6.0',
'skia_win_debuggers_path%': '<(skia_win_debuggers_path)',

View File

@ -133,17 +133,6 @@
'GR_CHROME_UTILS=1',
],
}],
[ 'skia_distancefield_fonts', {
'sources': [
'<(skia_src_path)/gpu/GrDistanceFieldTextContext.h',
'<(skia_src_path)/gpu/GrDistanceFieldTextContext.cpp',
'<(skia_src_path)/gpu/effects/GrDistanceFieldTextureEffect.cpp',
'<(skia_src_path)/gpu/effects/GrDistanceFieldTextureEffect.h',
],
'defines': [
'GR_DISTANCEFIELD_FONTS=1',
],
}],
[ 'skia_os == "linux" or skia_os == "chromeos"', {
'sources!': [
'../src/gpu/gl/GrGLDefaultInterface_none.cpp',

View File

@ -63,6 +63,8 @@
'<(skia_src_path)/gpu/GrContext.cpp',
'<(skia_src_path)/gpu/GrDefaultPathRenderer.cpp',
'<(skia_src_path)/gpu/GrDefaultPathRenderer.h',
'<(skia_src_path)/gpu/GrDistanceFieldTextContext.h',
'<(skia_src_path)/gpu/GrDistanceFieldTextContext.cpp',
'<(skia_src_path)/gpu/GrDrawState.cpp',
'<(skia_src_path)/gpu/GrDrawState.h',
'<(skia_src_path)/gpu/GrDrawTarget.cpp',
@ -140,6 +142,8 @@
'<(skia_src_path)/gpu/effects/GrBicubicEffect.h',
'<(skia_src_path)/gpu/effects/GrCustomCoordsTextureEffect.cpp',
'<(skia_src_path)/gpu/effects/GrCustomCoordsTextureEffect.h',
'<(skia_src_path)/gpu/effects/GrDistanceFieldTextureEffect.cpp',
'<(skia_src_path)/gpu/effects/GrDistanceFieldTextureEffect.h',
'<(skia_src_path)/gpu/effects/GrRRectEffect.cpp',
'<(skia_src_path)/gpu/effects/GrRRectEffect.h',
'<(skia_src_path)/gpu/effects/GrSimpleTextureEffect.cpp',

View File

@ -118,6 +118,8 @@ public:
kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
kVerticalText_Flag = 0x1000,
kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it
kDistanceFieldTextTEMP_Flag = 0x4000, //!< TEMPORARY mask to enable distance fields
// currently overrides LCD and subpixel rendering
// when adding extra flags, note that the fFlags member is specified
// with a bit-width and you'll have to expand it.
@ -284,6 +286,19 @@ public:
*/
void setDevKernText(bool devKernText);
/** Helper for getFlags(), returns true if kDistanceFieldTextTEMP_Flag bit is set
@return true if the distanceFieldText bit is set in the paint's flags.
*/
bool isDistanceFieldTextTEMP() const {
return SkToBool(this->getFlags() & kDistanceFieldTextTEMP_Flag);
}
/** Helper for setFlags(), setting or clearing the kDistanceFieldTextTEMP_Flag bit
@param distanceFieldText true to set the kDistanceFieldTextTEMP_Flag bit in the paint's
flags, false to clear it.
*/
void setDistanceFieldTextTEMP(bool distanceFieldText);
enum FilterLevel {
kNone_FilterLevel,
kLow_FilterLevel,
@ -1063,7 +1078,6 @@ private:
uint32_t fDirtyBits;
SkDrawCacheProc getDrawCacheProc() const;
SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,
bool needFullMetrics) const;

View File

@ -307,6 +307,10 @@ void SkPaint::setDevKernText(bool doDevKern) {
this->setFlags(SkSetClearMask(fFlags, doDevKern, kDevKernText_Flag));
}
void SkPaint::setDistanceFieldTextTEMP(bool doDistanceFieldText) {
this->setFlags(SkSetClearMask(fFlags, doDistanceFieldText, kDistanceFieldTextTEMP_Flag));
}
void SkPaint::setStyle(Style style) {
if ((unsigned)style < kStyleCount) {
GEN_ID_INC_EVAL((unsigned)style != fStyle);

View File

@ -488,11 +488,7 @@ void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
}
if (NULL == fStrike) {
#if SK_DISTANCEFIELD_FONTS
fStrike = fContext->getFontCache()->getStrike(scaler, false);
#else
fStrike = fContext->getFontCache()->getStrike(scaler);
#endif
}
GrGlyph* glyph = fStrike->getGlyph(packed, scaler);

View File

@ -45,7 +45,8 @@ GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
}
bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
return !paint.getRasterizer() && !paint.getMaskFilter() &&
return paint.isDistanceFieldTextTEMP() &&
!paint.getRasterizer() && !paint.getMaskFilter() &&
paint.getStyle() == SkPaint::kFill_Style &&
fContext->getTextTarget()->caps()->shaderDerivativeSupport() &&
!SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix());

View File

@ -12,9 +12,7 @@
#include "GrTextStrike_impl.h"
#include "SkString.h"
#if SK_DISTANCEFIELD_FONTS
#include "SkDistanceFieldGen.h"
#endif
///////////////////////////////////////////////////////////////////////////////
@ -198,11 +196,9 @@ void GrFontCache::dump() const {
static int gCounter;
#endif
#if SK_DISTANCEFIELD_FONTS
// this acts as the max magnitude for the distance field,
// as well as the pad we need around the glyph
#define DISTANCE_FIELD_RANGE 4
#endif
/*
The text strike is specific to a given font/style/matrix setup, which is
@ -251,7 +247,6 @@ GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed,
}
GrGlyph* glyph = fPool.alloc();
#if SK_DISTANCEFIELD_FONTS
// expand bounds to hold full distance field data
if (fUseDistanceField) {
bounds.fLeft -= DISTANCE_FIELD_RANGE;
@ -259,7 +254,6 @@ GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed,
bounds.fTop -= DISTANCE_FIELD_RANGE;
bounds.fBottom += DISTANCE_FIELD_RANGE;
}
#endif
glyph->init(packed, bounds);
fCache.insert(packed, glyph);
return glyph;
@ -293,7 +287,6 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) {
int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat);
GrPlot* plot;
#if SK_DISTANCEFIELD_FONTS
if (fUseDistanceField) {
// we've already expanded the glyph dimensions to match the final size
// but must shrink back down to get the packed glyph data
@ -341,7 +334,6 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) {
&glyph->fAtlasLocation);
} else {
#endif
size_t size = glyph->fBounds.area() * bytesPerPixel;
SkAutoSMalloc<1024> storage(size);
if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(),
@ -354,9 +346,7 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) {
plot = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(),
glyph->height(), storage.get(),
&glyph->fAtlasLocation);
#if SK_DISTANCEFIELD_FONTS
}
#endif
if (NULL == plot) {
return false;

View File

@ -64,9 +64,7 @@ private:
GrFontCache* fFontCache;
GrAtlasMgr* fAtlasMgr;
GrMaskFormat fMaskFormat;
#if SK_DISTANCEFIELD_FONTS
bool fUseDistanceField;
#endif
GrAtlas fAtlas;
@ -80,11 +78,7 @@ public:
GrFontCache(GrGpu*);
~GrFontCache();
#if SK_DISTANCEFIELD_FONTS
inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
#else
inline GrTextStrike* getStrike(GrFontScaler*);
#endif
void freeAll();

View File

@ -48,11 +48,7 @@ void GrFontCache::detachStrikeFromList(GrTextStrike* strike) {
}
}
#if SK_DISTANCEFIELD_FONTS
GrTextStrike* GrFontCache::getStrike(GrFontScaler* scaler, bool useDistanceField) {
#else
GrTextStrike* GrFontCache::getStrike(GrFontScaler* scaler) {
#endif
this->validate();
const Key key(scaler->getKey());
@ -69,9 +65,7 @@ GrTextStrike* GrFontCache::getStrike(GrFontScaler* scaler) {
strike->fPrev = NULL;
fHead = strike;
}
#if SK_DISTANCEFIELD_FONTS
strike->fUseDistanceField = useDistanceField;
#endif
this->validate();
return strike;
}

View File

@ -13,9 +13,7 @@
#include "GrContext.h"
#include "GrBitmapTextContext.h"
#if SK_DISTANCEFIELD_FONTS
#include "GrDistanceFieldTextContext.h"
#endif
#include "SkGrTexturePixelRef.h"
@ -189,13 +187,8 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context,
fContext = context;
fContext->ref();
#if SK_DISTANCEFIELD_FONTS
fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyProperties));
fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties));
#else
fMainTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties));
fFallbackTextContext = NULL;
#endif
fRenderTarget = NULL;
fNeedClear = false;
@ -274,13 +267,8 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
fContext = context;
fContext->ref();
#if SK_DISTANCEFIELD_FONTS
fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyProperties));
fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties));
#else
fMainTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties));
fFallbackTextContext = NULL;
#endif
fRenderTarget = NULL;
fNeedClear = false;