Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4a1f5fc

Browse files
herbderbySkia Commit-Bot
authored andcommitted
move makeAtlasTextOp to SubRun
When SubRun is sub classable, makeAtlasTextOp will be part of the virtual API. Change-Id: Ib316bca200de38c5aba64e0bef5fa43966e6f13a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301983 Reviewed-by: Robert Phillips <[email protected]> Commit-Queue: Herb Derby <[email protected]>
1 parent 4284f75 commit 4a1f5fc

File tree

5 files changed

+140
-144
lines changed

5 files changed

+140
-144
lines changed

src/gpu/GrRenderTargetContext.cpp

Lines changed: 1 addition & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include "src/gpu/GrTracing.h"
4848
#include "src/gpu/SkGr.h"
4949
#include "src/gpu/effects/GrBicubicEffect.h"
50-
#include "src/gpu/effects/GrDistanceFieldGeoProc.h"
5150
#include "src/gpu/effects/GrRRectEffect.h"
5251
#include "src/gpu/geometry/GrQuad.h"
5352
#include "src/gpu/geometry/GrQuadUtils.h"
@@ -480,137 +479,6 @@ void GrRenderTargetContext::drawTextPaths(const GrClip* clip,
480479
}
481480
}
482481

483-
static SkPMColor4f generate_filtered_color(const SkPaint& paint, const GrColorInfo& colorInfo) {
484-
SkColor4f c = paint.getColor4f();
485-
if (auto* xform = colorInfo.colorSpaceXformFromSRGB()) {
486-
c = xform->apply(c);
487-
}
488-
if (auto* cf = paint.getColorFilter()) {
489-
c = cf->filterColor4f(c, colorInfo.colorSpace(), colorInfo.colorSpace());
490-
}
491-
return c.premul();
492-
}
493-
494-
std::tuple<const GrClip*, std::unique_ptr<GrDrawOp>>
495-
GrRenderTargetContext::makeAtlasTextOp(const GrClip* clip,
496-
const SkMatrixProvider& viewMatrix,
497-
const SkGlyphRunList& glyphRunList,
498-
GrTextBlob::SubRun* subRun) {
499-
SkASSERT(subRun->glyphCount() != 0);
500-
501-
SkPoint drawOrigin = glyphRunList.origin();
502-
const SkPaint& drawPaint = glyphRunList.paint();
503-
const SkMatrix& drawMatrix = viewMatrix.localToDevice();
504-
GrRecordingContext* context = this->fContext;
505-
GrOpMemoryPool* pool = context->priv().opMemoryPool();
506-
const GrColorInfo& colorInfo = this->colorInfo();
507-
508-
// We can clip geometrically using clipRect and ignore clip if we're not using SDFs or
509-
// transformed glyphs, and we have an axis-aligned rectangular non-AA clip.
510-
std::unique_ptr<GrDrawOp> op;
511-
if (!subRun->drawAsDistanceFields()) {
512-
SkIRect clipRect = SkIRect::MakeEmpty();
513-
if (!subRun->needsTransform()) {
514-
// We only need to do clipping work if the SubRun isn't contained by the clip
515-
SkRect subRunBounds = subRun->deviceRect(drawMatrix, drawOrigin);
516-
SkRect renderTargetBounds = SkRect::MakeWH(this->width(), this->height());
517-
if (clip == nullptr && !renderTargetBounds.intersects(subRunBounds)) {
518-
// If the SubRun is completely outside, don't add an op for it.
519-
return {nullptr, nullptr};
520-
} else if (clip != nullptr) {
521-
GrClip::PreClipResult result = clip->preApply(subRunBounds);
522-
if (result.fEffect == GrClip::Effect::kClipped) {
523-
if (result.fIsRRect && result.fRRect.isRect() &&
524-
result.fAA == GrAA::kNo) {
525-
// Clip geometrically during onPrepare using clipRect.
526-
result.fRRect.getBounds().round(&clipRect);
527-
clip = nullptr;
528-
}
529-
} else if (result.fEffect == GrClip::Effect::kClippedOut) {
530-
return {nullptr, nullptr};
531-
}
532-
}
533-
}
534-
535-
if (!clipRect.isEmpty()) { SkASSERT(clip == nullptr); }
536-
537-
// Produce the Bitmap Op.
538-
GrPaint grPaint;
539-
if (kARGB_GrMaskFormat == subRun->maskFormat()) {
540-
SkPaintToGrPaintWithPrimitiveColor(
541-
context, colorInfo, drawPaint, viewMatrix, &grPaint);
542-
} else {
543-
SkPaintToGrPaint(context, colorInfo, drawPaint, viewMatrix, &grPaint);
544-
}
545-
546-
// This is the color the op will use to draw.
547-
SkPMColor4f drawingColor = generate_filtered_color(drawPaint, colorInfo);
548-
549-
GrAtlasTextOp::MaskType maskType = [&]() {
550-
switch (subRun->maskFormat()) {
551-
case kA8_GrMaskFormat: return GrAtlasTextOp::kGrayscaleCoverageMask_MaskType;
552-
case kA565_GrMaskFormat: return GrAtlasTextOp::kLCDCoverageMask_MaskType;
553-
case kARGB_GrMaskFormat: return GrAtlasTextOp::kColorBitmapMask_MaskType;
554-
// Needed to placate some compilers.
555-
default: return GrAtlasTextOp::kGrayscaleCoverageMask_MaskType;
556-
}
557-
}();
558-
559-
op = pool->allocate<GrAtlasTextOp>(maskType,
560-
std::move(grPaint),
561-
subRun,
562-
drawMatrix,
563-
drawOrigin,
564-
clipRect,
565-
drawingColor,
566-
0,
567-
false,
568-
0);
569-
} else {
570-
GrPaint grPaint;
571-
SkPaintToGrPaint(context, colorInfo, drawPaint, viewMatrix, &grPaint);
572-
573-
// This is the color the op will use to draw.
574-
SkPMColor4f drawingColor = generate_filtered_color(drawPaint, colorInfo);
575-
576-
const SkSurfaceProps& props = this->surfaceProps();
577-
bool isBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
578-
bool isLCD = subRun->hasUseLCDText() && SkPixelGeometryIsH(props.pixelGeometry());
579-
using MT = GrAtlasTextOp::MaskType;
580-
MT maskType = !subRun->isAntiAliased() ? MT::kAliasedDistanceField_MaskType
581-
: isLCD ? (isBGR ? MT::kLCDBGRDistanceField_MaskType
582-
: MT::kLCDDistanceField_MaskType)
583-
: MT::kGrayscaleDistanceField_MaskType;
584-
585-
bool useGammaCorrectDistanceTable = colorInfo.isLinearlyBlended();
586-
uint32_t DFGPFlags = drawMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
587-
DFGPFlags |= drawMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0;
588-
DFGPFlags |= drawMatrix.hasPerspective() ? kPerspective_DistanceFieldEffectFlag : 0;
589-
DFGPFlags |= useGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFlag : 0;
590-
DFGPFlags |= MT::kAliasedDistanceField_MaskType == maskType ?
591-
kAliased_DistanceFieldEffectFlag : 0;
592-
593-
if (isLCD) {
594-
DFGPFlags |= kUseLCD_DistanceFieldEffectFlag;
595-
DFGPFlags |= MT::kLCDBGRDistanceField_MaskType == maskType ?
596-
kBGR_DistanceFieldEffectFlag : 0;
597-
}
598-
599-
op = pool->allocate<GrAtlasTextOp>(maskType,
600-
std::move(grPaint),
601-
subRun,
602-
drawMatrix,
603-
drawOrigin,
604-
SkIRect::MakeEmpty(),
605-
drawingColor,
606-
SkPaintPriv::ComputeLuminanceColor(drawPaint),
607-
useGammaCorrectDistanceTable,
608-
DFGPFlags);
609-
}
610-
611-
return {clip, std::move(op)};
612-
}
613-
614482
void GrRenderTargetContext::drawGlyphRunList(const GrClip* clip,
615483
const SkMatrixProvider& viewMatrix,
616484
const SkGlyphRunList& glyphRunList) {
@@ -694,7 +562,7 @@ void GrRenderTargetContext::drawGlyphRunList(const GrClip* clip,
694562
if (subRun->drawAsPaths()) {
695563
this->drawTextPaths(clip, viewMatrix, glyphRunList, subRun);
696564
} else {
697-
auto [drawingClip, op] = this->makeAtlasTextOp(clip, viewMatrix, glyphRunList, subRun);
565+
auto [drawingClip, op] = subRun->makeAtlasTextOp(clip, viewMatrix, glyphRunList, this);
698566
if (op != nullptr) {
699567
this->addDrawOp(drawingClip, std::move(op));
700568
}

src/gpu/GrRenderTargetContext.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,6 @@ class GrRenderTargetContext : public GrSurfaceContext, public GrOpsTaskClosedObs
518518
const SkGlyphRunList& glyphRunList,
519519
GrTextBlob::SubRun* subRun);
520520

521-
/**
522-
* Make the AtlasTextOp - returns the op and the original clip or nullptr for the clip if the
523-
* op is going to clip geometrically.
524-
*/
525-
std::tuple<const GrClip*, std::unique_ptr<GrDrawOp>>
526-
makeAtlasTextOp(const GrClip*,
527-
const SkMatrixProvider& viewMatrix,
528-
const SkGlyphRunList& glyphRunList,
529-
GrTextBlob::SubRun* subRun);
530-
531521
/**
532522
* Draw the text specified by the SkGlyphRunList.
533523
*

src/gpu/ops/GrAtlasTextOp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ std::unique_ptr<GrDrawOp> GrAtlasTextOp::CreateOpTestingOnly(GrRenderTargetConte
509509

510510
std::unique_ptr<GrDrawOp> op;
511511
std::tie(std::ignore, op) =
512-
rtc->makeAtlasTextOp(nullptr, mtxProvider, glyphRunList, blob->firstSubRun());
512+
blob->firstSubRun()->makeAtlasTextOp(nullptr, mtxProvider, glyphRunList, rtc);
513513
return op;
514514
}
515515

src/gpu/text/GrTextBlob.cpp

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "include/core/SkColorFilter.h"
99
#include "include/gpu/GrContext.h"
10+
#include "include/gpu/GrRecordingContext.h"
1011
#include "include/private/SkTemplates.h"
1112
#include "src/core/SkMaskFilterBase.h"
1213
#include "src/core/SkMatrixPriv.h"
@@ -15,7 +16,13 @@
1516
#include "src/core/SkStrikeSpec.h"
1617
#include "src/gpu/GrBlurUtils.h"
1718
#include "src/gpu/GrClip.h"
19+
#include "src/gpu/GrMemoryPool.h"
20+
#include "src/gpu/GrRecordingContextPriv.h"
21+
#include "src/gpu/GrRenderTargetContext.h"
22+
#include "src/gpu/GrRenderTargetContextPriv.h"
1823
#include "src/gpu/GrStyle.h"
24+
#include "src/gpu/SkGr.h"
25+
#include "src/gpu/effects/GrDistanceFieldGeoProc.h"
1926
#include "src/gpu/geometry/GrStyledShape.h"
2027
#include "src/gpu/ops/GrAtlasTextOp.h"
2128
#include "src/gpu/text/GrAtlasManager.h"
@@ -58,6 +65,130 @@ GrTextBlob::SubRun::SubRun(GrTextBlob* textBlob, const SkStrikeSpec& strikeSpec)
5865
, fVertexBounds{SkRect::MakeEmpty()}
5966
, fVertexData{SkSpan<VertexData>{}} { }
6067

68+
static SkPMColor4f generate_filtered_color(const SkPaint& paint, const GrColorInfo& colorInfo) {
69+
SkColor4f c = paint.getColor4f();
70+
if (auto* xform = colorInfo.colorSpaceXformFromSRGB()) {
71+
c = xform->apply(c);
72+
}
73+
if (auto* cf = paint.getColorFilter()) {
74+
c = cf->filterColor4f(c, colorInfo.colorSpace(), colorInfo.colorSpace());
75+
}
76+
return c.premul();
77+
}
78+
79+
std::tuple<const GrClip*, std::unique_ptr<GrDrawOp> >
80+
GrTextBlob::SubRun::makeAtlasTextOp(const GrClip* clip,
81+
const SkMatrixProvider& viewMatrix,
82+
const SkGlyphRunList& glyphRunList,
83+
GrRenderTargetContext* rtc) {
84+
SkASSERT(this->glyphCount() != 0);
85+
86+
SkPoint drawOrigin = glyphRunList.origin();
87+
const SkPaint& drawPaint = glyphRunList.paint();
88+
const SkMatrix& drawMatrix = viewMatrix.localToDevice();
89+
GrRecordingContext* context = rtc->priv().getContext();
90+
GrOpMemoryPool* pool = context->priv().opMemoryPool();
91+
const GrColorInfo& colorInfo = rtc->colorInfo();
92+
93+
// This is the color the op will use to draw.
94+
SkPMColor4f drawingColor = generate_filtered_color(drawPaint, colorInfo);
95+
96+
GrPaint grPaint;
97+
if (this->maskFormat() == kARGB_GrMaskFormat) {
98+
SkPaintToGrPaintWithPrimitiveColor(
99+
context, colorInfo, drawPaint, viewMatrix, &grPaint);
100+
} else {
101+
SkPaintToGrPaint(context, colorInfo, drawPaint, viewMatrix, &grPaint);
102+
}
103+
104+
// We can clip geometrically using clipRect and ignore clip if we're not using SDFs or
105+
// transformed glyphs, and we have an axis-aligned rectangular non-AA clip.
106+
std::unique_ptr<GrDrawOp> op;
107+
if (!this->drawAsDistanceFields()) {
108+
SkIRect clipRect = SkIRect::MakeEmpty();
109+
if (!this->needsTransform()) {
110+
// We only need to do clipping work if the SubRun isn't contained by the clip
111+
SkRect subRunBounds = this->deviceRect(drawMatrix, drawOrigin);
112+
SkRect renderTargetBounds = SkRect::MakeWH(rtc->width(), rtc->height());
113+
if (clip == nullptr && !renderTargetBounds.intersects(subRunBounds)) {
114+
// If the SubRun is completely outside, don't add an op for it.
115+
return {nullptr, nullptr};
116+
} else if (clip != nullptr) {
117+
GrClip::PreClipResult result = clip->preApply(subRunBounds);
118+
if (result.fEffect == GrClip::Effect::kClipped) {
119+
if (result.fIsRRect && result.fRRect.isRect() &&
120+
result.fAA == GrAA::kNo) {
121+
// Clip geometrically during onPrepare using clipRect.
122+
result.fRRect.getBounds().round(&clipRect);
123+
clip = nullptr;
124+
}
125+
} else if (result.fEffect == GrClip::Effect::kClippedOut) {
126+
return {nullptr, nullptr};
127+
}
128+
}
129+
}
130+
131+
if (!clipRect.isEmpty()) { SkASSERT(clip == nullptr); }
132+
133+
GrAtlasTextOp::MaskType maskType = [&]() {
134+
switch (this->maskFormat()) {
135+
case kA8_GrMaskFormat: return GrAtlasTextOp::kGrayscaleCoverageMask_MaskType;
136+
case kA565_GrMaskFormat: return GrAtlasTextOp::kLCDCoverageMask_MaskType;
137+
case kARGB_GrMaskFormat: return GrAtlasTextOp::kColorBitmapMask_MaskType;
138+
// Needed to placate some compilers.
139+
default: return GrAtlasTextOp::kGrayscaleCoverageMask_MaskType;
140+
}
141+
}();
142+
143+
op = pool->allocate<GrAtlasTextOp>(maskType,
144+
std::move(grPaint),
145+
this,
146+
drawMatrix,
147+
drawOrigin,
148+
clipRect,
149+
drawingColor,
150+
0,
151+
false,
152+
0);
153+
} else {
154+
const SkSurfaceProps& props = rtc->surfaceProps();
155+
bool isBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
156+
bool isLCD = this->hasUseLCDText() && SkPixelGeometryIsH(props.pixelGeometry());
157+
using MT = GrAtlasTextOp::MaskType;
158+
MT maskType = !this->isAntiAliased() ? MT::kAliasedDistanceField_MaskType
159+
: isLCD ? (isBGR ? MT::kLCDBGRDistanceField_MaskType
160+
: MT::kLCDDistanceField_MaskType)
161+
: MT::kGrayscaleDistanceField_MaskType;
162+
163+
bool useGammaCorrectDistanceTable = colorInfo.isLinearlyBlended();
164+
uint32_t DFGPFlags = drawMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
165+
DFGPFlags |= drawMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0;
166+
DFGPFlags |= drawMatrix.hasPerspective() ? kPerspective_DistanceFieldEffectFlag : 0;
167+
DFGPFlags |= useGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFlag : 0;
168+
DFGPFlags |= MT::kAliasedDistanceField_MaskType == maskType ?
169+
kAliased_DistanceFieldEffectFlag : 0;
170+
171+
if (isLCD) {
172+
DFGPFlags |= kUseLCD_DistanceFieldEffectFlag;
173+
DFGPFlags |= MT::kLCDBGRDistanceField_MaskType == maskType ?
174+
kBGR_DistanceFieldEffectFlag : 0;
175+
}
176+
177+
op = pool->allocate<GrAtlasTextOp>(maskType,
178+
std::move(grPaint),
179+
this,
180+
drawMatrix,
181+
drawOrigin,
182+
SkIRect::MakeEmpty(),
183+
drawingColor,
184+
SkPaintPriv::ComputeLuminanceColor(drawPaint),
185+
useGammaCorrectDistanceTable,
186+
DFGPFlags);
187+
}
188+
189+
return {clip, std::move(op)};
190+
}
191+
61192
void GrTextBlob::SubRun::resetBulkUseToken() { fBulkUseToken.reset(); }
62193

63194
GrDrawOpAtlas::BulkUseTokenUpdater* GrTextBlob::SubRun::bulkUseToken() { return &fBulkUseToken; }

src/gpu/text/GrTextBlob.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
class GrAtlasManager;
2626
class GrAtlasTextOp;
2727
class GrDeferredUploadTarget;
28+
class GrDrawOp;
2829
class GrGlyph;
2930
class GrStrikeCache;
3031

@@ -264,6 +265,12 @@ class GrTextBlob::SubRun {
264265
// SubRun for paths
265266
SubRun(GrTextBlob* textBlob, const SkStrikeSpec& strikeSpec);
266267

268+
std::tuple<const GrClip*, std::unique_ptr<GrDrawOp>>
269+
makeAtlasTextOp(const GrClip* clip,
270+
const SkMatrixProvider& viewMatrix,
271+
const SkGlyphRunList& glyphRunList,
272+
GrRenderTargetContext* rtc);
273+
267274
// TODO when this object is more internal, drop the privacy
268275
void resetBulkUseToken();
269276
GrDrawOpAtlas::BulkUseTokenUpdater* bulkUseToken();

0 commit comments

Comments
 (0)