stroke-and-fill is deprecated, introduce simpler api

baby step for https://skia-review.googlesource.com/c/skia/+/158020/

Bug: skia:8428
Change-Id: I0411c52a4fb97755e1b06b2aba8cb969776309bc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290717
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-05-18 21:25:44 -04:00 committed by Skia Commit-Bot
parent ca76920e78
commit 1963009cd0
9 changed files with 51 additions and 42 deletions

View File

@ -38,7 +38,7 @@ protected:
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setStrokeWidth(15);
const SkScalar inset = paint.getStrokeWidth() + 4;
@ -82,7 +82,7 @@ DEF_SIMPLE_GM(addarc_meas, canvas, 2*R + 40, 2*R + 40) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
SkPaint measPaint;
measPaint.setAntiAlias(true);
@ -129,7 +129,7 @@ protected:
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setStrokeWidth(SK_Scalar1 / 2);
const SkScalar delta = paint.getStrokeWidth() * 3 / 2;
@ -179,7 +179,7 @@ protected:
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setStrokeWidth(SK_Scalar1 / 2);
const SkScalar strokeWidth = paint.getStrokeWidth();
@ -188,7 +188,7 @@ protected:
SkRandom rand;
// Reset style to fill. We only need stroke stype for producing delta and strokeWidth
paint.setStyle(SkPaint::kFill_Style);
paint.setStroke(false);
SkScalar sign = 1;
while (r.width() > strokeWidth * 2) {
@ -229,7 +229,7 @@ static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, Sk
DEF_SIMPLE_GM(manyarcs, canvas, 620, 330) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
canvas->translate(10, 10);
@ -274,7 +274,7 @@ DEF_SIMPLE_GM(manyarcs, canvas, 620, 330) {
DEF_SIMPLE_GM(tinyanglearcs, canvas, 620, 330) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
canvas->translate(50, 50);

View File

@ -97,7 +97,7 @@ protected:
// AA with stroke style
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStroke(true);
p.setStrokeWidth(SkIntToScalar(3));
fPaints.push_back(p);
}
@ -106,7 +106,7 @@ protected:
// AA with stroke style, width = 0
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStroke(true);
fPaints.push_back(p);
}

View File

