fix some small bugs with GrAtlasTextContext
BUG=skia:
Review URL: https://codereview.chromium.org/1098093003
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index c1a46fe..5f4f916 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -51,6 +51,7 @@
static const int kMediumDFFontSize = 72;
static const int kMediumDFFontLimit = 72;
static const int kLargeDFFontSize = 162;
+static const int kLargeDFFontLimit = 2 * kLargeDFFontSize;
SkDEBUGCODE(static const int kExpectedDistanceAdjustTableSize = 8;)
static const int kDistanceAdjustLumShift = 5;
@@ -326,8 +327,7 @@
#endif
(*outTransX) = transX;
(*outTransY) = transY;
- } else {
- SkASSERT(blob.hasDistanceField());
+ } else if (blob.hasDistanceField()) {
// A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
// distance field being generated, so we have to regenerate in those cases
SkScalar newMaxScale = viewMatrix.getMaxScale();
@@ -340,6 +340,9 @@
(*outTransX) = x - blob.fX;
(*outTransY) = y - blob.fY;
}
+ // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
+ // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
+ // the blob anyways at flush time, so no need to regenerate explicitly
return false;
}
@@ -441,7 +444,7 @@
SkScalar scaledTextSize = maxScale*skPaint.getTextSize();
// Hinted text looks far better at small resolutions
// Scaling up beyond 2x yields undesireable artifacts
- if (scaledTextSize < kMinDFFontSize || scaledTextSize > 2 * kLargeDFFontSize) {
+ if (scaledTextSize < kMinDFFontSize || scaledTextSize > kLargeDFFontLimit) {
return false;
}
@@ -611,17 +614,17 @@
SkScalar dfMaskScaleCeil;
if (scaledTextSize <= kSmallDFFontLimit) {
dfMaskScaleFloor = kMinDFFontSize;
- dfMaskScaleCeil = kMediumDFFontLimit;
+ dfMaskScaleCeil = kSmallDFFontLimit;
*textRatio = textSize / kSmallDFFontSize;
skPaint->setTextSize(SkIntToScalar(kSmallDFFontSize));
} else if (scaledTextSize <= kMediumDFFontLimit) {
- dfMaskScaleFloor = kMediumDFFontLimit;
- dfMaskScaleCeil = kLargeDFFontSize;
+ dfMaskScaleFloor = kSmallDFFontLimit;
+ dfMaskScaleCeil = kMediumDFFontLimit;
*textRatio = textSize / kMediumDFFontSize;
skPaint->setTextSize(SkIntToScalar(kMediumDFFontSize));
} else {
- dfMaskScaleFloor = kLargeDFFontSize;
- dfMaskScaleCeil = 2 * kLargeDFFontSize;
+ dfMaskScaleFloor = kMediumDFFontLimit;
+ dfMaskScaleCeil = kLargeDFFontLimit;
*textRatio = textSize / kLargeDFFontSize;
skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize));
}
@@ -633,6 +636,7 @@
// we look at the delta in scale between the new viewmatrix and the old viewmatrix, and test
// against these values to decide if we can reuse or not(ie, will a given scale change our mip
// level)
+ SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScaleCeil);
blob->fMaxMinScale = SkMaxScalar(dfMaskScaleFloor / scaledTextSize, blob->fMaxMinScale);
blob->fMinMaxScale = SkMinScalar(dfMaskScaleCeil / scaledTextSize, blob->fMinMaxScale);
diff --git a/src/gpu/GrAtlasTextContext.h b/src/gpu/GrAtlasTextContext.h
index d294126..c0975b9 100644
--- a/src/gpu/GrAtlasTextContext.h
+++ b/src/gpu/GrAtlasTextContext.h
@@ -248,7 +248,7 @@
uint8_t fTextType;
BitmapTextBlob()
- : fMaxMinScale(SK_ScalarMax)
+ : fMaxMinScale(-SK_ScalarMax)
, fMinMaxScale(SK_ScalarMax)
, fTextType(0) {}