use TypefaceID conversion for unflattening

Use the SkStrikeClient to do the TypefaceID translation if present
when creating a GrGlyphVector.

With this change, Chromium should be able to use the
flatten/MakeFromBuffer API. Currently, this will only
serialize DirectMask (the most common type) drawing.

Other SubRun type will follow soon.

Bug: chromium:1278340

Change-Id: I08a46c7e4e13f7bd899abfdad89c5b3db2548d6a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/511416
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-02-21 15:25:32 -05:00 committed by SkCQ
parent fca03fe881
commit 4f7b656012
4 changed files with 17 additions and 7 deletions

View File

@ -7,6 +7,7 @@
#include "src/gpu/text/GrGlyphVector.h"
#include "include/private/chromium/SkChromeRemoteGlyphCache.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkStrikeCache.h"
#include "src/core/SkStrikeSpec.h"
@ -33,17 +34,23 @@ GrGlyphVector GrGlyphVector::Make(
}
std::optional<GrGlyphVector> GrGlyphVector::MakeFromBuffer(SkReadBuffer& buffer,
const SkStrikeClient* client,
GrSubRunAllocator* alloc) {
auto descriptor = SkAutoDescriptor::MakeFromBuffer(buffer);
if (!descriptor.has_value()) { return {}; }
if (client != nullptr) {
if (!client->translateTypefaceID(&descriptor.value())) { return {}; }
}
sk_sp<SkStrike> strike = SkStrikeCache::GlobalStrikeCache()->findStrike(*descriptor->getDesc());
SkASSERT(strike != nullptr);
int32_t glyphCount = buffer.read32();
// Since the glyph count can never be zero. There was a buffer reading problem.
if (glyphCount == 0) { return {}; }
// Make sure we can do the multiply in the check below and not overflow an int.
// Make sure we can multiply without overflow in the check below.
if ((int)(INT_MAX / sizeof(uint32_t)) < glyphCount) { return {}; }
// Check for enough bytes to populate the packedGlyphID array. If not enought something has

View File

@ -16,6 +16,8 @@
#include "src/gpu/GrSubRunAllocator.h"
#include "src/gpu/text/GrStrikeCache.h"
class SkStrikeClient;
// -- GlyphVector ----------------------------------------------------------------------------------
// GlyphVector provides a way to delay the lookup of GrGlyphs until the code is running on the
// GPU in single threaded mode. The GlyphVector is created in a multi-threaded environment, but
@ -38,6 +40,7 @@ public:
SkSpan<const GrGlyph*> glyphs() const;
static std::optional<GrGlyphVector> MakeFromBuffer(SkReadBuffer& buffer,
const SkStrikeClient* strikeClient,
GrSubRunAllocator* alloc);
void flatten(SkWriteBuffer& buffer);

View File

@ -2935,7 +2935,7 @@ static bool pun_read(SkReadBuffer& buffer, T* dst) {
GrSubRunOwner DirectMaskSubRunSlug::MakeFromBuffer(const GrTextReferenceFrame* referenceFrame,
SkReadBuffer& buffer,
GrSubRunAllocator* alloc,
const SkStrikeClient*) {
const SkStrikeClient* client) {
GrMaskFormat format = (GrMaskFormat)buffer.readInt();
SkGlyphRect runBounds;
@ -2950,7 +2950,7 @@ GrSubRunOwner DirectMaskSubRunSlug::MakeFromBuffer(const GrTextReferenceFrame* r
}
SkSpan<DevicePosition> positions(positionsData, glyphCount);
auto glyphVector = GrGlyphVector::MakeFromBuffer(buffer, alloc);
auto glyphVector = GrGlyphVector::MakeFromBuffer(buffer, client, alloc);
SkASSERT(glyphVector.has_value());
if (!glyphVector) { return nullptr; }
SkASSERT(SkTo<int>(glyphVector->glyphs().size()) == glyphCount);

View File

@ -48,7 +48,7 @@ DEF_TEST(GrGlyphVector_Serialization, r) {
auto data = wBuffer.snapshotAsData();
SkReadBuffer rBuffer{data->data(), data->size()};
auto dst = GrGlyphVector::MakeFromBuffer(rBuffer, &alloc);
auto dst = GrGlyphVector::MakeFromBuffer(rBuffer, nullptr, &alloc);
REPORTER_ASSERT(r, dst.has_value());
REPORTER_ASSERT(r, TestingPeer::GetDescriptor(src) == TestingPeer::GetDescriptor(*dst));
@ -71,7 +71,7 @@ DEF_TEST(GrGlyphVector_BadLengths, r) {
auto data = wBuffer.snapshotAsData();
SkReadBuffer rBuffer{data->data(), data->size()};
GrSubRunAllocator alloc;
auto dst = GrGlyphVector::MakeFromBuffer(rBuffer, &alloc);
auto dst = GrGlyphVector::MakeFromBuffer(rBuffer, nullptr, &alloc);
REPORTER_ASSERT(r, !dst.has_value());
}
@ -89,7 +89,7 @@ DEF_TEST(GrGlyphVector_BadLengths, r) {
auto data = wBuffer.snapshotAsData();
SkReadBuffer rBuffer{data->data(), data->size()};
GrSubRunAllocator alloc;
auto dst = GrGlyphVector::MakeFromBuffer(rBuffer, &alloc);
auto dst = GrGlyphVector::MakeFromBuffer(rBuffer, nullptr, &alloc);
REPORTER_ASSERT(r, !dst.has_value());
}
@ -107,7 +107,7 @@ DEF_TEST(GrGlyphVector_BadLengths, r) {
auto data = wBuffer.snapshotAsData();
SkReadBuffer rBuffer{data->data(), data->size()};
GrSubRunAllocator alloc;
auto dst = GrGlyphVector::MakeFromBuffer(rBuffer, &alloc);
auto dst = GrGlyphVector::MakeFromBuffer(rBuffer, nullptr, &alloc);
REPORTER_ASSERT(r, !dst.has_value());
}
}