Remove use of RunPaint from regenerateGlyphRunList
Change uses of RunPaint and Paint to uses of SkPaint and a GrColor. Change-Id: I44d4c41a53e570f316e10dee26754c21d9593de0 Reviewed-on: https://skia-review.googlesource.com/145962 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
parent
9faf9fdee9
commit
919a784423
@ -14,6 +14,7 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrColorSpaceInfo.h"
|
||||
#include "GrRenderTargetContext.h"
|
||||
#include "SkGr.h"
|
||||
#include "text/GrTextBlobCache.h"
|
||||
#include "text/GrTextContext.h"
|
||||
#endif
|
||||
@ -850,6 +851,15 @@ void SkGlyphRunListDrawer::drawGlyphRunAsGlyphWithPathFallback(
|
||||
this->forEachMappedDrawableGlyph(glyphRun, origin, deviceMatrix, cache, eachGlyph);
|
||||
}
|
||||
|
||||
GrColor generate_filtered_color(const SkPaint& paint, const GrColorSpaceInfo& colorSpaceInfo) {
|
||||
GrColor4f filteredColor = SkColorToUnpremulGrColor4f(paint.getColor(), colorSpaceInfo);
|
||||
if (paint.getColorFilter() != nullptr) {
|
||||
filteredColor = GrColor4f::FromSkColor4f(
|
||||
paint.getColorFilter()->filterColor4f(filteredColor.toSkColor4f(),
|
||||
colorSpaceInfo.colorSpace()));
|
||||
}
|
||||
return filteredColor.premul().toGrColor();
|
||||
}
|
||||
|
||||
void GrTextContext::drawGlyphRunList(
|
||||
GrContext* context, GrTextUtils::Target* target, const GrClip& clip,
|
||||
@ -859,6 +869,7 @@ void GrTextContext::drawGlyphRunList(
|
||||
|
||||
// Get the first paint to use as the key paint.
|
||||
const SkPaint& skPaint = glyphRunList.paint();
|
||||
GrColor filteredColor = generate_filtered_color(skPaint, target->colorSpaceInfo());
|
||||
|
||||
// If we have been abandoned, then don't draw
|
||||
if (context->abandoned()) {
|
||||
@ -910,8 +921,8 @@ void GrTextContext::drawGlyphRunList(
|
||||
cacheBlob = textBlobCache->makeCachedBlob(glyphRunList, key, blurRec, skPaint);
|
||||
this->regenerateGlyphRunList(cacheBlob.get(), glyphCache,
|
||||
*context->contextPriv().caps()->shaderCaps(), paint,
|
||||
scalerContextFlags, viewMatrix, props, glyphRunList,
|
||||
target->glyphDrawer());
|
||||
filteredColor, scalerContextFlags, viewMatrix, props,
|
||||
glyphRunList, target->glyphDrawer());
|
||||
} else {
|
||||
textBlobCache->makeMRU(cacheBlob.get());
|
||||
|
||||
@ -922,7 +933,7 @@ void GrTextContext::drawGlyphRunList(
|
||||
sanityBlob->setupKey(key, blurRec, skPaint);
|
||||
this->regenerateGlyphRunList(
|
||||
sanityBlob.get(), glyphCache, *context->contextPriv().caps()->shaderCaps(),
|
||||
paint, scalerContextFlags, viewMatrix, props, glyphRunList,
|
||||
paint, filteredColor, scalerContextFlags, viewMatrix, props, glyphRunList,
|
||||
target->glyphDrawer());
|
||||
GrTextBlob::AssertEqual(*sanityBlob, *cacheBlob);
|
||||
}
|
||||
@ -935,8 +946,8 @@ void GrTextContext::drawGlyphRunList(
|
||||
}
|
||||
this->regenerateGlyphRunList(cacheBlob.get(), glyphCache,
|
||||
*context->contextPriv().caps()->shaderCaps(), paint,
|
||||
scalerContextFlags, viewMatrix, props, glyphRunList,
|
||||
target->glyphDrawer());
|
||||
filteredColor, scalerContextFlags, viewMatrix, props,
|
||||
glyphRunList, target->glyphDrawer());
|
||||
}
|
||||
|
||||
cacheBlob->flush(target, props, fDistanceAdjustTable.get(), paint,
|
||||
@ -1000,24 +1011,22 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
GrGlyphCache* glyphCache,
|
||||
const GrShaderCaps& shaderCaps,
|
||||
const GrTextUtils::Paint& paint,
|
||||
GrColor filteredColor,
|
||||
SkScalerContextFlags scalerContextFlags,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkSurfaceProps& props,
|
||||
const SkGlyphRunList& glyphRunList,
|
||||
SkGlyphRunListDrawer* glyphDrawer) {
|
||||
SkPoint origin = glyphRunList.origin();
|
||||
cacheBlob->initReusableBlob(paint.luminanceColor(), viewMatrix, origin.x(), origin.y());
|
||||
cacheBlob->initReusableBlob(
|
||||
glyphRunList.paint().computeLuminanceColor(), viewMatrix, origin.x(), origin.y());
|
||||
|
||||
// Regenerate GrTextBlob
|
||||
GrTextUtils::RunPaint runPaint(&paint);
|
||||
int runIndex = 0;
|
||||
for (const auto& glyphRun : glyphRunList) {
|
||||
const SkPaint& runPaint = glyphRun.paint();
|
||||
cacheBlob->push_back_run(runIndex);
|
||||
|
||||
if (!runPaint.modifyForRun([glyphRun](SkPaint* p) { *p = glyphRun.paint(); })) {
|
||||
continue;
|
||||
}
|
||||
cacheBlob->setRunPaintFlags(runIndex, runPaint.skPaint().getFlags());
|
||||
cacheBlob->setRunPaintFlags(runIndex, runPaint.getFlags());
|
||||
|
||||
if (CanDrawAsDistanceFields(runPaint, viewMatrix, props,
|
||||
shaderCaps.supportsDistanceFieldText(), fOptions)) {
|
||||
@ -1026,12 +1035,13 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
|
||||
// Setup distance field runPaint and text ratio
|
||||
SkScalar textRatio;
|
||||
SkPaint dfPaint(runPaint);
|
||||
SkPaint distanceFieldPaint{runPaint};
|
||||
SkScalerContextFlags flags;
|
||||
InitDistanceFieldPaint(cacheBlob, &dfPaint, viewMatrix, fOptions, &textRatio, &flags);
|
||||
InitDistanceFieldPaint(cacheBlob, &distanceFieldPaint, viewMatrix,
|
||||
fOptions, &textRatio, &flags);
|
||||
cacheBlob->setHasDistanceField();
|
||||
cacheBlob->setSubRunHasDistanceFields(runIndex, runPaint.skPaint().isLCDRenderText(),
|
||||
runPaint.skPaint().isAntiAlias(), hasWCoord);
|
||||
cacheBlob->setSubRunHasDistanceFields(runIndex, runPaint.isLCDRenderText(),
|
||||
runPaint.isAntiAlias(), hasWCoord);
|
||||
|
||||
FallbackGlyphRunHelper fallbackTextHelper(
|
||||
viewMatrix, runPaint, glyphCache->getGlyphSizeLimit(), textRatio);
|
||||
@ -1039,7 +1049,8 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
sk_sp<GrTextStrike> currStrike;
|
||||
|
||||
{
|
||||
auto cache = cacheBlob->setupCache(runIndex, props, flags, dfPaint, nullptr);
|
||||
auto cache = cacheBlob->setupCache(
|
||||
runIndex, props, flags, distanceFieldPaint, nullptr);
|
||||
|
||||
const SkPoint* positionCursor = glyphRun.positions().data();
|
||||
for (auto glyphID : glyphRun.shuntGlyphsIDs()) {
|
||||
@ -1065,7 +1076,7 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
} else {
|
||||
AppendGlyph(cacheBlob, runIndex, glyphCache, &currStrike,
|
||||
glyph, GrGlyph::kDistance_MaskStyle, sx, sy,
|
||||
runPaint.filteredPremulColor(),
|
||||
paint.filteredPremulColor(),
|
||||
cache.get(), textRatio, true);
|
||||
}
|
||||
|
||||
@ -1078,7 +1089,8 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
}
|
||||
|
||||
fallbackTextHelper.drawGlyphs(
|
||||
cacheBlob, runIndex, glyphCache, props, runPaint, scalerContextFlags);
|
||||
cacheBlob, runIndex, glyphCache, props,
|
||||
runPaint, filteredColor, scalerContextFlags);
|
||||
|
||||
} else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) {
|
||||
// Ensure the blob is set for bitmaptext
|
||||
@ -1114,7 +1126,8 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
glyphDrawer->drawUsingPaths(glyphRun, origin, cache.get(), drawOnePath);
|
||||
|
||||
fallbackTextHelper.drawGlyphs(
|
||||
cacheBlob, runIndex, glyphCache, props, runPaint, scalerContextFlags);
|
||||
cacheBlob, runIndex, glyphCache, props,
|
||||
runPaint, filteredColor, scalerContextFlags);
|
||||
|
||||
} else {
|
||||
// Ensure the blob is set for bitmaptext
|
||||
@ -1124,13 +1137,14 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
runIndex, props, scalerContextFlags, runPaint, &viewMatrix);
|
||||
|
||||
auto perGlyph =
|
||||
[cacheBlob, runIndex, glyphCache, &currStrike, runPaint, cache{cache.get()}]
|
||||
[cacheBlob, runIndex, glyphCache, &currStrike,
|
||||
filteredColor, cache{cache.get()}]
|
||||
(const SkGlyph& glyph, SkPoint mappedPt) {
|
||||
SkScalar sx = SkScalarFloorToScalar(mappedPt.fX),
|
||||
sy = SkScalarFloorToScalar(mappedPt.fY);
|
||||
AppendGlyph(cacheBlob, runIndex, glyphCache, &currStrike,
|
||||
glyph, GrGlyph::kCoverage_MaskStyle, sx, sy,
|
||||
runPaint.filteredPremulColor(), cache, SK_Scalar1, false);
|
||||
filteredColor, cache, SK_Scalar1, false);
|
||||
};
|
||||
|
||||
auto perPath =
|
||||
@ -1150,3 +1164,4 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -233,13 +233,13 @@ void GrTextContext::FallbackGlyphRunHelper::appendGlyph(
|
||||
|
||||
void GrTextContext::FallbackGlyphRunHelper::drawGlyphs(
|
||||
GrTextBlob* blob, int runIndex, GrGlyphCache* glyphCache, const SkSurfaceProps& props,
|
||||
const GrTextUtils::Paint& paint, SkScalerContextFlags scalerContextFlags) {
|
||||
const SkPaint& paint, GrColor filteredColor, SkScalerContextFlags scalerContextFlags) {
|
||||
if (!fFallbackTxt.empty()) {
|
||||
blob->initOverride(runIndex);
|
||||
blob->setHasBitmap();
|
||||
blob->setSubRunHasW(runIndex, fViewMatrix.hasPerspective());
|
||||
const SkPaint& skPaint = paint.skPaint();
|
||||
SkColor textColor = paint.filteredPremulColor();
|
||||
const SkPaint& skPaint = paint;
|
||||
SkColor textColor = filteredColor;
|
||||
|
||||
SkScalar textRatio = SK_Scalar1;
|
||||
SkPaint fallbackPaint(skPaint);
|
||||
@ -312,8 +312,8 @@ std::unique_ptr<GrDrawOp> GrTextContext::createOp_TestingOnly(GrContext* context
|
||||
ComputeScalerContextFlags(rtc->colorSpaceInfo());
|
||||
textContext->regenerateGlyphRunList(
|
||||
blob.get(), glyphCache, *context->contextPriv().caps()->shaderCaps(), utilsPaint,
|
||||
scalerContextFlags, viewMatrix, surfaceProps, glyphRunList,
|
||||
rtc->textTarget()->glyphDrawer());
|
||||
utilsPaint.filteredPremulColor(), scalerContextFlags, viewMatrix, surfaceProps,
|
||||
glyphRunList, rtc->textTarget()->glyphDrawer());
|
||||
}
|
||||
|
||||
return blob->test_makeOp(textLen, 0, 0, viewMatrix, x, y, utilsPaint, surfaceProps,
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
void appendGlyph(const SkGlyph& glyph, SkGlyphID glyphID, SkPoint glyphPos);
|
||||
void drawGlyphs(
|
||||
GrTextBlob* blob, int runIndex, GrGlyphCache* cache,
|
||||
const SkSurfaceProps& props, const GrTextUtils::Paint& flags,
|
||||
const SkSurfaceProps& props, const SkPaint& paint, GrColor filteredColor,
|
||||
SkScalerContextFlags scalerContextFlags);
|
||||
|
||||
void initializeForDraw(SkPaint* paint, SkScalar* textRatio, SkMatrix* matrix) const;
|
||||
@ -118,6 +118,7 @@ private:
|
||||
GrGlyphCache*,
|
||||
const GrShaderCaps&,
|
||||
const GrTextUtils::Paint&,
|
||||
GrColor filteredColor,
|
||||
SkScalerContextFlags scalerContextFlags,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkSurfaceProps&,
|
||||
|
@ -21,13 +21,3 @@ void GrTextUtils::Paint::initFilteredColor() {
|
||||
fFilteredPremulColor = filteredColor.premul().toGrColor();
|
||||
}
|
||||
|
||||
|
||||
bool GrTextUtils::RunPaint::modifyForRun(std::function<void(SkPaint*)> paintModFunc) {
|
||||
if (!fModifiedPaint.isValid()) {
|
||||
fModifiedPaint.init(fOriginalPaint->skPaint());
|
||||
fPaint = fModifiedPaint.get();
|
||||
}
|
||||
paintModFunc(fModifiedPaint.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -96,10 +96,7 @@ public:
|
||||
|
||||
operator const SkPaint&() const { return this->skPaint(); }
|
||||
|
||||
// Just for RunPaint's constructor
|
||||
const GrColorSpaceInfo* dstColorSpaceInfo() const { return fDstColorSpaceInfo; }
|
||||
|
||||
protected:
|
||||
void initFilteredColor();
|
||||
|
||||
Paint() = default;
|
||||
@ -121,13 +118,19 @@ public:
|
||||
public:
|
||||
RunPaint(const Paint* paint) : fOriginalPaint(paint) {
|
||||
// Initially we represent the original paint.
|
||||
fPaint = &fOriginalPaint->skPaint();
|
||||
fDstColorSpaceInfo = fOriginalPaint->dstColorSpaceInfo();
|
||||
fFilteredPremulColor = fOriginalPaint->filteredPremulColor();
|
||||
fPaint = paint->fPaint;
|
||||
fDstColorSpaceInfo = paint->fDstColorSpaceInfo;
|
||||
fFilteredPremulColor = paint->fFilteredPremulColor;
|
||||
}
|
||||
|
||||
bool modifyForRun(std::function<void(SkPaint*)> paintModFunc);
|
||||
|
||||
bool modifyForRun(std::function<void(SkPaint*)> paintModFunc) {
|
||||
if (!fModifiedPaint.isValid()) {
|
||||
fModifiedPaint.init(fOriginalPaint->skPaint());
|
||||
fPaint = fModifiedPaint.get();
|
||||
}
|
||||
paintModFunc(fModifiedPaint.get());
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
SkTLazy<SkPaint> fModifiedPaint;
|
||||
const Paint* fOriginalPaint;
|
||||
|
Loading…
Reference in New Issue
Block a user