Make fInitialViewMatrix const in GrTextBlob
This is a big plumbing CL to pass the viewMatrix to the right places.
Change-Id: I6af67c6ba44c9c830ea52e8b50baafb88b40afc6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/257894
Auto-Submit: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index c746583..017df0f 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -425,7 +425,7 @@
// but we'd have to clear the subrun information
textBlobCache->remove(cacheBlob.get());
cacheBlob = textBlobCache->makeCachedBlob(
- glyphRunList, grStrikeCache, key, blurRec, color, forceW);
+ glyphRunList, grStrikeCache, key, blurRec, viewMatrix, color, forceW);
cacheBlob->generateFromGlyphRunList(
*context->priv().caps()->shaderCaps(), fOptions,
listPaint, viewMatrix, props,
@@ -435,7 +435,7 @@
if (CACHE_SANITY_CHECK) {
sk_sp<GrTextBlob> sanityBlob(textBlobCache->makeBlob(
- glyphRunList, grStrikeCache, color, forceW));
+ glyphRunList, grStrikeCache, viewMatrix, color, forceW));
sanityBlob->setupKey(key, blurRec, listPaint);
cacheBlob->generateFromGlyphRunList(
*context->priv().caps()->shaderCaps(), fOptions,
@@ -447,9 +447,10 @@
} else {
if (canCache) {
cacheBlob = textBlobCache->makeCachedBlob(
- glyphRunList, grStrikeCache, key, blurRec, color, forceW);
+ glyphRunList, grStrikeCache, key, blurRec, viewMatrix, color, forceW);
} else {
- cacheBlob = textBlobCache->makeBlob(glyphRunList, grStrikeCache, color, forceW);
+ cacheBlob = textBlobCache->makeBlob(
+ glyphRunList, grStrikeCache, viewMatrix, color, forceW);
}
cacheBlob->generateFromGlyphRunList(
*context->priv().caps()->shaderCaps(), fOptions, listPaint,
@@ -469,7 +470,7 @@
const SkGlyphRunList& glyphRunList,
SkGlyphRunListPainter* glyphPainter) {
const SkPaint& runPaint = glyphRunList.paint();
- this->initReusableBlob(SkPaintPriv::ComputeLuminanceColor(runPaint), viewMatrix);
+ this->initReusableBlob(SkPaintPriv::ComputeLuminanceColor(runPaint));
glyphPainter->processGlyphRunList(glyphRunList,
viewMatrix,
@@ -702,7 +703,8 @@
auto glyphRunList = builder.useGlyphRunList();
sk_sp<GrTextBlob> blob;
if (!glyphRunList.empty()) {
- blob = direct->priv().getTextBlobCache()->makeBlob(glyphRunList, strikeCache, color, false);
+ blob = direct->priv().getTextBlobCache()->makeBlob(
+ glyphRunList, strikeCache, viewMatrix, color, false);
blob->generateFromGlyphRunList(
*context->priv().caps()->shaderCaps(), textContext->fOptions,
skPaint, viewMatrix, surfaceProps,
diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp
index 5a07500..412b671 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -25,6 +25,7 @@
sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount,
GrStrikeCache* strikeCache,
+ const SkMatrix& viewMatrix,
SkPoint origin,
GrColor color,
bool forceWForDistanceFields) {
@@ -44,7 +45,7 @@
}
sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{
- size, strikeCache, origin, color, forceWForDistanceFields}};
+ size, strikeCache, viewMatrix, origin, color, forceWForDistanceFields}};
// setup offsets for vertices / glyphs
blob->fVertices = SkTAddOffset<char>(blob.get(), vertex);
@@ -352,13 +353,24 @@
}
}
+static SkMatrix make_inverse(const SkMatrix& matrix) {
+ SkMatrix inverseMatrix;
+ if (!matrix.invert(&inverseMatrix)) {
+ inverseMatrix = SkMatrix::I();
+ }
+ return inverseMatrix;
+}
+
GrTextBlob::GrTextBlob(size_t size,
GrStrikeCache* strikeCache,
+ const SkMatrix& viewMatrix,
SkPoint origin,
GrColor color,
bool forceWForDistanceFields)
: fSize{size}
, fStrikeCache{strikeCache}
+ , fInitialViewMatrix{viewMatrix}
+ , fInitialViewMatrixInverse{make_inverse(viewMatrix)}
, fInitialOrigin{origin}
, fForceWForDistanceFields{forceWForDistanceFields}
, fColor{color} { }
diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h
index c4cd010..51fda8f 100644
--- a/src/gpu/text/GrTextBlob.h
+++ b/src/gpu/text/GrTextBlob.h
@@ -70,6 +70,7 @@
// adding SubRuns.
static sk_sp<GrTextBlob> Make(int glyphCount,
GrStrikeCache* strikeCache,
+ const SkMatrix& viewMatrix,
SkPoint origin,
GrColor color,
bool forceWForDistanceFields);
@@ -180,16 +181,9 @@
// This function will only be called when we are generating a blob from scratch.
// The color here is the GrPaint color, and it is used to determine whether we
// have to regenerate LCD text blobs.
- // We use this color vs the SkPaint color because it has the color filter applied. We record the
- // initial view matrix and initial offsets(x,y), because we record vertex bounds relative to
- // these numbers. When blobs are reused with new matrices, we need to return to source space so
- // we can update the vertex bounds appropriately.
- void initReusableBlob(SkColor luminanceColor, const SkMatrix& viewMatrix) {
+ // We use this color vs the SkPaint color because it has the color filter applied.
+ void initReusableBlob(SkColor luminanceColor) {
fLuminanceColor = luminanceColor;
- fInitialViewMatrix = viewMatrix;
- if (!viewMatrix.invert(&fInitialViewMatrixInverse)) {
- fInitialViewMatrixInverse = SkMatrix::I();
- }
}
const Key& key() const { return fKey; }
@@ -354,6 +348,7 @@
private:
GrTextBlob(size_t size,
GrStrikeCache* strikeCache,
+ const SkMatrix& viewMatrix,
SkPoint origin,
GrColor color,
bool forceWForDistanceFields);
@@ -398,6 +393,13 @@
// The GrRecordingContext also owns the GrTextBlob cache which owns this GrTextBlob.
GrStrikeCache* const fStrikeCache;
+ // The initial view matrix and its inverse. This is used for moving additional draws of this
+ // same text blob. We record the initial view matrix and initial offsets(x,y), because we
+ // record vertex bounds relative to these numbers. When blobs are reused with new matrices,
+ // we need to return to source space so we can update the vertex bounds appropriately.
+ const SkMatrix fInitialViewMatrix;
+ const SkMatrix fInitialViewMatrixInverse;
+
// Initial position of this blob. Used for calculating position differences when reusing this
// blob.
const SkPoint fInitialOrigin;
@@ -423,8 +425,6 @@
SkMaskFilterBase::BlurRec fBlurRec;
StrokeInfo fStrokeInfo;
Key fKey;
- SkMatrix fInitialViewMatrix;
- SkMatrix fInitialViewMatrixInverse;
SkColor fLuminanceColor;
diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h
index f45e897..1484cee 100644
--- a/src/gpu/text/GrTextBlobCache.h
+++ b/src/gpu/text/GrTextBlobCache.h
@@ -35,20 +35,27 @@
sk_sp<GrTextBlob> makeBlob(const SkGlyphRunList& glyphRunList,
GrStrikeCache* strikeCache,
+ const SkMatrix& viewMatrix,
GrColor color,
bool forceW) {
return GrTextBlob::Make(
- glyphRunList.totalGlyphCount(), strikeCache, glyphRunList.origin(), color, forceW);
+ glyphRunList.totalGlyphCount(),
+ strikeCache,
+ viewMatrix,
+ glyphRunList.origin(),
+ color,
+ forceW);
}
sk_sp<GrTextBlob> makeCachedBlob(const SkGlyphRunList& glyphRunList,
GrStrikeCache* strikeCache,
const GrTextBlob::Key& key,
const SkMaskFilterBase::BlurRec& blurRec,
+ const SkMatrix& viewMatrix,
GrColor color,
bool forceW) {
sk_sp<GrTextBlob> cacheBlob(
- this->makeBlob(glyphRunList, strikeCache, color, forceW));
+ this->makeBlob(glyphRunList, strikeCache, viewMatrix, color, forceW));
cacheBlob->setupKey(key, blurRec, glyphRunList.paint());
this->add(cacheBlob);
glyphRunList.temporaryShuntBlobNotifyAddedToCache(fUniqueID);