Add fallback code for TextContexts that don't support all features

BUG=skia:2018

NOTRY=true
R=bsalomon@google.com, reed@google.com

Author: jvanverth@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13236 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-01-30 15:22:54 +00:00
parent 8fe722845a
commit 9f94b9104a
6 changed files with 55 additions and 13 deletions

View File

@ -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*);

View File

@ -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&,

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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);
}
}