Skip to content

Commit c0d3495

Browse files
RusinoSkia Commit-Bot
authored andcommitted
Return to save/translate/restore for drawing via SkPicture
Can't really cache (x, y) in the picture - it's coming from the paint Change-Id: I4ff9abe19dcd5394b40af427dfab03e8c38fba0e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315648 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Julia Lavrova <jlavrova@google.com>
1 parent b6030fb commit c0d3495

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

modules/skparagraph/samples/SampleParagraph.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,8 +2904,7 @@ class ParagraphView46 : public ParagraphView_Base {
29042904

29052905
void onDrawContent(SkCanvas* canvas) override {
29062906

2907-
SkString text;
2908-
for (auto i = 0; i < 150; ++i) text.append("XXXXXXXXXX");
2907+
auto text = "XXXXXXXXXX\nYYYYYYYYYY\nZZZZZZZZZZ";
29092908
canvas->drawColor(SK_ColorWHITE);
29102909

29112910
auto fontCollection = sk_make_sp<FontCollection>();
@@ -2914,24 +2913,26 @@ class ParagraphView46 : public ParagraphView_Base {
29142913

29152914
ParagraphStyle paragraph_style;
29162915

2917-
auto draw = [&](DrawOptions options) {
2916+
auto column = width()/3;
2917+
auto draw = [&](DrawOptions options, SkScalar x) {
29182918
paragraph_style.setDrawOptions(options);
29192919
ParagraphBuilderImpl builder(paragraph_style, fontCollection);
29202920
TextStyle text_style;
29212921
text_style.setColor(SK_ColorBLACK);
29222922
text_style.setFontFamilies({SkString("Roboto")});
29232923
text_style.setFontSize(20);
29242924
builder.pushStyle(text_style);
2925-
builder.addText(text.c_str());
2925+
builder.addText(text);
29262926
auto paragraph = builder.Build();
2927-
paragraph->layout(width() / 3);
2928-
paragraph->paint(canvas, 0, 0);
2929-
canvas->translate(width() / 3, 0);
2927+
paragraph->layout(column);
2928+
paragraph->paint(canvas, x, 000);
2929+
paragraph->paint(canvas, x, 200);
2930+
paragraph->paint(canvas, x, 400);
29302931
};
29312932

2932-
draw(DrawOptions::kReplay);
2933-
draw(DrawOptions::kRecord);
2934-
draw(DrawOptions::kDirect);
2933+
draw(DrawOptions::kReplay, column*0);
2934+
draw(DrawOptions::kRecord, column*1);
2935+
draw(DrawOptions::kDirect, column*2);
29352936
}
29362937

29372938
private:

modules/skparagraph/src/ParagraphImpl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,20 @@ void ParagraphImpl::paint(SkCanvas* canvas, SkScalar x, SkScalar y) {
212212

213213
if (fState < kDrawn) {
214214
// Record the picture anyway (but if we have some pieces in the cache they will be used)
215-
this->paintLinesIntoPicture(x, y);
215+
this->paintLinesIntoPicture(0, 0);
216216
fState = kDrawn;
217217
}
218218

219219
if (fParagraphStyle.getDrawOptions() == DrawOptions::kReplay) {
220220
// Replay the recorded picture
221+
canvas->save();
222+
canvas->translate(x, y);
221223
fPicture->playback(canvas);
224+
canvas->restore();
222225
} else {
223226
// Draw the picture
224-
canvas->drawPicture(fPicture);
227+
SkMatrix matrix = SkMatrix::Translate(x, y);
228+
canvas->drawPicture(fPicture, &matrix, nullptr);
225229
}
226230
}
227231

0 commit comments

Comments
 (0)