Skip to content

Commit 54c1b3d

Browse files
kjlubickSkia Commit-Bot
authored andcommitted
[canvaskit] Remove Sk from nearly all function/type names.
This is a massive breaking change for all existing users of CanvasKit. It will be (one of the only) changes in 0.19.0 to make the transition easier. Suggested reviewing order: - index.d.ts (to see type changes). Notice SkPicture still has Sk prefix, but no other types do (this felt "right" since Sk is part of the name of the type, but I can be swayed on this). - canvaskit-wasm-tests.ts - tests/*.spec.js - interface.js and helper.js - html examples - markdown files Change-Id: I3b3d3815df2078f986893df3c70101d6248c117d Docs-Preview: https://skia.org/?cl=322617 Bug: skia:10717 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322617 Commit-Queue: Kevin Lubick <kjlubick@google.com> Reviewed-by: Nathaniel Nifong <nifong@google.com>
1 parent 99afada commit 54c1b3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1512
-1553
lines changed

demos.skia.org/demos/hello_world/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ <h1>Hello world</h1>
2626
throw 'Could not make surface';
2727
}
2828

29-
const paint = new CanvasKit.SkPaint();
29+
const paint = new CanvasKit.Paint();
3030
paint.setColor(CanvasKit.RED);
3131

32-
const textPaint = new CanvasKit.SkPaint();
33-
const textFont = new CanvasKit.SkFont(null, 20);
32+
const textPaint = new CanvasKit.Paint();
33+
const textFont = new CanvasKit.Font(null, 20);
3434

3535
function drawFrame(canvas) {
3636
canvas.drawRect(CanvasKit.LTRBRect(10, 10, 50, 50), paint);

demos.skia.org/demos/image_decode_web_worker/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Promise.all([
2020
throw 'Could not make main thread canvas surface';
2121
}
2222

23-
const paint = new CanvasKit.SkPaint();
23+
const paint = new CanvasKit.Paint();
2424
paint.setColor(CanvasKit.RED);
2525

2626
let decodedImage;
@@ -64,7 +64,7 @@ Promise.all([
6464
const decodedBuffer = e.data.decodedArrayBuffer;
6565
const pixels = new Uint8Array(decodedBuffer);
6666
decodedImage = CanvasKit.MakeImage(pixels, e.data.width, e.data.height,
67-
CanvasKit.AlphaType.Unpremul, CanvasKit.ColorType.RGBA_8888, CanvasKit.SkColorSpace.SRGB);
67+
CanvasKit.AlphaType.Unpremul, CanvasKit.ColorType.RGBA_8888, CanvasKit.ColorSpace.SRGB);
6868
});
6969
document.getElementById('clear-button').addEventListener('click', () => {
7070
if (decodedImage) {

demos.skia.org/demos/path_performance/shared.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class CanvasKitRenderer {
113113
}
114114
this.canvas = this.surface.getCanvas();
115115

116-
this.paint = new CanvasKit.SkPaint();
116+
this.paint = new CanvasKit.Paint();
117117
this.paint.setAntiAlias(true);
118118
this.paint.setStyle(CanvasKit.PaintStyle.Fill);
119119
}

modules/canvaskit/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Breaking
10+
- "Sk" has been removed from all names. e.g. `new CanvasKit.SkPaint()` becomes
11+
`new CanvasKit.Paint()`
12+
13+
### Removed
14+
- `Surface.captureFrameAsSkPicture`; it was deprecated previously.
15+
- `CanvasKit.MakeSkCornerPathEffect`, `CanvasKit.MakeSkDiscretePathEffect`,
16+
`CanvasKit.MakeBlurMaskFilter`, `CanvasKit.MakeSkDashPathEffect`,
17+
`CanvasKit.MakeLinearGradientShader`, `CanvasKit.MakeRadialGradientShader`,
18+
`CanvasKit.MakeTwoPointConicalGradientShader`; these were deprecated previously and have
19+
replacements like `CanvasKit.PathEffect.MakeDash`.
20+
- `Canvas.concat44`; it was deprecated previously, just use `Canvas.concat`
21+
922
## [0.18.1] - 2020-10-06
1023

1124
### Added

modules/canvaskit/canvaskit/example.html

Lines changed: 46 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
9999
return;
100100
}
101101

102-
const paint = new CanvasKit.SkPaint();
102+
const paint = new CanvasKit.Paint();
103103

104-
const fontMgr = CanvasKit.SkFontMgr.RefDefault();
104+
const fontMgr = CanvasKit.FontMgr.RefDefault();
105105
const roboto = fontMgr.MakeTypefaceFromData(robotoData);
106106

107-
const textPaint = new CanvasKit.SkPaint();
107+
const textPaint = new CanvasKit.Paint();
108108
textPaint.setColor(CanvasKit.RED);
109109
textPaint.setAntiAlias(true);
110110

111-
const textFont = new CanvasKit.SkFont(roboto, 30);
111+
const textFont = new CanvasKit.Font(roboto, 30);
112112

113113
let i = 0;
114114

@@ -120,7 +120,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
120120
// Some animations see performance improvements by marking their
121121
// paths as volatile.
122122
path.setIsVolatile(true);
123-
const dpe = CanvasKit.SkPathEffect.MakeDash([15, 5, 5, 10], i/5);
123+
const dpe = CanvasKit.PathEffect.MakeDash([15, 5, 5, 10], i/5);
124124
i++;
125125

126126
paint.setPathEffect(dpe);
@@ -165,13 +165,13 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
165165
}
166166

167167
function drawFrame(canvas) {
168-
const paint = new CanvasKit.SkPaint();
168+
const paint = new CanvasKit.Paint();
169169
paint.setStrokeWidth(1.0);
170170
paint.setAntiAlias(true);
171171
paint.setColor(CanvasKit.Color(0, 0, 0, 1.0));
172172
paint.setStyle(CanvasKit.PaintStyle.Stroke);
173173

174-
const path = new CanvasKit.SkPath();
174+
const path = new CanvasKit.Path();
175175
path.moveTo(10, 10);
176176
path.lineTo(100, 10);
177177
path.moveTo(10, 10);
@@ -197,13 +197,13 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
197197
}
198198

199199
function drawFrame(canvas) {
200-
const paint = new CanvasKit.SkPaint();
200+
const paint = new CanvasKit.Paint();
201201
paint.setStrokeWidth(1.0);
202202
paint.setAntiAlias(true);
203203
paint.setColor(CanvasKit.Color(0, 0, 0, 1.0));
204204
paint.setStyle(CanvasKit.PaintStyle.Stroke);
205205

206-
const path = new CanvasKit.SkPath();
206+
const path = new CanvasKit.Path();
207207
path.moveTo(20, 5);
208208
path.lineTo(30, 20);
209209
path.lineTo(40, 10);
@@ -229,7 +229,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
229229

230230
const rrect = CanvasKit.RRectXY([100, 10, 140, 62], 10, 4);
231231

232-
const rrectPath = new CanvasKit.SkPath().addRRect(rrect, true);
232+
const rrectPath = new CanvasKit.Path().addRRect(rrect, true);
233233

234234
canvas.drawPath(rrectPath, paint);
235235

@@ -256,15 +256,15 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
256256
return;
257257
}
258258

259-
let paint = new CanvasKit.SkPaint();
259+
let paint = new CanvasKit.Paint();
260260
paint.setAntiAlias(true);
261261
paint.setColor(CanvasKit.Color(0, 0, 0, 1.0));
262262
paint.setStyle(CanvasKit.PaintStyle.Stroke);
263263
paint.setStrokeWidth(4.0);
264-
paint.setPathEffect(CanvasKit.SkPathEffect.MakeCorner(50));
264+
paint.setPathEffect(CanvasKit.PathEffect.MakeCorner(50));
265265

266266
// Draw I N K
267-
let path = new CanvasKit.SkPath();
267+
let path = new CanvasKit.Path();
268268
path.moveTo(80, 30);
269269
path.lineTo(80, 80);
270270

@@ -305,7 +305,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
305305
paint = paint.copy();
306306
paint.setColor(CanvasKit.Color(Math.random() * 255, Math.random() * 255, Math.random() * 255, Math.random() + .2));
307307
paints.push(paint);
308-
path = new CanvasKit.SkPath();
308+
path = new CanvasKit.Path();
309309
paths.push(path);
310310
path.moveTo(e.offsetX, e.offsetY);
311311
}
@@ -320,7 +320,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
320320
}
321321

322322
function starPath(CanvasKit, X=128, Y=128, R=116) {
323-
let p = new CanvasKit.SkPath();
323+
let p = new CanvasKit.Path();
324324
p.moveTo(X + R, Y);
325325
for (let i = 1; i < 8; i++) {
326326
let a = 2.6927937 * i;
@@ -864,14 +864,14 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
864864
return;
865865
}
866866
const canvas = surface.getCanvas();
867-
let paint = new CanvasKit.SkPaint();
867+
let paint = new CanvasKit.Paint();
868868

869869
// See https://fiddle.skia.org/c/f48b22eaad1bb7adcc3faaa321754af6
870870
// for original c++ version.
871871
let points = [[ 0, 0 ], [ 250, 0 ], [ 100, 100 ], [ 0, 250 ]];
872872
let colors = [CanvasKit.RED, CanvasKit.BLUE,
873873
CanvasKit.YELLOW, CanvasKit.CYAN];
874-
let vertices = CanvasKit.MakeSkVertices(CanvasKit.VertexMode.TriangleFan,
874+
let vertices = CanvasKit.MakeVertices(CanvasKit.VertexMode.TriangleFan,
875875
points, null, colors,
876876
false /*isVolatile*/);
877877

