SkRunFont is gone, there is only SkFont

Bug: skia:
Change-Id: I720fd5d8b3755d4f19767db4077e0f3c43167cae
Reviewed-on: https://skia-review.googlesource.com/c/174850
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2018-12-05 21:32:05 -05:00 committed by Skia Commit-Bot
parent 7c4a9b7c7e
commit 7b7ab595d9
6 changed files with 37 additions and 58 deletions

View File

@ -47,7 +47,7 @@ class SkMaskFilter;
class SkPath; class SkPath;
class SkPathEffect; class SkPathEffect;
struct SkPoint; struct SkPoint;
class SkRunFont; class SkFont;
class SkShader; class SkShader;
class SkSurfaceProps; class SkSurfaceProps;
class SkTextBlob; class SkTextBlob;
@ -1279,7 +1279,7 @@ public:
private: private:
friend class SkGlyphRun; friend class SkGlyphRun;
friend class SkGlyphRunBuilder; friend class SkGlyphRunBuilder;
SkPaint(const SkPaint&, const SkRunFont&); SkPaint(const SkPaint&, const SkFont&);
sk_sp<SkTypeface> fTypeface; sk_sp<SkTypeface> fTypeface;
sk_sp<SkPathEffect> fPathEffect; sk_sp<SkPathEffect> fPathEffect;

View File