@ -77,13 +77,13 @@ void draw_arcs(SkCanvas* canvas, std::function<void(SkPaint*)> configureStyle) {
#define DEF_ARC_GM(name) DEF_SIMPLE_GM(circular_arcs_##name, canvas, kW, kH)
DEF_ARC_GM(fill) {
auto setFill = [] (SkPaint*p) { p->setStyle(SkPaint::kFill_Style); };
auto setFill = [] (SkPaint*p) { p->setStroke(false); };
draw_arcs(canvas, setFill);
}
DEF_ARC_GM(hairline) {
auto setHairline = [] (SkPaint* p) {
p->setStyle(SkPaint::kStroke_Style);
p->setStroke(true);
p->setStrokeWidth(0.f);
};
draw_arcs(canvas, setHairline);
@ -91,7 +91,7 @@ DEF_ARC_GM(hairline) {
DEF_ARC_GM(stroke_butt) {
auto setStroke = [](SkPaint* p) {
p->setStyle(SkPaint::kStroke_Style);
p->setStroke(true);
p->setStrokeCap(SkPaint::kButt_Cap);
};
draw_arcs(canvas, setStroke);
@ -99,7 +99,7 @@ DEF_ARC_GM(stroke_butt) {
DEF_ARC_GM(stroke_square) {
auto setStroke = [] (SkPaint* p) {
p->setStyle(SkPaint::kStroke_Style);
p->setStroke(true);
p->setStrokeCap(SkPaint::kSquare_Cap);
};
draw_arcs(canvas, setStroke);
@ -107,7 +107,7 @@ DEF_ARC_GM(stroke_square) {
DEF_ARC_GM(stroke_round) {
auto setStroke = [] (SkPaint* p) {
p->setStyle(SkPaint::kStroke_Style);
p->setStroke(true);
p->setStrokeCap(SkPaint::kRound_Cap);
};
draw_arcs(canvas, setStroke);
@ -174,16 +174,16 @@ DEF_SIMPLE_GM(circular_arcs_weird, canvas, 1000, 400) {
// fill
paints.push_back();
// stroke
paints.push_back().setStyle(SkPaint::kStroke_Style);
paints.push_back().setStroke(true);
paints.back().setStrokeWidth(kS / 6.f);
// hairline
paints.push_back().setStyle(SkPaint::kStroke_Style);
paints.push_back().setStroke(true);
paints.back().setStrokeWidth(0.f);
// stroke and fill
paints.push_back().setStyle(SkPaint::kStrokeAndFill_Style);
paints.back().setStrokeWidth(kS / 6.f);
// dash effect
paints.push_back().setStyle(SkPaint::kStroke_Style);
paints.push_back().setStroke(true);
paints.back().setStrokeWidth(kS / 6.f);
constexpr SkScalar kDashIntervals[] = {kS / 15, 2 * kS / 15};
paints.back().setPathEffect(SkDashPathEffect::Make(kDashIntervals, 2, 0.f));
@ -235,7 +235,7 @@ DEF_SIMPLE_GM(onebadarc, canvas, 100, 100) {
SkPaint p0;
p0.setColor(SK_ColorRED);
p0.setStrokeWidth(15.f);
p0.setStyle(SkPaint::kStroke_Style);
p0.setStroke(true);
p0.setAlpha(100);
canvas->translate(20, 0);
canvas->drawPath(path, p0);
@ -251,7 +251,7 @@ DEF_SIMPLE_GM(crbug_888453, canvas, 480, 150) {
SkPaint fill;
fill.setAntiAlias(true);
SkPaint hairline = fill;
hairline.setStyle(SkPaint::kStroke_Style);
hairline.setStroke(true);
SkPaint stroke = hairline;
stroke.setStrokeWidth(2.0f);
int x = 4;
@ -323,7 +323,7 @@ DEF_SIMPLE_GM(circular_arc_stroke_matrix, canvas, 820, 1090) {
SkPaint paint;
paint.setStrokeCap(cap);
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setStrokeWidth(kStrokeWidth);
canvas->save();
canvas->translate(x * (2*kRadius + kPad), y * (2*kRadius + kPad));

View File

@ -112,7 +112,7 @@ protected:
for (int aa = 0; aa < 2; ++aa) {
paint.setAntiAlias(SkToBool(aa));
for (int fh = 0; fh < 2; ++fh) {
paint.setStyle(fh ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
paint.setStroke(fh != 0);
const SkRect& bounds = fPaths[p].getBounds();
canvas->save();
@ -148,7 +148,7 @@ DEF_SIMPLE_GM(arccirclegap, canvas, 250, 250) {
SkScalar radius = 1096.702150363923f;
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
canvas->drawCircle(c, radius, paint);
SkPath path;
path.moveTo(288.88884710654133f, -280.26680862609f);
@ -164,7 +164,7 @@ DEF_SIMPLE_GM(largecircle, canvas, 250, 250) {
SkScalar radius = 1096.702150363923f;
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
canvas->drawCircle(c, radius, paint);
}
@ -174,7 +174,7 @@ DEF_SIMPLE_GM(largeovals, canvas, 250, 250) {
SkRect r = SkRect::MakeXYWH(-520, -520, 5000, 4000);
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setStrokeWidth(100);
canvas->drawOval(r, paint);
r.offset(-15, -15);
@ -188,7 +188,7 @@ DEF_SIMPLE_GM(largeovals, canvas, 250, 250) {
canvas->rotate(1.0f);
r.offset(55, 55);
paint.setColor(SK_ColorGRAY);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setStrokeWidth(100);
canvas->drawOval(r, paint);
r.offset(-15, -15);

View File

@ -50,7 +50,7 @@ protected:
SkPaint refPaint;
refPaint.setAntiAlias(true);
refPaint.setColor(0xFFbf3f7f);
refPaint.setStyle(SkPaint::kStroke_Style);
refPaint.setStroke(true);
refPaint.setStrokeWidth(1);
const SkScalar radius = 125;
SkRect oval = SkRect::MakeLTRB(-radius - 20, -radius - 20, radius + 20, radius + 20);
@ -85,7 +85,7 @@ protected:
canvas->restore();
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStroke(true);
p.setStrokeWidth(10);
SkScalar intervals[4];
int intervalCount = dashExample.length;
@ -188,7 +188,7 @@ protected:
SkPaint paint;
paint.setAntiAlias(true);
paint.setStrokeWidth(kStrokeWidth);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
// Compute the union of bounds of all of our test cases.
SkRect bounds = SkRect::MakeEmpty();
@ -242,7 +242,7 @@ DEF_SIMPLE_GM(maddash, canvas, 1600, 1600) {
SkPaint p;
p.setColor(SK_ColorRED);
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStroke(true);
p.setStrokeWidth(380);
SkScalar intvls[] = { 2.5, 10 /* 1200 */ };

View File

@ -31,7 +31,7 @@ static void flower(SkCanvas* canvas, const SkPath& path, SkScalar intervals[2],
SkPaint::Join join) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setStrokeJoin(join);
paint.setStrokeWidth(42);
canvas->drawPath(path, paint);
@ -119,7 +119,7 @@ protected:
SkPaint hairlinePaint;
hairlinePaint.setAntiAlias(true);
hairlinePaint.setStyle(SkPaint::kStroke_Style);
hairlinePaint.setStroke(true);
hairlinePaint.setStrokeCap(SkPaint::kRound_Cap);
hairlinePaint.setStrokeWidth(2);
SkPaint normalPaint = hairlinePaint;

View File

@ -54,7 +54,7 @@ static void show_zero_len_dash(SkCanvas* canvas) {
SkPaint paint;
drawline(canvas, 2, 2, paint, SkIntToScalar(0));
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setStrokeWidth(SkIntToScalar(2));
canvas->translate(0, SkIntToScalar(20));
drawline(canvas, 4, 4, paint, SkIntToScalar(0));
@ -72,7 +72,7 @@ class DashingGM : public skiagm::GM {
};
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
canvas->translate(0, SK_ScalarHalf);
@ -156,7 +156,7 @@ class Dashing2GM : public skiagm::GM {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setStrokeWidth(SkIntToScalar(6));
SkRect bounds = SkRect::MakeWH(SkIntToScalar(120), SkIntToScalar(120));
@ -204,7 +204,7 @@ class Dashing3GM : public skiagm::GM {
bool circles) {
SkPaint p;
p.setColor(SK_ColorBLACK);
p.setStyle(SkPaint::kStroke_Style);
p.setStroke(true);
p.setStrokeWidth(SkIntToScalar(strokeWidth));
if (circles) {
@ -324,7 +324,7 @@ class Dashing4GM : public skiagm::GM {
};
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
canvas->translate(SK_ScalarHalf, SK_ScalarHalf);
@ -430,7 +430,7 @@ private:
};
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setStroke(true);
paint.setAntiAlias(fDoAA);
@ -489,7 +489,7 @@ DEF_SIMPLE_GM(longpathdash, canvas, 612, 612) {
}
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStroke(true);
p.setStrokeWidth(1);
const SkScalar intervals[] = { 1, 1 };
p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0));
@ -501,7 +501,7 @@ DEF_SIMPLE_GM(longpathdash, canvas, 612, 612) {
DEF_SIMPLE_GM(longlinedash, canvas, 512, 512) {
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStroke(true);
p.setStrokeWidth(80);
const SkScalar intervals[] = { 2, 2 };
@ -512,7 +512,7 @@ DEF_SIMPLE_GM(longlinedash, canvas, 512, 512) {
DEF_SIMPLE_GM(longwavyline, canvas, 512, 512) {
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStroke(true);
p.setStrokeWidth(2);
SkPath wavy;
@ -527,7 +527,7 @@ DEF_SIMPLE_GM(longwavyline, canvas, 512, 512) {
DEF_SIMPLE_GM(dashtextcaps, canvas, 512, 512) {
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStroke(true);
p.setStrokeWidth(10);
p.setStrokeCap(SkPaint::kRound_Cap);
p.setStrokeJoin(SkPaint::kRound_Join);
@ -546,7 +546,7 @@ DEF_SIMPLE_GM(dash_line_zero_off_interval, canvas, 160, 330) {
SkPaint dashPaint;
dashPaint.setPathEffect(SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), 0.f));
SkASSERT(dashPaint.getPathEffect());
dashPaint.setStyle(SkPaint::kStroke_Style);
dashPaint.setStroke(true);
dashPaint.setStrokeWidth(20.f);
static constexpr struct {
SkPoint fA, fB;

View File

@ -235,6 +235,11 @@ public:
*/
void setStyle(Style style);
/**
* Set paint's style to kStroke if true, or kFill if false.
*/
void setStroke(bool);
/** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
a color component.

View File

@ -109,6 +109,10 @@ void SkPaint::setStyle(Style style) {
}
}
void SkPaint::setStroke(bool isStroke) {
fBitfields.fStyle = isStroke ? kStroke_Style : kFill_Style;
}
void SkPaint::setColor(SkColor color) {
fColor4f = SkColor4f::FromColor(color);
}