Have CategorizeGlyphRunList take a strike cache as a param

Change categorizeGlyphRunList to be static, and take the
strike cache as a parameter. This will simplify hoisting this
to the SkGlyphRunListBuilder.

Change-Id: I34b7d71aedc0dc67ae256d0121999fca2981a89f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541744
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-05-18 16:52:16 -04:00 committed by SkCQ
parent 9b59fe655c
commit f774e6c90b
14 changed files with 51 additions and 66 deletions

View File

@ -53,7 +53,6 @@ class DirectMaskGlyphVertexFillBenchmark : public Benchmark {
auto glyphRunList = builder.textToGlyphRunList(font, paint, gText, len, {100, 100});
SkASSERT(!glyphRunList.empty());
auto device = SkTestCanvas<FillBench>::GetDevice(canvas);
SkGlyphRunListPainter painter{SkStrikeCache::GlobalStrikeCache()};
SkMatrix drawMatrix = view;
const SkPoint drawOrigin = glyphRunList.origin();
drawMatrix.preTranslate(drawOrigin.x(), drawOrigin.y());
@ -61,7 +60,7 @@ class DirectMaskGlyphVertexFillBenchmark : public Benchmark {
paint,
drawMatrix,
device->strikeDeviceInfo(),
&painter);
SkStrikeCache::GlobalStrikeCache());
const GrAtlasSubRun* subRun = fBlob->testingOnlyFirstSubRun();
SkASSERT(subRun);

View File

@ -4682,7 +4682,6 @@ generated_cc_atom(
srcs = ["SkStrikeCache.cpp"],
visibility = ["//:__subpackages__"],
deps = [
":SkGlyphRunPainter_hdr",
":SkScalerCache_hdr",
":SkStrikeCache_hdr",
"//include/core:SkGraphics_hdr",

View File

@ -788,9 +788,7 @@ public:
sk_sp<SkColorSpace> colorSpace, sktext::gpu::SDFTControl SDFTControl)
: SkNoPixelsDevice(SkIRect::MakeSize(dimensions), props, std::move(colorSpace))
, fStrikeServerImpl(server)
, fSDFTControl(SDFTControl)
, fPainter{fStrikeServerImpl}
, fConvertPainter{SkStrikeCache::GlobalStrikeCache()} {
, fSDFTControl(SDFTControl) {
SkASSERT(fStrikeServerImpl != nullptr);
}
@ -811,12 +809,13 @@ protected:
const SkPaint& drawingPaint) override {
SkMatrix drawMatrix = this->localToDevice();
drawMatrix.preTranslate(glyphRunList.origin().x(), glyphRunList.origin().y());
fPainter.categorizeGlyphRunList(nullptr,
glyphRunList,
drawMatrix,
drawingPaint,
this->strikeDeviceInfo(),
"Cache Diff");
SkGlyphRunListPainter::CategorizeGlyphRunList(nullptr,
glyphRunList,
drawMatrix,
drawingPaint,
this->strikeDeviceInfo(),
fStrikeServerImpl,
"Cache Diff");
}
sk_sp<GrSlug> convertGlyphRunListToSlug(const SkGlyphRunList& glyphRunList,
@ -831,12 +830,13 @@ protected:
// Use the lightweight strike cache provided by SkRemoteGlyphCache through fPainter to do
// the analysis.
fPainter.categorizeGlyphRunList(nullptr,
glyphRunList,
positionMatrix,
drawingPaint,
this->strikeDeviceInfo(),
"Convert Slug Analysis");
SkGlyphRunListPainter::CategorizeGlyphRunList(nullptr,
glyphRunList,
positionMatrix,
drawingPaint,
this->strikeDeviceInfo(),
fStrikeServerImpl,
"Convert Slug Analysis");
// Use the glyph strike cache to get actual glyph information.
return skgpu::v1::MakeSlug(this->localToDevice(),
@ -844,14 +844,12 @@ protected:
initialPaint,
drawingPaint,
this->strikeDeviceInfo(),
&fConvertPainter);
SkStrikeCache::GlobalStrikeCache());
}
private:
SkStrikeServerImpl* const fStrikeServerImpl;
const sktext::gpu::SDFTControl fSDFTControl;
SkGlyphRunListPainter fPainter;
SkGlyphRunListPainter fConvertPainter;
};
#endif // SK_SUPPORT_GPU

View File

