Const all the things in GrAtlasTextOp

Move GrAtlasTextOp initialization code from GrTextBlob
to GrAtlasTextOp. Make many fields const.

Change-Id: I8a1c1992b43c8ad9db7d6762ef7cbd109888ac18
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/286176
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2020-04-29 15:56:07 -04:00 committed by Skia Commit-Bot
parent b67d056c30
commit 3c873afcd7
5 changed files with 148 additions and 125 deletions

View File

@ -402,7 +402,7 @@ std::unique_ptr<GrDrawOp> GrTextContext::createOp_TestingOnly(GrRecordingContext
textContext->fOptions, blob.get());
}
return blob->test_makeOp(textLen, mtxProvider, drawOrigin, skPaint, filteredColor, surfaceProps,
return blob->test_makeOp(mtxProvider, drawOrigin, skPaint, filteredColor, surfaceProps,
rtc->textTarget());
}

View File

@ -25,88 +25,114 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
GrAtlasTextOp::GrAtlasTextOp(MaskType maskType,
GrPaint&& paint,
GrTextBlob::SubRun* subrun,
const SkMatrix& drawMatrix,
SkPoint drawOrigin,
const SkIRect& clipRect,
const SkPMColor4f& filteredColor,
SkColor luminanceColor,
bool useGammaCorrectDistanceTable,
uint32_t DFGPFlags)
: INHERITED(ClassID())
, fMaskType{maskType}
, fNeedsGlyphTransform{subrun->needsTransform()}
, fLuminanceColor{luminanceColor}
, fUseGammaCorrectDistanceTable{useGammaCorrectDistanceTable}
, fDFGPFlags{DFGPFlags}
, fGeoDataAllocSize{kMinGeometryAllocated}
, fProcessors{std::move(paint)}
, fNumGlyphs{SkTo<int>(subrun->fGlyphs.size())} {
GrAtlasTextOp::Geometry& geometry = fGeoData[0];
// Unref handled in ~GrAtlasTextOp().
geometry.fBlob = SkRef(subrun->fBlob);
geometry.fSubRunPtr = subrun;
geometry.fDrawMatrix = drawMatrix;
geometry.fDrawOrigin = drawOrigin;
geometry.fClipRect = clipRect;
geometry.fColor = subrun->maskFormat() == kARGB_GrMaskFormat ? SK_PMColor4fWHITE
: filteredColor;
fGeoCount = 1;
SkRect bounds = subrun->deviceRect(drawMatrix, drawOrigin);
// We don't have tight bounds on the glyph paths in device space. For the purposes of bounds
// we treat this as a set of non-AA rects rendered with a texture.
this->setBounds(bounds, HasAABloat::kNo, IsHairline::kNo);
}
std::unique_ptr<GrAtlasTextOp> GrAtlasTextOp::MakeBitmap(GrRecordingContext* context,
GrPaint&& paint,
GrMaskFormat maskFormat,
int glyphCount,
bool needsTransform) {
GrOpMemoryPool* pool = context->priv().opMemoryPool();
GrTextBlob::SubRun* subrun,
const SkMatrix& drawMatrix,
SkPoint drawOrigin,
const SkIRect& clipRect,
const SkPMColor4f& filteredColor) {
GrOpMemoryPool* pool = context->priv().opMemoryPool();
std::unique_ptr<GrAtlasTextOp> op = pool->allocate<GrAtlasTextOp>(std::move(paint));
switch (maskFormat) {
case kA8_GrMaskFormat:
op->fMaskType = kGrayscaleCoverageMask_MaskType;
break;
case kA565_GrMaskFormat:
op->fMaskType = kLCDCoverageMask_MaskType;
break;
case kARGB_GrMaskFormat:
op->fMaskType = kColorBitmapMask_MaskType;
break;
MaskType maskType = [&]() {
switch (subrun->maskFormat()) {
case kA8_GrMaskFormat: return kGrayscaleCoverageMask_MaskType;
case kA565_GrMaskFormat: return kLCDCoverageMask_MaskType;
case kARGB_GrMaskFormat: return kColorBitmapMask_MaskType;
// Needed to placate some compilers.
default: return kGrayscaleCoverageMask_MaskType;
}
op->fNumGlyphs = glyphCount;
op->fGeoCount = 1;
op->fLuminanceColor = 0;
op->fNeedsGlyphTransform = needsTransform;
return op;
}
}();
return pool->allocate<GrAtlasTextOp>(maskType,
std::move(paint),
subrun,
drawMatrix,
drawOrigin,
clipRect,
filteredColor,
0,
false,
0);
}
std::unique_ptr<GrAtlasTextOp> GrAtlasTextOp::MakeDistanceField(
GrRecordingContext* context,
GrPaint&& paint,
int glyphCount,
GrTextBlob::SubRun* subrun,
const SkMatrix& drawMatrix,
SkPoint drawOrigin,
const SkIRect& clipRect,
const SkPMColor4f& filteredColor,
bool useGammaCorrectDistanceTable,
SkColor luminanceColor,
const SkSurfaceProps& props,
bool isAntiAliased,
bool useLCD) {
GrOpMemoryPool* pool = context->priv().opMemoryPool();
const SkSurfaceProps& props) {
GrOpMemoryPool* pool = context->priv().opMemoryPool();
bool isBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
bool isLCD = subrun->hasUseLCDText() && SkPixelGeometryIsH(props.pixelGeometry());
MaskType maskType = !subrun->isAntiAliased() ? kAliasedDistanceField_MaskType
: isLCD ? (isBGR ? kLCDBGRDistanceField_MaskType
: kLCDDistanceField_MaskType)
: kGrayscaleDistanceField_MaskType;
std::unique_ptr<GrAtlasTextOp> op = pool->allocate<GrAtlasTextOp>(std::move(paint));
uint32_t DFGPFlags = drawMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
DFGPFlags |= drawMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0;
DFGPFlags |= drawMatrix.hasPerspective() ? kPerspective_DistanceFieldEffectFlag : 0;
DFGPFlags |= useGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFlag : 0;
DFGPFlags |= kAliasedDistanceField_MaskType == maskType ? kAliased_DistanceFieldEffectFlag : 0;
bool isBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
bool isLCD = useLCD && SkPixelGeometryIsH(props.pixelGeometry());
op->fMaskType = !isAntiAliased ? kAliasedDistanceField_MaskType
: isLCD ? (isBGR ? kLCDBGRDistanceField_MaskType
: kLCDDistanceField_MaskType)
: kGrayscaleDistanceField_MaskType;
op->fUseGammaCorrectDistanceTable = useGammaCorrectDistanceTable;
op->fLuminanceColor = luminanceColor;
op->fNeedsGlyphTransform = true;
op->fNumGlyphs = glyphCount;
op->fGeoCount = 1;
return op;
if (isLCD) {
DFGPFlags |= kUseLCD_DistanceFieldEffectFlag;
DFGPFlags |= kLCDBGRDistanceField_MaskType == maskType ? kBGR_DistanceFieldEffectFlag : 0;
}
static const int kDistanceAdjustLumShift = 5;
void GrAtlasTextOp::init() {
const Geometry& geo = fGeoData[0];
if (this->usesDistanceFields()) {
bool isLCD = this->isLCD();
const SkMatrix& drawMatrix = geo.fDrawMatrix;
fDFGPFlags = drawMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
fDFGPFlags |= drawMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0;
fDFGPFlags |= drawMatrix.hasPerspective() ? kPerspective_DistanceFieldEffectFlag : 0;
fDFGPFlags |= fUseGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFlag : 0;
fDFGPFlags |= (kAliasedDistanceField_MaskType == fMaskType)
? kAliased_DistanceFieldEffectFlag
: 0;
if (isLCD) {
fDFGPFlags |= kUseLCD_DistanceFieldEffectFlag;
fDFGPFlags |=
(kLCDBGRDistanceField_MaskType == fMaskType) ? kBGR_DistanceFieldEffectFlag : 0;
}
}
SkRect bounds = geo.fSubRunPtr->deviceRect(geo.fDrawMatrix, geo.fDrawOrigin);
// We don't have tight bounds on the glyph paths in device space. For the purposes of bounds
// we treat this as a set of non-AA rects rendered with a texture.
this->setBounds(bounds, HasAABloat::kNo, IsHairline::kNo);
return pool->allocate<GrAtlasTextOp>(maskType,
std::move(paint),
subrun,
drawMatrix,
drawOrigin,
clipRect,
filteredColor,
luminanceColor,
useGammaCorrectDistanceTable,
DFGPFlags);
}
void GrAtlasTextOp::visitProxies(const VisitProxyFunc& func) const {
@ -590,6 +616,8 @@ GrOp::CombineResult GrAtlasTextOp::onCombineIfPossible(GrOp* t, GrRecordingConte
return CombineResult::kMerged;
}
static const int kDistanceAdjustLumShift = 5;
// TODO trying to figure out why lcd is so whack
// (see comments in GrTextContext::ComputeCanonicalColor)
GrGeometryProcessor* GrAtlasTextOp::setupDfProcessor(SkArenaAlloc* arena,

View File

@ -36,29 +36,25 @@ public:
SkPMColor4f fColor;
};
static std::unique_ptr<GrAtlasTextOp> MakeBitmap(GrRecordingContext*,
GrPaint&&,
GrMaskFormat,
int glyphCount,
bool needsTransform);
static std::unique_ptr<GrAtlasTextOp> MakeBitmap(GrRecordingContext* context,
GrPaint&& paint,
GrTextBlob::SubRun* subrun,
const SkMatrix& drawMatrix,
SkPoint drawOrigin,
const SkIRect& clipRect,
const SkPMColor4f& filteredColor);
static std::unique_ptr<GrAtlasTextOp> MakeDistanceField(
GrRecordingContext*,
GrPaint&&,
int glyphCount,
GrTextBlob::SubRun*,
const SkMatrix& drawMatrix,
SkPoint drawOrigin,
const SkIRect& clipRect,
const SkPMColor4f& filteredColor,
bool useGammaCorrectDistanceTable,
SkColor luminanceColor,
const SkSurfaceProps&,
bool isAntiAliased,
bool useLCD);
// To avoid even the initial copy of the struct, we have a getter for the first item which
// is used to seed the op with its initial geometry. After seeding, the client should call
// init() so the op can initialize itself
Geometry& geometry() { return fGeoData[0]; }
/** Called after this->geometry() has been configured. */
void init();
const SkSurfaceProps&);
const char* name() const override { return "AtlasTextOp"; }
@ -94,10 +90,16 @@ private:
// The minimum number of Geometry we will try to allocate.
static constexpr auto kMinGeometryAllocated = 12;
GrAtlasTextOp(GrPaint&& paint)
: INHERITED(ClassID())
, fGeoDataAllocSize(kMinGeometryAllocated)
, fProcessors(std::move(paint)) {}
GrAtlasTextOp(MaskType maskType,
GrPaint&& paint,
GrTextBlob::SubRun* subrun,
const SkMatrix& drawMatrix,
SkPoint drawOrigin,
const SkIRect& clipRect,
const SkPMColor4f& filteredColor,
SkColor luminanceColor,
bool useGammaCorrectDistanceTable,
uint32_t DFGPFlags);
struct FlushInfo {
sk_sp<const GrBuffer> fVertexBuffer;
@ -176,20 +178,18 @@ private:
const GrSurfaceProxyView* views,
unsigned int numActiveViews) const;
const MaskType fMaskType;
const bool fNeedsGlyphTransform;
const SkColor fLuminanceColor{0};
const bool fUseGammaCorrectDistanceTable{false};
// Distance field properties
const uint32_t fDFGPFlags;
SkAutoSTMalloc<kMinGeometryAllocated, Geometry> fGeoData;
int fGeoDataAllocSize;
GrProcessorSet fProcessors;
struct {
uint32_t fUsesLocalCoords : 1;
uint32_t fUseGammaCorrectDistanceTable : 1;
uint32_t fNeedsGlyphTransform : 1;
};
bool fUsesLocalCoords;
int fGeoCount;
int fNumGlyphs;
MaskType fMaskType;
// Distance field properties
SkColor fLuminanceColor;
uint32_t fDFGPFlags = 0;
typedef GrMeshDrawOp INHERITED;
};

