From de2ce568cc67b8d352b9399d2222dd5ba581ac8a Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 2 May 2014 12:39:41 +0000 Subject: 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/src@14525 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gpu/GrDistanceFieldTextContext.cpp | 14 +++++++------- gpu/GrDistanceFieldTextContext.h | 3 ++- gpu/SkGpuDevice.cpp | 4 +++- image/SkSurface_Gpu.cpp | 23 ++++++++++++++--------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/gpu/GrDistanceFieldTextContext.cpp b/gpu/GrDistanceFieldTextContext.cpp index 238bcca4..512420eb 100755 --- a/gpu/GrDistanceFieldTextContext.cpp +++ b/gpu/GrDistanceFieldTextContext.cpp @@ -33,15 +33,15 @@ static const int kLargeDFFontSize = 128; SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, "Dump the contents of the font cache before every purge."); +GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, + const SkDeviceProperties& properties, + bool enable) + : GrTextContext(context, properties) { #if SK_FORCE_DISTANCEFIELD_FONTS -static const bool kForceDistanceFieldFonts = true; + fEnableDFRendering = true; #else -static const bool kForceDistanceFieldFonts = false; + fEnableDFRendering = enable; #endif - -GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, - const SkDeviceProperties& properties) - : GrTextContext(context, properties) { fStrike = NULL; fCurrTexture = NULL; @@ -56,7 +56,7 @@ GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { } bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { - if (!kForceDistanceFieldFonts && !paint.isDistanceFieldTextTEMP()) { + if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) { return false; } diff --git a/gpu/GrDistanceFieldTextContext.h b/gpu/GrDistanceFieldTextContext.h index 58c0824e..3dfffd1c 100644 --- a/gpu/GrDistanceFieldTextContext.h +++ b/gpu/GrDistanceFieldTextContext.h @@ -17,7 +17,7 @@ class GrTextStrike; */ class GrDistanceFieldTextContext : public GrTextContext { public: - GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&); + GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable); virtual ~GrDistanceFieldTextContext(); virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength, @@ -33,6 +33,7 @@ private: GrTextStrike* fStrike; SkScalar fTextRatio; bool fUseLCDText; + bool fEnableDFRendering; void init(const GrPaint&, const SkPaint&); void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*); diff --git a/gpu/SkGpuDevice.cpp b/gpu/SkGpuDevice.cpp index 60b4e7c4..714a6da6 100644 --- a/gpu/SkGpuDevice.cpp +++ b/gpu/SkGpuDevice.cpp @@ -190,7 +190,9 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context, fContext = context; 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)); fRenderTarget = NULL; diff --git a/image/SkSurface_Gpu.cpp b/image/SkSurface_Gpu.cpp index 6f018bf2..a34b7743 100644 --- a/image/SkSurface_Gpu.cpp +++ b/image/SkSurface_Gpu.cpp @@ -14,7 +14,7 @@ class SkSurface_Gpu : public SkSurface_Base { public: SK_DECLARE_INST_COUNT(SkSurface_Gpu) - SkSurface_Gpu(GrRenderTarget*, bool cached); + SkSurface_Gpu(GrRenderTarget*, bool cached, TextRenderMode trm); virtual ~SkSurface_Gpu(); 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()) { - 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()) { 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) { 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) { return NULL; } @@ -122,10 +126,11 @@ SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i 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) { return NULL; } @@ -143,5 +148,5 @@ SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& return NULL; } - return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true)); + return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm)); } -- cgit v1.2.3