From 98209f67c00745bbeb754db9a552ea868a83228c Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Tue, 22 Feb 2022 13:44:58 -0500 Subject: [PATCH] additional serialize(void*, size_t) to match SkTextBlob Add serialize(void*, size_t) to mirror the SkTextBlob serialization methods. Bug: chromium:1278340 Change-Id: Ie3868d882263a0ec8833d4c9404e7410d30ac6ae Reviewed-on: https://skia-review.googlesource.com/c/skia/+/511798 Reviewed-by: Robert Phillips Commit-Queue: Herb Derby --- include/private/chromium/GrSlug.h | 1 + src/gpu/text/GrSlug.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/private/chromium/GrSlug.h b/include/private/chromium/GrSlug.h index 6466eceb95..867321f3bc 100644 --- a/include/private/chromium/GrSlug.h +++ b/include/private/chromium/GrSlug.h @@ -47,6 +47,7 @@ public: // Serialize the slug. sk_sp serialize() const; + size_t serialize(void* buffer, size_t size) const; // Set the client parameter to the appropriate SkStrikeClient when typeface ID translation // is needed. diff --git a/src/gpu/text/GrSlug.cpp b/src/gpu/text/GrSlug.cpp index 1a4ccf11c3..5c6fbd295c 100644 --- a/src/gpu/text/GrSlug.cpp +++ b/src/gpu/text/GrSlug.cpp @@ -25,6 +25,17 @@ sk_sp GrSlug::serialize() const { return buffer.snapshotAsData(); } +size_t GrSlug::serialize(void* buffer, size_t size) const { + SkBinaryWriteBuffer writeBuffer{buffer, size}; + this->doFlatten(writeBuffer); + + // If we overflow the given buffer, then SkWriteBuffer allocates a new larger buffer. Check + // to see if an additional buffer was allocated, if it wasn't then everything fit, else + // return 0 signaling the buffer overflowed. + // N.B. This is the idiom from SkTextBlob. + return writeBuffer.usingInitialStorage() ? writeBuffer.bytesWritten() : 0u; +} + sk_sp SkMakeSlugFromBuffer(SkReadBuffer& buffer, const SkStrikeClient* client); sk_sp GrSlug::Deserialize(const void* data, size_t size, const SkStrikeClient* client) { SkReadBuffer buffer{data, size};