[canvaskit] Clean up some APIs related to Path factories
These were uncovered during the recent documentation fiesta. This also adds a test for the previously untested CanvasKit.Path.MakeFromOp API. Bug: skia:10717 Change-Id: Icd3d31ec0f8d61bd399e76abdbf7b5c6395c4d85 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324626 Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
parent
efe767da91
commit
ffc20c2764
@ -6,10 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Breaking
|
||||
- `CanvasKit.MakePathFromSVGString` was renamed to `CanvasKit.Path.MakeFromSVGString`
|
||||
- `CanvasKit.MakePathFromOp` was renamed to `CanvasKit.Path.MakeFromOp`
|
||||
|
||||
### Changed
|
||||
- We now compile CanvasKit with emsdk 2.0.6 when testing and deploying to npm.
|
||||
- We no longer compile with rtti on, saving about 1% in code size.
|
||||
|
||||
### Removed
|
||||
- `CanvasKit.MakePathFromCmds`; Was deprecated in favor of `CanvasKit.Path.MakeFromCmds`.
|
||||
- `new CanvasKit.Path(path)` in favor of existing `path.copy()`.
|
||||
- Unused internal APIs (_getRasterN32PremulSurface, Drawable)
|
||||
|
||||
### Type Changes (index.d.ts)
|
||||
- Return value for MakeFromCmds correctly reflects the possibility of null.
|
||||
|
||||
## [0.19.0] - 2020-10-08
|
||||
|
||||
### Breaking
|
||||
|
37
modules/canvaskit/canvaskit/types/index.d.ts
vendored
37
modules/canvaskit/canvaskit/types/index.d.ts
vendored
@ -297,22 +297,6 @@ export interface CanvasKit {
|
||||
*/
|
||||
MakeImageFromCanvasImageSource(src: CanvasImageSource): Image;
|
||||
|
||||
/**
|
||||
* Creates a new path by combining the given paths according to op. If this fails, null will
|
||||
* be returned instead.
|
||||
* @param one
|
||||
* @param two
|
||||
* @param op
|
||||
*/
|
||||
MakePathFromOp(one: Path, two: Path, op: PathOp): Path | null;
|
||||
|
||||
/**
|
||||
* Creates a new path from the provided SVG string. If this fails, null will be
|
||||
* returned instead.
|
||||
* @param str
|
||||
*/
|
||||
MakePathFromSVGString(str: string): Path | null;
|
||||
|
||||
/**
|
||||
* Returns an SkPicture which has been serialized previously to the given bytes.
|
||||
* @param bytes
|
||||
@ -2860,10 +2844,27 @@ export interface MaskFilterFactory {
|
||||
*/
|
||||
export interface PathConstructorAndFactory extends DefaultConstructor<Path> {
|
||||
/**
|
||||
* Creates a new path from the given list of path commands.
|
||||
* Creates a new path from the given list of path commands. If this fails, null will be
|
||||
* returned instead.
|
||||
* @param cmds
|
||||
*/
|
||||
MakeFromCmds(cmds: PathCommand[]): Path;
|
||||
MakeFromCmds(cmds: PathCommand[]): Path | null;
|
||||
|
||||
/**
|
||||
* Creates a new path by combining the given paths according to op. If this fails, null will
|
||||
* be returned instead.
|
||||
* @param one
|
||||
* @param two
|
||||
* @param op
|
||||
*/
|
||||
MakeFromOp(one: Path, two: Path, op: PathOp): Path | null;
|
||||
|
||||
/**
|
||||
* Creates a new path from the provided SVG string. If this fails, null will be
|
||||
* returned instead.
|
||||
* @param str
|
||||
*/
|
||||
MakeFromSVGString(str: string): Path | null;
|
||||
|
||||
/**
|
||||
* Creates a new path using the provided verbs and associated points and weights. The process
|
||||
|
@ -770,16 +770,8 @@ EMSCRIPTEN_BINDINGS(Skia) {
|
||||
SkImageInfo imageInfo = toSkImageInfo(ii);
|
||||
return SkSurface::MakeRasterDirect(imageInfo, pixels, rowBytes, nullptr);
|
||||
}), allow_raw_pointers());
|
||||
function("_getRasterN32PremulSurface", optional_override([](int width, int height)->sk_sp<SkSurface> {
|
||||
return SkSurface::MakeRasterN32Premul(width, height, nullptr);
|
||||
}), allow_raw_pointers());
|
||||
|
||||
function("getDataBytes", &getSkDataBytes, allow_raw_pointers());
|
||||
// TODO(kjlubick) deprecate these path constructors and move them to class functions.
|
||||
#ifdef SK_INCLUDE_PATHOPS
|
||||
function("MakePathFromOp", &MakePathFromOp);
|
||||
#endif
|
||||
function("MakePathFromSVGString", &MakePathFromSVGString);
|
||||
|
||||
// These won't be called directly, there are corresponding JS helpers to deal with arrays.
|
||||
function("_MakeImage", optional_override([](SimpleImageInfo ii,
|
||||
@ -1200,10 +1192,6 @@ EMSCRIPTEN_BINDINGS(Skia) {
|
||||
.smart_ptr<sk_sp<SkData>>("sk_sp<Data>>")
|
||||
.function("size", &SkData::size);
|
||||
|
||||
// TODO(kjlubick) I think this can be deleted since AnimatedImage is no longer around.
|
||||
class_<SkDrawable>("Drawable")
|
||||
.smart_ptr<sk_sp<SkDrawable>>("sk_sp<Drawable>>");
|
||||
|
||||
#ifndef SK_NO_FONTS
|
||||
class_<SkFont>("Font")
|
||||
.constructor<>()
|
||||
@ -1439,8 +1427,10 @@ EMSCRIPTEN_BINDINGS(Skia) {
|
||||
// TODO(kjlubick, reed) Make SkPath immutable and only creatable via a factory/builder.
|
||||
class_<SkPath>("Path")
|
||||
.constructor<>()
|
||||
// TODO(kjlubick) remove this constructor in favor of the .copy() method.
|
||||
.constructor<const SkPath&>()
|
||||
#ifdef SK_INCLUDE_PATHOPS
|
||||
.class_function("MakeFromOp", &MakePathFromOp)
|
||||
#endif
|
||||
.class_function("MakeFromSVGString", &MakePathFromSVGString)
|
||||
.class_function("_MakeFromCmds", &MakePathFromCmds)
|
||||
.class_function("_MakeFromVerbsPointsWeights", &MakePathFromVerbsPointsWeights)
|
||||
.function("_addArc", optional_override([](SkPath& self,
|
||||
|
@ -48,9 +48,6 @@ var CanvasKit = {
|
||||
MakeImageFromEncoded: function() {},
|
||||
MakeImageFromCanvasImageSource: function() {},
|
||||
MakeOnScreenGLSurface: function() {},
|
||||
MakePathFromCmds: function() {},
|
||||
MakePathFromOp: function() {},
|
||||
MakePathFromSVGString: function() {},
|
||||
MakeRenderTarget: function() {},
|
||||
MakePicture: function() {},
|
||||
MakeSWCanvasSurface: function() {},
|
||||
@ -86,13 +83,11 @@ var CanvasKit = {
|
||||
_MakeManagedAnimation: function() {},
|
||||
_MakeParticles: function() {},
|
||||
_MakePicture: function() {},
|
||||
_MakeVertices: function() {},
|
||||
_MakeTwoPointConicalGradientShader: function() {},
|
||||
_decodeAnimatedImage: function() {},
|
||||
_decodeImage: function() {},
|
||||
_drawShapedText: function() {},
|
||||
_getRasterDirectSurface: function() {},
|
||||
_getRasterN32PremulSurface: function() {},
|
||||
|
||||
// The testing object is meant to expose internal functions
|
||||
// for more fine-grained testing, e.g. parseColor
|
||||
@ -496,6 +491,8 @@ var CanvasKit = {
|
||||
Path: {
|
||||
// public API (from C++ and JS bindings)
|
||||
MakeFromCmds: function() {},
|
||||
MakeFromSVGString: function() {},
|
||||
MakeFromOp: function() {},
|
||||
MakeFromVerbsPointsWeights: function() {},
|
||||
contains: function() {},
|
||||
/** @return {CanvasKit.Path} */
|
||||
@ -539,7 +536,6 @@ var CanvasKit = {
|
||||
rArcTo: function() {},
|
||||
rConicTo: function() {},
|
||||
rCubicTo: function() {},
|
||||
rect: function() {},
|
||||
rLineTo: function() {},
|
||||
rMoveTo: function() {},
|
||||
rQuadTo: function() {},
|
||||
@ -640,7 +636,6 @@ var CanvasKit = {
|
||||
|
||||
// private API
|
||||
_flush: function() {},
|
||||
_getRasterN32PremulSurface: function() {},
|
||||
_makeImageSnapshot: function() {},
|
||||
delete: function() {},
|
||||
},
|
||||
|
@ -145,7 +145,7 @@ function rect(skpath, x, y, width, height) {
|
||||
function Path2D(path) {
|
||||
this._path = null;
|
||||
if (typeof path === 'string') {
|
||||
this._path = CanvasKit.MakePathFromSVGString(path);
|
||||
this._path = CanvasKit.Path.MakeFromSVGString(path);
|
||||
} else if (path && path._getPath) {
|
||||
this._path = path._getPath().copy();
|
||||
} else {
|
||||
|
@ -579,9 +579,6 @@ CanvasKit.onRuntimeInitialized = function() {
|
||||
return path;
|
||||
};
|
||||
|
||||
// Deprecated
|
||||
CanvasKit.MakePathFromCmds = CanvasKit.Path.MakeFromCmds;
|
||||
|
||||
// The weights array is optional (only used for conics).
|
||||
CanvasKit.Path.MakeFromVerbsPointsWeights = function(verbs, pts, weights) {
|
||||
var verbsPtr = copy1dArray(verbs, 'HEAPU8');
|
||||
|
@ -64,7 +64,8 @@ describe('Path Behavior', () => {
|
||||
it('can create a path from an SVG string', () => {
|
||||
//.This is a parallelogram from
|
||||
// https://upload.wikimedia.org/wikipedia/commons/e/e7/Simple_parallelogram.svg
|
||||
const path = CanvasKit.MakePathFromSVGString('M 205,5 L 795,5 L 595,295 L 5,295 L 205,5 z');
|
||||
const path = CanvasKit.Path.MakeFromSVGString(
|
||||
'M 205,5 L 795,5 L 595,295 L 5,295 L 205,5 z');
|
||||
|
||||
const cmds = path.toCmds();
|
||||
expect(cmds).toBeTruthy();
|
||||
@ -80,6 +81,27 @@ describe('Path Behavior', () => {
|
||||
path.delete();
|
||||
});
|
||||
|
||||
it('can create a path by combining two other paths', () => {
|
||||
// Get the intersection of two overlapping squares and verify that it is the smaller square.
|
||||
const pathOne = new CanvasKit.Path();
|
||||
pathOne.addRect([10, 10, 20, 20]);
|
||||
|
||||
const pathTwo = new CanvasKit.Path();
|
||||
pathTwo.addRect([15, 15, 30, 30]);
|
||||
|
||||
const path = CanvasKit.Path.MakeFromOp(pathOne, pathTwo, CanvasKit.PathOp.Intersect);
|
||||
const cmds = path.toCmds();
|
||||
expect(cmds).toBeTruthy();
|
||||
expect(cmds).toEqual([[CanvasKit.MOVE_VERB, 15, 15],
|
||||
[CanvasKit.LINE_VERB, 20, 15],
|
||||
[CanvasKit.LINE_VERB, 20, 20],
|
||||
[CanvasKit.LINE_VERB, 15, 20],
|
||||
[CanvasKit.CLOSE_VERB]]);
|
||||
path.delete();
|
||||
pathOne.delete();
|
||||
pathTwo.delete();
|
||||
});
|
||||
|
||||
it('can create an SVG string from a path', () => {
|
||||
const cmds = [[CanvasKit.MOVE_VERB, 205, 5],
|
||||
[CanvasKit.LINE_VERB, 795, 5],
|
||||
|
Loading…
Reference in New Issue
Block a user