View File

@ -583,7 +583,7 @@ void GrTextBlob::addOp(GrTextTarget* target,
}
}
auto op = this->makeOp(*subRun, glyphCount, deviceMatrix, drawOrigin, clipRect,
auto op = this->makeOp(*subRun, deviceMatrix, drawOrigin, clipRect,
paint, filteredColor, props, target);
if (op) {
if (skipClip) {
@ -600,8 +600,7 @@ void GrTextBlob::addOp(GrTextTarget* target,
const GrTextBlob::Key& GrTextBlob::key() const { return fKey; }
size_t GrTextBlob::size() const { return fSize; }
std::unique_ptr<GrDrawOp> GrTextBlob::test_makeOp(int glyphCount,
const SkMatrixProvider& matrixProvider,
std::unique_ptr<GrDrawOp> GrTextBlob::test_makeOp(const SkMatrixProvider& matrixProvider,
SkPoint drawOrigin,
const SkPaint& paint,
const SkPMColor4f& filteredColor,
@ -609,7 +608,7 @@ std::unique_ptr<GrDrawOp> GrTextBlob::test_makeOp(int glyphCount,
GrTextTarget* target) {
SubRun* info = fFirstSubRun;
SkIRect emptyRect = SkIRect::MakeEmpty();
return this->makeOp(*info, glyphCount, matrixProvider, drawOrigin, emptyRect, paint,
return this->makeOp(*info, matrixProvider, drawOrigin, emptyRect, paint,
filteredColor, props, target);
}
@ -716,7 +715,6 @@ void GrTextBlob::insertSubRun(SubRun* subRun) {
}
std::unique_ptr<GrAtlasTextOp> GrTextBlob::makeOp(SubRun& info,
int glyphCount,
const SkMatrixProvider& matrixProvider,
SkPoint drawOrigin,
const SkIRect& clipRect,
@ -724,30 +722,29 @@ std::unique_ptr<GrAtlasTextOp> GrTextBlob::makeOp(SubRun& info,
const SkPMColor4f& filteredColor,
const SkSurfaceProps& props,
GrTextTarget* target) {
GrMaskFormat format = info.maskFormat();
GrPaint grPaint;
target->makeGrPaint(info.maskFormat(), paint, matrixProvider, &grPaint);
std::unique_ptr<GrAtlasTextOp> op;
if (info.drawAsDistanceFields()) {
// TODO: Can we be even smarter based on the dest transfer function?
op = GrAtlasTextOp::MakeDistanceField(
target->getContext(), std::move(grPaint), glyphCount,
target->colorInfo().isLinearlyBlended(), SkPaintPriv::ComputeLuminanceColor(paint),
props, info.isAntiAliased(), info.hasUseLCDText());
return GrAtlasTextOp::MakeDistanceField(target->getContext(),
std::move(grPaint),
&info,
matrixProvider.localToDevice(),
drawOrigin,
clipRect,
filteredColor,
target->colorInfo().isLinearlyBlended(),
SkPaintPriv::ComputeLuminanceColor(paint),
props);
} else {
op = GrAtlasTextOp::MakeBitmap(target->getContext(), std::move(grPaint), format, glyphCount,
info.needsTransform());
return GrAtlasTextOp::MakeBitmap(target->getContext(),
std::move(grPaint),
&info,
matrixProvider.localToDevice(),
drawOrigin,
clipRect,
filteredColor);
}
GrAtlasTextOp::Geometry& geometry = op->geometry();
geometry.fDrawMatrix = matrixProvider.localToDevice();
geometry.fClipRect = clipRect;
geometry.fBlob = SkRef(this);
geometry.fSubRunPtr = &info;
geometry.fColor = info.maskFormat() == kARGB_GrMaskFormat ? SK_PMColor4fWHITE : filteredColor;
geometry.fDrawOrigin = drawOrigin;
op->init();
return op;
}
void GrTextBlob::processDeviceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables,

View File

@ -166,8 +166,7 @@ public:
size_t size() const;
// Internal test methods
std::unique_ptr<GrDrawOp> test_makeOp(int glyphCount,
const SkMatrixProvider& matrixProvider,
std::unique_ptr<GrDrawOp> test_makeOp(const SkMatrixProvider& matrixProvider,
SkPoint drawOrigin,
const SkPaint& paint,
const SkPMColor4f& filteredColor,
@ -220,7 +219,6 @@ private:
void insertSubRun(SubRun* subRun);
std::unique_ptr<GrAtlasTextOp> makeOp(SubRun& info,
int glyphCount,
const SkMatrixProvider& matrixProvider,
SkPoint drawOrigin,
const SkIRect& clipRect,