Cleanup interface between SkGlyphRunPainter and SkDraw

- Remove unused paramaters
  - Unify the handling of paint
  - Simplify using ensureBitmapBuffers
  - Rename misc.

Change-Id: Id1100765f5f12fef3e5a8c1f0ce0f44cfb60ae2d
Reviewed-on: https://skia-review.googlesource.com/c/166482
Commit-Queue: Herb Derby <herb@google.com>
Auto-Submit: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Herb Derby 2018-10-30 13:51:53 -04:00 committed by Skia Commit-Bot
parent 134be1d9ba
commit 90b2e1c9a7
3 changed files with 57 additions and 58 deletions

View File

@ -53,7 +53,7 @@ SkGlyphRunListPainter::PerMask SkDraw::drawOneMaskCreator(const SkPaint& paint,
bool useRegion = fRC->isBW() && !fRC->isRect();
if (useRegion) {
return [this, blitter, &paint](const SkMask& mask, const SkGlyph&, SkPoint) {
return [this, blitter](const SkMask& mask, const SkPaint& paint) {
SkRegion::Cliperator clipper(fRC->bwRgn(), mask.fBounds);
if (!clipper.done()) {
@ -75,7 +75,7 @@ SkGlyphRunListPainter::PerMask SkDraw::drawOneMaskCreator(const SkPaint& paint,
} else {
SkIRect clipBounds = fRC->isBW() ? fRC->bwRgn().getBounds()
: fRC->aaRgn().getBounds();
return [this, blitter, clipBounds, &paint](const SkMask& mask, const SkGlyph&, SkPoint) {
return [this, blitter, clipBounds](const SkMask& mask, const SkPaint& paint) {
SkIRect storage;
const SkIRect* bounds = &mask.fBounds;
@ -114,13 +114,11 @@ void SkDraw::drawGlyphRunList(const SkGlyphRunList& glyphRunList,
return this->drawOneMaskCreator(paint, alloc);
};
auto perPathBuilder = [this](const SkPaint& paint, SkScalar scale, SkArenaAlloc*) {
return [this, scale, &paint](const SkPath* path, const SkGlyph&, SkPoint pos) {
if (path) {
SkMatrix m;
m.setScaleTranslate(scale,scale, pos.fX,pos.fY);
this->drawPath(*path, paint, &m, false);
}
auto perPathBuilder = [this]() {
return [this] (const SkPath& path, SkScalar scale, SkPoint pos, const SkPaint& paint) {
SkMatrix m;
m.setScaleTranslate(scale,scale, pos.fX,pos.fY);
this->drawPath(path, paint, &m, false);
};
};

View File

@ -74,13 +74,11 @@ bool SkGlyphRunListPainter::ShouldDrawAsPath(const SkPaint& paint, const SkMatri
return SkPaint::TooBigToUseCache(matrix, textM, 1024);
}
bool SkGlyphRunListPainter::ensureBitmapBuffers(size_t runSize) {
void SkGlyphRunListPainter::ensureBitmapBuffers(size_t runSize) {
if (runSize > fMaxRunSize) {
fPositions.reset(runSize);
fMaxRunSize = runSize;
}
return true;
}
static bool check_glyph_position(SkPoint position) {
@ -94,7 +92,7 @@ static bool check_glyph_position(SkPoint position) {
lt(position.fY, INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/)));
}
static SkMask prepare_mask(const SkGlyph& glyph, SkPoint position, const void* image) {
static SkMask create_mask(const SkGlyph& glyph, SkPoint position, const void* image) {
SkMask mask;
int left = SkScalarFloorToInt(position.fX);
int top = SkScalarFloorToInt(position.fY);
@ -122,13 +120,16 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
SkPoint origin = glyphRunList.origin();
for (auto& glyphRun : glyphRunList) {
SkSTArenaAlloc<3332> alloc;
// The bitmap blitters can only draw lcd text to a N32 bitmap in srcOver. Otherwise,
// convert the lcd text into A8 text. The props communicates this to the scaler.
auto& props = (kN32_SkColorType == fColorType && glyphRun.paint().isSrcOver())
? fDeviceProps
: fBitmapFallbackProps;
auto paint = glyphRun.paint();
if (ShouldDrawAsPath(glyphRun.paint(), deviceMatrix)) {
const SkPaint& paint = glyphRun.paint();
if (ShouldDrawAsPath(paint, deviceMatrix)) {
// setup our std pathPaint, in hopes of getting hits in the cache
SkPaint pathPaint(paint);
@ -137,7 +138,7 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
auto pathCache = SkStrikeCache::FindOrCreateStrikeExclusive(
pathPaint, &props, fScalerContextFlags, nullptr);
auto perPath = perPathCreator(paint, textScale, &alloc);
auto perPath = perPathCreator();
const SkPoint* positionCursor = glyphRun.positions().data();
for (auto glyphID : glyphRun.glyphsIDs()) {
@ -146,8 +147,10 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
const SkGlyph& glyph = pathCache->getGlyphMetrics(glyphID, {0, 0});
if (!glyph.isEmpty()) {
const SkPath* path = pathCache->findPath(glyph);
SkPoint loc = position + origin;
perPath(path, glyph, loc);
if (path != nullptr) {
SkPoint loc = position + origin;
perPath(*path, textScale, loc, paint);
}
}
}
}
@ -157,24 +160,23 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
auto perMask = perMaskCreator(paint, &alloc);
auto runSize = glyphRun.runSize();
if (this->ensureBitmapBuffers(runSize)) {
// Add rounding and origin.
SkMatrix matrix = deviceMatrix;
matrix.preTranslate(origin.x(), origin.y());
SkPoint rounding = cache->rounding();
matrix.postTranslate(rounding.x(), rounding.y());
matrix.mapPoints(fPositions, glyphRun.positions().data(), runSize);
this->ensureBitmapBuffers(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))) {
SkMask mask;
perMask(prepare_mask(glyph, position, image), glyph, position);
}
// Add rounding and origin.
SkMatrix matrix = deviceMatrix;
matrix.preTranslate(origin.x(), origin.y());
SkPoint rounding = cache->rounding();
matrix.postTranslate(rounding.x(), rounding.y());
matrix.mapPoints(fPositions, glyphRun.positions().data(), 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))) {
perMask(create_mask(glyph, position, image), paint);
}
}
}

View File

@ -26,11 +26,11 @@ public:
explicit SkGlyphRunListPainter(const GrRenderTargetContext& renderTargetContext);
#endif
using PerMask = std::function<void(const SkMask&, const SkGlyph&, SkPoint)>;
using PerMaskCreator = std::function<PerMask(const SkPaint&, SkArenaAlloc* alloc)>;
using PerPath = std::function<void(const SkPath*, const SkGlyph&, SkPoint)>;
using PerPathCreator = std::function<PerPath(
const SkPaint&, SkScalar matrixScale, SkArenaAlloc* alloc)>;
using PerMask = std::function<void(const SkMask& mask, const SkPaint& paint)>;
using PerMaskCreator = std::function<PerMask(const SkPaint& paint, SkArenaAlloc* alloc)>;
using PerPath = std::function<
void(const SkPath& path, SkScalar scale, SkPoint pos, const SkPaint& paint)>;
using PerPathCreator = std::function<PerPath()>;
void drawForBitmapDevice(
const SkGlyphRunList& glyphRunList, const SkMatrix& deviceMatrix,
PerMaskCreator perMaskCreator, PerPathCreator perPathCreator);
@ -71,7 +71,7 @@ public:
private:
static bool ShouldDrawAsPath(const SkPaint& paint, const SkMatrix& matrix);
bool ensureBitmapBuffers(size_t runSize);
void ensureBitmapBuffers(size_t runSize);
void processARGBFallback(
SkScalar maxGlyphDimension, const SkPaint& runPaint, SkPoint origin,
@ -161,26 +161,25 @@ void SkGlyphRunListPainter::drawGlyphRunAsBMPWithPathFallback(
mapping.postTranslate(rounding.x(), rounding.y());
auto runSize = glyphRun.runSize();
if (this->ensureBitmapBuffers(runSize)) {
mapping.mapPoints(fPositions, glyphRun.positions().data(), runSize);
const SkPoint* mappedPtCursor = fPositions;
for (auto glyphID : glyphRun.glyphsIDs()) {
auto mappedPt = *mappedPtCursor++;
if (SkScalarsAreFinite(mappedPt.x(), mappedPt.y())) {
const SkGlyph& glyph = cache->getGlyphMetrics(glyphID, mappedPt);
if (SkGlyphCacheCommon::GlyphTooBigForAtlas(glyph)) {
SkScalar sx = SkScalarFloorToScalar(mappedPt.fX),
sy = SkScalarFloorToScalar(mappedPt.fY);
this->ensureBitmapBuffers(runSize);
mapping.mapPoints(fPositions, glyphRun.positions().data(), runSize);
const SkPoint* mappedPtCursor = fPositions;
for (auto glyphID : glyphRun.glyphsIDs()) {
auto mappedPt = *mappedPtCursor++;
if (SkScalarsAreFinite(mappedPt.x(), mappedPt.y())) {
const SkGlyph& glyph = cache->getGlyphMetrics(glyphID, mappedPt);
if (SkGlyphCacheCommon::GlyphTooBigForAtlas(glyph)) {
SkScalar sx = SkScalarFloorToScalar(mappedPt.fX),
sy = SkScalarFloorToScalar(mappedPt.fY);
SkRect glyphRect =
rect_to_draw(glyph, {sx, sy}, SK_Scalar1, false);
SkRect glyphRect =
rect_to_draw(glyph, {sx, sy}, SK_Scalar1, false);
if (!glyphRect.isEmpty()) {
perPath(glyph, mappedPt);
}
} else {
perGlyph(glyph, mappedPt);
if (!glyphRect.isEmpty()) {
perPath(glyph, mappedPt);
}
} else {
perGlyph(glyph, mappedPt);
}
}
}