relocate GrTextBlob creation to GrTextBlobCache
Move the GrTextBlob creation code to GrTextBlobCache allowing
more cache calls to be private.
Change-Id: I9ecb732c066ef7dadf8bc478a8b4d3dea8c292a9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/482697
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp
index e7cca26..1e0f921 100644
--- a/src/gpu/text/GrTextBlobCache.cpp
+++ b/src/gpu/text/GrTextBlobCache.cpp
@@ -7,6 +7,8 @@
#include "src/gpu/text/GrTextBlobCache.h"
+#include "src/gpu/v1/SurfaceDrawContext_v1.h"
+
DECLARE_SKMESSAGEBUS_MESSAGE(GrTextBlobCache::PurgeBlobMessage, uint32_t, true)
// This function is captured by the above macro using implementations from SkMessageBus.h
@@ -20,6 +22,52 @@
, fMessageBusID(messageBusID)
, fPurgeBlobInbox(messageBusID) { }
+void GrTextBlobCache::drawGlyphRunList(const GrClip* clip,
+ const SkMatrixProvider& viewMatrix,
+ const SkGlyphRunList& glyphRunList,
+ const SkPaint& paint,
+ skgpu::v1::SurfaceDrawContext* sdc) {
+
+ SkMatrix positionMatrix{viewMatrix.localToDevice()};
+ positionMatrix.preTranslate(glyphRunList.origin().x(), glyphRunList.origin().y());
+
+ GrSDFTControl control =
+ sdc->recordingContext()->priv().getSDFTControl(
+ sdc->surfaceProps().isUseDeviceIndependentFonts());
+
+ auto [canCache, key] = GrTextBlob::Key::Make(glyphRunList,
+ paint,
+ sdc->surfaceProps(),
+ sdc->colorInfo(),
+ positionMatrix,
+ control);
+ sk_sp<GrTextBlob> blob;
+ if (canCache) {
+ blob = this->find(key);
+ }
+
+ if (blob == nullptr || !blob->canReuse(paint, positionMatrix)) {
+ if (blob != nullptr) {
+ // We have to remake the blob because changes may invalidate our masks.
+ this->remove(blob.get());
+ }
+
+ blob = GrTextBlob::Make(
+ glyphRunList, paint, positionMatrix, control, sdc->glyphRunPainter());
+
+ if (canCache) {
+ blob->addKey(key);
+ // The blob may already have been created on a different thread. Use the first one
+ // that was there.
+ blob = this->addOrReturnExisting(glyphRunList, blob);
+ }
+ }
+
+ for (const GrSubRun& subRun : blob->subRunList()) {
+ subRun.draw(clip, viewMatrix, glyphRunList.origin(), paint, sdc);
+ }
+}
+
sk_sp<GrTextBlob> GrTextBlobCache::addOrReturnExisting(
const SkGlyphRunList& glyphRunList, sk_sp<GrTextBlob> blob) {
SkAutoSpinlock lock{fSpinLock};
diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h
index 8c7f466..021ce9f 100644
--- a/src/gpu/text/GrTextBlobCache.h
+++ b/src/gpu/text/GrTextBlobCache.h
@@ -22,13 +22,11 @@
public:
GrTextBlobCache(uint32_t messageBusID);
- // If not already in the cache, then add it else, return the text blob from the cache.
- sk_sp<GrTextBlob> addOrReturnExisting(
- const SkGlyphRunList& glyphRunList, sk_sp<GrTextBlob> blob) SK_EXCLUDES(fSpinLock);
-
- sk_sp<GrTextBlob> find(const GrTextBlob::Key& key) SK_EXCLUDES(fSpinLock);
-
- void remove(GrTextBlob* blob) SK_EXCLUDES(fSpinLock);
+ void drawGlyphRunList(const GrClip* clip,
+ const SkMatrixProvider& viewMatrix,
+ const SkGlyphRunList& glyphRunList,
+ const SkPaint& paint,
+ skgpu::v1::SurfaceDrawContext* sdc);
void freeAll() SK_EXCLUDES(fSpinLock);
@@ -72,6 +70,14 @@
SkSTArray<1, sk_sp<GrTextBlob>> fBlobs;
};
+ // If not already in the cache, then add it else, return the text blob from the cache.
+ sk_sp<GrTextBlob> addOrReturnExisting(
+ const SkGlyphRunList& glyphRunList, sk_sp<GrTextBlob> blob) SK_EXCLUDES(fSpinLock);
+
+ sk_sp<GrTextBlob> find(const GrTextBlob::Key& key) SK_EXCLUDES(fSpinLock);
+
+ void remove(GrTextBlob* blob) SK_EXCLUDES(fSpinLock);
+
void internalPurgeStaleBlobs() SK_REQUIRES(fSpinLock);
sk_sp<GrTextBlob> internalAdd(sk_sp<GrTextBlob> blob) SK_REQUIRES(fSpinLock);
diff --git a/src/gpu/v1/SurfaceDrawContext.cpp b/src/gpu/v1/SurfaceDrawContext.cpp
index a6a1e50..99c9ac6 100644
--- a/src/gpu/v1/SurfaceDrawContext.cpp
+++ b/src/gpu/v1/SurfaceDrawContext.cpp
@@ -346,53 +346,6 @@
}
}
-void SurfaceDrawContext::drawGlyphRunListWithCache(const GrClip* clip,
- const SkMatrixProvider& viewMatrix,
- const SkGlyphRunList& glyphRunList,
- const SkPaint& paint) {
- SkMatrix positionMatrix{viewMatrix.localToDevice()};
- positionMatrix.preTranslate(glyphRunList.origin().x(), glyphRunList.origin().y());
-
- GrSDFTControl control =
- this->recordingContext()->priv().getSDFTControl(
- this->surfaceProps().isUseDeviceIndependentFonts());
-
- auto [canCache, key] = GrTextBlob::Key::Make(glyphRunList,
- paint,
- fSurfaceProps,
- this->colorInfo(),
- positionMatrix,
- control);
-
- sk_sp<GrTextBlob> blob;
- GrTextBlobCache* textBlobCache = fContext->priv().getTextBlobCache();
- if (canCache) {
- blob = textBlobCache->find(key);
- }
-
- if (blob == nullptr || !blob->canReuse(paint, positionMatrix)) {
- if (blob != nullptr) {
- // We have to remake the blob because changes may invalidate our masks.
- // TODO we could probably get away with reuse most of the time if the pointer is unique,
- // but we'd have to clear the SubRun information
- textBlobCache->remove(blob.get());
- }
-
- blob = GrTextBlob::Make(glyphRunList, paint, positionMatrix, control, &fGlyphPainter);
-
- if (canCache) {
- blob->addKey(key);
- // The blob may already have been created on a different thread. Use the first one
- // that was there.
- blob = textBlobCache->addOrReturnExisting(glyphRunList, blob);
- }
- }
-
- for (const GrSubRun& subRun : blob->subRunList()) {
- subRun.draw(clip, viewMatrix, glyphRunList.origin(), paint, this);
- }
-}
-
// choose to use the GrTextBlob cache or not.
bool gGrDrawTextNoCache = false;
void SurfaceDrawContext::drawGlyphRunList(const GrClip* clip,
@@ -417,7 +370,8 @@
// build the sub run directly and place it in the op.
this->drawGlyphRunListNoCache(clip, viewMatrix, glyphRunList, paint);
} else {
- this->drawGlyphRunListWithCache(clip, viewMatrix, glyphRunList, paint);
+ GrTextBlobCache* textBlobCache = fContext->priv().getTextBlobCache();
+ textBlobCache->drawGlyphRunList(clip, viewMatrix, glyphRunList, paint, this);
}
}
diff --git a/src/gpu/v1/SurfaceDrawContext_v1.h b/src/gpu/v1/SurfaceDrawContext_v1.h
index 1c8042f..48b79bf 100644
--- a/src/gpu/v1/SurfaceDrawContext_v1.h
+++ b/src/gpu/v1/SurfaceDrawContext_v1.h
@@ -484,17 +484,6 @@
* @param viewMatrix transformationMatrix
* @param glyphRunList text, text positions, and paint.
*/
- void drawGlyphRunListWithCache(const GrClip*,
- const SkMatrixProvider& viewMatrix,
- const SkGlyphRunList& glyphRunList,
- const SkPaint& paint);
-
- /**
- * Draw the text specified by the SkGlyphRunList.
- *
- * @param viewMatrix transformationMatrix
- * @param glyphRunList text, text positions, and paint.
- */
void drawGlyphRunListNoCache(const GrClip*,
const SkMatrixProvider& viewMatrix,
const SkGlyphRunList& glyphRunList,