@@ -883,10 +883,10 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
883883
// for original c++ version.
884884
points = [[ 300, 300 ], [ 50, 300 ], [ 200, 200 ], [ 300, 50 ]];
885885
let texs = [[ 0, 0 ], [ 0, 250 ], [ 250, 250 ], [ 250, 0 ]];
886-
vertices = CanvasKit.MakeSkVertices(CanvasKit.VertexMode.TriangleFan,
886+
vertices = CanvasKit.MakeVertices(CanvasKit.VertexMode.TriangleFan,
887887
points, texs, colors);
888888

889-
let shader = CanvasKit.SkShader.MakeLinearGradient([0, 0], [250, 0],
889+
let shader = CanvasKit.Shader.MakeLinearGradient([0, 0], [250, 0],
890890
colors, null, CanvasKit.TileMode.Clamp);
891891
paint.setShader(shader);
892892

@@ -905,7 +905,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
905905
return;
906906
}
907907
const canvas = surface.getCanvas();
908-
let paint = new CanvasKit.SkPaint();
908+
let paint = new CanvasKit.Paint();
909909

910910
// See https://fiddle.skia.org/c/f48b22eaad1bb7adcc3faaa321754af6
911911
// for original c++ version.
@@ -915,12 +915,12 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
915915
let transform = [2, 0, 0,
916916
0, 2, 0,
917917
0, 0, 1]
918-
let shader = CanvasKit.SkShader.MakeRadialGradient([150,150], 130, colors,
918+
let shader = CanvasKit.Shader.MakeRadialGradient([150,150], 130, colors,
919919
pos, CanvasKit.TileMode.Mirror, transform);
920920

921921
paint.setShader(shader);
922-
const textFont = new CanvasKit.SkFont(null, 75);
923-
const textBlob = CanvasKit.SkTextBlob.MakeFromText('Radial', textFont);
922+
const textFont = new CanvasKit.Font(null, 75);
923+
const textBlob = CanvasKit.TextBlob.MakeFromText('Radial', textFont);
924924

925925
canvas.drawTextBlob(textBlob, 10, 200, paint);
926926
paint.delete()
@@ -939,15 +939,15 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
939939
return;
940940
}
941941
const canvas = surface.getCanvas();
942-
const paint = new CanvasKit.SkPaint();
942+
const paint = new CanvasKit.Paint();
943943
paint.setColor(CanvasKit.BLUE);
944944
paint.setStyle(CanvasKit.PaintStyle.Stroke);
945945

946-
const fontMgr = CanvasKit.SkFontMgr.RefDefault();
946+
const fontMgr = CanvasKit.FontMgr.RefDefault();
947947
const notoSerif = fontMgr.MakeTypefaceFromData(notoserifData);
948948

949-
const textPaint = new CanvasKit.SkPaint();
950-
const textFont = new CanvasKit.SkFont(notoSerif, 20);
949+
const textPaint = new CanvasKit.Paint();
950+
const textFont = new CanvasKit.Font(notoSerif, 20);
951951

952952
canvas.drawRect(CanvasKit.LTRBRect(30, 30, 200, 200), paint);
953953
canvas.drawText('This text is not shaped, and overflows the boundry',
@@ -971,7 +971,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
971971

972972
canvas.drawRect(bounds, paint);
973973
const SHAPE_TEST_TEXT = 'VAVAVAVAVAFIfi';
974-
const textFont2 = new CanvasKit.SkFont(notoSerif, 60);
974+
const textFont2 = new CanvasKit.Font(notoSerif, 60);
975975
const shapedText2 = new CanvasKit.ShapedText({
976976
font: textFont2,
977977
leftToRight: true,
@@ -1006,16 +1006,16 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
10061006
console.error('Could not make surface');
10071007
return;
10081008
}
1009-
const paint = new CanvasKit.SkPaint();
1009+
const paint = new CanvasKit.Paint();
10101010
paint.setColor(CanvasKit.BLUE);
10111011
paint.setStyle(CanvasKit.PaintStyle.Stroke);
10121012

1013-
const fontMgr = CanvasKit.SkFontMgr.RefDefault();
1013+
const fontMgr = CanvasKit.FontMgr.RefDefault();
10141014
const notoSerif = fontMgr.MakeTypefaceFromData(notoserifData);
10151015

1016-
const textPaint = new CanvasKit.SkPaint();
1017-
const bigFont = new CanvasKit.SkFont(notoSerif, 40);
1018-
const smallFont = new CanvasKit.SkFont(notoSerif, 25);
1016+
const textPaint = new CanvasKit.Paint();
1017+
const bigFont = new CanvasKit.Font(notoSerif, 40);
1018+
const smallFont = new CanvasKit.Font(notoSerif, 25);
10191019

10201020
const TEXT = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ac leo vitae ipsum hendrerit euismod quis rutrum nibh. Quisque non suscipit urna. Donec enim urna, facilisis vitae volutpat in, mattis at elit. Sed quis augue et dolor dignissim fringilla. Sed non massa eu neque tristique malesuada. ';
10211021

@@ -1062,22 +1062,22 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
10621062
return;
10631063
}
10641064
const canvas = surface.getCanvas();
1065-
const paint = new CanvasKit.SkPaint();
1065+
const paint = new CanvasKit.Paint();
10661066
paint.setStyle(CanvasKit.PaintStyle.Stroke);
10671067
paint.setAntiAlias(true);
10681068

1069-
const font = new CanvasKit.SkFont(null, 24);
1070-
const fontPaint = new CanvasKit.SkPaint();
1069+
const font = new CanvasKit.Font(null, 24);
1070+
const fontPaint = new CanvasKit.Paint();
10711071
fontPaint.setStyle(CanvasKit.PaintStyle.Fill);
10721072
fontPaint.setAntiAlias(true);
10731073

1074-
const arc = new CanvasKit.SkPath();
1074+
const arc = new CanvasKit.Path();
10751075
arc.arcToOval(CanvasKit.LTRBRect(20, 40, 280, 300), -160, 140, true);
10761076
arc.lineTo(210, 140);
10771077
arc.arcToOval(CanvasKit.LTRBRect(20, 0, 280, 260), 160, -140, true);
10781078

10791079
const str = 'This téxt should follow the curve across contours...';
1080-
const textBlob = CanvasKit.SkTextBlob.MakeOnPath(str, arc, font);
1080+
const textBlob = CanvasKit.TextBlob.MakeOnPath(str, arc, font);
10811081

10821082
canvas.drawPath(arc, paint);
10831083
canvas.drawTextBlob(textBlob, 0, 0, fontPaint);
@@ -1105,7 +1105,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
11051105
height: 50,
11061106
alphaType: CanvasKit.AlphaType.Premul,
11071107
colorType: CanvasKit.ColorType.RGBA_8888,
1108-
colorSpace: CanvasKit.SkColorSpace.SRGB,
1108+
colorSpace: CanvasKit.ColorSpace.SRGB,
11091109
});
11101110

