hoist origin translation out of the run loop
Change-Id: If5da3dd75b2632a688081fce7517d08a979a3f05
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/376850
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/bench/GlyphQuadFillBench.cpp b/bench/GlyphQuadFillBench.cpp
index 3e0da52..dd4985f 100644
--- a/bench/GlyphQuadFillBench.cpp
+++ b/bench/GlyphQuadFillBench.cpp
@@ -52,16 +52,19 @@
GrSDFTOptions options{256, 256};
const SkPoint drawOrigin = glyphRunList.origin();
const SkPaint& drawPaint = glyphRunList.paint();
+
+ SkMatrix drawMatrix = view;
+ drawMatrix.preTranslate(drawOrigin.x(), drawOrigin.y());
for (auto& glyphRun : glyphRunList) {
painter.processGlyphRun(
- glyphRun, view, drawOrigin, drawPaint, props, false, options, fBlob.get());
+ glyphRun, drawMatrix, drawPaint, props, false, options, fBlob.get());
}
SkASSERT(!fBlob->subRunList().isEmpty());
GrAtlasSubRun* subRun = fBlob->subRunList().front().testingOnly_atlasSubRun();
SkASSERT(subRun);
subRun->testingOnly_packedGlyphIDToGrGlyph(&fCache);
- fVertices.reset(new char[subRun->vertexStride(view) * subRun->glyphCount() * 4]);
+ fVertices.reset(new char[subRun->vertexStride(drawMatrix) * subRun->glyphCount() * 4]);
}
void onDraw(int loops, SkCanvas* canvas) override {
diff --git a/src/core/SkGlyphBuffer.cpp b/src/core/SkGlyphBuffer.cpp
index 80be4a8..85ab918 100644
--- a/src/core/SkGlyphBuffer.cpp
+++ b/src/core/SkGlyphBuffer.cpp
@@ -70,17 +70,16 @@
void SkDrawableGlyphBuffer::startGPUDevice(
const SkZip<const SkGlyphID, const SkPoint>& source,
- SkPoint origin, const SkMatrix& viewMatrix,
+ const SkMatrix& drawMatrix,
const SkGlyphPositionRoundingSpec& roundingSpec) {
fInputSize = source.size();
fDrawableSize = 0;
// Build up the mapping from source space to device space. Add the rounding constant
// halfSampleFreq so we just need to floor to get the device result.
- SkMatrix device = viewMatrix;
+ SkMatrix device = drawMatrix;
SkPoint halfSampleFreq = roundingSpec.halfAxisSampleFreq;
device.postTranslate(halfSampleFreq.x(), halfSampleFreq.y());
- device.preTranslate(origin.x(), origin.y());
auto positions = source.get<1>();
device.mapPoints(fPositions, positions.data(), positions.size());
diff --git a/src/core/SkGlyphBuffer.h b/src/core/SkGlyphBuffer.h
index 5f51576..c7386ee 100644
--- a/src/core/SkGlyphBuffer.h
+++ b/src/core/SkGlyphBuffer.h
@@ -169,7 +169,7 @@
// floating point don't guarantee that, so force it to integer.
void startGPUDevice(
const SkZip<const SkGlyphID, const SkPoint>& source,
- SkPoint origin, const SkMatrix& viewMatrix,
+ const SkMatrix& drawMatrix,
const SkGlyphPositionRoundingSpec& roundingSpec);
// The input of SkPackedGlyphIDs
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 2f82f57..7addd95 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -139,7 +139,6 @@
#if SK_SUPPORT_GPU
void SkGlyphRunListPainter::processGlyphRun(const SkGlyphRun& glyphRun,
const SkMatrix& drawMatrix,
- SkPoint drawOrigin,
const SkPaint& runPaint,
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,
@@ -148,6 +147,7 @@
ScopedBuffers _ = this->ensureBuffers(glyphRun);
fRejects.setSource(glyphRun.source());
const SkFont& runFont = glyphRun.font();
+
bool useSDFT = options.canDrawAsDistanceFields(
runPaint, runFont, drawMatrix, props, contextSupportsDistanceFieldText);
@@ -183,7 +183,7 @@
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
- fDrawable.startGPUDevice(fRejects.source(), drawOrigin, drawMatrix, strike->roundingSpec());
+ fDrawable.startGPUDevice(fRejects.source(), drawMatrix, strike->roundingSpec());
strike->prepareForMaskDrawing(&fDrawable, &fRejects);
fRejects.flipRejectsToSource();
diff --git a/src/core/SkGlyphRunPainter.h b/src/core/SkGlyphRunPainter.h
index cd12c63..f768988 100644
--- a/src/core/SkGlyphRunPainter.h
+++ b/src/core/SkGlyphRunPainter.h
@@ -85,7 +85,6 @@
// callbacks will be called.
void processGlyphRun(const SkGlyphRun& glyphRun,
const SkMatrix& drawMatrix,
- SkPoint drawOrigin,
const SkPaint& drawPaint,
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index 1a110ea..db1201f 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -821,13 +821,12 @@
GrSDFTOptions options =
{ctxOptions.fMinDistanceFieldFontSize, ctxOptions.fGlyphsAsPathsFontSize};
- const SkPoint drawOrigin = glyphRunList.origin();
- const SkPaint& drawPaint = glyphRunList.paint();
+ SkMatrix drawMatrix = this->localToDevice();
+ drawMatrix.preTranslate(glyphRunList.origin().x(), glyphRunList.origin().y());
for (auto& glyphRun : glyphRunList) {
fPainter.processGlyphRun(glyphRun,
- this->localToDevice(),
- drawOrigin,
- drawPaint,
+ drawMatrix,
+ glyphRunList.paint(),
this->surfaceProps(),
fDFTSupport,
options,
diff --git a/src/gpu/GrSurfaceDrawContext.cpp b/src/gpu/GrSurfaceDrawContext.cpp
index a628b14..7bb2a6b 100644
--- a/src/gpu/GrSurfaceDrawContext.cpp
+++ b/src/gpu/GrSurfaceDrawContext.cpp
@@ -427,8 +427,7 @@
bool supportsSDFT = fContext->priv().caps()->shaderCaps()->supportsDistanceFieldText();
blob->makeSubRuns(&fGlyphPainter,
glyphRunList,
- viewMatrix.localToDevice(),
- drawOrigin,
+ drawMatrix,
drawPaint,
fSurfaceProps,
supportsSDFT,
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index 14f2ccb..5e3c6c1 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -471,8 +471,8 @@
int y) {
size_t textLen = (int)strlen(text);
- const SkMatrix& drawMatrix(mtxProvider.localToDevice());
-
+ SkMatrix drawMatrix(mtxProvider.localToDevice());
+ drawMatrix.preTranslate(x, y);
auto drawOrigin = SkPoint::Make(x, y);
SkGlyphRunBuilder builder;
builder.drawTextUTF8(skPaint, font, text, textLen, drawOrigin);
@@ -489,7 +489,7 @@
SkGlyphRunListPainter* painter = rtc->glyphRunPainter();
painter->processGlyphRun(
*glyphRunList.begin(),
- drawMatrix, glyphRunList.origin(),
+ drawMatrix,
glyphRunList.paint(),
rtc->surfaceProps(),
rContext->priv().caps()->shaderCaps()->supportsDistanceFieldText(),
diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp
index 1b14062..34811f5 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -1493,7 +1493,6 @@
void GrTextBlob::makeSubRuns(SkGlyphRunListPainter* painter,
const SkGlyphRunList& glyphRunList,
const SkMatrix& drawMatrix,
- SkPoint drawOrigin,
const SkPaint& runPaint,
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,
@@ -1501,7 +1500,6 @@
for (auto& glyphRun : glyphRunList) {
painter->processGlyphRun(glyphRun,
drawMatrix,
- drawOrigin,
runPaint,
props,
contextSupportsDistanceFieldText,
diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h
index bd3757a..00a5c92 100644
--- a/src/gpu/text/GrTextBlob.h
+++ b/src/gpu/text/GrTextBlob.h
@@ -403,7 +403,6 @@
SkGlyphRunListPainter* painter,
const SkGlyphRunList& glyphRunList,
const SkMatrix& drawMatrix,
- SkPoint drawOrigin,
const SkPaint& runPaint,
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,