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

Commit 79c5674

Browse files
herbderbySkia Commit-Bot
authored andcommitted
Place transformed drawing data at source space (0,0)
The direct device remains fully positioned, and will be addressed in a following CL. This is a step towards making the vertex data constant. The path data is positioned at draw time instead of at creation time. The GPU data is not constant at this time, but when all the vertex data is placed at (0,0) the data can be const. Bug: skia:10251 Change-Id: I24991e1ba76ab77f06bf040d88de93bc31002b31 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/289880 Reviewed-by: Robert Phillips <[email protected]> Commit-Queue: Herb Derby <[email protected]>
1 parent dbb3e1d commit 79c5674

File tree

9 files changed

+25
-39
lines changed

9 files changed

+25
-39
lines changed

src/core/SkDraw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class SkDraw : public SkGlyphRunListPainter::BitmapDevicePainter {
8282

8383
void paintPaths(SkDrawableGlyphBuffer* drawables,
8484
SkScalar scale,
85+
SkPoint origin,
8586
const SkPaint& paint) const override;
8687

8788
void paintMasks(SkDrawableGlyphBuffer* drawables, const SkPaint& paint) const override;

src/core/SkDraw_text.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ void SkDraw::paintMasks(SkDrawableGlyphBuffer* drawables, const SkPaint& paint)
112112

113113
void SkDraw::paintPaths(SkDrawableGlyphBuffer* drawables,
114114
SkScalar scale,
115+
SkPoint origin,
115116
const SkPaint& paint) const {
116117
for (auto [variant, pos] : drawables->drawable()) {
117118
const SkPath* path = variant.path();
118119
SkMatrix m;
119-
m.setScaleTranslate(scale, scale, pos.x(), pos.y());
120+
SkPoint translate = origin + pos;
121+
m.setScaleTranslate(scale, scale, translate.x(), translate.y());
120122
this->drawPath(*path, paint, &m, false);
121123
}
122124
}

src/core/SkGlyphBuffer.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,7 @@ void SkDrawableGlyphBuffer::ensureSize(size_t size) {
2525
fDrawableSize = 0;
2626
}
2727

28-
void SkDrawableGlyphBuffer::startSource(
29-
const SkZip<const SkGlyphID, const SkPoint>& source, SkPoint origin) {
30-
fInputSize = source.size();
31-
fDrawableSize = 0;
32-
33-
// Map all the positions.
34-
auto positions = source.get<1>();
35-
SkMatrix::MakeTrans(origin.x(), origin.y()).mapPoints(
36-
fPositions, positions.data(), positions.size());
37-
38-
// Convert from SkGlyphIDs to SkPackedGlyphIDs.
39-
SkGlyphVariant* packedIDCursor = fMultiBuffer;
40-
for (auto t : source) {
41-
*packedIDCursor++ = SkPackedGlyphID{std::get<0>(t)};
42-
}
43-
SkDEBUGCODE(fPhase = kInput);
44-
}
45-
46-
void SkDrawableGlyphBuffer::startPaths(const SkZip<const SkGlyphID, const SkPoint> &source) {
28+
void SkDrawableGlyphBuffer::startSource(const SkZip<const SkGlyphID, const SkPoint>& source) {
4729
fInputSize = source.size();
4830
fDrawableSize = 0;
4931

src/core/SkGlyphBuffer.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,9 @@ class SkDrawableGlyphBuffer {
143143
public:
144144
void ensureSize(size_t size);
145145

146-
// Load the buffer with SkPackedGlyphIDs and positions in source space.
147-
void startSource(const SkZip<const SkGlyphID, const SkPoint>& source, SkPoint origin);
148-
149-
// Use the original glyphIDs and positions.
150-
void startPaths(const SkZip<const SkGlyphID, const SkPoint>& source);
146+
// Load the buffer with SkPackedGlyphIDs and positions at (0, 0) ready to finish positioning
147+
// during drawing.
148+
void startSource(const SkZip<const SkGlyphID, const SkPoint>& source);
151149

152150
// Load the buffer with SkPackedGlyphIDs and positions using the device transform.
153151
void startDevice(

src/core/SkGlyphRunPainter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
106106

107107
auto strike = strikeSpec.findOrCreateStrike();
108108

109-
fDrawable.startSource(fRejects.source(), drawOrigin);
109+
fDrawable.startSource(fRejects.source());
110110
strike->prepareForPathDrawing(&fDrawable, &fRejects);
111111
fRejects.flipRejectsToSource();
112112

@@ -115,7 +115,8 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
115115
SkPaint pathPaint = runPaint;
116116
pathPaint.setAntiAlias(runFont.hasSomeAntiAliasing());
117117

118-
bitmapDevice->paintPaths(&fDrawable, strikeSpec.strikeToSourceRatio(), pathPaint);
118+
bitmapDevice->paintPaths(
119+
&fDrawable, strikeSpec.strikeToSourceRatio(), drawOrigin, pathPaint);
119120
}
120121
if (!fRejects.source().empty()) {
121122
SkStrikeSpec strikeSpec = SkStrikeSpec::MakeMask(
@@ -167,7 +168,7 @@ void SkGlyphRunListPainter::processGlyphRunList(const SkGlyphRunList& glyphRunLi
167168
if (!strikeSpec.isEmpty()) {
168169
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
169170

170-
fDrawable.startSource(fRejects.source(), origin);
171+
fDrawable.startSource(fRejects.source());
171172
strike->prepareForSDFTDrawing(&fDrawable, &fRejects);
172173
fRejects.flipRejectsToSource();
173174

@@ -212,7 +213,7 @@ void SkGlyphRunListPainter::processGlyphRunList(const SkGlyphRunList& glyphRunLi
212213
if (!strikeSpec.isEmpty()) {
213214
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
214215

215-
fDrawable.startPaths(fRejects.source());
216+
fDrawable.startSource(fRejects.source());
216217
strike->prepareForPathDrawing(&fDrawable, &fRejects);
217218
fRejects.flipRejectsToSource();
218219
maxDimensionInSourceSpace =
@@ -235,7 +236,7 @@ void SkGlyphRunListPainter::processGlyphRunList(const SkGlyphRunList& glyphRunLi
235236
if (!strikeSpec.isEmpty()) {
236237
SkScopedStrikeForGPU strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
237238

238-
fDrawable.startSource(fRejects.source(), origin);
239+
fDrawable.startSource(fRejects.source());
239240
strike->prepareForMaskDrawing(&fDrawable, &fRejects);
240241
fRejects.flipRejectsToSource();
241242
SkASSERT(fRejects.source().empty());

src/core/SkGlyphRunPainter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class SkGlyphRunListPainter {
7070
virtual ~BitmapDevicePainter() = default;
7171

7272
virtual void paintPaths(
73-
SkDrawableGlyphBuffer* drawables, SkScalar scale, const SkPaint& paint) const = 0;
73+
SkDrawableGlyphBuffer* drawables, SkScalar scale, SkPoint origin,
74+
const SkPaint& paint) const = 0;
7475

7576
virtual void paintMasks(SkDrawableGlyphBuffer* drawables, const SkPaint& paint) const = 0;
7677
};

src/core/SkOverdrawCanvas.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TextDevice : public SkNoPixelsDevice, public SkGlyphRunListPainter::Bitmap
5050
fOverdrawCanvas{overdrawCanvas},
5151
fPainter{props, kN32_SkColorType, nullptr, SkStrikeCache::GlobalStrikeCache()} {}
5252

53-
void paintPaths(SkDrawableGlyphBuffer*, SkScalar scale, const SkPaint& paint) const override {}
53+
void paintPaths(SkDrawableGlyphBuffer*, SkScalar, SkPoint, const SkPaint&) const override {}
5454

5555
void paintMasks(SkDrawableGlyphBuffer* drawables, const SkPaint& paint) const override {
5656
for (auto t : drawables->drawable()) {

src/gpu/text/GrTextBlob.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ GrTextBlob::SubRun::SubRun(SubRunType type, GrTextBlob* textBlob, const SkStrike
5050
, fVertexData{vertexData}
5151
, fStrikeSpec{strikeSpec}
5252
, fCurrentColor{textBlob->fColor}
53-
, fCurrentOrigin{textBlob->fInitialOrigin}
53+
, fCurrentOrigin{this->needsTransform() ? SkPoint{0, 0} : textBlob->fInitialOrigin}
5454
, fCurrentMatrix{textBlob->fInitialMatrix} {
5555
SkASSERT(type != kTransformedPath);
5656
textBlob->insertSubRun(this);
@@ -143,13 +143,14 @@ void GrTextBlob::SubRun::appendGlyphs(const SkZip<SkGlyphVariant, SkPoint>& draw
143143
packedIDCursor++;
144144
}
145145

146-
// Use the negative initial origin to make the fVertexBounds {0, 0} based.
147-
SkPoint pt = fBlob->fInitialOrigin;
148146
if (!this->needsTransform()) {
147+
// Use the negative initial origin to make the fVertexBounds {0, 0} based.
148+
SkPoint pt = fBlob->fInitialOrigin;
149+
149150
// If the box is in device space, then transform the source space origin to device space.
150151
pt = fBlob->fInitialMatrix.mapXY(pt.x(), pt.y());
152+
fVertexBounds.offset(-pt);
151153
}
152-
fVertexBounds.offset(-pt);
153154
}
154155

155156
void GrTextBlob::SubRun::resetBulkUseToken() { fBulkUseToken.reset(); }

tests/SkGlyphBufferTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ DEF_TEST(SkDrawableGlyphBufferBasic, reporter) {
160160
{
161161
SkDrawableGlyphBuffer drawable;
162162
drawable.ensureSize(100);
163-
drawable.startSource(source, {100, 100});
163+
drawable.startSource(source);
164164
for (auto [i, packedID, pos] : SkMakeEnumerate(drawable.input())) {
165165
REPORTER_ASSERT(reporter, packedID.packedID().glyphID() == glyphIDs[i]);
166-
REPORTER_ASSERT(reporter, pos == positions[i] + SkPoint::Make(100, 100));
166+
REPORTER_ASSERT(reporter, pos == positions[i]);
167167
}
168168
}
169169

@@ -184,7 +184,7 @@ DEF_TEST(SkDrawableGlyphBufferBasic, reporter) {
184184
{
185185
SkDrawableGlyphBuffer drawable;
186186
drawable.ensureSize(100);
187-
drawable.startSource(source, {100, 100});
187+
drawable.startSource(source);
188188
for (auto [i, packedID, pos] : SkMakeEnumerate(drawable.input())) {
189189
drawable.push_back(&glyphs[i], i);
190190
}

0 commit comments

Comments
 (0)