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 <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-02-15 16:39:35 -05:00 committed by SkCQ
parent 7b5b00aaf1
commit 2865ea30ff
2 changed files with 65 additions and 9 deletions

View File

@ -1208,5 +1208,9 @@ bool SkStrikeClient::translateTypefaceID(SkAutoDescriptor* descriptor) const {
}
#if SK_SUPPORT_GPU
sk_sp<GrSlug> SkStrikeClient::makeSlugFromBuffer(SkReadBuffer& buffer) const { return nullptr; }
// Entry point for making slugs from the Slug class in GrTextBlob.cpp
sk_sp<GrSlug> SkMakeSlugFromBuffer(SkReadBuffer& buffer, const SkStrikeClient* client);
sk_sp<GrSlug> SkStrikeClient::makeSlugFromBuffer(SkReadBuffer& buffer) const {
return SkMakeSlugFromBuffer(buffer, this);
}
#endif // SK_SUPPORT_GPU

View File

@ -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<Slug> 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<Slug> Make(const SkMatrixProvider& viewMatrix,
const SkGlyphRunList& glyphRunList,
const SkPaint& paint,
const GrSDFTControl& control,
SkGlyphRunListPainter* painter);
static sk_sp<GrSlug> 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<GrSlug> 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> 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<SkGlyphVariant, SkPoint>& 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<GrSlug> MakeSlug(const SkMatrixProvider& drawMatrix,
return Slug::Make(drawMatrix, glyphRunList, paint, control, painter);
}
} // namespace skgpu::v1
sk_sp<GrSlug> SkMakeSlugFromBuffer(SkReadBuffer& buffer, const SkStrikeClient* client) {
return Slug::MakeFromBuffer(buffer, client);
}