From 2865ea30ffdd8bdce5206f09af424f8aafdc91ac Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Tue, 15 Feb 2022 16:39:35 -0500 Subject: [PATCH] serialization framework down to the Slug level, but not runs Change-Id: I687ba55a61dd5d0509190804f19255851c328a31 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/509502 Reviewed-by: Robert Phillips Commit-Queue: Herb Derby --- src/core/SkChromeRemoteGlyphCache.cpp | 6 ++- src/gpu/text/GrTextBlob.cpp | 68 +++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/core/SkChromeRemoteGlyphCache.cpp b/src/core/SkChromeRemoteGlyphCache.cpp index 42a6e2c7e7..e61da61bb3 100644 --- a/src/core/SkChromeRemoteGlyphCache.cpp +++ b/src/core/SkChromeRemoteGlyphCache.cpp @@ -1208,5 +1208,9 @@ bool SkStrikeClient::translateTypefaceID(SkAutoDescriptor* descriptor) const { } #if SK_SUPPORT_GPU -sk_sp SkStrikeClient::makeSlugFromBuffer(SkReadBuffer& buffer) const { return nullptr; } +// Entry point for making slugs from the Slug class in GrTextBlob.cpp +sk_sp SkMakeSlugFromBuffer(SkReadBuffer& buffer, const SkStrikeClient* client); +sk_sp SkStrikeClient::makeSlugFromBuffer(SkReadBuffer& buffer) const { + return SkMakeSlugFromBuffer(buffer, this); +} #endif // SK_SUPPORT_GPU diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp index 2c94b23b4f..c16f2c1736 100644 --- a/src/gpu/text/GrTextBlob.cpp +++ b/src/gpu/text/GrTextBlob.cpp @@ -9,10 +9,12 @@ #include "include/gpu/GrRecordingContext.h" #include "include/private/SkTemplates.h" #include "include/private/chromium/GrSlug.h" +#include "include/private/chromium/SkChromeRemoteGlyphCache.h" #include "src/core/SkFontPriv.h" #include "src/core/SkMaskFilterBase.h" #include "src/core/SkMatrixProvider.h" #include "src/core/SkPaintPriv.h" +#include "src/core/SkReadBuffer.h" #include "src/core/SkStrikeCache.h" #include "src/core/SkStrikeSpec.h" #include "src/gpu/GrClip.h" @@ -2611,11 +2613,6 @@ namespace { // -- Slug ----------------------------------------------------------------------------------------- class Slug final : public GrSlug, public SkGlyphRunPainterInterface { public: - static sk_sp Make(const SkMatrixProvider& viewMatrix, - const SkGlyphRunList& glyphRunList, - const SkPaint& paint, - const GrSDFTControl& control, - SkGlyphRunListPainter* painter); Slug(SkRect sourceBounds, const SkPaint& paint, const SkMatrix& positionMatrix, @@ -2623,6 +2620,14 @@ public: int allocSize); ~Slug() override = default; + static sk_sp Make(const SkMatrixProvider& viewMatrix, + const SkGlyphRunList& glyphRunList, + const SkPaint& paint, + const GrSDFTControl& control, + SkGlyphRunListPainter* painter); + static sk_sp MakeFromBuffer(SkReadBuffer& buffer, + const SkStrikeClient* client); + void surfaceDraw(SkCanvas*, const GrClip* clip, const SkMatrixProvider& viewMatrix, @@ -2665,7 +2670,7 @@ public: subRunCount += 1; unflattenSizeHint += subrun.unflattenSize(); } - return {subRunCount, unflattenSizeHint + sizeof(Slug)}; + return {subRunCount, unflattenSizeHint}; } private: @@ -2697,6 +2702,51 @@ void Slug::surfaceDraw(SkCanvas* canvas, const GrClip* clip, const SkMatrixProvi } } +void Slug::flatten(SkWriteBuffer& buffer) const { + buffer.writeRect(fSourceBounds); + SkPaintPriv::Flatten(fPaint, buffer); + buffer.writeMatrix(fInitialPositionMatrix); + buffer.writePoint(fOrigin); + auto [subRunCount, subRunsUnflattenSizeHint] = this->subRunCountAndUnflattenSizeHint(); + buffer.writeInt(subRunCount); + buffer.writeInt(subRunsUnflattenSizeHint); + /* This will be uncommented when the serialize-runs CL goes in. + for (auto& subRun : fSubRuns) { + subRun.flatten(buffer); + } + */ +} + +sk_sp Slug::MakeFromBuffer(SkReadBuffer& buffer, const SkStrikeClient* client) { + SkRect sourceBounds = buffer.readRect(); + if (!buffer.validate(!sourceBounds.isEmpty())) { return nullptr; } + + SkPaint paint = buffer.readPaint(); + SkMatrix positionMatrix; + buffer.readMatrix(&positionMatrix); + SkPoint origin = buffer.readPoint(); + int subRunCount = buffer.readInt(); + if (!buffer.validate(subRunCount != 0)) { return nullptr; } + int subRunsUnflattenSizeHint = buffer.readInt(); + + sk_sp slug{new (::operator new (sizeof(Slug) + subRunsUnflattenSizeHint)) + Slug(sourceBounds, + paint, + positionMatrix, + origin, + subRunsUnflattenSizeHint)}; + /* This will be uncommented when the serialize-runs CL goes in. + for (int i = 0; i < subRunCount; ++i) { + slug->fSubRuns.append(GrSubRun::MakeFromBuffer(slug.get(), buffer, &slug->fAlloc, client)); + } + */ + + // Something went wrong while reading. + if (!buffer.isValid()) { return nullptr;} + + return std::move(slug); +} + // -- DirectMaskSubRunSlug ------------------------------------------------------------------------- class DirectMaskSubRunSlug final : public GrSubRun, public GrAtlasSubRun { public: @@ -3177,8 +3227,6 @@ void Slug::processSourceMasks(const SkZip& accepted, add_multi_mask_format(addGlyphsWithSameFormat, accepted, std::move(strike)); } - -void Slug::flatten(SkWriteBuffer& buffer) const { SK_ABORT("Not implemented."); } } // namespace namespace skgpu::v1 { @@ -3222,3 +3270,7 @@ sk_sp MakeSlug(const SkMatrixProvider& drawMatrix, return Slug::Make(drawMatrix, glyphRunList, paint, control, painter); } } // namespace skgpu::v1 + +sk_sp SkMakeSlugFromBuffer(SkReadBuffer& buffer, const SkStrikeClient* client) { + return Slug::MakeFromBuffer(buffer, client); +}