vexflow-native 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/base/VexflowRecordingReplay.js +118 -78
- package/lib/module/base/VexflowRecordingReplay.js.map +1 -1
- package/lib/module/renderer/layout.js +10 -0
- package/lib/module/renderer/layout.js.map +1 -1
- package/lib/module/renderer/useScoreRecording.js +50 -17
- package/lib/module/renderer/useScoreRecording.js.map +1 -1
- package/lib/typescript/src/base/VexflowRecordingReplay.d.ts.map +1 -1
- package/lib/typescript/src/renderer/layout.d.ts +7 -0
- package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
- package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/base/VexflowRecordingReplay.ts +193 -141
- package/src/renderer/layout.ts +15 -0
- package/src/renderer/useScoreRecording.ts +71 -19
|
@@ -15,14 +15,17 @@ function shadowBlurToSigma(shadowBlur) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
* distinct colors
|
|
18
|
+
* Skia objects one replay call allocates once and reuses across its commands.
|
|
19
|
+
* A recording uses a handful of distinct colors, glows and dashes but
|
|
20
|
+
* references them thousands of times, so each is created on first use and
|
|
21
|
+
* cached by value. Everything here is disposed when the replay ends: under
|
|
22
|
+
* NativeState only GC would free it otherwise.
|
|
20
23
|
*/
|
|
21
24
|
|
|
22
|
-
function getCachedColor(color,
|
|
25
|
+
function getCachedColor(color, pool) {
|
|
23
26
|
'worklet';
|
|
24
27
|
|
|
25
|
-
return
|
|
28
|
+
return pool.colors[color] ??= Skia.Color(color);
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
/**
|
|
@@ -31,7 +34,7 @@ function getCachedColor(color, cache) {
|
|
|
31
34
|
* the ink; `MakeDropShadow` (not `…Only`) keeps the source content, so the note
|
|
32
35
|
* still draws on top of its halo. No-op unless a `shadowColor` resolved.
|
|
33
36
|
*/
|
|
34
|
-
function applyGlow(skPaint, paint,
|
|
37
|
+
function applyGlow(skPaint, paint, pool) {
|
|
35
38
|
'worklet';
|
|
36
39
|
|
|
37
40
|
if (paint.shadowColor == null) {
|
|
@@ -41,12 +44,17 @@ function applyGlow(skPaint, paint, colorCache) {
|
|
|
41
44
|
return;
|
|
42
45
|
}
|
|
43
46
|
const sigma = shadowBlurToSigma(paint.shadowBlur ?? 0);
|
|
44
|
-
|
|
47
|
+
const key = `${paint.shadowColor}|${sigma}`;
|
|
48
|
+
skPaint.setImageFilter(pool.glows[key] ??= Skia.ImageFilter.MakeDropShadow(0, 0, sigma, sigma, getCachedColor(paint.shadowColor, pool)));
|
|
45
49
|
}
|
|
46
|
-
function
|
|
50
|
+
function applyDash(skPaint, lineDash, pool) {
|
|
47
51
|
'worklet';
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
if (lineDash == null || lineDash.length === 0) {
|
|
54
|
+
skPaint.setPathEffect(null);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
skPaint.setPathEffect(pool.dashes[lineDash.join(',')] ??= Skia.PathEffect.MakeDash(lineDash));
|
|
50
58
|
}
|
|
51
59
|
function mapRecordingLineCap(cap) {
|
|
52
60
|
'worklet';
|
|
@@ -69,49 +77,72 @@ function mapRecordingLineCap(cap) {
|
|
|
69
77
|
* state (glow filter, dash effect) is explicitly reset on every configure so
|
|
70
78
|
* nothing bleeds between commands.
|
|
71
79
|
*/
|
|
72
|
-
function
|
|
80
|
+
function createReplayPool() {
|
|
73
81
|
'worklet';
|
|
74
82
|
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
const fillPaint = Skia.Paint();
|
|
84
|
+
fillPaint.setStyle(PaintStyle.Fill);
|
|
85
|
+
fillPaint.setAntiAlias(true);
|
|
86
|
+
const strokePaint = Skia.Paint();
|
|
87
|
+
strokePaint.setStyle(PaintStyle.Stroke);
|
|
88
|
+
strokePaint.setAntiAlias(true);
|
|
89
|
+
return {
|
|
90
|
+
colors: {},
|
|
91
|
+
glows: {},
|
|
92
|
+
dashes: {},
|
|
93
|
+
fillPaint,
|
|
94
|
+
strokePaint,
|
|
95
|
+
clearPaint: null,
|
|
96
|
+
pathBuilder: Skia.PathBuilder.Make()
|
|
97
|
+
};
|
|
79
98
|
}
|
|
80
|
-
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Paints keep their own reference to an image filter / path effect, and a
|
|
102
|
+
* recorded picture copies the paint state it drew with, so disposing the JS
|
|
103
|
+
* handles here never invalidates what was drawn.
|
|
104
|
+
*/
|
|
105
|
+
function disposeReplayPool(pool) {
|
|
81
106
|
'worklet';
|
|
82
107
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
108
|
+
for (const key in pool.glows) {
|
|
109
|
+
pool.glows[key].dispose();
|
|
110
|
+
}
|
|
111
|
+
for (const key in pool.dashes) {
|
|
112
|
+
pool.dashes[key].dispose();
|
|
113
|
+
}
|
|
114
|
+
pool.fillPaint.dispose();
|
|
115
|
+
pool.strokePaint.dispose();
|
|
116
|
+
pool.clearPaint?.dispose();
|
|
117
|
+
pool.pathBuilder.dispose();
|
|
87
118
|
}
|
|
88
|
-
function configureFillPaint(
|
|
119
|
+
function configureFillPaint(paint, pool) {
|
|
89
120
|
'worklet';
|
|
90
121
|
|
|
91
|
-
skPaint.
|
|
92
|
-
|
|
122
|
+
const skPaint = pool.fillPaint;
|
|
123
|
+
skPaint.setColor(getCachedColor(paint.color, pool));
|
|
124
|
+
applyGlow(skPaint, paint, pool);
|
|
93
125
|
return skPaint;
|
|
94
126
|
}
|
|
95
|
-
function configureStrokePaint(
|
|
127
|
+
function configureStrokePaint(paint, pool) {
|
|
96
128
|
'worklet';
|
|
97
129
|
|
|
98
|
-
skPaint.
|
|
130
|
+
const skPaint = pool.strokePaint;
|
|
131
|
+
skPaint.setColor(getCachedColor(paint.color, pool));
|
|
99
132
|
skPaint.setStrokeWidth(paint.strokeWidth ?? 1);
|
|
100
133
|
skPaint.setStrokeCap(mapRecordingLineCap(paint.strokeCap ?? 'butt'));
|
|
101
|
-
applyGlow(skPaint, paint,
|
|
102
|
-
|
|
103
|
-
skPaint.setPathEffect(Skia.PathEffect.MakeDash(paint.lineDash));
|
|
104
|
-
} else {
|
|
105
|
-
skPaint.setPathEffect(null);
|
|
106
|
-
}
|
|
134
|
+
applyGlow(skPaint, paint, pool);
|
|
135
|
+
applyDash(skPaint, paint.lineDash, pool);
|
|
107
136
|
return skPaint;
|
|
108
137
|
}
|
|
109
|
-
function
|
|
138
|
+
function getClearPaint(pool) {
|
|
110
139
|
'worklet';
|
|
111
140
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
141
|
+
if (pool.clearPaint == null) {
|
|
142
|
+
pool.clearPaint = Skia.Paint();
|
|
143
|
+
pool.clearPaint.setBlendMode(BlendMode.Clear);
|
|
144
|
+
}
|
|
145
|
+
return pool.clearPaint;
|
|
115
146
|
}
|
|
116
147
|
/**
|
|
117
148
|
* Resolve a recorded paint against an optional per-group style override map
|
|
@@ -172,10 +203,10 @@ function applyPathCommand(builder, command) {
|
|
|
172
203
|
builder.quadTo(command.cpx, command.cpy, command.x, command.y);
|
|
173
204
|
break;
|
|
174
205
|
case 'addRect':
|
|
175
|
-
builder.addRect(
|
|
206
|
+
builder.addRect(command.rect);
|
|
176
207
|
break;
|
|
177
208
|
case 'addArc':
|
|
178
|
-
builder.addArc(
|
|
209
|
+
builder.addArc(command.rect, command.startDegrees, command.sweepDegrees);
|
|
179
210
|
break;
|
|
180
211
|
case 'close':
|
|
181
212
|
builder.close();
|
|
@@ -184,14 +215,21 @@ function applyPathCommand(builder, command) {
|
|
|
184
215
|
assertNever(command);
|
|
185
216
|
}
|
|
186
217
|
}
|
|
187
|
-
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Build the recorded path in the pooled builder (`detach` hands over the path
|
|
221
|
+
* and resets the builder for the next command), draw it, and free it at once:
|
|
222
|
+
* the canvas copies the path at the draw call.
|
|
223
|
+
*/
|
|
224
|
+
function drawRecordedPath(canvas, path, skPaint, builder) {
|
|
188
225
|
'worklet';
|
|
189
226
|
|
|
190
|
-
const builder = Skia.PathBuilder.Make();
|
|
191
227
|
for (const command of path) {
|
|
192
228
|
applyPathCommand(builder, command);
|
|
193
229
|
}
|
|
194
|
-
|
|
230
|
+
const skPath = builder.detach();
|
|
231
|
+
canvas.drawPath(skPath, skPaint);
|
|
232
|
+
skPath.dispose();
|
|
195
233
|
}
|
|
196
234
|
export function renderVexflowRecordingCommands(canvas, commands, fontProvider, defaultFont,
|
|
197
235
|
/**
|
|
@@ -211,47 +249,49 @@ replayFontManager) {
|
|
|
211
249
|
'worklet';
|
|
212
250
|
|
|
213
251
|
const fontManager = replayFontManager ?? new FontManager(fontProvider, defaultFont);
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
const pool = createReplayPool();
|
|
253
|
+
try {
|
|
254
|
+
for (const command of commands) {
|
|
255
|
+
switch (command.type) {
|
|
256
|
+
case 'clear':
|
|
257
|
+
canvas.clear(getCachedColor(command.color, pool));
|
|
258
|
+
break;
|
|
259
|
+
case 'save':
|
|
260
|
+
canvas.save();
|
|
261
|
+
break;
|
|
262
|
+
case 'restore':
|
|
263
|
+
canvas.restore();
|
|
264
|
+
break;
|
|
265
|
+
case 'scale':
|
|
266
|
+
canvas.scale(command.x, command.y);
|
|
267
|
+
break;
|
|
268
|
+
case 'translate':
|
|
269
|
+
canvas.translate(command.x, command.y);
|
|
270
|
+
break;
|
|
271
|
+
case 'clipRect':
|
|
272
|
+
canvas.clipRect(command.rect, ClipOp.Intersect, true);
|
|
273
|
+
break;
|
|
274
|
+
case 'fillRect':
|
|
275
|
+
canvas.drawRect(command.rect, configureFillPaint(resolveStyle(command.paint, command.groupId, 'fill', styleOverrides), pool));
|
|
276
|
+
break;
|
|
277
|
+
case 'clearRect':
|
|
278
|
+
canvas.drawRect(command.rect, getClearPaint(pool));
|
|
279
|
+
break;
|
|
280
|
+
case 'fillPath':
|
|
281
|
+
drawRecordedPath(canvas, command.path, configureFillPaint(resolveStyle(command.paint, command.groupId, 'fill', styleOverrides), pool), pool.pathBuilder);
|
|
282
|
+
break;
|
|
283
|
+
case 'strokePath':
|
|
284
|
+
drawRecordedPath(canvas, command.path, configureStrokePaint(resolveStyle(command.paint, command.groupId, 'stroke', styleOverrides), pool), pool.pathBuilder);
|
|
285
|
+
break;
|
|
286
|
+
case 'fillText':
|
|
287
|
+
canvas.drawText(command.text, command.x, command.y, configureFillPaint(resolveStyle(command.paint, command.groupId, 'fill', styleOverrides), pool), createFont(fontManager, command.font));
|
|
288
|
+
break;
|
|
289
|
+
default:
|
|
290
|
+
assertNever(command);
|
|
291
|
+
}
|
|
254
292
|
}
|
|
293
|
+
} finally {
|
|
294
|
+
disposeReplayPool(pool);
|
|
255
295
|
}
|
|
256
296
|
}
|
|
257
297
|
//# sourceMappingURL=VexflowRecordingReplay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BlendMode","ClipOp","PaintStyle","Skia","StrokeCap","FontManager","shadowBlurToSigma","shadowBlur","getCachedColor","color","
|
|
1
|
+
{"version":3,"names":["BlendMode","ClipOp","PaintStyle","Skia","StrokeCap","FontManager","shadowBlurToSigma","shadowBlur","getCachedColor","color","pool","colors","Color","applyGlow","skPaint","paint","shadowColor","setImageFilter","sigma","key","glows","ImageFilter","MakeDropShadow","applyDash","lineDash","length","setPathEffect","dashes","join","PathEffect","MakeDash","mapRecordingLineCap","cap","Round","Square","Butt","createReplayPool","fillPaint","Paint","setStyle","Fill","setAntiAlias","strokePaint","Stroke","clearPaint","pathBuilder","PathBuilder","Make","disposeReplayPool","dispose","configureFillPaint","setColor","configureStrokePaint","setStrokeWidth","strokeWidth","setStrokeCap","strokeCap","getClearPaint","setBlendMode","Clear","resolveStyle","groupId","kind","styleOverrides","override","fillColor","strokeColor","createFont","fontManager","font","createSkFont","size","weight","style","assertNever","value","Error","String","applyPathCommand","builder","command","type","moveTo","x","y","lineTo","cubicTo","cp1x","cp1y","cp2x","cp2y","quadTo","cpx","cpy","addRect","rect","addArc","startDegrees","sweepDegrees","close","drawRecordedPath","canvas","path","skPath","detach","drawPath","renderVexflowRecordingCommands","commands","fontProvider","defaultFont","replayFontManager","clear","save","restore","scale","translate","clipRect","Intersect","drawRect","drawText","text"],"sourceRoot":"../../../src","sources":["base/VexflowRecordingReplay.ts"],"mappings":";;AAAA,SACEA,SAAS,EACTC,MAAM,EACNC,UAAU,EACVC,IAAI,EACJC,SAAS,QAQJ,mBAAmB;AAE1B,OAAOC,WAAW,MAAM,kBAAe;AAUvC;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,iBAAiBA,CAACC,UAAkB,EAAU;EACrD,SAAS;;EAET,OAAOA,UAAU,GAAG,CAAC;AACvB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,SAASC,cAAcA,CAACC,KAAa,EAAEC,IAAgB,EAAW;EAChE,SAAS;;EAET,OAAQA,IAAI,CAACC,MAAM,CAACF,KAAK,CAAC,KAAKN,IAAI,CAACS,KAAK,CAACH,KAAK,CAAC;AAClD;;AAEA;AACA;AACA;AACA;AACA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AO,CAACe,IAAI,EAAEtC,aAAa,CAAC/C,IAAI,CAAC,CAAC;UAClD;QACF,KAAK,UAAU;UACb0F,gBAAgB,CACdC,MAAM,EACNrB,OAAO,CAACsB,IAAI,EACZpD,kBAAkB,CAChBU,YAAY,CACVoB,OAAO,CAACjE,KAAK,EACbiE,OAAO,CAACnB,OAAO,EACf,MAAM,EACNE,cACF,CAAC,EACDrD,IACF,CAAC,EACDA,IAAI,CAACmC,WACP,CAAC;UACD;QACF,KAAK,YAAY;UACfuD,gBAAgB,CACdC,MAAM,EACNrB,OAAO,CAACsB,IAAI,EACZlD,oBAAoB,CAClBQ,YAAY,CACVoB,OAAO,CAACjE,KAAK,EACbiE,OAAO,CAACnB,OAAO,EACf,QAAQ,EACRE,cACF,CAAC,EACDrD,IACF,CAAC,EACDA,IAAI,CAACmC,WACP,CAAC;UACD;QACF,KAAK,UAAU;UACbwD,MAAM,CAACkB,QAAQ,CACbvC,OAAO,CAACwC,IAAI,EACZxC,OAAO,CAACG,CAAC,EACTH,OAAO,CAACI,CAAC,EACTlC,kBAAkB,CAChBU,YAAY,CACVoB,OAAO,CAACjE,KAAK,EACbiE,OAAO,CAACnB,OAAO,EACf,MAAM,EACNE,cACF,CAAC,EACDrD,IACF,CAAC,EACDyD,UAAU,CAACC,WAAW,EAAEY,OAAO,CAACX,IAAI,CACtC,CAAC;UACD;QACF;UACEK,WAAW,CAACM,OAAO,CAAC;MACxB;IACF;EACF,CAAC,SAAS;IACRhC,iBAAiB,CAACtC,IAAI,CAAC;EACzB;AACF","ignoreList":[]}
|
|
@@ -46,6 +46,16 @@ export function layoutScore(score, measuredScore, options, rendererType, viewpor
|
|
|
46
46
|
groups
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Whether `layoutScore` reads `viewport.height` for this score. Only the
|
|
52
|
+
* infinite score centers on it; document layouts use it solely for the
|
|
53
|
+
* content size of a score with no measures. Callers can skip a re-layout on
|
|
54
|
+
* height-only viewport changes when this is false.
|
|
55
|
+
*/
|
|
56
|
+
export function layoutUsesViewportHeight(rendererType, measuredScore) {
|
|
57
|
+
return rendererType === 'infiniteScore' || measuredScore.measures.length === 0;
|
|
58
|
+
}
|
|
49
59
|
function buildGroupLayoutContext(score, measuredScore) {
|
|
50
60
|
const groups = buildMeasurementGroups(score);
|
|
51
61
|
return groups.map(group => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getAvailableDocumentWidth","getSystemGap","layoutDocumentEvenGroup","layoutDocumentGroup","resolveDocumentEvenMeasureWidth","resolveSystemVerticalLayout","buildMeasurementGroups","buildResolvedMeasureStates","resolveGroupStaves","layoutScore","score","measuredScore","options","rendererType","viewport","groups","buildGroupLayoutContext","groupResults","group","push","layoutInfiniteScoreGroup","availableWidth","measuresPerFullLine","equalMeasureWidth","cursorY","y","insets","top","result","x","left","nextY","contentSize","measureContentSize","systems","flatMap","measures","map","groupId","staffGroup","staffIds","staves","resolvedStatesByStaff","staff","filter","measure","sort","right","measureIndex","intrinsicWidth","intrinsicNoteWidth","measureNumbers","staffBounds","verticalLayout","
|
|
1
|
+
{"version":3,"names":["getAvailableDocumentWidth","getSystemGap","layoutDocumentEvenGroup","layoutDocumentGroup","resolveDocumentEvenMeasureWidth","resolveSystemVerticalLayout","buildMeasurementGroups","buildResolvedMeasureStates","resolveGroupStaves","layoutScore","score","measuredScore","options","rendererType","viewport","groups","buildGroupLayoutContext","groupResults","group","push","layoutInfiniteScoreGroup","availableWidth","measuresPerFullLine","equalMeasureWidth","cursorY","y","insets","top","result","x","left","nextY","contentSize","measureContentSize","systems","flatMap","measures","layoutUsesViewportHeight","length","map","groupId","staffGroup","staffIds","staves","resolvedStatesByStaff","staff","filter","measure","sort","right","measureIndex","intrinsicWidth","intrinsicNoteWidth","measureNumbers","staffBounds","verticalLayout","spacing","staffGap","maxIntrinsicWidth","Math","max","systemWidth","origin","getInfiniteScoreOriginX","getInfiniteScoreOriginY","cursorX","width","height","staffYOffsets","systemIndex","staffCount","measureIndices","insetContentWidth","visibleTop","visibleBottom","every","maxRight","maxBottom","system","measuredWidth","measuredHeight","bottom"],"sourceRoot":"../../../src","sources":["renderer/layout.ts"],"mappings":";;AACA,SACEA,yBAAyB,EACzBC,YAAY,QACP,2BAAwB;AAC/B,SACEC,uBAAuB,EACvBC,mBAAmB,EACnBC,+BAA+B,QAC1B,4BAAyB;AAChC,SAASC,2BAA2B,QAAQ,6BAA0B;AAEtE,SACEC,sBAAsB,EACtBC,0BAA0B,EAC1BC,kBAAkB,QAEb,mBAAgB;AAiEvB,OAAO,SAASC,WAAWA,CACzBC,KAAY,EACZC,aAA4B,EAC5BC,OAAqB,EACrBC,YAA0B,EAC1BC,QAAsB,EACL;EACjB,MAAMC,MAAM,GAAGC,uBAAuB,CAACN,KAAK,EAAEC,aAAa,CAAC;EAC5D,MAAMM,YAAiC,GAAG,EAAE;EAE5C,IAAIJ,YAAY,KAAK,eAAe,EAAE;IACpC,KAAK,MAAMK,KAAK,IAAIH,MAAM,EAAE;MAC1BE,YAAY,CAACE,IAAI,CAACC,wBAAwB,CAACF,KAAK,EAAEJ,QAAQ,EAAEF,OAAO,CAAC,CAAC;IACvE;EACF,CAAC,MAAM,IAAIC,YAAY,KAAK,cAAc,EAAE;IAC1C,MAAMQ,cAAc,GAAGrB,yBAAyB,CAACc,QAAQ,EAAEF,OAAO,CAAC;IACnE,MAAM;MAAEU,mBAAmB;MAAEC;IAAkB,CAAC,GAC9CnB,+BAA+B,CAACO,aAAa,EAAEU,cAAc,CAAC;IAChE,IAAIG,OAAO,GAAGV,QAAQ,CAACW,CAAC,GAAGb,OAAO,CAACc,MAAM,CAACC,GAAG;IAE7C,KAAK,MAAMT,KAAK,IAAIH,MAAM,EAAE;MAC1B,MAAMa,MAAM,GAAG1B,uBAAuB,CACpCgB,KAAK,EACL;QAAEW,CAAC,EAAEf,QAAQ,CAACe,CAAC,GAAGjB,OAAO,CAACc,MAAM,CAACI,IAAI;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9C,QAAQ,CAACoD,KAAK,EAAEa,aAAa,CAAC;IAC9CZ,MAAM,EAAErD,QAAQ,CAACqD;EACnB,CAAC;AACH","ignoreList":[]}
|
|
@@ -4,7 +4,7 @@ import { useMemo } from 'react';
|
|
|
4
4
|
import VexflowRecordingContext from "../base/VexflowRecordingContext.js";
|
|
5
5
|
import { buildVexflowGroupIndex } from "../base/VexflowRecordingIndex.js";
|
|
6
6
|
import { isVexflowNativeDebugEnabled } from "../shared/debug.js";
|
|
7
|
-
import { layoutScore } from "./layout.js";
|
|
7
|
+
import { layoutScore, layoutUsesViewportHeight } from "./layout.js";
|
|
8
8
|
import { measureScore } from "./measure.js";
|
|
9
9
|
import { renderScore } from "./render.js";
|
|
10
10
|
import { createContentViewport, getRenderScale, scaleItemsLayoutToViewSpace } from "./scale.js";
|
|
@@ -20,28 +20,53 @@ export function useScoreRecording({
|
|
|
20
20
|
score,
|
|
21
21
|
viewport
|
|
22
22
|
}) {
|
|
23
|
-
|
|
23
|
+
// Measuring does not depend on the viewport and is the most expensive pass,
|
|
24
|
+
// so it is cached apart from layout and render.
|
|
25
|
+
const measurement = useMemo(() => {
|
|
24
26
|
if (!enabled) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const measureStart = nowMs();
|
|
30
|
+
// On native, constructing a context installs it as VexFlow's text
|
|
31
|
+
// measurement canvas, so text is measured with this font setup.
|
|
32
|
+
// eslint-disable-next-line no-new
|
|
33
|
+
new VexflowRecordingContext(fontManager, defaultFont);
|
|
34
|
+
const measuredScore = measureScore(score, options, {
|
|
35
|
+
decorateItem
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
measuredScore,
|
|
39
|
+
measureMs: nowMs() - measureStart
|
|
40
|
+
};
|
|
41
|
+
}, [decorateItem, defaultFont, enabled, fontManager, options, score]);
|
|
42
|
+
|
|
43
|
+
// Height-only changes (a late safe-area inset, the keyboard) cannot move a
|
|
44
|
+
// layout that ignores the height, so the height is pinned to 0 for it and
|
|
45
|
+
// such a change keeps the recording.
|
|
46
|
+
const layoutHeight = !measurement || layoutUsesViewportHeight(rendererType, measurement.measuredScore) ? viewport.height : 0;
|
|
47
|
+
const layoutViewport = useMemo(() => ({
|
|
48
|
+
x: viewport.x,
|
|
49
|
+
y: viewport.y,
|
|
50
|
+
width: viewport.width,
|
|
51
|
+
height: layoutHeight
|
|
52
|
+
}), [layoutHeight, viewport.width, viewport.x, viewport.y]);
|
|
53
|
+
return useMemo(() => {
|
|
54
|
+
if (!measurement) {
|
|
25
55
|
return {
|
|
26
56
|
commands: [],
|
|
27
57
|
groupIndex: {},
|
|
28
|
-
layoutPlan: createEmptyLayoutPlan(rendererType,
|
|
29
|
-
itemsLayout: createEmptyItemsLayout(
|
|
58
|
+
layoutPlan: createEmptyLayoutPlan(rendererType, layoutViewport),
|
|
59
|
+
itemsLayout: createEmptyItemsLayout(layoutViewport)
|
|
30
60
|
};
|
|
31
61
|
}
|
|
32
62
|
|
|
33
|
-
// Layout
|
|
34
|
-
//
|
|
63
|
+
// Layout and render run in content space against the virtual viewport;
|
|
64
|
+
// see src/renderer/scale.ts.
|
|
35
65
|
const scale = getRenderScale(options);
|
|
36
|
-
const contentViewport = createContentViewport(
|
|
37
|
-
const measureStart = nowMs();
|
|
66
|
+
const contentViewport = createContentViewport(layoutViewport, scale);
|
|
38
67
|
const ctx = new VexflowRecordingContext(fontManager, defaultFont, colorScheme);
|
|
39
|
-
const measuredScore = measureScore(score, options, {
|
|
40
|
-
decorateItem
|
|
41
|
-
});
|
|
42
|
-
const measureMs = nowMs() - measureStart;
|
|
43
68
|
const layoutStart = nowMs();
|
|
44
|
-
const layoutPlan = layoutScore(score, measuredScore, options, rendererType, contentViewport);
|
|
69
|
+
const layoutPlan = layoutScore(score, measurement.measuredScore, options, rendererType, contentViewport);
|
|
45
70
|
const layoutMs = nowMs() - layoutStart;
|
|
46
71
|
const renderStart = nowMs();
|
|
47
72
|
const itemsLayout = scaleItemsLayoutToViewSpace(renderScore(ctx, score, layoutPlan, options, {
|
|
@@ -60,12 +85,12 @@ export function useScoreRecording({
|
|
|
60
85
|
finishMs,
|
|
61
86
|
layoutMs,
|
|
62
87
|
measureCount: layoutPlan.measures.length,
|
|
63
|
-
|
|
88
|
+
measurement,
|
|
64
89
|
renderMs,
|
|
65
90
|
rendererType,
|
|
66
91
|
scoreId: score.id,
|
|
67
92
|
systemCount: layoutPlan.systems.length,
|
|
68
|
-
viewport
|
|
93
|
+
viewport: layoutViewport
|
|
69
94
|
});
|
|
70
95
|
return {
|
|
71
96
|
commands,
|
|
@@ -73,8 +98,14 @@ export function useScoreRecording({
|
|
|
73
98
|
layoutPlan,
|
|
74
99
|
itemsLayout
|
|
75
100
|
};
|
|
76
|
-
}, [colorScheme, decorateItem, defaultFont,
|
|
101
|
+
}, [colorScheme, decorateItem, defaultFont, fontManager, layoutViewport, measurement, onDrawItem, options, rendererType, score]);
|
|
77
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Measurements already counted by a profile line. A cached measurement is
|
|
105
|
+
* reported once, by the first recording built on it, so summed profiles
|
|
106
|
+
* count each measure pass once.
|
|
107
|
+
*/
|
|
108
|
+
const profiledMeasurements = new WeakSet();
|
|
78
109
|
function createEmptyItemsLayout(viewport) {
|
|
79
110
|
return {
|
|
80
111
|
items: {},
|
|
@@ -104,7 +135,7 @@ function logScoreRecordingProfile({
|
|
|
104
135
|
finishMs,
|
|
105
136
|
layoutMs,
|
|
106
137
|
measureCount,
|
|
107
|
-
|
|
138
|
+
measurement,
|
|
108
139
|
renderMs,
|
|
109
140
|
rendererType,
|
|
110
141
|
scoreId,
|
|
@@ -114,6 +145,8 @@ function logScoreRecordingProfile({
|
|
|
114
145
|
if (!isVexflowNativeDebugEnabled()) {
|
|
115
146
|
return;
|
|
116
147
|
}
|
|
148
|
+
const measureMs = profiledMeasurements.has(measurement) ? 0 : measurement.measureMs;
|
|
149
|
+
profiledMeasurements.add(measurement);
|
|
117
150
|
console.info('[ScoreRenderer] recording profile', {
|
|
118
151
|
scoreId,
|
|
119
152
|
rendererType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","VexflowRecordingContext","buildVexflowGroupIndex","isVexflowNativeDebugEnabled","layoutScore","measureScore","renderScore","createContentViewport","getRenderScale","scaleItemsLayoutToViewSpace","useScoreRecording","decorateItem","defaultFont","enabled","fontManager","colorScheme","onDrawItem","options","rendererType","score","viewport","
|
|
1
|
+
{"version":3,"names":["useMemo","VexflowRecordingContext","buildVexflowGroupIndex","isVexflowNativeDebugEnabled","layoutScore","layoutUsesViewportHeight","measureScore","renderScore","createContentViewport","getRenderScale","scaleItemsLayoutToViewSpace","useScoreRecording","decorateItem","defaultFont","enabled","fontManager","colorScheme","onDrawItem","options","rendererType","score","viewport","measurement","measureStart","nowMs","measuredScore","measureMs","layoutHeight","height","layoutViewport","x","y","width","commands","groupIndex","layoutPlan","createEmptyLayoutPlan","itemsLayout","createEmptyItemsLayout","scale","contentViewport","ctx","layoutStart","layoutMs","renderStart","renderMs","finishStart","finish","finishMs","logScoreRecordingProfile","commandCount","length","groupCount","Object","keys","contentSize","measureCount","measures","scoreId","id","systemCount","systems","profiledMeasurements","WeakSet","items","groups","has","add","console","info","roundMs","totalMs","globalThis","performance","now","Date","value","Math","round"],"sourceRoot":"../../../src","sources":["renderer/useScoreRecording.ts"],"mappings":";;AAAA,SAASA,OAAO,QAAQ,OAAO;AAI/B,OAAOC,uBAAuB,MAAM,oCAAiC;AACrE,SACEC,sBAAsB,QAEjB,kCAA+B;AAEtC,SAASC,2BAA2B,QAAQ,oBAAiB;AAC7D,SACEC,WAAW,EACXC,wBAAwB,QAEnB,aAAU;AACjB,SAASC,YAAY,QAA4B,cAAW;AAC5D,SAASC,WAAW,QAAQ,aAAU;AACtC,SACEC,qBAAqB,EACrBC,cAAc,EACdC,2BAA2B,QACtB,YAAS;AA2BhB,OAAO,SAASC,iBAAiBA,CAAC;EAChCC,YAAY;EACZC,WAAW;EACXC,OAAO,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AAC,EAAE;EACD,IAAI,CAAClB,2BAA2B,CAAC,CAAC,EAAE;IAClC;EACF;EAEA,MAAMuB,SAAS,GAAGoC,oBAAoB,CAACI,GAAG,CAAC5C,WAAW,CAAC,GACnD,CAAC,GACDA,WAAW,CAACI,SAAS;EACzBoC,oBAAoB,CAACK,GAAG,CAAC7C,WAAW,CAAC;EAErC8C,OAAO,CAACC,IAAI,CAAC,mCAAmC,EAAE;IAChDX,OAAO;IACPvC,YAAY;IACZE,QAAQ;IACRkC,WAAW;IACXC,YAAY;IACZI,WAAW;IACXV,YAAY;IACZE,UAAU;IACV1B,SAAS,EAAE4C,OAAO,CAAC5C,SAAS,CAAC;IAC7BiB,QAAQ,EAAE2B,OAAO,CAAC3B,QAAQ,CAAC;IAC3BE,QAAQ,EAAEyB,OAAO,CAACzB,QAAQ,CAAC;IAC3BG,QAAQ,EAAEsB,OAAO,CAACtB,QAAQ,CAAC;IAC3BuB,OAAO,EAAED,OAAO,CAAC5C,SAAS,GAAGiB,QAAQ,GAAGE,QAAQ,GAAGG,QAAQ;EAC7D,CAAC,CAAC;AACJ;AAEA,SAASxB,KAAKA,CAAA,EAAW;EACvB,OAAOgD,UAAU,CAACC,WAAW,EAAEC,GAAG,GAAG,CAAC,IAAIC,IAAI,CAACD,GAAG,CAAC,CAAC;AACtD;AAEA,SAASJ,OAAOA,CAACM,KAAa,EAAU;EACtC,OAAOC,IAAI,CAACC,KAAK,CAACF,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE;AACpC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VexflowRecordingReplay.d.ts","sourceRoot":"","sources":["../../../../src/base/VexflowRecordingReplay.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"VexflowRecordingReplay.d.ts","sourceRoot":"","sources":["../../../../src/base/VexflowRecordingReplay.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,QAAQ,EAMb,KAAK,sBAAsB,EAC5B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EACV,uBAAuB,EAKvB,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AA+TjC,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,SAAS,uBAAuB,EAAE,EAC5C,YAAY,EAAE,sBAAsB,EACpC,WAAW,EAAE,MAAM;AACnB;;;;;;GAMG;AACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;AACrD;;;;GAIG;AACH,iBAAiB,CAAC,EAAE,WAAW,QAsGhC"}
|
|
@@ -53,4 +53,11 @@ export interface ScoreLayoutPlan {
|
|
|
53
53
|
groups: GroupLayoutContext[];
|
|
54
54
|
}
|
|
55
55
|
export declare function layoutScore(score: Score, measuredScore: MeasuredScore, options: ScoreOptions, rendererType: RendererType, viewport: RendererRect): ScoreLayoutPlan;
|
|
56
|
+
/**
|
|
57
|
+
* Whether `layoutScore` reads `viewport.height` for this score. Only the
|
|
58
|
+
* infinite score centers on it; document layouts use it solely for the
|
|
59
|
+
* content size of a score with no measures. Callers can skip a re-layout on
|
|
60
|
+
* height-only viewport changes when this is false.
|
|
61
|
+
*/
|
|
62
|
+
export declare function layoutUsesViewportHeight(rendererType: RendererType, measuredScore: MeasuredScore): boolean;
|
|
56
63
|
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../../src/renderer/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAYzD,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,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C1B,QAAQ,EAAE,YAAY,GACrB,eAAe,CAwDjB;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,GAC3B,OAAO,CAIT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScoreRecording.d.ts","sourceRoot":"","sources":["../../../../src/renderer/useScoreRecording.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAEvD,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,
|
|
1
|
+
{"version":3,"file":"useScoreRecording.d.ts","sourceRoot":"","sources":["../../../../src/renderer/useScoreRecording.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAEvD,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,UAAU,CAAC;AAQlB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,QAAQ,EAAE,SAAS,uBAAuB,EAAE,CAAC;IAC7C;;;OAGG;IACH,UAAU,EAAE,0BAA0B,CAAC;IACvC;;;OAGG;IACH,UAAU,EAAE,eAAe,CAAC;IAC5B,yDAAyD;IACzD,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,WAAW,EACX,OAAc,EACd,WAAW,EACX,WAAW,EACX,UAAU,EACV,OAAO,EACP,YAAY,EACZ,KAAK,EACL,QAAQ,GACT,EAAE,cAAc,GAAG;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,sBAAsB,CAAC;IACpC,WAAW,EAAE,wBAAwB,CAAC;IACtC,OAAO,EAAE,YAAY,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;CACxB,GAAG,cAAc,CAkHjB"}
|
package/package.json
CHANGED
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
StrokeCap,
|
|
7
7
|
type SkCanvas,
|
|
8
8
|
type SkColor,
|
|
9
|
+
type SkImageFilter,
|
|
9
10
|
type SkPaint,
|
|
10
11
|
type SkPathBuilder,
|
|
12
|
+
type SkPathEffect,
|
|
11
13
|
type SkTypefaceFontProvider,
|
|
12
14
|
} from 'react-native-skia';
|
|
13
15
|
|
|
@@ -18,7 +20,6 @@ import type {
|
|
|
18
20
|
VexflowRecordingLineCap,
|
|
19
21
|
VexflowRecordingPaint,
|
|
20
22
|
VexflowRecordingPathCommand,
|
|
21
|
-
VexflowRecordingRect,
|
|
22
23
|
VexflowStyleOverride,
|
|
23
24
|
} from './VexflowRecordingTypes';
|
|
24
25
|
|
|
@@ -35,15 +36,27 @@ function shadowBlurToSigma(shadowBlur: number): number {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
-
* distinct colors
|
|
39
|
+
* Skia objects one replay call allocates once and reuses across its commands.
|
|
40
|
+
* A recording uses a handful of distinct colors, glows and dashes but
|
|
41
|
+
* references them thousands of times, so each is created on first use and
|
|
42
|
+
* cached by value. Everything here is disposed when the replay ends: under
|
|
43
|
+
* NativeState only GC would free it otherwise.
|
|
40
44
|
*/
|
|
41
|
-
type
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
type ReplayPool = {
|
|
46
|
+
colors: Record<string, SkColor>;
|
|
47
|
+
glows: Record<string, SkImageFilter>;
|
|
48
|
+
dashes: Record<string, SkPathEffect>;
|
|
49
|
+
fillPaint: SkPaint;
|
|
50
|
+
strokePaint: SkPaint;
|
|
51
|
+
/** Created on the first `clearRect`; most recordings never clear a rect. */
|
|
52
|
+
clearPaint: SkPaint | null;
|
|
53
|
+
pathBuilder: SkPathBuilder;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function getCachedColor(color: string, pool: ReplayPool): SkColor {
|
|
44
57
|
'worklet';
|
|
45
58
|
|
|
46
|
-
return (
|
|
59
|
+
return (pool.colors[color] ??= Skia.Color(color));
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
/**
|
|
@@ -55,7 +68,7 @@ function getCachedColor(color: string, cache: SkColorCache): SkColor {
|
|
|
55
68
|
function applyGlow(
|
|
56
69
|
skPaint: SkPaint,
|
|
57
70
|
paint: VexflowRecordingPaint,
|
|
58
|
-
|
|
71
|
+
pool: ReplayPool
|
|
59
72
|
) {
|
|
60
73
|
'worklet';
|
|
61
74
|
|
|
@@ -67,22 +80,34 @@ function applyGlow(
|
|
|
67
80
|
}
|
|
68
81
|
|
|
69
82
|
const sigma = shadowBlurToSigma(paint.shadowBlur ?? 0);
|
|
83
|
+
const key = `${paint.shadowColor}|${sigma}`;
|
|
70
84
|
|
|
71
85
|
skPaint.setImageFilter(
|
|
72
|
-
Skia.ImageFilter.MakeDropShadow(
|
|
86
|
+
(pool.glows[key] ??= Skia.ImageFilter.MakeDropShadow(
|
|
73
87
|
0,
|
|
74
88
|
0,
|
|
75
89
|
sigma,
|
|
76
90
|
sigma,
|
|
77
|
-
getCachedColor(paint.shadowColor,
|
|
78
|
-
)
|
|
91
|
+
getCachedColor(paint.shadowColor, pool)
|
|
92
|
+
))
|
|
79
93
|
);
|
|
80
94
|
}
|
|
81
95
|
|
|
82
|
-
function
|
|
96
|
+
function applyDash(
|
|
97
|
+
skPaint: SkPaint,
|
|
98
|
+
lineDash: number[] | undefined,
|
|
99
|
+
pool: ReplayPool
|
|
100
|
+
) {
|
|
83
101
|
'worklet';
|
|
84
102
|
|
|
85
|
-
|
|
103
|
+
if (lineDash == null || lineDash.length === 0) {
|
|
104
|
+
skPaint.setPathEffect(null);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
skPaint.setPathEffect(
|
|
109
|
+
(pool.dashes[lineDash.join(',')] ??= Skia.PathEffect.MakeDash(lineDash))
|
|
110
|
+
);
|
|
86
111
|
}
|
|
87
112
|
|
|
88
113
|
function mapRecordingLineCap(cap: VexflowRecordingLineCap): StrokeCap {
|
|
@@ -106,67 +131,86 @@ function mapRecordingLineCap(cap: VexflowRecordingLineCap): StrokeCap {
|
|
|
106
131
|
* state (glow filter, dash effect) is explicitly reset on every configure so
|
|
107
132
|
* nothing bleeds between commands.
|
|
108
133
|
*/
|
|
109
|
-
function
|
|
134
|
+
function createReplayPool(): ReplayPool {
|
|
110
135
|
'worklet';
|
|
111
136
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
137
|
+
const fillPaint = Skia.Paint();
|
|
138
|
+
fillPaint.setStyle(PaintStyle.Fill);
|
|
139
|
+
fillPaint.setAntiAlias(true);
|
|
115
140
|
|
|
116
|
-
|
|
141
|
+
const strokePaint = Skia.Paint();
|
|
142
|
+
strokePaint.setStyle(PaintStyle.Stroke);
|
|
143
|
+
strokePaint.setAntiAlias(true);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
colors: {},
|
|
147
|
+
glows: {},
|
|
148
|
+
dashes: {},
|
|
149
|
+
fillPaint,
|
|
150
|
+
strokePaint,
|
|
151
|
+
clearPaint: null,
|
|
152
|
+
pathBuilder: Skia.PathBuilder.Make(),
|
|
153
|
+
};
|
|
117
154
|
}
|
|
118
155
|
|
|
119
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Paints keep their own reference to an image filter / path effect, and a
|
|
158
|
+
* recorded picture copies the paint state it drew with, so disposing the JS
|
|
159
|
+
* handles here never invalidates what was drawn.
|
|
160
|
+
*/
|
|
161
|
+
function disposeReplayPool(pool: ReplayPool) {
|
|
120
162
|
'worklet';
|
|
121
163
|
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
164
|
+
for (const key in pool.glows) {
|
|
165
|
+
pool.glows[key]!.dispose();
|
|
166
|
+
}
|
|
167
|
+
for (const key in pool.dashes) {
|
|
168
|
+
pool.dashes[key]!.dispose();
|
|
169
|
+
}
|
|
170
|
+
pool.fillPaint.dispose();
|
|
171
|
+
pool.strokePaint.dispose();
|
|
172
|
+
pool.clearPaint?.dispose();
|
|
173
|
+
pool.pathBuilder.dispose();
|
|
127
174
|
}
|
|
128
175
|
|
|
129
176
|
function configureFillPaint(
|
|
130
|
-
skPaint: SkPaint,
|
|
131
177
|
paint: VexflowRecordingPaint,
|
|
132
|
-
|
|
178
|
+
pool: ReplayPool
|
|
133
179
|
): SkPaint {
|
|
134
180
|
'worklet';
|
|
135
181
|
|
|
136
|
-
skPaint.
|
|
137
|
-
|
|
182
|
+
const skPaint = pool.fillPaint;
|
|
183
|
+
skPaint.setColor(getCachedColor(paint.color, pool));
|
|
184
|
+
applyGlow(skPaint, paint, pool);
|
|
138
185
|
|
|
139
186
|
return skPaint;
|
|
140
187
|
}
|
|
141
188
|
|
|
142
189
|
function configureStrokePaint(
|
|
143
|
-
skPaint: SkPaint,
|
|
144
190
|
paint: VexflowRecordingPaint,
|
|
145
|
-
|
|
191
|
+
pool: ReplayPool
|
|
146
192
|
): SkPaint {
|
|
147
193
|
'worklet';
|
|
148
194
|
|
|
149
|
-
skPaint.
|
|
195
|
+
const skPaint = pool.strokePaint;
|
|
196
|
+
skPaint.setColor(getCachedColor(paint.color, pool));
|
|
150
197
|
skPaint.setStrokeWidth(paint.strokeWidth ?? 1);
|
|
151
198
|
skPaint.setStrokeCap(mapRecordingLineCap(paint.strokeCap ?? 'butt'));
|
|
152
|
-
applyGlow(skPaint, paint,
|
|
153
|
-
|
|
154
|
-
if (paint.lineDash != null && paint.lineDash.length > 0) {
|
|
155
|
-
skPaint.setPathEffect(Skia.PathEffect.MakeDash(paint.lineDash));
|
|
156
|
-
} else {
|
|
157
|
-
skPaint.setPathEffect(null);
|
|
158
|
-
}
|
|
199
|
+
applyGlow(skPaint, paint, pool);
|
|
200
|
+
applyDash(skPaint, paint.lineDash, pool);
|
|
159
201
|
|
|
160
202
|
return skPaint;
|
|
161
203
|
}
|
|
162
204
|
|
|
163
|
-
function
|
|
205
|
+
function getClearPaint(pool: ReplayPool): SkPaint {
|
|
164
206
|
'worklet';
|
|
165
207
|
|
|
166
|
-
|
|
167
|
-
|
|
208
|
+
if (pool.clearPaint == null) {
|
|
209
|
+
pool.clearPaint = Skia.Paint();
|
|
210
|
+
pool.clearPaint.setBlendMode(BlendMode.Clear);
|
|
211
|
+
}
|
|
168
212
|
|
|
169
|
-
return clearPaint;
|
|
213
|
+
return pool.clearPaint;
|
|
170
214
|
}
|
|
171
215
|
|
|
172
216
|
type PaintKind = 'fill' | 'stroke';
|
|
@@ -261,14 +305,10 @@ function applyPathCommand(
|
|
|
261
305
|
builder.quadTo(command.cpx, command.cpy, command.x, command.y);
|
|
262
306
|
break;
|
|
263
307
|
case 'addRect':
|
|
264
|
-
builder.addRect(
|
|
308
|
+
builder.addRect(command.rect);
|
|
265
309
|
break;
|
|
266
310
|
case 'addArc':
|
|
267
|
-
builder.addArc(
|
|
268
|
-
toSkiaRect(command.rect),
|
|
269
|
-
command.startDegrees,
|
|
270
|
-
command.sweepDegrees
|
|
271
|
-
);
|
|
311
|
+
builder.addArc(command.rect, command.startDegrees, command.sweepDegrees);
|
|
272
312
|
break;
|
|
273
313
|
case 'close':
|
|
274
314
|
builder.close();
|
|
@@ -278,16 +318,26 @@ function applyPathCommand(
|
|
|
278
318
|
}
|
|
279
319
|
}
|
|
280
320
|
|
|
281
|
-
|
|
321
|
+
/**
|
|
322
|
+
* Build the recorded path in the pooled builder (`detach` hands over the path
|
|
323
|
+
* and resets the builder for the next command), draw it, and free it at once:
|
|
324
|
+
* the canvas copies the path at the draw call.
|
|
325
|
+
*/
|
|
326
|
+
function drawRecordedPath(
|
|
327
|
+
canvas: SkCanvas,
|
|
328
|
+
path: readonly VexflowRecordingPathCommand[],
|
|
329
|
+
skPaint: SkPaint,
|
|
330
|
+
builder: SkPathBuilder
|
|
331
|
+
) {
|
|
282
332
|
'worklet';
|
|
283
333
|
|
|
284
|
-
const builder = Skia.PathBuilder.Make();
|
|
285
|
-
|
|
286
334
|
for (const command of path) {
|
|
287
335
|
applyPathCommand(builder, command);
|
|
288
336
|
}
|
|
289
337
|
|
|
290
|
-
|
|
338
|
+
const skPath = builder.detach();
|
|
339
|
+
canvas.drawPath(skPath, skPaint);
|
|
340
|
+
skPath.dispose();
|
|
291
341
|
}
|
|
292
342
|
|
|
293
343
|
export function renderVexflowRecordingCommands(
|
|
@@ -314,98 +364,100 @@ export function renderVexflowRecordingCommands(
|
|
|
314
364
|
|
|
315
365
|
const fontManager =
|
|
316
366
|
replayFontManager ?? new FontManager(fontProvider, defaultFont);
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
)
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
367
|
+
const pool = createReplayPool();
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
for (const command of commands) {
|
|
371
|
+
switch (command.type) {
|
|
372
|
+
case 'clear':
|
|
373
|
+
canvas.clear(getCachedColor(command.color, pool));
|
|
374
|
+
break;
|
|
375
|
+
case 'save':
|
|
376
|
+
canvas.save();
|
|
377
|
+
break;
|
|
378
|
+
case 'restore':
|
|
379
|
+
canvas.restore();
|
|
380
|
+
break;
|
|
381
|
+
case 'scale':
|
|
382
|
+
canvas.scale(command.x, command.y);
|
|
383
|
+
break;
|
|
384
|
+
case 'translate':
|
|
385
|
+
canvas.translate(command.x, command.y);
|
|
386
|
+
break;
|
|
387
|
+
case 'clipRect':
|
|
388
|
+
canvas.clipRect(command.rect, ClipOp.Intersect, true);
|
|
389
|
+
break;
|
|
390
|
+
case 'fillRect':
|
|
391
|
+
canvas.drawRect(
|
|
392
|
+
command.rect,
|
|
393
|
+
configureFillPaint(
|
|
394
|
+
resolveStyle(
|
|
395
|
+
command.paint,
|
|
396
|
+
command.groupId,
|
|
397
|
+
'fill',
|
|
398
|
+
styleOverrides
|
|
399
|
+
),
|
|
400
|
+
pool
|
|
401
|
+
)
|
|
402
|
+
);
|
|
403
|
+
break;
|
|
404
|
+
case 'clearRect':
|
|
405
|
+
canvas.drawRect(command.rect, getClearPaint(pool));
|
|
406
|
+
break;
|
|
407
|
+
case 'fillPath':
|
|
408
|
+
drawRecordedPath(
|
|
409
|
+
canvas,
|
|
410
|
+
command.path,
|
|
411
|
+
configureFillPaint(
|
|
412
|
+
resolveStyle(
|
|
413
|
+
command.paint,
|
|
414
|
+
command.groupId,
|
|
415
|
+
'fill',
|
|
416
|
+
styleOverrides
|
|
417
|
+
),
|
|
418
|
+
pool
|
|
369
419
|
),
|
|
370
|
-
|
|
371
|
-
)
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
420
|
+
pool.pathBuilder
|
|
421
|
+
);
|
|
422
|
+
break;
|
|
423
|
+
case 'strokePath':
|
|
424
|
+
drawRecordedPath(
|
|
425
|
+
canvas,
|
|
426
|
+
command.path,
|
|
427
|
+
configureStrokePaint(
|
|
428
|
+
resolveStyle(
|
|
429
|
+
command.paint,
|
|
430
|
+
command.groupId,
|
|
431
|
+
'stroke',
|
|
432
|
+
styleOverrides
|
|
433
|
+
),
|
|
434
|
+
pool
|
|
384
435
|
),
|
|
385
|
-
|
|
386
|
-
)
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
436
|
+
pool.pathBuilder
|
|
437
|
+
);
|
|
438
|
+
break;
|
|
439
|
+
case 'fillText':
|
|
440
|
+
canvas.drawText(
|
|
441
|
+
command.text,
|
|
442
|
+
command.x,
|
|
443
|
+
command.y,
|
|
444
|
+
configureFillPaint(
|
|
445
|
+
resolveStyle(
|
|
446
|
+
command.paint,
|
|
447
|
+
command.groupId,
|
|
448
|
+
'fill',
|
|
449
|
+
styleOverrides
|
|
450
|
+
),
|
|
451
|
+
pool
|
|
401
452
|
),
|
|
402
|
-
|
|
403
|
-
)
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
assertNever(command);
|
|
453
|
+
createFont(fontManager, command.font)
|
|
454
|
+
);
|
|
455
|
+
break;
|
|
456
|
+
default:
|
|
457
|
+
assertNever(command);
|
|
458
|
+
}
|
|
409
459
|
}
|
|
460
|
+
} finally {
|
|
461
|
+
disposeReplayPool(pool);
|
|
410
462
|
}
|
|
411
463
|
}
|
package/src/renderer/layout.ts
CHANGED
|
@@ -144,6 +144,21 @@ export function layoutScore(
|
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Whether `layoutScore` reads `viewport.height` for this score. Only the
|
|
149
|
+
* infinite score centers on it; document layouts use it solely for the
|
|
150
|
+
* content size of a score with no measures. Callers can skip a re-layout on
|
|
151
|
+
* height-only viewport changes when this is false.
|
|
152
|
+
*/
|
|
153
|
+
export function layoutUsesViewportHeight(
|
|
154
|
+
rendererType: RendererType,
|
|
155
|
+
measuredScore: MeasuredScore
|
|
156
|
+
): boolean {
|
|
157
|
+
return (
|
|
158
|
+
rendererType === 'infiniteScore' || measuredScore.measures.length === 0
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
147
162
|
function buildGroupLayoutContext(
|
|
148
163
|
score: Score,
|
|
149
164
|
measuredScore: MeasuredScore
|
|
@@ -9,8 +9,12 @@ import {
|
|
|
9
9
|
} from '../base/VexflowRecordingIndex';
|
|
10
10
|
import type { Score } from '../state';
|
|
11
11
|
import { isVexflowNativeDebugEnabled } from '../shared/debug';
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
layoutScore,
|
|
14
|
+
layoutUsesViewportHeight,
|
|
15
|
+
type ScoreLayoutPlan,
|
|
16
|
+
} from './layout';
|
|
17
|
+
import { measureScore, type MeasuredScore } from './measure';
|
|
14
18
|
import { renderScore } from './render';
|
|
15
19
|
import {
|
|
16
20
|
createContentViewport,
|
|
@@ -64,34 +68,65 @@ export function useScoreRecording({
|
|
|
64
68
|
score: Score;
|
|
65
69
|
viewport: RendererRect;
|
|
66
70
|
}): ScoreRecording {
|
|
67
|
-
|
|
71
|
+
// Measuring does not depend on the viewport and is the most expensive pass,
|
|
72
|
+
// so it is cached apart from layout and render.
|
|
73
|
+
const measurement = useMemo((): ScoreMeasurement | null => {
|
|
68
74
|
if (!enabled) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const measureStart = nowMs();
|
|
79
|
+
// On native, constructing a context installs it as VexFlow's text
|
|
80
|
+
// measurement canvas, so text is measured with this font setup.
|
|
81
|
+
// eslint-disable-next-line no-new
|
|
82
|
+
new VexflowRecordingContext(fontManager, defaultFont);
|
|
83
|
+
const measuredScore = measureScore(score, options, { decorateItem });
|
|
84
|
+
|
|
85
|
+
return { measuredScore, measureMs: nowMs() - measureStart };
|
|
86
|
+
}, [decorateItem, defaultFont, enabled, fontManager, options, score]);
|
|
87
|
+
|
|
88
|
+
// Height-only changes (a late safe-area inset, the keyboard) cannot move a
|
|
89
|
+
// layout that ignores the height, so the height is pinned to 0 for it and
|
|
90
|
+
// such a change keeps the recording.
|
|
91
|
+
const layoutHeight =
|
|
92
|
+
!measurement ||
|
|
93
|
+
layoutUsesViewportHeight(rendererType, measurement.measuredScore)
|
|
94
|
+
? viewport.height
|
|
95
|
+
: 0;
|
|
96
|
+
const layoutViewport = useMemo(
|
|
97
|
+
(): RendererRect => ({
|
|
98
|
+
x: viewport.x,
|
|
99
|
+
y: viewport.y,
|
|
100
|
+
width: viewport.width,
|
|
101
|
+
height: layoutHeight,
|
|
102
|
+
}),
|
|
103
|
+
[layoutHeight, viewport.width, viewport.x, viewport.y]
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return useMemo(() => {
|
|
107
|
+
if (!measurement) {
|
|
69
108
|
return {
|
|
70
109
|
commands: [],
|
|
71
110
|
groupIndex: {},
|
|
72
|
-
layoutPlan: createEmptyLayoutPlan(rendererType,
|
|
73
|
-
itemsLayout: createEmptyItemsLayout(
|
|
111
|
+
layoutPlan: createEmptyLayoutPlan(rendererType, layoutViewport),
|
|
112
|
+
itemsLayout: createEmptyItemsLayout(layoutViewport),
|
|
74
113
|
};
|
|
75
114
|
}
|
|
76
115
|
|
|
77
|
-
// Layout
|
|
78
|
-
//
|
|
116
|
+
// Layout and render run in content space against the virtual viewport;
|
|
117
|
+
// see src/renderer/scale.ts.
|
|
79
118
|
const scale = getRenderScale(options);
|
|
80
|
-
const contentViewport = createContentViewport(
|
|
81
|
-
|
|
82
|
-
const measureStart = nowMs();
|
|
119
|
+
const contentViewport = createContentViewport(layoutViewport, scale);
|
|
83
120
|
const ctx = new VexflowRecordingContext(
|
|
84
121
|
fontManager,
|
|
85
122
|
defaultFont,
|
|
86
123
|
colorScheme
|
|
87
124
|
);
|
|
88
|
-
const measuredScore = measureScore(score, options, { decorateItem });
|
|
89
|
-
const measureMs = nowMs() - measureStart;
|
|
90
125
|
|
|
91
126
|
const layoutStart = nowMs();
|
|
92
127
|
const layoutPlan = layoutScore(
|
|
93
128
|
score,
|
|
94
|
-
measuredScore,
|
|
129
|
+
measurement.measuredScore,
|
|
95
130
|
options,
|
|
96
131
|
rendererType,
|
|
97
132
|
contentViewport
|
|
@@ -120,12 +155,12 @@ export function useScoreRecording({
|
|
|
120
155
|
finishMs,
|
|
121
156
|
layoutMs,
|
|
122
157
|
measureCount: layoutPlan.measures.length,
|
|
123
|
-
|
|
158
|
+
measurement,
|
|
124
159
|
renderMs,
|
|
125
160
|
rendererType,
|
|
126
161
|
scoreId: score.id,
|
|
127
162
|
systemCount: layoutPlan.systems.length,
|
|
128
|
-
viewport,
|
|
163
|
+
viewport: layoutViewport,
|
|
129
164
|
});
|
|
130
165
|
|
|
131
166
|
return {
|
|
@@ -138,16 +173,28 @@ export function useScoreRecording({
|
|
|
138
173
|
colorScheme,
|
|
139
174
|
decorateItem,
|
|
140
175
|
defaultFont,
|
|
141
|
-
enabled,
|
|
142
176
|
fontManager,
|
|
177
|
+
layoutViewport,
|
|
178
|
+
measurement,
|
|
143
179
|
onDrawItem,
|
|
144
180
|
options,
|
|
145
181
|
rendererType,
|
|
146
182
|
score,
|
|
147
|
-
viewport,
|
|
148
183
|
]);
|
|
149
184
|
}
|
|
150
185
|
|
|
186
|
+
interface ScoreMeasurement {
|
|
187
|
+
measuredScore: MeasuredScore;
|
|
188
|
+
measureMs: number;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Measurements already counted by a profile line. A cached measurement is
|
|
193
|
+
* reported once, by the first recording built on it, so summed profiles
|
|
194
|
+
* count each measure pass once.
|
|
195
|
+
*/
|
|
196
|
+
const profiledMeasurements = new WeakSet<ScoreMeasurement>();
|
|
197
|
+
|
|
151
198
|
function createEmptyItemsLayout(viewport: RendererRect): ScoreItemsLayout {
|
|
152
199
|
return {
|
|
153
200
|
items: {},
|
|
@@ -182,7 +229,7 @@ function logScoreRecordingProfile({
|
|
|
182
229
|
finishMs,
|
|
183
230
|
layoutMs,
|
|
184
231
|
measureCount,
|
|
185
|
-
|
|
232
|
+
measurement,
|
|
186
233
|
renderMs,
|
|
187
234
|
rendererType,
|
|
188
235
|
scoreId,
|
|
@@ -195,7 +242,7 @@ function logScoreRecordingProfile({
|
|
|
195
242
|
finishMs: number;
|
|
196
243
|
layoutMs: number;
|
|
197
244
|
measureCount: number;
|
|
198
|
-
|
|
245
|
+
measurement: ScoreMeasurement;
|
|
199
246
|
renderMs: number;
|
|
200
247
|
rendererType: RendererType;
|
|
201
248
|
scoreId: string;
|
|
@@ -206,6 +253,11 @@ function logScoreRecordingProfile({
|
|
|
206
253
|
return;
|
|
207
254
|
}
|
|
208
255
|
|
|
256
|
+
const measureMs = profiledMeasurements.has(measurement)
|
|
257
|
+
? 0
|
|
258
|
+
: measurement.measureMs;
|
|
259
|
+
profiledMeasurements.add(measurement);
|
|
260
|
+
|
|
209
261
|
console.info('[ScoreRenderer] recording profile', {
|
|
210
262
|
scoreId,
|
|
211
263
|
rendererType,
|