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

Unified Diff: src/core/SkPaint.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
Index: src/core/SkPaint.cpp
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 9b6b88386339d24a41d3c2f2bd5a3db4115c0dc5..811cbeff9ba8adc15dc54f8ebcdf954db2c0ee18 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -425,6 +425,37 @@ SkAnnotation* SkPaint::setAnnotation(SkAnnotation* annotation) {
///////////////////////////////////////////////////////////////////////////////
+static SkScalar mag2(SkScalar x, SkScalar y) {
+ return x * x + y * y;
+}
+
+static bool tooBig(const SkMatrix& m, SkScalar ma2max) {
+ return mag2(m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY]) > ma2max
+ ||
+ mag2(m[SkMatrix::kMSkewX], m[SkMatrix::kMScaleY]) > ma2max;
+}
+
+bool SkPaint::TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM) {
+ SkASSERT(!ctm.hasPerspective());
+ SkASSERT(!textM.hasPerspective());
+
+ SkMatrix matrix;
+ matrix.setConcat(ctm, textM);
+ return tooBig(matrix, MaxCacheSize2());
+}
+
+bool SkPaint::tooBigToUseCache(const SkMatrix& ctm) const {
+ SkMatrix textM;
+ return TooBigToUseCache(ctm, *this->setTextMatrix(&textM));
+}
+
+bool SkPaint::tooBigToUseCache() const {
+ SkMatrix textM;
+ return tooBig(*this->setTextMatrix(&textM), MaxCacheSize2());
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
#include "SkGlyphCache.h"
#include "SkUtils.h"
@@ -1072,7 +1103,7 @@ SkScalar SkPaint::measureText(const void* textData, size_t length,
SkScalar scale = 0;
SkAutoRestorePaintTextSizeAndFrame restore(this);
- if (this->isLinearText()) {
+ if (this->isLinearText() || this->tooBigToUseCache()) {
scale = fTextSize / kCanonicalTextSizeForPaths;
// this gets restored by restore
((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths));
@@ -1287,7 +1318,7 @@ int SkPaint::getTextWidths(const void* textData, size_t byteLength,
SkAutoRestorePaintTextSizeAndFrame restore(this);
SkScalar scale = 0;
- if (this->isLinearText()) {
+ if (this->isLinearText() || this->tooBigToUseCache()) {
scale = fTextSize / kCanonicalTextSizeForPaths;
// this gets restored by restore
((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths));
« src/core/SkDraw.cpp ('K') | « src/core/SkDraw.cpp ('k') | src/core/SkScalerContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698