Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f8823b5

Browse files
committed
Reland "[canvaskit] Change SkRects to be arrays, not objects."
This is a reland of bdc214a The CPU version of SkottieWasm is timing out for reasons unknown, but the GPU version is happy. I think we can get rid of the CPU version of the job since it has been more or less superseded by the SkottieFrames one (and the latter is more stable). Original change's description: > [canvaskit] Change SkRects to be arrays, not objects. > > This changes several APIs, so there are lots of breaking > notes in the Changelog. > > This made the "draw 100 colored regions" benchmark about > 20% faster (1ms -> .8ms). > > In theory, rendering should stay the same. > > Change-Id: Ib80b15e2d980ad5d568fff4460d2b529766c1b36 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/312491 > Reviewed-by: Nathaniel Nifong <nifong@google.com> Change-Id: I674aba85ecfb30b72e94cbaf89b2d97bfae3b7a4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315142 Reviewed-by: Nathaniel Nifong <nifong@google.com>
1 parent be72801 commit f8823b5

File tree

24 files changed

+619
-493
lines changed

24 files changed

+619
-493
lines changed

infra/bots/README.recipes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,9 @@ Run DM on lottie files with tracing turned on and then parse the output.
417417

418418
[DEPS](/infra/bots/recipes/perf_skottiewasm_lottieweb.py#12): [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/file][recipe_engine/recipe_modules/file], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/python][recipe_engine/recipe_modules/python], [recipe\_engine/step][recipe_engine/recipe_modules/step], [recipe\_engine/time][recipe_engine/recipe_modules/time], [checkout](#recipe_modules-checkout), [env](#recipe_modules-env), [flavor](#recipe_modules-flavor), [infra](#recipe_modules-infra), [run](#recipe_modules-run), [vars](#recipe_modules-vars)
419419

420-
&mdash; **def [RunSteps](/infra/bots/recipes/perf_skottiewasm_lottieweb.py#83)(api):**
420+
&mdash; **def [RunSteps](/infra/bots/recipes/perf_skottiewasm_lottieweb.py#84)(api):**
421421

422-
&mdash; **def [parse\_trace](/infra/bots/recipes/perf_skottiewasm_lottieweb.py#208)(trace_json, lottie_filename, api, renderer):**
422+
&mdash; **def [parse\_trace](/infra/bots/recipes/perf_skottiewasm_lottieweb.py#209)(trace_json, lottie_filename, api, renderer):**
423423

424424
parse_trace parses the specified trace JSON.
425425

infra/bots/recipes/perf_skottiewasm_lottieweb.expected/unrecognized_builder.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
" arg_names, **additional_args)",
3636
" File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/property_invoker.py\", in _invoke_with_properties",
3737
" return callable_obj(*props, **additional_args)",
38-
" File \"RECIPE_REPO[skia]/infra/bots/recipes/perf_skottiewasm_lottieweb.py\", line 128, in RunSteps",
38+
" File \"RECIPE_REPO[skia]/infra/bots/recipes/perf_skottiewasm_lottieweb.py\", line 129, in RunSteps",
3939
" raise Exception('Could not recognize the buildername %s' % buildername)",
4040
"Exception: Could not recognize the buildername Perf-Debian10-none-GCE-CPU-AVX2-x86_64-Release-All-Unrecognized"
4141
]

infra/bots/recipes/perf_skottiewasm_lottieweb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
'streetby_loading.json',
7070
'streetby_test_loading.json',
7171
# Times out
72+
'an_endless_hike_on_a_tiny_world_.json', # times out on CPU
7273
'beetle.json',
7374
]
7475

modules/canvaskit/CHANGELOG.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88

99
### Breaking
10+
- SkRect are no longer returned from `CanvasKit.LTRBRect`, `CanvasKit.XYWHRect` nor
11+
are accepted as JS objects. Instead, the format is 4 floats in either an array, a
12+
Float32Array or a piece of memory returned by CanvasKit.Malloc. These floats are the
13+
left, top, right, bottom numbers of the rectangle.
14+
- SkIRect (Rectangles with Integer values) are no longer accepted as JS objects.
15+
Instead, the format is 4 ints in either an array, an Int32Array or a piece of memory
16+
returned by CanvasKit.Malloc. These ints are the left, top, right, bottom numbers of
17+
the rectangle.
1018
- SkRRect (Rectangles with rounded corners) are no longer returned from `CanvasKit.RRectXY`
11-
nor accepted as JS objects. Instead, the format is 12 floats in either an array, a
19+
nor are accepted as JS objects. Instead, the format is 12 floats in either an array, a
1220
Float32Array or a piece of memory returned by CanvasKit.Malloc. The first 4 floats
1321
are the left, top, right, bottom numbers of the rectangle and then 4 sets of points
1422
starting in the upper left corner and going clockwise. This change allows for faster
1523
transfer between JS and WASM code.
24+
- `SkPath.addRoundRect` has been replaced with `SkPath.addRRect`. The same functionality
25+
can be had with the `CanvasKit.RRectXY` helper.
26+
- `SkPath.addRect` no longer accepts 4 floats as separate arguments. It only accepts
27+
an SkRect (an array/Float32Array of 4 floats) and an optional boolean for
28+
determining clockwise or counter-clockwise directionality.
29+
- The order of `SkCanvas.saveLayer` arguments is slightly different (more consistent).
30+
It is now `paint, bounds, backdrop, flags`
1631

1732
### Changed
1833
- We now compile CanvasKit with emsdk 2.0.0 when testing and deploying to npm.
1934
- WebGL interface creation is a little leaner in terms of code size and speed.
2035
- The signature of `main` used with SkSL passed to `CanvasKit.SkRuntimeEffect.Make` has changed.
2136
There is no longer an `inout half4 color` parameter, effects must return their color instead.
2237
Valid signatures are now `half4 main()` or `half4 main(float2 coord)`.
38+
- `SkPath.getBounds`, `SkShapedText.getBounds`, and `SkVertices.bounds` now
39+
take an optional argument. If a Float32Array with length 4 or greater is
40+
provided, the bounds will be copied into this array instead of allocating
41+
a new one.
42+
43+
### Removed
44+
- `SkCanvas.drawRoundRect` has been removed in favor of `SkCanvas.drawRRect`
45+
The same functionality can be had with the `CanvasKit.RRectXY` helper.
46+
- `SkPath.arcTo` which had been deprecated in favor of `SkPath.arcToOval`,
47+
`SkPath.arcToRotated`, `SkPath.arcToTangent`.
48+
49+
### Added
50+
- `CanvasKit.LTRBiRect` and `CanvasKit.XYWHiRect` as helpers to create SkIRects.
2351

2452
## [0.17.3] - 2020-08-05
2553

modules/canvaskit/canvaskit/example.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,22 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
219219
path.lineTo(36, 148);
220220

221221
path.moveTo(150, 180);
222-
path.arcTo(150, 100, 50, 200, 20);
222+
path.arcToTangent(150, 100, 50, 200, 20);
223223
path.lineTo(160, 160);
224224

225225
path.moveTo(20, 120);
226226
path.lineTo(20, 120);
227227

228228
canvas.drawPath(path, paint);
229229

230-
let rrect = new CanvasKit.SkPath()
231-
.addRoundRect(100, 10, 140, 62,
232-
10, 4, true);
230+
const rrect = CanvasKit.RRectXY([100, 10, 140, 62], 10, 4);
233231

234-
canvas.drawPath(rrect, paint);
232+
const rrectPath = new CanvasKit.SkPath().addRRect(rrect, true);
235233

234+
canvas.drawPath(rrectPath, paint);
235+
236+
rrectPath.delete();
236237
path.delete();
237-
rrect.delete();
238238
paint.delete();
239239
}
240240
// Intentionally just draw frame once
@@ -964,10 +964,10 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
964964
canvas.drawText(shapedText, textBoxX, textBoxY, textPaint);
965965
const bounds = shapedText.getBounds();
966966

967-
bounds.fLeft += textBoxX;
968-
bounds.fRight += textBoxX;
969-
bounds.fTop += textBoxY;
970-
bounds.fBottom += textBoxY
967+
bounds[0] += textBoxX; // left
968+
bounds[2] += textBoxX; // right
969+
bounds[1] += textBoxY; // top
970+
bounds[3] += textBoxY // bottom
971971

972972
canvas.drawRect(bounds, paint);
973973
const SHAPE_TEST_TEXT = 'VAVAVAVAVAFIfi';
@@ -1072,9 +1072,9 @@ <h2> CanvasKit can allow for text shaping (e.g. breaking, kerning)</h2>
10721072
fontPaint.setAntiAlias(true);
10731073

10741074
const arc = new CanvasKit.SkPath();
1075-
arc.arcTo(CanvasKit.LTRBRect(20, 40, 280, 300), -160, 140, true);
1075+
arc.arcToOval(CanvasKit.LTRBRect(20, 40, 280, 300), -160, 140, true);
10761076
arc.lineTo(210, 140);
1077-
arc.arcTo(CanvasKit.LTRBRect(20, 0, 280, 260), 160, -140, true);
1077+
arc.arcToOval(CanvasKit.LTRBRect(20, 0, 280, 260), 160, -140, true);
10781078

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

modules/canvaskit/canvaskit/extra.html

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ <h2> Support for extended color spaces </h2>
8181
p.lifetime = 3 + rand(p.seed);
8282
p.vel.y = -50;
8383
}
84-
84+
8585
void update(inout Particle p) {
8686
float w = mix(15, 3, p.age);
8787
p.pos.x = sin(radians(p.age * 320)) * mix(25, 10, p.age) + mix(-w, w, rand(p.seed));
8888
if (rand(p.seed) < 0.5) { p.pos.x = -p.pos.x; }
89-
89+
9090
p.color.g = (mix(75, 220, p.age) + mix(-30, 30, rand(p.seed))) / 255;
9191
}
9292
`
@@ -122,10 +122,10 @@ <h2> Support for extended color spaces </h2>
122122
// Examples requiring external resources.
123123
// Set bounds to fix the 4:3 resolution of the legos
124124
Promise.all([ckLoaded, loadLegoJSON]).then(([ck, jsonstr]) => {
125-
SkottieExample(ck, 'sk_legos', jsonstr, {fLeft: -50, fTop: 0, fRight: 350, fBottom: 300});
125+
SkottieExample(ck, 'sk_legos', jsonstr, [-50, 0, 350, 300]);
126126
});
127127
// Re-size to fit
128-
let fullBounds = {fLeft: 0, fTop: 0, fRight: 500, fBottom: 500};
128+
let fullBounds = [0, 0, 500, 500];
129129
Promise.all([ckLoaded, loadDrinksJSON]).then(([ck, jsonstr]) => {
130130
SkottieExample(ck, 'sk_drinks', jsonstr, fullBounds);
131131
});
@@ -146,6 +146,11 @@ <h2> Support for extended color spaces </h2>
146146
Promise.all([ckLoaded, loadSkp]).then((results) => {SkpExample(...results)});
147147
Promise.all([ckLoaded, loadBrickTex, loadBrickBump, loadFont]).then((results) => {Camera3D(...results)});
148148

149+
const rectLeft = 0;
150+
const rectTop = 1;
151+
const rectRight = 2;
152+
const rectBottom = 3;
153+
149154
function SkottieExample(CanvasKit, id, jsonStr, bounds, assets) {
150155
if (!CanvasKit || !jsonStr) {
151156
return;
@@ -154,7 +159,7 @@ <h2> Support for extended color spaces </h2>
154159
const duration = animation.duration() * 1000;
155160
const size = animation.size();
156161
let c = document.getElementById(id);
157-
bounds = bounds || {fLeft: 0, fTop: 0, fRight: size.w, fBottom: size.h};
162+
bounds = bounds || CanvasKit.LTRBRect(0, 0, size.w, size.h);
158163

159164
// Basic managed animation test.
160165
if (id === 'sk_drinks') {
@@ -172,16 +177,15 @@ <h2> Support for extended color spaces </h2>
172177
function drawFrame(canvas) {
173178
let seek = ((Date.now() - firstFrame) / duration) % 1.0;
174179
let damage = animation.seek(seek);
175-
// TODO: SkRect.isEmpty()?
176-
if (damage.fRight > damage.fLeft && damage.fBottom > damage.fTop) {
180+
181+
if (damage[rectRight] > damage[rectLeft] && damage[rectBottom] > damage[rectTop]) {
177182
canvas.clear(CanvasKit.WHITE);
178183
animation.render(canvas, bounds);
179184
}
180185
surface.requestAnimationFrame(drawFrame);
181186
}
182187
surface.requestAnimationFrame(drawFrame);
183188

184-
//animation.delete();
185189
return surface;
186190
}
187191

@@ -523,7 +527,7 @@ <h2> Support for extended color spaces </h2>
523527
float dp = dot(plane_norm, light_dir);
524528
float scale = min(ambient + max(dp, 0), 1);
525529
526-
color = sample(color_map, p) * half4(float4(scale, scale, scale, 1));
530+
color = sample(color_map, p) * half4(float4(scale, scale, scale, 1));
527531
}
528532
`;
529533

@@ -830,7 +834,7 @@ <h2> Support for extended color spaces </h2>
830834
// then covering with semitransparent background color.
831835
if (lastImage) {
832836
canvas.drawImage(lastImage, 0, 0, null);
833-
canvas.drawColor(CanvasKit.Color(171, 244, 255, 0.1)); // sky blue, almost transparent
837+
canvas.drawColor(CanvasKit.Color(171, 244, 255, 0.1)); // sky blue, almost transparent
834838
} else {
835839
canvas.clear(CanvasKit.Color(171, 244, 255)); // sky blue, opaque
836840
}
@@ -855,8 +859,8 @@ <h2> Support for extended color spaces </h2>
855859
let r = letter['r'];
856860
// rotate about the center of the glyph's rect.
857861
rotationPoint = [
858-
margin + r.fLeft + (r.fRight - r.fLeft) / 2,
859-
marginTop + r.fTop + (r.fBottom - r.fTop) / 2,
862+
margin + r[rectLeft] + (r[rectRight] - r[rectLeft]) / 2,
863+
marginTop + r[rectTop] + (r[rectBottom] - r[rectTop]) / 2,
860864
0
861865
];
862866
distanceFromPointer = CanvasKit.SkVector.dist(pointer, rotationPoint.slice(0, 2));
@@ -870,7 +874,7 @@ <h2> Support for extended color spaces </h2>
870874
CanvasKit.SkM44.rotated([0,1,0], distanceFromPointer * -0.035),
871875
CanvasKit.SkM44.translated(CanvasKit.SkVector.mulScalar(rotationPoint, -1)),
872876
));
873-
canvas.drawParagraph(letter['para'], margin + r.fLeft, marginTop + r.fTop);
877+
canvas.drawParagraph(letter['para'], margin + r[rectLeft], marginTop + r[rectTop]);
874878
i++;
875879
canvas.restore();
876880
}
@@ -907,9 +911,9 @@ <h2> Support for extended color spaces </h2>
907911
paint.setColor(red, CanvasKit.SkColorSpace.ADOBE_RGB);
908912
canvas.drawPaint(paint);
909913
paint.setColor(red, CanvasKit.SkColorSpace.DISPLAY_P3);
910-
canvas.drawRoundRect(CanvasKit.LTRBRect(50, 50, 250, 250), 30, 30, paint);
914+
canvas.drawRRect(CanvasKit.RRectXY([50, 50, 250, 250], 30, 30), paint);
911915
paint.setColor(red, CanvasKit.SkColorSpace.SRGB);
912-
canvas.drawRoundRect(CanvasKit.LTRBRect(100, 100, 200, 200), 30, 30, paint);
916+
canvas.drawRRect(CanvasKit.RRectXY([100, 100, 200, 200], 30, 30), paint);
913917

914918
surface.flush();
915919
surface.delete();

0 commit comments

Comments
 (0)