11111111
if (!subSurface) {
@@ -1114,7 +1114,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
11141114
}
11151115

11161116
// draw a small "scene"
1117-
const paint = new CanvasKit.SkPaint();
1117+
const paint = new CanvasKit.Paint();
11181118
paint.setColor(CanvasKit.Color(139, 228, 135, 0.95)); // greenish
11191119
paint.setStyle(CanvasKit.PaintStyle.Fill);
11201120
paint.setAntiAlias(true);
@@ -1131,7 +1131,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
11311131
subCanvas.drawOval(CanvasKit.XYWHRect(x, y, 6, 6), paint);
11321132
}
11331133

1134-
// Snap it off as an SkImage - this image will be in the form the
1134+
// Snap it off as an Image - this image will be in the form the
11351135
// parent surface prefers (e.g. Texture for GPU / Raster for CPU).
11361136
const img = subSurface.makeImageSnapshot();
11371137

@@ -1141,7 +1141,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
11411141

11421142
// Make it repeat a bunch with a shader
11431143
const pattern = img.makeShader(CanvasKit.TileMode.Repeat, CanvasKit.TileMode.Mirror);
1144-
const patternPaint = new CanvasKit.SkPaint();
1144+
const patternPaint = new CanvasKit.Paint();
11451145
patternPaint.setShader(pattern);
11461146

