#include "GrIndexBuffer.h"
#include "GrTextStrike.h"
#include "GrTextStrike_impl.h"
+#include "SkDraw.h"
+#include "SkGpuDevice.h"
#include "SkPath.h"
#include "SkRTConf.h"
#include "SkStrokeRec.h"
"Dump the contents of the font cache before every purge.");
GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
- const GrPaint& grPaint,
- const SkPaint& skPaint)
- : GrTextContext(context, grPaint, skPaint) {
+ const SkDeviceProperties& properties)
+ : GrTextContext(context, properties) {
fStrike = NULL;
fCurrTexture = NULL;
fVertices = NULL;
fMaxVertices = 0;
-
- fTextRatio = fSkPaint.getTextSize()/kBaseDFFontSize;
-
- fSkPaint.setTextSize(SkIntToScalar(kBaseDFFontSize));
- fSkPaint.setLCDRenderText(false);
- fSkPaint.setAutohinted(false);
- fSkPaint.setSubpixelText(false);
}
GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
this->flushGlyphs();
}
+bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
+ return !paint.getRasterizer() && !paint.getMaskFilter() &&
+ paint.getStyle() == SkPaint::kFill_Style &&
+ !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix());
+}
+
static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
unsigned r = SkColorGetR(c);
unsigned g = SkColorGetG(c);
fCurrVertex += 4;
}
-void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength,
- SkScalar x, SkScalar y, SkGlyphCache* cache,
- GrFontScaler* fontScaler) {
+inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {
+ GrTextContext::init(paint, skPaint);
+
+ fStrike = NULL;
+
+ fCurrTexture = NULL;
+ fCurrVertex = 0;
+
+ fVertices = NULL;
+ fMaxVertices = 0;
+
+ fTextRatio = fSkPaint.getTextSize()/kBaseDFFontSize;
+
+ fSkPaint.setTextSize(SkIntToScalar(kBaseDFFontSize));
+ fSkPaint.setLCDRenderText(false);
+ fSkPaint.setAutohinted(false);
+ fSkPaint.setSubpixelText(false);
+}
+
+inline void GrDistanceFieldTextContext::finish() {
+ flushGlyphs();
+
+ GrTextContext::finish();
+}
+
+void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y) {
SkASSERT(byteLength == 0 || text != NULL);
- // nothing to draw
- if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
+ // nothing to draw or can't draw
+ if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/
+ || fSkPaint.getRasterizer()) {
return;
}
+ this->init(paint, skPaint);
+
SkScalar sizeRatio = fTextRatio;
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
+ SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL);
+ SkGlyphCache* cache = autoCache.getCache();
+ GrFontScaler* fontScaler = GetGrFontScaler(cache);
+
// need to measure first
// TODO - generate positions and pre-load cache as well?
const char* stop = text + byteLength;
fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale);
fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale);
}
+
+ this->finish();
}
-void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLength,
+void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
+ const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY,
- int scalarsPerPosition,
- SkGlyphCache* cache, GrFontScaler* fontScaler) {
+ int scalarsPerPosition) {
SkASSERT(byteLength == 0 || text != NULL);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
return;
}
+ this->init(paint, skPaint);
+
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
+ SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL);
+ SkGlyphCache* cache = autoCache.getCache();
+ GrFontScaler* fontScaler = GetGrFontScaler(cache);
+
const char* stop = text + byteLength;
if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) {
pos += scalarsPerPosition;
}
}
+
+ this->finish();
}