Move luminance calculation to GrTextBlob::Make()

This allows a couple of routines to be removed, and simplifies
the calling chaing.

Change-Id: I88b9396be79e4e245bbea291f4e778d12416b836
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259196
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Herb Derby 2019-12-10 14:07:10 -05:00 committed by Skia Commit-Bot
parent 9715b6c450
commit aebc5f8bd7
3 changed files with 18 additions and 51 deletions

View File

@ -331,6 +331,8 @@ void GrTextContext::drawGlyphRunList(
} }
bool forceW = fOptions.fDistanceFieldVerticesAlwaysHaveW; bool forceW = fOptions.fDistanceFieldVerticesAlwaysHaveW;
bool supportsSDFT = context->priv().caps()->shaderCaps()->supportsDistanceFieldText();
SkGlyphRunListPainter* painter = target->glyphPainter();
if (cachedBlob) { if (cachedBlob) {
if (cachedBlob->mustRegenerate(blobPaint, glyphRunList.anyRunsSubpixelPositioned(), if (cachedBlob->mustRegenerate(blobPaint, glyphRunList.anyRunsSubpixelPositioned(),
blurRec, viewMatrix, origin.x(), origin.y())) { blurRec, viewMatrix, origin.x(), origin.y())) {
@ -341,10 +343,9 @@ void GrTextContext::drawGlyphRunList(
cachedBlob = textBlobCache->makeCachedBlob( cachedBlob = textBlobCache->makeCachedBlob(
glyphRunList, grStrikeCache, key, blurRec, viewMatrix, glyphRunList, grStrikeCache, key, blurRec, viewMatrix,
initialVertexColor, forceW); initialVertexColor, forceW);
cachedBlob->generateFromGlyphRunList(
*context->priv().caps()->shaderCaps(), fOptions, painter->processGlyphRunList(
blobPaint, viewMatrix, props, glyphRunList, viewMatrix, props, supportsSDFT, fOptions, cachedBlob.get());
glyphRunList, target->glyphPainter());
} else { } else {
textBlobCache->makeMRU(cachedBlob.get()); textBlobCache->makeMRU(cachedBlob.get());
} }
@ -357,10 +358,8 @@ void GrTextContext::drawGlyphRunList(
cachedBlob = textBlobCache->makeBlob( cachedBlob = textBlobCache->makeBlob(
glyphRunList, grStrikeCache, viewMatrix, initialVertexColor, forceW); glyphRunList, grStrikeCache, viewMatrix, initialVertexColor, forceW);
} }
cachedBlob->generateFromGlyphRunList( painter->processGlyphRunList(
*context->priv().caps()->shaderCaps(), fOptions, blobPaint, glyphRunList, viewMatrix, props, supportsSDFT, fOptions, cachedBlob.get());
viewMatrix, props, glyphRunList,
target->glyphPainter());
} }
cachedBlob->flush(target, props, fDistanceAdjustTable.get(), blobPaint, drawingColor, cachedBlob->flush(target, props, fDistanceAdjustTable.get(), blobPaint, drawingColor,
@ -404,10 +403,10 @@ std::unique_ptr<GrDrawOp> GrTextContext::createOp_TestingOnly(GrRecordingContext
if (!glyphRunList.empty()) { if (!glyphRunList.empty()) {
blob = direct->priv().getTextBlobCache()->makeBlob( blob = direct->priv().getTextBlobCache()->makeBlob(
glyphRunList, strikeCache, viewMatrix, color, false); glyphRunList, strikeCache, viewMatrix, color, false);
blob->generateFromGlyphRunList( SkGlyphRunListPainter* painter = rtc->textTarget()->glyphPainter();
*context->priv().caps()->shaderCaps(), textContext->fOptions, painter->processGlyphRunList(glyphRunList, viewMatrix, surfaceProps,
skPaint, viewMatrix, surfaceProps, context->priv().caps()->shaderCaps()->supportsDistanceFieldText(),
glyphRunList, rtc->textTarget()->glyphPainter()); textContext->fOptions, blob.get());
} }
return blob->test_makeOp(textLen, viewMatrix, x, y, skPaint, filteredColor, surfaceProps, return blob->test_makeOp(textLen, viewMatrix, x, y, skPaint, filteredColor, surfaceProps,

View File

@ -243,9 +243,10 @@ sk_sp<GrTextBlob> GrTextBlob::Make(const SkGlyphRunList& glyphRunList,
void* allocation = ::operator new (allocationSize); void* allocation = ::operator new (allocationSize);
SkColor initialLuminance = SkPaintPriv::ComputeLuminanceColor(glyphRunList.paint());
sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{ sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{
subRunsSize, strikeCache, viewMatrix, glyphRunList.origin(), subRunsSize, strikeCache, viewMatrix, glyphRunList.origin(),
color, forceWForDistanceFields}}; color, initialLuminance, forceWForDistanceFields}};
// setup offsets for vertices / glyphs // setup offsets for vertices / glyphs
blob->fVertices = SkTAddOffset<char>(blob.get(), vertexOffset); blob->fVertices = SkTAddOffset<char>(blob.get(), vertexOffset);
@ -254,24 +255,6 @@ sk_sp<GrTextBlob> GrTextBlob::Make(const SkGlyphRunList& glyphRunList,
return blob; return blob;
} }
void GrTextBlob::generateFromGlyphRunList(const GrShaderCaps& shaderCaps,
const GrTextContext::Options& options,
const SkPaint& paint,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
const SkGlyphRunList& glyphRunList,
SkGlyphRunListPainter* glyphPainter) {
const SkPaint& runPaint = glyphRunList.paint();
this->initReusableBlob(SkPaintPriv::ComputeLuminanceColor(runPaint));
glyphPainter->processGlyphRunList(glyphRunList,
viewMatrix,
props,
shaderCaps.supportsDistanceFieldText(),
options,
this);
}
void GrTextBlob::setupKey(const GrTextBlob::Key& key, const SkMaskFilterBase::BlurRec& blurRec, void GrTextBlob::setupKey(const GrTextBlob::Key& key, const SkMaskFilterBase::BlurRec& blurRec,
const SkPaint& paint) { const SkPaint& paint) {
fKey = key; fKey = key;
@ -320,7 +303,7 @@ bool GrTextBlob::mustRegenerate(const SkPaint& paint, bool anyRunHasSubpixelPosi
// to regenerate the blob on any color change // to regenerate the blob on any color change
// We use the grPaint to get any color filter effects // We use the grPaint to get any color filter effects
if (fKey.fCanonicalColor == SK_ColorTRANSPARENT && if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
fLuminanceColor != SkPaintPriv::ComputeLuminanceColor(paint)) { fInitialLuminance != SkPaintPriv::ComputeLuminanceColor(paint)) {
return true; return true;
} }
@ -530,10 +513,6 @@ void GrTextBlob::computeSubRunBounds(SkRect* outBounds, const GrTextBlob::SubRun
} }
} }
void GrTextBlob::initReusableBlob(SkColor luminanceColor) {
fLuminanceColor = luminanceColor;
}
const GrTextBlob::Key& GrTextBlob::key() const { return fKey; } const GrTextBlob::Key& GrTextBlob::key() const { return fKey; }
size_t GrTextBlob::size() const { return fSize; } size_t GrTextBlob::size() const { return fSize; }
@ -636,6 +615,7 @@ GrTextBlob::GrTextBlob(size_t allocSize,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
SkPoint origin, SkPoint origin,
GrColor color, GrColor color,
SkColor initialLuminance,
bool forceWForDistanceFields) bool forceWForDistanceFields)
: fSize{allocSize} : fSize{allocSize}
, fStrikeCache{strikeCache} , fStrikeCache{strikeCache}
@ -644,6 +624,7 @@ GrTextBlob::GrTextBlob(size_t allocSize,
, fInitialOrigin{origin} , fInitialOrigin{origin}
, fForceWForDistanceFields{forceWForDistanceFields} , fForceWForDistanceFields{forceWForDistanceFields}
, fColor{color} , fColor{color}
, fInitialLuminance{initialLuminance}
, fAlloc{SkTAddOffset<char>(this, sizeof(GrTextBlob)), allocSize, allocSize/2} { } , fAlloc{SkTAddOffset<char>(this, sizeof(GrTextBlob)), allocSize, allocSize/2} { }
void GrTextBlob::insertSubRun(SubRun* subRun) { void GrTextBlob::insertSubRun(SubRun* subRun) {

View File

@ -180,14 +180,6 @@ public:
GrColor color, GrColor color,
bool forceWForDistanceFields); bool forceWForDistanceFields);
void generateFromGlyphRunList(const GrShaderCaps& shaderCaps,
const GrTextContext::Options& options,
const SkPaint& paint,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
const SkGlyphRunList& glyphRunList,
SkGlyphRunListPainter* glyphPainter);
// Key manipulation functions // Key manipulation functions
void setupKey(const GrTextBlob::Key& key, void setupKey(const GrTextBlob::Key& key,
const SkMaskFilterBase::BlurRec& blurRec, const SkMaskFilterBase::BlurRec& blurRec,
@ -241,12 +233,6 @@ public:
static const int kVerticesPerGlyph = 4; static const int kVerticesPerGlyph = 4;
// This function will only be called when we are generating a blob from scratch.
// The color here is the GrPaint color, and it is used to determine whether we
// have to regenerate LCD text blobs.
// We use this color vs the SkPaint color because it has the color filter applied.
void initReusableBlob(SkColor luminanceColor);
const Key& key() const; const Key& key() const;
size_t size() const; size_t size() const;
@ -298,6 +284,7 @@ private:
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
SkPoint origin, SkPoint origin,
GrColor color, GrColor color,
SkColor initialLuminance,
bool forceWForDistanceFields); bool forceWForDistanceFields);
void insertSubRun(SubRun* subRun); void insertSubRun(SubRun* subRun);
@ -345,6 +332,7 @@ private:
// The color of the text to draw for solid colors. // The color of the text to draw for solid colors.
const GrColor fColor; const GrColor fColor;
const SkColor fInitialLuminance;
// Pool of bytes for vertex data. // Pool of bytes for vertex data.
char* fVertices; char* fVertices;
@ -358,7 +346,6 @@ private:
SkMaskFilterBase::BlurRec fBlurRec; SkMaskFilterBase::BlurRec fBlurRec;
StrokeInfo fStrokeInfo; StrokeInfo fStrokeInfo;
Key fKey; Key fKey;
SkColor fLuminanceColor;
// We can reuse distance field text, but only if the new view matrix would not result in // We can reuse distance field text, but only if the new view matrix would not result in
// a mip change. Because there can be multiple runs in a blob, we track the overall // a mip change. Because there can be multiple runs in a blob, we track the overall