Add flag for SkGpuSurface creation to enable distance fields.

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

Author: jvanverth@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@14525 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-05-02 12:39:41 +00:00
Родитель 9a40803f2b
Коммит 6fcd1ef244
6 изменённых файлов: 48 добавлений и 22 удалений

Просмотреть файл

@ -55,16 +55,32 @@ public:
return NewRaster(SkImageInfo::MakeN32Premul(width, height)); return NewRaster(SkImageInfo::MakeN32Premul(width, height));
} }
/**
* Text rendering modes that can be passed to NewRenderTarget*
*/
enum TextRenderMode {
/**
* This will use the standard text rendering method
*/
kStandard_TextRenderMode,
/**
* This will use signed distance fields for text rendering when possible
*/
kDistanceField_TextRenderMode,
};
/** /**
* Return a new surface using the specified render target. * Return a new surface using the specified render target.
*/ */
static SkSurface* NewRenderTargetDirect(GrRenderTarget*); static SkSurface* NewRenderTargetDirect(GrRenderTarget*,
TextRenderMode trm = kStandard_TextRenderMode);
/** /**
* Return a new surface whose contents will be drawn to an offscreen * Return a new surface whose contents will be drawn to an offscreen
* render target, allocated by the surface. * render target, allocated by the surface.
*/ */
static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sampleCount = 0); static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sampleCount = 0,
TextRenderMode trm = kStandard_TextRenderMode);
/** /**
* Return a new surface whose contents will be drawn to an offscreen * Return a new surface whose contents will be drawn to an offscreen
@ -78,7 +94,8 @@ public:
* Note: Scratch textures count against the GrContext's cached resource * Note: Scratch textures count against the GrContext's cached resource
* budget. * budget.
*/ */
static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int sampleCount = 0); static SkSurface* NewScratchRenderTarget(GrContext*, const SkImageInfo&, int sampleCount = 0,
TextRenderMode trm = kStandard_TextRenderMode);
int width() const { return fWidth; } int width() const { return fWidth; }
int height() const { return fHeight; } int height() const { return fHeight; }

Просмотреть файл

@ -32,6 +32,7 @@ public:
enum Flags { enum Flags {
kNeedClear_Flag = 1 << 0, //!< Surface requires an initial clear kNeedClear_Flag = 1 << 0, //!< Surface requires an initial clear
kCached_Flag = 1 << 1, //!< Surface is cached and needs to be unlocked when released kCached_Flag = 1 << 1, //!< Surface is cached and needs to be unlocked when released
kDFFonts_Flag = 1 << 2, //!< Surface should render fonts using signed distance fields
}; };
/** /**

Просмотреть файл

@ -33,15 +33,15 @@ static const int kLargeDFFontSize = 128;
SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
"Dump the contents of the font cache before every purge."); "Dump the contents of the font cache before every purge.");
#if SK_FORCE_DISTANCEFIELD_FONTS
static const bool kForceDistanceFieldFonts = true;
#else
static const bool kForceDistanceFieldFonts = false;
#endif
GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
const SkDeviceProperties& properties) const SkDeviceProperties& properties,
bool enable)
: GrTextContext(context, properties) { : GrTextContext(context, properties) {
#if SK_FORCE_DISTANCEFIELD_FONTS
fEnableDFRendering = true;
#else
fEnableDFRendering = enable;
#endif
fStrike = NULL; fStrike = NULL;
fCurrTexture = NULL; fCurrTexture = NULL;
@ -56,7 +56,7 @@ GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
} }
bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
if (!kForceDistanceFieldFonts && !paint.isDistanceFieldTextTEMP()) { if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) {
return false; return false;
} }

Просмотреть файл

@ -17,7 +17,7 @@ class GrTextStrike;
*/ */
class GrDistanceFieldTextContext : public GrTextContext { class GrDistanceFieldTextContext : public GrTextContext {
public: public:
GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&); GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable);
virtual ~GrDistanceFieldTextContext(); virtual ~GrDistanceFieldTextContext();
virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength, virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
@ -33,6 +33,7 @@ private:
GrTextStrike* fStrike; GrTextStrike* fStrike;
SkScalar fTextRatio; SkScalar fTextRatio;
bool fUseLCDText; bool fUseLCDText;
bool fEnableDFRendering;
void init(const GrPaint&, const SkPaint&); void init(const GrPaint&, const SkPaint&);
void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*); void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);

Просмотреть файл

@ -190,7 +190,9 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context,
fContext = context; fContext = context;
fContext->ref(); fContext->ref();
fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyProperties)); bool useDFFonts = !!(flags & kDFFonts_Flag);
fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyProperties,
useDFFonts));
fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties)); fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties));
fRenderTarget = NULL; fRenderTarget = NULL;

Просмотреть файл

@ -14,7 +14,7 @@ class SkSurface_Gpu : public SkSurface_Base {
public: public:
SK_DECLARE_INST_COUNT(SkSurface_Gpu) SK_DECLARE_INST_COUNT(SkSurface_Gpu)
SkSurface_Gpu(GrRenderTarget*, bool cached); SkSurface_Gpu(GrRenderTarget*, bool cached, TextRenderMode trm);
virtual ~SkSurface_Gpu(); virtual ~SkSurface_Gpu();
virtual SkCanvas* onNewCanvas() SK_OVERRIDE; virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
@ -33,9 +33,12 @@ private:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached) SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, TextRenderMode trm)
: INHERITED(renderTarget->width(), renderTarget->height()) { : INHERITED(renderTarget->width(), renderTarget->height()) {
fDevice = SkGpuDevice::Create(renderTarget, cached ? SkGpuDevice::kCached_Flag : 0); int flags = 0;
flags |= cached ? SkGpuDevice::kCached_Flag : 0;
flags |= (kDistanceField_TextRenderMode == trm) ? SkGpuDevice::kDFFonts_Flag : 0;
fDevice = SkGpuDevice::Create(renderTarget, flags);
if (kRGB_565_GrPixelConfig != renderTarget->config()) { if (kRGB_565_GrPixelConfig != renderTarget->config()) {
fDevice->clear(0x0); fDevice->clear(0x0);
@ -98,14 +101,15 @@ void SkSurface_Gpu::onDiscard() {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) { SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMode trm) {
if (NULL == target) { if (NULL == target) {
return NULL; return NULL;
} }
return SkNEW_ARGS(SkSurface_Gpu, (target, false)); return SkNEW_ARGS(SkSurface_Gpu, (target, false, trm));
} }
SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, int sampleCount) { SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, int sampleCount,
TextRenderMode trm) {
if (NULL == ctx) { if (NULL == ctx) {
return NULL; return NULL;
} }
@ -122,10 +126,11 @@ SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
return NULL; return NULL;
} }
return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false)); return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, trm));
} }
SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info, int sampleCount) { SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info,
int sampleCount, TextRenderMode trm) {
if (NULL == ctx) { if (NULL == ctx) {
return NULL; return NULL;
} }
@ -143,5 +148,5 @@ SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo&
return NULL; return NULL;
} }
return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true)); return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm));
} }