Use factories to avoid using (deprecated) path editing methods
Change-Id: Iae9944f6bba5a91c4643b3c3745c4c352bd07a17 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/312845 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
a1c4f1ad51
commit
58cc97a11f
@ -69,8 +69,7 @@ SkPath SkSVGCircle::onAsPath(const SkSVGRenderContext& ctx) const {
|
||||
SkScalar r;
|
||||
std::tie(pos, r) = this->resolve(ctx.lengthContext());
|
||||
|
||||
SkPath path;
|
||||
path.addCircle(pos.x(), pos.y(), r);
|
||||
SkPath path = SkPath::Circle(pos.x(), pos.y(), r);
|
||||
this->mapToParent(&path);
|
||||
|
||||
return path;
|
||||
|
@ -72,8 +72,7 @@ void SkSVGEllipse::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
|
||||
}
|
||||
|
||||
SkPath SkSVGEllipse::onAsPath(const SkSVGRenderContext& ctx) const {
|
||||
SkPath path;
|
||||
path.addOval(this->resolve(ctx.lengthContext()));
|
||||
SkPath path = SkPath::Oval(this->resolve(ctx.lengthContext()));
|
||||
this->mapToParent(&path);
|
||||
|
||||
return path;
|
||||
|
@ -14,10 +14,8 @@
|
||||
SkSVGPoly::SkSVGPoly(SkSVGTag t) : INHERITED(t) {}
|
||||
|
||||
void SkSVGPoly::setPoints(const SkSVGPointsType& pts) {
|
||||
fPath.reset();
|
||||
fPath.addPoly(pts.begin(),
|
||||
pts.count(),
|
||||
this->tag() == SkSVGTag::kPolygon); // only polygons are auto-closed
|
||||
fPath = SkPath::Polygon(pts.begin(), pts.count(),
|
||||
this->tag() == SkSVGTag::kPolygon); // only polygons are auto-closed
|
||||
}
|
||||
|
||||
void SkSVGPoly::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
||||
|
@ -88,8 +88,7 @@ void SkSVGRect::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
|
||||
}
|
||||
|
||||
SkPath SkSVGRect::onAsPath(const SkSVGRenderContext& ctx) const {
|
||||
SkPath path;
|
||||
path.addRRect(this->resolve(ctx.lengthContext()));
|
||||
SkPath path = SkPath::RRect(this->resolve(ctx.lengthContext()));
|
||||
|
||||
this->mapToParent(&path);
|
||||
|
||||
|
@ -28,8 +28,8 @@ protected:
|
||||
fY = 50;
|
||||
fR = 40;
|
||||
|
||||
fCircle1.addCircle(fX1, fY, fR, SkPathDirection::kCW);
|
||||
fCircle2.addCircle(fX2, fY, fR, SkPathDirection::kCW);
|
||||
fCircle1 = SkPath::Circle(fX1, fY, fR, SkPathDirection::kCW);
|
||||
fCircle2 = SkPath::Circle(fX2, fY, fR, SkPathDirection::kCW);
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,27 +67,27 @@ protected:
|
||||
|
||||
fRects[0].setLTRB(xB, yB, xE, yE);
|
||||
fRRects[0].setRectXY(fRects[0], 7, 7);
|
||||
fPaths[0].addRoundRect(fRects[0], 5, 5);
|
||||
fPaths[0] = SkPath::RRect(fRects[0], 5, 5);
|
||||
fRectColors[0] = SK_ColorRED;
|
||||
|
||||
fRects[1].setLTRB(xA, yA, xD, yD);
|
||||
fRRects[1].setRectXY(fRects[1], 7, 7);
|
||||
fPaths[1].addRoundRect(fRects[1], 5, 5);
|
||||
fPaths[1] = SkPath::RRect(fRects[1], 5, 5);
|
||||
fRectColors[1] = SK_ColorGREEN;
|
||||
|
||||
fRects[2].setLTRB(xC, yA, xF, yD);
|
||||
fRRects[2].setRectXY(fRects[2], 7, 7);
|
||||
fPaths[2].addRoundRect(fRects[2], 5, 5);
|
||||
fPaths[2] = SkPath::RRect(fRects[2], 5, 5);
|
||||
fRectColors[2] = SK_ColorBLUE;
|
||||
|
||||
fRects[3].setLTRB(xA, yC, xD, yF);
|
||||
fRRects[3].setRectXY(fRects[3], 7, 7);
|
||||
fPaths[3].addRoundRect(fRects[3], 5, 5);
|
||||
fPaths[3] = SkPath::RRect(fRects[3], 5, 5);
|
||||
fRectColors[3] = SK_ColorYELLOW;
|
||||
|
||||
fRects[4].setLTRB(xC, yC, xF, yF);
|
||||
fRRects[4].setRectXY(fRects[4], 7, 7);
|
||||
fPaths[4].addRoundRect(fRects[4], 5, 5);
|
||||
fPaths[4] = SkPath::RRect(fRects[4], 5, 5);
|
||||
fRectColors[4] = SK_ColorCYAN;
|
||||
|
||||
const SkClipOp ops[] = {
|
||||
|
@ -102,7 +102,7 @@ void test_hole(SkCanvas* canvas, const SkPaint& paint) {
|
||||
void test_star(SkCanvas* canvas, const SkPaint& paint) {
|
||||
canvas->save();
|
||||
canvas->translate(300, 100);
|
||||
canvas->drawPath(SkPath().addPoly({{30,20}, {50,80}, {70,20}, {20,57}, {80,57}}, false),
|
||||
canvas->drawPath(SkPath::Polygon({{30,20}, {50,80}, {70,20}, {20,57}, {80,57}}, false),
|
||||
paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ public:
|
||||
static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius,
|
||||
SkPathDirection dir = SkPathDirection::kCW);
|
||||
static SkPath RRect(const SkRRect&, SkPathDirection dir = SkPathDirection::kCW);
|
||||
static SkPath RRect(const SkRect& bounds, SkScalar rx, SkScalar ry,
|
||||
SkPathDirection dir = SkPathDirection::kCW);
|
||||
|
||||
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed,
|
||||
SkPathFillType = SkPathFillType::kWinding,
|
||||
@ -1071,6 +1073,10 @@ public:
|
||||
*/
|
||||
bool isRect(SkRect* rect, bool* isClosed = nullptr, SkPathDirection* direction = nullptr) const;
|
||||
|
||||
#ifdef SK_HIDE_PATH_EDIT_METHODS
|
||||
private:
|
||||
#endif
|
||||
|
||||
/** Adds SkRect to SkPath, appending kMove_Verb, three kLine_Verb, and kClose_Verb,
|
||||
starting with top-left corner of SkRect; followed by top-right, bottom-right,
|
||||
and bottom-left if dir is kCW_Direction; or followed by bottom-left,
|
||||
@ -1266,6 +1272,10 @@ public:
|
||||
return this->addPoly(list.begin(), SkToInt(list.size()), close);
|
||||
}
|
||||
|
||||
#ifdef SK_HIDE_PATH_EDIT_METHODS
|
||||
public:
|
||||
#endif
|
||||
|
||||
/** \enum SkPath::AddPathMode
|
||||
AddPathMode chooses how addPath() appends. Adding one SkPath to another can extend
|
||||
the last contour or start a new contour.
|
||||
|
@ -3421,6 +3421,10 @@ SkPath SkPath::RRect(const SkRRect& rr, SkPathDirection dir) {
|
||||
return SkPathBuilder().addRRect(rr, dir).detach();
|
||||
}
|
||||
|
||||
SkPath SkPath::RRect(const SkRect& r, SkScalar rx, SkScalar ry, SkPathDirection dir) {
|
||||
return SkPathBuilder().addRRect(SkRRect::MakeRectXY(r, rx, ry), dir).detach();
|
||||
}
|
||||
|
||||
SkPath SkPath::Polygon(const SkPoint pts[], int count, bool isClosed,
|
||||
SkPathFillType ft, bool isVolatile) {
|
||||
return SkPathBuilder().addPolygon(pts, count, isClosed)
|
||||
|
@ -100,12 +100,6 @@ private:
|
||||
|
||||
// Utility functions
|
||||
|
||||
static SkPath to_path(const SkRect& r) {
|
||||
SkPath p;
|
||||
p.addRect(r);
|
||||
return p;
|
||||
}
|
||||
|
||||
// This function destroys the mask and either frees or takes the pixels.
|
||||
sk_sp<SkImage> mask_to_greyscale_image(SkMask* mask) {
|
||||
sk_sp<SkImage> img;
|
||||
@ -211,7 +205,7 @@ static void set_style(SkTCopyOnFirstWrite<SkPaint>* paint, SkPaint::Style style)
|
||||
static bool calculate_inverse_path(const SkRect& bounds, const SkPath& invPath,
|
||||
SkPath* outPath) {
|
||||
SkASSERT(invPath.isInverseFillType());
|
||||
return Op(to_path(bounds), invPath, kIntersect_SkPathOp, outPath);
|
||||
return Op(SkPath::Rect(bounds), invPath, kIntersect_SkPathOp, outPath);
|
||||
}
|
||||
|
||||
SkBaseDevice* SkPDFDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint* layerPaint) {
|
||||
@ -356,8 +350,7 @@ void SkPDFDevice::drawAnnotation(const SkRect& rect, const char key[], SkData* v
|
||||
return;
|
||||
}
|
||||
// Convert to path to handle non-90-degree rotations.
|
||||
SkPath path = to_path(rect);
|
||||
path.transform(this->localToDevice(), &path);
|
||||
SkPath path = SkPath::Rect(rect).makeTransform(this->localToDevice());
|
||||
SkPath clip;
|
||||
SkClipStack_AsPath(this->cs(), &clip);
|
||||
Op(clip, path, kIntersect_SkPathOp, &path);
|
||||
@ -480,19 +473,15 @@ void SkPDFDevice::drawPoints(SkCanvas::PointMode mode,
|
||||
void SkPDFDevice::drawRect(const SkRect& rect, const SkPaint& paint) {
|
||||
SkRect r = rect;
|
||||
r.sort();
|
||||
this->internalDrawPath(this->cs(), this->localToDevice(), to_path(r), paint, true);
|
||||
this->internalDrawPath(this->cs(), this->localToDevice(), SkPath::Rect(r), paint, true);
|
||||
}
|
||||
|
||||
void SkPDFDevice::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
path.addRRect(rrect);
|
||||
this->internalDrawPath(this->cs(), this->localToDevice(), path, paint, true);
|
||||
this->internalDrawPath(this->cs(), this->localToDevice(), SkPath::RRect(rrect), paint, true);
|
||||
}
|
||||
|
||||
void SkPDFDevice::drawOval(const SkRect& oval, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
path.addOval(oval);
|
||||
this->internalDrawPath(this->cs(), this->localToDevice(), path, paint, true);
|
||||
this->internalDrawPath(this->cs(), this->localToDevice(), SkPath::Oval(oval), paint, true);
|
||||
}
|
||||
|
||||
void SkPDFDevice::drawPath(const SkPath& path, const SkPaint& paint, bool pathIsMutable) {
|
||||
@ -1007,7 +996,7 @@ void SkPDFDevice::drawDevice(SkBaseDevice* device, int x, int y, const SkPaint&
|
||||
}
|
||||
if (content.needShape()) {
|
||||
SkISize dim = device->imageInfo().dimensions();
|
||||
content.setShape(to_path(SkRect::Make(SkIRect::MakeXYWH(x, y, dim.width(), dim.height()))));
|
||||
content.setShape(SkPath::Rect(SkRect::Make(SkIRect::MakeXYWH(x, y, dim.width(), dim.height()))));
|
||||
}
|
||||
if (!content.needSource()) {
|
||||
return;
|
||||
@ -1588,7 +1577,7 @@ void SkPDFDevice::internalDrawImageRect(SkKeyedImage imageSubset,
|
||||
}
|
||||
if (paint->getMaskFilter()) {
|
||||
paint.writable()->setShader(imageSubset.image()->makeShader(&transform));
|
||||
SkPath path = to_path(dst); // handles non-integral clipping.
|
||||
SkPath path = SkPath::Rect(dst); // handles non-integral clipping.
|
||||
this->internalDrawPath(this->cs(), this->localToDevice(), path, *paint, true);
|
||||
return;
|
||||
}
|
||||
@ -1610,8 +1599,7 @@ void SkPDFDevice::internalDrawImageRect(SkKeyedImage imageSubset,
|
||||
// Transform the bitmap in the new space, without taking into
|
||||
// account the initial transform.
|
||||
SkRect imageBounds = SkRect::Make(imageSubset.image()->bounds());
|
||||
SkPath perspectiveOutline = to_path(imageBounds);
|
||||
perspectiveOutline.transform(transform);
|
||||
SkPath perspectiveOutline = SkPath::Rect(imageBounds).makeTransform(transform);
|
||||
|
||||
// TODO(edisonn): perf - use current clip too.
|
||||
// Retrieve the bounds of the new shape.
|
||||
@ -1622,8 +1610,7 @@ void SkPDFDevice::internalDrawImageRect(SkKeyedImage imageSubset,
|
||||
SkMatrix total = transform;
|
||||
total.postConcat(fInitialTransform);
|
||||
|
||||
SkPath physicalPerspectiveOutline = to_path(imageBounds);
|
||||
physicalPerspectiveOutline.transform(total);
|
||||
SkPath physicalPerspectiveOutline = SkPath::Rect(imageBounds).makeTransform(total);
|
||||
|
||||
SkRect physicalPerspectiveBounds =
|
||||
physicalPerspectiveOutline.getBounds();
|
||||
@ -1685,8 +1672,7 @@ void SkPDFDevice::internalDrawImageRect(SkKeyedImage imageSubset,
|
||||
return;
|
||||
}
|
||||
if (content.needShape()) {
|
||||
SkPath shape = to_path(SkRect::Make(subset));
|
||||
shape.transform(matrix);
|
||||
SkPath shape = SkPath::Rect(SkRect::Make(subset)).makeTransform(matrix);
|
||||
content.setShape(shape);
|
||||
}
|
||||
if (!content.needSource()) {
|
||||
|
@ -8,12 +8,6 @@
|
||||
#include "src/pdf/SkPDFUtils.h"
|
||||
#include "src/utils/SkClipStackUtils.h"
|
||||
|
||||
static SkPath to_path(const SkRect& r) {
|
||||
SkPath p;
|
||||
p.addRect(r);
|
||||
return p;
|
||||
}
|
||||
|
||||
static void emit_pdf_color(SkColor4f color, SkWStream* result) {
|
||||
SkASSERT(color.fA == 1); // We handle alpha elsewhere.
|
||||
SkPDFUtils::AppendColorComponentF(color.fR, result);
|
||||
@ -93,7 +87,7 @@ static void apply_clip(const SkClipStack& stack, const SkRect& outerBounds, F fn
|
||||
operand.isInverseFillType() ||
|
||||
!kHuge.contains(operand.getBounds()))
|
||||
{
|
||||
Op(to_path(bounds), operand, op, &operand);
|
||||
Op(SkPath::Rect(bounds), operand, op, &operand);
|
||||
}
|
||||
SkASSERT(!operand.isInverseFillType());
|
||||
fn(operand);
|
||||
@ -133,7 +127,7 @@ static void append_clip(const SkClipStack& clipStack,
|
||||
if (is_complex_clip(clipStack)) {
|
||||
SkPath clipPath;
|
||||
SkClipStack_AsPath(clipStack, &clipPath);
|
||||
if (Op(clipPath, to_path(outsetBounds), kIntersect_SkPathOp, &clipPath)) {
|
||||
if (Op(clipPath, SkPath::Rect(outsetBounds), kIntersect_SkPathOp, &clipPath)) {
|
||||
append_clip_path(clipPath, wStream);
|
||||
}
|
||||
// If Op() fails (pathological case; e.g. input values are
|
||||
|
@ -870,11 +870,8 @@ void SkSVGDevice::drawOval(const SkRect& oval, const SkPaint& paint) {
|
||||
}
|
||||
|
||||
void SkSVGDevice::drawRRect(const SkRRect& rr, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
path.addRRect(rr);
|
||||
|
||||
AutoElement elem("path", this, fResourceBucket.get(), MxCp(this), paint);
|
||||
elem.addPathAttributes(path);
|
||||
elem.addPathAttributes(SkPath::RRect(rr));
|
||||
}
|
||||
|
||||
void SkSVGDevice::drawPath(const SkPath& path, const SkPaint& paint, bool pathIsMutable) {
|
||||
|
Loading…
Reference in New Issue
Block a user