@ -251,9 +251,6 @@ void SkGlyphRunListPainterCPU::drawForBitmapDevice(
// -- SkGlyphRunListPainter ------------------------------------------------------------------------
#if SK_SUPPORT_GPU
SkGlyphRunListPainter::SkGlyphRunListPainter(SkStrikeForGPUCacheInterface* strikeCache)
: fStrikeCache{strikeCache} {}
// Use the following in your args.gn to dump telemetry for diagnosing chrome Renderer/GPU
// differences.
// extra_cflags = ["-D", "SK_TRACE_GLYPH_RUN_PROCESS"]
@ -264,11 +261,12 @@ namespace {
static const constexpr bool kTrace = false;
#endif
}
void SkGlyphRunListPainter::categorizeGlyphRunList(SkGlyphRunPainterInterface* process,
void SkGlyphRunListPainter::CategorizeGlyphRunList(SkGlyphRunPainterInterface* process,
const SkGlyphRunList& glyphRunList,
const SkMatrix& positionMatrix,
const SkPaint& runPaint,
SkStrikeDeviceInfo strikeDeviceInfo,
SkStrikeForGPUCacheInterface* strikeCache,
const char* tag) {
[[maybe_unused]] SkString msg;
if constexpr (kTrace) {
@ -318,7 +316,7 @@ void SkGlyphRunListPainter::categorizeGlyphRunList(SkGlyphRunPainterInterface* p
}
if (!SkScalarNearlyZero(strikeToSourceScale)) {
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(strikeCache);
accepted->startSource(rejected->source());
if constexpr (kTrace) {
@ -351,7 +349,7 @@ void SkGlyphRunListPainter::categorizeGlyphRunList(SkGlyphRunPainterInterface* p
msg.appendf(" Mask case:\n%s", strikeSpec.dump().c_str());
}
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(strikeCache);
accepted->startDevicePositioning(
rejected->source(), positionMatrix, strike->roundingSpec());
@ -385,7 +383,7 @@ void SkGlyphRunListPainter::categorizeGlyphRunList(SkGlyphRunPainterInterface* p
}
if (!SkScalarNearlyZero(strikeToSourceScale)) {
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(strikeCache);
accepted->startSource(rejected->source());
if constexpr (kTrace) {
@ -416,7 +414,7 @@ void SkGlyphRunListPainter::categorizeGlyphRunList(SkGlyphRunPainterInterface* p
#endif
if (!SkScalarNearlyZero(strikeToSourceScale)) {
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(strikeCache);
accepted->startSource(rejected->source());
if constexpr (kTrace) {
@ -449,7 +447,7 @@ void SkGlyphRunListPainter::categorizeGlyphRunList(SkGlyphRunPainterInterface* p
}
if (!SkScalarNearlyZero(strikeToSourceScale)) {
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(strikeCache);
accepted->startSource(rejected->source());
if constexpr (kTrace) {

View File

@ -87,20 +87,16 @@ private:
#if SK_SUPPORT_GPU
class SkGlyphRunListPainter {
public:
SkGlyphRunListPainter(SkStrikeForGPUCacheInterface* strikeCache);
// A nullptr for process means that the calls to the cache will be performed, but none of the
// callbacks will be called.
// N.B. The positionMatrix has already been translated to the glyph run list origin.
void categorizeGlyphRunList(SkGlyphRunPainterInterface* process,
const SkGlyphRunList& glyphRunList,
const SkMatrix& positionMatrix,
const SkPaint& drawPaint,
SkStrikeDeviceInfo strikeDeviceInfo,
const char* tag = nullptr);
private:
SkStrikeForGPUCacheInterface* const fStrikeCache;
static void CategorizeGlyphRunList(SkGlyphRunPainterInterface* process,
const SkGlyphRunList& glyphRunList,
const SkMatrix& positionMatrix,
const SkPaint& drawPaint,
SkStrikeDeviceInfo strikeDeviceInfo,
SkStrikeForGPUCacheInterface* strikeCache,
const char* tag = nullptr);
};
// SkGlyphRunPainterInterface are all the ways that Ganesh generates glyphs. The first

View File

@ -15,7 +15,6 @@
#include "include/core/SkTypeface.h"
#include "include/private/SkMutex.h"
#include "include/private/SkTemplates.h"
#include "src/core/SkGlyphRunPainter.h"
#include "src/core/SkScalerCache.h"
#if SK_SUPPORT_GPU

View File

@ -511,9 +511,8 @@ GrOp::Owner AtlasTextOp::CreateOpTestingOnly(SurfaceDrawContext* sdc,
SkScalerContextFlags::kBoostContrast,
&control};
SkGlyphRunListPainter painter{SkStrikeCache::GlobalStrikeCache()};
sk_sp<GrTextBlob> blob = GrTextBlob::Make(
glyphRunList, skPaint, drawMatrix, strikeDeviceInfo, &painter);
glyphRunList, skPaint, drawMatrix, strikeDeviceInfo, SkStrikeCache::GlobalStrikeCache());
const GrAtlasSubRun* subRun = blob->testingOnlyFirstSubRun();
if (!subRun) {

View File

@ -138,6 +138,7 @@ generated_cc_atom(
visibility = ["//:__subpackages__"],
deps = [
":GrTextBlobRedrawCoordinator_hdr",
"//src/core:SkStrikeCache_hdr",
"//src/gpu/ganesh/v1:SurfaceDrawContext_v1_hdr",
],
)

View File

@ -2174,7 +2174,7 @@ sk_sp<GrTextBlob> GrTextBlob::Make(const SkGlyphRunList& glyphRunList,
const SkPaint& paint,
const SkMatrix& positionMatrix,
SkStrikeDeviceInfo strikeDeviceInfo,
SkGlyphRunListPainter* painter) {
SkStrikeForGPUCacheInterface* strikeCache) {
// The difference in alignment from the per-glyph data to the SubRun;
constexpr size_t alignDiff = alignof(DirectMaskSubRun) - alignof(DevicePosition);
constexpr size_t vertexDataToSubRunPadding = alignDiff > 0 ? alignDiff : 0;
@ -2192,8 +2192,9 @@ sk_sp<GrTextBlob> GrTextBlob::Make(const SkGlyphRunList& glyphRunList,
sk_sp<GrTextBlob> blob = sk_sp<GrTextBlob>(initializer.initialize(
std::move(alloc), totalMemoryAllocated, positionMatrix, initialLuminance));
painter->categorizeGlyphRunList(
blob.get(), glyphRunList, positionMatrix, paint, strikeDeviceInfo, "GrTextBlob");
SkGlyphRunListPainter::CategorizeGlyphRunList(
blob.get(), glyphRunList, positionMatrix, paint,
strikeDeviceInfo, strikeCache, "GrTextBlob");
return blob;
}
@ -2336,7 +2337,7 @@ public:
const SkPaint& initialPaint,
const SkPaint& drawingPaint,
SkStrikeDeviceInfo strikeDeviceInfo,
SkGlyphRunListPainter* painter);
SkStrikeForGPUCacheInterface* strikeCache);
static sk_sp<GrSlug> MakeFromBuffer(SkReadBuffer& buffer,
const SkStrikeClient* client);
@ -2490,7 +2491,7 @@ sk_sp<Slug> Slug::Make(const SkMatrixProvider& viewMatrix,
const SkPaint& initialPaint,
const SkPaint& drawingPaint,
SkStrikeDeviceInfo strikeDeviceInfo,
SkGlyphRunListPainter* painter) {
SkStrikeForGPUCacheInterface* strikeCache) {
// The difference in alignment from the per-glyph data to the SubRun;
constexpr size_t alignDiff = alignof(DirectMaskSubRun) - alignof(DevicePosition);
constexpr size_t vertexDataToSubRunPadding = alignDiff > 0 ? alignDiff : 0;
@ -2512,8 +2513,9 @@ sk_sp<Slug> Slug::Make(const SkMatrixProvider& viewMatrix,
std::move(alloc), glyphRunList.sourceBounds(), initialPaint, positionMatrix,
glyphRunList.origin()));
painter->categorizeGlyphRunList(
slug.get(), glyphRunList, positionMatrix, drawingPaint, strikeDeviceInfo, "Make Slug");
SkGlyphRunListPainter::CategorizeGlyphRunList(
slug.get(), glyphRunList, positionMatrix, drawingPaint,
strikeDeviceInfo, strikeCache, "Make Slug");
// There is nothing to draw here. This is particularly a problem with RSX form blobs where a
// single space becomes a run with no glyphs.
@ -2579,7 +2581,7 @@ Device::convertGlyphRunListToSlug(const SkGlyphRunList& glyphRunList,
initialPaint,
drawingPaint,
this->strikeDeviceInfo(),
fSurfaceDrawContext->glyphRunPainter());
SkStrikeCache::GlobalStrikeCache());
}
void Device::drawSlug(SkCanvas* canvas, const GrSlug* grSlug, const SkPaint& drawingPaint) {
@ -2605,9 +2607,9 @@ sk_sp<GrSlug> MakeSlug(const SkMatrixProvider& drawMatrix,
const SkPaint& initialPaint,
const SkPaint& drawingPaint,
SkStrikeDeviceInfo strikeDeviceInfo,
SkGlyphRunListPainter* painter) {
SkStrikeForGPUCacheInterface* strikeCache) {
return Slug::Make(
drawMatrix, glyphRunList, initialPaint, drawingPaint, strikeDeviceInfo, painter);
drawMatrix, glyphRunList, initialPaint, drawingPaint, strikeDeviceInfo, strikeCache);
}
} // namespace skgpu::v1

View File

@ -227,7 +227,7 @@ public:
const SkPaint& paint,
const SkMatrix& positionMatrix,
SkStrikeDeviceInfo strikeDeviceInfo,
SkGlyphRunListPainter* painter);
SkStrikeForGPUCacheInterface* strikeCache);
GrTextBlob(sktext::gpu::SubRunAllocator&& alloc,
int totalMemorySize,
@ -309,6 +309,6 @@ sk_sp<GrSlug> MakeSlug(const SkMatrixProvider& drawMatrix,
const SkPaint& initialPaint,
const SkPaint& drawingPaint,
SkStrikeDeviceInfo strikeDeviceInfo,
SkGlyphRunListPainter* painter);
SkStrikeForGPUCacheInterface* strikeCache);
} // namespace skgpu::v1
#endif // GrTextBlob_DEFINED

View File

@ -7,6 +7,7 @@
#include "src/gpu/ganesh/text/GrTextBlobRedrawCoordinator.h"
#include "src/core/SkStrikeCache.h"
#include "src/gpu/ganesh/v1/SurfaceDrawContext_v1.h"
DECLARE_SKMESSAGEBUS_MESSAGE(GrTextBlobRedrawCoordinator::PurgeBlobMessage, uint32_t, true)
@ -47,7 +48,8 @@ void GrTextBlobRedrawCoordinator::drawGlyphRunList(SkCanvas* canvas,
}
blob = GrTextBlob::Make(
glyphRunList, paint, positionMatrix, strikeDeviceInfo, sdc->glyphRunPainter());
glyphRunList, paint, positionMatrix,
strikeDeviceInfo, SkStrikeCache::GlobalStrikeCache());
if (canCache) {
blob->addKey(key);

View File

@ -275,7 +275,6 @@ generated_cc_atom(
"//src/core:SkConvertPixels_hdr",
"//src/core:SkDrawProcs_hdr",
"//src/core:SkDrawShadowInfo_hdr",
"//src/core:SkGlyphRunPainter_hdr",
"//src/core:SkLatticeIter_hdr",
"//src/core:SkMatrixPriv_hdr",
"//src/core:SkMatrixProvider_hdr",
@ -342,7 +341,6 @@ generated_cc_atom(
"//include/core:SkSurfaceProps_hdr",
"//include/core:SkSurface_hdr",
"//include/private/gpu/ganesh:GrTypesPriv_hdr",
"//src/core:SkGlyphRunPainter_hdr",
"//src/gpu/ganesh:GrPaint_hdr",
"//src/gpu/ganesh:GrRenderTargetProxy_hdr",
"//src/gpu/ganesh:GrSurfaceProxyView_hdr",

View File

@ -21,7 +21,6 @@
#include "src/core/SkConvertPixels.h"
#include "src/core/SkDrawProcs.h"
#include "src/core/SkDrawShadowInfo.h"
#include "src/core/SkGlyphRunPainter.h"
#include "src/core/SkLatticeIter.h"
#include "src/core/SkMatrixPriv.h"
#include "src/core/SkMatrixProvider.h"
@ -299,8 +298,7 @@ SurfaceDrawContext::SurfaceDrawContext(GrRecordingContext* rContext,
, fSurfaceProps(surfaceProps)
, fCanUseDynamicMSAA(
(fSurfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) &&
rContext->priv().caps()->supportsDynamicMSAA(this->asRenderTargetProxy()))
, fGlyphPainter(SkStrikeCache::GlobalStrikeCache()) {
rContext->priv().caps()->supportsDynamicMSAA(this->asRenderTargetProxy())) {
SkDEBUGCODE(this->validate();)
}

View File

@ -14,7 +14,6 @@
#include "include/core/SkSurface.h"
#include "include/core/SkSurfaceProps.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/core/SkGlyphRunPainter.h"
#include "src/gpu/ganesh/GrPaint.h"
#include "src/gpu/ganesh/GrRenderTargetProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
@ -553,8 +552,6 @@ public:
int maxWindowRectangles() const;
SkGlyphRunListPainter* glyphRunPainter() { return &fGlyphPainter; }
/*
* This unique ID will not change for a given SurfaceDrawContext. However, it is _NOT_
* guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
@ -691,7 +688,6 @@ private:
#if GR_TEST_UTILS
bool fPreserveOpsOnFullClear_TestingOnly = false;
#endif
SkGlyphRunListPainter fGlyphPainter;
};
} // namespace skgpu::v1