Revert "serialize fonts instead of paints"
This reverts commit f1ae66bedd
.
Reason for revert: need to guard for no-serialization builds (I think)
Original change's description:
> serialize fonts instead of paints
>
> Some changes from before:
> - we don't force serializing a typeface if the field is null
> - we don't serialize the blob bounds (don't trust them)
>
> Bug: skia:
> Change-Id: I41281b2aa63a1026de87330023346f1da5378c1f
> Reviewed-on: https://skia-review.googlesource.com/c/179735
> Commit-Queue: Mike Reed <reed@google.com>
> Reviewed-by: Florin Malita <fmalita@chromium.org>
> Reviewed-by: Herb Derby <herb@google.com>
TBR=bungeman@google.com,herb@google.com,fmalita@chromium.org,reed@google.com
Change-Id: Id891198bc683b9b5e7417a30c2f7adb0bd978e30
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/c/179843
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
b4ba8269b2
commit
576633cf57
@ -495,7 +495,7 @@ private:
|
||||
kEmbolden_PrivFlag = 1 << 4,
|
||||
};
|
||||
|
||||
static constexpr unsigned kAllFlags = 0x1F;
|
||||
static constexpr unsigned kAllFlags = 0x07F;
|
||||
|
||||
sk_sp<SkTypeface> fTypeface;
|
||||
SkScalar fSize;
|
||||
|
@ -265,11 +265,10 @@ private:
|
||||
// V64: Remove occluder feature from blur maskFilter
|
||||
// V65: Float4 paint color
|
||||
// V66: Add saveBehind
|
||||
// V67: Blobs serialize fonts instead of paints
|
||||
|
||||
// Only SKPs within the min/current picture version range (inclusive) can be read.
|
||||
static const uint32_t MIN_PICTURE_VERSION = 56; // august 2017
|
||||
static const uint32_t CURRENT_PICTURE_VERSION = 67;
|
||||
static const uint32_t CURRENT_PICTURE_VERSION = 66;
|
||||
|
||||
static_assert(MIN_PICTURE_VERSION <= 62, "Remove kFontAxes_bad from SkFontDescriptor.cpp");
|
||||
|
||||
|
@ -585,111 +585,3 @@ void SkFontPriv::GlyphsToUnichars(const SkFont& font, const uint16_t glyphs[], i
|
||||
SkUnichar uni[]) {
|
||||
font.glyphsToUnichars(glyphs, count, uni);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkWriteBuffer.h"
|
||||
|
||||
// packed int at the beginning of the serialized font:
|
||||
//
|
||||
// control_bits:8 size_as_byte:8 flags:12 edging:2 hinting:2
|
||||
|
||||
enum {
|
||||
kSize_Is_Byte_Bit = 1 << 31,
|
||||
kHas_ScaleX_Bit = 1 << 30,
|
||||
kHas_SkewX_Bit = 1 << 29,
|
||||
kHas_Typeface_Bit = 1 << 28,
|
||||
|
||||
kShift_for_Size = 16,
|
||||
kMask_For_Size = 0xFF,
|
||||
|
||||
kShift_For_Flags = 4,
|
||||
kMask_For_Flags = 0xFFF,
|
||||
|
||||
kShift_For_Edging = 2,
|
||||
kMask_For_Edging = 0x3,
|
||||
|
||||
kShift_For_Hinting = 0,
|
||||
kMask_For_Hinting = 0x3
|
||||
};
|
||||
|
||||
static bool scalar_is_byte(SkScalar x) {
|
||||
int ix = (int)x;
|
||||
return ix == x && ix >= 0 && ix <= kMask_For_Size;
|
||||
}
|
||||
|
||||
void SkFontPriv::Flatten(const SkFont& font, SkWriteBuffer& buffer) {
|
||||
SkASSERT((font.fFlags & ~kMask_For_Flags) == 0);
|
||||
SkASSERT((font.fEdging & ~kMask_For_Edging) == 0);
|
||||
SkASSERT((font.fHinting & ~kMask_For_Hinting) == 0);
|
||||
|
||||
uint32_t packed = 0;
|
||||
packed |= font.fFlags << kShift_For_Flags;
|
||||
packed |= font.fEdging << kShift_For_Edging;
|
||||
packed |= font.fHinting << kShift_For_Hinting;
|
||||
|
||||
if (scalar_is_byte(font.fSize)) {
|
||||
packed |= kSize_Is_Byte_Bit;
|
||||
packed |= (int)font.fSize << kShift_for_Size;
|
||||
}
|
||||
if (font.fScaleX != 1) {
|
||||
packed |= kHas_ScaleX_Bit;
|
||||
}
|
||||
if (font.fSkewX != 0) {
|
||||
packed |= kHas_SkewX_Bit;
|
||||
}
|
||||
if (font.fTypeface) {
|
||||
packed |= kHas_Typeface_Bit;
|
||||
}
|
||||
|
||||
buffer.write32(packed);
|
||||
if (!(packed & kSize_Is_Byte_Bit)) {
|
||||
buffer.writeScalar(font.fSize);
|
||||
}
|
||||
if (packed & kHas_ScaleX_Bit) {
|
||||
buffer.writeScalar(font.fScaleX);
|
||||
}
|
||||
if (packed & kHas_SkewX_Bit) {
|
||||
buffer.writeScalar(font.fSkewX);
|
||||
}
|
||||
if (packed & kHas_Typeface_Bit) {
|
||||
buffer.writeTypeface(font.fTypeface.get());
|
||||
}
|
||||
}
|
||||
|
||||
bool SkFontPriv::Unflatten(SkFont* font, SkReadBuffer& buffer) {
|
||||
const uint32_t packed = buffer.read32();
|
||||
|
||||
if (packed & kSize_Is_Byte_Bit) {
|
||||
font->fSize = (packed >> kShift_for_Size) & kMask_For_Size;
|
||||
} else {
|
||||
font->fSize = buffer.readScalar();
|
||||
}
|
||||
if (packed & kHas_ScaleX_Bit) {
|
||||
font->fScaleX = buffer.readScalar();
|
||||
}
|
||||
if (packed & kHas_SkewX_Bit) {
|
||||
font->fSkewX = buffer.readScalar();
|
||||
}
|
||||
if (packed & kHas_Typeface_Bit) {
|
||||
font->fTypeface = buffer.readTypeface();
|
||||
}
|
||||
|
||||
SkASSERT(SkFont::kAllFlags <= kMask_For_Flags);
|
||||
// we & with kAllFlags, to clear out any unknown flag bits
|
||||
font->fFlags = SkToU8((packed >> kShift_For_Flags) & SkFont::kAllFlags);
|
||||
|
||||
unsigned edging = (packed >> kShift_For_Edging) & kMask_For_Edging;
|
||||
if (edging > (unsigned)SkFont::Edging::kSubpixelAntiAlias) {
|
||||
edging = 0;
|
||||
}
|
||||
font->fEdging = SkToU8(edging);
|
||||
|
||||
unsigned hinting = (packed >> kShift_For_Hinting) & kMask_For_Hinting;
|
||||
if (hinting > (unsigned)kFull_SkFontHinting) {
|
||||
hinting = 0;
|
||||
}
|
||||
font->fHinting = SkToU8(hinting);
|
||||
|
||||
return buffer.isValid();
|
||||
}
|
||||
|
@ -12,9 +12,6 @@
|
||||
#include "SkMatrix.h"
|
||||
#include "SkTypeface.h"
|
||||
|
||||
class SkReadBuffer;
|
||||
class SkWriteBuffer;
|
||||
|
||||
class SkFontPriv {
|
||||
public:
|
||||
/**
|
||||
@ -66,9 +63,6 @@ public:
|
||||
static int CountTextElements(const void* text, size_t byteLength, SkTextEncoding);
|
||||
|
||||
static void GlyphsToUnichars(const SkFont&, const uint16_t glyphs[], int count, SkUnichar[]);
|
||||
|
||||
static void Flatten(const SkFont&, SkWriteBuffer& buffer);
|
||||
static bool Unflatten(SkFont*, SkReadBuffer& buffer);
|
||||
};
|
||||
|
||||
class SkAutoToGlyphs {
|
||||
|
@ -44,7 +44,6 @@ public:
|
||||
kRemoveOccluderFromBlurMaskFilter = 64,
|
||||
kFloat4PaintColor_Version = 65,
|
||||
kSaveBehind_Version = 66,
|
||||
kSerializeFonts_Version = 67,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -696,6 +696,9 @@ int SkTextBlob::getIntercepts(const SkScalar bounds[2], SkScalar intervals[],
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkTextBlobPriv::Flatten(const SkTextBlob& blob, SkWriteBuffer& buffer) {
|
||||
buffer.writeRect(blob.fBounds);
|
||||
|
||||
SkPaint runPaint;
|
||||
SkTextBlobRunIterator it(&blob);
|
||||
while (!it.done()) {
|
||||
SkASSERT(it.glyphCount() > 0);
|
||||
@ -713,8 +716,9 @@ void SkTextBlobPriv::Flatten(const SkTextBlob& blob, SkWriteBuffer& buffer) {
|
||||
buffer.write32(textSize);
|
||||
}
|
||||
buffer.writePoint(it.offset());
|
||||
|
||||
SkFontPriv::Flatten(it.font(), buffer);
|
||||
// This should go away when switching to SkFont
|
||||
it.applyFontToPaint(&runPaint);
|
||||
buffer.writePaint(runPaint);
|
||||
|
||||
buffer.writeByteArray(it.glyphs(), it.glyphCount() * sizeof(uint16_t));
|
||||
buffer.writeByteArray(it.pos(),
|
||||
@ -734,11 +738,8 @@ void SkTextBlobPriv::Flatten(const SkTextBlob& blob, SkWriteBuffer& buffer) {
|
||||
}
|
||||
|
||||
sk_sp<SkTextBlob> SkTextBlobPriv::MakeFromBuffer(SkReadBuffer& reader) {
|
||||
if (reader.isVersionLT(SkReadBuffer::kSerializeFonts_Version)) {
|
||||
SkRect bounds;
|
||||
reader.readRect(&bounds);
|
||||
// ignored
|
||||
}
|
||||
SkRect bounds;
|
||||
reader.readRect(&bounds);
|
||||
|
||||
SkTextBlobBuilder blobBuilder;
|
||||
SkSafeMath safe;
|
||||
@ -762,14 +763,9 @@ sk_sp<SkTextBlob> SkTextBlobPriv::MakeFromBuffer(SkReadBuffer& reader) {
|
||||
|
||||
SkPoint offset;
|
||||
reader.readPoint(&offset);
|
||||
SkFont font;
|
||||
if (reader.isVersionLT(SkReadBuffer::kSerializeFonts_Version)) {
|
||||
SkPaint paint;
|
||||
reader.readPaint(&paint);
|
||||
font = SkFont::LEGACY_ExtractFromPaint(paint);
|
||||
} else {
|
||||
SkFontPriv::Unflatten(&font, reader);
|
||||
}
|
||||
SkPaint paint;
|
||||
reader.readPaint(&paint);
|
||||
SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
|
||||
|
||||
// Compute the expected size of the buffer and ensure we have enough to deserialize
|
||||
// a run before allocating it.
|
||||
@ -789,17 +785,17 @@ sk_sp<SkTextBlob> SkTextBlobPriv::MakeFromBuffer(SkReadBuffer& reader) {
|
||||
switch (pos) {
|
||||
case SkTextBlob::kDefault_Positioning:
|
||||
buf = &blobBuilder.allocRunText(font, glyphCount, offset.x(), offset.y(),
|
||||
textSize, SkString(), nullptr);
|
||||
textSize, SkString(), &bounds);
|
||||
break;
|
||||
case SkTextBlob::kHorizontal_Positioning:
|
||||
buf = &blobBuilder.allocRunTextPosH(font, glyphCount, offset.y(),
|
||||
textSize, SkString(), nullptr);
|
||||
textSize, SkString(), &bounds);
|
||||
break;
|
||||
case SkTextBlob::kFull_Positioning:
|
||||
buf = &blobBuilder.allocRunTextPos(font, glyphCount, textSize, SkString(), nullptr);
|
||||
buf = &blobBuilder.allocRunTextPos(font, glyphCount, textSize, SkString(), &bounds);
|
||||
break;
|
||||
case SkTextBlob::kRSXform_Positioning:
|
||||
buf = &blobBuilder.allocRunRSXform(font, glyphCount, textSize, SkString(), nullptr);
|
||||
buf = &blobBuilder.allocRunRSXform(font, glyphCount, textSize, SkString(), &bounds);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -415,8 +415,8 @@ DEF_TEST(TextBlob_serialize, reporter) {
|
||||
sk_sp<SkTypeface> tf = SkTypeface::MakeDefault();
|
||||
|
||||
SkTextBlobBuilder builder;
|
||||
add_run(&builder, "Hello", 10, 20, nullptr); // don't flatten a typeface
|
||||
add_run(&builder, "World", 10, 40, tf); // do flatten this typeface
|
||||
add_run(&builder, "Hello", 10, 20, nullptr); // we don't flatten this in the paint
|
||||
add_run(&builder, "World", 10, 40, tf); // we will flatten this in the paint
|
||||
return builder.make();
|
||||
}();
|
||||
|
||||
@ -425,7 +425,7 @@ DEF_TEST(TextBlob_serialize, reporter) {
|
||||
serializeProcs.fTypefaceProc = &SerializeTypeface;
|
||||
serializeProcs.fTypefaceCtx = (void*) &array;
|
||||
sk_sp<SkData> data = blob0->serialize(serializeProcs);
|
||||
REPORTER_ASSERT(reporter, array.count() == 1);
|
||||
REPORTER_ASSERT(reporter, array.count() == 2);
|
||||
SkDeserialProcs deserializeProcs;
|
||||
deserializeProcs.fTypefaceProc = &DeserializeTypeface;
|
||||
deserializeProcs.fTypefaceCtx = (void*) &array;
|
||||
|
Loading…
Reference in New Issue
Block a user