@ -29,7 +29,7 @@ static SkTypeface::Encoding convert_encoding(SkTextEncoding encoding) {
// -- SkGlyphRun ----------------------------------------------------------------------------------- // -- SkGlyphRun -----------------------------------------------------------------------------------
SkGlyphRun::SkGlyphRun(const SkPaint& basePaint, SkGlyphRun::SkGlyphRun(const SkPaint& basePaint,
const SkRunFont& runFont, const SkFont& runFont,
SkSpan<const SkPoint> positions, SkSpan<const SkPoint> positions,
SkSpan<const SkGlyphID> glyphIDs, SkSpan<const SkGlyphID> glyphIDs,
SkSpan<const char> text, SkSpan<const char> text,
@ -52,7 +52,7 @@ void SkGlyphRun::eachGlyphToGlyphRun(SkGlyphRun::PerGlyph perGlyph) {
SkGlyphID glyphID; SkGlyphID glyphID;
SkGlyphRun run{ SkGlyphRun run{
fRunPaint, fRunPaint,
SkRunFont{fRunPaint}, SkFont::LEGACY_ExtractFromPaint(fRunPaint),
SkSpan<const SkPoint>{&point, 1}, SkSpan<const SkPoint>{&point, 1},
SkSpan<const SkGlyphID>{&glyphID, 1}, SkSpan<const SkGlyphID>{&glyphID, 1},
SkSpan<const char>{}, SkSpan<const char>{},
@ -195,7 +195,7 @@ void SkGlyphRunBuilder::drawTextAtOrigin(
this->makeGlyphRun( this->makeGlyphRun(
paint, paint,
SkRunFont{paint}, SkFont::LEGACY_ExtractFromPaint(paint),
glyphIDs, glyphIDs,
positions, positions,
SkSpan<const char>{}, SkSpan<const char>{},
@ -208,7 +208,8 @@ void SkGlyphRunBuilder::drawText(
auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength); auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength);
if (!glyphIDs.empty()) { if (!glyphIDs.empty()) {
this->initialize(glyphIDs.size()); this->initialize(glyphIDs.size());
this->simplifyDrawText(paint, SkRunFont{paint}, glyphIDs, origin, fPositions); this->simplifyDrawText(paint, SkFont::LEGACY_ExtractFromPaint(paint),
glyphIDs, origin, fPositions);
} }
this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0)); this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0));
@ -221,7 +222,7 @@ void SkGlyphRunBuilder::drawPosTextH(const SkPaint& paint, const void* bytes,
if (!glyphIDs.empty()) { if (!glyphIDs.empty()) {
this->initialize(glyphIDs.size()); this->initialize(glyphIDs.size());
this->simplifyDrawPosTextH( this->simplifyDrawPosTextH(
paint, SkRunFont{paint}, glyphIDs, xpos, constY, fPositions); paint, SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, xpos, constY, fPositions);
} }
this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0)); this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0));
@ -232,7 +233,7 @@ void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, const void* bytes,
auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength); auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength);
if (!glyphIDs.empty()) { if (!glyphIDs.empty()) {
this->initialize(glyphIDs.size()); this->initialize(glyphIDs.size());
this->simplifyDrawPosText(paint, SkRunFont{paint}, glyphIDs, pos); this->simplifyDrawPosText(paint, SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, pos);
} }
this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0)); this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0));
@ -263,18 +264,18 @@ void SkGlyphRunBuilder::drawTextBlob(const SkPaint& paint, const SkTextBlob& blo
switch (it.positioning()) { switch (it.positioning()) {
case SkTextBlobRunIterator::kDefault_Positioning: { case SkTextBlobRunIterator::kDefault_Positioning: {
this->simplifyDrawText( this->simplifyDrawText(
paint, it.runFont(), glyphIDs, offset, positions, text, clusters); paint, it.font(), glyphIDs, offset, positions, text, clusters);
} }
break; break;
case SkTextBlobRunIterator::kHorizontal_Positioning: { case SkTextBlobRunIterator::kHorizontal_Positioning: {
auto constY = offset.y(); auto constY = offset.y();
this->simplifyDrawPosTextH( this->simplifyDrawPosTextH(
paint, it.runFont(), glyphIDs, it.pos(), constY, positions, text, clusters); paint, it.font(), glyphIDs, it.pos(), constY, positions, text, clusters);
} }
break; break;
case SkTextBlobRunIterator::kFull_Positioning: case SkTextBlobRunIterator::kFull_Positioning:
this->simplifyDrawPosText( this->simplifyDrawPosText(
paint, it.runFont(), glyphIDs, (const SkPoint*)it.pos(), text, clusters); paint, it.font(), glyphIDs, (const SkPoint*)it.pos(), text, clusters);
break; break;
} }
@ -288,7 +289,7 @@ void SkGlyphRunBuilder::drawGlyphPos(
const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos) { const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos) {
if (!glyphIDs.empty()) { if (!glyphIDs.empty()) {
this->initialize(glyphIDs.size()); this->initialize(glyphIDs.size());
this->simplifyDrawPosText(paint, SkRunFont{paint}, glyphIDs, pos); this->simplifyDrawPosText(paint, SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, pos);
this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0)); this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0));
} }
} }
@ -329,7 +330,7 @@ SkSpan<const SkGlyphID> SkGlyphRunBuilder::textToGlyphIDs(
void SkGlyphRunBuilder::makeGlyphRun( void SkGlyphRunBuilder::makeGlyphRun(
const SkPaint& basePaint, const SkPaint& basePaint,
const SkRunFont& runFont, const SkFont& runFont,
SkSpan<const SkGlyphID> glyphIDs, SkSpan<const SkGlyphID> glyphIDs,
SkSpan<const SkPoint> positions, SkSpan<const SkPoint> positions,
SkSpan<const char> text, SkSpan<const char> text,
@ -356,14 +357,16 @@ void SkGlyphRunBuilder::makeGlyphRunList(
} }
void SkGlyphRunBuilder::simplifyDrawText( void SkGlyphRunBuilder::simplifyDrawText(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
SkPoint origin, SkPoint* positions, SkPoint origin, SkPoint* positions,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) { SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
SkASSERT(!glyphIDs.empty()); SkASSERT(!glyphIDs.empty());
auto runSize = glyphIDs.size(); auto runSize = glyphIDs.size();
SkPaint runPaint{paint, runFont}; SkPaint runPaint(paint);
runFont.LEGACY_applyToPaint(&runPaint);
runPaint.setTextEncoding(kGlyphID_SkTextEncoding);
if (!glyphIDs.empty()) { if (!glyphIDs.empty()) {
fScratchAdvances.resize(runSize); fScratchAdvances.resize(runSize);
@ -391,7 +394,7 @@ void SkGlyphRunBuilder::simplifyDrawText(
} }
void SkGlyphRunBuilder::simplifyDrawPosTextH( void SkGlyphRunBuilder::simplifyDrawPosTextH(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
const SkScalar* xpos, SkScalar constY, SkPoint* positions, const SkScalar* xpos, SkScalar constY, SkPoint* positions,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) { SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
@ -404,7 +407,7 @@ void SkGlyphRunBuilder::simplifyDrawPosTextH(
} }
void SkGlyphRunBuilder::simplifyDrawPosText( void SkGlyphRunBuilder::simplifyDrawPosText(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
const SkPoint* pos, const SkPoint* pos,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) { SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
auto runSize = glyphIDs.size(); auto runSize = glyphIDs.size();

View File

@ -17,14 +17,14 @@
#include "SkTemplates.h" #include "SkTemplates.h"
#include "SkTypes.h" #include "SkTypes.h"
class SkFont;
class SkGlyph; class SkGlyph;
class SkRunFont;
class SkGlyphRun { class SkGlyphRun {
public: public:
SkGlyphRun() = default; SkGlyphRun() = default;
SkGlyphRun(const SkPaint& basePaint, SkGlyphRun(const SkPaint& basePaint,
const SkRunFont& runFont, const SkFont& runFont,
SkSpan<const SkPoint> positions, SkSpan<const SkPoint> positions,
SkSpan<const SkGlyphID> glyphIDs, SkSpan<const SkGlyphID> glyphIDs,
SkSpan<const char> text, SkSpan<const char> text,
@ -137,7 +137,7 @@ private:
void makeGlyphRun( void makeGlyphRun(
const SkPaint& basePaint, const SkPaint& basePaint,
const SkRunFont& runFont, const SkFont& runFont,
SkSpan<const SkGlyphID> glyphIDs, SkSpan<const SkGlyphID> glyphIDs,
SkSpan<const SkPoint> positions, SkSpan<const SkPoint> positions,
SkSpan<const char> text, SkSpan<const char> text,
@ -146,17 +146,17 @@ private:
void makeGlyphRunList(const SkPaint& paint, const SkTextBlob* blob, SkPoint origin); void makeGlyphRunList(const SkPaint& paint, const SkTextBlob* blob, SkPoint origin);
void simplifyDrawText( void simplifyDrawText(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
SkPoint origin, SkPoint* positions, SkPoint origin, SkPoint* positions,
SkSpan<const char> text = SkSpan<const char>{}, SkSpan<const char> text = SkSpan<const char>{},
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{}); SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});
void simplifyDrawPosTextH( void simplifyDrawPosTextH(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
const SkScalar* xpos, SkScalar constY, SkPoint* positions, const SkScalar* xpos, SkScalar constY, SkPoint* positions,
SkSpan<const char> text = SkSpan<const char>{}, SkSpan<const char> text = SkSpan<const char>{},
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{}); SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});
void simplifyDrawPosText( void simplifyDrawPosText(
const SkPaint& paint, const SkRunFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
const SkPoint* pos, const SkPoint* pos,
SkSpan<const char> text = SkSpan<const char>{}, SkSpan<const char> text = SkSpan<const char>{},
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{}); SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});

View File

@ -23,13 +23,6 @@
#include "text/GrTextBlobCache.h" #include "text/GrTextBlobCache.h"
#endif #endif
SkRunFont::SkRunFont(const SkPaint& paint) : SkFont(SkFont::LEGACY_ExtractFromPaint(paint)) {}
void SkRunFont::applyToPaint(SkPaint* paint) const {
this->LEGACY_applyToPaint(paint);
paint->setTextEncoding(kGlyphID_SkTextEncoding);
}
namespace { namespace {
struct RunFontStorageEquivalent { struct RunFontStorageEquivalent {
SkScalar fSize, fScaleX; SkScalar fSize, fScaleX;
@ -37,7 +30,7 @@ struct RunFontStorageEquivalent {
SkScalar fSkewX; SkScalar fSkewX;
uint32_t fFlags; uint32_t fFlags;
}; };
static_assert(sizeof(SkRunFont) == sizeof(RunFontStorageEquivalent), "runfont_should_stay_packed"); static_assert(sizeof(SkFont) == sizeof(RunFontStorageEquivalent), "runfont_should_stay_packed");
} }
size_t SkTextBlob::RunRecord::StorageSize(uint32_t glyphCount, uint32_t textSize, size_t SkTextBlob::RunRecord::StorageSize(uint32_t glyphCount, uint32_t textSize,
@ -74,7 +67,7 @@ const SkTextBlob::RunRecord* SkTextBlob::RunRecord::Next(const RunRecord* run) {
namespace { namespace {
struct RunRecordStorageEquivalent { struct RunRecordStorageEquivalent {
SkRunFont fFont; SkFont fFont;
SkPoint fOffset; SkPoint fOffset;
uint32_t fCount; uint32_t fCount;
uint32_t fFlags; uint32_t fFlags;
@ -235,7 +228,8 @@ SkTextBlobRunIterator::GlyphPositioning SkTextBlobRunIterator::positioning() con
void SkTextBlobRunIterator::applyFontToPaint(SkPaint* paint) const { void SkTextBlobRunIterator::applyFontToPaint(SkPaint* paint) const {
SkASSERT(!this->done()); SkASSERT(!this->done());
fCurrentRun->font().applyToPaint(paint); fCurrentRun->font().LEGACY_applyToPaint(paint);
paint->setTextEncoding(kGlyphID_SkTextEncoding);
} }
bool SkTextBlobRunIterator::isLCD() const { bool SkTextBlobRunIterator::isLCD() const {
@ -262,7 +256,8 @@ SkTextBlobBuilder::~SkTextBlobBuilder() {
SkRect SkTextBlobBuilder::TightRunBounds(const SkTextBlob::RunRecord& run) { SkRect SkTextBlobBuilder::TightRunBounds(const SkTextBlob::RunRecord& run) {
SkRect bounds; SkRect bounds;
SkPaint paint; SkPaint paint;
run.font().applyToPaint(&paint); run.font().LEGACY_applyToPaint(&paint);
paint.setTextEncoding(kGlyphID_SkTextEncoding);
if (SkTextBlob::kDefault_Positioning == run.positioning()) { if (SkTextBlob::kDefault_Positioning == run.positioning()) {
paint.measureText(run.glyphBuffer(), run.glyphCount() * sizeof(uint16_t), &bounds); paint.measureText(run.glyphBuffer(), run.glyphCount() * sizeof(uint16_t), &bounds);

View File

@ -59,21 +59,6 @@ public:
} }
}; };
// TODO(fmalita): replace with SkFont.
class SkRunFont : public SkFont {
public:
SkRunFont(const SkFont& font) : SkFont(font) {}
SkRunFont(const SkPaint& paint);
void applyToPaint(SkPaint* paint) const;
bool operator==(const SkRunFont& other) const { return SkFont::operator==(other); }
bool operator!=(const SkRunFont& other) const {
return !(*this == other);
}
};
// //
// Textblob data is laid out into externally-managed storage as follows: // Textblob data is laid out into externally-managed storage as follows:
// //
@ -120,7 +105,7 @@ public:
return fOffset; return fOffset;
} }
const SkRunFont& font() const { const SkFont& font() const {
return fFont; return fFont;
} }
@ -186,7 +171,7 @@ private:
return fFlags & kExtended_Flag; return fFlags & kExtended_Flag;
} }
SkRunFont fFont; SkFont fFont;
uint32_t fCount; uint32_t fCount;
SkPoint fOffset; SkPoint fOffset;
uint32_t fFlags; uint32_t fFlags;
@ -195,9 +180,9 @@ private:
}; };
// (paint->getFlags() & ~kFlagsMask) | fFlags // (paint->getFlags() & ~kFlagsMask) | fFlags
inline SkPaint::SkPaint(const SkPaint& basePaint, const SkRunFont& runFont) : SkPaint(basePaint) { inline SkPaint::SkPaint(const SkPaint& basePaint, const SkFont& runFont) : SkPaint(basePaint) {
fBitfields.fTextEncoding = (unsigned)kGlyphID_SkTextEncoding; fBitfields.fTextEncoding = (unsigned)kGlyphID_SkTextEncoding;
runFont.applyToPaint(this); runFont.LEGACY_applyToPaint(this);
} }
/** /**
@ -241,10 +226,6 @@ public:
SkASSERT(!this->done()); SkASSERT(!this->done());
return fCurrentRun->font(); return fCurrentRun->font();
} }
const SkRunFont& runFont() const {
SkASSERT(!this->done());
return fCurrentRun->font();
}
void applyFontToPaint(SkPaint*) const; void applyFontToPaint(SkPaint*) const;
GlyphPositioning positioning() const; GlyphPositioning positioning() const;
uint32_t* clusters() const { uint32_t* clusters() const {

View File

@ -488,7 +488,7 @@ DEF_TEST(SkPDF_Primitives_Color, reporter) {
static SkGlyphRun make_run(size_t len, const SkGlyphID* glyphs, SkPoint* pos, static SkGlyphRun make_run(size_t len, const SkGlyphID* glyphs, SkPoint* pos,
SkPaint paint, const uint32_t* clusters, SkPaint paint, const uint32_t* clusters,
size_t utf8TextByteLength, const char* utf8Text) { size_t utf8TextByteLength, const char* utf8Text) {
return SkGlyphRun(paint, SkRunFont{paint}, return SkGlyphRun(paint, SkFont::LEGACY_ExtractFromPaint(paint),
SkSpan<const SkPoint>{pos, len}, SkSpan<const SkPoint>{pos, len},
SkSpan<const SkGlyphID>{glyphs, len}, SkSpan<const SkGlyphID>{glyphs, len},
SkSpan<const char>{utf8Text, utf8TextByteLength}, SkSpan<const char>{utf8Text, utf8TextByteLength},