diff options
-rwxr-xr-x | include/gpu/GrBitmapTextContext.h | 9 | ||||
-rwxr-xr-x | include/gpu/GrDistanceFieldTextContext.h | 2 | ||||
-rw-r--r-- | include/gpu/GrTextContext.h | 7 | ||||
-rwxr-xr-x | src/gpu/GrBitmapTextContext.cpp | 5 | ||||
-rwxr-xr-x | src/gpu/GrDistanceFieldTextContext.cpp | 7 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 38 |
6 files changed, 55 insertions, 13 deletions
diff --git a/include/gpu/GrBitmapTextContext.h b/include/gpu/GrBitmapTextContext.h index c66f8a8564..6550e3c079 100755 --- a/include/gpu/GrBitmapTextContext.h +++ b/include/gpu/GrBitmapTextContext.h @@ -17,16 +17,17 @@ class GrTextStrike; */ class GrBitmapTextContext : public GrTextContext { public: + GrBitmapTextContext(GrContext*, const GrPaint&, const SkPaint&, const SkDeviceProperties&); + virtual ~GrBitmapTextContext(); + virtual void drawText(const char text[], size_t byteLength, SkScalar x, SkScalar y) SK_OVERRIDE; virtual void drawPosText(const char text[], size_t byteLength, const SkScalar pos[], SkScalar constY, int scalarsPerPosition) SK_OVERRIDE; + static bool CanDraw(const SkPaint& paint, const SkMatrix& ctm); + private: - GrBitmapTextContext(GrContext*, const GrPaint&, const SkPaint&, const SkDeviceProperties&); - virtual ~GrBitmapTextContext(); - friend class GrTTextContextManager<GrBitmapTextContext>; - GrTextStrike* fStrike; void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, GrFontScaler*); diff --git a/include/gpu/GrDistanceFieldTextContext.h b/include/gpu/GrDistanceFieldTextContext.h index 172342a0f0..8b94038b67 100755 --- a/include/gpu/GrDistanceFieldTextContext.h +++ b/include/gpu/GrDistanceFieldTextContext.h @@ -21,6 +21,8 @@ public: virtual void drawPosText(const char text[], size_t byteLength, const SkScalar pos[], SkScalar constY, int scalarsPerPosition) SK_OVERRIDE; + + static bool CanDraw(const SkPaint& paint, const SkMatrix& ctm); private: GrDistanceFieldTextContext(GrContext*, const GrPaint&, const SkPaint&, diff --git a/include/gpu/GrTextContext.h b/include/gpu/GrTextContext.h index 273e0947b1..c572d0d016 100644 --- a/include/gpu/GrTextContext.h +++ b/include/gpu/GrTextContext.h @@ -29,7 +29,7 @@ public: virtual void drawPosText(const char text[], size_t byteLength, const SkScalar pos[], SkScalar constY, int scalarsPerPosition) = 0; - + protected: GrTextContext(GrContext*, const GrPaint&, const SkPaint&, const SkDeviceProperties&); @@ -55,6 +55,7 @@ public: virtual ~GrTextContextManager() {} virtual GrTextContext* create(GrContext* grContext, const GrPaint& grPaint, const SkPaint& skPaint, const SkDeviceProperties& props) = 0; + virtual bool canDraw(const SkPaint& paint, const SkMatrix& ctm) = 0; }; template <class TextContextClass> @@ -110,6 +111,10 @@ public: return obj; } + virtual bool canDraw(const SkPaint& paint, const SkMatrix& ctm) SK_OVERRIDE { + return TextContextClass::CanDraw(paint, ctm); + } + private: void recycle(GrTextContext* textContext) { SkASSERT((void*)textContext == fAllocation); diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp index ff81b2d2c2..488aa137e9 100755 --- a/src/gpu/GrBitmapTextContext.cpp +++ b/src/gpu/GrBitmapTextContext.cpp @@ -19,6 +19,7 @@ #include "effects/GrCustomCoordsTextureEffect.h" #include "SkAutoKern.h" +#include "SkDraw.h" #include "SkGlyphCache.h" #include "SkGpuDevice.h" #include "SkGr.h" @@ -28,6 +29,10 @@ static const int kGlyphCoordsAttributeIndex = 1; SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, "Dump the contents of the font cache before every purge."); +bool GrBitmapTextContext::CanDraw(const SkPaint& paint, const SkMatrix& ctm) { + return !SkDraw::ShouldDrawTextAsPaths(paint, ctm); +} + GrBitmapTextContext::GrBitmapTextContext(GrContext* context, const GrPaint& grPaint, const SkPaint& skPaint, diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index 505ee39539..52b714ce25 100755 --- a/src/gpu/GrDistanceFieldTextContext.cpp +++ b/src/gpu/GrDistanceFieldTextContext.cpp @@ -13,6 +13,7 @@ #include "GrIndexBuffer.h" #include "GrTextStrike.h" #include "GrTextStrike_impl.h" +#include "SkDraw.h" #include "SkGpuDevice.h" #include "SkPath.h" #include "SkRTConf.h" @@ -26,6 +27,12 @@ static const int kBaseDFFontSize = 32; SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, "Dump the contents of the font cache before every purge."); +bool GrDistanceFieldTextContext::CanDraw(const SkPaint& paint, const SkMatrix& ctm) { + return !paint.getRasterizer() && !paint.getMaskFilter() && + paint.getStyle() == SkPaint::kFill_Style && + !SkDraw::ShouldDrawTextAsPaths(paint, ctm); +} + GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, const GrPaint& grPaint, const SkPaint& skPaint, diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index df302c4736..f951a1555e 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1771,9 +1771,7 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text, const SkPaint& paint) { CHECK_SHOULD_DRAW(draw, false); - if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { - draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); - } else { + if (fTextContextManager->canDraw(paint, fContext->getMatrix())) { GrPaint grPaint; if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { return; @@ -1785,6 +1783,20 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text, grPaint, paint, this->getDeviceProperties())); ctx->drawText((const char *)text, byteLength, x, y); + } else if (GrBitmapTextContext::CanDraw(paint, fContext->getMatrix())) { + GrPaint grPaint; + if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { + return; + } + + SkDEBUGCODE(this->validate();) + + GrBitmapTextContext textContext(this->context(), grPaint, paint, + this->getDeviceProperties()); + textContext.drawText((const char *)text, byteLength, x, y); + } else { + // this guy will just call our drawPath() + draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); } } @@ -1794,11 +1806,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, const SkPaint& paint) { CHECK_SHOULD_DRAW(draw, false); - if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { - // this guy will just call our drawPath() - draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, - scalarsPerPos, paint); - } else { + if (fTextContextManager->canDraw(paint, fContext->getMatrix())) { GrPaint grPaint; if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { return; @@ -1810,6 +1818,20 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, grPaint, paint, this->getDeviceProperties())); ctx->drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos); + } else if (GrBitmapTextContext::CanDraw(paint, fContext->getMatrix())) { + GrPaint grPaint; + if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { + return; + } + + SkDEBUGCODE(this->validate();) + + GrBitmapTextContext textContext(this->context(), grPaint, paint, + this->getDeviceProperties()); + textContext.drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos); + } else { + draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, + scalarsPerPos, paint); } } |