11471147
let i = 0;
@@ -1170,18 +1170,18 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
11701170
}
11711171
const img = CanvasKit.MakeImageFromEncoded(imgData);
11721172

1173-
const paint = new CanvasKit.SkPaint();
1173+
const paint = new CanvasKit.Paint();
11741174
paint.setColor(CanvasKit.Color(0, 0, 0, 0.8));
11751175

1176-
const srcs = new CanvasKit.SkRectBuilder();
1176+
const srcs = new CanvasKit.RectBuilder();
11771177
srcs.push(0, 0, 250, 250 ); // LTRB
11781178
srcs.push(250, 0, 500, 250 );
11791179

11801180
const dsts = new CanvasKit.RSXFormBuilder();
11811181
dsts.push(.5, 0, 0, 0); // scos, ssin, tx, ty
11821182
dsts.push(0, .8, 200, 100);
11831183

1184-
const colors = new CanvasKit.SkColorBuilder();
1184+
const colors = new CanvasKit.ColorBuilder();
11851185
colors.push(CanvasKit.ColorAsInt(85, 170, 10, 128)); // light green
11861186
colors.push(CanvasKit.ColorAsInt(51, 51, 191, 128)); // light blue
11871187

@@ -1199,18 +1199,7 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
11991199
dsts.set(1, scale*Math.sin(i/20), scale*Math.cos(i/20), 200, 100);
12001200

12011201
canvas.drawAtlas(img, srcs, dsts, paint, CanvasKit.BlendMode.Plus, colors);
1202-
1203-
// Skip drawing the 17th frame to the screen, and instead draw it to
1204-
// an SkPicture - a format which can be useful for debugging.
1205-
// The C++ version of Skia can open a SKP created by the WASM version,
1206-
// which can aid performance diagnosis.
1207-
//if (i === 17) {
1208-
// const pic = surface.captureFrameAsSkPicture(drawFrame, "frame17.skp");
1209-
// pic.DEBUGONLY_saveAsFile("frame17.skp");
1210-
// pic.delete();
1211-
// } else {
1212-
surface.requestAnimationFrame(drawFrame);
1213-
// }
1202+
surface.requestAnimationFrame(drawFrame);
12141203
}
12151204
surface.requestAnimationFrame(drawFrame);
12161205

0 commit comments

Comments
 (0)