Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: src/core/SkDraw.cpp

Issue 16336024: add size limit for using glyphcache. above that, draw using paths (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkPaint.h ('k') | src/core/SkPaint.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkDraw.cpp
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index fc615ab0ef967e5ec03d6b5ded6397a191974e5f..f313c4b1192923ef70f8756b4f929bda7975de9f 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -31,6 +31,22 @@
#include "SkDrawProcs.h"
#include "SkMatrixUtils.h"
+bool SkDraw::ShouldDrawTextAsPaths(const SkPaint& paint, const SkMatrix& ctm) {
+ // we don't cache hairlines in the cache
+ if (SkPaint::kStroke_Style == paint.getStyle() &&
+ 0 == paint.getStrokeWidth()) {
+ return true;
+ }
+
+ // we don't cache perspective
+ if (ctm.hasPerspective()) {
+ return true;
+ }
+
+ SkMatrix textM;
+ return SkPaint::TooBigToUseCache(ctm, *paint.setTextMatrix(&textM));
+}
+
//#define TRACE_BITMAP_DRAWS
#define kBlitterStorageLongCount (sizeof(SkBitmapProcShader) >> 2)
@@ -1663,9 +1679,7 @@ void SkDraw::drawText(const char text[], size_t byteLength,
// SkScalarRec doesn't currently have a way of representing hairline stroke and
// will fill if its frame-width is 0.
- if (/*paint.isLinearText() ||*/
- (fMatrix->hasPerspective()) ||
- (0 == paint.getStrokeWidth() && SkPaint::kStroke_Style == paint.getStyle())) {
+ if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
this->drawText_asPaths(text, byteLength, x, y, paint);
return;
}
@@ -1839,6 +1853,50 @@ TextMapState::Proc TextMapState::pickProc(int scalarsPerPosition) {
//////////////////////////////////////////////////////////////////////////////
+void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
+ const SkScalar pos[], SkScalar constY,
+ int scalarsPerPosition,
+ const SkPaint& origPaint) const {
+ // setup our std paint, in hopes of getting hits in the cache
+ SkPaint paint(origPaint);
+ SkScalar matrixScale = paint.setupForAsPaths();
+
+ SkDraw draw(*this);
+
+ // Now modify our matrix to account for the canonical text size
+ SkMatrix matrix = *fMatrix;
+ matrix.preScale(matrixScale, matrixScale);
+ const SkScalar posScale = SkScalarInvert(matrixScale);
+
+ SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
+ SkAutoGlyphCache autoCache(paint, NULL, NULL);
+ SkGlyphCache* cache = autoCache.getCache();
+
+ const char* stop = text + byteLength;
+ AlignProc alignProc = pick_align_proc(paint.getTextAlign());
+ TextMapState tms(SkMatrix::I(), constY);
+ TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition);
+
+ while (text < stop) {
+ const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
+ if (glyph.fWidth) {
+ const SkPath* path = cache->findPath(glyph);
+ if (path) {
+ tmsProc(tms, pos);
+ SkIPoint fixedLoc;
+ alignProc(tms.fLoc, glyph, &fixedLoc);
+
+ SkMatrix localMatrix = matrix;
+ localMatrix.preTranslate(SkFixedToScalar(fixedLoc.fX) * posScale,
+ SkFixedToScalar(fixedLoc.fY) * posScale);
+ draw.fMatrix = &localMatrix;
+ draw.drawPath(*path, paint);
+ }
+ }
+ pos += scalarsPerPosition;
+ }
+}
+
void SkDraw::drawPosText(const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY,
int scalarsPerPosition, const SkPaint& paint) const {
@@ -1852,10 +1910,9 @@ void SkDraw::drawPosText(const char text[], size_t byteLength,
return;
}
- if (/*paint.isLinearText() ||*/
- (fMatrix->hasPerspective())) {
- // TODO !!!!
-// this->drawText_asPaths(text, byteLength, x, y, paint);
+ if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
+ this->drawPosText_asPaths(text, byteLength, pos, constY,
+ scalarsPerPosition, paint);
return;
}
« no previous file with comments | « include/core/SkPaint.h ('k') | src/core/SkPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698