Convert the CPU mask case to use prepareForDrawing

Change-Id: I3a36084544e12730f4815dbf5b6c78a1cd719f1b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/207761
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2019-04-11 15:22:38 -04:00 committed by Skia Commit-Bot
parent 81fd86c1ca
commit c48879ed40
3 changed files with 41 additions and 36 deletions

View File

@ -20,6 +20,22 @@ void SkGlyph::toMask(SkMask* mask) const {
mask->fFormat = static_cast<SkMask::Format>(fMaskFormat);
}
SkMask SkGlyph::mask(SkPoint position) const {
// findImage had to be called.
SkASSERT(fImage != nullptr);
// getMetrics had to be called.
SkASSERT(fMaskFormat != MASK_FORMAT_UNKNOWN);
SkMask mask;
mask.fImage = (uint8_t*)fImage;
mask.fBounds.set(fLeft, fTop, fLeft + fWidth, fTop + fHeight);
mask.fBounds.offset(SkScalarFloorToInt(position.x()), SkScalarFloorToInt(position.y()));
mask.fRowBytes = this->rowBytes();
mask.fFormat = static_cast<SkMask::Format>(fMaskFormat);
return mask;
}
void SkGlyph::zeroMetrics() {
fAdvanceX = 0;
fAdvanceY = 0;
@ -119,4 +135,3 @@ SkPath* SkGlyph::addPath(SkScalerContext* scalerContext, SkArenaAlloc* alloc) {
}
return this->path();
}

View File

@ -152,6 +152,8 @@ public:
void toMask(SkMask* mask) const;
SkMask mask(SkPoint position) const;
SkPath* addPath(SkScalerContext*, SkArenaAlloc*);
SkPath* path() const {

View File

@ -138,27 +138,6 @@ static bool check_glyph_position(SkPoint position) {
lt(position.fY, INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/)));
}
static SkMask create_mask(const SkGlyph& glyph, SkPoint position, const void* image) {
SkMask mask;
int left = SkScalarFloorToInt(position.fX);
int top = SkScalarFloorToInt(position.fY);
left += glyph.fLeft;
top += glyph.fTop;
int right = left + glyph.fWidth;
int bottom = top + glyph.fHeight;
mask.fBounds.set(left, top, right, bottom);
SkASSERT(!mask.fBounds.isEmpty());
mask.fImage = (uint8_t*)image;
mask.fRowBytes = glyph.rowBytes();
mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
return mask;
}
void SkGlyphRunListPainter::drawForBitmapDevice(
const SkGlyphRunList& glyphRunList, const SkMatrix& deviceMatrix,
const BitmapDevicePainter* bitmapDevice) {
@ -216,30 +195,39 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
SkSpan<const SkPathPos>{pathsAndPositions.begin(), pathsAndPositions.size()},
textScale, pathPaint);
} else {
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
runFont, runPaint, props,
fScalerContextFlags, deviceMatrix);
SkAutoDescriptor ad;
SkScalerContextEffects effects;
SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
runFont, runPaint, props, fScalerContextFlags, deviceMatrix, &ad,
&effects);
SkTypeface* typeface = runFont.getTypefaceOrDefault();
SkScopedStrike strike =
fStrikeCache->findOrCreateScopedStrike(*ad.getDesc(), effects, *typeface);
// Add rounding and origin.
SkMatrix matrix = deviceMatrix;
matrix.preTranslate(origin.x(), origin.y());
SkPoint rounding = cache->rounding();
SkPoint rounding = strike->rounding();
matrix.postTranslate(rounding.x(), rounding.y());
matrix.mapPoints(fPositions, glyphRun.positions().data(), runSize);
SkSpan<const SkGlyphPos> glyphPosSpan = strike->prepareForDrawing(
glyphRun.glyphsIDs().data(), fPositions, glyphRun.runSize(),
std::numeric_limits<int>::max(), fGlyphPos);
SkTDArray<SkMask> masks;
masks.setReserve(runSize);
const SkPoint* positionCursor = fPositions;
for (auto glyphID : glyphRun.glyphsIDs()) {
auto position = *positionCursor++;
if (check_glyph_position(position)) {
const SkGlyph& glyph = cache->getGlyphMetrics(glyphID, position);
const void* image;
if (!glyph.isEmpty() && (image = cache->findImage(glyph))) {
masks.push_back(create_mask(glyph, position, image));
}
masks.setReserve(glyphPosSpan.size());
for (const SkGlyphPos& glyphPos : glyphPosSpan) {
const SkGlyph& glyph = *glyphPos.glyph;
SkPoint position = glyphPos.position;
if (check_glyph_position(position) && !glyph.isEmpty()) {
masks.push_back(glyph.mask(position));
}
}
bitmapDevice->paintMasks(SkSpan<const SkMask>{masks.begin(), masks.size()}, runPaint);
}
}